diff mbox series

[v2] tools: fw_env: use erasesize from MEMGETINFO ioctl

Message ID 20200324125740.10602-1-rasmus.villemoes@prevas.dk
State Accepted
Commit e282c422e0b9a64dc53f7f1e55309639bc645f38
Delegated to: Tom Rini
Headers show
Series [v2] tools: fw_env: use erasesize from MEMGETINFO ioctl | expand

Commit Message

Rasmus Villemoes March 24, 2020, 12:57 p.m. UTC
We have a board with several revisions. The older ones use a nor flash
with 64k erase size, while the newer have a flash with 4k sectors. The
environment size is 8k.

Currently, we have to put a column containing 0x10000 (64k) in
fw_env.config in order for it to work on the older boards. But that
ends up wasting quite a lot of time on the newer boards that could
just erase the 8k occupied by the environment - strace says the 64k
erase takes 0.405 seconds. With this patch, as expected, that's about
an 8-fold better, at 0.043 seconds.

Having different fw_env.config files for the different revisions is
highly impractical, and the correct information is already available
right at our fingertips. So use the erasesize returned by the
MEMGETINFO ioctl when the fourth and fifth columns (sector size and
#sectors, respectively) are absent or contain 0, a case where the
logic previously used to use the environment size as erase size (and
consequently computed ENVSECTORS(dev) as 1).

As I'm only testing this on a NOR flash, I'm only changing the logic
for that case, though I think it should be possible for the other
types as well.

Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
---

v2: Also require ENVSECTORS(dev) to be absent (or 0) to apply
this, in order to prevent regressions in the somewhat odd case
where someone used 0 as sector size (and hence used the
environment size as sector size) and explicitly listed 1 as
#sectors. 

 tools/env/fw_env.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Tom Rini April 28, 2020, 1:53 p.m. UTC | #1
On Tue, Mar 24, 2020 at 01:57:40PM +0100, Rasmus Villemoes wrote:

> We have a board with several revisions. The older ones use a nor flash
> with 64k erase size, while the newer have a flash with 4k sectors. The
> environment size is 8k.
> 
> Currently, we have to put a column containing 0x10000 (64k) in
> fw_env.config in order for it to work on the older boards. But that
> ends up wasting quite a lot of time on the newer boards that could
> just erase the 8k occupied by the environment - strace says the 64k
> erase takes 0.405 seconds. With this patch, as expected, that's about
> an 8-fold better, at 0.043 seconds.
> 
> Having different fw_env.config files for the different revisions is
> highly impractical, and the correct information is already available
> right at our fingertips. So use the erasesize returned by the
> MEMGETINFO ioctl when the fourth and fifth columns (sector size and
> #sectors, respectively) are absent or contain 0, a case where the
> logic previously used to use the environment size as erase size (and
> consequently computed ENVSECTORS(dev) as 1).
> 
> As I'm only testing this on a NOR flash, I'm only changing the logic
> for that case, though I think it should be possible for the other
> types as well.
> 
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index 381739d28d..8734663cd4 100644
--- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c
@@ -1647,6 +1647,9 @@  static int check_device_config(int dev)
 			goto err;
 		}
 		DEVTYPE(dev) = mtdinfo.type;
+		if (DEVESIZE(dev) == 0 && ENVSECTORS(dev) == 0 &&
+		    mtdinfo.type == MTD_NORFLASH)
+			DEVESIZE(dev) = mtdinfo.erasesize;
 		if (DEVESIZE(dev) == 0)
 			/* Assume the erase size is the same as the env-size */
 			DEVESIZE(dev) = ENVSIZE(dev);