Skip to contentSkip to conversation

Clean out SPL and enable driver model

PATCH Superseded Simon Glass 1 participant 7 messages Feb 10, 2015 – Feb 23, 2015

Subsystems (4)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover Clean out SPL and enable driver model

This series includes a few more patches aimed at getting rid of gdata, the parallel global_data structure introduced on some ARM boards.

It also collects together the other patches which have been sent previously, so that everything is in one place.

I would like get this agreed and applied to u-boot-dm this week if possible so that we will at last have driver model available in SPL.

This series is available at u-boot-dm/spl-working.

Changes in v4:
- Squash the gdata revert patch into this one
- Allow gdata to survive unless CONFIG_DM is defined, for now
- Rebase on top of dm/master
- Adjust README to mention that lowlevel_init() should have no stack
- Add new patch to make the export interface support CONFIG_SYS_MALLOC_SIMPLE

Changes in v3:
- Drop extra blank line

Changes in v2:
- Remove gdata definition from ARM spl header file also
- Rebase on top of the SPI series
- Move docs to top-level README file and expand them to cover U-Boot proper
- Add Kconfig settings

Simon Glass (5):
arm: Reduce the scope of lowlevel_init()
arm: spl: Avoid setting up a duplicate global data structure
dm: tegra: Enable driver model in SPL and adjust the GPIO driver
arm: spl: Allow board_init_r() to run with a larger stack Make export interface support CONFIG_SYS_MALLOC_SIMPLE

 Kconfig                                 | 18 +++++++++
 README                                  | 69 +++++++++++++++++++++++++++++++++
 arch/arm/cpu/armv7/lowlevel_init.S      | 23 ++++++-----
 arch/arm/cpu/armv7/tegra-common/Kconfig | 15 ++++---
 arch/arm/include/asm/spl.h              |  2 +
 arch/arm/lib/crt0.S                     | 13 +++++--
 arch/arm/lib/spl.c                      |  4 ++
 board/nvidia/seaboard/seaboard.c        |  4 +-
 common/spl/spl.c                        | 35 +++++++++++++++++
 drivers/gpio/Makefile                   |  4 ++
 drivers/gpio/tegra_gpio.c               | 27 ++++++-------
 include/_exports.h                      |  2 +
 include/configs/tegra-common.h          |  6 ---
 include/exports.h                       |  2 +
 14 files changed, 180 insertions(+), 44 deletions(-)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v4 1/5 arm: Reduce the scope of lowlevel_init()

This function has grown into something of a monster. Some boards are setting up a console and DRAM here in SPL. This requires global_data which should be set up in one place (crt0.S).

There is no need for SPL to use s_init() for anything since board_init_f() is called immediately afterwards.

---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/cpu/armv7/lowlevel_init.S | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
arch/arm/cpu/armv7/lowlevel_init.S +13 -10
index f1aea05..4803150 100644
@@ -17,24 +17,27 @@
 
 ENTRY(lowlevel_init)
 	/*
-	 * Setup a temporary stack
+	 * Setup a temporary stack. Global data is not available yet.
 	 */
 	ldr	sp, =CONFIG_SYS_INIT_SP_ADDR
-	bic	sp, sp, #7 /* 8-byte alignment for ABI compliance */
-#ifdef CONFIG_SPL_BUILD
-	ldr	r9, =gdata
-#else
-	sub	sp, sp, #GD_SIZE
-	bic	sp, sp, #7
-	mov	r9, sp
-#endif
+	mov	r9, #0
 	/*
 	 * Save the old lr(passed in ip) and the current lr to stack
 	 */
 	push	{ip, lr}
 
 	/*
-	 * go setup pll, mux, memory
+	 * Call the very early init function. This should do only the
+	 * absolute bare minimum to get started. It should not:
+	 *
+	 * - set up DRAM
+	 * - use global_data
+	 * - clear BSS
+	 * - try to start a console
+	 *
+	 * For boards with SPL this should be empty since SPL can do all of
+	 * this init in the SPL board_init_f() function which is called
+	 * immediately after this.
 	 */
 	bl	s_init
 	pop	{ip, pc}
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#2 lore raw

PATCH v4 2/5 arm: spl: Avoid setting up a duplicate global data structure

In reply to Simon Glass

This is already set up in crt0.S. We don't need a new structure and don't really want one in the 'data' section of the image, since it will be empty and crt0.S's changes will be ignored.

As an interim measure, remove it only if CONFIG_DM is not defined. This allows us to press ahead with driver model in SPL and allow the stragglers to catch up.

---

Changes in v4:
- Squash the gdata revert patch into this one
- Allow gdata to survive unless CONFIG_DM is defined, for now

Changes in v3: None
Changes in v2:
- Remove gdata definition from ARM spl header file also

 arch/arm/include/asm/spl.h | 2 ++
 arch/arm/lib/spl.c         | 4 ++++
 2 files changed, 6 insertions(+)
arch/arm/include/asm/spl.h +2 -0
index 8acd7cd..a6fdcf0 100644
@@ -33,6 +33,8 @@ enum {
 /* Linker symbols. */
 extern char __bss_start[], __bss_end[];
 
+#ifndef CONFIG_DM
 extern gd_t gdata;
+#endif
 
 #endif
arch/arm/lib/spl.c +4 -0
index c41850a..bd8c7d2 100644
@@ -13,6 +13,7 @@
 #include <image.h>
 #include <linux/compiler.h>
 
+#ifndef CONFIG_DM
 /* Pointer to as well as the global data structure for SPL */
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -21,6 +22,7 @@ DECLARE_GLOBAL_DATA_PTR;
  * pafches that rely on it. The global_data area is set up in crt0.S.
  */
 gd_t gdata __attribute__ ((section(".data")));
+#endif
 
 /*
  * In the context of SPL, board_init_f must ensure that any clocks/etc for
@@ -33,8 +35,10 @@ void __weak board_init_f(ulong dummy)
 	/* Clear the BSS. */
 	memset(__bss_start, 0, __bss_end - __bss_start);
 
+#ifndef CONFIG_DM
 	/* TODO: Remove settings of the global data pointer here */
 	gd = &gdata;
+#endif
 
 	board_init_r(NULL, 0);
 }
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#3 lore raw

PATCH v4 3/5 dm: tegra: Enable driver model in SPL and adjust the GPIO driver

In reply to Simon Glass

Use the full driver model GPIO and serial drivers in SPL now that these are supported. Since device tree is not available they will use platform data.

Remove the special SPL GPIO function as it is no longer needed.

This is all in one commit to maintain bisectability.

---

Changes in v4:
- Rebase on top of dm/master

Changes in v3:
- Drop extra blank line

Changes in v2:
- Rebase on top of the SPI series

 arch/arm/cpu/armv7/tegra-common/Kconfig | 15 +++++++++------
 board/nvidia/seaboard/seaboard.c        |  4 +---
 drivers/gpio/Makefile                   |  4 ++++
 drivers/gpio/tegra_gpio.c               | 27 +++++++++++----------------
 include/configs/tegra-common.h          |  6 ------
 5 files changed, 25 insertions(+), 31 deletions(-)
arch/arm/cpu/armv7/tegra-common/Kconfig +9 -6
index ee32469..0b427cb 100644
@@ -27,22 +27,25 @@ config USE_PRIVATE_LIBGCC
 	default y if SPL_BUILD
 
 config DM
-	default y if !SPL_BUILD
+	default y
+
+config SPL_DM
+	default y
 
 config DM_SERIAL
-	default y if !SPL_BUILD
+	default y
 
 config DM_SPI
-	default y if !SPL_BUILD
+	default y
 
 config DM_SPI_FLASH
-	default y if !SPL_BUILD
+	default y
 
 config DM_I2C
-	default y if !SPL_BUILD
+	default y
 
 config DM_GPIO
-	default y if !SPL_BUILD
+	default y
 
 source "arch/arm/cpu/armv7/tegra20/Kconfig"
 source "arch/arm/cpu/armv7/tegra30/Kconfig"
board/nvidia/seaboard/seaboard.c +1 -3
index 11472eb..25480e4 100644
@@ -20,10 +20,8 @@
 void gpio_early_init_uart(void)
 {
 	/* Enable UART via GPIO_PI3 (port 8, bit 3) so serial console works */
-#ifndef CONFIG_SPL_BUILD
 	gpio_request(GPIO_PI3, NULL);
-#endif
-	tegra_spl_gpio_direction_output(GPIO_PI3, 0);
+	gpio_direction_output(GPIO_PI3, 0);
 }
 #endif
 
drivers/gpio/Makefile +4 -0
index aa11f15..fe9a3b2 100644
@@ -8,6 +8,10 @@
 ifndef CONFIG_SPL_BUILD
 obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
 endif
+/* TODO(sjg at chromium.org): Only tegra supports driver model in SPL */
+ifdef CONFIG_TEGRA_GPIO
+obj-$(CONFIG_DM_GPIO)		+= gpio-uclass.o
+endif
 
 obj-$(CONFIG_AT91_GPIO)	+= at91_gpio.o
 obj-$(CONFIG_INTEL_ICH6_GPIO)	+= intel_ich6_gpio.o
drivers/gpio/tegra_gpio.c +11 -16
index 43928b8..f870cdb 100644
@@ -132,21 +132,6 @@ static void set_level(unsigned gpio, int high)
 	writel(u, &bank->gpio_out[GPIO_PORT(gpio)]);
 }
 
-/* set GPIO pin 'gpio' as an output, with polarity 'value' */
-int tegra_spl_gpio_direction_output(int gpio, int value)
-{
-	/* Configure as a GPIO */
-	set_config(gpio, 1);
-
-	/* Configure GPIO output value. */
-	set_level(gpio, value);
-
-	/* Configure GPIO direction as output. */
-	set_direction(gpio, 1);
-
-	return 0;
-}
-
 /*
  * Generic_GPIO primitives.
  */
@@ -338,12 +323,19 @@ static int gpio_tegra_bind(struct udevice *parent)
 	int bank_count;
 	int bank;
 	int ret;
-	int len;
 
 	/* If this is a child device, there is nothing to do here */
 	if (plat)
 		return 0;
 
+	/* TODO(sjg at chromium.org): Remove once SPL supports device tree */
+#ifdef CONFIG_SPL_BUILD
+	ctlr = (struct gpio_ctlr *)NV_PA_GPIO_BASE;
+	bank_count = TEGRA_GPIO_BANKS;
+#else
+	{
+	int len;
+
 	/*
 	 * This driver does not make use of interrupts, other than to figure
 	 * out the number of GPIO banks
@@ -353,6 +345,8 @@ static int gpio_tegra_bind(struct udevice *parent)
 	bank_count = len / 3 / sizeof(u32);
 	ctlr = (struct gpio_ctlr *)fdtdec_get_addr(gd->fdt_blob,
 						   parent->of_offset, "reg");
+	}
+#endif
 	for (bank = 0; bank < bank_count; bank++) {
 		int port;
 
@@ -388,4 +382,5 @@ U_BOOT_DRIVER(gpio_tegra) = {
 	.probe = gpio_tegra_probe,
 	.priv_auto_alloc_size = sizeof(struct tegra_port_info),
 	.ops	= &gpio_tegra_ops,
+	.flags	= DM_FLAG_PRE_RELOC,
 };
include/configs/tegra-common.h +0 -6
index 005fc6a..fa6ccc1 100644
@@ -43,13 +43,7 @@
 /*
  * NS16550 Configuration
  */
-#ifdef CONFIG_SPL_BUILD
-#define CONFIG_SYS_NS16550_SERIAL
-#define CONFIG_SYS_NS16550_REG_SIZE	(-4)
-#define CONFIG_SYS_NS16550_CLK		V_NS16550_CLK
-#else
 #define CONFIG_TEGRA_SERIAL
-#endif
 #define CONFIG_SYS_NS16550
 
 /*
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#4 lore raw

PATCH v4 4/5 arm: spl: Allow board_init_r() to run with a larger stack

In reply to Simon Glass

At present SPL uses a single stack, either CONFIG_SPL_STACK or CONFIG_SYS_INIT_SP_ADDR. Since some SPL features (such as MMC and environment) require a lot of stack, some boards set CONFIG_SPL_STACK to point into SDRAM. They then set up SDRAM very early, before board_init_f(), so that the larger stack can be used.

This is an abuse of lowlevel_init(). That function should only be used for essential start-up code which cannot be delayed. An example of a valid use is when only part of the SPL code is visible/executable, and the SoC must be set up so that board_init_f() can be reached. It should not be used for SDRAM init, console init, etc.

Add a CONFIG_SPL_STACK_R option, which allows the stack to be moved to a new address before board_init_r() is called in SPL.

The expected SPL flow (for CONFIG_SPL_FRAMEWORK) is documented in the README.

For version 1:

---

Changes in v4:
- Adjust README to mention that lowlevel_init() should have no stack

Changes in v3: None
Changes in v2:
- Move docs to top-level README file and expand them to cover U-Boot proper
- Add Kconfig settings

 Kconfig             | 18 ++++++++++++++
 README              | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 arch/arm/lib/crt0.S | 13 +++++++---
 common/spl/spl.c    | 35 +++++++++++++++++++++++++++
 4 files changed, 132 insertions(+), 3 deletions(-)
Kconfig +18 -0
index 75bab7f..cc68c88 100644
@@ -111,6 +111,24 @@ config SPL
 	help
 	  If you want to build SPL as well as the normal image, say Y.
 
+config CONFIG_SPL_STACK_R
+	depends on SPL
+	bool "Enable SDRAM location for SPL stack"
+	help
+	  SPL starts off execution in SRAM and thus typically has only a small
+	  stack available. Since SPL sets up DRAM while in its board_init_f()
+	  function, it is possible for the stack to move there before
+	  board_init_r() is reached. This option enables a special SDRAM
+	  location for the SPL stack. U-Boot SPL switches to this after
+	  board_init_f() completes, and before board_init_r() starts.
+
+config CONFIG_SPL_STACK_R_ADDR
+	depends on CONFIG_SPL_STACK_R
+	hex "SDRAM location for SPL stack"
+	help
+	  Specify the address in SDRAM for the SPL stack. This will be set up
+	  before board_init_r() is called.
+
 config TPL
 	bool
 	depends on SPL && SUPPORT_TPL
README +69 -0

75 lines not on this page · raw message

arch/arm/lib/crt0.S +10 -3
index 22df3e5..7939ced 100644
@@ -113,7 +113,14 @@ here:
 /* Set up final (full) environment */
 
 	bl	c_runtime_cpu_setup	/* we still call old routine here */
-
+#endif
+#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_FRAMEWORK)
+# ifdef CONFIG_SPL_BUILD
+	/* Use a DRAM stack for the rest of SPL, if requested */
+	bl	spl_relocate_stack_gd
+	cmp	r0, #0
+	movne	sp, r0
+# endif
 	ldr	r0, =__bss_start	/* this is auto-relocated! */
 	ldr	r1, =__bss_end		/* this is auto-relocated! */
 
@@ -124,9 +131,10 @@ clbss_l:cmp	r0, r1			/* while not at end of BSS */
 	addlo	r0, r0, #4		/* move to next */
 	blo	clbss_l
 
+#if ! defined(CONFIG_SPL_BUILD)
 	bl coloured_LED_init
 	bl red_led_on
-
+#endif
 	/* call board_init_r(gd_t *id, ulong dest_addr) */
 	mov     r0, r9                  /* gd_t */
 	ldr	r1, [r9, #GD_RELOCADDR]	/* dest_addr */
@@ -134,7 +142,6 @@ clbss_l:cmp	r0, r1			/* while not at end of BSS */
 	ldr	pc, =board_init_r	/* this is auto-relocated! */
 
 	/* we should not return here. */
-
 #endif
 
 ENDPROC(_main)
common/spl/spl.c +35 -0
index daaeb50..46c7a96 100644
@@ -276,3 +276,38 @@ void preloader_console_init(void)
 	spl_display_print();
 #endif
 }
+
+/**
+ * spl_relocate_stack_gd() - Relocate stack ready for board_init_r() execution
+ *
+ * Sometimes board_init_f() runs with a stack in SRAM but we want to use SDRAM
+ * for the main board_init_r() execution. This is typically because we need
+ * more stack space for things like the MMC sub-system.
+ *
+ * This function calculates the stack position, copies the global_data into
+ * place and returns the new stack position. The caller is responsible for
+ * setting up the sp register.
+ *
+ * @return new stack location, or 0 to use the same stack
+ */
+ulong spl_relocate_stack_gd(void)
+{
+#ifdef CONFIG_SPL_STACK_R
+	gd_t *new_gd;
+	ulong ptr;
+
+	/* Get stack position: use 8-byte alignment for ABI compliance */
+	ptr = CONFIG_SPL_STACK_R - sizeof(gd_t);
+	ptr &= ~7;
+	new_gd = (gd_t *)ptr;
+	memcpy(new_gd, (void *)gd, sizeof(gd_t));
+	gd = new_gd;
+
+	/* Clear the BSS. */
+	memset(__bss_start, 0, __bss_end - __bss_start);
+
+	return ptr;
+#else
+	return 0;
+#endif
+}
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#5 lore raw

PATCH v4 5/5 Make export interface support CONFIG_SYS_MALLOC_SIMPLE

In reply to Simon Glass

When CONFIG_SYS_MALLOC_SIMPLE is defined, free() is a static inline. Make sure that the export interface still builds in this case.

---

Changes in v4:
- Add new patch to make the export interface support CONFIG_SYS_MALLOC_SIMPLE

Changes in v3: None
Changes in v2: None

 include/_exports.h | 2 ++
 include/exports.h  | 2 ++
 2 files changed, 4 insertions(+)
include/_exports.h +2 -0
index 5944703..279017e 100644
@@ -23,7 +23,9 @@
 	EXPORT_FUNC(dummy, void, free_hdlr, void)
 #endif
 	EXPORT_FUNC(malloc, void *, malloc, size_t)
+#ifndef CONFIG_SYS_MALLOC_SIMPLE
 	EXPORT_FUNC(free, void, free, void *)
+#endif
 	EXPORT_FUNC(udelay, void, udelay, unsigned long)
 	EXPORT_FUNC(get_timer, unsigned long, get_timer, unsigned long)
 	EXPORT_FUNC(vprintf, int, vprintf, const char *, va_list)
include/exports.h +2 -0
index 205affe..1a01e43 100644
@@ -15,7 +15,9 @@ int printf(const char* fmt, ...);
 void install_hdlr(int, interrupt_handler_t, void*);
 void free_hdlr(int);
 void *malloc(size_t);
+#ifndef CONFIG_SYS_MALLOC_SIMPLE
 void free(void*);
+#endif
 void __udelay(unsigned long);
 unsigned long get_timer(unsigned long);
 int vprintf(const char *, va_list);
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#6 lore raw

v4 cover Clean out SPL and enable driver model

In reply to Simon Glass

Hi,

Quoted 9 lines · Simon Glass

This series includes a few more patches aimed at getting rid of gdata, the parallel global_data structure introduced on some ARM boards.

It also collects together the other patches which have been sent previously, so that everything is in one place.

I would like get this agreed and applied to u-boot-dm this week if possible so that we will at last have driver model available in SPL.

Quoted 8 lines

This series is available at u-boot-dm/spl-working.

Changes in v4:
- Squash the gdata revert patch into this one
- Allow gdata to survive unless CONFIG_DM is defined, for now
- Rebase on top of dm/master
- Adjust README to mention that lowlevel_init() should have no stack
- Add new patch to make the export interface support CONFIG_SYS_MALLOC_SIMPLE

If there are no more comments I would like to apply this to dm/master and enable driver model in SPL. I think that putting #ifdef around gdata instead of removing it is safer for now. We can always remove it later.

However if we are going to Masahiro's 'single .config' series soon (as I hope!) then I will hold off, and rebase against that once it is applied.

Quoted 33 lines

Changes in v3:
- Drop extra blank line

Changes in v2:
- Remove gdata definition from ARM spl header file also
- Rebase on top of the SPI series
- Move docs to top-level README file and expand them to cover U-Boot proper
- Add Kconfig settings

Simon Glass (5):
arm: Reduce the scope of lowlevel_init()
arm: spl: Avoid setting up a duplicate global data structure
dm: tegra: Enable driver model in SPL and adjust the GPIO driver
arm: spl: Allow board_init_r() to run with a larger stack Make export interface support CONFIG_SYS_MALLOC_SIMPLE

 Kconfig                                 | 18 +++++++++
 README                                  | 69 +++++++++++++++++++++++++++++++++
 arch/arm/cpu/armv7/lowlevel_init.S      | 23 ++++++-----
 arch/arm/cpu/armv7/tegra-common/Kconfig | 15 ++++---
 arch/arm/include/asm/spl.h              |  2 +
 arch/arm/lib/crt0.S                     | 13 +++++--
 arch/arm/lib/spl.c                      |  4 ++
 board/nvidia/seaboard/seaboard.c        |  4 +-
 common/spl/spl.c                        | 35 +++++++++++++++++
 drivers/gpio/Makefile                   |  4 ++
 drivers/gpio/tegra_gpio.c               | 27 ++++++-------
 include/_exports.h                      |  2 +
 include/configs/tegra-common.h          |  6 ---
 include/exports.h                       |  2 +
 14 files changed, 180 insertions(+), 44 deletions(-)
Quoted 3 lines

--
2.2.0.rc0.207.ga3a616c

Regards,
Simon