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 <[email protected]>
Cc: Stephan Gerhold <[email protected]>
Cc: Simon Glass <[email protected]>
Cc: Sam Protsenko <[email protected]>
Signed-off-by: Linus Walleij <[email protected]>
---
 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

Reply via email to