From patchwork Mon May 16 11:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 572966 Delivered-To: patch@linaro.org Received: by 2002:a5d:5051:0:0:0:0:0 with SMTP id h17csp499444wrt; Mon, 16 May 2022 04:01:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuGnZsKOmp1YaCaGZcMQ7wSfmI6jmiYSsjoGB2wSG6C1PtFSdkVDpSpikFbIC+tN6dxntR X-Received: by 2002:a2e:b8cc:0:b0:24f:501b:af80 with SMTP id s12-20020a2eb8cc000000b0024f501baf80mr10947698ljp.328.1652698872132; Mon, 16 May 2022 04:01:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652698872; cv=none; d=google.com; s=arc-20160816; b=lfKg96GM7iG7rmjZsghpxUWx1I2MSJRmZnecqFR/56kSxw/qhmWTse5UNWDWwVJsv7 Dodjzkr4n4IiCK/Xs8GVzVgZOXUXAvPPiY4SBVVXrIfrmT+V3ozGfYO6d6PTw/o9Bk53 kloGj26WxZ8zUYwBjJGedLTSNnbFFrByYdKpHuUl/8j55nrnBVz71tbtttBbTmjoqNx7 b+VHrY8nTdGNIUEI7b3aWS9dw67fg8Pzy2/fCAf7NNY3derAYyZ2iJTKoc7AlU5iAFQS lwdpK5Y8ghdvsD2j+pRj6/QK91EH0X8YlA+MeP5SdDSZIGKAkKhPh6tn1i91C0L8KWWv HgjA== 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=ifhMVyuup3/BtDvzEmObvgR+zLMyrl4yM0ZoKj2cHmw=; b=v+mF5tZfpcyz+E5uyjtRgkLqDIsAGj0JMinMDW3fV3EBPTr0jl2rQUqJPYiYlifgnV GEBFinRTGZtMH0gp10XzQxBldgIDbHsf0zPLdoLK8eVPHS1Ch+9fgr+UiqWY4fQIFSFA SmLrDJwlb8HFpKagQyJZABKN20PE9n8QqScMOO9BD3fTNIuyvEMqHCGGtov7qalS2cRl JxDk1aE0pHMLEUlNriftSPCo2/wQfi6IvLoNzNNHuCf3vkXh8mrx1NrRZt4VZcd0PkOa XiIrdlpdHNV8Z8Cf0fkhpMX9yEZOkIdEE8cL/YkqhdrgKBhijndd6IBoBlc0vfJkW9fc z/Ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LSs6VBfU; 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 a11-20020a05651c210b00b0024952f7bd21si12794414ljq.636.2022.05.16.04.01.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 04:01:12 -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=LSs6VBfU; 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 2E87484239; Mon, 16 May 2022 13:01:03 +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="LSs6VBfU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4DC1484245; Mon, 16 May 2022 13:00:49 +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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (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 04D44840DF for ; Mon, 16 May 2022 13:00:34 +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-x62b.google.com with SMTP id q4so14049936plr.11 for ; Mon, 16 May 2022 04:00:33 -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=ifhMVyuup3/BtDvzEmObvgR+zLMyrl4yM0ZoKj2cHmw=; b=LSs6VBfUpcIiB93gERD4LeZ5CW/jNf7bt6hqqu3ad+UN6/NRGdLPpBjLeE+AjWvj39 7or0ulzuTYDFaYUVSGNGt32LUEcCdZLRKn63OOldeDV9/JeW2ZG5ApAtoGFpRILX3+oT xp6f2TXO0Zbcvem25ckhBfmNygHE41/6xKdywHn9BsviQUwsF7ELEUZW6rAfaZp2j4Oa ZlkNTHXGG14v/8BslFwG27lQ7jopB2d6PkR6WsJPGod9nPYqVXkxU+LkATQANrk7ay5J BmWBMMOyHSJPIkzT3xikX2hZXogzajPl/sL7v1P6R8SJb7o4hCiVXIrnq3Df/1PT+4cq 7CjQ== 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=ifhMVyuup3/BtDvzEmObvgR+zLMyrl4yM0ZoKj2cHmw=; b=CWSStSegqwgYiigo3tP+SKL9T5cTKcB2xMjaIz2e0xokbahcqwu3+J1wRwz3mvA6kh AL6bZIvyfM4bCkvq2wV+Vll3QTi9sLDXg/1L7Z3BuVRjNtABwbEO4PcAaDnBp/uFZ2F/ FIWKHL+1NHMvoqGIXSX5+Ip3JvryKTE6T/GoG3oQ8sNFCwrwfq3ABFVo+NxxFaBYGVhO d0bGAcRIB0//89ZAh0og8wjdOwBi/YJSmYW5CXxnqKiRCuT1vVvH0n1VG1+njFHGXmTc RvipumNz6au2vsu6+VPIMnUIclP2DjGOu6Al80QZZOIszPGPtLsT4dIXPrifxdI+/Tr+ Kx6g== X-Gm-Message-State: AOAM531nh5qhc2CHXl+WDiu2HVl3YJP/tQqzFq+3t/NN0gJY9mwpQeU/ FRnGyxL0/DDRXySWB0q6X5d/trJrhfFLFQ== X-Received: by 2002:a17:90b:1bd1:b0:1dc:7118:cf28 with SMTP id oa17-20020a17090b1bd100b001dc7118cf28mr19131432pjb.3.1652698831951; Mon, 16 May 2022 04:00:31 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q2-20020a170902edc200b0016173113c50sm2446480plk.92.2022.05.16.04.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 May 2022 04:00:31 -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 v6 3/6] efi_loader: menu-driven update of UEFI bootorder variable Date: Mon, 16 May 2022 20:00:39 +0900 Message-Id: <20220516110043.31480-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220516110043.31480-1-masahisa.kojima@linaro.org> References: <20220516110043.31480-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 --- (no update since v5) 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 96306cd2cc..be67fca95f 100644 --- a/lib/efi_loader/efi_bootmenu_maintenance.c +++ b/lib/efi_loader/efi_bootmenu_maintenance.c @@ -746,6 +746,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; @@ -996,6 +1046,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; @@ -1025,6 +1126,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}, };