X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=common%2Fcmd_sf.c;h=9c76464a9a84a72862d97e4d1235f57785cb1e7b;hb=1b7935cd96f2295d5cdf144fa46696fb60a820ef;hp=72256567d32089a154b7c58edb3fda9e61acd486;hpb=8e8a4bc22fc475244dd7c794f2271dd55399e859;p=u-boot diff --git a/common/cmd_sf.c b/common/cmd_sf.c index 72256567d3..9c76464a9a 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -17,6 +17,12 @@ #ifndef CONFIG_SF_DEFAULT_MODE # define CONFIG_SF_DEFAULT_MODE SPI_MODE_3 #endif +#ifndef CONFIG_SF_DEFAULT_CS +# define CONFIG_SF_DEFAULT_CS 0 +#endif +#ifndef CONFIG_SF_DEFAULT_BUS +# define CONFIG_SF_DEFAULT_BUS 0 +#endif static struct spi_flash *flash; @@ -63,27 +69,26 @@ static int sf_parse_len_arg(char *arg, ulong *len) static int do_spi_flash_probe(int argc, char * const argv[]) { - unsigned int bus = 0; - unsigned int cs; + unsigned int bus = CONFIG_SF_DEFAULT_BUS; + unsigned int cs = CONFIG_SF_DEFAULT_CS; unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; struct spi_flash *new; - if (argc < 2) - return -1; - - cs = simple_strtoul(argv[1], &endp, 0); - if (*argv[1] == 0 || (*endp != 0 && *endp != ':')) - return -1; - if (*endp == ':') { - if (endp[1] == 0) - return -1; - - bus = cs; - cs = simple_strtoul(endp + 1, &endp, 0); - if (*endp != 0) + if (argc >= 2) { + cs = simple_strtoul(argv[1], &endp, 0); + if (*argv[1] == 0 || (*endp != 0 && *endp != ':')) return -1; + if (*endp == ':') { + if (endp[1] == 0) + return -1; + + bus = cs; + cs = simple_strtoul(endp + 1, &endp, 0); + if (*endp != 0) + return -1; + } } if (argc >= 3) { @@ -127,12 +132,12 @@ static int do_spi_flash_probe(int argc, char * const argv[]) static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset, size_t len, const char *buf, char *cmp_buf, size_t *skipped) { - debug("offset=%#x, sector_size=%#x, len=%#x\n", + debug("offset=%#x, sector_size=%#x, len=%#zx\n", offset, flash->sector_size, len); if (spi_flash_read(flash, offset, len, cmp_buf)) return "read"; if (memcmp(cmp_buf, buf, len) == 0) { - debug("Skip region %x size %x: no change\n", + debug("Skip region %x size %zx: no change\n", offset, len); *skipped += len; return NULL; @@ -293,13 +298,13 @@ done: return ret; usage: - return cmd_usage(cmdtp); + return CMD_RET_USAGE; } U_BOOT_CMD( sf, 5, 1, do_spi_flash, "SPI flash sub-system", - "probe [bus:]cs [hz] [mode] - init flash device on given SPI bus\n" + "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" " and chip select\n" "sf read addr offset len - read `len' bytes starting at\n" " `offset' to memory at `addr'\n"