From patchwork Thu Feb 14 07:56: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: 1041895 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="MgIsayE7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 440TK33xlQz9sMp for ; Thu, 14 Feb 2019 18:57:59 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 13AF4C220C0; Thu, 14 Feb 2019 07:57:03 +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 BF0F2C22072; Thu, 14 Feb 2019 07:56:27 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 91A57C2208F; Thu, 14 Feb 2019 07:56:25 +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 F0743C220BA for ; Thu, 14 Feb 2019 07:56:20 +0000 (UTC) Received: by mail-yb1-f193.google.com with SMTP id x9so2031644ybj.5 for ; Wed, 13 Feb 2019 23:56:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6jUXQ2gDq9EKUwsVQPqtqdcKvnSOK9c5M5V9JavrInQ=; b=MgIsayE7dh8Bm1FtF3J//blJ6Rks9vxQtustFvMgOPicWbAq6Br54vtbRTIbznyZYl RDAuo5RUN8BJD7KfTryZPkLFsEslzZBoJ5wZdClltxWZhP78UFKN3kpLnHsUOAOw7aRF IV4cJ5Ww6zib1HjPaEnV/7XzIVWp8eLG9dBRl/0xPtRcCiy6RUywuOBebkLyQZHNpcWe uOGz3VAb51IOCOXDx53J2+EBRsJodmt9GZIgwyJCdAXsEI5cCUwdQ91kY/EBV5UzBdZw 0XuJAiu1GOFgkrwu1auMZlU/WkeUbjKLrW/vONNUiA3MG4fRBxUAV2ozSCJlRIhS5SZU Vfjg== 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=6jUXQ2gDq9EKUwsVQPqtqdcKvnSOK9c5M5V9JavrInQ=; b=ijkqhSyFSZ1iPDxog9l71tZ8IZOx2uol2a+e3f2u9HO5/jlAy/pvN1gFyVB2I92a79 3aowUlQ1ZbexiBILoUyO7Ogqx7U5GLv/SNTY+d5WvSk/Jbg1cdfcNLknM5l8UcC47bXU n1DWOAaN4C5AzFLx5jaX//8ItGIw+XXhLrHU7vXKxIBzCXCxD3VCGF1K9VoD8YsgaSEG fWNlWHCSXAvHBwBs5/HxZZLiJRJzgLvMK8h7/mxoivGT6V1QWmT+EdW8cKApoTn2ha4m aMeyuxY3gbBDZLGXOQaio0MXDQ3dS3DN6DYUIeSbntXfP5awMqOK4hEKnA5TO+zVUX+p Zy0g== X-Gm-Message-State: AHQUAuYMLPZ7SLr0GRtAPTbgKZDqcv/vIsyCve149XImCpxC4Wg63+CP Z5Ytr/tGk0WfGGXqfcAbFW2oIA== X-Google-Smtp-Source: AHgI3IbhAlLN5SlCpVGTGK59J6WiJpwu8RQOtGBhOLmGw4eX9X7xXN3F9QHSSWn9QUvkLReoaGhgxw== X-Received: by 2002:a25:3b93:: with SMTP id i141mr1837907yba.87.1550130979918; Wed, 13 Feb 2019 23:56:19 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id i7sm654657ywd.7.2019.02.13.23.56.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 23:56:19 -0800 (PST) From: AKASHI Takahiro To: agraf@suse.de, xypron.glpk@gmx.de Date: Thu, 14 Feb 2019 16:56:30 +0900 Message-Id: <20190214075630.6672-3-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190214075630.6672-1-takahiro.akashi@linaro.org> References: <20190214075630.6672-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH 2/2] cmd: bootefi: rework 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" In this patch, do_bootefi() will be reworked, without any functional change, as it is a bit sloppy after Heinrich's "efi_loader: rework loading and starting of images." Signed-off-by: AKASHI Takahiro --- cmd/bootefi.c | 101 ++++++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 49 deletions(-) diff --git a/cmd/bootefi.c b/cmd/bootefi.c index e064edcd0cdb..159dc1ab8a30 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -361,34 +361,68 @@ err_add_protocol: return ret; } -static int do_bootefi_bootmgr_exec(void) +static int do_bootefi_load_and_exec(const char *arg) { - struct efi_device_path *device_path, *file_path; - void *addr; + void *image_buf; + struct efi_device_path *device_path, *image_path; + const char *saddr; + unsigned long addr, size; efi_status_t r; - addr = efi_bootmgr_load(&device_path, &file_path); - if (!addr) - return 1; + if (!strcmp(arg, "bootmgr")) { + image_buf = efi_bootmgr_load(&device_path, &image_path); + if (!image_buf) + return CMD_RET_FAILURE; + + addr = map_to_sysmem(image_buf); + } else +#ifdef CONFIG_CMD_BOOTEFI_HELLO + if (!strcmp(arg, "hello")) { + 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; + + image_buf = map_sysmem(addr, size); + memcpy(image_buf, __efi_helloworld_begin, size); + + device_path = NULL; + image_path = NULL; + } else +#endif + { + saddr = arg; + size = 0; + + addr = simple_strtoul(saddr, NULL, 16); + /* Check that a numeric value was passed */ + if (!addr && *saddr != '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 %p ...\n", addr); - r = do_bootefi_exec(addr, device_path, file_path); - printf("## Application terminated, r = %lu\n", - r & ~EFI_ERROR_MASK); + printf("## Starting EFI application at %08lx ...\n", addr); + r = do_bootefi_exec(image_buf, device_path, image_path); + printf("## Application terminated, r = %lu\n", r & ~EFI_ERROR_MASK); if (r != EFI_SUCCESS) - return 1; + return CMD_RET_FAILURE; - return 0; + return CMD_RET_SUCCESS; } /* 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; unsigned long fdt_addr; + efi_status_t r; /* Allow unaligned memory access */ allow_unaligned(); @@ -421,18 +455,7 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) efi_install_configuration_table(&efi_guid_fdt, NULL); printf("WARNING: booting without device tree\n"); } -#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 #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { struct efi_loaded_image_obj *image_obj; @@ -447,30 +470,10 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) r = 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(); - } else { - saddr = argv[1]; - - addr = simple_strtoul(saddr, NULL, 16); - /* Check that a numeric value was passed */ - if (!addr && *saddr != '0') - return CMD_RET_USAGE; - } +#endif - 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_load_and_exec(argv[1]); } #ifdef CONFIG_SYS_LONGHELP @@ -489,7 +492,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"