From patchwork Tue Nov 27 02:20:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 152102 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp687319ljp; Mon, 26 Nov 2018 18:18:41 -0800 (PST) X-Google-Smtp-Source: AJdET5ckMNuhJFPi+RqxnKpOl2XYu76a98KDBxRX1cyopfAVLwE0WfD20svGHxIRVuakQ29Tesol X-Received: by 2002:a17:906:8301:: with SMTP id j1-v6mr22049526ejx.60.1543285121818; Mon, 26 Nov 2018 18:18:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543285121; cv=none; d=google.com; s=arc-20160816; b=kdRNO5TCuCuH6VTeRF9zu0/scNLC551mbI3FGyXPA/Vz25Z1O0LFWOYzHzSTB1dd08 sVXMjomXtOAGjJ/efSTgay7xA+TrOIHOvbNhnfKWo+3+uLuUAJZL1kwQ7BPTs9pNK9xo tXB0pfr9LrMZgf81pou/BTJdyvxp9NVhWZDGTuHIVC2ZgGzXBtHV9pTtXyyIToX9lZSJ pucM/yN/WWnv2HYfPVo/4OKJX8LdelOKyiPhLSneu0KlfldRZPijxbtcD0KSjAf6Y2yB H42al6OPa71SOcWlctM0BKs/2dnBYnJYwRA/42j7dSbXND4HaR+NFgre4kCWdgQhah9p Et3w== 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:message-id:date:to:from:dkim-signature; bh=66UXc5hivzh2P7Jp3PFAUAndGw3YgrMwMc+SXUwZbrI=; b=siVJvP+gM26VlNOvCz/Mv6uO3bX+D3/s8yY5JoHNNwSsmJuEzvh14NQaZwk6k+OpwT FF0TAwTWu2tNijtGQbtN+YW2xBkM4Bx236iYyW5rHgJVx1U/OshDSeZvalK+RFvcMlUz sUBK8SBhwsEe8WniSHI2WcCKFEGC6qSIbdejE69hwVip45AIspfNQB725KAPxUB17wrg MtJpqk6fGLx17HV+FR/6rsr5OnqOiKMHgov6QVwd7yoe4B//Oh12aJs/lvvi/K0Bduzo 79NmIrNlSKoqxijOjkwYJqEICek059F41RxBjHgLBzrwgtZgYiChbnBFMgt5zckiRUUi 5JTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="S/WazDcA"; 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 cw4-v6si1107445ejb.52.2018.11.26.18.18.41; Mon, 26 Nov 2018 18:18:41 -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="S/WazDcA"; 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 53974C21FAC; Tue, 27 Nov 2018 02:18:36 +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_H3, RCVD_IN_MSPIKE_WL, 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 BBB71C21DAF; Tue, 27 Nov 2018 02:18:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A26DDC21C38; Tue, 27 Nov 2018 02:18:33 +0000 (UTC) Received: from mail-yw1-f68.google.com (mail-yw1-f68.google.com [209.85.161.68]) by lists.denx.de (Postfix) with ESMTPS id 55566C21C38 for ; Tue, 27 Nov 2018 02:18:32 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id l200so8494146ywe.10 for ; Mon, 26 Nov 2018 18:18:32 -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:mime-version :content-transfer-encoding; bh=SVJ6H1ag7MsQ6gC+j5Fw/+5HNViKy54gK9IEuTcW5R8=; b=S/WazDcAhhNcIjV4rUFMz1PVR7+/Eu1jC3KOtytpsFMlYUB6RiToZHKxhWpY8KeGAJ 5Cu1ep0Ae9clW1XkgDPTEHaYZiRO1IqE+9h1Gug4fmrFUKHm6ffjBI9htaDgZm0+Ajlv K81dlZY4HVkcRQrYMsFrp+EgsMAv5otE1gbR0= 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:mime-version :content-transfer-encoding; bh=SVJ6H1ag7MsQ6gC+j5Fw/+5HNViKy54gK9IEuTcW5R8=; b=Z18iwR72fC9dlHk3LgmeDMkfhCe6+AKPuFss5U7zQYQmqBbTmciOhSWEpwlu42zSDN bhyzS79CGbXHPvTIkWisQpc49vZEx12bJWXfaLG4LkxwBFtUsXAxT7O3Lg3RnnEROnjV BI8ENIdCKaB5Lzx1Be3zrmp8dhB1kRRrs4O80nIHQTQVWp/SqO7l8ThonUIYmnZnuAyR 62DEZCV4FVNFyoOTcuk+K6Jy+h7szvIT0vUC478PhMvgPXAeRDxrDz6XFZT0JFaPltNQ DVMdrxNiwTJGTQcq8KcKvHLB1IOUkuicYKB6NYUHPjqmt480Ue5kGtwAGzhEne84/QX9 qWIg== X-Gm-Message-State: AGRZ1gIdEU8spkVBB6yRLIjoW3E4ypTOSTDzyxKODSvswhmVveSLI3ti VN+qCTU+eFIIBrqwuI4bEK1hDA== X-Received: by 2002:a81:ae4a:: with SMTP id g10mr32573660ywk.382.1543285110790; Mon, 26 Nov 2018 18:18:30 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id f10sm3107455ywb.26.2018.11.26.18.18.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 26 Nov 2018 18:18:30 -0800 (PST) From: AKASHI Takahiro To: agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 27 Nov 2018 11:20:55 +0900 Message-Id: <20181127022055.30921-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH] 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 efishell command[1], 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 setvar BootNext =H0200 => efi bootmgr (starting HELLO ...) => efi dumpvar BootCurrent: {boot,run}(blob) 00000000: 02 00 .. BootOrder: {boot,run}(blob) 00000000: 01 00 02 00 .... Using "run -e" would be more human-friendly, though. [1] https://lists.denx.de/pipermail/u-boot/2018-November/346450.html Signed-off-by: AKASHI Takahiro --- lib/efi_loader/efi_bootmgr.c | 37 +++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 2aae12e15456..a9b774df6c91 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -118,11 +118,21 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, parse_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) @@ -146,16 +156,41 @@ error: void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path) { - uint16_t *bootorder; + u16 bootnext, *bootorder; + u32 attributes; efi_uintn_t size; void *image = NULL; int i, num; + efi_status_t ret; __efi_entry_check(); bs = systab.boottime; rs = systab.runtime; + /* 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; + + attributes = EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS; + size = 0; + ret = rs->set_variable(L"BootNext", + (efi_guid_t *)&efi_global_variable_guid, + attributes, size, &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;