arch/arm64/Makefile.mk: Unset toolchain vars for BL31
[coreboot.git] / util / cbfstool / bpdt_formats / subpart_entry_1.c
bloba5982ff13242b33adaa1f315f492de0d81d6fe2f
1 /* Subpart directory entry version 1 support */
2 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <sys/types.h>
6 #include "cse_serger.h"
8 #define SUBPART_OFFSET_SHIFT 0
9 #define SUBPART_OFFSET_MASK 0x1ffffff
10 #define SUBPART_OFFSET(x) (((x) >> SUBPART_OFFSET_SHIFT) & SUBPART_OFFSET_MASK)
11 #define SUBPART_COMPRESSED_SHIFT 25
12 #define SUBPART_COMPRESSED_MASK 1
13 #define SUBPART_COMPRESSED(x) \
14 (((x) >> SUBPART_COMPRESSED_SHIFT) & SUBPART_COMPRESSED_MASK)
16 struct subpart_entry {
17 uint8_t name[12];
18 uint32_t offset_bytes;
19 uint32_t length;
20 uint32_t rsvd2;
21 } __packed;
23 static void subpart_read_entry(struct buffer *buff, struct subpart_entry *e)
25 READ_MEMBER(buff, e->name);
26 READ_MEMBER(buff, e->offset_bytes);
27 READ_MEMBER(buff, e->length);
28 READ_MEMBER(buff, e->rsvd2);
31 static void subpart_print_entry(const struct subpart_entry *e, size_t index)
33 printf("%-25zd%-25.12s0x%-23x%-25c0x%-23x0x%-23x\n", index,
34 e->name, SUBPART_OFFSET(e->offset_bytes),
35 SUBPART_COMPRESSED(e->offset_bytes) ? 'Y' : 'N',
36 e->length, e->rsvd2);
39 static void subpart_print_entries(struct buffer *buff, size_t count)
41 struct subpart_entry *e = malloc(count * sizeof(*e));
43 if (!e)
44 return;
46 for (size_t i = 0; i < count; i++)
47 subpart_read_entry(buff, &e[i]);
49 printf("%-25s%-25s%-25s%-25s%-25s%-25s\n", "Entry #", "Name", "Offset",
50 "Huffman Compressed?", "Length", "Rsvd");
52 printf("====================================================================="
53 "=====================================================================\n");
55 for (size_t i = 0; i < count; i++)
56 subpart_print_entry(&e[i], i + 1);
58 printf("====================================================================="
59 "=====================================================================\n");
61 free(e);
64 const struct subpart_entry_ops subpart_entry_1_ops = {
65 .print = subpart_print_entries,