From patchwork Thu Apr 28 08:09:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 567141 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp5234042map; Thu, 28 Apr 2022 01:14:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLJYd6Q6pVZhyIyy1tJotoKj4N7yks9uEeDFCYxsnIkaIFmMWJ8buyxxqPcri9PosUm8P1 X-Received: by 2002:a05:6402:1850:b0:425:f2e2:2594 with SMTP id v16-20020a056402185000b00425f2e22594mr17561884edy.3.1651133654069; Thu, 28 Apr 2022 01:14:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651133654; cv=none; d=google.com; s=arc-20160816; b=uzeA4jDgkul2cu5M8J0TKBHD1VTt3M+rz4AvQZaiIY7emlraJy5htJY2xNE4BBb5q8 cJgD6qfhfMf6UYzH1cs5YiI7MQA9xZm54QiaZ55GyMoxMGIkc4aSOZv6ZHWvP6pCZhcy M2WLYDjFeHbF7sZ1zF/EuBeLizG3hdoX+bku8RoDlpcTBPgNrCKSI1TmknkDtHtq3ui5 r57de9Gv9KEv20ke8dgYhQQXXTiva5sSFE9bBEnGA9NyQGayUtw+W6gbcb+IdN20UiVJ 6O4On/XCoy6f9UZEIMUaxtLBaugl+/Z3ggHfUFPQ4LsikRQ6UEaOiGWCqRieWKKVQAq5 4vTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=iKVe0Cu41bsyIFo0sDuKev4Fa1eoKYlqHnpLTZDzMaA=; b=q4b/rfMWNGMjeINKCgcJqfOy4m8jUQCJ1CULRDJWmSmW89OiY9GmCo22nR1uHo9Mzu q4eW923AERZFNAyF6NogaySVgMq/XH5hOXSHdipeF2Fwuqpym0CJ2zt69mu2L5EhPcLp ZqVPW03R1mU7uebxq+ZZgQMj71oeBNe7sw41cZM+PpU6u3FGg9OiyD0dp4nyujn9DSls iAynwquPAf4Mr+CiZCDfYATgI+z/DXpM3T6NbGoPyDU8izWhNfHb02O+k6acudidvKa2 p9oSELJ49ZTeRARhCIGHO0ES2aBYkhtF6U89ZW2AfMJE2yYfySui65wOy8Y+ZXfdX+P2 PFow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kiCjO3dJ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id gf25-20020a170906e21900b006e48d161aaasi3277578ejb.213.2022.04.28.01.14.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:14:14 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kiCjO3dJ; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 07B5083F0A; Thu, 28 Apr 2022 10:12:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="kiCjO3dJ"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5577483EDF; Thu, 28 Apr 2022 10:11:38 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0CFEB83ED7 for ; Thu, 28 Apr 2022 10:11:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=masahisa.kojima@linaro.org Received: by mail-pl1-x62c.google.com with SMTP id n18so3693989plg.5 for ; Thu, 28 Apr 2022 01:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=iKVe0Cu41bsyIFo0sDuKev4Fa1eoKYlqHnpLTZDzMaA=; b=kiCjO3dJ74DggUmxPuO3foZf6TGhSyaL+537pC9dyn2flqX8WyvkCW77L/nKy/XUbk Cjr+ZjuFvcBsnHVzQthFW7J8BF7k3Z3FofXkhFxZYYxJ5P0bJ1YCrmyWtKpMteajf9yx mB2Sn3rRZ68qun5Zs5wuLmrlVGx1gzgGzusUpz3DpwMGPtalutIyMQzqFupbXFFO74be x0R2qsLrWuP5J/PU8nMeVK3TxWepjMJVEVa9Fp4kaneqlibzNreIZ4dg7cUwyWcwyzLg NTWpZIWyutMT9bARvWtWqG947RGJNugW1QoV4NXgoY3YtKQwgBhJS0J2HFlYCKocmpt0 cUPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=iKVe0Cu41bsyIFo0sDuKev4Fa1eoKYlqHnpLTZDzMaA=; b=nKM3ZWNRNhAgonq6zQv6X77hTh1n4F2/LclXBKMCVBEco4E6un1DmGg+zD21BgaRIz z4eFecBsM0EXChTvqiRW+JWCR6fl8VDuYjz4cd97SuC2fJG51zVHpgCN74YU3MdgmiIp 07xHtpX+VCalsEg0Kx9oBnNHoAYr5rPI3kJMQpsnsJvVua7Yrjv3rCEEq/joyqCq1GQn jQi+gzY5EFnN44KRMI1gnrOqNAYXXQfoQE4Cq/ot9jE8u5XttxFqEcoSyiPRrMz3TAIz qu5REnHCzpbwLFLxY5qpWH8PGC0auqnG1t+T0qJ4OA3e12+zPTjCyiJGxAGvPr1D7TJM nwmQ== X-Gm-Message-State: AOAM530adrMpsJKjhH6FFLafOipGbCWxtMkFsPF7iBYFN5jDR4ztKHnQ 4wylmGinBmVCkV9/x0pzNlRlXB61kYm3vQ== X-Received: by 2002:a17:90a:ab90:b0:1da:375f:2f44 with SMTP id n16-20020a17090aab9000b001da375f2f44mr8180160pjq.33.1651133479303; Thu, 28 Apr 2022 01:11:19 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id b15-20020a17090a7acf00b001cd4989ff5fsm5684259pjl.38.2022.04.28.01.11.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 01:11:18 -0700 (PDT) From: Masahisa Kojima To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Takahiro Akashi , Francois Ozog , Mark Kettenis , Masahisa Kojima Subject: [PATCH v5 15/17] efi_loader: menu-driven update of UEFI bootorder variable Date: Thu, 28 Apr 2022 17:09:48 +0900 Message-Id: <20220428080950.23509-16-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220428080950.23509-1-masahisa.kojima@linaro.org> References: <20220428080950.23509-1-masahisa.kojima@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean This commit adds the menu-driven update of UEFI bootorder variable. Signed-off-by: Masahisa Kojima --- Changes in v5: - split into the separate patch lib/efi_loader/efi_bootmenu_maintenance.c | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/lib/efi_loader/efi_bootmenu_maintenance.c b/lib/efi_loader/efi_bootmenu_maintenance.c index 26320a8b73..8c3f94c695 100644 --- a/lib/efi_loader/efi_bootmenu_maintenance.c +++ b/lib/efi_loader/efi_bootmenu_maintenance.c @@ -719,6 +719,56 @@ static efi_status_t efi_bootmenu_boot_add_enter_name(struct efi_bootmenu_boot_op return ret; } +static efi_status_t allow_decimal(struct efi_input_key *key) +{ + if (u'0' <= key->unicode_char && key->unicode_char <= u'9') + return EFI_SUCCESS; + + return EFI_INVALID_PARAMETER; +} + +static efi_status_t efi_bootmenu_change_boot_order(int selected, int max, int *new) +{ + efi_status_t ret; + u16 new_order[EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL] = {0}; + + printf(ANSI_CURSOR_POSITION, 2, 1); + puts(" *** U-Boot EFI Boot Manager Menu ***"); + printf(ANSI_CURSOR_POSITION, 4, 1); + printf(" current boot order : %d", selected); + + printf(ANSI_CURSOR_POSITION, 6, 1); + printf(" new boot order(0 - %4d): ", max); + + printf(ANSI_CURSOR_POSITION, 8, 1); + puts(" ENTER to complete, ESC/CTRL+C to quit"); + + printf(ANSI_CURSOR_POSITION, 6, 29); + puts(ANSI_CURSOR_SHOW); + + for (;;) { + memset(new_order, 0, sizeof(new_order)); + ret = efi_console_get_u16_string(cin, cout, new_order, 6, allow_decimal, 6, 29); + if (ret == EFI_SUCCESS) { + int i; + int val = 0; + + for (i = 0; + i < u16_strnlen(new_order, EFI_BOOT_ORDER_MAX_SIZE_IN_DECIMAL - 1); + i++) + val = (val * 10) + (new_order[i] - u'0'); + + if (val > max) + continue; + + *new = val; + return EFI_SUCCESS; + } else { + return ret; + } + } +} + static efi_status_t efi_bootmenu_select_file_handler(struct efi_bootmenu_boot_option *bo) { efi_status_t ret; @@ -958,6 +1008,57 @@ static efi_status_t efi_bootmenu_process_delete_boot_option(void *data, bool *ex return ret; } +static efi_status_t efi_bootmenu_process_change_boot_order(void *data, bool *exit) +{ + int selected; + int new_order; + efi_status_t ret; + efi_uintn_t num, size; + u16 *bootorder = NULL; + u16 *new_bootorder = NULL; + + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) + return EFI_NOT_FOUND; + + num = size / sizeof(u16); + ret = efi_bootmenu_show_boot_selection(bootorder, num, &selected); + if (ret != EFI_SUCCESS) + goto out; + + ret = efi_bootmenu_change_boot_order(selected, num - 1, &new_order); + if (ret != EFI_SUCCESS) + goto out; + + new_bootorder = calloc(1, size); + if (!new_bootorder) + goto out; + + memcpy(new_bootorder, bootorder, size); + if (selected > new_order) { + new_bootorder[new_order] = bootorder[selected]; + memcpy(&new_bootorder[new_order + 1], &bootorder[new_order], + (selected - new_order) * sizeof(u16)); + } else if (selected < new_order) { + new_bootorder[new_order] = bootorder[selected]; + memcpy(&new_bootorder[selected], &bootorder[selected + 1], + (new_order - selected) * sizeof(u16)); + } else { + /* nothing to change */ + goto out; + } + ret = efi_set_variable_int(u"BootOrder", &efi_global_variable_guid, + EFI_VARIABLE_NON_VOLATILE | + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, + size, new_bootorder, false); +out: + free(new_bootorder); + free(bootorder); + + return ret; +} + static efi_status_t efi_bootmenu_init(void) { efi_status_t ret; @@ -987,6 +1088,7 @@ static efi_status_t efi_bootmenu_init(void) static const struct efi_bootmenu_item maintenance_menu_items[] = { {u"Add Boot Option", efi_bootmenu_process_add_boot_option}, {u"Delete Boot Option", efi_bootmenu_process_delete_boot_option}, + {u"Change Boot Order", efi_bootmenu_process_change_boot_order}, {u"Quit", NULL}, };