core-image-minimal.bbappend
do_image_complete() {
# Create etc.ext4 part
dd if=/dev/zero of="${WORKDIR}/etc.ext4" bs=1M count=${ETC_PART_SIZE_MB};
mke2fs -d ${IMAGE_ROOTFS}/etc -t ext4 -L etc_image ${WORKDIR}/etc.ext4;
cp -rf ${WORKDIR}/etc.ext4 ${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.etc.ext4;
ln -sfn "${IMAGE_NAME}.etc.ext4" "${DEPLOY_DIR_IMAGE}/${IMAGE_BASENAME}-${MACHINE}.etc.ext4";
# Create boot.vfat part
cd ${DEPLOY_DIR_IMAGE}
dd if=/dev/zero of=${IMAGE_NAME}.boot.vfat bs=1M count=${BOOT_PART_SIZE_MB};
mkfs.vfat ${IMAGE_NAME}.boot.vfat
mcopy -i ${IMAGE_NAME}.boot.vfat imx8mp-evk.dtb ::imx8mp-evk.dtb
mcopy -i ${IMAGE_NAME}.boot.vfat Image ::Image
ln -sfn "${IMAGE_NAME}.boot.vfat" "${IMAGE_BASENAME}-${MACHINE}.boot.vfat";
# create .img link for flash.bin
ln -sfn imx-boot-imx8mp-lpddr4-evk-sd.bin-flash_evk imx-boot-imx8mp-lpddr4-evk-sd.img
}
update-bundle.bb
DESCRIPTION = "RAUC bundle generator"
LICENSE = "GPLv3"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/GPL-3.0-only;md5=c79ff39f19dfec6d293b95dea7b07891"
inherit bundle
SRC_URI += " \
file://bundle_hook.sh \
"
RAUC_BUNDLE_COMPATIBLE = "IMX8MPEVK"
RAUC_BUNDLE_VERSION = "${DISTRO_VERSION}"
RAUC_BUNDLE_DESCRIPTION = "IMX8MPEVK Rauc bundle"
RAUC_BUNDLE_HOOKS[file] = "bundle_hook.sh"
RAUC_BUNDLE_SLOTS = "rootfs boot bootloader"
RAUC_SLOT_rootfs = "core-image-minimal"
RAUC_SLOT_rootfs[fstype] = "ext4"
RAUC_SLOT_boot = "core-image-minimal"
RAUC_SLOT_boot[fstype] = "boot.vfat"
RAUC_SLOT_bootloader = "imx-boot"
RAUC_SLOT_bootloader[type] = "file"
RAUC_SLOT_bootloader[file] = "imx-boot-imx8mp-lpddr4-evk-sd.img"
RAUC_SLOT_bootloader[hooks] = "post-install"
RAUC_BUNDLE_EXTRA_FILES = "imx-boot-imx8mp-lpddr4-evk-sd.img"
RAUC_KEY_FILE = "${THISDIR}/files/development-1.key.pem"
RAUC_CERT_FILE = "${THISDIR}/files/development-1.cert.pem"
do_unpack[depends] += "u-boot-imx:do_deploy"
do_unpack[depends] += "imx-boot:do_deploy"
do_bundle[depends] += "u-boot-imx:do_deploy"
do_bundle[depends] += "imx-boot:do_deploy"
do_bundle() {
export OPENSSL_ENGINES=${STAGING_LIBDIR_NATIVE}/engines-1.1
export RAUC_PKCS11_MODULE=${RAUC_PKCS11_MODULE}
export PKCS11_PROXY_SOCKET=${PKCS11_PROXY_SOCKET}
export RAUC_PKCS11_PIN=${RAUC_PKCS11_PIN}
${STAGING_DIR_NATIVE}${bindir}/rauc bundle \
--conf= \
--debug \
--cert="${RAUC_CERT_FILE}" \
--key="${RAUC_KEY_FILE}" \
${BUNDLE_DIR} \
${B}/bundle.raucb
}
# SSTATE_SKIP_CREATION:task-deploy = '1'
bundle_hook.sh
#!/bin/sh
case "$1" in
slot-post-install)
if [ "$RAUC_SLOT_CLASS" = "bootloader" ]; then
echo "Rauc Bundle mount point: ${RAUC_BUNDLE_MOUNT_POINT}"
dd if=${RAUC_BUNDLE_MOUNT_POINT}/imx-boot-imx8mp-lpddr4-evk-sd.img of=/dev/mmcblk2 bs=1k seek=32
echo "update bootloader succesfully"
fi;
;;
*)
exit 1
;;
esac
exit 0
system.conf
[system]
compatible=IMX8MPEVK
bootloader=uboot
mountprefix=/mnt/rauc
[keyring]
path=/etc/rauc/ca.cert.pem
# bootloader
[slot.bootloader.0]
device=/dev/mmcblk2
type=boot-emmc
# boot A
[slot.boot.0]
device=/dev/mmcblk2p1
type=vfat
parent=rootfs.0
# boot B
[slot.boot.1]
device=/dev/mmcblk2p2
type=vfat
parent=rootfs.1
# rootfs A
[slot.rootfs.0]
device=/dev/mmcblk2p3
type=ext4
bootname=A
# rootfs B
[slot.rootfs.1]
device=/dev/mmcblk2p4
type=ext4
bootname=B
rauc_%.bbappend
FILESEXTRAPATHS:prepend := "${THISDIR}/files:"
SRC_URI:append= " \
file://system.conf \
file://ca.cert.pem \
file://fw_env.config \
"
RDEPENDS:${PN} += "u-boot-fw-utils"
DEPENDS += "u-boot-imx"
do_install:append () {
install -d ${D}${datadir}/rauc/
install -m 0644 ${WORKDIR}/system.conf ${D}${datadir}/rauc/system.conf
install -m 0644 ${WORKDIR}/ca.cert.pem ${D}${sysconfdir}/rauc/ca.cert.pem
install -m 0644 ${WORKDIR}/fw_env.config ${D}${sysconfdir}/fw_env.config
}
To provide support for u-boot-fw-utils the following file is needed based on the following u-boot cfg:
CONFIG_ENV_IS_NOWHERE=y
CONFIG_ENV_IS_IN_MMC=y
CONFIG_SYS_MMC_ENV_DEV=2
CONFIG_SYS_MMC_ENV_PART=0
CONFIG_ENV_SIZE=0x4000
CONFIG_ENV_OFFSET=0x400000
CONFIG_ENV_SECT_SIZE=0x10000
CONFIG_ENV_OFFSET_REDUND=0x404000
Then you need /etc/fw_env.config:
/* dev offset size */
/dev/mmcblk0 0x400000 0x4000
/dev/mmcblk0 0x800000 0x4000
fw_env.config testing:
hexdump -C /dev/mmcblk2 | grep BOOT_ORDER
hexdump -C /dev/mmcblk2 -s 0x00400000 | grep BOOT_ORDER
hexdump -C /dev/mmcblk2 -s 0x00400000
hexdump -C /dev/mmcblk2 -s 0x00404000
hexdump -C /dev/mmcblk2 | grep __boot=if
hexdump -C /dev/mmcblk2boot0 | grep __boot=if
hexdump -C /dev/mmcblk2boot1 | grep __boot=if
hexdump -C /dev/mmcblk2boot1 -s 0x00110000
U-Boot imx bbappend need the following:
FILESEXTRAPATHS:append := "${THISDIR}/files:"
SRC_URI:prepend:imx8mp-lpddr4-evk = " \
file://boot.cmd \
"
DEPENDS += "u-boot-mkimage-native"
PROVIDES += "u-boot-default-script"
DEPENDS += "bc-native dtc-native swig-native python3-native flex-native bison-native"
EXTRA_OEMAKE += 'HOSTLDSHARED="${BUILD_CC} -shared ${BUILD_LDFLAGS} ${BUILD_CFLAGS}"'
# The UBOOT_ENV_SUFFIX and UBOOT_ENV are mandatory in order to run the
# uboot-mkimage command from poky/meta/recipes-bsp/u-boot/u-boot.inc
UBOOT_ENV_SUFFIX = "scr"
UBOOT_ENV = "boot"
do_deploy:append() {
install -d ${DEPLOYDIR}
install -m 0644 ${WORKDIR}/${UBOOT_ENV_BINARY} ${DEPLOYDIR}
}
Where boot.cmd file:
test -n "${BOOT_ORDER}" || setenv BOOT_ORDER "A B"
test -n "${BOOT_A_LEFT}" || setenv BOOT_A_LEFT 3
test -n "${BOOT_B_LEFT}" || setenv BOOT_B_LEFT 3
test -n "${BOOT_DEV}" || setenv BOOT_DEV "mmc 2:1"
env set boot_part
env set rootfs_part
env set rauc_slot
for BOOT_SLOT in "${BOOT_ORDER}"; do
if test "x${rootfs_part}" != "x"; then
# skip remaining slots
elif test "x${BOOT_SLOT}" = "xA"; then
if test ${BOOT_A_LEFT} -gt 0; then
setexpr BOOT_A_LEFT ${BOOT_A_LEFT} - 1
echo "Booting RAUC slot A"
setenv boot_part "1"
setenv rootfs_part "/dev/mmcblk2p3"
setenv rauc_slot "A"
setenv BOOT_DEV "mmc 2:1"
fi
elif test "x${BOOT_SLOT}" = "xB"; then
if test ${BOOT_B_LEFT} -gt 0; then
setexpr BOOT_B_LEFT ${BOOT_B_LEFT} - 1
echo "Booting RAUC slot B"
setenv boot_part "2"
setenv rootfs_part "/dev/mmcblk2p4"
setenv rauc_slot "B"
setenv BOOT_DEV "mmc 2:2"
fi
fi
done
if test -n "${rootfs_part}"; then
saveenv
else
echo "No valid RAUC slot found. Resetting tries to 3"
setenv BOOT_A_LEFT 3
setenv BOOT_B_LEFT 3
saveenv
reset
fi
# set bootargs
setenv bootargs "console=ttymxc1,115200 root=${rootfs_part} rootwait rw loglevel=7 rauc.slot=${rauc_slot}"
# load dtb + kernel
load mmc 2:${boot_part} ${loadaddr} Image;
load mmc 2:${boot_part} ${fdt_addr} ${fdt_module};
booti ${loadaddr} - ${fdt_addr};
We need to add also boot.scr as a part of the BOOT_FILES then let's add this line to your machine.conf file:
IMAGE_BOOT_FILES:append = " boot.scr"
rauc info --keyring=/path-to/recipes-core/rauc/files/ca.cert.pem /path-to/update-bundle-imx8mp-lpddr4-evk.raucb
rauc bundle --cert=./development-1.cert.pem --key=./development-1.key.pem ./update-bundle-imx8mp-lpddr4-evk.raucb
rm -rf update-bundle-imx8mp-lpddr4-evk-signed.raucb
rauc resign --cert=development-1.cert.pem --key=development-1.key.pem --keyring=ca.cert.pem update-bundle-imx8mp-lpddr4-evk.raucb update-bundle-imx8mp-lpddr4-evk-signed.raucb
rauc install --keyring=/etc/rauc/ca.cert.pem update-bundle-imx8mp-lpddr4-evk-signed.raucb
scp update-bundle-imx8mp-lpddr4-evk-signed.raucb [email protected]:/home/root/
journalctl -u rauc.service
Rauc References:
- https://github.com/prusa3d/Prusa-Firmware-SL1/blob/master/sources/meta-prusa/recipes-core/bundles/sla-update-bundle.bb
- https://github.com/rauc/meta-rauc-community/tree/master
- rauc/rauc#804
- https://github.com/rauc/rauc/blob/master/test/install-content/hook.sh
- rauc/rauc#192
- rauc/meta-rauc#185
U-Boot fw utils References:
- https://stackoverflow.com/questions/65006727/configuring-the-bootloader-with-fw-env-config-and-config-env-offset
- https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/u-boot-environment-preset-for-sdcard-mirror/ta-p/1702549
- https://stackoverflow.com/questions/71955198/where-is-uboot-environment-variables-stored-in-emmc