[PATCH] cmd: abootimg: Accept a DTB in second for index 0

Linus Walleij linus.walleij at linaro.org
Thu Feb 17 00:16:47 CET 2022


If the user is using an old Android image (version < 2)
there are no special DTB pointers. What systems do in this
case is to use the "second" area for a DTB, and this is
what bootm is falling back to when booting and abootimg,
see image-fdt.c function boot_get_fdt().

So since I need this on some PostmarkeOS systems to modify
DTBs on-the-fly, make the abootimg also recognize and fall
back to using "second" if the Android image header is < 2.

Cc: Markuss Broks <markuss.broks at gmail.com>
Cc: Stephan Gerhold <stephan at gerhold.net>
Cc: Simon Glass <sjg at chromium.org>
Cc: Sam Protsenko <joe.skb7 at gmail.com>
Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
---
 cmd/abootimg.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/cmd/abootimg.c b/cmd/abootimg.c
index f48a9dcb021d..fd4c102d909f 100644
--- a/cmd/abootimg.c
+++ b/cmd/abootimg.c
@@ -119,7 +119,19 @@ static int abootimg_get_dtb_by_index(int argc, char *const argv[])
 
 	if (!android_image_get_dtb_by_index(abootimg_addr(), num,
 					    &addr, &size)) {
-		return CMD_RET_FAILURE;
+		/*
+		 * If we are asking for index 0 and have header v1 we fall back
+		 * to getting the FDT from the "second" area.
+		 */
+		const struct andr_img_hdr *hdr = (const struct andr_img_hdr *)abootimg_addr();
+		ulong tmp;
+
+		if (num == 0 && !android_image_get_second(hdr, &addr, &tmp)) {
+			size = tmp;
+			printf("Using FDT in Android image second area for index 0\n");
+		} else {
+			return CMD_RET_FAILURE;
+		}
 	}
 
 	if (argc == 1) {
-- 
2.34.1



More information about the U-Boot mailing list