-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-randconfig-kernel
executable file
·207 lines (180 loc) · 5.16 KB
/
build-randconfig-kernel
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
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
set -e
if [[ -f ${HOME}/.ragnar.rc ]]; then
source ${HOME}/.ragnar.rc
else
TOP=${TOP:-"${HOME}/ragnar-artifacts"}
fi
mkdir -p ${TOP}
NUM_CPUS=${NUM_CPUS:-"$(getconf _NPROCESSORS_ONLN)"}
KDIR=${KDIR:-$(pwd)}
clean_build=0
build_deb_packages=0
build_kselftests=0
loop=1
#ARCH=arm64
git_describe=$(git describe --long)
usage() {
echo -e "$0's help text"
echo -e " -a ARCH, specify the architecture to build, default: arm64"
echo -e " -c, cleanup output and staging dir before building, default: 0"
echo -e " -k, build kselftests"
echo -e " -l, loop"
echo -e " -p, build deb packages"
echo -e " -h, prints out this help"
}
MAKE() {
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} KDIR=${KDIR} O=${OUTPUT} "$@" ;
}
while getopts "a:chkl:p" arg; do
case $arg in
a)
ARCH="$OPTARG"
;;
c)
clean_build=1
;;
k)
build_kselftests=1
;;
l)
loop=$OPTARG
clean_build=1
;;
p)
build_deb_packages=1
;;
h|*)
usage
exit 0
;;
esac
done
OUTPUT=${OUTPUT:-"${TOP}/build_output/${ARCH}/${git_describe}"}
STAGING=${STAGING:-"${TOP}/staging/${git_describe}/${ARCH}"}
if [ $(grep -c "^WHAT IS LINUX" README) -ne 1 ] &&
[ $(grep -c "^Linux kernel" README) -ne 1 ]; then
echo -e "ERROR: Need to run this script $(basename $0),"
echo -e " from a kernel repository"
echo ""
usage
exit 1
fi
clean_build() {
if [[ $clean_build -eq 1 ]]; then
echo "Cleaning up output and staging dir before building!"
rm -rf ${OUTPUT}
rm -rf ${STAGING}
fi
}
create_dir() {
mkdir -p ${OUTPUT}
mkdir -p ${STAGING}
}
create_allrand_config_file() {
cat > ${STAGING}/allrand.config << EOF
CONFIG_COMPILE_TEST=y
# PROFILE_ALL_BRANCHES is not set
CONFIG_PREVENT_FIRMWARE_BUILD=y
CONFIG_STANDALONE=y
EOF
}
which_arch() {
case $ARCH in
arm)
CROSS_COMPILE=${CROSS_COMPILE:-arm-linux-gnueabihf-}
echo "CONFIG_MMU=y">>${STAGING}/allrand.config
echo "CONFIG_AEABI=y">>${STAGING}/allrand.config
image_name=zImage
;;
arm64)
CROSS_COMPILE=${CROSS_COMPILE:-aarch64-linux-gnu-}
image_name=Image
;;
x86)
CROSS_COMPILE=${CROSS_COMPILE:-""}
image_name=bzImage
;;
*)
esac
}
make_randconfig() {
MAKE -j ${NUM_CPUS} KCONFIG_ALLCONFIG=${STAGING}/allrand.config randconfig 2>&1 | tee ${STAGING}/make_config.log
cp -f ${OUTPUT}/.config ${STAGING}/kernel-${git_describe}.config
}
make_build() {
MAKE -j ${NUM_CPUS} 2>&1 | tee ${STAGING}/make_build.log
if [[ $(grep CONFIG_MODULES=y ${OUTPUT}/.config) ]]; then
MAKE -j ${NUM_CPUS} modules 2>&1 | tee -a ${STAGING}/make_build.log
fi
}
make_dtb() {
if [[ -d arch/${ARCH}/boot/dts ]]; then
MAKE -j ${NUM_CPUS} INSTALL_DTBS_PATH=${STAGING}/dtbs dtbs_install 2>&1 | tee ${STAGING}/make_dts.log
for file in $(find ${STAGING}/dtbs -type f -name '*.dtb') ; do
if [[ ! $(basename ${file}) =~ ${git_describe}.dtb ]]; then
new_file=$(printf '%s\n' "${file%.dtb}-${git_describe}.dtb");
mv ${file} ${new_file}
fi
done
fi
}
make_modules_install() {
if [[ $(grep CONFIG_MODULES=y ${OUTPUT}/.config) ]]; then
MAKE -j ${NUM_CPUS} INSTALL_MOD_PATH=${STAGING} modules_install 2>&1 | tee ${STAGING}/make_modules.log
pushd ${STAGING}
tar -zcf modules-$(basename ${STAGING}).tar.gz lib/
popd
fi
}
make_image() {
MAKE -j ${NUM_CPUS} ${image_name} 2>&1 | tee ${STAGING}/make_image.log
}
make_deb_packages() {
if [[ $build_deb_packages -eq 1 ]]; then
MAKE -j ${NUM_CPUS} bindeb-pkg 2>&1 | tee ${STAGING}/make_deb-pkg.log
mv -f ${OUTPUT}/../*$(basename ${OUTPUT} |awk -F'-' '{print $1-$2}')*.* ${STAGING}
fi
}
ls
pwd
make_kselftests() {
if [[ $build_kselftests -eq 1 ]]; then
MAKE -C tools/testing/selftests 2>&1 | tee ${STAGING}/make_kselftest.log
MAKE -C tools/testing/selftests install 2>&1 | tee ${STAGING}/make_kselftest_install.log
fi
}
warning_error_file=$(dirname ${STAGING})/${ARCH}_warning_error.log
for count in $(seq 1 $loop); do
clean_build
create_dir
create_allrand_config_file
which_arch
if [[ -z ${ARCH} ]]; then
echo "Need to setup ARCH=..."
echo ""
usage
exit 1
fi
make_randconfig
make_build
make_dtb
make_modules_install
make_image
make_deb_packages
make_kselftests
echo "===================">>${warning_error_file}
echo "${STAGING}-${count}">>${warning_error_file}
echo "">>${warning_error_file}
grep -i -A 4 -B 1 "\(warning\|error\):" ${STAGING}/make_build.log 2>&1 | tee -a ${warning_error_file}
echo "">>${warning_error_file}
mv ${STAGING} ${STAGING}-${count}
done
echo ""
echo ""
echo "If build warnings or errors, they will be printed below:"
echo ""
echo ""
cat ${warning_error_file}
echo ""
## vim: set sw=4 sts=4 et foldmethod=syntax : ##