From patchwork Tue Dec 18 05:02:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 154057 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3279266ljp; Mon, 17 Dec 2018 21:03:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/V1sej/b69cZQIm/nCYA+ww15vpE09rv8C2yfbWRWBQQ0HF57CIuj/TWHgaioeotpf1s3nI X-Received: by 2002:a50:a726:: with SMTP id h35mr15219074edc.192.1545109409267; Mon, 17 Dec 2018 21:03:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545109409; cv=none; d=google.com; s=arc-20160816; b=c8/KuXFBCo1HL8Rtkmql/mdJNpgH/arsvoZj2CZ2Z7/nGoud3xVPYAJU1Y/9e6x/t1 mIk0Akn4PbEbKftAZAGf7EIskIMVWOAz+ZSN49BlJrFmimef34J9UdfFs+iEiqTXKG1x hin4rlyl/sxidiG6E0POgceNpQr26TDevD5ZRy4uz62+3aMrKpLlt+pZyqtLi3BiexVx gUex+CytnkwV8aJDQPzp74OkXJVJJTJF/7BI9nmWwtQBZ6I5ZFneigIVDDNFmhB43ibb QuTJqSWDVOF36N3klxMWizQkiOFhzUTMPdHMXK7ZJC96EmlzJY2Gt7j6aUUPCubg7xvR M5KA== 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=Ntjm+Knn8OSQZGp1Fbp7qEaaSTzHqGoDY0FSH/IFTcA=; b=C7ZybFG9TUqLyDlmPK062uHzDWpgO48iMYT4P0Cl4YopLwBI2vCgxqm9wgd+BMlN/t yZpvNWtt/Eo3Y4bK/xo2FyGkE6XhAC503BYCN/29FbVY7tJbNHFj8jYv2rB/IxzJoDuo 5BtFVmTPW6Wy9CNhGr5aFzSqO5XduBVrt1/IOG1j3Fx/8BaaanpkryMye0J6dzdxNMcx A5W3GceyQTLPRUbJwRDfT1ciPxjT/8jUUUjAAkEcf/WbyubVJ3bOlkDVY1dO2Di/LMz5 qmlk5JKmacXAdB5r9neP97+DNQm/SURG4iZ/GajJxTljU7ad14sbxca7Fbmr+KCNpuRl H8Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="cBX/gMNa"; 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 u19-v6si4970808ejm.190.2018.12.17.21.03.29; Mon, 17 Dec 2018 21:03: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="cBX/gMNa"; 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 C0D9DC21F68; Tue, 18 Dec 2018 05:00:34 +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 55E7EC21F79; Tue, 18 Dec 2018 05:00:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 47BFFC2207B; Tue, 18 Dec 2018 04:59:40 +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 F3335C21FAC for ; Tue, 18 Dec 2018 04:59:34 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id e124so5991020ybb.8 for ; Mon, 17 Dec 2018 20:59:34 -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=mn2VI8IXVGHLcm/1gZI+cQjDOH0ghEQ3cWP5xJ4AnZA=; b=cBX/gMNa3wHE2LS9I8yC0f7XMm/mInW2gksaNhr3/nhMMaueAkRmpP5Tqyg61kUy9r 4PfXtbUnrpqYcaoLR1K9S/tJpSLrpFxp8CNVuxy6rADYeUWBEnIECT7SjPSnMaZxQvk/ 65jr3YhhMxCgcxPG275hdbfdfRAwtxK8JHVcc= 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=mn2VI8IXVGHLcm/1gZI+cQjDOH0ghEQ3cWP5xJ4AnZA=; b=CeT79ZayEiCYBk9lYIM2Qh2zzUuP7TmL0IYheSTlUWmsbZfsaz6pPRqO/v76hQSoZP 8DkfTfIGBm5nzdXuYfdE+dybQhMeZ2zYymWObaZyZaNPQkPygAvNX3t8jwoCgh+45e9W AKTTxN2jouW6TEWninrw62vQnecYgbSj+1oy3pExWGpatGLinWRdA2+wt9b4WtWjP9O0 wJt331A7JnJIl1xyCPg9MugtdUjHA+clat/ppHS2k8B2rYezAyWl65fk5n7tfWX/DMKG /s4qqIGjNvlZMoay3S3bEYMb2qU8JvNNtwUvQB8r1lpj8k7yR6uKXVg0SBb+remC+2m9 V7Mw== X-Gm-Message-State: AA+aEWZGGIK3GgoIJPKJrpoEWqSzVeea2ctGgVjwZ69VmqY6XmIBrhD8 bxzUm9cTl6JlPvipuAMY3w2Ydw== X-Received: by 2002:a25:9c86:: with SMTP id y6mr15716255ybo.216.1545109173814; Mon, 17 Dec 2018 20:59:33 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id w2sm4616951ywe.62.2018.12.17.20.59.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Dec 2018 20:59:33 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de, xypron.glpk@gmx.de Date: Tue, 18 Dec 2018 14:02:53 +0900 Message-Id: <20181218050257.20142-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181218050257.20142-1-takahiro.akashi@linaro.org> References: <20181218050257.20142-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 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 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 a095df3f540b..a54ae28343ce 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,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;