Lines Matching refs:state
116 boot_read_image_headers(struct boot_loader_state *state, bool require_all, in boot_read_image_headers() argument
124 BOOT_CURR_IMG(state), i, boot_img_hdr(state, i)); in boot_read_image_headers()
127 rc = boot_read_image_header(state, i, boot_img_hdr(state, i), bs); in boot_read_image_headers()
156 boot_add_shared_data(struct boot_loader_state *state, in boot_add_shared_data() argument
163 rc = boot_save_boot_status(BOOT_CURR_IMG(state), in boot_add_shared_data()
164 boot_img_hdr(state, active_slot), in boot_add_shared_data()
165 BOOT_IMG_AREA(state, active_slot)); in boot_add_shared_data()
173 rc = boot_save_shared_data(boot_img_hdr(state, active_slot), in boot_add_shared_data()
174 BOOT_IMG_AREA(state, active_slot), in boot_add_shared_data()
185 (void) (state); in boot_add_shared_data()
199 fill_rsp(struct boot_loader_state *state, struct boot_rsp *rsp) in fill_rsp() argument
205 BOOT_CURR_IMG(state) = 0; in fill_rsp()
206 IMAGES_ITER(BOOT_CURR_IMG(state)) { in fill_rsp()
207 if (!state->img_mask[BOOT_CURR_IMG(state)]) { in fill_rsp()
212 if (BOOT_CURR_IMG(state) >= BOOT_IMAGE_NUMBER) { in fill_rsp()
218 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot; in fill_rsp()
223 rsp->br_flash_dev_id = flash_area_get_device_id(BOOT_IMG_AREA(state, active_slot)); in fill_rsp()
224 rsp->br_image_off = boot_img_slot_off(state, active_slot); in fill_rsp()
225 rsp->br_hdr = boot_img_hdr(state, active_slot); in fill_rsp()
234 close_all_flash_areas(struct boot_loader_state *state) in close_all_flash_areas() argument
238 IMAGES_ITER(BOOT_CURR_IMG(state)) { in close_all_flash_areas()
240 if (state->img_mask[BOOT_CURR_IMG(state)]) { in close_all_flash_areas()
245 flash_area_close(BOOT_SCRATCH_AREA(state)); in close_all_flash_areas()
248 flash_area_close(BOOT_IMG_AREA(state, BOOT_NUM_SLOTS - 1 - slot)); in close_all_flash_areas()
312 boot_initialize_area(struct boot_loader_state *state, int flash_area) in boot_initialize_area() argument
321 if (flash_area == FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state))) { in boot_initialize_area()
322 out_sectors = BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors; in boot_initialize_area()
323 out_num_sectors = &BOOT_IMG(state, BOOT_PRIMARY_SLOT).num_sectors; in boot_initialize_area()
324 } else if (flash_area == FLASH_AREA_IMAGE_SECONDARY(BOOT_CURR_IMG(state))) { in boot_initialize_area()
325 out_sectors = BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors; in boot_initialize_area()
326 out_num_sectors = &BOOT_IMG(state, BOOT_SECONDARY_SLOT).num_sectors; in boot_initialize_area()
329 out_sectors = state->scratch.sectors; in boot_initialize_area()
330 out_num_sectors = &state->scratch.num_sectors; in boot_initialize_area()
352 boot_read_sectors_recovery(struct boot_loader_state *state) in boot_read_sectors_recovery() argument
357 image_index = BOOT_CURR_IMG(state); in boot_read_sectors_recovery()
359 rc = boot_initialize_area(state, FLASH_AREA_IMAGE_PRIMARY(image_index)); in boot_read_sectors_recovery()
364 rc = boot_initialize_area(state, FLASH_AREA_IMAGE_SECONDARY(image_index)); in boot_read_sectors_recovery()
378 boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot);
389 boot_verify_slot_dependency(struct boot_loader_state *state, in boot_verify_slot_dependency() argument
399 uint8_t swap_type = state->swap_type[dep->image_id]; in boot_verify_slot_dependency()
403 dep_slot = state->slot_usage[dep->image_id].active_slot; in boot_verify_slot_dependency()
406 dep_version = &state->imgs[dep->image_id][dep_slot].hdr.ih_ver; in boot_verify_slot_dependency()
417 switch (BOOT_SWAP_TYPE(state)) { in boot_verify_slot_dependency()
420 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE; in boot_verify_slot_dependency()
423 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_REVERT; in boot_verify_slot_dependency()
448 boot_verify_dependencies(struct boot_loader_state *state) in boot_verify_dependencies() argument
453 BOOT_CURR_IMG(state) = 0; in boot_verify_dependencies()
454 while (BOOT_CURR_IMG(state) < BOOT_IMAGE_NUMBER) { in boot_verify_dependencies()
455 if (state->img_mask[BOOT_CURR_IMG(state)]) { in boot_verify_dependencies()
456 BOOT_CURR_IMG(state)++; in boot_verify_dependencies()
459 if (BOOT_SWAP_TYPE(state) != BOOT_SWAP_TYPE_NONE && in boot_verify_dependencies()
460 BOOT_SWAP_TYPE(state) != BOOT_SWAP_TYPE_FAIL) { in boot_verify_dependencies()
466 rc = boot_verify_slot_dependencies(state, slot); in boot_verify_dependencies()
469 BOOT_CURR_IMG(state)++; in boot_verify_dependencies()
475 BOOT_CURR_IMG(state) = idx; in boot_verify_dependencies()
476 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE; in boot_verify_dependencies()
487 boot_remove_image_from_sram(struct boot_loader_state *state);
500 boot_verify_dependencies(struct boot_loader_state *state) in boot_verify_dependencies() argument
505 IMAGES_ITER(BOOT_CURR_IMG(state)) { in boot_verify_dependencies()
506 if (state->img_mask[BOOT_CURR_IMG(state)]) { in boot_verify_dependencies()
509 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot; in boot_verify_dependencies()
510 rc = boot_verify_slot_dependencies(state, active_slot); in boot_verify_dependencies()
515 boot_remove_image_from_sram(state); in boot_verify_dependencies()
518 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false; in boot_verify_dependencies()
519 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT; in boot_verify_dependencies()
538 boot_verify_slot_dependencies(struct boot_loader_state *state, uint32_t slot) in boot_verify_slot_dependencies() argument
548 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot); in boot_verify_slot_dependencies()
555 rc = bootutil_tlv_iter_begin(&it, boot_img_hdr(state, slot), fap, in boot_verify_slot_dependencies()
575 rc = LOAD_IMAGE_DATA(boot_img_hdr(state, slot), in boot_verify_slot_dependencies()
588 rc = boot_verify_slot_dependency(state, &dep); in boot_verify_slot_dependencies()
609 boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size) in boot_read_image_size() argument
619 (void)state; in boot_read_image_size()
622 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot); in boot_read_image_size()
629 off = BOOT_TLV_OFF(boot_img_hdr(state, slot)); in boot_read_image_size()
636 protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size; in boot_read_image_size()
668 boot_write_sz(struct boot_loader_state *state) in boot_write_sz() argument
679 elem_sz = flash_area_align(BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT)); in boot_write_sz()
681 align = flash_area_align(BOOT_SCRATCH_AREA(state)); in boot_write_sz()
697 boot_read_sectors(struct boot_loader_state *state) in boot_read_sectors() argument
702 image_index = BOOT_CURR_IMG(state); in boot_read_sectors()
704 rc = boot_initialize_area(state, FLASH_AREA_IMAGE_PRIMARY(image_index)); in boot_read_sectors()
709 rc = boot_initialize_area(state, FLASH_AREA_IMAGE_SECONDARY(image_index)); in boot_read_sectors()
716 rc = boot_initialize_area(state, FLASH_AREA_IMAGE_SCRATCH); in boot_read_sectors()
722 BOOT_WRITE_SZ(state) = boot_write_sz(state); in boot_read_sectors()
743 bs->state = BOOT_STATUS_STATE_0; in boot_status_reset()
752 bs->state == BOOT_STATUS_STATE_0); in boot_status_is_reset()
764 boot_write_status(const struct boot_loader_state *state, struct boot_status *bs) in boot_write_status() argument
787 area_id = FLASH_AREA_IMAGE_PRIMARY(BOOT_CURR_IMG(state)); in boot_write_status()
798 boot_status_internal_off(bs, BOOT_WRITE_SZ(state)); in boot_write_status()
802 buf[0] = bs->state; in boot_write_status()
824 boot_image_check(struct boot_loader_state *state, struct image_header *hdr, in boot_image_check() argument
832 (void)state; in boot_image_check()
841 if (MUST_DECRYPT(fap, BOOT_CURR_IMG(state), hdr)) { in boot_image_check()
842 rc = boot_enc_load(BOOT_CURR_ENC(state), 1, hdr, fap, bs); in boot_image_check()
846 if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs)) { in boot_image_check()
852 FIH_CALL(bootutil_img_validate, fih_rc, BOOT_CURR_ENC(state), in boot_image_check()
853 BOOT_CURR_IMG(state), hdr, fap, tmpbuf, BOOT_TMPBUF_SZ, in boot_image_check()
901 struct boot_loader_state *state) argument
905 (void)state;
916 if (!MUST_DECOMPRESS(fap, BOOT_CURR_IMG(state), hdr)) {
973 boot_check_header_erased(struct boot_loader_state *state, int slot) argument
981 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
990 hdr = boot_img_hdr(state, slot);
1010 boot_rom_address_check(struct boot_loader_state *state) argument
1016 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
1017 hdr = boot_img_hdr(state, active_slot);
1018 f_off = boot_img_slot_off(state, active_slot);
1044 boot_validate_slot(struct boot_loader_state *state, int slot, argument
1053 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
1059 hdr = boot_img_hdr(state, slot);
1060 if (boot_check_header_erased(state, slot) == 0 ||
1075 swap_erase_trailer_sectors(state, fap);
1088 &boot_img_hdr(state, BOOT_SECONDARY_SLOT)->ih_ver,
1089 &boot_img_hdr(state, BOOT_PRIMARY_SLOT)->ih_ver);
1090 if (rc < 0 && boot_check_header_erased(state, BOOT_PRIMARY_SLOT)) {
1101 if (!boot_is_header_valid(hdr, fap, state)) {
1105 fih_rc, BOOT_CURR_IMG(state), slot);
1107 FIH_CALL(boot_image_check, fih_rc, state, hdr, fap, bs);
1131 if (area_id == FLASH_AREA_IMAGE_SECONDARY(BOOT_CURR_IMG(state))) {
1132 const struct flash_area *pri_fa = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
1133 struct image_header *secondary_hdr = boot_img_hdr(state, slot);
1221 boot_validated_swap_type(struct boot_loader_state *state, argument
1227 swap_type = boot_swap_type_multi(BOOT_CURR_IMG(state));
1232 FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_SECONDARY_SLOT, bs);
1293 boot_copy_region(struct boot_loader_state *state, argument
1308 uint8_t image_index = BOOT_CURR_IMG(state);
1321 (void)state;
1333 hdr = boot_img_hdr(state, BOOT_PRIMARY_SLOT);
1337 hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
1395 boot_enc_encrypt(BOOT_CURR_ENC(state), source_slot,
1399 boot_enc_decrypt(BOOT_CURR_ENC(state), source_slot,
1435 boot_copy_image(struct boot_loader_state *state, struct boot_status *bs) argument
1458 rc = boot_read_image_size(state, BOOT_SECONDARY_SLOT, &src_size);
1462 image_index = BOOT_CURR_IMG(state);
1475 sect_count = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT);
1477 this_size = boot_img_sector_size(state, BOOT_PRIMARY_SLOT, sect);
1484 size += BOOT_WRITE_SZ(state) - (size % BOOT_WRITE_SZ(state));
1493 trailer_sz = boot_trailer_sz(BOOT_WRITE_SZ(state));
1494 sector = boot_img_num_sectors(state, BOOT_PRIMARY_SLOT) - 1;
1497 sz += boot_img_sector_size(state, BOOT_PRIMARY_SLOT, sector);
1498 off = boot_img_sector_off(state, BOOT_PRIMARY_SLOT, sector);
1507 if (IS_ENCRYPTED(boot_img_hdr(state, BOOT_SECONDARY_SLOT))) {
1508 rc = boot_enc_load(BOOT_CURR_ENC(state), BOOT_SECONDARY_SLOT,
1509 boot_img_hdr(state, BOOT_SECONDARY_SLOT),
1515 if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs)) {
1523 rc = boot_copy_region(state, fap_secondary_slot, fap_primary_slot, 0, 0, size);
1535 rc = BOOT_HOOK_CALL(boot_copy_region_post_hook, 0, BOOT_CURR_IMG(state),
1536 BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT), size);
1547 rc = boot_update_security_counter(BOOT_CURR_IMG(state), BOOT_PRIMARY_SLOT,
1548 boot_img_hdr(state, BOOT_SECONDARY_SLOT));
1563 boot_img_sector_off(state, BOOT_SECONDARY_SLOT, 0),
1564 boot_img_sector_size(state, BOOT_SECONDARY_SLOT, 0));
1568 last_sector = boot_img_num_sectors(state, BOOT_SECONDARY_SLOT) - 1;
1571 boot_img_sector_off(state, BOOT_SECONDARY_SLOT,
1573 boot_img_sector_size(state, BOOT_SECONDARY_SLOT,
1600 boot_swap_image(struct boot_loader_state *state, struct boot_status *bs) argument
1616 image_index = BOOT_CURR_IMG(state);
1623 hdr = boot_img_hdr(state, BOOT_PRIMARY_SLOT);
1625 rc = boot_read_image_size(state, BOOT_PRIMARY_SLOT, ©_size);
1631 fap = BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT);
1632 rc = boot_enc_load(BOOT_CURR_ENC(state), 0, hdr, fap, bs);
1636 rc = boot_enc_set_key(BOOT_CURR_ENC(state), 0, bs);
1646 hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
1648 rc = boot_read_image_size(state, BOOT_SECONDARY_SLOT, &size);
1653 hdr = boot_img_hdr(state, BOOT_SECONDARY_SLOT);
1655 fap = BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT);
1656 rc = boot_enc_load(BOOT_CURR_ENC(state), 1, hdr, fap, bs);
1660 rc = boot_enc_set_key(BOOT_CURR_ENC(state), 1, bs);
1699 boot_enc_init(BOOT_CURR_ENC(state), slot);
1702 boot_enc_set_key(BOOT_CURR_ENC(state), slot, bs);
1709 swap_run(state, bs, copy_size);
1718 rc = BOOT_HOOK_CALL(boot_copy_region_post_hook, 0, BOOT_CURR_IMG(state),
1719 BOOT_IMG_AREA(state, BOOT_PRIMARY_SLOT), size);
1734 boot_perform_update(struct boot_loader_state *state, struct boot_status *bs) argument
1743 rc = boot_copy_image(state, bs);
1750 rc = boot_check_header_erased(state, BOOT_PRIMARY_SLOT);
1751 FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, bs);
1753 rc = boot_copy_image(state, bs);
1755 rc = boot_swap_image(state, bs);
1758 rc = boot_swap_image(state, bs);
1766 swap_type = BOOT_SWAP_TYPE(state);
1769 rc = swap_set_image_ok(BOOT_CURR_IMG(state));
1771 BOOT_SWAP_TYPE(state) = swap_type = BOOT_SWAP_TYPE_PANIC;
1787 BOOT_CURR_IMG(state),
1789 boot_img_hdr(state, BOOT_SECONDARY_SLOT));
1793 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
1799 rc = swap_set_copy_done(BOOT_CURR_IMG(state));
1801 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
1818 boot_complete_partial_swap(struct boot_loader_state *state, argument
1826 rc = boot_swap_image(state, bs);
1829 BOOT_SWAP_TYPE(state) = bs->swap_type;
1836 rc = swap_set_image_ok(BOOT_CURR_IMG(state));
1838 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
1843 rc = swap_set_copy_done(BOOT_CURR_IMG(state));
1845 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
1849 if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_PANIC) {
1869 boot_review_image_swap_types(struct boot_loader_state *state, argument
1897 if (BOOT_CURR_IMG(state) == 0) {
1903 if ((BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_NONE) ||
1904 (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_REVERT)) {
1910 for (uint8_t i = 0; i < BOOT_CURR_IMG(state); i++) {
1911 if (state->swap_type[i] == BOOT_SWAP_TYPE_REVERT) {
1912 state->swap_type[i] = BOOT_SWAP_TYPE_NONE;
1930 boot_prepare_image_for_update(struct boot_loader_state *state, argument
1941 rc = boot_read_sectors(state);
1948 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
1957 rc = boot_read_image_headers(state, false, NULL);
1961 BOOT_CURR_IMG(state));
1962 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
1968 max_size = app_max_size(state);
1971 image_max_sizes[BOOT_CURR_IMG(state)].calculated = true;
1972 image_max_sizes[BOOT_CURR_IMG(state)].max_size = max_size;
1979 if (boot_slots_compatible(state)) {
1983 rc = swap_read_status(state, bs);
1986 BOOT_CURR_IMG(state));
1988 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
1998 rc = boot_read_image_headers(state, !boot_status_is_reset(bs), bs);
2001 if (rc != 0 && (BOOT_CURR_IMG(state) != BOOT_PRIMARY_SLOT ||
2002 boot_check_header_erased(state, BOOT_PRIMARY_SLOT) != 0)) {
2009 BOOT_CURR_IMG(state));
2010 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
2021 boot_review_image_swap_types(state, true);
2033 rc = boot_complete_partial_swap(state, bs);
2039 rc = boot_read_image_headers(state, false, bs);
2043 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
2047 BOOT_SWAP_TYPE(state) = boot_validated_swap_type(state, bs);
2050 state, BOOT_SECONDARY_SLOT, bs);
2052 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_FAIL;
2054 BOOT_SWAP_TYPE(state) = bs->swap_type;
2059 boot_review_image_swap_types(state, false);
2063 if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_NONE) {
2070 rc = boot_check_header_erased(state, BOOT_PRIMARY_SLOT);
2072 state, BOOT_PRIMARY_SLOT, bs);
2076 rc = (boot_img_hdr(state, BOOT_SECONDARY_SLOT)->ih_magic == IMAGE_MAGIC) ? 1: 0;
2078 state, BOOT_SECONDARY_SLOT, bs);
2086 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_REVERT;
2094 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
2106 boot_update_hw_rollback_protection(struct boot_loader_state *state) argument
2121 if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_NONE) {
2123 BOOT_CURR_IMG(state),
2125 boot_img_hdr(state, BOOT_PRIMARY_SLOT));
2136 (void) (state);
2153 check_downgrade_prevention(struct boot_loader_state *state) argument
2162 rc = bootutil_get_img_security_cnt(&(BOOT_IMG(state, 0).hdr),
2163 BOOT_IMG(state, 0).area,
2170 rc = bootutil_get_img_security_cnt(&(BOOT_IMG(state, 1).hdr),
2171 BOOT_IMG(state, 1).area,
2178 rc = boot_version_cmp(&boot_img_hdr(state, BOOT_SECONDARY_SLOT)->ih_ver,
2179 &boot_img_hdr(state, BOOT_PRIMARY_SLOT)->ih_ver);
2183 BOOT_LOG_INF("Image %d in slot 1 erased due to downgrade prevention", BOOT_CURR_IMG(state));
2184 flash_area_erase(BOOT_IMG(state, 1).area, 0,
2185 flash_area_get_size(BOOT_IMG(state, 1).area));
2191 (void)state;
2197 context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp) argument
2231 IMAGES_ITER(BOOT_CURR_IMG(state)) {
2233 if (state->img_mask[BOOT_CURR_IMG(state)]) {
2242 boot_enc_zeroize(BOOT_CURR_ENC(state));
2245 image_index = BOOT_CURR_IMG(state);
2248 BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors =
2250 BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors =
2253 state->scratch.sectors = sector_buffers.scratch;
2256 BOOT_IMG(state, BOOT_PRIMARY_SLOT).sectors =
2258 BOOT_IMG(state, BOOT_SECONDARY_SLOT).sectors =
2261 state->scratch.sectors = scratch_sectors;
2270 rc = flash_area_open(fa_id, &BOOT_IMG_AREA(state, slot));
2281 &BOOT_SCRATCH_AREA(state));
2291 boot_prepare_image_for_update(state, &bs);
2293 if (BOOT_IS_UPGRADE(BOOT_SWAP_TYPE(state))) {
2303 rc = boot_verify_dependencies(state);
2323 IMAGES_ITER(BOOT_CURR_IMG(state)) {
2325 if (state->img_mask[BOOT_CURR_IMG(state)]) {
2334 boot_enc_zeroize(BOOT_CURR_ENC(state));
2342 bs.swap_type = BOOT_SWAP_TYPE(state);
2344 switch (BOOT_SWAP_TYPE(state)) {
2351 if (check_downgrade_prevention(state) != 0) {
2353 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_NONE;
2359 BOOT_CURR_IMG(state), &(BOOT_IMG(state, 1).hdr),
2360 BOOT_IMG_AREA(state, BOOT_SECONDARY_SLOT));
2363 rc = boot_perform_update(state, &bs);
2375 rc = swap_set_image_ok(BOOT_CURR_IMG(state));
2377 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
2383 BOOT_SWAP_TYPE(state) = BOOT_SWAP_TYPE_PANIC;
2386 if (BOOT_SWAP_TYPE(state) == BOOT_SWAP_TYPE_PANIC) {
2400 IMAGES_ITER(BOOT_CURR_IMG(state)) {
2406 FIH_SET(tmp_img_mask, state->img_mask[BOOT_CURR_IMG(state)]);
2412 if (BOOT_SWAP_TYPE(state) != BOOT_SWAP_TYPE_NONE) {
2421 rc = boot_read_image_headers(state, false, NULL);
2434 FIH_CALL(boot_validate_slot, fih_rc, state, BOOT_PRIMARY_SLOT, NULL);
2449 if (BOOT_IMG(state, BOOT_PRIMARY_SLOT).hdr.ih_magic != IMAGE_MAGIC) {
2451 BOOT_IMG(state, BOOT_PRIMARY_SLOT).hdr.ih_magic,
2452 BOOT_CURR_IMG(state));
2459 rc = boot_update_hw_rollback_protection(state);
2465 rc = boot_add_shared_data(state, BOOT_PRIMARY_SLOT);
2481 fill_rsp(state, rsp);
2496 close_all_flash_areas(state);
2578 boot_get_slot_usage(struct boot_loader_state *state) argument
2585 IMAGES_ITER(BOOT_CURR_IMG(state)) {
2587 if (state->img_mask[BOOT_CURR_IMG(state)]) {
2594 BOOT_CURR_IMG(state), slot);
2595 rc = flash_area_open(fa_id, &BOOT_IMG_AREA(state, slot));
2600 rc = boot_read_image_headers(state, false, NULL);
2608 hdr = boot_img_hdr(state, slot);
2610 if (boot_is_header_valid(hdr, BOOT_IMG_AREA(state, slot), state)) {
2611 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = true;
2614 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot] = false;
2616 BOOT_CURR_IMG(state),
2622 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
2638 find_slot_with_highest_version(struct boot_loader_state *state) argument
2645 if (state->slot_usage[BOOT_CURR_IMG(state)].slot_available[slot]) {
2650 &boot_img_hdr(state, slot)->ih_ver,
2651 &boot_img_hdr(state, candidate_slot)->ih_ver);
2672 print_loaded_images(struct boot_loader_state *state) argument
2676 (void)state;
2678 IMAGES_ITER(BOOT_CURR_IMG(state)) {
2680 if (state->img_mask[BOOT_CURR_IMG(state)]) {
2684 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
2687 BOOT_CURR_IMG(state),
2705 boot_select_or_erase(struct boot_loader_state *state) argument
2713 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
2715 fa_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), active_slot);
2719 active_swap_state = &(state->slot_usage[BOOT_CURR_IMG(state)].swap_state);
2784 boot_verify_ram_load_address(struct boot_loader_state *state) argument
2792 (void)state;
2797 rc = boot_get_image_exec_ram_info(BOOT_CURR_IMG(state), &exec_ram_start,
2807 img_dst = state->slot_usage[BOOT_CURR_IMG(state)].img_dst;
2808 img_sz = state->slot_usage[BOOT_CURR_IMG(state)].img_sz;
2840 boot_decrypt_and_copy_image_to_sram(struct boot_loader_state *state, argument
2865 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
2879 rc = boot_enc_load(BOOT_CURR_ENC(state), slot, hdr, fap_src, &bs);
2885 if (rc == 0 && boot_enc_set_key(BOOT_CURR_ENC(state), slot, &bs)) {
2906 boot_enc_decrypt(BOOT_CURR_ENC(state), slot,
2932 boot_copy_image_to_sram(struct boot_loader_state *state, int slot, argument
2940 (void)state;
2943 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
2954 BOOT_CURR_IMG(state), rc);
2997 boot_check_ram_load_overlapping(struct boot_loader_state *state) argument
3005 uint32_t image_id_to_check = BOOT_CURR_IMG(state);
3007 start_a = state->slot_usage[image_id_to_check].img_dst;
3010 end_a = start_a + state->slot_usage[image_id_to_check].img_sz;
3013 if (state->slot_usage[i].active_slot == NO_ACTIVE_SLOT
3018 start_b = state->slot_usage[i].img_dst;
3021 end_b = start_b + state->slot_usage[i].img_sz;
3041 boot_load_image_to_sram(struct boot_loader_state *state) argument
3049 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
3050 hdr = boot_img_hdr(state, active_slot);
3056 rc = boot_read_image_size(state, active_slot, &img_sz);
3061 state->slot_usage[BOOT_CURR_IMG(state)].img_dst = img_dst;
3062 state->slot_usage[BOOT_CURR_IMG(state)].img_sz = img_sz;
3064 rc = boot_verify_ram_load_address(state);
3066 … BOOT_LOG_INF("Image %d RAM load address 0x%x is invalid.", BOOT_CURR_IMG(state), img_dst);
3071 rc = boot_check_ram_load_overlapping(state);
3074 another image.", BOOT_CURR_IMG(state), img_dst);
3081 rc = boot_decrypt_and_copy_image_to_sram(state, active_slot, hdr, img_sz, img_dst);
3083 rc = boot_copy_image_to_sram(state, active_slot, img_dst, img_sz);
3089 rc = boot_copy_image_to_sram(state, active_slot, img_dst, img_sz);
3092 BOOT_LOG_INF("Image %d RAM loading to 0x%x is failed.", BOOT_CURR_IMG(state), img_dst);
3094 … BOOT_LOG_INF("Image %d RAM loading to 0x%x is succeeded.", BOOT_CURR_IMG(state), img_dst);
3104 state->slot_usage[BOOT_CURR_IMG(state)].img_dst = 0;
3105 state->slot_usage[BOOT_CURR_IMG(state)].img_sz = 0;
3119 boot_remove_image_from_sram(struct boot_loader_state *state) argument
3121 (void)state;
3124 BOOT_CURR_IMG(state),
3125 state->slot_usage[BOOT_CURR_IMG(state)].img_dst);
3127 memset((void*)(IMAGE_RAM_BASE + state->slot_usage[BOOT_CURR_IMG(state)].img_dst),
3128 0, state->slot_usage[BOOT_CURR_IMG(state)].img_sz);
3130 state->slot_usage[BOOT_CURR_IMG(state)].img_dst = 0;
3131 state->slot_usage[BOOT_CURR_IMG(state)].img_sz = 0;
3145 boot_remove_image_from_flash(struct boot_loader_state *state, uint32_t slot) argument
3151 (void)state;
3153 BOOT_LOG_INF("Removing image %d slot %d from flash", BOOT_CURR_IMG(state),
3155 area_id = flash_area_id_from_multi_image_slot(BOOT_CURR_IMG(state), slot);
3175 boot_load_and_validate_images(struct boot_loader_state *state) argument
3182 IMAGES_ITER(BOOT_CURR_IMG(state)) {
3188 active_slot = state->slot_usage[BOOT_CURR_IMG(state)].active_slot;
3194 active_slot = find_slot_with_highest_version(state);
3197 BOOT_CURR_IMG(state));
3202 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = active_slot;
3205 if (state->img_mask[BOOT_CURR_IMG(state)]) {
3211 rc = boot_rom_address_check(state);
3214 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
3215 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
3220 rc = boot_select_or_erase(state);
3223 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
3224 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
3236 rc = boot_load_image_to_sram(state);
3239 boot_remove_image_from_flash(state, active_slot);
3240 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
3241 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
3246 FIH_CALL(boot_validate_slot, fih_rc, state, active_slot, NULL);
3250 boot_remove_image_from_sram(state);
3252 state->slot_usage[BOOT_CURR_IMG(state)].slot_available[active_slot] = false;
3253 state->slot_usage[BOOT_CURR_IMG(state)].active_slot = NO_ACTIVE_SLOT;
3273 boot_update_hw_rollback_protection(struct boot_loader_state *state) argument
3287 if (state->slot_usage[BOOT_CURR_IMG(state)].swap_state.image_ok == BOOT_FLAG_SET) {
3289 rc = boot_update_security_counter(BOOT_CURR_IMG(state),
3290 state->slot_usage[BOOT_CURR_IMG(state)].active_slot,
3291 … boot_img_hdr(state, state->slot_usage[BOOT_CURR_IMG(state)].active_slot));
3293 … BOOT_LOG_ERR("Security counter update failed after image %d validation.", BOOT_CURR_IMG(state));
3303 (void) (state);
3309 context_boot_go(struct boot_loader_state *state, struct boot_rsp *rsp) argument
3314 rc = boot_get_slot_usage(state);
3322 FIH_CALL(boot_load_and_validate_images, fih_rc, state);
3329 rc = boot_verify_dependencies(state);
3342 IMAGES_ITER(BOOT_CURR_IMG(state)) {
3344 if (state->img_mask[BOOT_CURR_IMG(state)]) {
3348 rc = boot_update_hw_rollback_protection(state);
3354 … rc = boot_add_shared_data(state, (uint8_t)state->slot_usage[BOOT_CURR_IMG(state)].active_slot);
3363 print_loaded_images(state);
3366 fill_rsp(state, rsp);
3369 close_all_flash_areas(state);
3435 void boot_state_clear(struct boot_loader_state *state) argument
3437 if (state != NULL) {
3438 memset(state, 0, sizeof(struct boot_loader_state));