Skip to content

Commit 6f203a8

Browse files
committed
Fixed upgrade in OVERWRITE_ONLY mode
1 parent c5f644f commit 6f203a8

4 files changed

Lines changed: 29 additions & 30 deletions

File tree

include/target.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
#define FLASH_DEV_NAME "flash"
55
#define FLASH_ALIGN 4
66

7-
/* Example flash partitioning.
8-
* Ensure that your firmware entry point is
9-
* at FLASH_AREA_IMAGE_0_OFFSET + 0x100
10-
*/
11-
#define FLASH_AREA_IMAGE_0_OFFSET 0x20000
12-
#define FLASH_AREA_IMAGE_0_SIZE 0x20000
13-
#define FLASH_AREA_IMAGE_1_OFFSET 0x40000
14-
#define FLASH_AREA_IMAGE_1_SIZE 0x20000
15-
#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x60000
16-
#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x20000
7+
#define FLASH_AREA_IMAGE_0_OFFSET 0x2f000
8+
#define FLASH_AREA_IMAGE_0_SIZE 0x28000
9+
/* Unused page 0x57000:0x58000 */
10+
#define FLASH_AREA_IMAGE_1_OFFSET 0x58000
11+
#define FLASH_AREA_IMAGE_1_SIZE 0x28000
12+
#define FLASH_AREA_IMAGE_NO_SCRATCH
13+
//#define FLASH_AREA_IMAGE_SCRATCH_OFFSET 0x6f000
14+
//#define FLASH_AREA_IMAGE_SCRATCH_SIZE 0x11000
1715

1816
/*
1917
* Sanity check the target support.

lib/bootutil/src/bootutil_misc.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,6 @@ int flash_area_open(uint8_t id, const struct flash_area **area)
643643
wolfBoot_printf("Unsupported area\n");
644644
boot_panic();
645645
}
646-
647-
/* Unsure if this is right, just returning the first area. */
648646
*area = &flash_areas->slots[i].whole;
649647
return 0;
650648
}
@@ -718,6 +716,10 @@ int flash_area_to_sectors(int idx, int *cnt, struct flash_area *ret)
718716
boot_panic();
719717
}
720718

719+
if (slot->num_areas == 1) {
720+
slot->areas = &slot->whole;
721+
}
722+
721723
*cnt = slot->num_areas;
722724
memcpy(ret, slot->areas, slot->num_areas * sizeof(struct flash_area));
723725

@@ -746,13 +748,17 @@ int flash_area_get_sectors(int fa_id, uint32_t *count,
746748
boot_panic();
747749
}
748750

749-
for (i = 0; i < slot->num_areas; i++) {
750-
sectors[i].fs_off = slot->areas[i].fa_off -
751-
slot->whole.fa_off;
752-
sectors[i].fs_size = slot->areas[i].fa_size;
753-
}
754751
*count = slot->num_areas;
755-
752+
if (slot->num_areas == 1) {
753+
sectors[0].fs_off = slot->whole.fa_off;
754+
sectors[0].fs_size = slot->whole.fa_size;
755+
} else {
756+
for (i = 0; i < slot->num_areas; i++) {
757+
sectors[i].fs_off = slot->areas[i].fa_off -
758+
slot->whole.fa_off;
759+
sectors[i].fs_size = slot->areas[i].fa_size;
760+
}
761+
}
756762
return 0;
757763
}
758764

lib/bootutil/src/loader.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,14 @@ boot_status_source(void)
155155
size_t i;
156156
uint8_t source;
157157

158+
memset(&state_scratch, 0xFF, sizeof(state_scratch));
159+
158160
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_0, &state_slot0);
159161
boot_panic_unless(rc == 0);
160-
162+
#ifndef WOLFBOOT_OVERWRITE_ONLY
161163
rc = boot_read_swap_state_by_id(FLASH_AREA_IMAGE_SCRATCH, &state_scratch);
162164
boot_panic_unless(rc == 0);
165+
#endif
163166

164167
BOOT_LOG_SWAP_STATE("Image 0", &state_slot0);
165168
BOOT_LOG_SWAP_STATE("Scratch", &state_scratch);
@@ -213,7 +216,6 @@ boot_previous_swap_type(void)
213216
* Compute the total size of the given image. Includes the size of
214217
* the TLVs.
215218
*/
216-
#if !defined(WOLFBOOT_OVERWRITE_ONLY) || defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
217219
static int
218220
boot_read_image_size(int slot, struct image_header *hdr, uint32_t *size)
219221
{
@@ -246,7 +248,6 @@ boot_read_image_size(int slot, struct image_header *hdr, uint32_t *size)
246248
flash_area_close(fap);
247249
return rc;
248250
}
249-
#endif /* !WOLFBOOT_OVERWRITE_ONLY */
250251

251252
static int
252253
boot_read_image_header(int slot, struct image_header *out_hdr)
@@ -464,19 +465,17 @@ boot_read_status(struct boot_status *bs)
464465

465466
memset(bs, 0, sizeof *bs);
466467

467-
#ifdef WOLFBOOT_OVERWRITE_ONLY
468-
/* Overwrite-only doesn't make use of the swap status area. */
469-
return 0;
470-
#endif
471468

472469
status_loc = boot_status_source();
473470
switch (status_loc) {
474471
case BOOT_STATUS_SOURCE_NONE:
475472
return 0;
476473

474+
#ifndef WOLFBOOT_OVERWRITE_ONLY
477475
case BOOT_STATUS_SOURCE_SCRATCH:
478476
area_id = FLASH_AREA_IMAGE_SCRATCH;
479477
break;
478+
#endif
480479

481480
case BOOT_STATUS_SOURCE_SLOT0:
482481
area_id = FLASH_AREA_IMAGE_0;
@@ -1040,11 +1039,9 @@ boot_copy_image(struct boot_status *bs)
10401039

10411040
(void)bs;
10421041

1043-
#if defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
10441042
uint32_t src_size = 0;
10451043
rc = boot_read_image_size(1, boot_img_hdr(&boot_data, 1), &src_size);
10461044
boot_panic_unless(rc == 0);
1047-
#endif
10481045

10491046
wolfBoot_printf("Image upgrade slot1 -> slot0");
10501047
wolfBoot_printf("Erasing slot0");
@@ -1059,11 +1056,9 @@ boot_copy_image(struct boot_status *bs)
10591056

10601057
size += this_size;
10611058

1062-
#if defined(WOLFBOOT_OVERWRITE_ONLY_FAST)
10631059
if (size >= src_size) {
10641060
break;
10651061
}
1066-
#endif
10671062
}
10681063

10691064
wolfBoot_printf("Copying slot 1 to slot 0: 0x%lx bytes", size);

0 commit comments

Comments
 (0)