Function is simliar to load_image_to_fw_cfg() but loads the image into a named fw_cfg file instead of fixed keys.
Signed-off-by: Gerd Hoffmann <[email protected]> --- hw/nvram/fw_cfg.c | 22 ++++++++++++++++++++++ include/hw/nvram/fw_cfg.h | 15 +++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c index 1d7d835421..d8653d93cd 100644 --- a/hw/nvram/fw_cfg.c +++ b/hw/nvram/fw_cfg.c @@ -1143,6 +1143,28 @@ void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, fw_cfg_add_bytes(fw_cfg, data_key, data, size); } +void load_image_to_fw_cfg_file(FWCfgState *fw_cfg, + const char *fw_cfg_name, + const char *image_name) +{ + GMappedFile *mapped_file; + GError *gerr = NULL; + + if (image_name == NULL) { + return; + } + + mapped_file = g_mapped_file_new(image_name, false, &gerr); + if (!mapped_file) { + error_report("qemu: error reading %s: %s", + image_name, gerr->message); + exit(1); + } + fw_cfg_add_file(fw_cfg, fw_cfg_name, + g_mapped_file_get_contents(mapped_file), + g_mapped_file_get_length(mapped_file)); +} + static void fw_cfg_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc = DEVICE_CLASS(klass); diff --git a/include/hw/nvram/fw_cfg.h b/include/hw/nvram/fw_cfg.h index 56f17a0bdc..7b31bd0ba6 100644 --- a/include/hw/nvram/fw_cfg.h +++ b/include/hw/nvram/fw_cfg.h @@ -351,4 +351,19 @@ void load_image_to_fw_cfg(FWCfgState *fw_cfg, uint16_t size_key, uint16_t data_key, const char *image_name, bool try_decompress); +/** + * load_image_to_fw_cfg_file() - Load an image file into an fw_cfg entry + * identified by fw_cfg file name. + * @fw_cfg: The firmware config instance to store the data in. + * @fw_cfg_name: The name of the fw_cfg (pseudo) file. + * @image_name: The name of the image file to load. If it is NULL, the + * function returns without doing anything. + * + * In case of failure, the function prints an error message to stderr and the + * process exits with status 1. + */ +void load_image_to_fw_cfg_file(FWCfgState *fw_cfg, + const char *fw_cfg_name, + const char *image_name); + #endif -- 2.54.0
