From patchwork Fri Jun 14 07:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 557 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pf1-f199.google.com (mail-pf1-f199.google.com [209.85.210.199]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 1A6663F033 for ; Fri, 14 Jun 2019 09:37:36 +0200 (CEST) Received: by mail-pf1-f199.google.com with SMTP id x9sf1168103pfm.16 for ; Fri, 14 Jun 2019 00:37:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560497854; cv=pass; d=google.com; s=arc-20160816; b=aNeh7rX34LrR7lIDTYn8DnJD6x0KD8Kv+LO5Mfv2aLIt6Sfy9KEjxyJ0crpOh17hMQ aEaJDu6h+llXsFgytxFKskCURhMvy5fkS5JT1NpHB54q/AMIUvPZLaZSvnsqyg5T/Gdk seNbQhazXFQ/cCSUHVXePXfi1FrXsKAKD/em+yAV4vQwN+w5KbJHDdIH09gNvoa9J1Fp eOGgrEPqMPyOM7RQkHXabz5xktBGo2ryVcb5gPAF2a+0LJVb3ESSIEbln+eHtlISkmVF 37TxxDmaNqMyAqwui1xUAYjpFjm2QiWjahZIFFeYEKOM62ucSEfD99EU0lIO5+8+xxLe 5M3w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:message-id:date:subject:cc:to:from :mime-version:dkim-signature; bh=+3RTK1fHLPuJRM8W483jcRUuKkUIC8irr9R7NTif1aQ=; b=HanTpLlFzo03RfOL1fdCtpkoRUwEnXBQBe7V7IRVu7QeJHpM+l7Yqmx3zhX480IGRY xXeByIMV8F0dpuRdeQOTbil1eAKCDI0NC0dtXs6P2AL1E25mwmqoKV+GfNio70gh+StU B7wR5RFdg/1dUDHRxapbvDYDWpXbRasZf6MwtOKmzyt3lTXv3xLUxp7qqfqy0EHuchyI u/AxAkoaHHuLylDpJjZXQro0XGBCOc74wqrNeyoiGWa+cFDh1uc+TVw7RH28c+Dw+Ffc 2QQJNqYUliruKOjiOQ7dccfhQF5HnQvmdzuE6zb0Q3ZPf1/nairiWpAePuOryQxDMsPL tONA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ejYypAEQ; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=+3RTK1fHLPuJRM8W483jcRUuKkUIC8irr9R7NTif1aQ=; b=oWMDFPi4k+jd6WU/svPEifwlHpMt9WDr+td8zMZL9vDsm41rqSt1rbm0sptZp/qDXq qYyEqROEgoXpHF5aOrh5XItAePw3x4JKotkO+5wOe9rttjlb4vWfRI7Y2zul1BBfbpL7 E4KGzt3cPQuNtnaUWN5xn3tR7FanqbRVbnXN8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:x-spam-checked-in-group:list-post:list-help :list-archive:list-unsubscribe; bh=+3RTK1fHLPuJRM8W483jcRUuKkUIC8irr9R7NTif1aQ=; b=axPcZhFRKbvBkID/rwyildXcb0BXan1UJvx4ejQzcJnv0MJPP3E8GLUqf3+qBoHx93 hGnw2Uz55byEMuckCwtIELyN5doXR2tX1l8Z4TG3vTUPbrisl4pQ+323lPVZM4CX5E/0 8sCa72MSHZDxsei0OBnTQiNA+9o9Ls7EJzs6uxneDIDW1dztGTCEHHdwjMuPH4tDbUgJ 5KIzCEH9RnVDHLOhQADUPoPZuTOE55XrlT4IgVghkJHXq2CdJ93EKFtdVjb8XhVLzm3a 23JYiThp1vaPpJL4VCMi1dVQfr06E/4JmS0RnWzHaEe3E4W7S+fCAjNk/e9BeMkZGz/o a0wg== X-Gm-Message-State: APjAAAWdr3Bl53AKviE7EGYdt98SZXdddNdOZf+RqYaCTotuIDqezq1t cZ4OK6sIVfqw5jyQ8+Iu89pawOR6 X-Google-Smtp-Source: APXvYqxfr6gBXdPHENe1nxAW4giiZkResC9sIvUcyBfbNaxtoIEf4Odq6L36ElH0pz5Rpce2ofFxBA== X-Received: by 2002:a63:5009:: with SMTP id e9mr33831045pgb.396.1560497853668; Fri, 14 Jun 2019 00:37:33 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a62:ea02:: with SMTP id t2ls1819458pfh.4.gmail; Fri, 14 Jun 2019 00:37:33 -0700 (PDT) X-Received: by 2002:a63:574b:: with SMTP id h11mr9249178pgm.25.1560497853130; Fri, 14 Jun 2019 00:37:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560497853; cv=none; d=google.com; s=arc-20160816; b=h/tNnNp4h1a+zQiv1uD77dji/2z2+EwqwFKR1+f1wlB7mhfGuXlrDR3WBsepX3sq4Z eb7MejFrmIKoAj9Hun6/EMub+pcj2V0g3AkzGwcvNhVWGuAvAmqS+fYn9GPZ1cZ1XWe9 SRMbtuTzkIgENX625PrZxSaSwJKKtlsHFsPcjb4IAkDJTaf9LSkCdmkeXijReChs19T4 g6RfFuUbOFTUE5YQEZ3ngEUNzR7kETEeNtw3fSotKi8nGuOZ1k2ihcTQarqm/mcpX8VD 66h9rRHb13Q7do3XPyPxq3A9UQiBEqbfS1PTMngJ4RGlifdqgyADyGD4LpcY7GN/GAVT aFzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature; bh=+3HOsNqLLfpWziWFI3gSG9D7aVb0oytlzYMyj2lFXDI=; b=hbb/tyjD53ycEIvKPz+1NGwuFliHmj4ZTv8VEMig2NvErTJTU6kwAALzX1hrxbMOP7 ZKGkLLaBmj+FjAZPTW1yQrVVVja1oIh+RFWfudSHTmM0b07mbBqSVwVDNiRbaGo2HTLl s9w0dYMBgFmHVBGqHIyqpoJ7OKppfvsgygQfcx0Jdf699TFG+ai0fq/LmLJh1Nz20IdB KAQId98hBj5ULa5LGJaSQW+u1HeYhGZ5fJPSBpHLxNQMLbT49ZCp9LB/lf9mAiunjpjq Zc0RresH7s88ykaEz5PpIm6qm3HBXzAf6qmCaZNw4Ca/dzL/P1reNGennCxfzsd5hgWm h+Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ejYypAEQ; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x13sor2243372pgx.2.2019.06.14.00.37.32 for (Google Transport Security); Fri, 14 Jun 2019 00:37:32 -0700 (PDT) Received-SPF: pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a65:5945:: with SMTP id g5mr2088078pgu.169.1560497851808; Fri, 14 Jun 2019 00:37:31 -0700 (PDT) Received: from localhost.localdomain ([183.82.230.16]) by smtp.googlemail.com with ESMTPSA id c14sm887609pgm.40.2019.06.14.00.37.27 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 00:37:30 -0700 (PDT) From: Shyam Saini To: sbabic@denx.de Cc: u-boot@lists.denx.de, ksi@koi8.net, stefan.agner@toradex.com, festevam@gmail.com, jagan@amarulasolutions.com, michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, uboot-imx@nxp.com, Shyam Saini Subject: [PATCH v6 1/3] i.MX6: nand: add nandbcb command for imx Date: Fri, 14 Jun 2019 13:05:33 +0530 Message-Id: <20190614073535.12502-1-shyam.saini@amarulasolutions.com> X-Mailer: git-send-email 2.11.0 X-Original-Sender: shyam.saini@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=ejYypAEQ; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Writing/updating boot image in nand device is not straight forward in i.MX6 platform and it requires boot control block(BCB) to be configured. It becomes difficult to use uboot 'nand' command to write BCB since it requires platform specific attributes need to be taken care of. It is even difficult to use existing msx-nand.c driver by incorporating BCB attributes like mxs_dma_desc does because it requires change in mtd and nand command. So, cmd_nandbcb implemented in arch/arm/mach-imx BCB contains two data structures, Firmware Configuration Block(FCB) and Discovered Bad Block Table(DBBT). FCB has nand timings, DBBT search area, page address of firmware. On summary, nandbcb update will - erase the entire partition - create BCB by creating 2 FCB/DBBT block followed by 1 FW block based on partition size and erasesize. - fill FCB/DBBT structures - write FW/SPL on FW1 - write FCB/DBBT in first 2 blocks for nand boot, up on reset bootrom look for FCB structure in first block's if FCB found the nand timings are loaded for further reads. once FCB read done, DTTB will load and finally firmware will be loaded which is boot image. Refer section "NAND Boot" from doc/imx/common/imx6.txt for more usage information. Reviewed-by: Stefano Babic Signed-off-by: Jagan Teki Signed-off-by: Sergey Kubushyn Signed-off-by: Shyam Saini --- Changes for v6: - Consolidate v5 patch 1 and patch 2 into one single patch - Make separate docs patch out of v5 patch 1 Changes for v5: - Move mxs_nand.h file from drivers/mtd/nand/raw/ to include/ directory so that it can be used by both drivers/ and arch/ - Fix command steps output in docs Changes for v4: - Remove obselete apis and use bch_geometry structure for calculating ecc level, bad block start bit and bad block byte - Write firmware only once - Shorten variable names - Update commit message - Update docs as per current patch - Fix checkpatch warnings Changes for v3: - Fixed multi-line comments - Better error handling for failed allocations Changes for v2: - Fixed commit message notes - Updated proper commit message - Update doc/README.imx6 with NAND boot details - Fixed long length variable names. - Fixed Gigantic variable name. - NULL checks for kzalloc - Move Kconfig option in separate patch - Fixed checkpatch warninigs arch/arm/include/asm/mach-imx/imx-nandbcb.h | 111 ++++++++ arch/arm/mach-imx/Kconfig | 11 + arch/arm/mach-imx/Makefile | 1 + arch/arm/mach-imx/cmd_nandbcb.c | 369 +++++++++++++++++++++++++++ drivers/mtd/nand/raw/mxs_nand.c | 2 +- drivers/mtd/nand/raw/mxs_nand_dt.c | 2 +- drivers/mtd/nand/raw/mxs_nand_spl.c | 2 +- {drivers/mtd/nand/raw => include}/mxs_nand.h | 0 8 files changed, 495 insertions(+), 3 deletions(-) create mode 100644 arch/arm/include/asm/mach-imx/imx-nandbcb.h create mode 100644 arch/arm/mach-imx/cmd_nandbcb.c rename {drivers/mtd/nand/raw => include}/mxs_nand.h (100%) diff --git a/arch/arm/include/asm/mach-imx/imx-nandbcb.h b/arch/arm/include/asm/mach-imx/imx-nandbcb.h new file mode 100644 index 0000000000..033659a038 --- /dev/null +++ b/arch/arm/include/asm/mach-imx/imx-nandbcb.h @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2017 Jagan Teki + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _IMX_NAND_BCB_H_ +#define _IMX_NAND_BCB_H_ + +#define FCB_FINGERPRINT 0x20424346 /* 'FCB' */ +#define FCB_VERSION_1 0x01000000 + +#define DBBT_FINGERPRINT2 0x54424244 /* 'DBBT' */ +#define DBBT_VERSION_1 0x01000000 + +struct dbbt_block { + u32 checksum; /* reserved on i.MX6 */ + u32 fingerprint; + u32 version; + u32 numberbb; /* reserved on i.MX6 */ + u32 dbbtpages; +}; + +struct fcb_block { + u32 checksum; /* First fingerprint in first byte */ + u32 fingerprint; /* 2nd fingerprint at byte 4 */ + u32 version; /* 3rd fingerprint at byte 8 */ + u8 datasetup; + u8 datahold; + u8 addr_setup; + u8 dsample_time; + + /* These are for application use only and not for ROM. */ + u8 nandtiming; + u8 rea; + u8 rloh; + u8 rhoh; + u32 pagesize; /* 2048 for 2K pages, 4096 for 4K pages */ + u32 oob_pagesize; /* 2112 for 2K pages, 4314 for 4K pages */ + u32 sectors; /* Number of 2K sections per block */ + u32 nr_nand; /* Total Number of NANDs - not used by ROM */ + u32 nr_die; /* Number of separate chips in this NAND */ + u32 celltype; /* MLC or SLC */ + u32 ecc_type; /* Type of ECC, can be one of BCH-0-20 */ + u32 ecc_nr; /* Number of bytes for Block0 - BCH */ + + /* Block size in bytes for all blocks other than Block0 - BCH */ + u32 ecc_size; + u32 ecc_level; /* Ecc level for Block 0 - BCH */ + u32 meta_size; /* Metadata size - BCH */ + /* Number of blocks per page for ROM use - BCH */ + u32 nr_blocks; + u32 ecc_type_sdk; /* Type of ECC, can be one of BCH-0-20 */ + u32 ecc_nr_sdk; /* Number of bytes for Block0 - BCH */ + /* Block size in bytes for all blocks other than Block0 - BCH */ + u32 ecc_size_sdk; + u32 ecc_level_sdk; /* Ecc level for Block 0 - BCH */ + /* Number of blocks per page for SDK use - BCH */ + u32 nr_blocks_sdk; + u32 meta_size_sdk; /* Metadata size - BCH */ + u32 erase_th; /* To set into BCH_MODE register */ + + /* + * 0: normal boot + * 1: to load patch starting next to FCB + */ + u32 bootpatch; + u32 patch_size; /* Size of patch in sectors */ + u32 fw1_start; /* Firmware image starts on this sector */ + u32 fw2_start; /* Secondary FW Image starting Sector */ + u32 fw1_pages; /* Number of sectors in firmware image */ + u32 fw2_pages; /* Number of sector in secondary FW image */ + u32 dbbt_start; /* Page address where dbbt search area begins */ + + /* + * Byte in page data that have manufacturer marked bad block marker, + * this will be swapped with metadata[0] to complete page data. + */ + u32 bb_byte; + + /* + * For BCH ECC sizes other than 8 and 16 the bad block marker does not + * start at 0th bit of bb_byte. This field is used to get to + * the start bit of bad block marker byte with in bb_byte + */ + u32 bb_start_bit; + + /* + * FCB value that gives byte offset for + * bad block marker on physical NAND page + */ + u32 phy_offset; + u32 bchtype; + + u32 readlatency; + u32 predelay; + u32 cedelay; + u32 postdelay; + u32 cmdaddpause; + u32 datapause; + u32 tmspeed; + u32 busytimeout; + + /* the flag to enable (1)/disable(0) bi swap */ + u32 disbbm; + + /* The swap position of main area in spare area */ + u32 spare_offset; +}; + +#endif /* _IMX_NAND_BCB_H_ */ diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index ec09ef240f..5dd286f9a7 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -71,6 +71,17 @@ config CMD_HDMIDETECT This enables the 'hdmidet' command which detects if an HDMI monitor is connected. +config CMD_NANDBCB + bool "i.MX6 NAND Boot Control Block(BCB) command" + depends on NAND && CMD_MTDPARTS + default y if ARCH_MX6 && NAND_MXS + help + Unlike normal 'nand write/erase' commands, this command update + Boot Control Block(BCB) for i.MX6 platform NAND IP's. + + This is similar to kobs-ng, which is used in Linux as separate + rootfs package. + config NXP_BOARD_REVISION bool "Read NXP board revision from fuses" depends on ARCH_MX6 || ARCH_MX7 diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index c46984994a..96f0b89fd1 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -59,6 +59,7 @@ ifneq ($(CONFIG_SPL_BUILD),y) obj-$(CONFIG_CMD_BMODE) += cmd_bmode.o obj-$(CONFIG_CMD_HDMIDETECT) += cmd_hdmidet.o obj-$(CONFIG_CMD_DEKBLOB) += cmd_dek.o +obj-$(CONFIG_CMD_NANDBCB) += cmd_nandbcb.o endif PLUGIN = board/$(BOARDDIR)/plugin diff --git a/arch/arm/mach-imx/cmd_nandbcb.c b/arch/arm/mach-imx/cmd_nandbcb.c new file mode 100644 index 0000000000..065b814b2e --- /dev/null +++ b/arch/arm/mach-imx/cmd_nandbcb.c @@ -0,0 +1,369 @@ +/* + * i.MX6 nand boot control block(bcb). + * + * Based on the common/imx-bbu-nand-fcb.c from barebox and imx kobs-ng + * + * Copyright (C) 2017 Jagan Teki + * Copyright (C) 2016 Sergey Kubushyn + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +#define BF_VAL(v, bf) (((v) & bf##_MASK) >> bf##_OFFSET) +#define GETBIT(v, n) (((v) >> (n)) & 0x1) + +static u8 calculate_parity_13_8(u8 d) +{ + u8 p = 0; + + p |= (GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 3) ^ GETBIT(d, 2)) << 0; + p |= (GETBIT(d, 7) ^ GETBIT(d, 5) ^ GETBIT(d, 4) ^ GETBIT(d, 2) ^ + GETBIT(d, 1)) << 1; + p |= (GETBIT(d, 7) ^ GETBIT(d, 6) ^ GETBIT(d, 5) ^ GETBIT(d, 1) ^ + GETBIT(d, 0)) << 2; + p |= (GETBIT(d, 7) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 0)) << 3; + p |= (GETBIT(d, 6) ^ GETBIT(d, 4) ^ GETBIT(d, 3) ^ GETBIT(d, 2) ^ + GETBIT(d, 1) ^ GETBIT(d, 0)) << 4; + + return p; +} + +static void encode_hamming_13_8(void *_src, void *_ecc, size_t size) +{ + int i; + u8 *src = _src; + u8 *ecc = _ecc; + + for (i = 0; i < size; i++) + ecc[i] = calculate_parity_13_8(src[i]); +} + +static u32 calc_chksum(void *buf, size_t size) +{ + u32 chksum = 0; + u8 *bp = buf; + size_t i; + + for (i = 0; i < size; i++) + chksum += bp[i]; + + return ~chksum; +} + +static void fill_fcb(struct fcb_block *fcb, struct mtd_info *mtd) +{ + struct nand_chip *chip = mtd_to_nand(mtd); + struct mxs_nand_info *nand_info = nand_get_controller_data(chip); + + fcb->fingerprint = FCB_FINGERPRINT; + fcb->version = FCB_VERSION_1; + fcb->pagesize = mtd->writesize; + fcb->oob_pagesize = mtd->writesize + mtd->oobsize; + fcb->sectors = mtd->erasesize / mtd->writesize; + + /* Divide ECC strength by two and save the value into FCB structure. */ + fcb->ecc_level = nand_info->bch_geometry.ecc_strength >> 1; + + fcb->ecc_type = fcb->ecc_level; + + /* Also hardcoded in kobs-ng */ + fcb->ecc_nr = 0x00000200; + fcb->ecc_size = 0x00000200; + fcb->datasetup = 80; + fcb->datahold = 60; + fcb->addr_setup = 25; + fcb->dsample_time = 6; + fcb->meta_size = 10; + + /* DBBT search area starts at second page on first block */ + fcb->dbbt_start = 1; + + fcb->bb_byte = nand_info->bch_geometry.block_mark_byte_offset; + fcb->bb_start_bit = nand_info->bch_geometry.block_mark_bit_offset; + + fcb->phy_offset = mtd->writesize; + + fcb->nr_blocks = mtd->writesize / fcb->ecc_nr - 1; + + fcb->checksum = calc_chksum((void *)fcb + 4, sizeof(*fcb) - 4); +} + +static int dbbt_fill_data(struct mtd_info *mtd, void *buf, int num_blocks) +{ + int n, n_bad_blocks = 0; + u32 *bb = buf + 0x8; + u32 *n_bad_blocksp = buf + 0x4; + + for (n = 0; n < num_blocks; n++) { + loff_t offset = n * mtd->erasesize; + if (mtd_block_isbad(mtd, offset)) { + n_bad_blocks++; + *bb = n; + bb++; + } + } + + *n_bad_blocksp = n_bad_blocks; + + return n_bad_blocks; +} + +static int nandbcb_update(struct mtd_info *mtd, loff_t off, size_t size, + size_t maxsize, const u_char *buf) +{ + nand_erase_options_t opts; + struct fcb_block *fcb; + struct dbbt_block *dbbt; + loff_t fw1_off; + void *fwbuf, *fcb_raw_page, *dbbt_page, *dbbt_data_page; + int nr_blks, nr_blks_fcb, fw1_blk; + size_t fwsize, dummy; + int i, ret; + + /* erase */ + memset(&opts, 0, sizeof(opts)); + opts.offset = off; + opts.length = maxsize - 1; + ret = nand_erase_opts(mtd, &opts); + if (ret) { + printf("%s: erase failed (ret = %d)\n", __func__, ret); + return ret; + } + + /* + * Reference documentation from i.MX6DQRM section 8.5.2.2 + * + * Nand Boot Control Block(BCB) contains two data structures, + * - Firmware Configuration Block(FCB) + * - Discovered Bad Block Table(DBBT) + * + * FCB contains, + * - nand timings + * - DBBT search page address, + * - start page address of primary firmware + * - start page address of secondary firmware + * + * setup fcb: + * - number of blocks = mtd partition size / mtd erasesize + * - two firmware blocks, primary and secondary + * - first 4 block for FCB/DBBT + * - rest split in half for primary and secondary firmware + * - same firmware will write two times + */ + nr_blks_fcb = 2; + nr_blks = maxsize / mtd->erasesize; + fw1_blk = nr_blks_fcb; + + /* write fw */ + fwsize = ALIGN(size + FLASH_OFFSET_STANDARD + mtd->writesize, + mtd->writesize); + fwbuf = kzalloc(fwsize, GFP_KERNEL); + if (!fwbuf) { + debug("failed to allocate fwbuf\n"); + ret = -ENOMEM; + goto err; + } + + memcpy(fwbuf + FLASH_OFFSET_STANDARD, buf, size); + fw1_off = fw1_blk * mtd->erasesize; + ret = nand_write_skip_bad(mtd, fw1_off, &fwsize, NULL, maxsize, + (u_char *)fwbuf, WITH_WR_VERIFY); + printf("NAND fw write: 0x%llx offset, 0x%x bytes written: %s\n", + fw1_off, fwsize, ret ? "ERROR" : "OK"); + if (ret) + goto fwbuf_err; + + /* fill fcb */ + fcb = kzalloc(sizeof(*fcb), GFP_KERNEL); + if (!fcb) { + debug("failed to allocate fcb\n"); + ret = -ENOMEM; + goto fwbuf_err; + } + + fcb->fw1_start = (fw1_blk * mtd->erasesize) / mtd->writesize; + fcb->fw1_pages = size / mtd->writesize + 1; + fill_fcb(fcb, mtd); + + /* fill dbbt */ + dbbt_page = kzalloc(mtd->writesize, GFP_KERNEL); + if (!dbbt_page) { + debug("failed to allocate dbbt_page\n"); + ret = -ENOMEM; + goto fcb_err; + } + + dbbt_data_page = kzalloc(mtd->writesize, GFP_KERNEL); + if (!dbbt_data_page) { + debug("failed to allocate dbbt_data_page\n"); + ret = -ENOMEM; + goto dbbt_page_err; + } + + dbbt = dbbt_page; + dbbt->checksum = 0; + dbbt->fingerprint = DBBT_FINGERPRINT2; + dbbt->version = DBBT_VERSION_1; + ret = dbbt_fill_data(mtd, dbbt_data_page, nr_blks); + if (ret < 0) + goto dbbt_data_page_err; + else if (ret > 0) + dbbt->dbbtpages = 1; + + /* write fcb/dbbt */ + fcb_raw_page = kzalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); + if (!fcb_raw_page) { + debug("failed to allocate fcb_raw_page\n"); + ret = -ENOMEM; + goto dbbt_data_page_err; + } + + memcpy(fcb_raw_page + 12, fcb, sizeof(struct fcb_block)); + encode_hamming_13_8(fcb_raw_page + 12, fcb_raw_page + 12 + 512, 512); + /* + * Set the first and second byte of OOB data to 0xFF, not 0x00. These + * bytes are used as the Manufacturers Bad Block Marker (MBBM). Since + * the FCB is mostly written to the first page in a block, a scan for + * factory bad blocks will detect these blocks as bad, e.g. when + * function nand_scan_bbt() is executed to build a new bad block table. + */ + memset(fcb_raw_page + mtd->writesize, 0xFF, 2); + + for (i = 0; i < nr_blks_fcb; i++) { + if (mtd_block_isbad(mtd, off)) { + printf("Block %d is bad, skipped\n", i); + continue; + } + + /* raw write */ + mtd_oob_ops_t ops = { + .datbuf = (u8 *)fcb_raw_page, + .oobbuf = ((u8 *)fcb_raw_page) + mtd->writesize, + .len = mtd->writesize, + .ooblen = mtd->oobsize, + .mode = MTD_OPS_RAW + }; + + ret = mtd_write_oob(mtd, mtd->erasesize * i, &ops); + if (ret) + goto fcb_raw_page_err; + debug("NAND fcb write: 0x%x offset, 0x%x bytes written: %s\n", + mtd->erasesize * i, ops.len, ret ? "ERROR" : "OK"); + + ret = mtd_write(mtd, mtd->erasesize * i + mtd->writesize, + mtd->writesize, &dummy, dbbt_page); + if (ret) + goto fcb_raw_page_err; + debug("NAND dbbt write: 0x%x offset, 0x%x bytes written: %s\n", + mtd->erasesize * i + mtd->writesize, dummy, + ret ? "ERROR" : "OK"); + + /* dbbtpages == 0 if no bad blocks */ + if (dbbt->dbbtpages > 0) { + loff_t to = (mtd->erasesize * i + mtd->writesize * 5); + + ret = mtd_write(mtd, to, mtd->writesize, &dummy, + dbbt_data_page); + if (ret) + goto fcb_raw_page_err; + } + } + +fcb_raw_page_err: + kfree(fcb_raw_page); +dbbt_data_page_err: + kfree(dbbt_data_page); +dbbt_page_err: + kfree(dbbt_page); +fcb_err: + kfree(fcb); +fwbuf_err: + kfree(fwbuf); +err: + return ret; +} + +static int do_nandbcb_update(int argc, char * const argv[]) +{ + struct mtd_info *mtd; + loff_t addr, offset, size, maxsize; + char *endp; + u_char *buf; + int dev; + int ret; + + if (argc != 4) + return CMD_RET_USAGE; + + dev = nand_curr_device; + if (dev < 0) { + printf("failed to get nand_curr_device, run nand device"); + return CMD_RET_FAILURE; + } + + addr = simple_strtoul(argv[1], &endp, 16); + if (*argv[1] == 0 || *endp != 0) + return CMD_RET_FAILURE; + + mtd = get_nand_dev_by_index(dev); + if (mtd_arg_off_size(argc - 2, argv + 2, &dev, &offset, &size, + &maxsize, MTD_DEV_TYPE_NAND, mtd->size)) + return CMD_RET_FAILURE; + + buf = map_physmem(addr, size, MAP_WRBACK); + if (!buf) { + puts("failed to map physical memory\n"); + return CMD_RET_FAILURE; + } + + ret = nandbcb_update(mtd, offset, size, maxsize, buf); + + return ret == 0 ? CMD_RET_SUCCESS : CMD_RET_FAILURE; +} + +static int do_nandbcb(cmd_tbl_t *cmdtp, int flag, int argc, + char * const argv[]) +{ + const char *cmd; + int ret = 0; + + if (argc < 5) + goto usage; + + cmd = argv[1]; + --argc; + ++argv; + + if (strcmp(cmd, "update") == 0) { + ret = do_nandbcb_update(argc, argv); + goto done; + } + +done: + if (ret != -1) + return ret; +usage: + return CMD_RET_USAGE; +} + +static char nandbcb_help_text[] = + "update addr off|partition len - update 'len' bytes starting at\n" + " 'off|part' to memory address 'addr', skipping bad blocks"; + +U_BOOT_CMD(nandbcb, 5, 1, do_nandbcb, + "i.MX6 Nand BCB", + nandbcb_help_text +); diff --git a/drivers/mtd/nand/raw/mxs_nand.c b/drivers/mtd/nand/raw/mxs_nand.c index b93d77a395..a41b9620d0 100644 --- a/drivers/mtd/nand/raw/mxs_nand.c +++ b/drivers/mtd/nand/raw/mxs_nand.c @@ -25,7 +25,7 @@ #include #include #include -#include "mxs_nand.h" +#include #define MXS_NAND_DMA_DESCRIPTOR_COUNT 4 diff --git a/drivers/mtd/nand/raw/mxs_nand_dt.c b/drivers/mtd/nand/raw/mxs_nand_dt.c index 44dec5dedf..8ad7d618c6 100644 --- a/drivers/mtd/nand/raw/mxs_nand_dt.c +++ b/drivers/mtd/nand/raw/mxs_nand_dt.c @@ -15,7 +15,7 @@ #include #include -#include "mxs_nand.h" +#include struct mxs_nand_dt_data { unsigned int max_ecc_strength_supported; diff --git a/drivers/mtd/nand/raw/mxs_nand_spl.c b/drivers/mtd/nand/raw/mxs_nand_spl.c index ee7d9cb957..975a91a37d 100644 --- a/drivers/mtd/nand/raw/mxs_nand_spl.c +++ b/drivers/mtd/nand/raw/mxs_nand_spl.c @@ -6,7 +6,7 @@ #include #include #include -#include "mxs_nand.h" +#include static struct mtd_info *mtd; static struct nand_chip nand_chip; diff --git a/drivers/mtd/nand/raw/mxs_nand.h b/include/mxs_nand.h similarity index 100% rename from drivers/mtd/nand/raw/mxs_nand.h rename to include/mxs_nand.h From patchwork Fri Jun 14 07:35:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 558 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 860CD3F033 for ; Fri, 14 Jun 2019 09:37:38 +0200 (CEST) Received: by mail-pg1-f200.google.com with SMTP id z10sf1277530pgf.15 for ; Fri, 14 Jun 2019 00:37:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560497857; cv=pass; d=google.com; s=arc-20160816; b=elrVPaKTbFw3L2IW6TMsRTLLAU2VhQqcRvZS39p67ufLVIGdf2PMl/xuWGdTH0hxbz J0bhDV7/tsIFa5HWvbERPdFn0KbM9k8EzruWw8TjnhYi1l3+T4u67y9aMHe+lP1uSOJM myQeMbyuW3Dv2hU9YGLLwfOKlboTHCoE5g/EZ87tMtDbEoIDgInrTvGKyf/1wTszhZr8 ISxsViqpwDYox4nLgTjx4BcMckY/IMXqqpuHsfIqjISMtIh8eYC7XobjHQzVPMJIpL6F PuBN4pljMd8UKC1diM+YZOyvyzoeWtBzgTmclA04Y8EaoP7LlAJ6zJqQBZADyb87cPDF DqHg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=SPlF+wQtvpR+PwQjQBjb3xDeTBYxZPONd92aKb5inCw=; b=IxlARhj6lrYeeDpKpQkN45KDlWgvG2lUq5msH5QYKStjWuCgVlAcBqrOm2SBGzG+Rx FoJiLXMhz9XT14wV6jPZvtyoGcn6muFY3I/z4Yu2mxYUeBmLHcc/BtGaI6zYmQyGZyNv R5FE71F3QqBop3Bxcpl2Ps0H6peqfI4h9SoP3I83D/zdNOJ7/h9Yqx5zR4CgdG8zd3Xd QvKUH8fdtcwurkksBHxPHE+TG7Ycq8JiCkZWJNW9LJfIQRk+gflkzwKjV8fSZW2tcCwO E7G2dEd8haWsKGwNAkBpZK9yJZjNlIjs2k/aYdS0UxrQnQmkBXdXFK0Gu8zdGmNtzuQN 5caA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Bfr+nITd; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=SPlF+wQtvpR+PwQjQBjb3xDeTBYxZPONd92aKb5inCw=; b=eDgpAqg/ecOQacRxh3THpXTedsMYQO/tF64zMKtf3fapyuud1PomqU2ZZ4HPUeHNFN A9y6KkJer6V2nva9IkUeMKsDhDOMBfLfyQNCDPc9cXxE1X7aJJiHsQC1e9wDDrft3Jet HS7I7PjJv2cObfJTwTRnx2UtpqaA4HYvUhO+g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=SPlF+wQtvpR+PwQjQBjb3xDeTBYxZPONd92aKb5inCw=; b=dw+hGm/WB8UjclI2mgnVLvn8QEMmJ546hq50kMSGZs6ifzCD/monrsFSucEfSH/jVW VEyRztDMUPFrY+/XtQr2SpoM/uxIQiKTVHiMU+qUUAjvpIN3Fm0DcXjk8i1Xe/Hlk0lO 0S/KzH+MJ6aBHHZ9t0a/5NuRRH+5ffwSVE9/V9+4W570EOJPkApspiRLjlCUkJBHtHY8 gknAY0S9shB3+rA+FwGjBVuG793J+fxf61kIphcVJp4JGKnlfPsWZOfarEu1XxjrXgxk 8J3FfhdoLQZWenBwbBxvgD8TGgzre2oSlfmf+z+RLBwqqy96lhmitNXD3w3q8/J+jT71 bHyA== X-Gm-Message-State: APjAAAWhb7A0YFo2Rb61YjYlXJ4SqQRNp9PdwTy5tGbHd6WxsbdDe0Go uI5PoX3zBH8B691VROpsz8jt1sjz X-Google-Smtp-Source: APXvYqzg9WBf5m5tVSZTSv71MZkygTB9MnVlZAnFsQcvvSlnfIgRRD/iUGX0+1N+yg41K4gyh2FWxQ== X-Received: by 2002:a17:902:29a7:: with SMTP id h36mr40194410plb.158.1560497856880; Fri, 14 Jun 2019 00:37:36 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:90a:a584:: with SMTP id b4ls2065454pjq.0.canary-gmail; Fri, 14 Jun 2019 00:37:36 -0700 (PDT) X-Received: by 2002:a17:90a:650c:: with SMTP id i12mr9787510pjj.44.1560497856526; Fri, 14 Jun 2019 00:37:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560497856; cv=none; d=google.com; s=arc-20160816; b=OkEoK0KxjNmHnGV0fUzSule8Uc0rVq5LYVVEPJobhGdPlARfpRnJvRlZ5cWMBrL/GN sJBPm30LDpcIZlUI0JDs3aQTGtd2d2IkPnZa/4WaTaUc1n9UBsn29WuOu/ri0tXGGqzF nPkpYDSEdra2Z51CtiiZytxO4zuldnp0dJCpdd/mE/C+GiMePecvNXX5iy2bkPLdXjk7 AW0HSmxydzaQ3zm1MRfo9o8+52va9anMy35e9dEw369fWErWR6GnW82uoUfr1NORy5D8 mGADG7Sy/hILnXbIXb+l6PrSNph+4EN/hyI7bgS9wEy6MevmCEjcWxfNV6TvzgHGssA6 j2Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=c+zYlXki46zCqY3AFhSZxwJIMfJq3ZZaYoo+5+ukRuE=; b=Om/JjL7vUCEVkrsavD+bVe8zlzx93wcINtosHr/pFjSahTnSVOEDJyYupt+ib/tmQa g4xbDt/x/JNFvDVCAh2/AszvZubwV2VAWmmWsv+JqX0Aqj6FEGjk73GnSn4dk1Prg5nt 9JTRTkAMBtcZ0oedHgS2Hn76TF7ZmKhmSognwAmvZn5wUG8iIHClMPyBlGQ67rXwAWIx fxzFJHFOFsIusSqOp0k6Bf2fW5D36LuU1ezzBSp2tmcVOy6SnP886OpPp393JDU8a7u9 SVXeWA2oAjdUdAyIwCOqXztiTD+ATQ5Dasn3g2unBScQc5fuQH3vT4sCvMPHZlxVVrKY PN4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Bfr+nITd; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r8sor2181789pgk.75.2019.06.14.00.37.36 for (Google Transport Security); Fri, 14 Jun 2019 00:37:36 -0700 (PDT) Received-SPF: pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a65:6284:: with SMTP id f4mr34882340pgv.14.1560497856183; Fri, 14 Jun 2019 00:37:36 -0700 (PDT) Received: from localhost.localdomain ([183.82.230.16]) by smtp.googlemail.com with ESMTPSA id c14sm887609pgm.40.2019.06.14.00.37.32 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 00:37:35 -0700 (PDT) From: Shyam Saini To: sbabic@denx.de Cc: u-boot@lists.denx.de, ksi@koi8.net, stefan.agner@toradex.com, festevam@gmail.com, jagan@amarulasolutions.com, michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, uboot-imx@nxp.com, Shyam Saini Subject: [PATCH 2/3] configs: icorem6: Enable nandbcb command Date: Fri, 14 Jun 2019 13:05:34 +0530 Message-Id: <20190614073535.12502-2-shyam.saini@amarulasolutions.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614073535.12502-1-shyam.saini@amarulasolutions.com> References: <20190614073535.12502-1-shyam.saini@amarulasolutions.com> X-Original-Sender: shyam.saini@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Bfr+nITd; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , This also enables mtd configs which are required by nandbcb command. This command would be used to configure boot control block(BCB) while writing spl image on nand device. Signed-off-by: Shyam Saini --- configs/imx6qdl_icore_mmc_defconfig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/configs/imx6qdl_icore_mmc_defconfig b/configs/imx6qdl_icore_mmc_defconfig index b65979967a..620d49f954 100644 --- a/configs/imx6qdl_icore_mmc_defconfig +++ b/configs/imx6qdl_icore_mmc_defconfig @@ -15,6 +15,7 @@ CONFIG_DEBUG_UART_BASE=0x021f0000 CONFIG_DEBUG_UART_CLOCK=24000000 CONFIG_SPL_LIBDISK_SUPPORT=y # CONFIG_CMD_BMODE is not set +CONFIG_CMD_NANDBCB=y CONFIG_DEBUG_UART=y CONFIG_FIT=y CONFIG_FIT_SIGNATURE=y @@ -58,6 +59,9 @@ CONFIG_SYS_I2C_MXC=y CONFIG_FSL_ESDHC=y CONFIG_NAND=y CONFIG_NAND_MXS=y +CONFIG_CMD_MTDPARTS=y +CONFIG_MTDIDS_DEFAULT="nand0=gpmi-nand" +CONFIG_MTDPARTS_DEFAULT="mtdparts=gpmi-nand:2m(spl),2m(uboot),1m(env),8m(kernel),1m(dtb),-(rootfs)" CONFIG_PHYLIB=y CONFIG_PHY_SMSC=y CONFIG_FEC_MXC=y From patchwork Fri Jun 14 07:35:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Saini X-Patchwork-Id: 559 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-pg1-f200.google.com (mail-pg1-f200.google.com [209.85.215.200]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 8CCF93F033 for ; Fri, 14 Jun 2019 09:37:43 +0200 (CEST) Received: by mail-pg1-f200.google.com with SMTP id c4sf1267372pgm.21 for ; Fri, 14 Jun 2019 00:37:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1560497862; cv=pass; d=google.com; s=arc-20160816; b=nuJtvq6zunChBzRPxVuP+dv3R67IoREFvwdQ+RF5wn69kAUIZaxlH3Nd0qfeSBW+LH KiayR2iTqJVlK6CXclIUPwyZ+i0gj4EGLah3Rh7sIKGYIWcP1PIXJA7YMn6a3IJFa24L wdvpr5C2CvRzYF8v9CSMfCJ5xj+GJ3h5fZp9Fu+fvt5SBf2mRPAJv8+7NUiNqN7qeVIM BObsCIC4aQ4qKqFnN51XTTi85Jrcq9AP6QjsR9VjZiszkrC2z8ecNEDsp/T+9FbRW5Q3 2DxrxWusGzyRnZAfTu2vSJqd+Wefg5l4Nn3VgOBdApsGbOkEpjdF1HqEEHTZcRWU0bGY Fn6w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:references:in-reply-to:message-id:date :subject:cc:to:from:mime-version:dkim-signature; bh=EmSoC8lveNN5qYIWVnBFDBGCQGhoAuytr/Dzwfe+feo=; b=C/iL+Fss1fONmN0vKBYymscgBr5JZauGBY3oEWccMqpYhoWkk6ehEqXZrKpsyh6RDR +8s0ZwzQSJSjE6EbrT4yZum63bM6yqaK6vfBbF0dlUishWZ4FqIgZyRDTtkuFNuUN4fw pFEbI0E3Ln6jy4aghj95h2G/1c3doypVPyynJZZ7LIl7rEbPIIHsBGL1TqsBsEkJTcTy JyDsqREYenPUCLFXFW47rUGplERhCKiUlsbywnA+E/MzWooLmn5M5Di/8BVFMs3Kqi3d QTdPXDptbNJefHfCZ2iddo4CG1KMVgL1E5OZ0b0Z/AszHKtNGM7Ze0oBx47lDI9nkL2a nNYA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=g3VDvbwo; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=EmSoC8lveNN5qYIWVnBFDBGCQGhoAuytr/Dzwfe+feo=; b=KHpCCoz4BJw22VKAQAszCo6n+z4u3z1RppsSgFqIAQ+sbLuqwj5uRV5JesrhbxLvx5 89wEcCRVkr+71ng6NqL7Dje88boJgG4KuyUR6pq4Knv2FVCoyEDG0h7E6CpEQjD35RnV RE8ztHBxogN4P1Upfo/fOudEfzdf8K2h5cso4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:to:cc:subject:date:message-id :in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-unsubscribe; bh=EmSoC8lveNN5qYIWVnBFDBGCQGhoAuytr/Dzwfe+feo=; b=mkwgSb+cwvyJqBKgnJi+A456h7aqr6wglMzassAYGKW8YzxypTDIkGsoLjqODuQz8+ 5fmvxw3AS/dY0P7o9ZOkBq+VHVEefRy3lhFNRZKVRj7NGt5hEvT2Gaz6+WCQcv9V4dDL 8QtQJM3gCcqb1Jdue16gDbOkRyqMEMRRoVSrErGsI6heLRmXkKP5dP7EikbF8ygcjrJ4 rlBMQUXB0/FP129Au2j4/4utrI+weFbbKYDMswrcXK0HTqqsaCeO7HSTR2gZ3yC/U+bR vqF3v0Nzn2Saxi+FhfZARGht8gdB+a3T0h3ccV+B+NKgBUfRI4zGwoJGn4yniLK8I5tc y7MA== X-Gm-Message-State: APjAAAV+gwrCLrohsn7G3R7PZajlcFeQkRLkncB07EawvviXACaG9dKW 6FXm+x65INHtA/EdAjW7C3nOw0qv X-Google-Smtp-Source: APXvYqzUZUIRCf7YesnO0nZB3v8Pl35MrOAJ69Y2JxM4R/zTprofsJK1Kb4I7q8cNWJranUWj6b9vg== X-Received: by 2002:a63:a84c:: with SMTP id i12mr34869931pgp.115.1560497861469; Fri, 14 Jun 2019 00:37:41 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a17:902:bd8b:: with SMTP id q11ls2020741pls.4.gmail; Fri, 14 Jun 2019 00:37:41 -0700 (PDT) X-Received: by 2002:a17:90a:3544:: with SMTP id q62mr8801784pjb.53.1560497861018; Fri, 14 Jun 2019 00:37:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560497861; cv=none; d=google.com; s=arc-20160816; b=MpY9WlgVgrgne6EGaed5qEvTvbPuNaejYDv1nMKip4EBTOYCNmzqxNUTkS5N6UFMOE 3p8OaRCp3ufndsMsP9ymU9YOanWgx+KyNpQnUFaWs+PCiU65L+IGH2f42wFF67umTkBu ji6bQVDXrxVq0PO8m6jOO7NYnbEGOJMHRLWyGoAqRaIMgL/fMtHLykt97OEa8yHLm7WR IcicdHxquIvGdo5RiSJ/0xtylpO9nlIrpSTn3t9oDSbEZ95B8VwnMVYDLvmloJmaOeaa Jubb8/c91rAHiIHKWyi3Xe84sWv0S1Ggxo/GCl9mdwz7FNprDpAupD95Dod+Z/lmZVge hLXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C1FOLgewwrxSe2tMRN8cITeMNwRmrSSodIfL+Et9fn4=; b=sRTyt11bk0PkcPKGcvOMWBnTpiMw1dOuPpm2EPbPfv8yM5GgQLNSj/R+AF77mqTmK2 LXdSjKLawlx6bL+4eBcVG+Z/FRAMSCK1uHBOcKBe+hlvkSGgkgGAf0xBVclKMd9uEZ7t jFGsXullVAp8DSp2TBMS938BMS2A01JXf2jiTKGjtjwvRGkVNBkMhqSGtu9GidjqD8xw YgFupupduGipJW/K2EFYBLjH8ZwVJxVjaF67yctZuL7g8+x7lRy0KS2HbklH12KfoTIB IDPlzGkmzFv784nkfJLWxEIMLMmchQaXv9YU4hX+0wo+rZgjpW7YXUGhoyJJ4PQ/zlMr vJhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=g3VDvbwo; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id w2sor2626634ply.72.2019.06.14.00.37.40 for (Google Transport Security); Fri, 14 Jun 2019 00:37:41 -0700 (PDT) Received-SPF: pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; X-Received: by 2002:a17:902:d916:: with SMTP id c22mr67567722plz.195.1560497860698; Fri, 14 Jun 2019 00:37:40 -0700 (PDT) Received: from localhost.localdomain ([183.82.230.16]) by smtp.googlemail.com with ESMTPSA id c14sm887609pgm.40.2019.06.14.00.37.36 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Fri, 14 Jun 2019 00:37:40 -0700 (PDT) From: Shyam Saini To: sbabic@denx.de Cc: u-boot@lists.denx.de, ksi@koi8.net, stefan.agner@toradex.com, festevam@gmail.com, jagan@amarulasolutions.com, michael@amarulasolutions.com, linux-amarula@amarulasolutions.com, uboot-imx@nxp.com, Shyam Saini Subject: [PATCH 3/3] doc: imx: Add documentation for nandbcb command Date: Fri, 14 Jun 2019 13:05:35 +0530 Message-Id: <20190614073535.12502-3-shyam.saini@amarulasolutions.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190614073535.12502-1-shyam.saini@amarulasolutions.com> References: <20190614073535.12502-1-shyam.saini@amarulasolutions.com> X-Original-Sender: shyam.saini@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=g3VDvbwo; spf=pass (google.com: domain of shyam.saini@amarulasolutions.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=shyam.saini@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Signed-off-by: Shyam Saini --- doc/imx/common/imx6.txt | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/doc/imx/common/imx6.txt b/doc/imx/common/imx6.txt index eab88353f6..0b5061128c 100644 --- a/doc/imx/common/imx6.txt +++ b/doc/imx/common/imx6.txt @@ -88,3 +88,77 @@ Reading bank 4: Word 0x00000002: 9f027772 00000004 +NAND Boot on i.MX6 with SPL support +-------------------------------------- + +Writing/updating boot image in nand device is not straight forward in +i.MX6 platform and it requires boot control block(BCB) to be configured. + +BCB contains two data structures, Firmware Configuration Block(FCB) and +Discovered Bad Block Table(DBBT). FCB has nand timings, DBBT search area, +and firmware. See IMX6DQRM Section 8.5.2.2 +for more information. + +We can't use 'nand write' command to write SPL/firmware image directly +like other platforms does. So we need special setup to write BCB block +as per IMX6QDL reference manual 'nandbcb update' command do that job. + +for nand boot, up on reset bootrom look for FCB structure in +first block's if FCB found the nand timings are loaded for +further reads. once FCB read done, DTTB will be loaded and +finally firmware will be loaded which is boot image. + +cmd_nandbcb will create FCB these structures +by taking mtd partition as an example. +- initial code will erase entire partition +- followed by FCB setup, like first 2 blocks for FCB/DBBT write, + and next block for FW1/SPL +- write firmware at FW1 block and +- finally write fcb/dttb in first 2 block. + +Typical NAND BCB layout: +======================= + + no.of blocks = partition size / erasesize + no.of fcb/dbbt blocks = 2 + FW1 offset = no.of fcb/dbbt + +block 0 1 2 + ------------------------------- + |FCB/DBBT 0|FCB/DBBT 1| FW 1 | + -------------------------------- + +On summary, nandbcb update will +- erase the entire partition +- create BCB by creating 2 FCB/BDDT block followed by + 1 FW blocks based on partition size and erasesize. +- fill FCB/DBBT structures +- write FW/SPL in FW1 +- write FCB/DBBT in first 2 blocks + +step-1: write SPL + +icorem6qdl> ext4load mmc 0:1 $loadaddr SPL +39936 bytes read in 10 ms (3.8 MiB/s) + +icorem6qdl> nandbcb update $loadaddr spl $filesize +device 0 offset 0x0, size 0x9c00 +Erasing at 0x1c0000 -- 100% complete. +NAND fw write: 0x80000 offset, 0xb000 bytes written: OK + +step-2: write u-boot-dtb.img + +icorem6qdl> nand erase.part uboot + +NAND erase.part: device 0 offset 0x200000, size 0x200000 +Erasing at 0x3c0000 -- 100% complete. +OK + +icorem6qdl> ext4load mmc 0:1 $loadaddr u-boot-dtb.img +589094 bytes read in 37 ms (15.2 MiB/s) + +icorem6qdl> nand write ${loadaddr} uboot ${filesize} + +NAND write: device 0 offset 0x200000, size 0x8fd26 + 589094 bytes written: OK +icorem6qdl>