diff options
author | Jeremy Compostella <jeremy.compostella@intel.com> | 2019-12-09 17:02:45 -0700 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2019-12-17 13:14:07 +0000 |
commit | 31e2188c385ce1d9326d18044c5e6a567a68b048 (patch) | |
tree | 5006192d9f211f21297a704bdb42edc5e6538cf3 /util/cbfstool | |
parent | d908916642eadf613e02d083cc54c9dacea28152 (diff) |
ifwitool: Introduce a use the Second Logical Boot Partition option
The ApolloLake SoC allows two Logical Boot Partitions. This patch
introduces a '-s' optional parameter to select the second Logical
Boot Partition.
Change-Id: If32ec11fc7291d52b821bf95c1e186690d06ba11
Signed-off-by: Jeremy Compostella <jeremy.compostella@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37660
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util/cbfstool')
-rw-r--r-- | util/cbfstool/ifwitool.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/util/cbfstool/ifwitool.c b/util/cbfstool/ifwitool.c index 1fbb61bfac..76b84e26df 100644 --- a/util/cbfstool/ifwitool.c +++ b/util/cbfstool/ifwitool.c @@ -34,9 +34,13 @@ */ #define BPDT_SIGNATURE (0x000055AA) +#define LBP1 (0) +#define LBP2 (1) + /* Parameters passed in by caller. */ static struct param { const char *file_name; + size_t logical_boot_partition; const char *subpart_name; const char *image_name; bool dir_ops; @@ -851,6 +855,18 @@ static void parse_subpart_dir(struct buffer *subpart_dir_buf, print_subpart_dir(subpart_dir); } +/* Parse the bpdt entries to compute the size of the BPDT */ +static size_t bpdt_size(void *data) +{ + struct bpdt *b = (struct bpdt *)data; + size_t i, size = 0; + + for (i = 0; i < b->h.descriptor_count; i++) + size = MAX(size, b->e[i].offset + b->e[i].size); + + return size; +} + /* Parse input image file to identify different sub-partitions. */ static int ifwi_parse(void) { @@ -867,17 +883,22 @@ static int ifwi_parse(void) INFO("Buffer %p size 0x%zx\n", buff->data, buff->size); /* Look for BPDT signature at 4K intervals. */ - size_t offset = 0; + size_t offset = 0, lbp = LBP1; void *data = buffer_get(buff); while (offset < buffer_size(buff)) { - if (read_at_le32(data, offset) == BPDT_SIGNATURE) - break; - offset += 4 * KiB; + if (read_at_le32(data, offset) == BPDT_SIGNATURE) { + if (lbp == param.logical_boot_partition) + break; + offset += bpdt_size((uint8_t *)data + offset); + lbp++; + } else + offset += 4 * KiB; } if (offset >= buffer_size(buff)) { - ERROR("Image does not contain BPDT!!\n"); + ERROR("Image does not contain BPDT for LBP=%zd!!\n", + param.logical_boot_partition); return -1; } @@ -1850,12 +1871,12 @@ struct command { }; static const struct command commands[] = { - {"add", "f:n:e:dvh?", ifwi_add}, - {"create", "f:vh?", ifwi_create}, - {"delete", "f:n:vh?", ifwi_delete}, - {"extract", "f:n:e:dvh?", ifwi_extract}, - {"print", "dh?", ifwi_print}, - {"replace", "f:n:e:dvh?", ifwi_replace}, + {"add", "f:n:e:dsvh?", ifwi_add}, + {"create", "f:svh?", ifwi_create}, + {"delete", "f:n:svh?", ifwi_delete}, + {"extract", "f:n:e:dsvh?", ifwi_extract}, + {"print", "dsh?", ifwi_print}, + {"replace", "f:n:e:dsvh?", ifwi_replace}, }; static struct option long_options[] = { @@ -1865,6 +1886,7 @@ static struct option long_options[] = { {"name", required_argument, 0, 'n'}, {"dir_ops", no_argument, 0, 'd'}, {"verbose", no_argument, 0, 'v'}, + {"second_lbp", no_argument, 0, 's'}, {NULL, 0, 0, 0 } }; @@ -1875,14 +1897,15 @@ static void usage(const char *name) " %s [-h]\n" " %s FILE COMMAND [PARAMETERS]\n\n" "COMMANDs:\n" - " add -f FILE -n NAME [-d -e ENTRY]\n" - " create -f FILE\n" - " delete -n NAME\n" - " extract -f FILE -n NAME [-d -e ENTRY]\n" - " print [-d]\n" - " replace -f FILE -n NAME [-d -e ENTRY]\n" + " add -f FILE -n NAME [-d -e ENTRY] [-s]\n" + " create -f FILE [-s]\n" + " delete -n NAME [-s]\n" + " extract -f FILE -n NAME [-d -e ENTRY] [-s]\n" + " print [-d] [-s]\n" + " replace -f FILE -n NAME [-d -e ENTRY] [-s]\n" "OPTIONs:\n" " -f FILE : File to read/write/create/extract\n" + " -s : Use the second Logical Boot Partition\n" " -d : Perform directory operation\n" " -e ENTRY: Name of directory entry to operate on\n" " -v : Verbose level\n" @@ -1906,6 +1929,7 @@ int main(int argc, char **argv) } param.image_name = argv[1]; + param.logical_boot_partition = LBP1; char *cmd = argv[2]; optind += 2; @@ -1937,6 +1961,9 @@ int main(int argc, char **argv) case 'n': param.subpart_name = optarg; break; + case 's': + param.logical_boot_partition = LBP2; + break; case 'f': param.file_name = optarg; break; |