diff --git a/.github/workflows/build-all.yml b/.github/workflows/build-all.yml index 78c5ffc..97d6e3c 100644 --- a/.github/workflows/build-all.yml +++ b/.github/workflows/build-all.yml @@ -56,7 +56,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ - bc binfmt-support bzip2 fakeroot gcc gcc-arm-linux-gnueabihf git \ + bc binfmt-support bzip2 fakeroot file gcc gcc-arm-linux-gnueabihf git \ gnupg make parted rsync qemu-user-static wget xz-utils zip debootstrap \ sudo dirmngr bison flex libssl-dev kmod @@ -86,7 +86,7 @@ jobs: run: | sudo apt-get update sudo apt-get install -y \ - bc binfmt-support bzip2 fakeroot gcc gcc-arm-linux-gnueabihf git \ + bc binfmt-support bzip2 fakeroot file gcc gcc-arm-linux-gnueabihf git \ gnupg make parted rsync qemu-user-static wget xz-utils zip debootstrap \ sudo dirmngr bison flex libssl-dev kmod diff --git a/Dockerfile b/Dockerfile index 7c8ead0..bd9e540 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y RUN apt-get install -y \ - bc binfmt-support bzip2 fakeroot gcc gcc-arm-linux-gnueabihf \ + bc binfmt-support bzip2 fakeroot file gcc gcc-arm-linux-gnueabihf \ git gnupg make parted rsync qemu-user-static wget xz-utils zip \ debootstrap sudo dirmngr bison flex libssl-dev kmod udev cpio \ apt-utils diff --git a/Makefile b/Makefile index 652d55b..30177ee 100644 --- a/Makefile +++ b/Makefile @@ -323,10 +323,24 @@ linux-image-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf. #### linux-headers-deb #### -HEADER_DEPS := linux-${LINUX_VER}/arch/arm/boot/zImage +tmp-rootfs: + mkdir -p tmp-rootfs + sudo update-binfmts --enable qemu-arm + sudo qemu-debootstrap \ + --include=bc,bison,file,flex,gcc,libc6-dev,make,ssh,sudo,vim \ + --arch=armhf bookworm tmp-rootfs http://deb.debian.org/debian/ + +tmp-rootfs/linux-${LINUX_VER}/scripts/basic/fixdep: tmp-rootfs linux-${LINUX_VER}.tar.xz + sudo rm -rf tmp-rootfs/linux-${LINUX_VER} tmp-rootfs/linux-${LINUX_VER}.tar.xz + sudo tar xvf linux-${LINUX_VER}.tar.xz -C tmp-rootfs/ + sudo wget ${USBARMORY_REPO}/software/kernel_conf/usbarmory_linux-${LINUX_VER_MAJOR}.defconfig -O tmp-rootfs/linux-${LINUX_VER}/.config + sudo chroot tmp-rootfs mount -t proc none /proc + sudo chroot tmp-rootfs bash -c "cd linux-${LINUX_VER}; make olddefconfig scripts modules_prepare" + sudo chroot tmp-rootfs umount /proc + +HEADER_DEPS := linux-${LINUX_VER}/arch/arm/boot/zImage tmp-rootfs/linux-${LINUX_VER}/scripts/basic/fixdep linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf.deb: $(HEADER_DEPS) mkdir -p linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/{DEBIAN,boot,lib/modules/${LINUX_VER}${LOCALVERSION}/build} - cd linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/lib/modules/${LINUX_VER}${LOCALVERSION} ; ln -sf build source cat control_template_linux-headers | \ sed -e 's/XXXX/${LINUX_VER_MAJOR}/' | \ sed -e 's/YYYY/${LINUX_VER}${LOCALVERSION}/' | \ @@ -337,7 +351,7 @@ linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armh sed -i -e 's/${LINUX_VER_MAJOR}-usbarmory/${LINUX_VER_MAJOR}-usbarmory-mark-two/' \ linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/DEBIAN/control; \ fi - cd linux-${LINUX_VER} && make INSTALL_HDR_PATH=../linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/lib/modules/${LINUX_VER}${LOCALVERSION}/build ARCH=arm headers_install + cd linux-${LINUX_VER} && ../tools/prepare_headers.sh ../tmp-rootfs/linux-${LINUX_VER} ../linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/lib/modules/${LINUX_VER}${LOCALVERSION}/build chmod 755 linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf/DEBIAN fakeroot dpkg-deb -b linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf linux-headers-${LINUX_VER_MAJOR}-usbarmory-${V}_${LINUX_VER}${LOCALVERSION}_armhf.deb @@ -411,5 +425,6 @@ clean: -rm -fr armoryctl* crucible* linux-* linux-image-* linux-headers-* u-boot-* -rm -fr mxc-scc2-master* mxs-dcp-master* caam-keyblob-master* -rm -f usbarmory-*.raw + -sudo rm -fr tmp-rootfs -sudo umount -f rootfs -rmdir rootfs diff --git a/tools/prepare_headers.sh b/tools/prepare_headers.sh new file mode 100755 index 0000000..063d263 --- /dev/null +++ b/tools/prepare_headers.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# Based on: +# https://gitlab.archlinux.org/archlinux/packaging/packages/linux/-/blob/main/PKGBUILD + +scriptlinuxdir=$(realpath $1) +builddir=$(realpath $2) + +echo "Installing build files..." +install -Dt "$builddir" -m644 .config Makefile Module.symvers System.map vmlinux +install -Dt "$builddir/kernel" -m644 kernel/Makefile +install -Dt "$builddir/arch/arm" -m644 arch/arm/Makefile +cp -t "$builddir" -a scripts +echo "Overwrite executable files with arm native ones..." +cd $scriptlinuxdir && find scripts -type f -executable -exec install -Dm755 {} "${builddir}/{}" \; && cd - + +echo "Installing headers..." +cp -t "$builddir" -a include +cp -t "$builddir/arch/arm" -a arch/arm/include +install -Dt "$builddir/arch/arm/kernel" -m644 arch/arm/kernel/asm-offsets.s + +install -Dt "$builddir/drivers/md" -m644 drivers/md/*.h +install -Dt "$builddir/net/mac80211" -m644 net/mac80211/*.h + +# https://bugs.archlinux.org/task/13146 +install -Dt "$builddir/drivers/media/i2c" -m644 drivers/media/i2c/msp3400-driver.h + +# https://bugs.archlinux.org/task/20402 +install -Dt "$builddir/drivers/media/usb/dvb-usb" -m644 drivers/media/usb/dvb-usb/*.h +install -Dt "$builddir/drivers/media/dvb-frontends" -m644 drivers/media/dvb-frontends/*.h +install -Dt "$builddir/drivers/media/tuners" -m644 drivers/media/tuners/*.h + +# https://bugs.archlinux.org/task/71392 +install -Dt "$builddir/drivers/iio/common/hid-sensors" -m644 drivers/iio/common/hid-sensors/*.h + +echo "Installing KConfig files..." +find . -name 'Kconfig*' -exec install -Dm644 {} "$builddir/{}" \; + +echo "Removing unneeded architectures..." +for arch in "$builddir"/arch/*/; do + [[ $arch = */arm/ ]] && continue + echo "Removing $(basename "$arch")" + rm -r "$arch" +done + +echo "Removing documentation..." +rm -r "$builddir/Documentation" + +echo "Removing broken symlinks..." +find -L "$builddir" -type l -printf 'Removing %P\n' -delete + +echo "Removing loose objects..." +find "$builddir" -type f -name '*.o' -printf 'Removing %P\n' -delete