fix: add btrfs support using magic (#5)

* Use old GPL release from https://github.com/fabianishere/udm-kernel/tree/master to build and steal it's btrfs kernel module + depends.
* Can't use full kernel, NIC issues everywhere, so we will just use it for btrfs for OMV. Will move to our own kernel fully if I can get an updated GPL release from Ui.
* BONUS: Fixup issue where system would reboot when shutdown from touch screen
This commit is contained in:
Chris Blake 2024-05-30 17:42:12 -05:00 committed by GitHub
parent be235b00ac
commit f399e13958
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 495 additions and 8 deletions

View file

@ -0,0 +1,27 @@
#!/bin/bash
set -e
# Source our common vars
scripts_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. ${scripts_path}/vars.sh
debug_msg "Starting 02_download_dependencies.sh"
# Make sure our BuildEnv dir exists
if [ ! -d ${root_path}/downloads ]; then
mkdir ${root_path}/downloads
fi
# Toolchain
if [ ! -f ${root_path}/downloads/${toolchain_filename} ]; then
debug_msg "Downloading toolchain..."
wget ${toolchain_url} -P ${root_path}/downloads
fi
# Kernel
if [ ! -f ${root_path}/downloads/${kernel_filename} ]; then
debug_msg "Downloading Kernel..."
wget ${kernel_src} -O ${root_path}/downloads/${kernel_filename}
fi
debug_msg "Finished 02_download_dependencies.sh"

View file

@ -7,6 +7,18 @@ scripts_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
debug_msg "Starting 03_docker.sh"
# Start with things we can do now
if [ ! -d ${build_path}/toolchain ]; then
debug_msg "Setting up the toolchain for docker..."
mkdir -p ${build_path}/toolchain
tar -xf ${root_path}/downloads/${toolchain_filename} -C ${build_path}/toolchain
fi
if [ ! -d ${build_path}/kernel ]; then
debug_msg "Docker: Building Kernel..."
docker run --ulimit nofile=1024 --rm -v "${root_path}:/repo:Z" -it ${docker_tag} /repo/scripts/docker/build_kernel.sh
fi
debug_msg "Doing safety checks... please enter your password for sudo if prompted..."
# Before we do anything, make our dirs, and validate they are not mounted atm. If they are, exit!
if mountpoint -q ${build_path}/rootfs/boot; then

View file

@ -20,6 +20,6 @@ docker run --rm -v "${root_path}:/repo:Z" -it ${docker_tag} /repo/scripts/docker
TIMESTAMP=`date +%Y%m%d-%H%M`
mkdir -p ${root_path}/output/${TIMESTAMP}
mv ${build_path}/final/debian*.img.gz ${root_path}/output/${TIMESTAMP}/
sudo rm -rf ${build_path} # Be gone, we done buildin! :)
#sudo rm -rf ${build_path} # Be gone, we done buildin! :)
debug_msg "Finished 04_post_docker.sh"
debug_msg "Finished 04_post_docker.sh"

View file

@ -10,6 +10,9 @@ export APT_LISTCHANGES_FRONTEND=none
debconf-set-selections /debconf.set
rm -f /debconf.set
# Run depmod for our kernel so we pick up btrfs + more
depmod -a 4.19.152-alpine-unvr
# Initial package install
apt-get clean
apt-get update

54
scripts/docker/build_kernel.sh Executable file
View file

@ -0,0 +1,54 @@
#!/bin/bash
set -e
scripts_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )"
. ${scripts_path}/vars.sh
# Make our temp builddir outside of the world of mounts for SPEEDS
kernel_builddir=$(mktemp -d)
tar -xzf ${root_path}/downloads/${kernel_filename} -C ${kernel_builddir}
# Exports baby
export PATH=${build_path}/toolchain/${toolchain_bin_path}:${PATH}
export GCC_COLORS=auto
export CROSS_COMPILE=${toolchain_cross_compile}
export ARCH=arm64
# Here we go
cd ${kernel_builddir}/${kernel_filename%.tar.gz}
# If we have patches, apply them
if [[ -d ${root_path}/patches/kernel/ ]]; then
for file in ${root_path}/patches/kernel/*.patch; do
echo "Applying kernel patch ${file}"
patch -p1 < ${file}
done
fi
# Apply overlay if it exists
if [[ -d ${root_path}/overlay/${kernel_overlay_dir}/ ]]; then
echo "Applying ${kernel_overlay_dir} overlay"
cp -R ${root_path}/overlay/${kernel_overlay_dir}/* ./
fi
# Normally we would build a full kernel, but the old GPL doesn't work right with NICs and I don't
# want to debug a 2+ year old GPL source. Waiting for Unifi to release the lastest GPL code, and
# then we can fully move to our own custom kernel but for now we just use the old GPL to strip out
# some modules. This is why some lines below are commented out.
# Build as normal, with our extra version set to a timestamp
make ${kernel_config}
make -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr # Build kernel and modules
#make -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr Image.gz # makes gzip image
make INSTALL_MOD_PATH=./modules-dir -j`getconf _NPROCESSORS_ONLN` EXTRAVERSION=-alpine-unvr modules_install # installs modules to dir
#mkimage -A arm64 -O linux -T kernel -C gzip -a 04080000 -e 04080000 -n "Linux-UNVR-NAS-$(date +%Y%m%d-%H%M%S)" -d ./arch/arm64/boot/Image.gz uImage
# Save our config
mkdir -p ${build_path}/kernel
make savedefconfig
mv defconfig ${build_path}/kernel/kernel_config
# Save our kernel(s) and libs
#cp ./arch/arm64/boot/Image.gz ${build_path}/kernel
#mv uImage ${build_path}/kernel
mv ./modules-dir ${build_path}/kernel/kernel-modules

View file

@ -19,10 +19,15 @@ debootstrap --no-check-gpg --foreign --arch=${deb_arch} --include=apt-transport-
cp /usr/bin/qemu-aarch64-static usr/bin/
chroot ${build_path}/rootfs /debootstrap/debootstrap --second-stage
# Copy over our kernel modules and kernel
mv -f "${build_path}/fw-extract/rootfs/lib/modules" ${build_path}/rootfs/lib
# 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"
# 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/"
cp "${build_path}/kernel/kernel-modules/lib/modules/4.19.152-alpine-unvr/kernel/fs/btrfs/btrfs.ko" "${build_path}/rootfs/lib/modules/4.19.152-alpine-unvr/extra/"
# Copy over our overlay if we have one
if [[ -d ${root_path}/overlay/${fs_overlay_dir}/ ]]; then
echo "Applying ${fs_overlay_dir} overlay"

View file

@ -10,6 +10,18 @@ docker_tag=unvr-nas:builder
firmware_filename="f449-UNVRPRO-4.0.3-fdec2c4f-1855-4eb6-8711-e22f8f904922.bin"
firmware_md5="5dcdc03bdec1524767007fcd12e81777"
# 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"
toolchain_filename="$(basename ${toolchain_url})"
toolchain_bin_path="${toolchain_filename%.tar.xz}/bin"
toolchain_cross_compile="aarch64-none-linux-gnu-"
# Kernel
kernel_src="https://github.com/fabianishere/udm-kernel/archive/refs/heads/master.tar.gz"
kernel_filename="udm-kernel-master.tar.gz"
kernel_config="alpine_v2_defconfig"
kernel_overlay_dir="kernel"
# Genimage
genimage_src="https://github.com/pengutronix/genimage/releases/download/v16/genimage-16.tar.xz"
genimage_filename="$(basename ${genimage_src})"