-
-
Notifications
You must be signed in to change notification settings - Fork 5
136 lines (114 loc) · 4.75 KB
/
kernel-driver-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Kernel driver build tests
on:
pull_request:
paths:
- "software/driver/**"
branches: [ "v2" ]
push:
paths:
- "software/driver/**"
branches: [ "v2" ]
workflow_dispatch:
env:
KERNEL_ROOT: "/opt/linux"
KERNEL_BRANCH: "stable_20240124" # Raspberry Pi kernel branch when building for arm64
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- arch: amd64
- arch: arm64
steps:
- name: Update install
run:
sudo apt-get update
timeout-minutes: 5
- name: Install build dependencies
run: |
if [[ "${{matrix.arch}}" == "amd64" ]]; then
# Native
sudo apt-get install build-essential
elif [[ "${{matrix.arch}}" == "arm64" ]]; then
# 64-bit ARM
sudo apt-get install crossbuild-essential-arm64
fi
timeout-minutes: 5
- name: Install Kernel headers
run: |
if [[ "${{matrix.arch}}" == "amd64" ]]; then
# Native
sudo apt-get install linux-headers-$(uname -r)
elif [[ "${{matrix.arch}}" == "arm64" ]]; then
# 64-bit ARM
# Build Raspberry Pi Kernel modules
sudo mkdir -p $KERNEL_ROOT
sudo chown $USER $KERNEL_ROOT
git clone --depth=1 --branch $KERNEL_BRANCH https://github.com/raspberrypi/linux $KERNEL_ROOT
cd $KERNEL_ROOT
KERNEL=kernel8
make ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- bcm2711_defconfig
make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- modules
fi
- uses: actions/checkout@v4
with:
fetch-depth: 1
clean: true
- name: Build Kernel driver (${{matrix.arch}})
run: |
cd ${{github.workspace}}/software/driver
if [[ "${{matrix.arch}}" == "amd64" ]]; then
# Native
make -j$(nproc)
elif [[ "${{matrix.arch}}" == "arm64" ]]; then
# 64-bit ARM
make -j$(nproc) ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- KPATH=$KERNEL_ROOT
fi
- name: Make deb package (${{matrix.arch}})
run: |
mkdir deb
mkdir deb/DEBIAN
cp ${{github.workspace}}/software/driver/.deb/* deb/DEBIAN/
MOD_VERSION=$(cat ${{github.workspace}}/software/driver/src/icyradio.c | grep MODULE_VERSION | sed "s@MODULE_VERSION(\"@@g" | sed "s@\");@@g")
echo "Architecture: ${{matrix.arch}}" >> deb/DEBIAN/control
echo "Version: ${MOD_VERSION}" >> deb/DEBIAN/control
echo "" >> deb/DEBIAN/control
echo "#!/bin/sh" >> deb/DEBIAN/postinst
echo "" >> deb/DEBIAN/postinst
echo "dkms add -m icyradio -v ${MOD_VERSION}" >> deb/DEBIAN/postinst
echo "dkms build -m icyradio -v ${MOD_VERSION} && dkms install -m icyradio -v ${MOD_VERSION} || true" >> deb/DEBIAN/postinst
echo "" >> deb/DEBIAN/postinst
chmod +x deb/DEBIAN/postinst
echo "#!/bin/sh" >> deb/DEBIAN/prerm
echo "" >> deb/DEBIAN/prerm
echo "dkms remove -m icyradio -v ${MOD_VERSION} --all || true" >> deb/DEBIAN/prerm
echo "" >> deb/DEBIAN/prerm
chmod +x deb/DEBIAN/prerm
mkdir -p deb/usr/src/icyradio-${MOD_VERSION}
cp ${{github.workspace}}/software/driver/Makefile deb/usr/src/icyradio-${MOD_VERSION}
cp -r ${{github.workspace}}/software/driver/src deb/usr/src/icyradio-${MOD_VERSION}
cp -r ${{github.workspace}}/software/driver/include deb/usr/src/icyradio-${MOD_VERSION}
echo "PACKAGE_NAME=\"icyradio\"" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
echo "PACKAGE_VERSION=\"${MOD_VERSION}\"" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
echo "BUILT_MODULE_NAME[0]=\"icyradio\"" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
echo "DEST_MODULE_LOCATION[0]=\"/extra\"" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
echo "AUTOINSTALL=\"yes\"" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
echo "" >> deb/usr/src/icyradio-${MOD_VERSION}/dkms.conf
dpkg-deb --build --root-owner-group ./deb ${{github.workspace}}/software/driver/icyradio-driver_${{matrix.arch}}.deb
- name: Test deb package (DKMS) (${{matrix.arch}})
run: |
if [[ "${{matrix.arch}}" == "amd64" ]]; then
sudo apt-get install dkms
sudo dpkg -i ${{github.workspace}}/software/driver/icyradio-driver_${{matrix.arch}}.deb
else
echo "Cross-testing DKMS not implemented, skipping"
fi
- name: Upload results
uses: actions/upload-artifact@v4
with:
name: kernel_driver_${{matrix.arch}}
path: |
${{github.workspace}}/software/driver/icyradio.ko
${{github.workspace}}/software/driver/icyradio-driver_${{matrix.arch}}.deb
retention-days: 30