From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Alistair Francis" <alistair@alistair23.me>,
julien@xen.org, masami.hiramatsu@linaro.org,
andre.przywara@arm.com, stefano.stabellini@linaro.org,
takahiro.akashi@linaro.org, stefano.stabellini@xilinx.com,
"Alex Bennée" <alex.bennee@linaro.org>,
stratos-dev@op-lists.linaro.org
Subject: [RFC PATCH 4/4] generic_loader: allow the insertion of /chosen/module stanzas
Date: Fri, 9 Oct 2020 18:07:42 +0100 [thread overview]
Message-ID: <20201009170742.23695-5-alex.bennee@linaro.org> (raw)
In-Reply-To: <20201009170742.23695-1-alex.bennee@linaro.org>
The /chosen FDT node is how the firmware indicates information about
the kernel to the loader code. In a full boot chain this would come
from something like a boot loader. However if we use the generic
loader to load blobs into RAM before launching a hypervisor for
example we can boot directly:
$QEMU $ARGS -kernel ~/xen.git/xen/xen \
-append "dom0_mem=1G,max:1G loglvl=all guest_loglvl=all" \
-device loader,addr=0x47000000,\
file=Image,\
len-fdt-compat=2,\
fdt-compat[0]='multiboot,,module',\
fdt-compat[1]='multiboot,,kernel',\
fdt-bootargs="root=/dev/mapper/vg0-root ro console=hvc0 earlyprintk=xen"
Note the ,, escapes required for the command line parser.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
include/hw/core/generic-loader.h | 4 +++
hw/core/generic-loader.c | 42 ++++++++++++++++++++++++++++++++
2 files changed, 46 insertions(+)
diff --git a/include/hw/core/generic-loader.h b/include/hw/core/generic-loader.h
index 19d87b39c8..98b0452430 100644
--- a/include/hw/core/generic-loader.h
+++ b/include/hw/core/generic-loader.h
@@ -39,6 +39,10 @@ struct GenericLoaderState {
bool force_raw;
bool data_be;
bool set_pc;
+
+ char **fdt_compat;
+ uint32_t fdt_compat_count;
+ char *fdt_bootargs;
};
#define TYPE_GENERIC_LOADER "loader"
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
index a242c076f6..8bd8a33e80 100644
--- a/hw/core/generic-loader.c
+++ b/hw/core/generic-loader.c
@@ -40,6 +40,8 @@
#include "qapi/error.h"
#include "qemu/module.h"
#include "hw/core/generic-loader.h"
+#include "sysemu/device_tree.h"
+#include "hw/boards.h"
#define CPU_NONE 0xFFFFFFFF
@@ -61,6 +63,39 @@ static void generic_loader_reset(void *opaque)
}
}
+/*
+ * Insert some FDT nodes for the loaded blob.
+ */
+static void loader_insert_fdt(GenericLoaderState *s, int size, Error **errp)
+{
+ MachineState *machine = MACHINE(qdev_get_machine());
+ void *fdt = machine->fdt;
+ g_autofree char *node = g_strdup_printf("/chosen/module@%#08lx", s->addr);
+ uint64_t reg_attr[2] = {cpu_to_be64(s->addr), cpu_to_be64(size)};
+
+ if (!fdt) {
+ error_setg(errp, "Cannot modify FDT fields if the machine has none");
+ return;
+ }
+
+ qemu_fdt_add_subnode(fdt, node);
+ qemu_fdt_setprop(fdt, node, "reg", ®_attr, sizeof(reg_attr));
+
+ if (s->fdt_compat) {
+ if (qemu_fdt_setprop_string_array
+ (fdt, node, "compatible", s->fdt_compat, s->fdt_compat_count) < 0) {
+ error_setg(errp, "couldn't set %s/compatible", node);
+ return;
+ }
+ }
+
+ if (s->fdt_bootargs) {
+ if (qemu_fdt_setprop_string(fdt, node, "bootargs", s->fdt_bootargs) < 0) {
+ error_setg(errp, "couldn't set %s/bootargs", node);
+ }
+ }
+}
+
static void generic_loader_realize(DeviceState *dev, Error **errp)
{
GenericLoaderState *s = GENERIC_LOADER(dev);
@@ -171,6 +206,10 @@ static void generic_loader_realize(DeviceState *dev, Error **errp)
} else {
s->data = cpu_to_le64(s->data);
}
+
+ if (s->fdt_compat || s->fdt_bootargs) {
+ loader_insert_fdt(s, size, errp);
+ }
}
static void generic_loader_unrealize(DeviceState *dev)
@@ -186,6 +225,9 @@ static Property generic_loader_props[] = {
DEFINE_PROP_UINT32("cpu-num", GenericLoaderState, cpu_num, CPU_NONE),
DEFINE_PROP_BOOL("force-raw", GenericLoaderState, force_raw, false),
DEFINE_PROP_STRING("file", GenericLoaderState, file),
+ DEFINE_PROP_ARRAY("fdt-compat", GenericLoaderState, fdt_compat_count,
+ fdt_compat, qdev_prop_string, char *),
+ DEFINE_PROP_STRING("fdt-bootargs", GenericLoaderState, fdt_bootargs),
DEFINE_PROP_END_OF_LIST(),
};
--
2.20.1
next prev parent reply other threads:[~2020-10-09 17:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-09 17:07 [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot) Alex Bennée
2020-10-09 17:07 ` [RFC PATCH 1/4] hw/board: promote fdt from ARM VirtMachineState to MachineState Alex Bennée
2020-10-09 17:07 ` [RFC PATCH 2/4] hw/riscv: migrate fdt field to generic MachineState Alex Bennée
2020-10-09 17:07 ` [RFC PATCH 3/4] device_tree: add qemu_fdt_setprop_string_array helper Alex Bennée
2020-10-09 17:07 ` Alex Bennée [this message]
2020-10-09 17:24 ` [RFC PATCH 0/4] generic loader FDT support (for direct Xen boot) no-reply
2020-10-09 23:27 ` Alistair Francis
2020-10-12 16:02 ` Alex Bennée
2020-10-12 16:40 ` Peter Maydell
2020-10-12 17:11 ` Alex Bennée
2020-10-12 17:25 ` Edgar E. Iglesias
2020-10-13 10:11 ` Alex Bennée
2020-10-14 19:51 ` Alistair Francis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201009170742.23695-5-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=andre.przywara@arm.com \
--cc=julien@xen.org \
--cc=masami.hiramatsu@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@linaro.org \
--cc=stefano.stabellini@xilinx.com \
--cc=stratos-dev@op-lists.linaro.org \
--cc=takahiro.akashi@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).