scripts: eva_ramboot.py: remove unused import
[openwrt/staging/wigyori.git] / scripts / flashing / eva_ramboot.py
1 #!/usr/bin/env python3
2
3 import argparse
4
5 from ftplib import FTP
6 from os import stat
7
8 parser = argparse.ArgumentParser(description='Tool to boot AVM EVA ramdisk images.')
9 parser.add_argument('ip', type=str, help='IP-address to transfer the image to')
10 parser.add_argument('image', type=str, help='Location of the ramdisk image')
11 parser.add_argument('--offset', type=lambda x: int(x,0), help='Offset to load the image to in hex format with leading 0x. Only needed for non-lantiq devices.')
12 args = parser.parse_args()
13
14 size = stat(args.image).st_size
15 # arbitrary size limit, to prevent the address calculations from overflows etc.
16 assert size < 0x2000000
17
18 if args.offset:
19 addr = size
20 haddr = args.offset
21 else:
22 # We need to align the address.
23 # A page boundary seems to be sufficient on 7362sl and 7412
24 addr = ((0x8000000 - size) & ~0xfff)
25 haddr = 0x80000000 + addr
26
27 img = open(args.image, "rb")
28 ftp = FTP(args.ip, 'adam2', 'adam2')
29
30 def adam(cmd):
31 print("> %s"%(cmd))
32 resp = ftp.sendcmd(cmd)
33 print("< %s"%(resp))
34 assert resp[0:3] == "200"
35
36 ftp.set_pasv(True)
37 # The following parameters allow booting the avm recovery system with this
38 # script.
39 adam('SETENV memsize 0x%08x'%(addr))
40 adam('SETENV kernel_args_tmp mtdram1=0x%08x,0x88000000'%(haddr))
41 adam('MEDIA SDRAM')
42 ftp.storbinary('STOR 0x%08x 0x88000000'%(haddr), img)
43 img.close()
44 ftp.close()