forked from friendlyarm/sd-fuse_s5p6818
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-kernel.sh
executable file
·196 lines (174 loc) · 5.39 KB
/
build-kernel.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
set -eu
# Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
# (http://www.friendlyarm.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, you can access it online at
# http://www.gnu.org/licenses/gpl-2.0.html.
true ${SOC:=s5p6818}
true ${DISABLE_MKIMG:=0}
true ${LOGO:=}
true ${TARGET_OS:=$(echo ${1,,}|sed 's/\///g')}
KERNEL_REPO=https://github.com/friendlyarm/linux
KERNEL_BRANCH=nanopi2-v4.4.y
ARCH=arm64
true ${KCFG:=nanopi3_linux_defconfig}
KIMG=arch/${ARCH}/boot/Image
KDTB=arch/${ARCH}/boot/dts/nexell/s5p6818-nanopi3-*.dtb
KALL=
case "$(uname -mpi)" in
x86_64*)
CROSS_COMPILE=aarch64-linux-gnu-
;;
aarch64*)
CROSS_COMPILE=
;;
*)
echo "Error: Cannot build arm64 arch on $(uname -mpi) host."
;;
esac
#
# kernel logo:
#
# convert logo.jpg -type truecolor /tmp/logo.bmp
# convert logo.jpg -type truecolor /tmp/logo_kernel.bmp
# LOGO=/tmp/logo.bmp
# KERNEL_LOGO=/tmp/logo_kernel.bmp
#
TOPPATH=$PWD
OUT=$TOPPATH/out
if [ ! -d $OUT ]; then
echo "path not found: $OUT"
exit 1
fi
KMODULES_OUTDIR="${OUT}/output_${SOC}_kmodules"
true ${kernel_src:=${OUT}/kernel-${SOC}}
true ${KERNEL_SRC:=${kernel_src}}
function usage() {
echo "Usage: $0 <friendlycore-arm64|friendlycore|friendlycore-arm64|friendlycore-lite-focal|friendlycore-lite-focal-arm64|lubuntu|friendlywrt|eflasher>"
echo "# example:"
echo "# clone kernel source from github:"
echo " git clone ${KERNEL_REPO} --depth 1 -b ${KERNEL_BRANCH} ${KERNEL_SRC}"
echo "# or clone your local repo:"
echo " git clone [email protected]:/path/to/linux.git --depth 1 -b ${KERNEL_BRANCH} ${KERNEL_SRC}"
echo "# then"
echo " LOGO=/tmp/logo.bmp ./build-kernel.sh friendlycore-arm64"
echo " LOGO=/tmp/logo.bmp ./build-kernel.sh eflasher"
echo " ./mk-emmc-image.sh friendlycore-arm64"
echo "# also can do:"
echo " KERNEL_SRC=~/mykernel ./build-kernel.sh friendlycore-arm64"
exit 0
}
if [ $# -ne 1 ]; then
usage
fi
. ${TOPPATH}/tools/util.sh
check_and_install_toolchain
if [ $? -ne 0 ]; then
exit 1
fi
check_and_install_package
PARTMAP=./${TARGET_OS}/partmap.txt
case ${TARGET_OS} in
friendlycore* | lubuntu* | friendlywrt | eflasher)
;;
*)
echo "Error: Unsupported target OS: ${TARGET_OS}"
exit 1
esac
download_img() {
if [ ! -f ${PARTMAP} ]; then
ROMFILE=`./tools/get_pkg_filename.sh ${1}`
cat << EOF
Warn: Image not found for ${1}
----------------
you may download it from the netdisk (dl.friendlyarm.com) to get a higher downloading speed,
the image files are stored in a directory called "03_Partition image files", for example:
tar xvzf /path/to/NetDrive/03_Partition\ image\ files/${ROMFILE}
----------------
Do you want to download it now via http? (Y/N):
EOF
while read -r -n 1 -t 3600 -s USER_REPLY; do
if [[ ${USER_REPLY} = [Nn] ]]; then
echo ${USER_REPLY}
exit 1
elif [[ ${USER_REPLY} = [Yy] ]]; then
echo ${USER_REPLY}
break;
fi
done
if [ -z ${USER_REPLY} ]; then
echo "Cancelled."
exit 1
fi
./tools/get_rom.sh ${1} || exit 1
fi
}
if [ ! -d ${KERNEL_SRC} ]; then
git clone ${KERNEL_REPO} --depth 1 -b ${KERNEL_BRANCH} ${KERNEL_SRC}
fi
if [ -f "${LOGO}" ]; then
cp -f ${LOGO} ${KERNEL_SRC}/logo.bmp
echo "using ${LOGO} as logo."
else
echo "using official logo."
fi
cd ${KERNEL_SRC}
make distclean
touch .scmversion
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} ${KCFG}
if [ $? -ne 0 ]; then
echo "failed to build kernel."
exit 1
fi
if [ x"${TARGET_OS}" = x"eflasher" ]; then
cp -avf .config .config.old
sed -i "s/.*\(PROT_MT_SYNC\).*/CONFIG_TOUCHSCREEN_\1=y/g" .config
sed -i "s/\(.*PROT_MT_SLOT\).*/# \1 is not set/g" .config
fi
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} ${KALL} -j$(nproc)
if [ $? -ne 0 ]; then
echo "failed to build kernel."
exit 1
fi
rm -rf ${KMODULES_OUTDIR}
mkdir -p ${KMODULES_OUTDIR}
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} INSTALL_MOD_PATH=${KMODULES_OUTDIR} modules -j$(nproc)
if [ $? -ne 0 ]; then
echo "failed to build kernel modules."
exit 1
fi
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} INSTALL_MOD_PATH=${KMODULES_OUTDIR} modules_install
if [ $? -ne 0 ]; then
echo "failed to build kernel modules."
exit 1
fi
(cd ${KMODULES_OUTDIR} && find . -name \*.ko | xargs ${CROSS_COMPILE}strip --strip-unneeded)
if [ ! -d ${KMODULES_OUTDIR}/lib ]; then
echo "not found kernel modules."
exit 1
fi
if [ x"$DISABLE_MKIMG" = x"1" ]; then
exit 0
fi
echo "building kernel ok."
cd ${TOPPATH}
download_img ${TARGET_OS}
LOGO=${LOGO} KCFG=${KCFG} ./tools/update_kernel_bin_to_img.sh ${OUT} ${KERNEL_SRC} ${TARGET_OS} ${TOPPATH}/prebuilt
if [ $? -eq 0 ]; then
echo "updating kernel ok."
else
echo "failed."
exit 1
fi