Skip to content

boot: bootutil: swap_offset: Fix maximum application size #2269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2025

Conversation

nordicjm
Copy link
Collaborator

Fixes this functionality to have the maximum allowable application size

Fixes this functionality to have the maximum allowable application
size

Signed-off-by: Jamie McCrae <[email protected]>
@nordicjm nordicjm requested a review from davidvincze as a code owner April 17, 2025 14:04
@nordicjm nordicjm requested a review from de-nordic April 17, 2025 14:04
Comment on lines +345 to +347
if (num_sectors_pri != num_sectors_sec &&
(num_sectors_pri + 1) != num_sectors_sec &&
num_usable_sectors != (num_sectors_sec - 1)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm. The allowed primary will be always at least one page shorter than secondary, because that page is used for swapping, so:

num_sectors_pri - 1 >= num_sectors_sec

is the first condition.
From that we have sectors really available for image as:

num_usable_sectors = num_sectors_sec - int((trailer_sz + PAGE_SIZE  - 1) / PAGE_SIZE)

That is how much could be uploaded if num_sectors_pri - 1 >= num_sectors_sec. Secondary slot sets the limit.

If we have

num_sectors_pri - 1 < num_sectors_sec

then:

num_usable_sectors = (num_sectors_pri - 1) - int((trailer_sz + PAGE_SIZE  - 1) / PAGE_SIZE)

That is how much could be swapped, the primary slot sets the limit.

@nordicjm nordicjm requested a review from de-nordic April 23, 2025 09:34
@nordicjm nordicjm merged commit 47d826e into mcu-tools:main Apr 23, 2025
58 of 70 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants