From 48354cc5a3744c9a56462e5053e1f267a0ce69de Mon Sep 17 00:00:00 2001 From: "Michael S. Tsirkin" Date: Sun, 18 Aug 2013 17:02:33 +0300 Subject: loader: support for unmapped ROM blobs Support ROM blobs not mapped into guest memory: same as ROM files really but use caller's buffer. Support invoking callback on access and return memory pointer making it easier for caller to update memory if necessary. Reviewed-by: Gerd Hoffmann Tested-by: Gerd Hoffmann Reviewed-by: Laszlo Ersek Reviewed-by: Igor Mammedov Tested-by: Igor Mammedov Signed-off-by: Michael S. Tsirkin --- hw/core/loader.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'hw/core/loader.c') diff --git a/hw/core/loader.c b/hw/core/loader.c index 7b3d3ee6a0..449bd4c90a 100644 --- a/hw/core/loader.c +++ b/hw/core/loader.c @@ -700,10 +700,12 @@ err: return -1; } -int rom_add_blob(const char *name, const void *blob, size_t len, - hwaddr addr) +void *rom_add_blob(const char *name, const void *blob, size_t len, + hwaddr addr, const char *fw_file_name, + FWCfgReadCallback fw_callback, void *callback_opaque) { Rom *rom; + void *data = NULL; rom = g_malloc0(sizeof(*rom)); rom->name = g_strdup(name); @@ -713,7 +715,22 @@ int rom_add_blob(const char *name, const void *blob, size_t len, rom->data = g_malloc0(rom->datasize); memcpy(rom->data, blob, len); rom_insert(rom); - return 0; + if (fw_file_name && fw_cfg) { + char devpath[100]; + + snprintf(devpath, sizeof(devpath), "/rom@%s", fw_file_name); + + if (rom_file_in_ram) { + data = rom_set_mr(rom, OBJECT(fw_cfg), devpath); + } else { + data = rom->data; + } + + fw_cfg_add_file_callback(fw_cfg, fw_file_name, + fw_callback, callback_opaque, + data, rom->romsize); + } + return data; } /* This function is specific for elf program because we don't need to allocate -- cgit v1.2.3