From patchwork Fri Apr 19 03:22:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087934 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="BNU6MiuZ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhCW6xLlz9s4V for ; Fri, 19 Apr 2019 13:24:07 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 95AB4C21E0F; Fri, 19 Apr 2019 03:23:38 +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_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 75B8DC21E0F; Fri, 19 Apr 2019 03:23:35 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5B2A6C21E3E; Fri, 19 Apr 2019 03:23:31 +0000 (UTC) Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by lists.denx.de (Postfix) with ESMTPS id 7BEC3C21E26 for ; Fri, 19 Apr 2019 03:23:27 +0000 (UTC) Received: by mail-yb1-f194.google.com with SMTP id e190so1609111ybf.2 for ; Thu, 18 Apr 2019 20:23:27 -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=6bdl+6UNct+MdlfLJsS82fSHdXZgtq5I+vw4lbCcp5g=; b=BNU6MiuZbXwr3lixLhCIcUSFTj7qrDV4BPP7QyLT4B0+Unzb5LUD/zn6cRnAwjnvqo sVydPHTU0liGw4N5kYhtMIp64Xe1nGCcy6K+x7jWWqgXy+85rje0+MOMQ2Prb11kD11r wPhtY3tGBz0u+iYYQUuOYSn+NG67vf7VF2+OsXpAeKLT3Y9jqLQPC5x/34xaJKcRXn5V P+rxaLKC0IPARIfv0AX2pO9Z5zciOPOdZylR49SCIOG5Zw2ZWCEfVka82Xrl8VaIjNwH qdiUS9qE0NL71gYRtjMw1v7hSNhgKfMXvQUStAOKgprcFZ6yCH4U57/iHyfv1dm53Ojx mVBA== 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=6bdl+6UNct+MdlfLJsS82fSHdXZgtq5I+vw4lbCcp5g=; b=AfYC/IjF4El/n9e8a/ZE+e72BQgt7RwLKQY8xvRG65YTSotIaOS0Zk2xMYTrxjrCx6 HiM2FL4nu7tmZfuUXP4538dFvXA+oIA8yAaukTNGTUMZ0iIDBas/U6BrxCGRSU9/mZAn UyzEksTeOWH9JzHIAmRHL+hwzlRYqMsV+TZTt/JyK00L6+kBZqNoEeL7qvldKJo8ViAb Giva5oXo7NK7+5gDNrks6Kmk13cDmCtd/y/7/I4ql8fd2H2PhmP/ho2Hq1mbhNZi3pVz dXBra/d8In1oLhejXgiX+WDbfPBaF7v47lwPVpmlJR5bNVf6sCfvzvlMyVmGE6fGWTwM K/qg== X-Gm-Message-State: APjAAAWyUh2le6h+jJGYEwRyNdECFHJFD38VcA2e9TJvk4rxeHjIt7xG jsOABDXO72qNQcnpg591EFe4KMIja1Y= X-Google-Smtp-Source: APXvYqxt0R+zWWlkJpRuuBHxa5R7d7lHCwQrzt65Ibop27jC+cH7BjsudgH3YI+4+yxvIlL6Ubm0kg== X-Received: by 2002:a25:aaaa:: with SMTP id t39mr1015547ybi.494.1555644206486; Thu, 18 Apr 2019 20:23:26 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id b131sm1608734ywb.103.2019.04.18.20.23.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:25 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:28 +0900 Message-Id: <20190419032236.8242-2-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 1/9] cmd: bootefi: rework set_load_options() 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" set_load_options() can fail, so it should return error code to stop invoking an image. In addition, set_load_options() now takes a handle, instead of loaded_image_info, to utilize efi_load_image() in a later patch. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 15ee4af45667..d8ca4ed703ef 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -39,29 +39,49 @@ void __weak allow_unaligned(void) /* * Set the load options of an image from an environment variable. * - * @loaded_image_info: the image - * @env_var: name of the environment variable + * @handle: the image handle + * @env_var: name of the environment variable + * Return: status code */ -static void set_load_options(struct efi_loaded_image *loaded_image_info, - const char *env_var) +static efi_status_t set_load_options(efi_handle_t handle, const char *env_var) { + struct efi_loaded_image *loaded_image_info; size_t size; const char *env = env_get(env_var); u16 *pos; + efi_status_t ret; + + ret = EFI_CALL(systab.boottime->open_protocol( + handle, + &efi_guid_loaded_image, + (void **)&loaded_image_info, + efi_root, NULL, + EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL)); + if (ret != EFI_SUCCESS) + return EFI_INVALID_PARAMETER; loaded_image_info->load_options = NULL; loaded_image_info->load_options_size = 0; if (!env) - return; + goto out; + size = utf8_utf16_strlen(env) + 1; loaded_image_info->load_options = calloc(size, sizeof(u16)); if (!loaded_image_info->load_options) { printf("ERROR: Out of memory\n"); - return; + EFI_CALL(systab.boottime->close_protocol(handle, + &efi_guid_loaded_image, + efi_root, NULL)); + return EFI_OUT_OF_RESOURCES; } pos = loaded_image_info->load_options; utf8_utf16_strcpy(&pos, env); loaded_image_info->load_options_size = size * 2; + +out: + return EFI_CALL(systab.boottime->close_protocol(handle, + &efi_guid_loaded_image, + efi_root, NULL)); } /** @@ -212,9 +232,7 @@ static efi_status_t bootefi_run_prepare(const char *load_options_path, return ret; /* Transfer environment variable as load options */ - set_load_options(*loaded_image_infop, load_options_path); - - return 0; + return set_load_options((efi_handle_t)*image_objp, load_options_path); } /** From patchwork Fri Apr 19 03:22:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087938 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="vZrafarD"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhG86FBLz9s4V for ; Fri, 19 Apr 2019 13:26:24 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 8E05CC21E1A; Fri, 19 Apr 2019 03:24:33 +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=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 BBB71C21E1B; Fri, 19 Apr 2019 03:24:05 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9146FC21E30; Fri, 19 Apr 2019 03:23:33 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 01FE2C21E0F for ; Fri, 19 Apr 2019 03:23:30 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id a13so1595760ybl.8 for ; Thu, 18 Apr 2019 20:23:29 -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=TQoF2a1HWGmgGIbqwp+4l52pXJRvRxQSGR9hY5U4A6A=; b=vZrafarDB1xh2V0cRosMTVt6TNiEjKiqAV0QmQ2khweHdmg75+AJwsOygSKySD1nBv mORRId6PsFbBKkVN60wW+K8QIjPl8n3ZMPK+hxEhF5wY3qwnEuLrbcmT3i4hU/Dc2qJa N8+coxZYnguGfUURRCAoCRQtmlSVlxDScyilmTI7ORZHnzOMjyP4Z5NCUKxcd87Uzh5r VSObvPYUredmr1fWRIpkR/nE+curfitc5RV960sHDP626qHnwwZFJIGZEeMiwZ7FoypP pSAsL24A248wiFyPLz5PBiY/VFXE8ogl2A9tWLdjZWWql1UBAYPw8eIDwoX5su2HRPj1 dqLQ== 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=TQoF2a1HWGmgGIbqwp+4l52pXJRvRxQSGR9hY5U4A6A=; b=qykwmt6NEZZTUAx1AtBu9eSFiPOjHC2jaThMrQH6KrAyhsc4Lo+ksGEQckrhQQJApY 93wmuPjwwIBls2XcyGD8m1qFSEWHYQlz8maK3T6PiVWzgLTTSgoa68r/9OImAAPG7NgS bn9lxx0H1dfzv/dYjk/XrxXQUs7IMIQEcJW0j+VumClfzr+S6TIlGlei7WFYH/cr89QD xDh/Bh3PZsVJPj9ucG/ud24EVKlrJ1f/l66ylBqWrHL0KjsSEAmwW/N1FcVufx1PTx7R 8Impd3BFIGF7u4C96QxLXBJ0SF3iq19c/Jn047PvKJ35HmB2cekcKBOt8hcrbLQvOEo+ cVgQ== X-Gm-Message-State: APjAAAUbWIasOGTmlEOa9+NAT5Zk+xbZybFsw0ZSDAM0wXblgeUQMnAp anNu30u6oSaLJllYi9V0l4x33w== X-Google-Smtp-Source: APXvYqwmO3PNU05CLMFQ6b1QyF+ufHRv7ykdRcyFNMT5tZ3msqWa0AOxFMKyjS/5I3mvgyNLeIww/Q== X-Received: by 2002:a25:320a:: with SMTP id y10mr1016345yby.215.1555644208972; Thu, 18 Apr 2019 20:23:28 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e14sm2587621ywa.8.2019.04.18.20.23.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:28 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:29 +0900 Message-Id: <20190419032236.8242-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/9] cmd: bootefi: carve out fdt handling from do_bootefi() 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" This is a preparatory patch for reworking do_bootefi() in later patch. Carve out a function to handle the installation of the device tree as a configuration table in system table. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 54 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index d8ca4ed703ef..fb6703ce84f3 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -218,6 +218,38 @@ static efi_status_t efi_install_fdt(ulong fdt_addr) return ret; } +/** + * efi_process_fdt() - process fdt passed by a command argument + * @fdt_opt: pointer to argument + * Return: status code + * + * If specified, fdt will be installed as configuration table, + * otherwise no fdt will be passed. + */ +static efi_status_t efi_process_fdt(const char *fdt_opt) +{ + unsigned long fdt_addr; + efi_status_t ret; + + if (fdt_opt) { + fdt_addr = simple_strtoul(fdt_opt, NULL, 16); + if (!fdt_addr && *fdt_opt != '0') + return EFI_INVALID_PARAMETER; + + /* Install device tree */ + ret = efi_install_fdt(fdt_addr); + if (ret != EFI_SUCCESS) { + printf("ERROR: failed to install device tree\n"); + return ret; + } + } else { + /* Remove device tree. EFI_NOT_FOUND can be ignored here */ + efi_install_configuration_table(&efi_guid_fdt, NULL); + } + + return EFI_SUCCESS; +} + static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, struct efi_device_path *image_path, @@ -407,7 +439,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) unsigned long addr; char *saddr; efi_status_t r; - unsigned long fdt_addr; /* Allow unaligned memory access */ allow_unaligned(); @@ -425,21 +456,12 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - if (argc > 2) { - fdt_addr = simple_strtoul(argv[2], NULL, 16); - if (!fdt_addr && *argv[2] != '0') - return CMD_RET_USAGE; - /* Install device tree */ - r = efi_install_fdt(fdt_addr); - if (r != EFI_SUCCESS) { - printf("ERROR: failed to install device tree\n"); - return CMD_RET_FAILURE; - } - } else { - /* Remove device tree. EFI_NOT_FOUND can be ignored here */ - efi_install_configuration_table(&efi_guid_fdt, NULL); - printf("WARNING: booting without device tree\n"); - } + r = efi_process_fdt(argc > 2 ? argv[2] : NULL); + if (r == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (r != EFI_SUCCESS) + return CMD_RET_FAILURE; + #ifdef CONFIG_CMD_BOOTEFI_HELLO if (!strcmp(argv[1], "hello")) { ulong size = __efi_helloworld_end - __efi_helloworld_begin; From patchwork Fri Apr 19 03:22:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087939 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="U8bHHDa3"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhH10Vl2z9s4V for ; Fri, 19 Apr 2019 13:27:09 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id C3D41C21DF8; Fri, 19 Apr 2019 03:24:46 +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=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 4CA76C21E1A; Fri, 19 Apr 2019 03:24:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 92EB7C21DFD; Fri, 19 Apr 2019 03:23:35 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id 43E3BC21E18 for ; Fri, 19 Apr 2019 03:23:32 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id e190so1609165ybf.2 for ; Thu, 18 Apr 2019 20:23:32 -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=eTjdGD+6rrLXr0PvNJ44FJ15N/vxB2Hj6efQR2nePQ8=; b=U8bHHDa3cD8EyemuZhWCrFM16TUlY5Uv62YBkWTzNRGs4sLXWcP7B6F0hGwBPhg90w MWsFlqbnKYbYXFdCYatPMbJdc7yqSFXHWEuxEx0H6y5pIMizn16Ojt1PkBeFNafHGdpG hjOZJ3WwzFCap/Z86uE1xo4gIHmTlyhtD29ha2xzB0TVmnkMlgRAIln67HnuQUMmigN5 09VNfmjh6NXZyiugAaYV+bfAZlM48H6QjXI5LJawKxcHr3cycaBDlWD7g0lAB6qMHLTr 8Zl0hc/KhWB4clsD/FcPhgz0sFAIpcNvx5gAOt86eAV9DsjSQmi+CkJWGoGW4CANnqBk KpJw== 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=eTjdGD+6rrLXr0PvNJ44FJ15N/vxB2Hj6efQR2nePQ8=; b=qLBZyAmhmfI52zBSapTak2lL/QZmQeH0ZO4X0KV8dhypbntY1cCGwAIkequEPmpioT 7+uu1BmbGQXdQJFp2jcTkAvVwNthxy+YPy70SeO16Tfw2g0hFsJ7WOVMHssL3Vicw+Uq SZV7CO1/s3vYsQQskjgmDQvhejoDE8OSgPITTpe+8FSQ6F9F+b3QPsWlBlqdiSS7fRtM 8VFWfBmFjLp303MPQ78+dqg9q9npUNZSiKQZ7BAdGEQMUJKqgRZNg6YWhDRDrlghVTlc kjkUs4b+nDuNe0LScaR5/HZUp3xYL5gKAEJzRu12HPq88+9obf513TTRuxvx2xutEu+w YQeA== X-Gm-Message-State: APjAAAUV3R1PzJ0atDpnCFO4lpGoVY1UW6xKTfUXffishR6G1nHsZ3qR Z5cHWlt57WMVv+FmPNn2i3NAYE/Ee1Q= X-Google-Smtp-Source: APXvYqwvo8fICPpNauRGX7R5onb5qK1ZeTmhk7SWDl3Idd/gqBMRprMONegGsQtXdpNkDz7Br2CNJA== X-Received: by 2002:a25:1a45:: with SMTP id a66mr1057310yba.390.1555644211223; Thu, 18 Apr 2019 20:23:31 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 129sm2032692ywv.38.2019.04.18.20.23.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:30 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:30 +0900 Message-Id: <20190419032236.8242-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 3/9] cmd: bootefi: merge efi_install_fdt() and efi_process_fdt() 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" This is a preparatory patch for reworking do_bootefi() in later patch. For simplicity, merge two functions. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 67 +++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 39 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index fb6703ce84f3..c6d6eb7312e8 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -185,62 +185,51 @@ static void efi_carve_out_dt_rsv(void *fdt) } } -static efi_status_t efi_install_fdt(ulong fdt_addr) -{ - bootm_headers_t img = { 0 }; - efi_status_t ret; - void *fdt; - - fdt = map_sysmem(fdt_addr, 0); - if (fdt_check_header(fdt)) { - printf("ERROR: invalid device tree\n"); - return EFI_INVALID_PARAMETER; - } - - /* Create memory reservation as indicated by the device tree */ - efi_carve_out_dt_rsv(fdt); - - /* Prepare fdt for payload */ - ret = copy_fdt(&fdt); - if (ret) - return ret; - - if (image_setup_libfdt(&img, fdt, 0, NULL)) { - printf("ERROR: failed to process device tree\n"); - return EFI_LOAD_ERROR; - } - - /* Link to it in the efi tables */ - ret = efi_install_configuration_table(&efi_guid_fdt, fdt); - if (ret != EFI_SUCCESS) - return EFI_OUT_OF_RESOURCES; - - return ret; -} - /** - * efi_process_fdt() - process fdt passed by a command argument + * efi_install_fdt() - install fdt passed by a command argument * @fdt_opt: pointer to argument * Return: status code * * If specified, fdt will be installed as configuration table, * otherwise no fdt will be passed. */ -static efi_status_t efi_process_fdt(const char *fdt_opt) +static efi_status_t efi_install_fdt(const char *fdt_opt) { unsigned long fdt_addr; + void *fdt; + bootm_headers_t img = { 0 }; efi_status_t ret; if (fdt_opt) { + /* Install device tree */ fdt_addr = simple_strtoul(fdt_opt, NULL, 16); if (!fdt_addr && *fdt_opt != '0') return EFI_INVALID_PARAMETER; - /* Install device tree */ - ret = efi_install_fdt(fdt_addr); + fdt = map_sysmem(fdt_addr, 0); + if (fdt_check_header(fdt)) { + printf("ERROR: invalid device tree\n"); + return EFI_INVALID_PARAMETER; + } + + /* Create memory reservation as indicated by the device tree */ + efi_carve_out_dt_rsv(fdt); + + /* Prepare fdt for payload */ + ret = copy_fdt(&fdt); + if (ret) + return ret; + + if (image_setup_libfdt(&img, fdt, 0, NULL)) { + printf("ERROR: failed to process device tree\n"); + return EFI_LOAD_ERROR; + } + + /* Link to it in the efi tables */ + ret = efi_install_configuration_table(&efi_guid_fdt, fdt); if (ret != EFI_SUCCESS) { printf("ERROR: failed to install device tree\n"); - return ret; + return EFI_OUT_OF_RESOURCES; } } else { /* Remove device tree. EFI_NOT_FOUND can be ignored here */ @@ -456,7 +445,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; - r = efi_process_fdt(argc > 2 ? argv[2] : NULL); + r = efi_install_fdt(argc > 2 ? argv[2] : NULL); if (r == EFI_INVALID_PARAMETER) return CMD_RET_USAGE; else if (r != EFI_SUCCESS) From patchwork Fri Apr 19 03:22:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087942 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="AbYU+3An"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhHc2PNlz9s4V for ; Fri, 19 Apr 2019 13:27:40 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 0DD88C21E2C; Fri, 19 Apr 2019 03:24:18 +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_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 2140DC21E35; Fri, 19 Apr 2019 03:23:57 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7234FC21E1D; Fri, 19 Apr 2019 03:23:36 +0000 (UTC) Received: from mail-yb1-f194.google.com (mail-yb1-f194.google.com [209.85.219.194]) by lists.denx.de (Postfix) with ESMTPS id B870FC21DCA for ; Fri, 19 Apr 2019 03:23:34 +0000 (UTC) Received: by mail-yb1-f194.google.com with SMTP id i10so1614157ybk.0 for ; Thu, 18 Apr 2019 20:23:34 -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=HGObLMQI20a1ZUquvtZW3yYG5kjwx7BD4573S+xtsEU=; b=AbYU+3An6pZYTpjqP33F1BvIggqpWSVaXL24+3NsuWTUmjra6L990OD7D+FnPA36Qo qc5pKsIZgjLt+g4nUm3m/hw42C7rzcsr/wpjUBakxdEA9LqAYOkCx2l2DaX6yOUacfcx iHfaHGn9ykuRoVakubP5k12HMdDrb8joKeJYr59e9Pger1Zwv/wMvciZvBfqcURMtG0N yr1VkWqShFA12p0aCk1elfCKNbZt2lA6dMLcQs1OGpLQ1BpC+iboY74LrNgQrMg1oHD8 76dgmT3thxQLtw9eEDlQ3I6lQQeWNhtqBZoJofxKzVJfLgfKyFT3htkJDCGbp4csQqID XfGA== 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=HGObLMQI20a1ZUquvtZW3yYG5kjwx7BD4573S+xtsEU=; b=MkHQEvWIcKBvUbmaLwtHtO10DIEiwdzem2mXWvxEvuBLB2tIBDQcfYCKI8ShofCUjL n31PdX8K4Ut70T1VAkWcqvzyN0gdLQ8lJpg1hnla8ySbodakpCGT4sn9ZO8NQe0sHfnA 9rJh2X5caWpXMmBEZZtf1LYe3hwLgqfhwvGa+onH6A5OEECOpIy+7hiT4K3OFbz1mhF6 MzpJa0eRHuV9dXPLm7jcD0ISWIWBPL2KJsk3vt/CC8Af2PKRJjSsQRyOfvIYLxaCCa7C Ovhuq2xQ854PTGbqJ4FWSn31JF2jQju5RW+kYpPMAxdeld2h016WPp/OVXvr6HQiQekt nVDg== X-Gm-Message-State: APjAAAXvOmXyZ7wFCECE1Hwwcku9ND0OaU6WyFbDCpIsKZSd1MKm1Ifd Df94c40Sh6e9brD6jg6+SFimZKExqQI= X-Google-Smtp-Source: APXvYqy6kpZ3b/OoA7Vke5s4hSqUChJYrkKeMQvUEvVUhpAFFXnYXON/r9aglSDq5mMWgaaD6Ohy0g== X-Received: by 2002:a25:c246:: with SMTP id s67mr1010671ybf.165.1555644213702; Thu, 18 Apr 2019 20:23:33 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 12sm1293132yww.88.2019.04.18.20.23.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:33 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:31 +0900 Message-Id: <20190419032236.8242-5-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 4/9] cmd: bootefi: carve out efi_selftest code from do_bootefi() 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" This is a preparatory patch for reworking do_bootefi() in later patch. Efi_selftest code is unusual in terms of execution path in do_bootefi(), which make that function complicated and hard to understand. With this patch, all efi_selftest related code will be put in a separate function. The change also includes expanding efi_run_prepare() and efi_run_finish() in do_bootefi_exec(). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 145 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 92 insertions(+), 53 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index c6d6eb7312e8..e73b4cb563cd 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -239,37 +239,6 @@ static efi_status_t efi_install_fdt(const char *fdt_opt) return EFI_SUCCESS; } -static efi_status_t bootefi_run_prepare(const char *load_options_path, - struct efi_device_path *device_path, - struct efi_device_path *image_path, - struct efi_loaded_image_obj **image_objp, - struct efi_loaded_image **loaded_image_infop) -{ - efi_status_t ret; - - ret = efi_setup_loaded_image(device_path, image_path, image_objp, - loaded_image_infop); - if (ret != EFI_SUCCESS) - return ret; - - /* Transfer environment variable as load options */ - return set_load_options((efi_handle_t)*image_objp, load_options_path); -} - -/** - * bootefi_run_finish() - finish up after running an EFI test - * - * @loaded_image_info: Pointer to a struct which holds the loaded image info - * @image_objj: Pointer to a struct which holds the loaded image object - */ -static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, - struct efi_loaded_image *loaded_image_info) -{ - efi_restore_gd(); - free(loaded_image_info->load_options); - efi_delete_handle(&image_obj->header); -} - /** * do_bootefi_exec() - execute EFI binary * @@ -316,11 +285,16 @@ static efi_status_t do_bootefi_exec(void *efi, assert(device_path && image_path); } - ret = bootefi_run_prepare("bootargs", device_path, image_path, - &image_obj, &loaded_image_info); + ret = efi_setup_loaded_image(device_path, image_path, &image_obj, + &loaded_image_info); if (ret) goto err_prepare; + /* Transfer environment variable as load options */ + ret = set_load_options((efi_handle_t)image_obj, "bootargs"); + if (ret != EFI_SUCCESS) + goto err_prepare; + /* Load the EFI payload */ ret = efi_load_pe(image_obj, efi, loaded_image_info); if (ret != EFI_SUCCESS) @@ -344,7 +318,9 @@ static efi_status_t do_bootefi_exec(void *efi, err_prepare: /* image has returned, loaded-image obj goes *poof*: */ - bootefi_run_finish(image_obj, loaded_image_info); + efi_restore_gd(); + free(loaded_image_info->load_options); + efi_delete_handle(&image_obj->header); err_add_protocol: if (mem_handle) @@ -354,6 +330,23 @@ err_add_protocol: } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST +static efi_status_t bootefi_run_prepare(const char *load_options_path, + struct efi_device_path *device_path, + struct efi_device_path *image_path, + struct efi_loaded_image_obj **image_objp, + struct efi_loaded_image **loaded_image_infop) +{ + efi_status_t ret; + + ret = efi_setup_loaded_image(device_path, image_path, image_objp, + loaded_image_infop); + if (ret != EFI_SUCCESS) + return ret; + + /* Transfer environment variable as load options */ + return set_load_options((efi_handle_t)*image_objp, load_options_path); +} + /** * bootefi_test_prepare() - prepare to run an EFI test * @@ -399,6 +392,64 @@ failure: return ret; } +/** + * bootefi_run_finish() - finish up after running an EFI test + * + * @loaded_image_info: Pointer to a struct which holds the loaded image info + * @image_obj: Pointer to a struct which holds the loaded image object + */ +static void bootefi_run_finish(struct efi_loaded_image_obj *image_obj, + struct efi_loaded_image *loaded_image_info) +{ + efi_restore_gd(); + free(loaded_image_info->load_options); + efi_delete_handle(&image_obj->header); +} + +/** + * do_efi_selftest() - execute EFI Selftest + * + * @fdt_opt: string of fdt start address + * Return: status code + * + * Execute EFI Selftest + */ +static int do_efi_selftest(const char *fdt_opt) +{ + struct efi_loaded_image_obj *image_obj; + struct efi_loaded_image *loaded_image_info; + efi_status_t ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + ret = bootefi_test_prepare(&image_obj, &loaded_image_info, + "\\selftest", "efi_selftest"); + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + + /* Execute the test */ + ret = EFI_CALL(efi_selftest(&image_obj->header, &systab)); + bootefi_run_finish(image_obj, loaded_image_info); + + return ret != EFI_SUCCESS; +} #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ static int do_bootefi_bootmgr_exec(void) @@ -429,6 +480,13 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) char *saddr; efi_status_t r; + if (argc < 2) + return CMD_RET_USAGE; +#ifdef CONFIG_CMD_BOOTEFI_SELFTEST + else if (!strcmp(argv[1], "selftest")) + return do_efi_selftest(argc > 2 ? argv[2] : NULL); +#endif + /* Allow unaligned memory access */ allow_unaligned(); @@ -442,9 +500,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return CMD_RET_FAILURE; } - if (argc < 2) - return CMD_RET_USAGE; - r = efi_install_fdt(argc > 2 ? argv[2] : NULL); if (r == EFI_INVALID_PARAMETER) return CMD_RET_USAGE; @@ -462,22 +517,6 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) addr = CONFIG_SYS_LOAD_ADDR; memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); } else -#endif -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST - if (!strcmp(argv[1], "selftest")) { - struct efi_loaded_image_obj *image_obj; - struct efi_loaded_image *loaded_image_info; - - r = bootefi_test_prepare(&image_obj, &loaded_image_info, - "\\selftest", "efi_selftest"); - if (r != EFI_SUCCESS) - return CMD_RET_FAILURE; - - /* Execute the test */ - r = EFI_CALL(efi_selftest(&image_obj->header, &systab)); - bootefi_run_finish(image_obj, loaded_image_info); - return r != EFI_SUCCESS; - } else #endif if (!strcmp(argv[1], "bootmgr")) { return do_bootefi_bootmgr_exec(); From patchwork Fri Apr 19 03:22:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087936 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="rpJV0Iwu"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhDS3CDyz9s4V for ; Fri, 19 Apr 2019 13:24:56 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 06F9BC21DD3; Fri, 19 Apr 2019 03:23:51 +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=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 172EFC21DF9; Fri, 19 Apr 2019 03:23:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6C1D9C21E0D; Fri, 19 Apr 2019 03:23:40 +0000 (UTC) Received: from mail-yw1-f66.google.com (mail-yw1-f66.google.com [209.85.161.66]) by lists.denx.de (Postfix) with ESMTPS id F0E10C21E1E for ; Fri, 19 Apr 2019 03:23:36 +0000 (UTC) Received: by mail-yw1-f66.google.com with SMTP id z9so1479084ywd.6 for ; Thu, 18 Apr 2019 20:23:36 -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=0TSYAFv1gZIPvDmCP5wUUYhb5V6QIe1sYBzOYcLtrKY=; b=rpJV0Iwuli1Ubn8EkEUcHNzorf/nZPAgL4qFh6RYQAebdQV9GU5NUq6yIO5s6WoRfq eFbuILD/9SrpmeHoFpTrfwDdwLRrGd1g6LQm4YqrqpgjkxDHz7kiMjoi3nJ6unzV8Mbs LeeE6Jobsr7YDUkmsFLkKHcqoNznMVqM6+TkYavxi+qaEpcfg+prEpuvmTKxXLQfiYmn 8M7FrlcokvQ0DTlCBUSmlnEpDMq8k1aXDb3hWPWg4g5j/8usKs1tkH3AeH6EIzuXR+3E MlBYFPrXe+3VqjF+Dz9HaC6raexsoEhxSWo1bncVsRnggmVLslVZ2QOp+L16zL6M9WMV LpqQ== 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=0TSYAFv1gZIPvDmCP5wUUYhb5V6QIe1sYBzOYcLtrKY=; b=sazEVbA7BBdgImU+zJ27QQ5qd2hCzx50IEfWcqCwKNspyfj47mG3TtnnPiVwL82IZp 9YPQLwP2xmD9USGzmTshs39g7IByKfI21MOYJzfOcH/YxMH2WLybBYup+U1WabvKrUBL 7gLWzE+5hysEoL4gWlPHENDrIL3nnDVabmjutcCoXzRvw7hlLb0diG3ZRIOIfuOHLjCj JhLxNKamm+ImuZqjGXBtMie48y8LwisOg90hOGlx56lVDVIQIyOH6j9zs6bYRnQ12Gzb e2ndv7DA1045Rx8+N/IR4kJyrvEP5+zpm4Xp/o8MQjo8P7vNF1ec1bzZj3Qv9Ubcz3xf PC5w== X-Gm-Message-State: APjAAAVZFZTdB/xWDjvldh/jJmJ7ErvT6sx5R4Ql7ZXk/Nd5KrrXCe55 0ri2a3/Pxitn8U9lL8VRGR2ncg8k5DY= X-Google-Smtp-Source: APXvYqyiqkEYE0LCzIDhrGaf1xdsuqhiHk9S86yf24ki93Db9XewS6/+ZUn9RJfRPEGS6hpzuBcrBA== X-Received: by 2002:a0d:d9d6:: with SMTP id b205mr931055ywe.508.1555644215986; Thu, 18 Apr 2019 20:23:35 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id z193sm1432948ywa.70.2019.04.18.20.23.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:35 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:32 +0900 Message-Id: <20190419032236.8242-6-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 5/9] cmd: bootefi: move do_bootefi_bootmgr_exec() forward 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" This is a preparatory patch for reworking do_bootefi() in later patch. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index e73b4cb563cd..d8ddd770e031 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -329,6 +329,27 @@ err_add_protocol: return ret; } +static int do_bootefi_bootmgr_exec(void) +{ + struct efi_device_path *device_path, *file_path; + void *addr; + efi_status_t r; + + addr = efi_bootmgr_load(&device_path, &file_path); + if (!addr) + return 1; + + printf("## Starting EFI application at %p ...\n", addr); + r = do_bootefi_exec(addr, device_path, file_path); + printf("## Application terminated, r = %lu\n", + r & ~EFI_ERROR_MASK); + + if (r != EFI_SUCCESS) + return 1; + + return 0; +} + #ifdef CONFIG_CMD_BOOTEFI_SELFTEST static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, @@ -452,27 +473,6 @@ static int do_efi_selftest(const char *fdt_opt) } #endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ -static int do_bootefi_bootmgr_exec(void) -{ - struct efi_device_path *device_path, *file_path; - void *addr; - efi_status_t r; - - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; - - printf("## Starting EFI application at %p ...\n", addr); - r = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); - - if (r != EFI_SUCCESS) - return 1; - - return 0; -} - /* Interpreter command to boot an arbitrary EFI image from memory */ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { From patchwork Fri Apr 19 03:22: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: 1087935 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="J81zdA/0"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhCs0VHYz9s4V for ; Fri, 19 Apr 2019 13:24:25 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id A40DCC21DD7; Fri, 19 Apr 2019 03:24:05 +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_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 9C58FC21DFB; Fri, 19 Apr 2019 03:23:50 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A8BA9C21E12; Fri, 19 Apr 2019 03:23:42 +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 4A34EC21DC1 for ; Fri, 19 Apr 2019 03:23:39 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id e76so1608218ybc.3 for ; Thu, 18 Apr 2019 20:23:39 -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=PAhCOV+H/iPXdi1BmDt4xNNajEhoa9Z/0u0y1F8Ppvw=; b=J81zdA/0G2cl0bA+mR7A1NMtTMzmakwc00d/Jc8VGMTBknHQcIOern06ZTaEAlmO34 +LumhSWQKD4z9YAF33Gijn7UYECaYFxdOp+vddq8BZCaLsBWr6gcDLYThlcBhWTtIT3a nJ3+drT+/y5DBQ+C4hYG3vihZr5yamIIc3mFWOoxx+wod0U8StW1SIzP5VGDn9fmeguP kJggMiXwdNlfOfjAHlqkhNCPT5NuuiNgaVwOBbo3AIxIi+/SmRLyRpwzqNtYCvjWS85r kQq9OPBtBq3Yh5q9xpisB4Eh8n94DVbH5OQmmzKQKGTM0TnB4wzKpsJOc7YkaKmCsS1u j6mA== 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=PAhCOV+H/iPXdi1BmDt4xNNajEhoa9Z/0u0y1F8Ppvw=; b=itEjx/V1ZXhWlMt0LtZp9DkdMop4z2jemY+OuLtQ6WGfRwtvf95Ol2O2wc/v30Dr7J Q9KGGQ6srxSxXSvByhdCGtFB96CRnGz43XBbAzFP1M/2Ff43xVI2SJljLfJNNWQ+mKvL dJ/YscNDJc5WAEqY6Q+zJEfUr46k11lADwoDSAXzLVHs3X4BZ0rfgACOnMBi8ThF50W3 kv7z+O0tTT0Hcyeo9e+JW6+I8iVDpm68xhTdxTmKU/F1afECNO0Cz8c2e6sSp3UgTViX k8WAhH0OFSo4yn8WVOWyIRMpNRKllNhSfwXpF4R9YnREji3AjIbPa3d0CkPAcyJrl6mx UJlg== X-Gm-Message-State: APjAAAVQd3gdMSOkbSW8QT5Se7oKL+W5Qmt9bmRIUZvnV0+3SVag4Eoa +6N/x4VAsvuaPY0o4AhvAeiudw== X-Google-Smtp-Source: APXvYqzLTZb9bsw2WszQQB+WCxWutT9qgR056pnDhcVPXMAf2eRDPvxD5ARcmwkZPHFgEbFmeyAxQg== X-Received: by 2002:a25:cb0e:: with SMTP id b14mr913606ybg.405.1555644218280; Thu, 18 Apr 2019 20:23:38 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id v144sm1628125ywc.37.2019.04.18.20.23.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:37 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:33 +0900 Message-Id: <20190419032236.8242-7-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 6/9] cmd: bootefi: carve out bootmgr code from do_bootefi() 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" This is a preparatory patch for reworking do_bootefi() in later patch. do_bootmgr_exec() is renamed to do_efibootmgr() as we put all the necessary code into this function. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index d8ddd770e031..2822456d8128 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -329,22 +329,49 @@ err_add_protocol: return ret; } -static int do_bootefi_bootmgr_exec(void) +/** + * do_efibootmgr() - execute EFI Boot Manager + * + * @fdt_opt: string of fdt start address + * Return: status code + * + * Execute EFI Boot Manager + */ +static int do_efibootmgr(const char *fdt_opt) { struct efi_device_path *device_path, *file_path; void *addr; - efi_status_t r; + efi_status_t ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; addr = efi_bootmgr_load(&device_path, &file_path); if (!addr) return 1; printf("## Starting EFI application at %p ...\n", addr); - r = do_bootefi_exec(addr, device_path, file_path); + ret = do_bootefi_exec(addr, device_path, file_path); printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); + ret & ~EFI_ERROR_MASK); - if (r != EFI_SUCCESS) + if (ret != EFI_SUCCESS) return 1; return 0; @@ -482,6 +509,9 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) if (argc < 2) return CMD_RET_USAGE; + + if (!strcmp(argv[1], "bootmgr")) + return do_efibootmgr(argc > 2 ? argv[2] : NULL); #ifdef CONFIG_CMD_BOOTEFI_SELFTEST else if (!strcmp(argv[1], "selftest")) return do_efi_selftest(argc > 2 ? argv[2] : NULL); @@ -518,9 +548,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); } else #endif - if (!strcmp(argv[1], "bootmgr")) { - return do_bootefi_bootmgr_exec(); - } else { + { saddr = argv[1]; addr = simple_strtoul(saddr, NULL, 16); From patchwork Fri Apr 19 03:22:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087940 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="y0kuG82O"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhHD4rMvz9s4V for ; Fri, 19 Apr 2019 13:27:20 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4FCB4C21E1E; Fri, 19 Apr 2019 03:25:47 +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=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 7D898C21DF8; Fri, 19 Apr 2019 03:25:42 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D09E8C21E0D; Fri, 19 Apr 2019 03:23:45 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id A3A51C21E2B for ; Fri, 19 Apr 2019 03:23:41 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id b18so1586904yba.12 for ; Thu, 18 Apr 2019 20:23:41 -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=dkF5IFJicmd6szv0OabpVcj/lwV6qcU1+rAhtv8jn18=; b=y0kuG82OHfQJtCoId3KGqccCU5wSlBKQCHlF8maCKlafYE/NwM60WBjsmy9wyoUFMS ciWpFlQU0ImQGaSDoHaXhbk9I02EuPfNRPDLt1sBt3YoYk2ym1iROu7d7KLi288m0ZML 2N8ptAEboVUJxvYPjWEIxAyl5pfW8gBmP85INoG1iQN4Deyk0DaDOtuyKuG1u0vyOawr 4tP/hr0tZlsSgI2GrtD3jLG7hZMUjbvBjKlAdp9zTBk+NXPCUU/Yw+yBW6E0VVDy4qA9 Y06gbQmfmdWu96cx6zXUZoh0uMRcVE99ml7h5T2wqkZ8j5NMS8kCQHTS/efxv56inZw5 rr6A== 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=dkF5IFJicmd6szv0OabpVcj/lwV6qcU1+rAhtv8jn18=; b=tnrKWep6KbACCcY4+yI84YvlwWQX9japEb7Q15EUiCSlk2yw6qGfNRviUHuB1/OaOe tLMUG+9WXzZKuPkp7oIpJrSE37I9u7FBAb0wQLcYv7mN9Ri93niEOqsYaTc8tlFuYiQJ 4cN2sBE1zT6j+pLtQ9HZSJmCYEbtRu5KyYLyQBB6LAg3RTOx/wvP9YoXLk7KziMHZVG8 UGzhImTpe0P9lmYMw138YAro6tBMr+NXC1tYlv8fpo2gBrxr6SbyDYri/xhFTIXLavds jgFjJzmp+gWtS/tl3aG8kfYIcLTWe9m3bZXjs7LPBU1udf1hH4x/o9Llf0iNUQB8bEcu 6Qfg== X-Gm-Message-State: APjAAAUC5NH/2mrebrVMgXJSYrP2Z0kO/mScpITcMveb+iWZpX/PYMT2 ay0HkSinKO4y9qYBaZtqhUj1Fw== X-Google-Smtp-Source: APXvYqw2wUmC03fsxDKPGcy72TD4sbv12rlhKnGKY4cnb07sHJyrvHY6r6GGPyDvDeVd0zNSU1nWqQ== X-Received: by 2002:a5b:549:: with SMTP id r9mr1036190ybp.88.1555644220648; Thu, 18 Apr 2019 20:23:40 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id j83sm1255581ywj.93.2019.04.18.20.23.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:40 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:34 +0900 Message-Id: <20190419032236.8242-8-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 7/9] cmd: bootefi: carve out do_bootefi_image() from do_bootefi() 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" This is a preparatory patch for reworking do_bootefi() in later patch. All the non-boot-manager-based (that is, bootefi ) code is put into one function, do_bootefi_image(). Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 122 +++++++++++++++++++++++++++----------------------- 1 file changed, 67 insertions(+), 55 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 2822456d8128..e2ca68c4dc12 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -377,6 +377,72 @@ static int do_efibootmgr(const char *fdt_opt) return 0; } +/* + * do_bootefi_image() - execute EFI binary from command line + * + * @image_opt: string of image start address + * @fdt_opt: string of fdt start address + * Return: status code + * + * Set up memory image for the binary to be loaded, prepare + * device path and then call do_bootefi_exec() to execute it. + */ +static int do_bootefi_image(const char *image_opt, const char *fdt_opt) +{ + unsigned long addr; + efi_status_t ret; + + /* Allow unaligned memory access */ + allow_unaligned(); + + switch_to_non_secure_mode(); + + /* Initialize EFI drivers */ + ret = efi_init_obj_list(); + if (ret != EFI_SUCCESS) { + printf("Error: Cannot initialize UEFI sub-system, r = %lu\n", + ret & ~EFI_ERROR_MASK); + return CMD_RET_FAILURE; + } + + ret = efi_install_fdt(fdt_opt); + if (ret == EFI_INVALID_PARAMETER) + return CMD_RET_USAGE; + else if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + +#ifdef CONFIG_CMD_BOOTEFI_HELLO + if (!strcmp(image_opt, "hello")) { + char *saddr; + ulong size = __efi_helloworld_end - __efi_helloworld_begin; + + saddr = env_get("loadaddr"); + if (saddr) + addr = simple_strtoul(saddr, NULL, 16); + else + addr = CONFIG_SYS_LOAD_ADDR; + memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); + } else +#endif + { + addr = simple_strtoul(image_opt, NULL, 16); + /* Check that a numeric value was passed */ + if (!addr && *image_opt != '0') + return CMD_RET_USAGE; + } + + printf("## Starting EFI application at %08lx ...\n", addr); + ret = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, + bootefi_image_path); + printf("## Application terminated, r = %lu\n", + ret & ~EFI_ERROR_MASK); + + if (ret != EFI_SUCCESS) + return CMD_RET_FAILURE; + else + return CMD_RET_SUCCESS; +} + #ifdef CONFIG_CMD_BOOTEFI_SELFTEST static efi_status_t bootefi_run_prepare(const char *load_options_path, struct efi_device_path *device_path, @@ -503,10 +569,6 @@ static int do_efi_selftest(const char *fdt_opt) /* Interpreter command to boot an arbitrary EFI image from memory */ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - unsigned long addr; - char *saddr; - efi_status_t r; - if (argc < 2) return CMD_RET_USAGE; @@ -517,57 +579,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) return do_efi_selftest(argc > 2 ? argv[2] : NULL); #endif - /* Allow unaligned memory access */ - allow_unaligned(); - - switch_to_non_secure_mode(); - - /* 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; - } - - r = efi_install_fdt(argc > 2 ? argv[2] : NULL); - if (r == EFI_INVALID_PARAMETER) - return CMD_RET_USAGE; - else if (r != EFI_SUCCESS) - return CMD_RET_FAILURE; - -#ifdef CONFIG_CMD_BOOTEFI_HELLO - if (!strcmp(argv[1], "hello")) { - ulong size = __efi_helloworld_end - __efi_helloworld_begin; - - saddr = env_get("loadaddr"); - if (saddr) - addr = simple_strtoul(saddr, NULL, 16); - else - addr = CONFIG_SYS_LOAD_ADDR; - memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); - } else -#endif - { - saddr = argv[1]; - - addr = simple_strtoul(saddr, NULL, 16); - /* Check that a numeric value was passed */ - if (!addr && *saddr != '0') - return CMD_RET_USAGE; - - } - - printf("## Starting EFI application at %08lx ...\n", addr); - r = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, - bootefi_image_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); - - if (r != EFI_SUCCESS) - return 1; - else - return 0; + return do_bootefi_image(argv[1], argc > 2 ? argv[2] : NULL); } #ifdef CONFIG_SYS_LONGHELP From patchwork Fri Apr 19 03:22:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087941 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="wCuhMfFT"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhHW4zb3z9s4V for ; Fri, 19 Apr 2019 13:27:35 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 63754C21DF9; Fri, 19 Apr 2019 03:25:10 +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=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 F163AC21DE8; Fri, 19 Apr 2019 03:25:08 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id BCA71C21E0F; Fri, 19 Apr 2019 03:23:48 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id 8F766C21E39 for ; Fri, 19 Apr 2019 03:23:44 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id u187so1585515ybg.11 for ; Thu, 18 Apr 2019 20:23: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=IjVFbfTIxIM0kIgHTMQEPRJOzezc0M/kIuHUQUmIAA0=; b=wCuhMfFT5zFEOMygDPvClbpN8aJ9aTiW6k6T+E0/feFUVXtBzbn5Mxi2VZE+ZsxSJJ CsmsXG7LoRoSVw0Zybq55g6AQc1ELueAS+YO+SClzuH6K6M3syZTv4OdyYNracP2Y+YA 6crBm71uahO+ZN3tpmIIYlNDKNc3tkxQPZSQIK8bTZ3DqebyxgVwSN1QvwkrA6uQliBG ewNvP1JEwt/paWuDG5ZHo+rzCGDU//Ta1ZlIYP/rQGooBuk1Kt8e3aeQyDMn7pOTvkMB V2a6FYrK0v5c19vQpiOGQFTajYGtbn3qLZIuDoQ9jacZabT8FQm/im6MyIqzDwVpj+G4 usIQ== 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=IjVFbfTIxIM0kIgHTMQEPRJOzezc0M/kIuHUQUmIAA0=; b=qfpskZyPq2c2O1iHk+NVyYByt03GCBLlbUH8ZIigZNYh4s0y2+1zzT7md+Phr1FIsB mGbHBVR1NFwl7pzZzL9HcLBQqErEd/to9usPSoTo+Dh8q6p1czgPG6yMjdpxtT4pVPDT A5MZJCK/2WjkEF3VJSdn2+slMKOcjjxkGMK0LH0j2alTOUO+3thHGl9IzNgZdxpAQwt8 XnSR+aG7Q8cbNCy4tal6JfrBw69R7gtjW44rhERAIUk6/JYf2GSiglAWydWXqvYaY3aM z/5x0YLUyTAKz0IyXYt2yABDHF0qxPdzwVGwAD55gtdn8Ck1s1pJByLcc0HucrMJ//9f nFrA== X-Gm-Message-State: APjAAAXuk2HM/35qYkN/PJvJCpnH6sPTNNDvyQ33PU4xJW46CQc0Y6WJ wH+WF/mI2/uzOQeVtnPQbQ4i+g== X-Google-Smtp-Source: APXvYqyEizndWNjK4jrIjwHrKJKt1IHMZuqIrt3dtl53S0ksfZt1QxwTT4CfEmLhTOzBMjR4ZLaMNQ== X-Received: by 2002:a25:d84:: with SMTP id 126mr968329ybn.385.1555644223386; Thu, 18 Apr 2019 20:23:43 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id e14sm2587776ywa.8.2019.04.18.20.23.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:42 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:35 +0900 Message-Id: <20190419032236.8242-9-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 8/9] efi_loader: rework bootmgr/bootefi using load_image API 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 the current implementation, bootefi command and EFI boot manager don't use load_image API, instead, use more primitive and internal functions. This will introduce duplicated code and potentially unknown bugs as well as inconsistent behaviours. With this patch, do_efibootmgr() and do_boot_efi() are completely overhauled and re-implemented using load_image API. Signed-off-by: AKASHI Takahiro Reviewed-by: Heinrich Schuchardt --- cmd/bootefi.c | 187 ++++++++++++++++++---------------- include/efi_loader.h | 5 +- lib/efi_loader/efi_bootmgr.c | 43 ++++---- lib/efi_loader/efi_boottime.c | 2 + 4 files changed, 127 insertions(+), 110 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index e2ca68c4dc12..8c84fff590a7 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -242,89 +242,36 @@ static efi_status_t efi_install_fdt(const char *fdt_opt) /** * do_bootefi_exec() - execute EFI binary * - * @efi: address of the binary - * @device_path: path of the device from which the binary was loaded - * @image_path: device path of the binary + * @handle: handle of loaded image * Return: status code * * Load the EFI binary into a newly assigned memory unwinding the relocation * information, install the loaded image protocol, and call the binary. */ -static efi_status_t do_bootefi_exec(void *efi, - struct efi_device_path *device_path, - struct efi_device_path *image_path) +static efi_status_t do_bootefi_exec(efi_handle_t handle) { - efi_handle_t mem_handle = NULL; - struct efi_device_path *memdp = NULL; efi_status_t ret; - struct efi_loaded_image_obj *image_obj = NULL; - struct efi_loaded_image *loaded_image_info = NULL; - - /* - * Special case for efi payload not loaded from disk, such as - * 'bootefi hello' or for example payload loaded directly into - * memory via JTAG, etc: - */ - if (!device_path && !image_path) { - printf("WARNING: using memory device/image path, this may confuse some payloads!\n"); - /* actual addresses filled in after efi_load_pe() */ - memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, 0, 0); - device_path = image_path = memdp; - /* - * Grub expects that the device path of the loaded image is - * installed on a handle. - */ - ret = efi_create_handle(&mem_handle); - if (ret != EFI_SUCCESS) - return ret; /* TODO: leaks device_path */ - ret = efi_add_protocol(mem_handle, &efi_guid_device_path, - device_path); - if (ret != EFI_SUCCESS) - goto err_add_protocol; - } else { - assert(device_path && image_path); - } - - ret = efi_setup_loaded_image(device_path, image_path, &image_obj, - &loaded_image_info); - if (ret) - goto err_prepare; /* Transfer environment variable as load options */ - ret = set_load_options((efi_handle_t)image_obj, "bootargs"); - if (ret != EFI_SUCCESS) - goto err_prepare; - - /* Load the EFI payload */ - ret = efi_load_pe(image_obj, efi, loaded_image_info); + ret = set_load_options(handle, "bootargs"); if (ret != EFI_SUCCESS) - goto err_prepare; - - if (memdp) { - struct efi_device_path_memory *mdp = (void *)memdp; - mdp->memory_type = loaded_image_info->image_code_type; - mdp->start_address = (uintptr_t)loaded_image_info->image_base; - mdp->end_address = mdp->start_address + - loaded_image_info->image_size; - } + return ret; /* we don't support much: */ env_set("efi_8be4df61-93ca-11d2-aa0d-00e098032b8c_OsIndicationsSupported", "{ro,boot}(blob)0000000000000000"); /* Call our payload! */ - debug("%s: Jumping to 0x%p\n", __func__, image_obj->entry); - ret = EFI_CALL(efi_start_image(&image_obj->header, NULL, NULL)); + ret = EFI_CALL(efi_start_image(handle, NULL, NULL)); -err_prepare: - /* image has returned, loaded-image obj goes *poof*: */ efi_restore_gd(); - free(loaded_image_info->load_options); - efi_delete_handle(&image_obj->header); -err_add_protocol: - if (mem_handle) - efi_delete_handle(mem_handle); + /* + * FIXME: Who is responsible for + * free(loaded_image_info->load_options); + * Once efi_exit() is implemented correctly, + * handle itself doesn't exist here. + */ return ret; } @@ -339,8 +286,7 @@ err_add_protocol: */ static int do_efibootmgr(const char *fdt_opt) { - struct efi_device_path *device_path, *file_path; - void *addr; + efi_handle_t handle; efi_status_t ret; /* Allow unaligned memory access */ @@ -362,19 +308,19 @@ static int do_efibootmgr(const char *fdt_opt) else if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; + ret = efi_bootmgr_load(&handle); + if (ret != EFI_SUCCESS) { + printf("EFI boot manager: Cannot load any image\n"); + return CMD_RET_FAILURE; + } - printf("## Starting EFI application at %p ...\n", addr); - ret = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - ret & ~EFI_ERROR_MASK); + ret = do_bootefi_exec(handle); + printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); if (ret != EFI_SUCCESS) - return 1; + return CMD_RET_FAILURE; - return 0; + return CMD_RET_SUCCESS; } /* @@ -389,7 +335,12 @@ static int do_efibootmgr(const char *fdt_opt) */ static int do_bootefi_image(const char *image_opt, const char *fdt_opt) { - unsigned long addr; + void *image_buf; + struct efi_device_path *device_path, *image_path; + struct efi_device_path *memdp = NULL, *file_path = NULL; + unsigned long addr, size; + const char *size_str; + efi_handle_t mem_handle = NULL, handle; efi_status_t ret; /* Allow unaligned memory access */ @@ -414,33 +365,90 @@ static int do_bootefi_image(const char *image_opt, const char *fdt_opt) #ifdef CONFIG_CMD_BOOTEFI_HELLO if (!strcmp(image_opt, "hello")) { char *saddr; - ulong size = __efi_helloworld_end - __efi_helloworld_begin; saddr = env_get("loadaddr"); + size = __efi_helloworld_end - __efi_helloworld_begin; + if (saddr) addr = simple_strtoul(saddr, NULL, 16); else addr = CONFIG_SYS_LOAD_ADDR; - memcpy(map_sysmem(addr, size), __efi_helloworld_begin, size); + + image_buf = map_sysmem(addr, size); + memcpy(image_buf, __efi_helloworld_begin, size); + + device_path = NULL; + image_path = NULL; } else #endif { + size_str = env_get("filesize"); + if (size_str) + size = simple_strtoul(size_str, NULL, 16); + else + size = 0; + addr = simple_strtoul(image_opt, NULL, 16); /* Check that a numeric value was passed */ if (!addr && *image_opt != '0') return CMD_RET_USAGE; + + image_buf = map_sysmem(addr, size); + + device_path = bootefi_device_path; + image_path = bootefi_image_path; } - printf("## Starting EFI application at %08lx ...\n", addr); - ret = do_bootefi_exec(map_sysmem(addr, 0), bootefi_device_path, - bootefi_image_path); - printf("## Application terminated, r = %lu\n", - ret & ~EFI_ERROR_MASK); + if (!device_path && !image_path) { + /* + * Special case for efi payload not loaded from disk, + * such as 'bootefi hello' or for example payload + * loaded directly into memory via JTAG, etc: + */ + memdp = efi_dp_from_mem(EFI_RESERVED_MEMORY_TYPE, + (uintptr_t)image_buf, size); + file_path = memdp; /* append(memdp, NULL) */ + + /* + * Make sure that device for device_path exist + * in load_image(). Otherwise, shell and grub will fail. + */ + ret = efi_create_handle(&mem_handle); + if (ret != EFI_SUCCESS) + /* TODO: leaks device_path */ + goto err_add_protocol; + + ret = efi_add_protocol(mem_handle, &efi_guid_device_path, + memdp); + if (ret != EFI_SUCCESS) + goto err_add_protocol; + } else { + assert(device_path && image_path); + file_path = efi_dp_append(device_path, image_path); + } + + ret = EFI_CALL(efi_load_image(false, efi_root, + file_path, image_buf, size, &handle)); + if (ret != EFI_SUCCESS) + goto err_prepare; + + ret = do_bootefi_exec(handle); + printf("## Application terminated, r = %lu\n", ret & ~EFI_ERROR_MASK); + +err_prepare: + if (device_path) + efi_free_pool(file_path); + +err_add_protocol: + if (mem_handle) + efi_delete_handle(mem_handle); + if (file_path) /* hence memdp */ + efi_free_pool(file_path); if (ret != EFI_SUCCESS) return CMD_RET_FAILURE; - else - return CMD_RET_SUCCESS; + + return CMD_RET_SUCCESS; } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST @@ -598,7 +606,7 @@ static char bootefi_help_text[] = " Use environment variable efi_selftest to select a single test.\n" " Use 'setenv efi_selftest list' to enumerate all tests.\n" #endif - "bootefi bootmgr [fdt addr]\n" + "bootefi bootmgr [fdt address]\n" " - load and boot EFI payload based on BootOrder/BootXXXX variables.\n" "\n" " If specified, the device tree located at gets\n" @@ -623,6 +631,13 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) ret = efi_dp_from_name(dev, devnr, path, &device, &image); if (ret == EFI_SUCCESS) { bootefi_device_path = device; + if (image) { + /* FIXME: image should not contain device */ + struct efi_device_path *image_tmp = image; + + efi_dp_split_file_path(image, &device, &image); + efi_free_pool(image_tmp); + } bootefi_image_path = image; } else { bootefi_device_path = NULL; diff --git a/include/efi_loader.h b/include/efi_loader.h index 93f7672aecbc..39ed8a6fa592 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -412,8 +412,6 @@ efi_status_t efi_setup_loaded_image(struct efi_device_path *device_path, struct efi_device_path *file_path, struct efi_loaded_image_obj **handle_ptr, struct efi_loaded_image **info_ptr); -efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, - void **buffer, efi_uintn_t *size); /* Print information about all loaded images */ void efi_print_image_infos(void *pc); @@ -567,8 +565,7 @@ struct efi_load_option { void efi_deserialize_load_option(struct efi_load_option *lo, u8 *data); unsigned long efi_serialize_load_option(struct efi_load_option *lo, u8 **data); -void *efi_bootmgr_load(struct efi_device_path **device_path, - struct efi_device_path **file_path); +efi_status_t efi_bootmgr_load(efi_handle_t *handle); #else /* CONFIG_IS_ENABLED(EFI_LOADER) */ diff --git a/lib/efi_loader/efi_bootmgr.c b/lib/efi_loader/efi_bootmgr.c index 4fccadc5483d..13ec79b2098b 100644 --- a/lib/efi_loader/efi_bootmgr.c +++ b/lib/efi_loader/efi_bootmgr.c @@ -120,14 +120,14 @@ static void *get_var(u16 *name, const efi_guid_t *vendor, * if successful. This checks that the EFI_LOAD_OPTION is active (enabled) * and that the specified file to boot exists. */ -static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, - struct efi_device_path **file_path) +static efi_status_t try_load_entry(u16 n, efi_handle_t *handle) { struct efi_load_option lo; u16 varname[] = L"Boot0000"; u16 hexmap[] = L"0123456789ABCDEF"; - void *load_option, *image = NULL; + void *load_option; efi_uintn_t size; + efi_status_t ret; varname[4] = hexmap[(n & 0xf000) >> 12]; varname[5] = hexmap[(n & 0x0f00) >> 8]; @@ -136,19 +136,19 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, load_option = get_var(varname, &efi_global_variable_guid, &size); if (!load_option) - return NULL; + return EFI_LOAD_ERROR; 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); - ret = efi_load_image_from_path(lo.file_path, &image, &size); - + ret = EFI_CALL(efi_load_image(false, (void *)0x1 /* FIXME */, + lo.file_path, NULL, 0, + handle)); if (ret != EFI_SUCCESS) goto error; @@ -159,17 +159,22 @@ static void *try_load_entry(uint16_t n, struct efi_device_path **device_path, L"BootCurrent", (efi_guid_t *)&efi_global_variable_guid, attributes, size, &n)); - if (ret != EFI_SUCCESS) + if (ret != EFI_SUCCESS) { + if (EFI_CALL(efi_unload_image(*handle)) + != EFI_SUCCESS) + printf("Unloading image failed\n"); goto error; + } printf("Booting: %ls\n", lo.label); - efi_dp_split_file_path(lo.file_path, device_path, file_path); + } else { + ret = EFI_LOAD_ERROR; } error: free(load_option); - return image; + return ret; } /* @@ -177,12 +182,10 @@ error: * EFI variable, the available load-options, finding and returning * the first one that can be loaded successfully. */ -void *efi_bootmgr_load(struct efi_device_path **device_path, - struct efi_device_path **file_path) +efi_status_t efi_bootmgr_load(efi_handle_t *handle) { u16 bootnext, *bootorder; efi_uintn_t size; - void *image = NULL; int i, num; efi_status_t ret; @@ -209,10 +212,9 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, /* load BootNext */ if (ret == EFI_SUCCESS) { if (size == sizeof(u16)) { - image = try_load_entry(bootnext, device_path, - file_path); - if (image) - return image; + ret = try_load_entry(bootnext, handle); + if (ret == EFI_SUCCESS) + return ret; } } else { printf("Deleting BootNext failed\n"); @@ -223,19 +225,20 @@ void *efi_bootmgr_load(struct efi_device_path **device_path, bootorder = get_var(L"BootOrder", &efi_global_variable_guid, &size); if (!bootorder) { printf("BootOrder not defined\n"); + ret = EFI_NOT_FOUND; goto error; } num = size / sizeof(uint16_t); for (i = 0; i < num; i++) { debug("%s: trying to load Boot%04X\n", __func__, bootorder[i]); - image = try_load_entry(bootorder[i], device_path, file_path); - if (image) + ret = try_load_entry(bootorder[i], handle); + if (ret == EFI_SUCCESS) break; } free(bootorder); error: - return image; + return ret; } diff --git a/lib/efi_loader/efi_boottime.c b/lib/efi_loader/efi_boottime.c index abc295e392e9..19a58144cf4b 100644 --- a/lib/efi_loader/efi_boottime.c +++ b/lib/efi_loader/efi_boottime.c @@ -1591,6 +1591,7 @@ failure: * @size: size of the loaded image * Return: status code */ +static efi_status_t efi_load_image_from_path(struct efi_device_path *file_path, void **buffer, efi_uintn_t *size) { @@ -2664,6 +2665,7 @@ efi_status_t EFIAPI efi_start_image(efi_handle_t image_handle, } current_image = image_handle; + EFI_PRINT("Jumping into 0x%p\n", image_obj->entry); ret = EFI_CALL(image_obj->entry(image_handle, &systab)); /* From patchwork Fri Apr 19 03:22:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1087937 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="pK5q1gXZ"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 44lhFz4wYnz9s4V for ; Fri, 19 Apr 2019 13:26:15 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 656FBC21CB1; Fri, 19 Apr 2019 03:25: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=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 C1155C21DFB; Fri, 19 Apr 2019 03:25:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 1B810C21E16; Fri, 19 Apr 2019 03:23:50 +0000 (UTC) Received: from mail-yb1-f196.google.com (mail-yb1-f196.google.com [209.85.219.196]) by lists.denx.de (Postfix) with ESMTPS id A7415C21DF9 for ; Fri, 19 Apr 2019 03:23:46 +0000 (UTC) Received: by mail-yb1-f196.google.com with SMTP id b18so1586970yba.12 for ; Thu, 18 Apr 2019 20:23:46 -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=kSzGtqopmFWGV1YB2tDhyancxug2eoEvBYpIDlTTbCs=; b=pK5q1gXZfU+XcG+ORijzLBE/UpJt0EmfcQsz10nCgHrz9SMzo0OudJu+YKRnLA/VtS Yj4sBlSHAF3cLoUyIXrk9rUcfjUht3XUXqq1YiqP6W0C4Ndi92KEVeyELMshI40q0oSe 1wflqzmyO5+LdKCBX2TbYNVOl1SREoycT9WkYuZoasphMqEYg0+CpyTlIXyrCTxw0Nr3 UTCne/BKbHYHw4ldS5S2hH/8MvnOVwhoaJT+PGaopvsASgJ2o+suvv5vLVthrX/b9/k1 gZvoQqEnTlDyBId3d2o2ce1w3ILcYVkhRsjkztucZei6L+tukPfdihYu+13bZ0+yZYrV IuKg== 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=kSzGtqopmFWGV1YB2tDhyancxug2eoEvBYpIDlTTbCs=; b=oQo6wD7IKximu5AQDsjyxFMAOu/RBEDZmQD55abiOVJz5moVxx69j9nsueni0l9s/U sYZhAqfNAAya3qFb2sgbeVE9Fzxr/2MZpGG2juxJD6zx03XvUYt9CQNMaNNZulyzN6nK Q8QbIXmwb8b1LijiK6Ug6pq98molzIARBA8WUZ4a7ZZy3cdiXTAK41wEjstP0ScZ/SR4 /M9SQYD+VwXCqMrywzswvxZLL3LCqeEGTPSNm58YMjZE7zxq6HrFPYnlC8IKmJ75XQsX 1IYnPfIUtcBX+miD8h6wv+SFwVECsK5MXyPXB6xdYJzvPisqMAjA34QTlBV1z3895bmV iqSQ== X-Gm-Message-State: APjAAAX4o94phU8OB/J22EATXKeU7rNnl9BSxLfdWjZYAGxDhq5uPPY9 YG0R4cn23ffPhwL/AOQhXVkTGQ== X-Google-Smtp-Source: APXvYqzygC7xdECWQqXNOt9QwFOcccbZM0/vM49vHhgLbHckAmEM13wermpL5QKS+jvirP8p+vX/4A== X-Received: by 2002:a25:c549:: with SMTP id v70mr1043655ybe.123.1555644225711; Thu, 18 Apr 2019 20:23:45 -0700 (PDT) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id 139sm1321155ywk.83.2019.04.18.20.23.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 Apr 2019 20:23:45 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de Date: Fri, 19 Apr 2019 12:22:36 +0900 Message-Id: <20190419032236.8242-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190419032236.8242-1-takahiro.akashi@linaro.org> References: <20190419032236.8242-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 9/9] cmd: add efibootmgr 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" Add CONFIG_CMD_STANDALONE_EFIBOOTMGR. With this patch, EFI boot manager can be kicked in by a standalone command, efibootmgr. Signed-off-by: AKASHI Takahiro --- cmd/Kconfig | 8 ++++++++ cmd/bootefi.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/cmd/Kconfig b/cmd/Kconfig index 2bdbfcb3d091..46222be4a3c6 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -224,6 +224,14 @@ config CMD_BOOTEFI help Boot an EFI image from memory. +config CMD_STANDALONE_EFIBOOTMGR + bool "Enable EFI Boot Manager as a standalone command" + depends on CMD_BOOTEFI + default n + help + With this option enabled, EFI Boot Manager can be invoked + as a standalone command. + config CMD_BOOTEFI_HELLO_COMPILE bool "Compile a standard EFI hello world binary for testing" depends on CMD_BOOTEFI && !CPU_V7M && !SANDBOX diff --git a/cmd/bootefi.c b/cmd/bootefi.c index 8c84fff590a7..348c6fdbe28d 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -644,3 +644,38 @@ void efi_set_bootdev(const char *dev, const char *devnr, const char *path) bootefi_image_path = NULL; } } + +#ifdef CONFIG_CMD_STANDALONE_EFIBOOTMGR +static int do_efibootmgr_cmd(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + char *fdt_opt; + int ret; + + if (argc != 1) + return CMD_RET_USAGE; + + fdt_opt = env_get("fdtaddr"); + if (!fdt_opt) + fdt_opt = env_get("fdtcontroladdr"); + + ret = do_efibootmgr(fdt_opt); + + free(fdt_opt); + + return ret; +} + +#ifdef CONFIG_SYS_LONGHELP +static char efibootmgr_help_text[] = + "(no arguments)\n" + " - Launch EFI boot manager and execute EFI application\n" + " based on BootNext and BootOrder variables\n"; +#endif + +U_BOOT_CMD( + efibootmgr, 1, 0, do_efibootmgr_cmd, + "Launch EFI boot manager", + efibootmgr_help_text +); +#endif /* CONFIG_CMD_STANDALONE_EFIBOOTMGR */