boot: Change TLV tag to 16 bits
The current TLV tag is an unsigned 8-bit integer, that is stored with 8
bits of padding. As the TLV tag is defined to be little endian
(although the code doesn't properly handle this), we can use the 8 bits
of padding as the upper 8-bits, treating the TLV tag as a 16 bit value,
and all existing tags will operate as they did before.
Change the types used throughout the code to represent the TLV to a
`uint16_t`. Change the ANY tag type to `0xffff` instead of `0xff`.
This value is never stored, but will avoid conflicts with any future
allocated tags.
Signed-off-by: David Brown <david.brown@linaro.org>
diff --git a/boot/bootutil/include/bootutil/image.h b/boot/bootutil/include/bootutil/image.h
index 24c83b6..b8491f4 100644
--- a/boot/bootutil/include/bootutil/image.h
+++ b/boot/bootutil/include/bootutil/image.h
@@ -84,7 +84,7 @@
#define IMAGE_TLV_ENC_KW128 0x31 /* Key encrypted with AES-KW-128 */
#define IMAGE_TLV_ENC_EC256 0x32 /* Key encrypted with ECIES-EC256 */
#define IMAGE_TLV_DEPENDENCY 0x40 /* Image depends on other image */
-#define IMAGE_TLV_ANY 0xff /* Used to iterate over all TLV */
+#define IMAGE_TLV_ANY 0xffff /* Used to iterate over all TLV */
struct image_version {
uint8_t iv_major;
@@ -123,8 +123,7 @@
/** Image trailer TLV format. All fields in little endian. */
struct image_tlv {
- uint8_t it_type; /* IMAGE_TLV_[...]. */
- uint8_t _pad;
+ uint16_t it_type; /* IMAGE_TLV_[...]. */
uint16_t it_len; /* Data length (not including TLV header). */
};
@@ -150,7 +149,7 @@
struct image_tlv_iter {
const struct image_header *hdr;
const struct flash_area *fap;
- uint8_t type;
+ uint16_t type;
bool prot;
uint32_t prot_end;
uint32_t tlv_off;
@@ -159,10 +158,10 @@
int bootutil_tlv_iter_begin(struct image_tlv_iter *it,
const struct image_header *hdr,
- const struct flash_area *fap, uint8_t type,
+ const struct flash_area *fap, uint16_t type,
bool prot);
int bootutil_tlv_iter_next(struct image_tlv_iter *it, uint32_t *off,
- uint16_t *len, uint8_t *type);
+ uint16_t *len, uint16_t *type);
#ifdef __cplusplus
}
diff --git a/boot/bootutil/src/image_validate.c b/boot/bootutil/src/image_validate.c
index 9fbd88f..2fea71d 100644
--- a/boot/bootutil/src/image_validate.c
+++ b/boot/bootutil/src/image_validate.c
@@ -212,7 +212,7 @@
{
uint32_t off;
uint16_t len;
- uint8_t type;
+ uint16_t type;
int sha256_valid = 0;
#ifdef EXPECTED_SIG_TLV
int valid_signature = 0;
diff --git a/boot/bootutil/src/tlv.c b/boot/bootutil/src/tlv.c
index bf6aebd..1bf1cbf 100644
--- a/boot/bootutil/src/tlv.c
+++ b/boot/bootutil/src/tlv.c
@@ -34,7 +34,7 @@
*/
int
bootutil_tlv_iter_begin(struct image_tlv_iter *it, const struct image_header *hdr,
- const struct flash_area *fap, uint8_t type, bool prot)
+ const struct flash_area *fap, uint16_t type, bool prot)
{
uint32_t off_;
struct image_tlv_info info;
@@ -89,7 +89,7 @@
*/
int
bootutil_tlv_iter_next(struct image_tlv_iter *it, uint32_t *off, uint16_t *len,
- uint8_t *type)
+ uint16_t *type)
{
struct image_tlv tlv;
int rc;