diff mbox series

cmd: abootimg: Accept a DTB in second for index 0

Message ID 20220216231647.1314798-1-linus.walleij@linaro.org
State New
Headers show
Series cmd: abootimg: Accept a DTB in second for index 0 | expand

Commit Message

Linus Walleij Feb. 16, 2022, 11:16 p.m. UTC
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@gmail.com>
Cc: Stephan Gerhold <stephan@gerhold.net>
Cc: Simon Glass <sjg@chromium.org>
Cc: Sam Protsenko <joe.skb7@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 cmd/abootimg.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

Comments

Simon Glass Feb. 26, 2022, 6:37 p.m. UTC | #1
Hi Linus,

On Wed, 16 Feb 2022 at 16:18, Linus Walleij <linus.walleij@linaro.org> wrote:
>
> 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@gmail.com>
> Cc: Stephan Gerhold <stephan@gerhold.net>
> Cc: Simon Glass <sjg@chromium.org>
> Cc: Sam Protsenko <joe.skb7@gmail.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
>  cmd/abootimg.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
>

Please update test/py/tests/test_android/test_avb.py

Regards,
Simo
n
diff mbox series

Patch

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) {