diff mbox series

[U-Boot] ubi: fastmap: Implement produce_free_peb()

Message ID 1526976651-22181-1-git-send-email-patrice.chotard@st.com
State Accepted
Commit 65c3d25a6a21b5cf4d978f05f84aaeb6b250e636
Delegated to: Heiko Schocher
Headers show
Series [U-Boot] ubi: fastmap: Implement produce_free_peb() | expand

Commit Message

Patrice CHOTARD May 22, 2018, 8:10 a.m. UTC
Since 'commit f82290afc847 ("mtd: ubi: Fix worker handling")',
when booting from NAND, on a fresh NAND just after being flashed (and
only in this case), we got the following log:

ubi0: default fastmap pool size: 200
ubi0: default fastmap WL pool size: 100
ubi0: attaching mtd2
ubi0: scanning is finished
ubi0 error: ubi_update_fastmap: could not find any anchor PEB
ubi0 error: ubi_update_fastmap: could not find any anchor PEB
ubi0 error: ubi_wl_get_peb: Unable to get a free PEB from user WL pool
ubi0 error: autoresize: cannot auto-resize volume 1
UBI error: cannot attach mtd2UBI error: cannot initialize UBI, error
-28UBI init error 28

After analysis, in ubi_wl_init(), when performing schedule_erase(),
thread_enabled flag is not yet set to 1, which forbids ubi_do_worker()
to execute pending works.

This has to effect to not populate ubi->free with free physical
eraseblocks.

Following Richard Weinberger's advice, this patch has been
backported from kernel tree :
'commit 1cb8f9776c7d ("ubi: fastmap: Implement produce_free_peb()")'

Tested-by: Patrice Chotard <patrice.chotard@st.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

 drivers/mtd/ubi/fastmap-wl.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

Comments

Heiko Schocher May 22, 2018, 9:34 a.m. UTC | #1
Hello Patrice,

Am 22.05.2018 um 10:10 schrieb Patrice Chotard:
> Since 'commit f82290afc847 ("mtd: ubi: Fix worker handling")',
> when booting from NAND, on a fresh NAND just after being flashed (and
> only in this case), we got the following log:
> 
> ubi0: default fastmap pool size: 200
> ubi0: default fastmap WL pool size: 100
> ubi0: attaching mtd2
> ubi0: scanning is finished
> ubi0 error: ubi_update_fastmap: could not find any anchor PEB
> ubi0 error: ubi_update_fastmap: could not find any anchor PEB
> ubi0 error: ubi_wl_get_peb: Unable to get a free PEB from user WL pool
> ubi0 error: autoresize: cannot auto-resize volume 1
> UBI error: cannot attach mtd2UBI error: cannot initialize UBI, error
> -28UBI init error 28
> 
> After analysis, in ubi_wl_init(), when performing schedule_erase(),
> thread_enabled flag is not yet set to 1, which forbids ubi_do_worker()
> to execute pending works.
> 
> This has to effect to not populate ubi->free with free physical
> eraseblocks.
> 
> Following Richard Weinberger's advice, this patch has been
> backported from kernel tree :
> 'commit 1cb8f9776c7d ("ubi: fastmap: Implement produce_free_peb()")'
> 
> Tested-by: Patrice Chotard <patrice.chotard@st.com>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> 
>   drivers/mtd/ubi/fastmap-wl.c | 29 +++++++++++++++++++++++++++++
>   1 file changed, 29 insertions(+)

Thanks!

Acked-by: Heiko Schocher <hs@denx.de>

I do some tests and a travis build for it ...

bye,
Heiko
Heiko Schocher May 29, 2018, 3:35 a.m. UTC | #2
Hello Patrice,

Am 22.05.2018 um 10:10 schrieb Patrice Chotard:
> Since 'commit f82290afc847 ("mtd: ubi: Fix worker handling")',
> when booting from NAND, on a fresh NAND just after being flashed (and
> only in this case), we got the following log:
> 
> ubi0: default fastmap pool size: 200
> ubi0: default fastmap WL pool size: 100
> ubi0: attaching mtd2
> ubi0: scanning is finished
> ubi0 error: ubi_update_fastmap: could not find any anchor PEB
> ubi0 error: ubi_update_fastmap: could not find any anchor PEB
> ubi0 error: ubi_wl_get_peb: Unable to get a free PEB from user WL pool
> ubi0 error: autoresize: cannot auto-resize volume 1
> UBI error: cannot attach mtd2UBI error: cannot initialize UBI, error
> -28UBI init error 28
> 
> After analysis, in ubi_wl_init(), when performing schedule_erase(),
> thread_enabled flag is not yet set to 1, which forbids ubi_do_worker()
> to execute pending works.
> 
> This has to effect to not populate ubi->free with free physical
> eraseblocks.
> 
> Following Richard Weinberger's advice, this patch has been
> backported from kernel tree :
> 'commit 1cb8f9776c7d ("ubi: fastmap: Implement produce_free_peb()")'
> 
> Tested-by: Patrice Chotard <patrice.chotard@st.com>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
> 
>   drivers/mtd/ubi/fastmap-wl.c | 29 +++++++++++++++++++++++++++++
>   1 file changed, 29 insertions(+)

Applied to u-boot-ubi.git master

Thanks!

bye,
Heiko
diff mbox series

Patch

diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index b7876a81cb0f..e36fb39943a5 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -171,6 +171,30 @@  void ubi_refill_pools(struct ubi_device *ubi)
 }
 
 /**
+ * produce_free_peb - produce a free physical eraseblock.
+ * @ubi: UBI device description object
+ *
+ * This function tries to make a free PEB by means of synchronous execution of
+ * pending works. This may be needed if, for example the background thread is
+ * disabled. Returns zero in case of success and a negative error code in case
+ * of failure.
+ */
+static int produce_free_peb(struct ubi_device *ubi)
+{
+	int err;
+
+	while (!ubi->free.rb_node && ubi->works_count) {
+		dbg_wl("do one work synchronously");
+		err = do_work(ubi);
+
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+/**
  * ubi_wl_get_peb - get a physical eraseblock.
  * @ubi: UBI device description object
  *
@@ -212,6 +236,11 @@  again:
 		}
 		retried = 1;
 		up_read(&ubi->fm_eba_sem);
+		ret = produce_free_peb(ubi);
+		if (ret < 0) {
+			down_read(&ubi->fm_eba_sem);
+			goto out;
+		}
 		goto again;
 	}