boot: bootutil: Fix max image size computation for swap-move/swap-offset
When computing the maximum image size in bootutil_max_image_size for swap-move or swap-offset strategy, the computation was using the size of the flash area provided as argument and was not taking into account the size of the padding sector. This was causing an incorrect size to be returned in some cases, for example when the two slots have the same size or when the slots haven't the same size but the routine is called for the slot containing the padding sector. For example, let's imagine swap-move is being used on a device having a sector size S and two slots of N bytes. This is valid configuration and the maximum image size is N - S - T, T being the size of the trailer rounded up to the next multiple of S. When calling bootutil_max_image_size with either the primary or secondary slot, the size N - T is returned, which is incorrect. This commit fixes the issue by computing always the maximum image using the size of the slot containing the padding and substracting the size of the padding and of the aligned trailer. Note: This PR has been modified from the upstream commit due to a merge failure from other changes that are not being brought into Zephyr 3.7 Signed-off-by:Thomas Altenbach <thomas.altenbach@legrand.com> (cherry picked from commit 61d280b9)
Loading
Please sign in to comment