* [Qemu-devel] [RFC v1 0/2] Add a generic loader
@ 2016-01-16 0:19 Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 1/2] qdev-monitor.c: Register reset function if the device has one Alistair Francis
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Alistair Francis @ 2016-01-16 0:19 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, crosthwaitepeter, pbonzini, lig.fnst,
alistair.francis
This work is based on the original work by Li Guang with extra
features added by Peter C.
The idea of this loader is to allow the user to load multiple images
or values into QEMU at startup.
Memory values can be loaded like this: -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4
Images can be loaded like this: -device loader,file=./images/u-boot.elf,cpu=0
This can be useful and we use it a lot in Xilinx to load multiple images
into a machine at creation (ATF, Kernel and DTB for example).
It can also be used to set registers.
At the moment only LE ARM is supported. I haven't tested BE support,
so I'm not sure what state it is in. The limiation for arch is based off
settting the ELF_ARCH macro.
The reset patch is required otherwise the reset will never be registered
and the loader can't change the PC in the case of images.
I have tested this on ARM and it works. What do people think? Is it worth
pursuing to try and get accepted?
Alistair Francis (2):
qdev-monitor.c: Register reset function if the device has one
generic-loader: Add a generic loader
default-configs/arm-softmmu.mak | 1 +
hw/misc/Makefile.objs | 2 +
hw/misc/generic-loader.c | 121 +++++++++++++++++++++++++++++++++++++++
include/hw/misc/generic-loader.h | 50 ++++++++++++++++
qdev-monitor.c | 2 +
5 files changed, 176 insertions(+)
create mode 100644 hw/misc/generic-loader.c
create mode 100644 include/hw/misc/generic-loader.h
--
2.5.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [RFC v1 1/2] qdev-monitor.c: Register reset function if the device has one
2016-01-16 0:19 [Qemu-devel] [RFC v1 0/2] Add a generic loader Alistair Francis
@ 2016-01-16 0:19 ` Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 2/2] generic-loader: Add a generic loader Alistair Francis
2016-01-28 20:59 ` [Qemu-devel] [RFC v1 0/2] " Christopher Covington
2 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2016-01-16 0:19 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, crosthwaitepeter, pbonzini, lig.fnst,
alistair.francis
If the device being added when running qdev_device_add() has
a reset function, register it so that it can be called.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
qdev-monitor.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/qdev-monitor.c b/qdev-monitor.c
index 3ce4710..8e43074 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -560,6 +560,8 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
if (bus) {
qdev_set_parent_bus(dev, bus);
+ } else if (dc->reset) {
+ qemu_register_reset((void (*)(void *))dc->reset, dev);
}
id = qemu_opts_id(opts);
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [RFC v1 2/2] generic-loader: Add a generic loader
2016-01-16 0:19 [Qemu-devel] [RFC v1 0/2] Add a generic loader Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 1/2] qdev-monitor.c: Register reset function if the device has one Alistair Francis
@ 2016-01-16 0:19 ` Alistair Francis
2016-01-28 20:59 ` [Qemu-devel] [RFC v1 0/2] " Christopher Covington
2 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2016-01-16 0:19 UTC (permalink / raw)
To: qemu-devel
Cc: peter.maydell, crosthwaitepeter, pbonzini, lig.fnst,
alistair.francis
Add a generic loader to QEMU which can be used to load images or set
memory values.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
default-configs/arm-softmmu.mak | 1 +
hw/misc/Makefile.objs | 2 +
hw/misc/generic-loader.c | 121 +++++++++++++++++++++++++++++++++++++++
include/hw/misc/generic-loader.h | 50 ++++++++++++++++
4 files changed, 174 insertions(+)
create mode 100644 hw/misc/generic-loader.c
create mode 100644 include/hw/misc/generic-loader.h
diff --git a/default-configs/arm-softmmu.mak b/default-configs/arm-softmmu.mak
index d9b90a5..0fd2df7 100644
--- a/default-configs/arm-softmmu.mak
+++ b/default-configs/arm-softmmu.mak
@@ -109,3 +109,4 @@ CONFIG_IOH3420=y
CONFIG_I82801B11=y
CONFIG_ACPI=y
CONFIG_SMBIOS=y
+CONFIG_LOADER=y
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index d4765c2..c006b70 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -44,3 +44,5 @@ obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
obj-$(CONFIG_PVPANIC) += pvpanic.o
obj-$(CONFIG_EDU) += edu.o
obj-$(CONFIG_HYPERV_TESTDEV) += hyperv_testdev.o
+
+obj-$(CONFIG_LOADER) += generic-loader.o
diff --git a/hw/misc/generic-loader.c b/hw/misc/generic-loader.c
new file mode 100644
index 0000000..da53d29
--- /dev/null
+++ b/hw/misc/generic-loader.c
@@ -0,0 +1,121 @@
+/*
+ * Generic Loader
+ *
+ * Copyright (C) 2014 Li Guang
+ * Written by Li Guang <lig.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "hw/sysbus.h"
+#include "sysemu/dma.h"
+#include "hw/loader.h"
+#include "hw/misc/generic-loader.h"
+
+#define CPU_NONE 0xFF
+
+static void generic_loader_reset(DeviceState *dev)
+{
+ GenericLoaderState *s = GENERIC_LOADER(dev);
+
+ if (s->cpu) {
+ CPUClass *cc = CPU_GET_CLASS(s->cpu);
+ cpu_reset(s->cpu);
+ cc->set_pc(s->cpu, s->addr);
+ }
+ /* Probably only works on LE */
+ if (s->data_len) {
+ dma_memory_write((s->cpu ? s->cpu : first_cpu)->as, s->addr, &s->data,
+ s->data_len);
+ }
+}
+
+static void generic_loader_realize(DeviceState *dev, Error **errp)
+{
+ GenericLoaderState *s = GENERIC_LOADER(dev);
+ hwaddr entry;
+ int size = 0;
+
+ if (s->cpu_nr != CPU_NONE) {
+ CPUState *cs = first_cpu;
+ int cpu_num = 0;
+
+ CPU_FOREACH(cs) {
+ if (cpu_num == s->cpu_nr) {
+ s->cpu = cs;
+ break;
+ } else if (!CPU_NEXT(cs)) {
+ error_setg(errp, "Specified boot CPU#%d is non existant",
+ s->cpu_nr);
+ return;
+ } else {
+ cpu_num++;
+ }
+ }
+ }
+
+ /* FIXME: Add BE support */
+ if (s->file) {
+ if (!s->force_raw) {
+ size = load_elf(s->file, NULL, NULL, &entry, NULL, NULL, 0,
+ ELF_ARCH, 0);
+
+ if (size < 0) {
+ size = load_uimage(s->file, &entry, NULL, NULL, NULL, NULL);
+ }
+ }
+
+ if (size < 0) {
+ size = load_image_targphys(s->file, s->addr, 0);
+ } else {
+ s->addr = entry;
+ }
+
+ if (size < 0) {
+ error_setg(errp, "Cannot load specified image %s", s->file);
+ return;
+ }
+ }
+}
+
+static Property generic_loader_props[] = {
+ DEFINE_PROP_UINT64("addr", GenericLoaderState, addr, 0),
+ DEFINE_PROP_UINT64("data", GenericLoaderState, data, 0),
+ DEFINE_PROP_UINT8("data-len", GenericLoaderState, data_len, 0),
+ DEFINE_PROP_UINT8("cpu", GenericLoaderState, cpu_nr, CPU_NONE),
+ DEFINE_PROP_BOOL("force-raw", GenericLoaderState, force_raw, false),
+ DEFINE_PROP_STRING("file", GenericLoaderState, file),
+ DEFINE_PROP_END_OF_LIST(),
+};
+
+static void generic_loader_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ dc->reset = generic_loader_reset;
+ dc->realize = generic_loader_realize;
+ dc->props = generic_loader_props;
+ dc->desc = "Generic Loader";
+}
+
+static TypeInfo generic_loader_info = {
+ .name = TYPE_GENERIC_LOADER,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(GenericLoaderState),
+ .class_init = generic_loader_class_init,
+};
+
+static void generic_loader_register_type(void)
+{
+ type_register_static(&generic_loader_info);
+}
+
+type_init(generic_loader_register_type)
diff --git a/include/hw/misc/generic-loader.h b/include/hw/misc/generic-loader.h
new file mode 100644
index 0000000..79b5536
--- /dev/null
+++ b/include/hw/misc/generic-loader.h
@@ -0,0 +1,50 @@
+/*
+ * Generic Loader
+ *
+ * Copyright (C) 2014 Li Guang
+ * Written by Li Guang <lig.fnst@cn.fujitsu.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef GENERIC_LOADER_H
+#define GENERIC_LOADER_H
+
+#include "elf.h"
+
+#if defined(TARGET_AARCH64)
+ #define ELF_ARCH EM_AARCH64
+#elif defined(TARGET_ARM)
+ #define ELF_ARCH EM_ARM
+#endif
+
+typedef struct GenericLoaderState {
+ /* <private> */
+ DeviceState parent_obj;
+
+ /* <public> */
+ CPUState *cpu;
+
+ uint64_t addr;
+ uint64_t data;
+ uint8_t data_len;
+ uint8_t cpu_nr;
+
+ char *file;
+
+ bool force_raw;
+} GenericLoaderState;
+
+#define TYPE_GENERIC_LOADER "loader"
+#define GENERIC_LOADER(obj) OBJECT_CHECK(GenericLoaderState, (obj), \
+ TYPE_GENERIC_LOADER)
+
+#endif
--
2.5.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [RFC v1 0/2] Add a generic loader
2016-01-16 0:19 [Qemu-devel] [RFC v1 0/2] Add a generic loader Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 1/2] qdev-monitor.c: Register reset function if the device has one Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 2/2] generic-loader: Add a generic loader Alistair Francis
@ 2016-01-28 20:59 ` Christopher Covington
2016-01-28 21:43 ` Alistair Francis
2 siblings, 1 reply; 5+ messages in thread
From: Christopher Covington @ 2016-01-28 20:59 UTC (permalink / raw)
To: Alistair Francis, qemu-devel
Cc: peter.maydell, crosthwaitepeter, lig.fnst, pbonzini
Hi Alistair,
On 01/15/2016 07:19 PM, Alistair Francis wrote:
> This work is based on the original work by Li Guang with extra
> features added by Peter C.
>
> The idea of this loader is to allow the user to load multiple images
> or values into QEMU at startup.
> I have tested this on ARM and it works. What do people think? Is it worth
> pursuing to try and get accepted?
For what it's worth, I think this is worthwhile.
Cov
--
Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [RFC v1 0/2] Add a generic loader
2016-01-28 20:59 ` [Qemu-devel] [RFC v1 0/2] " Christopher Covington
@ 2016-01-28 21:43 ` Alistair Francis
0 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2016-01-28 21:43 UTC (permalink / raw)
To: Christopher Covington
Cc: Peter Maydell, qemu-devel@nongnu.org Developers, Alistair Francis,
Peter Crosthwaite, Paolo Bonzini, lig.fnst
On Thu, Jan 28, 2016 at 12:59 PM, Christopher Covington
<cov@codeaurora.org> wrote:
> Hi Alistair,
>
> On 01/15/2016 07:19 PM, Alistair Francis wrote:
>> This work is based on the original work by Li Guang with extra
>> features added by Peter C.
>>
>> The idea of this loader is to allow the user to load multiple images
>> or values into QEMU at startup.
>
>> I have tested this on ARM and it works. What do people think? Is it worth
>> pursuing to try and get accepted?
>
> For what it's worth, I think this is worthwhile.
Hey Chris,
That is great! Any chance you would mind commenting on the code?
I'm assuming you are looking at ARM targets, which is all that is
supported at the moment.
Thanks,
Alistair
>
> Cov
>
> --
> Qualcomm Innovation Center, Inc.
> Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
> a Linux Foundation Collaborative Project
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-01-28 21:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-16 0:19 [Qemu-devel] [RFC v1 0/2] Add a generic loader Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 1/2] qdev-monitor.c: Register reset function if the device has one Alistair Francis
2016-01-16 0:19 ` [Qemu-devel] [RFC v1 2/2] generic-loader: Add a generic loader Alistair Francis
2016-01-28 20:59 ` [Qemu-devel] [RFC v1 0/2] " Christopher Covington
2016-01-28 21:43 ` Alistair Francis
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).