uboot-envtools: backport some usefull patches from v2024.04-rc1
authorShiji Yang <yangshiji66@qq.com>
Sat, 10 Feb 2024 13:47:40 +0000 (13:47 +0000)
committerNick Hainke <vincent@systemli.org>
Sun, 11 Feb 2024 09:48:59 +0000 (10:48 +0100)
Highlights:
- Silence small page read warning.
- Autodetect NAND erase size and env sectors.

Signed-off-by: Shiji Yang <yangshiji66@qq.com>
package/boot/uboot-envtools/Makefile
package/boot/uboot-envtools/patches/011-fw_env-keep-calling-read-until-whole-flash-block-is-.patch [new file with mode: 0644]
package/boot/uboot-envtools/patches/012-fw_env-autodetect-NAND-erase-size-and-env-sectors.patch [new file with mode: 0644]

index 4ea93f9c791bb07c124a95226e22d3ac485f35f8..00aa4241625f52784ce22fc43db54ea530b78a2e 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=uboot-envtools
 PKG_DISTNAME:=u-boot
 PKG_VERSION:=2024.01
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE:=$(PKG_DISTNAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:= \
diff --git a/package/boot/uboot-envtools/patches/011-fw_env-keep-calling-read-until-whole-flash-block-is-.patch b/package/boot/uboot-envtools/patches/011-fw_env-keep-calling-read-until-whole-flash-block-is-.patch
new file mode 100644 (file)
index 0000000..af1c32f
--- /dev/null
@@ -0,0 +1,75 @@
+From 9e3003f79d168eac7ee65cd457e3904e2fb4eea8 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <rafal@milecki.pl>
+Date: Wed, 13 Dec 2023 13:13:54 +0100
+Subject: [PATCH] fw_env: keep calling read() until whole flash block is read
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+It's totally valid for read() to provide less bytes than requested
+maximum. It may happen if there is no more data available yet or source
+pushes data in small chunks.
+
+This actually happens when trying to read env data from NVMEM device.
+Kernel may provide NVMEM content in page size parts (like 4096 B).
+
+This fixes warnings like:
+Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 16384 bytes but got 4096
+Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 12288 bytes but got 4096
+Warning on /sys/bus/nvmem/devices/u-boot-env0/nvmem: Attempted to read 8192 bytes but got 4096
+
+Since the main loop in flash_read_buf() is used to read blocks this
+patch adds a new nested one.
+
+Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
+---
+ tools/env/fw_env.c | 34 +++++++++++++++-------------------
+ 1 file changed, 15 insertions(+), 19 deletions(-)
+
+--- a/tools/env/fw_env.c
++++ b/tools/env/fw_env.c
+@@ -948,29 +948,25 @@ static int flash_read_buf(int dev, int f
+                */
+               lseek(fd, blockstart + block_seek, SEEK_SET);
+-              rc = read(fd, buf + processed, readlen);
+-              if (rc == -1) {
+-                      fprintf(stderr, "Read error on %s: %s\n",
+-                              DEVNAME(dev), strerror(errno));
+-                      return -1;
+-              }
++              while (readlen) {
++                      rc = read(fd, buf + processed, readlen);
++                      if (rc == -1) {
++                              fprintf(stderr, "Read error on %s: %s\n",
++                                      DEVNAME(dev), strerror(errno));
++                              return -1;
++                      }
+ #ifdef DEBUG
+-              fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n",
+-                      rc, (unsigned long long)blockstart + block_seek,
+-                      DEVNAME(dev));
++                      fprintf(stderr, "Read 0x%x bytes at 0x%llx on %s\n",
++                              rc, (unsigned long long)blockstart + block_seek,
++                              DEVNAME(dev));
+ #endif
+-              processed += rc;
+-              if (rc != readlen) {
+-                      fprintf(stderr,
+-                              "Warning on %s: Attempted to read %zd bytes but got %d\n",
+-                              DEVNAME(dev), readlen, rc);
++                      processed += rc;
+                       readlen -= rc;
+-                      block_seek += rc;
+-              } else {
+-                      blockstart += blocklen;
+-                      readlen = min(blocklen, count - processed);
+-                      block_seek = 0;
+               }
++
++              blockstart += blocklen;
++              readlen = min(blocklen, count - processed);
++              block_seek = 0;
+       }
+       return processed;
diff --git a/package/boot/uboot-envtools/patches/012-fw_env-autodetect-NAND-erase-size-and-env-sectors.patch b/package/boot/uboot-envtools/patches/012-fw_env-autodetect-NAND-erase-size-and-env-sectors.patch
new file mode 100644 (file)
index 0000000..78f555f
--- /dev/null
@@ -0,0 +1,49 @@
+From d73a6641868029b5cae53ed00c5766921c9d8b1f Mon Sep 17 00:00:00 2001
+From: Anthony Loiseau <anthony.loiseau@allcircuits.com>
+Date: Thu, 21 Dec 2023 23:44:38 +0100
+Subject: [PATCH] fw_env: autodetect NAND erase size and env sectors
+
+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(-)
+
+--- a/tools/env/README
++++ b/tools/env/README
+@@ -58,6 +58,9 @@ DEVICEx_ENVSECTORS defines the number of
+ 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.
+--- a/tools/env/fw_env.c
++++ b/tools/env/fw_env.c
+@@ -1655,8 +1655,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);