Jeremy Compostella has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/37660 )
Change subject: ifwitool: Introduce a skip BPDT parameter ......................................................................
ifwitool: Introduce a skip BPDT parameter
SoCs like apololake can require two Boot Partition Descriptor Table entries. The second BPDT is usually in the ifwi binary which is supplied but ifwitool can only create a BPDT binary with the first BPDT of the supplied ifwi.
This patch introduces a skip BPDT parameter which is passed to the ifwi_parse() function. It allows the caller script to extract any BPDT separately. This is useful to extract the Logical Boot Partition 2 contains in some IFWI to inject it with fmaptool.
The same result could be achieve mixing up dd and ifwitool commands but it would create dependencies on the dd command and more importantly the script or Makefile would need to know the offset where the second BPDT is. With this simple new ifwitool option, the second BPDP (or third, ...) can be located and then extracted in one command without know its offset.
Change-Id: If32ec11fc7291d52b821bf95c1e186690d06ba11 Signed-off-by: Jeremy Compostella jeremy.compostella@intel.com --- M util/cbfstool/ifwitool.c 1 file changed, 36 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/60/37660/1
diff --git a/util/cbfstool/ifwitool.c b/util/cbfstool/ifwitool.c index 1fbb61b..c34e193 100644 --- a/util/cbfstool/ifwitool.c +++ b/util/cbfstool/ifwitool.c @@ -20,6 +20,8 @@
#include "common.h"
+#define max(a, b) (((a) > (b)) ? (a) : (b)) + /* * BPDT is Boot Partition Descriptor Table. It is located at the start of a * logical boot partition(LBP). It stores information about the critical @@ -851,8 +853,20 @@ 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) +static int ifwi_parse(size_t skip_bpdt_nb) { DEBUG("Parsing IFWI image...\n"); const char *image_name = param.image_name; @@ -871,9 +885,13 @@ 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 (!skip_bpdt_nb) + break; + offset += bpdt_size(buffer_get(buff) + offset); + skip_bpdt_nb--; + } else + offset += 4 * KiB; }
if (offset >= buffer_size(buff)) { @@ -1851,7 +1869,7 @@
static const struct command commands[] = { {"add", "f:n:e:dvh?", ifwi_add}, - {"create", "f:vh?", ifwi_create}, + {"create", "f:s:vh?", ifwi_create}, {"delete", "f:n:vh?", ifwi_delete}, {"extract", "f:n:e:dvh?", ifwi_extract}, {"print", "dh?", ifwi_print}, @@ -1883,6 +1901,7 @@ " replace -f FILE -n NAME [-d -e ENTRY]\n" "OPTIONs:\n" " -f FILE : File to read/write/create/extract\n" + " -s NB : NB of BPDT to skip during IFWI parsing\n" " -d : Perform directory operation\n" " -e ENTRY: Name of directory entry to operate on\n" " -v : Verbose level\n" @@ -1915,6 +1934,7 @@ if (strcmp(cmd, commands[i].name) != 0) continue;
+ size_t skip_bpdt_nb = 0; int c;
while (1) { @@ -1937,6 +1957,16 @@ case 'n': param.subpart_name = optarg; break; + case 's': { + char *endptr; + skip_bpdt_nb = strtoul(optarg, &endptr, 0); + if (*endptr != '\0') { + ERROR("%s: invalid offset\n", optarg); + return 1; + } + break; + } + case 'f': param.file_name = optarg; break; @@ -1958,7 +1988,7 @@ } }
- if (ifwi_parse()) { + if (ifwi_parse(skip_bpdt_nb)) { ERROR("%s: ifwi parsing failed\n", argv[0]); return 1; }