feat: Add UNVR support (#11)

* Move partition mounts to PARTLABEL instead of paths
* Add dual firmware building support, specify the build type using the BOARD env var when using make
* Update to Unifi 4.0.5 pre-release firmware
* Move ulcmd init to be our "user interface" setup script, will handle LEDs on the UNVR4 in the future
* Update README with updated instructions
* Add udev rules to support /dev/boot which is what Unifi uses for some stupid reason for their emmc. This is required for systemd to mount correctly after chroot.
* Fixup small bugs found along the way
This commit is contained in:
Chris Blake 2024-06-15 18:53:44 -05:00 committed by GitHub
parent 8e2262e121
commit 3f90bd2357
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 210 additions and 79 deletions

View file

@ -21,6 +21,17 @@ if [ ! -d /sys/module/loop ]; then
exit 1
fi
# Did we have a board set?
if [ -z "${BOARD}" ]; then
echo "Error: BOARD is not set, so we don't know what we are building for! Exiting..."
echo "Please review the README.md on usage!"
exit 1
elif [ -z "${firmware_filename}" ]; then
# Board is set, make sure it's a board we support
echo "Error: Invalid BOARD value of ${BOARD}. Please review the README.md on usage!"
exit 1
fi
# Validate FW is downloaded
if ! [ -f "${root_path}/unifi-firmware/${firmware_filename}" ]; then
echo "Error: File ${firmware_filename} does not exist in ./unifi-firmware! Exiting..."

View file

@ -15,14 +15,14 @@ else
fi
# Extract the goodies
${scripts_path}/ubnt-fw-parse.py "${root_path}/unifi-firmware/${firmware_filename}" "${build_path}/fw-extract"
${scripts_path}/ubnt-fw-parse.py "${root_path}/unifi-firmware/${firmware_filename}" "${build_path}/fw-extract/${firmware_filename%.bin}"
# Extract the squashfs rootfs
echo "Extracting unifi rootfs as root..."
sudo unsquashfs -f -d "${build_path}/fw-extract/rootfs" "${build_path}/fw-extract/rootfs.bin"
sudo unsquashfs -f -d "${build_path}/fw-extract/${BOARD}-rootfs" "${build_path}/fw-extract/${firmware_filename%.bin}/rootfs.bin"
# Always build to pickup changes/updates/improvements
debug_msg "Building ${docker_tag}"
docker build -t ${docker_tag} ${root_path}
debug_msg "Finished 01_pre_docker.sh"
debug_msg "Finished 01_pre_docker.sh"

View file

@ -67,7 +67,7 @@ sudo rm -f ${build_path}/rootfs/placeholder ${build_path}/rootfs/boot/placeholde
# SAFETY NET - trap it, even tho we have makefile with set -e
debug_msg "Docker: debootstraping..."
trap "sudo umount ${build_path}/rootfs/boot; sudo umount ${build_path}/rootfs; sudo losetup -d ${boot_loop_dev}; sudo losetup -d ${rootfs_loop_dev}" SIGINT SIGTERM
docker run --ulimit nofile=1024 --rm --privileged --cap-add=ALL -v /dev:/dev -v "${root_path}:/repo:Z" -it ${docker_tag} /repo/scripts/docker/run_debootstrap.sh
docker run --ulimit nofile=1024 --rm --privileged --cap-add=ALL -v /dev:/dev -v "${root_path}:/repo:Z" -e BOARD="${BOARD}" -it ${docker_tag} /repo/scripts/docker/run_debootstrap.sh
debug_msg "Note: You might be asked for your password for losetup and umount since we are cleaning up mounts..."
debug_msg "Cleaning up..."

View file

@ -14,7 +14,7 @@ fi
mkdir -p ${build_path}/final
# Kick off the docker to do the magics for us, since we need genimage
docker run --rm -v "${root_path}:/repo:Z" -it ${docker_tag} /repo/scripts/docker/run_mkimage_final.sh
docker run --rm -v "${root_path}:/repo:Z" -e BOARD="${BOARD}" -it ${docker_tag} /repo/scripts/docker/run_mkimage_final.sh
# Just create our final dir and move bits over
TIMESTAMP=`date +%Y%m%d-%H%M`

View file

@ -69,6 +69,7 @@ jq --null-input --compact-output \
omv-confdbadm update "conf.system.network.interface" -
# Set hostname
omv-confdbadm update "conf.system.network.dns" "{\"hostname\": \"unvr-nas\"}"
sed -i "s|myhostname = .*|myhostname = unvr-nas|g" /etc/postfix/main.cf
# Cleanup stuff we don't want floating around
apt-get autoclean || true

View file

@ -14,15 +14,15 @@ export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
# CD into our rootfs mount, and starts the fun!
cd ${build_path}/rootfs
debootstrap --no-check-gpg --foreign --arch=${deb_arch} --include=apt-transport-https ${deb_release} ${build_path}/rootfs ${deb_mirror}
cd "${build_path}/rootfs"
debootstrap --no-check-gpg --foreign --arch=${deb_arch} --include=apt-transport-https ${deb_release} "${build_path}/rootfs" ${deb_mirror}
cp /usr/bin/qemu-aarch64-static usr/bin/
chroot ${build_path}/rootfs /debootstrap/debootstrap --second-stage
chroot "${build_path}/rootfs" /debootstrap/debootstrap --second-stage
# Copy over our kernel modules and kernel from the FS image
# Note that in the future, we wanna use our own kernel, but the current GPL is way too old!!!!!
mv -f "${build_path}/fw-extract/rootfs/lib/modules" "${build_path}/rootfs/lib"
cp "${build_path}/fw-extract/kernel.bin" "${build_path}/rootfs/boot/uImage"
mv -f "${build_path}/fw-extract/${BOARD}-rootfs/lib/modules" "${build_path}/rootfs/lib"
cp "${build_path}/fw-extract/${firmware_filename%.bin}/kernel.bin" "${build_path}/rootfs/boot/uImage"
# Now, for the old kernel we built, pull in btrfs + depends modules (we do depmod in bootstrap)
cp "${build_path}/kernel/kernel-modules/lib/modules/4.19.152-alpine-unvr/kernel/lib/zstd/zstd_compress.ko" "${build_path}/rootfs/lib/modules/4.19.152-alpine-unvr/extra/"
@ -34,31 +34,32 @@ if [[ -d ${root_path}/overlay/${fs_overlay_dir}/ ]]; then
cp -R ${root_path}/overlay/${fs_overlay_dir}/* ./
fi
# Apply our part UUIDs to fstab
#sed -i "s|BOOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/boot.ext4)|g" ${build_path}/rootfs/etc/fstab
#sed -i "s|ROOTUUIDPLACEHOLDER|$(blkid -o value -s UUID ${build_path}/rootfs.ext4)|g" ${build_path}/rootfs/etc/fstab
# Hostname
echo "${distrib_name}" > ${build_path}/rootfs/etc/hostname
echo "127.0.1.1 ${distrib_name}" >> ${build_path}/rootfs/etc/hosts
echo "unvr-nas" > "${build_path}/rootfs/etc/hostname"
echo "127.0.1.1 unvr-nas" >> "${build_path}/rootfs/etc/hosts"
# Console settings
echo "console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select us
" > ${build_path}/rootfs/debconf.set
" > "${build_path}/rootfs/debconf.set"
# Copy over stuff for ulcmd, this is hacky, but that's this ENTIRE repo for you
mv "${build_path}/fw-extract/rootfs/usr/bin/ulcmd" "${build_path}/rootfs/usr/bin/ulcmd" # LCD controller
mv "${build_path}/fw-extract/rootfs/usr/share/firmware" "${build_path}/rootfs/usr/share/" # LCD panel firmwares
mkdir -p "${build_path}/rootfs/usr/lib/ubnt-fw/" # Home for ulcmd libraries
for file in libgrpc++.so.1 libgrpc.so.10 libprotobuf.so.23 \
libssl.so.1.1 libcrypto.so.1.1 libabsl*.so.20200923 libatomic.so.1; do
cp -H ${build_path}/fw-extract/rootfs/usr/lib/aarch64-linux-gnu/${file} "${build_path}/rootfs/usr/lib/ubnt-fw/"
done
# Copy over stuff for ulcmd on UNVRPRO. this is hacky, but that's this ENTIRE repo for you
if [ "${BOARD}" == "UNVRPRO" ]; then
mv "${build_path}/fw-extract/${BOARD}-rootfs/usr/bin/ulcmd" "${build_path}/rootfs/usr/bin/ulcmd" # LCD controller
mv "${build_path}/fw-extract/${BOARD}-rootfs/usr/share/firmware" "${build_path}/rootfs/usr/share/" # LCD panel firmwares
mkdir -p "${build_path}/rootfs/usr/lib/ubnt-fw/" # Home for ulcmd libraries
for file in libgrpc++.so.1 libgrpc.so.10 libprotobuf.so.23 \
libssl.so.1.1 libcrypto.so.1.1 libabsl*.so.20200923 libatomic.so.1; do
cp -H ${build_path}/fw-extract/${BOARD}-rootfs/usr/lib/aarch64-linux-gnu/${file} "${build_path}/rootfs/usr/lib/ubnt-fw/"
done
else
# Remove our ld.so.conf.d as it's not needed for UVNR
rm "${build_path}/rootfs/etc/ld.so.conf.d/ubnt.conf"
fi
# Copy over bluetooth firmware files
mkdir -p "${build_path}/rootfs/lib/firmware"
cp -R "${build_path}/fw-extract/rootfs/lib/firmware/csr8x11" "${build_path}/rootfs/lib/firmware/" # LCD panel firmwares
cp -R "${build_path}/fw-extract/${BOARD}-rootfs/lib/firmware/csr8x11" "${build_path}/rootfs/lib/firmware/" # LCD panel firmwares
# Install our bccmd we compiled (less we use from unifi the better)
cp -R "${build_path}/packages/bluez/bccmd" "${build_path}/rootfs/usr/bin"
@ -69,9 +70,9 @@ cp -R "${build_path}/packages/ubnteeprom/ubnteeprom" "${build_path}/rootfs/usr/b
chmod +x "${build_path}/rootfs/usr/bin/ubnteeprom"
# Kick off bash setup script within chroot
cp ${docker_scripts_path}/bootstrap/001-bootstrap ${build_path}/rootfs/bootstrap
chroot ${build_path}/rootfs /bootstrap
rm ${build_path}/rootfs/bootstrap
cp "${docker_scripts_path}/bootstrap/001-bootstrap" "${build_path}/rootfs/bootstrap"
chroot "${build_path}/rootfs" /bootstrap
rm "${build_path}/rootfs/bootstrap"
# Final cleanup
rm ${build_path}/rootfs/usr/bin/qemu-aarch64-static
rm "${build_path}/rootfs/usr/bin/qemu-aarch64-static"

View file

@ -21,8 +21,8 @@ genimage \
--inputpath "${build_path}/final" \
--outputpath "${build_path}/final" \
--config "${build_path}/genimage.cfg"
mv ${build_path}/final/emmc.img ${build_path}/final/debian-UNVRPRO.img
gzip ${build_path}/final/debian-UNVRPRO.img
mv ${build_path}/final/emmc.img ${build_path}/final/debian-${BOARD}.img
gzip ${build_path}/final/debian-${BOARD}.img
rm -rf /tmp/genimage-initial-tmppath # Cleanup
# Cleanup

View file

@ -6,9 +6,17 @@ build_path="${root_path}/BuildEnv"
# Docker image name
docker_tag=unvr-nas:builder
# Expected UNVR Firmware and hash
firmware_filename="f449-UNVRPRO-4.0.3-fdec2c4f-1855-4eb6-8711-e22f8f904922.bin"
firmware_md5="5dcdc03bdec1524767007fcd12e81777"
# Expected UNVR Firmware(s) and hash(s)
UNVR_firmware_filename="7f7c-UNVR-4.0.5-1d4b9c7d-926b-4ef4-88c6-23978c2455a8.bin"
UNVR_firmware_md5="3bab9336619125e7fe6e4af7484a79dc"
UNVRPRO_firmware_filename="b0a3-UNVRPRO-4.0.5-f221e29e-3405-4cb9-8d13-0f117d9cc3a1.bin"
UNVRPRO_firmware_md5="f6aec555fa79c4e083168ec2aac4a71a"
# Render our board out
fwfnvar="${BOARD}_firmware_filename"
firmware_filename="${!fwfnvar}"
fwmd5var="${BOARD}_firmware_md5"
firmware_md5="${!fwmd5var}"
# Toolchain
toolchain_url="https://developer.arm.com/-/media/Files/downloads/gnu/12.2.rel1/binrel/arm-gnu-toolchain-12.2.rel1-x86_64-aarch64-none-linux-gnu.tar.xz"