Commit a5d59b4c authored by Thomas Altenbach's avatar Thomas Altenbach Committed by Jamie McCrae
Browse files

boot_serial: Use flash area from bootloader state when possible



Now we have a valid bootloader state in bs_list and bs_set, opening and
closing the flash areas within those routines is no longer needed. This
commit removes superfluous open/close.

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 avatarThomas Altenbach <thomas.altenbach@legrand.com>
(cherry picked from commit 13edc5fb)
parent 16472e08
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -250,7 +250,7 @@ static void
bs_list(struct boot_loader_state *state, char *buf, int len)
{
    struct image_header hdr;
    uint32_t slot, area_id;
    uint32_t slot;
    const struct flash_area *fap;
    uint8_t image_index;
#ifdef MCUBOOT_SERIAL_IMG_GRP_HASH
@@ -283,8 +283,8 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
            bool permanent = false;
#endif

            area_id = flash_area_id_from_multi_image_slot(image_index, slot);
            if (flash_area_open(area_id, &fap)) {
            fap = BOOT_IMG_AREA(state, slot);
            if (fap == NULL) {
                continue;
            }

@@ -328,7 +328,6 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
            }

            if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
                flash_area_close(fap);
                continue;
            }

@@ -337,7 +336,6 @@ bs_list(struct boot_loader_state *state, char *buf, int len)
            rc = boot_serial_get_hash(&hdr, fap, hash);
#endif

            flash_area_close(fap);
            zcbor_map_start_encode(cbor_state, 20);

#if (BOOT_IMAGE_NUMBER > 1)
@@ -480,13 +478,11 @@ bs_set(struct boot_loader_state *state, char *buf, int len)

            for (slot = 0; slot < BOOT_NUM_SLOTS; slot++) {
                struct image_header hdr;
                uint32_t area_id;
                const struct flash_area *fap;
                uint8_t tmpbuf[64];

                area_id = flash_area_id_from_multi_image_slot(image_index, slot);
                if (flash_area_open(area_id, &fap)) {
                    BOOT_LOG_ERR("Failed to open flash area ID %d", area_id);
                fap = BOOT_IMG_AREA(state, slot);
                if (fap == NULL) {
                    continue;
                }

@@ -526,7 +522,6 @@ bs_set(struct boot_loader_state *state, char *buf, int len)

                /* Retrieve SHA256 hash of image for identification */
                rc = boot_serial_get_hash(&hdr, fap, hash);
                flash_area_close(fap);

                if (rc == 0 && memcmp(hash, img_hash.value, sizeof(hash)) == 0) {
                    /* Hash matches, set this slot for test or confirmation */