The purpose of this repository is to provide templates that implement a mechanism to update a device that allows it to return to a previous working state in case the update fails with these considerations:
- The device provides a webpage at
http://<your_device_ip>:8080to receive a new image. - The device uses two redundant sets of partitions, named A and B. Each set has a
bootand arootfs. - The supported devices are
Raspberry Pi 2BandRaspberry Pi Compute Module 4.
When the device is running from one of those sets of partitions and an update is requested, the device will:
- Write the set of partitions that is not in use with the image received.
- Once completed, the device will restart to test the updated set of partitions.
- If it is able to boot, it will update a file that will tell it to use that set of partitions for the next boots.
In case that the process is interrupted at any point before the last step the device will keep using the set of partitions that was not updated.
This repo also serves as a starting point to test related improvements over its basic purpose. Currently the following is due to be solved:
- Investigate how to prevent and deal with possible corruptions of the filesystem.
- The current
web-appat/board/raspberrypi/generic/overlay_swupdate/var/www/swupdate/is a copy of the one shipped withSWUpdate 2021.04. Investigate why a newer version can't be used.
For the CM4 it requires EEPROM updated to pieeprom-2022-10-18.bin at least.
🛠 Pull requests are welcome! 🛠
SWUpdate deploys a web page to receive the new image provided by the user and writes it to the device.
The reboot mechanism is provided by a custom rebootp command implemented
originally by the PINN project because the original reboot
command does not inject both the partition number and tryboot arguments
required to switch partitions.
An init script called S80swupdate is in charge of testing if the device is
starting from the expected boot partition after an update has been performed,
making the change permanent in that case.
The autoboot mechanism and its option tryboot_a_b
are implemented to let the device identify the current working boot partition
and the one to test when requested by a rebootp using the tryboot argument.
There are variants of images to try autoboot and tryboot with no
SWUpdate on them.
Besides using this repo in your existing Buildroot installation using the external mechanism, there is also the option to use this docker-buildroot repo that provides a fast and convenient way to start working right away and keep multiple and independent instances for different targets at the same time.
- Clone docker-buildroot, if not already present:
git clone https://github.com/vidalastudillo/docker-buildroot
cd docker-buildroot- Set up the Buildroot source:
./scripts/bootstrap.shSee BUILDROOT_VERSION in docker-buildroot for the configured fork and branch, or to use a different one.
- Clone this repo into
externals/pi_swupdate:
git clone https://github.com/maovidal/buildroot_pi_swupdate externals/pi_swupdate- Build the shared Docker image (once):
docker buildx build -t va_buildroot .These are the relevant folders on your host:
externals/pi_swupdate/: the external tree with configs, packages, overlays and related files.images/pi_swupdate/: build outputs organized by target variant.target/pi_swupdate/: unpacked root filesystem for inspection.
Run scripts are provided for each target variant. They must always be called
from the root of the docker-buildroot project.
# Raspberry Pi 2B
./externals/pi_swupdate/run_pi2.sh make pi2_defconfig
./externals/pi_swupdate/run_pi2.sh make all
# Raspberry Pi Compute Module 4
./externals/pi_swupdate/run_cm4.sh make cm4_defconfig
./externals/pi_swupdate/run_cm4.sh make all./externals/pi_swupdate/run_pi2_tryboot.sh make pi2_tryboot_defconfig
./externals/pi_swupdate/run_pi2_autoboot.sh make pi2_autoboot_defconfig
./externals/pi_swupdate/run_cm4_tryboot.sh make cm4_tryboot_defconfig
./externals/pi_swupdate/run_cm4_autoboot.sh make cm4_autoboot_defconfig./externals/pi_swupdate/run_cm4_autoboot.sh make menuconfig
./externals/pi_swupdate/run_cm4_autoboot.sh make linux-rebuild
./externals/pi_swupdate/run_cm4_autoboot.sh make linux-menuconfig
./externals/pi_swupdate/run_cm4_autoboot.sh make allOnce built, images are located in ./images/pi_swupdate/<variant>/ on your
host (e.g. images/pi_swupdate/cm4_autoboot/sdcard.img) and can be flashed
following the official Raspberry Pi documentation.
By default, once started, the device will provide:
- A SSH server. Login with
root/ passwordhi. - A web page at
http://<your_device_ip>:8080 - A
./check.shscript that reports the current active mountpoints.
Drop the SWUpdate image named MyProduct.swu found at
./images/pi_swupdate/<variant>/ to that web page to trigger an update.
Partitions created on the device's eMMC:
boot_aatmmcblk0p1: boot files when set A is active.boot_batmmcblk0p2: boot files when set B is active.persistentatmmcblk0p3: VFAT partition that survives updates.rootfs_aatmmcblk0p5: root filesystem for set A.rootfs_batmmcblk0p6: root filesystem for set B.
Partitions created on the device's eMMC:
persistentatmmcblk0p1: containsautoboot.txt. The Pi2 variant also containsbootcode.bin.boot_aatmmcblk0p2: boot files when set A is active.boot_batmmcblk0p3: boot files when set B is active.rootfs_aatmmcblk0p5: root filesystem for set A.rootfs_batmmcblk0p6: root filesystem for set B.
This software is licensed under MIT License.
© 2022 Mauricio Vidal.