* [Qemu-devel] [PATCH v9 0/8] Add a generic loader
@ 2016-07-14 0:03 Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch Alistair Francis
` (7 more replies)
0 siblings, 8 replies; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
This work is based on the original work by Li Guang with extra
features added by Peter C and myself.
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.
This patch series makes the load_elf() function more generic by not
requiring an architecture. It also adds new functions load_elf_as(),
load_uimage_as and load_image_targphys_as which allows custom
AddressSpaces when loading images.
V9:
- Logic and documentation corrections
- Add address space loading support for uImages and targphys
V8:
- Allow custom AddressSpaces when loading images
- Move ELF architecture handling code
- Rebase
- Corrections to loading code
- Corrections to documentation
V7:
- Fix typo in comment
- Rebase
V6:
- Add error checking
V5:
- Rebase
V4:
- Re-write documentation
- Allow the loader to work with every architecture
- Move the file to hw/core
- Increase the maximum number of CPUs
- Make the CPU operations conditional
- Convert the cpu option to cpu-num
- Require the user to specify endianess
V2:
- Add an entry to the maintainers file
- Add some documentation
- Perform bounds checking on the data_len
- Register and unregister the reset in the realise/unrealise
Changes since RFC:
- Add support for BE
Alistair Francis (8):
loader: Allow ELF loader to auto-detect the ELF arch
loader: Use the specified MemoryRegion
loader: Allow a custom AddressSpace when loading ROMs
loader: Add AddressSpace loading support to ELFs
loader: Add AddressSpace loading support to uImages
loader: Add AddressSpace loading support to targphys
generic-loader: Add a generic loader
docs: Add a generic loader explanation document
MAINTAINERS | 6 ++
docs/generic-loader.txt | 63 +++++++++++++
hw/core/Makefile.objs | 2 +
hw/core/generic-loader.c | 185 +++++++++++++++++++++++++++++++++++++++
hw/core/loader.c | 85 +++++++++++++-----
include/hw/core/generic-loader.h | 45 ++++++++++
include/hw/elf_ops.h | 10 ++-
include/hw/loader.h | 40 +++++++--
8 files changed, 409 insertions(+), 27 deletions(-)
create mode 100644 docs/generic-loader.txt
create mode 100644 hw/core/generic-loader.c
create mode 100644 include/hw/core/generic-loader.h
--
2.7.4
^ permalink raw reply [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 15:42 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion Alistair Francis
` (6 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
If the caller didn't specify an architecture for the ELF machine
the load_elf() function will auto detect it based on the ELF file.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V9:
- Update documentation
V8:
- Move into load_elf64/load_elf32
V7:
- Fix typo
include/hw/elf_ops.h | 5 +++++
include/hw/loader.h | 3 +++
2 files changed, 8 insertions(+)
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index f510e7e..db70c11 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
glue(bswap_ehdr, SZ)(&ehdr);
}
+ if (elf_machine < 1) {
+ /* The caller didn't specify an ARCH, we can figure it out */
+ elf_machine = ehdr.e_machine;
+ }
+
switch (elf_machine) {
case EM_PPC64:
if (ehdr.e_machine != EM_PPC64) {
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 4879b63..fd540fc 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -68,6 +68,9 @@ const char *load_elf_strerror(int error);
* load will fail if the target ELF does not match. Some architectures
* have some architecture-specific behaviours that come into effect when
* their particular values for @elf_machine are set.
+ * If no @elf_machine is provided the machine will default to the value
+ * in the ELFs header and no checks will be carried out against the
+ * machine type.
*/
int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 17:34 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs Alistair Francis
` (5 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
Prevously the specified MemoryRegion was ignored during the rom register
reset. This patch uses the rom MemoryRegion is avaliable.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
hw/core/loader.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 53e0e41..6b61f29 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -1045,7 +1045,8 @@ int rom_check_and_register_reset(void)
}
addr = rom->addr;
addr += rom->romsize;
- section = memory_region_find(get_system_memory(), rom->addr, 1);
+ section = memory_region_find(rom->mr ? rom->mr : get_system_memory(),
+ rom->addr, 1);
rom->isrom = int128_nz(section.size) && memory_region_is_rom(section.mr);
memory_region_unref(section.mr);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 15:56 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs Alistair Francis
` (4 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
When loading ROMs allow the caller to specify an AddressSpace to use for
the load.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V9:
- Fixup the ROM ordering
- Don't allow address space and memory region to be specified
V8:
- Introduce an RFC version of AddressSpace loading support
hw/core/loader.c | 39 ++++++++++++++++++++++++++++-----------
include/hw/elf_ops.h | 2 +-
include/hw/loader.h | 10 ++++++----
3 files changed, 35 insertions(+), 16 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 6b61f29..a024133 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -777,6 +777,7 @@ struct Rom {
uint8_t *data;
MemoryRegion *mr;
+ AddressSpace *as;
int isrom;
char *fw_dir;
char *fw_file;
@@ -796,12 +797,15 @@ static void rom_insert(Rom *rom)
hw_error ("ROM images must be loaded at startup\n");
}
- /* list is ordered by load address */
+ /* List is ordered by load address in the same address space */
QTAILQ_FOREACH(item, &roms, next) {
- if (rom->addr >= item->addr)
- continue;
- QTAILQ_INSERT_BEFORE(item, rom, next);
- return;
+ if (rom->addr >= item->addr && rom->as == item->as) {
+ QTAILQ_INSERT_AFTER(&roms, item, rom, next);
+ return;
+ } else if (rom->addr <= item->addr && rom->as == item->as) {
+ QTAILQ_INSERT_BEFORE(item, rom, next);
+ return;
+ }
}
QTAILQ_INSERT_TAIL(&roms, rom, next);
}
@@ -833,16 +837,25 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
int rom_add_file(const char *file, const char *fw_dir,
hwaddr addr, int32_t bootindex,
- bool option_rom, MemoryRegion *mr)
+ bool option_rom, MemoryRegion *mr,
+ AddressSpace *as)
{
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
Rom *rom;
int rc, fd = -1;
char devpath[100];
+ if (as && mr) {
+ fprintf(stderr, "Specifying an Address Space and Memory Region is " \
+ "not valid when loading a rom\n");
+ /* We haven't allocated anything so we don't need any cleanup */
+ return -1;
+ }
+
rom = g_malloc0(sizeof(*rom));
rom->name = g_strdup(file);
rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
+ rom->as = as;
if (rom->path == NULL) {
rom->path = g_strdup(file);
}
@@ -969,7 +982,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
* memory ownership of "data", so we don't have to allocate and copy the buffer.
*/
int rom_add_elf_program(const char *name, void *data, size_t datasize,
- size_t romsize, hwaddr addr)
+ size_t romsize, hwaddr addr, AddressSpace *as)
{
Rom *rom;
@@ -979,18 +992,19 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
rom->datasize = datasize;
rom->romsize = romsize;
rom->data = data;
+ rom->as = as;
rom_insert(rom);
return 0;
}
int rom_add_vga(const char *file)
{
- return rom_add_file(file, "vgaroms", 0, -1, true, NULL);
+ return rom_add_file(file, "vgaroms", 0, -1, true, NULL, NULL);
}
int rom_add_option(const char *file, int32_t bootindex)
{
- return rom_add_file(file, "genroms", 0, bootindex, true, NULL);
+ return rom_add_file(file, "genroms", 0, bootindex, true, NULL, NULL);
}
static void rom_reset(void *unused)
@@ -1008,7 +1022,8 @@ static void rom_reset(void *unused)
void *host = memory_region_get_ram_ptr(rom->mr);
memcpy(host, rom->data, rom->datasize);
} else {
- cpu_physical_memory_write_rom(&address_space_memory,
+ cpu_physical_memory_write_rom(rom->as ? rom->as :
+ &address_space_memory,
rom->addr, rom->data, rom->datasize);
}
if (rom->isrom) {
@@ -1031,12 +1046,13 @@ int rom_check_and_register_reset(void)
hwaddr addr = 0;
MemoryRegionSection section;
Rom *rom;
+ AddressSpace *as = NULL;
QTAILQ_FOREACH(rom, &roms, next) {
if (rom->fw_file) {
continue;
}
- if (addr > rom->addr) {
+ if ((addr > rom->addr) && (as == rom->as)) {
fprintf(stderr, "rom: requested regions overlap "
"(rom %s. free=0x" TARGET_FMT_plx
", addr=0x" TARGET_FMT_plx ")\n",
@@ -1049,6 +1065,7 @@ int rom_check_and_register_reset(void)
rom->addr, 1);
rom->isrom = int128_nz(section.size) && memory_region_is_rom(section.mr);
memory_region_unref(section.mr);
+ as = rom->as;
}
qemu_register_reset(rom_reset, NULL);
roms_loaded = 1;
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index db70c11..1339677 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -405,7 +405,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
snprintf(label, sizeof(label), "phdr #%d: %s", i, name);
/* rom_add_elf_program() seize the ownership of 'data' */
- rom_add_elf_program(label, data, file_size, mem_size, addr);
+ rom_add_elf_program(label, data, file_size, mem_size, addr, NULL);
total_size += mem_size;
if (addr < low)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index fd540fc..a701423 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -121,14 +121,14 @@ extern bool rom_file_has_mr;
int rom_add_file(const char *file, const char *fw_dir,
hwaddr addr, int32_t bootindex,
- bool option_rom, MemoryRegion *mr);
+ bool option_rom, MemoryRegion *mr, AddressSpace *as);
MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
size_t max_len, hwaddr addr,
const char *fw_file_name,
FWCfgReadCallback fw_callback,
void *callback_opaque);
int rom_add_elf_program(const char *name, void *data, size_t datasize,
- size_t romsize, hwaddr addr);
+ size_t romsize, hwaddr addr, AddressSpace *as);
int rom_check_and_register_reset(void);
void rom_set_fw(FWCfgState *f);
void rom_set_order_override(int order);
@@ -138,11 +138,13 @@ void *rom_ptr(hwaddr addr);
void hmp_info_roms(Monitor *mon, const QDict *qdict);
#define rom_add_file_fixed(_f, _a, _i) \
- rom_add_file(_f, NULL, _a, _i, false, NULL)
+ rom_add_file(_f, NULL, _a, _i, false, NULL, NULL)
#define rom_add_blob_fixed(_f, _b, _l, _a) \
rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL)
#define rom_add_file_mr(_f, _mr, _i) \
- rom_add_file(_f, NULL, 0, _i, false, _mr)
+ rom_add_file(_f, NULL, 0, _i, false, _mr, NULL)
+#define rom_add_file_as(_f, _as, _i) \
+ rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
#define PC_ROM_MIN_VGA 0xc0000
#define PC_ROM_MIN_OPTION 0xc8000
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
` (2 preceding siblings ...)
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 17:35 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages Alistair Francis
` (3 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
Add a new function load_elf_as() that allows the caller to specify an
AddressSpace to use when loading the ELF. The original load_elf()
function doesn't have any change in functionality.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V8:
- Introduce an RFC version of AddressSpace support
hw/core/loader.c | 16 ++++++++++++++--
include/hw/elf_ops.h | 5 +++--
include/hw/loader.h | 16 +++++++++++++++-
3 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index a024133..0f69894 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -417,6 +417,18 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
uint64_t *highaddr, int big_endian, int elf_machine,
int clear_lsb, int data_swab)
{
+ return load_elf_as(filename, translate_fn, translate_opaque, pentry,
+ lowaddr, highaddr, big_endian, elf_machine, clear_lsb,
+ data_swab, NULL);
+}
+
+/* return < 0 if error, otherwise the number of bytes loaded in memory */
+int load_elf_as(const char *filename,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
+ uint64_t *highaddr, int big_endian, int elf_machine,
+ int clear_lsb, int data_swab, AddressSpace *as)
+{
int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED;
uint8_t e_ident[EI_NIDENT];
@@ -455,11 +467,11 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
if (e_ident[EI_CLASS] == ELFCLASS64) {
ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab,
pentry, lowaddr, highaddr, elf_machine, clear_lsb,
- data_swab);
+ data_swab, as);
} else {
ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab,
pentry, lowaddr, highaddr, elf_machine, clear_lsb,
- data_swab);
+ data_swab, as);
}
fail:
diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
index 1339677..3b8c9e9 100644
--- a/include/hw/elf_ops.h
+++ b/include/hw/elf_ops.h
@@ -263,7 +263,8 @@ static int glue(load_elf, SZ)(const char *name, int fd,
void *translate_opaque,
int must_swab, uint64_t *pentry,
uint64_t *lowaddr, uint64_t *highaddr,
- int elf_machine, int clear_lsb, int data_swab)
+ int elf_machine, int clear_lsb, int data_swab,
+ AddressSpace *as)
{
struct elfhdr ehdr;
struct elf_phdr *phdr = NULL, *ph;
@@ -405,7 +406,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
snprintf(label, sizeof(label), "phdr #%d: %s", i, name);
/* rom_add_elf_program() seize the ownership of 'data' */
- rom_add_elf_program(label, data, file_size, mem_size, addr, NULL);
+ rom_add_elf_program(label, data, file_size, mem_size, addr, as);
total_size += mem_size;
if (addr < low)
diff --git a/include/hw/loader.h b/include/hw/loader.h
index a701423..36a16cc 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -45,7 +45,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
#define ELF_LOAD_WRONG_ENDIAN -4
const char *load_elf_strerror(int error);
-/** load_elf:
+/** load_elf_as:
* @filename: Path of ELF file
* @translate_fn: optional function to translate load addresses
* @translate_opaque: opaque data passed to @translate_fn
@@ -59,6 +59,8 @@ const char *load_elf_strerror(int error);
* @data_swab: Set to order of byte swapping for data. 0 for no swap, 1
* for swapping bytes within halfwords, 2 for bytes within
* words and 3 for within doublewords.
+ * @as: The AddressSpace to load the ELF to. The value of address_space_memory
+ * is used if nothing is supplied here.
*
* Load an ELF file's contents to the emulated system's address space.
* Clients may optionally specify a callback to perform address
@@ -73,6 +75,16 @@ const char *load_elf_strerror(int error);
* machine type.
*/
+int load_elf_as(const char *filename,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
+ uint64_t *highaddr, int big_endian, int elf_machine,
+ int clear_lsb, int data_swab, AddressSpace *as);
+
+/** load_elf:
+ * Same as above, but doesn't allow the caller to specify an AddressSpace
+ */
+
int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
uint64_t *highaddr, int big_endian, int elf_machine,
@@ -141,8 +153,10 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict);
rom_add_file(_f, NULL, _a, _i, false, NULL, NULL)
#define rom_add_blob_fixed(_f, _b, _l, _a) \
rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL)
+
#define rom_add_file_mr(_f, _mr, _i) \
rom_add_file(_f, NULL, 0, _i, false, _mr, NULL)
+
#define rom_add_file_as(_f, _as, _i) \
rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
` (3 preceding siblings ...)
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 17:41 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys Alistair Francis
` (2 subsequent siblings)
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
Add a new function load_uimage_as() that allows the caller to
specify an AddressSpace to use when loading the uImage. The
original load_uimage() function doesn't have any change in
functionality.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
hw/core/loader.c | 17 +++++++++++++----
include/hw/loader.h | 6 ++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 0f69894..861dbc2 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -581,7 +581,7 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src,
static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
int *is_linux, uint8_t image_type,
uint64_t (*translate_fn)(void *, uint64_t),
- void *translate_opaque)
+ void *translate_opaque, AddressSpace *as)
{
int fd;
int size;
@@ -682,7 +682,7 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
hdr->ih_size = bytes;
}
- rom_add_blob_fixed(filename, data, hdr->ih_size, address);
+ rom_add_blob_fixed_as(filename, data, hdr->ih_size, address, as);
ret = hdr->ih_size;
@@ -698,14 +698,23 @@ int load_uimage(const char *filename, hwaddr *ep, hwaddr *loadaddr,
void *translate_opaque)
{
return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL,
- translate_fn, translate_opaque);
+ translate_fn, translate_opaque, NULL);
+}
+
+int load_uimage_as(const char *filename, hwaddr *ep, hwaddr *loadaddr,
+ int *is_linux,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque, AddressSpace *as)
+{
+ return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL,
+ translate_fn, translate_opaque, as);
}
/* Load a ramdisk. */
int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
{
return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK,
- NULL, NULL);
+ NULL, NULL, NULL);
}
/* Load a gzip-compressed kernel to a dynamically allocated buffer. */
diff --git a/include/hw/loader.h b/include/hw/loader.h
index 36a16cc..ede98f6 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -108,6 +108,10 @@ int load_uimage(const char *filename, hwaddr *ep,
hwaddr *loadaddr, int *is_linux,
uint64_t (*translate_fn)(void *, uint64_t),
void *translate_opaque);
+int load_uimage_as(const char *filename, hwaddr *ep,
+ hwaddr *loadaddr, int *is_linux,
+ uint64_t (*translate_fn)(void *, uint64_t),
+ void *translate_opaque, AddressSpace *as);
/**
* load_ramdisk:
@@ -159,6 +163,8 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict);
#define rom_add_file_as(_f, _as, _i) \
rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
+#define rom_add_blob_fixed_as(_f, _b, _l, _a, _as) \
+ rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, _as)
#define PC_ROM_MIN_VGA 0xc0000
#define PC_ROM_MIN_OPTION 0xc8000
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
` (4 preceding siblings ...)
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 17:42 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 7/8] generic-loader: Add a generic loader Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document Alistair Francis
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
Add a new function load_image_targphys_as() that allows the caller
to specify an AddressSpace to use when loading a targphys. The
original load_image_targphys() function doesn't have any change in
functionality.
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
hw/core/loader.c | 10 ++++++++--
include/hw/loader.h | 5 +++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/hw/core/loader.c b/hw/core/loader.c
index 861dbc2..31a2d4a 100644
--- a/hw/core/loader.c
+++ b/hw/core/loader.c
@@ -133,10 +133,16 @@ ssize_t read_targphys(const char *name,
return did;
}
-/* return the size or -1 if error */
int load_image_targphys(const char *filename,
hwaddr addr, uint64_t max_sz)
{
+ return load_image_targphys_as(filename, addr, max_sz, NULL);
+}
+
+/* return the size or -1 if error */
+int load_image_targphys_as(const char *filename,
+ hwaddr addr, uint64_t max_sz, AddressSpace *as)
+{
int size;
size = get_image_size(filename);
@@ -144,7 +150,7 @@ int load_image_targphys(const char *filename,
return -1;
}
if (size > 0) {
- rom_add_file_fixed(filename, addr, -1);
+ rom_add_file_fixed_as(filename, addr, -1, as);
}
return size;
}
diff --git a/include/hw/loader.h b/include/hw/loader.h
index ede98f6..1a9053f 100644
--- a/include/hw/loader.h
+++ b/include/hw/loader.h
@@ -16,6 +16,9 @@ int load_image(const char *filename, uint8_t *addr); /* deprecated */
ssize_t load_image_size(const char *filename, void *addr, size_t size);
int load_image_targphys(const char *filename, hwaddr,
uint64_t max_sz);
+int load_image_targphys_as(const char *filename,
+ hwaddr addr, uint64_t max_sz, AddressSpace *as);
+
/**
* load_image_mr: load an image into a memory region
* @filename: Path to the image file
@@ -163,6 +166,8 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict);
#define rom_add_file_as(_f, _as, _i) \
rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
+#define rom_add_file_fixed_as(_f, _a, _i, _as) \
+ rom_add_file(_f, NULL, _a, _i, false, NULL, _as)
#define rom_add_blob_fixed_as(_f, _b, _l, _a, _as) \
rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, _as)
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 7/8] generic-loader: Add a generic loader
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
` (5 preceding siblings ...)
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document Alistair Francis
7 siblings, 0 replies; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
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>
---
V9:
- Fix error messages
- Updated some incorrect logic
- Add address space loading support for all image types
- Explain why the reset is manually registered
V8:
- Code corrections
- Rebase
V7:
- Rebase
V6:
- Add error checking
V5:
- Rebase
V4:
- Allow the loader to work with every architecture
- Move the file to hw/core
- Increase the maximum number of CPUs
- Make the CPU operations conditional
- Convert the cpu option to cpu-num
- Require the user to specify endianess
V3:
- Pass the ram_size to load_image_targphys()
V2:
- Add maintainers entry
- Perform bounds checking
- Register and unregister the reset in the realise/unrealise
Changes since RFC:
- Add BE support
MAINTAINERS | 6 ++
hw/core/Makefile.objs | 2 +
hw/core/generic-loader.c | 185 +++++++++++++++++++++++++++++++++++++++
include/hw/core/generic-loader.h | 45 ++++++++++
4 files changed, 238 insertions(+)
create mode 100644 hw/core/generic-loader.c
create mode 100644 include/hw/core/generic-loader.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 1d0e2c3..ea3a3b5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -993,6 +993,12 @@ M: Dmitry Fleytman <dmitry@daynix.com>
S: Maintained
F: hw/net/e1000e*
+Generic Loader
+M: Alistair Francis <alistair.francis@xilinx.com>
+S: Maintained
+F: hw/core/generic-loader.c
+F: include/hw/core/generic-loader.h
+
Subsystems
----------
Audio
diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs
index cfd4840..939c94e 100644
--- a/hw/core/Makefile.objs
+++ b/hw/core/Makefile.objs
@@ -17,3 +17,5 @@ common-obj-$(CONFIG_SOFTMMU) += loader.o
common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o
common-obj-$(CONFIG_SOFTMMU) += register.o
common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o
+
+obj-$(CONFIG_SOFTMMU) += generic-loader.o
diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c
new file mode 100644
index 0000000..3fbb954
--- /dev/null
+++ b/hw/core/generic-loader.c
@@ -0,0 +1,185 @@
+/*
+ * Generic Loader
+ *
+ * Copyright (C) 2014 Li Guang
+ * Copyright (C) 2016 Xilinx Inc.
+ * 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 "qemu/osdep.h"
+#include "qom/cpu.h"
+#include "hw/sysbus.h"
+#include "sysemu/dma.h"
+#include "hw/loader.h"
+#include "qapi/error.h"
+#include "hw/core/generic-loader.h"
+
+#define CPU_NONE 0xFFFFFFFF
+
+static void generic_loader_reset(void *opaque)
+{
+ GenericLoaderState *s = GENERIC_LOADER(opaque);
+
+ if (s->cpu) {
+ CPUClass *cc = CPU_GET_CLASS(s->cpu);
+ cpu_reset(s->cpu);
+ if (cc) {
+ cc->set_pc(s->cpu, s->addr);
+ }
+ }
+
+ if (s->data_len) {
+ assert(s->data_len < sizeof(s->data));
+ dma_memory_write(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 big_endian;
+ int size = 0;
+
+ /* Perform some error checking on the user's options */
+ if (s->data || s->data_len || s->data_be) {
+ /* User is loading memory values */
+ if (s->file) {
+ error_setg(errp, "Specifying a file is not supported when loading "
+ "memory values");
+ return;
+ } else if (s->force_raw) {
+ error_setg(errp, "Specifying force-raw is not supported when "
+ "loading memory values");
+ return;
+ } else if (!s->data || !s->data_len) {
+ error_setg(errp, "Both data and data-len must be specified");
+ return;
+ } else if (s->cpu_num != CPU_NONE) {
+ error_setg(errp, "Setting data and cpu-num is not supported");
+ return;
+ }
+ } else if (s->file || s->force_raw) {
+ /* User is loading an image */
+ if (s->data || s->data_len || s->data_be) {
+ error_setg(errp, "data can not be specified when loading an "
+ "image");
+ return;
+ }
+ } else if (s->data_len) {
+ if (s->data_len > 8) {
+ error_setg(errp, "data-len cannot be greater then 8 bytes");
+ return;
+ } else if (s->data_len > sizeof(s->data)) {
+ error_setg(errp, "data-len cannot be more then the data size");
+ return;
+ }
+ }
+
+ qemu_register_reset(generic_loader_reset, dev);
+
+ if (s->cpu_num != CPU_NONE) {
+ s->cpu = qemu_get_cpu(s->cpu_num);
+ if (!s->cpu) {
+ error_setg(errp, "Specified boot CPU#%d is nonexistent",
+ s->cpu_num);
+ return;
+ }
+ }
+
+#ifdef TARGET_WORDS_BIGENDIAN
+ big_endian = 1;
+#else
+ big_endian = 0;
+#endif
+
+ if (s->file) {
+ if (!s->force_raw) {
+ size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL,
+ big_endian, 0, 0, 0,
+ (s->cpu ? s->cpu : first_cpu)->as);
+
+ if (size < 0) {
+ size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL,
+ (s->cpu ? s->cpu : first_cpu)->as);
+ }
+ }
+
+ if (size < 0 || s->force_raw) {
+ /* Default to the maximum size being the machine's ram size */
+ size = load_image_targphys_as(s->file, s->addr, ram_size,
+ (s->cpu ? s->cpu : first_cpu)->as);
+ } else {
+ s->addr = entry;
+ }
+
+ if (size < 0) {
+ error_setg(errp, "Cannot load specified image %s", s->file);
+ return;
+ }
+ }
+
+ /* Convert the data endiannes */
+ if (s->data_be) {
+ s->data = cpu_to_be64(s->data);
+ } else {
+ s->data = cpu_to_le64(s->data);
+ }
+}
+
+static void generic_loader_unrealize(DeviceState *dev, Error **errp)
+{
+ qemu_unregister_reset(generic_loader_reset, dev);
+}
+
+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_BOOL("data-be", GenericLoaderState, data_be, false),
+ 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_END_OF_LIST(),
+};
+
+static void generic_loader_class_init(ObjectClass *klass, void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+
+ /* The reset function is not registered here and is instead registered in
+ * the realize function to allow this device to be added via the device_add
+ * command in the QEMU monitor.
+ * TODO: Improve the device_add functionality to allow resets to be
+ * connected
+ */
+ dc->realize = generic_loader_realize;
+ dc->unrealize = generic_loader_unrealize;
+ 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/core/generic-loader.h b/include/hw/core/generic-loader.h
new file mode 100644
index 0000000..4dd2361
--- /dev/null
+++ b/include/hw/core/generic-loader.h
@@ -0,0 +1,45 @@
+/*
+ * 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"
+
+typedef struct GenericLoaderState {
+ /* <private> */
+ DeviceState parent_obj;
+
+ /* <public> */
+ CPUState *cpu;
+
+ uint64_t addr;
+ uint64_t data;
+ uint8_t data_len;
+ uint32_t cpu_num;
+
+ char *file;
+
+ bool force_raw;
+ bool data_be;
+} GenericLoaderState;
+
+#define TYPE_GENERIC_LOADER "loader"
+#define GENERIC_LOADER(obj) OBJECT_CHECK(GenericLoaderState, (obj), \
+ TYPE_GENERIC_LOADER)
+
+#endif
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
` (6 preceding siblings ...)
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 7/8] generic-loader: Add a generic loader Alistair Francis
@ 2016-07-14 0:03 ` Alistair Francis
2016-07-29 17:55 ` Peter Maydell
7 siblings, 1 reply; 20+ messages in thread
From: Alistair Francis @ 2016-07-14 0:03 UTC (permalink / raw)
To: qemu-devel, peter.maydell
Cc: alistair.francis, crosthwaitepeter, armbru, cov, pbonzini
Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
---
V9:
- Clarify the image loading options
V8:
- Improve documentation
V6:
- Fixup documentation
V4:
- Re-write to be more comprehensive
docs/generic-loader.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 63 insertions(+)
create mode 100644 docs/generic-loader.txt
diff --git a/docs/generic-loader.txt b/docs/generic-loader.txt
new file mode 100644
index 0000000..16c11ee
--- /dev/null
+++ b/docs/generic-loader.txt
@@ -0,0 +1,63 @@
+Copyright (c) 2016 Xilinx Inc.
+
+This work is licensed under the terms of the GNU GPL, version 2 or later. See
+the COPYING file in the top-level directory.
+
+
+The 'loader' device allows the user to load multiple images or values into
+QEMU at startup.
+
+Loading Memory Values
+---------------------
+The loader device allows memory values to be set from the command line. This
+can be done by following the syntax below:
+
+ -device loader,addr=<addr>,data=<data>,data-len=<len>
+ -device loader,addr=<addr>,cpu-num=<cpu-num>
+
+ <addr> - The address to store the data or the value to use as the
+ CPU's PC.
+ <data> - The value to be written to the address. The maximum size of
+ the data is 8 bytes.
+ <data-len> - The length of the data in bytes. This argument must be
+ included if the data argument is.
+ <data-be> - Set to true if the data to be stored on the guest should be
+ written as big endian data. The default is to write little
+ endian data.
+ <cpu-num> - This will cause the CPU to be reset and the PC to be set to
+ the value of addr.
+
+For all values both hex and decimal values are allowed. By default the values
+will be parsed as decimal. To use hex values the user should prefix the number
+with a '0x'.
+
+An example of loading value 0x8000000e to address 0xfd1a0104 is:
+ -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4
+
+Loading Files
+-------------
+The loader device also allows files to be loaded into memory. This can be done
+similarly to setting memory values. The syntax is shown below:
+
+ -device loader,file=<file>,addr=<addr>,cpu-num=<cpu-num>,force-raw=<raw>
+
+ <file> - A file to be loaded into memory
+ <addr> - The addr in memory that the file should be loaded. This is
+ ignored if you are using an ELF (unless force-raw is true).
+ This is required if you aren't loading an ELF.
+ <cpu-num> - This specifies the CPU that should be used. This is an
+ optional argument and will cause the CPU's PC to be set to
+ where the image is stored or in the case of an ELF file to
+ the value in the header. This option should only be used
+ for the boot image.
+ This will also cause the image to be written to the specified
+ CPUs address space.
+ <force-raw> - Forces the file to be treated as a raw image. This can be
+ used to specify the load address of ELF files.
+
+For all values both hex and decimal values are allowed. By default the values
+will be parsed as decimal. To use hex values the user should prefix the number
+with a '0x'.
+
+An example of loading an ELF file which CPU0 will boot is shown below:
+ -device loader,file=./images/boot.elf,cpu-num=0
--
2.7.4
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch Alistair Francis
@ 2016-07-29 15:42 ` Peter Maydell
2016-08-02 0:03 ` Alistair Francis
0 siblings, 1 reply; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 15:42 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> If the caller didn't specify an architecture for the ELF machine
> the load_elf() function will auto detect it based on the ELF file.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V9:
> - Update documentation
> V8:
> - Move into load_elf64/load_elf32
> V7:
> - Fix typo
>
> include/hw/elf_ops.h | 5 +++++
> include/hw/loader.h | 3 +++
> 2 files changed, 8 insertions(+)
>
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index f510e7e..db70c11 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
> glue(bswap_ehdr, SZ)(&ehdr);
> }
>
> + if (elf_machine < 1) {
> + /* The caller didn't specify an ARCH, we can figure it out */
> + elf_machine = ehdr.e_machine;
> + }
> +
> switch (elf_machine) {
> case EM_PPC64:
> if (ehdr.e_machine != EM_PPC64) {
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index 4879b63..fd540fc 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -68,6 +68,9 @@ const char *load_elf_strerror(int error);
> * load will fail if the target ELF does not match. Some architectures
> * have some architecture-specific behaviours that come into effect when
> * their particular values for @elf_machine are set.
> + * If no @elf_machine is provided the machine will default to the value
> + * in the ELFs header and no checks will be carried out against the
> + * machine type.
> */
The argument is mandatory, you can't not provide it.
Should we make this "if @elf_machine is EM_NONE then the
machine type will be read from the ELF header" ? (EM_NONE is 0).
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs Alistair Francis
@ 2016-07-29 15:56 ` Peter Maydell
2016-08-02 22:59 ` Alistair Francis
0 siblings, 1 reply; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 15:56 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> When loading ROMs allow the caller to specify an AddressSpace to use for
> the load.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V9:
> - Fixup the ROM ordering
> - Don't allow address space and memory region to be specified
> V8:
> - Introduce an RFC version of AddressSpace loading support
>
> hw/core/loader.c | 39 ++++++++++++++++++++++++++++-----------
> include/hw/elf_ops.h | 2 +-
> include/hw/loader.h | 10 ++++++----
> 3 files changed, 35 insertions(+), 16 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 6b61f29..a024133 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -777,6 +777,7 @@ struct Rom {
>
> uint8_t *data;
> MemoryRegion *mr;
> + AddressSpace *as;
> int isrom;
> char *fw_dir;
> char *fw_file;
> @@ -796,12 +797,15 @@ static void rom_insert(Rom *rom)
> hw_error ("ROM images must be loaded at startup\n");
> }
>
> - /* list is ordered by load address */
> + /* List is ordered by load address in the same address space */
> QTAILQ_FOREACH(item, &roms, next) {
> - if (rom->addr >= item->addr)
> - continue;
> - QTAILQ_INSERT_BEFORE(item, rom, next);
> - return;
> + if (rom->addr >= item->addr && rom->as == item->as) {
> + QTAILQ_INSERT_AFTER(&roms, item, rom, next);
> + return;
> + } else if (rom->addr <= item->addr && rom->as == item->as) {
> + QTAILQ_INSERT_BEFORE(item, rom, next);
> + return;
> + }
> }
> QTAILQ_INSERT_TAIL(&roms, rom, next);
This seems a somewhat confusing way of writing this. I think you
should define a comparison function and then just replace the
current "rom->addr >= item->addr" with "rom_order_compare(rom, item) >= 0".
Then it's clear what the comparison you're using to define the
sorted order is and that the loop will put things in in sorted
position.
> }
> @@ -833,16 +837,25 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
>
> int rom_add_file(const char *file, const char *fw_dir,
> hwaddr addr, int32_t bootindex,
> - bool option_rom, MemoryRegion *mr)
> + bool option_rom, MemoryRegion *mr,
> + AddressSpace *as)
> {
> MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
> Rom *rom;
> int rc, fd = -1;
> char devpath[100];
>
> + if (as && mr) {
> + fprintf(stderr, "Specifying an Address Space and Memory Region is " \
> + "not valid when loading a rom\n");
Some day we'll fix this up to use Errors, but that day need not be today.
> + /* We haven't allocated anything so we don't need any cleanup */
> + return -1;
> + }
> +
> rom = g_malloc0(sizeof(*rom));
> rom->name = g_strdup(file);
> rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
> + rom->as = as;
> if (rom->path == NULL) {
> rom->path = g_strdup(file);
> }
> @@ -969,7 +982,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
> * memory ownership of "data", so we don't have to allocate and copy the buffer.
> */
> int rom_add_elf_program(const char *name, void *data, size_t datasize,
> - size_t romsize, hwaddr addr)
> + size_t romsize, hwaddr addr, AddressSpace *as)
> {
> Rom *rom;
>
> @@ -979,18 +992,19 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
> rom->datasize = datasize;
> rom->romsize = romsize;
> rom->data = data;
> + rom->as = as;
> rom_insert(rom);
> return 0;
> }
>
> int rom_add_vga(const char *file)
> {
> - return rom_add_file(file, "vgaroms", 0, -1, true, NULL);
> + return rom_add_file(file, "vgaroms", 0, -1, true, NULL, NULL);
> }
>
> int rom_add_option(const char *file, int32_t bootindex)
> {
> - return rom_add_file(file, "genroms", 0, bootindex, true, NULL);
> + return rom_add_file(file, "genroms", 0, bootindex, true, NULL, NULL);
> }
>
> static void rom_reset(void *unused)
> @@ -1008,7 +1022,8 @@ static void rom_reset(void *unused)
> void *host = memory_region_get_ram_ptr(rom->mr);
> memcpy(host, rom->data, rom->datasize);
> } else {
> - cpu_physical_memory_write_rom(&address_space_memory,
> + cpu_physical_memory_write_rom(rom->as ? rom->as :
> + &address_space_memory,
Should we just make rom->as be &address_space_memory if the caller
doesn't provide one rather than having it be NULL and then special
casing what NULL means? (This will also avoid potentially odd
effects with some of the ROMs in the list having &address_space_memory
for an explicitly specified AS and some having NULL for the same
AS but implicitly specified, which is otherwise a pain to deal with
in comparisons.)
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion Alistair Francis
@ 2016-07-29 17:34 ` Peter Maydell
0 siblings, 0 replies; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 17:34 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Prevously the specified MemoryRegion was ignored during the rom register
> reset. This patch uses the rom MemoryRegion is avaliable.
"if available"
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs Alistair Francis
@ 2016-07-29 17:35 ` Peter Maydell
0 siblings, 0 replies; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 17:35 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Add a new function load_elf_as() that allows the caller to specify an
> AddressSpace to use when loading the ELF. The original load_elf()
> function doesn't have any change in functionality.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V8:
> - Introduce an RFC version of AddressSpace support
>
> hw/core/loader.c | 16 ++++++++++++++--
> include/hw/elf_ops.h | 5 +++--
> include/hw/loader.h | 16 +++++++++++++++-
> 3 files changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index a024133..0f69894 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -417,6 +417,18 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
> uint64_t *highaddr, int big_endian, int elf_machine,
> int clear_lsb, int data_swab)
> {
> + return load_elf_as(filename, translate_fn, translate_opaque, pentry,
> + lowaddr, highaddr, big_endian, elf_machine, clear_lsb,
> + data_swab, NULL);
> +}
> +
> +/* return < 0 if error, otherwise the number of bytes loaded in memory */
> +int load_elf_as(const char *filename,
> + uint64_t (*translate_fn)(void *, uint64_t),
> + void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
> + uint64_t *highaddr, int big_endian, int elf_machine,
> + int clear_lsb, int data_swab, AddressSpace *as)
> +{
> int fd, data_order, target_data_order, must_swab, ret = ELF_LOAD_FAILED;
> uint8_t e_ident[EI_NIDENT];
>
> @@ -455,11 +467,11 @@ int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
> if (e_ident[EI_CLASS] == ELFCLASS64) {
> ret = load_elf64(filename, fd, translate_fn, translate_opaque, must_swab,
> pentry, lowaddr, highaddr, elf_machine, clear_lsb,
> - data_swab);
> + data_swab, as);
> } else {
> ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab,
> pentry, lowaddr, highaddr, elf_machine, clear_lsb,
> - data_swab);
> + data_swab, as);
> }
>
> fail:
> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
> index 1339677..3b8c9e9 100644
> --- a/include/hw/elf_ops.h
> +++ b/include/hw/elf_ops.h
> @@ -263,7 +263,8 @@ static int glue(load_elf, SZ)(const char *name, int fd,
> void *translate_opaque,
> int must_swab, uint64_t *pentry,
> uint64_t *lowaddr, uint64_t *highaddr,
> - int elf_machine, int clear_lsb, int data_swab)
> + int elf_machine, int clear_lsb, int data_swab,
> + AddressSpace *as)
> {
> struct elfhdr ehdr;
> struct elf_phdr *phdr = NULL, *ph;
> @@ -405,7 +406,7 @@ static int glue(load_elf, SZ)(const char *name, int fd,
> snprintf(label, sizeof(label), "phdr #%d: %s", i, name);
>
> /* rom_add_elf_program() seize the ownership of 'data' */
> - rom_add_elf_program(label, data, file_size, mem_size, addr, NULL);
> + rom_add_elf_program(label, data, file_size, mem_size, addr, as);
>
> total_size += mem_size;
> if (addr < low)
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index a701423..36a16cc 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -45,7 +45,7 @@ int load_image_gzipped(const char *filename, hwaddr addr, uint64_t max_sz);
> #define ELF_LOAD_WRONG_ENDIAN -4
> const char *load_elf_strerror(int error);
>
> -/** load_elf:
> +/** load_elf_as:
> * @filename: Path of ELF file
> * @translate_fn: optional function to translate load addresses
> * @translate_opaque: opaque data passed to @translate_fn
> @@ -59,6 +59,8 @@ const char *load_elf_strerror(int error);
> * @data_swab: Set to order of byte swapping for data. 0 for no swap, 1
> * for swapping bytes within halfwords, 2 for bytes within
> * words and 3 for within doublewords.
> + * @as: The AddressSpace to load the ELF to. The value of address_space_memory
> + * is used if nothing is supplied here.
"if @as is NULL".
> *
> * Load an ELF file's contents to the emulated system's address space.
> * Clients may optionally specify a callback to perform address
> @@ -73,6 +75,16 @@ const char *load_elf_strerror(int error);
> * machine type.
> */
>
> +int load_elf_as(const char *filename,
> + uint64_t (*translate_fn)(void *, uint64_t),
> + void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
> + uint64_t *highaddr, int big_endian, int elf_machine,
> + int clear_lsb, int data_swab, AddressSpace *as);
> +
> +/** load_elf:
> + * Same as above, but doesn't allow the caller to specify an AddressSpace
"Same as load_elf_as()", just in case things get shuffled around
in the file later.
> + */
> +
> int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),
> void *translate_opaque, uint64_t *pentry, uint64_t *lowaddr,
> uint64_t *highaddr, int big_endian, int elf_machine,
> @@ -141,8 +153,10 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict);
> rom_add_file(_f, NULL, _a, _i, false, NULL, NULL)
> #define rom_add_blob_fixed(_f, _b, _l, _a) \
> rom_add_blob(_f, _b, _l, _l, _a, NULL, NULL, NULL)
> +
> #define rom_add_file_mr(_f, _mr, _i) \
> rom_add_file(_f, NULL, 0, _i, false, _mr, NULL)
> +
> #define rom_add_file_as(_f, _as, _i) \
> rom_add_file(_f, NULL, 0, _i, false, NULL, _as)
Random whitespace changes.
Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages Alistair Francis
@ 2016-07-29 17:41 ` Peter Maydell
0 siblings, 0 replies; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 17:41 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Add a new function load_uimage_as() that allows the caller to
> specify an AddressSpace to use when loading the uImage. The
> original load_uimage() function doesn't have any change in
> functionality.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
>
> hw/core/loader.c | 17 +++++++++++++----
> include/hw/loader.h | 6 ++++++
> 2 files changed, 19 insertions(+), 4 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 0f69894..861dbc2 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -581,7 +581,7 @@ static ssize_t gunzip(void *dst, size_t dstlen, uint8_t *src,
> static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
> int *is_linux, uint8_t image_type,
> uint64_t (*translate_fn)(void *, uint64_t),
> - void *translate_opaque)
> + void *translate_opaque, AddressSpace *as)
> {
> int fd;
> int size;
> @@ -682,7 +682,7 @@ static int load_uboot_image(const char *filename, hwaddr *ep, hwaddr *loadaddr,
> hdr->ih_size = bytes;
> }
>
> - rom_add_blob_fixed(filename, data, hdr->ih_size, address);
> + rom_add_blob_fixed_as(filename, data, hdr->ih_size, address, as);
>
> ret = hdr->ih_size;
>
> @@ -698,14 +698,23 @@ int load_uimage(const char *filename, hwaddr *ep, hwaddr *loadaddr,
> void *translate_opaque)
> {
> return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL,
> - translate_fn, translate_opaque);
> + translate_fn, translate_opaque, NULL);
> +}
> +
> +int load_uimage_as(const char *filename, hwaddr *ep, hwaddr *loadaddr,
> + int *is_linux,
> + uint64_t (*translate_fn)(void *, uint64_t),
> + void *translate_opaque, AddressSpace *as)
> +{
> + return load_uboot_image(filename, ep, loadaddr, is_linux, IH_TYPE_KERNEL,
> + translate_fn, translate_opaque, as);
> }
>
> /* Load a ramdisk. */
> int load_ramdisk(const char *filename, hwaddr addr, uint64_t max_sz)
> {
> return load_uboot_image(filename, NULL, &addr, NULL, IH_TYPE_RAMDISK,
> - NULL, NULL);
> + NULL, NULL, NULL);
> }
>
> /* Load a gzip-compressed kernel to a dynamically allocated buffer. */
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index 36a16cc..ede98f6 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -108,6 +108,10 @@ int load_uimage(const char *filename, hwaddr *ep,
> hwaddr *loadaddr, int *is_linux,
> uint64_t (*translate_fn)(void *, uint64_t),
> void *translate_opaque);
> +int load_uimage_as(const char *filename, hwaddr *ep,
> + hwaddr *loadaddr, int *is_linux,
> + uint64_t (*translate_fn)(void *, uint64_t),
> + void *translate_opaque, AddressSpace *as);
The code changes are good, but could we have a doc comment for
this new function, please?
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys Alistair Francis
@ 2016-07-29 17:42 ` Peter Maydell
2016-08-02 21:21 ` Alistair Francis
0 siblings, 1 reply; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 17:42 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Add a new function load_image_targphys_as() that allows the caller
> to specify an AddressSpace to use when loading a targphys. The
> original load_image_targphys() function doesn't have any change in
> functionality.
>
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
>
> hw/core/loader.c | 10 ++++++++--
> include/hw/loader.h | 5 +++++
> 2 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/hw/core/loader.c b/hw/core/loader.c
> index 861dbc2..31a2d4a 100644
> --- a/hw/core/loader.c
> +++ b/hw/core/loader.c
> @@ -133,10 +133,16 @@ ssize_t read_targphys(const char *name,
> return did;
> }
>
> -/* return the size or -1 if error */
> int load_image_targphys(const char *filename,
> hwaddr addr, uint64_t max_sz)
> {
> + return load_image_targphys_as(filename, addr, max_sz, NULL);
> +}
> +
> +/* return the size or -1 if error */
> +int load_image_targphys_as(const char *filename,
> + hwaddr addr, uint64_t max_sz, AddressSpace *as)
> +{
> int size;
>
> size = get_image_size(filename);
> @@ -144,7 +150,7 @@ int load_image_targphys(const char *filename,
> return -1;
> }
> if (size > 0) {
> - rom_add_file_fixed(filename, addr, -1);
> + rom_add_file_fixed_as(filename, addr, -1, as);
> }
> return size;
> }
> diff --git a/include/hw/loader.h b/include/hw/loader.h
> index ede98f6..1a9053f 100644
> --- a/include/hw/loader.h
> +++ b/include/hw/loader.h
> @@ -16,6 +16,9 @@ int load_image(const char *filename, uint8_t *addr); /* deprecated */
> ssize_t load_image_size(const char *filename, void *addr, size_t size);
> int load_image_targphys(const char *filename, hwaddr,
> uint64_t max_sz);
> +int load_image_targphys_as(const char *filename,
> + hwaddr addr, uint64_t max_sz, AddressSpace *as);
> +
Again, code changes are fine but could we have a doc comment?
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document Alistair Francis
@ 2016-07-29 17:55 ` Peter Maydell
2016-08-03 18:22 ` Alistair Francis
0 siblings, 1 reply; 20+ messages in thread
From: Peter Maydell @ 2016-07-29 17:55 UTC (permalink / raw)
To: Alistair Francis
Cc: QEMU Developers, Peter Crosthwaite, Markus Armbruster,
Christopher Covington, Paolo Bonzini
On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
> ---
> V9:
> - Clarify the image loading options
> V8:
> - Improve documentation
> V6:
> - Fixup documentation
> V4:
> - Re-write to be more comprehensive
>
> docs/generic-loader.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 63 insertions(+)
> create mode 100644 docs/generic-loader.txt
>
> diff --git a/docs/generic-loader.txt b/docs/generic-loader.txt
> new file mode 100644
> index 0000000..16c11ee
> --- /dev/null
> +++ b/docs/generic-loader.txt
> @@ -0,0 +1,63 @@
> +Copyright (c) 2016 Xilinx Inc.
> +
> +This work is licensed under the terms of the GNU GPL, version 2 or later. See
> +the COPYING file in the top-level directory.
> +
> +
> +The 'loader' device allows the user to load multiple images or values into
> +QEMU at startup.
> +
> +Loading Memory Values
> +---------------------
> +The loader device allows memory values to be set from the command line. This
> +can be done by following the syntax below:
> +
> + -device loader,addr=<addr>,data=<data>,data-len=<len>
> + -device loader,addr=<addr>,cpu-num=<cpu-num>
> +
> + <addr> - The address to store the data or the value to use as the
> + CPU's PC.
> + <data> - The value to be written to the address. The maximum size of
> + the data is 8 bytes.
> + <data-len> - The length of the data in bytes. This argument must be
> + included if the data argument is.
> + <data-be> - Set to true if the data to be stored on the guest should be
> + written as big endian data. The default is to write little
> + endian data.
> + <cpu-num> - This will cause the CPU to be reset and the PC to be set to
> + the value of addr.
> +
> +For all values both hex and decimal values are allowed. By default the values
> +will be parsed as decimal. To use hex values the user should prefix the number
> +with a '0x'.
> +
> +An example of loading value 0x8000000e to address 0xfd1a0104 is:
> + -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4
> +
> +Loading Files
> +-------------
> +The loader device also allows files to be loaded into memory. This can be done
> +similarly to setting memory values. The syntax is shown below:
> +
> + -device loader,file=<file>,addr=<addr>,cpu-num=<cpu-num>,force-raw=<raw>
> +
> + <file> - A file to be loaded into memory
> + <addr> - The addr in memory that the file should be loaded. This is
> + ignored if you are using an ELF (unless force-raw is true).
> + This is required if you aren't loading an ELF.
> + <cpu-num> - This specifies the CPU that should be used. This is an
> + optional argument and will cause the CPU's PC to be set to
> + where the image is stored or in the case of an ELF file to
> + the value in the header. This option should only be used
> + for the boot image.
> + This will also cause the image to be written to the specified
> + CPUs address space.
> + <force-raw> - Forces the file to be treated as a raw image. This can be
> + used to specify the load address of ELF files.
> +
> +For all values both hex and decimal values are allowed. By default the values
> +will be parsed as decimal. To use hex values the user should prefix the number
> +with a '0x'.
> +
> +An example of loading an ELF file which CPU0 will boot is shown below:
> + -device loader,file=./images/boot.elf,cpu-num=0
With this interface, you can specify a file to be loaded to CPU 2's
address space (via file=whatever,cpu-num=2) but you can't specify
a data value to be loaded to CPU 2's address space (because
addr=a,data=x,data-len=y,cpu-num=2 isn't valid). I think we could
usefully make that syntax do that.
This is probably most clearly documented by completely splitting
-device loader,addr=<addr>,cpu-num=<cpu-num>
(set the PC)
from
-device loader,addr=<addr>,data=<data>,data-len=<data-len>[,data-be=<data-be>][,cpu-num=<cpu-num>]
(load raw data values)
in the documentation in the same way that loader,file is split.
(I have a feeling we've been circling around on this option syntax
over the last few revisions so apologies if I've been inconsistent.)
You also can't specify a file to be loaded which doesn't set the
CPU PC, but I'm not sure how important that is. We can always add
it later with a no-set-pc option flag if we need it I guess.
thanks
-- PMM
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch
2016-07-29 15:42 ` Peter Maydell
@ 2016-08-02 0:03 ` Alistair Francis
0 siblings, 0 replies; 20+ messages in thread
From: Alistair Francis @ 2016-08-02 0:03 UTC (permalink / raw)
To: Peter Maydell
Cc: Alistair Francis, Christopher Covington, Peter Crosthwaite,
Paolo Bonzini, QEMU Developers, Markus Armbruster
On Fri, Jul 29, 2016 at 8:42 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> If the caller didn't specify an architecture for the ELF machine
>> the load_elf() function will auto detect it based on the ELF file.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>> V9:
>> - Update documentation
>> V8:
>> - Move into load_elf64/load_elf32
>> V7:
>> - Fix typo
>>
>> include/hw/elf_ops.h | 5 +++++
>> include/hw/loader.h | 3 +++
>> 2 files changed, 8 insertions(+)
>>
>> diff --git a/include/hw/elf_ops.h b/include/hw/elf_ops.h
>> index f510e7e..db70c11 100644
>> --- a/include/hw/elf_ops.h
>> +++ b/include/hw/elf_ops.h
>> @@ -280,6 +280,11 @@ static int glue(load_elf, SZ)(const char *name, int fd,
>> glue(bswap_ehdr, SZ)(&ehdr);
>> }
>>
>> + if (elf_machine < 1) {
>> + /* The caller didn't specify an ARCH, we can figure it out */
>> + elf_machine = ehdr.e_machine;
>> + }
>> +
>> switch (elf_machine) {
>> case EM_PPC64:
>> if (ehdr.e_machine != EM_PPC64) {
>> diff --git a/include/hw/loader.h b/include/hw/loader.h
>> index 4879b63..fd540fc 100644
>> --- a/include/hw/loader.h
>> +++ b/include/hw/loader.h
>> @@ -68,6 +68,9 @@ const char *load_elf_strerror(int error);
>> * load will fail if the target ELF does not match. Some architectures
>> * have some architecture-specific behaviours that come into effect when
>> * their particular values for @elf_machine are set.
>> + * If no @elf_machine is provided the machine will default to the value
>> + * in the ELFs header and no checks will be carried out against the
>> + * machine type.
>> */
>
> The argument is mandatory, you can't not provide it.
> Should we make this "if @elf_machine is EM_NONE then the
> machine type will be read from the ELF header" ? (EM_NONE is 0).
Good point, fixed.
Thanks,
Alistair
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys
2016-07-29 17:42 ` Peter Maydell
@ 2016-08-02 21:21 ` Alistair Francis
0 siblings, 0 replies; 20+ messages in thread
From: Alistair Francis @ 2016-08-02 21:21 UTC (permalink / raw)
To: Peter Maydell
Cc: Alistair Francis, Christopher Covington, Peter Crosthwaite,
Paolo Bonzini, QEMU Developers, Markus Armbruster
On Fri, Jul 29, 2016 at 10:42 AM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> Add a new function load_image_targphys_as() that allows the caller
>> to specify an AddressSpace to use when loading a targphys. The
>> original load_image_targphys() function doesn't have any change in
>> functionality.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>>
>> hw/core/loader.c | 10 ++++++++--
>> include/hw/loader.h | 5 +++++
>> 2 files changed, 13 insertions(+), 2 deletions(-)
>>
>> diff --git a/hw/core/loader.c b/hw/core/loader.c
>> index 861dbc2..31a2d4a 100644
>> --- a/hw/core/loader.c
>> +++ b/hw/core/loader.c
>> @@ -133,10 +133,16 @@ ssize_t read_targphys(const char *name,
>> return did;
>> }
>>
>> -/* return the size or -1 if error */
>> int load_image_targphys(const char *filename,
>> hwaddr addr, uint64_t max_sz)
>> {
>> + return load_image_targphys_as(filename, addr, max_sz, NULL);
>> +}
>> +
>> +/* return the size or -1 if error */
>> +int load_image_targphys_as(const char *filename,
>> + hwaddr addr, uint64_t max_sz, AddressSpace *as)
>> +{
>> int size;
>>
>> size = get_image_size(filename);
>> @@ -144,7 +150,7 @@ int load_image_targphys(const char *filename,
>> return -1;
>> }
>> if (size > 0) {
>> - rom_add_file_fixed(filename, addr, -1);
>> + rom_add_file_fixed_as(filename, addr, -1, as);
>> }
>> return size;
>> }
>> diff --git a/include/hw/loader.h b/include/hw/loader.h
>> index ede98f6..1a9053f 100644
>> --- a/include/hw/loader.h
>> +++ b/include/hw/loader.h
>> @@ -16,6 +16,9 @@ int load_image(const char *filename, uint8_t *addr); /* deprecated */
>> ssize_t load_image_size(const char *filename, void *addr, size_t size);
>> int load_image_targphys(const char *filename, hwaddr,
>> uint64_t max_sz);
>> +int load_image_targphys_as(const char *filename,
>> + hwaddr addr, uint64_t max_sz, AddressSpace *as);
>> +
>
> Again, code changes are fine but could we have a doc comment?
I have added comments to both.
Thanks,
Alistair
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs
2016-07-29 15:56 ` Peter Maydell
@ 2016-08-02 22:59 ` Alistair Francis
0 siblings, 0 replies; 20+ messages in thread
From: Alistair Francis @ 2016-08-02 22:59 UTC (permalink / raw)
To: Peter Maydell
Cc: Alistair Francis, Christopher Covington, Peter Crosthwaite,
Paolo Bonzini, QEMU Developers, Markus Armbruster
On Fri, Jul 29, 2016 at 8:56 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> When loading ROMs allow the caller to specify an AddressSpace to use for
>> the load.
>>
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>> V9:
>> - Fixup the ROM ordering
>> - Don't allow address space and memory region to be specified
>> V8:
>> - Introduce an RFC version of AddressSpace loading support
>>
>> hw/core/loader.c | 39 ++++++++++++++++++++++++++++-----------
>> include/hw/elf_ops.h | 2 +-
>> include/hw/loader.h | 10 ++++++----
>> 3 files changed, 35 insertions(+), 16 deletions(-)
>>
>> diff --git a/hw/core/loader.c b/hw/core/loader.c
>> index 6b61f29..a024133 100644
>> --- a/hw/core/loader.c
>> +++ b/hw/core/loader.c
>> @@ -777,6 +777,7 @@ struct Rom {
>>
>> uint8_t *data;
>> MemoryRegion *mr;
>> + AddressSpace *as;
>> int isrom;
>> char *fw_dir;
>> char *fw_file;
>> @@ -796,12 +797,15 @@ static void rom_insert(Rom *rom)
>> hw_error ("ROM images must be loaded at startup\n");
>> }
>>
>> - /* list is ordered by load address */
>> + /* List is ordered by load address in the same address space */
>> QTAILQ_FOREACH(item, &roms, next) {
>> - if (rom->addr >= item->addr)
>> - continue;
>> - QTAILQ_INSERT_BEFORE(item, rom, next);
>> - return;
>> + if (rom->addr >= item->addr && rom->as == item->as) {
>> + QTAILQ_INSERT_AFTER(&roms, item, rom, next);
>> + return;
>> + } else if (rom->addr <= item->addr && rom->as == item->as) {
>> + QTAILQ_INSERT_BEFORE(item, rom, next);
>> + return;
>> + }
>> }
>> QTAILQ_INSERT_TAIL(&roms, rom, next);
>
> This seems a somewhat confusing way of writing this. I think you
> should define a comparison function and then just replace the
> current "rom->addr >= item->addr" with "rom_order_compare(rom, item) >= 0".
> Then it's clear what the comparison you're using to define the
> sorted order is and that the loop will put things in in sorted
> position.
I tidied this up so it is easier to read and am now using the
rom_order_compare() function.
>
>> }
>> @@ -833,16 +837,25 @@ static void *rom_set_mr(Rom *rom, Object *owner, const char *name)
>>
>> int rom_add_file(const char *file, const char *fw_dir,
>> hwaddr addr, int32_t bootindex,
>> - bool option_rom, MemoryRegion *mr)
>> + bool option_rom, MemoryRegion *mr,
>> + AddressSpace *as)
>> {
>> MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
>> Rom *rom;
>> int rc, fd = -1;
>> char devpath[100];
>>
>> + if (as && mr) {
>> + fprintf(stderr, "Specifying an Address Space and Memory Region is " \
>> + "not valid when loading a rom\n");
>
> Some day we'll fix this up to use Errors, but that day need not be today.
Phew!
>
>> + /* We haven't allocated anything so we don't need any cleanup */
>> + return -1;
>> + }
>> +
>> rom = g_malloc0(sizeof(*rom));
>> rom->name = g_strdup(file);
>> rom->path = qemu_find_file(QEMU_FILE_TYPE_BIOS, rom->name);
>> + rom->as = as;
>> if (rom->path == NULL) {
>> rom->path = g_strdup(file);
>> }
>> @@ -969,7 +982,7 @@ MemoryRegion *rom_add_blob(const char *name, const void *blob, size_t len,
>> * memory ownership of "data", so we don't have to allocate and copy the buffer.
>> */
>> int rom_add_elf_program(const char *name, void *data, size_t datasize,
>> - size_t romsize, hwaddr addr)
>> + size_t romsize, hwaddr addr, AddressSpace *as)
>> {
>> Rom *rom;
>>
>> @@ -979,18 +992,19 @@ int rom_add_elf_program(const char *name, void *data, size_t datasize,
>> rom->datasize = datasize;
>> rom->romsize = romsize;
>> rom->data = data;
>> + rom->as = as;
>> rom_insert(rom);
>> return 0;
>> }
>>
>> int rom_add_vga(const char *file)
>> {
>> - return rom_add_file(file, "vgaroms", 0, -1, true, NULL);
>> + return rom_add_file(file, "vgaroms", 0, -1, true, NULL, NULL);
>> }
>>
>> int rom_add_option(const char *file, int32_t bootindex)
>> {
>> - return rom_add_file(file, "genroms", 0, bootindex, true, NULL);
>> + return rom_add_file(file, "genroms", 0, bootindex, true, NULL, NULL);
>> }
>>
>> static void rom_reset(void *unused)
>> @@ -1008,7 +1022,8 @@ static void rom_reset(void *unused)
>> void *host = memory_region_get_ram_ptr(rom->mr);
>> memcpy(host, rom->data, rom->datasize);
>> } else {
>> - cpu_physical_memory_write_rom(&address_space_memory,
>> + cpu_physical_memory_write_rom(rom->as ? rom->as :
>> + &address_space_memory,
>
> Should we just make rom->as be &address_space_memory if the caller
> doesn't provide one rather than having it be NULL and then special
> casing what NULL means? (This will also avoid potentially odd
> effects with some of the ROMs in the list having &address_space_memory
> for an explicitly specified AS and some having NULL for the same
> AS but implicitly specified, which is otherwise a pain to deal with
> in comparisons.)
Good point, I have added the setter in rom_insert() function.
Thanks,
Alistair
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document
2016-07-29 17:55 ` Peter Maydell
@ 2016-08-03 18:22 ` Alistair Francis
0 siblings, 0 replies; 20+ messages in thread
From: Alistair Francis @ 2016-08-03 18:22 UTC (permalink / raw)
To: Peter Maydell
Cc: Alistair Francis, Christopher Covington, Peter Crosthwaite,
Paolo Bonzini, QEMU Developers, Markus Armbruster
On Fri, Jul 29, 2016 at 10:55 AM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 14 July 2016 at 01:03, Alistair Francis <alistair.francis@xilinx.com> wrote:
>> Signed-off-by: Alistair Francis <alistair.francis@xilinx.com>
>> ---
>> V9:
>> - Clarify the image loading options
>> V8:
>> - Improve documentation
>> V6:
>> - Fixup documentation
>> V4:
>> - Re-write to be more comprehensive
>>
>> docs/generic-loader.txt | 63 +++++++++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 63 insertions(+)
>> create mode 100644 docs/generic-loader.txt
>>
>> diff --git a/docs/generic-loader.txt b/docs/generic-loader.txt
>> new file mode 100644
>> index 0000000..16c11ee
>> --- /dev/null
>> +++ b/docs/generic-loader.txt
>> @@ -0,0 +1,63 @@
>> +Copyright (c) 2016 Xilinx Inc.
>> +
>> +This work is licensed under the terms of the GNU GPL, version 2 or later. See
>> +the COPYING file in the top-level directory.
>> +
>> +
>> +The 'loader' device allows the user to load multiple images or values into
>> +QEMU at startup.
>> +
>> +Loading Memory Values
>> +---------------------
>> +The loader device allows memory values to be set from the command line. This
>> +can be done by following the syntax below:
>> +
>> + -device loader,addr=<addr>,data=<data>,data-len=<len>
>> + -device loader,addr=<addr>,cpu-num=<cpu-num>
>> +
>> + <addr> - The address to store the data or the value to use as the
>> + CPU's PC.
>> + <data> - The value to be written to the address. The maximum size of
>> + the data is 8 bytes.
>> + <data-len> - The length of the data in bytes. This argument must be
>> + included if the data argument is.
>> + <data-be> - Set to true if the data to be stored on the guest should be
>> + written as big endian data. The default is to write little
>> + endian data.
>> + <cpu-num> - This will cause the CPU to be reset and the PC to be set to
>> + the value of addr.
>> +
>> +For all values both hex and decimal values are allowed. By default the values
>> +will be parsed as decimal. To use hex values the user should prefix the number
>> +with a '0x'.
>> +
>> +An example of loading value 0x8000000e to address 0xfd1a0104 is:
>> + -device loader,addr=0xfd1a0104,data=0x8000000e,data-len=4
>> +
>> +Loading Files
>> +-------------
>> +The loader device also allows files to be loaded into memory. This can be done
>> +similarly to setting memory values. The syntax is shown below:
>> +
>> + -device loader,file=<file>,addr=<addr>,cpu-num=<cpu-num>,force-raw=<raw>
>> +
>> + <file> - A file to be loaded into memory
>> + <addr> - The addr in memory that the file should be loaded. This is
>> + ignored if you are using an ELF (unless force-raw is true).
>> + This is required if you aren't loading an ELF.
>> + <cpu-num> - This specifies the CPU that should be used. This is an
>> + optional argument and will cause the CPU's PC to be set to
>> + where the image is stored or in the case of an ELF file to
>> + the value in the header. This option should only be used
>> + for the boot image.
>> + This will also cause the image to be written to the specified
>> + CPUs address space.
>> + <force-raw> - Forces the file to be treated as a raw image. This can be
>> + used to specify the load address of ELF files.
>> +
>> +For all values both hex and decimal values are allowed. By default the values
>> +will be parsed as decimal. To use hex values the user should prefix the number
>> +with a '0x'.
>> +
>> +An example of loading an ELF file which CPU0 will boot is shown below:
>> + -device loader,file=./images/boot.elf,cpu-num=0
>
> With this interface, you can specify a file to be loaded to CPU 2's
> address space (via file=whatever,cpu-num=2) but you can't specify
> a data value to be loaded to CPU 2's address space (because
> addr=a,data=x,data-len=y,cpu-num=2 isn't valid). I think we could
> usefully make that syntax do that.
>
> This is probably most clearly documented by completely splitting
> -device loader,addr=<addr>,cpu-num=<cpu-num>
> (set the PC)
>
> from
> -device loader,addr=<addr>,data=<data>,data-len=<data-len>[,data-be=<data-be>][,cpu-num=<cpu-num>]
> (load raw data values)
>
> in the documentation in the same way that loader,file is split.
Ok, I have split these two up. There is now a new variable in the
device loader that keeps track of if the PC should be set or not.
At the moment it is not exposed at all to the user, but in the future
we can make it user forceable.
>
> (I have a feeling we've been circling around on this option syntax
> over the last few revisions so apologies if I've been inconsistent.)
I think we have, but it's ok. I just want this in.
>
> You also can't specify a file to be loaded which doesn't set the
> CPU PC, but I'm not sure how important that is. We can always add
> it later with a no-set-pc option flag if we need it I guess.
Agreed!
Thanks,
Alistair
>
> thanks
> -- PMM
>
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2016-08-03 18:23 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-07-14 0:03 [Qemu-devel] [PATCH v9 0/8] Add a generic loader Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 1/8] loader: Allow ELF loader to auto-detect the ELF arch Alistair Francis
2016-07-29 15:42 ` Peter Maydell
2016-08-02 0:03 ` Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 2/8] loader: Use the specified MemoryRegion Alistair Francis
2016-07-29 17:34 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 3/8] loader: Allow a custom AddressSpace when loading ROMs Alistair Francis
2016-07-29 15:56 ` Peter Maydell
2016-08-02 22:59 ` Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 4/8] loader: Add AddressSpace loading support to ELFs Alistair Francis
2016-07-29 17:35 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 5/8] loader: Add AddressSpace loading support to uImages Alistair Francis
2016-07-29 17:41 ` Peter Maydell
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 6/8] loader: Add AddressSpace loading support to targphys Alistair Francis
2016-07-29 17:42 ` Peter Maydell
2016-08-02 21:21 ` Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 7/8] generic-loader: Add a generic loader Alistair Francis
2016-07-14 0:03 ` [Qemu-devel] [PATCH v9 8/8] docs: Add a generic loader explanation document Alistair Francis
2016-07-29 17:55 ` Peter Maydell
2016-08-03 18:22 ` 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).