Commit d13318a1 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

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: default avatarDavid Brown <david.brown@linaro.org>
parent 2b951c92
Loading
Loading
Loading
Loading
+5 −6
Changes for boot/bootutil/include/bootutil/image.h: 5 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ struct flash_area;
#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 @@ struct image_tlv_info {

/** 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 @@ int bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
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 @@ struct image_tlv_iter {

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
}
+1 −1
Changes for boot/bootutil/src/image_validate.c: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -212,7 +212,7 @@ bootutil_img_validate(struct enc_key_data *enc_state, int image_index,
{
    uint32_t off;
    uint16_t len;
    uint8_t type;
    uint16_t type;
    int sha256_valid = 0;
#ifdef EXPECTED_SIG_TLV
    int valid_signature = 0;
+2 −2
Changes for boot/bootutil/src/tlv.c: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -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 @@ bootutil_tlv_iter_begin(struct image_tlv_iter *it, const struct image_header *hd
 */
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;