At the moment we are limited when updating kernel by version of dtb files presented in system-boot partition. Those dtb flies are read by pi’s firmware therefore they cannot be scripted and need to be compatible with all kernel revision presented on device. This limits us when updating kernel as we cannot do major kernel updates, let alone dtb changes…
Proposed solution to get out of this lock down.
With combination of pre and post refresh hooks we can actually overcome this limitation and freely update between major kernel versions, it would work as following:
- new kernel revision is being installed
- pre-refresh hook is invoked on current kernel revision, in this hook we extract current run time dtb (this has all overlays from config.txt and other data filled in by pi’s firmware). After bootargs cleanup (removing part which has been added by u-boot such as snap_kernel snap_core) we store this dtb to
/boot/uboot/pi2-kernel_\<current rev>.snap/raspi2.dtbin case we need it later
- snapd introduces new kernel revision to the system
- post-refresh hook is invoked for new kernel revision. This hook copies dtbs and overlay dtbo files to
/boot/uboot/so at next boot firmware will use new updated files related to kernel we are trying to boot
Changes in u-boot:
u-boot always tries to load
In normal situation this always fails, as file does not exist and dtb prepared by firmware is used instead. Only situation this actually kicks in is when there was kernel rollback. In such a situation it ensures that even if we rollbacked because of boot fail and therefore raspi firmware is now using dtb from borked kernel, dtb prepared by firmware is ignored and backed up one is used instead, one created for kernel we are now trying to boot.
Additionally to ensure safe rollout,
post-refresh hook will only copy new dtbs in if
pre-refresh hook made successful dtb backup. So if current kernel revision does not have
post-refresh hook on new kernel revision will do nothing.
I have prototyped this and so far it functions as expected, I have been switching between 4.4 and 4.15 kernels, interrupting boots in the middle to force rollback and system recovers as desired.
Related changes are here:
Kernel patch introducing hooks:
Gadget u-boot tweak:
To support this functionality, we need tweak one existing interface and add one new one
- update to hardware-observe to allow reading of device tree:
- new boot-update interface allowing us update of boot components: