@@ -69,6 +69,33 @@ 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+ // https://android.googlesource.com/platform/external/avb/+/refs/heads/android11-release/libavb/avb_hash_descriptor.h
87+ struct AvbHashDescriptor {
88+ AvbDescriptor header; // tag == 2
89+ uint64_t image_size;
90+ uint8_t hash_algorithm[32 ];
91+ uint32_t partition_name_len;
92+ uint32_t salt_len;
93+ uint32_t digest_len;
94+ uint32_t flags;
95+ uint8_t reserved[60 ];
96+ // followed by: partition_name, salt, digest (variable length)
97+ } __attribute__((packed));
98+
7299// https://android.googlesource.com/platform/external/avb/+/refs/heads/android11-release/libavb/avb_vbmeta_image.h
73100struct AvbVBMetaImageHeader {
74101 uint8_t magic[AVB_MAGIC_LEN];
@@ -94,6 +121,33 @@ struct AvbVBMetaImageHeader {
94121 uint8_t reserved[80 ];
95122} __attribute__((packed));
96123
124+ struct AvbDescriptorIterator {
125+ AvbDescriptor *ptr;
126+ AvbDescriptor &operator *() const { return *ptr; }
127+ AvbDescriptor *operator ->() const { return ptr; }
128+ bool operator !=(const AvbDescriptorIterator &o) const { return ptr != o.ptr ; }
129+ AvbDescriptorIterator &operator ++() {
130+ ptr = reinterpret_cast <AvbDescriptor *>(
131+ reinterpret_cast <uint8_t *>(ptr) + sizeof (AvbDescriptor) + __builtin_bswap64 (ptr->num_bytes ));
132+ return *this ;
133+ }
134+ };
135+
136+ struct AvbDescriptorRange {
137+ AvbDescriptor *first, *last;
138+ AvbDescriptorIterator begin () const { return {first}; }
139+ AvbDescriptorIterator end () const { return {last}; }
140+ };
141+
142+ inline AvbDescriptorRange AvbVBMetaImageHeader::descriptors () const {
143+ auto *base = reinterpret_cast <const uint8_t *>(this ) + sizeof (AvbVBMetaImageHeader);
144+ base += __builtin_bswap64 (authentication_data_block_size);
145+ base += __builtin_bswap64 (descriptors_offset);
146+ auto *first = reinterpret_cast <AvbDescriptor *>(const_cast <uint8_t *>(base));
147+ auto *last = reinterpret_cast <AvbDescriptor *>(const_cast <uint8_t *>(base) + __builtin_bswap64 (descriptors_size));
148+ return {first, last};
149+ }
150+
97151/* ********************
98152 * Boot Image Headers
99153 *********************/
0 commit comments