From patchwork Wed Oct 17 07:32:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149022 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp318818lji; Wed, 17 Oct 2018 00:31:20 -0700 (PDT) X-Google-Smtp-Source: ACcGV62PWhSBxAf6UnsEa7riVcyD2deyGAAWiwj4B7EVuyhF7oEpCWecYpqABced6vXJoUGuCT8R X-Received: by 2002:a17:906:29d7:: with SMTP id y23-v6mr26671309eje.156.1539761480439; Wed, 17 Oct 2018 00:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761480; cv=none; d=google.com; s=arc-20160816; b=nSUJcV0t0dxKJj5mQ9C+VFx2Cz1Uy9krgJ2aWP77rr0q6NtMIiArFF3VmJawuUkNlQ LH2wyWuitKUHZI0WEiIFGPWO+smPvgdBcx4jhdhvD3SDtKwjBMX22l0OkuU4yjhcY5hy sdCCee47njzKLVH9sEC/40c/SNYPn98nEOrZjbyDvtzCkodUKvEM4SBu/G3rr9Z1B0Nw kuXWOhohVVl3GZUmb/WXds/4X1YKlKsdhssu0HEmMHNglmTal9nsrAsegPwQIluGQPI5 Qo4aMn6Rf+TcjClNWWFbmdq6ryubB54KyXQJOpla/yckJe2Rc7pl7gHhY1wH8tdJaJRm 9e/w== 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=Z7vrsFQRPPm/OhJSISDj+gHGki9pBPq41PfP/KTNV7E=; b=jrNrQluc7dgTHCRoXO8W2BfWOc9DH9kMHSrBJ1oEiCJgcFAMqKa70E9BJu/xC/bdYF 2j5CK/ThqQqxGkbmvzbpz/dwlb7A4vngKGDdU8QjcA6vcam7kFMEPOBo8TTnCqxjiBc5 s/O4oIq7407c+xhiBIdlUke8cknm6FFOIdgFMPrjr4iaWG5r2vJYO4wV0kkeTgR7MbrC 8eYLQHneIqUKJqkiA0Gj4MtxPZlK7Ajks8D7id8JFj/W/JP12FsamE1MtPTKzopoaIab 5a3G/5xtWKsk2gNMapqSrYWYZ2nVMOgj8tz1OVyGtRlzmqmIC53BeNHYVcRXvqboDLjQ KRuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=RVsrtaeb; 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 y3-v6si3843899edv.448.2018.10.17.00.31.20; Wed, 17 Oct 2018 00:31:20 -0700 (PDT) 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=RVsrtaeb; 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 0D908C21E08; Wed, 17 Oct 2018 07:30:57 +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 E61E9C21C27; Wed, 17 Oct 2018 07:30:54 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5ACACC21C38; Wed, 17 Oct 2018 07:30:41 +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 65964C21DC1 for ; Wed, 17 Oct 2018 07:30:35 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id w7-v6so9957146ybm.7 for ; Wed, 17 Oct 2018 00:30:35 -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 :mime-version:content-transfer-encoding; bh=mex2lAZQqyEAyMZm1ZRq4gKMdNSr795ar23/kt68Jng=; b=RVsrtaebzkdB+dc5MVfCDXCfXar27Yjfm7x+LmIbgjBABqlInJsGD+20gRkdB/Sy70 ZS7xLGYlvoD5C5jtt24rTjpTGmTcreyXtZ8uYfgzXpIGmMGhJx5MGKEkPgaVKY2vb5l/ uVzqMKFtwzs8kb3CQiEkaPquoqztgtEpdelNI= 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=mex2lAZQqyEAyMZm1ZRq4gKMdNSr795ar23/kt68Jng=; b=ljcFgrGTG6+xX6VY+ctGwO9zqCZHLGFLkqO1mK9hnomefUUeASDhB5o0Ew/u7rdZmA k4L4VhxaQ/CM0zHJSIYAWTuo+NRLAcAh/+fv3oeitEnQdbdCkqLib+F8t3kLHgSaE4N3 VfpL7rcBXi+f7tAvUU4mG8WRVvnrArt++Efmtta+/S0osRopz1OFP+4YYZjyHLtIEgZ7 C/cGJUaruIQ1zruSnqHSKx6tU5mnccJYW5qXdaZeEeCDaffZYa0r9O9AOAu49y6nisQh trdae5z49Gjtz+5eYOxfTVsGzRrKaK+tGzvRjQk1M43WVHi80zbp/1rgUot02dmLBKNi Ziew== X-Gm-Message-State: ABuFfohvK7JA5MSMe6HKFtb4wxxOAORd2gnP+6k9AmEkAexpbEBFI8qM rvm3wditlJXrond9cogjyGlXjw== X-Received: by 2002:a25:e6d7:: with SMTP id d206-v6mr13547618ybh.258.1539761434188; Wed, 17 Oct 2018 00:30:34 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id d136-v6sm4313302ywh.33.2018.10.17.00.30.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:33 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:02 +0900 Message-Id: <20181017073207.13150-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/6] fs: update fs_dev_part in fs_set_blk_dev_with_part() 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" As in the case of fs_set_blk_dev(), fs_set_blk_dev_with_part() should maintain and update fs_dev_part whenever called. Without this patch, a problem will come up when an efi binary associated with efi's BOOTxxxx variable is invoked via "bootefi bootmgr". Signed-off-by: AKASHI Takahiro --- fs/fs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/fs.c b/fs/fs.c index adae98d021ee..cb265174e2f2 100644 --- a/fs/fs.c +++ b/fs/fs.c @@ -365,6 +365,7 @@ int fs_set_blk_dev_with_part(struct blk_desc *desc, int part) for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { if (!info->probe(fs_dev_desc, &fs_partition)) { fs_type = info->fstype; + fs_dev_part = part; return 0; } } From patchwork Wed Oct 17 07:32:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149023 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp318968lji; Wed, 17 Oct 2018 00:31:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV60tQdFo6f+KWMJKKGUeDg1nY4c3h6eoPbsyF+EOG6Yb1OcHfji+/Hrlf0G+6m9/V3BKEY7s X-Received: by 2002:a50:9151:: with SMTP id f17-v6mr5772719eda.159.1539761493398; Wed, 17 Oct 2018 00:31:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761493; cv=none; d=google.com; s=arc-20160816; b=Vjalj8IPfRF0oYM0cTxB70sQuKhDqzT+AjaOYuOdyk1VIa5vCTK88ctjP1a+sPMw3h KVXxVnpXsgP9MDBtku8K+PtaONwS1OmXmQWeQ5B5e0LZAIhw0oZHH3BDlNMZZrVk9Nh6 kuKzh1nZkQ56BTLJ4alXVl1tFvUNHGHiaYln4cOiSa13CcancAgzQni9Uk+2BDy22B2R clbN3OkaL48eVPGHFZEZ0lKC5Srg9zP8GfJS5l935HWUm+jvStezSAiZiBZYeFhdCmXb wahWvEuET4JDWU1AJl0/gUw8DFMNHOBRhRd+9/4VR3kyh0agPcDPMf8Olessc6nm0AtZ RwTQ== 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=AItn3FEgZgz3XLuh4q6+rakLoQQZiaY3CWP4hs202Ow=; b=zSyOxqgQ8JZx6UagJZVlO7WbNGxV3YvO33iunMnuUqxaRmMtLpIBDU8ANa2wakS7Eg DAoqSEogjpevq8wPGW1/WFQaSgfW+5Q3W2TVJjeOfzh+vNxPI4Szw9BfpiVrbnkTuMa3 INvPrmt23D0SPiRUbDlPr+XRw+VeIBhf9t7ewbe7WuHJXm3xunsdQhXQRh+uEIlOp+Tp k62IvpvvQxn3C0OoxFi8YF8WbBj2typamI0wM7HGDLf7d0/UpPmjEc19/ZZffevgQ3g3 FjBtU+6XXkQXN2tPqKIKUIp774AJR7jh/pu5G9VwwavbzIh9XqbXEalgk9RfKpTr9IPy 4QDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="ifYiF/1c"; 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 ch16-v6si4840274ejb.147.2018.10.17.00.31.33; Wed, 17 Oct 2018 00:31:33 -0700 (PDT) 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="ifYiF/1c"; 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 046A3C21DD7; Wed, 17 Oct 2018 07:31:19 +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 BA075C21D9A; Wed, 17 Oct 2018 07:31:00 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B61CEC21E08; Wed, 17 Oct 2018 07:30:44 +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 34BA3C21C2C for ; Wed, 17 Oct 2018 07:30:40 +0000 (UTC) Received: by mail-yw1-f68.google.com with SMTP id v198-v6so9948170ywg.12 for ; Wed, 17 Oct 2018 00:30:40 -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 :mime-version:content-transfer-encoding; bh=S+zst4eVwZEd8oZfKOrZwRDmBIZDGuz/IBWtT1IdhC0=; b=ifYiF/1cBZRFc4RsDmktyUCHrd6W8PlnC+MYouBTbcch3VqKNz981/QkB+r3IPjSJf EjrIoiuZxmKsda4tDSFWo/UpRUxJEReVwiBA3FB5D9HI6GxCRbAmVDO7gz6ty+fWKb32 0er+NlrbjzxynsMmwCNY8P/72Cd5Adxoii50M= 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=S+zst4eVwZEd8oZfKOrZwRDmBIZDGuz/IBWtT1IdhC0=; b=nFVw1M9M3bZ925HMUx3eZTXrtt0atS+w8C9EBopfQmbooVEJ2VmaTV+5AGTaOScglN OPfhpF6YTo+1l0v6RTfAb5eg9l31OYt4VLMI0tS4MHro6MEosArXE6E5zxGRyfv9ja3/ IUGSUj44oD/On4Opgb3+SNguq7EFODgBfKCq4OcZGn+VurLVgaYPmK5JKYMXKITqNIPD 1zPcw/MPeX803A06uWk9UPRYV7lJkV/zcNM9duw3zfTAkNiygqultdC+wxKrSJxmLdGF kwQf1Q/nURkLmrHvNElGPuKwgkQAPsI9CdeRiaJdV4yvu3Q9axCod2fdu7Maw5hMzLnn 3vSA== X-Gm-Message-State: ABuFfoggidxTDBxTsaqvLkAYr1ww7A/XoBDl4BOpZ6/9+nfwZ68SP99d 9m2oAzR/P/Q+7WZdGwykRxH3Yw== X-Received: by 2002:a81:af0b:: with SMTP id n11-v6mr13614891ywh.377.1539761439096; Wed, 17 Oct 2018 00:30:39 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id l30-v6sm7710696ywa.104.2018.10.17.00.30.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:38 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:03 +0900 Message-Id: <20181017073207.13150-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/6] efi_loader: add efi_dp_from_name() 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" Factor out efi_set_bootdev() and extract efi_dp_from_name(). This function will be used to set a boot device in efishell command. Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 42 ++++++---------------------- include/efi_loader.h | 4 +++ lib/efi_loader/efi_device_path.c | 47 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 34 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 99f5b2b95706..b3e2845120fe 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -647,45 +647,19 @@ U_BOOT_CMD( void efi_set_bootdev(const char *dev, const char *devnr, const char *path) { - char filename[32] = { 0 }; /* dp->str is u16[32] long */ - char *s; + struct efi_device_path *device, *image; + efi_status_t ret; /* efi_set_bootdev is typically called repeatedly, recover memory */ efi_free_pool(bootefi_device_path); efi_free_pool(bootefi_image_path); - /* If blk_get_device_part_str fails, avoid duplicate free. */ - bootefi_device_path = NULL; - bootefi_image_path = NULL; - - if (strcmp(dev, "Net")) { - struct blk_desc *desc; - disk_partition_t fs_partition; - int part; - - part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, - 1); - if (part < 0) - return; - - bootefi_device_path = efi_dp_from_part(desc, part); - } else { -#ifdef CONFIG_NET - bootefi_device_path = efi_dp_from_eth(); -#endif - } - - if (!path) - return; - if (strcmp(dev, "Net")) { - /* Add leading / to fs paths, because they're absolute */ - snprintf(filename, sizeof(filename), "/%s", path); + ret = efi_dp_from_name(dev, devnr, path, &device, &image); + if (ret == EFI_SUCCESS) { + bootefi_device_path = device; + bootefi_image_path = image; } else { - snprintf(filename, sizeof(filename), "%s", path); + bootefi_device_path = NULL; + bootefi_image_path = NULL; } - /* DOS style file path: */ - s = filename; - while ((s = strchr(s, '/'))) - *s++ = '\\'; - bootefi_image_path = efi_dp_from_file(NULL, 0, filename); } diff --git a/include/efi_loader.h b/include/efi_loader.h index 74df070316a0..b73fbb6de23f 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -425,6 +425,10 @@ const struct efi_device_path *efi_dp_last_node( efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, struct efi_device_path **device_path, struct efi_device_path **file_path); +efi_status_t efi_dp_from_name(const char *dev, const char *devnr, + const char *path, + struct efi_device_path **device, + struct efi_device_path **file); #define EFI_DP_TYPE(_dp, _type, _subtype) \ (((_dp)->type == DEVICE_PATH_TYPE_##_type) && \ diff --git a/lib/efi_loader/efi_device_path.c b/lib/efi_loader/efi_device_path.c index 5a61a1c1dcf9..3af444147283 100644 --- a/lib/efi_loader/efi_device_path.c +++ b/lib/efi_loader/efi_device_path.c @@ -942,3 +942,50 @@ efi_status_t efi_dp_split_file_path(struct efi_device_path *full_path, *file_path = fp; return EFI_SUCCESS; } + +efi_status_t efi_dp_from_name(const char *dev, const char *devnr, + const char *path, + struct efi_device_path **device, + struct efi_device_path **file) +{ + int is_net; + struct blk_desc *desc = NULL; + disk_partition_t fs_partition; + int part = 0; + char filename[32] = { 0 }; /* dp->str is u16[32] long */ + char *s; + + if (!device || (path && !file)) + return EFI_INVALID_PARAMETER; + + is_net = !strcmp(dev, "Net"); + if (!is_net) { + part = blk_get_device_part_str(dev, devnr, &desc, &fs_partition, + 1); + if (part < 0) + return EFI_INVALID_PARAMETER; + + *device = efi_dp_from_part(desc, part); + } else { +#ifdef CONFIG_NET + *device = efi_dp_from_eth(); +#endif + } + + if (!path) + return EFI_SUCCESS; + + if (!is_net) { + /* Add leading / to fs paths, because they're absolute */ + snprintf(filename, sizeof(filename), "/%s", path); + } else { + snprintf(filename, sizeof(filename), "%s", path); + } + /* DOS style file path: */ + s = filename; + while ((s = strchr(s, '/'))) + *s++ = '\\'; + *file = efi_dp_from_file(NULL, 0, filename); + + return EFI_SUCCESS; +} From patchwork Wed Oct 17 07:32:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149027 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp321733lji; Wed, 17 Oct 2018 00:34:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV6236DEhqoN7RlJuvrbwngeVaj55IssDQfMrS760624fJa8C36muWhkVXBNaWwpLMXjhw6GM X-Received: by 2002:a50:d51d:: with SMTP id u29-v6mr34500445edi.291.1539761682166; Wed, 17 Oct 2018 00:34:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761682; cv=none; d=google.com; s=arc-20160816; b=AzkCMSzKZ9+nNkWGBbzYeLY5avKd0b0FGiinhPZ0tXkuf+Cp00mtaIKcUc5LPgHI6O OtVkYLSTk/lLr33zZJbkBBBAG9l4UielJwxWLhd39NwrW111RfCDd3JrmpTAoznFXX2A mB/FbsIll6htfxY0iPZdcpIxb/U+ATpE/eJ4Bwfa413AGNZgNAoZGobXMDqLDQQm3e0G +gLEUtBXzsaloo6lTKk0JqOocP522O2FMpTMl9tbrdcRVtKlAL5Xyv5BNDWXXSwLaD1X kfr6x1O8ILi1Ww8jgucJHW+/biSa1d6to7ktVODP9SLpV2792zd9wTkCq/dybtZPYevl 4xKQ== 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=UwGlR8LMAIeTbdaT6Evkn3Ln2ablkW2QFn36v5yjMSo=; b=nUdkxIUJOlRY9nek7rC5eJ+PcMIzAACpdk1UFJNFaJM+mEtXipVmG3yKzfJpU8PUxh 6WVX0mgJGNW1GSzUBl65YrXPFSNlBzKhOdYYE76PXY7VoK7UmFGGssiE3YFyrg64nxN8 728smGLVbivHih5ZGah/F6m9iARvOX1JZD9lAHrawV4vxs8uY/KmtgDbCLU4E1rcVCcw imO6/tbcewFg2Pfp59UwyvywYstj8HYfph+XHNKt5eZMAK3vAg252WPDexTg2lxnF90t khDntkXl1TWDU1uZgGK29c69oIaBz8DtJUUzdB8ftYac659EoRPA7rJDUVpoooEunfUC 8gpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZzCe3PbC; 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 p27-v6si12950873edi.343.2018.10.17.00.34.41; Wed, 17 Oct 2018 00:34:42 -0700 (PDT) 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=ZzCe3PbC; 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 B0CA2C21DFD; Wed, 17 Oct 2018 07:32:30 +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 594AFC21C2C; Wed, 17 Oct 2018 07:31:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A6183C21BE5; Wed, 17 Oct 2018 07:30:49 +0000 (UTC) Received: from mail-yw1-f67.google.com (mail-yw1-f67.google.com [209.85.161.67]) by lists.denx.de (Postfix) with ESMTPS id 971D7C21DCA for ; Wed, 17 Oct 2018 07:30:44 +0000 (UTC) Received: by mail-yw1-f67.google.com with SMTP id l79-v6so9953717ywc.7 for ; Wed, 17 Oct 2018 00:30:44 -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 :mime-version:content-transfer-encoding; bh=OREM892Y+bGO/OGQjV2MrIj2U+HDOOJvcy8xMXO5xZw=; b=ZzCe3PbC2afb6SV9FM0v0VR/QMRsqMRmuEIy8v0CS+yZkf/p34QEOoghQwsOKRTQD2 xooHInkhOUzdTDjECcWVxDXTmtdHrTdGlkh2kEWsIM37i6PZ5z/shMEra7uZpfAF49YW BfuqaaJ2lIc12oSPEKdASz8kImJKezBpPYIzU= 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=OREM892Y+bGO/OGQjV2MrIj2U+HDOOJvcy8xMXO5xZw=; b=rdUMVhSqBtT2n5x/M6a5jQnb2tx3eUFFWflUa2GHTNx2fbTQX64TyLxnxpRAUVBneL +ww53/sxLm8OHYWGtXBN+XW2Q5qwUZgY1Ya+Jy5fb/ghvQy9hJgJgX+6UH2zzIKzqWp+ IwTrDFN05DWcrjP9s2e6ULkFKMnwHvLZgRuM7GASU2kjnrzWYqq3ArlwmtcPZMvSszMK iw7H1tnVGSOeOjtDdkFTgO3JXbZUd5/ZjvD0JZSrB1fO6cCMp0OdATXMqJdHl1CSQGhq qs+VV+FWkmIH5i9orY98mIDM2BBrzkVJWln82IdYJxtG73/8k62mkZceXmcxDGgZusCK MjBA== X-Gm-Message-State: ABuFfoguZnhePmNIC7ysaubsD/n+33A8QZDwwMMnXPCzVUEQFPyL/WQI Qn6knogmEYXS9VuVoGITGpc7FQ== X-Received: by 2002:a81:9148:: with SMTP id i69-v6mr13867465ywg.371.1539761443502; Wed, 17 Oct 2018 00:30:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id r5-v6sm6645288ywr.80.2018.10.17.00.30.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:42 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:04 +0900 Message-Id: <20181017073207.13150-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 3/6] efi_loader: bootmgr: add load option helper functions 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" In this patch, helper functions for an load option variable (BootXXXX) are added: * efi_parse_load_option(): parse a string into load_option data (renamed from parse_load_option and exported) * efi_marshel_load_option(): convert load_option data into a string Those functions will be used to implement efishell command. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 25 +++++++++++++ lib/efi_loader/efi_bootmgr.c | 68 ++++++++++++++++++++++++------------ 2 files changed, 70 insertions(+), 23 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index b73fbb6de23f..1cabb1680d20 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -502,6 +502,31 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor, u32 attributes, efi_uintn_t data_size, void *data); +/* + * See section 3.1.3 in the v2.7 UEFI spec for more details on + * the layout of EFI_LOAD_OPTION. In short it is: + * + * typedef struct _EFI_LOAD_OPTION { + * UINT32 Attributes; + * UINT16 FilePathListLength; + * // CHAR16 Description[]; <-- variable length, NULL terminated + * // EFI_DEVICE_PATH_PROTOCOL FilePathList[]; + * <-- FilePathListLength bytes + * // UINT8 OptionalData[]; + * } EFI_LOAD_OPTION; + */ +struct load_option { + u32 attributes; + u16 file_path_length; + u16 *label; + struct efi_device_path *file_path; + u8 *optional_data; +}; + +void efi_parse_load_option(struct load_option *lo, void *ptr); +unsigned long efi_marshal_load_option(u32 attr, u16 *label, + struct efi_device_path *file_path, + char *option, void **data); void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path); diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 0c5764db127b..c2d29f956065 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -30,28 +30,8 @@ static const struct efi_runtime_services *rs; */ -/* - * See section 3.1.3 in the v2.7 UEFI spec for more details on - * the layout of EFI_LOAD_OPTION. In short it is: - * - * typedef struct _EFI_LOAD_OPTION { - * UINT32 Attributes; - * UINT16 FilePathListLength; - * // CHAR16 Description[]; <-- variable length, NULL terminated - * // EFI_DEVICE_PATH_PROTOCOL FilePathList[]; <-- FilePathListLength bytes - * // UINT8 OptionalData[]; - * } EFI_LOAD_OPTION; - */ -struct load_option { - u32 attributes; - u16 file_path_length; - u16 *label; - struct efi_device_path *file_path; - u8 *optional_data; -}; - /* parse an EFI_LOAD_OPTION, as described above */ -static void parse_load_option(struct load_option *lo, void *ptr) +void efi_parse_load_option(struct load_option *lo, void *ptr) { lo->attributes = *(u32 *)ptr; ptr += sizeof(u32); @@ -60,7 +40,7 @@ static void parse_load_option(struct load_option *lo, void *ptr) ptr += sizeof(u16); lo->label = ptr; - ptr += (u16_strlen(lo->label) + 1) * 2; + ptr += (u16_strlen(lo->label) + 1) * sizeof(u16); lo->file_path = ptr; ptr += lo->file_path_length; @@ -68,6 +48,48 @@ static void parse_load_option(struct load_option *lo, void *ptr) lo->optional_data = ptr; } +unsigned long efi_marshal_load_option(u32 attr, u16 *label, + struct efi_device_path *file_path, + char *option, void **data) +{ + unsigned long size; + unsigned long label_len, option_len; + u16 file_path_len; + void *p; + + label_len = (u16_strlen(label) + 1) * sizeof(u16); + file_path_len = efi_dp_size(file_path) + + sizeof(struct efi_device_path); /* for END */ + option_len = strlen(option); + + /* total size */ + size = sizeof(attr); + size += file_path_len; + size += label_len; + size += option_len + 1; + p = malloc(size); + if (!p) + return 0; + + /* copy data */ + *data = p; + memcpy(p, &attr, sizeof(attr)); + p += sizeof(attr); + memcpy(p, &file_path_len, sizeof(file_path_len)); + p += sizeof(file_path_len); + memcpy(p, label, label_len); + p += label_len; + + memcpy(p, file_path, file_path_len); + p += file_path_len; + + memcpy(p, option, option_len); + p += option_len; + *(char *)p = '\0'; + + return size; +} + /* free() the result */ static void *get_var(u16 *name, const efi_guid_t *vendor, efi_uintn_t *size) @@ -115,7 +137,7 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, if (!load_option) return NULL; - parse_load_option(&lo, load_option); + efi_parse_load_option(&lo, load_option); if (lo.attributes & LOAD_OPTION_ACTIVE) { efi_status_t ret; From patchwork Wed Oct 17 07:32:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 149024 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp319747lji; Wed, 17 Oct 2018 00:32:24 -0700 (PDT) X-Google-Smtp-Source: ACcGV62xKqf4ZHuns+0B4j8btNnN1+sW3HEMdQCx+QkmdfAFN13hYCR1F15+pz6GTVB1BXQhj0+3 X-Received: by 2002:a50:aca2:: with SMTP id x31-v6mr34250380edc.76.1539761544689; Wed, 17 Oct 2018 00:32:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539761544; cv=none; d=google.com; s=arc-20160816; b=prXUHGck+aWcBI5sf7pwVyt/MFWXzFWrlTUqO/h8OPRA5FLDgjyY8pMSnUbPxNq54r 7IbBJ+7DKcE0N89Sf3YeT6oFTVHNYNJDfXn9sJem7EHBN6dqi7gYr3+56ypLUKT2q2IP Ed/1K55yiMTy4bnDaPNC2VyPKGG5WcPMDDj31LnSFHxId2dT7+OFQOTpXvFXWM1JcQFM lztjTB4uPpv2cJZNwrkgqiPzkXWbEWGF68GMPO0JmPpvbRUNkED4zfdLX+4VmRaV1l30 mW9YEKFu84i3jZEIGCVABiVz3UBh8BEggE2WF5C4Pqxs8wXa++pYNuU5x/p3dx/yTiP6 b4+A== 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=xYBeNMRwWnL3hT730QDrp3xcap81EcyJrAsHZgW3ff4=; b=nByv1HvUhv95lTl4lwUNbkzch5QzaePxyRY2cY2mCVXUeCZy1vcwYBj5k0T2a9QuhZ lgvuqnwDDDEsSUr0lB7ACrlHsWRmsMOFYEMc5Kp9pkh1TScQkxYdqCLPFLMKdXAM71EX rKG74EU22Dw1FND1bvPnT9kA49UWVUPy36PzTBL8ers7chiQ5M8djc3h34wGTXDFbeWn 1DsUa/bwOrFWU4OzWi9PNcpzK8FBn+hcWJ0/yeNzEJeMm0Y1R0GIqdh8VrpFddzgo7DV CboyS/E3Jq0j+YekiwJK1qgwEYDJSwUHKqsWg8xJKdTLc7ylQFm0iQRVkFlPJWij/60T IDHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=hr2d2Gzz; 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 b58-v6si7436900ede.270.2018.10.17.00.32.24; Wed, 17 Oct 2018 00:32:24 -0700 (PDT) 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=hr2d2Gzz; 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 3C78DC21DC1; Wed, 17 Oct 2018 07:31:58 +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 0455BC21D8E; Wed, 17 Oct 2018 07:31:10 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id C6025C21DA2; Wed, 17 Oct 2018 07:30:50 +0000 (UTC) Received: from mail-yw1-f65.google.com (mail-yw1-f65.google.com [209.85.161.65]) by lists.denx.de (Postfix) with ESMTPS id 6A069C21DA2 for ; Wed, 17 Oct 2018 07:30:49 +0000 (UTC) Received: by mail-yw1-f65.google.com with SMTP id v198-v6so9948367ywg.12 for ; Wed, 17 Oct 2018 00:30:49 -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 :mime-version:content-transfer-encoding; bh=xk3V7MDwJG6eRbv1MQsB9ZTaYp9hRJkJrx1Milj3di4=; b=hr2d2GzzwKFvyo4DCAlgCidyKTdV3RlTr0gt/Abmqs5/lAHOVe6Vd+XuYqDPNYuplB VTX5JiufmU7Z6f7qlSSCJfHGR9PqHxi+0tW28hTzatI7nErqwFG4Puas/fvDs/h9D4ZP PSCaN5Co0pqg5XuMJT7j7NVAWm7A77EE8EH1M= 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=xk3V7MDwJG6eRbv1MQsB9ZTaYp9hRJkJrx1Milj3di4=; b=WXbvNY6U0ylEyk/XHfcLoLf+/YVkBhZkXTKkHb6pwR9EoWyLvmfwT9UuETFz5RFAou mGTOCbjT2tNEn34hdUjyl59c5h5rMAmBu2c/g7YfMmMhAWu7vr59RNxAV89RGXZzvyeO nxcBNjDibUGcmnkLU2ePHKODDwedXlFrbkGtu6oKNJ8axkGbFcQF9CI6uqAzggYGgBYH d05+rg6e9Yq8HIZqcI5JjtNrDhZ867ejBAivr69VVab+EFhlmKSnS2AIlaRUR6Lubo4j U6jwp/5uC/zBzXwQOMX0BFv6rihNvX8mC0t3ecsC5HTFuIUhR29kWerFK3C569PfNohV DX4g== X-Gm-Message-State: ABuFfoh9LBkbPJc10/HsYRhMhPZicwIi7H3l+goOTR5a4FyfEwN09qBN 38RhCLgmQdRH1hilHDwcLcA+sw== X-Received: by 2002:a81:b209:: with SMTP id q9-v6mr13960366ywh.45.1539761448164; Wed, 17 Oct 2018 00:30:48 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id u79-v6sm4918716ywe.110.2018.10.17.00.30.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Oct 2018 00:30:47 -0700 (PDT) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Wed, 17 Oct 2018 16:32:05 +0900 Message-Id: <20181017073207.13150-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181017073207.13150-1-takahiro.akashi@linaro.org> References: <20181017073207.13150-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 4/6] cmd: add efishell command 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" Currently, there is no easy way to add or modify UEFI variables. In particular, bootmgr supports BootOrder/BootXXXX variables, it is quite hard to define them as u-boot variables because they are represented in a complicated and encoded format. The new command, efishell, helps address these issues and give us more friendly interfaces: * efishell boot add: add BootXXXX variable * efishell boot rm: remove BootXXXX variable * efishell boot dump: display all BootXXXX variables * efishell boot order: set/display a boot order (BootOrder) * efishell setvar: set an UEFI variable (with limited functionality) * efishell dumpvar: display all UEFI variables As the name suggests, this command basically provides a subset fo UEFI shell commands with simplified functionality. Signed-off-by: AKASHI Takahiro --- cmd/Makefile | 2 +- cmd/efishell.c | 531 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 cmd/efishell.c diff --git a/cmd/Makefile b/cmd/Makefile index a61fab6583df..e18fb21e4b71 100644 --- a/cmd/Makefile +++ b/cmd/Makefile @@ -24,7 +24,7 @@ obj-$(CONFIG_CMD_BINOP) += binop.o obj-$(CONFIG_CMD_BLOCK_CACHE) += blkcache.o obj-$(CONFIG_CMD_BMP) += bmp.o obj-$(CONFIG_CMD_BOOTCOUNT) += bootcount.o -obj-$(CONFIG_CMD_BOOTEFI) += bootefi.o +obj-$(CONFIG_CMD_BOOTEFI) += bootefi.o efishell.o obj-$(CONFIG_CMD_BOOTMENU) += bootmenu.o obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o obj-$(CONFIG_CMD_BOOTZ) += bootz.o diff --git a/cmd/efishell.c b/cmd/efishell.c new file mode 100644 index 000000000000..7cadb9e47712 --- /dev/null +++ b/cmd/efishell.c @@ -0,0 +1,531 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * EFI Shell-like command + * + * Copyright (c) 2018 Takahiro AKASHI, Linaro Limited + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +DECLARE_GLOBAL_DATA_PTR; + +/* + * From efi_variable.c, + * + * Mapping between EFI variables and u-boot variables: + * + * efi_$guid_$varname = {attributes}(type)value + */ +static int do_efi_dump_var(int argc, char * const argv[]) +{ + char regex[256]; + char * const regexlist[] = {regex}; + char *res = NULL; + int len; + + if (argc > 2) + return CMD_RET_USAGE; + + if (argc == 2) + snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_%s", argv[1]); + else + snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_.*"); + debug("%s:%d grep uefi var %s\n", __func__, __LINE__, regex); + + len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY, + &res, 0, 1, regexlist); + + if (len < 0) + return CMD_RET_FAILURE; + + if (len > 0) { + puts(res); + free(res); + if (len < 2 && argc == 2) + printf("%s: not found\n", argv[1]); + } + + return CMD_RET_SUCCESS; +} + +static bool isalnum(char c) +{ + if (c >= '0' && c <= '9') + return true; + if (c >= 'A' && c <= 'F') + return true; + if (c >= 'a' && c <= 'f') + return true; + + return false; +} + +static int do_efi_set_var(int argc, char * const argv[]) +{ + char *value, *data, *ptr, *ptr2 = NULL, num[3] = {'\0', '\0', '\0'}; + unsigned long len, size; + u16 *var_name16; + efi_guid_t guid; + efi_status_t ret; + + if (argc > 3) + return CMD_RET_USAGE; + + if (argc == 1) + return CMD_RET_SUCCESS; + + if (argc == 2) { + /* remove */ + value = NULL; + size = 0; + } else { /* set */ + value = argv[2]; + if (value[0] == '=') + value++; + len = strlen(value); + if ((len > 2) && !strncmp(value, "0x", 2)) { + if ((len % 2)) + return CMD_RET_USAGE; + + data = value + 2; + size = (len - 2) / 2; + /* FIXME */ + ptr = malloc(size); + ptr2 = ptr; + len = 0; + while (len < size * 2) { + num[0] = data[len++]; + num[1] = data[len++]; + if (!isalnum(num[0]) || !isalnum(num[1])) { + printf("Invalid format: %s\n\n", value); + ret = CMD_RET_USAGE; + goto out; + } + *ptr++ = (char)simple_strtoul(num, NULL, 16); + } + value = data; + } else { + size = len; + } + } + + var_name16 = malloc((strlen(argv[1]) + 1) * 2); + utf8_to_utf16(var_name16, (u8 *)argv[1], strlen(argv[1]) + 1); + + guid = efi_global_variable_guid; + ret = efi_set_variable(var_name16, &guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, size, value); + ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); +out: + if (ptr2) + free(ptr2); + return ret; +} + +static int do_efi_boot_add(int argc, char * const argv[]) +{ + int id; + char *endp; + char var_name[9]; + u16 var_name16[9]; + efi_guid_t guid; + u32 attr; + size_t label_len, label_len16; + u16 *label, *p; + char *interface, *device, *file, *option; + struct efi_device_path *device_path = NULL, *file_path = NULL; + void *data = NULL; + unsigned long size; + int ret; + + if (argc < 6 || argc > 7) + return CMD_RET_USAGE; + + id = (int)simple_strtoul(argv[1], &endp, 0); + if (*endp != '\0' || id > 0xffff) + return CMD_RET_FAILURE; + + sprintf(var_name, "Boot%04X", id); + utf8_to_utf16(var_name16, (u8 *)var_name, 9); + guid = efi_global_variable_guid; + + attr = 0x1; /* always ACTIVE */ + + label_len = strlen(argv[2]); + label_len16 = utf8_utf16_strnlen(argv[2], label_len); + label = malloc((label_len16 + 1) * sizeof(u16)); + if (!label) + return CMD_RET_FAILURE; + p = label; + utf8_utf16_strncpy(&p, argv[2], label_len); + + interface = argv[3]; + device = argv[4]; + file = argv[5]; + option = (argc == 6 ? "" : argv[6]); + + ret = efi_dp_from_name(interface, device, file, &device_path, + &file_path); + if (ret != EFI_SUCCESS) { + ret = CMD_RET_FAILURE; + goto out; + } + + size = efi_marshal_load_option(attr, label, file_path, option, &data); + if (!size) { + ret = CMD_RET_FAILURE; + goto out; + } + + ret = efi_set_variable(var_name16, &guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, size, data); + ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); +out: + free(data); + free(device_path); + free(file_path); + free(label); + return ret; +} + +static int do_efi_boot_rm(int argc, char * const argv[]) +{ + efi_guid_t guid; + int id, i; + char *endp; + char var_name[9]; + u16 var_name16[9]; + efi_status_t ret; + + if (argc == 1) + return CMD_RET_USAGE; + + guid = efi_global_variable_guid; + for (i = 1; i < argc; i++, argv++) { + id = (int)simple_strtoul(argv[1], &endp, 0); + if (*endp != '\0' || id > 0xffff) + return CMD_RET_FAILURE; + + sprintf(var_name, "Boot%04X", id); + utf8_to_utf16(var_name16, (u8 *)var_name, 9); + + ret = efi_set_variable(var_name16, &guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, 0, NULL); + if (ret) { + printf("cannot remove Boot%04X", id); + return CMD_RET_FAILURE; + } + } + + return CMD_RET_SUCCESS; +} + +static void show_efi_boot_opt_data(int id, void *data) +{ + struct load_option lo; + char *label, *p; + size_t label_len16, label_len; + u16 *dp_str; + + efi_parse_load_option(&lo, data); + + label_len16 = u16_strlen(lo.label); + label_len = utf16_utf8_strnlen(lo.label, label_len16); + label = malloc(label_len + 1); + if (!label) + return; + p = label; + utf16_utf8_strncpy(&p, lo.label, label_len16); + + printf("Boot%04X:\n", id); + printf("\tattributes: %c%c%c (0x%08x)\n", + /* ACTIVE */ + lo.attributes & 0x1 ? 'A' : '-', + /* FORCE RECONNECT */ + lo.attributes & 0x2 ? 'R' : '-', + /* HIDDEN */ + lo.attributes & 0x8 ? 'H' : '-', + lo.attributes); + printf("\tlabel: %s\n", label); + + dp_str = efi_dp_str(lo.file_path); + printf("\tfile_path: %ls\n", dp_str); + efi_free_pool(dp_str); + + printf("\tdata: %s\n", lo.optional_data); + + free(label); +} + +static void show_efi_boot_opt(int id) +{ + char var_name[9]; + u16 var_name16[9]; + efi_guid_t guid; + void *data = NULL; + unsigned long size; + int ret; + + sprintf(var_name, "Boot%04X", id); + utf8_to_utf16(var_name16, (u8 *)var_name, 9); + guid = efi_global_variable_guid; + + size = 0; + ret = efi_get_variable(var_name16, &guid, NULL, &size, NULL); + if (ret == (int)EFI_BUFFER_TOO_SMALL) { + data = malloc(size); + ret = efi_get_variable(var_name16, &guid, NULL, &size, data); + } + if (ret == EFI_SUCCESS) { + show_efi_boot_opt_data(id, data); + free(data); + } else if (ret == EFI_NOT_FOUND) { + printf("Boot%04X: not found\n", id); + } +} + +static int do_efi_boot_dump(int argc, char * const argv[]) +{ + char regex[256]; + char * const regexlist[] = {regex}; + char *variables = NULL, *boot, *value; + int len; + int id; + + if (argc > 1) + return CMD_RET_USAGE; + + snprintf(regex, 256, "efi_.*-.*-.*-.*-.*_Boot[0-9A-F]+"); + + len = hexport_r(&env_htab, '\n', H_MATCH_REGEX | H_MATCH_KEY, + &variables, 0, 1, regexlist); + + if (!len) + return CMD_RET_SUCCESS; + + if (len < 0) + return CMD_RET_FAILURE; + + boot = variables; + while (*boot) { + value = strstr(boot, "Boot") + 4; + id = (int)simple_strtoul(value, NULL, 16); + show_efi_boot_opt(id); + boot = strchr(boot, '\n'); + if (!*boot) + break; + boot++; + } + free(variables); + + return CMD_RET_SUCCESS; +} + +static int show_efi_boot_order(void) +{ + efi_guid_t guid; + u16 *bootorder = NULL; + unsigned long size; + int num, i; + char var_name[9]; + u16 var_name16[9]; + void *data; + struct load_option lo; + char *label, *p; + size_t label_len16, label_len; + efi_status_t ret = CMD_RET_SUCCESS; + + guid = efi_global_variable_guid; + size = 0; + ret = efi_get_variable(L"BootOrder", &guid, NULL, &size, NULL); + if (ret == EFI_BUFFER_TOO_SMALL) { + bootorder = malloc(size); + ret = efi_get_variable(L"BootOrder", &guid, NULL, &size, + bootorder); + } + if (ret != EFI_SUCCESS) { + printf("BootOrder not defined\n"); + return CMD_RET_SUCCESS; + } + + num = size / sizeof(u16); + for (i = 0; i < num; i++) { + sprintf(var_name, "Boot%04X", bootorder[i]); + utf8_to_utf16(var_name16, (u8 *)var_name, 9); + + size = 0; + ret = efi_get_variable(var_name16, &guid, NULL, &size, NULL); + if (ret != EFI_BUFFER_TOO_SMALL) { + printf("%2d: Boot%04X: (not defined)\n", + i + 1, bootorder[i]); + continue; + } + + data = malloc(size); + if (!data) { + ret = CMD_RET_FAILURE; + goto out; + } + ret = efi_get_variable(var_name16, &guid, NULL, &size, data); + if (ret != EFI_SUCCESS) { + free(data); + ret = CMD_RET_FAILURE; + goto out; + } + + efi_parse_load_option(&lo, data); + + label_len16 = u16_strlen(lo.label); + label_len = utf16_utf8_strnlen(lo.label, label_len16); + label = malloc(label_len + 1); + if (!label) { + free(data); + ret = CMD_RET_FAILURE; + goto out; + } + p = label; + utf16_utf8_strncpy(&p, lo.label, label_len16); + printf("%2d: Boot%04X: %s\n", i + 1, bootorder[i], label); + free(label); + + free(data); + } +out: + free(bootorder); + + return ret; +} + +static int do_efi_boot_order(int argc, char * const argv[]) +{ + u16 *bootorder = NULL; + unsigned long size; + int id, i; + char *endp; + efi_guid_t guid; + efi_status_t ret; + + if (argc == 1) + return show_efi_boot_order(); + + argc--; + argv++; + + size = argc * sizeof(u16); + bootorder = malloc(size); + if (!bootorder) + return CMD_RET_FAILURE; + + for (i = 0; i < argc; i++) { + id = (int)simple_strtoul(argv[i], &endp, 0); + if (*endp != '\0' || id > 0xffff) { + printf("invalid value: %s\n", argv[i]); + ret = CMD_RET_FAILURE; + goto out; + } + + bootorder[i] = (u16)id; + } + + guid = efi_global_variable_guid; + ret = efi_set_variable(L"BootOrder", &guid, + EFI_VARIABLE_BOOTSERVICE_ACCESS | + EFI_VARIABLE_RUNTIME_ACCESS, size, bootorder); + ret = (ret == EFI_SUCCESS ? CMD_RET_SUCCESS : CMD_RET_FAILURE); +out: + free(bootorder); + + return ret; +} + +static int do_efi_boot_opt(int argc, char * const argv[]) +{ + char *sub_command; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; argv++; + sub_command = argv[0]; + + if (!strcmp(sub_command, "add")) + return do_efi_boot_add(argc, argv); + else if (!strcmp(sub_command, "rm")) + return do_efi_boot_rm(argc, argv); + else if (!strcmp(sub_command, "dump")) + return do_efi_boot_dump(argc, argv); + else if (!strcmp(sub_command, "order")) + return do_efi_boot_order(argc, argv); + else + return CMD_RET_USAGE; +} + +/* Interpreter command to configure EFI environment */ +static int do_efishell(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + char *command; + /* TODO: declare this somewhere else */ + extern efi_status_t efi_init_obj_list(void); + efi_status_t r; + + if (argc < 2) + return CMD_RET_USAGE; + + argc--; argv++; + command = argv[0]; + + /* Initialize EFI drivers */ + r = efi_init_obj_list(); + if (r != EFI_SUCCESS) { + printf("Error: Cannot set up EFI drivers, r = %lu\n", + r & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + if (!strcmp(command, "boot")) + return do_efi_boot_opt(argc, argv); + else if (!strcmp(command, "dumpvar")) + return do_efi_dump_var(argc, argv); + else if (!strcmp(command, "setvar")) + return do_efi_set_var(argc, argv); + else + return CMD_RET_USAGE; +} + +#ifdef CONFIG_SYS_LONGHELP +static char efishell_help_text[] = + " - EFI Shell-like interface to configure EFI environment\n" + "\n" + "efishell boot add