-
Notifications
You must be signed in to change notification settings - Fork 0
/
kmk
executable file
·153 lines (130 loc) · 3.6 KB
/
kmk
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
function usage () {
cat <<EOUSAGE
$(basename $0) [--kdir kernel-dir] [--dconf deconfig]
--kdir: Kernel Source Address
--dconf: defconfig to use
--kout: Kernel build output
--help: Show this help
EOUSAGE
exit 0
}
extra_args=
kernel_dir=$(realpath "${HOME}/work/src/linux")
dconfig="defconfig"
kernel_out="~/work/tmp/linux-out"
aparse() {
while [[ $# > 0 ]] ; do
case "$1" in
--kdir)
kernel_dir=$2
shift 2
echo "Using kernel at ${kernel_dir}"
;;
--dconf)
dconfig=$2
shift 2
;;
--kout)
kernel_out=$2
if [ ! -e $2 ]; then
mkdir -p $2
fi
shift 2
;;
--help)
usage
shift
;;
*)
extra_args="$extra_args $1"
shift
;;
esac
done
}
aparse "$@"
echo extra args: $extra_args
echo ${dconfig}
#
# Auto probe toolchains
#
export ARCH=arm64
cross_toolchains=(
aarch64-none-elf-
aarch64-unknown-linux-gnu-
)
for cross_toolchain in ${cross_toolchains[@]}
do
which ${cross_toolchain}gcc 1>/dev/null 2>&1
if [ $? == 0 ]; then
echo "Found ${cross_toolchain}"
export CROSS_COMPILE=${cross_toolchain}
break
fi
done
if [ -z $CROSS_COMPILE ]; then
echo "Can't found a valid toolchains"
exit -1
fi
pushd $kernel_dir
# use clang
export LLVM=1
if [ x"$extra_args" != x ]; then
lkmake O=${kernel_out} $extra_args -j8
exit $?
fi
eval kernel_out=$kernel_out
export OUT_BUILD_KERNEL_DIR=$kernel_out
export SRC_KERNEL_DIR=$kernel_dir
export KCFLAGS="-Wno-int-conversion -Wno-incompatible-pointer-types-discards-qualifiers"
# Remove outdated kernel module
rm -rif ${kernel_out}/_install
#ROOTFS=~/work/src/rootfs/rootfs.cpio.gz
ROOTFS=~/work/images/initramfs.cpio
# ~/work/src/rootfs/rootfs.cpio.gz
mkdir -p ${kernel_out}/_install
lkmake O=${kernel_out} ${dconfig}
echo "apply my enabled configs"
ENABLE_CONFIGS=(
CONFIG_GDB_SCRIPTS
CONFIG_DYNAMIC_DEBUG_CORE
CONFIG_DYNAMIC_DEBUG
CONFIG_FW_LOADER_DEBUG
CONFIG_TEST_DYNAMIC_DEBUG
CONFIG_DEBUG_IRQFLAGS
CONFIG_VIRTIO_MMIO
CONFIG_VIRTIO_NET
CONFIG_BLK_DEV_INITRD
CONFIG_RD_GZIP
CONFIG_GENERIC_PTDUMP
CONFIG_PTDUMP_CORE
CONFIG_PTDUMP_DEBUGFS
)
for config in ${ENABLE_CONFIGS[@]}; do
echo "enable config: ${config}"
${kernel_out}/source/scripts/config --file ${kernel_out}/.config -e $config
done
echo "apply my disabled configs"
DISABLE_CONFIGS=(
CONFIG_MODULE_SIG
CONFIG_MODVERSIONS
)
for config in ${DISABLE_CONFIGS[@]}; do
echo "disable config: ${config}"
${kernel_out}/source/scripts/config --file ${kernel_out}/.config -d $config
done
lkmake O=${kernel_out} -j8
lkmake O=${kernel_out} modules_install INSTALL_MOD_PATH=${kernel_out}/_install 2>/dev/null
#LINUX_VER=$(cat ${kernel_out}/include/config/kernel.release)
#depmod -b ${kernel_out}/_install/lib/modules/${LINUX_VER} -F ${kernel_out}/System.map ${LINUX_VER}
if [ -e ~/work/src/code_snippet/kernel_moduless/ ]; then
export KERNELDIR=${kernel_out}
export ROOT_DIR=~/work/src/code_snippet/
pushd ~/work/src/code_snippet/kernel_module/
lkmake -j8
find . -name "*.ko" -exec ${KERNELDIR}/scripts/sign-file sha512 ${KERNELDIR}/certs/signing_key.pem ${KERNELDIR}/certs/signing_key.x509 {} \;
popd
fi
# ~/work/sync.sh
popd