]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
ARM: uniphier: support eMMC boot for PH1-LD11 and PH1-LD20
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Sat, 4 Jun 2016 13:39:08 +0000 (22:39 +0900)
committerMasahiro Yamada <yamada.masahiro@socionext.com>
Wed, 8 Jun 2016 23:17:49 +0000 (08:17 +0900)
The Boot ROM on PH1-LD11/LD20 exports built-in APIs to load images
from an eMMC device.  They are useful to reduce the memory footprint
of SPL, rather than compiling the whole MMC framework.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
arch/arm/mach-uniphier/boot-mode/Makefile
arch/arm/mach-uniphier/boot-mode/boot-mode.c
arch/arm/mach-uniphier/boot-mode/spl_board.c [new file with mode: 0644]
include/configs/uniphier.h

index d7fefc5bbd0d6af8e7df8e3f00247fcafb7c749d..a8980210b1cbb3082161333e16ef8fefb1d94cca 100644 (file)
@@ -14,4 +14,8 @@ obj-$(CONFIG_ARCH_UNIPHIER_LD6B)      += boot-mode-pxs2.o
 obj-$(CONFIG_ARCH_UNIPHIER_LD11)       += boot-mode-ld20.o
 obj-$(CONFIG_ARCH_UNIPHIER_LD20)       += boot-mode-ld20.o
 
+ifdef CONFIG_SPL_BUILD
+obj-$(CONFIG_SPL_BOARD_LOAD_IMAGE)     += spl_board.o
+else
 obj-$(CONFIG_CMD_PINMON) += cmd_pinmon.o
+endif
index 4b744da2529af728733b90da39028ff8d046cda1..d34b9af9a18700b4d4dcfc643d442bb9c5867bc8 100644 (file)
@@ -51,11 +51,30 @@ u32 spl_boot_device_raw(void)
 
 u32 spl_boot_device(void)
 {
-       u32 ret;
+       u32 mode;
 
-       ret = spl_boot_device_raw();
+       mode = spl_boot_device_raw();
 
-       return ret == BOOT_DEVICE_USB ? BOOT_DEVICE_NOR : ret;
+       switch (uniphier_get_soc_type()) {
+#if defined(CONFIG_ARCH_UNIPHIER_PXS2) || defined(CONFIG_ARCH_UNIPHIER_LD6B)
+       case SOC_UNIPHIER_PXS2:
+       case SOC_UNIPHIER_LD6B:
+               if (mode == BOOT_DEVICE_USB)
+                       mode = BOOT_DEVICE_NOR;
+               break;
+#endif
+#if defined(CONFIG_ARCH_UNIPHIER_LD11) || defined(CONFIG_ARCH_UNIPHIER_LD20)
+       case SOC_UNIPHIER_LD11:
+       case SOC_UNIPHIER_LD20:
+               if (mode == BOOT_DEVICE_MMC1 || mode == BOOT_DEVICE_USB)
+                       mode = BOOT_DEVICE_BOARD;
+               break;
+#endif
+       default:
+               break;
+       }
+
+       return mode;
 }
 
 u32 spl_boot_mode(void)
diff --git a/arch/arm/mach-uniphier/boot-mode/spl_board.c b/arch/arm/mach-uniphier/boot-mode/spl_board.c
new file mode 100644 (file)
index 0000000..86292b6
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2016 Socionext Inc.
+ *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <spl.h>
+#include <linux/io.h>
+#include <asm/processor.h>
+
+#include "../soc-info.h"
+
+void spl_board_announce_boot_device(void)
+{
+       printf("eMMC");
+}
+
+struct uniphier_romfunc_table {
+       void *mmc_send_cmd;
+       void *mmc_card_blockaddr;
+       void *mmc_switch_part;
+       void *mmc_load_image;
+};
+
+static const struct uniphier_romfunc_table uniphier_ld11_romfunc_table = {
+       .mmc_send_cmd = (void *)0x20d8,
+       .mmc_card_blockaddr = (void *)0x1b68,
+       .mmc_switch_part = (void *)0x1c38,
+       .mmc_load_image = (void *)0x2e48,
+};
+
+static const struct uniphier_romfunc_table uniphier_ld20_romfunc_table = {
+       .mmc_send_cmd = (void *)0x2130,
+       .mmc_card_blockaddr = (void *)0x1ba0,
+       .mmc_switch_part = (void *)0x1c70,
+       .mmc_load_image = (void *)0x2ef0,
+};
+
+int uniphier_rom_get_mmc_funcptr(int (**send_cmd)(u32, u32),
+                                int (**card_blockaddr)(u32),
+                                int (**switch_part)(int),
+                                int (**load_image)(u32, uintptr_t, u32))
+{
+       const struct uniphier_romfunc_table *table;
+
+       switch (uniphier_get_soc_type()) {
+       case SOC_UNIPHIER_LD11:
+               table = &uniphier_ld11_romfunc_table;
+               break;
+       case SOC_UNIPHIER_LD20:
+               table = &uniphier_ld20_romfunc_table;
+               break;
+       default:
+               printf("unsupported SoC\n");
+               return -EINVAL;
+       }
+
+       *send_cmd = table->mmc_send_cmd;
+       *card_blockaddr = table->mmc_card_blockaddr;
+       *switch_part = table->mmc_switch_part;
+       *load_image = table->mmc_load_image;
+
+       return 0;
+}
+
+int spl_board_load_image(void)
+{
+       int (*send_cmd)(u32 cmd, u32 arg);
+       int (*card_blockaddr)(u32 rca);
+       int (*switch_part)(int part);
+       int (*load_image)(u32 dev_addr, uintptr_t load_addr, u32 block_cnt);
+       u32 dev_addr = CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
+       const u32 rca = 0x1000; /* RCA assigned by Boot ROM */
+       int ret;
+
+       ret = uniphier_rom_get_mmc_funcptr(&send_cmd, &card_blockaddr,
+                                          &switch_part, &load_image);
+       if (ret)
+               return ret;
+
+       /*
+        * deselect card before SEND_CSD command.
+        * Do not check the return code.  It fails, but it is OK.
+        */
+       (*send_cmd)(0x071a0000, 0); /* CMD7 (arg=0) */
+
+       /* reset CMD Line */
+       writeb(0x6, 0x5a00022f);
+       while (readb(0x5a00022f))
+               cpu_relax();
+
+       ret = (*card_blockaddr)(rca);
+       if (ret) {
+               debug("card is block addressing\n");
+       } else {
+               debug("card is byte addressing\n");
+               dev_addr *= 512;
+       }
+
+       ret = (*send_cmd)(0x071a0000, rca << 16); /* CMD7: select card again */
+       if (ret)
+               printf("failed to select card\n");
+
+       ret = (*switch_part)(1); /* Switch to Boot Partition 1 */
+       if (ret)
+               printf("failed to switch partition\n");
+
+       ret = (*load_image)(dev_addr, CONFIG_SYS_TEXT_BASE, 1);
+       if (ret) {
+               printf("failed to load image\n");
+               return ret;
+       }
+
+       ret = spl_parse_image_header((void *)CONFIG_SYS_TEXT_BASE);
+       if (ret)
+               return ret;
+
+       ret = (*load_image)(dev_addr, spl_image.load_addr,
+                           spl_image.size / 512);
+       if (ret) {
+               printf("failed to load image\n");
+               return ret;
+       }
+
+       return 0;
+}
index 10fd8c21ea53b3d910437d96eb4d833efbe0c04d..058ccd8d8e03585f796c73f9fe119156b38846ec 100644 (file)
 #define CONFIG_SPL_FRAMEWORK
 #define CONFIG_SPL_SERIAL_SUPPORT
 #define CONFIG_SPL_NOR_SUPPORT
-#ifndef CONFIG_ARM64
+#ifdef CONFIG_ARM64
+#define CONFIG_SPL_BOARD_LOAD_IMAGE
+#else
 #define CONFIG_SPL_NAND_SUPPORT
 #define CONFIG_SPL_MMC_SUPPORT
 #endif