Skip to content
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

Unconditional erase of trailer sector in serial recovery #1862

Open
jomigo96 opened this issue Nov 20, 2023 · 6 comments
Open

Unconditional erase of trailer sector in serial recovery #1862

jomigo96 opened this issue Nov 20, 2023 · 6 comments
Labels

Comments

@jomigo96
Copy link

With MCUBoot in serial recovery, and with MCUBOOT_ERASE_PROGRESSIVELY, it seems that the last flash sector is unconditionally erased after the full image is received, causing the slot to be invalid if there was image data in that sector.

In this section from boot_serial.c

            /* Assure that sector for image trailer was erased. */
            /* Check whether it was erased during previous upload. */
            off_t start = flash_sector_get_off(&status_sector);

            if (erase_range(fap, start, start) < 0) {
                rc = MGMT_ERR_EUNKNOWN;
                goto out;
            }

The comment appears to indicate that it should check if the sector was already erased, but no such check is done.

Is this unintended, or does this mean that the last sector cannot have image data? I'm using a swap with scratch configuration.

@thedjnK
Copy link

thedjnK commented Nov 20, 2023

This is expected, the MCUboot swap status goes there. An MCUboot image should be your whole image i.e. the hex/bin file, which then goes through imgtool to add the MCUboot header and footer, at this point that is the final image that cannot be changed, you cannot append data to the end of it. If you want to do that, you need to edit the hex/bin file before it is passed to imgtool

@jomigo96
Copy link
Author

jomigo96 commented Nov 21, 2023

By image data I did not mean any modifications to the binary after imgtool, just the normal binary.

Let's say the image slot is 896 KiB with flash sectors of 128KiB. I observe that if the signed binary is larger than 768KiB, after upload this last sector is erased. Since it would have data/tlvs, the image is invalid. The same binary is working fine if flashed via debugger or uploaded without MCUBOOT_ERASE_PROGRESSIVELY.

@nordicjm
Copy link
Collaborator

Let's say the image slot is 896 KiB with flash sectors of 128KiB. I observe that if the signed binary is larger than 768KiB, after upload this last sector is erased. Since it would have data/tlvs, the image is invalid. The same binary is working fine if flashed via debugger or uploaded without MCUBOOT_ERASE_PROGRESSIVELY.

This is incorrect, there is the TLVs which are part of the image, they do not go in a new sector. There is a new sector(s) which is/are used for the swap status, this should be visible on https://docs.mcuboot.com/design.html but the website is down at present for some reason

@jomigo96
Copy link
Author

there is the TLVs which are part of the image, they do not go in a new sector

Not a new sector, but in the last sector of the slot due to the size of the binary requiring it.

There is a new sector(s) which is/are used for the swap status

But is it exclusively for swap status? The design page only mentions

Note: Be aware that the image trailers make the ending area of the image slot unavailable for carrying the image data. In particular, the swap status size could be huge. For example, for 128 slot sectors with a 4-byte alignment, it would become 1536 B.

I was under the impression that it needs space for swap information, but this is controlled by MCUBOOT_MAX_IMG_SECTORS and the remaining space could be image data.

@nordicjm
Copy link
Collaborator

nordicjm commented Nov 21, 2023

That Kconfig is the maximum number of sectors that will be searched and are supported (i.e. controls how large the swap field size will be), the size is limited by the partition size, so you can set that Kconfig to 5000 but with a 4KiB sector size and only 20 sectors in the partition, the 5000 value will just waste flash space, it will never go beyond 80KiB.

Copy link

This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time.

@github-actions github-actions bot added the stale label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants