From patchwork Mon Dec 31 11:13:42 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 208833 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 861482C0086 for ; Mon, 31 Dec 2012 22:16:26 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 1830F4A156; Mon, 31 Dec 2012 12:16:24 +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 unVEmvoJzNWD; Mon, 31 Dec 2012 12:16:23 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BB9284A15B; Mon, 31 Dec 2012 12:15:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EE8154A11F for ; Mon, 31 Dec 2012 12:14:58 +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 yVj+5vUHJrut for ; Mon, 31 Dec 2012 12:14:54 +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-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by theia.denx.de (Postfix) with ESMTPS id B222C4A01E for ; Mon, 31 Dec 2012 12:14:17 +0100 (CET) Received: by mail-pb0-f50.google.com with SMTP id wz7so6989528pbc.9 for ; Mon, 31 Dec 2012 03:14:16 -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=XKwRMBDh/jgiiYA5ovV00KmVDD0sx33MYVu+ZoNxWhQ=; b=YNIALCfJI+rKxbBUDpc/NGK1+oFLP6q0u5BvOWrI7HNJ601SnAMp5QvH9GEJSI1LCv TAkfx6gNCWfx6NGmvGEFVl3djD87ReCVCJEEbaZjJtI8q5XOLcLYZkOR+yxm7AAyLRr/ 84grsCAj0fRE0o8U3GtU5liDlQwvL4ht5M3b9FGTB8Rhqhfcv36rs3cbjuw2bhHYGoBP BRHOB6vsJx7OWJa8lVCxcD1HMSCXlSbbszdM2aWnXA7yiUfKRu4Sh8n/GXPtroCyI+jc UEuSKklujDTXJHXqfC45kogKHlFUBm4MH9NeYCqHE3M8kzqDqDgMVpnsxJaBN+dx5nA+ JIZQ== X-Received: by 10.68.241.133 with SMTP id wi5mr126119640pbc.48.1356952456060; Mon, 31 Dec 2012 03:14:16 -0800 (PST) Received: from localhost.localdomain ([49.204.11.250]) by mx.google.com with ESMTPS id nw9sm24715215pbb.42.2012.12.31.03.14.14 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Dec 2012 03:14:15 -0800 (PST) From: Jagannadha Sutradharudu Teki To: u-boot@lists.denx.de Date: Mon, 31 Dec 2012 16:43:42 +0530 Message-Id: <1356952428-19824-4-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 03/12] cmd_sf: Add wr_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 write instruction(wr_inst) argument to 'sf update' command. User will dynamically use the specific write instruction while programming the flash using 'sf update' command. Currently added an existing write instruction called pp(Page Program). Example: erase and write 0x2000 length bytes from memory at 0x10000 address to flash offset at 0x0 using pp write instruction. u-boot> sf update pp 0x10000 0x0 0x2000 Signed-off-by: Jagannadha Sutradharudu Teki --- common/cmd_sf.c | 37 ++++++++++++++++++++++++++----------- 1 files changed, 26 insertions(+), 11 deletions(-) diff --git a/common/cmd_sf.c b/common/cmd_sf.c index 88b18f8..0f4e440 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -141,6 +141,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) * If the data being written is the same, then *skipped is incremented by len. * * @param flash flash context pointer + * @param wr_inst write instruction * @param offset flash offset to write * @param len number of bytes to write * @param buf buffer to write from @@ -148,8 +149,9 @@ static int do_spi_flash_probe(int argc, char * const argv[]) * @param skipped Count of skipped data (incremented by this function) * @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) +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) { debug("offset=%#x, sector_size=%#x, len=%#zx\n", offset, flash->sector_size, len); @@ -163,7 +165,7 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset, } if (spi_flash_erase(flash, offset, len)) return "erase"; - if (spi_flash_write(flash, offset, len, buf)) + if (spi_flash_write(flash, wr_inst, offset, len, buf)) return "write"; return NULL; } @@ -173,12 +175,13 @@ static const char *spi_flash_update_block(struct spi_flash *flash, u32 offset, * to change. Existing blocks with the correct data are left unchanged. * * @param flash flash context pointer + * @param wr_inst write 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, u32 offset, +static int spi_flash_update(struct spi_flash *flash, u8 wr_inst, u32 offset, size_t len, const char *buf) { const char *err_oper = NULL; @@ -206,8 +209,9 @@ static int spi_flash_update(struct spi_flash *flash, u32 offset, start_time)); last_update = get_timer(0); } - err_oper = spi_flash_update_block(flash, offset, todo, - buf, cmp_buf, &skipped); + err_oper = spi_flash_update_block(flash, wr_inst, + offset, todo, buf, cmp_buf, + &skipped); } } else { err_oper = "malloc"; @@ -264,9 +268,17 @@ static int do_spi_flash_read_write(int argc, char * const argv[]) return 1; } - if (strcmp(argv[0], "update") == 0) - ret = spi_flash_update(flash, offset, len, buf); - else if (strcmp(argv[0], "read") == 0) { + if (strcmp(argv[0], "update") == 0) { + if (strcmp(argv[1], "pp") == 0) + wr_inst = CMD_PAGE_PROGRAM; + else { + printf("SF: Unknown %s wr_inst on 'sf update'\n", + argv[1]); + return 1; + } + + ret = spi_flash_update(flash, wr_inst, offset, len, buf); + } else if (strcmp(argv[0], "read") == 0) { if (strcmp(argv[1], "afr") == 0) rd_inst = CMD_READ_ARRAY_FAST; else { @@ -555,7 +567,10 @@ 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 addr offset len - erase and write `len' bytes from memory\n" - " at `addr' to flash at `offset'" + "sf update wr_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)" SF_TEST_HELP );