diff options
author | Brandon Maier | 2024-01-04 18:50:08 +0000 |
---|---|---|
committer | Michal Simek | 2024-01-10 09:27:12 +0100 |
commit | d47935b35fc1126f59b6ddde36597948afbfa66e (patch) | |
tree | da5556476d6191a1f68d41af9fe77e14c696840a /tools/zynqmpimage.h | |
parent | 2ddd0248e9cc8bf1da7c3d42c0bab1f65e859913 (diff) |
tools: zynqmpimage: add partition extracting
Extract partitions from a Xilinx Boot Image using dumpimage.
Add helper for_each_zynqmp_part() to reuse the partition walking code
between the printing and extracting functions.
Signed-off-by: Brandon Maier <brandon.maier@collins.com>
Link: https://lore.kernel.org/r/20240104185258.39465-3-brandon.maier@collins.com
Signed-off-by: Michal Simek <michal.simek@amd.com>
Diffstat (limited to 'tools/zynqmpimage.h')
-rw-r--r-- | tools/zynqmpimage.h | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/tools/zynqmpimage.h b/tools/zynqmpimage.h index ca7489835a8..32be0d125fd 100644 --- a/tools/zynqmpimage.h +++ b/tools/zynqmpimage.h @@ -135,4 +135,62 @@ struct zynqmp_header { void zynqmpimage_default_header(struct zynqmp_header *ptr); void zynqmpimage_print_header(const void *ptr, struct image_tool_params *params); +static inline struct image_header_table * +zynqmp_get_iht(const struct zynqmp_header *zynqhdr) +{ + if (!zynqhdr->image_header_table_offset) + return NULL; + return (struct image_header_table *)((void *)zynqhdr + zynqhdr->image_header_table_offset); +} + +static inline void *zynqmp_get_offset(const struct zynqmp_header *zynqhdr, + uint32_t offset) +{ + uint32_t offset_cpu = le32_to_cpu(offset); + + if (!offset_cpu) + return NULL; + return (void *)zynqhdr + offset_cpu * 4; +} + +static inline struct partition_header * +zynqmp_part_first(const struct zynqmp_header *zynqhdr) +{ + struct image_header_table *iht; + + iht = zynqmp_get_iht(zynqhdr); + if (!iht) + return NULL; + + return zynqmp_get_offset(zynqhdr, iht->partition_header_offset); +} + +static inline struct partition_header * +zynqmp_part_next(const struct zynqmp_header *zynqhdr, + const struct partition_header *ph) +{ + return zynqmp_get_offset(zynqhdr, ph->next_partition_offset); +} + +static inline size_t zynqmp_part_count(const struct zynqmp_header *zynqhdr) +{ + struct image_header_table *iht; + + iht = zynqmp_get_iht(zynqhdr); + if (!iht) + return 0; + + return le32_to_cpu(iht->nr_parts); +} + +#define _for_each_zynqmp_part(_zynqhdr, _iter, _ph, _start, _count) \ + for (_iter = 0, _ph = _start; \ + _iter < (_count) && _ph; \ + _iter++, _ph = zynqmp_part_next(_zynqhdr, _ph)) + +#define for_each_zynqmp_part(_zynqhdr, _iter, _ph) \ + _for_each_zynqmp_part(_zynqhdr, _iter, _ph, \ + zynqmp_part_first(_zynqhdr), \ + zynqmp_part_count(_zynqhdr)) + #endif /* _ZYNQMPIMAGE_H_ */ |