Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/58214 )
Change subject: util/cse_serger: Replace cse_layout_regions with array of regions ......................................................................
util/cse_serger: Replace cse_layout_regions with array of regions
This change replaces `struct cse_layout_regions` with an array of `struct region` and introduces enums for DP and BP[1-4]. This makes it easier to loop over the different regions in following changes.
BUG=b:189177186
Change-Id: If3cced4506d26dc534047cb9c385aaa9418d8522 Signed-off-by: Furquan Shaikh furquan@google.com --- M util/cbfstool/bpdt_formats/bpdt_1_6.c M util/cbfstool/bpdt_formats/bpdt_1_7.c M util/cbfstool/cse_serger.c M util/cbfstool/cse_serger.h 4 files changed, 51 insertions(+), 38 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/14/58214/1
diff --git a/util/cbfstool/bpdt_formats/bpdt_1_6.c b/util/cbfstool/bpdt_formats/bpdt_1_6.c index eaa2902..b894936 100644 --- a/util/cbfstool/bpdt_formats/bpdt_1_6.c +++ b/util/cbfstool/bpdt_formats/bpdt_1_6.c @@ -142,21 +142,21 @@ h->descriptor_count++; }
-static cse_layout_ptr create_cse_layout(const struct cse_layout_regions *r) +static cse_layout_ptr create_cse_layout(const struct region *r) { struct cse_layout *l = malloc(sizeof(*l));
if (!l) return NULL;
- l->data_offset = r->data_partition.offset; - l->data_size = r->data_partition.size; - l->bp1_offset = r->bp1.offset; - l->bp1_size = r->bp1.size; - l->bp2_offset = r->bp2.offset; - l->bp2_size = r->bp2.size; - l->bp3_offset = r->bp3.offset; - l->bp3_size = r->bp3.size; + l->data_offset = r[DP].offset; + l->data_size = r[DP].size; + l->bp1_offset = r[BP1].offset; + l->bp1_size = r[BP1].size; + l->bp2_offset = r[BP2].offset; + l->bp2_size = r[BP2].size; + l->bp3_offset = r[BP3].offset; + l->bp3_size = r[BP3].size; l->checksum = 0; /* unused */
return 0; diff --git a/util/cbfstool/bpdt_formats/bpdt_1_7.c b/util/cbfstool/bpdt_formats/bpdt_1_7.c index eccbdd1..a4a6017 100644 --- a/util/cbfstool/bpdt_formats/bpdt_1_7.c +++ b/util/cbfstool/bpdt_formats/bpdt_1_7.c @@ -179,7 +179,7 @@ return calc_checksum; }
-static cse_layout_ptr create_cse_layout(const struct cse_layout_regions *r) +static cse_layout_ptr create_cse_layout(const struct region *r) { struct cse_layout *l = calloc(1, sizeof(*l));
@@ -190,16 +190,16 @@ l->size = sizeof(struct cse_layout) - sizeof(l->rom_bypass); l->redundancy = 0; l->checksum = 0; - l->data_offset = r->data_partition.offset; - l->data_size = r->data_partition.size; - l->bp1_offset = r->bp1.offset; - l->bp1_size = r->bp1.size; - l->bp2_offset = r->bp2.offset; - l->bp2_size = r->bp2.size; - l->bp3_offset = r->bp3.offset; - l->bp3_size = r->bp3.size; - l->bp4_offset = r->bp4.offset; - l->bp4_size = r->bp4.size; + l->data_offset = r[DP].offset; + l->data_size = r[DP].size; + l->bp1_offset = r[BP1].offset; + l->bp1_size = r[BP1].size; + l->bp2_offset = r[BP2].offset; + l->bp2_size = r[BP2].size; + l->bp3_offset = r[BP3].offset; + l->bp3_size = r[BP3].size; + l->bp4_offset = r[BP4].offset; + l->bp4_size = r[BP4].size; l->bp5_offset = 0; l->bp5_size = 0; l->temp_base_addr = 0; diff --git a/util/cbfstool/cse_serger.c b/util/cbfstool/cse_serger.c index c8bd104..2cdfc49 100644 --- a/util/cbfstool/cse_serger.c +++ b/util/cbfstool/cse_serger.c @@ -21,7 +21,7 @@ const char *image_name; const char *version_str; const char *input_file; - struct cse_layout_regions layout_regions; + struct region layout_regions[BP_TOTAL]; } params;
static const struct { @@ -640,14 +640,15 @@ return 0; }
-static int cmd_create_layout(void) { - struct buffer buff, wbuff; +static int fill_layout_buffer(struct buffer *buff) +{ + struct buffer wbuff;
- if (allocate_buffer(&buff, &wbuff, "CSE layout")) + if (allocate_buffer(buff, &wbuff, "CSE layout")) return -1;
- ifwi.cse_layout = ifwi.bpdt_ops->create_layout(¶ms.layout_regions); + ifwi.cse_layout = ifwi.bpdt_ops->create_layout(¶ms.layout_regions[0]); if (!ifwi.cse_layout) { ERROR("Failed to create layout!\n"); return -1; @@ -658,6 +659,16 @@ return -1; }
+ return 0; +} + +static int cmd_create_layout(void) +{ + struct buffer buff; + + if (fill_layout_buffer(&buff)) + return -1; + buffer_write_file(&buff, params.image_name); return 0; } @@ -815,7 +826,7 @@ "COMMANDs:\n" " print [-s][-n NAME][-t TYPE]\n" " dump [-o DIR][-n NAME]\n" - " create-layout --dp offset:size --bp1 offset:size --bp2 offset:size -v VERSION\n" + " create-layout --dp offset:size --bp* offset:size -v VERSION\n" " print-layout -v VERSION\n" " create-bpdt -v VERSION\n" " add [-n NAME][-t TYPE][-f INPUT_FILE]\n" @@ -896,19 +907,20 @@ params.partition_type = atoi(optarg); break; case LONGOPT_BP1: - parse_region(¶ms.layout_regions.bp1, optarg); + parse_region(¶ms.layout_regions[BP1], optarg); break; case LONGOPT_BP2: - parse_region(¶ms.layout_regions.bp2, optarg); + parse_region(¶ms.layout_regions[BP2], optarg); break; case LONGOPT_BP3: - parse_region(¶ms.layout_regions.bp3, optarg); + parse_region(¶ms.layout_regions[BP3], optarg); break; case LONGOPT_BP4: - parse_region(¶ms.layout_regions.bp4, optarg); + parse_region(¶ms.layout_regions[BP4], optarg); break; case LONGOPT_DATA: - parse_region(¶ms.layout_regions.data_partition, optarg); + parse_region(¶ms.layout_regions[DP], optarg); + break; break; case 'h': case '?': diff --git a/util/cbfstool/cse_serger.h b/util/cbfstool/cse_serger.h index 8727f59..e1f351a 100644 --- a/util/cbfstool/cse_serger.h +++ b/util/cbfstool/cse_serger.h @@ -27,12 +27,13 @@ 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; +enum { + DP, + BP1, + BP2, + BP3, + BP4, + BP_TOTAL, };
typedef void *cse_layout_ptr; @@ -56,7 +57,7 @@ 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); + cse_layout_ptr (*create_layout)(const struct region *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);