Skip to content

Commit b5f6438

Browse files
authored
Merge pull request #11 from journey-wang/master
generate headers when building kernel && support nvidia
2 parents c5f48d2 + 55a2786 commit b5f6438

File tree

2 files changed

+139
-1
lines changed

2 files changed

+139
-1
lines changed

linux/build.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,23 @@ function kernel_build() {
273273
cp arch/x86/boot/bzImage ${INSTALL_PATH}/vmlinuz-${_KERNEL_VERSION}
274274
cp System.map ${INSTALL_PATH}/System.map-${_KERNEL_VERSION}
275275
cp .config ${INSTALL_PATH}/config-${_KERNEL_VERSION}
276-
cp install_kernel.sh ${INSTALL_PATH}
276+
cp install*.sh ${INSTALL_PATH}
277+
278+
# build header
279+
# TODO to replace with an elegant method
280+
rsync -a scripts ${INSTALL_PATH}/linux-headers-${_KERNEL_VERSION}/
281+
rsync -a arch block certs crypto Documentation drivers firmware fs include init ipc Kbuild Kconfig kernel lib Makefile mm modules.builtin modules.order Module.symvers net samples security sound System.map tools usr virt ${INSTALL_PATH}/linux-headers-${_KERNEL_VERSION}/ --exclude=*.c --exclude=*.ko --exclude=*.o --exclude=.git* --exclude=*.dts* --exclude=*.S --exclude=*.txt --exclude=*o.cmd
282+
for i in `find ${INSTALL_PATH}/linux-headers-${_KERNEL_VERSION}/ -type f|grep -v Kconfig|grep -v Makefile|grep -v Kbuild|grep -v pl |grep -v include|grep -v .sh|grep -v scripts|grep -v arch|grep -v Module|grep -v module |grep -v .config |grep -v System.map |grep -v .vmlinux.cmd |grep -v .version`; do rm -rf $i; done
277283

278284
cd ${INSTALL_PATH}
279285
depmod -a -b . -w ${_KERNEL_VERSION}
280286

281287
mv lib/* . && rm -r lib
288+
# remove source link
289+
rm -f modules/${_KERNEL_VERSION}/source
290+
rm -f modules/${_KERNEL_VERSION}/build
291+
ln -s /usr/src/linux-headers-${_KERNEL_VERSION} modules/${_KERNEL_VERSION}/build
292+
282293
mkdir install
283294
mv * install
284295
for i in `find install -name "*.ko" `; do strip --strip-unneeded $i; done

linux/install-nvidia.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
3+
BUILD_BASE=`pwd`
4+
NV_FILE="NVIDIA-Linux-x86_64-375.39.run"
5+
NV_URL="http://us.download.nvidia.com/XFree86/Linux-x86_64/375.39/${NV_FILE}"
6+
NEED_TO_COMPILE_NV_KO=0
7+
8+
function clean_env() {
9+
10+
[ -d ./${NV_DIR} ] && rm -rf ./${NV_DIR}
11+
}
12+
13+
function check_env() {
14+
15+
# check if in apollo kernel
16+
uname -r | grep apollo 1>/dev/null 2>&1
17+
if [ $? -ne 0 ]
18+
then
19+
echo "Not in apollo kernel, Please install apollo kernel and reboot machine first."
20+
exit 2
21+
fi
22+
23+
# check if nv ko already in kernel
24+
if [ ! -f /lib/modules/`uname -r`/kernel/drivers/video/nvidia.ko ]
25+
then
26+
export NEED_TO_COMPILE_NV_KO=1
27+
fi
28+
}
29+
30+
function prepare_nv() {
31+
32+
# download nv install file from nvidia home page
33+
if [ ! -f ./${NV_FILE} ]
34+
then
35+
echo "Downloading ${NV_FILE} from nvidia website..."
36+
wget ${NV_URL} -O ${NV_FILE}
37+
if [ $? -ne 0 ]
38+
then
39+
echo "Downloading ${NV_FILE} failed, please check your network connection!"
40+
rm -rf ./${NV_FILE}
41+
exit 1
42+
fi
43+
fi
44+
45+
# +x
46+
chmod +x ./${NV_FILE}
47+
echo "Extracting nvidia install run file..."
48+
./${NV_FILE} -x 1>/dev/null 2>&1
49+
NV_DIR="`echo ${NV_FILE} | awk -F '.run' '{print $1}'`"
50+
NV_VERSION="`echo ${NV_FILE} | awk -F '-' '{print $4}' | awk -F '.run' '{print $1}'`"
51+
52+
export NV_DIR
53+
export NV_VERSION
54+
export NVIDIA_SOURCE="${NV_DIR}/kernel"
55+
}
56+
57+
function install_lib() {
58+
59+
NV_LIB_OUTPUT_PATH="/usr/lib/x86_64-linux-gnu/"
60+
NV_BIN_OUTPUT_PATH="/usr/bin/"
61+
62+
[ -f ./${NV_DIR}/libnvidia-ml.so.${NV_VERSION} ] && /bin/cp -f ./${NV_DIR}/libnvidia-ml.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH}
63+
[ -f ./${NV_DIR}/libnvidia-fatbinaryloader.so.${NV_VERSION} ] && /bin/cp -f ./${NV_DIR}/libnvidia-fatbinaryloader.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH}
64+
[ -f ./${NV_DIR}/libnvidia-ptxjitcompiler.so.${NV_VERSION} ] && /bin/cp -f ./${NV_DIR}/libnvidia-ptxjitcompiler.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH}
65+
[ -f ./${NV_DIR}/libcuda.so.${NV_VERSION} ] && /bin/cp -f ./${NV_DIR}/libcuda.so.${NV_VERSION} ${NV_LIB_OUTPUT_PATH}
66+
[ -f ./${NV_DIR}/nvidia-modprobe ] && /bin/cp -f ./${NV_DIR}/nvidia-modprobe ${NV_BIN_OUTPUT_PATH}
67+
[ -f ./${NV_DIR}/nvidia-smi ] && /bin/cp -f ./${NV_DIR}/nvidia-smi ${NV_BIN_OUTPUT_PATH}
68+
69+
chmod +x /usr/bin/nvidia*
70+
chmod +s /usr/bin/nvidia-modprobe
71+
72+
# link for nvidia
73+
/bin/rm -rf /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /usr/lib/x86_64-linux-gnu/libnvidia-ml.so
74+
/bin/ln -s /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.${NV_VERSION} /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1
75+
/bin/ln -s /usr/lib/x86_64-linux-gnu/libnvidia-ml.so.1 /usr/lib/x86_64-linux-gnu/libnvidia-ml.so
76+
77+
/bin/rm -rf /usr/lib/x86_64-linux-gnu/libcuda.so /usr/lib/x86_64-linux-gnu/libcuda.so.1
78+
/bin/ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.${NV_VERSION} /usr/lib/x86_64-linux-gnu/libcuda.so.1
79+
/bin/ln -s /usr/lib/x86_64-linux-gnu/libcuda.so.1 /usr/lib/x86_64-linux-gnu/libcuda.so
80+
81+
# take effect
82+
/sbin/ldconfig 1>/dev/null 2>&1
83+
}
84+
85+
function build_nv() {
86+
87+
if [ ${NEED_TO_COMPILE_NV_KO} == 0 ]
88+
then
89+
return
90+
fi
91+
92+
NVIDIA_MOD_REL_PATH='kernel/drivers/video'
93+
NVIDIA_OUTPUT_PATH="/lib/modules/`uname -r`/${NVIDIA_MOD_REL_PATH}"
94+
CPUNUM=`cat /proc/cpuinfo | grep processor | wc | awk -F " " '{print $1}'`
95+
96+
export IGNORE_PREEMPT_RT_PRESENCE=true
97+
cd ${NVIDIA_SOURCE} && make -j ${CPUNUM} module
98+
cd ${BUILD_BASE}
99+
100+
unset IGNORE_PREEMPT_RT_PRESENCE
101+
102+
mkdir -p ${NVIDIA_OUTPUT_PATH}
103+
104+
[ -f ${NVIDIA_SOURCE}/nvidia.ko ] && cp ${NVIDIA_SOURCE}/nvidia.ko ${NVIDIA_OUTPUT_PATH}
105+
[ -f ${NVIDIA_SOURCE}/nvidia-modeset.ko ] && cp ${NVIDIA_SOURCE}/nvidia-modeset.ko ${NVIDIA_OUTPUT_PATH}
106+
[ -f ${NVIDIA_SOURCE}/nvidia-drm.ko ] && cp ${NVIDIA_SOURCE}/nvidia-drm.ko ${NVIDIA_OUTPUT_PATH}
107+
[ -f ${NVIDIA_SOURCE}/nvidia-uvm.ko ] && cp ${NVIDIA_SOURCE}/nvidia-uvm.ko ${NVIDIA_OUTPUT_PATH}
108+
109+
depmod -a
110+
}
111+
112+
# check environment
113+
check_env
114+
115+
# prepare for nvidia
116+
prepare_nv
117+
118+
# build nvidia.ko
119+
build_nv
120+
121+
# install user lib
122+
install_lib
123+
124+
# clean environment
125+
clean_env
126+
127+
echo "Done to install nvidia kernel driver and user libraries."

0 commit comments

Comments
 (0)