From patchwork Fri Mar 20 14:04:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 244010 List-Id: U-Boot discussion From: rasmus.villemoes at prevas.dk (Rasmus Villemoes) Date: Fri, 20 Mar 2020 15:04:14 +0100 Subject: [PATCH] tools: fw_env: use erasesize from MEMGETINFO ioctl Message-ID: <20200320140414.19689-1-rasmus.villemoes@prevas.dk> 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 column is absent or contains a 0. 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 --- tools/env/fw_env.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index 381739d28d..87c3504315 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1647,6 +1647,8 @@ static int check_device_config(int dev) goto err; } DEVTYPE(dev) = mtdinfo.type; + if (DEVESIZE(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);