hw/nvram: add load_image_to_fw_cfg_file()

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 <kraxel@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Message-id: 20260521112806.504961-2-kraxel@redhat.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Gerd Hoffmann
2026-05-21 13:28:04 +02:00
committed by Peter Maydell
parent bf6530630e
commit 40fd898e86
2 changed files with 37 additions and 0 deletions

View File

@@ -1139,6 +1139,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);

View File

@@ -399,4 +399,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