From d4544a7f433d1cd9d7044e8f7c4cdbe3236c9f14 Mon Sep 17 00:00:00 2001 From: Arturo Buzarra Date: Tue, 18 Oct 2022 16:35:40 +0200 Subject: [PATCH] libubootenv: adapt recipe to platforms with bootloader environment in UBI volume This commit adds support to read bootloader environment from a UBI volume. https://onedigi.atlassian.net/browse/DEL-8133 Signed-off-by: Arturo Buzarra --- meta-digi-arm/conf/machine/ccimx6ulsbc.conf | 5 +++-- meta-digi-arm/conf/machine/ccimx6ulstarter.conf | 5 +++-- meta-digi-arm/conf/machine/ccmp15-dvk.conf | 1 + .../libubootenv/libubootenv/ubi/fw_env.config | 11 +++++++++++ .../recipes-bsp/libubootenv/libubootenv_%.bbappend | 9 +++++++-- 5 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 meta-digi-arm/recipes-bsp/libubootenv/libubootenv/ubi/fw_env.config diff --git a/meta-digi-arm/conf/machine/ccimx6ulsbc.conf b/meta-digi-arm/conf/machine/ccimx6ulsbc.conf index 56cc48f12..44b42f30e 100644 --- a/meta-digi-arm/conf/machine/ccimx6ulsbc.conf +++ b/meta-digi-arm/conf/machine/ccimx6ulsbc.conf @@ -12,10 +12,11 @@ UBOOT_CONFIG[ccimx6ulsbc1GB] = "ccimx6ulsbc1GB_defconfig,,u-boot-dtb.${UBOOT_SUF UBOOT_CONFIG[ccimx6ulsbc512MB] = "ccimx6ulsbc512MB_defconfig,,u-boot-dtb.${UBOOT_SUFFIX}" UBOOT_CONFIG[ccimx6ulsbc] = "ccimx6ulsbc_defconfig,,u-boot-dtb.${UBOOT_SUFFIX}" -# U-Boot environment offset (within partition) -UBOOT_ENV_OFFSET ?= "0x0" # U-Boot environment size UBOOT_ENV_SIZE ?= "0x20000" +# U-Boot environment offset (within partition) +UBOOT_ENV_OFFSET ?= "0x0" +UBOOT_ENV_REDUND_OFFSET ?= "${UBOOT_ENV_SIZE}" # U-Boot environment range: size (in hex) in the environment partition that # the U-Boot environment can take up (if undefined, it will take up all the # available space in the environment partition) diff --git a/meta-digi-arm/conf/machine/ccimx6ulstarter.conf b/meta-digi-arm/conf/machine/ccimx6ulstarter.conf index de232c8cd..178abaa60 100644 --- a/meta-digi-arm/conf/machine/ccimx6ulstarter.conf +++ b/meta-digi-arm/conf/machine/ccimx6ulstarter.conf @@ -12,10 +12,11 @@ UBOOT_CONFIG[ccimx6ulstarter1GB] = "ccimx6ulstarter1GB_defconfig,,u-boot-dtb.${U UBOOT_CONFIG[ccimx6ulstarter512MB] = "ccimx6ulstarter512MB_defconfig,,u-boot-dtb.${UBOOT_SUFFIX}" UBOOT_CONFIG[ccimx6ulstarter] = "ccimx6ulstarter_defconfig,,u-boot-dtb.${UBOOT_SUFFIX}" -# U-Boot environment offset (within partition) -UBOOT_ENV_OFFSET ?= "0x0" # U-Boot environment size UBOOT_ENV_SIZE ?= "0x20000" +# U-Boot environment offset (within partition) +UBOOT_ENV_OFFSET ?= "0x0" +UBOOT_ENV_REDUND_OFFSET ?= "${UBOOT_ENV_SIZE}" # U-Boot environment range: size (in hex) in the environment partition that # the U-Boot environment can take up (if undefined, it will take up all the # available space in the environment partition) diff --git a/meta-digi-arm/conf/machine/ccmp15-dvk.conf b/meta-digi-arm/conf/machine/ccmp15-dvk.conf index d106586b7..4fe8c57a5 100644 --- a/meta-digi-arm/conf/machine/ccmp15-dvk.conf +++ b/meta-digi-arm/conf/machine/ccmp15-dvk.conf @@ -136,6 +136,7 @@ IMAGE_CLASSES = "image_types_digi image_types-stubi" # U-Boot environment offset (within partition) UBOOT_ENV_OFFSET ?= "0x0" +UBOOT_ENV_REDUND_OFFSET ?= "0x0" # U-Boot environment size UBOOT_ENV_SIZE ?= "0x20000" # U-Boot environment range: size (in hex) in the environment partition that diff --git a/meta-digi-arm/recipes-bsp/libubootenv/libubootenv/ubi/fw_env.config b/meta-digi-arm/recipes-bsp/libubootenv/libubootenv/ubi/fw_env.config new file mode 100644 index 000000000..d38cb8cf9 --- /dev/null +++ b/meta-digi-arm/recipes-bsp/libubootenv/libubootenv/ubi/fw_env.config @@ -0,0 +1,11 @@ +# Configuration file for fw_(printenv/setenv) utility. +# Up to two entries are valid, in this case the redundant +# environment sector is assumed present. +# Notice, that the "Number of sectors" is not required on NOR and SPI-dataflash. +# Futhermore, if the Flash sector size is omitted, this value is assumed to +# be the same as the Environment size, which is valid for NOR and SPI-dataflash +# Device offset must be prefixed with 0x to be parsed as a hexadecimal value. + +# UBI volume by name Offset Size Erase-size +/dev/ubi0:uboot_config ##ENV_OFFSET## ##ENV_SIZE## ##ENV_SIZE## +/dev/ubi0:uboot_config_r ##ENV_REDUND_OFFSET## ##ENV_SIZE## ##ENV_SIZE## diff --git a/meta-digi-arm/recipes-bsp/libubootenv/libubootenv_%.bbappend b/meta-digi-arm/recipes-bsp/libubootenv/libubootenv_%.bbappend index e3db95d3e..8076b29bd 100644 --- a/meta-digi-arm/recipes-bsp/libubootenv/libubootenv_%.bbappend +++ b/meta-digi-arm/recipes-bsp/libubootenv/libubootenv_%.bbappend @@ -11,6 +11,8 @@ FW_CONFIG_FILE = "${@bb.utils.contains('STORAGE_MEDIA', 'mtd', \ '${STORAGE_MEDIA}/fw_env.config', \ d)}" +FW_CONFIG_FILE:ccmp1 = "ubi/fw_env.config" + SRC_URI += " \ file://${FW_CONFIG_FILE} \ file://0001-Implement-support-for-environment-encryption-by-CAAM.patch \ @@ -23,6 +25,9 @@ do_install:append() { install -m 0644 ${WORKDIR}/${FW_CONFIG_FILE} ${D}${sysconfdir}/fw_env.config } +UBOOT_ENV_PARTITION = "environment" +UBOOT_ENV_PARTITION:ccmp1 = "UBI" + pkg_postinst_ontarget:${PN}() { CONFIG_FILE="/etc/fw_env.config" MMCDEV="$(sed -ne 's,.*root=/dev/mmcblk\([0-9]\)p.*,\1,g;T;p' /proc/cmdline)" @@ -31,12 +36,12 @@ pkg_postinst_ontarget:${PN}() { fi PARTTABLE="/proc/mtd" - MTDINDEX="$(sed -ne "s/\(^mtd[0-9]\+\):.*\.*/\1/g;T;p" ${PARTTABLE} 2>/dev/null)" + MTDINDEX="$(sed -ne "s/\(^mtd[0-9]\+\):.*\<${UBOOT_ENV_PARTITION}\>.*/\1/g;T;p" ${PARTTABLE} 2>/dev/null)" if [ -n "${MTDINDEX}" ]; then # Initialize variables for fixed offset values # (backwards compatible with old U-Boot) ENV_OFFSET="${UBOOT_ENV_OFFSET}" - ENV_REDUND_OFFSET="${UBOOT_ENV_SIZE}" + ENV_REDUND_OFFSET="${UBOOT_ENV_REDUND_OFFSET}" ENV_SIZE="${UBOOT_ENV_SIZE}" ERASEBLOCK="" NBLOCKS=""