From f2dcb7fea00cf86a57212c3dbf91cbbbb2cd585b Mon Sep 17 00:00:00 2001 From: Javier Viguera Date: Tue, 1 Apr 2014 19:08:40 +0200 Subject: [PATCH] u-boot-fw-utils: support unlocking EMMC boot partition By default EMMC boot partition is locked. This prevents fw_setenv utility to configure the u-boot environment from Linux. This commit adds a patch that unlocks the EMMC boot partition just before writing into it and then locks it again once the environment is written. https://jira.digi.com/browse/DEL-1021 Signed-off-by: Javier Viguera --- ...upport-to-unlock-emmc-boot-partition.patch | 62 +++++++++++++++++++ .../u-boot/u-boot-dey-fw-utils_2013.04.bb | 5 +- 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils-2013.04/0001-fw_env-add-support-to-unlock-emmc-boot-partition.patch diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils-2013.04/0001-fw_env-add-support-to-unlock-emmc-boot-partition.patch b/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils-2013.04/0001-fw_env-add-support-to-unlock-emmc-boot-partition.patch new file mode 100644 index 000000000..42729bd3e --- /dev/null +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils-2013.04/0001-fw_env-add-support-to-unlock-emmc-boot-partition.patch @@ -0,0 +1,62 @@ +From: Javier Viguera +Date: Tue, 1 Apr 2014 18:43:07 +0200 +Subject: [PATCH] fw_env: add support to unlock emmc boot partition + +Signed-off-by: Javier Viguera +--- + tools/env/fw_env.c | 33 +++++++++++++++++++++++++++++++++ + 1 file changed, 33 insertions(+) + +diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c +index 12fe7539d2f9..395c5351c9a0 100644 +--- a/tools/env/fw_env.c ++++ b/tools/env/fw_env.c +@@ -1001,6 +1001,27 @@ static int flash_read (int fd) + return (rc != CUR_ENVSIZE) ? -1 : 0; + } + ++/* ++ * Set mmcboot partition read-write protection ++ */ ++static int sysfs_mmcboot_set_protection(char *device, int value) ++{ ++ int fd; ++ char buf[64]; ++ ++ snprintf(buf, sizeof(buf), "/sys/block/%s/force_ro", device); ++ fd = open(buf, O_WRONLY); ++ if (fd < 0) { ++ perror("sysfs_mmcboot_set_protection"); ++ return fd; ++ } ++ snprintf(buf, sizeof(buf), "%s", value ? "1" : "0"); ++ write(fd, buf, 2); ++ close(fd); ++ ++ return 0; ++} ++ + static int flash_io (int mode) + { + int fd_current, fd_target, rc, dev_target; +@@ -1033,8 +1054,20 @@ static int flash_io (int mode) + fd_target = fd_current; + } + ++ /* ++ * Disable mmcboot protection (set read-write) ++ * ++ * In a CCIMX6 dev_current and dev_target is the same device so it's ok to ++ * just use dev_current here. ++ * ++ */ ++ sysfs_mmcboot_set_protection(DEVNAME(dev_current) + 5 /* /dev/ */ , 0); ++ + rc = flash_write (fd_current, fd_target, dev_target); + ++ /* Re-enable mmcboot protection (set read-only) */ ++ sysfs_mmcboot_set_protection(DEVNAME(dev_current) + 5 /* /dev/ */ , 1); ++ + if (HaveRedundEnv) { + if (close (fd_target)) { + fprintf (stderr, diff --git a/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils_2013.04.bb b/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils_2013.04.bb index 20ad8402d..2b9e6363a 100644 --- a/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils_2013.04.bb +++ b/meta-digi-arm/recipes-bsp/u-boot/u-boot-dey-fw-utils_2013.04.bb @@ -5,7 +5,10 @@ SECTION = "bootloader" include u-boot-dey-rev_${PV}.inc -SRC_URI += "file://fw_env.config" +SRC_URI += " \ + file://0001-fw_env-add-support-to-unlock-emmc-boot-partition.patch \ + file://fw_env.config \ +" S = "${WORKDIR}/git"