[PATCH 8/9] drivers:mtd:ubi:init UBI bakvol and recover corrupted lower page
From: Bean Huo 霍斌斌 (beanhuo)
Date: Mon Sep 28 2015 - 03:06:02 EST
During UBI attach, bakvol be initialized,
And if exist corrupted lower page, recover it by its backup data in internal
Log volume.
Signed-off-by: Bean Huo <beanhuo@xxxxxxxxxx>
---
drivers/mtd/ubi/attach.c | 26 +++++++++++++++++++++++++-
drivers/mtd/ubi/build.c | 7 +++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/attach.c b/drivers/mtd/ubi/attach.c
index 68eea5b..4e00d79 100644
--- a/drivers/mtd/ubi/attach.c
+++ b/drivers/mtd/ubi/attach.c
@@ -919,6 +919,17 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
err = ubi_io_read_vid_hdr(ubi, pnum, vidh, 0);
if (err < 0)
return err;
+
+#ifdef CONFIG_MTD_UBI_MLC_NAND_BAKVOL
+ /*
+ * Before ubi scan the NAND flash, call ubi_backup_volume_scan
+ * to build the backup volume first. when the ubi scan NAND and
+ * find corrupt data, then we can try to check if there is backup
+ * data in the backup volume.
+ */
+ ubi_backup_volume_scan(ubi, vidh, pnum);
+#endif
+
switch (err) {
case 0:
break;
@@ -995,7 +1006,8 @@ static int scan_peb(struct ubi_device *ubi, struct ubi_attach_info *ai,
*vid = vol_id;
if (sqnum)
*sqnum = be64_to_cpu(vidh->sqnum);
- if (vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID) {
+ if ((vol_id > UBI_MAX_VOLUMES && vol_id != UBI_LAYOUT_VOLUME_ID)
+ && vol_id != UBI_BACKUP_VOLUME_ID) {
int lnum = be32_to_cpu(vidh->lnum);
/* Unsupported internal volume */
@@ -1408,6 +1420,12 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
if (!ai)
return -ENOMEM;
+#ifdef CONFIG_MTD_UBI_MLC_NAND_BAKVOL
+ err = ubi_backup_volume_init(ubi);
+ if (err)
+ goto out_ai;
+#endif
+
#ifdef CONFIG_MTD_UBI_FASTMAP
/* On small flash devices we disable fastmap in any case. */
if ((int)mtd_div_by_eb(ubi->mtd->size, ubi->mtd) <= UBI_FM_MAX_START) {
@@ -1449,6 +1467,12 @@ int ubi_attach(struct ubi_device *ubi, int force_scan)
if (err)
goto out_ai;
+#ifdef CONFIG_MTD_UBI_MLC_NAND_BAKVOL
+ err = ubi_backup_volume_init_tail(ubi, ai);
+ if (err)
+ goto out_ai;
+#endif
+
err = ubi_wl_init(ubi, ai);
if (err)
goto out_vtbl;
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 22fd19c..05524f7 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1033,6 +1033,11 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
ubi_devices[ubi_num] = ubi;
ubi_notify_all(ubi, UBI_VOLUME_ADDED, NULL);
+
+#ifdef CONFIG_MTD_UBI_MLC_NAND_BAKVOL
+ ubi_bad_data_recovery(ubi);
+#endif
+
return ubi_num;
out_debugfs:
@@ -1118,6 +1123,8 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
*/
get_device(&ubi->dev);
+ clear_bakvol(ubi);
+
ubi_debugfs_exit_dev(ubi);
uif_close(ubi);
--
1.9.1