Files
auracaster-os/example/create-update-package.sh
2025-04-17 13:21:38 +02:00

109 lines
3.3 KiB
Bash
Executable File

#!/bin/bash
#
# Script to create SWUpdate update package for A/B system
# This demonstrates the format of a SWUpdate package for A/B partitioning
set -e
# Configuration
BUILDROOT_DIR="../buildroot"
OUTPUT_DIR="$BUILDROOT_DIR/output"
BINARIES_DIR="$OUTPUT_DIR/images"
ROOTFS_FILE="$BINARIES_DIR/rootfs.ext4"
SWU_FILE="auracaster-update.swu"
SW_VERSION="1.0.1"
SW_DESCRIPTION="example/sw-description"
# Check if necessary files exist
if [ ! -f "$ROOTFS_FILE" ]; then
echo "Error: rootfs.ext4 not found at $ROOTFS_FILE"
echo "You need to build the project first using:"
echo "cd $BUILDROOT_DIR && make BR2_EXTERNAL=../auracaster-system auracaster_raspberrypi3_swupdate_defconfig && make"
exit 1
fi
# Create temporary directory
TEMP_DIR=$(mktemp -d)
echo "Creating update package in $TEMP_DIR"
# Create sw-description file
cat > $SW_DESCRIPTION << EOF
software = {
version = "$SW_VERSION";
raspberrypi3 = {
hardware-compatibility: [ "1.0" ];
/* We have 2 systems, A and B */
stable = {
/* Selection based on U-Boot variable 'active_part' */
/* If active_part == A, then use B for update */
/* If active_part == B, then use A for update */
/* Update copy based on active_part variable */
copy1 = {
/* Install on the inactive partition */
images: (
{
filename = "rootfs.ext4";
device = "/dev/mmcblk0p\${inactive_part == "A" ? "2" : "3"}";
type = "raw";
}
);
/* Update U-Boot environment to boot from the updated partition */
uboot: (
{
name = "bootcount";
value = "0";
},
{
name = "upgrade_available";
value = "1";
},
{
name = "active_part";
value = "\${inactive_part}";
},
{
name = "active_root";
value = "\${inactive_root}";
},
{
name = "inactive_part";
value = "\${active_part}";
},
{
name = "inactive_root";
value = "\${active_root}";
}
);
};
};
};
}
EOF
# Copy required files to temp directory
cp $ROOTFS_FILE $TEMP_DIR/
cp $SW_DESCRIPTION $TEMP_DIR/
# Create update package
echo "Creating SWUpdate package $SWU_FILE"
(cd $TEMP_DIR && \
for i in sw-description rootfs.ext4; do
echo $i;
done | cpio -ov -H crc > ../$SWU_FILE)
# Clean up
rm -rf $TEMP_DIR
echo "Update package created: $SWU_FILE"
echo "To apply this update:"
echo "1. Boot the Raspberry Pi with the SD card image"
echo "2. Access the web interface at http://<raspberry-pi-ip>:8080"
echo "3. Upload $SWU_FILE to update the inactive partition"
echo "4. After update completes, reboot the device"
echo "5. The device will boot from the updated partition"
exit 0