]> git.ozlabs.org Git - petitboot/commitdiff
discover: Add petitboot,tty and track available consoles
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 8 Jun 2016 03:51:28 +0000 (13:51 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Wed, 29 Jun 2016 04:19:08 +0000 (14:19 +1000)
Add the NVRAM parameter petitboot,tty which sets the default console to
use when booting a kernel.
In load_config() construct a list of available consoles depending on the
current platform. A future patch depending on firmware changes will
allow this list to be constructed dynamically.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/platform-powerpc.c
discover/platform.c

index 1f8d27d772d93081b72d2977f96af837690db429..eb54c6dddf231d73a5f1f1965f76703f7967d471 100644 (file)
@@ -59,6 +59,7 @@ static const char *known_params[] = {
        "petitboot,debug?",
        "petitboot,write?",
        "petitboot,snapshots?",
+       "petitboot,tty",
        NULL,
 };
 
@@ -565,6 +566,10 @@ static void populate_config(struct platform_powerpc *platform,
        val = get_param(platform, "petitboot,snapshots?");
        if (val)
                config->disable_snapshots = !strcmp(val, "false");
+
+       val = get_param(platform, "petitboot,tty");
+       if (val)
+               config->boot_tty = talloc_strdup(config, val);
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -732,6 +737,9 @@ static int update_config(struct platform_powerpc *platform,
                val = config->allow_writes ? "true" : "false";
        update_string_config(platform, "petitboot,write?", val);
 
+       val = config->boot_tty ?: "";
+       update_string_config(platform, "petitboot,tty", val);
+
        update_network_config(platform, config);
 
        update_bootdev_config(platform, config);
@@ -1217,6 +1225,39 @@ static void get_ipmi_network_override(struct platform_powerpc *platform,
        }
 }
 
+static void get_active_consoles(struct config *config)
+{
+       struct stat sbuf;
+       char *fsp_prop = NULL;
+
+       config->n_tty = 2;
+       config->tty_list = talloc_array(config, char *, config->n_tty);
+       if (!config->tty_list)
+               goto err;
+
+       config->tty_list[0] = talloc_asprintf(config->tty_list,
+                                       "/dev/hvc0 [IPMI / Serial]");
+       config->tty_list[1] = talloc_asprintf(config->tty_list,
+                                       "/dev/tty1 [VGA]");
+
+       fsp_prop = talloc_asprintf(config, "%sfsps", devtree_dir);
+       if (stat(fsp_prop, &sbuf) == 0) {
+               /* FSP based machines also have a separate serial console */
+               config->tty_list = talloc_realloc(config, config->tty_list,
+                                               char *, config->n_tty + 1);
+               if (!config->tty_list)
+                       goto err;
+               config->tty_list[config->n_tty++] = talloc_asprintf(
+                                               config->tty_list,
+                                               "/dev/hvc1 [Serial]");
+       }
+
+       return;
+err:
+       config->n_tty = 0;
+       pb_log("Failed to allocate memory for tty_list\n");
+}
+
 static int load_config(struct platform *p, struct config *config)
 {
        struct platform_powerpc *platform = to_platform_powerpc(p);
@@ -1241,6 +1282,8 @@ static int load_config(struct platform *p, struct config *config)
        if (platform->ipmi)
                get_ipmi_network_override(platform, config);
 
+       get_active_consoles(config);
+
        return 0;
 }
 
index fc0930db29a1cd67d6223d891f9fa9a865e064e6..254da979b41e2cc8157ba39f0ad9734979d43498 100644 (file)
@@ -79,6 +79,12 @@ static void dump_config(struct config *config)
        pb_log("  IPMI boot device 0x%02x%s\n", config->ipmi_bootdev,
                        config->ipmi_bootdev_persistent ? " (persistent)" : "");
 
+       pb_log("  Modifications allowed to disks: %s\n",
+                       config->allow_writes ? "yes" : "no");
+
+       pb_log("  Default UI to boot on: %s\n",
+               config->boot_tty ?: "none set");
+
 
        pb_log(" language: %s\n", config->lang ?: "");
 }
@@ -117,6 +123,10 @@ void config_set_defaults(struct config *config)
        config->allow_writes = true;
        config->disable_snapshots = false;
 
+       config->n_tty = 0;
+       config->tty_list = NULL;
+       config->boot_tty = NULL;
+
        config->n_autoboot_opts = 2;
        config->autoboot_opts = talloc_array(config, struct autoboot_option,
                                                config->n_autoboot_opts);