Skip to contentSkip to conversation

Add spi boot to SPL on SUNIV

PATCH Superseded Jesse Taube 2 participants 12 messages Feb 10, 2022 1 message not in the archive

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add spi boot to SPL on SUNIV

This patch adds the ability to detect the
BROM's boot source as well as the ability to boot from spi.

Jesse Taube (3):
mach-sunxi: Add boot device detection for SUNIV
mach-sunxi: Add spi boot for SUNIV
mach-sunxi: Enable spi boot for SUNIV

 arch/arm/include/asm/arch-sunxi/gpio.h |  1 +
 arch/arm/include/asm/arch-sunxi/spl.h  | 15 ++++++++
 arch/arm/mach-sunxi/Kconfig            |  2 +-
 arch/arm/mach-sunxi/board.c            | 50 ++++++++++++--------------
 arch/arm/mach-sunxi/spl_spi_sunxi.c    | 26 ++++++++++----
 configs/licheepi_nano_defconfig        |  1 +
 6 files changed, 60 insertions(+), 35 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 mach-sunxi: Add boot device detection for SUNIV

Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device.

---
 arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++
 arch/arm/mach-sunxi/board.c           | 50 ++++++++++++---------------
 2 files changed, 38 insertions(+), 27 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +15 -0
index 58cdf806d9..d069091297 100644
@@ -19,8 +19,23 @@
 #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
 #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
 
+/*
+ * Values taken from the Bootrom's stack used
+ * to determine where we booted from.
+ * 0xffff40f8: mmc0
+ * 0xffff4114: spi0 NAND
+ * 0xffff4130: spi0 NOR
+ * 0xffff4150: mmc1
+ */
+
+#define SUNIV_BOOTED_FROM_MMC0	0xffff40f8
+#define SUNIV_BOOTED_FROM_NAND	0xffff4114
+#define SUNIV_BOOTED_FROM_SPI	0xffff4130
+#define SUNIV_BOOTED_FROM_MMC1	0xffff4150
+
 #define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
 uint32_t sunxi_get_boot_device(void);
+uint32_t suniv_get_boot_device(void);
 
 #endif
arch/arm/mach-sunxi/board.c +23 -27

65 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

On Wed, 9 Feb 2022 23:34:36 -0500
Jesse Taube <[email protected]> wrote:

Hi Jesse,

many thanks for sending this, much appreciated!

Quoted 2 lines

Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device.

Can you please elaborate here what's going on, for future reference? Like:
=============
In contrast to other Allwinner SoCs the F1C100s BROM does not store a boot source indicator in the eGON header in SRAM. This leaves us guessing where we were exactly booted from, and for instance trying the SD card first, even though we booted from SPI flash.
By inspecting the BROM code and by experimentation, Samuel found that the top of the BROM stack contains unique pointers for each of the boot sources, which we can use as a boot source indicator.

Remove the existing board_boot_order kludge and replace it with a proper boot source indication function.
=============

Quoted 13 lines
---
 arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++
 arch/arm/mach-sunxi/board.c           | 50 ++++++++++++---------------
 2 files changed, 38 insertions(+), 27 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +0 -0
index 58cdf806d9..d069091297 100644

arch/arm/include/asm/arch-sunxi/spl.h line 28

Quoted 10 lines
arch/arm/include/asm/arch-sunxi/spl.h +7 -0
@@ -19,8 +19,23 @@
 #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
 #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
 
+/*
+ * Values taken from the Bootrom's stack used
+ * to determine where we booted from.
+ * 0xffff40f8: mmc0
+ * 0xffff4114: spi0 NAND
+ * 0xffff4130: spi0 NOR
+ * 0xffff4150: mmc1

Those last four lines are redundant, as you say exactly that, in code, down here again. Comments are good, speaking code is better.

Quoted 18 lines
arch/arm/include/asm/arch-sunxi/spl.h +8 -0
+ */
+
+#define SUNIV_BOOTED_FROM_MMC0	0xffff40f8
+#define SUNIV_BOOTED_FROM_NAND	0xffff4114
+#define SUNIV_BOOTED_FROM_SPI	0xffff4130
+#define SUNIV_BOOTED_FROM_MMC1	0xffff4150
+
 #define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
 uint32_t sunxi_get_boot_device(void);
+uint32_t suniv_get_boot_device(void);
 
 #endif
arch/arm/mach-sunxi/board.c +0 -0
index 57078f7a7b..b0658d583e 100644

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 244

Quoted 4 lines
arch/arm/mach-sunxi/board.c +1 -0
@@ -241,6 +241,25 @@ uint32_t sunxi_get_boot_device(void)
 	return -1;		/* Never reached */
 }
 
+uint32_t suniv_get_boot_device(void)

This can be static, right?

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 257

Quoted 13 lines
arch/arm/mach-sunxi/board.c +13 -0
+{
+	/* Get the last function call from BootRom's stack. */
+	u32 brom_call = *(u32 *)(fel_stash.sp - 4);
+
+	switch (brom_call) {
+	case SUNIV_BOOTED_FROM_MMC0:
+		return BOOT_DEVICE_MMC1;
+	case SUNIV_BOOTED_FROM_NAND:
+	case SUNIV_BOOTED_FROM_SPI:
+		return BOOT_DEVICE_SPI;
+	case SUNIV_BOOTED_FROM_MMC1:
+		return BOOT_DEVICE_MMC2;
+	}

Don't you need to handle FEL boot here somehow?

Cheers,
Andre

Quoted 49 lines
arch/arm/mach-sunxi/board.c +9 -27
+
+	printf("Unknown boot source from BROM: 0x%x\n", brom_call);
+	return BOOT_DEVICE_MMC1;
+}
+
 #ifdef CONFIG_SPL_BUILD
 static u32 sunxi_get_spl_size(void)
 {
@@ -276,36 +295,13 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
 	return sector;
 }
 
-#ifdef CONFIG_MACH_SUNIV
-/*
- * The suniv BROM does not pass the boot media type to SPL, so we try with the
- * boot sequence in BROM: mmc0->spinor->fail.
- * TODO: This has the slight chance of being wrong (invalid SPL signature,
- * but valid U-Boot legacy image on the SD card), but this should be rare.
- * It looks like we can deduce from some BROM state upon entering the SPL
- * (registers, SP, or stack itself) where the BROM was coming from and use
- * that here.
- */
-void board_boot_order(u32 *spl_boot_list)
-{
-	/*
-	 * See the comments above in sunxi_get_boot_device() for information
-	 * about FEL boot.
-	 */
-	if (!is_boot0_magic(SPL_ADDR + 4)) {
-		spl_boot_list[0] = BOOT_DEVICE_BOARD;
-		return;
-	}
-
-	spl_boot_list[0] = BOOT_DEVICE_MMC1;
-	spl_boot_list[1] = BOOT_DEVICE_SPI;
-}
-#else
 u32 spl_boot_device(void)
 {
-	return sunxi_get_boot_device();
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		return suniv_get_boot_device();
+	else
+		return sunxi_get_boot_device();
 }
-#endif
 
 __weak void sunxi_sram_init(void)
 {
#3 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

Quoted 73 lines · Andre Przywara

On Wed, 9 Feb 2022 23:34:36 -0500
Jesse Taube <[email protected]> wrote:

Hi Jesse,

many thanks for sending this, much appreciated!

Quoted 2 lines

Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device.

Can you please elaborate here what's going on, for future reference? Like:
=============
In contrast to other Allwinner SoCs the F1C100s BROM does not store a boot source indicator in the eGON header in SRAM. This leaves us guessing where we were exactly booted from, and for instance trying the SD card first, even though we booted from SPI flash.
By inspecting the BROM code and by experimentation, Samuel found that the top of the BROM stack contains unique pointers for each of the boot sources, which we can use as a boot source indicator.

Remove the existing board_boot_order kludge and replace it with a proper boot source indication function.
=============

Quoted 13 lines
---
  arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++
  arch/arm/mach-sunxi/board.c           | 50 ++++++++++++---------------
  2 files changed, 38 insertions(+), 27 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +0 -0
index 58cdf806d9..d069091297 100644

arch/arm/include/asm/arch-sunxi/spl.h line 28

Quoted 10 lines
arch/arm/include/asm/arch-sunxi/spl.h +7 -0
@@ -19,8 +19,23 @@
  #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
  #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
 
+/*
+ * Values taken from the Bootrom's stack used
+ * to determine where we booted from.
+ * 0xffff40f8: mmc0
+ * 0xffff4114: spi0 NAND
+ * 0xffff4130: spi0 NOR
+ * 0xffff4150: mmc1

Those last four lines are redundant, as you say exactly that, in code, down here again. Comments are good, speaking code is better.

Quoted 21 lines
arch/arm/include/asm/arch-sunxi/spl.h +8 -0
+ */
+
+#define SUNIV_BOOTED_FROM_MMC0	0xffff40f8
+#define SUNIV_BOOTED_FROM_NAND	0xffff4114
+#define SUNIV_BOOTED_FROM_SPI	0xffff4130
+#define SUNIV_BOOTED_FROM_MMC1	0xffff4150
+
  #define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
  uint32_t sunxi_get_boot_device(void);
+uint32_t suniv_get_boot_device(void);
 
  #endif
arch/arm/mach-sunxi/board.c +0 -0
index 57078f7a7b..b0658d583e 100644
@@ -241,6 +241,25 @@ uint32_t sunxi_get_boot_device(void)
  	return -1;		/* Never reached */
  }
 
Quoted 3 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 244

Quoted 1 line
arch/arm/mach-sunxi/board.c +1 -0
+uint32_t suniv_get_boot_device(void)

This can be static, right?

Yes it can it is not because sunxi_get_boot_device isn'tm, but that is only not static because board/sunxi/board.c:mmc_get_env_dev. I will make it static.

Quoted 70 lines
Quoted 4 lines
arch/arm/mach-sunxi/board.c +3 -0
+{
+	/* Get the last function call from BootRom's stack. */
+	u32 brom_call = *(u32 *)(fel_stash.sp - 4);

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 257

Quoted 10 lines
arch/arm/mach-sunxi/board.c +10 -0
+
+	switch (brom_call) {
+	case SUNIV_BOOTED_FROM_MMC0:
+		return BOOT_DEVICE_MMC1;
+	case SUNIV_BOOTED_FROM_NAND:
+	case SUNIV_BOOTED_FROM_SPI:
+		return BOOT_DEVICE_SPI;
+	case SUNIV_BOOTED_FROM_MMC1:
+		return BOOT_DEVICE_MMC2;
+	}

Don't you need to handle FEL boot here somehow?

Cheers,
Andre

Quoted 49 lines
arch/arm/mach-sunxi/board.c +9 -27
+
+	printf("Unknown boot source from BROM: 0x%x\n", brom_call);
+	return BOOT_DEVICE_MMC1;
+}
+
  #ifdef CONFIG_SPL_BUILD
  static u32 sunxi_get_spl_size(void)
  {
@@ -276,36 +295,13 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
  	return sector;
  }
 
-#ifdef CONFIG_MACH_SUNIV
-/*
- * The suniv BROM does not pass the boot media type to SPL, so we try with the
- * boot sequence in BROM: mmc0->spinor->fail.
- * TODO: This has the slight chance of being wrong (invalid SPL signature,
- * but valid U-Boot legacy image on the SD card), but this should be rare.
- * It looks like we can deduce from some BROM state upon entering the SPL
- * (registers, SP, or stack itself) where the BROM was coming from and use
- * that here.
- */
-void board_boot_order(u32 *spl_boot_list)
-{
-	/*
-	 * See the comments above in sunxi_get_boot_device() for information
-	 * about FEL boot.
-	 */
-	if (!is_boot0_magic(SPL_ADDR + 4)) {
-		spl_boot_list[0] = BOOT_DEVICE_BOARD;
-		return;
-	}
-
-	spl_boot_list[0] = BOOT_DEVICE_MMC1;
-	spl_boot_list[1] = BOOT_DEVICE_SPI;
-}
-#else
  u32 spl_boot_device(void)
  {
-	return sunxi_get_boot_device();
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		return suniv_get_boot_device();
+	else
+		return sunxi_get_boot_device();
  }
-#endif
 
  __weak void sunxi_sram_init(void)
  {
#4 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

In reply to Andre Przywara
Quoted 73 lines · Andre Przywara

On Wed, 9 Feb 2022 23:34:36 -0500
Jesse Taube <[email protected]> wrote:

Hi Jesse,

many thanks for sending this, much appreciated!

Quoted 2 lines

Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device.

Can you please elaborate here what's going on, for future reference? Like:
=============
In contrast to other Allwinner SoCs the F1C100s BROM does not store a boot source indicator in the eGON header in SRAM. This leaves us guessing where we were exactly booted from, and for instance trying the SD card first, even though we booted from SPI flash.
By inspecting the BROM code and by experimentation, Samuel found that the top of the BROM stack contains unique pointers for each of the boot sources, which we can use as a boot source indicator.

Remove the existing board_boot_order kludge and replace it with a proper boot source indication function.
=============

Quoted 13 lines
---
  arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++
  arch/arm/mach-sunxi/board.c           | 50 ++++++++++++---------------
  2 files changed, 38 insertions(+), 27 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +0 -0
index 58cdf806d9..d069091297 100644

arch/arm/include/asm/arch-sunxi/spl.h line 28

Quoted 10 lines
arch/arm/include/asm/arch-sunxi/spl.h +7 -0
@@ -19,8 +19,23 @@
  #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
  #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
 
+/*
+ * Values taken from the Bootrom's stack used
+ * to determine where we booted from.
+ * 0xffff40f8: mmc0
+ * 0xffff4114: spi0 NAND
+ * 0xffff4130: spi0 NOR
+ * 0xffff4150: mmc1

Those last four lines are redundant, as you say exactly that, in code, down here again. Comments are good, speaking code is better.

Quoted 21 lines
arch/arm/include/asm/arch-sunxi/spl.h +8 -0
+ */
+
+#define SUNIV_BOOTED_FROM_MMC0	0xffff40f8
+#define SUNIV_BOOTED_FROM_NAND	0xffff4114
+#define SUNIV_BOOTED_FROM_SPI	0xffff4130
+#define SUNIV_BOOTED_FROM_MMC1	0xffff4150
+
  #define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
  uint32_t sunxi_get_boot_device(void);
+uint32_t suniv_get_boot_device(void);
 
  #endif
arch/arm/mach-sunxi/board.c +0 -0
index 57078f7a7b..b0658d583e 100644
@@ -241,6 +241,25 @@ uint32_t sunxi_get_boot_device(void)
  	return -1;		/* Never reached */
  }
 
Quoted 7 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 244

Quoted 1 line
arch/arm/mach-sunxi/board.c +1 -0
+uint32_t suniv_get_boot_device(void)

This can be static, right?

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void)

Quoted 3 lines
arch/arm/mach-sunxi/board.c +3 -0
+{
+	/* Get the last function call from BootRom's stack. */
+	u32 brom_call = *(u32 *)(fel_stash.sp - 4);You are okay with this I was expecting you to explain a better way that 

i don't know about.

Quoted 4 lines
Quoted 4 lines
arch/arm/mach-sunxi/board.c +4 -0
+
+	switch (brom_call) {
+	case SUNIV_BOOTED_FROM_MMC0:
+		return BOOT_DEVICE_MMC1;
Quoted 8 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 257

Quoted 6 lines
arch/arm/mach-sunxi/board.c +6 -0
+	case SUNIV_BOOTED_FROM_NAND:
+	case SUNIV_BOOTED_FROM_SPI:
+		return BOOT_DEVICE_SPI;
+	case SUNIV_BOOTED_FROM_MMC1:
+		return BOOT_DEVICE_MMC2;
+	}

Don't you need to handle FEL boot here somehow?

Yes but I have no clue what the SP is also wouldn't we have it hang anyway. The other changes requested i have fixed, I'm sorry about the subpar commit descriptions.

Thanks,
Jesse

Quoted 53 lines

Cheers,
Andre

Quoted 49 lines
arch/arm/mach-sunxi/board.c +9 -27
+
+	printf("Unknown boot source from BROM: 0x%x\n", brom_call);
+	return BOOT_DEVICE_MMC1;
+}
+
  #ifdef CONFIG_SPL_BUILD
  static u32 sunxi_get_spl_size(void)
  {
@@ -276,36 +295,13 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
  	return sector;
  }
 
-#ifdef CONFIG_MACH_SUNIV
-/*
- * The suniv BROM does not pass the boot media type to SPL, so we try with the
- * boot sequence in BROM: mmc0->spinor->fail.
- * TODO: This has the slight chance of being wrong (invalid SPL signature,
- * but valid U-Boot legacy image on the SD card), but this should be rare.
- * It looks like we can deduce from some BROM state upon entering the SPL
- * (registers, SP, or stack itself) where the BROM was coming from and use
- * that here.
- */
-void board_boot_order(u32 *spl_boot_list)
-{
-	/*
-	 * See the comments above in sunxi_get_boot_device() for information
-	 * about FEL boot.
-	 */
-	if (!is_boot0_magic(SPL_ADDR + 4)) {
-		spl_boot_list[0] = BOOT_DEVICE_BOARD;
-		return;
-	}
-
-	spl_boot_list[0] = BOOT_DEVICE_MMC1;
-	spl_boot_list[1] = BOOT_DEVICE_SPI;
-}
-#else
  u32 spl_boot_device(void)
  {
-	return sunxi_get_boot_device();
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		return suniv_get_boot_device();
+	else
+		return sunxi_get_boot_device();
  }
-#endif
 
  __weak void sunxi_sram_init(void)
  {
#5 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

On Thu, 10 Feb 2022 14:20:26 -0500
Jesse Taube <[email protected]> wrote:

Hi,

Quoted 74 lines · Andre Przywara
Quoted 73 lines

On Wed, 9 Feb 2022 23:34:36 -0500
Jesse Taube <[email protected]> wrote:

Hi Jesse,

many thanks for sending this, much appreciated!

Quoted 2 lines

Use Samuel's suggestion of looking at the BootRom's stack to determine the boot device.

Can you please elaborate here what's going on, for future reference? Like:
=============
In contrast to other Allwinner SoCs the F1C100s BROM does not store a boot source indicator in the eGON header in SRAM. This leaves us guessing where we were exactly booted from, and for instance trying the SD card first, even though we booted from SPI flash.
By inspecting the BROM code and by experimentation, Samuel found that the top of the BROM stack contains unique pointers for each of the boot sources, which we can use as a boot source indicator.

Remove the existing board_boot_order kludge and replace it with a proper boot source indication function.
=============

Quoted 13 lines
---
  arch/arm/include/asm/arch-sunxi/spl.h | 15 ++++++++
  arch/arm/mach-sunxi/board.c           | 50 ++++++++++++---------------
  2 files changed, 38 insertions(+), 27 deletions(-)
arch/arm/include/asm/arch-sunxi/spl.h +0 -0
index 58cdf806d9..d069091297 100644

arch/arm/include/asm/arch-sunxi/spl.h line 28

Quoted 10 lines
arch/arm/include/asm/arch-sunxi/spl.h +7 -0
@@ -19,8 +19,23 @@
  #define SUNXI_BOOTED_FROM_MMC0_HIGH	0x10
  #define SUNXI_BOOTED_FROM_MMC2_HIGH	0x12
 
+/*
+ * Values taken from the Bootrom's stack used
+ * to determine where we booted from.
+ * 0xffff40f8: mmc0
+ * 0xffff4114: spi0 NAND
+ * 0xffff4130: spi0 NOR
+ * 0xffff4150: mmc1  

Those last four lines are redundant, as you say exactly that, in code, down here again. Comments are good, speaking code is better.

Quoted 21 lines
arch/arm/include/asm/arch-sunxi/spl.h +8 -0
+ */
+
+#define SUNIV_BOOTED_FROM_MMC0	0xffff40f8
+#define SUNIV_BOOTED_FROM_NAND	0xffff4114
+#define SUNIV_BOOTED_FROM_SPI	0xffff4130
+#define SUNIV_BOOTED_FROM_MMC1	0xffff4150
+
  #define is_boot0_magic(addr)	(memcmp((void *)(addr), BOOT0_MAGIC, 8) == 0)
 
  uint32_t sunxi_get_boot_device(void);
+uint32_t suniv_get_boot_device(void);
 
  #endif
arch/arm/mach-sunxi/board.c +0 -0
index 57078f7a7b..b0658d583e 100644
@@ -241,6 +241,25 @@ uint32_t sunxi_get_boot_device(void)
  	return -1;		/* Never reached */
  }
 
Quoted 3 lines
Quoted 3 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 244

Quoted 1 line
arch/arm/mach-sunxi/board.c +1 -0
+uint32_t suniv_get_boot_device(void)  

This can be static, right?

Actually, looking closer, I think this should be restructured:
You keep this function, as a static, but let it return the sunxi internal boot source codes (that the BROM would write on other SoCs):

	case SUNIV_BOOTED_FROM_MMC0:
		return SUNXI_BOOTED_FROM_MMC0;
	...
Possibly rename it to suniv_get_boot_source.
Then you change sunxi_get_boot_source() to:
	...
	if (IS_ENABLED(CONFIG_MACH_SUNIV))
		return suniv_get_boot_source();
	else
		return readb(SPL_ADDR + 0x28);

This way we fix this one level deeper, and can call sunxi_get_boot_source() from elsewhere as well.

Hope that makes sense.

Quoted 5 lines
Quoted 4 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void)

Quoted 4 lines
arch/arm/mach-sunxi/board.c +3 -0
+{
+	/* Get the last function call from BootRom's stack. */
+	u32 brom_call = *(u32 *)(fel_stash.sp - 4);You are okay with this I was expecting you to explain a better way that   

i don't know about.

That looks alright, I think we explained how it works by now (commit message plus two comments), plus the code makes that clear.

Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
arch/arm/mach-sunxi/board.c +4 -0
+
+	switch (brom_call) {
+	case SUNIV_BOOTED_FROM_MMC0:
+		return BOOT_DEVICE_MMC1;
Quoted 8 lines

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 257

Quoted 6 lines
arch/arm/mach-sunxi/board.c +6 -0
+	case SUNIV_BOOTED_FROM_NAND:
+	case SUNIV_BOOTED_FROM_SPI:
+		return BOOT_DEVICE_SPI;
+	case SUNIV_BOOTED_FROM_MMC1:
+		return BOOT_DEVICE_MMC2;
+	}  

Don't you need to handle FEL boot here somehow?

Quoted 2 lines

Yes but I have no clue what the SP is also wouldn't we have it hang anyway.

The stack would be from some SPL thunk code, which is not necessarily stable (in fact we are still working on that). However we support FEL booting already, because our FEL thunk code writes a signature into SRAM - even when the BROM does not do that.
So we just keep that check from the current code, see the first part of board_boot_order().

Quoted 2 lines

The other changes requested i have fixed, I'm sorry about the subpar commit descriptions.

No worries, it's just from experience that we want good commit messages, so that others (or even yourself!) can make sense of code in the future.

Cheers,
Andre

Quoted 50 lines
Quoted 50 lines
Quoted 49 lines
arch/arm/mach-sunxi/board.c +9 -27
+
+	printf("Unknown boot source from BROM: 0x%x\n", brom_call);
+	return BOOT_DEVICE_MMC1;
+}
+
  #ifdef CONFIG_SPL_BUILD
  static u32 sunxi_get_spl_size(void)
  {
@@ -276,36 +295,13 @@ unsigned long spl_mmc_get_uboot_raw_sector(struct mmc *mmc,
  	return sector;
  }
 
-#ifdef CONFIG_MACH_SUNIV
-/*
- * The suniv BROM does not pass the boot media type to SPL, so we try with the
- * boot sequence in BROM: mmc0->spinor->fail.
- * TODO: This has the slight chance of being wrong (invalid SPL signature,
- * but valid U-Boot legacy image on the SD card), but this should be rare.
- * It looks like we can deduce from some BROM state upon entering the SPL
- * (registers, SP, or stack itself) where the BROM was coming from and use
- * that here.
- */
-void board_boot_order(u32 *spl_boot_list)
-{
-	/*
-	 * See the comments above in sunxi_get_boot_device() for information
-	 * about FEL boot.
-	 */
-	if (!is_boot0_magic(SPL_ADDR + 4)) {
-		spl_boot_list[0] = BOOT_DEVICE_BOARD;
-		return;
-	}
-
-	spl_boot_list[0] = BOOT_DEVICE_MMC1;
-	spl_boot_list[1] = BOOT_DEVICE_SPI;
-}
-#else
  u32 spl_boot_device(void)
  {
-	return sunxi_get_boot_device();
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		return suniv_get_boot_device();
+	else
+		return sunxi_get_boot_device();
  }
-#endif
 
  __weak void sunxi_sram_init(void)
  {  

A message that is not in the archive (sent off-list or not yet received): CACY+gR2NuuRn3qn+htsa15+cVLbE1KYsy7sUpnC5ATpRDW5V_w@mail.gmail.com

#7 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

Quoted 8 lines · Siarhei Siamashka

On Thu, Feb 10, 2022 at 6:35 AM Jesse Taube <[email protected]> wrote:
[...]

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 254

Quoted 3 lines
arch/arm/mach-sunxi/board.c +3 -0
+       case SUNIV_BOOTED_FROM_NAND:
+       case SUNIV_BOOTED_FROM_SPI:
+               return BOOT_DEVICE_SPI;

Is it really okay to lump SPI and NAND together and return BOOT_DEVICE_SPI for both?

Booting from SPI NAND.
I can change it to BOOT_DEVICE_NAND.

Quoted 1 line

What's the NAND support story on this device?

I thought BOOT_DEVICE_NAND was for parallel NAND but I may be wrong could come one clarify please?

Thanks,
Jesse Taube

#8 lore raw

Re: [PATCH v1 1/3] mach-sunxi: Add boot device detection for SUNIV

Quoted 11 lines · On Thu, 10 Feb 2022 14:51:11 -0500 Jesse Taube <[email protected]> wrote:
Quoted 8 lines · Siarhei Siamashka

On Thu, Feb 10, 2022 at 6:35 AM Jesse Taube <[email protected]> wrote:
[...]

arch/arm/mach-sunxi/board.c uint32_t sunxi_get_boot_device(void) · line 254

Quoted 3 lines
arch/arm/mach-sunxi/board.c +3 -0
+       case SUNIV_BOOTED_FROM_NAND:
+       case SUNIV_BOOTED_FROM_SPI:
+               return BOOT_DEVICE_SPI;  

Is it really okay to lump SPI and NAND together and return BOOT_DEVICE_SPI for both?

Booting from SPI NAND.
I can change it to BOOT_DEVICE_NAND.

Ah, sorry, I missed that. So SPI NAND is different from both SPI NOR and parallel NAND, and we just don't support it (yet).
So just bail out in this case, ideally with a message.

Cheers,
Andre

Quoted 6 lines
Quoted 1 line

What's the NAND support story on this device?

I thought BOOT_DEVICE_NAND was for parallel NAND but I may be wrong could come one clarify please?

Thanks,
Jesse Taube

#9 lore raw

PATCH 2/3 mach-sunxi: Add spi boot for SUNIV

In reply to Jesse Taube

Add support for the spi boot in spl on suniv architecture.

---
 arch/arm/include/asm/arch-sunxi/gpio.h |  1 +
 arch/arm/mach-sunxi/spl_spi_sunxi.c    | 26 +++++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +1 -0
index 7f7eb0517c..edd0fbf49f 100644
@@ -160,6 +160,7 @@ enum sunxi_gpio_number {
 #define SUNXI_GPC_SDC2		3
 #define SUN6I_GPC_SDC3		4
 #define SUN50I_GPC_SPI0		4
+#define SUNIV_GPC_SPI0		2
 
 #define SUNXI_GPD_LCD0		2
 #define SUNXI_GPD_LVDS0		3
arch/arm/mach-sunxi/spl_spi_sunxi.c +19 -7
index 910e805016..9a3666a2d7 100644
@@ -90,6 +90,7 @@
 
 #define SPI0_CLK_DIV_BY_2           0x1000
 #define SPI0_CLK_DIV_BY_4           0x1001
+#define SPI0_CLK_DIV_BY_32          0x100f
 
 /*****************************************************************************/
 
@@ -132,7 +133,8 @@ static uintptr_t spi0_base_address(void)
 	if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
 		return 0x05010000;
 
-	if (!is_sun6i_gen_spi())
+	if (!is_sun6i_gen_spi() ||
+	    IS_ENABLED(CONFIG_MACH_SUNIV))
 		return 0x01C05000;
 
 	return 0x01C68000;
@@ -156,11 +158,17 @@ static void spi0_enable_clock(void)
 	if (!IS_ENABLED(CONFIG_MACH_SUN50I_H6))
 		setbits_le32(CCM_AHB_GATING0, (1 << AHB_GATE_OFFSET_SPI0));
 
-	/* Divide by 4 */
-	writel(SPI0_CLK_DIV_BY_4, base + (is_sun6i_gen_spi() ?
-				  SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
-	/* 24MHz from OSC24M */
-	writel((1 << 31), CCM_SPI0_CLK);
+	if (IS_ENABLED(CONFIG_MACH_SUNIV)) {
+		/* Divide by 32, clock source is AHB clock 200MHz */
+		writel(SPI0_CLK_DIV_BY_32, base + (IS_ENABLED(CONFIG_SUNXI_GEN_SUN6I) ?
+					   SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
+	} else {
+		/* Divide by 4 */
+		writel(SPI0_CLK_DIV_BY_4, base + (is_sun6i_gen_spi() ?
+					  SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
+		/* 24MHz from OSC24M */
+		writel((1 << 31), CCM_SPI0_CLK);
+	}
 
 	if (is_sun6i_gen_spi()) {
 		/* Enable SPI in the master mode and do a soft reset */
@@ -191,7 +199,8 @@ static void spi0_disable_clock(void)
 					     SUN4I_CTL_ENABLE);
 
 	/* Disable the SPI0 clock */
-	writel(0, CCM_SPI0_CLK);
+	if (!IS_ENABLED(CONFIG_MACH_SUNIV))
+		writel(0, CCM_SPI0_CLK);
 
 	/* Close the SPI0 gate */
 	if (!IS_ENABLED(CONFIG_MACH_SUN50I_H6))
@@ -213,6 +222,9 @@ static void spi0_init(void)
 	    IS_ENABLED(CONFIG_MACH_SUN50I_H6))
 		pin_function = SUN50I_GPC_SPI0;
 
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		pin_function = SUNIV_GPC_SPI0;
+
 	spi0_pinmux_setup(pin_function);
 	spi0_enable_clock();
 }
Signature · 1 line
2.34.1
#10 lore raw

Re: [PATCH v1 2/3] mach-sunxi: Add spi boot for SUNIV

On Wed, 9 Feb 2022 23:34:37 -0500
Jesse Taube <[email protected]> wrote:

Hi Jesse,

many thanks for sending this, I guess this makes those little boards much more useful.

Quoted 1 line

Add support for the spi boot in spl on suniv architecture.

A more elaborate commit message would be welcomed.
Please mention the F1C100s, to give some more context. Also briefly mention the differences, I think Icenowy summarised this quite well in her version of the patch (06/27):

The suniv SoC come with a sun6i-style SPI controller at the base address of sun4i SPI controller. The module clock of the SPI controller is also missing.

You could add: "... is also missing, which leaves us running directly from the AHB clock, set to 200 MHz."

Quoted 43 lines
---
 arch/arm/include/asm/arch-sunxi/gpio.h |  1 +
 arch/arm/mach-sunxi/spl_spi_sunxi.c    | 26 +++++++++++++++++++-------
 2 files changed, 20 insertions(+), 7 deletions(-)
arch/arm/include/asm/arch-sunxi/gpio.h +1 -0
index 7f7eb0517c..edd0fbf49f 100644
@@ -160,6 +160,7 @@ enum sunxi_gpio_number {
 #define SUNXI_GPC_SDC2		3
 #define SUN6I_GPC_SDC3		4
 #define SUN50I_GPC_SPI0		4
+#define SUNIV_GPC_SPI0		2
 
 #define SUNXI_GPD_LCD0		2
 #define SUNXI_GPD_LVDS0		3
arch/arm/mach-sunxi/spl_spi_sunxi.c +3 -1
index 910e805016..9a3666a2d7 100644
@@ -90,6 +90,7 @@
 
 #define SPI0_CLK_DIV_BY_2           0x1000
 #define SPI0_CLK_DIV_BY_4           0x1001
+#define SPI0_CLK_DIV_BY_32          0x100f
 
 /*****************************************************************************/
 
@@ -132,7 +133,8 @@ static uintptr_t spi0_base_address(void)
 	if (IS_ENABLED(CONFIG_MACH_SUN50I_H6))
 		return 0x05010000;
 
-	if (!is_sun6i_gen_spi())
+	if (!is_sun6i_gen_spi() ||
+	    IS_ENABLED(CONFIG_MACH_SUNIV))
 		return 0x01C05000;
 
 	return 0x01C68000;
@@ -156,11 +158,17 @@ static void spi0_enable_clock(void)
 	if (!IS_ENABLED(CONFIG_MACH_SUN50I_H6))

arch/arm/mach-sunxi/spl_spi_sunxi.c static void spi0_enable_clock(void) · line 163

Quoted 10 lines
arch/arm/mach-sunxi/spl_spi_sunxi.c +3 -5
 		setbits_le32(CCM_AHB_GATING0, (1 << AHB_GATE_OFFSET_SPI0));
 
-	/* Divide by 4 */
-	writel(SPI0_CLK_DIV_BY_4, base + (is_sun6i_gen_spi() ?
-				  SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
-	/* 24MHz from OSC24M */
-	writel((1 << 31), CCM_SPI0_CLK);
+	if (IS_ENABLED(CONFIG_MACH_SUNIV)) {
+		/* Divide by 32, clock source is AHB clock 200MHz */
+		writel(SPI0_CLK_DIV_BY_32, base + (IS_ENABLED(CONFIG_SUNXI_GEN_SUN6I) ?

This seems pointless and redundant, since we exactly know the register when MACH_SUNIV is selected.

Quoted 22 lines
arch/arm/mach-sunxi/spl_spi_sunxi.c +10 -1
+					   SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
+	} else {
+		/* Divide by 4 */
+		writel(SPI0_CLK_DIV_BY_4, base + (is_sun6i_gen_spi() ?
+					  SUN6I_SPI0_CCTL : SUN4I_SPI0_CCTL));
+		/* 24MHz from OSC24M */
+		writel((1 << 31), CCM_SPI0_CLK);
+	}
 
 	if (is_sun6i_gen_spi()) {
 		/* Enable SPI in the master mode and do a soft reset */
@@ -191,7 +199,8 @@ static void spi0_disable_clock(void)
 					     SUN4I_CTL_ENABLE);
 
 	/* Disable the SPI0 clock */
-	writel(0, CCM_SPI0_CLK);
+	if (!IS_ENABLED(CONFIG_MACH_SUNIV))
+		writel(0, CCM_SPI0_CLK);
 
 	/* Close the SPI0 gate */
 	if (!IS_ENABLED(CONFIG_MACH_SUN50I_H6))

arch/arm/mach-sunxi/spl_spi_sunxi.c static void spi0_init(void) · line 227

Quoted 6 lines
arch/arm/mach-sunxi/spl_spi_sunxi.c +3 -0
@@ -213,6 +222,9 @@ static void spi0_init(void)
 	    IS_ENABLED(CONFIG_MACH_SUN50I_H6))
 		pin_function = SUN50I_GPC_SPI0;
 
+	if (IS_ENABLED(CONFIG_MACH_SUNIV))
+		pin_function = SUNIV_GPC_SPI0;
+

It looks a bit better to tie connect this with an "else if" to the previous comparison, since there is only one choice.

Cheers,
Andre

Quoted 3 lines
arch/arm/mach-sunxi/spl_spi_sunxi.c +0 -0
 	spi0_pinmux_setup(pin_function);
 	spi0_enable_clock();
 }
#11 lore raw

PATCH 3/3 mach-sunxi: Enable spi boot for SUNIV

In reply to Jesse Taube

Enable spi boot in spl on suniv architecture.

---
 arch/arm/mach-sunxi/Kconfig     | 2 +-
 configs/licheepi_nano_defconfig | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-sunxi/Kconfig +1 -1
index 205fe3c9d3..d1c60d2408 100644
@@ -1038,7 +1038,7 @@ config SPL_STACK_R_ADDR
 
 config SPL_SPI_SUNXI
 	bool "Support for SPI Flash on Allwinner SoCs in SPL"
-	depends on MACH_SUN4I || MACH_SUN5I || MACH_SUN7I || MACH_SUNXI_H3_H5 || MACH_SUN50I || MACH_SUN8I_R40 || MACH_SUN50I_H6
+	depends on MACH_SUN4I || MACH_SUN5I || MACH_SUN7I || MACH_SUNXI_H3_H5 || MACH_SUN50I || MACH_SUN8I_R40 || MACH_SUN50I_H6 || MACH_SUNIV
 	help
 	  Enable support for SPI Flash. This option allows SPL to read from
 	  sunxi SPI Flash. It uses the same method as the boot ROM, so does
configs/licheepi_nano_defconfig +1 -0
index 2ac0ef4285..9fd1dcc995 100644
@@ -9,3 +9,4 @@ CONFIG_MACH_SUNIV=y
 CONFIG_DRAM_CLK=156
 CONFIG_DRAM_ZQ=0
 # CONFIG_VIDEO_SUNXI is not set
+CONFIG_SPL_SPI_SUNXI=y
Signature · 1 line
2.34.1
Reviewed-by on v1 3/3
#12 lore raw

Re: [PATCH v1 3/3] mach-sunxi: Enable spi boot for SUNIV

On Wed, 9 Feb 2022 23:34:38 -0500
Jesse Taube <[email protected]> wrote:

Hi,

Quoted 1 line

Enable spi boot in spl on suniv architecture.

Please mention the F1C100s for context, and also that you are enabling it for the LicheePi Nano board, which comes with SPI flash.

Otherwise:

Quoted 1 line

Cheers,
Andre

Quoted 27 lines
---
 arch/arm/mach-sunxi/Kconfig     | 2 +-
 configs/licheepi_nano_defconfig | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
arch/arm/mach-sunxi/Kconfig +1 -1
index 205fe3c9d3..d1c60d2408 100644
@@ -1038,7 +1038,7 @@ config SPL_STACK_R_ADDR
 
 config SPL_SPI_SUNXI
 	bool "Support for SPI Flash on Allwinner SoCs in SPL"
-	depends on MACH_SUN4I || MACH_SUN5I || MACH_SUN7I || MACH_SUNXI_H3_H5 || MACH_SUN50I || MACH_SUN8I_R40 || MACH_SUN50I_H6
+	depends on MACH_SUN4I || MACH_SUN5I || MACH_SUN7I || MACH_SUNXI_H3_H5 || MACH_SUN50I || MACH_SUN8I_R40 || MACH_SUN50I_H6 || MACH_SUNIV
 	help
 	  Enable support for SPI Flash. This option allows SPL to read from
 	  sunxi SPI Flash. It uses the same method as the boot ROM, so does
configs/licheepi_nano_defconfig +1 -0
index 2ac0ef4285..9fd1dcc995 100644
@@ -9,3 +9,4 @@ CONFIG_MACH_SUNIV=y
 CONFIG_DRAM_CLK=156
 CONFIG_DRAM_ZQ=0
 # CONFIG_VIDEO_SUNXI is not set
+CONFIG_SPL_SPI_SUNXI=y