From patchwork Tue Jan 15 02:54:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 155600 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4383597jaa; Mon, 14 Jan 2019 18:55:29 -0800 (PST) X-Google-Smtp-Source: ALg8bN5i9goNd5mj+uzs2m1Gr4mQuB4I/5+1WiMC0I3ibd2RJN/7YR4r+Q66ob0Gvu32a0cvWBu+ X-Received: by 2002:a50:ca86:: with SMTP id x6mr1521054edh.287.1547520929616; Mon, 14 Jan 2019 18:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547520929; cv=none; d=google.com; s=arc-20160816; b=JKBr5fO7IgM/1xHI8gRJnRVc5MbuPCpVZ93jsfJuP6yRqCBZgwGFvC5imVOr0eyi/B F/fcB9efVzbx5r7GMN/VXQhmpE5UF1XQBCrCwsVnfBsFViMtHCgRjDzBBnD2zjzsAj/n 05ozBxQ5doLs3r/0pVv/gTgebJZzm4ByV2bNaoN3pnK8ENQ8SPrfCae07qMe4YXWe39/ VotwJW0FYLyCEm++fZUEYknc7lzNv/n7wQCkpbvZtcAx8jDScV6yC1njT+UbJiEzCrm4 9TyHvru5vF05sPuPFSM+XBjthm299Vvmj7eBzLoksWLI2mtiY3PzO4Wvb93NY0yHuTGH uVOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=zaPnT/UgeOTsEN7R3D/8iatQ+s0T+br63n7TSGzAH7o=; b=JMdXIV7xVb4QL9hhxii8H/EwS16oHIs5Irqd/Lfl4lRqjKF+yw8JsTaQOkA1P54SRE L7XwMJpjb5ujtP4Q5OKJIJpY7qK4MP8WPklhKGD2AFe2bR+PF6hCmR7AxcdHW89Vd/S3 ySw9LbYg1n7wXkMIvUGFQd2+x6LJ7tLaPCF49CQKW/CW2ZCqiWVYGgBhd/R42NcXmi0y dJ0ik+EQc7onh66MXNH/9mtFeKF/uA3VDr7OwxDhxuA6Lo7xDBvktsZAom9S8qKNybBk UzHbKjDzuDysevBAo0vMCBMfFPZFSyFNiCx1U8DUv5CYUOfEnIvOHBZhHPrCmK3XJteJ q2QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=J0NXnSV2; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id h4si11300eda.166.2019.01.14.18.55.29; Mon, 14 Jan 2019 18:55:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=J0NXnSV2; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id 21331C21D65; Tue, 15 Jan 2019 02:55:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 41A47C21FBD; Tue, 15 Jan 2019 02:54:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CFBD1C21FC7; Tue, 15 Jan 2019 02:54:38 +0000 (UTC) Received: from mail-yb1-f193.google.com (mail-yb1-f193.google.com [209.85.219.193]) by lists.denx.de (Postfix) with ESMTPS id 40841C22005 for ; Tue, 15 Jan 2019 02:54:38 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id q145so486283ybq.9 for ; Mon, 14 Jan 2019 18:54:38 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=WMjtXav7CB+xiDee0XiwMp4b+bfeGqowvGW1B38iFFw=; b=J0NXnSV2nLmWvBfEx6Tnr12ub2azUSPiPmgNQyClO4BoOHtYyPH1Go/0DKHVjFVDkj YvE8ZhuXLeztl6n02iiT/NQlORuZfKzpkTfxBTLXbwAM1KMcwmsDtTKpVqUlR4wmyREP jZ1WepXTTxTS3ojk1w0GAZUljHDfMSIMlRaeY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WMjtXav7CB+xiDee0XiwMp4b+bfeGqowvGW1B38iFFw=; b=KoAbkVGuDUJRC3FEaYFZ8Ij2mXT1f75tRyzJMP7zL2Kfuecc0uxekXLBXSyxzcZxto ekpH6RDceo/ObswHfumlAhvmwRh5zMI2zx8ia5GQ/y6vSnUTfCAmvcXpANpPiEmNuaia +nMP5oeUUUon0LeKFt6nH3VplpT4Uvw1/8bh1j4deu12Xhlj/hWZbzFzeeVjR2Pmc/K/ a9eMEEPyeCHpfOSlOQXy0SSO9f+BksR4xkIwte99j+R21q/Aj7e0DSE3N/xQjNn5DCdl DUQmBsQtEb7J74T0jfs8RAQ3GGDxlc7Q0Sz48auC1pUC2zoDZnBD8PM+1jy1ywcwMvYX U2mw== X-Gm-Message-State: AJcUukdhKnJuJP293S3TZnl9o68VAUnpumiVYNFye6tr+kUFw+eOQR9C DpwJeVQ3bSvSED/0invRkz/eDg== X-Received: by 2002:a25:dacc:: with SMTP id n195mr1266085ybf.287.1547520876954; Mon, 14 Jan 2019 18:54:36 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v9sm840987ywh.2.2019.01.14.18.54.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 18:54:36 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 15 Jan 2019 11:54:33 +0900 Message-Id: <20190115025437.11966-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190115025437.11966-1-takahiro.akashi@linaro.org> References: <20190115025437.11966-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 1/5] efi_loader: bootmgr: support BootNext and BootCurrent variable behavior X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" See UEFI v2.7, section 3.1.2 for details of the specification. With my efitool command, you can try as the following: => efi boot add 1 SHELL ... => efi boot add 2 HELLO ... => efi boot order 1 2 => efi bootmgr (starting SHELL ...) => efi boot next 2 => efi bootmgr (starting HELLO ...) => efi dumpvar BootCurrent: {boot,run}(blob) 00000000: 02 00 .. BootOrder: {boot,run}(blob) 00000000: 01 00 02 00 .... Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_bootmgr.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index a095df3f540b..6c5303736dc6 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -145,11 +145,21 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, efi_deserialize_load_option(&lo, load_option); if (lo.attributes & LOAD_OPTION_ACTIVE) { + u32 attributes; efi_status_t ret; debug("%s: trying to load \"%ls\" from %pD\n", __func__, lo.label, lo.file_path); + attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS; + size = sizeof(n); + ret = rs->set_variable(L"BootCurrent", + (efi_guid_t *)&efi_global_variable_guid, + attributes, size, &n); + if (ret != EFI_SUCCESS) + goto error; + ret = efi_load_image_from_path(lo.file_path, &image); if (ret != EFI_SUCCESS) @@ -173,16 +183,38 @@ error: void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path) { - uint16_t *bootorder; + u16 bootnext, *bootorder; efi_uintn_t size; void *image = NULL; int i, num; + efi_status_t ret; __efi_entry_check(); bs = systab.boottime; rs = systab.runtime; + /* get BootNext */ + size = sizeof(bootnext); + ret = rs->get_variable(L"BootNext", + (efi_guid_t *)&efi_global_variable_guid, + NULL, &size, &bootnext); + if (!bootnext) + goto run_list; + + /* delete BootNext */ + ret = rs->set_variable(L"BootNext", + (efi_guid_t *)&efi_global_variable_guid, + 0, 0, &bootnext); + if (ret != EFI_SUCCESS) + goto error; + + image = try_load_entry(bootnext, device_path, file_path); + if (image) + goto error; + +run_list: + /* BootOrder */ bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); if (!bootorder) goto error;