Commit b0f04733 authored by Fabio Utzig's avatar Fabio Utzig Committed by Fabio Utzig
Browse files

Remove current_image global and macro updates

Currently to determine which image is being operated on, there is a global
variable called current_image which is used by most macros and APIs to
correctly access the flash areas required by the bootloader. This moves
this variable to the already existing state struct and refactors all
macros and APIs to receive the current image by parameters. To maintain
compatibility some of the macros were not updated and use image 0 when
called.

The definitions of FLASH_AREA_IMAGE_PRIMARY and FLASH_AREA_IMAGE_SECONDARY
for Mynewt compatibility were moved out of bootutil sources to a Mynewt
specific include file.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent abec073f
Loading
Loading
Loading
Loading
+1 −1
Changes for boot/boot_serial/src/boot_serial.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -178,7 +178,7 @@ bs_list(char *buf, int len)
        flash_area_read(fap, 0, &hdr, sizeof(hdr));

        if (hdr.ih_magic != IMAGE_MAGIC ||
          bootutil_img_validate(&hdr, fap, tmpbuf, sizeof(tmpbuf),
          bootutil_img_validate(0, &hdr, fap, tmpbuf, sizeof(tmpbuf),
                                NULL, 0, NULL)) {
            flash_area_close(fap);
            continue;
+1 −1
Changes for boot/boot_serial/test/src/testcases/boot_serial_img_msg.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ TEST_CASE(boot_serial_img_msg)
    /*
     * Validate contents inside the primary slot
     */
    rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY, &fap);
    rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(0), &fap);
    assert(rc == 0);

    rc = flash_area_read(fap, 0, enc_img, sizeof(img));
+4 −5
Changes for boot/bootutil/include/bootutil/bootutil.h: 4 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -26,11 +26,6 @@
extern "C" {
#endif

#if defined(MCUBOOT_MYNEWT)
#define FLASH_AREA_IMAGE_PRIMARY    FLASH_AREA_IMAGE_0
#define FLASH_AREA_IMAGE_SECONDARY  FLASH_AREA_IMAGE_1
#endif

/** Attempt to boot the contents of the primary slot. */
#define BOOT_SWAP_TYPE_NONE     1

@@ -91,6 +86,10 @@ struct image_trailer {
/* you must have pre-allocated all the entries within this structure */
int boot_go(struct boot_rsp *rsp);

struct boot_loader_state;
int context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp);

int boot_swap_type_multi(int image_index);
int boot_swap_type(void);

int boot_set_pending(int permanent);
+5 −5
Changes for boot/bootutil/include/bootutil/enc_key.h: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -50,12 +50,12 @@ struct enc_key_data {
extern const struct bootutil_key bootutil_enc_key;

int boot_enc_set_key(uint8_t slot, uint8_t *enckey);
int boot_enc_load(const struct image_header *hdr, const struct flash_area *fap,
        uint8_t *enckey);
bool boot_enc_valid(const struct flash_area *fap);
int boot_enc_load(int image_index, const struct image_header *hdr,
        const struct flash_area *fap, uint8_t *enckey);
bool boot_enc_valid(int image_index, const struct flash_area *fap);
void boot_enc_mark_keys_invalid(void);
void boot_encrypt(const struct flash_area *fap, uint32_t off, uint32_t sz,
        uint32_t blk_off, uint8_t *buf);
void boot_encrypt(int image_index, const struct flash_area *fap, uint32_t off,
        uint32_t sz, uint32_t blk_off, uint8_t *buf);
void boot_enc_zeroize(void);

#ifdef __cplusplus
+1 −1
Changes for boot/bootutil/include/bootutil/image.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -134,7 +134,7 @@ _Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
               "struct image_header not required size");
#endif

int bootutil_img_validate(struct image_header *hdr,
int bootutil_img_validate(int image_index, struct image_header *hdr,
                          const struct flash_area *fap,
                          uint8_t *tmp_buf, uint32_t tmp_buf_sz,
                          uint8_t *seed, int seed_len, uint8_t *out_hash);
Loading