summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorYe Li <ye.li@nxp.com>2018-06-05 01:34:41 -0700
committerYe Li <ye.li@nxp.com>2018-06-13 03:06:25 -0700
commit2c840c82b3558267650b98735790ac7151644ae1 (patch)
treeb62bd46f634e8a76ec122085113a92a967db6288 /common
parent4ec81a0b075d8d853ac696172660a7771064405d (diff)
MLK-18591-3 android: Add FSL android fastboot support
Porting the FSL android fastboot features from imx u-boot v2017.03 to support all SoCs: imx6/imx7/imx7ulp/imx8/imx8m Signed-off-by: Ye Li <ye.li@nxp.com>
Diffstat (limited to 'common')
-rw-r--r--common/autoboot.c4
-rw-r--r--common/board_r.c23
-rw-r--r--common/image-android.c136
-rw-r--r--common/image-fdt.c31
4 files changed, 173 insertions, 21 deletions
diff --git a/common/autoboot.c b/common/autoboot.c
index 1b52e44939..0d826e81df 100644
--- a/common/autoboot.c
+++ b/common/autoboot.c
@@ -311,7 +311,7 @@ const char *bootdelay_process(void)
s = env_get("bootdelay");
bootdelay = s ? (int)simple_strtol(s, NULL, 10) : CONFIG_BOOTDELAY;
-#ifdef is_boot_from_usb
+#if !defined(CONFIG_FSL_FASTBOOT) && defined(is_boot_from_usb)
if (is_boot_from_usb()) {
disconnect_from_pc();
printf("Boot from USB for mfgtools\n");
@@ -349,7 +349,7 @@ const char *bootdelay_process(void)
#endif /* CONFIG_BOOTCOUNT_LIMIT */
s = env_get("bootcmd");
-#ifdef is_boot_from_usb
+#if !defined(CONFIG_FSL_FASTBOOT) && defined(is_boot_from_usb)
if (is_boot_from_usb()) {
s = env_get("bootcmd_mfg");
printf("Run bootcmd_mfg: %s\n", s);
diff --git a/common/board_r.c b/common/board_r.c
index 84d2b251f8..6d6adc13a9 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -54,6 +54,9 @@
#include <linux/compiler.h>
#include <linux/err.h>
#include <efi_loader.h>
+#ifdef CONFIG_FSL_FASTBOOT
+#include <fsl_fastboot.h>
+#endif
DECLARE_GLOBAL_DATA_PTR;
@@ -659,6 +662,20 @@ static int initr_avbkey(void)
}
#endif
+#ifdef CONFIG_FSL_FASTBOOT
+static int initr_fastboot_setup(void)
+{
+ fastboot_setup();
+ return 0;
+}
+
+static int initr_check_fastboot(void)
+{
+ fastboot_run_bootmode();
+ return 0;
+}
+#endif
+
static int run_main_loop(void)
{
#ifdef CONFIG_SANDBOX
@@ -831,6 +848,9 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_BOARD_LATE_INIT
board_late_init,
#endif
+#ifdef CONFIG_FSL_FASTBOOT
+ initr_fastboot_setup,
+#endif
#if defined(CONFIG_SCSI) && !defined(CONFIG_DM_SCSI)
INIT_FUNC_WATCHDOG_RESET
initr_scsi,
@@ -873,6 +893,9 @@ static init_fnc_t init_sequence_r[] = {
#ifdef AVB_RPMB
initr_avbkey,
#endif
+#ifdef CONFIG_FSL_FASTBOOT
+ initr_check_fastboot,
+#endif
run_main_loop,
};
diff --git a/common/image-android.c b/common/image-android.c
index 5ad3a1fa38..07d82d5459 100644
--- a/common/image-android.c
+++ b/common/image-android.c
@@ -1,6 +1,9 @@
/*
* Copyright (c) 2011 Sebastian Andrzej Siewior <bigeasy@linutronix.de>
*
+ * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
+ * Copyright 2017 NXP
+ *
* SPDX-License-Identifier: GPL-2.0+
*/
@@ -9,6 +12,11 @@
#include <android_image.h>
#include <malloc.h>
#include <errno.h>
+#include <asm/bootm.h>
+#include <asm/mach-imx/boot_mode.h>
+#include <asm/arch/sys_proto.h>
+#include <fsl_fastboot.h>
+#include <asm/setup.h>
#define ANDROID_IMAGE_DEFAULT_KERNEL_ADDR 0x10008000
@@ -51,6 +59,7 @@ static ulong android_image_get_kernel_addr(const struct andr_img_hdr *hdr)
int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
ulong *os_data, ulong *os_len)
{
+ extern boot_metric metrics;
u32 kernel_addr = android_image_get_kernel_addr(hdr);
/*
@@ -66,31 +75,110 @@ int android_image_get_kernel(const struct andr_img_hdr *hdr, int verify,
printf("Kernel load addr 0x%08x size %u KiB\n",
kernel_addr, DIV_ROUND_UP(hdr->kernel_size, 1024));
- int len = 0;
- if (*hdr->cmdline) {
- printf("Kernel command line: %s\n", hdr->cmdline);
- len += strlen(hdr->cmdline);
+ char newbootargs[512] = {0};
+ char commandline[2048] = {0};
+ char *bootargs = env_get("bootargs");
+
+ if (bootargs) {
+ if (strlen(bootargs) + 1 > sizeof(commandline)) {
+ printf("bootargs is too long!\n");
+ return -1;
+ }
+ else
+ strncpy(commandline, bootargs, sizeof(commandline) - 1);
+ } else if (*hdr->cmdline) {
+ if (strlen(hdr->cmdline) + 1 > sizeof(commandline)) {
+ printf("cmdline in bootimg is too long!\n");
+ return -1;
+ }
+ else
+ strncpy(commandline, hdr->cmdline, strlen(commandline) - 1);
}
- char *bootargs = env_get("bootargs");
- if (bootargs)
- len += strlen(bootargs);
+#ifdef CONFIG_SERIAL_TAG
+ struct tag_serialnr serialnr;
+ get_board_serial(&serialnr);
- char *newbootargs = malloc(len + 2);
- if (!newbootargs) {
- puts("Error: malloc in android_image_get_kernel failed!\n");
- return -ENOMEM;
+ sprintf(newbootargs,
+ " androidboot.serialno=%08x%08x",
+ serialnr.high,
+ serialnr.low);
+ strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
+#endif
+
+ /* append soc type into bootargs */
+ char *soc_type = env_get("soc_type");
+ if (soc_type) {
+ sprintf(newbootargs,
+ " androidboot.soc_type=%s",
+ soc_type);
+ strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
}
- *newbootargs = '\0';
- if (bootargs) {
- strcpy(newbootargs, bootargs);
- strcat(newbootargs, " ");
+ int bootdev = get_boot_device();
+ if (bootdev == SD1_BOOT || bootdev == SD2_BOOT ||
+ bootdev == SD3_BOOT || bootdev == SD4_BOOT) {
+ sprintf(newbootargs,
+ " androidboot.storage_type=sd");
+ } else if (bootdev == MMC1_BOOT || bootdev == MMC2_BOOT ||
+ bootdev == MMC3_BOOT || bootdev == MMC4_BOOT) {
+ sprintf(newbootargs,
+ " androidboot.storage_type=emmc");
+ } else if (bootdev == NAND_BOOT) {
+ sprintf(newbootargs,
+ " androidboot.storage_type=nand");
+ } else
+ printf("boot device type is incorrect.\n");
+ strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
+ if (bootloader_gpt_overlay()) {
+ sprintf(newbootargs, " gpt");
+ strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
}
- if (*hdr->cmdline)
- strcat(newbootargs, hdr->cmdline);
- env_set("bootargs", newbootargs);
+ /* boot metric variables */
+ metrics.ble_1 = get_timer(0);
+ sprintf(newbootargs,
+ " androidboot.boottime=1BLL:%d,1BLE:%d,KL:%d,KD:%d,AVB:%d,ODT:%d,SW:%d",
+ metrics.bll_1, metrics.ble_1, metrics.kl, metrics.kd, metrics.avb,
+ metrics.odt, metrics.sw);
+ strncat(commandline, newbootargs, sizeof(commandline) - strlen(commandline));
+
+#ifdef CONFIG_AVB_SUPPORT
+ /* secondary cmdline added by avb */
+ char *bootargs_sec = env_get("bootargs_sec");
+ if (bootargs_sec) {
+ strncat(commandline, " ", sizeof(commandline) - strlen(commandline));
+ strncat(commandline, bootargs_sec, sizeof(commandline) - strlen(commandline));
+ }
+#endif
+#ifdef CONFIG_SYSTEM_RAMDISK_SUPPORT
+ /* Normal boot:
+ * cmdline to bypass ramdisk in boot.img, but use the system.img
+ * Recovery boot:
+ * Use the ramdisk in boot.img
+ */
+ char *bootargs_3rd = env_get("bootargs_3rd");
+ if (bootargs_3rd) {
+ strncat(commandline, " ", sizeof(commandline) - strlen(commandline));
+ strncat(commandline, bootargs_3rd, sizeof(commandline) - strlen(commandline));
+ }
+#endif
+
+ /* Add 'append_bootargs' to hold some paramemters which need to be appended
+ * to bootargs */
+ char *append_bootargs = env_get("append_bootargs");
+ if (append_bootargs) {
+ if (strlen(append_bootargs) + 2 >
+ (sizeof(commandline) - strlen(commandline))) {
+ printf("The 'append_bootargs' is too long to be appended to bootargs\n");
+ } else {
+ strncat(commandline, " ", sizeof(commandline) - strlen(commandline));
+ strncat(commandline, append_bootargs, sizeof(commandline) - strlen(commandline));
+ }
+ }
+
+ printf("Kernel command line: %s\n", commandline);
+ env_set("bootargs", commandline);
if (os_data) {
*os_data = (ulong)hdr;
@@ -202,3 +290,15 @@ void android_print_contents(const struct andr_img_hdr *hdr)
printf("%scmdline: %s\n", p, hdr->cmdline);
}
#endif
+
+#define ARM64_IMAGE_MAGIC 0x644d5241
+bool image_arm64(void *images)
+{
+ struct header_image *ih;
+
+ ih = (struct header_image *)images;
+ debug("image magic: %x\n", ih->magic);
+ if (ih->magic == le32_to_cpu(ARM64_IMAGE_MAGIC))
+ return true;
+ return false;
+}
diff --git a/common/image-fdt.c b/common/image-fdt.c
index 25103ba3b5..5691e964f5 100644
--- a/common/image-fdt.c
+++ b/common/image-fdt.c
@@ -6,6 +6,8 @@
* (C) Copyright 2000-2006
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
*
+ * Copyright (C) 2015-2016 Freescale Semiconductor, Inc.
+ *
* SPDX-License-Identifier: GPL-2.0+
*/
@@ -413,7 +415,34 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
debug("## No Flattened Device Tree\n");
goto no_fdt;
}
- } else {
+ }
+#ifdef CONFIG_ANDROID_BOOT_IMAGE
+ else if (genimg_get_format((void *)images->os.start) ==
+ IMAGE_FORMAT_ANDROID) {
+ ulong fdt_data, fdt_len;
+ android_image_get_second((void *)images->os.start,
+ &fdt_data, &fdt_len);
+
+ if (fdt_len) {
+ fdt_blob = (char *)fdt_data;
+ printf(" Booting using the fdt at 0x%p\n", fdt_blob);
+
+ if (fdt_check_header(fdt_blob) != 0) {
+ fdt_error("image is not a fdt");
+ goto error;
+ }
+
+ if (fdt_totalsize(fdt_blob) != fdt_len) {
+ fdt_error("fdt size != image size");
+ goto error;
+ }
+ } else {
+ debug("## No Flattened Device Tree\n");
+ goto no_fdt;
+ }
+ }
+#endif
+ else {
debug("## No Flattened Device Tree\n");
goto no_fdt;
}