diff mbox series

[v1,3/3] booti/bootm: riscv: Verify image arch type

Message ID 20250311133506.124914-4-mchitale@ventanamicro.com
State Changes Requested
Delegated to: Andes
Headers show
Series Risc-V 32 bit/64 bit images | expand

Commit Message

Mayuresh Chitale March 11, 2025, 1:35 p.m. UTC
Unlike ARM and X86, booting 32-bit images on 64-bit CPUs is currently
not supported for Risc-V. Hence, for bootm, disallow booting a FIT
or a legacy image that was built for an arch type which is different
than the current arch and for booti, set the arch type to be the
same as the current arch.

Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
---
 arch/riscv/lib/bootm.c | 4 ++++
 cmd/booti.c            | 5 ++++-
 2 files changed, 8 insertions(+), 1 deletion(-)

Comments

Heinrich Schuchardt March 11, 2025, 1:59 p.m. UTC | #1
On 11.03.25 14:35, Mayuresh Chitale wrote:
> Unlike ARM and X86, booting 32-bit images on 64-bit CPUs is currently
> not supported for Risc-V. Hence, for bootm, disallow booting a FIT
> or a legacy image that was built for an arch type which is different
> than the current arch and for booti, set the arch type to be the
> same as the current arch.
>
> Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
> ---
>   arch/riscv/lib/bootm.c | 4 ++++
>   cmd/booti.c            | 5 ++++-
>   2 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
> index 76c610bcee0..90f71bee6a5 100644
> --- a/arch/riscv/lib/bootm.c
> +++ b/arch/riscv/lib/bootm.c
> @@ -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,
> diff --git a/cmd/booti.c b/cmd/booti.c
> index 1a57fe91397..00921ec4a9d 100644
> --- a/cmd/booti.c
> +++ b/cmd/booti.c
> @@ -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))

Why do we check for S-mode here? Wouldn't checking CONFIG_RISCV be more
adequate? Think of a micro-controller with only M and U mode.

sipeed_maix_bitm_defconfig has CONFIG_RISCV_MMODE=y, CONFIG_CMD_BOOTI=y.

Cf. 3cedc97479ff ("RISCV: image: Add booti support")

Otherwise looks good.

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

> -		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;
>
Mayuresh Chitale April 3, 2025, 10:58 a.m. UTC | #2
On Tue, Mar 11, 2025 at 7:29 PM Heinrich Schuchardt <xypron.glpk@gmx.de> wrote:
>
> On 11.03.25 14:35, Mayuresh Chitale wrote:
> > Unlike ARM and X86, booting 32-bit images on 64-bit CPUs is currently
> > not supported for Risc-V. Hence, for bootm, disallow booting a FIT
> > or a legacy image that was built for an arch type which is different
> > than the current arch and for booti, set the arch type to be the
> > same as the current arch.
> >
> > Signed-off-by: Mayuresh Chitale <mchitale@ventanamicro.com>
> > ---
> >   arch/riscv/lib/bootm.c | 4 ++++
> >   cmd/booti.c            | 5 ++++-
> >   2 files changed, 8 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
> > index 76c610bcee0..90f71bee6a5 100644
> > --- a/arch/riscv/lib/bootm.c
> > +++ b/arch/riscv/lib/bootm.c
> > @@ -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,
> > diff --git a/cmd/booti.c b/cmd/booti.c
> > index 1a57fe91397..00921ec4a9d 100644
> > --- a/cmd/booti.c
> > +++ b/cmd/booti.c
> > @@ -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))
>
> Why do we check for S-mode here? Wouldn't checking CONFIG_RISCV be more
> adequate? Think of a micro-controller with only M and U mode.
>
> sipeed_maix_bitm_defconfig has CONFIG_RISCV_MMODE=y, CONFIG_CMD_BOOTI=y.
>
> Cf. 3cedc97479ff ("RISCV: image: Add booti support")
>
> Otherwise looks good.

Thanks Heinrich. I will update the patch.
>
> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>
> > -             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;
> >
>
diff mbox series

Patch

diff --git a/arch/riscv/lib/bootm.c b/arch/riscv/lib/bootm.c
index 76c610bcee0..90f71bee6a5 100644
--- a/arch/riscv/lib/bootm.c
+++ b/arch/riscv/lib/bootm.c
@@ -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,
diff --git a/cmd/booti.c b/cmd/booti.c
index 1a57fe91397..00921ec4a9d 100644
--- a/cmd/booti.c
+++ b/cmd/booti.c
@@ -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;