From c0065f64e37e5e3b7189edc9901c5d16b4d14cf9 Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz Date: Tue, 19 Mar 2019 18:01:40 +0100 Subject: [PATCH] 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 --- .../u-boot/u-boot-common_2017.09.inc | 15 --- ...ent-support-for-environment-encrypti.patch | 100 +++++++++--------- ...-U-Boot-environment-access-functions.patch | 19 ++-- ...upport-to-unlock-emmc-boot-partition.patch | 73 ++++++------- ...pport-to-set-dynamic-location-of-env.patch | 37 +++---- ....%.bbappend => u-boot-fw-utils_%.bbappend} | 0 .../u-boot/u-boot-fw-utils_2017.09.bb | 34 ------ meta-digi-dey/conf/distro/dey.conf | 1 - 8 files changed, 112 insertions(+), 167 deletions(-) delete mode 100644 meta-digi-arm/recipes-bsp/u-boot/u-boot-common_2017.09.inc rename meta-digi-arm/recipes-bsp/u-boot/{u-boot-fw-utils_2017.%.bbappend => u-boot-fw-utils_%.bbappend} (100%) delete mode 100644 meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.09.bb diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-common_2017.09.inc b/meta-digi-arm/recipes-bsp/u-boot/u-boot-common_2017.09.inc deleted file mode 100644 index 390e7a965..000000000 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-common_2017.09.inc +++ /dev/null @@ -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" diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0001-tools-env-implement-support-for-environment-encrypti.patch b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0001-tools-env-implement-support-for-environment-encrypti.patch index 3dc6f1f80..b9b75f12e 100644 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0001-tools-env-implement-support-for-environment-encrypti.patch +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0001-tools-env-implement-support-for-environment-encrypti.patch @@ -6,39 +6,40 @@ Subject: [PATCH 1/4] tools: env: implement support for environment encryption https://jira.digi.com/browse/DEL-2836 Signed-off-by: Diaz de Grenu, Jose +Signed-off-by: Gonzalo Ruiz --- configs/sandbox_defconfig | 1 + tools/env/Makefile | 2 +- tools/env/caam_keyblob.h | 45 +++++++++++++++ - tools/env/fw_env.c | 139 ++++++++++++++++++++++++++++++++++++++++++++++ - 4 files changed, 186 insertions(+), 1 deletion(-) + tools/env/fw_env.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++ + 4 files changed, 187 insertions(+), 1 deletion(-) create mode 100644 tools/env/caam_keyblob.h diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig -index 4c4e4809be76..82ebe96067b5 100644 +index 2fc84a1..f033d9c 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig -@@ -193,3 +193,4 @@ CONFIG_UNIT_TEST=y - CONFIG_UT_TIME=y +@@ -200,3 +200,4 @@ CONFIG_UT_TIME=y CONFIG_UT_DM=y CONFIG_UT_ENV=y + CONFIG_UT_OVERLAY=y +CONFIG_MD5=y diff --git a/tools/env/Makefile b/tools/env/Makefile -index 95b28c0b3a3c..c10ff66c7772 100644 +index 4633e0e..33e41f5 100644 --- a/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 \ crc32.o ctype.o linux_string.o \ -- env_attr.o env_flags.o aes.o -+ env_attr.o env_flags.o aes.o ../../lib/md5.o - +- env_attr.o env_flags.o ++ env_attr.o env_flags.o ../../lib/md5.o + fw_printenv-objs := fw_env_main.o $(lib-y) - + diff --git a/tools/env/caam_keyblob.h b/tools/env/caam_keyblob.h new file mode 100644 -index 000000000000..1cdf3946c1ba +index 0000000..1cdf394 --- /dev/null +++ b/tools/env/caam_keyblob.h @@ -0,0 +1,45 @@ @@ -88,7 +89,7 @@ index 000000000000..1cdf3946c1ba + +#endif /* CAAM_KEYBLOB_H */ 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 +++ b/tools/env/fw_env.c @@ -24,6 +24,7 @@ @@ -97,16 +98,16 @@ index ab06415898c2..de2e693e9f93 100644 #include +#include #include - - #ifdef MTD_OLD -@@ -34,9 +35,19 @@ - # include - #endif - + #include + +@@ -37,9 +38,19 @@ + + #include + +#include "caam_keyblob.h" #include "fw_env_private.h" #include "fw_env.h" - + +/* + * The BLOB includes a random AES-256 key (32 bytes) and a + * Message Authentication Code (MAC) (16 bytes) @@ -119,19 +120,18 @@ index ab06415898c2..de2e693e9f93 100644 struct env_opts default_opts = { #ifdef CONFIG_FILE .config_file = CONFIG_FILE -@@ -113,6 +124,8 @@ static struct environment environment = { - - static int env_aes_cbc_crypt(char *data, const int enc, uint8_t *key); - +@@ -117,6 +128,7 @@ static struct environment environment = { + }; + + static int have_redund_env; +static int caam_encryption_flag; -+ - static int HaveRedundEnv = 0; - + static unsigned char active_flag = 1; -@@ -245,6 +258,103 @@ int parse_aes_key(char *key, uint8_t *bin_key) - return 0; + /* obsolete_flag must be 0 to efficiently set it on NOR flash without erasing */ +@@ -442,6 +454,103 @@ char *fw_getdefenv(char *name) + return NULL; } - + +static void check_caam_encryption(void) +{ + 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 * 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) { + ret = env_caam_crypt(environment.data, 1); + if (ret) { @@ -248,19 +253,19 @@ index ab06415898c2..de2e693e9f93 100644 /* * 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_redundant *redundant; - + + check_caam_encryption(); + if (!opts) opts = &default_opts; - -@@ -1189,6 +1310,15 @@ int fw_env_open(struct env_opts *opts) - goto open_cleanup; - } - + +@@ -1434,6 +1556,15 @@ int fw_env_open(struct env_opts *opts) + + crc0 = crc32(0, (uint8_t *)environment.data, ENV_SIZE); + + if (caam_encryption_flag) { + ret = env_caam_crypt(environment.data, 0); + if (ret) { @@ -271,12 +276,12 @@ index ab06415898c2..de2e693e9f93 100644 + } + crc0_ok = (crc0 == *environment.crc); - if (!HaveRedundEnv) { + if (!have_redund_env) { if (!crc0_ok) { -@@ -1251,6 +1381,15 @@ int fw_env_open(struct env_opts *opts) - goto open_cleanup; - } - +@@ -1491,6 +1622,15 @@ int fw_env_open(struct env_opts *opts) + + crc1 = crc32(0, (uint8_t *)redundant->data, ENV_SIZE); + + if (caam_encryption_flag) { + ret = env_caam_crypt(redundant->data, 0); + if (ret) { @@ -288,4 +293,3 @@ index ab06415898c2..de2e693e9f93 100644 + crc1_ok = (crc1 == redundant->crc); flag1 = redundant->flags; - diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0002-Implement-U-Boot-environment-access-functions.patch b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0002-Implement-U-Boot-environment-access-functions.patch index 974bbe3cc..63bcc8d7b 100644 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0002-Implement-U-Boot-environment-access-functions.patch +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0002-Implement-U-Boot-environment-access-functions.patch @@ -4,6 +4,7 @@ Subject: [PATCH 2/4] Implement U-Boot environment access functions Signed-off-by: Javier Viguera Signed-off-by: Jose Diaz de Grenu +Signed-off-by: Gonzalo Ruiz --- tools/env/Makefile | 2 +- tools/env/ubootenv.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ @@ -13,21 +14,21 @@ Signed-off-by: Jose Diaz de Grenu create mode 100644 tools/env/ubootenv.h diff --git a/tools/env/Makefile b/tools/env/Makefile -index c10ff66c7772..1d99e3b65dc6 100644 +index 33e41f5..486e76c 100644 --- a/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 \ crc32.o ctype.o linux_string.o \ -- env_attr.o env_flags.o aes.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 ++ env_attr.o env_flags.o ../../lib/md5.o ubootenv.o + fw_printenv-objs := fw_env_main.o $(lib-y) - + diff --git a/tools/env/ubootenv.c b/tools/env/ubootenv.c new file mode 100644 -index 000000000000..eb9ad5fce097 +index 0000000..eb9ad5f --- /dev/null +++ b/tools/env/ubootenv.c @@ -0,0 +1,66 @@ @@ -99,7 +100,7 @@ index 000000000000..eb9ad5fce097 +} diff --git a/tools/env/ubootenv.h b/tools/env/ubootenv.h new file mode 100644 -index 000000000000..d4043db75372 +index 0000000..d4043db --- /dev/null +++ b/tools/env/ubootenv.h @@ -0,0 +1,46 @@ diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0003-fw_env-add-support-to-unlock-emmc-boot-partition.patch b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0003-fw_env-add-support-to-unlock-emmc-boot-partition.patch index 9089605ee..75360b6dd 100644 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0003-fw_env-add-support-to-unlock-emmc-boot-partition.patch +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0003-fw_env-add-support-to-unlock-emmc-boot-partition.patch @@ -4,18 +4,17 @@ Subject: [PATCH 3/4] fw_env: add support to unlock emmc boot partition Signed-off-by: Javier Viguera Signed-off-by: Arturo Buzarra +Signed-off-by: Gonzalo Ruiz --- - tools/env/fw_env.c | 39 +++++++++++++++++++++++++++++++++++++++ - 1 file changed, 39 insertions(+) + tools/env/fw_env.c | 38 ++++++++++++++++++++++++++++++++++++++ + 1 file changed, 38 insertions(+) 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 +++ b/tools/env/fw_env.c -@@ -1052,13 +1052,42 @@ static int flash_read (int fd) - return -1; - - return 0; +@@ -1383,10 +1383,39 @@ err: + return rc; } +/* @@ -46,44 +45,34 @@ index ab06415898..5ebd7d6208 100644 + 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; - /* dev_current: fd_current, erase_current */ - fd_current = open (DEVNAME (dev_current), mode); - if (fd_current < 0) { - fprintf (stderr, -@@ -1084,10 +1113,15 @@ static int flash_io (int mode) - } else { - dev_target = dev_current; + if (have_redund_env) { + /* switch to next partition for writing */ +@@ -1414,6 +1443,11 @@ static int flash_io_write(int 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; + } diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0004-tools-env-add-support-to-set-dynamic-location-of-env.patch b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0004-tools-env-add-support-to-set-dynamic-location-of-env.patch index 34ee46d80..422fd82c5 100644 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0004-tools-env-add-support-to-set-dynamic-location-of-env.patch +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils/0004-tools-env-add-support-to-set-dynamic-location-of-env.patch @@ -1,6 +1,6 @@ From: Hector Palacios 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 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 https://jira.digi.com/browse/DUB-741 +Signed-off-by: Gonzalo Ruiz --- tools/env/fw_env.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) 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 +++ 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 HaveRedundEnv = 0; +static int have_dynamic_env; +static off_t top_of_range; /* end of the last block we may use */ - + static unsigned char active_flag = 1; /* 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) { + /* + * 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 */ if (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; } - + +static int set_dynamic_location(void) +{ + int fd, i, nsectors; @@ -70,7 +71,7 @@ index db1182c7216e..820feb3946f5 100644 + int copies = 1; + int rc = 0; + -+ if (HaveRedundEnv) ++ if (have_redund_env) + copies++; + + fd = open(DEVNAME(dev), O_RDONLY); @@ -119,18 +120,18 @@ index db1182c7216e..820feb3946f5 100644 + return rc; +} + - static int flash_io (int mode) + static int flash_io_write(int fd_current) { - int fd_current, fd_target, rc, dev_target; -@@ -1327,6 +1402,18 @@ int fw_env_open(struct env_opts *opts) - environment.data = single->data; + int fd_target = -1, rc, dev_target; +@@ -1586,6 +1661,18 @@ int fw_env_open(struct env_opts *opts) + environment.data = single->data; } - + + /* + * Trigger dynamic location of environment if redundant copy has the + * same offset than primary copy. + */ -+ if (HaveRedundEnv && (DEVOFFSET(0) == DEVOFFSET(1))) { ++ if (have_redund_env && (DEVOFFSET(0) == DEVOFFSET(1))) { + have_dynamic_env = 1; + top_of_range = DEVOFFSET(0) + (ENVSECTORS(0) * DEVESIZE(0)); + diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.%.bbappend b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_%.bbappend similarity index 100% rename from meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.%.bbappend rename to meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_%.bbappend diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.09.bb b/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.09.bb deleted file mode 100644 index 02887a138..000000000 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-fw-utils_2017.09.bb +++ /dev/null @@ -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" diff --git a/meta-digi-dey/conf/distro/dey.conf b/meta-digi-dey/conf/distro/dey.conf index 6743aaa5e..d4e727d4c 100644 --- a/meta-digi-dey/conf/distro/dey.conf +++ b/meta-digi-dey/conf/distro/dey.conf @@ -64,7 +64,6 @@ PREFERRED_VERSION_linux-yocto ?= "4.18%" # Some features (swupdate, environment encryption) depends on this specific # provider for u-boot-fw-tools PREFERRED_PROVIDER_u-boot-fw-utils ?= "u-boot-fw-utils" -PREFERRED_VERSION_u-boot-fw-utils ?= "2017.09" # Use git recipe for libsoc PREFERRED_VERSION_libsoc = "git"