From 00b83cc85a531f215c80ad5b9d9804285d2304c0 Mon Sep 17 00:00:00 2001 From: Jonas Albrecht Date: Fri, 1 Mar 2019 22:48:02 +0000 Subject: [PATCH] modifie the 4052-NAND-add-easybox904-bbt.patch This patch was breaking all other devices with NAND-flash in past, because the different BBT-patern-matching will disable/enable by a define makro only (#define CUSTOMIZED_BBT 1) Now it ask first for the customized-samsung-K9F4G08U0x field from devicetree: ... nand@1 { customized-samsung-K9F4G08U0x; ... Signed-off-by: Jonas Albrecht --- .../arch/mips/boot/dts/VGV952CJW33-E-IR.dts | 1 + .../4052-NAND-add-easybox904-bbt.patch | 109 ++++++++++++++---- 2 files changed, 87 insertions(+), 23 deletions(-) diff --git a/target/linux/lantiq/files-4.14/arch/mips/boot/dts/VGV952CJW33-E-IR.dts b/target/linux/lantiq/files-4.14/arch/mips/boot/dts/VGV952CJW33-E-IR.dts index d619465dab9..a73ce20df66 100644 --- a/target/linux/lantiq/files-4.14/arch/mips/boot/dts/VGV952CJW33-E-IR.dts +++ b/target/linux/lantiq/files-4.14/arch/mips/boot/dts/VGV952CJW33-E-IR.dts @@ -253,6 +253,7 @@ lantiq,cs = <1>; // Seems to be needed (EASY80920NAND.dts) nand-on-flash-bbt; + customized-samsung-K9F4G08U0x; partitions { compatible = "fixed-partitions"; diff --git a/target/linux/lantiq/patches-4.14/4052-NAND-add-easybox904-bbt.patch b/target/linux/lantiq/patches-4.14/4052-NAND-add-easybox904-bbt.patch index 4e9e9d16ecb..b83d6c10b9e 100644 --- a/target/linux/lantiq/patches-4.14/4052-NAND-add-easybox904-bbt.patch +++ b/target/linux/lantiq/patches-4.14/4052-NAND-add-easybox904-bbt.patch @@ -1,68 +1,131 @@ ---- a/drivers/mtd/nand/nand_bbt.c -+++ b/drivers/mtd/nand/nand_bbt.c -@@ -76,6 +76,13 @@ +diff -aurN a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c +--- a/drivers/mtd/nand/nand_bbt.c 2019-02-26 10:04:39.551525839 +0000 ++++ b/drivers/mtd/nand/nand_bbt.c 2019-02-26 10:04:39.697524014 +0000 +@@ -76,6 +76,32 @@ #define BBT_ENTRY_MASK 0x03 #define BBT_ENTRY_SHIFT 2 +#define CUSTOMIZED_BBT 1 -+#if CUSTOMIZED_BBT /*ctc*/ -+ #define BAD_BLK_OOB_MARK_START 4 -+ #define BAD_BLK_OOB_MARK_END 5 -+ #define BAD_BLK_OOB_MARK_PATT 0xFF ++#if CUSTOMIZED_BBT ++ #define BAD_BLK_OOB_MARK_START 4 ++ #define BAD_BLK_OOB_MARK_END 5 ++ #define BAD_BLK_OOB_MARK_PATT 0xFF ++ ++ ++#include ++#include ++ ++static bool of_get_customized_bbt_from_mtd(struct mtd_info *mtd) ++{ ++ struct nand_chip *chip = mtd_to_nand(mtd); ++ struct device_node *dn = nand_get_flash_node(chip); ++ return of_property_read_bool(dn, "customized-samsung-K9F4G08U0x"); ++} ++ ++static bool of_get_customized_bbt_from_chip(struct nand_chip *chip) ++{ ++ struct device_node *dn = nand_get_flash_node(chip); ++ return of_property_read_bool(dn, "customized-samsung-K9F4G08U0x"); ++} ++ +#endif ++ + static int nand_update_bbt(struct mtd_info *mtd, loff_t offs); static inline uint8_t bbt_get_entry(struct nand_chip *chip, int block) -@@ -111,6 +118,10 @@ static int check_pattern_no_oob(uint8_t +@@ -109,8 +135,15 @@ + * Check for a pattern at the given place. Used to search bad block tables and + * good / bad block identifiers. */ - static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) - { -+#if CUSTOMIZED_BBT /*ctc*/ ++#if CUSTOMIZED_BBT ++static int check_pattern(struct mtd_info *mtd, uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) ++{ + int i; + uint8_t *p = buf; ++#else + static int check_pattern(uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) + { +#endif if (td->options & NAND_BBT_NO_OOB) return check_pattern_no_oob(buf, td); -@@ -118,6 +129,13 @@ static int check_pattern(uint8_t *buf, i +@@ -118,6 +151,15 @@ if (memcmp(buf + paglen + td->offs, td->pattern, td->len)) return -1; +#if CUSTOMIZED_BBT /*ctc*/ -+ for (i = BAD_BLK_OOB_MARK_START, p=buf+paglen; i <= BAD_BLK_OOB_MARK_END; i++) { -+ if (p[i] != BAD_BLK_OOB_MARK_PATT) -+ return -1; ++ if (of_get_customized_bbt_from_mtd(mtd)) { ++ for (i = BAD_BLK_OOB_MARK_START, p=buf+paglen; i <= BAD_BLK_OOB_MARK_END; i++) { ++ if (p[i] != BAD_BLK_OOB_MARK_PATT) ++ return -1; ++ } + } +#endif + return 0; } -@@ -1277,8 +1295,13 @@ static int nand_update_bbt(struct mtd_in +@@ -561,7 +603,11 @@ + + /* Read first page */ + scan_read(mtd, buf, offs, mtd->writesize, td); ++#if CUSTOMIZED_BBT ++ if (!check_pattern(mtd, buf, scanlen, mtd->writesize, td)) { ++#else + if (!check_pattern(buf, scanlen, mtd->writesize, td)) { ++#endif + td->pages[i] = actblock << blocktopage; + if (td->options & NAND_BBT_VERSION) { + offs = bbt_get_ver_offs(mtd, td); +@@ -1277,8 +1323,13 @@ static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; /* Generic flash bbt descriptors */ -+#if CUSTOMIZED_BBT /*ctc*/ -+static uint8_t bbt_pattern[] = {'A', 'R', 'C', 'A' }; -+static uint8_t mirror_pattern[] = {'a', 'c', 'r', 'a' }; -+#else ++//#if CUSTOMIZED_BBT /*ctc*/ ++//static uint8_t bbt_pattern[] = {'A', 'R', 'C', 'A' }; ++//static uint8_t mirror_pattern[] = {'a', 'c', 'r', 'a' }; ++//#else static uint8_t bbt_pattern[] = {'B', 'b', 't', '0' }; static uint8_t mirror_pattern[] = {'1', 't', 'b', 'B' }; -+#endif ++//#endif static struct nand_bbt_descr bbt_main_descr = { .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE -@@ -1340,7 +1363,12 @@ static int nand_create_badblock_pattern( +@@ -1340,7 +1391,16 @@ bd = kzalloc(sizeof(*bd), GFP_KERNEL); if (!bd) return -ENOMEM; + +#if CUSTOMIZED_BBT /*ctc*/ -+ bd->options = 0 & BADBLOCK_SCAN_MASK; ++ if (of_get_customized_bbt_from_chip(this)) { ++ bd->options = 0 & BADBLOCK_SCAN_MASK; ++ } else { ++ bd->options = this->bbt_options & BADBLOCK_SCAN_MASK; ++ } +#else bd->options = this->bbt_options & BADBLOCK_SCAN_MASK; +#endif bd->offs = this->badblockpos; bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1; bd->pattern = scan_ff_pattern; +@@ -1360,6 +1420,19 @@ + { + struct nand_chip *this = mtd_to_nand(mtd); + int ret; ++/* change the generic bad / good block scan pattern if of_get_customized_bbt_from_chip(this) true */ ++#if CUSTOMIZED_BBT ++ if(of_get_customized_bbt_from_chip(this)) { ++ bbt_pattern[0] = 'A'; ++ bbt_pattern[1] = 'R'; ++ bbt_pattern[2] = 'C'; ++ bbt_pattern[3] = 'A'; ++ mirror_pattern[0] = 'a'; ++ mirror_pattern[1] = 'c'; ++ mirror_pattern[2] = 'r'; ++ mirror_pattern[3] = 'a'; ++ } ++#endif + + /* Is a flash based bad block table requested? */ + if (this->bbt_options & NAND_BBT_USE_FLASH) {