MCPcopy Create free account
hub / github.com/FrameworkComputer/framework-system / write_flashimage

Function write_flashimage

decode_pcapng.py:160–195  ·  view source on GitHub ↗
(path, binary1, binary2)

Source from the content-addressed store, hash-verified

158
159# Write the binary in the same layout with padding as on flash
160def write_flashimage(path, binary1, binary2):
161 with open(path, "wb") as f:
162 # Write fist padding
163 # Verified
164 print("Padding 1: {:04X} to {:04X}".format(0, binary1[0][0]))
165 for row in range(0, binary1[0][0]):
166 f.write(b'\0' * ROW_SIZE)
167
168 # Verified
169 print("FW IMG 1: {:04X} to {:04X}".format(binary1[0][0], binary1[-2][0]))
170 for (addr, row) in binary1[0:-1]:
171 f.write(row)
172
173 print("Padding 2: {:04X} to {:04X}".format(binary1[-2][0], binary2[0][0]-1))
174 for row in range(binary1[-2][0], binary2[0][0]-1):
175 f.write(b'\0' * ROW_SIZE)
176
177 print("FW IMG 2: {:04X} to {:04X}".format(binary2[0][0], binary2[-2][0]))
178 for (addr, row) in binary2[0:-1]:
179 f.write(row)
180
181 print("Padding 3: {:04X} to {:04X}".format(binary2[-2][0], binary2[-1][0]-1))
182 for row in range(binary2[-2][0], binary2[-1][0]-1):
183 f.write(b'\0' * ROW_SIZE)
184
185 # Notice that these are in reverse order!
186 # FW2 metadata is before FW1 metadata
187 print("Metadata 2: {:04X} to {:04X}".format(binary2[-1][0], binary2[-1][0]))
188 f.write(binary2[-1][1])
189 print("Metadata 1: {:04X} to {:04X}".format(binary1[-1][0], binary1[-1][0]))
190 f.write(binary1[-1][1])
191
192 # Pad from end of FW1 metadata
193 print("Padding 4: {:04X} to {:04X}".format(binary1[-1][0], MAX_ROWS-1))
194 for row in range(binary1[-1][0], MAX_ROWS-1):
195 f.write(b'\0' * ROW_SIZE)
196
197
198def check_assumptions(img1_binary, img2_binary):

Callers 1

mainFunction · 0.85

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected