From 4715d15e1726cac7a8e86a5514072b024c71547e Mon Sep 17 00:00:00 2001 From: Andy Yan Date: Tue, 6 Feb 2018 09:52:31 +0800 Subject: [PATCH] cmd: sf: add test count Change-Id: I06c0783998152ef5d32f95f6813d5dfe315b4cc2 Signed-off-by: Andy Yan --- cmd/sf.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/sf.c b/cmd/sf.c index f971eec781..9953895268 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -442,12 +442,15 @@ static int spi_flash_test(struct spi_flash *flash, uint8_t *buf, ulong len, { struct test_info test; int i; + int erase_len; printf("SPI flash test:\n"); memset(&test, '\0', sizeof(test)); test.base_ms = get_timer(0); test.bytes = len; - if (spi_flash_erase(flash, offset, len)) { + + erase_len = roundup(len, 4096); + if (spi_flash_erase(flash, offset, erase_len)) { printf("Erase failed\n"); return -1; } @@ -506,6 +509,8 @@ static int do_spi_flash_test(int argc, char * const argv[]) char *endp; uint8_t *vbuf; int ret; + int count; + int i; if (argc < 3) return -1; @@ -516,6 +521,10 @@ static int do_spi_flash_test(int argc, char * const argv[]) if (*argv[2] == 0 || *endp != 0) return -1; + count = simple_strtoul(argv[3], &endp, 10); + if (!count) + count = 1; + vbuf = memalign(ARCH_DMA_MINALIGN, len); if (!vbuf) { printf("Cannot allocate memory (%lu bytes)\n", len); @@ -530,7 +539,13 @@ static int do_spi_flash_test(int argc, char * const argv[]) from = map_sysmem(CONFIG_SYS_TEXT_BASE, 0); memcpy(buf, from, len); - ret = spi_flash_test(flash, buf, len, offset, vbuf); + for (i = 0; i < count; i++) { + ret = spi_flash_test(flash, buf, len, offset, vbuf); + if (ret < 0) { + printf("Test Failed, passed count:%d\n", i); + break; + } + } free(vbuf); free(buf); if (ret) {