-
Notifications
You must be signed in to change notification settings - Fork 79
/
flash.py
executable file
·73 lines (52 loc) · 2.19 KB
/
flash.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
import os
import argparse
import make
def main():
parser = argparse.ArgumentParser(description="Board flashing tool")
make.get_args(parser)
parser.add_argument("--mode", default="image", choices=["image", "gateware", "bios", "firmware", "other"], help="Type of file to flash")
parser.add_argument("--other-file", default=None)
parser.add_argument("--address", type=int, help="Where to flash if using --mode=other")
args = parser.parse_args()
builddir = make.get_builddir(args)
platform = make.get_platform(args)
soc = make.get_soc(args, platform)
bios_maxsize = make.get_bios_maxsize(args, soc)
if args.mode == 'image':
filename = make.get_image(builddir, "flash")
address_start = 0
address_end = platform.spiflash_total_size
elif args.mode == 'gateware':
filename = make.get_gateware(builddir, "flash")
address_start = 0
address_end = platform.gateware_size
elif args.mode == 'bios':
filename = make.get_bios(builddir, "flash")
address_start = platform.gateware_size
address_end = platform.gateware_size + bios_maxsize
elif args.mode == 'firmware':
if args.override_firmware:
filename = args.override_firmware
else:
filename = make.get_firmware(builddir, "flash")
address_start = platform.gateware_size + bios_maxsize
address_end = platform.spiflash_total_size
elif args.mode == 'other':
filename = args.other_file
address_start = args.address
address_end = platform.spiflash_total_size
else:
assert False, "Unknown flashing mode."
filepath = os.path.realpath(filename)
assert address_start >= 0
assert os.path.exists(filepath), "%s not found at %s" % (
args.mode, filepath)
file_size = len(open(filepath, 'rb').read())
file_end = address_start+file_size
assert file_end < address_end, "File is too big!\n%s file doesn't fit in %s space (%s extra bytes)." % (
filename, file_size, address_end - address_start)
prog = make.get_prog(args, platform)
prog.flash(address_start, filepath)
if __name__ == "__main__":
main()