]> git.sur5r.net Git - u-boot/blobdiff - drivers/mtd/nand/nand_bbt.c
Merge branch 'master' of git://git.denx.de/u-boot-i2c; branch 'master' of git://git...
[u-boot] / drivers / mtd / nand / nand_bbt.c
index c8f28c792b2a3e21c919be0a725aca19fe794a28..00f28a41571a6b0a0bc1454ecd832bf31032722a 100644 (file)
  *
  */
 
-#define __UBOOT__
-#ifndef __UBOOT__
-#include <linux/slab.h>
-#include <linux/types.h>
+#include <common.h>
+#include <malloc.h>
+#include <linux/compat.h>
 #include <linux/mtd/mtd.h>
 #include <linux/mtd/bbm.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/nand_ecc.h>
 #include <linux/bitops.h>
-#include <linux/delay.h>
-#include <linux/vmalloc.h>
-#include <linux/export.h>
 #include <linux/string.h>
-#else
-#include <common.h>
-#include <malloc.h>
-#include <linux/compat.h>
-
- #include <linux/mtd/mtd.h>
- #include <linux/mtd/bbm.h>
- #include <linux/mtd/nand.h>
- #include <linux/mtd/nand_ecc.h>
- #include <linux/bitops.h>
- #include <linux/string.h>
-#endif
 
 #define BBT_BLOCK_GOOD         0x00
 #define BBT_BLOCK_WORN         0x01
@@ -215,12 +199,12 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num,
                res = mtd_read(mtd, from, len, &retlen, buf);
                if (res < 0) {
                        if (mtd_is_eccerr(res)) {
-                               pr_info("nand_bbt: ECC error in BBT at "
-                                       "0x%012llx\n", from & ~mtd->writesize);
+                               pr_info("nand_bbt: ECC error in BBT at 0x%012llx\n",
+                                       from & ~mtd->writesize);
                                return res;
                        } else if (mtd_is_bitflip(res)) {
-                               pr_info("nand_bbt: corrected error in BBT at "
-                                       "0x%012llx\n", from & ~mtd->writesize);
+                               pr_info("nand_bbt: corrected error in BBT at 0x%012llx\n",
+                                       from & ~mtd->writesize);
                                ret = res;
                        } else {
                                pr_info("nand_bbt: error reading BBT\n");
@@ -542,11 +526,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
 {
        struct nand_chip *this = mtd->priv;
        int i, chips;
-#ifndef __UBOOT__
-       int bits, startblock, block, dir;
-#else
        int startblock, block, dir;
-#endif
        int scanlen = mtd->writesize + mtd->oobsize;
        int bbtblocks;
        int blocktopage = this->bbt_erase_shift - this->page_shift;
@@ -570,11 +550,6 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
                bbtblocks = mtd->size >> this->bbt_erase_shift;
        }
 
-#ifndef __UBOOT__
-       /* Number of bits for each erase block in the bbt */
-       bits = td->options & NAND_BBT_NRBITS_MSK;
-#endif
-
        for (i = 0; i < chips; i++) {
                /* Reset version information */
                td->version[i] = 0;
@@ -603,8 +578,8 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
                if (td->pages[i] == -1)
                        pr_warn("Bad block table not found for chip %d\n", i);
                else
-                       pr_info("Bad block table found at page %d, version "
-                                "0x%02X\n", td->pages[i], td->version[i]);
+                       pr_info("Bad block table found at page %d, version 0x%02X\n",
+                               td->pages[i], td->version[i]);
        }
        return 0;
 }
@@ -748,12 +723,10 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf,
                        res = mtd_read(mtd, to, len, &retlen, buf);
                        if (res < 0) {
                                if (retlen != len) {
-                                       pr_info("nand_bbt: error reading block "
-                                               "for writing the bad block table\n");
+                                       pr_info("nand_bbt: error reading block for writing the bad block table\n");
                                        return res;
                                }
-                               pr_warn("nand_bbt: ECC error while reading "
-                                       "block for writing bad block table\n");
+                               pr_warn("nand_bbt: ECC error while reading block for writing bad block table\n");
                        }
                        /* Read oob data */
                        ops.ooblen = (len >> this->page_shift) * mtd->oobsize;
@@ -1305,6 +1278,7 @@ static int nand_create_badblock_pattern(struct nand_chip *this)
 int nand_default_bbt(struct mtd_info *mtd)
 {
        struct nand_chip *this = mtd->priv;
+       int ret;
 
        /* Is a flash based bad block table requested? */
        if (this->bbt_options & NAND_BBT_USE_FLASH) {
@@ -1323,12 +1297,29 @@ int nand_default_bbt(struct mtd_info *mtd)
                this->bbt_md = NULL;
        }
 
-       if (!this->badblock_pattern)
-               nand_create_badblock_pattern(this);
+       if (!this->badblock_pattern) {
+               ret = nand_create_badblock_pattern(this);
+               if (ret)
+                       return ret;
+       }
 
        return nand_scan_bbt(mtd, this->badblock_pattern);
 }
 
+/**
+ * nand_isreserved_bbt - [NAND Interface] Check if a block is reserved
+ * @mtd: MTD device structure
+ * @offs: offset in the device
+ */
+int nand_isreserved_bbt(struct mtd_info *mtd, loff_t offs)
+{
+       struct nand_chip *this = mtd->priv;
+       int block;
+
+       block = (int)(offs >> this->bbt_erase_shift);
+       return bbt_get_entry(this, block) == BBT_BLOCK_RESERVED;
+}
+
 /**
  * nand_isbad_bbt - [NAND Interface] Check if a block is bad
  * @mtd: MTD device structure
@@ -1343,9 +1334,8 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt)
        block = (int)(offs >> this->bbt_erase_shift);
        res = bbt_get_entry(this, block);
 
-       pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: "
-                       "(block %d) 0x%02x\n",
-                       (unsigned int)offs, block, res);
+       pr_debug("nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n",
+                (unsigned int)offs, block, res);
 
        switch (res) {
        case BBT_BLOCK_GOOD: