tools: Pad final chunks with 0xff if necessary.
authorTilman Sauerbeck <tilman@code-monkey.de>
Fri, 3 Jan 2020 15:33:15 +0000 (16:33 +0100)
committerTilman Sauerbeck <tilman@code-monkey.de>
Mon, 6 Jan 2020 09:45:34 +0000 (10:45 +0100)
The bootloader only accepts chunks whose size is a multiple of four.

tools/update-firmware

index f610343f37c8ba1fb672b73e49ac37c2fde44841..cd711241ab3858d6e62cb366b1d376549ae48f47 100755 (executable)
@@ -168,6 +168,13 @@ class Application:
                 sys.stderr.write('File too large.\n')
                 return 3
 
+            # The bootloader only accepts chunks whose size is word-aligned:
+            num_extra = len(chunks[-1]) & 3
+
+            if num_extra != 0:
+                num_pad = 4 - extra
+                chunks[-1] += b'\xff' * num_pad
+
         # Defaulting to zero seems too dangerous:
         if self._offset is None:
             sector0 = None