1 --- a/drivers/mtd/nand/Kconfig
2 +++ b/drivers/mtd/nand/Kconfig
3 @@ -5,3 +5,7 @@ config MTD_NAND_CORE
4 source "drivers/mtd/nand/onenand/Kconfig"
5 source "drivers/mtd/nand/raw/Kconfig"
6 source "drivers/mtd/nand/spi/Kconfig"
8 +config MTD_NAND_MTK_BMT
9 + bool "Support MediaTek NAND Bad-block Management Table"
11 --- a/drivers/mtd/nand/Makefile
12 +++ b/drivers/mtd/nand/Makefile
15 nandcore-objs := core.o bbt.o
16 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
17 +obj-$(CONFIG_MTD_NAND_MTK_BMT) += mtk_bmt.o
22 +++ b/drivers/mtd/nand/mtk_bmt.c
25 + * Copyright (c) 2017 MediaTek Inc.
26 + * Author: Xiangsheng Hou <xiangsheng.hou@mediatek.com>
27 + * Copyright (c) 2020 Felix Fietkau <nbd@nbd.name>
29 + * This program is free software; you can redistribute it and/or modify
30 + * it under the terms of the GNU General Public License version 2 as
31 + * published by the Free Software Foundation.
33 + * This program is distributed in the hope that it will be useful,
34 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 + * GNU General Public License for more details.
39 +#include <linux/slab.h>
40 +#include <linux/gfp.h>
41 +#include <linux/kernel.h>
42 +#include <linux/of.h>
43 +#include <linux/mtd/nand.h>
44 +#include <linux/mtd/partitions.h>
45 +#include <linux/mtd/mtk_bmt.h>
46 +#include <linux/module.h>
47 +#include <linux/debugfs.h>
49 +#define MAIN_SIGNATURE_OFFSET 0
50 +#define OOB_SIGNATURE_OFFSET 1
51 +#define BBPOOL_RATIO 2
53 +#define BBT_LOG(fmt, ...) pr_debug("[BBT][%s|%d] "fmt"\n", __func__, __LINE__, ##__VA_ARGS__)
55 +/* Maximum 8k blocks */
56 +#define BB_TABLE_MAX 0x2000U
57 +#define BMT_TABLE_MAX (BB_TABLE_MAX * BBPOOL_RATIO / 100)
58 +#define BMT_TBL_DEF_VAL 0x0
61 + * Burner Bad Block Table
62 + * --------- Only support SLC Nand Chips!!!!!!!!!!! ----------
67 + /* This version is used to distinguish the legacy and new algorithm */
68 +#define BBMT_VERSION 2
69 + unsigned char version;
70 + /* Below 2 tables will be written in SLC */
71 + u16 bb_tbl[BB_TABLE_MAX];
75 +#define NORMAL_MAPPED 1
78 + } bmt_tbl[BMT_TABLE_MAX];
81 +static struct bmt_desc {
82 + struct mtd_info *mtd;
84 + int (*_read_oob) (struct mtd_info *mtd, loff_t from,
85 + struct mtd_oob_ops *ops);
86 + int (*_write_oob) (struct mtd_info *mtd, loff_t to,
87 + struct mtd_oob_ops *ops);
88 + const struct nand_ops *nand_ops;
92 + struct dentry *debugfs_dir;
98 + /* bbt logical address */
100 + /* bbt physical address */
102 + /* Maximum count of bad blocks that the vendor guaranteed */
104 + /* Total blocks of the Nand Chip */
106 + /* The block(n) BMT is located at (bmt_tbl[n]) */
108 + /* How many pages needs to store 'struct bbbt' */
111 + /* to compensate for driver level remapping */
115 +static unsigned char *nand_bbt_buf;
116 +static unsigned char *nand_data_buf;
118 +/* -------- Unit conversions -------- */
119 +static inline u32 blk_pg(u16 block)
121 + return (u32)(block << (bmtd.blk_shift - bmtd.pg_shift));
124 +/* -------- Nand operations wrapper -------- */
126 +bbt_nand_read(u32 page, unsigned char *dat, int dat_len,
127 + unsigned char *fdm, int fdm_len)
129 + struct mtd_oob_ops ops = {
130 + .mode = MTD_OPS_PLACE_OOB,
131 + .ooboffs = bmtd.oob_offset,
138 + return bmtd._read_oob(bmtd.mtd, page << bmtd.pg_shift, &ops);
141 +static inline int bbt_nand_erase(u16 block)
143 + struct nand_device *nand = mtd_to_nanddev(bmtd.mtd);
144 + loff_t addr = (loff_t)block << bmtd.blk_shift;
145 + struct nand_pos pos;
147 + nanddev_offs_to_pos(nand, addr, &pos);
148 + return bmtd.nand_ops->erase(nand, &pos);
151 +/* -------- Bad Blocks Management -------- */
153 +read_bmt(u16 block, unsigned char *dat, unsigned char *fdm, int fdm_len)
155 + u32 len = bmtd.bmt_pgs << bmtd.pg_shift;
157 + return bbt_nand_read(blk_pg(block), dat, len, fdm, fdm_len);
160 +static int write_bmt(u16 block, unsigned char *dat)
162 + struct mtd_oob_ops ops = {
163 + .mode = MTD_OPS_PLACE_OOB,
164 + .ooboffs = OOB_SIGNATURE_OFFSET + bmtd.oob_offset,
168 + .len = bmtd.bmt_pgs << bmtd.pg_shift,
170 + loff_t addr = (loff_t)block << bmtd.blk_shift;
172 + return bmtd._write_oob(bmtd.mtd, addr, &ops);
175 +static u16 find_valid_block(u16 block)
182 + if (block >= bmtd.total_blks)
185 + ret = bbt_nand_read(blk_pg(block), nand_data_buf, bmtd.pg_size,
187 + /* Read the 1st byte of FDM to judge whether it's a bad
190 + if (ret || fdm[0] != 0xff) {
191 + pr_info("nand: found bad block 0x%x\n", block);
192 + if (loop >= bmtd.bb_max) {
193 + pr_info("nand: FATAL ERR: too many bad blocks!!\n");
205 +/* Find out all bad blocks, and fill in the mapping table */
206 +static int scan_bad_blocks(struct bbbt *bbt)
211 + /* First time download, the block0 MUST NOT be a bad block,
212 + * this is guaranteed by vendor
214 + bbt->bb_tbl[0] = 0;
217 + * Construct the mapping table of Normal data area(non-PMT/BMTPOOL)
218 + * G - Good block; B - Bad block
219 + * ---------------------------
220 + * physical |G|G|B|G|B|B|G|G|G|G|B|G|B|
221 + * ---------------------------
222 + * What bb_tbl[i] looks like:
223 + * physical block(i):
224 + * 0 1 2 3 4 5 6 7 8 9 a b c
225 + * mapped block(bb_tbl[i]):
226 + * 0 1 3 6 7 8 9 b ......
228 + * If new bad block ocurred(n), search bmt_tbl to find
229 + * a available block(x), and fill in the bb_tbl[n] = x;
231 + for (i = 1; i < bmtd.pool_lba; i++) {
232 + bbt->bb_tbl[i] = find_valid_block(bbt->bb_tbl[i - 1] + 1);
233 + BBT_LOG("bb_tbl[0x%x] = 0x%x", i, bbt->bb_tbl[i]);
234 + if (bbt->bb_tbl[i] == 0)
238 + /* Physical Block start Address of BMT pool */
239 + bmtd.pool_pba = bbt->bb_tbl[i - 1] + 1;
240 + if (bmtd.pool_pba >= bmtd.total_blks - 2) {
241 + pr_info("nand: FATAL ERR: Too many bad blocks!!\n");
245 + BBT_LOG("pool_pba=0x%x", bmtd.pool_pba);
247 + block = bmtd.pool_pba;
249 + * The bmt table is used for runtime bad block mapping
250 + * G - Good block; B - Bad block
251 + * ---------------------------
252 + * physical |G|G|B|G|B|B|G|G|G|G|B|G|B|
253 + * ---------------------------
254 + * block: 0 1 2 3 4 5 6 7 8 9 a b c
255 + * What bmt_tbl[i] looks like in initial state:
258 + * bmt_tbl[i].block:
260 + * bmt_tbl[i].mapped:
262 + * N - Not mapped(Available)
266 + * BMT always in the last valid block in pool
268 + while ((block = find_valid_block(block)) != 0) {
269 + bbt->bmt_tbl[i].block = block;
270 + bbt->bmt_tbl[i].mapped = NO_MAPPED;
271 + BBT_LOG("bmt_tbl[%d].block = 0x%x", i, block);
276 + /* i - How many available blocks in pool, which is the length of bmt_tbl[]
277 + * bmtd.bmt_blk_idx - bmt_tbl[bmtd.bmt_blk_idx].block => the BMT block
279 + bmtd.bmt_blk_idx = i - 1;
280 + bbt->bmt_tbl[bmtd.bmt_blk_idx].mapped = BMT_MAPPED;
283 + pr_info("nand: FATAL ERR: no space to store BMT!!\n");
287 + pr_info("[BBT] %d available blocks in BMT pool\n", i);
292 +static bool is_valid_bmt(unsigned char *buf, unsigned char *fdm)
294 + struct bbbt *bbt = (struct bbbt *)buf;
295 + u8 *sig = (u8*)bbt->signature + MAIN_SIGNATURE_OFFSET;
298 + if (memcmp(bbt->signature + MAIN_SIGNATURE_OFFSET, "BMT", 3) == 0 &&
299 + memcmp(fdm + OOB_SIGNATURE_OFFSET, "bmt", 3) == 0) {
300 + if (bbt->version == BBMT_VERSION)
303 + BBT_LOG("[BBT] BMT Version not match,upgrage preloader and uboot please! sig=%02x%02x%02x, fdm=%02x%02x%02x",
304 + sig[0], sig[1], sig[2],
305 + fdm[1], fdm[2], fdm[3]);
309 +static u16 get_bmt_index(struct bbmt *bmt)
313 + while (bmt[i].block != BMT_TBL_DEF_VAL) {
314 + if (bmt[i].mapped == BMT_MAPPED)
321 +static struct bbbt *scan_bmt(u16 block)
325 + if (block < bmtd.pool_lba)
328 + if (read_bmt(block, nand_bbt_buf, fdm, sizeof(fdm)))
329 + return scan_bmt(block - 1);
331 + if (is_valid_bmt(nand_bbt_buf, fdm)) {
332 + bmtd.bmt_blk_idx = get_bmt_index(((struct bbbt *)nand_bbt_buf)->bmt_tbl);
333 + if (bmtd.bmt_blk_idx == 0) {
334 + pr_info("[BBT] FATAL ERR: bmt block index is wrong!\n");
337 + pr_info("[BBT] BMT.v2 is found at 0x%x\n", block);
338 + return (struct bbbt *)nand_bbt_buf;
340 + return scan_bmt(block - 1);
343 +/* Write the Burner Bad Block Table to Nand Flash
344 + * n - write BMT to bmt_tbl[n]
346 +static u16 upload_bmt(struct bbbt *bbt, int n)
351 + if (n < 0 || bbt->bmt_tbl[n].mapped == NORMAL_MAPPED) {
352 + pr_info("nand: FATAL ERR: no space to store BMT!\n");
356 + block = bbt->bmt_tbl[n].block;
357 + BBT_LOG("n = 0x%x, block = 0x%x", n, block);
358 + if (bbt_nand_erase(block)) {
359 + bbt->bmt_tbl[n].block = 0;
360 + /* erase failed, try the previous block: bmt_tbl[n - 1].block */
365 + /* The signature offset is fixed set to 0,
366 + * oob signature offset is fixed set to 1
368 + memcpy(bbt->signature + MAIN_SIGNATURE_OFFSET, "BMT", 3);
369 + bbt->version = BBMT_VERSION;
371 + if (write_bmt(block, (unsigned char *)bbt)) {
372 + bbt->bmt_tbl[n].block = 0;
374 + /* write failed, try the previous block in bmt_tbl[n - 1] */
379 + /* Return the current index(n) of BMT pool (bmt_tbl[n]) */
383 +static u16 find_valid_block_in_pool(struct bbbt *bbt)
387 + if (bmtd.bmt_blk_idx == 0)
390 + for (i = 0; i < bmtd.bmt_blk_idx; i++) {
391 + if (bbt->bmt_tbl[i].block != 0 && bbt->bmt_tbl[i].mapped == NO_MAPPED) {
392 + bbt->bmt_tbl[i].mapped = NORMAL_MAPPED;
393 + return bbt->bmt_tbl[i].block;
398 + pr_info("nand: FATAL ERR: BMT pool is run out!\n");
402 +/* We met a bad block, mark it as bad and map it to a valid block in pool,
403 + * if it's a write failure, we need to write the data to mapped block
405 +static bool update_bmt(u16 block)
411 + mapped_blk = find_valid_block_in_pool(bbt);
412 + if (mapped_blk == 0)
415 + /* Map new bad block to available block in pool */
416 + bbt->bb_tbl[block] = mapped_blk;
417 + bmtd.bmt_blk_idx = upload_bmt(bbt, bmtd.bmt_blk_idx);
422 +u16 get_mapping_block_index(int block)
426 + if (block < bmtd.pool_lba)
427 + mapping_block = bmtd.bbt->bb_tbl[block];
429 + mapping_block = block;
430 + BBT_LOG("0x%x mapped to 0x%x", block, mapping_block);
432 + return mapping_block;
436 +mtk_bmt_read(struct mtd_info *mtd, loff_t from,
437 + struct mtd_oob_ops *ops)
439 + struct mtd_oob_ops cur_ops = *ops;
440 + int retry_count = 0;
445 + ops->oobretlen = 0;
447 + while (ops->retlen < ops->len || ops->oobretlen < ops->ooblen) {
448 + u32 offset = from & (bmtd.blk_size - 1);
449 + u32 block = from >> bmtd.blk_shift;
452 + cur_block = get_mapping_block_index(block);
453 + cur_from = ((loff_t)cur_block << bmtd.blk_shift) + offset;
455 + cur_ops.oobretlen = 0;
456 + cur_ops.retlen = 0;
457 + cur_ops.len = min_t(u32, mtd->erasesize - offset,
458 + ops->len - ops->retlen);
459 + ret = bmtd._read_oob(mtd, cur_from, &cur_ops);
462 + if (retry_count++ < 10)
468 + ops->retlen += cur_ops.retlen;
469 + ops->oobretlen += cur_ops.oobretlen;
471 + cur_ops.datbuf += cur_ops.retlen;
472 + cur_ops.oobbuf += cur_ops.oobretlen;
473 + cur_ops.ooblen -= cur_ops.oobretlen;
476 + cur_ops.len = mtd->erasesize - offset;
478 + from += cur_ops.len;
486 +mtk_bmt_write(struct mtd_info *mtd, loff_t to,
487 + struct mtd_oob_ops *ops)
489 + struct mtd_oob_ops cur_ops = *ops;
490 + int retry_count = 0;
495 + ops->oobretlen = 0;
497 + while (ops->retlen < ops->len || ops->oobretlen < ops->ooblen) {
498 + u32 offset = to & (bmtd.blk_size - 1);
499 + u32 block = to >> bmtd.blk_shift;
502 + cur_block = get_mapping_block_index(block);
503 + cur_to = ((loff_t)cur_block << bmtd.blk_shift) + offset;
505 + cur_ops.oobretlen = 0;
506 + cur_ops.retlen = 0;
507 + cur_ops.len = min_t(u32, bmtd.blk_size - offset,
508 + ops->len - ops->retlen);
509 + ret = bmtd._write_oob(mtd, cur_to, &cur_ops);
512 + if (retry_count++ < 10)
518 + ops->retlen += cur_ops.retlen;
519 + ops->oobretlen += cur_ops.oobretlen;
521 + cur_ops.datbuf += cur_ops.retlen;
522 + cur_ops.oobbuf += cur_ops.oobretlen;
523 + cur_ops.ooblen -= cur_ops.oobretlen;
526 + cur_ops.len = mtd->erasesize - offset;
538 +mtk_bmt_erase(struct nand_device *nand, const struct nand_pos *pos)
540 + struct nand_pos new_pos = *pos;
541 + int retry_count = 0;
545 + new_pos.eraseblock = get_mapping_block_index(pos->eraseblock);
547 + ret = bmtd.nand_ops->erase(nand, &new_pos);
549 + update_bmt(pos->eraseblock);
550 + if (retry_count++ < 10)
558 +mtk_bmt_isbad(struct nand_device *nand, const struct nand_pos *pos)
560 + struct nand_pos new_pos = *pos;
561 + int retry_count = 0;
565 + new_pos.eraseblock = get_mapping_block_index(pos->eraseblock);
567 + ret = bmtd.nand_ops->isbad(nand, &new_pos);
569 + update_bmt(pos->eraseblock);
570 + if (retry_count++ < 10)
578 +mtk_bmt_markbad(struct nand_device *nand, const struct nand_pos *pos)
580 + struct nand_pos new_pos = *pos;
582 + new_pos.eraseblock = get_mapping_block_index(new_pos.eraseblock);
583 + update_bmt(pos->eraseblock);
585 + return bmtd.nand_ops->markbad(nand, &new_pos);
589 +mtk_bmt_replace_ops(struct mtd_info *mtd)
591 + static const struct nand_ops mtk_bmt_nand_ops = {
592 + .erase = mtk_bmt_erase,
593 + .isbad = mtk_bmt_isbad,
594 + .markbad = mtk_bmt_markbad,
596 + struct nand_device *nand = mtd_to_nanddev(mtd);
598 + bmtd.nand_ops = nand->ops;
599 + bmtd._read_oob = mtd->_read_oob;
600 + bmtd._write_oob = mtd->_write_oob;
602 + mtd->_read_oob = mtk_bmt_read;
603 + mtd->_write_oob = mtk_bmt_write;
604 + nand->ops = &mtk_bmt_nand_ops;
607 +static int mtk_bmt_debug_mark_good(void *data, u64 val)
609 + u32 block = val >> bmtd.blk_shift;
611 + bmtd.bbt->bb_tbl[block] = block;
612 + bmtd.bmt_blk_idx = upload_bmt(bmtd.bbt, bmtd.bmt_blk_idx);
617 +static int mtk_bmt_debug_mark_bad(void *data, u64 val)
619 + u32 block = val >> bmtd.blk_shift;
626 +DEFINE_DEBUGFS_ATTRIBUTE(fops_mark_good, NULL, mtk_bmt_debug_mark_good, "%llu\n");
627 +DEFINE_DEBUGFS_ATTRIBUTE(fops_mark_bad, NULL, mtk_bmt_debug_mark_bad, "%llu\n");
630 +mtk_bmt_add_debugfs(void)
632 + struct dentry *dir;
634 + dir = bmtd.debugfs_dir = debugfs_create_dir("mtk-bmt", NULL);
638 + debugfs_create_file_unsafe("mark_good", S_IWUSR, dir, NULL, &fops_mark_good);
639 + debugfs_create_file_unsafe("mark_bad", S_IWUSR, dir, NULL, &fops_mark_bad);
642 +void mtk_bmt_detach(struct mtd_info *mtd)
644 + struct nand_device *nand = mtd_to_nanddev(mtd);
646 + if (bmtd.mtd != mtd)
649 + if (bmtd.debugfs_dir)
650 + debugfs_remove_recursive(bmtd.debugfs_dir);
651 + bmtd.debugfs_dir = NULL;
653 + kfree(nand_bbt_buf);
654 + kfree(nand_data_buf);
656 + mtd->_read_oob = bmtd._read_oob;
657 + mtd->_write_oob = bmtd._write_oob;
658 + mtd->size = bmtd.total_blks << bmtd.blk_shift;
659 + nand->ops = bmtd.nand_ops;
661 + memset(&bmtd, 0, sizeof(bmtd));
664 +/* total_blocks - The total count of blocks that the Nand Chip has */
665 +int mtk_bmt_attach(struct mtd_info *mtd)
667 + struct device_node *np;
671 + u16 total_blocks, pmt_block;
678 + np = mtd_get_of_node(mtd);
682 + if (!of_property_read_bool(np, "mediatek,bmt-v2"))
685 + if (of_property_read_u32(np, "mediatek,bmt-pool-size",
686 + &bmt_pool_size) != 0)
687 + bmt_pool_size = 80;
689 + if (of_property_read_u8(np, "mediatek,bmt-oob-offset",
690 + &bmtd.oob_offset) != 0)
691 + bmtd.oob_offset = 8;
694 + mtk_bmt_replace_ops(mtd);
696 + bmtd.blk_size = mtd->erasesize;
697 + bmtd.blk_shift = ffs(bmtd.blk_size) - 1;
698 + bmtd.pg_size = mtd->writesize;
699 + bmtd.pg_shift = ffs(bmtd.pg_size) - 1;
700 + total_blocks = mtd->size >> bmtd.blk_shift;
701 + pmt_block = total_blocks - bmt_pool_size - 2;
703 + mtd->size = pmt_block << bmtd.blk_shift;
706 + * ---------------------------------------
707 + * | PMT(2blks) | BMT POOL(totalblks * 2%) |
708 + * ---------------------------------------
711 + * pmt_block pmt_block + 2blocks(pool_lba)
714 + * The blocks ahead of the boundary block are stored in bb_tbl
715 + * and blocks behind are stored in bmt_tbl
718 + bmtd.pool_lba = (u16)(pmt_block + 2);
719 + bmtd.total_blks = total_blocks;
720 + bmtd.bb_max = bmtd.total_blks * BBPOOL_RATIO / 100;
722 + /* 3 buffers we need */
723 + bufsz = round_up(sizeof(struct bbbt), bmtd.pg_size);
724 + bmtd.bmt_pgs = bufsz >> bmtd.pg_shift;
726 + nand_bbt_buf = kzalloc(bufsz, GFP_KERNEL);
727 + nand_data_buf = kzalloc(bmtd.pg_size, GFP_KERNEL);
729 + if (!nand_bbt_buf || !nand_data_buf) {
730 + pr_info("nand: FATAL ERR: allocate buffer failed!\n");
735 + memset(nand_bbt_buf, 0xff, bufsz);
736 + memset(nand_data_buf, 0xff, bmtd.pg_size);
738 + BBT_LOG("bbtbuf=0x%p(0x%x) dat=0x%p(0x%x)",
739 + nand_bbt_buf, bufsz, nand_data_buf, bmtd.pg_size);
740 + BBT_LOG("pool_lba=0x%x total_blks=0x%x bb_max=0x%x",
741 + bmtd.pool_lba, bmtd.total_blks, bmtd.bb_max);
743 + /* Scanning start from the first page of the last block
746 + bbt = scan_bmt(bmtd.total_blks - 1);
748 + /* BMT not found */
749 + if (bmtd.total_blks > BB_TABLE_MAX + BMT_TABLE_MAX) {
750 + pr_info("nand: FATAL: Too many blocks, can not support!\n");
755 + bbt = (struct bbbt *)nand_bbt_buf;
756 + memset(bbt->bmt_tbl, BMT_TBL_DEF_VAL, sizeof(bbt->bmt_tbl));
758 + if (scan_bad_blocks(bbt)) {
763 + /* BMT always in the last valid block in pool */
764 + bmtd.bmt_blk_idx = upload_bmt(bbt, bmtd.bmt_blk_idx);
765 + block = bbt->bmt_tbl[bmtd.bmt_blk_idx].block;
766 + pr_notice("[BBT] BMT.v2 is written into PBA:0x%x\n", block);
768 + if (bmtd.bmt_blk_idx == 0)
769 + pr_info("nand: Warning: no available block in BMT pool!\n");
770 + else if (bmtd.bmt_blk_idx == (u16)-1) {
775 + mtk_bmt_add_debugfs();
781 + mtk_bmt_detach(mtd);
786 +MODULE_LICENSE("GPL");
787 +MODULE_AUTHOR("Xiangsheng Hou <xiangsheng.hou@mediatek.com>, Felix Fietkau <nbd@nbd.name>");
788 +MODULE_DESCRIPTION("Bad Block mapping management v2 for MediaTek NAND Flash Driver");
790 --- a/drivers/mtd/nand/spi/core.c
791 +++ b/drivers/mtd/nand/spi/core.c
793 #include <linux/slab.h>
794 #include <linux/spi/spi.h>
795 #include <linux/spi/spi-mem.h>
796 +#include <linux/mtd/mtk_bmt.h>
798 static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
800 @@ -1099,6 +1100,8 @@ static int spinand_probe(struct spi_mem
804 + mtk_bmt_attach(mtd);
806 ret = mtd_device_register(mtd, NULL, 0);
808 goto err_spinand_cleanup;
809 @@ -1124,6 +1127,7 @@ static int spinand_remove(struct spi_mem
813 + mtk_bmt_detach(mtd);
814 spinand_cleanup(spinand);
818 +++ b/include/linux/mtd/mtk_bmt.h
823 +#ifdef CONFIG_MTD_NAND_MTK_BMT
824 +int mtk_bmt_attach(struct mtd_info *mtd);
825 +void mtk_bmt_detach(struct mtd_info *mtd);
827 +static inline int mtk_bmt_attach(struct mtd_info *mtd)
832 +static inline void mtk_bmt_detach(struct mtd_info *mtd)