Double partitions to implement A/B update mechanism
Hello, i'm currently working on the stm32mp135f-dk with the kirkstone yocto version for layers provided by st. I'm trying to double all fs partitions (rootfs bootfs and userfs) to implement a software update mechanism with an active set of partitions and another one that will be used after being updated. My Flashlayout.tsv file generated by bitbake is the following:
#Opt Id Name Type IP Offset Binary
- 0x01 fsbl-boot Binary none 0x0 arm-trusted-firmware/tf-a-stm32mp135f-dk-usb.stm32
- 0x03 fip-boot FIP none 0x0 fip/fip-stm32mp135f-dk-optee.bin
P 0x04 fsbl1 Binary mmc0 0x00004400 arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32
P 0x05 fsbl2 Binary mmc0 0x00044400 arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32
P 0x06 metadata1 Binary mmc0 0x00084400 arm-trusted-firmware/metadata.bin
P 0x07 metadata2 Binary mmc0 0x000C4400 arm-trusted-firmware/metadata.bin
P 0x08 fip-a FIP mmc0 0x00104400 fip/fip-stm32mp135f-dk-optee.bin
PED 0x09 fip-b FIP mmc0 0x00504400 none
PED 0x0A u-boot-env Binary mmc0 0x00904400 none
P 0x10 bootfs-a System mmc0 0x00984400 st-image-bootfs-openstlinux-weston-stm32mp13-disco.ext4
P 0x11 rootfs-a FileSystem mmc0 0x04984400 st-image-core-openstlinux-weston-stm32mp13-disco.ext4
P 0x12 userfs-a FileSystem mmc0 0x104984400 st-image-userfs-openstlinux-weston-stm32mp13-disco.ext4
P 0x13 bootfs-b System mmc0 0x114984400 st-image-bootfs-openstlinux-weston-stm32mp13-disco.ext4
P 0x14 rootfs-b FileSystem mmc0 0x118984400 st-image-core-openstlinux-weston-stm32mp13-disco.ext4
P 0x15 userfs-b FileSystem mmc0 0x146984400 st-image-userfs-openstlinux-weston-stm32mp13-disco.ext4My machine file is currently like that :
# Enable use of extra partition(s)
ST_BOOTFS ?= "1"
ST_VENDORFS ?= "0"
ST_USERFS ?= "1"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_BOOTFS', '1', 'bootfs-a', '', d)}"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_VENDORFS', '1', 'vendorfs-a', '', d)}"
PARTITIONS_IMAGES += "rootfs-a"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_USERFS', '1', 'userfs-a', '', d)}"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_BOOTFS', '1', 'bootfs-b', '', d)}"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_VENDORFS', '1', 'vendorfs-b', '', d)}"
PARTITIONS_IMAGES += "rootfs-b"
PARTITIONS_IMAGES += "${@bb.utils.contains('ST_USERFS', '1', 'userfs-b', '', d)}"
# Define image to use for extra partitions
STM32MP_BOOTFS_IMAGE ?= "st-image-bootfs"
STM32MP_BOOTFS_LABEL ?= "bootfs-a"
STM32MP_BOOTFS_MOUNTPOINT ?= "/boot-a"
# Proposed value for bootfs is 64MB
STM32MP_BOOTFS_SIZE ?= "65536"
STM32MP_ROOTFS_IMAGE ?= "${IMAGE_BASENAME}"
STM32MP_ROOTFS_LABEL ?= "rootfs-a"
# Configure the rootfs size with IMAGE_ROOTFS_MAXSIZE variable
STM32MP_ROOTFS_SIZE ?= "${IMAGE_ROOTFS_MAXSIZE}"
STM32MP_USERFS_IMAGE ?= "st-image-userfs"
STM32MP_USERFS_LABEL ?= "userfs-a"
STM32MP_USERFS_MOUNTPOINT ?= "/usr/local-a"
# Proposed value for userfs is 128MB
STM32MP_USERFS_SIZE ?= "262144"
STM32MP_VENDORFS_IMAGE ?= "st-image-vendorfs"
STM32MP_VENDORFS_LABEL ?= "vendorfs-a"
STM32MP_VENDORFS_MOUNTPOINT ?= "/vendor-a"
# Proposed value for vendorfs is 16MB
STM32MP_VENDORFS_SIZE ?= "16384"
# <image_name>,<partition_label>,<mountpoint>,<size>,<type>
PARTITIONS_IMAGES[bootfs-a] ?= "${STM32MP_BOOTFS_IMAGE},${STM32MP_BOOTFS_LABEL},${STM32MP_BOOTFS_MOUNTPOINT},${STM32MP_BOOTFS_SIZE},System"
PARTITIONS_IMAGES[vendorfs-a] ?= "${STM32MP_VENDORFS_IMAGE},${STM32MP_VENDORFS_LABEL},${STM32MP_VENDORFS_MOUNTPOINT},${STM32MP_VENDORFS_SIZE},FileSystem"
PARTITIONS_IMAGES[rootfs-a] ?= "${STM32MP_ROOTFS_IMAGE},${STM32MP_ROOTFS_LABEL},,${STM32MP_ROOTFS_SIZE},FileSystem"
PARTITIONS_IMAGES[userfs-a] ?= "${STM32MP_USERFS_IMAGE},${STM32MP_USERFS_LABEL},${STM32MP_USERFS_MOUNTPOINT},${STM32MP_USERFS_SIZE},FileSystem"
# Define image to use for extra partitions
STM32MP_BOOTFSB_IMAGE ?= "st-image-bootfs"
STM32MP_BOOTFSB_LABEL ?= "bootfs-b"
STM32MP_BOOTFSB_MOUNTPOINT ?= "/boot-b"
# Proposed valBue for bootfs is 64MB
STM32MP_BOOTFSB_SIZE ?= "65536"
STM32MP_ROOTFSB_IMAGE ?= "${IMAGE_BASENAME}"
STM32MP_ROOTFSB_LABEL ?= "rootfs-b"
# Configure the rootfs size with IMAGE_ROOTFS_MAXSIZE variable
STM32MP_ROOTFSB_SIZE ?= "${IMAGE_ROOTFS_MAXSIZE}"
STM32MP_USERFSB_IMAGE ?= "st-image-userfs"
STM32MP_USERFSB_LABEL ?= "userfs-b"
STM32MP_USERFSB_MOUNTPOINT ?= "/usr/local-b"
# Proposed valBue for userfs is 128MB
STM32MP_USERFSB_SIZE ?= "262144"
STM32MP_VENDORFSB_IMAGE ?= "st-image-vendorfs"
STM32MP_VENDORFSB_LABEL ?= "vendorfs-b"
STM32MP_VENDORFSB_MOUNTPOINT ?= "/vendor-b"
# Proposed value for vendorfs is 16MB
STM32MP_VENDORFS_SIZE ?= "16384"
# <image_name>,<partition_label>,<mountpoint>,<size>,<type>
PARTITIONS_IMAGES[bootfs-b] ?= "${STM32MP_BOOTFSB_IMAGE},${STM32MP_BOOTFSB_LABEL},${STM32MP_BOOTFSB_MOUNTPOINT},${STM32MP_BOOTFSB_SIZE},System"
PARTITIONS_IMAGES[vendorfs-b] ?= "${STM32MP_VENDORFSB_IMAGE},${STM32MP_VENDORFSB_LABEL},${STM32MP_VENDORFSB_MOUNTPOINT},${STM32MPB_VENDORFS_SIZE},FileSystem"
PARTITIONS_IMAGES[rootfs-b] ?= "${STM32MP_ROOTFSB_IMAGE},${STM32MP_ROOTFSB_LABEL},,${STM32MP_ROOTFSB_SIZE},FileSystem"
PARTITIONS_IMAGES[userfs-b] ?= "${STM32MP_USERFSB_IMAGE},${STM32MP_USERFSB_LABEL},${STM32MP_USERFSB_MOUNTPOINT},${STM32MP_USERFSB_SIZE},FileSystem"But when I am generating the image and then flashing it on the board, I got an unexpected error that I can't explain, happening after the kernel starts.
root '/dev/disk/by-partuuid/e91c4e10-16e6-4c0e-bd0e-77becf4a3582' doesn't exist or does not contain a /dev.By searching through st layers, I found that sd card rootfs has its own defined uuid that is written as is in the code. I saw that fip1 and fip2 has 2 separate uuid. I wonder if I need to have 2 different uuid for my 2 rootfs. I tried to modify .wks files too, I found 2 of them, one with vendorfs and the other without.
# short-description: Create SD card image with a boot partition (1GB)
# long-description: Creates a partitioned SD card image (1GB)
#
# - -------- ------------- ------ ------ ------------ -------- --------- --------
# | | TFA(2) | Metadata(2) | FIPA | FIPB | U-BOOT ENV | bootfs | rootfs | userfs |
# - -------- ------------- ------ ------ ------------ -------- --------- --------
# ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
# | | | | | | | | | |
# 0 17kB 542kB 1.06MB 5.26MB 9.45MB 9.97MB 77.1MB 898MB 1032MB
#
# Warning: the first stage of boot (here fsbl1, fsbl2, metadata1, metadata2, fipa, fipb) MUST be on GPT partition to be detected.
#
# FSBL partitions aka TF-A BL2
part fsbl1 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fsbl1 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K --align 17
part fsbl2 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fsbl2 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
# Metadata partitions
part metadata1 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=metadata1 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/metadata.bin" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
part metadata2 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=metadata2 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/metadata.bin" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
# Fip partitions
part fip-a --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fip-a --sourceparams="file=${DEPLOY_DIR_IMAGE}/fip/fip-stm32mp135f-dk-optee.bin" --ondisk mmcblk --part-type 19d5df83-11b0-457b-be2c-7559c13142a5 --fixed-size 4096K --uuid 4fd84c93-54ef-463f-a7ef-ae25ff887087
part fip-b --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fip-b --sourceparams="file=${DEPLOY_DIR_IMAGE}/fip/fip-stm32mp135f-dk-optee.bin" --ondisk mmcblk --part-type 19d5df83-11b0-457b-be2c-7559c13142a5 --fixed-size 4096K --uuid 09c54952-d5bf-45af-acee-335303766fb3
# U-BOOT env
part u-boot-env --source empty --part-name=uboot-env --ondisk mmcblk --part-type 0x8301 --fixed-size 512K
# Bootfs
part bootfs-a --source rawcopy --sourceparams="file=st-image-bootfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label bootfs-a --part-name "bootfs-a" --active --fixed-size 64M
# Rootfs
part / --source rootfs-a --ondisk mmcblk --fstype=ext4 --label rootfs-a --part-name"rootfs-a" --fixed-size 783M --uuid e91c4e10-16e6-4c0e-bd0e-77becf4a3582
# Userfs
part userfs-a --source rawcopy --sourceparams="file=st-image-userfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label userfs-a --part-name "userfs-a" --fixed-size 128M
# Bootfs
part bootfs-b --source rawcopy --sourceparams="file=st-image-bootfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label bootfs-b --part-name "bootfs-b" --active --fixed-size 64M
# Rootfs
part / --source rootfs-b --ondisk mmcblk --fstype=ext4 --label rootfs-b --part-name "rootfs-b" --fixed-size 783M --uuid e91c4e10-16e6-4c0e-bd0e-77becf4a3583
# Userfs
part userfs-b --source rawcopy --sourceparams="file=st-image-userfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label userfs-b --part-name "userfs-b" --fixed-size 128M
bootloader --ptable gptand with vendorfs
# short-description: Create SD card image with a boot partition (1GB)
# long-description: Creates a partitioned SD card image (1GB)
#
# --------------------------------------------------------------------------------------------
# | | TFA(2) | Metadata(2) | FIPA | FIPB | U-BOOT ENV | bootfs-b | vendorfs-b | rootfs-b | userfs-b |
# --------------------------------------------------------------------------------------------
# ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
# | | | | | | | | | | |
# 0 17kB 542kB 1.06MB 5.26MB 9.45MB 9.97MB 77.1MB 93.9Mb 939MB 1073MB
#
# Warning: the first stage of boot (here fsbl1, fsbl2, metadata1, metadata2, fipa, fipb) MUST be on GPT partition to be detected.
#
# FSBL partitions aka TF-A BL2
part fsbl1 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fsbl1 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K --align 17
part fsbl2 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fsbl2 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/tf-a-stm32mp135f-dk-sdcard.stm32" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
# Metadata partitions
part metadata1 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=metadata1 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/metadata.bin" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
part metadata2 --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=metadata2 --sourceparams="file=${DEPLOY_DIR_IMAGE}/arm-trusted-firmware/metadata.bin" --ondisk mmcblk --part-type 0x8301 --fixed-size 256K
# Fip partitions
part fip-a --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fip-a --sourceparams="file=${DEPLOY_DIR_IMAGE}/fip/fip-stm32mp135f-dk-optee.bin" --ondisk mmcblk --part-type 19d5df83-11b0-457b-be2c-7559c13142a5 --fixed-size 4096K --uuid 4fd84c93-54ef-463f-a7ef-ae25ff887087
part fip-b --source rawcopy --fstype=ext4 --fsoptions "noauto" --part-name=fip-b --sourceparams="file=${DEPLOY_DIR_IMAGE}/fip/fip-stm32mp135f-dk-optee.bin" --ondisk mmcblk --part-type 19d5df83-11b0-457b-be2c-7559c13142a5 --fixed-size 4096K --uuid 09c54952-d5bf-45af-acee-335303766fb3
# U-BOOT env
part u-boot-env --source empty --part-name=uboot-env --ondisk mmcblk --part-type 0x8301 --fixed-size 512K
# Bootfs
part bootfs-a --source rawcopy --sourceparams="file=st-image-bootfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label bootfs-a --part-name "bootfs-a" --active --fixed-size 64M
# Vendorfs
part vendorfs-a --source rawcopy --sourceparams="file=st-image-vendorfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label vendorfs-a --part-name "vendorfs-a" --fixed-size 16M
# Rootfs
part / --source rootfs --ondisk mmcblk --fstype=ext4 --label rootfs-a --part-name "rootfs-a" --fixed-size 772M --uuid e91c4e10-16e6-4c0e-bd0e-77becf4a3582
# Userfs
part userfs-a --source rawcopy --sourceparams="file=st-image-userfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label userfs-a --part-name "userfs-a" --fixed-size 128M
# Bootfs
part bootfs-b --source rawcopy --sourceparams="file=st-image-bootfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label bootfs-b --part-name "bootfs-b" --fixed-size 64M
# Vendorfs
part vendorfs-b --source rawcopy --sourceparams="file=st-image-vendorfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label vendorfs-b --part-name "vendorfs-b" --fixed-size 16M
# Rootfs
part /rootfs-b --source rootfs --ondisk mmcblk --fstype=ext4 --label rootfs-b --part-name "rootfs-b" --fixed-size 772M --uuid e91c4e10-16e6-4c0e-bd0e-77becf4a3583
# Userfs
part userfs-b --source rawcopy --sourceparams="file=st-image-userfs-${DISTRO}-${MACHINE}.ext4" --ondisk mmcblk --fstype=ext4 --label userfs-b --part-name "userfs-b" --fixed-size 128M
bootloader --ptable gptI also saw another post on this forum (https://community.st.com/t5/stm32-mpus-embedded-software/change-u-boot-variables-for-different-rootfs-bootfs-partitions/m-p/206170) where 3 boot partition were needed. One for a script and the 2 others containing kernel, etc... I'm just a beginner, sorry if I forgot something very important in my process. Thank you for your time.
