diff --git a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h index ac4b38f7a2..dd504695b3 100644 --- a/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h +++ b/src/commonlib/bsd/include/commonlib/bsd/cbfs_serialized.h @@ -114,6 +114,9 @@ struct cbfs_file_attribute { uint8_t data[0]; } __packed; +/* All attribute sizes must be divisible by this! */ +#define CBFS_ATTRIBUTE_ALIGN 4 + /* Depending on how the header was initialized, it may be backed with 0x00 or * 0xff. Support both. */ enum cbfs_file_attr_tag { diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 0191682de9..d3c6c94d48 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -34,10 +34,6 @@ * removing said guarantees. */ -/* The file name align is not defined in CBFS spec -- only a preference by - * (old) cbfstool. */ -#define CBFS_FILENAME_ALIGN (16) - static const char *lookup_name_by_type(const struct typedesc_t *desc, uint32_t type, const char *default_value) { @@ -70,7 +66,7 @@ int cbfs_parse_comp_algo(const char *name) size_t cbfs_calculate_file_header_size(const char *name) { return (sizeof(struct cbfs_file) + - align_up(strlen(name) + 1, CBFS_FILENAME_ALIGN)); + align_up(strlen(name) + 1, CBFS_ATTRIBUTE_ALIGN)); } /* Only call on legacy CBFSes possessing a master header. */ @@ -1870,6 +1866,7 @@ struct cbfs_file_attribute *cbfs_add_file_attr(struct cbfs_file *header, uint32_t tag, uint32_t size) { + assert(IS_ALIGNED(size, CBFS_ATTRIBUTE_ALIGN)); struct cbfs_file_attribute *attr, *next; next = cbfs_file_first_attr(header); do { diff --git a/util/cbfstool/cbfstool.c b/util/cbfstool/cbfstool.c index c7330a493e..72c01b9ea0 100644 --- a/util/cbfstool/cbfstool.c +++ b/util/cbfstool/cbfstool.c @@ -751,7 +751,8 @@ static int cbfs_add_component(const char *filename, if (param.padding) { const uint32_t hs = sizeof(struct cbfs_file_attribute); - uint32_t size = MAX(hs, param.padding); + uint32_t size = ALIGN_UP(MAX(hs, param.padding), + CBFS_ATTRIBUTE_ALIGN); INFO("Padding %d bytes\n", size); struct cbfs_file_attribute *attr = (struct cbfs_file_attribute *)cbfs_add_file_attr(