From patchwork Fri May 16 18:26:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 349716 X-Patchwork-Delegate: scottwood@freescale.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 9C6B0140084 for ; Sat, 17 May 2014 04:27:17 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6BFF54B662; Fri, 16 May 2014 20:27:10 +0200 (CEST) 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 22Wp0swvKGWl; Fri, 16 May 2014 20:27:10 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CDA184B774; Fri, 16 May 2014 20:27:00 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 841D54B662 for ; Fri, 16 May 2014 20:26:53 +0200 (CEST) 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 EwABjqrWsKYi for ; Fri, 16 May 2014 20:26:49 +0200 (CEST) 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 devils.ext.ti.com (devils.ext.ti.com [198.47.26.153]) by theia.denx.de (Postfix) with ESMTPS id 098C14B739 for ; Fri, 16 May 2014 20:26:47 +0200 (CEST) Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s4GIQjQC001282 for ; Fri, 16 May 2014 13:26:45 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4GIQjRu027120 for ; Fri, 16 May 2014 13:26:45 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Fri, 16 May 2014 13:26:45 -0500 Received: from khorivan.itg.ti.com (incasgf5a_e1_2.itg.ti.com [10.167.216.36]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s4GIQeKq032261; Fri, 16 May 2014 13:26:43 -0500 From: Ivan Khoronzhuk To: , Date: Fri, 16 May 2014 21:26:36 +0300 Message-ID: <1400264797-3593-2-git-send-email-ivan.khoronzhuk@ti.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1400264797-3593-1-git-send-email-ivan.khoronzhuk@ti.com> References: <1400264797-3593-1-git-send-email-ivan.khoronzhuk@ti.com> MIME-Version: 1.0 Cc: hzhang@ti.com, w-kwok2@ti.com, santosh.shilimkar@ti.com Subject: [U-Boot] [U-boot] [Patch 1/2] common: cmd_nand: add nand ecclayout 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: WingMan Kwok This commit adds a nand ecclayout command that allows the ecclayout of the current nand device to be changed during run time. This feature is useful when using u-boot to write something to nand flash that will be read by other applications, such as ROM bootloader, that expects a different ECC layout. In that case, change the current nand device ecclayout using the "nand ecclayout set" command before writing the data to nand flash. Signed-off-by: WingMan Kwok Signed-off-by: Ivan Khoronzhuk --- common/cmd_nand.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++- include/nand.h | 10 +++++ 2 files changed, 124 insertions(+), 1 deletion(-) diff --git a/common/cmd_nand.c b/common/cmd_nand.c index 04ab0f1..7cbe6fc 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -462,6 +462,53 @@ static void adjust_size_for_badblocks(loff_t *size, loff_t offset, int dev) } } +#ifdef CONFIG_CMD_NAND_ECCLAYOUT +static void nand_print_ecclayout_info(struct nand_ecclayout *p) +{ + int i; + struct nand_oobfree *oobfree; + + if (!p) + return; + + printf(" num ecc bytes: %d\n", p->eccbytes); + puts(" ecc pos:\n "); + + for (i = 0; i < p->eccbytes; i++) { + if (i && !(i % 9)) + printf("\n "); + + printf("%2d ", p->eccpos[i]); + } + + puts("\n oobfree:\n"); + puts(" offset length\n"); + + oobfree = p->oobfree; + for (i = 0; oobfree->length && i < MTD_MAX_OOBFREE_ENTRIES_LARGE; i++) { + printf(" %2d %2d\n", oobfree->offset, oobfree->length); + oobfree++; + } +} + +static void nand_print_device_ecclayout(int dev) +{ + int idx; + nand_info_t *nand = &nand_info[dev]; + struct nand_chip *chip = nand->priv; + + idx = board_nand_ecclayout_get_idx(chip, chip->ecc.layout); + + if (idx < 0) { + puts("no ecc layout\n"); + return; + } + + printf("\necc layout %d:\n", idx); + nand_print_ecclayout_info(chip->ecc.layout); +} +#endif + static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int i, ret = 0; @@ -506,8 +553,12 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) putc('\n'); if (dev < 0 || dev >= CONFIG_SYS_MAX_NAND_DEVICE) puts("no devices available\n"); - else + else { nand_print_and_set_info(dev); +#ifdef CONFIG_CMD_NAND_ECCLAYOUT + nand_print_device_ecclayout(dev); +#endif + } return 0; } @@ -836,6 +887,60 @@ static int do_nand(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif +#ifdef CONFIG_CMD_NAND_ECCLAYOUT + if (strcmp(cmd, "ecclayout") == 0) { + int idx; + struct nand_ecclayout *p; + nand_info_t *nand = &nand_info[dev]; + struct nand_chip *chip = nand->priv; + + if (argc < 3) { + puts("Current device ecclayout:\n"); + nand_print_device_ecclayout(dev); + return 0; + } + + if (!strcmp(argv[2], "set")) { + if (argc < 4) + return 1; + + idx = (int)simple_strtoul(argv[3], NULL, 10); + if (!board_nand_ecclayout_set(chip, idx)) { + p = chip->ecc.layout; + p->oobavail = 0; + for (i = 0; p->oobfree[i].length && + i < ARRAY_SIZE(p->oobfree); i++) + p->oobavail += p->oobfree[i].length; + + nand->oobavail = p->oobavail; + } else { + printf("Setting current device" + " to ecc layout %d FAILED!\n", idx); + } + + return 0; + } + + if (strcmp(argv[2], "all") != 0) + return 1; + + /* show all available ecc layouts */ + puts("Available ecc layouts:\n"); + + idx = 0; + while (1) { + p = board_nand_ecclayout_get_layout(chip, idx); + if (!p) + break; + + printf("\n ecc layout %d:\n", idx++); + nand_print_ecclayout_info(p); + } + + return 0; + } +#endif + usage: return CMD_RET_USAGE; } @@ -890,6 +995,14 @@ static char nand_help_text[] = "nand env.oob set off|partition - set enviromnent offset\n" "nand env.oob get - get environment offset" #endif +#ifdef CONFIG_CMD_NAND_ECCLAYOUT + "\n" + "nand ecclayout |all> - show or set ecclayout" + " of current device\n" + " 'all' shows all available ecc layouts for setting" + " to current device\n" + " 'set' sets current device ecc layout to layout indexed by idx\n" +#endif ""; #endif diff --git a/include/nand.h b/include/nand.h index fc735d1..0e8a093 100644 --- a/include/nand.h +++ b/include/nand.h @@ -155,6 +155,16 @@ void nand_deselect(void); void board_nand_select_device(struct nand_chip *nand, int chip); #endif +#ifdef CONFIG_CMD_NAND_ECCLAYOUT +int board_nand_ecclayout_get_idx(struct nand_chip *nand, + struct nand_ecclayout *p); + +struct nand_ecclayout *board_nand_ecclayout_get_layout(struct nand_chip *nand, + int idx); + +int board_nand_ecclayout_set(struct nand_chip *nand, int idx); +#endif + __attribute__((noreturn)) void nand_boot(void); #endif