Navigation Menu

Skip to content

Commit

Permalink
ui/ncurses: Add preboot check option in the config screen
Browse files Browse the repository at this point in the history
Petitboot might run some checks to validate the kernel images before
call the kexec load. This patch adds both 'preboot check' option in the
config UI screen and a NVRAM variable 'petitboot,preboot-check' to make
the user choice persistent.

The 'preboot check' is enabled by default. The 'petitboot,preboot-check'
is created on NVRAM only when 'preboot check' is disabled by the user.

NVRAM property changed to preboot-check, small label changes and help
text added by Jeremy Kerr <jk@ozlabs.org>.

Signed-off-by: Maxiwell S. Garcia <maxiwell@linux.ibm.com>
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
  • Loading branch information
maxiwell authored and jk-ozlabs committed Jan 25, 2020
1 parent 0c07402 commit 3513c7f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
7 changes: 7 additions & 0 deletions discover/platform-powerpc.c
Expand Up @@ -222,6 +222,13 @@ static void params_update_all(struct param_list *pl,

params_update_network_values(pl, "petitboot,network", config);
params_update_bootdev_values(pl, "petitboot,bootdevs", config);

if (config->preboot_check_enabled == defaults->preboot_check_enabled)
val = "";
else
val = config->preboot_check_enabled ? "true" : "false";

param_list_set_non_empty(pl, "petitboot,preboot-check", val, true);
}

static void config_set_ipmi_bootdev(struct config *config, enum ipmi_bootdev bootdev,
Expand Down
4 changes: 4 additions & 0 deletions discover/platform.c
Expand Up @@ -159,6 +159,7 @@ void config_set_defaults(struct config *config)
else
config->lang = NULL;

config->preboot_check_enabled = true;
}

int platform_init(void *ctx)
Expand Down Expand Up @@ -572,6 +573,9 @@ void config_populate_all(struct config *config, const struct param_list *pl)
val = param_list_get_value(pl, "petitboot,https_proxy");
if (val)
config->https_proxy = talloc_strdup(config, val);

val = param_list_get_value(pl, "petitboot,preboot-check");
config->preboot_check_enabled = !val || strcmp(val, "false");
}

static char *interface_config_str(void *ctx, struct interface_config *config)
Expand Down
1 change: 1 addition & 0 deletions lib/param_list/param_list.c
Expand Up @@ -23,6 +23,7 @@ const char **common_known_params(void)
"petitboot,http_proxy",
"petitboot,https_proxy",
"petitboot,password",
"petitboot,preboot-check",
NULL,
};

Expand Down
9 changes: 9 additions & 0 deletions lib/pb-protocol/pb-protocol.c
Expand Up @@ -344,6 +344,8 @@ int pb_protocol_config_len(const struct config *config)

len += 4 + optional_strlen(config->lang);

len += 4; /* preboot check */

return len;
}

Expand Down Expand Up @@ -677,6 +679,9 @@ int pb_protocol_serialise_config(const struct config *config,

pos += pb_protocol_serialise_string(pos, config->lang);

*(uint32_t *)pos = config->preboot_check_enabled;
pos += 4;

assert(pos <= buf + buf_len);

return (pos <= buf + buf_len) ? 0 : -1;
Expand Down Expand Up @@ -1335,6 +1340,10 @@ int pb_protocol_deserialise_config(struct config *config,

config->lang = str;

if (read_u32(&pos, &len, &tmp))
goto out;
config->preboot_check_enabled = !!tmp;

rc = 0;

out:
Expand Down
2 changes: 2 additions & 0 deletions lib/types/types.h
Expand Up @@ -187,6 +187,8 @@ struct config {
unsigned int autoboot_timeout_sec;
struct network_config network;

bool preboot_check_enabled;

struct autoboot_option *autoboot_opts;
unsigned int n_autoboot_opts;

Expand Down
8 changes: 7 additions & 1 deletion ui/ncurses/nc-config-help.c
Expand Up @@ -50,4 +50,10 @@ the pb-discover server will use these details.\n"
"\n"
"Disk R/W: Certain bootloader configurations may request write access to \
disks to save information or update parameters (eg. GRUB2). "
"Use this option to control access to disks.\n");
"Use this option to control access to disks.\n"
"\n"
"Pre-boot check: Petitboot is able to check a payload for compatibility before \
booting it. If this check fails, petitboot will determine that the payload will \
not properly boot on this platform, and abort the boot. This configuration \
option allows skipping this check.\n"
"");
44 changes: 43 additions & 1 deletion ui/ncurses/nc-config.c
Expand Up @@ -34,7 +34,7 @@
#include "nc-config.h"
#include "nc-widgets.h"

#define N_FIELDS 51
#define N_FIELDS 53

extern struct help_text config_help_text;

Expand Down Expand Up @@ -70,6 +70,8 @@ struct config_screen {
bool ipmi_mailbox;
bool net_override;

bool preboot_check_enabled;

struct {
struct nc_widget_label *autoboot_l;
struct nc_widget_select *autoboot_f;
Expand Down Expand Up @@ -124,6 +126,9 @@ struct config_screen {

struct nc_widget_button *update_password_l;

struct nc_widget_label *preboot_check_l;
struct nc_widget_select *preboot_check_f;

struct nc_widget_label *net_override_l;
struct nc_widget_label *safe_mode;
struct nc_widget_button *ok_b;
Expand Down Expand Up @@ -364,6 +369,9 @@ static int screen_process_form(struct config_screen *screen)
}
}

config->preboot_check_enabled = widget_select_get_value(
screen->widgets.preboot_check_f);

config->safe_mode = false;
rc = cui_send_config(screen->cui, config);
talloc_free(config);
Expand Down Expand Up @@ -735,6 +743,17 @@ static void config_screen_layout_widgets(struct config_screen *screen)
y += 1;
}

wl = widget_label_base(screen->widgets.preboot_check_l);
widget_set_visible(wl, true);
widget_move(wl, y, screen->label_x);

wf = widget_select_base(screen->widgets.preboot_check_f);
widget_set_visible(wf, true);
widget_move(wf, y, screen->field_x);
y += widget_height(wf);

y += 1;

widget_move(widget_button_base(screen->widgets.ok_b),
y, screen->field_x);
widget_move(widget_button_base(screen->widgets.help_b),
Expand Down Expand Up @@ -770,6 +789,15 @@ static void config_screen_autoboot_change(void *arg, int value)
widgetset_post(screen->widgetset);
}

static void config_screen_preboot_check_change(void *arg, int value)
{
struct config_screen *screen = arg;
screen->preboot_check_enabled = !!value;
widgetset_unpost(screen->widgetset);
config_screen_layout_widgets(screen);
widgetset_post(screen->widgetset);
}

static void config_screen_add_device(void *arg)
{
struct config_screen *screen = arg;
Expand Down Expand Up @@ -1196,6 +1224,20 @@ static void config_screen_setup_widgets(struct config_screen *screen,
_("Update system password"), password_click, screen);
#endif

screen->preboot_check_enabled = config->preboot_check_enabled;
screen->widgets.preboot_check_l = widget_new_label(set, 0, 0,
_("Pre-boot check:"));
screen->widgets.preboot_check_f = widget_new_select(set, 0, 0,
COLS - screen->field_x - 1);

widget_select_add_option(screen->widgets.preboot_check_f, 0, _("Disabled"),
!screen->preboot_check_enabled);
widget_select_add_option(screen->widgets.preboot_check_f, 1, _("Enabled"),
screen->preboot_check_enabled);

widget_select_on_change(screen->widgets.preboot_check_f,
config_screen_preboot_check_change, screen);

screen->widgets.ok_b = widget_new_button(set, 0, 0, 10, _("OK"),
ok_click, screen);
screen->widgets.help_b = widget_new_button(set, 0, 0, 10, _("Help"),
Expand Down

0 comments on commit 3513c7f

Please sign in to comment.