Skip to content

Commit 21e614f

Browse files
committed
Revert "[nrf noup] zephyr: Add support for compressed image updates"
This reverts commit 898b9bc. Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent e44a698 commit 21e614f

File tree

7 files changed

+24
-1929
lines changed

7 files changed

+24
-1929
lines changed

boot/bootutil/src/bootutil_misc.c

Lines changed: 17 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747
#include "swap_priv.h"
4848
#endif
4949

50-
#if defined(MCUBOOT_DECOMPRESS_IMAGES)
51-
#include <nrf_compress/implementation.h>
52-
#include <compression/decompression.h>
53-
#endif
54-
5550
BOOT_LOG_MODULE_DECLARE(mcuboot);
5651

5752
/* Currently only used by imgmgr */
@@ -487,76 +482,35 @@ boot_read_image_size(struct boot_loader_state *state, int slot, uint32_t *size)
487482
fap = BOOT_IMG_AREA(state, slot);
488483
assert(fap != NULL);
489484

490-
#ifdef MCUBOOT_DECOMPRESS_IMAGES
491-
if (MUST_DECOMPRESS(fap, BOOT_CURR_IMG(state), boot_img_hdr(state, slot))) {
492-
uint32_t tmp_size = 0;
493-
494-
rc = bootutil_get_img_decomp_size(boot_img_hdr(state, slot), fap, &tmp_size);
495-
496-
if (rc) {
497-
rc = BOOT_EBADIMAGE;
498-
goto done;
499-
}
500-
501-
off = boot_img_hdr(state, slot)->ih_hdr_size + tmp_size;
502-
503-
rc = boot_size_protected_tlvs(boot_img_hdr(state, slot), fap, &tmp_size);
485+
off = BOOT_TLV_OFF(boot_img_hdr(state, slot));
504486

505-
if (rc) {
506-
rc = BOOT_EBADIMAGE;
507-
goto done;
508-
}
509-
510-
off += tmp_size;
511-
512-
if (flash_area_read(fap, (BOOT_TLV_OFF(boot_img_hdr(state, slot)) +
513-
boot_img_hdr(state, slot)->ih_protect_tlv_size), &info,
514-
sizeof(info))) {
515-
rc = BOOT_EFLASH;
516-
goto done;
517-
}
487+
if (flash_area_read(fap, off, &info, sizeof(info))) {
488+
rc = BOOT_EFLASH;
489+
goto done;
490+
}
518491

519-
if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
492+
protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
493+
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
494+
if (protect_tlv_size != info.it_tlv_tot) {
520495
rc = BOOT_EBADIMAGE;
521496
goto done;
522497
}
523498

524-
*size = off + info.it_tlv_tot;
525-
} else {
526-
#else
527-
if (1) {
528-
#endif
529-
off = BOOT_TLV_OFF(boot_img_hdr(state, slot));
530-
531-
if (flash_area_read(fap, off, &info, sizeof(info))) {
499+
if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
532500
rc = BOOT_EFLASH;
533501
goto done;
534502
}
503+
} else if (protect_tlv_size != 0) {
504+
rc = BOOT_EBADIMAGE;
505+
goto done;
506+
}
535507

536-
protect_tlv_size = boot_img_hdr(state, slot)->ih_protect_tlv_size;
537-
if (info.it_magic == IMAGE_TLV_PROT_INFO_MAGIC) {
538-
if (protect_tlv_size != info.it_tlv_tot) {
539-
rc = BOOT_EBADIMAGE;
540-
goto done;
541-
}
542-
543-
if (flash_area_read(fap, off + info.it_tlv_tot, &info, sizeof(info))) {
544-
rc = BOOT_EFLASH;
545-
goto done;
546-
}
547-
} else if (protect_tlv_size != 0) {
548-
rc = BOOT_EBADIMAGE;
549-
goto done;
550-
}
551-
552-
if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
553-
rc = BOOT_EBADIMAGE;
554-
goto done;
555-
}
556-
557-
*size = off + protect_tlv_size + info.it_tlv_tot;
508+
if (info.it_magic != IMAGE_TLV_INFO_MAGIC) {
509+
rc = BOOT_EBADIMAGE;
510+
goto done;
558511
}
559512

513+
*size = off + protect_tlv_size + info.it_tlv_tot;
560514
rc = 0;
561515

562516
done:

boot/bootutil/src/image_validate.c

Lines changed: 1 addition & 222 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@
4545

4646
BOOT_LOG_MODULE_DECLARE(mcuboot);
4747

48-
#if defined(MCUBOOT_DECOMPRESS_IMAGES)
49-
#include <nrf_compress/implementation.h>
50-
#include <compression/decompression.h>
51-
#endif
52-
5348
#ifdef MCUBOOT_ENC_IMAGES
5449
#include "bootutil/enc_key.h"
5550
#endif
@@ -512,7 +507,7 @@ bootutil_img_validate(struct boot_loader_state *state,
512507
#endif
513508
)
514509
{
515-
#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || defined(MCUBOOT_HW_ROLLBACK_PROT) || defined(MCUBOOT_DECOMPRESS_IMAGES)
510+
#if (defined(EXPECTED_KEY_TLV) && defined(MCUBOOT_HW_KEY)) || defined(MCUBOOT_HW_ROLLBACK_PROT)
516511
int image_index = (state == NULL ? 0 : BOOT_CURR_IMG(state));
517512
#endif
518513
uint32_t off;
@@ -560,67 +555,6 @@ bootutil_img_validate(struct boot_loader_state *state,
560555
#endif
561556

562557
BOOT_LOG_DBG("bootutil_img_validate: flash area %p", fap);
563-
#ifdef MCUBOOT_DECOMPRESS_IMAGES
564-
/* If the image is compressed, the integrity of the image must also be validated */
565-
if (MUST_DECOMPRESS(fap, image_index, hdr)) {
566-
bool found_decompressed_size = false;
567-
bool found_decompressed_sha = false;
568-
bool found_decompressed_signature = false;
569-
570-
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_ANY, true);
571-
if (rc) {
572-
goto out;
573-
}
574-
575-
if (it.tlv_end > bootutil_max_image_size(state, fap)) {
576-
rc = -1;
577-
goto out;
578-
}
579-
580-
while (true) {
581-
uint16_t expected_size = 0;
582-
bool *found_flag = NULL;
583-
584-
rc = bootutil_tlv_iter_next(&it, &off, &len, &type);
585-
if (rc < 0) {
586-
goto out;
587-
} else if (rc > 0) {
588-
break;
589-
}
590-
591-
switch (type) {
592-
case IMAGE_TLV_DECOMP_SIZE:
593-
expected_size = sizeof(size_t);
594-
found_flag = &found_decompressed_size;
595-
break;
596-
case IMAGE_TLV_DECOMP_SHA:
597-
expected_size = IMAGE_HASH_SIZE;
598-
found_flag = &found_decompressed_sha;
599-
break;
600-
case IMAGE_TLV_DECOMP_SIGNATURE:
601-
found_flag = &found_decompressed_signature;
602-
break;
603-
default:
604-
continue;
605-
};
606-
607-
if (type == IMAGE_TLV_DECOMP_SIGNATURE && !EXPECTED_SIG_LEN(len)) {
608-
rc = -1;
609-
goto out;
610-
} else if (type != IMAGE_TLV_DECOMP_SIGNATURE && len != expected_size) {
611-
rc = -1;
612-
goto out;
613-
}
614-
615-
*found_flag = true;
616-
}
617-
618-
rc = (!found_decompressed_size || !found_decompressed_sha || !found_decompressed_signature);
619-
if (rc) {
620-
goto out;
621-
}
622-
}
623-
#endif
624558

625559
#if defined(EXPECTED_HASH_TLV) && !defined(MCUBOOT_SIGN_PURE)
626560
#if defined(MCUBOOT_SWAP_USING_OFFSET) && defined(MCUBOOT_SERIAL_RECOVERY)
@@ -887,161 +821,6 @@ bootutil_img_validate(struct boot_loader_state *state,
887821
skip_security_counter_check:
888822
#endif
889823

890-
#ifdef MCUBOOT_DECOMPRESS_IMAGES
891-
/* Only after all previous verifications have passed, perform a dry-run of the decompression
892-
* and ensure the image is valid
893-
*/
894-
if (!rc && MUST_DECOMPRESS(fap, image_index, hdr)) {
895-
image_hash_valid = 0;
896-
FIH_SET(valid_signature, FIH_FAILURE);
897-
898-
rc = bootutil_img_hash_decompress(state, hdr, fap, tmp_buf, tmp_buf_sz,
899-
hash, seed, seed_len);
900-
if (rc) {
901-
goto out;
902-
}
903-
904-
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_DECOMP_SHA, true);
905-
if (rc) {
906-
goto out;
907-
}
908-
909-
if (it.tlv_end > bootutil_max_image_size(state, fap)) {
910-
rc = -1;
911-
goto out;
912-
}
913-
914-
while (true) {
915-
rc = bootutil_tlv_iter_next(&it, &off, &len, &type);
916-
if (rc < 0) {
917-
goto out;
918-
} else if (rc > 0) {
919-
break;
920-
}
921-
922-
if (type == IMAGE_TLV_DECOMP_SHA) {
923-
/* Verify the image hash. This must always be present. */
924-
if (len != sizeof(hash)) {
925-
rc = -1;
926-
goto out;
927-
}
928-
rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, sizeof(hash));
929-
if (rc) {
930-
goto out;
931-
}
932-
933-
FIH_CALL(boot_fih_memequal, fih_rc, hash, buf, sizeof(hash));
934-
if (FIH_NOT_EQ(fih_rc, FIH_SUCCESS)) {
935-
FIH_SET(fih_rc, FIH_FAILURE);
936-
goto out;
937-
}
938-
939-
image_hash_valid = 1;
940-
}
941-
}
942-
943-
rc = !image_hash_valid;
944-
if (rc) {
945-
goto out;
946-
}
947-
948-
#ifdef EXPECTED_SIG_TLV
949-
#ifdef EXPECTED_KEY_TLV
950-
rc = bootutil_tlv_iter_begin(&it, hdr, fap, EXPECTED_KEY_TLV, false);
951-
if (rc) {
952-
goto out;
953-
}
954-
955-
if (it.tlv_end > bootutil_max_image_size(state, fap)) {
956-
rc = -1;
957-
goto out;
958-
}
959-
960-
while (true) {
961-
rc = bootutil_tlv_iter_next(&it, &off, &len, &type);
962-
if (rc < 0) {
963-
goto out;
964-
} else if (rc > 0) {
965-
break;
966-
}
967-
968-
if (type == EXPECTED_KEY_TLV) {
969-
/*
970-
* Determine which key we should be checking.
971-
*/
972-
if (len > KEY_BUF_SIZE) {
973-
rc = -1;
974-
goto out;
975-
}
976-
#ifndef MCUBOOT_HW_KEY
977-
rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len);
978-
if (rc) {
979-
goto out;
980-
}
981-
key_id = bootutil_find_key(buf, len);
982-
#else
983-
rc = LOAD_IMAGE_DATA(hdr, fap, off, key_buf, len);
984-
if (rc) {
985-
goto out;
986-
}
987-
key_id = bootutil_find_key(image_index, key_buf, len);
988-
#endif /* !MCUBOOT_HW_KEY */
989-
/*
990-
* The key may not be found, which is acceptable. There
991-
* can be multiple signatures, each preceded by a key.
992-
*/
993-
}
994-
}
995-
#endif /* EXPECTED_KEY_TLV */
996-
997-
rc = bootutil_tlv_iter_begin(&it, hdr, fap, IMAGE_TLV_DECOMP_SIGNATURE, true);
998-
if (rc) {
999-
goto out;
1000-
}
1001-
1002-
if (it.tlv_end > bootutil_max_image_size(state, fap)) {
1003-
rc = -1;
1004-
goto out;
1005-
}
1006-
1007-
while (true) {
1008-
rc = bootutil_tlv_iter_next(&it, &off, &len, &type);
1009-
if (rc < 0) {
1010-
goto out;
1011-
} else if (rc > 0) {
1012-
rc = 0;
1013-
break;
1014-
}
1015-
1016-
if (type == IMAGE_TLV_DECOMP_SIGNATURE) {
1017-
/* Ignore this signature if it is out of bounds. */
1018-
if (key_id < 0 || key_id >= bootutil_key_cnt) {
1019-
key_id = -1;
1020-
continue;
1021-
}
1022-
1023-
if (!EXPECTED_SIG_LEN(len) || len > sizeof(buf)) {
1024-
rc = -1;
1025-
goto out;
1026-
}
1027-
rc = LOAD_IMAGE_DATA(hdr, fap, off, buf, len);
1028-
if (rc) {
1029-
goto out;
1030-
}
1031-
1032-
FIH_CALL(bootutil_verify_sig, valid_signature, hash, sizeof(hash),
1033-
buf, len, key_id);
1034-
key_id = -1;
1035-
}
1036-
}
1037-
#endif /* EXPECTED_SIG_TLV */
1038-
}
1039-
#endif
1040-
1041-
#ifdef EXPECTED_SIG_TLV
1042-
FIH_SET(fih_rc, valid_signature);
1043-
#endif
1044-
1045824
out:
1046825
if (rc) {
1047826
FIH_SET(fih_rc, FIH_FAILURE);

0 commit comments

Comments
 (0)