Skip to contentSkip to conversation

add TCB driver for sama5d2

PATCH Superseded Clément Léger 2 participants 11 messages Mar 11, 2022 – Mar 31, 2022

Subsystems (3)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover add TCB driver for sama5d2

When booting under OP-TEE, the SYSC is secured which means the PIT is also not accessible by non-secure world. The TCB 0 however is always available for non-secure world and thus can be used.
This series add a TCB driver and enables it in sama5d2 configs.

---
Changes in v7:
- Keep the exact same Linux aic node definition
- Fixed a few constant definition to use (1 << x)

Changes in V6:
- Fix node ordering in device tree
- Disable CONFIG_PIT_TIMER in sama5d2 configuration file
- Fixed mach-at91/armv7/Makefile to allow building with TCB

Changes in v5:
- Fixed missing include in .dts file for IRQ defines
- Add aic interrupt controller node to avoid DTC warnings

Changes in v4:
- Add missing interrupts property to tcb node

Changes in v3:
- Remove useless defines
- Add printf in case of unsupported timers specified in device-tree
- Add "syscon" compatible to tcb node

Changes in v2:
- Reworked driver to use existing Linux bindings

Clément Léger (4):
timer: atmel_tcb_timer: add atmel_tcb driver
ARM: dts: at91: sama5d2: add AIC node
ARM: dts: at91: sama5d2: add TCB node
configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

 MAINTAINERS                                  |   1 +
 arch/arm/dts/sama5d2.dtsi                    |  25 +++
 arch/arm/mach-at91/armv7/Makefile            |   2 +
 configs/sama5d2_icp_mmc_defconfig            |   2 +-
 configs/sama5d2_ptc_ek_mmc_defconfig         |   2 +-
 configs/sama5d2_ptc_ek_nandflash_defconfig   |   2 +-
 configs/sama5d2_xplained_emmc_defconfig      |   2 +-
 configs/sama5d2_xplained_mmc_defconfig       |   2 +-
 configs/sama5d2_xplained_qspiflash_defconfig |   2 +-
 configs/sama5d2_xplained_spiflash_defconfig  |   2 +-
 drivers/timer/Kconfig                        |   8 +
 drivers/timer/Makefile                       |   1 +
 drivers/timer/atmel_tcb_timer.c              | 154 +++++++++++++++++++
 13 files changed, 198 insertions(+), 7 deletions(-)
 create mode 100644 drivers/timer/atmel_tcb_timer.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v7 1/4 timer: atmel_tcb_timer: add atmel_tcb driver

Add a driver for the timer counter block that can be found on sama5d2. This driver will be used when booting under OP-TEE since the pit timer which is part of the SYSC is secured. Channel 1 & 2 are configured to be chained together which allows to have a 64bits counter.

---
 MAINTAINERS                       |   1 +
 arch/arm/mach-at91/armv7/Makefile |   2 +
 drivers/timer/Kconfig             |   8 ++
 drivers/timer/Makefile            |   1 +
 drivers/timer/atmel_tcb_timer.c   | 154 ++++++++++++++++++++++++++++++
 5 files changed, 166 insertions(+)
 create mode 100644 drivers/timer/atmel_tcb_timer.c
MAINTAINERS +1 -0
index 0f39bc6bc9..e30389dc3e 100644
@@ -352,6 +352,7 @@ F:	arch/arm/mach-at91/
 F:	board/atmel/
 F:	drivers/cpu/at91_cpu.c
 F:	drivers/misc/microchip_flexcom.c
+F:	drivers/timer/atmel_tcb_timer.c
 F:	include/dt-bindings/mfd/atmel-flexcom.h
 F:	drivers/timer/mchp-pit64b-timer.c
 
arch/arm/mach-at91/armv7/Makefile +2 -0
index 246050b67b..f395b55c3d 100644
@@ -14,9 +14,11 @@ obj-y += cpu.o
 ifndef CONFIG_$(SPL_TPL_)SYSRESET
 obj-y	+= reset.o
 endif
+ifneq ($(CONFIG_ATMEL_TCB_TIMER),y)
 ifneq ($(CONFIG_ATMEL_PIT_TIMER),y)
 ifneq ($(CONFIG_MCHP_PIT64B_TIMER),y)
 # old non-DM timer driver
 obj-y += timer.o
 endif
 endif
+endif
drivers/timer/Kconfig +8 -0
index 8913142654..8fad59b81a 100644
@@ -96,6 +96,14 @@ config ATMEL_PIT_TIMER
 	  it is designed to offer maximum accuracy and efficient management,
 	  even for systems with long response time.
 
+config ATMEL_TCB_TIMER
+	bool "Atmel timer counter support"
+	depends on TIMER
+	depends on ARCH_AT91
+	help
+	  Select this to enable the use of the timer counter as a monotonic
+	  counter.
+
 config CADENCE_TTC_TIMER
 	bool "Cadence TTC (Triple Timer Counter)"
 	depends on TIMER
drivers/timer/Makefile +1 -0
index e2bd530eb0..58da6c1e84 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_ARC_TIMER)	+= arc_timer.o
 obj-$(CONFIG_AST_TIMER)	+= ast_timer.o
 obj-$(CONFIG_ATCPIT100_TIMER) += atcpit100_timer.o
 obj-$(CONFIG_ATMEL_PIT_TIMER) += atmel_pit_timer.o
+obj-$(CONFIG_ATMEL_TCB_TIMER) += atmel_tcb_timer.o
 obj-$(CONFIG_CADENCE_TTC_TIMER)	+= cadence-ttc.o
 obj-$(CONFIG_DESIGNWARE_APB_TIMER)	+= dw-apb-timer.o
 obj-$(CONFIG_MPC83XX_TIMER) += mpc83xx_timer.o
drivers/timer/atmel_tcb_timer.c new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

PATCH v7 2/4 ARM: dts: at91: sama5d2: add AIC node

In reply to Clément Léger

When using interrupts property, a global interrupt controller needs to be added to avoid warnings when compiling device-tree:

arch/arm/dts/at91-sama5d2_xplained.dtb: Warning (interrupts_property):
/ahb/apb/timer@f800c000: Missing interrupt-parent

Add AIC node as the sama5d2 global interrupt controller.

---
 arch/arm/dts/sama5d2.dtsi | 9 +++++++++
 1 file changed, 9 insertions(+)
arch/arm/dts/sama5d2.dtsi +9 -0
index 038cd73c03..7de58e4a1f 100644
@@ -3,6 +3,7 @@
 / {
 	model = "Atmel SAMA5D2 family SoC";
 	compatible = "atmel,sama5d2";
+	interrupt-parent = <&aic>;
 
 	aliases {
 		spi0 = &spi0;
@@ -762,6 +763,14 @@
 				status = "disabled";
 			};
 
+			aic: interrupt-controller@fc020000 {
+				#interrupt-cells = <3>;
+				compatible = "atmel,sama5d2-aic";
+				interrupt-controller;
+				reg = <0xfc020000 0x200>;
+				atmel,external-irqs = <49>;
+			};
+
 			i2c1: i2c@fc028000 {
 				compatible = "atmel,sama5d2-i2c";
 				reg = <0xfc028000 0x100>;
Signature · 1 line
2.34.1
#3 lore raw

PATCH v7 3/4 ARM: dts: at91: sama5d2: add TCB node

In reply to Clément Léger

Add the device-tree node to describe the TCB timer.

---
 arch/arm/dts/sama5d2.dtsi | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/arm/dts/sama5d2.dtsi +16 -0
index 7de58e4a1f..058009adca 100644
@@ -1,4 +1,5 @@
 #include "skeleton.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
 
 / {
 	model = "Atmel SAMA5D2 family SoC";
@@ -639,6 +640,21 @@
 				status = "disabled";
 			};
 
+			tcb0: timer@f800c000 {
+				compatible = "atmel,sama5d2-tcb", "simple-mfd", "syscon";
+				reg = <0xf800c000 0x100>;
+				interrupts = <35 IRQ_TYPE_LEVEL_HIGH 0>;
+				clocks = <&tcb0_clk>, <&tcb0_gclk>, <&clk32k>;
+				clock-names = "t0_clk", "gclk", "slow_clk";
+				#address-cells = <1>;
+				#size-cells = <0>;
+
+				timer0: timer@0 {
+					compatible = "atmel,tcb-timer";
+					reg = <0>, <1>;
+				};
+			};
+
 			uart0: serial@f801c000 {
 				compatible = "atmel,at91sam9260-usart";
 				reg = <0xf801c000 0x100>;
Signature · 1 line
2.34.1
#4 lore raw

PATCH v7 4/4 configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

In reply to Clément Léger

Enable CONFIG_ATMEL_TCB_TIMER and disable CONFIG_ATMEL_PIT_TIMER. This will allow using the TCB timer instead of the PIT one when running under OP-TEE.

---
 configs/sama5d2_icp_mmc_defconfig            | 2 +-
 configs/sama5d2_ptc_ek_mmc_defconfig         | 2 +-
 configs/sama5d2_ptc_ek_nandflash_defconfig   | 2 +-
 configs/sama5d2_xplained_emmc_defconfig      | 2 +-
 configs/sama5d2_xplained_mmc_defconfig       | 2 +-
 configs/sama5d2_xplained_qspiflash_defconfig | 2 +-
 configs/sama5d2_xplained_spiflash_defconfig  | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)
configs/sama5d2_icp_mmc_defconfig +1 -1
index 7761a57e0c..c035d7aad8 100644
@@ -82,6 +82,6 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_OF_LIBFDT_OVERLAY=y
 # CONFIG_EFI_LOADER_HII is not set
configs/sama5d2_ptc_ek_mmc_defconfig +1 -1
index 9f458e100b..7cb5ba37f6 100644
@@ -71,7 +71,7 @@ CONFIG_DM_SERIAL=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_ptc_ek_nandflash_defconfig +1 -1
index 6460ff3dad..667a10e93f 100644
@@ -71,7 +71,7 @@ CONFIG_DM_SERIAL=y
 CONFIG_DEBUG_UART_ANNOUNCE=y
 CONFIG_ATMEL_USART=y
 CONFIG_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_emmc_defconfig +1 -1
index 844a9cde64..72544b65bb 100644
@@ -90,7 +90,7 @@ CONFIG_DM_SPI=y
 CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_mmc_defconfig +1 -1
index 0de0636587..bcdb84ce2c 100644
@@ -92,7 +92,7 @@ CONFIG_DM_SPI=y
 CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_qspiflash_defconfig +1 -1
index a6e002e59e..c30a90a3e1 100644
@@ -91,7 +91,7 @@ CONFIG_DM_SPI=y
 CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_spiflash_defconfig +1 -1
index 676385fe55..eae54469f8 100644
@@ -95,7 +95,7 @@ CONFIG_DM_SPI=y
 CONFIG_ATMEL_QSPI=y
 CONFIG_TIMER=y
 CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_STORAGE=y
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 3 lines · Clément Léger

Enable CONFIG_ATMEL_TCB_TIMER and disable CONFIG_ATMEL_PIT_TIMER. This will allow using the TCB timer instead of the PIT one when running under OP-TEE.

Hello Clement,

We have to make sure that the PIT_TIMER was not mandatory for SPL operations, and if it was, the TCB_TIMER successfully replaces it.

If we have the PIT_TIMER with the u-boot property u-boot,dm-pre-reloc;
then the PIT_TIMER is available in the SPL and the SPL works :

RomBOOT
;4▒ls▒K{▒KOp▒C▒▒
<debug_uart>

U-Boot SPL 2022.04-rc4-00204-g5f7086d8a8-dirty (Mar 22 2022 - 13:10:58 +0200)
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices

(well, it fails to boot because I removed the MMC drivers to have it smaller than 64k, but it boots)

However, with your patches, even if I add the pre-reloc property to the tcb nodes, it fails to boot:

RomBOOT
;4▒Ls▒k{▒kOp▒C▒▒
<debug_uart>
Could not initialize timer (err -22)

Could not initialize timer (err -22)

Could not initialize timer (err -22)

Could not initialize timer (err -22)

...

Could you investigate this please ?

Otherwise we cannot switch to using the TCB if it does not fully replace the PIT_TIMER in all the use cases.

Thanks,

Eugen

Quoted 106 lines
---
  configs/sama5d2_icp_mmc_defconfig            | 2 +-
  configs/sama5d2_ptc_ek_mmc_defconfig         | 2 +-
  configs/sama5d2_ptc_ek_nandflash_defconfig   | 2 +-
  configs/sama5d2_xplained_emmc_defconfig      | 2 +-
  configs/sama5d2_xplained_mmc_defconfig       | 2 +-
  configs/sama5d2_xplained_qspiflash_defconfig | 2 +-
  configs/sama5d2_xplained_spiflash_defconfig  | 2 +-
  7 files changed, 7 insertions(+), 7 deletions(-)
configs/sama5d2_icp_mmc_defconfig +1 -1
index 7761a57e0c..c035d7aad8 100644
@@ -82,6 +82,6 @@ CONFIG_DEBUG_UART_ANNOUNCE=y
  CONFIG_ATMEL_USART=y
  CONFIG_TIMER=y
  CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_OF_LIBFDT_OVERLAY=y
  # CONFIG_EFI_LOADER_HII is not set
configs/sama5d2_ptc_ek_mmc_defconfig +1 -1
index 9f458e100b..7cb5ba37f6 100644
@@ -71,7 +71,7 @@ CONFIG_DM_SERIAL=y
  CONFIG_DEBUG_UART_ANNOUNCE=y
  CONFIG_ATMEL_USART=y
  CONFIG_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
configs/sama5d2_ptc_ek_nandflash_defconfig +1 -1
index 6460ff3dad..667a10e93f 100644
@@ -71,7 +71,7 @@ CONFIG_DM_SERIAL=y
  CONFIG_DEBUG_UART_ANNOUNCE=y
  CONFIG_ATMEL_USART=y
  CONFIG_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_emmc_defconfig +1 -1
index 844a9cde64..72544b65bb 100644
@@ -90,7 +90,7 @@ CONFIG_DM_SPI=y
  CONFIG_ATMEL_QSPI=y
  CONFIG_TIMER=y
  CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_mmc_defconfig +1 -1
index 0de0636587..bcdb84ce2c 100644
@@ -92,7 +92,7 @@ CONFIG_DM_SPI=y
  CONFIG_ATMEL_QSPI=y
  CONFIG_TIMER=y
  CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_qspiflash_defconfig +1 -1
index a6e002e59e..c30a90a3e1 100644
@@ -91,7 +91,7 @@ CONFIG_DM_SPI=y
  CONFIG_ATMEL_QSPI=y
  CONFIG_TIMER=y
  CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
configs/sama5d2_xplained_spiflash_defconfig +1 -2
index 676385fe55..eae54469f8 100644
@@ -95,7 +95,7 @@ CONFIG_DM_SPI=y
  CONFIG_ATMEL_QSPI=y
  CONFIG_TIMER=y
  CONFIG_SPL_TIMER=y
-CONFIG_ATMEL_PIT_TIMER=y
+CONFIG_ATMEL_TCB_TIMER=y
  CONFIG_USB=y
  CONFIG_USB_EHCI_HCD=y
  CONFIG_USB_STORAGE=y
--

2.34.1

#6 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 40 lines · Le Tue, 22 Mar 2022 11:18:39 +0000, <[email protected]> a écrit :
Quoted 3 lines · Clément Léger

Enable CONFIG_ATMEL_TCB_TIMER and disable CONFIG_ATMEL_PIT_TIMER. This will allow using the TCB timer instead of the PIT one when running under OP-TEE.

Hello Clement,

We have to make sure that the PIT_TIMER was not mandatory for SPL operations, and if it was, the TCB_TIMER successfully replaces it.

If we have the PIT_TIMER with the u-boot property u-boot,dm-pre-reloc;
then the PIT_TIMER is available in the SPL and the SPL works :

RomBOOT
;4▒ls▒K{▒KOp▒C▒▒
<debug_uart>

U-Boot SPL 2022.04-rc4-00204-g5f7086d8a8-dirty (Mar 22 2022 - 13:10:58 +0200)
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices

(well, it fails to boot because I removed the MMC drivers to have it smaller than 64k, but it boots)

However, with your patches, even if I add the pre-reloc property to the tcb nodes, it fails to boot:

RomBOOT
;4▒Ls▒k{▒kOp▒C▒▒
<debug_uart>
Could not initialize timer (err -22)

Could not initialize timer (err -22)

Could not initialize timer (err -22)

Quoted 7 lines

Could not initialize timer (err -22)

...

Could you investigate this please ?

Hi Eugen,

Ok, I'll try to debug that !

Quoted 3 lines

Otherwise we cannot switch to using the TCB if it does not fully replace the PIT_TIMER in all the use cases.

Yes, that is completely understandable.

Quoted 5 lines

Thanks,

Eugen

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#7 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 3 lines · Clément Léger

Le Tue, 22 Mar 2022 11:18:39 +0000,
<[email protected]> a écrit :

[...]

Quoted 7 lines
Quoted 7 lines

Could not initialize timer (err -22)

...

Quoted 5 lines
Quoted 1 line

Could you investigate this please ?

Hi Eugen,

Ok, I'll try to debug that !

Hi Eugen, while debugging it, I found that there was actually one major flaw. The clock that I used was the GLCK. If only this clock is enabled, the TCB can not work, the tcb0_clk must also be enabled for the TCB to start counting. It worked on my side because I forgot that I had a quirk in OP-TEE that was enabling the clocks before starting U-Boot. Without that, it actually could not work.

Since the tcb0_clk is needed, I switched the driver to use this one only and it works well on a "bare" setup (ie without OP-TEE). I even think it could not work with the tcb0_gclk since this one does not correctly handles the case when the parent clock is the slow_clk (which might be the case after booting) and in this case, will return 0 as rate (this is by the way supported in your CCF branch).

Anyway, I fixed the driver to use the tcb0_clk and thus it should work much better. I will send a V8 and it should work with U-Boot and the SPL.

By the way, do you have any documentation which explains how to use U-Boot SPL on sama5d2_xplained (or other) board ?

Regards,

Clément.

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#8 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 36 lines · Clément Léger
Quoted 3 lines · Clément Léger

Le Tue, 22 Mar 2022 11:18:39 +0000,
<[email protected]> a écrit :

[...]

Quoted 7 lines
Quoted 7 lines

Could not initialize timer (err -22)

...

Quoted 5 lines
Quoted 1 line

Could you investigate this please ?

Hi Eugen,

Ok, I'll try to debug that !

Hi Eugen, while debugging it, I found that there was actually one major flaw. The clock that I used was the GLCK. If only this clock is enabled, the TCB can not work, the tcb0_clk must also be enabled for the TCB to start counting. It worked on my side because I forgot that I had a quirk in OP-TEE that was enabling the clocks before starting U-Boot. Without that, it actually could not work.

Since the tcb0_clk is needed, I switched the driver to use this one only and it works well on a "bare" setup (ie without OP-TEE). I even think it could not work with the tcb0_gclk since this one does not correctly handles the case when the parent clock is the slow_clk (which might be the case after booting) and in this case, will return 0 as rate (this is by the way supported in your CCF branch).

Quoted 6 lines

Anyway, I fixed the driver to use the tcb0_clk and thus it should work much better. I will send a V8 and it should work with U-Boot and the SPL.

By the way, do you have any documentation which explains how to use U-Boot SPL on sama5d2_xplained (or other) board ?

Hi Clement,

I don't have any documentation at hand, but what I can say in a few words is that once you build the SPL, you should have a file spl/boot.bin and this binary should replace our stage2 at91 bootloader at91bootstrap.

Unlike at91bootstrap, the SPL has all the drivers inside and can boot from all supported media, however, SPL will read a dedicated CPU register where the stage1 has written some bits representing the index of the NVM *used to copy the boot.bin from* . The SPL will then attempt to read the u-boot.bin from the same media. (you can alter the file name in defconfig ).

What is required for your series is that the SPL still works as it worked before your series. (e.g. no regressions with your patches).

Eugen

Quoted 10 lines

Regards,

Clément.

--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com

#9 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 51 lines · Le Thu, 31 Mar 2022 05:59:02 +0000, <[email protected]> a écrit :
Quoted 36 lines · Clément Léger
Quoted 3 lines · Clément Léger

Le Tue, 22 Mar 2022 11:18:39 +0000,
<[email protected]> a écrit :

[...]

Quoted 7 lines
Quoted 7 lines

Could not initialize timer (err -22)

...

Quoted 5 lines
Quoted 1 line

Could you investigate this please ?

Hi Eugen,

Ok, I'll try to debug that !

Hi Eugen, while debugging it, I found that there was actually one major flaw. The clock that I used was the GLCK. If only this clock is enabled, the TCB can not work, the tcb0_clk must also be enabled for the TCB to start counting. It worked on my side because I forgot that I had a quirk in OP-TEE that was enabling the clocks before starting U-Boot. Without that, it actually could not work.

Since the tcb0_clk is needed, I switched the driver to use this one only and it works well on a "bare" setup (ie without OP-TEE). I even think it could not work with the tcb0_gclk since this one does not correctly handles the case when the parent clock is the slow_clk (which might be the case after booting) and in this case, will return 0 as rate (this is by the way supported in your CCF branch).

Quoted 6 lines

Anyway, I fixed the driver to use the tcb0_clk and thus it should work much better. I will send a V8 and it should work with U-Boot and the SPL.

By the way, do you have any documentation which explains how to use U-Boot SPL on sama5d2_xplained (or other) board ?

Hi Clement,

I don't have any documentation at hand, but what I can say in a few words is that once you build the SPL, you should have a file spl/boot.bin and this binary should replace our stage2 at91 bootloader at91bootstrap.

Quoted 6 lines

Unlike at91bootstrap, the SPL has all the drivers inside and can boot from all supported media, however, SPL will read a dedicated CPU register where the stage1 has written some bits representing the index of the NVM *used to copy the boot.bin from* . The SPL will then attempt to read the u-boot.bin from the same media. (you can alter the file name in defconfig ).

Ok, I successfully booted a SPL < 64k from SD card by disabling MMC support after fixing the TCB driver:

;4��K3K{�KOp�C�0�
U-Boot SPL 2022.04-rc3-00023-gf9da67b41a-dirty (Mar 31 2022 - 09:23:48 +0200)
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

However, as soon as the size is greater than 64K, it does not boot anymore. Looks like you already had the same problem. Do you have any more documentation which would allow me to boot a u-boot.bin file from this SPL easily ?

By the way, since u-boot,dm-pre-reloc is needed in the device-tree to be used with the SPL, I will probably add them to my series (property which by the way is missing for the PIT timer device-tree node).

Thanks,

Clément

Signature · 3 lines
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com
#10 lore raw

Re: [PATCH v7 4/4] configs: sama5d2: enable option CONFIG_ATMEL_TCB_TIMER

Quoted 71 lines · Clément Léger
Quoted 51 lines · Le Thu, 31 Mar 2022 05:59:02 +0000, <[email protected]> a écrit :
Quoted 36 lines · Clément Léger
Quoted 3 lines · Clément Léger

Le Tue, 22 Mar 2022 11:18:39 +0000,
<[email protected]> a écrit :

[...]

Quoted 7 lines
Quoted 7 lines

Could not initialize timer (err -22)

...

Quoted 5 lines
Quoted 1 line

Could you investigate this please ?

Hi Eugen,

Ok, I'll try to debug that !

Hi Eugen, while debugging it, I found that there was actually one major flaw. The clock that I used was the GLCK. If only this clock is enabled, the TCB can not work, the tcb0_clk must also be enabled for the TCB to start counting. It worked on my side because I forgot that I had a quirk in OP-TEE that was enabling the clocks before starting U-Boot. Without that, it actually could not work.

Since the tcb0_clk is needed, I switched the driver to use this one only and it works well on a "bare" setup (ie without OP-TEE). I even think it could not work with the tcb0_gclk since this one does not correctly handles the case when the parent clock is the slow_clk (which might be the case after booting) and in this case, will return 0 as rate (this is by the way supported in your CCF branch).

Quoted 6 lines

Anyway, I fixed the driver to use the tcb0_clk and thus it should work much better. I will send a V8 and it should work with U-Boot and the SPL.

By the way, do you have any documentation which explains how to use U-Boot SPL on sama5d2_xplained (or other) board ?

Hi Clement,

I don't have any documentation at hand, but what I can say in a few words is that once you build the SPL, you should have a file spl/boot.bin and this binary should replace our stage2 at91 bootloader at91bootstrap.

Quoted 6 lines

Unlike at91bootstrap, the SPL has all the drivers inside and can boot from all supported media, however, SPL will read a dedicated CPU register where the stage1 has written some bits representing the index of the NVM *used to copy the boot.bin from* . The SPL will then attempt to read the u-boot.bin from the same media. (you can alter the file name in defconfig ).

Ok, I successfully booted a SPL < 64k from SD card by disabling MMC support after fixing the TCB driver:

;4��K3K{�KOp�C�0�
U-Boot SPL 2022.04-rc3-00023-gf9da67b41a-dirty (Mar 31 2022 - 09:23:48 +0200)
SPL: Unsupported Boot Device!
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

Quoted 4 lines

However, as soon as the size is greater than 64K, it does not boot anymore. Looks like you already had the same problem. Do you have any more documentation which would allow me to boot a u-boot.bin file from this SPL easily ?

Hi,

If size is above 64k, it won't fit into the SRAM, thus the stage1 won't copy it at all, and abort booting it.

For arm926 there is a build time check for the size in the lds linker script, but it looks like for the armv7 it's missing... No idea why , if it was removed, I haven't checked.

I don't have any more documentation.

Quoted 5 lines

By the way, since u-boot,dm-pre-reloc is needed in the device-tree to be used with the SPL, I will probably add them to my series (property which by the way is missing for the PIT timer device-tree node).

Yes, definitely. You can send a prequel or separate patch to add this to the PIT timer if you like.
And have this property for your node yes.

Normally all u-boot properties should be in a separate dtsi file, but this is an old DT in uboot so I think it's fine to have it in the base DT.

Eugen

Quoted 10 lines

Thanks,

Clément

--
Clément Léger,
Embedded Linux and Kernel engineer at Bootlin
https://bootlin.com