diff options
Diffstat (limited to 'src/commonlib')
-rw-r--r-- | src/commonlib/bsd/cbfs_mcache.c | 4 | ||||
-rw-r--r-- | src/commonlib/bsd/cbfs_private.c | 13 | ||||
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h | 6 | ||||
-rw-r--r-- | src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h | 120 | ||||
-rw-r--r-- | src/commonlib/cbfs.c | 2 |
5 files changed, 76 insertions, 69 deletions
diff --git a/src/commonlib/bsd/cbfs_mcache.c b/src/commonlib/bsd/cbfs_mcache.c index f54b6631af..d2f969dbc3 100644 --- a/src/commonlib/bsd/cbfs_mcache.c +++ b/src/commonlib/bsd/cbfs_mcache.c @@ -106,8 +106,8 @@ cb_err_t cbfs_mcache_lookup(const void *mcache, size_t mcache_size, const char * assert(entry->magic == MCACHE_MAGIC_FILE); const uint32_t data_offset = be32toh(entry->file.h.offset); const uint32_t data_length = be32toh(entry->file.h.len); - if (namesize <= data_offset - offsetof(union cbfs_mdata, filename) && - memcmp(name, entry->file.filename, namesize) == 0) { + if (namesize <= data_offset - offsetof(union cbfs_mdata, h.filename) && + memcmp(name, entry->file.h.filename, namesize) == 0) { LOG("Found '%s' @%#x size %#x in mcache @%p\n", name, entry->offset, data_length, current); *data_offset_out = entry->offset + data_offset; diff --git a/src/commonlib/bsd/cbfs_private.c b/src/commonlib/bsd/cbfs_private.c index 7814c4a727..527860db75 100644 --- a/src/commonlib/bsd/cbfs_private.c +++ b/src/commonlib/bsd/cbfs_private.c @@ -46,7 +46,7 @@ cb_err_t cbfs_walk(cbfs_dev_t dev, cb_err_t (*walker)(cbfs_dev_t dev, size_t off const uint32_t data_offset = be32toh(mdata.h.offset); const uint32_t data_length = be32toh(mdata.h.len); const uint32_t type = be32toh(mdata.h.type); - const bool empty = (type == CBFS_TYPE_DELETED || type == CBFS_TYPE_DELETED2); + const bool empty = (type == CBFS_TYPE_DELETED || type == CBFS_TYPE_NULL); DEBUG("Found CBFS header @%#zx (type %d, attr +%#x, data +%#x, length %#x)\n", offset, type, attr_offset, data_offset, data_length); @@ -75,7 +75,7 @@ cb_err_t cbfs_walk(cbfs_dev_t dev, cb_err_t (*walker)(cbfs_dev_t dev, size_t off if (cbfs_dev_read(dev, mdata.raw + sizeof(mdata.h), offset + sizeof(mdata.h), todo) != todo) return CB_CBFS_IO; - DEBUG("File name: '%s'\n", mdata.filename); + DEBUG("File name: '%s'\n", mdata.h.filename); if (do_hash && !empty && vb2_digest_extend(&dc, mdata.raw, data_offset)) return CB_ERR; @@ -134,10 +134,9 @@ static cb_err_t lookup_walker(cbfs_dev_t dev, size_t offset, const union cbfs_md size_t already_read, void *arg) { struct cbfs_lookup_args *args = arg; - /* Check if the name we're looking for could fit, then we can safely memcmp() it. */ - if (args->namesize > already_read - offsetof(union cbfs_mdata, filename) || - memcmp(args->name, mdata->filename, args->namesize) != 0) + if (args->namesize > already_read - offsetof(union cbfs_mdata, h.filename) || + memcmp(args->name, mdata->h.filename, args->namesize) != 0) return CB_CBFS_NOT_FOUND; LOG("Found '%s' @%#zx size %#x\n", args->name, offset, be32toh(mdata->h.len)); @@ -175,13 +174,13 @@ const void *cbfs_find_attr(const union cbfs_mdata *mdata, uint32_t attr_tag, siz if (offset + len > end) { ERROR("Attribute %s[%u] overflows end of metadata\n", - mdata->filename, tag); + mdata->h.filename, tag); return NULL; } if (tag == attr_tag) { if (size_check && len != size_check) { ERROR("Attribute %s[%u] size mismatch: %u != %zu\n", - mdata->filename, tag, len, size_check); + mdata->h.filename, tag, len, size_check); return NULL; } return attr; diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h index b72463aba3..9fe740c917 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_private.h @@ -48,12 +48,8 @@ * avoid byte-order confusion, fields should always and only be converted to host byte order at * exactly the time they are read from one of these structures into their own separate variable. */ -#define CBFS_METADATA_MAX_SIZE 256 union cbfs_mdata { - struct { - struct cbfs_file h; - char filename[]; - }; + struct cbfs_file h; uint8_t raw[CBFS_METADATA_MAX_SIZE]; }; diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h index 7171634c8e..ac4b38f7a2 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h @@ -6,45 +6,40 @@ #include <stdint.h> #include <vb2_sha.h> -/** These are standard values for the known compression - algorithms that coreboot knows about for stages and - payloads. Of course, other CBFS users can use whatever - values they want, as long as they understand them. */ - -#define CBFS_COMPRESS_NONE 0 -#define CBFS_COMPRESS_LZMA 1 -#define CBFS_COMPRESS_LZ4 2 - -/** These are standard component types for well known - components (i.e - those that coreboot needs to consume. - Users are welcome to use any other value for their - components */ - -#define CBFS_TYPE_DELETED 0x00000000 -#define CBFS_TYPE_DELETED2 0xffffffff -#define CBFS_TYPE_BOOTBLOCK 0x01 -#define CBFS_TYPE_STAGE 0x10 -#define CBFS_TYPE_SELF 0x20 -#define CBFS_TYPE_FIT 0x21 -#define CBFS_TYPE_OPTIONROM 0x30 -#define CBFS_TYPE_BOOTSPLASH 0x40 -#define CBFS_TYPE_RAW 0x50 -#define CBFS_TYPE_VSA 0x51 -#define CBFS_TYPE_MBI 0x52 -#define CBFS_TYPE_MICROCODE 0x53 -#define CBFS_TYPE_FSP 0x60 -#define CBFS_TYPE_MRC 0x61 -#define CBFS_TYPE_MMA 0x62 -#define CBFS_TYPE_EFI 0x63 -#define CBFS_TYPE_STRUCT 0x70 -#define CBFS_COMPONENT_CMOS_DEFAULT 0xaa -#define CBFS_TYPE_SPD 0xab -#define CBFS_TYPE_MRC_CACHE 0xac -#define CBFS_COMPONENT_CMOS_LAYOUT 0x01aa - -#define CBFS_HEADER_MAGIC 0x4F524243 -#define CBFS_HEADER_VERSION1 0x31313131 -#define CBFS_HEADER_VERSION2 0x31313132 +enum cbfs_compression { + CBFS_COMPRESS_NONE = 0, + CBFS_COMPRESS_LZMA = 1, + CBFS_COMPRESS_LZ4 = 2, +}; + +enum cbfs_type { + CBFS_TYPE_DELETED = 0x00000000, + CBFS_TYPE_NULL = 0xffffffff, + CBFS_TYPE_BOOTBLOCK = 0x01, + CBFS_TYPE_CBFSHEADER = 0x02, + CBFS_TYPE_STAGE = 0x10, + CBFS_TYPE_SELF = 0x20, + CBFS_TYPE_FIT = 0x21, + CBFS_TYPE_OPTIONROM = 0x30, + CBFS_TYPE_BOOTSPLASH = 0x40, + CBFS_TYPE_RAW = 0x50, + CBFS_TYPE_VSA = 0x51, + CBFS_TYPE_MBI = 0x52, + CBFS_TYPE_MICROCODE = 0x53, + CBFS_TYPE_FSP = 0x60, + CBFS_TYPE_MRC = 0x61, + CBFS_TYPE_MMA = 0x62, + CBFS_TYPE_EFI = 0x63, + CBFS_TYPE_STRUCT = 0x70, + CBFS_TYPE_CMOS_DEFAULT = 0xaa, + CBFS_TYPE_SPD = 0xab, + CBFS_TYPE_MRC_CACHE = 0xac, + CBFS_TYPE_CMOS_LAYOUT = 0x01aa, +}; + +#define CBFS_HEADER_MAGIC 0x4F524243 /* BE: 'ORBC' */ +#define CBFS_HEADER_VERSION1 0x31313131 /* BE: '1111' */ +#define CBFS_HEADER_VERSION2 0x31313132 /* BE: '1112' */ #define CBFS_HEADER_VERSION CBFS_HEADER_VERSION2 /* this is the master cbfs header - it must be located somewhere available @@ -68,9 +63,15 @@ struct cbfs_header { /* "Unknown" refers to CBFS headers version 1, * before the architecture was defined (i.e., x86 only). */ -#define CBFS_ARCHITECTURE_UNKNOWN 0xFFFFFFFF -#define CBFS_ARCHITECTURE_X86 0x00000001 -#define CBFS_ARCHITECTURE_ARM 0x00000010 +enum cbfs_architecture { + CBFS_ARCHITECTURE_UNKNOWN = 0xFFFFFFFF, + CBFS_ARCHITECTURE_X86 = 0x00000001, + CBFS_ARCHITECTURE_ARM = 0x00000010, + CBFS_ARCHITECTURE_AARCH64 = 0x0000aa64, + CBFS_ARCHITECTURE_MIPS = 0x00000100, /* deprecated */ + CBFS_ARCHITECTURE_RISCV = 0xc001d0de, + CBFS_ARCHITECTURE_PPC64 = 0x407570ff, +}; /** This is a component header - every entry in the CBFS will have this header. @@ -88,6 +89,7 @@ struct cbfs_header { */ #define CBFS_FILE_MAGIC "LARCHIVE" +#define CBFS_METADATA_MAX_SIZE 256 struct cbfs_file { char magic[8]; @@ -95,8 +97,13 @@ struct cbfs_file { uint32_t type; uint32_t attributes_offset; uint32_t offset; + char filename[0]; } __packed; +#if defined __GNUC__ && (__GNUC__ * 100 + __GNUC_MINOR__) >= 406 +_Static_assert(sizeof(struct cbfs_file) == 24, "cbfs_file size mismatch"); +#endif + /* The common fields of extended cbfs file attributes. Attributes are expected to start with tag/len, then append their specific fields. */ @@ -109,13 +116,16 @@ struct cbfs_file_attribute { /* Depending on how the header was initialized, it may be backed with 0x00 or * 0xff. Support both. */ -#define CBFS_FILE_ATTR_TAG_UNUSED 0 -#define CBFS_FILE_ATTR_TAG_UNUSED2 0xffffffff -#define CBFS_FILE_ATTR_TAG_COMPRESSION 0x42435a4c -#define CBFS_FILE_ATTR_TAG_HASH 0x68736148 -#define CBFS_FILE_ATTR_TAG_POSITION 0x42435350 /* PSCB */ -#define CBFS_FILE_ATTR_TAG_ALIGNMENT 0x42434c41 /* ALCB */ -#define CBFS_FILE_ATTR_TAG_IBB 0x32494242 /* Initial BootBlock */ +enum cbfs_file_attr_tag { + CBFS_FILE_ATTR_TAG_UNUSED = 0, + CBFS_FILE_ATTR_TAG_UNUSED2 = 0xffffffff, + CBFS_FILE_ATTR_TAG_COMPRESSION = 0x42435a4c, /* BE: 'BCZL' */ + CBFS_FILE_ATTR_TAG_HASH = 0x68736148, /* BE: 'hsaH' */ + CBFS_FILE_ATTR_TAG_POSITION = 0x42435350, /* BE: 'BCSP' */ + CBFS_FILE_ATTR_TAG_ALIGNMENT = 0x42434c41, /* BE: 'BCLA' */ + CBFS_FILE_ATTR_TAG_IBB = 0x32494242, /* BE: '2IBB' */ + CBFS_FILE_ATTR_TAG_PADDING = 0x47444150, /* BE: 'GNDP' */ +}; struct cbfs_file_attr_compression { uint32_t tag; @@ -176,11 +186,13 @@ struct cbfs_payload { struct cbfs_payload_segment segments; }; -#define PAYLOAD_SEGMENT_CODE 0x434F4445 -#define PAYLOAD_SEGMENT_DATA 0x44415441 -#define PAYLOAD_SEGMENT_BSS 0x42535320 -#define PAYLOAD_SEGMENT_PARAMS 0x50415241 -#define PAYLOAD_SEGMENT_ENTRY 0x454E5452 +enum cbfs_payload_segment_type { + PAYLOAD_SEGMENT_CODE = 0x434F4445, /* BE: 'CODE' */ + PAYLOAD_SEGMENT_DATA = 0x44415441, /* BE: 'DATA' */ + PAYLOAD_SEGMENT_BSS = 0x42535320, /* BE: 'BSS ' */ + PAYLOAD_SEGMENT_PARAMS = 0x50415241, /* BE: 'PARA' */ + PAYLOAD_SEGMENT_ENTRY = 0x454E5452, /* BE: 'ENTR' */ +}; struct cbfs_optionrom { uint32_t compression; diff --git a/src/commonlib/cbfs.c b/src/commonlib/cbfs.c index 999c35e52a..f256938d5f 100644 --- a/src/commonlib/cbfs.c +++ b/src/commonlib/cbfs.c @@ -335,7 +335,7 @@ int cbfs_vb2_hash_contents(const struct region_device *cbfs, if (cbfsf_file_type(fh, &ftype)) return VB2_ERROR_UNKNOWN; - if (ftype == CBFS_TYPE_DELETED || ftype == CBFS_TYPE_DELETED2) + if (ftype == CBFS_TYPE_DELETED || ftype == CBFS_TYPE_NULL) continue; rv = cbfs_extend_hash_with_offset(&ctx, cbfs, &fh->data); |