mtdblock: add squashfs mount support [1/1]

PD#SWPL-117382

Problem:
add squashfs mount support

Solution:
add squashfs mount support

Verify:
s4_aq2432

Change-Id: I663aa278d5521dd03279951b4fecf1d0183fdf8b
Signed-off-by: Feng Chen <feng.chen@amlogic.com>
This commit is contained in:
Feng Chen
2023-03-28 20:58:14 +08:00
committed by gerrit autosubmit
parent 68e43b8752
commit bc95150e80
@@ -1,4 +1,4 @@
From 96900c1c398d6a798a83a651760c9fb939d9bd8d Mon Sep 17 00:00:00 2001
From f09d46d6e974a6178ce577f92cf4e606486b3c65 Mon Sep 17 00:00:00 2001
From: Feng Chen <feng.chen@amlogic.com>
Date: Tue, 21 Mar 2023 10:59:15 +0800
Subject: [PATCH] mtdblock: modify for squashfs mount [1/2]
@@ -20,25 +20,29 @@ s4_aq2432
Change-Id: Icbaec2b6679727ebe0d12fd92bf4d21cc4d5f3fe
Signed-off-by: Feng Chen <feng.chen@amlogic.com>
---
drivers/mtd/mtdblock.c | 97 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 97 insertions(+)
drivers/mtd/mtdblock.c | 107 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 107 insertions(+)
diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c
index 1e94e7d10b8b..6c7766a66672 100644
index 1e94e7d10b8b..030071bfaf27 100644
--- a/drivers/mtd/mtdblock.c
+++ b/drivers/mtd/mtdblock.c
@@ -29,6 +29,10 @@ struct mtdblk_dev {
unsigned long cache_offset;
unsigned int cache_size;
@@ -31,6 +31,14 @@ struct mtdblk_dev {
enum { STATE_EMPTY, STATE_CLEAN, STATE_DIRTY } cache_state;
+#ifdef CONFIG_AMLOGIC_NAND
+ unsigned int bad_cnt;
+ unsigned short *part_bbt;
+#endif
};
+#ifdef CONFIG_AMLOGIC_NAND
+struct mtdblk_pbbt {
+ struct mtdblk_dev mb;
+ unsigned int bad_cnt;
+ unsigned short *part_bbt;
+};
+#endif
+
/*
@@ -101,11 +105,43 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
* Cache stuff...
*
@@ -101,11 +109,41 @@ static int write_cached_data (struct mtdblk_dev *mtdblk)
* written to the device. Clear cache_state to avoid writing to
* bad blocks repeatedly.
*/
@@ -47,28 +51,26 @@ index 1e94e7d10b8b..6c7766a66672 100644
+ return ret;
+ mtdblk->cache_state = STATE_EMPTY;
+ return ret;
+ /*
+ * If define CONFIG_AMLOGIC_NAND, never come here.
+ */
+ /* coverity[unreachable:SUPPRESS] */
+#endif
+#else
if (ret == 0 || ret == -EIO)
mtdblk->cache_state = STATE_EMPTY;
return ret;
+#endif
}
+#ifdef CONFIG_AMLOGIC_NAND
+static unsigned long map_block(struct mtdblk_dev *mtdblk, unsigned long pos)
+{
+ struct mtd_info *mtd = mtdblk->mbd.mtd;
+ struct mtdblk_pbbt *pbbt = container_of(mtdblk, struct mtdblk_pbbt, mb);
+ int block, i;
+
+ if (!mtdblk->part_bbt)
+ if (!pbbt->part_bbt)
+ return pos;
+
+ block = (int)(pos >> mtd->erasesize_shift);
+ for (i = 0; i < mtdblk->bad_cnt; i++) {
+ if (block >= mtdblk->part_bbt[i])
+ for (i = 0; i < pbbt->bad_cnt; i++) {
+ if (block >= pbbt->part_bbt[i])
+ block++;
+ else
+ break;
@@ -82,7 +84,7 @@ index 1e94e7d10b8b..6c7766a66672 100644
static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
int len, const char *buf)
@@ -118,6 +154,10 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
@@ -118,6 +156,10 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos,
pr_debug("mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n",
mtd->name, pos, len);
@@ -93,7 +95,7 @@ index 1e94e7d10b8b..6c7766a66672 100644
if (!sect_size)
return mtd_write(mtd, pos, len, &retlen, buf);
@@ -188,6 +228,10 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
@@ -188,6 +230,10 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos,
pr_debug("mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n",
mtd->name, pos, len);
@@ -104,22 +106,23 @@ index 1e94e7d10b8b..6c7766a66672 100644
if (!sect_size)
return mtd_read(mtd, pos, len, &retlen, buf);
@@ -249,6 +293,9 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
@@ -249,6 +295,10 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev,
static int mtdblock_open(struct mtd_blktrans_dev *mbd)
{
struct mtdblk_dev *mtdblk = container_of(mbd, struct mtdblk_dev, mbd);
+#ifdef CONFIG_AMLOGIC_NAND
+ int block_cnt, i, bad_cnt = 0;
+ struct mtdblk_pbbt *pbbt = container_of(mtdblk, struct mtdblk_pbbt, mb);
+#endif
pr_debug("mtdblock_open\n");
@@ -270,6 +317,35 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
@@ -270,6 +320,35 @@ static int mtdblock_open(struct mtd_blktrans_dev *mbd)
mtdblk->cache_data = NULL;
}
+#ifdef CONFIG_AMLOGIC_NAND
+ mtdblk->part_bbt = NULL;
+ pbbt->part_bbt = NULL;
+ if (!mtd_can_have_bb(mbd->mtd))
+ goto _ok;
+
@@ -131,10 +134,10 @@ index 1e94e7d10b8b..6c7766a66672 100644
+ /* coverity[divide_by_zero:SUPPRESS] */
+ if (mtd_block_isbad(mbd->mtd, i * mbd->mtd->erasesize))
+ bad_cnt++;
+ mtdblk->bad_cnt = bad_cnt;
+ pbbt->bad_cnt = bad_cnt;
+ if (bad_cnt) {
+ mtdblk->part_bbt =
+ kmalloc_array(block_cnt, sizeof(*mtdblk->part_bbt), GFP_KERNEL);
+ pbbt->part_bbt =
+ kmalloc_array(block_cnt, sizeof(*pbbt->part_bbt), GFP_KERNEL);
+ bad_cnt = 0;
+ for (i = 0; i < block_cnt; i++)
+ /*
@@ -142,7 +145,7 @@ index 1e94e7d10b8b..6c7766a66672 100644
+ */
+ /* coverity[divide_by_zero:SUPPRESS] */
+ if (mtd_block_isbad(mbd->mtd, i * mbd->mtd->erasesize))
+ mtdblk->part_bbt[bad_cnt++] = i;
+ pbbt->part_bbt[bad_cnt++] = i;
+ }
+
+_ok:
@@ -150,18 +153,11 @@ index 1e94e7d10b8b..6c7766a66672 100644
pr_debug("ok\n");
return 0;
@@ -307,12 +383,23 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
@@ -307,27 +386,55 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev)
ret = write_cached_data(mtdblk);
mutex_unlock(&mtdblk->cache_mutex);
mtd_sync(dev->mtd);
+
+#ifdef CONFIG_AMLOGIC_NAND
+ return 0;
+ /*
+ * If define CONFIG_AMLOGIC_NAND, never come here.
+ */
+ /* coverity[unreachable:SUPPRESS] */
+#endif
return ret;
}
@@ -170,11 +166,18 @@ index 1e94e7d10b8b..6c7766a66672 100644
struct mtdblk_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+#ifdef CONFIG_AMLOGIC_NAND
+ int i = 0;
+ struct mtdblk_pbbt *pbbt = kzalloc(sizeof(*pbbt), GFP_KERNEL);
+#endif
if (!dev)
return;
@@ -321,6 +408,16 @@ static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
+#ifdef CONFIG_AMLOGIC_NAND
+ if (!pbbt)
+ return;
+#endif
+
dev->mbd.mtd = mtd;
dev->mbd.devnum = mtd->index;
dev->mbd.size = mtd->size >> 9;
@@ -191,6 +194,21 @@ index 1e94e7d10b8b..6c7766a66672 100644
dev->mbd.tr = tr;
if (!(mtd->flags & MTD_WRITEABLE))
dev->mbd.readonly = 1;
+#ifdef CONFIG_AMLOGIC_NAND
+ pbbt->mb = *dev;
+ if (add_mtd_blktrans_dev(&dev->mbd)) {
+ kfree(dev);
+ kfree(pbbt);
+ }
+#else
if (add_mtd_blktrans_dev(&dev->mbd))
kfree(dev);
+#endif
}
static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev)
--
2.37.1