Skip to content

Commit

Permalink
Fix linux-header debian package
Browse files Browse the repository at this point in the history
Add missing files to allow build out-of-tree kernel modules.
  • Loading branch information
andrejro committed Feb 21, 2024
1 parent 9800ad1 commit 3366929
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 18 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}/' | \
Expand All @@ -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

Expand Down Expand Up @@ -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
52 changes: 52 additions & 0 deletions tools/prepare_headers.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3366929

Please sign in to comment.