diff mbox series

[U-Boot] fdt: support booting with dtb in Android image

Message ID 20190115142637.13817-1-shawn.guo@linaro.org
State Accepted
Commit 6a7b406aa8b98155597c408da0764fca85dec377
Delegated to: Tom Rini
Headers show
Series [U-Boot] fdt: support booting with dtb in Android image | expand

Commit Message

Shawn Guo Jan. 15, 2019, 2:26 p.m. UTC
Some platforms choose to store device tree blob in Android image second
area.  Let's try to look for dtb from there when booting an Android
image, and use it for booting if found.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
---
 common/image-fdt.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Tom Rini Feb. 10, 2019, 1:11 p.m. UTC | #1
On Tue, Jan 15, 2019 at 10:26:37PM +0800, Shawn Guo wrote:

> Some platforms choose to store device tree blob in Android image second
> area.  Let's try to look for dtb from there when booting an Android
> image, and use it for booting if found.
> 
> Signed-off-by: Shawn Guo <shawn.guo@linaro.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/common/image-fdt.c b/common/image-fdt.c
index 95748f0ae108..57f150311392 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -230,6 +230,7 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 	ulong		load, load_end;
 	ulong		image_start, image_data, image_end;
 #endif
+	ulong		img_addr;
 	ulong		fdt_addr;
 	char		*fdt_blob = NULL;
 	void		*buf;
@@ -245,6 +246,9 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 	*of_flat_tree = NULL;
 	*of_size = 0;
 
+	img_addr = simple_strtoul(argv[0], NULL, 16);
+	buf = map_sysmem(img_addr, 0);
+
 	if (argc > 2)
 		select = argv[2];
 	if (select || genimg_has_config(images)) {
@@ -415,6 +419,23 @@  int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 			debug("## No Flattened Device Tree\n");
 			goto no_fdt;
 		}
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+	} else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
+		struct andr_img_hdr *hdr = buf;
+		ulong fdt_data, fdt_len;
+
+		if (android_image_get_second(hdr, &fdt_data, &fdt_len) != 0)
+			goto no_fdt;
+
+		fdt_blob = (char *)fdt_data;
+		if (fdt_check_header(fdt_blob) != 0)
+			goto no_fdt;
+
+		if (fdt_totalsize(fdt_blob) != fdt_len)
+			goto error;
+
+		debug("## Using FDT found in Android image second area\n");
+#endif
 	} else {
 		debug("## No Flattened Device Tree\n");
 		goto no_fdt;