X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cmd%2Fsf.c;h=cd50b38081c2e5959dad9fae5d7caeaf73ff3830;hb=fc97ff2695d6d7fbea7d5fda7b080f405d6ee744;hp=eac27ed2d77d2bd2e702c73cab82c0f040751d0d;hpb=51aef405550e603ff702c034f0e2cd0f15bdf2bb;p=platform%2Fkernel%2Fu-boot.git diff --git a/cmd/sf.c b/cmd/sf.c index eac27ed..cd50b38 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -72,7 +72,7 @@ static int sf_parse_len_arg(char *arg, ulong *len) * * @param len amount of bytes currently processed * @param start_ms start time of processing in ms - * @return bytes per second if OK, 0 on error + * Return: bytes per second if OK, 0 on error */ static ulong bytes_per_second(unsigned int len, ulong start_ms) { @@ -91,6 +91,7 @@ static int do_spi_flash_probe(int argc, char *const argv[]) unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; + bool use_dt = true; #if CONFIG_IS_ENABLED(DM_SPI_FLASH) struct udevice *new, *bus_dev; int ret; @@ -117,11 +118,13 @@ static int do_spi_flash_probe(int argc, char *const argv[]) speed = simple_strtoul(argv[2], &endp, 0); if (*argv[2] == 0 || *endp != 0) return -1; + use_dt = false; } if (argc >= 4) { mode = hextoul(argv[3], &endp); if (*argv[3] == 0 || *endp != 0) return -1; + use_dt = false; } #if CONFIG_IS_ENABLED(DM_SPI_FLASH) @@ -131,14 +134,18 @@ static int do_spi_flash_probe(int argc, char *const argv[]) device_remove(new, DM_REMOVE_NORMAL); } flash = NULL; - ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new); - if (ret) { + if (use_dt) { + spi_flash_probe_bus_cs(bus, cs, &new); + flash = dev_get_uclass_priv(new); + } else { + flash = spi_flash_probe(bus, cs, speed, mode); + } + + if (!flash) { printf("Failed to initialize SPI flash at %u:%u (error %d)\n", bus, cs, ret); return 1; } - - flash = dev_get_uclass_priv(new); #else if (flash) spi_flash_free(flash); @@ -166,7 +173,7 @@ static int do_spi_flash_probe(int argc, char *const argv[]) * @param buf buffer to write from * @param cmp_buf read buffer to use to compare data * @param skipped Count of skipped data (incremented by this function) - * @return NULL if OK, else a string containing the stage which failed + * Return: NULL if OK, else a string containing the stage which failed */ 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) @@ -208,7 +215,7 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset, * @param offset flash offset to write * @param len number of bytes to write * @param buf buffer to write from - * @return 0 if ok, 1 on error + * Return: 0 if ok, 1 on error */ static int spi_flash_update(struct spi_flash *flash, u32 offset, size_t len, const char *buf) @@ -287,6 +294,12 @@ static int do_spi_flash_read_write(int argc, char *const argv[]) return 1; } + if (strncmp(argv[0], "read", 4) != 0 && flash->flash_is_unlocked && + !flash->flash_is_unlocked(flash, offset, len)) { + printf("ERROR: flash area is locked\n"); + return 1; + } + buf = map_physmem(addr, len, MAP_WRBACK); if (!buf && addr) { puts("Failed to map physical memory\n"); @@ -343,6 +356,12 @@ static int do_spi_flash_erase(int argc, char *const argv[]) return 1; } + if (flash->flash_is_unlocked && + !flash->flash_is_unlocked(flash, offset, len)) { + printf("ERROR: flash area is locked\n"); + return 1; + } + ret = spi_flash_erase(flash, offset, size); printf("SF: %zu bytes @ %#x Erased: ", (size_t)size, (u32)offset); if (ret) @@ -384,7 +403,6 @@ static int do_spi_protect(int argc, char *const argv[]) return ret == 0 ? 0 : 1; } -#ifdef CONFIG_CMD_SF_TEST enum { STAGE_ERASE, STAGE_CHECK, @@ -394,7 +412,7 @@ enum { STAGE_COUNT, }; -static char *stage_name[STAGE_COUNT] = { +static const char *stage_name[STAGE_COUNT] = { "erase", "check", "write", @@ -439,7 +457,7 @@ static void spi_test_next_stage(struct test_info *test) * @param len Size of data to read/write * @param offset Offset within flash to check * @param vbuf Verification buffer - * @return 0 if ok, -1 on error + * Return: 0 if ok, -1 on error */ static int spi_flash_test(struct spi_flash *flash, uint8_t *buf, ulong len, ulong offset, uint8_t *vbuf) @@ -548,7 +566,6 @@ static int do_spi_flash_test(int argc, char *const argv[]) return 0; } -#endif /* CONFIG_CMD_SF_TEST */ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) @@ -582,10 +599,8 @@ static int do_spi_flash(struct cmd_tbl *cmdtp, int flag, int argc, ret = do_spi_flash_erase(argc, argv); else if (strcmp(cmd, "protect") == 0) ret = do_spi_protect(argc, argv); -#ifdef CONFIG_CMD_SF_TEST - else if (!strcmp(cmd, "test")) + else if (IS_ENABLED(CONFIG_CMD_SF_TEST) && !strcmp(cmd, "test")) ret = do_spi_flash_test(argc, argv); -#endif else ret = -1; @@ -597,16 +612,8 @@ usage: return CMD_RET_USAGE; } -#ifdef CONFIG_CMD_SF_TEST -#define SF_TEST_HELP "\nsf test offset len " \ - "- run a very basic destructive test" -#else -#define SF_TEST_HELP -#endif - -U_BOOT_CMD( - sf, 5, 1, do_spi_flash, - "SPI flash sub-system", +#ifdef CONFIG_SYS_LONGHELP +static const char long_help[] = "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" " and chip select\n" "sf read addr offset|partition len - read `len' bytes starting at\n" @@ -622,6 +629,14 @@ U_BOOT_CMD( " at `addr' to flash at `offset'\n" " or to start of mtd `partition'\n" "sf protect lock/unlock sector len - protect/unprotect 'len' bytes starting\n" - " at address 'sector'\n" - SF_TEST_HELP + " at address 'sector'" +#ifdef CONFIG_CMD_SF_TEST + "\nsf test offset len - run a very basic destructive test" +#endif +#endif /* CONFIG_SYS_LONGHELP */ + ; + +U_BOOT_CMD( + sf, 5, 1, do_spi_flash, + "SPI flash sub-system", long_help );