diff options
author | Michael Brown <mcb30@ipxe.org> | 2021-03-02 19:34:16 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2021-03-02 19:35:11 +0000 |
commit | 7b963310aad3e68663d93ddaa10f8f27ab33d157 (patch) | |
tree | 31bffb07090264c13ba154d4ad2631b04972e03f | |
parent | 8055d5c48b4194f24c1705fd6a15e7125e8ef4c5 (diff) | |
download | ipxe-7b963310aad3e68663d93ddaa10f8f27ab33d157.tar.gz |
[linux] Allow arbitrary settings to be applied to Linux devices
Allow arbitrary settings to be specified on the Linux command line.
For example:
./bin-x86_64-linux/slirp.linux \
--net slirp,testserver=qa-test.ipxe.org
This can be useful when using the Linux userspace build to test
embedded scripts, since it allows arbitrary parameters to be passed
directly on the command line.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r-- | src/drivers/linux/linux.c | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/drivers/linux/linux.c b/src/drivers/linux/linux.c index 83546b27e..898f50024 100644 --- a/src/drivers/linux/linux.c +++ b/src/drivers/linux/linux.c @@ -130,24 +130,48 @@ struct linux_setting *linux_find_setting(char *name, struct list_head *settings) return result; } -void linux_apply_settings(struct list_head *new_settings, struct settings *settings_block) -{ - struct linux_setting *setting; +/** + * Apply Linux command-line settings + * + * @v list List of command-line settings + * @v settings Settings block + */ +void linux_apply_settings ( struct list_head *list, + struct settings *settings ) { + struct linux_setting *lsetting; + struct settings *ignore; + struct setting setting; int rc; - list_for_each_entry(setting, new_settings, list) { + list_for_each_entry ( lsetting, list, list ) { + /* Skip already applied settings */ - if (setting->applied) + if ( lsetting->applied ) continue; - struct setting *s = find_setting(setting->name); - if (s) { - rc = storef_setting(settings_block, find_setting(setting->name), setting->value); - if (rc != 0) - DBG("linux storing setting '%s' = '%s' failed\n", setting->name, setting->value); - setting->applied = 1; - } else { - DBG("linux unknown setting '%s'\n", setting->name); + /* Parse setting name */ + if ( ( rc = parse_setting_name ( lsetting->name, + find_child_settings, &ignore, + &setting ) ) != 0 ) { + DBGC ( settings, "Linux cannot parse %s: %s\n", + lsetting->name, strerror ( rc ) ); + continue; + } + + /* Apply default type if not specified */ + if ( ! setting.type ) + setting.type = &setting_type_string; + + /* Store setting */ + if ( ( rc = storef_setting ( settings, &setting, + lsetting->value ) ) != 0 ) { + DBGC ( settings, "Linux cannot set %s=\"%s\": %s\n", + lsetting->name, lsetting->value, + strerror ( rc ) ); + continue; } + + /* Mark setting as applied */ + lsetting->applied = 1; } } |