diff mbox series

riscv: Add a 64-bit image type

Message ID 20230402202813.2341959-1-sjg@chromium.org
State New
Delegated to: Andes
Headers show
Series riscv: Add a 64-bit image type | expand

Commit Message

Simon Glass April 2, 2023, 8:28 p.m. UTC
At present it is not possible to know whether an image can be booted by
a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot
the wrong image. This may cause a crash which might be hard to debug.

Add a new property to make this explicit.

The existing 'RISC-V' is now taken to mean 32-bit.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/image.c    | 3 ++-
 include/image.h | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Comments

Rick Chen April 10, 2023, 7:25 a.m. UTC | #1
> From: Simon Glass <sjg@chromium.org>
> Sent: Monday, April 03, 2023 4:28 AM
> To: U-Boot Mailing List <u-boot@lists.denx.de>
> Cc: Sean Anderson <seanga2@gmail.com>; Bin Meng <bmeng.cn@gmail.com>; Rick Jian-Zhi Chen(陳建志) <rick@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycliang@andestech.com>; Simon Glass <sjg@chromium.org>; Andre Przywara <andre.przywara@arm.com>; Marc Kleine-Budde <mkl@pengutronix.de>; SESA644425 <giojahermann@gmail.com>; Samuel Holland <samuel@sholland.org>; Steven Lawrance <steven.lawrance@softathome.com>
> Subject: [PATCH] riscv: Add a 64-bit image type
>
> At present it is not possible to know whether an image can be booted by a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot the wrong image. This may cause a crash which might be hard to debug.
>
> Add a new property to make this explicit.
>
> The existing 'RISC-V' is now taken to mean 32-bit.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  boot/image.c    | 3 ++-
>  include/image.h | 3 ++-
>  2 files changed, 4 insertions(+), 2 deletions(-)

Reviewed-by: Rick Chen <rick@andestech.com>
Bin Meng April 13, 2023, 10:06 a.m. UTC | #2
On Mon, Apr 10, 2023 at 3:25 PM Rick Chen <rickchen36@gmail.com> wrote:
>
> > From: Simon Glass <sjg@chromium.org>
> > Sent: Monday, April 03, 2023 4:28 AM
> > To: U-Boot Mailing List <u-boot@lists.denx.de>
> > Cc: Sean Anderson <seanga2@gmail.com>; Bin Meng <bmeng.cn@gmail.com>; Rick Jian-Zhi Chen(陳建志) <rick@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycliang@andestech.com>; Simon Glass <sjg@chromium.org>; Andre Przywara <andre.przywara@arm.com>; Marc Kleine-Budde <mkl@pengutronix.de>; SESA644425 <giojahermann@gmail.com>; Samuel Holland <samuel@sholland.org>; Steven Lawrance <steven.lawrance@softathome.com>
> > Subject: [PATCH] riscv: Add a 64-bit image type
> >
> > At present it is not possible to know whether an image can be booted by a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot the wrong image. This may cause a crash which might be hard to debug.
> >
> > Add a new property to make this explicit.
> >
> > The existing 'RISC-V' is now taken to mean 32-bit.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> >  boot/image.c    | 3 ++-
> >  include/image.h | 3 ++-
> >  2 files changed, 4 insertions(+), 2 deletions(-)
>
> Reviewed-by: Rick Chen <rick@andestech.com>

This might create compatibility issues if the shipped host tool
(mkimage) does not match U-Boot version. Any idea how to avoid that?

Regards,
Bin
Leo Liang April 17, 2023, 5:22 a.m. UTC | #3
Hi Bin,

On Thu, Apr 13, 2023 at 06:06:29PM +0800, Bin Meng wrote:
> On Mon, Apr 10, 2023 at 3:25 PM Rick Chen <rickchen36@gmail.com> wrote:
> >
> > > From: Simon Glass <sjg@chromium.org>
> > > Sent: Monday, April 03, 2023 4:28 AM
> > > To: U-Boot Mailing List <u-boot@lists.denx.de>
> > > Cc: Sean Anderson <seanga2@gmail.com>; Bin Meng <bmeng.cn@gmail.com>; Rick Jian-Zhi Chen(陳建志) <rick@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycliang@andestech.com>; Simon Glass <sjg@chromium.org>; Andre Przywara <andre.przywara@arm.com>; Marc Kleine-Budde <mkl@pengutronix.de>; SESA644425 <giojahermann@gmail.com>; Samuel Holland <samuel@sholland.org>; Steven Lawrance <steven.lawrance@softathome.com>
> > > Subject: [PATCH] riscv: Add a 64-bit image type
> > >
> > > At present it is not possible to know whether an image can be booted by a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot the wrong image. This may cause a crash which might be hard to debug.
> > >
> > > Add a new property to make this explicit.
> > >
> > > The existing 'RISC-V' is now taken to mean 32-bit.
> > >
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > ---
> > >
> > >  boot/image.c    | 3 ++-
> > >  include/image.h | 3 ++-
> > >  2 files changed, 4 insertions(+), 2 deletions(-)
> >
> > Reviewed-by: Rick Chen <rick@andestech.com>
> 
> This might create compatibility issues if the shipped host tool
> (mkimage) does not match U-Boot version. Any idea how to avoid that?
> 

I am not sure if I understand you correctly.
Do you mean that there could be compatibility issue
if one uses 2023.04 release host tool (mkimage) to build images
that are to be booted by 2023.07 release u-boot (if this patch is merged in 2023.07 u-boot)?

If that is the case, I guess there is no easy way to avoid that.
We could probably have RISCV represent 64 bit riscv architecture
and RISCV32 32 bit because most of the boards are 64 bit.

If that is not the case, could you elaborate more ?

And Rick has sent out a patch to fix booting issue based on Simon's patch as well.

Best regards,
Leo

> Regards,
> Bin
Bin Meng April 17, 2023, 6:27 a.m. UTC | #4
Hi Leo,

On Mon, Apr 17, 2023 at 1:22 PM Leo Liang <ycliang@andestech.com> wrote:
>
> Hi Bin,
>
> On Thu, Apr 13, 2023 at 06:06:29PM +0800, Bin Meng wrote:
> > On Mon, Apr 10, 2023 at 3:25 PM Rick Chen <rickchen36@gmail.com> wrote:
> > >
> > > > From: Simon Glass <sjg@chromium.org>
> > > > Sent: Monday, April 03, 2023 4:28 AM
> > > > To: U-Boot Mailing List <u-boot@lists.denx.de>
> > > > Cc: Sean Anderson <seanga2@gmail.com>; Bin Meng <bmeng.cn@gmail.com>; Rick Jian-Zhi Chen(陳建志) <rick@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycliang@andestech.com>; Simon Glass <sjg@chromium.org>; Andre Przywara <andre.przywara@arm.com>; Marc Kleine-Budde <mkl@pengutronix.de>; SESA644425 <giojahermann@gmail.com>; Samuel Holland <samuel@sholland.org>; Steven Lawrance <steven.lawrance@softathome.com>
> > > > Subject: [PATCH] riscv: Add a 64-bit image type
> > > >
> > > > At present it is not possible to know whether an image can be booted by a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot the wrong image. This may cause a crash which might be hard to debug.
> > > >
> > > > Add a new property to make this explicit.
> > > >
> > > > The existing 'RISC-V' is now taken to mean 32-bit.
> > > >
> > > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > > ---
> > > >
> > > >  boot/image.c    | 3 ++-
> > > >  include/image.h | 3 ++-
> > > >  2 files changed, 4 insertions(+), 2 deletions(-)
> > >
> > > Reviewed-by: Rick Chen <rick@andestech.com>
> >
> > This might create compatibility issues if the shipped host tool
> > (mkimage) does not match U-Boot version. Any idea how to avoid that?
> >
>
> I am not sure if I understand you correctly.
> Do you mean that there could be compatibility issue
> if one uses 2023.04 release host tool (mkimage) to build images
> that are to be booted by 2023.07 release u-boot (if this patch is merged in 2023.07 u-boot)?

Yes.

>
> If that is the case, I guess there is no easy way to avoid that.
> We could probably have RISCV represent 64 bit riscv architecture
> and RISCV32 32 bit because most of the boards are 64 bit.
>
> If that is not the case, could you elaborate more ?
>
> And Rick has sent out a patch to fix booting issue based on Simon's patch as well.

I believe we should be querying some wider audience other than U-Boot
that if the RISC-V community intends to support 64-bit U-Boot booting
a 32-bit kernel, before we introduce such incompatibility change.

Regards,
Bin
Simon Glass April 17, 2023, 11:13 p.m. UTC | #5
Hi Bin,

On Thu, 13 Apr 2023 at 04:06, Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Mon, Apr 10, 2023 at 3:25 PM Rick Chen <rickchen36@gmail.com> wrote:
> >
> > > From: Simon Glass <sjg@chromium.org>
> > > Sent: Monday, April 03, 2023 4:28 AM
> > > To: U-Boot Mailing List <u-boot@lists.denx.de>
> > > Cc: Sean Anderson <seanga2@gmail.com>; Bin Meng <bmeng.cn@gmail.com>; Rick Jian-Zhi Chen(陳建志) <rick@andestech.com>; Leo Yu-Chi Liang(梁育齊) <ycliang@andestech.com>; Simon Glass <sjg@chromium.org>; Andre Przywara <andre.przywara@arm.com>; Marc Kleine-Budde <mkl@pengutronix.de>; SESA644425 <giojahermann@gmail.com>; Samuel Holland <samuel@sholland.org>; Steven Lawrance <steven.lawrance@softathome.com>
> > > Subject: [PATCH] riscv: Add a 64-bit image type
> > >
> > > At present it is not possible to know whether an image can be booted by a 32- or 64-bit bootloader. This means that U-Boot may attempt to boot the wrong image. This may cause a crash which might be hard to debug.
> > >
> > > Add a new property to make this explicit.
> > >
> > > The existing 'RISC-V' is now taken to mean 32-bit.
> > >
> > > Signed-off-by: Simon Glass <sjg@chromium.org>
> > > ---
> > >
> > >  boot/image.c    | 3 ++-
> > >  include/image.h | 3 ++-
> > >  2 files changed, 4 insertions(+), 2 deletions(-)
> >
> > Reviewed-by: Rick Chen <rick@andestech.com>
>
> This might create compatibility issues if the shipped host tool
> (mkimage) does not match U-Boot version. Any idea how to avoid that?

If the images are created as 'riscv' then they will look like 32-bit
images to U-Boot, so likely won't be allowed on a 64-bit machine. I
don't think we can avoid that, but of course, the images could be
updated to use the new type. Note that the type is a string in the
image, so mkimage may in fact tolerate it. I haven't checked though.

Regards,
Simon
diff mbox series

Patch

diff --git a/boot/image.c b/boot/image.c
index 958dbf853474..3f75069695f8 100644
--- a/boot/image.c
+++ b/boot/image.c
@@ -95,7 +95,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,			"",		"",		},
 };
 
diff --git a/include/image.h b/include/image.h
index 7717a4c13d38..a3bdcc6e7f80 100644
--- a/include/image.h
+++ b/include/image.h
@@ -138,7 +138,8 @@  enum {
 	IH_ARCH_ARC,			/* Synopsys DesignWare ARC */
 	IH_ARCH_X86_64,			/* AMD x86_64, Intel and Via */
 	IH_ARCH_XTENSA,			/* Xtensa	*/
-	IH_ARCH_RISCV,			/* RISC-V */
+	IH_ARCH_RISCV,			/* RISC-V 32-Bit */
+	IH_ARCH_RISCV64,		/* RISC-V 64 Bit */
 
 	IH_ARCH_COUNT,
 };