diff options
Diffstat (limited to 'util/cbfstool/cse_serger.h')
-rw-r--r-- | util/cbfstool/cse_serger.h | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/util/cbfstool/cse_serger.h b/util/cbfstool/cse_serger.h new file mode 100644 index 0000000000..b60a9c7a0a --- /dev/null +++ b/util/cbfstool/cse_serger.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __CBFSTOOL_CSE_SERGER_H__ +#define __CBFSTOOL_CSE_SERGER_H__ + +#include <commonlib/endian.h> +#include <commonlib/region.h> + +#include "common.h" + +#define BPDT_SIGNATURE (0x000055AA) + +#define BUFF_SIZE_ALIGN (4 * KiB) + +#define READ_MEMBER(_buff, _x) read_member(_buff, &(_x), sizeof(_x)) +#define WRITE_MEMBER(_buff, _x) write_member(_buff, &(_x), sizeof(_x)) + +enum bpdt_version { + BPDT_VERSION_1_6 = 1, + BPDT_VERSION_1_7 = 2, +}; + +enum subpart_hdr_version { + SUBPART_HDR_VERSION_1 = 1, + SUBPART_HDR_VERSION_2 = 2, +}; + +enum subpart_entry_version { + SUBPART_ENTRY_VERSION_1 = 1, +}; + +struct cse_layout_regions { + struct region data_partition; + struct region bp1; + struct region bp2; + struct region bp3; + struct region bp4; +}; + +typedef void *cse_layout_ptr; +typedef void *bpdt_hdr_ptr; +typedef void *subpart_hdr_ptr; + +struct bpdt_entry { + uint32_t type; + uint32_t offset; + uint32_t size; +} __packed; + +struct bpdt_ops { + bool (*match_version)(const struct buffer *buff); + + bpdt_hdr_ptr (*create_hdr)(void); + void (*print_hdr)(const bpdt_hdr_ptr ptr); + bpdt_hdr_ptr (*read_hdr)(struct buffer *buff); + int (*write_hdr)(struct buffer *buff, const bpdt_hdr_ptr ptr); + + size_t (*get_entry_count)(const bpdt_hdr_ptr ptr); + void (*inc_entry_count)(bpdt_hdr_ptr ptr); + + cse_layout_ptr (*create_layout)(const struct cse_layout_regions *regions); + void (*print_layout)(const cse_layout_ptr ptr); + cse_layout_ptr (*read_layout)(struct buffer *buff); + int (*write_layout)(struct buffer *buff, const cse_layout_ptr ptr); + + void (*update_checksum)(bpdt_hdr_ptr ptr, struct bpdt_entry *entry); + bool (*validate_checksum)(bpdt_hdr_ptr ptr, struct bpdt_entry *entry); + + enum subpart_hdr_version subpart_hdr_version; + enum subpart_entry_version subpart_entry_version; +}; + +struct subpart_hdr_ops { + subpart_hdr_ptr (*read)(struct buffer *buffer); + void (*print)(const subpart_hdr_ptr ptr); + size_t (*get_entry_count)(const subpart_hdr_ptr ptr); + void (*free)(subpart_hdr_ptr ptr); +}; + +struct subpart_entry_ops { + void (*print)(struct buffer *buff, size_t size); +}; + +extern const struct bpdt_ops bpdt_1_7_ops; +extern const struct bpdt_ops bpdt_1_6_ops; + +extern const struct subpart_hdr_ops subpart_hdr_1_ops; +extern const struct subpart_hdr_ops subpart_hdr_2_ops; + +extern const struct subpart_entry_ops subpart_entry_1_ops; + +void read_member(struct buffer *buff, void *dst, size_t size); +void write_member(struct buffer *buff, void *src, size_t size); + +#endif /* __CBFSTOOL_CSE_SERGER_H__ */ |