u-boot-fw-utils: update to version 2018.07

Update u-boot-fw-utils patches to apply on current upstream version. Remove
recipe for version 2017.09 since both U-Boot v2017.03 and v2018.03 work fine
with the newer version.

https://jira.digi.com/browse/DUB-881

Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
This commit is contained in:
Gonzalo Ruiz 2019-03-19 18:01:40 +01:00
parent 4803dba689
commit c0065f64e3
8 changed files with 112 additions and 167 deletions

View File

@ -1,15 +0,0 @@
HOMEPAGE = "http://www.denx.de/wiki/U-Boot/WebHome"
SECTION = "bootloaders"
LICENSE = "GPLv2+"
LIC_FILES_CHKSUM = "file://Licenses/README;md5=a2c678cfd4a4d97135585cad908541c6"
PE = "1"
# We use the revision in order to avoid having to fetch it from the
# repo during parse
SRCREV = "c98ac3487e413c71e5d36322ef3324b21c6f60f9"
SRC_URI = "git://git.denx.de/u-boot.git \
"
S = "${WORKDIR}/git"

View File

@ -6,39 +6,40 @@ Subject: [PATCH 1/4] tools: env: implement support for environment encryption
https://jira.digi.com/browse/DEL-2836 https://jira.digi.com/browse/DEL-2836
Signed-off-by: Diaz de Grenu, Jose <Jose.DiazdeGrenu@digi.com> Signed-off-by: Diaz de Grenu, Jose <Jose.DiazdeGrenu@digi.com>
Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
--- ---
configs/sandbox_defconfig | 1 + configs/sandbox_defconfig | 1 +
tools/env/Makefile | 2 +- tools/env/Makefile | 2 +-
tools/env/caam_keyblob.h | 45 +++++++++++++++ tools/env/caam_keyblob.h | 45 +++++++++++++++
tools/env/fw_env.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++ tools/env/fw_env.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 186 insertions(+), 1 deletion(-) 4 files changed, 187 insertions(+), 1 deletion(-)
create mode 100644 tools/env/caam_keyblob.h create mode 100644 tools/env/caam_keyblob.h
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 4c4e4809be76..82ebe96067b5 100644 index 2fc84a1..f033d9c 100644
--- a/configs/sandbox_defconfig --- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig
@@ -193,3 +193,4 @@ CONFIG_UNIT_TEST=y @@ -200,3 +200,4 @@ CONFIG_UT_TIME=y
CONFIG_UT_TIME=y
CONFIG_UT_DM=y CONFIG_UT_DM=y
CONFIG_UT_ENV=y CONFIG_UT_ENV=y
CONFIG_UT_OVERLAY=y
+CONFIG_MD5=y +CONFIG_MD5=y
diff --git a/tools/env/Makefile b/tools/env/Makefile diff --git a/tools/env/Makefile b/tools/env/Makefile
index 95b28c0b3a3c..c10ff66c7772 100644 index 4633e0e..33e41f5 100644
--- a/tools/env/Makefile --- a/tools/env/Makefile
+++ b/tools/env/Makefile +++ b/tools/env/Makefile
@@ -25,7 +25,7 @@ hostprogs-y := fw_printenv @@ -23,7 +23,7 @@ hostprogs-y := fw_printenv
lib-y += fw_env.o \ lib-y += fw_env.o \
crc32.o ctype.o linux_string.o \ crc32.o ctype.o linux_string.o \
- env_attr.o env_flags.o aes.o - env_attr.o env_flags.o
+ env_attr.o env_flags.o aes.o ../../lib/md5.o + env_attr.o env_flags.o ../../lib/md5.o
fw_printenv-objs := fw_env_main.o $(lib-y) fw_printenv-objs := fw_env_main.o $(lib-y)
diff --git a/tools/env/caam_keyblob.h b/tools/env/caam_keyblob.h diff --git a/tools/env/caam_keyblob.h b/tools/env/caam_keyblob.h
new file mode 100644 new file mode 100644
index 000000000000..1cdf3946c1ba index 0000000..1cdf394
--- /dev/null --- /dev/null
+++ b/tools/env/caam_keyblob.h +++ b/tools/env/caam_keyblob.h
@@ -0,0 +1,45 @@ @@ -0,0 +1,45 @@
@ -88,7 +89,7 @@ index 000000000000..1cdf3946c1ba
+ +
+#endif /* CAAM_KEYBLOB_H */ +#endif /* CAAM_KEYBLOB_H */
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index ab06415898c2..de2e693e9f93 100644 index a5d7595..b124b1e 100644
--- a/tools/env/fw_env.c --- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c +++ b/tools/env/fw_env.c
@@ -24,6 +24,7 @@ @@ -24,6 +24,7 @@
@ -97,16 +98,16 @@ index ab06415898c2..de2e693e9f93 100644
#include <sys/stat.h> #include <sys/stat.h>
+#include <u-boot/md5.h> +#include <u-boot/md5.h>
#include <unistd.h> #include <unistd.h>
#include <dirent.h>
#ifdef MTD_OLD
@@ -34,9 +35,19 @@ @@ -37,9 +38,19 @@
# include <mtd/mtd-user.h>
#endif #include <mtd/ubi-user.h>
+#include "caam_keyblob.h" +#include "caam_keyblob.h"
#include "fw_env_private.h" #include "fw_env_private.h"
#include "fw_env.h" #include "fw_env.h"
+/* +/*
+ * The BLOB includes a random AES-256 key (32 bytes) and a + * The BLOB includes a random AES-256 key (32 bytes) and a
+ * Message Authentication Code (MAC) (16 bytes) + * Message Authentication Code (MAC) (16 bytes)
@ -119,19 +120,18 @@ index ab06415898c2..de2e693e9f93 100644
struct env_opts default_opts = { struct env_opts default_opts = {
#ifdef CONFIG_FILE #ifdef CONFIG_FILE
.config_file = CONFIG_FILE .config_file = CONFIG_FILE
@@ -113,6 +124,8 @@ static struct environment environment = { @@ -117,6 +128,7 @@ static struct environment environment = {
};
static int env_aes_cbc_crypt(char *data, const int enc, uint8_t *key);
static int have_redund_env;
+static int caam_encryption_flag; +static int caam_encryption_flag;
+
static int HaveRedundEnv = 0;
static unsigned char active_flag = 1; static unsigned char active_flag = 1;
@@ -245,6 +258,103 @@ int parse_aes_key(char *key, uint8_t *bin_key) /* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
return 0; @@ -442,6 +454,103 @@ char *fw_getdefenv(char *name)
return NULL;
} }
+static void check_caam_encryption(void) +static void check_caam_encryption(void)
+{ +{
+ const char *dt_prop = "/proc/device-tree/digi,uboot-env,encrypted"; + const char *dt_prop = "/proc/device-tree/digi,uboot-env,encrypted";
@ -232,10 +232,15 @@ index ab06415898c2..de2e693e9f93 100644
/* /*
* Print the current definition of one, or more, or all * Print the current definition of one, or more, or all
* environment variables * environment variables
@@ -323,6 +433,15 @@ int fw_env_flush(struct env_opts *opts) @@ -505,9 +614,20 @@ int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts)
}
} int fw_env_flush(struct env_opts *opts)
{
+ int ret;
+
if (!opts)
opts = &default_opts;
+ if (caam_encryption_flag) { + if (caam_encryption_flag) {
+ ret = env_caam_crypt(environment.data, 1); + ret = env_caam_crypt(environment.data, 1);
+ if (ret) { + if (ret) {
@ -248,19 +253,19 @@ index ab06415898c2..de2e693e9f93 100644
/* /*
* Update CRC * Update CRC
*/ */
@@ -1144,6 +1263,8 @@ int fw_env_open(struct env_opts *opts) @@ -1396,6 +1516,8 @@ int fw_env_open(struct env_opts *opts)
struct env_image_single *single; struct env_image_single *single;
struct env_image_redundant *redundant; struct env_image_redundant *redundant;
+ check_caam_encryption(); + check_caam_encryption();
+ +
if (!opts) if (!opts)
opts = &default_opts; opts = &default_opts;
@@ -1189,6 +1310,15 @@ int fw_env_open(struct env_opts *opts) @@ -1434,6 +1556,15 @@ int fw_env_open(struct env_opts *opts)
goto open_cleanup;
} crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE);
+ if (caam_encryption_flag) { + if (caam_encryption_flag) {
+ ret = env_caam_crypt(environment.data, 0); + ret = env_caam_crypt(environment.data, 0);
+ if (ret) { + if (ret) {
@ -271,12 +276,12 @@ index ab06415898c2..de2e693e9f93 100644
+ } + }
+ +
crc0_ok = (crc0 == *environment.crc); crc0_ok = (crc0 == *environment.crc);
if (!HaveRedundEnv) { if (!have_redund_env) {
if (!crc0_ok) { if (!crc0_ok) {
@@ -1251,6 +1381,15 @@ int fw_env_open(struct env_opts *opts) @@ -1491,6 +1622,15 @@ int fw_env_open(struct env_opts *opts)
goto open_cleanup;
} crc1 = crc32(0, (uint8_t *)redundant->data, ENV_SIZE);
+ if (caam_encryption_flag) { + if (caam_encryption_flag) {
+ ret = env_caam_crypt(redundant->data, 0); + ret = env_caam_crypt(redundant->data, 0);
+ if (ret) { + if (ret) {
@ -288,4 +293,3 @@ index ab06415898c2..de2e693e9f93 100644
+ +
crc1_ok = (crc1 == redundant->crc); crc1_ok = (crc1 == redundant->crc);
flag1 = redundant->flags; flag1 = redundant->flags;

View File

@ -4,6 +4,7 @@ Subject: [PATCH 2/4] Implement U-Boot environment access functions
Signed-off-by: Javier Viguera <javier.viguera@digi.com> Signed-off-by: Javier Viguera <javier.viguera@digi.com>
Signed-off-by: Jose Diaz de Grenu <Jose.DiazdeGrenu@digi.com> Signed-off-by: Jose Diaz de Grenu <Jose.DiazdeGrenu@digi.com>
Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
--- ---
tools/env/Makefile | 2 +- tools/env/Makefile | 2 +-
tools/env/ubootenv.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/env/ubootenv.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++
@ -13,21 +14,21 @@ Signed-off-by: Jose Diaz de Grenu <Jose.DiazdeGrenu@digi.com>
create mode 100644 tools/env/ubootenv.h create mode 100644 tools/env/ubootenv.h
diff --git a/tools/env/Makefile b/tools/env/Makefile diff --git a/tools/env/Makefile b/tools/env/Makefile
index c10ff66c7772..1d99e3b65dc6 100644 index 33e41f5..486e76c 100644
--- a/tools/env/Makefile --- a/tools/env/Makefile
+++ b/tools/env/Makefile +++ b/tools/env/Makefile
@@ -25,7 +25,7 @@ hostprogs-y := fw_printenv @@ -23,7 +23,7 @@ hostprogs-y := fw_printenv
lib-y += fw_env.o \ lib-y += fw_env.o \
crc32.o ctype.o linux_string.o \ crc32.o ctype.o linux_string.o \
- env_attr.o env_flags.o aes.o ../../lib/md5.o - env_attr.o env_flags.o ../../lib/md5.o
+ env_attr.o env_flags.o aes.o ../../lib/md5.o ubootenv.o + env_attr.o env_flags.o ../../lib/md5.o ubootenv.o
fw_printenv-objs := fw_env_main.o $(lib-y) fw_printenv-objs := fw_env_main.o $(lib-y)
diff --git a/tools/env/ubootenv.c b/tools/env/ubootenv.c diff --git a/tools/env/ubootenv.c b/tools/env/ubootenv.c
new file mode 100644 new file mode 100644
index 000000000000..eb9ad5fce097 index 0000000..eb9ad5f
--- /dev/null --- /dev/null
+++ b/tools/env/ubootenv.c +++ b/tools/env/ubootenv.c
@@ -0,0 +1,66 @@ @@ -0,0 +1,66 @@
@ -99,7 +100,7 @@ index 000000000000..eb9ad5fce097
+} +}
diff --git a/tools/env/ubootenv.h b/tools/env/ubootenv.h diff --git a/tools/env/ubootenv.h b/tools/env/ubootenv.h
new file mode 100644 new file mode 100644
index 000000000000..d4043db75372 index 0000000..d4043db
--- /dev/null --- /dev/null
+++ b/tools/env/ubootenv.h +++ b/tools/env/ubootenv.h
@@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@

View File

@ -4,18 +4,17 @@ Subject: [PATCH 3/4] fw_env: add support to unlock emmc boot partition
Signed-off-by: Javier Viguera <javier.viguera@digi.com> Signed-off-by: Javier Viguera <javier.viguera@digi.com>
Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com> Signed-off-by: Arturo Buzarra <arturo.buzarra@digi.com>
Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
--- ---
tools/env/fw_env.c | 39 +++++++++++++++++++++++++++++++++++++++ tools/env/fw_env.c | 38 ++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+) 1 file changed, 38 insertions(+)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index ab06415898..5ebd7d6208 100644 index b124b1e..b87cd83 100644
--- a/tools/env/fw_env.c --- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c +++ b/tools/env/fw_env.c
@@ -1052,13 +1052,42 @@ static int flash_read (int fd) @@ -1383,10 +1383,39 @@ err:
return -1; return rc;
return 0;
} }
+/* +/*
@ -46,44 +45,34 @@ index ab06415898..5ebd7d6208 100644
+ return 0; + return 0;
+} +}
+ +
static int flash_io (int mode) static int flash_io_write(int fd_current)
{ {
int fd_current, fd_target, rc, dev_target; int fd_target = -1, rc, dev_target;
const char *dname, *target_temp = NULL;
+ char *mmcblk = NULL; + char *mmcblk = NULL;
/* dev_current: fd_current, erase_current */ if (have_redund_env) {
fd_current = open (DEVNAME (dev_current), mode); /* switch to next partition for writing */
if (fd_current < 0) { @@ -1414,6 +1443,11 @@ static int flash_io_write(int fd_current)
fprintf (stderr,
@@ -1084,10 +1113,15 @@ static int flash_io (int mode)
} else {
dev_target = dev_current;
fd_target = fd_current; fd_target = fd_current;
}
+ /* Disable mmcboot protection if using EMMC (set read-write) */
+ mmcblk = strstr(DEVNAME(dev_target), "mmcblk");
+ if (mmcblk)
+ sysfs_mmcboot_set_protection(mmcblk, 0);
+
rc = flash_write (fd_current, fd_target, dev_target);
if (fsync(fd_current) &&
!(errno == EINVAL || errno == EROFS)) {
fprintf (stderr,
@@ -1109,10 +1143,15 @@ static int flash_io (int mode)
DEVNAME (dev_target),
strerror (errno));
rc = -1;
}
}
+
+ /* Re-enable mmcboot protection (set read-only) */
+ if (mmcblk)
+ sysfs_mmcboot_set_protection(mmcblk, 1);
+
} else {
rc = flash_read (fd_current);
} }
exit: + /* Disable mmcboot protection if using EMMC (set read-write) */
+ mmcblk = strstr(DEVNAME(dev_target), "mmcblk");
+ if (mmcblk)
+ sysfs_mmcboot_set_protection(mmcblk, 0);
+
rc = flash_write(fd_current, fd_target, dev_target);
if (fsync(fd_current) && !(errno == EINVAL || errno == EROFS)) {
@@ -1465,6 +1499,10 @@ static int flash_io_write(int fd_current)
dname, strerror(errno));
}
}
+
+ /* Re-enable mmcboot protection (set read-only) */
+ if (mmcblk)
+ sysfs_mmcboot_set_protection(mmcblk, 1);
exit:
return rc;
}

View File

@ -1,6 +1,6 @@
From: Hector Palacios <hector.palacios@digi.com> From: Hector Palacios <hector.palacios@digi.com>
Date: Mon, 22 Jan 2018 10:18:18 +0100 Date: Mon, 22 Jan 2018 10:18:18 +0100
Subject: [PATCH] tools: env: add support to set dynamic location of Subject: [PATCH 4/4] tools: env: add support to set dynamic location of
environment copies environment copies
A mechanism was added in U-Boot to set the location of environment copies A mechanism was added in U-Boot to set the location of environment copies
@ -18,27 +18,28 @@ of the area, like in this example:
Signed-off-by: Hector Palacios <hector.palacios@digi.com> Signed-off-by: Hector Palacios <hector.palacios@digi.com>
https://jira.digi.com/browse/DUB-741 https://jira.digi.com/browse/DUB-741
Signed-off-by: Gonzalo Ruiz <Gonzalo.Ruiz@digi.com>
--- ---
tools/env/fw_env.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tools/env/fw_env.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+) 1 file changed, 87 insertions(+)
diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
index db1182c7216e..820feb3946f5 100644 index b87cd83..041dc1b 100644
--- a/tools/env/fw_env.c --- a/tools/env/fw_env.c
+++ b/tools/env/fw_env.c +++ b/tools/env/fw_env.c
@@ -127,6 +127,8 @@ static int env_aes_cbc_crypt(char *data, const int enc, uint8_t *key); @@ -129,6 +129,8 @@ static struct environment environment = {
static int have_redund_env;
static int caam_encryption_flag; static int caam_encryption_flag;
static int HaveRedundEnv = 0;
+static int have_dynamic_env; +static int have_dynamic_env;
+static off_t top_of_range; /* end of the last block we may use */ +static off_t top_of_range; /* end of the last block we may use */
static unsigned char active_flag = 1; static unsigned char active_flag = 1;
/* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */ /* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */
@@ -847,6 +849,22 @@ static int flash_read_buf (int dev, int fd, void *buf, size_t count, @@ -1031,6 +1033,22 @@ static int flash_read_buf(int dev, int fd, void *buf, size_t count,
*/ */
blocklen = DEVESIZE (dev); blocklen = DEVESIZE(dev);
+ if (!have_dynamic_env) { + if (!have_dynamic_env) {
+ /* + /*
+ * To calculate the top of the range, we have to use the + * To calculate the top of the range, we have to use the
@ -58,10 +59,10 @@ index db1182c7216e..820feb3946f5 100644
/* Limit to one block for the first read */ /* Limit to one block for the first read */
if (readlen > blocklen - block_seek) if (readlen > blocklen - block_seek)
readlen = blocklen - block_seek; readlen = blocklen - block_seek;
@@ -1194,6 +1212,63 @@ static int sysfs_mmcboot_set_protection(const char *device, int value) @@ -1411,6 +1429,63 @@ static int sysfs_mmcboot_set_protection(const char *device, int value)
return 0; return 0;
} }
+static int set_dynamic_location(void) +static int set_dynamic_location(void)
+{ +{
+ int fd, i, nsectors; + int fd, i, nsectors;
@ -70,7 +71,7 @@ index db1182c7216e..820feb3946f5 100644
+ int copies = 1; + int copies = 1;
+ int rc = 0; + int rc = 0;
+ +
+ if (HaveRedundEnv) + if (have_redund_env)
+ copies++; + copies++;
+ +
+ fd = open(DEVNAME(dev), O_RDONLY); + fd = open(DEVNAME(dev), O_RDONLY);
@ -119,18 +120,18 @@ index db1182c7216e..820feb3946f5 100644
+ return rc; + return rc;
+} +}
+ +
static int flash_io (int mode) static int flash_io_write(int fd_current)
{ {
int fd_current, fd_target, rc, dev_target; int fd_target = -1, rc, dev_target;
@@ -1327,6 +1402,18 @@ int fw_env_open(struct env_opts *opts) @@ -1586,6 +1661,18 @@ int fw_env_open(struct env_opts *opts)
environment.data = single->data; environment.data = single->data;
} }
+ /* + /*
+ * Trigger dynamic location of environment if redundant copy has the + * Trigger dynamic location of environment if redundant copy has the
+ * same offset than primary copy. + * same offset than primary copy.
+ */ + */
+ if (HaveRedundEnv && (DEVOFFSET(0) == DEVOFFSET(1))) { + if (have_redund_env && (DEVOFFSET(0) == DEVOFFSET(1))) {
+ have_dynamic_env = 1; + have_dynamic_env = 1;
+ top_of_range = DEVOFFSET(0) + (ENVSECTORS(0) * DEVESIZE(0)); + top_of_range = DEVOFFSET(0) + (ENVSECTORS(0) * DEVESIZE(0));
+ +

View File

@ -1,34 +0,0 @@
require u-boot-common_${PV}.inc
SUMMARY = "U-Boot bootloader fw_printenv/setenv utilities"
DEPENDS = "mtd-utils"
INSANE_SKIP_${PN} = "already-stripped"
EXTRA_OEMAKE_class-target = 'CROSS_COMPILE=${TARGET_PREFIX} CC="${CC} ${CFLAGS} ${LDFLAGS}" HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" V=1'
EXTRA_OEMAKE_class-cross = 'HOSTCC="${CC} ${CFLAGS} ${LDFLAGS}" V=1'
inherit uboot-config
do_compile () {
oe_runmake ${UBOOT_MACHINE}
oe_runmake envtools
}
do_install () {
install -d ${D}${base_sbindir}
install -d ${D}${sysconfdir}
install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_printenv
install -m 755 ${S}/tools/env/fw_printenv ${D}${base_sbindir}/fw_setenv
install -m 0644 ${S}/tools/env/fw_env.config ${D}${sysconfdir}/fw_env.config
}
do_install_class-cross () {
install -d ${D}${bindir_cross}
install -m 755 ${S}/tools/env/fw_printenv ${D}${bindir_cross}/fw_printenv
install -m 755 ${S}/tools/env/fw_printenv ${D}${bindir_cross}/fw_setenv
}
SYSROOT_DIRS_append_class-cross = " ${bindir_cross}"
PACKAGE_ARCH = "${MACHINE_ARCH}"
BBCLASSEXTEND = "cross"

View File

@ -64,7 +64,6 @@ PREFERRED_VERSION_linux-yocto ?= "4.18%"
# Some features (swupdate, environment encryption) depends on this specific # Some features (swupdate, environment encryption) depends on this specific
# provider for u-boot-fw-tools # provider for u-boot-fw-tools
PREFERRED_PROVIDER_u-boot-fw-utils ?= "u-boot-fw-utils" PREFERRED_PROVIDER_u-boot-fw-utils ?= "u-boot-fw-utils"
PREFERRED_VERSION_u-boot-fw-utils ?= "2017.09"
# Use git recipe for libsoc # Use git recipe for libsoc
PREFERRED_VERSION_libsoc = "git" PREFERRED_VERSION_libsoc = "git"