@@ -69,6 +69,51 @@ struct AvbFooter {
6969 uint8_t reserved[28 ];
7070} __attribute__((packed));
7171
72+ // https://android.googlesource.com/platform/external/avb/+/refs/heads/android11-release/libavb/avb_descriptor.h
73+ enum AvbDescriptorTag : uint64_t {
74+ AVB_DESCRIPTOR_TAG_PROPERTY = 0 ,
75+ AVB_DESCRIPTOR_TAG_HASHTREE = 1 ,
76+ AVB_DESCRIPTOR_TAG_HASH = 2 ,
77+ AVB_DESCRIPTOR_TAG_KERNEL_CMDLINE = 3 ,
78+ AVB_DESCRIPTOR_TAG_CHAIN_PARTITION = 4 ,
79+ };
80+
81+ struct AvbDescriptor {
82+ uint64_t tag;
83+ uint64_t num_bytes; // size of descriptor body (excludes this header)
84+ } __attribute__((packed));
85+
86+ struct AvbDescriptorIterator {
87+ AvbDescriptor *ptr;
88+ AvbDescriptor &operator *() const { return *ptr; }
89+ AvbDescriptor *operator ->() const { return ptr; }
90+ bool operator !=(const AvbDescriptorIterator &o) const { return ptr != o.ptr ; }
91+ AvbDescriptorIterator &operator ++() {
92+ ptr = reinterpret_cast <AvbDescriptor *>(
93+ reinterpret_cast <uint8_t *>(ptr) + sizeof (AvbDescriptor) + __builtin_bswap64 (ptr->num_bytes ));
94+ return *this ;
95+ }
96+ };
97+
98+ struct AvbDescriptorRange {
99+ AvbDescriptor *first, *last;
100+ AvbDescriptorIterator begin () const { return {first}; }
101+ AvbDescriptorIterator end () const { return {last}; }
102+ };
103+
104+ // https://android.googlesource.com/platform/external/avb/+/refs/heads/android11-release/libavb/avb_hash_descriptor.h
105+ struct AvbHashDescriptor {
106+ AvbDescriptor header; // tag == 2
107+ uint64_t image_size;
108+ uint8_t hash_algorithm[32 ];
109+ uint32_t partition_name_len;
110+ uint32_t salt_len;
111+ uint32_t digest_len;
112+ uint32_t flags;
113+ uint8_t reserved[60 ];
114+ // followed by: partition_name, salt, digest (variable length)
115+ } __attribute__((packed));
116+
72117// https://android.googlesource.com/platform/external/avb/+/refs/heads/android11-release/libavb/avb_vbmeta_image.h
73118struct AvbVBMetaImageHeader {
74119 uint8_t magic[AVB_MAGIC_LEN];
@@ -92,6 +137,15 @@ struct AvbVBMetaImageHeader {
92137 uint32_t rollback_index_location;
93138 uint8_t release_string[AVB_RELEASE_STRING_SIZE];
94139 uint8_t reserved[80 ];
140+
141+ AvbDescriptorRange descriptors () const {
142+ auto *base = reinterpret_cast <const uint8_t *>(this ) + sizeof (AvbVBMetaImageHeader);
143+ base += __builtin_bswap64 (authentication_data_block_size);
144+ base += __builtin_bswap64 (descriptors_offset);
145+ auto *first = reinterpret_cast <AvbDescriptor *>(const_cast <uint8_t *>(base));
146+ auto *last = reinterpret_cast <AvbDescriptor *>(const_cast <uint8_t *>(base) + __builtin_bswap64 (descriptors_size));
147+ return {first, last};
148+ }
95149} __attribute__((packed));
96150
97151/* ********************
0 commit comments