From 20f655da11cdddfeb0814197f9b3c71d4d297061 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:54 -0700 Subject: sandbox: spi: Add more debugging to SPI emulation Add a little more debugging to help when things go wrong. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- drivers/mtd/spi/sandbox.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index 895604d736..ec07be71a1 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -142,13 +142,15 @@ static int sandbox_sf_probe(struct udevice *dev) if (bus->seq < CONFIG_SANDBOX_SPI_MAX_BUS) spec = state->spi[bus->seq][cs].spec; if (!spec) { + debug("%s: No spec found for bus %d, cs %d\n", + __func__, bus->seq, cs); ret = -ENOENT; goto error; } file = strchr(spec, ':'); if (!file) { - printf("sandbox_sf: unable to parse file\n"); + printf("%s: unable to parse file\n", __func__); ret = -EINVAL; goto error; } @@ -174,7 +176,7 @@ static int sandbox_sf_probe(struct udevice *dev) break; } if (!data->name) { - printf("sandbox_sf: unknown flash '%*s'\n", (int)idname_len, + printf("%s: unknown flash '%*s'\n", __func__, (int)idname_len, spec); ret = -EINVAL; goto error; @@ -186,7 +188,7 @@ static int sandbox_sf_probe(struct udevice *dev) sbsf->fd = os_open(pdata->filename, 02); if (sbsf->fd == -1) { free(sbsf); - printf("sandbox_sf: unable to open file '%s'\n", + printf("%s: unable to open file '%s'\n", __func__, pdata->filename); ret = -EIO; goto error; @@ -553,6 +555,9 @@ static int sandbox_cmdline_cb_spi_sf(struct sandbox_state *state, * yet. Perhaps we can figure something out. */ state->spi[bus][cs].spec = spec; + debug("%s: Setting up spec '%s' for bus %ld, cs %ld\n", __func__, + spec, bus, cs); + return 0; } SANDBOX_CMDLINE_OPT(spi_sf, 1, "connect a SPI flash: :::"); @@ -671,6 +676,8 @@ int dm_scan_other(bool pre_reloc_only) __func__, busnum, cs); return ret; } + debug("%s: Setting up spec '%s' for bus %d, cs %d\n", + __func__, spec, busnum, cs); } } } -- cgit From ffe276d27a538ca410d697126c562a1ce0ac8bbc Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:55 -0700 Subject: sandbox: spi: Remove an incorrect free() We must not free data that is managed by driver mode. Remove this line, which is a hangover from the pre-driver-model code. This fixes a problem where 'sf probe' crashes U-Boot if the backing file for the SPI flash cannot be found. Signed-off-by: Simon Glass Reviewed-by: Jagan Teki Tested-by: Jagan Teki Reviewed-by: Tom Rini --- drivers/mtd/spi/sandbox.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sandbox.c b/drivers/mtd/spi/sandbox.c index ec07be71a1..53470b90ce 100644 --- a/drivers/mtd/spi/sandbox.c +++ b/drivers/mtd/spi/sandbox.c @@ -187,7 +187,6 @@ static int sandbox_sf_probe(struct udevice *dev) sbsf->fd = os_open(pdata->filename, 02); if (sbsf->fd == -1) { - free(sbsf); printf("%s: unable to open file '%s'\n", __func__, pdata->filename); ret = -EIO; -- cgit From 0badb23d110c886cf25550325f36ce1eba1eb5e2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 24 Feb 2016 09:14:56 -0700 Subject: spi: Correct two error return values When an error number is provided we should use it, not change it. This fixes the SPI and SPI flash tests. One of these is long-standing. The other seems to have been introduced by commit 1e90d9fd (sf: Move read_id code to sf_ops). Signed-off-by: Simon Glass Fixes: 1e90d9fd (sf: Move read_id code to sf_ops) Reviewed-by: Jagan Teki Tested-by: Jagan Teki --- drivers/mtd/spi/sf_probe.c | 4 +--- drivers/mtd/spi/spi_flash.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index daa1d5b249..7b296378d2 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -42,10 +42,8 @@ static int spi_flash_probe_slave(struct spi_flash *flash) } ret = spi_flash_scan(flash); - if (ret) { - ret = -EINVAL; + if (ret) goto err_read_id; - } #ifdef CONFIG_SPI_FLASH_MTD ret = spi_flash_mtd_register(flash); diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 3c365d5e9a..2ae2e3c8c9 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -989,7 +989,7 @@ int spi_flash_scan(struct spi_flash *flash) ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode)); if (ret) { printf("SF: Failed to get idcodes\n"); - return -EINVAL; + return ret; } #ifdef DEBUG -- cgit