Skip to content

Commit 91d86b8

Browse files
committed
bootutil: Add compressed image flags and TLV
Adds some flags to indicate if the data of an image is compressed (lzma1 and lzma2) and adds new TLVs for compressed images relating to the hash, signature and size of the decompressed image data, this allows the image to be validated before decompressing, then validated after decompression to ensure an image is always valid for a device Signed-off-by: Jamie McCrae <[email protected]>
1 parent bf13555 commit 91d86b8

File tree

1 file changed

+25
-0
lines changed
  • boot/bootutil/include/bootutil

1 file changed

+25
-0
lines changed

boot/bootutil/include/bootutil/image.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ struct flash_area;
7171
*/
7272
#define IMAGE_F_ROM_FIXED 0x00000100
7373

74+
/*
75+
* Flags that indicate if the image data is compressed
76+
*/
77+
#define IMAGE_F_COMPRESSED_LZMA1 0x00000200
78+
#define IMAGE_F_COMPRESSED_LZMA2 0x00000400
79+
#define IMAGE_F_COMPRESSED_ARM_THUMB_FLT 0x00000800
80+
7481
/*
7582
* ECSDA224 is with NIST P-224
7683
* ECSDA256 is with NIST P-256
@@ -101,6 +108,18 @@ struct flash_area;
101108
#define IMAGE_TLV_DEPENDENCY 0x40 /* Image depends on other image */
102109
#define IMAGE_TLV_SEC_CNT 0x50 /* security counter */
103110
#define IMAGE_TLV_BOOT_RECORD 0x60 /* measured boot record */
111+
/* The following flags relate to compressed images and are for the decompressed image data */
112+
#define IMAGE_TLV_DECOMP_SIZE 0x70 /* Decompressed image size excluding header/TLVs */
113+
#define IMAGE_TLV_DECOMP_SHA 0x71 /*
114+
* Decompressed image shaX hash, this field must match
115+
* the format and size of the raw slot (compressed)
116+
* shaX hash
117+
*/
118+
#define IMAGE_TLV_DECOMP_SIGNATURE 0x72 /*
119+
* Decompressed image signature, this field must match
120+
* the format and size of the raw slot (compressed)
121+
* signature
122+
*/
104123
/*
105124
* vendor reserved TLVs at xxA0-xxFF,
106125
* where xx denotes the upper byte
@@ -160,6 +179,12 @@ struct image_tlv {
160179
#define MUST_DECRYPT(fap, idx, hdr) \
161180
(flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(idx) && IS_ENCRYPTED(hdr))
162181

182+
#define COMPRESSIONFLAGS (IMAGE_F_COMPRESSED_LZMA1 | IMAGE_F_COMPRESSED_LZMA2 \
183+
| IMAGE_F_COMPRESSED_ARM_THUMB_FLT)
184+
#define IS_COMPRESSED(hdr) ((hdr)->ih_flags & COMPRESSIONFLAGS)
185+
#define MUST_DECOMPRESS(fap, idx, hdr) \
186+
(flash_area_get_id(fap) == FLASH_AREA_IMAGE_SECONDARY(idx) && IS_COMPRESSED(hdr))
187+
163188
_Static_assert(sizeof(struct image_header) == IMAGE_HEADER_SIZE,
164189
"struct image_header not required size");
165190

0 commit comments

Comments
 (0)