Last active
July 10, 2019 14:59
-
-
Save satmandu/b60a804fa2275615c88367bc68e4bad0 to your computer and use it in GitHub Desktop.
Workaround for ubuntu mainline kernel cross-compile issues with module building files compiled in wrong architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This should go in /etc/kernel/header_postinst.d | |
kernelver=$1 | |
files=("scripts/recordmcount" "scripts/mod/modpost" \ | |
"scripts/basic/fixdep") | |
rebuild=0 | |
ARCH=`uname -m` | |
for i in "${files[@]}" | |
do | |
ARCHCHECK=`file /usr/src/linux-headers-$kernelver/$i |grep -c $ARCH` | |
if [ "$ARCHCHECK" = "1" ] ; then | |
echo "correct arch for $i" | |
else | |
echo "wrong arch for $i, rebuilding scripts" | |
rm /usr/src/linux-headers-$kernelver/$i | |
rebuild=1 | |
fi | |
done | |
if [ "$rebuild" = "0" ] ; | |
then exit 0 | |
fi | |
echo "Rebuilding Ubuntu Mainline module infrastructure for non-AMD64 arch" | |
echo "Note also that you will need to install the following" | |
echo "packages first using:" | |
echo "sudo apt install bison dkms flex gcc libssl-dev -y" | |
echo "Otherwise this process will fail." | |
majorversion=`grep VERSION /usr/src/linux-headers-$kernelver/Makefile | head -1 | awk -F ' = ' '{print $2}'` | |
patchlevel=`grep PATCHLEVEL /usr/src/linux-headers-$kernelver/Makefile | head -1 | awk -F ' = ' '{print $2}'` | |
sublevel=`grep SUBLEVEL /usr/src/linux-headers-$kernelver/Makefile | head -1 | awk -F ' = ' '{print $2}'` | |
extraversion=`grep EXTRAVERSION /usr/src/linux-headers-$kernelver/Makefile | head -1 | awk -F ' = ' '{print $2}'` | |
if [ ! -z "$extraversion" ]; then | |
export kernid=$majorversion.$patchlevel$extraversion | |
else | |
export kernid=$majorversion.$patchlevel.$sublevel | |
fi | |
echo "Now downloading missing headers needed for rebuild." | |
files=("security/selinux/include/classmap.h" \ | |
"security/selinux/include/initial_sid_to_string.h" \ | |
"tools/include/tools/be_byteshift.h" \ | |
"tools/include/tools/le_byteshift.h") | |
for i in "${files[@]}" | |
do | |
if [ ! -f /usr/src/linux-headers-$kernelver/$i ]; then | |
echo "Downloading $kernelver/$i" | |
# curl --create-dirs -o /usr/src/linux-headers-$kernelver/$i https://git.launchpad.net/~ubuntu-kernel-test/ubuntu/+source/linux/+git/mainline-crack/plain/$i?id=v$kernid | |
curl --create-dirs -o /usr/src/linux-headers-$kernelver/$i \ | |
https://raw.githubusercontent.com/torvalds/linux/v$kernid/$i | |
fi | |
done | |
cd /usr/src/linux-headers-$kernelver | |
# This next step is known to fail, but gets most of what is needed done. | |
make modules_prepare 2>/dev/null | |
#make scripts_basic | |
#make scripts/recordmcount | |
#make scripts/mod/modpost | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment