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