@@ -712,6 +712,35 @@ static int bch_write(struct mtd_info *mtd, struct nand_chip *chip,
return 0;
}
+/*
+ * Bad Block Tables/Bad Block Markers
+ */
+#define BBT_MARK_BAD_FACTORY 0x0
+#define BBT_MARK_BAD_WEAR 0x1
+#define BBT_MARK_GOOD 0x3
+
+static void bbt_set_block_mark(uint8_t *bbt, uint32_t block, uint8_t mark)
+{
+ unsigned int byte = block >> 2;
+ unsigned int shift = (block & 0x3) << 1;
+
+ bbt[byte] &= ~(0x3 << shift);
+ bbt[byte] |= ((mark & 0x3) << shift);
+}
+
+static uint8_t bbt_get_block_mark(uint8_t *bbt, uint32_t block)
+{
+ unsigned int byte = block >> 2;
+ unsigned int shift = (block & 0x3) << 1;
+
+ return (bbt[byte] >> shift) & 0x3;
+}
+
+static int bbt_is_block_bad(uint8_t *bbt, uint32_t block)
+{
+ return bbt_get_block_mark(bbt, block) == BBT_MARK_GOOD ? 0 : 1;
+}
+
/* Scan block for IBBT signature */
static int bch_find_ibbt_sig(struct nandi_controller *nandi,
uint32_t block, int *bak, uint8_t *vers,
Bad Block Markers (BBMs) keep track of unusable/unsuitable memory blocks which can prevent unnecessary data loss. These helpers aid in reading and writing to/from the Bad Block Tables (BBTs) where the BBMs are stored. Signed-off-by: Lee Jones <lee.jones@linaro.org> --- drivers/mtd/nand/stm_nand_bch.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)