diff options
Diffstat (limited to 'utils/fiio_m3k_tools/nand_patcher.py')
-rwxr-xr-x | utils/fiio_m3k_tools/nand_patcher.py | 69 |
1 files changed, 0 insertions, 69 deletions
diff --git a/utils/fiio_m3k_tools/nand_patcher.py b/utils/fiio_m3k_tools/nand_patcher.py deleted file mode 100755 index 261a4de678..0000000000 --- a/utils/fiio_m3k_tools/nand_patcher.py +++ /dev/null | |||
@@ -1,69 +0,0 @@ | |||
1 | #!/usr/bin/python3 | ||
2 | |||
3 | import sys | ||
4 | |||
5 | IMAGE_SIZE = 128 * 1024 # image is an 128 KiB erase block | ||
6 | SPL_SIZE = 12 * 1024 # SPL is at most 12 KiB | ||
7 | BOOT_SIZE = 102 * 1024 # bootloader at most 102 KiB | ||
8 | BOOT_OFF = 26 * 1024 # offset of bootloader in image | ||
9 | BOOT_END = BOOT_OFF+BOOT_SIZE | ||
10 | |||
11 | def patch(in_path, boot_path, spl_path, out_path): | ||
12 | # Open the input files | ||
13 | in_file = open(in_path, 'rb') | ||
14 | boot_file = open(boot_path, 'rb') | ||
15 | spl_file = open(spl_path, 'rb') | ||
16 | |||
17 | # Read the data | ||
18 | in_data = in_file.read() | ||
19 | boot_data = boot_file.read() | ||
20 | spl_data = spl_file.read() | ||
21 | |||
22 | # Close input files | ||
23 | in_file.close() | ||
24 | boot_file.close() | ||
25 | spl_file.close() | ||
26 | |||
27 | if len(in_data) != IMAGE_SIZE: | ||
28 | print("error: input image is %d bytes, expected %d" % (len(in_data), IMAGE_SIZE)) | ||
29 | sys.exit(1) | ||
30 | |||
31 | if len(spl_data) > SPL_SIZE: | ||
32 | print("error: SPL is %d bytes, maximum is %d" % (len(spl_data), SPL_SIZE)) | ||
33 | sys.exit(1) | ||
34 | |||
35 | if len(boot_data) > BOOT_SIZE: | ||
36 | print("error: bootloader is %d bytes, maximum is %d" % (len(boot_data), SPL_SIZE)) | ||
37 | sys.exit(1) | ||
38 | |||
39 | print('Patching input image %s' % in_path) | ||
40 | print('- SPL size %d' % len(spl_data)) | ||
41 | print('- Boot size %d' % len(boot_data)) | ||
42 | |||
43 | # Construct output image | ||
44 | out_data = b'' | ||
45 | out_data += spl_data | ||
46 | out_data += b'\xff' * (SPL_SIZE - len(spl_data)) | ||
47 | out_data += in_data[SPL_SIZE:BOOT_OFF] | ||
48 | out_data += boot_data | ||
49 | out_data += b'\xff' * (BOOT_SIZE - len(boot_data)) | ||
50 | |||
51 | # Sanity check | ||
52 | assert( len(out_data) == IMAGE_SIZE ) | ||
53 | |||
54 | # Write output | ||
55 | print('Writing output image %s' % out_path) | ||
56 | out_file = open(out_path, 'wb') | ||
57 | out_file.write(out_data) | ||
58 | out_file.close() | ||
59 | |||
60 | |||
61 | def main(): | ||
62 | if len(sys.argv) != 5: | ||
63 | print("usage: nand_patcher.py IN_FILE BOOT_FILE SPL_FILE OUT_FILE") | ||
64 | sys.exit(1) | ||
65 | |||
66 | patch(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]) | ||
67 | |||
68 | if __name__ == '__main__': | ||
69 | main() | ||