]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[linux] Allow arbitrary settings to be applied to Linux devices
authorMichael Brown <mcb30@ipxe.org>
Tue, 2 Mar 2021 19:34:16 +0000 (19:34 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 2 Mar 2021 19:35:11 +0000 (19:35 +0000)
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>
src/drivers/linux/linux.c

index 83546b27e0e26ab39431b0d17556a22b0682148a..898f50024a617897fce94c32f2b5c8336fc003b8 100644 (file)
@@ -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;
        }
 }