[PATCH v3 2/2] sandbox: spi: Add SPI EEPROM emulator and DM test
Simon Glass
sjg at chromium.org
Sun Jun 14 14:18:51 CEST 2026
Hi João,
On 2026-06-10T22:11:58, João Loureiro <joaofl at gmail.com> wrote:
> sandbox: spi: Add SPI EEPROM emulator and DM test
>
> Add a sandbox emulator for an AT25-style SPI EEPROM so the new SPI
> EEPROM uclass can be exercised without real hardware.
>
> The sandbox SPI controller previously always bound the SPI flash
> emulator for every chip select. Allow a slave node to select its own
> emulator through a sandbox,emul phandle (mirroring the sandbox I2C
> bus), falling back to the SPI flash emulator when none is given so that
> existing behaviour is preserved.
>
> A test EEPROM is wired up on chip select 3 of the sandbox SPI bus and a
> test/dm test verifies size reporting, patterned reads, out-of-bounds
> rejection and the unimplemented write path.
>
> Signed-off-by: João Loureiro <joaofl at gmail.com>
>
> MAINTAINERS | 2 +
> arch/sandbox/dts/test.dts | 13 ++++-
> drivers/misc/Makefile | 1 +
> drivers/misc/spi_eeprom_emul.c | 118 +++++++++++++++++++++++++++++++++++++++++
> drivers/spi/sandbox_spi.c | 31 ++++++++++-
> test/dm/Makefile | 1 +
> test/dm/spi_eeprom.c | 45 ++++++++++++++++
> 7 files changed, 209 insertions(+), 2 deletions(-)
> diff --git a/drivers/spi/sandbox_spi.c b/drivers/spi/sandbox_spi.c
> @@ -77,6 +77,35 @@ static int sandbox_spi_set_wordlen(struct udevice *dev, unsigned int wordlen)
> +/**
> + * sandbox_spi_emul_get() - find the emulator for a SPI slave
> + *
> + * A slave can name a dedicated emulator through a 'sandbox,emul' phandle (for
> + * example an SPI EEPROM). When no such phandle is present we fall back to the
> + * built-in SPI flash emulator, preserving the previous behaviour.
> + */
> +static int sandbox_spi_emul_get(struct sandbox_state *state, struct udevice *bus,
> + struct udevice *slave, struct udevice **emulp)
Can you please add rull kerneldoc for @state, @bus, @slave, @emulp and
a Return: line. Try to wrap to 80 columns.
> diff --git a/drivers/misc/spi_eeprom_emul.c b/drivers/misc/spi_eeprom_emul.c
> @@ -0,0 +1,118 @@
> + priv->data = calloc(1, priv->size);
> + if (!priv->data)
> + return -ENOMEM;
This is never freed, so each probe/remove cycle in the tests leaks the
backing store. Please can you add a remove method that frees
priv->data, as sandbox_i2c_eeprom_remove() does in i2c_eeprom_emul.c
With those fixed:
Reviewed-by: Simon Glass <sjg at chromium.org>
Tested-by: Simon Glass <sjg at chromium.org> # sandbox
Regards,
Simon
More information about the U-Boot
mailing list