summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoy Cho <joy.cho@hardkernel.com>2017-12-27 05:17:12 +0300
committerJoy Cho <joy.cho@hardkernel.com>2017-12-28 04:34:56 +0300
commitdeed6a89bf577f87ac933fac2e6dfdf5ad65a53f (patch)
tree13f6fb327ca67af7f57f010620aaaa095c4c1edf
parent58374392dffce4951a7a1de780a844c5f1ddd579 (diff)
downloadu-boot-deed6a89bf577f87ac933fac2e6dfdf5ad65a53f.tar.xz
Add boot device detection logic to operate flexible mmc orders
In case of rk3399 platform, there is no way to detect boot storage from chip side, so mmc orders are fixed based on aliases setting. - mmc0 : sdhci (eMMC) / mmc1 : dwmmc (SD) To be available to use both of eMMC and SD with a single image, this storage scanning logic is introduced. Change-Id: Iecb3778b43c096a0b0eeba1741763b7bc10013e8
-rw-r--r--board/rockchip/odroidn1/Makefile1
-rw-r--r--board/rockchip/odroidn1/odroidn1-disk.c104
-rw-r--r--board/rockchip/odroidn1/odroidn1.c14
-rw-r--r--cmd/cfgload.c5
-rw-r--r--drivers/mmc/mmc-uclass.c9
-rw-r--r--include/configs/odroidn1.h16
6 files changed, 143 insertions, 6 deletions
diff --git a/board/rockchip/odroidn1/Makefile b/board/rockchip/odroidn1/Makefile
index bad5e036ac..7904b48f43 100644
--- a/board/rockchip/odroidn1/Makefile
+++ b/board/rockchip/odroidn1/Makefile
@@ -5,3 +5,4 @@
#
obj-y += odroidn1.o
+obj-y += odroidn1-disk.o
diff --git a/board/rockchip/odroidn1/odroidn1-disk.c b/board/rockchip/odroidn1/odroidn1-disk.c
new file mode 100644
index 0000000000..8ccbdbdc0c
--- /dev/null
+++ b/board/rockchip/odroidn1/odroidn1-disk.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2017 Hardkernel Co,. Ltd
+ * Joy Cho <joy.cho@hardkernel.com>
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+#include <common.h>
+#include <linux/sizes.h>
+#include <linux/string.h>
+#include <mmc.h>
+
+/*
+ * Scan all of boot devices and check magic pattern
+ * magic1 : 6 chars of fixed uboot header pattern
+ * magic2 : 4 chars of fixed trust header pattern
+ */
+#define MMC_DEV_SDHCI 0 /* sdhci@fe330000 */
+#define MMC_DEV_DWMMC 1 /* sdmmc@fe320000 */
+#define MAGIC_OFFSET1 16384
+#define MAGIC_OFFSET2 24576
+static const char *magic1 = "LOADER";
+static const char *magic2 = "BL3X";
+
+int board_check_magic(struct blk_desc *dev_desc)
+{
+ char pattern[512];
+
+ /* Check magic1 */
+ if (blk_dread(dev_desc, MAGIC_OFFSET1, 1, pattern) != 1) {
+ printf("scan boot: block read fail\n");
+ return -EIO;
+ }
+
+ if (0 != strncmp(pattern, magic1, strlen(magic1))) {
+ printf("scan boot: magic1 fail");
+ return -EIO;
+ }
+
+ /* Check magic2 */
+ if (blk_dread(dev_desc, MAGIC_OFFSET2, 1, pattern) != 1) {
+ printf("scan boot: block read fail\n");
+ return -EIO;
+ }
+
+ if (0 != strncmp(pattern, magic2, strlen(magic2))) {
+ printf("scan boot: magic2 fail");
+ return -EIO;
+ }
+
+ return 0;
+}
+
+int board_scan_boot_storage(void)
+{
+ struct mmc *mmc;
+ struct blk_desc *dev_desc;
+
+ /* First, try checking eMMC */
+ mmc = find_mmc_device(MMC_DEV_SDHCI);
+ if (!mmc) {
+ printf("no sdhci device\n");
+ } else {
+ dev_desc = blk_get_dev("mmc", MMC_DEV_SDHCI);
+ if (dev_desc) {
+ if (0 == board_check_magic(dev_desc)) {
+ /* Two magic patterns are available
+ * on eMMC, so related env is set
+ * and then exit this routine.
+ */
+ char *s = getenv("storagemedia");
+ if ((s == 0) || (strcmp(s, "emmc") != 0)) {
+ setenv("storagemedia", "emmc");
+ setenv("bootdev", "0");
+ saveenv();
+ }
+
+ return 0;
+ }
+ }
+ }
+
+ /* No emmc magic, now try sdmmc */
+ mmc = find_mmc_device(MMC_DEV_DWMMC);
+ if (!mmc) {
+ printf("no sdmmc device, no way...\n");
+ } else {
+ dev_desc = blk_get_dev("mmc", MMC_DEV_DWMMC);
+ if (dev_desc) {
+ if (0 == board_check_magic(dev_desc)) {
+ char *s = getenv("storagemedia");
+ if ((s == 0) || (strcmp(s, "sd") != 0)) {
+ setenv("storagemedia", "sd");
+ setenv("bootdev", "1");
+ saveenv();
+ }
+
+ return 0;
+ }
+ }
+ }
+
+ return -EIO;
+}
diff --git a/board/rockchip/odroidn1/odroidn1.c b/board/rockchip/odroidn1/odroidn1.c
index 73fb90875d..d61c33b56e 100644
--- a/board/rockchip/odroidn1/odroidn1.c
+++ b/board/rockchip/odroidn1/odroidn1.c
@@ -15,6 +15,20 @@
DECLARE_GLOBAL_DATA_PTR;
+extern int board_scan_boot_storage(void);
+
+#ifdef CONFIG_BOARD_LATE_INIT
+int board_late_init(void)
+{
+ if (board_scan_boot_storage() != 0) {
+ printf("board: scan boot stoarge fail\n");
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
int board_init(void)
{
struct udevice *pinctrl, *regulator;
diff --git a/cmd/cfgload.c b/cmd/cfgload.c
index caaf5b7bb2..2da7548e65 100644
--- a/cmd/cfgload.c
+++ b/cmd/cfgload.c
@@ -51,6 +51,7 @@ static char* read_cfgload(void)
unsigned long filesize;
char *p;
char *tmp;
+ u32 dev_no;
tmp = getenv("loadaddr");
if (NULL == tmp)
@@ -60,7 +61,9 @@ static char* read_cfgload(void)
setenv("filesize", "0");
- sprintf(cmd, "fatload mmc 0:1 0x%p boot.ini", (void *)p);
+ dev_no = getenv_ulong("bootdev", 10, 0);
+
+ sprintf(cmd, "fatload mmc %d:1 0x%p boot.ini", dev_no, (void *)p);
run_command(cmd, 0);
filesize = getenv_ulong("filesize", 16, 0);
diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c
index 229b83b475..30d0b2a4b3 100644
--- a/drivers/mmc/mmc-uclass.c
+++ b/drivers/mmc/mmc-uclass.c
@@ -287,7 +287,16 @@ static int mmc_blk_probe(struct udevice *dev)
ret = mmc_init(mmc);
if (ret) {
debug("%s: mmc_init() failed (err=%d)\n", __func__, ret);
+#ifndef CONFIG_TARGET_ODROIDN1
+ /* In case of rk3399 platform, there is no way to detect
+ * boot storage from chip side, so mmc orders are fixed.
+ * If first boot storage gets fail, this routine blocks
+ * trying next mmc list. So just as a workaround, this
+ * will be blocked until we find a better solution
+ * to handle a flexible boot order assignment.
+ */
return ret;
+#endif
}
return 0;
diff --git a/include/configs/odroidn1.h b/include/configs/odroidn1.h
index 7491948d4c..a411eb0d08 100644
--- a/include/configs/odroidn1.h
+++ b/include/configs/odroidn1.h
@@ -36,10 +36,16 @@
#undef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
- "bootargs=earlyprintk swiotlb=1 console=ttyFIQ0,115200n8 " \
- "rw root=/dev/mmcblk1p2 rootfstype=ext4 rootwait\0" \
- "bootcmd=cfgload; load mmc 0 0x02000000 Image; " \
- "load mmc 0 0x04000000 uInitrd; " \
- "load mmc 0 0x01f00000 rk3399-odroidn1-linux.dtb; " \
+ "setbootargs=setenv bootargs earlyprintk swiotlb=1 " \
+ "console=ttyFIQ0,115200n8 " \
+ "rw root=/dev/mmcblk1p2 rootfstype=ext4 rootwait " \
+ "storagemedia=${storagemedia}\0" \
+ "bootcmd=cfgload; run setbootargs; mmc dev ${bootdev}; " \
+ "load mmc ${bootdev} 0x02000000 Image; " \
+ "load mmc ${bootdev} 0x04000000 uInitrd; " \
+ "load mmc ${bootdev} 0x01f00000 rk3399-odroidn1-linux.dtb; " \
"booti 0x02000000 - 0x01f00000\0"
+
+#define CONFIG_BOARD_LATE_INIT
+
#endif