layout: Introduce flashrom_layout_new()

It initializes an empty layout. Currently the maximum number of entries
has to be specified, which will vanish once we use dynamic allocation
per entry.

We replace the two special cases `single_layout` and `ich_layout` with
dynamically allocated layouts. As a result, we have to take care to
release the `default_layout` in a flashctx once we are done with it.

Change-Id: I2ae7246493ff592e631cce924777925c7825e398
Signed-off-by: Nico Huber <nico.h@gmx.de>
Original-Reviewed-on: https://review.coreboot.org/c/flashrom/+/33543
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom-stable/+/72214
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/flashrom.c b/flashrom.c
index f99cff9..361f135 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -831,15 +831,12 @@
 	if (!flash->chip)
 		return -1;
 
-	/* Fill fallback layout covering the whole chip. */
-	struct single_layout *const fallback = &flash->fallback_layout;
-	fallback->base.entries		= &fallback->entry;
-	fallback->base.capacity		= 1;
-	fallback->base.num_entries	= 0;
-	if (flashrom_layout_add_region(&fallback->base,
+	/* Fill default layout covering the whole chip. */
+	if (flashrom_layout_new(&flash->default_layout, 1) ||
+	    flashrom_layout_add_region(flash->default_layout,
 			0, flash->chip->total_size * 1024 - 1, "complete flash") ||
-	    flashrom_layout_include_region(&fallback->base, "complete flash"))
-		return -1;
+	    flashrom_layout_include_region(flash->default_layout, "complete flash"))
+	        return -1;
 
 	tmp = flashbuses_to_text(flash->chip->bustype);
 	msg_cinfo("%s %s flash chip \"%s\" (%d kB, %s) ", force ? "Assuming" : "Found",