Skip to contentSkip to conversation

board: sl28: various updates

PATCH Applied Michael Walle 2 participants 7 messages Aug 23, 2022 – Sep 7, 2022 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

v3 cover board: sl28: various updates

This is a resend of the original v1 series. It was just rebased. Apparently not all patches made it into u-boot. Unfortunately, there was no feedback at all.

This is an update for the sl28 board which adds support for
- 8 GiB memory variant
- different boot sources, like eMMC, SD-card
- dynamic prompts
- various cleanups

changes since v2:
- only mark secure ram on layerscape SoCs which actually have it.

changes since v1:
- rebased onto the latest master

Michael Walle (5):
armv8: layerscape: spl: mark OCRAM as non-secure
board: sl28: implement additional bootsources
board: sl28: add user friendly names for the boot sources
board: sl28: support dynamic prompts
board: sl28: remove COUNTER_FREQUENCY_REAL

 arch/arm/cpu/armv8/fsl-layerscape/spl.c | 13 ++++++
 board/kontron/sl28/common.c             | 22 ++++++++++
 board/kontron/sl28/sl28.c               | 43 ++++++++++++++++++++
 board/kontron/sl28/sl28.h               | 16 ++++++++
 board/kontron/sl28/spl.c                | 54 ++++++++++++++++++++++++-
 configs/kontron_sl28_defconfig          |  6 ++-
 include/configs/kontron_sl28.h          |  2 -
 7 files changed, 152 insertions(+), 4 deletions(-)
 create mode 100644 board/kontron/sl28/sl28.h
Signature · 1 line
2.30.2
#1 lore raw

PATCH v3 1/5 armv8: layerscape: spl: mark OCRAM as non-secure

By default the OCRAM is marked as secure. While the SPL runs in EL3 and thus can access it, DMA devices cannot. Mark the whole OCRAM as non-secure.
This will fix MMC and SD card boot on LS1028A when using SPL instead of TF-A.

---
 arch/arm/cpu/armv8/fsl-layerscape/spl.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/arm/cpu/armv8/fsl-layerscape/spl.c +13 -0
index 5f09ef0a4a..3a4b665f24 100644
@@ -67,11 +67,24 @@ void spl_board_init(void)
 #endif
 }
 
+void tzpc_init(void)
+{
+	/*
+	 * Mark the whole OCRAM as non-secure, otherwise DMA devices cannot
+	 * access it. This is for example necessary for MMC boot.
+	 */
+#ifdef TZPCR0SIZE_BASE
+	out_le32(TZPCR0SIZE_BASE, 0);
+#endif
+}
+
 void board_init_f(ulong dummy)
 {
 	int ret;
 
 	icache_enable();
+	tzpc_init();
+
 	/* Clear global data */
 	memset((void *)gd, 0, sizeof(gd_t));
 	if (IS_ENABLED(CONFIG_DEBUG_UART))
Signature · 1 line
2.30.2
#2 lore raw

PATCH v3 2/5 board: sl28: implement additional bootsources

In reply to Michael Walle

The board is able to boot from the following source:
- user-updateble SPI flash
- write-protected part of the same SPI flash
- eMMC
- SD card

Implement the needed function hooks to support all of these boot sources.

---
 board/kontron/sl28/common.c    | 22 ++++++++++++++++++++
 board/kontron/sl28/sl28.c      | 23 ++++++++++++++++++++
 board/kontron/sl28/sl28.h      | 16 ++++++++++++++
 board/kontron/sl28/spl.c       | 38 +++++++++++++++++++++++++++++++++-
 configs/kontron_sl28_defconfig |  5 ++++-
 5 files changed, 102 insertions(+), 2 deletions(-)
 create mode 100644 board/kontron/sl28/sl28.h
board/kontron/sl28/common.c +22 -0
index 33c6843c3f..331de29bae 100644
@@ -2,6 +2,9 @@
 
 #include <common.h>
 #include <asm/global_data.h>
+#include <asm/io.h>
+
+#include "sl28.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -9,3 +12,22 @@ u32 get_lpuart_clk(void)
 {
 	return gd->bus_clk / CONFIG_SYS_FSL_LPUART_CLK_DIV;
 }
+
+enum boot_source sl28_boot_source(void)
+{
+	u32 rcw_src = in_le32(DCFG_BASE + DCFG_PORSR1) & DCFG_PORSR1_RCW_SRC;
+
+	switch (rcw_src) {
+	case DCFG_PORSR1_RCW_SRC_SDHC1:
+		return BOOT_SOURCE_SDHC;
+	case DCFG_PORSR1_RCW_SRC_SDHC2:
+		return BOOT_SOURCE_MMC;
+	case DCFG_PORSR1_RCW_SRC_I2C:
+		return BOOT_SOURCE_I2C;
+	case DCFG_PORSR1_RCW_SRC_FSPI_NOR:
+		return BOOT_SOURCE_SPI;
+	default:
+		debug("unknown bootsource (%08x)\n", rcw_src);
+		return BOOT_SOURCE_UNKNOWN;
+	}
+}
board/kontron/sl28/sl28.c +23 -0
index 32e9694b77..54719cc01c 100644
@@ -24,6 +24,8 @@
 #include <fdtdec.h>
 #include <miiphy.h>
 
+#include "sl28.h"
+
 DECLARE_GLOBAL_DATA_PTR;
 
 #if CONFIG_IS_ENABLED(EFI_HAVE_CAPSULE_SUPPORT)
@@ -60,6 +62,27 @@ int board_eth_init(struct bd_info *bis)
 	return pci_eth_init(bis);
 }
 
+enum env_location env_get_location(enum env_operation op, int prio)
+{
+	enum boot_source src = sl28_boot_source();
+
+	if (prio)
+		return ENVL_UNKNOWN;
+
+	if (!CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
+		return ENVL_NOWHERE;
+
+	/* write and erase always operate on the environment */
+	if (op == ENVOP_SAVE || op == ENVOP_ERASE)
+		return ENVL_SPI_FLASH;
+
+	/* failsafe boot will always use the compiled-in default environment */
+	if (src == BOOT_SOURCE_SPI)
+		return ENVL_NOWHERE;
+
+	return ENVL_SPI_FLASH;
+}
+
 static int __sl28cpld_read(uint reg)
 {
 	struct udevice *dev;
board/kontron/sl28/sl28.h new file +16 -0
new file mode 100644
index 0000000000..7f0105049c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef __SL28_H
+#define __SL28_H
+
+enum boot_source {
+	BOOT_SOURCE_UNKNOWN,
+	BOOT_SOURCE_SDHC,
+	BOOT_SOURCE_MMC,
+	BOOT_SOURCE_I2C,
+	BOOT_SOURCE_SPI,
+};
+
+enum boot_source sl28_boot_source(void);
+
+#endif
board/kontron/sl28/spl.c +37 -1
index 0e6ad5f37e..b1fefc22b2 100644
@@ -5,6 +5,9 @@
 #include <asm/spl.h>
 #include <asm/arch-fsl-layerscape/fsl_serdes.h>
 #include <asm/arch-fsl-layerscape/soc.h>
+#include <spi_flash.h>
+
+#include "sl28.h"
 
 #define DCFG_RCWSR25 0x160
 #define GPINFO_HW_VARIANT_MASK 0xff
@@ -58,7 +61,40 @@ int board_fit_config_name_match(const char *name)
 
 void board_boot_order(u32 *spl_boot_list)
 {
-	spl_boot_list[0] = BOOT_DEVICE_SPI;
+	enum boot_source src = sl28_boot_source();
+
+	switch (src) {
+	case BOOT_SOURCE_SDHC:
+		spl_boot_list[0] = BOOT_DEVICE_MMC2;
+		break;
+	case BOOT_SOURCE_SPI:
+	case BOOT_SOURCE_I2C:
+		spl_boot_list[0] = BOOT_DEVICE_SPI;
+		break;
+	case BOOT_SOURCE_MMC:
+		spl_boot_list[0] = BOOT_DEVICE_MMC1;
+		break;
+	default:
+		panic("unexpected bootsource (%d)\n", src);
+		break;
+	}
+}
+
+unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash)
+{
+	enum boot_source src = sl28_boot_source();
+
+	switch (src) {
+	case BOOT_SOURCE_SPI:
+		return 0x000000;
+	case BOOT_SOURCE_I2C:
+		return 0x230000;
+	default:
+		panic("unexpected bootsource (%d)\n", src);
+		break;
+	}
+}
+
 }
 
 int board_early_init_f(void)
configs/kontron_sl28_defconfig +4 -1
index b0b5fb11ca..4d50c681f9 100644
@@ -12,6 +12,7 @@ CONFIG_ENV_SECT_SIZE=0x10000
 CONFIG_DEFAULT_DEVICE_TREE="fsl-ls1028a-kontron-sl28"
 CONFIG_SPL_TEXT_BASE=0x18010000
 CONFIG_SYS_FSL_SDHC_CLK_DIV=1
+CONFIG_SPL_MMC=y
 CONFIG_SPL_SERIAL=y
 CONFIG_SPL_SIZE_LIMIT=0x20000
 CONFIG_SPL_SIZE_LIMIT_PROVIDE_STACK=0x0
@@ -46,9 +47,11 @@ CONFIG_SPL_BOARD_INIT=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_STACK=0x18009ff0
 CONFIG_SYS_SPL_MALLOC=y
+CONFIG_SPL_SEPARATE_BSS=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR=y
+CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x900
 CONFIG_SPL_MPC8XXX_INIT_DDR=y
 CONFIG_SPL_SPI_LOAD=y
-CONFIG_SYS_SPI_U_BOOT_OFFS=0x230000
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x800000
Signature · 1 line
2.30.2
#3 lore raw

PATCH v3 3/5 board: sl28: add user friendly names for the boot sources

In reply to Michael Walle

During startup the SPL will print where the u-boot proper is read from. Instead of using the default names, provide more user friendly names.

---
 board/kontron/sl28/spl.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
board/kontron/sl28/spl.c +16 -0
index b1fefc22b2..ffaf517a8b 100644
@@ -95,6 +95,22 @@ unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash)
 	}
 }
 
+const char *spl_board_loader_name(u32 boot_device)
+{
+	enum boot_source src = sl28_boot_source();
+
+	switch (src) {
+	case BOOT_SOURCE_SDHC:
+		return "SD card (Test mode)";
+	case BOOT_SOURCE_SPI:
+		return "Failsafe SPI flash";
+	case BOOT_SOURCE_I2C:
+		return "SPI flash";
+	case BOOT_SOURCE_MMC:
+		return "eMMC";
+	default:
+		return "(unknown)";
+	}
 }
 
 int board_early_init_f(void)
Signature · 1 line
2.30.2
#4 lore raw

PATCH v3 4/5 board: sl28: support dynamic prompts

In reply to Michael Walle

Depending on the boot source, set different CLI prompts. This will help the user to figure out in which mode the bootloader was started. There are two special modes: failsafe and SDHC boot.

---
 board/kontron/sl28/sl28.c      | 20 ++++++++++++++++++++
 configs/kontron_sl28_defconfig |  1 +
 2 files changed, 21 insertions(+)
board/kontron/sl28/sl28.c +20 -0
index 54719cc01c..0576b3eae4 100644
@@ -126,8 +126,28 @@ static void stop_recovery_watchdog(void)
 		wdt_stop(dev);
 }
 
+static void sl28_set_prompt(void)
+{
+	enum boot_source src = sl28_boot_source();
+
+	switch (src) {
+	case BOOT_SOURCE_SPI:
+		env_set("PS1", "[FAILSAFE] => ");
+		break;
+	case BOOT_SOURCE_SDHC:
+		env_set("PS1", "[SDHC] => ");
+		break;
+	default:
+		env_set("PS1", NULL);
+		break;
+	}
+}
+
 int fsl_board_late_init(void)
 {
+	if (IS_ENABLED(CONFIG_CMDLINE_PS_SUPPORT))
+		sl28_set_prompt();
+
 	/*
 	 * Usually, the after a board reset, the watchdog is enabled by
 	 * default. This is to supervise the bootloader boot-up. Therefore,
configs/kontron_sl28_defconfig +1 -0
index 4d50c681f9..fc1c607927 100644
@@ -55,6 +55,7 @@ CONFIG_SPL_SPI_LOAD=y
 CONFIG_SYS_CBSIZE=256
 CONFIG_SYS_PBSIZE=276
 CONFIG_SYS_BOOTM_LEN=0x800000
+CONFIG_CMDLINE_PS_SUPPORT=y
 CONFIG_CMD_ASKENV=y
 CONFIG_CMD_GREPENV=y
 CONFIG_CMD_NVEDIT_EFI=y
Signature · 1 line
2.30.2
#5 lore raw

PATCH v3 5/5 board: sl28: remove COUNTER_FREQUENCY_REAL

In reply to Michael Walle

The frequency of the system counter is static which is given by the COUNTER_FREQUENCY option. Remove COUNTER_FREQUENCY_REAL.

---
 include/configs/kontron_sl28.h | 2 --
 1 file changed, 2 deletions(-)
include/configs/kontron_sl28.h +0 -2
index 38063ba484..df46e586f3 100644
@@ -37,8 +37,6 @@
 /* serial port */
 #define CONFIG_SYS_NS16550_CLK          (get_bus_freq(0) / 2)
 
-#define COUNTER_FREQUENCY_REAL		(get_board_sys_clk() / 4)
-
 /* SPL */
 
 #define CONFIG_SYS_MONITOR_LEN		(1024 * 1024)
Signature · 1 line
2.30.2
Applied
#6 lore raw
In reply to Michael Walle
Quoted 31 lines · Michael Walle

This is a resend of the original v1 series. It was just rebased. Apparently not all patches made it into u-boot. Unfortunately, there was no feedback at all.

This is an update for the sl28 board which adds support for
- 8 GiB memory variant
- different boot sources, like eMMC, SD-card
- dynamic prompts
- various cleanups

changes since v2:
- only mark secure ram on layerscape SoCs which actually have it.

changes since v1:
- rebased onto the latest master

Michael Walle (5):
armv8: layerscape: spl: mark OCRAM as non-secure
board: sl28: implement additional bootsources
board: sl28: add user friendly names for the boot sources
board: sl28: support dynamic prompts
board: sl28: remove COUNTER_FREQUENCY_REAL

  arch/arm/cpu/armv8/fsl-layerscape/spl.c | 13 ++++++
  board/kontron/sl28/common.c             | 22 ++++++++++
  board/kontron/sl28/sl28.c               | 43 ++++++++++++++++++++
  board/kontron/sl28/sl28.h               | 16 ++++++++
  board/kontron/sl28/spl.c                | 54 ++++++++++++++++++++++++-
  configs/kontron_sl28_defconfig          |  6 ++-
  include/configs/kontron_sl28.h          |  2 -
  7 files changed, 152 insertions(+), 4 deletions(-)
Quoted 2 lines

create mode 100644 board/kontron/sl28/sl28.h

Applied, PR sent.

Thanks,
Peng.