forked from longsleep/build-pine64-image
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install_kernel_headers.sh
executable file
·70 lines (54 loc) · 2.75 KB
/
install_kernel_headers.sh
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
#!/bin/sh
set -e
DEST=$(readlink -f "$1")
if [ -z "$DEST" ]; then
echo "Usage: $0 <destination-root> [linux-folder]"
exit 1
fi
LINUX="linux-pine64"
echo "Using Linux from $LINUX ..."
VERSION=$(strings $LINUX/arch/arm64/boot/Image |grep "Linux version"|awk '{print $3}')
echo "Kernel build version $VERSION ..."
if [ -z "$VERSION" ]; then
echo "Failed to get build version, correct <linux-folder>?"
exit 1
fi
LINUX_ARCH=arm64
CROSS_COMPILE=aarch64-linux-gnu-
cd $LINUX
TARGET="$DEST/usr/src/linux-headers-$VERSION"
mkdir -p "$TARGET"
cp -a Makefile "$TARGET"
mkdir -p "$TARGET/arch/$LINUX_ARCH"
cp -a arch/$LINUX_ARCH/Makefile "$TARGET/arch/$LINUX_ARCH"
cp -a Module.symvers "$TARGET"
# Install Kernel headers
make ARCH=$LINUX_ARCH CROSS_COMPILE=$CROSS_COMPILE headers_install INSTALL_HDR_PATH="$TARGET"
tar cfh - include | (cd "$TARGET"; umask 000; tar xsf -)
tar cfh - scripts | (cd "$TARGET"; umask 000; tar xsf -)
find . -path './scripts/*' -prune -o -path './Documentation/*' -prune -o \
-path './debian/*' -prune -o -type f \
\( -name Makefile -o -name 'Kconfig*' \) -print | \
cpio -pd --preserve-modification-time "$TARGET";
# Clean compile host executables and replace some with target arch.
find "$TARGET/scripts" -type f | while read i; do if file -b $i | egrep -q "^ELF.*executable"; then rm "$i"; fi; done
(cd scripts && ${CROSS_COMPILE}gcc kallsyms.c -o "$TARGET/scripts/kallsyms")
(cd scripts && ${CROSS_COMPILE}gcc pnmtologo.c -o "$TARGET/scripts/pnmtologo")
(cd scripts && ${CROSS_COMPILE}gcc conmakehash.c -o "$TARGET/scripts/conmakehash")
(cd scripts && ${CROSS_COMPILE}gcc bin2c.c -o "$TARGET/scripts/bin2c")
(cd scripts && ${CROSS_COMPILE}gcc recordmcount.c -o "$TARGET/scripts/recordmcount")
(cd scripts && ${CROSS_COMPILE}gcc -I../tools/include sortextable.c -o "$TARGET/scripts/sortextable")
(cd scripts && ${CROSS_COMPILE}gcc unifdef.c -o "$TARGET/scripts/unifdef")
(cd scripts/basic && ${CROSS_COMPILE}gcc fixdep.c -o "$TARGET/scripts/basic/fixdep")
(cd scripts/mod && ${CROSS_COMPILE}gcc modpost.c file2alias.c sumversion.c -o "$TARGET/scripts/mod/modpost")
(cd scripts/mod && ${CROSS_COMPILE}gcc mk_elfconfig.c -o "$TARGET/scripts/mod/mk_elfconfig")
(cd scripts/genksyms && ${CROSS_COMPILE}gcc genksyms.c parse.tab.c lex.lex.c -o "$TARGET/scripts/genksyms/genksyms")
find arch/$LINUX_ARCH/include \
-print | cpio -pdL --preserve-modification-time "$TARGET";
mkdir -p "$TARGET/arch/um"
cp -a arch/um/Makefile* "$TARGET/arch/um/"
mkdir -p "$TARGET/arch/$LINUX_ARCH/kernel"
cp -a arch/$LINUX_ARCH/kernel/asm-offsets.s "$TARGET/arch/$LINUX_ARCH/kernel"
rm -f "$TARGET/include/linux/version.h"
cp -a .config "$TARGET/"
echo "Done - installed Kernel headers to $DEST"