From patchwork Thu Jun 14 16:55:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 929591 X-Patchwork-Delegate: sjg@chromium.org 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=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="nwm1Oe39"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41691z2tBqz9s01 for ; Fri, 15 Jun 2018 03:03:51 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 26EBFC21E15; Thu, 14 Jun 2018 16:58:41 +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 F29E6C21E73; Thu, 14 Jun 2018 16:56:04 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 7BA1FC21DF8; Thu, 14 Jun 2018 16:55:42 +0000 (UTC) Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) by lists.denx.de (Postfix) with ESMTPS id 52604C21DE8 for ; Thu, 14 Jun 2018 16:55:37 +0000 (UTC) Received: by mail-io0-f178.google.com with SMTP id e15-v6so7857922iog.1 for ; Thu, 14 Jun 2018 09:55:37 -0700 (PDT) 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=ofkIafnf31LJJr66+z8s7wAdVxk1cFYOiRfM/quxR7Y=; b=nwm1Oe39j6NdB9Y/hhuI/+H9rDOlWKOamWm1dyrAyBKIcXnIwxD40jnzut7RZFAFZX GL+BjzPVJOFfE530p8sec62Hh5HmNztdodflk1pypx7ltaxm+sPgwgHbCiJ4lL8wRzdL J1CQLDS6Y+LzgydQAIdk6LYjYlK0ihVBB/5ddeby+uDpmxvmPhRu1vS5pBOlv6ClfNwW gFa2zl252lsemwBJY+6vjZ6ozbu/y8T2JY8Z5q8+uMOYL73hszMsRKCmfY3EvWdMhkLj n0wFprD5WKSErpspzai7ytS+A3HzCfAShG05+8rzgjLZ5+UXXWcalzUNDl4TXNkxwfwD O5xw== 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=ofkIafnf31LJJr66+z8s7wAdVxk1cFYOiRfM/quxR7Y=; b=XwWW0znQRHanWqWA71dIp5PoxA8RqnLEuNQ2UopFrE8+MGCZap8lNsMabZD8VUzt05 wx2mxSDfDUvB2sLKwpmZayR5Y5QoF1kR+2FnuzXK15rY6uNnMkpl+34HikrNEo4GdG97 Lnqfy3toYcKaMxUXgjO517xP8EWs05Y8xC8WkDpzma9U+ZTQP8QOskA9P16SqvF3OAf3 SGOPitBxDWREFBLqM7tZZLmm2kRh/L+rgf8vqSx7S42b0zbOcwrpkdilw/K7oP6VRLqY +PEuICd7ZpAzLpOwDV0I5Jap7X5IViwU1HczTyDLSY8KRyThDqP9QULRzwfAb1JShac4 xptQ== X-Gm-Message-State: APt69E3B6XwAEakMbVX4FvZbk9wgShFOxQwfB3fZnRBKqqMOLlsm4gh3 dNcHvI8qjHi7vgXch39vdoeclA== X-Google-Smtp-Source: ADUXVKKwpU0enlTXVz2gVuG39WpK8VXJRLgfF5WScS9wrGFQ/eGZZG2BF106mW0YX+hN63oQTG6KZA== X-Received: by 2002:a6b:f314:: with SMTP id m20-v6mr2994777ioh.253.1528995335641; Thu, 14 Jun 2018 09:55:35 -0700 (PDT) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id j140-v6sm2851027itj.33.2018.06.14.09.55.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 14 Jun 2018 09:55:32 -0700 (PDT) Received: by kiwi.bld.corp.google.com (Postfix, from userid 121222) id C7B3F140984; Thu, 14 Jun 2018 10:55:31 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Thu, 14 Jun 2018 10:55:23 -0600 Message-Id: <20180614165526.183597-9-sjg@chromium.org> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog In-Reply-To: <20180614165526.183597-1-sjg@chromium.org> References: <20180614165526.183597-1-sjg@chromium.org> Cc: Andy Shevchenko , Heinrich Schuchardt , Alexander Graf Subject: [U-Boot] [PATCH v7 08/10] 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. This test can be executed without causing problems to the run-time environemnt (e.g. U-Boot does not need to reboot afterwards). 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 WARNING: booting without device tree Hello, world! Test passed Signed-off-by: Simon Glass --- Changes in v7: None Changes in v6: None Changes in v5: None Changes in v4: - Rebase to master - Update SPDX tags Changes in v3: - Rebase to master Changes in v2: - Rebase to master cmd/bootefi.c | 26 ++++++++++++++++++++------ include/efi_loader.h | 3 +++ lib/efi_loader/Kconfig | 10 ++++++++++ lib/efi_loader/Makefile | 1 + lib/efi_loader/efi_test.c | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 lib/efi_loader/efi_test.c diff --git a/cmd/bootefi.c b/cmd/bootefi.c index a9ebde0c75..ac80074bc4 100644 --- a/cmd/bootefi.c +++ b/cmd/bootefi.c @@ -347,7 +347,6 @@ exit: return ret; } -#ifdef CONFIG_CMD_BOOTEFI_SELFTEST /** * bootefi_test_prepare() - prepare to run an EFI test * @@ -399,7 +398,6 @@ static void bootefi_test_finish(struct efi_loaded_image *image, free(image->load_options); list_del(&obj->link); } -#endif /* CONFIG_CMD_BOOTEFI_SELFTEST */ static int do_bootefi_bootmgr_exec(void) { @@ -431,8 +429,10 @@ static int do_bootefi_bootmgr_exec(void) /* 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; + struct efi_loaded_image image; + struct efi_object obj; char *saddr; + unsigned long addr; efi_status_t r; void *fdt_addr; @@ -477,11 +477,25 @@ 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; + + if (bootefi_test_prepare(&image, &obj, "\\test", + (ulong)&efi_test)) + return CMD_RET_FAILURE; + + ret = efi_test(&image, &systab); + bootefi_test_finish(&image, &obj); + 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 image; - struct efi_object obj; - if (bootefi_test_prepare(&image, &obj, "\\selftest", (uintptr_t)&efi_selftest)) return CMD_RET_FAILURE; diff --git a/include/efi_loader.h b/include/efi_loader.h index c66252a7dd..0615cfac85 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -442,6 +442,9 @@ efi_status_t EFIAPI efi_set_variable(u16 *variable_name, efi_guid_t *vendor, 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 d471e6f4a4..110dcb23c9 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -25,3 +25,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 c6046e36d2..2da28f9c90 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..4b8d49f324 --- /dev/null +++ b/lib/efi_loader/efi_test.c @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2017, Google Inc. + */ + +#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; +}