Commit 45f96eb7 authored by Andrzej Puzdrowski's avatar Andrzej Puzdrowski Committed by Jamie McCrae
Browse files

boot/boot_serial: build-time skip of the erasing of img status page



For MCUboot's MCUBOOT_SINGLE_APPLICATION_SLOT, MCUBOOT_FIRMWARE_LOADER,
MCUBOOT_SINGLE_APPLICATION_SLOT_RAM_LOAD
modes there is not image run-time status data at the end on the image.
Erase of that was done as the last image page erase - and was no harm
before by luck.

Following commit just reveled the issue:
 #35536633

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: default avatarAndrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
(cherry picked from commit 713b98b6)
parent a3166c52
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -77,6 +77,12 @@


BOOT_LOG_MODULE_DECLARE(mcuboot);
BOOT_LOG_MODULE_DECLARE(mcuboot);


#if !(defined(MCUBOOT_SINGLE_APPLICATION_SLOT) || \
    defined(MCUBOOT_FIRMWARE_LOADER) ||           \
    defined(MCUBOOT_SINGLE_APPLICATION_SLOT_RAM_LOAD))
#define BOOT_IMAGE_HAS_STATUS_FIELDS
#endif

#ifndef ARRAY_SIZE
#ifndef ARRAY_SIZE
#define ARRAY_SIZE ZCBOR_ARRAY_SIZE
#define ARRAY_SIZE ZCBOR_ARRAY_SIZE
#endif
#endif
@@ -709,8 +715,10 @@ bs_upload(char *buf, int len)
                                         * erase has stopped to let us know whether erase
                                         * erase has stopped to let us know whether erase
                                         * is needed to be able to write current chunk.
                                         * is needed to be able to write current chunk.
                                         */
                                         */
#ifdef BOOT_IMAGE_HAS_STATUS_FIELDS
    static struct flash_sector status_sector;
    static struct flash_sector status_sector;
#endif
#endif
#endif /* MCUBOOT_ERASE_PROGRESSIVELY */


    zcbor_state_t zsd[4 + CBOR_EXTRA_STATES];
    zcbor_state_t zsd[4 + CBOR_EXTRA_STATES];
    zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), (uint8_t *)buf, len, 1, NULL, 0);
    zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), (uint8_t *)buf, len, 1, NULL, 0);
@@ -775,7 +783,7 @@ bs_upload(char *buf, int len)
        const size_t area_size = flash_area_get_size(fap);
        const size_t area_size = flash_area_get_size(fap);


        curr_off = 0;
        curr_off = 0;
#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#if defined(MCUBOOT_ERASE_PROGRESSIVELY) && defined(BOOT_IMAGE_HAS_STATUS_FIELDS)
        /* Get trailer sector information; this is done early because inability to get
        /* Get trailer sector information; this is done early because inability to get
         * that sector information means that upload will not work anyway.
         * that sector information means that upload will not work anyway.
         * TODO: This is single occurrence issue, it should get detected during tests
         * TODO: This is single occurrence issue, it should get detected during tests
@@ -903,7 +911,7 @@ bs_upload(char *buf, int len)
    if (rc == 0) {
    if (rc == 0) {
        curr_off += img_chunk_len + rem_bytes;
        curr_off += img_chunk_len + rem_bytes;
        if (curr_off == img_size) {
        if (curr_off == img_size) {
#ifdef MCUBOOT_ERASE_PROGRESSIVELY
#if defined(MCUBOOT_ERASE_PROGRESSIVELY) && defined(BOOT_IMAGE_HAS_STATUS_FIELDS)
            /* Assure that sector for image trailer was erased. */
            /* Assure that sector for image trailer was erased. */
            /* Check whether it was erased during previous upload. */
            /* Check whether it was erased during previous upload. */
            off_t start = flash_sector_get_off(&status_sector);
            off_t start = flash_sector_get_off(&status_sector);