From patchwork Mon Dec 4 21:28:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 844473 X-Patchwork-Delegate: agraf@suse.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; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="OMaGoLE7"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3yrJ8w1Rlsz9s7g for ; Tue, 5 Dec 2017 08:36:16 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id CAC8AC21DB2; Mon, 4 Dec 2017 21:31: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_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 A18E6C220AC; Mon, 4 Dec 2017 21:29:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9325DC220A6; Mon, 4 Dec 2017 21:29:03 +0000 (UTC) Received: from mail-it0-f66.google.com (mail-it0-f66.google.com [209.85.214.66]) by lists.denx.de (Postfix) with ESMTPS id 212C5C21F4F for ; Mon, 4 Dec 2017 21:28:59 +0000 (UTC) Received: by mail-it0-f66.google.com with SMTP id r6so10218113itr.3 for ; Mon, 04 Dec 2017 13:28:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=EhJMuJQ2oot271hKzWKLLuDnf/wv7fBoa9l9NH3F0tU=; b=OMaGoLE7wujK5Pg87NVLJRb46SUZT5ASwFPc5hMTKDIxrLdIKSWya3TZ1aQx4l4Ug5 YZPos2kvxtlTY9ibc4equiBbSkAuGVMZIMb4j2uaxHop5+0Dh4mHNEUG8ju5uPGv0WEI Lx+WhCD0bJsj4qX6g6f7Hupp6s//36lCTeZ8TcheYio5qi85FwwSRvPN5ZuyNvKl+jW5 Dc7XPq60LM01t0FQ9TEGzPZVxylD7q7Y+yTxJM7gpndJo9TkrWBHNgp9nFLrR8LWFw4c 0K6EkHsAjfF+utcNVPCJ5+bgzkgB8QoRWMzKHA8ILwqgC9+axdxbjB/RcIRPC9ca4ukB zEbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=EhJMuJQ2oot271hKzWKLLuDnf/wv7fBoa9l9NH3F0tU=; b=V0eHm6YgL9kQWFIJ81trYacc6UZIvohyFb0roLWIUc64jQrU3kN/HCxPvZQenEYKEz Sgn1fXaIH400IpRfw3iYtP3XiXmIAtufV7bBCuSEj48GOO4wo4HT79ZZlwKDuQWQ/0Gc czStx7YPIdt11gDhkXzQtVhd0/bVKLoZL7r9imd5sSEbwhGK27pmukydpgZmkY0eARN4 slzNeMp8OxxxJGsqs8O/qh4K6qO64eGV6xKo3K37nUOhEQ0coEcPzp9vyBBqil80tOVL ewtHE3sE0Viw1pJAK7uLs5MIflz1+uFlwuZbrkcpmlopJvVItOWVCkGsy0qsDxSbazho qPKg== X-Gm-Message-State: AJaThX6S3Taq14S5Fm7lbzNa3mP/55QzjJmRLWVmuxY8uxvawsPFBxhc pV/U2eEM24AoRUrCv64EI6IV4g== X-Google-Smtp-Source: AGs4zMZ6893u8qv84mlbfharv98ZSAwzDyQdT9OS84+EO+nhTxyXTYEN7SnW5Ff8a63dfeZZ4icpBA== X-Received: by 10.107.55.138 with SMTP id e132mr27270226ioa.82.1512422937537; Mon, 04 Dec 2017 13:28:57 -0800 (PST) Received: from kiwi.bld.corp.google.com ([100.67.80.24]) by smtp.gmail.com with ESMTPSA id x16sm5315927ioi.62.2017.12.04.13.28.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 Dec 2017 13:28:54 -0800 (PST) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C17D2143C42; Mon, 4 Dec 2017 14:28:53 -0700 (MST) From: Simon Glass To: U-Boot Mailing List Date: Mon, 4 Dec 2017 14:28:32 -0700 Message-Id: <20171204212832.130100-17-sjg@chromium.org> X-Mailer: git-send-email 2.15.0.531.g2ccb3012c9-goog In-Reply-To: <20171204212832.130100-1-sjg@chromium.org> References: <20171204212832.130100-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v2 16/16] efi: sandbox: Add a simple 'bootefi test' 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: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" This jumps to test code which can call directly into the EFI support. It does not need a separate image so it is easy to write tests with it. For now the test just outputs a message. To try it: ./sandbox/u-boot -c "bootefi test" U-Boot 2017.09-00204-g696c9855fe (Sep 17 2017 - 16:43:53 -0600) DRAM: 128 MiB MMC: Using default environment In: serial Out: serial Err: serial SCSI: Net: No ethernet found. IDE: Bus 0: not available Found 0 disks Hello, world! Test passed Signed-off-by: Simon Glass --- Changes in v2: - Rebase to master cmd/bootefi.c | 25 +++++++++++++++++++++++-- configs/sandbox_defconfig | 1 + include/efi_loader.h | 3 +++ lib/efi_loader/Kconfig | 10 ++++++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_test.c | 17 +++++++++++++++++ 6 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 lib/efi_loader/efi_test.c diff --git a/cmd/bootefi.c b/cmd/bootefi.c index a4686f17f0..a77d8b256e 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -148,13 +148,11 @@ static unsigned long do_bootefi_exec(void *efi, void *fdt, struct efi_object loaded_image_info_obj = {}; struct efi_device_path *memdp = NULL; ulong ret; - ulong (*entry)(void *image_handle, struct efi_system_table *st) asmlinkage; ulong fdt_pages, fdt_size, fdt_start, fdt_end; const efi_guid_t fdt_guid = EFI_FDT_GUID; bootm_headers_t img = { 0 }; - int ret; /* * Special case for efi payload not loaded from disk, such as @@ -318,6 +316,29 @@ static int do_bootefi(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) memcpy((char *)addr, __efi_helloworld_begin, size); } else #endif + if (IS_ENABLED(CONFIG_BOOTEFI_TEST) && !strcmp(argv[1], "test")) { + int ret; + + /* Initialize and populate EFI object list */ + if (efi_init_obj_list()) + return CMD_RET_FAILURE; + + struct efi_loaded_image loaded_image_info = {}; + struct efi_object loaded_image_info_obj = {}; + + efi_setup_loaded_image(&loaded_image_info, + &loaded_image_info_obj, + bootefi_device_path, bootefi_image_path); + + ret = efi_test(&loaded_image_info, &systab); + if (ret) { + printf("Test failed: err=%d\n", ret); + return CMD_RET_FAILURE; + } + printf("Test passed\n"); + + return 0; + } #ifdef CONFIG_CMD_BOOTEFI_SELFTEST if (!strcmp(argv[1], "selftest")) { struct efi_loaded_image loaded_image_info = {}; diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 08eec8ecc6..ccf142c51d 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -194,3 +194,4 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_UT_ENV=y CONFIG_UT_OVERLAY=y +CONFIG_CMD_BOOTEFI_SELFTEST=y diff --git a/include/efi_loader.h b/include/efi_loader.h index 35f8f84401..90018fbe9e 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -335,6 +335,9 @@ efi_status_t EFIAPI efi_set_variable(s16 *variable_name, void *efi_bootmgr_load(struct efi_device_path **device_path, struct efi_device_path **file_path); +/* Perform EFI tests */ +int efi_test(efi_handle_t image_handle, struct efi_system_table *systab); + #else /* defined(EFI_LOADER) && !defined(CONFIG_SPL_BUILD) */ /* Without CONFIG_EFI_LOADER we don't have a runtime section, stub it out */ diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index dee0a96a98..659b2b18f4 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -16,3 +16,13 @@ config EFI_LOADER_BOUNCE_BUFFER Some hardware does not support DMA to full 64bit addresses. For this hardware we can create a bounce buffer so that payloads don't have to worry about platform details. + +config BOOTEFI_TEST + bool "Provide a test for the EFI loader" + depends on EFI_LOADER && SANDBOX + default y + help + Provides a test of the EFI loader functionality accessed via the + command line ('bootefi test'). This runs within U-Boot so does not + need a separate EFI application to work. It aims to include coverage + of all EFI code which can be accessed within sandbox. diff --git a/lib/efi_loader/Makefile b/lib/efi_loader/Makefile index ddb978f650..14ef85cc67 100644 --- a/lib/efi_loader/Makefile +++ b/lib/efi_loader/Makefile @@ -23,3 +23,4 @@ obj-$(CONFIG_DM_VIDEO) += efi_gop.o obj-$(CONFIG_PARTITIONS) += efi_disk.o obj-$(CONFIG_NET) += efi_net.o obj-$(CONFIG_GENERATE_SMBIOS_TABLE) += efi_smbios.o +obj-$(CONFIG_BOOTEFI_TEST) += efi_test.o diff --git a/lib/efi_loader/efi_test.c b/lib/efi_loader/efi_test.c new file mode 100644 index 0000000000..3fdce78b05 --- /dev/null +++ b/lib/efi_loader/efi_test.c @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017, Google Inc. All rights reserved. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +int efi_test(efi_handle_t image_handle, struct efi_system_table *systable) +{ + struct efi_simple_text_output_protocol *con_out = systable->con_out; + + con_out->output_string(con_out, L"Hello, world!\n"); + + return 0; +}