All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 14/16] efi: sandbox: Add a simple 'bootefi test' command
Date: Wed, 16 May 2018 09:42:31 -0600	[thread overview]
Message-ID: <20180516154233.21457-15-sjg@chromium.org> (raw)
In-Reply-To: <20180516154233.21457-1-sjg@chromium.org>

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
Hello, world!
Test passed

Signed-off-by: Simon Glass <sjg@chromium.org>
---

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 9bcdf8bdc48..46bd80d2077 100644
--- a/cmd/bootefi.c
+++ b/cmd/bootefi.c
@@ -335,7 +335,6 @@ exit:
 	return ret;
 }
 
-#ifdef CONFIG_CMD_BOOTEFI_SELFTEST
 /**
  * bootefi_test_prepare() - prepare to run an EFI test
  *
@@ -391,7 +390,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)
 {
@@ -423,8 +421,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;
 
@@ -466,11 +466,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, "\\test",
 					 (uintptr_t)&efi_selftest))
 			return CMD_RET_FAILURE;
diff --git a/include/efi_loader.h b/include/efi_loader.h
index 2519a7c33a7..a19f1eaef24 100644
--- a/include/efi_loader.h
+++ b/include/efi_loader.h
@@ -435,6 +435,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 96107a90a90..59bdd389f4f 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -24,3 +24,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 c6046e36d26..2da28f9c90c 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 00000000000..4b8d49f324b
--- /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 <common.h>
+#include <efi_api.h>
+
+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;
+}
-- 
2.17.0.441.gb46fe60e1d-goog

  parent reply	other threads:[~2018-05-16 15:42 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-16 15:42 [U-Boot] [PATCH v4 00/16] efi: Enable basic sandbox support for EFI loader Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 01/16] efi: Init the 'rows' and 'cols' variables Simon Glass
2018-05-16 16:21   ` Heinrich Schuchardt
2018-05-16 15:42 ` [U-Boot] [PATCH v4 02/16] efi: Update some comments related to smbios tables Simon Glass
2018-05-16 16:30   ` Heinrich Schuchardt
2018-05-24 12:44   ` [U-Boot] [U-Boot, v4, " Alexander Graf
2018-05-16 15:42 ` [U-Boot] [PATCH v4 03/16] efi: sandbox: Adjust memory usage for sandbox Simon Glass
2018-05-16 17:02   ` Heinrich Schuchardt
2018-05-16 17:15   ` Heinrich Schuchardt
2018-05-24 19:16     ` Heinrich Schuchardt
2018-05-25  2:42       ` Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 04/16] sandbox: smbios: Update to support sandbox Simon Glass
2018-05-24 12:24   ` Alexander Graf
2018-05-25  2:42     ` Simon Glass
2018-06-03 12:13       ` Alexander Graf
2018-06-07 20:25         ` Simon Glass
2018-06-07 20:36           ` Alexander Graf
2018-06-07 20:41             ` Simon Glass
2018-06-07 20:47               ` Alexander Graf
2018-06-08 21:59                 ` Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 05/16] sandbox: Add a setjmp() implementation Simon Glass
2018-05-24 12:44   ` [U-Boot] [U-Boot, v4, " Alexander Graf
2018-06-15 12:01   ` [U-Boot] [PATCH v4 " Alexander Graf
2018-06-15 15:16     ` Simon Glass
2018-06-15 19:59       ` Alexander Graf
2018-05-16 15:42 ` [U-Boot] [PATCH v4 06/16] efi: sandbox: Add required linker sections Simon Glass
2018-05-24 12:43   ` [U-Boot] [U-Boot, v4, " Alexander Graf
2018-05-16 15:42 ` [U-Boot] [PATCH v4 07/16] efi: sandbox: Add distroboot support Simon Glass
2018-05-24 12:32   ` Alexander Graf
2018-06-12  5:27     ` Simon Glass
2018-06-12  5:42       ` Alexander Graf
2018-06-12  6:05         ` Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 08/16] Define board_quiesce_devices() in a shared location Simon Glass
2018-05-24 12:43   ` [U-Boot] [U-Boot, v4, " Alexander Graf
2018-05-16 15:42 ` [U-Boot] [PATCH v4 09/16] Add a comment for board_quiesce_devices() Simon Glass
2018-05-24 12:43   ` [U-Boot] [U-Boot, v4, " Alexander Graf
2018-05-16 15:42 ` [U-Boot] [PATCH v4 10/16] efi: sandbox: Add relocation constants Simon Glass
2018-05-24 12:34   ` Alexander Graf
2018-06-12  5:27     ` Simon Glass
2018-06-12  5:44       ` Alexander Graf
2018-06-12  6:05         ` Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 11/16] efi: Add a comment about duplicated ELF constants Simon Glass
2018-05-16 16:47   ` Heinrich Schuchardt
2018-05-16 15:42 ` [U-Boot] [PATCH v4 12/16] efi: sandbox: Enable EFI loader builder for sandbox Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 13/16] efi: Split out test init/uninit into functions Simon Glass
2018-05-16 15:42 ` Simon Glass [this message]
2018-05-16 15:42 ` [U-Boot] [PATCH v4 15/16] efi: Create a function to set up for running EFI code Simon Glass
2018-05-16 15:42 ` [U-Boot] [PATCH v4 16/16] efi: Rename bootefi_test_finish() to bootefi_run_finish() Simon Glass
2018-05-16 17:13 ` [U-Boot] [PATCH v4 00/16] efi: Enable basic sandbox support for EFI loader Heinrich Schuchardt
2018-05-17  5:31   ` Heinrich Schuchardt
2018-06-12  5:27     ` Simon Glass
2018-05-24 12:40 ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180516154233.21457-15-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.