Skip to contentSkip to conversation

U-boot: arm: Refine the booting on Total Compute

PATCH In review Leo Yan 2 participants 10 messages Oct 25, 2024 – Nov 5, 2024

Subsystems (2)
lore
Share & tools
lore

Leo Yan

author
#0 lore raw

cover U-boot: arm: Refine the booting on Total Compute

This patch series is to refine the booting on Arm Total Compuate platform.

It changes to use the info passed in DTB for initialization DRAM info, and dynamically initializes the booting envoironment variables.

Another big change is to use an envoironment file for boot commands, based on it, the series extends to support multiple block devices (MMC and virtio). And the env file is extended for booting Debian.

The last commit is to update memory mapping info based on the DRAM info passed via DT binding.

Boyan Karatotev (5):
arm: total_compute: depend on TF-A for hardware description
arm: total_compute: Initialize environment variables
arm: total_compute: Remove unused bootm_size
arm: total_compute: move the boot command to an env file
arm: total_compute: Minor improvement for boot arguments

Leo Yan (3):
arm: total_compute: Dynamically detect block device
arm: total_compute: Support Debian boot
arm: total_compute: Update memory mapping info

 arch/arm/Kconfig                             |   2 +
 board/armltd/total_compute/Makefile          |   1 +
 board/armltd/total_compute/lowlevel_init.S   |  12 +++
 board/armltd/total_compute/total_compute.c   | 102 ++++++++++++++-----
 board/armltd/total_compute/total_compute.env |  39 +++++++
 configs/total_compute_defconfig              |   2 +-
 include/configs/total_compute.h              |  31 ------
 7 files changed, 130 insertions(+), 59 deletions(-)
 create mode 100644 board/armltd/total_compute/lowlevel_init.S
 create mode 100644 board/armltd/total_compute/total_compute.env
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/8 arm: total_compute: depend on TF-A for hardware description

From: Boyan Karatotev <[email protected]>

On Total Compute, TF-A passes the info via DT binding for the hardware description - includes the serial, memory, and arm_ffa nodes.

This commit initializes the fdt base address based on the passed the register x1.

The similar implementation has already been done for the raspberry pi, so borrow a lot of it.

---
 arch/arm/Kconfig                           |  1 +
 board/armltd/total_compute/Makefile        |  1 +
 board/armltd/total_compute/lowlevel_init.S | 12 +++++++
 board/armltd/total_compute/total_compute.c | 41 +++++++++++-----------
 include/configs/total_compute.h            | 18 ----------
 5 files changed, 35 insertions(+), 38 deletions(-)
 create mode 100644 board/armltd/total_compute/lowlevel_init.S
arch/arm/Kconfig +1 -0
index 060636e9e2..d0127418ee 100644
@@ -1390,6 +1390,7 @@ config TARGET_TOTAL_COMPUTE
 	select DM_SERIAL
 	select DM_MMC
 	select DM_GPIO
+	imply OF_HAS_PRIOR_STAGE
 
 config TARGET_LS2080A_EMU
 	bool "Support ls2080a_emu"
board/armltd/total_compute/Makefile +1 -0
index 8b10458431..f1ef5a0c39 100644
@@ -4,3 +4,4 @@
 # Usama Arif <[email protected]>
 
 obj-y	:= total_compute.o
+obj-y	+= lowlevel_init.o
board/armltd/total_compute/lowlevel_init.S new file +12 -0
new file mode 100644
index 0000000000..3c06937966
@@ -0,0 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) Copyright 2024 Arm Limited
+ */
+
+.global save_boot_params
+save_boot_params:
+	/* The firmware provided FDT address via x1 */
+	adr	x8, fw_dtb_pointer
+	str	x1, [x8]
+
+	b	save_boot_params_ret
board/armltd/total_compute/total_compute.c +21 -20

65 lines not on this page · raw message

include/configs/total_compute.h +0 -18
index a8bd8e259c..205e6a6278 100644
@@ -11,24 +11,6 @@
 
 /* Link Definitions */
 
-/* AP non-secure UART base address */
-#define UART0_BASE		0x2A400000
-
-/* PL011 Serial Configuration */
-#define CFG_PL011_CLOCK	7372800
-
-/* Miscellaneous configurable options */
-
-/* Physical Memory Map */
-#define PHYS_SDRAM_1		0x80000000
-/* Top 48MB reserved for secure world use */
-#define DRAM_SEC_SIZE		0x03000000
-#define PHYS_SDRAM_1_SIZE	0x80000000 - DRAM_SEC_SIZE
-#define CFG_SYS_SDRAM_BASE	PHYS_SDRAM_1
-
-#define PHYS_SDRAM_2		0x8080000000
-#define PHYS_SDRAM_2_SIZE	0x180000000
-
 #define CFG_EXTRA_ENV_SETTINGS	\
 				"bootm_size=0x20000000\0"	\
 				"load_addr=0xa0000000\0"	\
Signature · 1 line
2.34.1
author
#2 lore raw

PATCH 2/8 arm: total_compute: Initialize environment variables

In reply to Leo Yan

From: Boyan Karatotev <[email protected]>

Initialize the environment variables 'fdt_addr_r' and 'kernel_addr_r' during the misc init phase. The static configurations are not needed, remove them.

---
 arch/arm/Kconfig                           |  1 +
 board/armltd/total_compute/total_compute.c | 23 ++++++++++++++++++++++
 include/configs/total_compute.h            |  4 +---
 3 files changed, 25 insertions(+), 3 deletions(-)
arch/arm/Kconfig +1 -0
index d0127418ee..f4ce884e37 100644
@@ -1391,6 +1391,7 @@ config TARGET_TOTAL_COMPUTE
 	select DM_MMC
 	select DM_GPIO
 	imply OF_HAS_PRIOR_STAGE
+	imply MISC_INIT_R
 
 config TARGET_LS2080A_EMU
 	bool "Support ls2080a_emu"
board/armltd/total_compute/total_compute.c +23 -0
index 571a075145..02bb648ce7 100644
@@ -8,6 +8,8 @@
 #include <dm.h>
 #include <dm/platform_data/serial_pl01x.h>
 #include <env.h>
+#include <linux/sizes.h>
+
 #include <asm/armv8/mmu.h>
 #include <asm/global_data.h>
 #include <asm/system.h>
@@ -51,6 +53,27 @@ void *board_fdt_blob_setup(int *err)
 	return (void *)fw_dtb_pointer;
 }
 
+int misc_init_r(void)
+{
+	size_t base;
+
+	if (!env_get("fdt_addr_r"))
+		env_set_hex("fdt_addr_r", fw_dtb_pointer);
+
+	if (!env_get("kernel_addr_r")) {
+		/*
+		 * The kernel has to be 2M aligned and the first 64K at the
+		 * start of SDRAM is reserved for DTB.
+		 */
+		base = gd->ram_base + SZ_2M;
+		assert(IS_ALIGNED(base, SZ_2M));
+
+		env_set_hex("kernel_addr_r", base);
+	}
+
+	return 0;
+}
+
 int board_init(void)
 {
 	return 0;
include/configs/total_compute.h +1 -3
index 205e6a6278..8053dca315 100644
@@ -14,9 +14,7 @@
 #define CFG_EXTRA_ENV_SETTINGS	\
 				"bootm_size=0x20000000\0"	\
 				"load_addr=0xa0000000\0"	\
-				"kernel_addr_r=0x80080000\0"	\
-				"initrd_addr_r=0x88000000\0"	\
-				"fdt_addr_r=0x83000000\0"
+				"initrd_addr_r=0x88000000\0"
 /*
  * If vbmeta partition is present, boot Android with verification using AVB.
  * Else if system partition is present (no vbmeta partition), boot Android
Signature · 1 line
2.34.1
author
#3 lore raw

PATCH 3/8 arm: total_compute: Remove unused bootm_size

In reply to Leo Yan

From: Boyan Karatotev <[email protected]>

The whole DRAM bank is used for loading and U-boot can detect the overlap between the kernel and initramfs. So it is safe to drop bootm_size.

---
 include/configs/total_compute.h | 1 -
 1 file changed, 1 deletion(-)
include/configs/total_compute.h +0 -1
index 8053dca315..4c966ce4bf 100644
@@ -12,7 +12,6 @@
 /* Link Definitions */
 
 #define CFG_EXTRA_ENV_SETTINGS	\
-				"bootm_size=0x20000000\0"	\
 				"load_addr=0xa0000000\0"	\
 				"initrd_addr_r=0x88000000\0"
 /*
Signature · 1 line
2.34.1
author
#4 lore raw

PATCH 4/8 arm: total_compute: move the boot command to an env file

In reply to Leo Yan

From: Boyan Karatotev <[email protected]>

The boot command for Total Compute has many aspects and changes from time to time. So move it to an .env file where it can be a proper script.

---
 board/armltd/total_compute/total_compute.env | 28 ++++++++++++++++++++
 configs/total_compute_defconfig              |  2 +-
 include/configs/total_compute.h              | 10 -------
 3 files changed, 29 insertions(+), 11 deletions(-)
 create mode 100644 board/armltd/total_compute/total_compute.env
board/armltd/total_compute/total_compute.env new file +28 -0
new file mode 100644
index 0000000000..8975a86fd2
@@ -0,0 +1,28 @@
+/* DRAM1 + 0x2000_0000 */
+load_addr=0xa0000000
+/* DRAM1 + 0x0800_0000 */
+initrd_addr_r=0x88000000
+
+bootcmd=
+    if part number mmc 0 vbmeta is_avb; then
+        echo 'MMC with vbmeta partition detected.';
+        echo 'Starting Android Verified boot...';
+        avb init 0;
+        if avb verify; then
+            set bootargs $bootargs $avb_bootargs;
+            part start mmc 0 boot boot_start;
+            part size mmc 0 boot boot_size;
+            mmc read ${load_addr} ${boot_start} ${boot_size};
+            bootm ${load_addr} ${load_addr} ${fdt_addr_r};
+        else;
+            echo 'AVB verification failed.';
+            exit;
+        fi;
+    elif part number mmc 0 system is_non_avb_android; then
+        echo 'Booting Android non-AVB...';
+        booti ${kernel_addr_r} ${initrd_addr_r} ${fdt_addr_r};
+    elif iminfo ${load_addr}; then
+        echo 'Booting FIT image...';
+        bootm ${load_addr} ${load_addr} ${fdt_addr_r};
+    fi;
+    echo 'ERROR: No valid image to boot the system. Aborting boot sequence.';
configs/total_compute_defconfig +1 -1
index 5f21d2e367..291083d8b6 100644
@@ -18,7 +18,6 @@ CONFIG_FIT_SIGNATURE=y
 CONFIG_LEGACY_IMAGE_FORMAT=y
 CONFIG_DISTRO_DEFAULTS=y
 CONFIG_BOOTDELAY=5
-CONFIG_BOOTCOMMAND="if part number mmc 0 vbmeta is_avb; then  echo MMC with vbmeta partition detected.;  echo starting Android Verified boot.;  avb init 0;   if avb verify; then     set bootargs $bootargs $avb_bootargs;     part start mmc 0 boot boot_start;     part size mmc 0 boot boot_size;     mmc read ${load_addr} ${boot_start} ${boot_size};     bootm ${load_addr} ${load_addr} ${fdt_addr_r};   else;     echo AVB verification failed.;     exit;   fi; elif part number mmc 0 system is_non_avb_android; then   booti ${kernel_addr_r} ${initrd_addr_r} ${fdt_addr_r};else;  echo Booting FIT image.;  bootm ${load_addr} ${load_addr} ${fdt_addr_r}; fi;"
 CONFIG_SYS_CBSIZE=512
 CONFIG_SYS_PBSIZE=544
 # CONFIG_DISPLAY_CPUINFO is not set
@@ -60,3 +59,4 @@ CONFIG_SYS_FLASH_CFI=y
 CONFIG_SYS_MAX_FLASH_SECT=256
 # CONFIG_RANDOM_UUID is not set
 CONFIG_LIBAVB=y
+CONFIG_ENV_SOURCE_FILE=total_compute
include/configs/total_compute.h +0 -10
index 4c966ce4bf..5cc0166f19 100644
@@ -11,16 +11,6 @@
 
 /* Link Definitions */
 
-#define CFG_EXTRA_ENV_SETTINGS	\
-				"load_addr=0xa0000000\0"	\
-				"initrd_addr_r=0x88000000\0"
-/*
- * If vbmeta partition is present, boot Android with verification using AVB.
- * Else if system partition is present (no vbmeta partition), boot Android
- * without verification (for development purposes).
- * Else boot FIT image.
- */
-
 #define CFG_SYS_FLASH_BASE		0x0C000000
 
 #endif /* __TOTAL_COMPUTE_H */
Signature · 1 line
2.34.1
author
#5 lore raw

PATCH 5/8 arm: total_compute: Minor improvement for boot arguments

In reply to Leo Yan

From: Boyan Karatotev <[email protected]>

Tell the AVB command that is loading from MMC.

---
 board/armltd/total_compute/total_compute.env | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/armltd/total_compute/total_compute.env +1 -1
index 8975a86fd2..9dd50819ea 100644
@@ -7,7 +7,7 @@ bootcmd=
     if part number mmc 0 vbmeta is_avb; then
         echo 'MMC with vbmeta partition detected.';
         echo 'Starting Android Verified boot...';
-        avb init 0;
+        avb init mmc 0;
         if avb verify; then
             set bootargs $bootargs $avb_bootargs;
             part start mmc 0 boot boot_start;
Signature · 1 line
2.34.1
author
#6 lore raw

PATCH 6/8 arm: total_compute: Dynamically detect block device

In reply to Leo Yan

Dynamically detect block device in the boot command, this allows to support both MMC and virtio block devices.

---
 board/armltd/total_compute/total_compute.env | 21 +++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
board/armltd/total_compute/total_compute.env +14 -7
index 9dd50819ea..93460aa5dc 100644
@@ -4,21 +4,28 @@ load_addr=0xa0000000
 initrd_addr_r=0x88000000
 
 bootcmd=
-    if part number mmc 0 vbmeta is_avb; then
-        echo 'MMC with vbmeta partition detected.';
+    virtio scan;
+    if virtio info; then
+        blk_dev=virtio;
+    else;
+        blk_dev=mmc;
+    fi;
+    echo block device is ${blk_dev};
+    if part number ${blk_dev} 0 vbmeta is_avb; then
+        echo '${blk_dev} with vbmeta partition detected.';
         echo 'Starting Android Verified boot...';
-        avb init mmc 0;
+        avb init ${blk_dev} 0;
         if avb verify; then
             set bootargs $bootargs $avb_bootargs;
-            part start mmc 0 boot boot_start;
-            part size mmc 0 boot boot_size;
-            mmc read ${load_addr} ${boot_start} ${boot_size};
+            part start ${blk_dev} 0 boot boot_start;
+            part size ${blk_dev} 0 boot boot_size;
+            ${blk_dev} read ${load_addr} ${boot_start} ${boot_size};
             bootm ${load_addr} ${load_addr} ${fdt_addr_r};
         else;
             echo 'AVB verification failed.';
             exit;
         fi;
-    elif part number mmc 0 system is_non_avb_android; then
+    elif part number ${blk_dev} 0 system is_non_avb_android; then
         echo 'Booting Android non-AVB...';
         booti ${kernel_addr_r} ${initrd_addr_r} ${fdt_addr_r};
     elif iminfo ${load_addr}; then
Signature · 1 line
2.34.1
author
#7 lore raw

PATCH 7/8 arm: total_compute: Support Debian boot

In reply to Leo Yan

Add booting option for Debian system.

---
 board/armltd/total_compute/total_compute.env | 4 ++++
 1 file changed, 4 insertions(+)
board/armltd/total_compute/total_compute.env +4 -0
index 93460aa5dc..7924632678 100644
@@ -31,5 +31,9 @@ bootcmd=
     elif iminfo ${load_addr}; then
         echo 'Booting FIT image...';
         bootm ${load_addr} ${load_addr} ${fdt_addr_r};
+    else;
+        echo 'Booting Debian...';
+        set bootargs $bootargs root=/dev/mmcblk0p1 rw;
+        booti ${kernel_addr_r} - ${fdt_addr_r};
     fi;
     echo 'ERROR: No valid image to boot the system. Aborting boot sequence.';
Signature · 1 line
2.34.1
author
#8 lore raw

PATCH 8/8 arm: total_compute: Update memory mapping info

In reply to Leo Yan

This commit introduces build_mem_map() function for updating the mem_map structure with copying info from gd->bd->bi_dram, so that it can keep the consistence for DRAM info passed via DT.

The page table size is calculated prior to mem_map is ready, introduce the get_page_table_size() function for a predefined table size.

---
 board/armltd/total_compute/total_compute.c | 44 +++++++++++++++++-----
 1 file changed, 34 insertions(+), 10 deletions(-)
board/armltd/total_compute/total_compute.c +34 -10
index 02bb648ce7..4101816317 100644
@@ -14,7 +14,10 @@
 #include <asm/global_data.h>
 #include <asm/system.h>
 
-static struct mm_region total_compute_mem_map[] = {
+/* +1 is end of list which needs to be empty */
+#define TC_MEM_MAP_MAX		(1 + CONFIG_NR_DRAM_BANKS + 1)
+
+static struct mm_region total_compute_mem_map[TC_MEM_MAP_MAX] = {
 	{
 		.virt = 0x0UL,
 		.phys = 0x0UL,
@@ -22,15 +25,6 @@ static struct mm_region total_compute_mem_map[] = {
 		.attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
 			 PTE_BLOCK_NON_SHARE |
 			 PTE_BLOCK_PXN | PTE_BLOCK_UXN
-	}, {
-		.virt = 0x80000000UL,
-		.phys = 0x80000000UL,
-		.size = 0xff80000000UL,
-		.attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
-			 PTE_BLOCK_INNER_SHARE
-	}, {
-		/* List terminator */
-		0,
 	}
 };
 
@@ -89,6 +83,36 @@ int dram_init_banksize(void)
 	return fdtdec_setup_memory_banksize();
 }
 
+void build_mem_map(void)
+{
+	int i;
+
+	for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
+		/*
+		 * The first node is for I/O device, start from node 1 for
+		 * updating DRAM info.
+		 */
+		mem_map[i + 1].virt = gd->bd->bi_dram[i].start;
+		mem_map[i + 1].phys = gd->bd->bi_dram[i].start;
+		mem_map[i + 1].size = gd->bd->bi_dram[i].size;
+		mem_map[i + 1].attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
+				       PTE_BLOCK_INNER_SHARE;
+	}
+}
+
+void enable_caches(void)
+{
+	build_mem_map();
+
+	icache_enable();
+	dcache_enable();
+}
+
+u64 get_page_table_size(void)
+{
+	return SZ_256K;
+}
+
 /* Nothing to be done here as handled by PSCI interface */
 void reset_cpu(void)
 {
Signature · 1 line
2.34.1
#9 lore raw
In reply to Leo Yan
Quoted 11 lines · Leo Yan

This patch series is to refine the booting on Arm Total Compuate platform.

It changes to use the info passed in DTB for initialization DRAM info, and dynamically initializes the booting envoironment variables.

Another big change is to use an envoironment file for boot commands, based on it, the series extends to support multiple block devices (MMC and virtio). And the env file is extended for booting Debian.

[...]

Applied to u-boot/master, thanks!

Signature · 1 line
Tom