Skip to contentSkip to conversation

Risc-V 32 bit/64 bit images

RFC PATCH In review Mayuresh Chitale 2 participants 6 messages Feb 21, 2025 – Feb 24, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

cover Risc-V 32 bit/64 bit images

This series adds support for building different images for 32-bit vs 64-bit Risc-V CPUs and also for verifying the target arch of an image before booting it.

Mayuresh Chitale (3):
riscv: image: Add new image type for RV64
riscv: Select appropriate image type
riscv: booti/bootm: Verify image arch type

 arch/riscv/dts/binman.dtsi      | 14 ++++++++++----
 arch/riscv/include/asm/u-boot.h |  4 ++++
 arch/riscv/lib/bootm.c          |  4 ++++
 boot/image.c                    |  3 ++-
 cmd/booti.c                     |  5 ++++-
 include/image.h                 |  1 +
 6 files changed, 25 insertions(+), 6 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/3 riscv: image: Add new image type for RV64

Similar to ARM and X86, introduce a new image type which allows u-boot to distinguish between images built for 32-bit vs 64-bit Risc-V CPUs.

---
 boot/image.c    | 3 ++-
 include/image.h | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)
boot/image.c +2 -1
index abac254e026..03d5e59b634 100644
@@ -92,7 +92,8 @@ static const table_entry_t uimage_arch[] = {
 	{	IH_ARCH_ARC,		"arc",		"ARC",		},
 	{	IH_ARCH_X86_64,		"x86_64",	"AMD x86_64",	},
 	{	IH_ARCH_XTENSA,		"xtensa",	"Xtensa",	},
-	{	IH_ARCH_RISCV,		"riscv",	"RISC-V",	},
+	{	IH_ARCH_RISCV,		"riscv",	"RISC-V 32 Bit",},
+	{	IH_ARCH_RISCV64,	"riscv64",	"RISC-V 64 Bit",},
 	{	-1,			"",		"",		},
 };
 
include/image.h +1 -0
index 8a9f779d3ff..12b31166e86 100644
@@ -139,6 +139,7 @@ enum {
 	IH_ARCH_X86_64,			/* AMD x86_64, Intel and Via */
 	IH_ARCH_XTENSA,			/* Xtensa	*/
 	IH_ARCH_RISCV,			/* RISC-V */
+	IH_ARCH_RISCV64,		/* RISC-V 64 bit*/
 
 	IH_ARCH_COUNT,
 };
Signature · 1 line
2.45.2
#2 lore raw

RFC PATCH 2/3 riscv: Select appropriate image type

In reply to Mayuresh Chitale

Select between the 32-bit or 64-bit arch type for the image headers depending on how the build is configured.

---
 arch/riscv/dts/binman.dtsi      | 14 ++++++++++----
 arch/riscv/include/asm/u-boot.h |  4 ++++
 2 files changed, 14 insertions(+), 4 deletions(-)
arch/riscv/dts/binman.dtsi +10 -4
index 0405faca574..a1a566b511b 100644
@@ -5,6 +5,12 @@
 
 #include <config.h>
 
+#ifdef CONFIG_64BIT
+#define ARCH "riscv64"
+#else
+#define ARCH "riscv"
+
+#endif
 / {
 	binman: binman {
 		multiple-images;
@@ -31,7 +37,7 @@
 					description = "U-Boot";
 					type = "standalone";
 					os = "U-Boot";
-					arch = "riscv";
+					arch = ARCH;
 					compression = "none";
 					load = /bits/ 64 <CONFIG_TEXT_BASE>;
 
@@ -44,7 +50,7 @@
 					description = "Linux";
 					type = "standalone";
 					os = "Linux";
-					arch = "riscv";
+					arch = ARCH;
 					compression = "none";
 					load = /bits/ 64 <CONFIG_TEXT_BASE>;
 
@@ -57,7 +63,7 @@
 				tee {
 					description = "OP-TEE";
 					type = "tee";
-					arch = "riscv";
+					arch = ARCH;
 					compression = "none";
 					os = "tee";
 					load = /bits/ 64 <CONFIG_SPL_OPTEE_LOAD_ADDR>;
@@ -71,7 +77,7 @@
 					description = "OpenSBI fw_dynamic Firmware";
 					type = "firmware";
 					os = "opensbi";
-					arch = "riscv";
+					arch = ARCH;
 					compression = "none";
 					load = /bits/ 64 <CONFIG_SPL_OPENSBI_LOAD_ADDR>;
 					entry = /bits/ 64 <CONFIG_SPL_OPENSBI_LOAD_ADDR>;
arch/riscv/include/asm/u-boot.h +4 -0
index d5e1d5f3231..a90cc4c21cf 100644
@@ -23,6 +23,10 @@
 #include <asm/u-boot-riscv.h>
 
 /* For image.h:image_check_target_arch() */
+#ifdef CONFIG_64BIT
+#define IH_ARCH_DEFAULT IH_ARCH_RISCV64
+#else
 #define IH_ARCH_DEFAULT IH_ARCH_RISCV
+#endif
 
 #endif	/* _U_BOOT_H_ */
Signature · 1 line
2.45.2
#3 lore raw

RFC PATCH 3/3 riscv: booti/bootm: Verify image arch type

In reply to Mayuresh Chitale

For bootm, disallow booting an image that was built for an arch type other than the current arch. For booti, set the arch type same as the current arch.

---
 arch/riscv/lib/bootm.c | 4 ++++
 cmd/booti.c            | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
arch/riscv/lib/bootm.c +4 -0
index 76c610bcee0..90f71bee6a5 100644
@@ -94,6 +94,10 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	announce_and_cleanup(fake);
 
 	if (!fake) {
+		if (images->os.arch != IH_ARCH_DEFAULT) {
+			printf("Image arch not compatible with host arch.\n");
+			hang();
+		}
 		if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_SMP
 			ret = smp_call_function(images->ep,
cmd/booti.c +4 -1
index 1a57fe91397..00921ec4a9d 100644
@@ -131,7 +131,10 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	images.os.os = IH_OS_LINUX;
 	if (IS_ENABLED(CONFIG_RISCV_SMODE))
-		images.os.arch = IH_ARCH_RISCV;
+		if (IS_ENABLED(CONFIG_64BIT))
+			images.os.arch = IH_ARCH_RISCV64;
+		else
+			images.os.arch = IH_ARCH_RISCV;
 	else if (IS_ENABLED(CONFIG_ARM64))
 		images.os.arch = IH_ARCH_ARM64;
 
Signature · 1 line
2.45.2
#4 lore raw

Re: [RFC PATCH 3/3] riscv: booti/bootm: Verify image arch type

Am 21. Februar 2025 13:58:53 MEZ schrieb Mayuresh Chitale <[email protected]>:

Quoted 3 lines

For bootm, disallow booting an image that was built for an arch type other than the current arch. For booti, set the arch type same as the current arch.

Hello Mayuresh,

The code change looks fine, but the commit message could be a bit more exhaustive:

A commit message should provide the reason why you are making a change. E.g. you could state that booting a RISC-V FIT image of different bitness is not supported by the current code and that you want to catch that problem early.

The current commit message sounds like you are forbidding booting amd64 from i386, too. Please, mention that this is a RISC-V only change in the commit message.

Best regards

Heinrich

Quoted 38 lines

---
arch/riscv/lib/bootm.c | 4 ++++
cmd/booti.c | 5 ++++-

2 files changed, 8 insertions(+), 1 deletion(-)
arch/riscv/lib/bootm.c +4 -0
index 76c610bcee0..90f71bee6a5 100644
@@ -94,6 +94,10 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
 	announce_and_cleanup(fake);
 
 	if (!fake) {
+		if (images->os.arch != IH_ARCH_DEFAULT) {
+			printf("Image arch not compatible with host arch.\n");
+			hang();
+		}
 		if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_SMP
 			ret = smp_call_function(images->ep,
cmd/booti.c +4 -1
index 1a57fe91397..00921ec4a9d 100644
@@ -131,7 +131,10 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
 	images.os.os = IH_OS_LINUX;
 	if (IS_ENABLED(CONFIG_RISCV_SMODE))
-		images.os.arch = IH_ARCH_RISCV;
+		if (IS_ENABLED(CONFIG_64BIT))
+			images.os.arch = IH_ARCH_RISCV64;
+		else
+			images.os.arch = IH_ARCH_RISCV;
 	else if (IS_ENABLED(CONFIG_ARM64))
 		images.os.arch = IH_ARCH_ARM64;
 
#5 lore raw

Re: [RFC PATCH 3/3] riscv: booti/bootm: Verify image arch type

Hi Heinrich,

Quoted 6 lines · Heinrich Schuchardt

Am 21. Februar 2025 13:58:53 MEZ schrieb Mayuresh Chitale <[email protected]>:

Quoted 3 lines

For bootm, disallow booting an image that was built for an arch type other than the current arch. For booti, set the arch type same as the current arch.

Quoted 7 lines

Hello Mayuresh,

The code change looks fine, but the commit message could be a bit more exhaustive:

A commit message should provide the reason why you are making a change. E.g. you could state that booting a RISC-V FIT image of different bitness is not supported by the current code and that you want to catch that problem early.

The current commit message sounds like you are forbidding booting amd64 from i386, too. Please, mention that this is a RISC-V only change in the commit message.

Sure. Will do that.

Quoted 44 lines

Best regards

Heinrich

Quoted 38 lines

---
arch/riscv/lib/bootm.c | 4 ++++
cmd/booti.c | 5 ++++-

2 files changed, 8 insertions(+), 1 deletion(-)
arch/riscv/lib/bootm.c +4 -0
index 76c610bcee0..90f71bee6a5 100644
@@ -94,6 +94,10 @@ static void boot_jump_linux(struct bootm_headers *images, int flag)
      announce_and_cleanup(fake);
 
      if (!fake) {
+              if (images->os.arch != IH_ARCH_DEFAULT) {
+                      printf("Image arch not compatible with host arch.\n");
+                      hang();
+              }
              if (CONFIG_IS_ENABLED(OF_LIBFDT) && images->ft_len) {
 #ifdef CONFIG_SMP
                      ret = smp_call_function(images->ep,
cmd/booti.c +4 -1
index 1a57fe91397..00921ec4a9d 100644
@@ -131,7 +131,10 @@ int do_booti(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 
      images.os.os = IH_OS_LINUX;
      if (IS_ENABLED(CONFIG_RISCV_SMODE))
-              images.os.arch = IH_ARCH_RISCV;
+              if (IS_ENABLED(CONFIG_64BIT))
+                      images.os.arch = IH_ARCH_RISCV64;
+              else
+                      images.os.arch = IH_ARCH_RISCV;
      else if (IS_ENABLED(CONFIG_ARM64))
              images.os.arch = IH_ARCH_ARM64;