Proposal: Add End Alignment Padding Option to imgtool #2218
r-pfitzner-truma
started this conversation in
Ideas
Replies: 1 comment
-
The image should be written with padding, so if your minimum write size is 32 bytes and your image is 65517 bytes, 65504 bytes should be written directly then last 19 should be written as 19 bytes of data and 13 bytes of padding (i.e. 0xff on flash). Can see the MCUboot serial recovery code handling that: https://github.com/mcu-tools/mcuboot/blob/main/boot/boot_serial/src/boot_serial.c#L1085 and zephyr's dfu subsystem also handles it |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Context
In the current implementation of the imgtool used in MCUboot, the TLV (Type-Length-Value) area is not padded to a multiple of the alignment size. While the TLV area is correctly aligned at the beginning, it is not padded at the end to ensure the entire image size is a multiple of the alignment size. This can result in an image that is not a multiple of the write size, depending on the content of the TLV area.
Proposal
Introduce a new boolean switch
--end-align
to the imgtool sign command. This switch will pad the generated image to the next alignment boundary with the erased value (0xFF). This ensures that the final image size is a multiple of the alignment size. The default value for this option can be set tofalse
to maintain the current default behavior.Implementation Details
The padding should be added in the image create function after the TLV area has been appended. The padding should be added before the
check_trailer
function is called to ensure there is still enough space for the trailer after padding.Additionally, the
imgtool dump
function will require a minor modification to be compatible with this change.Proposed Code Change
Rationale
Padding the image to the next alignment boundary ensures that the image size is always a multiple of the alignment size. This can prevent potential issues with writing the image to flash memory, where write operations often require the size to be a multiple of the write size.
Request for Feedback
I would appreciate feedback on this proposal, especially regarding any potential issues or improvements that could be made. If this idea is deemed useful, I am willing to implement the changes and contribute a pull request to MCUboot. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions