Background
The gadget snaps typically contain bootloader files like e.g. bcm2709-rpi-2-b.dtb that is critical for the system to boot. Those files are put in place by ubuntu-image on image creation time, e.g. to /boot/uboot/bcm2709-rpi-2-b.dtb.
Subsequent updates of the gadget snap via snapd will not modify these files currently. Sometimes it is important to provide updates to those files and snapd should support this.
Possible options
Updating the bootloader files is very dangerous, if the power goes down in the middle of a write the device is potentially bricked. We also have no fallback (like we do for os/kernel) if its a bad firmware. So the update mechanism must at least follow the best practises for atomic writes and directory sync etc and should be used with a lot of care.
Given the risks involved the bootloader assets update should always be a manual process triggered by a human either from the command-line or via the REST api from e.g. snapweb with clear warnings.
Below some of the options we have:
Delivering updates via hooks
We could provide a way to update these files via a hook (e.g. update-bootloader) that is called when snap update-bootloader (or the responding REST api) is called. The hook would need an interface to read/write the /boot/{grub,uboot} directories and potentially even direct access to the hard-disk (if e.g. a MBR needs updating). We would also rely on the gadget snap author to follow best practises for writing those files with the risk that the implementation is sub-par.
Delivering updates via snapd
We could make snapd support a subset of the gadget.yaml spec, especially the ācontentā part. snapd would compare the files on disk and in the snap and when snap update-bootloader (or the coresponding REST api) is called, then it would update the files that changed following the atomic/sync-dir patterns. We still need to be very careful and ideally replace all the files at once (as there may be dependencies between them). There is also the issue that some files ship as defaults (like config.txt on the pi2) but are also user modifiable and we can not replace those once the user has touched them.
Open questions
- Should we support a mechanism from the gadget to signal that bootloader files need an update and for the user to query that? If so, we can integrate it in the same way as above, either via a hook (bootloader-needs-update) or as a native snapd implementation.