Skip to content

Commit 4535ad9

Browse files
de-nordicnordicjm
authored andcommitted
boot: Additional flash_area_open removals
Another set of flash_area_open removals where boot_loader_state is available to provide flash_area object's pointer. Signed-off-by: Dominik Ermel <[email protected]>
1 parent c0bb133 commit 4535ad9

File tree

5 files changed

+22
-60
lines changed

5 files changed

+22
-60
lines changed

boot/bootutil/src/bootutil_misc.c

+3-11
Original file line numberDiff line numberDiff line change
@@ -447,19 +447,12 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
447447
struct image_tlv_info info;
448448
uint32_t off;
449449
uint32_t protect_tlv_size;
450-
int area_id;
451450
int rc;
452451

453-
#if (BOOT_IMAGE_NUMBER == 1)
454-
(void)state;
455-
#endif
452+
assert(slot == BOOT_PRIMARY_SLOT || slot == BOOT_SECONDARY_SLOT);
456453

457-
area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
458-
rc = flash_area_open(area_id, &fap);
459-
if (rc != 0) {
460-
rc = BOOT_EFLASH;
461-
goto done;
462-
}
454+
fap = BOOT_IMG_AREA(state, slot);
455+
assert(fap != NULL);
463456

464457
off = BOOT_TLV_OFF(boot_img_hdr(state, slot));
465458

@@ -493,7 +486,6 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
493486
rc = 0;
494487

495488
done:
496-
flash_area_close(fap);
497489
return rc;
498490
}
499491
#endif /* !MCUBOOT_OVERWRITE_ONLY */

boot/bootutil/src/loader.c

+6-19
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
716716
{
717717
const struct flash_area *fap;
718718
uint32_t off;
719-
int area_id;
720719
int rc = 0;
721720
uint8_t buf[BOOT_MAX_ALIGN];
722721
uint32_t align;
@@ -731,20 +730,15 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
731730
#if MCUBOOT_SWAP_USING_SCRATCH
732731
if (bs->use_scratch) {
733732
/* Write to scratch. */
734-
area_id = FLASH_AREA_IMAGE_SCRATCH;
733+
fap = state->scratch.area;
735734
} else {
736735
#endif
737736
/* Write to the primary slot. */
738-
area_id = FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state));
737+
fap = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
739738
#if MCUBOOT_SWAP_USING_SCRATCH
740739
}
741740
#endif
742741

743-
rc = flash_area_open(area_id, &fap);
744-
if (rc != 0) {
745-
return BOOT_EFLASH;
746-
}
747-
748742
off = boot_status_off(fap) +
749743
boot_status_internal_off(bs, BOOT_WRITE_SZ(state));
750744
align = flash_area_align(fap);
@@ -761,8 +755,6 @@ boot_write_status(const struct boot_loader_state *state, struct boot_status *bs)
761755
rc = BOOT_EFLASH;
762756
}
763757

764-
flash_area_close(fap);
765-
766758
return rc;
767759
}
768760
#endif /* !MCUBOOT_RAM_LOAD */
@@ -1470,13 +1462,11 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
14701462
BOOT_LOG_INF("Image %d upgrade secondary slot -> primary slot", image_index);
14711463
BOOT_LOG_INF("Erasing the primary slot");
14721464

1473-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index),
1474-
&fap_primary_slot);
1475-
assert (rc == 0);
1465+
fap_primary_slot = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
1466+
assert(fap_primary_slot != NULL);
14761467

1477-
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index),
1478-
&fap_secondary_slot);
1479-
assert (rc == 0);
1468+
fap_secondary_slot = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
1469+
assert(fap_secondary_slot != NULL);
14801470

14811471
sect_count = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
14821472
for (sect = 0, size = 0; sect < sect_count; sect++) {
@@ -1590,9 +1580,6 @@ boot_copy_image(struct boot_loader_state *state, struct boot_status *bs)
15901580
last_sector));
15911581
assert(rc == 0);
15921582

1593-
flash_area_close(fap_primary_slot);
1594-
flash_area_close(fap_secondary_slot);
1595-
15961583
/* TODO: Perhaps verify the primary slot's signature again? */
15971584

15981585
return 0;

boot/bootutil/src/swap_misc.c

+3-9
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
124124
const struct flash_area *fap;
125125
uint32_t off;
126126
uint8_t swap_info;
127-
int area_id;
128127
int rc;
129128

130129
bs->source = swap_status_source(state);
@@ -134,23 +133,20 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
134133

135134
#if MCUBOOT_SWAP_USING_SCRATCH
136135
case BOOT_STATUS_SOURCE_SCRATCH:
137-
area_id = FLASH_AREA_IMAGE_SCRATCH;
136+
fap = state->scratch.area;
138137
break;
139138
#endif
140139

141140
case BOOT_STATUS_SOURCE_PRIMARY_SLOT:
142-
area_id = FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state));
141+
fap = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
143142
break;
144143

145144
default:
146145
assert(0);
147146
return BOOT_EBADARGS;
148147
}
149148

150-
rc = flash_area_open(area_id, &fap);
151-
if (rc != 0) {
152-
return BOOT_EFLASH;
153-
}
149+
assert(fap != NULL);
154150

155151
rc = swap_read_status_bytes(fap, state, bs);
156152
if (rc == 0) {
@@ -171,8 +167,6 @@ swap_read_status(struct boot_loader_state *state, struct boot_status *bs)
171167
}
172168

173169
done:
174-
flash_area_close(fap);
175-
176170
return rc;
177171
}
178172

boot/bootutil/src/swap_move.c

+4-11
Original file line numberDiff line numberDiff line change
@@ -517,10 +517,8 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
517517
uint32_t trailer_sz;
518518
uint32_t first_trailer_idx;
519519
uint32_t last_idx;
520-
uint8_t image_index;
521520
const struct flash_area *fap_pri;
522521
const struct flash_area *fap_sec;
523-
int rc;
524522

525523
BOOT_LOG_INF("Starting swap using move algorithm.");
526524

@@ -553,13 +551,11 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
553551
}
554552
}
555553

556-
image_index = BOOT_CURR_IMG(state);
554+
fap_pri = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
555+
assert(fap_pri != NULL);
557556

558-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index), &fap_pri);
559-
assert (rc == 0);
560-
561-
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap_sec);
562-
assert (rc == 0);
557+
fap_sec = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
558+
assert(fap_sec != NULL);
563559

564560
fixup_revert(state, bs, fap_sec);
565561

@@ -583,9 +579,6 @@ swap_run(struct boot_loader_state *state, struct boot_status *bs,
583579
}
584580
idx++;
585581
}
586-
587-
flash_area_close(fap_pri);
588-
flash_area_close(fap_sec);
589582
}
590583

591584
int app_max_size(struct boot_loader_state *state)

boot/bootutil/src/swap_scratch.c

+6-10
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,14 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
564564

565565
image_index = BOOT_CURR_IMG(state);
566566

567-
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(image_index), &fap_primary_slot);
568-
assert (rc == 0);
567+
fap_primary_slot = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
568+
assert(fap_primary_slot != NULL);
569569

570-
rc = flash_area_open(FLASH_AREA_IMAGE_SECONDARY(image_index), &fap_secondary_slot);
571-
assert (rc == 0);
570+
fap_secondary_slot = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
571+
assert(fap_secondary_slot != NULL);
572572

573-
rc = flash_area_open(FLASH_AREA_IMAGE_SCRATCH, &fap_scratch);
574-
assert (rc == 0);
573+
fap_scratch = state->scratch.area;
574+
assert(fap_scratch != NULL);
575575

576576
/* Calculate offset from start of image area. */
577577
img_off = boot_img_sector_off(state, BOOT_PRIMARY_SLOT, idx);
@@ -782,10 +782,6 @@ boot_swap_sectors(int idx, uint32_t sz, struct boot_loader_state *state,
782782
assert(rc == 0);
783783
}
784784
}
785-
786-
flash_area_close(fap_primary_slot);
787-
flash_area_close(fap_secondary_slot);
788-
flash_area_close(fap_scratch);
789785
}
790786

791787
void

0 commit comments

Comments
 (0)