Skip to content

Commit 6552d87

Browse files
committed
softmmu/vl: Let -fw_cfg option take a 'gen_id' argument
The 'gen_id' argument refers to a QOM object able to produce data consumable by the fw_cfg device. The producer object must implement the FW_CFG_DATA_GENERATOR interface. Reviewed-by: Laszlo Ersek <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Reviewed-by: Daniel P. Berrangé <[email protected]> Message-Id: <[email protected]>
1 parent 3203148 commit 6552d87

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

softmmu/vl.c

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,11 @@ static QemuOptsList qemu_fw_cfg_opts = {
489489
.name = "string",
490490
.type = QEMU_OPT_STRING,
491491
.help = "Sets content of the blob to be inserted from a string",
492+
}, {
493+
.name = "gen_id",
494+
.type = QEMU_OPT_STRING,
495+
.help = "Sets id of the object generating the fw_cfg blob "
496+
"to be inserted",
492497
},
493498
{ /* end of list */ }
494499
},
@@ -2020,7 +2025,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
20202025
{
20212026
gchar *buf;
20222027
size_t size;
2023-
const char *name, *file, *str;
2028+
const char *name, *file, *str, *gen_id;
20242029
FWCfgState *fw_cfg = (FWCfgState *) opaque;
20252030

20262031
if (fw_cfg == NULL) {
@@ -2030,14 +2035,13 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
20302035
name = qemu_opt_get(opts, "name");
20312036
file = qemu_opt_get(opts, "file");
20322037
str = qemu_opt_get(opts, "string");
2038+
gen_id = qemu_opt_get(opts, "gen_id");
20332039

2034-
/* we need name and either a file or the content string */
2035-
if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))) {
2036-
error_setg(errp, "invalid argument(s)");
2037-
return -1;
2038-
}
2039-
if (nonempty_str(file) && nonempty_str(str)) {
2040-
error_setg(errp, "file and string are mutually exclusive");
2040+
/* we need the name, and exactly one of: file, content string, gen_id */
2041+
if (!nonempty_str(name) ||
2042+
nonempty_str(file) + nonempty_str(str) + nonempty_str(gen_id) != 1) {
2043+
error_setg(errp, "name, plus exactly one of file,"
2044+
" string and gen_id, are needed");
20412045
return -1;
20422046
}
20432047
if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) {
@@ -2052,6 +2056,15 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
20522056
if (nonempty_str(str)) {
20532057
size = strlen(str); /* NUL terminator NOT included in fw_cfg blob */
20542058
buf = g_memdup(str, size);
2059+
} else if (nonempty_str(gen_id)) {
2060+
Error *local_err = NULL;
2061+
2062+
fw_cfg_add_from_generator(fw_cfg, name, gen_id, errp);
2063+
if (local_err) {
2064+
error_propagate(errp, local_err);
2065+
return -1;
2066+
}
2067+
return 0;
20552068
} else {
20562069
GError *err = NULL;
20572070
if (!g_file_get_contents(file, &buf, &size, &err)) {

0 commit comments

Comments
 (0)