-
Notifications
You must be signed in to change notification settings - Fork 157
/
Copy pathflash_to_spi.py
65 lines (38 loc) · 1.3 KB
/
flash_to_spi.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
#!/usr/bin/env python
import sys, os
FLASH_SIZE = 8 * 1024 * 1024
FLASHROM = 'flashrom'
# needed files
LAYOUT = 'spi_rom.layout'
TEMP = 'spi_rom.tmp'
def main():
if len(sys.argv) >= 3:
prog = sys.argv[1]
path = sys.argv[2]
remote = sys.argv[3] if len(sys.argv) >= 4 else None
size = os.path.getsize(path)
with open(LAYOUT, 'wb') as fd:
# write flash layout file
fd.write('%.8x:%.8x main' % (0, size - 1))
with open(TEMP, 'wb') as fd:
with open(path, 'rb') as fd_s:
fd.write(fd_s.read())
# write padding
fd.write('\0' * (FLASH_SIZE - size))
if remote:
# copy needed files to remote machine
assert os.system('scp spi_rom.* %s:/tmp' % remote) == 0
# execute flashrom
return os.system('ssh %s %s -p %s --layout /tmp/%s --image main -w /tmp/%s' % \
(remote, FLASHROM, prog, LAYOUT, TEMP))
else:
return os.system('%s -p %s --layout %s --image main -w %s' % \
(FLASHROM, prog, LAYOUT, TEMP))
else:
print('USAGE: flash_to_spi.py <programmer> <bin_file> [remote]')
return -1
if __name__ == '__main__':
sys.exit(main())
#
# EoF
#