From patchwork Mon Jun 13 09:38:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahisa Kojima X-Patchwork-Id: 581412 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5806:0:0:0:0 with SMTP id j6csp1797850max; Mon, 13 Jun 2022 02:38:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1Ry1Kh0wn2D720f5S0Pu48qlM9iAcc3qDj03Zii25y3onPikOO8itNMjxrebcl/bD+4w9 X-Received: by 2002:a05:6638:13cc:b0:331:7c5e:6124 with SMTP id i12-20020a05663813cc00b003317c5e6124mr25440253jaj.83.1655113129795; Mon, 13 Jun 2022 02:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655113129; cv=none; d=google.com; s=arc-20160816; b=dFCvXqd8FxxL16E7cwFMiGfqz5k4IwxNl4ZCwOa/owgFsvfttZknRPInX+6eUMdxRv jcSs2gOwX7fFoWEdIVoZs1IP4xJWgLbhATMDA66JQMQvPpkqwwKkkCALkJrit2QclDN/ FzI1bTYBX3xEIJt0UAUisBqMRMBk+1sPeFykHGuxeUtKk0FXkaUt4IsEIn9EHu6ri5Hu xRguNp0NfanpIX3XFN0Hrprg6wmjcdHdxC5RcGR4AFuFFkBIW0PO1IKX+ueCzdxjs4bC dayq0r7C082DpD/vSF7AO38LL1h5iNKFNiuxSTt1MhDSckdCuaV0ht5nh1t5Zxbm6SnW sefA== 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=IykigmOgQXbpm1uZ4F94KFNVdQgAZf3SDno6DR/ENqI=; b=CD5+OTh9hcLnUE1+votmCD1c5uEVYkdRUmlJngn7/4a2k8wq/HSvefPODxHAtdHKkB GhLxM9tlUCyauefdJSMHZqHhqfaBMkm1nIcjDH/rH8bWGWk4jYG0hfrOAKldPyMeXtr0 YhXvZGCBCbBTfJruBJMufsMdTRFg2WedWT0iBIShZntS88Io4UBOkaVwDqIAtR5+301W farVjvVY/NvyWYb5XD1o4aefWMjPo3EMoXPF6hj/zC6IMfkl+TeeT1jK2iqjIiqMn5GD CQTPPUgNJvuTf7BnOKmKwvvT33TIcAwmLtZ5AItCAOGOMgGeDb9E8yVzk46xiWCjwPJG DLsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cdQIPEtI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id k25-20020a6b6f19000000b00665e06dd40esi7519100ioc.96.2022.06.13.02.38.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 02:38:49 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cdQIPEtI; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 2DC1784447; Mon, 13 Jun 2022 11:38:33 +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="cdQIPEtI"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 8F68784442; Mon, 13 Jun 2022 11:38:30 +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-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 895C284439 for ; Mon, 13 Jun 2022 11:38:26 +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-pj1-x102d.google.com with SMTP id o6-20020a17090a0a0600b001e2c6566046so8335999pjo.0 for ; Mon, 13 Jun 2022 02:38:26 -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=IykigmOgQXbpm1uZ4F94KFNVdQgAZf3SDno6DR/ENqI=; b=cdQIPEtIZ7d36dKyyCsDzCuYnqWD1pS026+aolTErnqW/fMEV+UcJFPyL+VBEckxuv ciWxRHJnqUoCzK66D5ocfIsemgdS/WC7GXcGi+kCWw+C5mvOZWjpOzsC3NwICRcrAetB 3zdX29G14qn5jyTXX1LgMMcksFPeyF6olM6PA/Cf7e3ZKTwfgw/W1lzOU7Baffdudhnf BCA+CaKkr1nMp5CJLbSk0iPuyKaHJ9zt3m4Uipv3WFYkYeuBL+K9GSos3DHrtPUbykzE VEtDR6mpsxY2WRSgWlSKP/R+1/N/6PwVL5L45baofdWnUsLlkAMKgs1H/yL1ZEfsMAaO cdkQ== 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=IykigmOgQXbpm1uZ4F94KFNVdQgAZf3SDno6DR/ENqI=; b=CMpp4ZJE94H6aTOkROYixursa7bml8zalSpw+zavTO9MaolzLI6VBmMZNTdlVolDig DnVLPcEWVbb6P8fKoqkdc1+UL102u8CgAO2Yd+3/ngNqXkrrgT57gcj1tPcJaVJBbH0+ mWnxliDuFy9HJAF4CwhBXaF7mCOWRIL4oxgxQCcg5sE5dOa6+/qUs7DmfAZ1Fk6Mp+Mu rym2a/+sGrfzir5gDHV6F420kYgK2QXuuJQmzNRrooc6vECNNl/uA7n2wwTjw7u1BKA3 /5ujM+3lbooOd7ULWrg8DvQPf4lrBPN5aG2UntnNx84E7KstokzWZqT4Nv55SM/JilTJ hWQw== X-Gm-Message-State: AOAM531eyV0ZiS/RELOYTIR2t0M0bRZab1S0qxny3ucBUX/2rcPtznUn LdV/UI3gTbtRSLleMmgByh67TNmG59Si1Q== X-Received: by 2002:a17:903:32c4:b0:167:6e6f:204b with SMTP id i4-20020a17090332c400b001676e6f204bmr43480245plr.117.1655113104708; Mon, 13 Jun 2022 02:38:24 -0700 (PDT) Received: from localhost.localdomain ([240d:1a:cf7:5800:82fa:5bff:fe4b:26b1]) by smtp.gmail.com with ESMTPSA id q6-20020a170902a3c600b00163f7935772sm4629227plb.46.2022.06.13.02.38.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jun 2022 02:38:24 -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 v7 3/9] efimenu: add "Edit Boot Option" menu entry Date: Mon, 13 Jun 2022 18:38:47 +0900 Message-Id: <20220613093853.23865-4-masahisa.kojima@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220613093853.23865-1-masahisa.kojima@linaro.org> References: <20220613093853.23865-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 entry to edit the existing BOOT#### variable contents. User selects the item from the boot option list, then user can edit the description, file path and optional_data. Note that automatically generated boot option entry by bootmenu to suppport the removable media device is filtered out and user can not edit the automatically generated entry. Signed-off-by: Masahisa Kojima --- Newly created in v7 cmd/efimenu.c | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/cmd/efimenu.c b/cmd/efimenu.c index fce08900db..918e9dffa2 100644 --- a/cmd/efimenu.c +++ b/cmd/efimenu.c @@ -1190,6 +1190,175 @@ out: return ret; } +static efi_status_t efimenu_process_boot_selected(void *data) +{ + struct efimenu_boot_selection_data *info = data; + + if (info) + *info->selected = info->bootorder_index; + + return EFI_SUCCESS; +} + +static efi_status_t efimenu_show_boot_selection(u16 *bootorder, efi_uintn_t count, + int *selected) +{ + u32 i; + efi_status_t ret; + efi_uintn_t size, actual_count = 0; + void *load_option; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + struct efimenu_item *menu_item, *iter; + + menu_item = calloc(count + 1, sizeof(struct efimenu_item)); + if (!menu_item) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + iter = menu_item; + for (i = 0; i < count; i++) { + efi_create_indexed_name(varname, sizeof(varname), + "Boot", bootorder[i]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) + continue; + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + log_warning("Invalid load option for %ls\n", varname); + free(load_option); + continue; + } + + if (size >= sizeof(efi_guid_t) && + !guidcmp(lo.optional_data, &efi_guid_bootmenu_auto_generated)) { + /* + * auto generated entry has GUID in optional_data, + * skip auto generated entry because it will be generated + * again even if it is edited or deleted. + */ + free(load_option); + continue; + } + + if (lo.attributes & LOAD_OPTION_ACTIVE) { + char *buf, *p; + struct efimenu_boot_selection_data *info; + + info = calloc(1, sizeof(struct efimenu_boot_selection_data)); + if (!info) { + free(load_option); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + buf = calloc(1, utf16_utf8_strlen(lo.label) + 1); + if (!buf) { + free(load_option); + free(info); + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + p = buf; + utf16_utf8_strcpy(&p, lo.label); + info->bootorder_index = i; + info->selected = selected; + iter->title = buf; + iter->func = efimenu_process_boot_selected; + iter->data = info; + iter++; + actual_count++; + } + free(load_option); + } + + /* add "Quit" entry */ + iter->title = strdup("Quit"); + iter->func = efimenu_process_quit; + iter->data = NULL; + actual_count += 1; + + ret = efimenu_process_common(menu_item, actual_count, " ** Select Boot Order **"); + +out: + iter = menu_item; + for (i = 0; i < actual_count; i++, iter++) { + free(iter->title); + free(iter->data); + } + + free(menu_item); + + return ret; +} + +static efi_status_t efimenu_process_edit_boot_option(void *data) +{ + u16 *bootorder; + efi_status_t ret; + efi_uintn_t num, size; + struct efimenu_boot_option *bo = NULL; + + bootorder = efi_get_var(u"BootOrder", &efi_global_variable_guid, &size); + if (!bootorder) { + ret = EFI_NOT_FOUND; + return ret; + } + + num = size / sizeof(u16); + while (1) { + int selected; + void *load_option; + struct efi_load_option lo; + u16 varname[] = u"Boot####"; + + ret = efimenu_show_boot_selection(bootorder, num, &selected); + if (ret != EFI_SUCCESS) + break; + + bo = calloc(1, sizeof(struct efimenu_boot_option)); + if (!bo) { + ret = EFI_OUT_OF_RESOURCES; + goto out; + } + + bo->boot_index = selected; + efi_create_indexed_name(varname, sizeof(varname), + "Boot", bootorder[selected]); + load_option = efi_get_var(varname, &efi_global_variable_guid, &size); + if (!load_option) { + free(bo); + ret = EFI_NOT_FOUND; + goto out; + } + + ret = efi_deserialize_load_option(&lo, load_option, &size); + if (ret != EFI_SUCCESS) { + free(bo); + free(load_option); + goto out; + } + + ret = efimenu_edit_boot_option(varname, bo, lo.label, lo.optional_data, + size, lo.file_path); + + free(load_option); + free(bo); + if (ret != EFI_SUCCESS && ret != EFI_ABORTED) + break; + } + +out: + free(bootorder); + + /* to stay the parent menu */ + ret = (ret == EFI_ABORTED) ? EFI_NOT_READY : ret; + + return ret; +} + static efi_status_t efimenu_init(void) { efi_status_t ret; @@ -1223,6 +1392,7 @@ static efi_status_t efimenu_init(void) static const struct efimenu_item maintenance_menu_items[] = { {"Add Boot Option", efimenu_process_add_boot_option}, + {"Edit Boot Option", efimenu_process_edit_boot_option}, {"Quit", efimenu_process_quit}, };