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>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58214
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
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 5329424..9badc82 100644
--- a/util/cbfstool/bpdt_formats/bpdt_1_7.c
+++ b/util/cbfstool/bpdt_formats/bpdt_1_7.c
@@ -185,7 +185,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));
@@ -196,16 +196,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..13afeab 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,14 @@
return 0;
}
-static int cmd_create_layout(void)
+static int fill_layout_buffer(struct buffer *buff)
{
- struct buffer buff, wbuff;
+ 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 +658,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 +825,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 +906,19 @@
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;
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);