From patchwork Mon Dec 31 11:13:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 208835 X-Patchwork-Delegate: jagannadh.teki@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 287502C0086 for ; Mon, 31 Dec 2012 22:16:47 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EF5C74A16D; Mon, 31 Dec 2012 12:16:42 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tYckcJ9ExhJL; Mon, 31 Dec 2012 12:16:42 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 139C44A16E; Mon, 31 Dec 2012 12:15:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1C3BA4A11F for ; Mon, 31 Dec 2012 12:15:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HOKTsor+DxFn for ; Mon, 31 Dec 2012 12:14:59 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-da0-f48.google.com (mail-da0-f48.google.com [209.85.210.48]) by theia.denx.de (Postfix) with ESMTPS id 2567E4A026 for ; Mon, 31 Dec 2012 12:14:19 +0100 (CET) Received: by mail-da0-f48.google.com with SMTP id k18so5770949dae.7 for ; Mon, 31 Dec 2012 03:14:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=f1VlqA26C+whtoriiE+OU9yHboX12oXGoG9WRwKBU4s=; b=AYg29hytWuaw+Jkoy71lV0TXJoa/C/ZcrpORf75kJysgoXknOCqGAcYkUU4Zd3rB2s tEM0kMsvM6g+Gi0tuNDJXzuNYu34bRHTL/+uQ8Ha0tlctgVw7MwxbglQ/G+WBF4bSh3J p2foSQ5eGuIF8gCRWCIgJ38mtvbalRCHAXHFVLKzEYWj7WHVZBf9QUtK6uyQYPN/7abW a45X254R0x2FvqYRHZ7sVqW6WTaKcI6AdyQOzMF2f9jp5HvVgH05Ne05O97PNJHZl/MK WqVUkeaBZjC9tA4nmMxWwj/Z/3I/uviA1UnFNbzEJG6Lcrk7fJ3bmnjyO4+SzT4Kqm0V MiLw== X-Received: by 10.66.77.200 with SMTP id u8mr119947535paw.43.1356952458068; Mon, 31 Dec 2012 03:14:18 -0800 (PST) Received: from localhost.localdomain ([49.204.11.250]) by mx.google.com with ESMTPS id nw9sm24715215pbb.42.2012.12.31.03.14.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Dec 2012 03:14:17 -0800 (PST) From: Jagannadha Sutradharudu Teki To: u-boot@lists.denx.de Date: Mon, 31 Dec 2012 16:43:43 +0530 Message-Id: <1356952428-19824-5-git-send-email-jagannadh.teki@gmail.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1356952428-19824-1-git-send-email-jagannadh.teki@gmail.com> References: <1356952428-19824-1-git-send-email-jagannadh.teki@gmail.com> Subject: [U-Boot] [PATCH 04/12] cmd_sf: Add rd_inst argument to 'sf update' command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This patch provides a support to add a read instruction(rd_inst) argument to 'sf update' command. User will dynamically use the specific read instruction while reading the flash using 'sf update' command. Currently added an existing read instruction called afr(Array Fast Read). Example: erase and write 0x2000 length bytes from memory at 0x10000 address to flash offset at 0x0 using pp write instruction and afr read instruction. u-boot> sf update pp afr 0x10000 0x0 0x2000 Signed-off-by: Jagannadha Sutradharudu Teki --- common/cmd_sf.c | 63 +++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 43 insertions(+), 20 deletions(-) diff --git a/common/cmd_sf.c b/common/cmd_sf.c index 0f4e440..4cfd48a 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -142,6 +142,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) * * @param flash flash context pointer * @param wr_inst write instruction + * @param rd_inst read instruction * @param offset flash offset to write * @param len number of bytes to write * @param buf buffer to write from @@ -150,12 +151,12 @@ static int do_spi_flash_probe(int argc, char * const argv[]) * @return NULL if OK, else a string containing the stage which failed */ static const char *spi_flash_update_block(struct spi_flash *flash, u8 wr_inst, - u32 offset, size_t len, const char *buf, char *cmp_buf, - size_t *skipped) + u8 rd_inst, u32 offset, size_t len, const char *buf, + char *cmp_buf, size_t *skipped) { debug("offset=%#x, sector_size=%#x, len=%#zx\n", offset, flash->sector_size, len); - if (spi_flash_read(flash, offset, len, cmp_buf)) + if (spi_flash_read(flash, rd_inst, offset, len, cmp_buf)) return "read"; if (memcmp(cmp_buf, buf, len) == 0) { debug("Skip region %x size %zx: no change\n", @@ -176,13 +177,14 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u8 wr_inst, * * @param flash flash context pointer * @param wr_inst write instruction + * @param rd_inst read instruction * @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 */ -static int spi_flash_update(struct spi_flash *flash, u8 wr_inst, u32 offset, - size_t len, const char *buf) +static int spi_flash_update(struct spi_flash *flash, u8 wr_inst, u8 rd_inst, + u32 offset, size_t len, const char *buf) { const char *err_oper = NULL; char *cmp_buf; @@ -210,8 +212,8 @@ static int spi_flash_update(struct spi_flash *flash, u8 wr_inst, u32 offset, last_update = get_timer(0); } err_oper = spi_flash_update_block(flash, wr_inst, - offset, todo, buf, cmp_buf, - &skipped); + rd_inst, offset, todo, buf, + cmp_buf, &skipped); } } else { err_oper = "malloc"; @@ -240,19 +242,29 @@ static int do_spi_flash_read_write(int argc, char * const argv[]) void *buf; char *endp; u8 wr_inst, rd_inst; + int update_rd_inst; int ret; - if (argc < 5) - return -1; + if (strcmp(argv[0], "update") == 0) { + if (argc < 6) + return -1; - addr = simple_strtoul(argv[2], &endp, 16); - if (*argv[2] == 0 || *endp != 0) + update_rd_inst = 1; + } else { + if (argc < 5) + return -1; + + update_rd_inst = 0; + } + + addr = simple_strtoul(argv[update_rd_inst + 2], &endp, 16); + if (*argv[update_rd_inst + 2] == 0 || *endp != 0) return -1; - offset = simple_strtoul(argv[3], &endp, 16); - if (*argv[3] == 0 || *endp != 0) + offset = simple_strtoul(argv[update_rd_inst + 3], &endp, 16); + if (*argv[update_rd_inst + 3] == 0 || *endp != 0) return -1; - len = simple_strtoul(argv[4], &endp, 16); - if (*argv[4] == 0 || *endp != 0) + len = simple_strtoul(argv[update_rd_inst + 4], &endp, 16); + if (*argv[update_rd_inst + 4] == 0 || *endp != 0) return -1; /* Consistency checking */ @@ -277,7 +289,16 @@ static int do_spi_flash_read_write(int argc, char * const argv[]) return 1; } - ret = spi_flash_update(flash, wr_inst, offset, len, buf); + if (strcmp(argv[2], "afr") == 0) + rd_inst = CMD_READ_ARRAY_FAST; + else { + printf("SF: Unknown %s rd_inst on 'sf update'\n", + argv[2]); + return 1; + } + + ret = spi_flash_update(flash, wr_inst, rd_inst, + offset, len, buf); } else if (strcmp(argv[0], "read") == 0) { if (strcmp(argv[1], "afr") == 0) rd_inst = CMD_READ_ARRAY_FAST; @@ -551,7 +572,7 @@ usage: #endif U_BOOT_CMD( - sf, 6, 1, do_spi_flash, + sf, 7, 1, do_spi_flash, "SPI flash sub-system", "probe [[bus:]cs] [hz] [mode] - init flash device on given SPI bus\n" " and chip select\n" @@ -567,10 +588,12 @@ U_BOOT_CMD( " pp (Page Program, 02h)\n" "sf erase offset [+]len - erase `len' bytes from `offset'\n" " `+len' round up `len' to block size\n" - "sf update wr_inst addr offset len\n" + "sf update wr_inst rd_inst addr offset len\n" " - erase and write `len' bytes from memory\n" " at `addr' to flash at `offset' using\n" - " pp `wr_inst' write instruction\n" - " pp (Page Program, 02h)" + " pp `wr_inst' write instruction and\n" + " pp (Page Program, 02h)\n" + " afr `rd_inst' read instruction\n" + " afr (Array Fast Read, 0bh)" SF_TEST_HELP );