@@ -548,15 +548,10 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
548
548
struct image_dependency dep ;
549
549
uint32_t off ;
550
550
uint16_t len ;
551
- int area_id ;
552
551
int rc ;
553
552
554
- area_id = flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), slot );
555
- rc = flash_area_open (area_id , & fap );
556
- if (rc != 0 ) {
557
- rc = BOOT_EFLASH ;
558
- goto done ;
559
- }
553
+ fap = BOOT_IMG_AREA (state , slot );
554
+ assert (fap != NULL );
560
555
561
556
#if defined(MCUBOOT_SWAP_USING_OFFSET )
562
557
it .start_off = boot_get_state_secondary_offset (state , fap );
@@ -603,7 +598,6 @@ boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot)
603
598
}
604
599
605
600
done :
606
- flash_area_close (fap );
607
601
return rc ;
608
602
}
609
603
@@ -948,20 +942,14 @@ boot_data_is_set_to(uint8_t val, void *data, size_t len)
948
942
static int
949
943
boot_check_header_erased (struct boot_loader_state * state , int slot )
950
944
{
951
- const struct flash_area * fap ;
945
+ const struct flash_area * fap = NULL ;
952
946
struct image_header * hdr ;
953
947
uint8_t erased_val ;
954
- int area_id ;
955
- int rc ;
956
948
957
- area_id = flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), slot );
958
- rc = flash_area_open (area_id , & fap );
959
- if (rc != 0 ) {
960
- return -1 ;
961
- }
949
+ fap = BOOT_IMG_AREA (state , slot );
950
+ assert (fap != NULL );
962
951
963
952
erased_val = flash_area_erased_val (fap );
964
- flash_area_close (fap );
965
953
966
954
hdr = boot_img_hdr (state , slot );
967
955
if (!boot_data_is_set_to (erased_val , & hdr -> ih_magic , sizeof (hdr -> ih_magic ))) {
@@ -1022,19 +1010,14 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1022
1010
{
1023
1011
const struct flash_area * fap ;
1024
1012
struct image_header * hdr ;
1025
- int area_id ;
1026
1013
FIH_DECLARE (fih_rc , FIH_FAILURE );
1027
- int rc ;
1028
1014
1029
1015
#if !defined(MCUBOOT_SWAP_USING_OFFSET )
1030
1016
(void )expected_swap_type ;
1031
1017
#endif
1032
1018
1033
- area_id = flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), slot );
1034
- rc = flash_area_open (area_id , & fap );
1035
- if (rc != 0 ) {
1036
- FIH_RET (fih_rc );
1037
- }
1019
+ fap = BOOT_IMG_AREA (state , slot );
1020
+ assert (fap != NULL );
1038
1021
1039
1022
hdr = boot_img_hdr (state , slot );
1040
1023
if (boot_check_header_erased (state , slot ) == 0 ||
@@ -1056,20 +1039,13 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1056
1039
#if defined(MCUBOOT_SWAP_USING_MOVE )
1057
1040
if (bs -> swap_type == BOOT_SWAP_TYPE_REVERT ||
1058
1041
boot_swap_type_multi (BOOT_CURR_IMG (state )) == BOOT_SWAP_TYPE_REVERT ) {
1059
- const struct flash_area * fap_pri ;
1060
-
1061
- rc = flash_area_open (flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ),
1062
- BOOT_PRIMARY_SLOT ),
1063
- & fap_pri );
1042
+ const struct flash_area * fap_pri = BOOT_IMG_AREA (state , BOOT_PRIMARY_SLOT );
1064
1043
1065
- if (rc == 0 ) {
1066
- rc = swap_erase_trailer_sectors (state , fap_pri );
1067
- flash_area_close (fap_pri );
1044
+ assert (fap_pri != NULL );
1068
1045
1069
- if (rc == 0 ) {
1070
- BOOT_LOG_INF ("Cleared image %d primary slot trailer due to stuck revert" ,
1071
- BOOT_CURR_IMG (state ));
1072
- }
1046
+ if (swap_erase_trailer_sectors (state , fap_pri ) == 0 ) {
1047
+ BOOT_LOG_INF ("Cleared image %d primary slot trailer due to stuck revert" ,
1048
+ BOOT_CURR_IMG (state ));
1073
1049
}
1074
1050
}
1075
1051
#endif
@@ -1103,6 +1079,8 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1103
1079
1104
1080
#if defined(MCUBOOT_OVERWRITE_ONLY ) && defined(MCUBOOT_DOWNGRADE_PREVENTION )
1105
1081
if (slot != BOOT_PRIMARY_SLOT ) {
1082
+ int rc ;
1083
+
1106
1084
/* Check if version of secondary slot is sufficient */
1107
1085
rc = boot_version_cmp (
1108
1086
& boot_img_hdr (state , BOOT_SECONDARY_SLOT )-> ih_ver ,
@@ -1151,14 +1129,13 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1151
1129
* overwriting an application written to the incorrect slot.
1152
1130
* This feature is only supported by ARM platforms.
1153
1131
*/
1154
- if (area_id == FLASH_AREA_IMAGE_SECONDARY ( BOOT_CURR_IMG ( state ) )) {
1132
+ if (fap == BOOT_IMG_AREA ( state , BOOT_SECONDARY_SLOT )) {
1155
1133
const struct flash_area * pri_fa = BOOT_IMG_AREA (state , BOOT_PRIMARY_SLOT );
1156
1134
struct image_header * secondary_hdr = boot_img_hdr (state , slot );
1157
1135
uint32_t reset_value = 0 ;
1158
1136
uint32_t reset_addr = secondary_hdr -> ih_hdr_size + sizeof (reset_value );
1159
1137
1160
- rc = flash_area_read (fap , reset_addr , & reset_value , sizeof (reset_value ));
1161
- if (rc != 0 ) {
1138
+ if (flash_area_read (fap , reset_addr , & reset_value , sizeof (reset_value )) != 0 ) {
1162
1139
fih_rc = FIH_NO_BOOTABLE_IMAGE ;
1163
1140
goto out ;
1164
1141
}
@@ -1181,8 +1158,6 @@ boot_validate_slot(struct boot_loader_state *state, int slot,
1181
1158
#endif
1182
1159
1183
1160
out :
1184
- flash_area_close (fap );
1185
-
1186
1161
FIH_RET (fih_rc );
1187
1162
}
1188
1163
@@ -1208,12 +1183,8 @@ boot_update_security_counter(struct boot_loader_state *state, int slot, int hdr_
1208
1183
uint32_t img_security_cnt ;
1209
1184
int rc ;
1210
1185
1211
- rc = flash_area_open (flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), slot ),
1212
- & fap );
1213
- if (rc != 0 ) {
1214
- rc = BOOT_EFLASH ;
1215
- goto done ;
1216
- }
1186
+ fap = BOOT_IMG_AREA (state , slot );
1187
+ assert (fap != NULL );
1217
1188
1218
1189
rc = bootutil_get_img_security_cnt (state , hdr_slot_idx , fap , & img_security_cnt );
1219
1190
if (rc != 0 ) {
@@ -1226,7 +1197,6 @@ boot_update_security_counter(struct boot_loader_state *state, int slot, int hdr_
1226
1197
}
1227
1198
1228
1199
done :
1229
- flash_area_close (fap );
1230
1200
return rc ;
1231
1201
}
1232
1202
#endif /* MCUBOOT_HW_ROLLBACK_PROT */
@@ -1732,7 +1702,7 @@ boot_swap_image(struct boot_loader_state *state, struct boot_status *bs)
1732
1702
* in the trailer...
1733
1703
*/
1734
1704
1735
- rc = boot_find_status (image_index , & fap );
1705
+ fap = boot_find_status (state , image_index );
1736
1706
assert (fap != NULL );
1737
1707
rc = boot_read_swap_size (fap , & bs -> swap_size );
1738
1708
assert (rc == 0 );
@@ -2764,17 +2734,15 @@ print_loaded_images(struct boot_loader_state *state)
2764
2734
static int
2765
2735
boot_select_or_erase (struct boot_loader_state * state )
2766
2736
{
2767
- const struct flash_area * fap ;
2768
- int fa_id ;
2737
+ const struct flash_area * fap = NULL ;
2769
2738
int rc ;
2770
2739
uint32_t active_slot ;
2771
2740
struct boot_swap_state * active_swap_state ;
2772
2741
2773
2742
active_slot = state -> slot_usage [BOOT_CURR_IMG (state )].active_slot ;
2774
2743
2775
- fa_id = flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ), active_slot );
2776
- rc = flash_area_open (fa_id , & fap );
2777
- assert (rc == 0 );
2744
+ fap = BOOT_IMG_AREA (state , active_slot );
2745
+ assert (fap != NULL );
2778
2746
2779
2747
active_swap_state = & (state -> slot_usage [BOOT_CURR_IMG (state )].swap_state );
2780
2748
@@ -2795,7 +2763,6 @@ boot_select_or_erase(struct boot_loader_state *state)
2795
2763
rc = flash_area_erase (fap , 0 , flash_area_get_size (fap ));
2796
2764
assert (rc == 0 );
2797
2765
2798
- flash_area_close (fap );
2799
2766
rc = -1 ;
2800
2767
} else {
2801
2768
if (active_swap_state -> copy_done != BOOT_FLAG_SET ) {
@@ -2817,7 +2784,6 @@ boot_select_or_erase(struct boot_loader_state *state)
2817
2784
rc = 0 ;
2818
2785
}
2819
2786
}
2820
- flash_area_close (fap );
2821
2787
}
2822
2788
2823
2789
return rc ;
@@ -3200,8 +3166,7 @@ const struct image_max_size *boot_get_max_app_size(void)
3200
3166
uint32_t boot_get_state_secondary_offset (struct boot_loader_state * state ,
3201
3167
const struct flash_area * fap )
3202
3168
{
3203
- if (state != NULL && flash_area_id_from_multi_image_slot (BOOT_CURR_IMG (state ),
3204
- BOOT_SECONDARY_SLOT ) == fap -> fa_id ) {
3169
+ if (state != NULL && BOOT_IMG_AREA (state , BOOT_SECONDARY_SLOT ) == fap ) {
3205
3170
return state -> secondary_offset [BOOT_CURR_IMG (state )];
3206
3171
}
3207
3172
0 commit comments