Commit 9bd7f90e authored by David Brown's avatar David Brown Committed by David Brown
Browse files

boot: Add a RAM base to support testing



Add a macro `IMAGE_RAM_BASE` that will support a simulated device RAM
that can be different per test.  This will be zero on targets.  Define
an invalid value (3) in the simulator environment.  As there are not yet
tests of this configuration, all tests will continue to pass.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 94ed12c4
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -403,10 +403,14 @@ boot_img_sector_off(const struct boot_loader_state *state, size_t slot,
#endif  /* !defined(MCUBOOT_USE_FLASH_AREA_GET_SECTORS) */

#ifdef MCUBOOT_RAM_LOAD
#define IMAGE_RAM_BASE ((uintptr_t)0)

#define LOAD_IMAGE_DATA(hdr, fap, start, output, size)       \
    (memcpy((output),(void*)((hdr)->ih_load_addr + (start)), \
    (memcpy((output),(void*)(IMAGE_RAM_BASE + (hdr)->ih_load_addr + (start)), \
    (size)), 0)
#else
#define IMAGE_RAM_BASE ((uintptr_t)0)

#define LOAD_IMAGE_DATA(hdr, fap, start, output, size)       \
    (flash_area_read((fap), (start), (output), (size)))
#endif /* MCUBOOT_RAM_LOAD */
+3 −1
Original line number Diff line number Diff line
@@ -116,7 +116,9 @@ bootutil_img_hash(struct enc_key_data *enc_state, int image_index,
    size += hdr->ih_protect_tlv_size;

#ifdef MCUBOOT_RAM_LOAD
    bootutil_sha256_update(&sha256_ctx,(void*)(hdr->ih_load_addr), size);
    bootutil_sha256_update(&sha256_ctx,
                           (void*)(IMAGE_RAM_BASE + hdr->ih_load_addr),
                           size);
#else
    for (off = 0; off < size; off += blk_sz) {
        blk_sz = size - off;
+1 −1
Original line number Diff line number Diff line
@@ -2416,7 +2416,7 @@ boot_copy_image_to_sram(struct boot_loader_state *state, int slot,
    }

    /* Direct copy from flash to its new location in SRAM. */
    rc = flash_area_read(fap_src, 0, (void *)img_dst, img_sz);
    rc = flash_area_read(fap_src, 0, (void *)(IMAGE_RAM_BASE + img_dst), img_sz);
    if (rc != 0) {
        BOOT_LOG_INF("Error whilst copying image from Flash to SRAM: %d", rc);
    }