summaryrefslogtreecommitdiff
path: root/tools/kwbimage.h
diff options
context:
space:
mode:
authorPali Rohár <pali@kernel.org>2022-02-17 10:43:36 +0100
committerStefan Roese <sr@denx.de>2022-02-17 14:17:07 +0100
commitf76ae2571fe050bf8b3f29e57e9f4705f427ec53 (patch)
tree3c5052b97dc483a8214037be901bd67d0d46248e /tools/kwbimage.h
parent9a9a2c1acf6d343f943815b561e870b7746701ca (diff)
downloadu-boot-f76ae2571fe050bf8b3f29e57e9f4705f427ec53.tar.gz
tools: kwbimage: Add support for dumping extended and binary v0 headers
dumpimage is now able to successfully parse and dump content of the Dove bootloader image. Note that support for generating these extended parts of v0 images is not included yet. Signed-off-by: Pali Rohár <pali@kernel.org> Tested-by: Tony Dinh <mibodhi@gmail.com> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'tools/kwbimage.h')
-rw-r--r--tools/kwbimage.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/tools/kwbimage.h b/tools/kwbimage.h
index 502b6d5033..505522332b 100644
--- a/tools/kwbimage.h
+++ b/tools/kwbimage.h
@@ -270,6 +270,57 @@ static inline size_t kwbheader_size_for_csum(const void *header)
return kwbheader_size(header);
}
+static inline struct ext_hdr_v0 *ext_hdr_v0_first(void *img)
+{
+ struct main_hdr_v0 *mhdr;
+
+ if (kwbimage_version(img) != 0)
+ return NULL;
+
+ mhdr = img;
+ if (mhdr->ext)
+ return (struct ext_hdr_v0 *)(mhdr + 1);
+ else
+ return NULL;
+}
+
+static inline void *_ext_hdr_v0_end(struct main_hdr_v0 *mhdr)
+{
+ return (uint8_t *)mhdr + kwbheader_size(mhdr) - mhdr->bin * sizeof(struct bin_hdr_v0);
+}
+
+static inline struct ext_hdr_v0 *ext_hdr_v0_next(void *img, struct ext_hdr_v0 *cur)
+{
+ if ((void *)(cur + 1) < _ext_hdr_v0_end(img))
+ return (struct ext_hdr_v0 *)((uint8_t *)(cur + 1) + 0x20);
+ else
+ return NULL;
+}
+
+#define for_each_ext_hdr_v0(ehdr, img) \
+ for ((ehdr) = ext_hdr_v0_first((img)); \
+ (ehdr) != NULL; \
+ (ehdr) = ext_hdr_v0_next((img), (ehdr)))
+
+static inline struct bin_hdr_v0 *bin_hdr_v0_first(void *img)
+{
+ struct main_hdr_v0 *mhdr;
+
+ if (kwbimage_version(img) != 0)
+ return NULL;
+
+ mhdr = img;
+ if (mhdr->bin)
+ return _ext_hdr_v0_end(mhdr);
+ else
+ return NULL;
+}
+
+#define for_each_bin_hdr_v0(bhdr, img) \
+ for ((bhdr) = bin_hdr_v0_first((img)); \
+ (bhdr) && (void *)(bhdr) < (void *)((uint8_t *)img + kwbheader_size(img)); \
+ (bhdr) = (struct bin_hdr_v0 *)((bhdr))+1)
+
static inline uint32_t opt_hdr_v1_size(const struct opt_hdr_v1 *ohdr)
{
return (ohdr->headersz_msb << 16) | le16_to_cpu(ohdr->headersz_lsb);