mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support
@ 2018-04-14 17:50 Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 01/17] ARM: i.MX: boot: Coalesce copy-pasted code Andrey Smirnov
                   ` (16 more replies)
  0 siblings, 17 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Everyone:

This patchset is the result of my work on adding support for
bootsource detection of VFxxx as well as fixing a number of
bugs/unsupported corner cases in similar i.MX7 specific code.

NOTE: While VFxxx support is added in this series the code integrating
it into the SoC initalization sequnce is not included. Patch for that
is dependent on recently submitted "i.MX reset reason detection
support" and I didn't want to intertwine two otherwise independent
submissions.

Feedback is wellcome!

Thanks,
Andrey Smirnov

Andrey Smirnov (17):
  ARM: i.MX: boot: Coalesce copy-pasted code
  ARM: i.MX: Add function to extract BMOD value
  ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7
  ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7
  ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode
  ARM: i.MX7: boot: Remove incorrect NAND bootsource detection
  ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup
  ARM: i.MX: boot: Remove unnecessary retruns
  ARM: i.MX: boot: Move magic values into small functions
  ARM: i.MX: boot: Share code to detect NAND as a boot source
  ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6
  ARM: i.MX53: boot: Move magic numbers info utility functions
  ARM: i.MX6: boot: Move magic numbers into utility functions
  ARM: i.MX7: boot: Move magic numbers into utility functions
  bootsource: Add BOOTSOURCE_CAN
  ARM: VFxxx: Implement code to detect bootsource
  ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI

 arch/arm/boards/datamodul-edm-qmx6/board.c |   2 +-
 arch/arm/boards/dfi-fs700-m60/board.c      |   2 +-
 arch/arm/boards/phytec-som-imx6/board.c    |   2 +-
 arch/arm/boards/zii-imx6q-rdu2/lowlevel.c  |   2 +-
 arch/arm/mach-imx/boot.c                   | 411 ++++++++++++++++++++---------
 arch/arm/mach-imx/include/mach/generic.h   |   2 +
 arch/arm/mach-imx/xload.c                  |   2 +-
 common/bootsource.c                        |   1 +
 include/bootsource.h                       |   1 +
 9 files changed, 289 insertions(+), 136 deletions(-)

-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 01/17] ARM: i.MX: boot: Coalesce copy-pasted code
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value Andrey Smirnov
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

All of the instances of imx*_boot_save_loc() do exactly the same thing with
the only difference being SoC-specific imx*_get_boot_source
call. Convert the code into a generic function taking function pointer
+ a macro to take care of the boilerplate.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 85 ++++++++++--------------------------------------
 1 file changed, 17 insertions(+), 68 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 72597f5e2..4657fa017 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -89,17 +89,6 @@ void imx25_get_boot_source(enum bootsource *src, int *instance)
 				    (val >> MX25_CCM_RCSR_MEM_TYPE_SHIFT) & 0x3);
 }
 
-void imx25_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx25_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 void imx35_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *ccm_base = IOMEM(MX35_CCM_BASE_ADDR);
@@ -110,17 +99,6 @@ void imx35_get_boot_source(enum bootsource *src, int *instance)
 				    (val >> MX35_CCM_RCSR_MEM_TYPE_SHIFT) & 0x3);
 }
 
-void imx35_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx35_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 #define IMX27_SYSCTRL_GPCR	0x18
 #define IMX27_GPCR_BOOT_SHIFT			16
 #define IMX27_GPCR_BOOT_MASK			(0xf << IMX27_GPCR_BOOT_SHIFT)
@@ -157,17 +135,6 @@ void imx27_get_boot_source(enum bootsource *src, int *instance)
 	}
 }
 
-void imx27_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx27_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 #define IMX51_SRC_SBMR			0x4
 #define IMX51_SBMR_BT_MEM_TYPE_SHIFT	7
 #define IMX51_SBMR_BT_MEM_CTL_SHIFT	0
@@ -201,17 +168,6 @@ void imx51_get_boot_source(enum bootsource *src, int *instance)
 	}
 }
 
-void imx51_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx51_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 #define IMX53_SRC_SBMR	0x4
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
@@ -260,17 +216,6 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 	}
 }
 
-void imx53_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx53_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 #define IMX6_SRC_SBMR1	0x04
 #define IMX6_SRC_SBMR2	0x1c
 
@@ -337,17 +282,6 @@ internal_boot:
 	return;
 }
 
-void imx6_boot_save_loc(void)
-{
-	enum bootsource src = BOOTSOURCE_UNKNOWN;
-	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
-
-	imx6_get_boot_source(&src, &instance);
-
-	bootsource_set(src);
-	bootsource_set_instance(instance);
-}
-
 #define IMX7_SRC_SBMR1	0x58
 #define IMX7_SRC_SBMR2	0x70
 
@@ -406,13 +340,28 @@ internal_boot:
 	return;
 }
 
-void imx7_boot_save_loc(void)
+static void
+imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
 {
 	enum bootsource src = BOOTSOURCE_UNKNOWN;
 	int instance = BOOTSOURCE_INSTANCE_UNKNOWN;
 
-	imx7_get_boot_source(&src, &instance);
+	get_boot_source(&src, &instance);
 
 	bootsource_set(src);
 	bootsource_set_instance(instance);
 }
+
+#define IMX_BOOT_SAVE_LOC(soc)					\
+	void soc##_boot_save_loc(void)				\
+	{							\
+		imx_boot_save_loc(soc##_get_boot_source);	\
+	}
+
+IMX_BOOT_SAVE_LOC(imx25)
+IMX_BOOT_SAVE_LOC(imx27)
+IMX_BOOT_SAVE_LOC(imx35)
+IMX_BOOT_SAVE_LOC(imx51)
+IMX_BOOT_SAVE_LOC(imx53)
+IMX_BOOT_SAVE_LOC(imx6)
+IMX_BOOT_SAVE_LOC(imx7)
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 01/17] ARM: i.MX: boot: Coalesce copy-pasted code Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-16  7:37   ` Sascha Hauer
  2018-04-14 17:50 ` [PATCH 03/17] ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7 Andrey Smirnov
                   ` (14 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

The location of BMDO field in SBMR/SBMR2 registers is consistent
across all i.MX SoCs starting from i.MX53. Add simple helper function
imx53_get_bmod and use it to avoid code duplication.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 4657fa017..56f9fb5d4 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -169,12 +169,23 @@ void imx51_get_boot_source(enum bootsource *src, int *instance)
 }
 
 #define IMX53_SRC_SBMR	0x4
+
+static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
+{
+	return (r & GENMASK(msb, lsb)) >> lsb;
+}
+
+static unsigned int imx53_get_bmod(uint32_t r)
+{
+	return sbmr(r, 25, 24);
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
 	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
 
-	if (((cfg1 >> 24) & 0x3) == 0x3) {
+	if (imx53_get_bmod(cfg1) == 0x3) {
 		*src = BOOTSOURCE_USB;
 		*instance = 0;
 		return;
@@ -225,12 +236,8 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 	uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
 	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
 	uint32_t boot_cfg_4_2_0;
-	int boot_mode;
 
-	/* BMOD[1:0] */
-	boot_mode = (sbmr2 >> 24) & 0x3;
-
-	switch (boot_mode) {
+	switch (imx53_get_bmod(sbmr2)) {
 	case 0: /* Fuses, fall through */
 	case 2: /* internal boot */
 		goto internal_boot;
@@ -290,12 +297,8 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
 	uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
 	uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
-	int boot_mode;
-
-	/* BMOD[1:0] */
-	boot_mode = (sbmr2 >> 24) & 0x3;
 
-	switch (boot_mode) {
+	switch (imx53_get_bmod(sbmr2)) {
 	case 0: /* Fuses, fall through */
 	case 2: /* internal boot */
 		goto internal_boot;
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 03/17] ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 01/17] ARM: i.MX: boot: Coalesce copy-pasted code Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 04/17] ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7 Andrey Smirnov
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

The algorithm to detect serial mode can be shared between i.M6 and
i.MX7 as wall as simplified a bit by replacing swich goto/break/return
termination logic with more trivial if statements.

This commit also sets the stage for additional improvements in the
commits that follow.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 50 +++++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 56f9fb5d4..7eb7a16f3 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -229,6 +229,18 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 
 #define IMX6_SRC_SBMR1	0x04
 #define IMX6_SRC_SBMR2	0x1c
+#define IMX6_BMOD_SERIAL	0b01
+#define IMX6_BMOD_RESERVED	0b11
+
+static bool imx6_bootsource_reserved(uint32_t sbmr2)
+{
+	return imx53_get_bmod(sbmr2) == IMX6_BMOD_RESERVED;
+}
+
+static bool imx6_bootsource_serial(uint32_t sbmr2)
+{
+	return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL;
+}
 
 void imx6_get_boot_source(enum bootsource *src, int *instance)
 {
@@ -237,20 +249,13 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
 	uint32_t boot_cfg_4_2_0;
 
-	switch (imx53_get_bmod(sbmr2)) {
-	case 0: /* Fuses, fall through */
-	case 2: /* internal boot */
-		goto internal_boot;
-	case 1: /* Serial Downloader */
-		*src = BOOTSOURCE_SERIAL;
-		break;
-	case 3: /* reserved */
-		break;
-	};
-
-	return;
+	if (imx6_bootsource_reserved(sbmr2))
+		return;
 
-internal_boot:
+	if (imx6_bootsource_serial(sbmr2)) {
+		*src = BOOTSOURCE_SERIAL;
+		return;
+	}
 
 	/* BOOT_CFG1[7:4] */
 	switch ((sbmr1 >> 4) & 0xf) {
@@ -298,20 +303,13 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
 	uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
 
-	switch (imx53_get_bmod(sbmr2)) {
-	case 0: /* Fuses, fall through */
-	case 2: /* internal boot */
-		goto internal_boot;
-	case 1: /* Serial Downloader */
-		*src = BOOTSOURCE_SERIAL;
-		break;
-	case 3: /* reserved */
-		break;
-	};
-
-	return;
+	if (imx6_bootsource_reserved(sbmr2))
+		return;
 
-internal_boot:
+	if (imx6_bootsource_serial(sbmr2)) {
+		*src = BOOTSOURCE_SERIAL;
+		return;
+	}
 
 	switch ((sbmr1 >> 12) & 0xf) {
 	case 1:
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 04/17] ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (2 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 03/17] ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7 Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 05/17] ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode Andrey Smirnov
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

On both i.MX6 and i.MX7 (also true for VFxxx) there's an additional
path that leads mask ROM to switch into serial bootloader mode. Add
code to support it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 7eb7a16f3..a98c716fb 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -231,6 +231,8 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 #define IMX6_SRC_SBMR2	0x1c
 #define IMX6_BMOD_SERIAL	0b01
 #define IMX6_BMOD_RESERVED	0b11
+#define IMX6_BMOD_FUSES		0b00
+#define BT_FUSE_SEL		BIT(4)
 
 static bool imx6_bootsource_reserved(uint32_t sbmr2)
 {
@@ -239,7 +241,14 @@ static bool imx6_bootsource_reserved(uint32_t sbmr2)
 
 static bool imx6_bootsource_serial(uint32_t sbmr2)
 {
-	return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL;
+	return imx53_get_bmod(sbmr2) == IMX6_BMOD_SERIAL ||
+		/*
+		 * If boot from fuses is selected and fuses are not
+		 * programmed by setting BT_FUSE_SEL, ROM code will
+		 * fallback to serial mode
+		 */
+	       (imx53_get_bmod(sbmr2) == IMX6_BMOD_FUSES &&
+		!(sbmr2 & BT_FUSE_SEL));
 }
 
 void imx6_get_boot_source(enum bootsource *src, int *instance)
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 05/17] ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (3 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 04/17] ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7 Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 06/17] ARM: i.MX7: boot: Remove incorrect NAND bootsource detection Andrey Smirnov
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index a98c716fb..4082f46ae 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -306,6 +306,19 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 #define IMX7_SRC_SBMR1	0x58
 #define IMX7_SRC_SBMR2	0x70
 
+#define IMX_BOOT_SW_INFO_POINTER_ADDR	0x000001E8
+#define IMX_BOOT_SW_INFO_BDT_SD		0x1
+
+struct imx_boot_sw_info {
+	uint8_t  reserved_1;
+	uint8_t  boot_device_instance;
+	uint8_t  boot_device_type;
+	uint8_t  reserved_2;
+	uint32_t frequency_hz[4]; /* Various frequencies (ARM, AXI,
+				   * DDR, etc.). Not used */
+	uint32_t reserved_3[3];
+} __packed;
+
 void imx7_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
@@ -316,6 +329,33 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 		return;
 
 	if (imx6_bootsource_serial(sbmr2)) {
+		/*
+		 * On i.MX7 ROM code will try to bood from uSDHC1
+		 * before entering serial mode. It doesn't seem to be
+		 * reflected in the contents of SBMR1 in any way when
+		 * that happens, so we check "Boot_SW_Info" structure
+		 * (per 6.6.14 Boot information for software) to see
+		 * if that really happened.
+		 *
+		 * FIXME: This behaviour can be inhibited by
+		 * DISABLE_SDMMC_MFG, but location of that fuse
+		 * doesn't seem to be documented anywhere. Once that
+		 * is known it should be taken into account here.
+		 */
+		const struct imx_boot_sw_info *info;
+
+		info = (const void *)readl(IMX_BOOT_SW_INFO_POINTER_ADDR);
+
+		if (info->boot_device_type == IMX_BOOT_SW_INFO_BDT_SD) {
+			*src = BOOTSOURCE_MMC;
+			/*
+			 * We are expecting to only ever boot from
+			 * uSDHC1 here
+			 */
+			WARN_ON(*instance = info->boot_device_instance);
+			return;
+		}
+
 		*src = BOOTSOURCE_SERIAL;
 		return;
 	}
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 06/17] ARM: i.MX7: boot: Remove incorrect NAND bootsource detection
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (4 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 05/17] ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 07/17] ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup Andrey Smirnov
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

i.MX7 differs from i.MX6 and i.MX53 and bit 7 in SBMR is not used to
signify boot from NAND.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 4082f46ae..1c5a47f37 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -383,10 +383,6 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 		break;
 	}
 
-	/* BOOT_CFG1[7:0] */
-	if (sbmr1 & (1 << 7))
-		*src = BOOTSOURCE_NAND;
-
 	return;
 }
 
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 07/17] ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (5 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 06/17] ARM: i.MX7: boot: Remove incorrect NAND bootsource detection Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns Andrey Smirnov
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

As per "Table 6-33. Boot device selection" from "i.MX 7Dual
Applications Processor Reference Manual, Rev. 1, 01/2018" QSPI is
encoded with 0b0100 and Serial ROM with 0b0110. Fix the original code
to use correct values.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 1c5a47f37..42ea2ccd6 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -369,11 +369,11 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	case 3:
 		*src = BOOTSOURCE_NAND;
 		break;
-	case 4:
+	case 6:
 		*src = BOOTSOURCE_SPI_NOR,
 		*instance = (sbmr1 >> 9 & 0x7);
 		break;
-	case 6:
+	case 4:
 		*src = BOOTSOURCE_SPI; /* Really: qspi */
 		break;
 	case 5:
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (6 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 07/17] ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-15  2:22   ` Marc Reilly
  2018-04-14 17:50 ` [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions Andrey Smirnov
                   ` (8 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 42ea2ccd6..cc54ea15a 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -299,8 +299,6 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 	/* BOOT_CFG1[7:0] */
 	if (sbmr1 & (1 << 7))
 		*src = BOOTSOURCE_NAND;
-
-	return;
 }
 
 #define IMX7_SRC_SBMR1	0x58
@@ -382,8 +380,6 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	default:
 		break;
 	}
-
-	return;
 }
 
 static void
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (7 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-15  2:24   ` Marc Reilly
  2018-04-14 17:50 ` [PATCH 10/17] ARM: i.MX: boot: Share code to detect NAND as a boot source Andrey Smirnov
                   ` (7 subsequent siblings)
  16 siblings, 1 reply; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Move code to extract appropiate BOOT_CFG bits to decode booutsource on
i.MX53, 6, and 7 into small functions for clarity and to allow sharing
the code between i.MX53 and i.MX6.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index cc54ea15a..66e1a9254 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -180,6 +180,11 @@ static unsigned int imx53_get_bmod(uint32_t r)
 	return sbmr(r, 25, 24);
 }
 
+static int imx53_bootsource_internal(uint32_t r)
+{
+	return sbmr(r, 7, 4);	/* BOOT_CFG1[7:4] */
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
@@ -191,7 +196,7 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 		return;
 	}
 
-	switch ((cfg1 & 0xff) >> 4) {
+	switch (imx53_bootsource_internal(cfg1)) {
 	case 2:
 		*src = BOOTSOURCE_HD;
 		break;
@@ -266,8 +271,7 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 		return;
 	}
 
-	/* BOOT_CFG1[7:4] */
-	switch ((sbmr1 >> 4) & 0xf) {
+	switch (imx53_bootsource_internal(sbmr1)) {
 	case 2:
 		*src = BOOTSOURCE_HD;
 		break;
@@ -307,6 +311,11 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 #define IMX_BOOT_SW_INFO_POINTER_ADDR	0x000001E8
 #define IMX_BOOT_SW_INFO_BDT_SD		0x1
 
+static unsigned int imx7_bootsource_internal(uint32_t r)
+{
+	return sbmr(r, 15, 12);	/* BOOT_CFG[15:12] */
+}
+
 struct imx_boot_sw_info {
 	uint8_t  reserved_1;
 	uint8_t  boot_device_instance;
@@ -358,7 +367,7 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 		return;
 	}
 
-	switch ((sbmr1 >> 12) & 0xf) {
+	switch (imx7_bootsource_internal(sbmr1)) {
 	case 1:
 	case 2:
 		*src = BOOTSOURCE_MMC;
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 10/17] ARM: i.MX: boot: Share code to detect NAND as a boot source
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (8 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 11/17] ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6 Andrey Smirnov
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Share code to detect NAND as a boot source between i.MX53 and i.MX6
which behave the same in that aspect.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 66e1a9254..c092dc827 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -175,6 +175,8 @@ static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
 	return (r & GENMASK(msb, lsb)) >> lsb;
 }
 
+#define BOOT_CFG1(r, n)	sbmr(r, n, n)
+
 static unsigned int imx53_get_bmod(uint32_t r)
 {
 	return sbmr(r, 25, 24);
@@ -185,6 +187,11 @@ static int imx53_bootsource_internal(uint32_t r)
 	return sbmr(r, 7, 4);	/* BOOT_CFG1[7:4] */
 }
 
+static bool imx53_bootsource_nand(uint32_t r)
+{
+	return BOOT_CFG1(r, 7);
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
@@ -216,7 +223,7 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 		break;
 	}
 
-	if (cfg1 & (1 << 7))
+	if (imx53_bootsource_nand(cfg1))
 		*src = BOOTSOURCE_NAND;
 
 
@@ -300,8 +307,7 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 		break;
 	}
 
-	/* BOOT_CFG1[7:0] */
-	if (sbmr1 & (1 << 7))
+	if (imx53_bootsource_nand(sbmr1))
 		*src = BOOTSOURCE_NAND;
 }
 
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 11/17] ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (9 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 10/17] ARM: i.MX: boot: Share code to detect NAND as a boot source Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 12/17] ARM: i.MX53: boot: Move magic numbers info utility functions Andrey Smirnov
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

We don't need to check if the boot source is NAND in cases when we
already know for a fact that we booted from something else. To avoid
that, move the NAND check to be done inside of default branch of
the preceeding switch statement.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index c092dc827..8fbccb260 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -220,13 +220,11 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 		*src = BOOTSOURCE_MMC;
 		break;
 	default:
+		if (imx53_bootsource_nand(cfg1))
+			*src = BOOTSOURCE_NAND;
 		break;
 	}
 
-	if (imx53_bootsource_nand(cfg1))
-		*src = BOOTSOURCE_NAND;
-
-
 	switch (*src) {
 	case BOOTSOURCE_MMC:
 	case BOOTSOURCE_SPI:
@@ -304,11 +302,10 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 		*instance = (sbmr1 >> 11) & 0x3;
 		break;
 	default:
+		if (imx53_bootsource_nand(sbmr1))
+			*src = BOOTSOURCE_NAND;
 		break;
 	}
-
-	if (imx53_bootsource_nand(sbmr1))
-		*src = BOOTSOURCE_NAND;
 }
 
 #define IMX7_SRC_SBMR1	0x58
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 12/17] ARM: i.MX53: boot: Move magic numbers info utility functions
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (10 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 11/17] ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6 Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:50 ` [PATCH 13/17] ARM: i.MX6: boot: Move magic numbers into " Andrey Smirnov
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 8fbccb260..3cd79acfc 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -169,6 +169,7 @@ void imx51_get_boot_source(enum bootsource *src, int *instance)
 }
 
 #define IMX53_SRC_SBMR	0x4
+#define IMX53_BMOD_SERIAL	0b11
 
 static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
 {
@@ -187,17 +188,27 @@ static int imx53_bootsource_internal(uint32_t r)
 	return sbmr(r, 7, 4);	/* BOOT_CFG1[7:4] */
 }
 
+static int imx53_port_select(uint32_t r)
+{
+	return sbmr(r, 21, 20);	/* BOOT_CFG3[5:4] */
+}
+
 static bool imx53_bootsource_nand(uint32_t r)
 {
 	return BOOT_CFG1(r, 7);
 }
 
+static enum bootsource imx53_bootsource_serial_rom(uint32_t r)
+{
+	return BOOT_CFG1(r, 3) ? BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+}
+
 void imx53_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
 	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
 
-	if (imx53_get_bmod(cfg1) == 0x3) {
+	if (imx53_get_bmod(cfg1) == IMX53_BMOD_SERIAL) {
 		*src = BOOTSOURCE_USB;
 		*instance = 0;
 		return;
@@ -208,10 +219,7 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 		*src = BOOTSOURCE_HD;
 		break;
 	case 3:
-		if (cfg1 & (1 << 3))
-			*src = BOOTSOURCE_SPI;
-		else
-			*src = BOOTSOURCE_I2C;
+		*src = imx53_bootsource_serial_rom(cfg1);
 		break;
 	case 4:
 	case 5:
@@ -229,7 +237,7 @@ void imx53_get_boot_source(enum bootsource *src, int *instance)
 	case BOOTSOURCE_MMC:
 	case BOOTSOURCE_SPI:
 	case BOOTSOURCE_I2C:
-		*instance = (cfg1 >> 20) & 0x3;
+		*instance = imx53_port_select(cfg1);
 		break;
 	default:
 		*instance = 0;
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 13/17] ARM: i.MX6: boot: Move magic numbers into utility functions
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (11 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 12/17] ARM: i.MX53: boot: Move magic numbers info utility functions Andrey Smirnov
@ 2018-04-14 17:50 ` Andrey Smirnov
  2018-04-14 17:51 ` [PATCH 14/17] ARM: i.MX7: " Andrey Smirnov
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:50 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Move magic numbers and algorithm for determining Serial ROM bootsource
and boot instance into utility functions. Add a comment on the logic
behing the latter while at it.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 63 +++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 49 insertions(+), 14 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 3cd79acfc..cdfe3749d 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -269,12 +269,57 @@ static bool imx6_bootsource_serial(uint32_t sbmr2)
 		!(sbmr2 & BT_FUSE_SEL));
 }
 
+static int __imx6_bootsource_serial_rom(uint32_t r)
+{
+	return sbmr(r, 26, 24);	/* BOOT_CFG4[2:0] */
+}
+
+/*
+ * Serial ROM bootsource on i.MX6 are as follows:
+ *
+ *	000 - ECSPI-1
+ *	001 - ECSPI-2
+ *	010 - ECSPI-3
+ *	011 - ECSPI-4
+ *	100 - ECSPI-5
+ *	101 - I2C1
+ *	110 - I2C2
+ *	111 - I2C3
+ *
+ * There's no single bit that would tell us we are booting from I2C or
+ * SPI, so we just have to compare the "source" agains the value for
+ * I2C1 for both: calculating bootsource and boot instance.
+ */
+#define IMX6_BOOTSOURCE_SERIAL_ROM_I2C1	0b101
+
+static enum bootsource imx6_bootsource_serial_rom(uint32_t sbmr)
+{
+	const int source = __imx6_bootsource_serial_rom(sbmr);
+
+	return source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1 ?
+		BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+}
+
+static int imx6_boot_instance_serial_rom(uint32_t sbmr)
+{
+	const int source = __imx6_bootsource_serial_rom(sbmr);
+
+	if (source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1)
+		return source;
+
+	return source - IMX6_BOOTSOURCE_SERIAL_ROM_I2C1;
+}
+
+static int imx6_boot_instance_mmc(uint32_t r)
+{
+	return sbmr(r, 13, 11);	/* BOOT_CFG2[4:3] */
+}
+
 void imx6_get_boot_source(enum bootsource *src, int *instance)
 {
 	void __iomem *src_base = IOMEM(MX6_SRC_BASE_ADDR);
 	uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
 	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
-	uint32_t boot_cfg_4_2_0;
 
 	if (imx6_bootsource_reserved(sbmr2))
 		return;
@@ -289,25 +334,15 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
 		*src = BOOTSOURCE_HD;
 		break;
 	case 3:
-		/* BOOT_CFG4[2:0] */
-		boot_cfg_4_2_0 = (sbmr1 >> 24) & 0x7;
-
-		if (boot_cfg_4_2_0 > 4) {
-			*src = BOOTSOURCE_I2C;
-			*instance = boot_cfg_4_2_0 - 5;
-		} else {
-			*src = BOOTSOURCE_SPI;
-			*instance = boot_cfg_4_2_0;
-		}
+		*src = imx6_bootsource_serial_rom(sbmr1);
+		*instance = imx6_boot_instance_serial_rom(sbmr1);
 		break;
 	case 4:
 	case 5:
 	case 6:
 	case 7:
 		*src = BOOTSOURCE_MMC;
-
-		/* BOOT_CFG2[4:3] */
-		*instance = (sbmr1 >> 11) & 0x3;
+		*instance = imx6_boot_instance_mmc(sbmr1);
 		break;
 	default:
 		if (imx53_bootsource_nand(sbmr1))
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 14/17] ARM: i.MX7: boot: Move magic numbers into utility functions
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (12 preceding siblings ...)
  2018-04-14 17:50 ` [PATCH 13/17] ARM: i.MX6: boot: Move magic numbers into " Andrey Smirnov
@ 2018-04-14 17:51 ` Andrey Smirnov
  2018-04-14 17:51 ` [PATCH 15/17] bootsource: Add BOOTSOURCE_CAN Andrey Smirnov
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:51 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index cdfe3749d..0398804b0 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -362,6 +362,16 @@ static unsigned int imx7_bootsource_internal(uint32_t r)
 	return sbmr(r, 15, 12);	/* BOOT_CFG[15:12] */
 }
 
+static int imx7_boot_instance_spi_nor(uint32_t r)
+{
+	return sbmr(r, 11, 9);	/* BOOT_CFG[11:9] */
+}
+
+static int imx7_boot_instance_mmc(uint32_t r)
+{
+	return sbmr(r, 11, 10);	/* BOOT_CFG[11:10] */
+}
+
 struct imx_boot_sw_info {
 	uint8_t  reserved_1;
 	uint8_t  boot_device_instance;
@@ -417,14 +427,14 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	case 1:
 	case 2:
 		*src = BOOTSOURCE_MMC;
-		*instance = (sbmr1 >> 10 & 0x3);
+		*instance = imx7_boot_instance_mmc(sbmr1);
 		break;
 	case 3:
 		*src = BOOTSOURCE_NAND;
 		break;
 	case 6:
 		*src = BOOTSOURCE_SPI_NOR,
-		*instance = (sbmr1 >> 9 & 0x7);
+		*instance = imx7_boot_instance_spi_nor(sbmr1);
 		break;
 	case 4:
 		*src = BOOTSOURCE_SPI; /* Really: qspi */
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 15/17] bootsource: Add BOOTSOURCE_CAN
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (13 preceding siblings ...)
  2018-04-14 17:51 ` [PATCH 14/17] ARM: i.MX7: " Andrey Smirnov
@ 2018-04-14 17:51 ` Andrey Smirnov
  2018-04-14 17:51 ` [PATCH 16/17] ARM: VFxxx: Implement code to detect bootsource Andrey Smirnov
  2018-04-14 17:51 ` [PATCH 17/17] ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI Andrey Smirnov
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:51 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Add BOOTSOURCE_CAN for SoCs that can boot from CAN interface.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 common/bootsource.c  | 1 +
 include/bootsource.h | 1 +
 2 files changed, 2 insertions(+)

diff --git a/common/bootsource.c b/common/bootsource.c
index 707b07924..78ecd8267 100644
--- a/common/bootsource.c
+++ b/common/bootsource.c
@@ -36,6 +36,7 @@ static const char *bootsource_str[] = {
 	[BOOTSOURCE_HD] = "harddisk",
 	[BOOTSOURCE_USB] = "usb",
 	[BOOTSOURCE_NET] = "net",
+	[BOOTSOURCE_CAN] = "can",
 };
 
 static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
diff --git a/include/bootsource.h b/include/bootsource.h
index c6d3b3a98..064f6b9a2 100644
--- a/include/bootsource.h
+++ b/include/bootsource.h
@@ -16,6 +16,7 @@ enum bootsource {
 	BOOTSOURCE_HD,
 	BOOTSOURCE_USB,
 	BOOTSOURCE_NET,
+	BOOTSOURCE_CAN,
 };
 
 #define BOOTSOURCE_INSTANCE_UNKNOWN	-1
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 16/17] ARM: VFxxx: Implement code to detect bootsource
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (14 preceding siblings ...)
  2018-04-14 17:51 ` [PATCH 15/17] bootsource: Add BOOTSOURCE_CAN Andrey Smirnov
@ 2018-04-14 17:51 ` Andrey Smirnov
  2018-04-14 17:51 ` [PATCH 17/17] ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI Andrey Smirnov
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:51 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/mach-imx/boot.c                 | 93 ++++++++++++++++++++++++++++++++
 arch/arm/mach-imx/include/mach/generic.h |  2 +
 2 files changed, 95 insertions(+)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 0398804b0..24e2501e9 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -26,6 +26,7 @@
 #include <mach/imx53-regs.h>
 #include <mach/imx6-regs.h>
 #include <mach/imx7-regs.h>
+#include <mach/vf610-regs.h>
 
 /* [CTRL][TYPE] */
 static const enum bootsource locations[4][4] = {
@@ -177,6 +178,8 @@ static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
 }
 
 #define BOOT_CFG1(r, n)	sbmr(r, n, n)
+#define BOOT_CFG2(r, n)	BOOT_CFG1(r, (n) + 8)
+#define BOOT_CFG4(r, n)	BOOT_CFG1(r, (n) + 24)
 
 static unsigned int imx53_get_bmod(uint32_t r)
 {
@@ -447,6 +450,95 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
 	}
 }
 
+static int vf610_boot_instance_spi(uint32_t r)
+{
+	return BOOT_CFG1(r, 1);
+}
+
+static int vf610_boot_instance_nor(uint32_t r)
+{
+	return BOOT_CFG1(r, 3);
+}
+
+/*
+ * Vybrid's Serial ROM boot sources (BOOT_CFG4[2:0]) are as follows:
+ *
+ *	000 - SPI0
+ *	001 - SPI1
+ *	010 - SPI2
+ *	011 - SPI3
+ *	100 - I2C0
+ *	101 - I2C1
+ *	110 - I2C2
+ *	111 - I2C3
+ *
+ * Which we can neatly divide in two halves and use MSb to detect if
+ * bootsource is I2C or SPI EEPROM and 2 LSbs directly as boot
+ * insance.
+ */
+static enum bootsource vf610_bootsource_serial_rom(uint32_t r)
+{
+	return BOOT_CFG4(r, 2) ? BOOTSOURCE_I2C : BOOTSOURCE_SPI_NOR;
+}
+
+static int vf610_boot_instance_serial_rom(uint32_t r)
+{
+	return __imx6_bootsource_serial_rom(r) & 0b11;
+}
+
+static int vf610_boot_instance_can(uint32_t r)
+{
+	return BOOT_CFG1(r, 0);
+}
+
+static int vf610_boot_instance_mmc(uint32_t r)
+{
+	return BOOT_CFG2(r, 3);
+}
+
+void vf610_get_boot_source(enum bootsource *src, int *instance)
+{
+	void __iomem *src_base = IOMEM(VF610_SRC_BASE_ADDR);
+	uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
+	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
+
+	if (imx6_bootsource_reserved(sbmr2))
+		return;
+
+	if (imx6_bootsource_serial(sbmr2)) {
+		*src = BOOTSOURCE_SERIAL;
+		return;
+	}
+
+	switch (imx53_bootsource_internal(sbmr1)) {
+	case 0:
+		*src = BOOTSOURCE_SPI; /* Really: qspi */
+		*instance = vf610_boot_instance_spi(sbmr1);
+		break;
+	case 1:
+		*src = BOOTSOURCE_NOR;
+		*instance = vf610_boot_instance_nor(sbmr1);
+		break;
+	case 2:
+		*src = vf610_bootsource_serial_rom(sbmr1);
+		*instance = vf610_boot_instance_serial_rom(sbmr1);
+		break;
+	case 3:
+		*src = BOOTSOURCE_CAN;
+		*instance = vf610_boot_instance_can(sbmr1);
+		break;
+	case 6:
+	case 7:
+		*src = BOOTSOURCE_MMC;
+		*instance = vf610_boot_instance_mmc(sbmr1);
+		break;
+	default:
+		if (imx53_bootsource_nand(sbmr1))
+			*src = BOOTSOURCE_NAND;
+		break;
+	}
+}
+
 static void
 imx_boot_save_loc(void (*get_boot_source)(enum bootsource *, int *))
 {
@@ -472,3 +564,4 @@ IMX_BOOT_SAVE_LOC(imx51)
 IMX_BOOT_SAVE_LOC(imx53)
 IMX_BOOT_SAVE_LOC(imx6)
 IMX_BOOT_SAVE_LOC(imx7)
+IMX_BOOT_SAVE_LOC(vf610)
diff --git a/arch/arm/mach-imx/include/mach/generic.h b/arch/arm/mach-imx/include/mach/generic.h
index cb5675185..ad9d9cb02 100644
--- a/arch/arm/mach-imx/include/mach/generic.h
+++ b/arch/arm/mach-imx/include/mach/generic.h
@@ -15,6 +15,7 @@ void imx51_boot_save_loc(void);
 void imx53_boot_save_loc(void);
 void imx6_boot_save_loc(void);
 void imx7_boot_save_loc(void);
+void vf610_boot_save_loc(void);
 
 void imx25_get_boot_source(enum bootsource *src, int *instance);
 void imx35_get_boot_source(enum bootsource *src, int *instance);
@@ -22,6 +23,7 @@ void imx51_get_boot_source(enum bootsource *src, int *instance);
 void imx53_get_boot_source(enum bootsource *src, int *instance);
 void imx6_get_boot_source(enum bootsource *src, int *instance);
 void imx7_get_boot_source(enum bootsource *src, int *instance);
+void vf610_get_boot_source(enum bootsource *src, int *instance);
 
 int imx1_init(void);
 int imx21_init(void);
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH 17/17] ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI
  2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
                   ` (15 preceding siblings ...)
  2018-04-14 17:51 ` [PATCH 16/17] ARM: VFxxx: Implement code to detect bootsource Andrey Smirnov
@ 2018-04-14 17:51 ` Andrey Smirnov
  16 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-14 17:51 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

We use BOOTSOURCE_SPI to denote, among other things, QSPI on i.MX7 and
VFxxx, whereas on i.MX6 it is used to mean SPI-NOR. To make functions
like imx_xload() work consistently across various i.MX platforms use
already existent BOOTSOURCE_SPI_NOR constant to mean booting from
SPI-NOR on i.MX6 as well.

Replace all in-tree code that relying on the old value as well.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 arch/arm/boards/datamodul-edm-qmx6/board.c | 2 +-
 arch/arm/boards/dfi-fs700-m60/board.c      | 2 +-
 arch/arm/boards/phytec-som-imx6/board.c    | 2 +-
 arch/arm/boards/zii-imx6q-rdu2/lowlevel.c  | 2 +-
 arch/arm/mach-imx/boot.c                   | 2 +-
 arch/arm/mach-imx/xload.c                  | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm/boards/datamodul-edm-qmx6/board.c b/arch/arm/boards/datamodul-edm-qmx6/board.c
index 043a93461..d93c940e3 100644
--- a/arch/arm/boards/datamodul-edm-qmx6/board.c
+++ b/arch/arm/boards/datamodul-edm-qmx6/board.c
@@ -132,7 +132,7 @@ static int realq7_device_init(void)
 		}
 		break;
 	default:
-	case BOOTSOURCE_SPI:
+	case BOOTSOURCE_SPI_NOR:
 		of_device_enable_path("/chosen/environment-spi");
 		break;
 	}
diff --git a/arch/arm/boards/dfi-fs700-m60/board.c b/arch/arm/boards/dfi-fs700-m60/board.c
index bef4612d9..2cb8e3106 100644
--- a/arch/arm/boards/dfi-fs700-m60/board.c
+++ b/arch/arm/boards/dfi-fs700-m60/board.c
@@ -105,7 +105,7 @@ static int dfi_fs700_m60_init(void)
 
 	phy_register_fixup_for_uid(PHY_ID_AR8031, AR_PHY_ID_MASK, ar8031_phy_fixup);
 
-	if (bootsource_get() == BOOTSOURCE_SPI)
+	if (bootsource_get() == BOOTSOURCE_SPI_NOR)
 		flag_spi |= BBU_HANDLER_FLAG_DEFAULT;
 	else
 		flag_mmc |= BBU_HANDLER_FLAG_DEFAULT;
diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c
index 717a22963..ecb22f956 100644
--- a/arch/arm/boards/phytec-som-imx6/board.c
+++ b/arch/arm/boards/phytec-som-imx6/board.c
@@ -152,7 +152,7 @@ static int physom_imx6_devices_init(void)
 		environment_path = basprintf("/chosen/environment-nand");
 		envdev = "NAND flash";
 		break;
-	case BOOTSOURCE_SPI:
+	case BOOTSOURCE_SPI_NOR:
 		environment_path = basprintf("/chosen/environment-spinor");
 		envdev = "SPI NOR flash";
 		break;
diff --git a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
index 22ffdf85e..3b4dbd212 100644
--- a/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
+++ b/arch/arm/boards/zii-imx6q-rdu2/lowlevel.c
@@ -290,7 +290,7 @@ static noinline void rdu2_sram_setup(void)
 		write_regs(imx6q_dcd, ARRAY_SIZE(imx6q_dcd));
 
 	imx6_get_boot_source(&bootsrc, &instance);
-	if (bootsrc == BOOTSOURCE_SPI)
+	if (bootsrc == BOOTSOURCE_SPI_NOR)
 		imx6_spi_start_image(0);
 	else
 		imx6_esdhc_start_image(instance);
diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 24e2501e9..bd2af2ef4 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -300,7 +300,7 @@ static enum bootsource imx6_bootsource_serial_rom(uint32_t sbmr)
 	const int source = __imx6_bootsource_serial_rom(sbmr);
 
 	return source < IMX6_BOOTSOURCE_SERIAL_ROM_I2C1 ?
-		BOOTSOURCE_SPI : BOOTSOURCE_I2C;
+		BOOTSOURCE_SPI_NOR : BOOTSOURCE_I2C;
 }
 
 static int imx6_boot_instance_serial_rom(uint32_t sbmr)
diff --git a/arch/arm/mach-imx/xload.c b/arch/arm/mach-imx/xload.c
index 16d56ab28..921e9ade2 100644
--- a/arch/arm/mach-imx/xload.c
+++ b/arch/arm/mach-imx/xload.c
@@ -24,7 +24,7 @@ static __noreturn int imx_xload(void)
 		pr_info("booting from MMC\n");
 		buf = bootstrap_read_disk("disk0.0", "fat");
 		break;
-	case BOOTSOURCE_SPI:
+	case BOOTSOURCE_SPI_NOR:
 		pr_info("booting from SPI\n");
 		buf = bootstrap_read_devfs("dataflash0", false,
 					   SZ_256K, SZ_1M, SZ_1M);
-- 
2.14.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns
  2018-04-14 17:50 ` [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns Andrey Smirnov
@ 2018-04-15  2:22   ` Marc Reilly
  2018-04-16 16:34     ` Andrey Smirnov
  0 siblings, 1 reply; 24+ messages in thread
From: Marc Reilly @ 2018-04-15  2:22 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

Nitpick: in subject s/retruns/returns

On Sunday, April 15, 2018 3:50:54 AM AEST Andrey Smirnov wrote:
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  arch/arm/mach-imx/boot.c | 4 ----
>  1 file changed, 4 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
> index 42ea2ccd6..cc54ea15a 100644
> --- a/arch/arm/mach-imx/boot.c
> +++ b/arch/arm/mach-imx/boot.c
> @@ -299,8 +299,6 @@ void imx6_get_boot_source(enum bootsource *src, int
> *instance) /* BOOT_CFG1[7:0] */
>  	if (sbmr1 & (1 << 7))
>  		*src = BOOTSOURCE_NAND;
> -
> -	return;
>  }
> 
>  #define IMX7_SRC_SBMR1	0x58
> @@ -382,8 +380,6 @@ void imx7_get_boot_source(enum bootsource *src, int
> *instance) default:
>  		break;
>  	}
> -
> -	return;
>  }
> 
>  static void





_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions
  2018-04-14 17:50 ` [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions Andrey Smirnov
@ 2018-04-15  2:24   ` Marc Reilly
  2018-04-16 16:33     ` Andrey Smirnov
  0 siblings, 1 reply; 24+ messages in thread
From: Marc Reilly @ 2018-04-15  2:24 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov

On Sunday, April 15, 2018 3:50:55 AM AEST Andrey Smirnov wrote:
> Move code to extract appropiate BOOT_CFG bits to decode booutsource on

s/booutsource/bootsource

> i.MX53, 6, and 7 into small functions for clarity and to allow sharing
> the code between i.MX53 and i.MX6.
> 

Cheers,
Marc



_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value
  2018-04-14 17:50 ` [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value Andrey Smirnov
@ 2018-04-16  7:37   ` Sascha Hauer
  2018-04-16 13:36     ` Andrey Smirnov
  0 siblings, 1 reply; 24+ messages in thread
From: Sascha Hauer @ 2018-04-16  7:37 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox

On Sat, Apr 14, 2018 at 10:50:48AM -0700, Andrey Smirnov wrote:
> The location of BMDO field in SBMR/SBMR2 registers is consistent
> across all i.MX SoCs starting from i.MX53. Add simple helper function
> imx53_get_bmod and use it to avoid code duplication.
> 
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  arch/arm/mach-imx/boot.c | 25 ++++++++++++++-----------
>  1 file changed, 14 insertions(+), 11 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
> index 4657fa017..56f9fb5d4 100644
> --- a/arch/arm/mach-imx/boot.c
> +++ b/arch/arm/mach-imx/boot.c
> @@ -169,12 +169,23 @@ void imx51_get_boot_source(enum bootsource *src, int *instance)
>  }
>  
>  #define IMX53_SRC_SBMR	0x4
> +
> +static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
> +{
> +	return (r & GENMASK(msb, lsb)) >> lsb;
> +}

If you like GENMASK then maybe the FIELD_GET and FIELD_PREP macros from
the Linux kernel are for you aswell.

#define SRC_SBMR_BMOD	GENMASK(25, 24)

> +
> +static unsigned int imx53_get_bmod(uint32_t r)
> +{
> +	return sbmr(r, 25, 24);

return FIELD_GET(SRC_SBMR_BMOD, r);

Sascha

> +}
> +
>  void imx53_get_boot_source(enum bootsource *src, int *instance)
>  {
>  	void __iomem *src_base = IOMEM(MX53_SRC_BASE_ADDR);
>  	uint32_t cfg1 = readl(src_base + IMX53_SRC_SBMR);
>  
> -	if (((cfg1 >> 24) & 0x3) == 0x3) {
> +	if (imx53_get_bmod(cfg1) == 0x3) {
>  		*src = BOOTSOURCE_USB;
>  		*instance = 0;
>  		return;
> @@ -225,12 +236,8 @@ void imx6_get_boot_source(enum bootsource *src, int *instance)
>  	uint32_t sbmr1 = readl(src_base + IMX6_SRC_SBMR1);
>  	uint32_t sbmr2 = readl(src_base + IMX6_SRC_SBMR2);
>  	uint32_t boot_cfg_4_2_0;
> -	int boot_mode;
>  
> -	/* BMOD[1:0] */
> -	boot_mode = (sbmr2 >> 24) & 0x3;
> -
> -	switch (boot_mode) {
> +	switch (imx53_get_bmod(sbmr2)) {
>  	case 0: /* Fuses, fall through */
>  	case 2: /* internal boot */
>  		goto internal_boot;
> @@ -290,12 +297,8 @@ void imx7_get_boot_source(enum bootsource *src, int *instance)
>  	void __iomem *src_base = IOMEM(MX7_SRC_BASE_ADDR);
>  	uint32_t sbmr1 = readl(src_base + IMX7_SRC_SBMR1);
>  	uint32_t sbmr2 = readl(src_base + IMX7_SRC_SBMR2);
> -	int boot_mode;
> -
> -	/* BMOD[1:0] */
> -	boot_mode = (sbmr2 >> 24) & 0x3;
>  
> -	switch (boot_mode) {
> +	switch (imx53_get_bmod(sbmr2)) {
>  	case 0: /* Fuses, fall through */
>  	case 2: /* internal boot */
>  		goto internal_boot;
> -- 
> 2.14.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value
  2018-04-16  7:37   ` Sascha Hauer
@ 2018-04-16 13:36     ` Andrey Smirnov
  0 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-16 13:36 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

On Mon, Apr 16, 2018 at 12:37 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Sat, Apr 14, 2018 at 10:50:48AM -0700, Andrey Smirnov wrote:
>> The location of BMDO field in SBMR/SBMR2 registers is consistent
>> across all i.MX SoCs starting from i.MX53. Add simple helper function
>> imx53_get_bmod and use it to avoid code duplication.
>>
>> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>> ---
>>  arch/arm/mach-imx/boot.c | 25 ++++++++++++++-----------
>>  1 file changed, 14 insertions(+), 11 deletions(-)
>>
>> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
>> index 4657fa017..56f9fb5d4 100644
>> --- a/arch/arm/mach-imx/boot.c
>> +++ b/arch/arm/mach-imx/boot.c
>> @@ -169,12 +169,23 @@ void imx51_get_boot_source(enum bootsource *src, int *instance)
>>  }
>>
>>  #define IMX53_SRC_SBMR       0x4
>> +
>> +static unsigned int sbmr(uint32_t r, unsigned int msb, unsigned int lsb)
>> +{
>> +     return (r & GENMASK(msb, lsb)) >> lsb;
>> +}
>
> If you like GENMASK then maybe the FIELD_GET and FIELD_PREP macros from
> the Linux kernel are for you aswell.
>
> #define SRC_SBMR_BMOD   GENMASK(25, 24)
>

Definetly! I like it a lot! I was hoping that something like that
existed but didn't find anything in barebox's tree. Should've checked
the kernel one instead. Will add and use in v2 of the patch.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions
  2018-04-15  2:24   ` Marc Reilly
@ 2018-04-16 16:33     ` Andrey Smirnov
  0 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-16 16:33 UTC (permalink / raw)
  To: Marc Reilly; +Cc: Barebox List

On Sat, Apr 14, 2018 at 7:24 PM, Marc Reilly <marc@cpdesign.com.au> wrote:
> On Sunday, April 15, 2018 3:50:55 AM AEST Andrey Smirnov wrote:
>> Move code to extract appropiate BOOT_CFG bits to decode booutsource on
>
> s/booutsource/bootsource
>

Fixed in v2.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns
  2018-04-15  2:22   ` Marc Reilly
@ 2018-04-16 16:34     ` Andrey Smirnov
  0 siblings, 0 replies; 24+ messages in thread
From: Andrey Smirnov @ 2018-04-16 16:34 UTC (permalink / raw)
  To: Marc Reilly; +Cc: Barebox List

On Sat, Apr 14, 2018 at 7:22 PM, Marc Reilly <marc@cpdesign.com.au> wrote:
> Nitpick: in subject s/retruns/returns
>

 Fixed in v2.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2018-04-16 16:34 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-14 17:50 [PATCH 00/17] i.MX bootsource bugfixes, refactoring and VFxxx support Andrey Smirnov
2018-04-14 17:50 ` [PATCH 01/17] ARM: i.MX: boot: Coalesce copy-pasted code Andrey Smirnov
2018-04-14 17:50 ` [PATCH 02/17] ARM: i.MX: Add function to extract BMOD value Andrey Smirnov
2018-04-16  7:37   ` Sascha Hauer
2018-04-16 13:36     ` Andrey Smirnov
2018-04-14 17:50 ` [PATCH 03/17] ARM: i.MX: Simplify serial bootsource detection for i.MX6 and 7 Andrey Smirnov
2018-04-14 17:50 ` [PATCH 04/17] ARM: i.MX: Account for unprogrammed fuses on i.MX6 and i.MX7 Andrey Smirnov
2018-04-14 17:50 ` [PATCH 05/17] ARM: i.MX7: boot: Add code to handle SD/MMC manufacture mode Andrey Smirnov
2018-04-14 17:50 ` [PATCH 06/17] ARM: i.MX7: boot: Remove incorrect NAND bootsource detection Andrey Smirnov
2018-04-14 17:50 ` [PATCH 07/17] ARM: i.MX7: boot: Fix SPI-NOR/QSPI boot source mixup Andrey Smirnov
2018-04-14 17:50 ` [PATCH 08/17] ARM: i.MX: boot: Remove unnecessary retruns Andrey Smirnov
2018-04-15  2:22   ` Marc Reilly
2018-04-16 16:34     ` Andrey Smirnov
2018-04-14 17:50 ` [PATCH 09/17] ARM: i.MX: boot: Move magic values into small functions Andrey Smirnov
2018-04-15  2:24   ` Marc Reilly
2018-04-16 16:33     ` Andrey Smirnov
2018-04-14 17:50 ` [PATCH 10/17] ARM: i.MX: boot: Share code to detect NAND as a boot source Andrey Smirnov
2018-04-14 17:50 ` [PATCH 11/17] ARM: i.MX: boot: Check for NAND boot only if necessary on i.MX53, 6 Andrey Smirnov
2018-04-14 17:50 ` [PATCH 12/17] ARM: i.MX53: boot: Move magic numbers info utility functions Andrey Smirnov
2018-04-14 17:50 ` [PATCH 13/17] ARM: i.MX6: boot: Move magic numbers into " Andrey Smirnov
2018-04-14 17:51 ` [PATCH 14/17] ARM: i.MX7: " Andrey Smirnov
2018-04-14 17:51 ` [PATCH 15/17] bootsource: Add BOOTSOURCE_CAN Andrey Smirnov
2018-04-14 17:51 ` [PATCH 16/17] ARM: VFxxx: Implement code to detect bootsource Andrey Smirnov
2018-04-14 17:51 ` [PATCH 17/17] ARM: i.MX6: boot: Return BOOTSOURCE_SPI_NOR, not BOOTSOURCE_SPI Andrey Smirnov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox