Commit 884be206 authored by Mark Schulte's avatar Mark Schulte Committed by Fabio Utzig
Browse files

imgtool: Adjust base_addr when injecting header

If adding a header to a .hex file (using the command line
"--pad-header"), the hex file gets shifted by header size. This may
cause hard coded addresses to be off by "header-size", making the
firmware unusable. Instead, adjust the base address by the header
size, so the existing firmware in the hex file is loaded to the
proper addresses.

Signed-off-by: default avatarMark Schulte <mschulte@lyft.com>
parent 0ccee874
Loading
Loading
Loading
Loading
+3
Changes for scripts/imgtool/image.py: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -79,6 +79,9 @@ class Image():

        # Add the image header if needed.
        if pad_header and obj.header_size > 0:
            if obj.base_addr:
                # Adjust base_addr for new header
                obj.base_addr -= obj.header_size
            obj.payload = (b'\000' * obj.header_size) + obj.payload

        obj.check()