[U-Boot] [PATCH 2/2] [rfc] support booting arm64 android image

Bin Chen bin.chen at linaro.org
Tue Jul 11 05:56:04 UTC 2017


It's my understanding that we are supposed to use booti, instead of bootm,
for arm64 image. But booti lacks of android image support. Bootm has
the andriod image support but lack of the arm64 image handling.

So, what is suppose the right way of booting an android arm64 image?
or, should we create a separate command?

This patch is an invitation for that discussion.

It *hacked* the booti command and it aslo assume the dtb is in the second area
of android boot image. It also has other belives like u-boot should be
in control of where to put the kernnel/ramdisk/dtb images so it ignores
the value specified in the android images.

Signed-off-by: Bin Chen <bin.chen at linaro.org>
---
 cmd/booti.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 79 insertions(+), 1 deletion(-)

diff --git a/cmd/booti.c b/cmd/booti.c
index da6fb01..8fab96c 100644
--- a/cmd/booti.c
+++ b/cmd/booti.c
@@ -9,8 +9,10 @@
 #include <bootm.h>
 #include <command.h>
 #include <image.h>
+#include <libfdt.h>
 #include <lmb.h>
 #include <mapmem.h>
+#include <stdlib.h>
 #include <linux/kernel.h>
 #include <linux/sizes.h>
 
@@ -130,7 +132,7 @@ static int booti_start(cmd_tbl_t *cmdtp, int flag, int argc,
 	return 0;
 }
 
-int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_booti_a(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	int ret;
 
@@ -159,6 +161,82 @@ int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	return ret;
 }
 
+int do_booti(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	struct andr_img_hdr *hdr;
+	ulong kernel_addr = 0;
+	ulong kernel_len = 0;
+	ulong ramdisk_addr = 0;
+	ulong ramdisk_len = 0;
+	ulong fdt_addr = 0;
+	ulong fdt_len = 0;
+	ulong ramdisk_addr_env = 0;
+	ulong fdt_addr_env = 0;
+
+	if (argc == 4) {
+		debug("normal %s %s %s %s\n", argv[0], argv[1], argv[2], argv[3]);
+		return do_booti_a(cmdtp, flag, argc, argv);
+	}
+
+	debug("boot android arm64 bootimage\n");
+	hdr = (struct andr_img_hdr *)simple_strtoul(argv[1], NULL, 16);
+	if (android_image_check_header(hdr)) {
+		printf("invalid android image\n");
+		return -1;
+	}
+
+	android_image_get_kernel(hdr, false, &kernel_addr, &kernel_len);
+	android_image_get_ramdisk(hdr, &ramdisk_addr, &ramdisk_len);
+	android_image_get_second(hdr, &fdt_addr, &fdt_len);
+
+	if (fdt_check_header((void*)fdt_addr)) {
+		printf(" error: invalid fdt\n");
+		return -1;
+	}
+
+	/* relocate ramdisk and fdt to the address defined by the environment variable.
+	 * that means we'll ignore the load address of ramdisk and dtb defined in the
+	 * abootimg, since it make more sense letting u-boot handling where to put what.
+	 * kernel relocation will be handled in booti_setup
+	 */
+	ramdisk_addr_env = getenv_ulong("ramdisk_addr_r", 16, 0);;
+	fdt_addr_env = getenv_ulong("fdt_addr_r", 16, 0);
+
+	if (!ramdisk_addr_env) {
+		printf(" error: didn't define ramdisk_addr_r\n");
+		return -1;
+	}
+	memmove((void *)ramdisk_addr_env, (void *)ramdisk_addr, ramdisk_len);
+
+	if (!fdt_addr_env) {
+		printf(" error: didn't define fdt_addr_r\n");
+		return -1;
+	}
+	memmove((void *)fdt_addr_env, (void *)fdt_addr, fdt_len);
+
+	const int max_length = 40;
+	const int new_argc = 4;
+	char *new_argv[new_argc];
+
+	for (int i = 0; i < new_argc; i++) {
+		new_argv[i] = (char*) malloc(max_length);
+	}
+
+	strcpy(new_argv[0], "booti");
+	snprintf(new_argv[1], max_length, "0x%lx", kernel_addr);
+	snprintf(new_argv[2], max_length, "0x%lx:%ld", ramdisk_addr_env,ramdisk_len);
+	snprintf(new_argv[3], max_length, "0x%lx", fdt_addr_env);
+
+	debug("android: %s %s %s %s\n", new_argv[0], new_argv[1], new_argv[2], new_argv[3]);
+
+	int ret = do_booti_a(cmdtp, flag, new_argc, new_argv);
+
+	for (int i = 0; i < new_argc; i++) {
+		free(new_argv[i]);
+	}
+
+	return ret;
+}
 #ifdef CONFIG_SYS_LONGHELP
 static char booti_help_text[] =
 	"[addr [initrd[:size]] [fdt]]\n"
-- 
1.9.1



More information about the U-Boot mailing list