Skip to content

Commit

Permalink
Fixes detection of zero-containing blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsracz committed Dec 20, 2023
1 parent 2fd8ecf commit 95e699a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ LDFLAGSEXTRA+= --specs=nano.specs
bootloader_bin/bootloader.bin: FORCE
$(MAKE) -C $(realpath bootloader_bin) bootloader.bin

payload.cxxout: bootloader_bin/bootloader.bin
payload.cxxout: bootloader_bin/bootloader.bin $(OPENMRNPATH)/bin/build_bootloader_img.py
$(OPENMRNPATH)/bin/build_bootloader_img.py -i bootloader_bin/bootloader.bin -o $@

.cxxout.o:
Expand Down
8 changes: 7 additions & 1 deletion bin/build_bootloader_img.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,32 @@ def print_c_array(file_out, name, payload):

outputblocks = []

print("Blocks:", end=" ")
for k, block in enumerate(blocks):
if k == 0:
b = Block()
b.ofs = 0
b.data = block
b.end_ofs = 0
outputblocks.append(b)
print("b", end="")
continue
if block.count('\0') == len(block): # all zeros
if block.count(b'\x00') == len(block): # all zeros
print("o", end="")
continue
if outputblocks[-1].end_ofs == k - 1:
outputblocks[-1].data += block
outputblocks[-1].end_ofs = k
print("x", end="")
else:
b = Block()
b.ofs = k
b.data = block
b.end_ofs = k
outputblocks.append(b)
print("b", end="")

print("")
segmenttable = ''
for b in outputblocks:
print_c_array(file_out, "payload_%d" % b.ofs, b.data);
Expand Down

0 comments on commit 95e699a

Please sign in to comment.