* [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels @ 2025-05-13 9:50 牛 志宏 2025-05-23 16:41 ` Simon Glass 0 siblings, 1 reply; 9+ messages in thread From: 牛 志宏 @ 2025-05-13 9:50 UTC (permalink / raw) To: u-boot@lists.denx.de When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), explicitly pass SMP core/hart ID and DTB address to comply with modern SMP-enabled kernels' boot protocol requirements. Signed-off-by: Zone.N <zone.niuzh@hotmail.com> --- boot/bootm_os.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/boot/bootm_os.c b/boot/bootm_os.c index a3c7cb5332e..a0f310b1359 100644 --- a/boot/bootm_os.c +++ b/boot/bootm_os.c @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) if (flag != BOOTM_STATE_OS_GO) return 0; +#if defined(CONFIG_RISCV) + bmi->argc = gd->arch.boot_hart; + bmi->argv = (char **)bmi->images->ft_addr; +#endif + bootelf(bmi->images->ep, flags, bmi->argc, bmi->argv); return 1; -- 2.45.2 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-13 9:50 [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 牛 志宏 @ 2025-05-23 16:41 ` Simon Glass 2025-05-23 17:04 ` Heinrich Schuchardt 0 siblings, 1 reply; 9+ messages in thread From: Simon Glass @ 2025-05-23 16:41 UTC (permalink / raw) To: 牛 志宏, Heinrich Schuchardt; +Cc: u-boot@lists.denx.de +Heinrich Schuchardt Hi, On Tue, 13 May 2025 at 13:28, 牛 志宏 <Zone.Niuzh@hotmail.com> wrote: > > When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), > explicitly pass SMP core/hart ID and DTB address to comply with modern > SMP-enabled kernels' boot protocol requirements. > > Signed-off-by: Zone.N <zone.niuzh@hotmail.com> > --- > boot/bootm_os.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/boot/bootm_os.c b/boot/bootm_os.c > index a3c7cb5332e..a0f310b1359 100644 > --- a/boot/bootm_os.c > +++ b/boot/bootm_os.c > @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) > if (flag != BOOTM_STATE_OS_GO) > return 0; > > +#if defined(CONFIG_RISCV) > + bmi->argc = gd->arch.boot_hart; > + bmi->argv = (char **)bmi->images->ft_addr; > +#endif If this is a kernel, it should really be using a FIT. The Elf entry is for general ELF files, not Linux. Perhaps RISC-V is special in some way? > + > bootelf(bmi->images->ep, flags, bmi->argc, bmi->argv); > > return 1; > -- > 2.45.2 Regards, Simon ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-23 16:41 ` Simon Glass @ 2025-05-23 17:04 ` Heinrich Schuchardt 2025-05-23 22:29 ` Tom Rini 0 siblings, 1 reply; 9+ messages in thread From: Heinrich Schuchardt @ 2025-05-23 17:04 UTC (permalink / raw) To: Simon Glass, 牛 志宏; +Cc: u-boot@lists.denx.de Am 23. Mai 2025 18:41:45 MESZ schrieb Simon Glass <sjg@chromium.org>: >+Heinrich Schuchardt > >Hi, > >On Tue, 13 May 2025 at 13:28, 牛 志宏 <Zone.Niuzh@hotmail.com> wrote: >> >> When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), >> explicitly pass SMP core/hart ID and DTB address to comply with modern >> SMP-enabled kernels' boot protocol requirements. >> >> Signed-off-by: Zone.N <zone.niuzh@hotmail.com> >> --- >> boot/bootm_os.c | 5 +++++ >> 1 file changed, 5 insertions(+) >> >> diff --git a/boot/bootm_os.c b/boot/bootm_os.c >> index a3c7cb5332e..a0f310b1359 100644 >> --- a/boot/bootm_os.c >> +++ b/boot/bootm_os.c >> @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) >> if (flag != BOOTM_STATE_OS_GO) >> return 0; >> >> +#if defined(CONFIG_RISCV) >> + bmi->argc = gd->arch.boot_hart; >> + bmi->argv = (char **)bmi->images->ft_addr; >> +#endif > >If this is a kernel, it should really be using a FIT. The Elf entry >is for general ELF files, not Linux. Perhaps RISC-V is special in some >way? A defconfig kernel is booted via the booti command or via its EFI stub. Why would you use an ELF formatted kernel? What kernel configuration are you using to get such a kernel? Best regards Heinrich > >> + >> bootelf(bmi->images->ep, flags, bmi->argc, bmi->argv); >> >> return 1; >> -- >> 2.45.2 > >Regards, >Simon ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-23 17:04 ` Heinrich Schuchardt @ 2025-05-23 22:29 ` Tom Rini 2025-05-24 4:29 ` Heinrich Schuchardt 0 siblings, 1 reply; 9+ messages in thread From: Tom Rini @ 2025-05-23 22:29 UTC (permalink / raw) To: Heinrich Schuchardt Cc: Simon Glass, 牛 志宏, u-boot@lists.denx.de [-- Attachment #1: Type: text/plain, Size: 1623 bytes --] On Fri, May 23, 2025 at 07:04:46PM +0200, Heinrich Schuchardt wrote: > Am 23. Mai 2025 18:41:45 MESZ schrieb Simon Glass <sjg@chromium.org>: > >+Heinrich Schuchardt > > > >Hi, > > > >On Tue, 13 May 2025 at 13:28, 牛 志宏 <Zone.Niuzh@hotmail.com> wrote: > >> > >> When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), > >> explicitly pass SMP core/hart ID and DTB address to comply with modern > >> SMP-enabled kernels' boot protocol requirements. > >> > >> Signed-off-by: Zone.N <zone.niuzh@hotmail.com> > >> --- > >> boot/bootm_os.c | 5 +++++ > >> 1 file changed, 5 insertions(+) > >> > >> diff --git a/boot/bootm_os.c b/boot/bootm_os.c > >> index a3c7cb5332e..a0f310b1359 100644 > >> --- a/boot/bootm_os.c > >> +++ b/boot/bootm_os.c > >> @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) > >> if (flag != BOOTM_STATE_OS_GO) > >> return 0; > >> > >> +#if defined(CONFIG_RISCV) > >> + bmi->argc = gd->arch.boot_hart; > >> + bmi->argv = (char **)bmi->images->ft_addr; > >> +#endif > > > >If this is a kernel, it should really be using a FIT. The Elf entry > >is for general ELF files, not Linux. Perhaps RISC-V is special in some > >way? > > A defconfig kernel is booted via the booti command or via its EFI stub. > > Why would you use an ELF formatted kernel? What kernel configuration are you using to get such a kernel? This is I assume a non-Linux OS kernel being booted. So the question is, does anyone externally have some standard defined here which should be used? -- Tom [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 659 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-23 22:29 ` Tom Rini @ 2025-05-24 4:29 ` Heinrich Schuchardt 2025-05-29 9:33 ` 回复: " 牛 志宏 0 siblings, 1 reply; 9+ messages in thread From: Heinrich Schuchardt @ 2025-05-24 4:29 UTC (permalink / raw) To: Tom Rini Cc: Simon Glass, 牛 志宏, u-boot@lists.denx.de, Leo Yu-Chi Liang, Rick Chen On 5/24/25 00:29, Tom Rini wrote: > On Fri, May 23, 2025 at 07:04:46PM +0200, Heinrich Schuchardt wrote: >> Am 23. Mai 2025 18:41:45 MESZ schrieb Simon Glass <sjg@chromium.org>: >>> +Heinrich Schuchardt >>> >>> Hi, >>> >>> On Tue, 13 May 2025 at 13:28, 牛 志宏 <Zone.Niuzh@hotmail.com> wrote: >>>> >>>> When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), >>>> explicitly pass SMP core/hart ID and DTB address to comply with modern >>>> SMP-enabled kernels' boot protocol requirements. >>>> >>>> Signed-off-by: Zone.N <zone.niuzh@hotmail.com> >>>> --- >>>> boot/bootm_os.c | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/boot/bootm_os.c b/boot/bootm_os.c >>>> index a3c7cb5332e..a0f310b1359 100644 >>>> --- a/boot/bootm_os.c >>>> +++ b/boot/bootm_os.c >>>> @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) >>>> if (flag != BOOTM_STATE_OS_GO) >>>> return 0; >>>> >>>> +#if defined(CONFIG_RISCV) >>>> + bmi->argc = gd->arch.boot_hart; >>>> + bmi->argv = (char **)bmi->images->ft_addr; >>>> +#endif >>> >>> If this is a kernel, it should really be using a FIT. The Elf entry >>> is for general ELF files, not Linux. Perhaps RISC-V is special in some >>> way? >> >> A defconfig kernel is booted via the booti command or via its EFI stub. >> >> Why would you use an ELF formatted kernel? What kernel configuration are you using to get such a kernel? > > This is I assume a non-Linux OS kernel being booted. So the question is, > does anyone externally have some standard defined here which should be > used? > https://docs.kernel.org/arch/riscv/boot.html describes the requirements: "The RISC-V kernel expects: $a0 to contain the hartid of the current core. $a1 to contain the address of the devicetree in memory." Both the bootm command and the bootelf command end up calling bootelf_exec(). So the correction should probably be made in lib/elf.c and not in /boot/bootm_os.c. a0 and a1 are the the first and second arguments in the RISC-V calling convention. Using a0 and a1 as required by the kernel is completely incompatible with the current design of the bootelf command where you can pass arbitrary string arguments to an ELF binary. CONFIG_CMD_ELF_FDT_SETUP allows to pass a device-tree address string as argv[0]. It is unclear to me if there are use cases where we want to execute ELF binaries that are not OS kernels via the bootelf or bootm command. The RISC-V maintainers should review any change for RISC-V in the handling of ELF binaries. Best regards Heinrich ^ permalink raw reply [flat|nested] 9+ messages in thread
* 回复: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-24 4:29 ` Heinrich Schuchardt @ 2025-05-29 9:33 ` 牛 志宏 2025-05-29 15:49 ` Tom Rini 0 siblings, 1 reply; 9+ messages in thread From: 牛 志宏 @ 2025-05-29 9:33 UTC (permalink / raw) To: Heinrich Schuchardt, Tom Rini Cc: Simon Glass, u-boot@lists.denx.de, Leo Yu-Chi Liang, Rick Chen hi team, The ITS file looks something like the following, and the kernel is not a standard Linux kernel: ``` /dts-v1/; / { ... images { kernel { type = "kernel"; arch = "riscv"; os = "elf"; ... }; fdt { type = "flat_dt"; arch = "riscv"; ... }; }; ... }; ``` To handle this scenario, we need to: 1. Access the values of the `type`, os, and arch fields stored in bootm_headers->image_info to determine the current context. 2. Access the boot_hart and ft_addr stored in the gd variable to update argc and argv. Not sure whether accessing the bootm_headers and gd variables in lib/elf.c is allowed or safe. BR, zhihong ________________________________ 发件人: Heinrich Schuchardt <xypron.glpk@gmx.de> 发送时间: 2025年5月24日 12:29 收件人: Tom Rini <trini@konsulko.com> 抄送: Simon Glass <sjg@chromium.org>; 牛 志宏 <Zone.Niuzh@hotmail.com>; u-boot@lists.denx.de <u-boot@lists.denx.de>; Leo Yu-Chi Liang <ycliang@andestech.com>; Rick Chen <rick@andestech.com> 主题: Re: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels On 5/24/25 00:29, Tom Rini wrote: > On Fri, May 23, 2025 at 07:04:46PM +0200, Heinrich Schuchardt wrote: >> Am 23. Mai 2025 18:41:45 MESZ schrieb Simon Glass <sjg@chromium.org>: >>> +Heinrich Schuchardt >>> >>> Hi, >>> >>> On Tue, 13 May 2025 at 13:28, 牛 志宏 <Zone.Niuzh@hotmail.com> wrote: >>>> >>>> When booting RISC-V ELF-formatted kernel images (IH_TYPE_KERNEL + IH_OS_ELF), >>>> explicitly pass SMP core/hart ID and DTB address to comply with modern >>>> SMP-enabled kernels' boot protocol requirements. >>>> >>>> Signed-off-by: Zone.N <zone.niuzh@hotmail.com> >>>> --- >>>> boot/bootm_os.c | 5 +++++ >>>> 1 file changed, 5 insertions(+) >>>> >>>> diff --git a/boot/bootm_os.c b/boot/bootm_os.c >>>> index a3c7cb5332e..a0f310b1359 100644 >>>> --- a/boot/bootm_os.c >>>> +++ b/boot/bootm_os.c >>>> @@ -402,6 +402,11 @@ static int do_bootm_elf(int flag, struct bootm_info *bmi) >>>> if (flag != BOOTM_STATE_OS_GO) >>>> return 0; >>>> >>>> +#if defined(CONFIG_RISCV) >>>> + bmi->argc = gd->arch.boot_hart; >>>> + bmi->argv = (char **)bmi->images->ft_addr; >>>> +#endif >>> >>> If this is a kernel, it should really be using a FIT. The Elf entry >>> is for general ELF files, not Linux. Perhaps RISC-V is special in some >>> way? >> >> A defconfig kernel is booted via the booti command or via its EFI stub. >> >> Why would you use an ELF formatted kernel? What kernel configuration are you using to get such a kernel? > > This is I assume a non-Linux OS kernel being booted. So the question is, > does anyone externally have some standard defined here which should be > used? > https://docs.kernel.org/arch/riscv/boot.html describes the requirements: "The RISC-V kernel expects: $a0 to contain the hartid of the current core. $a1 to contain the address of the devicetree in memory." Both the bootm command and the bootelf command end up calling bootelf_exec(). So the correction should probably be made in lib/elf.c and not in /boot/bootm_os.c. a0 and a1 are the the first and second arguments in the RISC-V calling convention. Using a0 and a1 as required by the kernel is completely incompatible with the current design of the bootelf command where you can pass arbitrary string arguments to an ELF binary. CONFIG_CMD_ELF_FDT_SETUP allows to pass a device-tree address string as argv[0]. It is unclear to me if there are use cases where we want to execute ELF binaries that are not OS kernels via the bootelf or bootm command. The RISC-V maintainers should review any change for RISC-V in the handling of ELF binaries. Best regards Heinrich ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 回复: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 2025-05-29 9:33 ` 回复: " 牛 志宏 @ 2025-05-29 15:49 ` Tom Rini [not found] ` <ME0P300MB13099B02B4C316E4784D23529F6FA@ME0P300MB1309.AUSP300.PROD.OUTLOOK.COM> 0 siblings, 1 reply; 9+ messages in thread From: Tom Rini @ 2025-05-29 15:49 UTC (permalink / raw) To: 牛 志宏 Cc: Heinrich Schuchardt, Simon Glass, u-boot@lists.denx.de, Leo Yu-Chi Liang, Rick Chen [-- Attachment #1: Type: text/plain, Size: 1245 bytes --] On Thu, May 29, 2025 at 09:33:56AM +0000, 牛 志宏 wrote: > hi team, > > The ITS file looks something like the following, and the kernel is not a standard Linux kernel: > ``` > /dts-v1/; > > / { > ... > images { > kernel { > type = "kernel"; > arch = "riscv"; > os = "elf"; > ... > }; > > fdt { > type = "flat_dt"; > arch = "riscv"; > ... > }; > }; > ... > }; > ``` > > To handle this scenario, we need to: > > 1. > Access the values of the `type`, os, and arch fields stored in bootm_headers->image_info to determine the current context. > 2. > Access the boot_hart and ft_addr stored in the gd variable to update argc and argv. > > Not sure whether accessing the bootm_headers and gd variables in lib/elf.c is allowed or safe. So this is why I was asking if there's some more generalized specification we can reference. Is the OS you're using something pre-existing and so we need to do what it already expect from some other loader? Or is it something you're also creating and if so, why not follow the linux kernel convention for compatibility? -- Tom [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 659 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
[parent not found: <ME0P300MB13099B02B4C316E4784D23529F6FA@ME0P300MB1309.AUSP300.PROD.OUTLOOK.COM>]
* Re: 回复: 回复: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels [not found] ` <ME0P300MB13099B02B4C316E4784D23529F6FA@ME0P300MB1309.AUSP300.PROD.OUTLOOK.COM> @ 2025-06-05 14:29 ` Yao Zi 2025-06-05 14:47 ` Tom Rini 1 sibling, 0 replies; 9+ messages in thread From: Yao Zi @ 2025-06-05 14:29 UTC (permalink / raw) To: 牛 志宏, Tom Rini Cc: Heinrich Schuchardt, Simon Glass, u-boot@lists.denx.de, Leo Yu-Chi Liang, Rick Chen On Thu, Jun 05, 2025 at 08:04:28AM +0000, 牛 志宏 wrote: > Yes, this is a new OS currently being developed with plans to support Linux compatibility. > Registers a0 and a1 pass the boot core ID and DTB address respectively, following a de facto standard shared by both the SBI (RISC-V Supervisor Binary Interface) specification and the Linux implementation. > My rationale is: if U-Boot supports the combination of kernel + ELF loading, why shouldn't we implement this capability as well? Do you mean passing arguments according to the convention of Linux even when booting ELF stuff? TBH, it should be easy to turn your ELF into an Linux-style Image... > > ________________________________ > 发件人: Tom Rini > 已发送: 2025 年 5 月 29 日 星期四 23:49 > 收件人: 牛 志宏 > 抄送: Heinrich Schuchardt; Simon Glass; u-boot@lists.denx.de; Leo Yu-Chi Liang; Rick Chen > 主题: Re: 回复: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels > > On Thu, May 29, 2025 at 09:33:56AM +0000, 牛 志宏 wrote: > > hi team, > > > > The ITS file looks something like the following, and the kernel is not a standard Linux kernel: > > ``` > > /dts-v1/; > > > > / { > > ... > > images { > > kernel { > > type = "kernel"; > > arch = "riscv"; > > os = "elf"; > > ... > > }; > > > > fdt { > > type = "flat_dt"; > > arch = "riscv"; > > ... > > }; > > }; > > ... > > }; > > ``` > > > > To handle this scenario, we need to: > > > > 1. > > Access the values of the `type`, os, and arch fields stored in bootm_headers->image_info to determine the current context. > > 2. > > Access the boot_hart and ft_addr stored in the gd variable to update argc and argv. > > > > Not sure whether accessing the bootm_headers and gd variables in lib/elf.c is allowed or safe. > So this is why I was asking if there's some more generalized > specification we can reference. Is the OS you're using something > pre-existing and so we need to do what it already expect from some other > loader? Or is it something you're also creating and if so, why not > follow the linux kernel convention for compatibility? > > -- > Tom Regards, Yao Zi ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: 回复: 回复: [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels [not found] ` <ME0P300MB13099B02B4C316E4784D23529F6FA@ME0P300MB1309.AUSP300.PROD.OUTLOOK.COM> 2025-06-05 14:29 ` 回复: " Yao Zi @ 2025-06-05 14:47 ` Tom Rini 1 sibling, 0 replies; 9+ messages in thread From: Tom Rini @ 2025-06-05 14:47 UTC (permalink / raw) To: 牛 志宏 Cc: Heinrich Schuchardt, Simon Glass, u-boot@lists.denx.de, Leo Yu-Chi Liang, Rick Chen [-- Attachment #1: Type: text/plain, Size: 761 bytes --] On Thu, Jun 05, 2025 at 08:04:28AM +0000, 牛 志宏 wrote: > Yes, this is a new OS currently being developed with plans to support Linux compatibility. > Registers a0 and a1 pass the boot core ID and DTB address respectively, following a de facto standard shared by both the SBI (RISC-V Supervisor Binary Interface) specification and the Linux implementation. > My rationale is: if U-Boot supports the combination of kernel + ELF loading, why shouldn't we implement this capability as well? Thanks. I see this is spelled out in https://www.kernel.org/doc/html/latest/arch/riscv/boot.html as well. Can you please do a v2 with an expanded commit message and a Link: to that URL as well so it's clearer that isn't just an ad-hoc decision? -- Tom [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 659 bytes --] ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-06-05 14:48 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-13 9:50 [PATCH] bootm: Pass SMP core ID and DTB address for ELF-formatted kernels 牛 志宏
2025-05-23 16:41 ` Simon Glass
2025-05-23 17:04 ` Heinrich Schuchardt
2025-05-23 22:29 ` Tom Rini
2025-05-24 4:29 ` Heinrich Schuchardt
2025-05-29 9:33 ` 回复: " 牛 志宏
2025-05-29 15:49 ` Tom Rini
[not found] ` <ME0P300MB13099B02B4C316E4784D23529F6FA@ME0P300MB1309.AUSP300.PROD.OUTLOOK.COM>
2025-06-05 14:29 ` 回复: " Yao Zi
2025-06-05 14:47 ` Tom Rini
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.