I have not continued the effort of dual and failsafe boot as I've been busy with some other things.
I now wonder whether the additional complexity introduced (which means more room for bugs as well) is worth it?
At that time, there were a couple of things that were pending and I think should be addressed to have a robust implementation.
1: When doing a sysupgrade, or bootenv initialization, boot slot being flashed should be checked to be compatible with OpenWrt.
OEM firmware has UBI volumes that are not compatible with the ones from OpenWrt.
If OEM UBI volumes are found, you could either refuse to flash or attempt to format the UBI (ubiformat can be used, but you would need to detach it first and find the proper one).
This could be implemented as part of platform_check_image(), or platform_do_upgrade().
I think I tried once of flashing a OpenWrt on top of OEM UBI volumes and it didn't boot properly.
For reference, here is a comparison between UBI volumes (on my device):
UBI vol | OEM | OpenWrt
0 | kernel (4.0 MiB) | kernel (4.7 MiB)
1 | ubi_rootfs (33.5 MiB) | rootfs (8.7 MiB)
2 | rootfs_data (51.1 MiB) | rootfs_data (75.1 MiB)
2: Be robust (or try to detect) OEM boot slot change.
OEM boot slot defines how the offsets and names of mtd partitions are observed by u-boot and OpenWrt.
Current logic to detect OEM boot slot relies on offset of mtd18 and is only done once when initializing uboot env.
OpenWrt relies on this detection to define an appropriated value for mtdparts u-boot variable, and the "OpenWrt slot".
When booting, kernel partition is taken from mtdparts (fs or fs_1), and UBI (for rootfs) from mtd partition (rootfs or rootfs_1, as observed by kernel).
This works fine as long as OEM boot slot does not change.
However, OEM boot slot can be changed by writing to BOOTCONFIG mtd partition (or maybe by trying to restore OEM firmware).
If this changes, u-boot variable mtdparts no longer represents correct partitions and it might boot a kernel and rootfs that no longer match.
I'm not sure how to fix this, or if it can be ignored hoping that never occurs.