Fixed upgrade in OVERWRITE_ONLY mode

pull/1/head
Daniele Lacamera 2018-10-26 12:15:25 +02:00
parent c5f644f97e
commit 6f203a84c3
4 changed files with 29 additions and 30 deletions

View File

@ -4,16 +4,14 @@
#define FLASH_DEV_NAME "flash"
#define FLASH_ALIGN 4
/* Example flash partitioning.
* Ensure that your firmware entry point is
* at FLASH_AREA_IMAGE_0_OFFSET + 0x100
*/
#define FLASH_AREA_IMAGE_0_OFFSET 0x20000
#define FLASH_AREA_IMAGE_0_SIZE 0x20000
#define FLASH_AREA_IMAGE_1_OFFSET 0x40000
#define FLASH_AREA_IMAGE_1_SIZE 0x20000
#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x60000
#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x20000
#define FLASH_AREA_IMAGE_0_OFFSET 0x2f000
#define FLASH_AREA_IMAGE_0_SIZE 0x28000
/* Unused page 0x57000:0x58000 */
#define FLASH_AREA_IMAGE_1_OFFSET 0x58000
#define FLASH_AREA_IMAGE_1_SIZE 0x28000
#define FLASH_AREA_IMAGE_NO_SCRATCH
//#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x6f000
//#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x11000
/*
* Sanity check the target support.

View File

@ -643,8 +643,6 @@ int flash_area_open(uint8_t id, const struct flash_area **area)
wolfBoot_printf("Unsupported area\n");
boot_panic();
}
/* Unsure if this is right, just returning the first area. */
*area = &flash_areas->slots[i].whole;
return 0;
}
@ -718,6 +716,10 @@ int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
boot_panic();
}
if (slot->num_areas == 1) {
slot->areas = &slot->whole;
}
*cnt = slot->num_areas;
memcpy(ret, slot->areas, slot->num_areas * sizeof(struct flash_area));
@ -746,13 +748,17 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,
boot_panic();
}
for (i = 0; i < slot->num_areas; i++) {
sectors[i].fs_off = slot->areas[i].fa_off -
slot->whole.fa_off;
sectors[i].fs_size = slot->areas[i].fa_size;
}
*count = slot->num_areas;
if (slot->num_areas == 1) {
sectors[0].fs_off = slot->whole.fa_off;
sectors[0].fs_size = slot->whole.fa_size;
} else {
for (i = 0; i < slot->num_areas; i++) {
sectors[i].fs_off = slot->areas[i].fa_off -
slot->whole.fa_off;
sectors[i].fs_size = slot->areas[i].fa_size;
}
}
return 0;
}

View File

@ -155,11 +155,14 @@ boot_status_source(void)
size_t i;
uint8_t source;
memset(&state_scratch, 0xFF, sizeof(state_scratch));
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_0, &state_slot0);
boot_panic_unless(rc == 0);
#ifndef WOLFBOOT_OVERWRITE_ONLY
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SCRATCH, &state_scratch);
boot_panic_unless(rc == 0);
#endif
BOOT_LOG_SWAP_STATE("Image 0", &state_slot0);
BOOT_LOG_SWAP_STATE("Scratch", &state_scratch);
@ -213,7 +216,6 @@ boot_previous_swap_type(void)
* Compute the total size of the given image. Includes the size of
* the TLVs.
*/
#if !defined(WOLFBOOT_OVERWRITE_ONLY) || defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
static int
boot_read_image_size(int slot, struct image_header *hdr, uint32_t *size)
{
@ -246,7 +248,6 @@ done:
flash_area_close(fap);
return rc;
}
#endif /* !WOLFBOOT_OVERWRITE_ONLY */
static int
boot_read_image_header(int slot, struct image_header *out_hdr)
@ -464,19 +465,17 @@ boot_read_status(struct boot_status *bs)
memset(bs, 0, sizeof *bs);
#ifdef WOLFBOOT_OVERWRITE_ONLY
/* Overwrite-only doesn't make use of the swap status area. */
return 0;
#endif
status_loc = boot_status_source();
switch (status_loc) {
case BOOT_STATUS_SOURCE_NONE:
return 0;
#ifndef WOLFBOOT_OVERWRITE_ONLY
case BOOT_STATUS_SOURCE_SCRATCH:
area_id = FLASH_AREA_IMAGE_SCRATCH;
break;
#endif
case BOOT_STATUS_SOURCE_SLOT0:
area_id = FLASH_AREA_IMAGE_0;
@ -1040,11 +1039,9 @@ boot_copy_image(struct boot_status *bs)
(void)bs;
#if defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
uint32_t src_size = 0;
rc = boot_read_image_size(1, boot_img_hdr(&boot_data, 1), &src_size);
boot_panic_unless(rc == 0);
#endif
wolfBoot_printf("Image upgrade slot1 -> slot0");
wolfBoot_printf("Erasing slot0");
@ -1059,11 +1056,9 @@ boot_copy_image(struct boot_status *bs)
size += this_size;
#if defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
if (size >= src_size) {
break;
}
#endif
}
wolfBoot_printf("Copying slot 1 to slot 0: 0x%lx bytes", size);

@ -1 +1 @@
Subproject commit 9a0ecd4eb69d932aed46fb4b448492bcfdf28ea9
Subproject commit 84fb23cfabd00a3ba2ae8f53665526c9f3844a48