diff mbox

[U-Boot,1/5] i.MX6Q: icorem6: Add modeboot env via board_late_init

Message ID 1490637743-18535-1-git-send-email-jagan@openedev.com
State Accepted
Commit 98f5661033a250b6333460cf1d2bb628c8d66e3d
Delegated to: Stefano Babic
Headers show

Commit Message

Jagan Teki March 27, 2017, 6:02 p.m. UTC
From: Jagan Teki <jagan@amarulasolutions.com>

Add runtime, modeboot env which is setting mmcboot, or
nandboot based on the bootdevice so-that conditional
macros b/w MMC and NAND for CONFIG_BOOTCOMMAND should
be avoided in config files.

Cc: Matteo Lisi <matteo.lisi@engicam.com>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Cc: Stefano Babic <sbabic@denx.de>
Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
---
 arch/arm/cpu/armv7/mx6/Kconfig  |  1 +
 board/engicam/icorem6/icorem6.c | 19 +++++++++++++++++++
 include/configs/imx6qdl_icore.h | 36 ++++++++++++++++--------------------
 3 files changed, 36 insertions(+), 20 deletions(-)

Comments

Jagan Teki April 25, 2017, 6:34 p.m. UTC | #1
Hi Stefano,

On Mon, Apr 17, 2017 at 9:18 PM, Jagan Teki <jagannadh.teki@gmail.com> wrote:
> On Wed, Apr 12, 2017 at 9:27 PM, Stefano Babic <sbabic@denx.de> wrote:
>> On 07/04/2017 19:50, Jagan Teki wrote:
>>> Hi Stefano,
>>>
>>> On Mon, Mar 27, 2017 at 11:32 PM, Jagan Teki <jagan@openedev.com> wrote:
>>>> From: Jagan Teki <jagan@amarulasolutions.com>
>>>>
>>>> Add runtime, modeboot env which is setting mmcboot, or
>>>> nandboot based on the bootdevice so-that conditional
>>>> macros b/w MMC and NAND for CONFIG_BOOTCOMMAND should
>>>> be avoided in config files.
>>>>
>>>> Cc: Matteo Lisi <matteo.lisi@engicam.com>
>>>> Cc: Michael Trimarchi <michael@amarulasolutions.com>
>>>> Cc: Stefano Babic <sbabic@denx.de>
>>>> Signed-off-by: Jagan Teki <jagan@amarulasolutions.com>
>>>
>>> Can you take this series?
>>>
>>
>> I could take, but I am just asking if you do not find another way to
>> avoid code duplication. You have very similar boards, and code is simply
>> duplicated. Let's see Pathch 1/5 and Patch 3/5:
>>
>>
>> +int board_late_init(void)
>> +{
>> +       switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
>> +                       IMX6_BMODE_SHIFT) {
>> +       case IMX6_BMODE_SD:
>> +       case IMX6_BMODE_ESD:
>> +               setenv("modeboot", "mmcboot");
>> +               break;
>> +       case IMX6_BMODE_NAND:
>> +               setenv("modeboot", "nandboot");
>> +               break;
>> +       default:
>> +               setenv("modeboot", "");
>> +               break;
>> +       }
>> +
>> +       return 0;
>> +}
>>
>> And patch 3/5:
>>
>> +int board_late_init(void)
>> +{
>> +       switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
>> +                       IMX6_BMODE_SHIFT) {
>> +       case IMX6_BMODE_SD:
>> +       case IMX6_BMODE_ESD:
>> +               setenv("modeboot", "mmcboot");
>> +               break;
>> +       case IMX6_BMODE_NAND:
>> +               setenv("modeboot", "nandboot");
>> +               break;
>> +       default:
>> +               setenv("modeboot", "");
>> +               break;
>> +       }
>> +
>> +       return 0;
>> +}
>> +
>>
>>
>> Why do you not use the same factorization as for Freescale's boards ? A
>> board/engicam/common could contain shared code, and you reuse it among
>> boards. The same for the default environment: it is duplicated again.
>
> Yes, I understand completely. will factorized the code in coming MW.

Any help?

thanks!
diff mbox

Patch

diff --git a/arch/arm/cpu/armv7/mx6/Kconfig b/arch/arm/cpu/armv7/mx6/Kconfig
index 9174136..37f271b 100644
--- a/arch/arm/cpu/armv7/mx6/Kconfig
+++ b/arch/arm/cpu/armv7/mx6/Kconfig
@@ -160,6 +160,7 @@  config TARGET_MX6QARM2
 
 config TARGET_MX6Q_ICORE
 	bool "Support Engicam i.Core"
+	select BOARD_LATE_INIT
 	select MX6QDL
 	select OF_CONTROL
 	select DM
diff --git a/board/engicam/icorem6/icorem6.c b/board/engicam/icorem6/icorem6.c
index 171ec45..f78f8c9 100644
--- a/board/engicam/icorem6/icorem6.c
+++ b/board/engicam/icorem6/icorem6.c
@@ -205,6 +205,25 @@  int board_early_init_f(void)
 	return 0;
 }
 
+int board_late_init(void)
+{
+	switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
+			IMX6_BMODE_SHIFT) {
+	case IMX6_BMODE_SD:
+	case IMX6_BMODE_ESD:
+		setenv("modeboot", "mmcboot");
+		break;
+	case IMX6_BMODE_NAND:
+		setenv("modeboot", "nandboot");
+		break;
+	default:
+		setenv("modeboot", "");
+		break;
+	}
+
+	return 0;
+}
+
 int board_init(void)
 {
 	/* Address of boot parameters */
diff --git a/include/configs/imx6qdl_icore.h b/include/configs/imx6qdl_icore.h
index 5a28b15..b517e87 100644
--- a/include/configs/imx6qdl_icore.h
+++ b/include/configs/imx6qdl_icore.h
@@ -64,7 +64,7 @@ 
 	"fitboot=echo Booting FIT image from mmc ...; " \
 		"run mmcargs; " \
 		"bootm ${loadaddr}\0" \
-	"mmcboot=echo Booting from mmc ...; " \
+	"_mmcboot=run mmcargs; " \
 		"run mmcargs; " \
 		"if test ${boot_fdt} = yes || test ${boot_fdt} = try; then " \
 			"if run loadfdt; then " \
@@ -79,6 +79,20 @@ 
 		"else " \
 			"bootm; " \
 		"fi\0" \
+	"mmcboot=echo Booting from mmc ...; " \
+		"if mmc rescan; then " \
+			"if run loadbootscript; then " \
+				"run bootscript; " \
+			"else " \
+				"if run loadfit; then " \
+					"run fitboot; " \
+				"else " \
+					"if run loadimage; then " \
+						"run _mmcboot; " \
+					"fi; " \
+				"fi; " \
+			"fi; " \
+		"fi\0" \
 	"nandboot=echo Booting from nand ...; " \
 		"if mtdparts; then " \
 			"echo Starting nand boot ...; " \
@@ -90,25 +104,7 @@ 
 		"nand read ${fdt_addr} dtb 0x100000; " \
 		"bootm ${loadaddr} - ${fdt_addr}\0"
 
-#ifdef CONFIG_NAND_MXS
-# define CONFIG_BOOTCOMMAND		"run nandboot"
-#else
-# define CONFIG_BOOTCOMMAND \
-	"mmc dev ${mmcdev};" \
-	"if mmc rescan; then " \
-		"if run loadbootscript; then " \
-			"run bootscript; " \
-		"else " \
-			"if run loadfit; then " \
-				"run fitboot; " \
-			"else " \
-				"if run loadimage; then " \
-					"run mmcboot; " \
-				"fi; " \
-			"fi; " \
-		"fi; " \
-	"fi"
-#endif
+#define CONFIG_BOOTCOMMAND		"run $modeboot"
 
 /* Miscellaneous configurable options */
 #define CONFIG_SYS_MEMTEST_START	0x80000000