All Collections
Custom Firmware
Firmware
Package Custom U-Boot Firmware for AVH
Package Custom U-Boot Firmware for AVH
avhsupport avatar
Written by avhsupport
Updated over a week ago

Table of Contents

AVH supports U-Boot, a common bootloader used with embedded devices.

In this article, we provide two examples of packaging custom firmware that uses U-Boot โ€” BalenaOS and Home Assistant.

Package the BalenaOS Firmware

We will use the Development version of the most recent RASPBERRY PI 4 (USING 64BIT OS) release from the BalenaOS Download page.

Run the script as a superuser.

#!/bin/bash
set -e

dir_name="balena_pi_package"
output_filename="balenaos_rpi4b.zip"
firmware_name="raspberrypi4-64-2.113.18-v14.9.4.img.zip"
image_name=$(basename ${firmware_name} .zip)

[ -d ${dir_name} ] || mkdir ${dir_name}
cd ${dir_name}
cp ../${firmware_name} .
unzip ${firmware_name}
mv ${image_name} nand

# Mount the firmware image and extract the kernel and device tree
LO="$(losetup -f)"
losetup -P "${LO}" nand
mkdir {boot,rootfs}
mount "${LO}p1" boot
cp boot/bcm2711-rpi-4-b.dtb devicetree
umount boot/
rm -r boot/

mount "${LO}p2" rootfs
cp rootfs/hostapps/*/boot/Image.gz .
gunzip Image.gz
mv Image kernel
umount rootfs/
rm -r rootfs/
losetup -d "${LO}"

# create the Info plist that describes the model image
cat << EOF > Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Type</key>
<string>iot</string>
<key>UniqueIdentifier</key>
<string>BalenaOS</string>
<key>DeviceIdentifier</key>
<string>rpi4b</string>
<key>Version</key>
<string>2.113.18</string>
<key>Build</key>
<string>production</string>
</dict>
</plist>
EOF

zip -m ../${output_filename} nand kernel devicetree Info.plist
cd ../
rm -r ${dir_name}

Package the Home Assistant Firmware

To package Home Assistant, we will use the most recent rpi4 release from the Home Assistant Releases page.

Run the script as a superuser.

#!/bin/bash
set -e

output_filename="home_assistant_rpi4b.zip"
firmware_url="https://github.com/home-assistant/operating-system/releases/download/10.0.rc1/haos_rpi4-10.0.rc1.img.xz"
firmware_tarball=$(basename "${firmware_url}")
firmware_image=$(basename "${firmware_url}" .xz)

wget "${firmware_url}"
xz -d "${firmware_tarball}"
mv "${firmware_image}" nand

LO="$(losetup -f)"
losetup -P "${LO}" nand
mkdir boot
mount "${LO}p1" boot
cp boot/bcm2711-rpi-4-b.dtb devicetree
umount boot
rm -r boot
mkdir rootfs
mount "${LO}p2" rootfs
cp rootfs/Image ~/kernel
umount rootfs
rm -r rootfs
losetup -D "${LO}"

cat << EOF > Info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Type</key>
<string>iot</string>
<key>UniqueIdentifier</key>
<string>Home Assistant</string>
<key>DeviceIdentifier</key>
<string>rpi4b</string>
<key>Version</key>
<string>10.0</string>
<key>Build</key>
<string>desktop</string>
</dict>
</plist>
EOF

zip -m "${output_filename}" Info.plist nand kernel devicetree

Did this answer your question?