From patchwork Tue Jul 3 06:34:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeremy Kerr X-Patchwork-Id: 938406 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41KZDq2QSGz9s29 for ; Tue, 3 Jul 2018 16:37:47 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 41KZDq0vlyzF1Nr for ; Tue, 3 Jul 2018 16:37:47 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral X-Original-To: petitboot@lists.ozlabs.org Delivered-To: petitboot@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 41KZDF6v1czF1LK for ; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.b="DG8vynoe"; dkim-atps=neutral Received: by ozlabs.org (Postfix, from userid 1023) id 41KZDF5Xs7z9s29; Tue, 3 Jul 2018 16:37:17 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1530599837; bh=9MmWW3eAAPP5Gjmb5kmHCBvT8joBoyWre9GkndCs5I4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DG8vynoep9uERxibFwaF46hYUmq4i+3j947fHBbUAhC8au21Tq3JiZijS23H58VFk bX+bLemYj6r8y0nY8ldMkOSAh1qBHjYTcV7z4T96D4QWmUIIXq8MwG5PeGXNZrsis0 0oZz/lqNbRPSzyYD3JAMgLEXzXnA/8a/ldI5SxHWnEPqrVY7shJrZBIdHgGzndaFWN yiYIqpdmQ/LHEqJYlMdquvsEFBikVIlJ/sO/ftzqQ6nk6Za+BVQx9bNpGjzwNqtkKP UFBKCPAIC7HbkK6mbVoQP78e/nIvDEnRRlboIvKdruBJw6mDyS+Qf0F02L/C/gS9Wi iWU8nFdqHc+lQ== From: Jeremy Kerr To: petitboot@lists.ozlabs.org Subject: [PATCH 5/5] ui/ncurses: Implement F10-F12 for autoboot device control Date: Tue, 3 Jul 2018 16:34:47 +1000 Message-Id: <20180703063447.8338-6-jk@ozlabs.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180703063447.8338-1-jk@ozlabs.org> References: <20180703063447.8338-1-jk@ozlabs.org> X-BeenThere: petitboot@lists.ozlabs.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: Petitboot bootloader development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yewei@inspur.com MIME-Version: 1.0 Errors-To: petitboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Petitboot" Add a few mappings to specify temporary autoboot settings: F10: Only autoboot from disk F11: Only autoboot from USB devices F12: Only autoboot from network These use the new code to prevent cancelling autoboot. Signed-off-by: Jeremy Kerr --- discover/device-handler.c | 25 +++++++++++++++++++++ ui/common/discover-client.c | 18 +++++++++++++++ ui/common/discover-client.h | 4 ++++ ui/ncurses/nc-cui-help.c | 9 ++++++++ ui/ncurses/nc-cui.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ ui/ncurses/nc-cui.h | 1 + 6 files changed, 112 insertions(+) diff --git a/discover/device-handler.c b/discover/device-handler.c index 3d75e57..0a93a06 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -916,13 +916,38 @@ static void set_default(struct device_handler *handler, default_timeout(handler); } +static char *autoboot_option_desc(void *ctx, const struct autoboot_option *opt) +{ + const char *type, *val; + + if (opt->boot_type == BOOT_DEVICE_TYPE) { + type = _("device type"); + val = device_type_display_name(opt->type); + } else if (opt->boot_type == BOOT_DEVICE_UUID) { + type = _("device UUID"); + val = opt->uuid; + } else { + type = _("unknown specifier"); + val = NULL; + } + + return talloc_asprintf(ctx, "%s = %s", type, val); +} + void device_handler_apply_temp_autoboot(struct device_handler *handler, struct autoboot_option *opt) { unsigned int i; + char *desc; handler->temp_autoboot = talloc_steal(handler, opt); + desc = autoboot_option_desc(handler, opt); + device_handler_status_info(handler, + _("Applying temporary autoboot override: %s"), + desc); + talloc_free(desc); + if (!handler->autoboot_enabled) return; diff --git a/ui/common/discover-client.c b/ui/common/discover-client.c index 784154e..88d0b4e 100644 --- a/ui/common/discover-client.c +++ b/ui/common/discover-client.c @@ -453,3 +453,21 @@ int discover_client_send_plugin_install(struct discover_client *client, return pb_protocol_write_message(client->fd, message); } + +int discover_client_send_temp_autoboot(struct discover_client *client, + const struct autoboot_option *opt) +{ + struct pb_protocol_message *message; + int len; + + len = pb_protocol_temp_autoboot_len(opt); + + message = pb_protocol_create_message(client, + PB_PROTOCOL_ACTION_TEMP_AUTOBOOT, len); + if (!message) + return -1; + + pb_protocol_serialise_temp_autoboot(opt, message->payload, len); + + return pb_protocol_write_message(client->fd, message); +} diff --git a/ui/common/discover-client.h b/ui/common/discover-client.h index 7224691..2a2ea28 100644 --- a/ui/common/discover-client.h +++ b/ui/common/discover-client.h @@ -102,4 +102,8 @@ int discover_client_send_url(struct discover_client *client, char *url); int discover_client_send_plugin_install(struct discover_client *client, char *file); +/* send a temporary autoboot override */ +int discover_client_send_temp_autoboot(struct discover_client *client, + const struct autoboot_option *opt); + #endif diff --git a/ui/ncurses/nc-cui-help.c b/ui/ncurses/nc-cui-help.c index 7d97ba5..0e57b77 100644 --- a/ui/ncurses/nc-cui-help.c +++ b/ui/ncurses/nc-cui-help.c @@ -26,5 +26,14 @@ option.\n\ To retreive new boot options from a remote configuration file, select \ the 'Retrieve config from URL' option.\n\ \n\ +To restrict petitboot to only autobooting from a specific device type, the \ +following keys are available:\n\ +\n\ + F10: Only autoboot from disk\n\ + F11: Only autoboot from USB devices\n\ + F12: Only autoboot from network\n\ +\n\ +Unlike other keys, these do not cancel automatic boot.\n\ +\n\ To close the Petitboot interface, type X (exit).\n" ); diff --git a/ui/ncurses/nc-cui.c b/ui/ncurses/nc-cui.c index 87540ca..87d2503 100644 --- a/ui/ncurses/nc-cui.c +++ b/ui/ncurses/nc-cui.c @@ -59,6 +59,27 @@ static struct pmenu *plugin_menu_init(struct cui *cui); static void cui_cancel_autoboot_on_exit(struct cui *cui); +static struct { + int key; + struct autoboot_option opt; +} autoboot_override_keys[] = { + { KEY_F(10), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_DISK, + }, + }, + { KEY_F(11), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_USB, + }, + }, + { KEY_F(12), { + .boot_type = BOOT_DEVICE_TYPE, + .type = DEVICE_TYPE_NETWORK, + }, + }, +}; + static bool lockdown_active(void) { #if defined(SIGNED_BOOT) && defined(HARD_LOCKDOWN) @@ -527,22 +548,50 @@ struct nc_scr *cui_set_current(struct cui *cui, struct nc_scr *scr) return old; } +static bool set_temp_autoboot_opt(struct cui *cui, struct autoboot_option *opt) +{ + cui->autoboot_opt = opt; + if (cui->client) + discover_client_send_temp_autoboot(cui->client, opt); + + return true; +} + static bool key_cancels_boot(int key) { + unsigned int i; + if (key == 0xc) return false; + for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++) + if (key == autoboot_override_keys[i].key) + return false; + return true; } static bool process_global_keys(struct cui *cui, int key) { + unsigned int i; + switch (key) { case 0xc: if (cui->current && cui->current->main_ncw) wrefresh(curscr); return true; } + + /* check for autoboot override keys */ + for (i = 0; i < ARRAY_SIZE(autoboot_override_keys); i++) { + if (key != autoboot_override_keys[i].key) + continue; + + pb_log("Sending temporary autoboot override\n"); + set_temp_autoboot_opt(cui, &autoboot_override_keys[i].opt); + return true; + } + return false; } @@ -1428,6 +1477,12 @@ static int cui_server_wait(void *arg) pb_log("Aborting default boot on pb-discover connect\n"); discover_client_cancel_default(cui->client); } + + if (cui->autoboot_opt) { + pb_log("Sending autoboot override on pb-discover connect\n"); + discover_client_send_temp_autoboot(cui->client, + cui->autoboot_opt); + } } return 0; diff --git a/ui/ncurses/nc-cui.h b/ui/ncurses/nc-cui.h index b310f4a..4997f4b 100644 --- a/ui/ncurses/nc-cui.h +++ b/ui/ncurses/nc-cui.h @@ -52,6 +52,7 @@ struct cui_opt_data { struct cui { enum pb_nc_sig c_sig; bool has_input; + struct autoboot_option *autoboot_opt; sig_atomic_t abort; sig_atomic_t resize; struct nc_scr *current;