[PATCH v2 0/1] fw_env: auto-detect NAND characteristics

From: Anthony Loiseau anthony.loiseau@allcircuits.com
Hello,
Here is a patch proposal which modifies fw_env so NAND chip erase size as well as environment sector counts are guessed at runtime if they are both statically configured as zero. This actually extends a previous similar behavior which was NOR-specific, useful when a same RootFS is executed with several flash chips, see e282c422e0b.
Be aware that I did not test this exact patch for real. I extracted it from my older u-boot-flsc 2016 tree on which it works well, and built it using a sandbox configuration, without running it. I only checked my gcc was happy with those lines (no warnings added). My feeling is that this patch is small enough to feel confident it will work on master as it worked on my old tree.
Opened to any reviews or requests, best rergards, Anthony Loiseau
v1: initial buggy submission (broken thread) stephan toradex email no more valid v2: fix cover letter use another email for Stefan cc Rasmus (author of the changed lines)
Cc: Joe Hershberger joe.hershberger@ni.com cc: Stefan Agner stefan@agner.ch cc: Rasmus Villemoes rasmus.villemoes@prevas.dk Signed-off-by: Anthony Loiseau anthony.loiseau@allcircuits.com
Anthony Loiseau (1): fw_env: autodetect NAND erase size and env sectors
tools/env/README | 3 +++ tools/env/fw_env.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)

From: Anthony Loiseau anthony.loiseau@allcircuits.com
As already done for NOR chips, if device ESIZE and ENVSECTORS static configurations are both zero, then autodetect them at runtime.
Cc: Joe Hershberger joe.hershberger@ni.com cc: Stefan Agner stefan@agner.ch cc: Rasmus Villemoes rasmus.villemoes@prevas.dk Signed-off-by: Anthony Loiseau anthony.loiseau@allcircuits.com --- tools/env/README | 3 +++ tools/env/fw_env.c | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/tools/env/README b/tools/env/README index 480a893202..b8c6a7e197 100644 --- a/tools/env/README +++ b/tools/env/README @@ -58,6 +58,9 @@ DEVICEx_ENVSECTORS defines the number of sectors that may be used for this environment instance. On NAND this is used to limit the range within which bad blocks are skipped, on NOR it is not used.
+If DEVICEx_ESIZE and DEVICEx_ENVSECTORS are both zero, then a runtime +detection is attempted for NOR and NAND mtd types. + To prevent losing changes to the environment and to prevent confusing the MTD drivers, a lock file at /run/fw_printenv.lock is used to serialize access to the environment. diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c index c9a8774ace..9f57f19d80 100644 --- a/tools/env/fw_env.c +++ b/tools/env/fw_env.c @@ -1659,8 +1659,15 @@ static int check_device_config(int dev) } DEVTYPE(dev) = mtdinfo.type; if (DEVESIZE(dev) == 0 && ENVSECTORS(dev) == 0 && - mtdinfo.type == MTD_NORFLASH) - DEVESIZE(dev) = mtdinfo.erasesize; + mtdinfo.erasesize > 0) { + if (mtdinfo.type == MTD_NORFLASH) + DEVESIZE(dev) = mtdinfo.erasesize; + else if (mtdinfo.type == MTD_NANDFLASH) { + DEVESIZE(dev) = mtdinfo.erasesize; + ENVSECTORS(dev) = + mtdinfo.size / mtdinfo.erasesize; + } + } if (DEVESIZE(dev) == 0) /* Assume the erase size is the same as the env-size */ DEVESIZE(dev) = ENVSIZE(dev);

On Thu, Dec 21, 2023 at 11:44:38PM +0100, Anthony Loiseau wrote:
From: Anthony Loiseau anthony.loiseau@allcircuits.com
As already done for NOR chips, if device ESIZE and ENVSECTORS static configurations are both zero, then autodetect them at runtime.
Cc: Joe Hershberger joe.hershberger@ni.com cc: Stefan Agner stefan@agner.ch cc: Rasmus Villemoes rasmus.villemoes@prevas.dk Signed-off-by: Anthony Loiseau anthony.loiseau@allcircuits.com
Applied to u-boot/next, thanks!
participants (2)
-
Anthony Loiseau
-
Tom Rini