public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Harald Seiler <hws@denx.de>, Simon Glass <sjg@chromium.org>,
	Sean Anderson <seanga2@gmail.com>,
	Jagan Teki <jagan@amarulasolutions.com>,
	Vignesh R <vigneshr@ti.com>
Subject: [PATCH 26/26] test: spl: Add a test for the SPI load method
Date: Wed, 11 Oct 2023 21:56:26 -0400	[thread overview]
Message-ID: <20231012015626.3487451-27-seanga2@gmail.com> (raw)
In-Reply-To: <20231012015626.3487451-1-seanga2@gmail.com>

Add test for the SPI load method. This one is pretty straightforward. We
can't enable FIT_EXTERNAL with LOAD_FIT_FULL because spl_spi_load_image
doesn't know the total image size and has to guess from fdt_totalsize. This
doesn't include external data, so loading it will fail.

Signed-off-by: Sean Anderson <seanga2@gmail.com>
---

 arch/sandbox/include/asm/spl.h   |  1 +
 configs/sandbox_noinst_defconfig |  6 +++++
 include/spl.h                    | 10 ++++++++
 test/image/Kconfig               |  8 +++++++
 test/image/Makefile              |  1 +
 test/image/spl_load.c            |  1 +
 test/image/spl_load_spi.c        | 41 ++++++++++++++++++++++++++++++++
 test/py/tests/test_spl.py        | 10 ++++++++
 8 files changed, 78 insertions(+)
 create mode 100644 test/image/spl_load_spi.c

diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h
index cf16af5278a..f349ea19971 100644
--- a/arch/sandbox/include/asm/spl.h
+++ b/arch/sandbox/include/asm/spl.h
@@ -14,6 +14,7 @@ enum {
 	BOOT_DEVICE_VBE,
 	BOOT_DEVICE_CPGMAC,
 	BOOT_DEVICE_NOR,
+	BOOT_DEVICE_SPI,
 };
 
 /**
diff --git a/configs/sandbox_noinst_defconfig b/configs/sandbox_noinst_defconfig
index 085cc30c1e2..db05e630832 100644
--- a/configs/sandbox_noinst_defconfig
+++ b/configs/sandbox_noinst_defconfig
@@ -4,6 +4,7 @@ CONFIG_SPL_LIBCOMMON_SUPPORT=y
 CONFIG_SPL_LIBGENERIC_SUPPORT=y
 CONFIG_NR_DRAM_BANKS=1
 CONFIG_ENV_SIZE=0x2000
+CONFIG_SPL_DM_SPI=y
 CONFIG_DEFAULT_DEVICE_TREE="sandbox"
 CONFIG_DM_RESET=y
 CONFIG_SPL_MMC=y
@@ -12,6 +13,8 @@ CONFIG_SPL_DRIVERS_MISC=y
 CONFIG_SPL_SYS_MALLOC_F_LEN=0x8000
 CONFIG_SPL=y
 CONFIG_SPL_FS_FAT=y
+CONFIG_SPL_SPI_FLASH_SUPPORT=y
+CONFIG_SPL_SPI=y
 CONFIG_SYS_LOAD_ADDR=0x1000000
 CONFIG_PCI=y
 CONFIG_SANDBOX_SPL=y
@@ -48,9 +51,12 @@ CONFIG_SPL_ETH=y
 CONFIG_SPL_FS_EXT4=y
 CONFIG_SPL_I2C=y
 CONFIG_SPL_MMC_WRITE=y
+CONFIG_SPL_DM_SPI_FLASH=y
 CONFIG_SPL_NET=y
 CONFIG_SPL_NOR_SUPPORT=y
 CONFIG_SPL_RTC=y
+# CONFIG_SPL_SPI_FLASH_TINY is not set
+CONFIG_SPL_SPI_LOAD=y
 CONFIG_CMD_CPU=y
 CONFIG_CMD_LICENSE=y
 CONFIG_CMD_BOOTZ=y
diff --git a/include/spl.h b/include/spl.h
index 8229d40adab..cc343ada1ec 100644
--- a/include/spl.h
+++ b/include/spl.h
@@ -416,6 +416,16 @@ int spl_load_imx_container(struct spl_image_info *spl_image,
 void preloader_console_init(void);
 u32 spl_boot_device(void);
 
+struct spi_flash;
+
+/**
+ * spl_spi_get_uboot_offs() - Lookup function for the SPI boot offset
+ * @flash: The spi flash to boot from
+ *
+ * Return: The offset of U-Boot within the SPI flash
+ */
+unsigned int spl_spi_get_uboot_offs(struct spi_flash *flash);
+
 /**
  * spl_spi_boot_bus() - Lookup function for the SPI boot bus source.
  *
diff --git a/test/image/Kconfig b/test/image/Kconfig
index 99c50787816..8f9e6ae036b 100644
--- a/test/image/Kconfig
+++ b/test/image/Kconfig
@@ -32,6 +32,14 @@ config SPL_UT_LOAD_NET
 	help
 	  Test loading images over TFTP using the NET image load method.
 
+config SPL_UT_LOAD_SPI
+	bool "Test loading from SPI Flash"
+	depends on SANDBOX && SPL_OF_REAL
+	depends on SPL_SPI_LOAD
+	default y
+	help
+	  Test the SPI flash image load metod.
+
 config SPL_UT_LOAD_OS
 	bool "Test loading from the host OS"
 	depends on SANDBOX && SPL_LOAD_FIT
diff --git a/test/image/Makefile b/test/image/Makefile
index 41b29995993..4cb4f96cedc 100644
--- a/test/image/Makefile
+++ b/test/image/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_SPL_UT_LOAD_FS) += spl_load_fs.o
 obj-$(CONFIG_SPL_UT_LOAD_NET) += spl_load_net.o
 obj-$(CONFIG_SPL_NOR_SUPPORT) += spl_load_nor.o
 obj-$(CONFIG_SPL_UT_LOAD_OS) += spl_load_os.o
+obj-$(CONFIG_SPL_UT_LOAD_SPI) += spl_load_spi.o
diff --git a/test/image/spl_load.c b/test/image/spl_load.c
index 3f69e652630..7df411edafd 100644
--- a/test/image/spl_load.c
+++ b/test/image/spl_load.c
@@ -10,6 +10,7 @@
 #include <mapmem.h>
 #include <memalign.h>
 #include <rand.h>
+#include <spi_flash.h>
 #include <spl.h>
 #include <test/spl.h>
 #include <test/ut.h>
diff --git a/test/image/spl_load_spi.c b/test/image/spl_load_spi.c
new file mode 100644
index 00000000000..8f9b6e0139b
--- /dev/null
+++ b/test/image/spl_load_spi.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Sean Anderson <seanga2@gmail.com>
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <spi_flash.h>
+#include <spl.h>
+#include <test/spl.h>
+#include <test/ut.h>
+
+static int spl_test_spi_write_image(struct unit_test_state *uts, void *img,
+				    size_t img_size)
+{
+	struct spi_flash *flash;
+
+	flash = spi_flash_probe(spl_spi_boot_bus(), spl_spi_boot_cs(),
+				CONFIG_SF_DEFAULT_SPEED,
+				CONFIG_SF_DEFAULT_MODE);
+	ut_assertnonnull(flash);
+	ut_assertok(spi_flash_write(flash, spl_spi_get_uboot_offs(flash),
+				    img_size, img));
+
+	return 0;
+}
+
+static int spl_test_spi(struct unit_test_state *uts, const char *test_name,
+			enum spl_test_image type)
+{
+	return do_spl_test_load(uts, test_name, type,
+				SPL_LOAD_IMAGE_GET(1, BOOT_DEVICE_SPI,
+						   spl_spi_load_image),
+				spl_test_spi_write_image);
+}
+SPL_IMG_TEST(spl_test_spi, LEGACY, DM_FLAGS);
+SPL_IMG_TEST(spl_test_spi, IMX8, DM_FLAGS);
+SPL_IMG_TEST(spl_test_spi, FIT_INTERNAL, DM_FLAGS);
+#if !IS_ENABLED(CONFIG_SPL_LOAD_FIT_FULL)
+SPL_IMG_TEST(spl_test_spi, FIT_EXTERNAL, DM_FLAGS);
+#endif
diff --git a/test/py/tests/test_spl.py b/test/py/tests/test_spl.py
index bd273dad893..42e4c4342b2 100644
--- a/test/py/tests/test_spl.py
+++ b/test/py/tests/test_spl.py
@@ -5,6 +5,16 @@
 import os.path
 import pytest
 
+@pytest.mark.buildconfigspec('spl_unit_test')
+def test_ut_spl_init(u_boot_console):
+    """Initialize data for ut spl tests."""
+
+    fn = u_boot_console.config.source_dir + '/spi.bin'
+    if not os.path.exists(fn):
+        data = b'\x00' * (2 * 1024 * 1024)
+        with open(fn, 'wb') as fh:
+            fh.write(data)
+
 def test_spl(u_boot_console, ut_spl_subtest):
     """Execute a "ut" subtest.
 
-- 
2.37.1


  parent reply	other threads:[~2023-10-12  2:34 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-12  1:56 [PATCH 00/26] test: spl: Test some load methods Sean Anderson
2023-10-12  1:56 ` [PATCH 01/26] spl: legacy: Fix referencing _image_binary_end Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:30     ` Sean Anderson
2023-10-12 15:28       ` Simon Glass
2023-10-12  1:56 ` [PATCH 02/26] spl: nor: Don't allocate header on stack Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  7:26     ` Michael Nazzareno Trimarchi
2023-10-12  1:56 ` [PATCH 03/26] spl: fit: Fix entry point for SPL_LOAD_FIT_FULL Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:28     ` Sean Anderson
2023-10-12 15:20       ` Tom Rini
2023-10-12 15:28       ` Simon Glass
2023-10-12  1:56 ` [PATCH 04/26] arm: imx: Fix i.MX8 container load address Sean Anderson
2023-10-12  1:56 ` [PATCH 05/26] arm: imx: Add newlines after error messages Sean Anderson
2023-10-12  7:33   ` Heinrich Schuchardt
2023-10-12  1:56 ` [PATCH 06/26] arm: imx: Add function to validate i.MX8 containers Sean Anderson
2023-10-12  1:56 ` [PATCH 07/26] arm: imx: Check header before calling spl_load_imx_container Sean Anderson
2023-10-12  7:44   ` Heinrich Schuchardt
2023-10-13  0:48     ` Sean Anderson
2023-10-12 16:40   ` Tom Rini
2023-10-13  1:39     ` Sean Anderson
2023-10-13 12:55       ` Tom Rini
2023-10-12  1:56 ` [PATCH 08/26] Move i.MX8 container image loading support to common/spl Sean Anderson
2023-10-12  1:56 ` [PATCH 09/26] spl: Allow enabling SPL_OF_REAL and SPL_OF_PLATDATA at the same time Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:22     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 10/26] lib: acpi: Fix linking SPL when ACPIGEN is enabled Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 11/26] fs: ext4: Fix building ext4 in SPL if write " Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 12/26] fs: Compile in sandbox filesystem in SPL if it " Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  6:39   ` Heinrich Schuchardt
2023-10-12 14:15     ` Sean Anderson
2023-10-12 14:50       ` Tom Rini
2023-10-12 14:52       ` Tom Rini
2023-10-12  1:56 ` [PATCH 13/26] net: Fix compiling SPL when fastboot " Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  6:52   ` Heinrich Schuchardt
2023-10-12 14:16     ` Sean Anderson
2023-10-12 14:52   ` Tom Rini
2023-10-12  1:56 ` [PATCH 14/26] net: bootp: Move port numbers to header Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  6:53   ` Heinrich Schuchardt
2023-10-12  1:56 ` [PATCH 15/26] net: bootp: Fall back to BOOTP from DHCP when unit testing Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  7:16   ` Heinrich Schuchardt
2023-10-12 14:18     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 16/26] spl: Don't cache devices when UNIT_TEST is enabled Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:18     ` Sean Anderson
2023-10-12  7:23   ` Heinrich Schuchardt
2023-10-12 14:19     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 17/26] spl: Use map_sysmem where appropriate Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 18/26] test: spl: Split tests up and use some configs Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 19/26] test: spl: Fix spl_test_load not failing if fname doesn't exist Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 20/26] test: spl: Add functions to create images Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-13 19:44   ` [SPAM] " Xavier Drudis Ferran
2023-10-14 14:37     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 21/26] test: spl: Add functions to create filesystems Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:11     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 22/26] test: spl: Add a test for spl_blk_load_image Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  1:56 ` [PATCH 23/26] test: spl: Add a test for the MMC load method Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:12     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 24/26] test: spl: Add a test for the NET " Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:11     ` Sean Anderson
2023-10-12  1:56 ` [PATCH 25/26] test: spl: Add a test for the NOR " Sean Anderson
2023-10-12  3:41   ` Simon Glass
2023-10-12  4:16     ` Sean Anderson
2023-10-12 15:28       ` Simon Glass
2023-10-12  1:56 ` Sean Anderson [this message]
2023-10-12  3:41   ` [PATCH 26/26] test: spl: Add a test for the SPI " Simon Glass
2023-10-12  1:59 ` [PATCH 00/26] test: spl: Test some load methods Sean Anderson
2023-10-12  3:41 ` Simon Glass

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=20231012015626.3487451-27-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=hws@denx.de \
    --cc=jagan@amarulasolutions.com \
    --cc=sjg@chromium.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    --cc=xypron.glpk@gmx.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox