]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: spl: Add a test for the SPI load method
authorSean Anderson <seanga2@gmail.com>
Sat, 14 Oct 2023 20:48:05 +0000 (16:48 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 18 Oct 2023 00:50:52 +0000 (20:50 -0400)
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>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/sandbox/include/asm/spl.h
configs/sandbox_noinst_defconfig
include/spl.h
test/image/Kconfig
test/image/Makefile
test/image/spl_load.c
test/image/spl_load_spi.c [new file with mode: 0644]
test/py/tests/test_spl.py

index cf16af5278a3707901f8cfc8de119255c0d6a482..f349ea199712a2e4ea7899d30d52467993229e8b 100644 (file)
@@ -14,6 +14,7 @@ enum {
        BOOT_DEVICE_VBE,
        BOOT_DEVICE_CPGMAC,
        BOOT_DEVICE_NOR,
+       BOOT_DEVICE_SPI,
 };
 
 /**
index 085cc30c1e29dbdef5de5b6d0a43a4aef3353aee..db05e6308329bbc3b97ae9e7d6faa942b1995049 100644 (file)
@@ -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
index ad1543ae16bca35e3ac021591f702f886505472c..0d49e4a454cabe67929065b84d8b45398b5a501e 100644 (file)
@@ -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.
  *
index 99c5078781696b71def1cc1aa1f9d7818dd8bb3c..8f9e6ae036b06a30c71f180a9d585dd0098898c4 100644 (file)
@@ -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
index a82aa40449d3d5ca1bcb03a695772b46f537dbe7..b30210106a42c71d10a1a3ec10464cdb01ffc6a9 100644 (file)
@@ -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
index 07a986258d94dfc74d2a2e7f78e442e06a57d077..ab4c14d6491f73f374f6f675f93bb5ab6772aa6e 100644 (file)
@@ -9,6 +9,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 (file)
index 0000000..8f9b6e0
--- /dev/null
@@ -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
index bd273dad89357d8d9880522aa0d9a55249c2bb28..42e4c4342b23c4fc7c5b3b3897e70fb8f3f6058f 100644 (file)
@@ -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.