aboutsummaryrefslogtreecommitdiff
path: root/arch/sandbox
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sandbox')
-rw-r--r--arch/sandbox/cpu/spl.c84
-rw-r--r--arch/sandbox/cpu/start.c30
-rw-r--r--arch/sandbox/cpu/state.c2
-rw-r--r--arch/sandbox/dts/sandbox.dts7
-rw-r--r--arch/sandbox/dts/sandbox_vpl.dtsi84
-rw-r--r--arch/sandbox/dts/test.dts72
-rw-r--r--arch/sandbox/include/asm/spl.h4
-rw-r--r--arch/sandbox/include/asm/state.h3
8 files changed, 256 insertions, 30 deletions
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c
index 1d49a9bd10..0faf34cc00 100644
--- a/arch/sandbox/cpu/spl.c
+++ b/arch/sandbox/cpu/spl.c
@@ -49,13 +49,14 @@ void board_init_f(ulong flag)
preloader_console_init();
}
-u32 spl_boot_device(void)
+void board_boot_order(u32 *spl_boot_list)
{
- return BOOT_DEVICE_BOARD;
+ spl_boot_list[0] = BOOT_DEVICE_VBE;
+ spl_boot_list[1] = BOOT_DEVICE_BOARD;
}
-static int spl_board_load_image(struct spl_image_info *spl_image,
- struct spl_boot_device *bootdev)
+static int spl_board_load_file(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev)
{
char fname[256];
int ret;
@@ -74,10 +75,52 @@ static int spl_board_load_image(struct spl_image_info *spl_image,
if (!spl_image->arg)
return log_msg_ret("exec", -ENOMEM);
strcpy(spl_image->arg, fname);
+ spl_image->flags = SPL_SANDBOXF_ARG_IS_FNAME;
return 0;
}
-SPL_LOAD_IMAGE_METHOD("sandbox", 9, BOOT_DEVICE_BOARD, spl_board_load_image);
+SPL_LOAD_IMAGE_METHOD("sandbox_file", 9, BOOT_DEVICE_BOARD,
+ spl_board_load_file);
+
+static int load_from_image(struct spl_image_info *spl_image,
+ struct spl_boot_device *bootdev)
+{
+ struct sandbox_state *state = state_get_current();
+ enum u_boot_phase next_phase;
+ const char *fname;
+ ulong pos, size;
+ int full_size;
+ void *buf;
+ int ret;
+
+ if (!IS_ENABLED(CONFIG_SANDBOX_VPL))
+ return -ENOENT;
+
+ next_phase = spl_next_phase();
+ pos = spl_get_image_pos();
+ size = spl_get_image_size();
+ if (pos == BINMAN_SYM_MISSING || size == BINMAN_SYM_MISSING) {
+ log_debug("No image found\n");
+ return -ENOENT;
+ }
+ log_info("Reading from pos %lx size %lx\n", pos, size);
+
+ /*
+ * Set up spl_image to boot from jump_to_image_no_args(). Allocate this
+ * outside the RAM buffer (i.e. don't use strdup()).
+ */
+ fname = state->prog_fname ? state->prog_fname : state->argv[0];
+ ret = os_read_file(fname, &buf, &full_size);
+ if (ret)
+ return log_msg_ret("rd", -ENOMEM);
+ spl_image->flags = SPL_SANDBOXF_ARG_IS_BUF;
+ spl_image->arg = buf;
+ spl_image->offset = pos;
+ spl_image->size = size;
+
+ return 0;
+}
+SPL_LOAD_IMAGE_METHOD("sandbox_image", 7, BOOT_DEVICE_BOARD, load_from_image);
void spl_board_init(void)
{
@@ -89,20 +132,37 @@ void spl_board_init(void)
int ret;
ret = ut_run_list("spl", NULL, tests, count,
- state->select_unittests, 1);
+ state->select_unittests, 1, false);
/* continue execution into U-Boot */
}
}
void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
{
- const char *fname = spl_image->arg;
+ switch (spl_image->flags) {
+ case SPL_SANDBOXF_ARG_IS_FNAME: {
+ const char *fname = spl_image->arg;
+
+ if (fname) {
+ os_fd_restore();
+ os_spl_to_uboot(fname);
+ } else {
+ log_err("No filename provided for U-Boot\n");
+ }
+ break;
+ }
+ case SPL_SANDBOXF_ARG_IS_BUF: {
+ int ret;
- if (fname) {
- os_fd_restore();
- os_spl_to_uboot(fname);
- } else {
- printf("No filename provided for U-Boot\n");
+ ret = os_jump_to_image(spl_image->arg + spl_image->offset,
+ spl_image->size);
+ if (ret)
+ log_err("Failed to load image\n");
+ break;
+ }
+ default:
+ log_err("Invalid flags\n");
+ break;
}
hang();
}
diff --git a/arch/sandbox/cpu/start.c b/arch/sandbox/cpu/start.c
index 642be164a3..622df41f54 100644
--- a/arch/sandbox/cpu/start.c
+++ b/arch/sandbox/cpu/start.c
@@ -244,6 +244,36 @@ static int sandbox_cmdline_cb_jump(struct sandbox_state *state,
}
SANDBOX_CMDLINE_OPT_SHORT(jump, 'j', 1, "Jumped from previous U-Boot");
+static int sandbox_cmdline_cb_program(struct sandbox_state *state,
+ const char *arg)
+{
+ /*
+ * Record the program name to use when jumping to future phases. This
+ * is the original executable which holds all the phases. We need to
+ * use this instead of argv[0] since each phase is started by
+ * extracting a particular binary from the full program, then running
+ * it. Therefore in that binary, argv[0] contains only the
+ * current-phase executable.
+ *
+ * For example, sandbox TPL may be started using image file:
+ *
+ * ./image.bin
+ *
+ * but then TPL needs to run VPL, which it does by extracting the VPL
+ * image from the image.bin file.
+ *
+ * ./temp-vpl
+ *
+ * When VPL runs it needs access to the original image.bin so it can
+ * extract the next phase (SPL). This works if we use '-f image.bin'
+ * when starting the original image.bin file.
+ */
+ state->prog_fname = arg;
+
+ return 0;
+}
+SANDBOX_CMDLINE_OPT_SHORT(program, 'p', 1, "U-Boot program name");
+
static int sandbox_cmdline_cb_memory(struct sandbox_state *state,
const char *arg)
{
diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index fcc4a337e5..a681e472ab 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -470,7 +470,7 @@ int state_uninit(void)
int err;
if (state->write_ram_buf || state->write_state)
- log_info("Writing sandbox state\n");
+ log_debug("Writing sandbox state\n");
state = &main_state;
/* Finish the bloblist, so that it is correct before writing memory */
diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
index 21f00fcab5..1b60914a01 100644
--- a/arch/sandbox/dts/sandbox.dts
+++ b/arch/sandbox/dts/sandbox.dts
@@ -21,6 +21,9 @@
spi0 = &spi;
};
+ binman: binman {
+ };
+
memory {
reg = <0 CONFIG_SYS_SDRAM_SIZE>;
};
@@ -103,3 +106,7 @@
#include "sandbox.dtsi"
#include "cros-ec-keyboard.dtsi"
#include "sandbox_pmic.dtsi"
+
+#ifdef CONFIG_SANDBOX_VPL
+#include "sandbox_vpl.dtsi"
+#endif
diff --git a/arch/sandbox/dts/sandbox_vpl.dtsi b/arch/sandbox/dts/sandbox_vpl.dtsi
new file mode 100644
index 0000000000..1fba537f13
--- /dev/null
+++ b/arch/sandbox/dts/sandbox_vpl.dtsi
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Devicetree file for VPL (Verifying Program Loader)
+ */
+
+&binman {
+ u-boot-tpl-elf {
+ no-expanded;
+ };
+ u-boot-vpl-elf {
+ no-expanded;
+ };
+ fw-update {
+ type = "section";
+
+ /*
+ * provide plenty of space for ELF files with debug info so that
+ * gdb can be used
+ */
+ offset = <0x400000>;
+ size = <0xdffc00>;
+
+ fit {
+ fit,external-offset = <0>;
+ description = "AP firmware";
+ images {
+ spl {
+ description = "U-Boot SPL";
+ type = "firmware";
+ phase = "spl";
+ arch = "sandbox";
+ os = "u-boot";
+ compression = "none";
+
+ hash-1 {
+ algo = "sha256";
+ };
+
+ u-boot-spl-elf {
+ };
+ };
+ u-boot {
+ description = "U-Boot";
+ type = "firmware";
+ phase = "u-boot";
+ arch = "sandbox";
+ os = "u-boot";
+ compression = "none";
+
+ hash-1 {
+ algo = "sha256";
+ };
+
+ u-boot-elf {
+ };
+ };
+ };
+
+ configurations {
+ conf-1 {
+ compatible = "sandbox";
+ description = "AP Firmware v1";
+ firmware = "spl", "u-boot";
+ signature {
+ algo = "sha1,rsa2048";
+ key-name-hint = "dev";
+ sign-images = "firmware";
+ };
+ };
+ };
+ };
+ };
+ state {
+ type = "fill";
+ size = <0x200>;
+ };
+ version {
+ type = "text";
+ text = "1.2.3";
+ size = <0x200>;
+ };
+ fdtmap {
+ };
+};
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index db72c64b1e..25fd2bcab8 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -37,6 +37,8 @@
i2c0 = "/i2c@0";
mmc0 = "/mmc0";
mmc1 = "/mmc1";
+ mmc2 = "/mmc2";
+ mmc3 = "/mmc3";
pci0 = &pci0;
pci1 = &pci1;
pci2 = &pci2;
@@ -64,7 +66,7 @@
osd0 = "/osd";
};
- binman {
+ binman: binman {
};
config {
@@ -78,6 +80,7 @@
};
bootstd {
+ u-boot,dm-vpl;
compatible = "u-boot,boot-std";
filename-prefixes = "/", "/boot/";
@@ -90,6 +93,46 @@
efi {
compatible = "u-boot,distro-efi";
};
+
+ /*
+ * This is used for the VBE OS-request tests. A FAT filesystem
+ * created in a partition with the VBE information appearing
+ * before the parititon starts
+ */
+ firmware0 {
+ u-boot,dm-vpl;
+ compatible = "fwupd,vbe-simple";
+ storage = "mmc1";
+ skip-offset = <0x200>;
+ area-start = <0x400>;
+ area-size = <0x1000>;
+ state-offset = <0x400>;
+ state-size = <0x40>;
+ version-offset = <0x800>;
+ version-size = <0x100>;
+ };
+
+ /*
+ * This is used for the VBE VPL tests. The MMC device holds the
+ * binman image.bin file. The test progresses through each phase
+ * of U-Boot, loading each in turn from MMC.
+ *
+ * Note that the test enables this node (and mmc3) before
+ * running U-Boot
+ */
+ firmware1 {
+ u-boot,dm-vpl;
+ status = "disabled";
+ compatible = "fwupd,vbe-simple";
+ storage = "mmc3";
+ skip-offset = <0x400000>;
+ area-start = <0>;
+ area-size = <0xe00000>;
+ state-offset = <0xdffc00>;
+ state-size = <0x40>;
+ version-offset = <0xdffe00>;
+ version-size = <0x100>;
+ };
};
fuzzing-engine {
@@ -962,6 +1005,14 @@
compatible = "sandbox,mmc";
};
+ /* This is used for VBE VPL tests */
+ mmc3 {
+ status = "disabled";
+ compatible = "sandbox,mmc";
+ filename = "image.bin";
+ non-removable;
+ };
+
pch {
compatible = "sandbox,pch";
};
@@ -1404,21 +1455,6 @@
compatible = "denx,u-boot-fdt-test";
reg = <9 1>;
};
-
- fwupd {
- compatible = "simple-bus";
- firmware0 {
- compatible = "fwupd,vbe-simple";
- storage = "mmc1";
- area-start = <0x400>;
- area-size = <0x1000>;
- skip-offset = <0x200>;
- state-offset = <0x400>;
- state-size = <0x40>;
- version-offset = <0x800>;
- version-size = <0x100>;
- };
- };
};
translation-test@8000 {
@@ -1708,3 +1744,7 @@
#include "sandbox_pmic.dtsi"
#include "cros-ec-keyboard.dtsi"
+
+#ifdef CONFIG_SANDBOX_VPL
+#include "sandbox_vpl.dtsi"
+#endif
diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h
index bf5a585622..2f8b5fcfcf 100644
--- a/arch/sandbox/include/asm/spl.h
+++ b/arch/sandbox/include/asm/spl.h
@@ -7,7 +7,11 @@
#define __asm_spl_h
enum {
+ BOOT_DEVICE_MMC1,
+ BOOT_DEVICE_MMC2,
+ BOOT_DEVICE_MMC2_2,
BOOT_DEVICE_BOARD,
+ BOOT_DEVICE_VBE,
};
/**
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index fd42daad51..49ea483d33 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -71,7 +71,8 @@ struct sandbox_state {
const char *parse_err; /* Error to report from parsing */
int argc; /* Program arguments */
char **argv; /* Command line arguments */
- const char *jumped_fname; /* Jumped from previous U_Boot */
+ const char *jumped_fname; /* Jumped from previous U-Boot */
+ const char *prog_fname; /* U-Boot executable filename */
uint8_t *ram_buf; /* Emulated RAM buffer */
unsigned long ram_size; /* Size of RAM buffer */
const char *ram_buf_fname; /* Filename to use for RAM buffer */