* [RFC 0/1] add support of `--initrd` for ELF-ARM kernels
@ 2023-04-14 7:34 Stefan Lankes
2023-04-14 7:34 ` [RFC 1/1] " Stefan Lankes
0 siblings, 1 reply; 7+ messages in thread
From: Stefan Lankes @ 2023-04-14 7:34 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, Stefan Lankes
We are developing an ELF-based kernel for ARM processor and would like
to use the flag "—initrd". An initial ramdisk simplifies the boot
process, but as far as I know, it is currently not support by Qemu for
ARM processors. The flag is only available for pure Linux kernels.
This patch enables the flags for ELF kernels and creates a device tree
entry, which helps the kernel to find the address of the initial ramdisk.
Stefan Lankes (1):
add support of `--initrd` for ELF-ARM kernels
hw/arm/boot.c | 106 +++++++++++++++++++++++++++++---------------------
1 file changed, 62 insertions(+), 44 deletions(-)
--
2.39.2 (Apple Git-143)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 7:34 [RFC 0/1] add support of `--initrd` for ELF-ARM kernels Stefan Lankes
@ 2023-04-14 7:34 ` Stefan Lankes
2023-04-14 8:54 ` Alex Bennée
2023-04-14 9:02 ` Peter Maydell
0 siblings, 2 replies; 7+ messages in thread
From: Stefan Lankes @ 2023-04-14 7:34 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, qemu-arm, Stefan Lankes
Currently, the flag `--initrd` is only support for Linux ARM kernels.
However, also other ELF kernels could depend on an initial ramdisk.
This PR loads also the initrd for ELF kernels and announce the
location by the nodes "/chosen/initrd-start" and
"/chosen/initrd-end" within the device tree.
Signed-off-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
---
hw/arm/boot.c | 106 +++++++++++++++++++++++++++++---------------------
1 file changed, 62 insertions(+), 44 deletions(-)
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 54f6a3e0b3..f767a4809e 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -657,20 +657,38 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
}
if (binfo->initrd_size) {
- rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
+ if (binfo->is_linux) {
+ rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
acells, binfo->initrd_start);
- if (rc < 0) {
- fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
- goto fail;
- }
+ if (rc < 0) {
+ fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
+ goto fail;
+ }
- rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
- acells,
- binfo->initrd_start +
- binfo->initrd_size);
- if (rc < 0) {
- fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
- goto fail;
+ rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
+ acells,
+ binfo->initrd_start +
+ binfo->initrd_size);
+ if (rc < 0) {
+ fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
+ goto fail;
+ }
+ } else {
+ rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-start",
+ acells, binfo->initrd_start);
+ if (rc < 0) {
+ fprintf(stderr, "couldn't set /chosen/initrd-start\n");
+ goto fail;
+ }
+
+ rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-end",
+ acells,
+ binfo->initrd_start +
+ binfo->initrd_size);
+ if (rc < 0) {
+ fprintf(stderr, "couldn't set /chosen/initrd-end\n");
+ goto fail;
+ }
}
}
@@ -1099,41 +1117,41 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu,
}
info->initrd_start = TARGET_PAGE_ALIGN(info->initrd_start);
- if (is_linux) {
- uint32_t fixupcontext[FIXUP_MAX];
-
- if (info->initrd_filename) {
+ if (info->initrd_filename) {
- if (info->initrd_start >= ram_end) {
- error_report("not enough space after kernel to load initrd");
- exit(1);
- }
+ if (info->initrd_start >= ram_end) {
+ error_report("not enough space after kernel to load initrd");
+ exit(1);
+ }
- initrd_size = load_ramdisk_as(info->initrd_filename,
- info->initrd_start,
- ram_end - info->initrd_start, as);
- if (initrd_size < 0) {
- initrd_size = load_image_targphys_as(info->initrd_filename,
- info->initrd_start,
- ram_end -
- info->initrd_start,
- as);
- }
- if (initrd_size < 0) {
- error_report("could not load initrd '%s'",
- info->initrd_filename);
- exit(1);
- }
- if (info->initrd_start + initrd_size > ram_end) {
- error_report("could not load initrd '%s': "
- "too big to fit into RAM after the kernel",
- info->initrd_filename);
- exit(1);
- }
- } else {
- initrd_size = 0;
+ initrd_size = load_ramdisk_as(info->initrd_filename,
+ info->initrd_start,
+ ram_end - info->initrd_start, as);
+ if (initrd_size < 0) {
+ initrd_size = load_image_targphys_as(info->initrd_filename,
+ info->initrd_start,
+ ram_end -
+ info->initrd_start,
+ as);
+ }
+ if (initrd_size < 0) {
+ error_report("could not load initrd '%s'",
+ info->initrd_filename);
+ exit(1);
+ }
+ if (info->initrd_start + initrd_size > ram_end) {
+ error_report("could not load initrd '%s': "
+ "too big to fit into RAM after the kernel",
+ info->initrd_filename);
+ exit(1);
}
- info->initrd_size = initrd_size;
+ } else {
+ initrd_size = 0;
+ }
+ info->initrd_size = initrd_size;
+
+ if (is_linux) {
+ uint32_t fixupcontext[FIXUP_MAX];
fixupcontext[FIXUP_BOARDID] = info->board_id;
fixupcontext[FIXUP_BOARD_SETUP] = info->board_setup_addr;
--
2.39.2 (Apple Git-143)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 7:34 ` [RFC 1/1] " Stefan Lankes
@ 2023-04-14 8:54 ` Alex Bennée
2023-04-14 12:34 ` Lankes, Stefan
2023-04-14 9:02 ` Peter Maydell
1 sibling, 1 reply; 7+ messages in thread
From: Alex Bennée @ 2023-04-14 8:54 UTC (permalink / raw)
To: Stefan Lankes; +Cc: peter.maydell, qemu-arm, qemu-devel
Stefan Lankes <slankes@eonerc.rwth-aachen.de> writes:
> Currently, the flag `--initrd` is only support for Linux ARM kernels.
> However, also other ELF kernels could depend on an initial ramdisk.
> This PR loads also the initrd for ELF kernels and announce the
> location by the nodes "/chosen/initrd-start" and
> "/chosen/initrd-end" within the device tree.
>
> Signed-off-by: Stefan Lankes <slankes@eonerc.rwth-aachen.de>
> ---
> hw/arm/boot.c | 106 +++++++++++++++++++++++++++++---------------------
> 1 file changed, 62 insertions(+), 44 deletions(-)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index 54f6a3e0b3..f767a4809e 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -657,20 +657,38 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
> }
>
> if (binfo->initrd_size) {
> - rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
> + if (binfo->is_linux) {
> + rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
> acells, binfo->initrd_start);
> - if (rc < 0) {
> - fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
> - goto fail;
> - }
> + if (rc < 0) {
> + fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
> + goto fail;
> + }
>
> - rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
> - acells,
> - binfo->initrd_start +
> - binfo->initrd_size);
> - if (rc < 0) {
> - fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
> - goto fail;
> + rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-end",
> + acells,
> + binfo->initrd_start +
> + binfo->initrd_size);
> + if (rc < 0) {
> + fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
> + goto fail;
> + }
> + } else {
> + rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-start",
> + acells, binfo->initrd_start);
> + if (rc < 0) {
> + fprintf(stderr, "couldn't set /chosen/initrd-start\n");
> + goto fail;
> + }
> +
> + rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "initrd-end",
> + acells,
> + binfo->initrd_start +
> + binfo->initrd_size);
> + if (rc < 0) {
> + fprintf(stderr, "couldn't set /chosen/initrd-end\n");
> + goto fail;
> + }
Where are these DTB nodes documented?
Also could you not achieve the same thing using the guest-loader which
uses the multiboot spec and sets:
const char *compat[2] = { "multiboot,module", "multiboot,ramdisk" };
if (qemu_fdt_setprop_string_array(fdt, node, "compatible",
(char **) &compat,
ARRAY_SIZE(compat)) < 0) {
error_setg(errp, "couldn't set %s/compatible", node);
return;
}
--
Alex Bennée
Virtualisation Tech Lead @ Linaro
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 7:34 ` [RFC 1/1] " Stefan Lankes
2023-04-14 8:54 ` Alex Bennée
@ 2023-04-14 9:02 ` Peter Maydell
2023-04-14 9:26 ` Lankes, Stefan
1 sibling, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2023-04-14 9:02 UTC (permalink / raw)
To: Stefan Lankes; +Cc: qemu-devel, qemu-arm
On Fri, 14 Apr 2023 at 08:35, Stefan Lankes
<slankes@eonerc.rwth-aachen.de> wrote:
>
> Currently, the flag `--initrd` is only support for Linux ARM kernels.
> However, also other ELF kernels could depend on an initial ramdisk.
> This PR loads also the initrd for ELF kernels and announce the
> location by the nodes "/chosen/initrd-start" and
> "/chosen/initrd-end" within the device tree.
What are these "other ELF kernels" ? Is there some defined
specification of bootloader you're trying to implement here?
Currently QEMU for Arm supports two things:
(1) I am a Linux kernel, load me like the Linux kernel defines
(2) I'm just a bare-metal image (ELF file or raw)
Adding support for some third type of loading would need a
pretty solid justification, eg that this is a very common kind
of image to load, that there is a well defined specification,
that it's supported by lots of other bootloaders, etc.
The bootloading code is too complicated already and I am
very reluctant to add more to it.
thanks
-- PMM
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 9:02 ` Peter Maydell
@ 2023-04-14 9:26 ` Lankes, Stefan
0 siblings, 0 replies; 7+ messages in thread
From: Lankes, Stefan @ 2023-04-14 9:26 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-devel@nongnu.org, qemu-arm@nongnu.org
[-- Attachment #1.1: Type: text/plain, Size: 1740 bytes --]
Hello Peter,
I totally agree. We are developing a unikernel (https://github.com/hermitcore/rusty-hermit). On x86, we are using the multiboot specification. I thought that this specification is only available on x86.
In principle, a unikernel is a single application, which runs directly on the hardware/VM. Our ELF loader parse the ELF application to determine the thread local storage. On x86, Qemu loads the unikernel as initrd into the memory. The loader just initialize the system. I miss a similar feature on ARM. Maybe I oversee something.
Cheers
Stefan
> Am 14.04.2023 um 11:03 schrieb Peter Maydell <peter.maydell@linaro.org>:
>
> On Fri, 14 Apr 2023 at 08:35, Stefan Lankes
> <slankes@eonerc.rwth-aachen.de> wrote:
>> Currently, the flag `--initrd` is only support for Linux ARM kernels.
>> However, also other ELF kernels could depend on an initial ramdisk.
>> This PR loads also the initrd for ELF kernels and announce the
>> location by the nodes "/chosen/initrd-start" and
>> "/chosen/initrd-end" within the device tree.
>
> What are these "other ELF kernels" ? Is there some defined
> specification of bootloader you're trying to implement here?
>
> Currently QEMU for Arm supports two things:
> (1) I am a Linux kernel, load me like the Linux kernel defines
> (2) I'm just a bare-metal image (ELF file or raw)
>
> Adding support for some third type of loading would need a
> pretty solid justification, eg that this is a very common kind
> of image to load, that there is a well defined specification,
> that it's supported by lots of other bootloaders, etc.
> The bootloading code is too complicated already and I am
> very reluctant to add more to it.
>
> thanks
> -- PMM
[-- Attachment #1.2: Type: text/html, Size: 3693 bytes --]
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3031 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 8:54 ` Alex Bennée
@ 2023-04-14 12:34 ` Lankes, Stefan
2023-04-15 7:51 ` Lankes, Stefan
0 siblings, 1 reply; 7+ messages in thread
From: Lankes, Stefan @ 2023-04-14 12:34 UTC (permalink / raw)
To: Alex Bennée
Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org,
qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 746 bytes --]
> Am 14.04.2023 um 10:54 schrieb Alex Bennée <alex.bennee@linaro.org>:
>
Hello Alex,
>
> Where are these DTB nodes documented?
Yes, it is currently missing.
>
> Also could you not achieve the same thing using the guest-loader which
> uses the multiboot spec and sets:
>
> const char *compat[2] = { "multiboot,module", "multiboot,ramdisk" };
> if (qemu_fdt_setprop_string_array(fdt, node, "compatible",
> (char **) &compat,
> ARRAY_SIZE(compat)) < 0) {
> error_setg(errp, "couldn't set %s/compatible", node);
> return;
> }
>
Thanks for the hint. I will check it.
Cheers
Stefan
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5789 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC 1/1] add support of `--initrd` for ELF-ARM kernels
2023-04-14 12:34 ` Lankes, Stefan
@ 2023-04-15 7:51 ` Lankes, Stefan
0 siblings, 0 replies; 7+ messages in thread
From: Lankes, Stefan @ 2023-04-15 7:51 UTC (permalink / raw)
To: Alex Bennée
Cc: Peter Maydell, qemu-arm@nongnu.org, qemu-devel@nongnu.org
[-- Attachment #1: Type: text/plain, Size: 839 bytes --]
Hello Alex,
>
>
>> Am 14.04.2023 um 10:54 schrieb Alex Bennée <alex.bennee@linaro.org>:
>>
>>
>> Also could you not achieve the same thing using the guest-loader which
>> uses the multiboot spec and sets:
>>
>> const char *compat[2] = { "multiboot,module", "multiboot,ramdisk" };
>> if (qemu_fdt_setprop_string_array(fdt, node, "compatible",
>> (char **) &compat,
>> ARRAY_SIZE(compat)) < 0) {
>> error_setg(errp, "couldn't set %s/compatible", node);
>> return;
>> }
>>
>
> Thanks for the hint. I will check it.
>
I check it and it works fine for me. Consequently, you can ignore this RFC.
I was confused that the flag `—initrd` is available and not used.
Cheers
Stefan
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5789 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2023-04-15 7:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-14 7:34 [RFC 0/1] add support of `--initrd` for ELF-ARM kernels Stefan Lankes
2023-04-14 7:34 ` [RFC 1/1] " Stefan Lankes
2023-04-14 8:54 ` Alex Bennée
2023-04-14 12:34 ` Lankes, Stefan
2023-04-15 7:51 ` Lankes, Stefan
2023-04-14 9:02 ` Peter Maydell
2023-04-14 9:26 ` Lankes, Stefan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).