Consolidate petitboot,tty and petitboot,console
authorSamuel Mendoza-Jonas <sam@mendozajonas.com>
Tue, 9 Aug 2016 06:16:48 +0000 (16:16 +1000)
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>
Thu, 8 Sep 2016 04:26:27 +0000 (14:26 +1000)
Commit ce54f86 "Add petitboot,tty and track available consoles" added
the petitboot,tty parameter, but the petitboot,console parameter is also
recognised by Petitboot. These are ultimately handled by the 30-add-offb
and 80-set-stdout hooks respectively, but exist for mostly the same
purpose.

We consolidate these down to just the original petitboot,console
parameter. If the contents of petitboot,console have been configured by
Petitboot (ie. it is of the form /dev/dev# [ Description ]) we behave as
normal, otherwise we assume that petitboot,console contains a full
OF path to the intended console device and do not allow it to be
modified. This follows petitboot,console's original intent to be a debug
aid, and takes precedence over any other use.
The 80-set-stdout hook is removed as 30-add-offb now accounts for both
use cases.

Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
discover/boot.c
discover/platform-powerpc.c
discover/platform.c
lib/pb-config/pb-config.c
lib/pb-protocol/pb-protocol.c
lib/types/types.h
ui/ncurses/nc-config.c
utils/Makefile.am
utils/hooks/30-add-offb.c
utils/hooks/80-set-stdout [deleted file]

index 0732a50aea0318fce5f2fc5225716b50c8350776..dc6da7d5254d9a3b420cd01ed698f2a0af1053ee 100644 (file)
@@ -517,7 +517,7 @@ struct boot_task *boot(void *ctx, struct discover_boot_option *opt,
        struct pb_url *image = NULL, *initrd = NULL, *dtb = NULL;
        struct pb_url *image_sig = NULL, *initrd_sig = NULL, *dtb_sig = NULL,
                *cmdline_sig = NULL;
        struct pb_url *image = NULL, *initrd = NULL, *dtb = NULL;
        struct pb_url *image_sig = NULL, *initrd_sig = NULL, *dtb_sig = NULL,
                *cmdline_sig = NULL;
-       const struct config *config;
+       const struct config *config = config_get();
        struct boot_task *boot_task;
        const char *boot_desc;
        int rc;
        struct boot_task *boot_task;
        const char *boot_desc;
        int rc;
@@ -574,12 +574,10 @@ struct boot_task *boot(void *ctx, struct discover_boot_option *opt,
                boot_task->args = NULL;
        }
 
                boot_task->args = NULL;
        }
 
-       if (cmd && cmd->console)
+       if (cmd && cmd->console && !config->manual_console)
                boot_task->boot_console = talloc_strdup(boot_task, cmd->console);
                boot_task->boot_console = talloc_strdup(boot_task, cmd->console);
-       else {
-               config = config_get();
+       else
                boot_task->boot_console = config ? config->boot_console : NULL;
                boot_task->boot_console = config ? config->boot_console : NULL;
-       }
 
        if (boot_task->verify_signature || boot_task->decrypt_files) {
                if (cmd && cmd->args_sig_file) {
 
        if (boot_task->verify_signature || boot_task->decrypt_files) {
                if (cmd && cmd->args_sig_file) {
index 57618c3592bc5922c395de72e0fb6b9a411a5cf6..a4b13e4f8dd7e224896ffd9c8f303eaed8c3de1e 100644 (file)
@@ -59,7 +59,7 @@ static const char *known_params[] = {
        "petitboot,debug?",
        "petitboot,write?",
        "petitboot,snapshots?",
        "petitboot,debug?",
        "petitboot,write?",
        "petitboot,snapshots?",
-       "petitboot,tty",
+       "petitboot,console",
        NULL,
 };
 
        NULL,
 };
 
@@ -567,9 +567,12 @@ static void populate_config(struct platform_powerpc *platform,
        if (val)
                config->disable_snapshots = !strcmp(val, "false");
 
        if (val)
                config->disable_snapshots = !strcmp(val, "false");
 
-       val = get_param(platform, "petitboot,tty");
+       val = get_param(platform, "petitboot,console");
        if (val)
                config->boot_console = talloc_strdup(config, val);
        if (val)
                config->boot_console = talloc_strdup(config, val);
+       /* If a full path is already set we don't want to override it */
+       config->manual_console = config->boot_console &&
+                                       !strchr(config->boot_console, '[');
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
 }
 
 static char *iface_config_str(void *ctx, struct interface_config *config)
@@ -746,8 +749,10 @@ static int update_config(struct platform_powerpc *platform,
                val = config->allow_writes ? "true" : "false";
        update_string_config(platform, "petitboot,write?", val);
 
                val = config->allow_writes ? "true" : "false";
        update_string_config(platform, "petitboot,write?", val);
 
-       val = config->boot_console ?: "";
-       update_string_config(platform, "petitboot,tty", val);
+       if (!config->manual_console) {
+               val = config->boot_console ?: "";
+               update_string_config(platform, "petitboot,console", val);
+       }
 
        update_network_config(platform, config);
 
 
        update_network_config(platform, config);
 
index 95a905d6ec82eac746c1bd6d38f928d34c4f4aa1..93cd05787406cf1d01dd51a6dd469c253b2636e6 100644 (file)
@@ -84,6 +84,8 @@ static void dump_config(struct config *config)
 
        pb_log("  Default UI to boot on: %s\n",
                config->boot_console ?: "none set");
 
        pb_log("  Default UI to boot on: %s\n",
                config->boot_console ?: "none set");
+       if (config->manual_console)
+               pb_log("    (Manually set)\n");
 
 
        pb_log(" language: %s\n", config->lang ?: "");
 
 
        pb_log(" language: %s\n", config->lang ?: "");
index 86f14c9082baddb9e7bce67fc62f764a76b34f4b..2f9af286b770aec0e5083a1a92296fd642e27fe3 100644 (file)
@@ -92,6 +92,7 @@ struct config *config_copy(void *ctx, const struct config *src)
 
        if (src->boot_console)
                dest->boot_console = talloc_strdup(dest, src->boot_console);
 
        if (src->boot_console)
                dest->boot_console = talloc_strdup(dest, src->boot_console);
+       dest->manual_console = src->manual_console;
 
        if (src->lang && strlen(src->lang))
                dest->lang = talloc_strdup(dest, src->lang);
 
        if (src->lang && strlen(src->lang))
                dest->lang = talloc_strdup(dest, src->lang);
index 0d83bde0d11fca8f7b4902755cfa13e458a6277f..47d04a399e4a4fd0ff2420356f32c523e7d0c07a 100644 (file)
@@ -323,6 +323,7 @@ int pb_protocol_config_len(const struct config *config)
                len += 4 + optional_strlen(config->consoles[i]);
 
        len += 4 + optional_strlen(config->boot_console);
                len += 4 + optional_strlen(config->consoles[i]);
 
        len += 4 + optional_strlen(config->boot_console);
+       len += 4; /* manual_console */
 
        len += 4 + optional_strlen(config->lang);
 
 
        len += 4 + optional_strlen(config->lang);
 
@@ -579,6 +580,8 @@ int pb_protocol_serialise_config(const struct config *config,
                pos += pb_protocol_serialise_string(pos, config->consoles[i]);
 
        pos += pb_protocol_serialise_string(pos, config->boot_console);
                pos += pb_protocol_serialise_string(pos, config->consoles[i]);
 
        pos += pb_protocol_serialise_string(pos, config->boot_console);
+       *(uint32_t *)pos = config->manual_console;
+       pos += 4;
 
        pos += pb_protocol_serialise_string(pos, config->lang);
 
 
        pos += pb_protocol_serialise_string(pos, config->lang);
 
@@ -1124,6 +1127,10 @@ int pb_protocol_deserialise_config(struct config *config,
 
        config->boot_console = str;
 
 
        config->boot_console = str;
 
+       if (read_u32(&pos, &len, &tmp))
+               goto out;
+       config->manual_console = !!tmp;
+
        if (read_string(config, &pos, &len, &str))
                goto out;
 
        if (read_string(config, &pos, &len, &str))
                goto out;
 
index b7430f4910f6d5e6a97363aa5844b2064c872079..31922d0d81fb01b75256173e8f9b5c881aefba17 100644 (file)
@@ -164,6 +164,7 @@ struct config {
        bool                    allow_writes;
 
        char                    *boot_console;
        bool                    allow_writes;
 
        char                    *boot_console;
+       bool                    manual_console;
        char                    *lang;
 
        /* not user-settable */
        char                    *lang;
 
        /* not user-settable */
index c668bde12ae0255ceba9a73d4034abccc0b04cf1..1bc77e8ec44750b6385388fa902e3a83b552c5a6 100644 (file)
@@ -111,6 +111,7 @@ struct config_screen {
                struct nc_widget_select         *allow_write_f;
                struct nc_widget_label          *boot_console_l;
                struct nc_widget_select         *boot_console_f;
                struct nc_widget_select         *allow_write_f;
                struct nc_widget_label          *boot_console_l;
                struct nc_widget_select         *boot_console_f;
+               struct nc_widget_label          *manual_console_l;
                struct nc_widget_label          *current_console_l;
 
                struct nc_widget_label          *net_override_l;
                struct nc_widget_label          *current_console_l;
 
                struct nc_widget_label          *net_override_l;
@@ -338,7 +339,7 @@ static int screen_process_form(struct config_screen *screen)
        if (allow_write != config->allow_writes)
                config->allow_writes = allow_write;
 
        if (allow_write != config->allow_writes)
                config->allow_writes = allow_write;
 
-       if (config->n_consoles) {
+       if (config->n_consoles && !config->manual_console) {
                idx = widget_select_get_value(screen->widgets.boot_console_f);
                if (!config->boot_console) {
                        config->boot_console = talloc_strdup(config,
                idx = widget_select_get_value(screen->widgets.boot_console_f);
                if (!config->boot_console) {
                        config->boot_console = talloc_strdup(config,
@@ -592,7 +593,15 @@ static void config_screen_layout_widgets(struct config_screen *screen)
 
        y += 1;
 
 
        y += 1;
 
-       if (widget_height(widget_select_base(screen->widgets.boot_console_f))) {
+       if (screen->widgets.manual_console_l) {
+               layout_pair(screen, y++, screen->widgets.boot_console_l,
+                       widget_label_base(screen->widgets.manual_console_l));
+               widget_move(widget_label_base(screen->widgets.current_console_l),
+                       y, screen->field_x);
+               widget_set_visible(widget_select_base(
+                       screen->widgets.boot_console_f), false);
+               y += 2;
+       } else if (widget_height(widget_select_base(screen->widgets.boot_console_f))) {
                layout_pair(screen, y, screen->widgets.boot_console_l,
                            widget_select_base(screen->widgets.boot_console_f));
                y += widget_height(widget_select_base(screen->widgets.boot_console_f));
                layout_pair(screen, y, screen->widgets.boot_console_l,
                            widget_select_base(screen->widgets.boot_console_f));
                y += widget_height(widget_select_base(screen->widgets.boot_console_f));
@@ -785,7 +794,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 {
        struct nc_widgetset *set = screen->widgetset;
        struct interface_config *ifcfg;
 {
        struct nc_widgetset *set = screen->widgetset;
        struct interface_config *ifcfg;
-       char *str, *ip, *mask, *gw, *url, *tty;
+       char *str, *ip, *mask, *gw, *url, *tty, *label;
        enum net_conf_type type;
        unsigned int i;
        int add_len, clear_len, any_len, min_len = 20;
        enum net_conf_type type;
        unsigned int i;
        int add_len, clear_len, any_len, min_len = 20;
@@ -841,7 +850,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        for (i = 0; i < sysinfo->n_blockdevs; i++) {
                struct blockdev_info *bd = sysinfo->blockdevs[i];
 
        for (i = 0; i < sysinfo->n_blockdevs; i++) {
                struct blockdev_info *bd = sysinfo->blockdevs[i];
-               char *label;
 
                label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
                                bd->name, bd->uuid);
 
                label = talloc_asprintf(screen, _("disk: %s [uuid: %s]"),
                                bd->name, bd->uuid);
@@ -851,7 +859,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *info = sysinfo->interfaces[i];
 
        for (i = 0; i < sysinfo->n_interfaces; i++) {
                struct interface_info *info = sysinfo->interfaces[i];
-               char *label, mac[20];
+               char mac[20];
 
                mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
 
 
                mac_str(info->hwaddr, info->hwaddr_size, mac, sizeof(mac));
 
@@ -862,7 +870,6 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        }
 
        for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_UNKNOWN; i++) {
        }
 
        for (i = DEVICE_TYPE_NETWORK; i < DEVICE_TYPE_UNKNOWN; i++) {
-               char *label;
 
                if (i == DEVICE_TYPE_ANY)
                        label = talloc_asprintf(screen, _("Any Device"));
 
                if (i == DEVICE_TYPE_ANY)
                        label = talloc_asprintf(screen, _("Any Device"));
@@ -903,7 +910,7 @@ static void config_screen_setup_widgets(struct config_screen *screen,
        widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
 
        if (config->ipmi_bootdev) {
        widget_textbox_set_validator_integer(screen->widgets.timeout_f, 0, 999);
 
        if (config->ipmi_bootdev) {
-               char *label = talloc_asprintf(screen,
+               label = talloc_asprintf(screen,
                                _("%s IPMI boot option: %s"),
                                config->ipmi_bootdev_persistent ?
                                "Persistent" : "Temporary",
                                _("%s IPMI boot option: %s"),
                                config->ipmi_bootdev_persistent ?
                                "Persistent" : "Temporary",
@@ -1051,6 +1058,12 @@ static void config_screen_setup_widgets(struct config_screen *screen,
                                        config->consoles[i], found);
        }
 
                                        config->consoles[i], found);
        }
 
+       if (config->manual_console) {
+               label = talloc_asprintf(screen, _("Manually set: '%s'"),
+                                       config->boot_console);
+               screen->widgets.manual_console_l = widget_new_label(set, 0, 0, label);
+       }
+
        tty = talloc_asprintf(screen, _("Current interface: %s"),
                                ttyname(STDIN_FILENO));
        screen->widgets.current_console_l = widget_new_label(set, 0 , 0, tty);
        tty = talloc_asprintf(screen, _("Current interface: %s"),
                                ttyname(STDIN_FILENO));
        screen->widgets.current_console_l = widget_new_label(set, 0 , 0, tty);
index 2bbfb9c19b9988ff62f88b03bcc1330414d2eaaa..453fdbd683e2cca21631b44d6b13b138bc65f20d 100644 (file)
@@ -34,5 +34,4 @@ dist_pkgdata_DATA = \
        utils/logrotate.conf \
        utils/hooks/01-create-default-dtb \
        utils/hooks/20-update-dtb-sample \
        utils/logrotate.conf \
        utils/hooks/01-create-default-dtb \
        utils/hooks/20-update-dtb-sample \
-       utils/hooks/90-sort-dtb \
-       utils/hooks/80-set-stdout
+       utils/hooks/90-sort-dtb
index eca9d133520da3a41282de4bbb971c95e428375c..aff3844dd5e9f613e8d1717085e108408eb76c9d 100644 (file)
@@ -512,7 +512,10 @@ static int set_stdout(struct offb_ctx *ctx)
                return 0;
        }
 
                return 0;
        }
 
-       if (strstr(boot_console, "tty") != NULL) {
+       if (strncmp(boot_console, "/dev/", strlen("/dev/")) != 0) {
+               /* We already have the full path */
+               stdout_path = talloc_strdup(ctx, boot_console);
+       } else if (strstr(boot_console, "tty") != NULL) {
                fprintf(stderr, "TTY recognised: %s\n", boot_console);
                stdout_path = get_vga_path(ctx);
        } else {
                fprintf(stderr, "TTY recognised: %s\n", boot_console);
                stdout_path = get_vga_path(ctx);
        } else {
diff --git a/utils/hooks/80-set-stdout b/utils/hooks/80-set-stdout
deleted file mode 100755 (executable)
index 92ff030..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/bin/sh
-
-# Hook to set the linux,stdout-path property from an nvram property
-# (named $nvram_prop).
-
-nvram_prop=petitboot,console
-
-# we need to be using a dtb
-[ -n "$boot_dtb" ] || exit
-
-console=$(nvram --print-config="$nvram_prop")
-
-[ $? = 0 -a -n "$console" ] || exit
-
-dtb_in=$boot_dtb
-dtb_out=$(mktemp)
-
-(
-       dtc -I dtb -O dts $dtb_in
-       echo '/ { chosen { linux,stdout-path = "'$console'"; }; }; '
-) | dtc -I dts -O dtb -o $dtb_out
-
-[ $? = 0 ] && mv $dtb_out $dtb_in