imgtool: Make "included header" optional
The imgtool.py program has been assuming that the input image for
signing has a zero padded place for the header at the beginning of the
image. This is only true for some platforms.
Instead, make this included header space optional. By default, prepend
the header to the image. If `--included-header` is specified to the
sign command, consider the bytes at the beginning of the image to be
padded space for the header. This option is required for Zephyr builds.
diff --git a/scripts/imgtool/image.py b/scripts/imgtool/image.py
index c4bedfe..b6a572d 100644
--- a/scripts/imgtool/image.py
+++ b/scripts/imgtool/image.py
@@ -55,12 +55,17 @@
class Image():
@classmethod
- def load(cls, path, **kwargs):
+ def load(cls, path, included_header=False, **kwargs):
"""Load an image from a given file"""
with open(path, 'rb') as f:
payload = f.read()
obj = cls(**kwargs)
obj.payload = payload
+
+ # Add the image header if needed.
+ if not included_header and obj.header_size > 0:
+ obj.payload = (b'\000' * obj.header_size) + obj.payload
+
obj.check()
return obj