summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMing Liu <ming.liu@toradex.com>2020-08-05 19:15:34 +0200
committerMing Liu <ming.liu@toradex.com>2020-08-09 10:06:53 +0200
commit43e1bb53dd46cae7eaf5c253a343da5a1bebfca9 (patch)
tree06657fec3af502750528fcb7f2b8b8658c5087d7
parentcdcf6c6c538f4458e798530762d9d1b0db510f7a (diff)
libubootenv: fix several issues
- We dont want to store to device when fw_setenv is called and there is no value change, to avoid flash wear-out. - We are using symbolic links in /etc/fw_env.config, libubootenv should handle that. - u-boot-default-env is being referred by libubootenv, add it to RRECOMMENDS_${PN}-bin tor target build. Related-to: ELB-2552 Signed-off-by: Ming Liu <ming.liu@toradex.com>
-rw-r--r--recipes-bsp/u-boot/libubootenv/0001-Dont-store-to-device-if-no-value-changes.patch68
-rw-r--r--recipes-bsp/u-boot/libubootenv/0001-uboot_env-Use-canonicalized-pathname-when-reading-de.patch60
-rw-r--r--recipes-bsp/u-boot/libubootenv_%.bbappend8
3 files changed, 136 insertions, 0 deletions
diff --git a/recipes-bsp/u-boot/libubootenv/0001-Dont-store-to-device-if-no-value-changes.patch b/recipes-bsp/u-boot/libubootenv/0001-Dont-store-to-device-if-no-value-changes.patch
new file mode 100644
index 0000000..d6294e1
--- /dev/null
+++ b/recipes-bsp/u-boot/libubootenv/0001-Dont-store-to-device-if-no-value-changes.patch
@@ -0,0 +1,68 @@
+From ad5444c5498cb8e12c874488be45a29369fc6532 Mon Sep 17 00:00:00 2001
+From: Ming Liu <liu.ming50@gmail.com>
+Date: Thu, 30 Jul 2020 14:16:24 +0200
+Subject: [PATCH] Dont store to device if no value changes
+
+Upstream-Status: Submitted
+
+When fw_setenv is called, it could happen that the new value is same
+with the old one, in which case, we should avoid storing data to
+device.
+
+Reference:
+http://patchwork.ozlabs.org/project/swupdate/patch/20200804202120.31374-1-liu.ming50@gmail.com/
+
+Signed-off-by: Ming Liu <liu.ming50@gmail.com>
+---
+ src/fw_printenv.c | 31 ++++++++++++++++++++++---------
+ 1 file changed, 22 insertions(+), 9 deletions(-)
+
+diff --git a/src/fw_printenv.c b/src/fw_printenv.c
+index 18887f9..8b830d5 100644
+--- a/src/fw_printenv.c
++++ b/src/fw_printenv.c
+@@ -151,19 +151,32 @@ int main (int argc, char **argv) {
+ }
+ }
+ } else { /* setenv branch */
+- if (scriptfile)
++ bool need_store = false;
++ if (scriptfile) {
+ libuboot_load_file(ctx, scriptfile);
+- else {
++ need_store = true;
++ } else {
+ for (i = 0; i < argc; i += 2) {
+- if (i + 1 == argc)
+- libuboot_set_env(ctx, argv[i], NULL);
+- else
+- libuboot_set_env(ctx, argv[i], argv[i+1]);
++ value = libuboot_get_env(ctx, argv[i]);
++ if (i + 1 == argc) {
++ if (value != NULL) {
++ libuboot_set_env(ctx, argv[i], NULL);
++ need_store = true;
++ }
++ } else {
++ if (value == NULL || strcmp(value, argv[i+1]) != 0) {
++ libuboot_set_env(ctx, argv[i], argv[i+1]);
++ need_store = true;
++ }
++ }
+ }
+ }
+- ret = libuboot_env_store(ctx);
+- if (ret)
+- fprintf(stderr, "Error storing the env\n");
++
++ if (need_store) {
++ ret = libuboot_env_store(ctx);
++ if (ret)
++ fprintf(stderr, "Error storing the env\n");
++ }
+ }
+
+ libuboot_close(ctx);
+--
+2.28.0
+
diff --git a/recipes-bsp/u-boot/libubootenv/0001-uboot_env-Use-canonicalized-pathname-when-reading-de.patch b/recipes-bsp/u-boot/libubootenv/0001-uboot_env-Use-canonicalized-pathname-when-reading-de.patch
new file mode 100644
index 0000000..ed08cc3
--- /dev/null
+++ b/recipes-bsp/u-boot/libubootenv/0001-uboot_env-Use-canonicalized-pathname-when-reading-de.patch
@@ -0,0 +1,60 @@
+From 7f8564ad2702a95b496ffaae86afe33ee987af29 Mon Sep 17 00:00:00 2001
+From: Ming Liu <liu.ming50@gmail.com>
+Date: Sat, 30 May 2020 20:56:42 +0200
+Subject: [PATCH] uboot_env: Use canonicalized pathname when reading device
+
+Upstream-Status: Submitted
+
+Some platform uses softlinks to the devices that hold environment
+data. The mechanism used to read device type from config is not robust
+in this case. Calculating the canonicalized absolute pathname of the
+device could fix the problem.
+
+Reference:
+https://patchwork.ozlabs.org/project/swupdate/patch/20200729193959.23115-1-liu.ming50@gmail.com/
+
+Signed-off-by: Mathias Thore <mathias.thore@atlascopco.com>
+Signed-off-by: Ming Liu <liu.ming50@gmail.com>
+---
+ src/uboot_env.c | 10 +++++++++-
+ 1 file changed, 9 insertions(+), 1 deletion(-)
+
+diff --git a/src/uboot_env.c b/src/uboot_env.c
+index f9ffeda..934f1bf 100644
+--- a/src/uboot_env.c
++++ b/src/uboot_env.c
+@@ -20,6 +20,7 @@
+ #include <stddef.h>
+ #include <dirent.h>
+ #include <unistd.h>
++#include <limits.h>
+ #include <linux/fs.h>
+ #include <string.h>
+ #include <fcntl.h>
+@@ -1103,6 +1104,7 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
+ int ndev = 0;
+ struct uboot_flash_env *dev;
+ char *tmp;
++ char *path;
+ int retval = 0;
+
+ if (!config)
+@@ -1145,8 +1147,14 @@ int libuboot_read_config(struct uboot_ctx *ctx, const char *config)
+ ctx->size = dev->envsize;
+
+ if (tmp) {
+- strncpy(dev->devname, tmp, sizeof(dev->devname));
++ if ((path = realpath(tmp, NULL)) == NULL) {
++ free(tmp);
++ retval = -EINVAL;
++ break;
++ }
++ strncpy(dev->devname, path, sizeof(dev->devname));
+ free(tmp);
++ free(path);
+ }
+
+ if (check_env_device(ctx, dev) < 0) {
+--
+2.28.0
+
diff --git a/recipes-bsp/u-boot/libubootenv_%.bbappend b/recipes-bsp/u-boot/libubootenv_%.bbappend
new file mode 100644
index 0000000..1237040
--- /dev/null
+++ b/recipes-bsp/u-boot/libubootenv_%.bbappend
@@ -0,0 +1,8 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/${BPN}:"
+
+SRC_URI_append = " \
+ file://0001-Dont-store-to-device-if-no-value-changes.patch \
+ file://0001-uboot_env-Use-canonicalized-pathname-when-reading-de.patch \
+"
+
+RRECOMMENDS_${PN}-bin_class-target += "u-boot-default-env"