-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbuild.sh
executable file
·317 lines (257 loc) · 8.08 KB
/
build.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
#!/bin/bash
#
# This file is part of the Rainbow Pi project.
# Copyright (c) 2018 YuanJun <[email protected]>
# This work is licensed under the MIT license, see the file LICENSE for details.
#
#
# https://mvdevice.taobao.com is our E-Shop
#
USERNAME=`echo $USER`
GROUPNAME=`id -gn ${USERNAME}`
mkdir -p output/
mkdir -p output/image/
mkdir -p output/rootfs/
if [ "x${RAINBOWPI_SDK_DIR}" = "x" ]; then
echo "# "
echo "# You should set RAINBOWPI_SDK_DIR environment variable correctly!"
echo "# "
echo "# See : https://github.com/rainbow-pi/rainbow-pi-sdk for details!"
echo "# "
exit 1
fi
if [ ! -d ${RAINBOWPI_SDK_DIR}/buildroot -o ! -d ${RAINBOWPI_SDK_DIR}/tools/pack ]; then
echo "# "
echo "# You should set RAINBOWPI_SDK_DIR environment variable correctly!"
echo "# "
echo "# See : https://github.com/rainbow-pi/rainbow-pi-sdk for details!"
echo "# "
exit 1
fi
export BOARD=tiger-spinand-standard
# buildroot
export BUILDROOT_DIR=${RAINBOWPI_SDK_DIR}/buildroot/
# export BUILDROOT_OUTPUT_DIR=${BUILDROOT_DIR}output-rainbow-pi-baseline/
export BUILDROOT_OUTPUT_DIR=${BUILDROOT_DIR}output-rainbow-pi-qt/
export BUILDROOT_ROOTFS_FILE=${BUILDROOT_OUTPUT_DIR}images/rootfs.tar.bz2
export APP_COMPILER_DIR=${BUILDROOT_OUTPUT_DIR}host/bin/
# config file
export SDK_CONFIG_DIR=${RAINBOWPI_SDK_DIR}/configs/
# application
export APP_DIR=${RAINBOWPI_SDK_DIR}/app/
# u-boot
export UBOOT_DIR=${RAINBOWPI_SDK_DIR}/u-boot-2011.09/
# linux
export KERNEL_DIR=${RAINBOWPI_SDK_DIR}/linux-3.4/
export KERNEL_TOOLCHAINS_DIR=${RAINBOWPI_SDK_DIR}/tools/external-toolchain/bin/
export KERNEL_CROSS_COMPILE=${KERNEL_TOOLCHAINS_DIR}arm-linux-gnueabi-
export UBOOT_CROSS_COMPILE=${KERNEL_CROSS_COMPILE}
export PREBUILT_DIR=${RAINBOWPI_SDK_DIR}/prebuilt/
export OUTPUT_DIR=${RAINBOWPI_SDK_DIR}/output/
export HOSTTOOLS_DIR=${RAINBOWPI_SDK_DIR}/tools/bin/
export PACKTOOLS_DIR=${RAINBOWPI_SDK_DIR}/tools/pack/
export ROOTFS_DIR=${OUTPUT_DIR}rootfs/
export ROOTFS_OVERRIDE_DIR=${PREBUILT_DIR}rootfs-override/
copy_file_list=(
${ROOTFS_OVERRIDE_DIR}etc/wpa_supplicant.conf:${ROOTFS_DIR}etc/wpa_supplicant.conf
${ROOTFS_OVERRIDE_DIR}etc/hostapd.conf:${ROOTFS_DIR}etc/hostapd.conf
${ROOTFS_OVERRIDE_DIR}etc/udhcpd.conf:${ROOTFS_DIR}etc/udhcpd.conf
${ROOTFS_OVERRIDE_DIR}etc/mdev.conf:${ROOTFS_DIR}etc/mdev.conf
${ROOTFS_OVERRIDE_DIR}etc/init.d/S50sshd:${ROOTFS_DIR}etc/init.d/
${ROOTFS_OVERRIDE_DIR}etc/init.d/S90camera:${ROOTFS_DIR}etc/init.d/
${ROOTFS_OVERRIDE_DIR}etc/init.d/S90wifiap:${ROOTFS_DIR}etc/init.d/_S90wifiap
${ROOTFS_OVERRIDE_DIR}etc/init.d/S90wifista:${ROOTFS_DIR}etc/init.d/_S90wifista
${ROOTFS_OVERRIDE_DIR}etc/init.d/S99appstart:${ROOTFS_DIR}etc/init.d/
${ROOTFS_OVERRIDE_DIR}etc/ssh/sshd_config:${ROOTFS_DIR}etc/ssh/
${ROOTFS_OVERRIDE_DIR}root/*.sh:${ROOTFS_DIR}root/
${ROOTFS_OVERRIDE_DIR}root/demo-h264enc:${ROOTFS_DIR}usr/bin/
${APP_DIR}demo-camera/demo-camera:${ROOTFS_DIR}usr/bin/
${APP_DIR}demo-qt/digitalclock:${ROOTFS_DIR}root/
${PREBUILT_DIR}libs/*:${ROOTFS_DIR}lib/
)
function copy_file_to_rootfs()
{
for line in ${copy_file_list[@]} ; do
srcfile=`echo $line | awk -F: '{print $1}'`
dstfile=`echo $line | awk -F: '{print $2}'`
cp -drf $srcfile $dstfile 2>/dev/null
done
}
function build_buildroot()
{
(cd ${BUILDROOT_DIR} && ./build-qt.sh)
[ $? -ne 0 ] && echo "build buildroot Failed" && return 1
cd ${RAINBOWPI_SDK_DIR}
return 0
}
function build_uboot_spinandflash_or_emmc()
{
if [ ! -d ${UBOOT_DIR} ]; then
git clone https://github.com/rainbow-pi/u-boot-2011.09.git
[ $? -ne 0 ] && echo "download u-boot failed" && return 1
fi
(cd ${UBOOT_DIR} && ./build.sh -p sun8iw8p1_spinand_emmc)
[ $? -ne 0 ] && echo "build u-boot Failed" && return 1
return 0
}
function build_uboot_norflash()
{
if [ ! -d ${UBOOT_DIR} ]; then
git clone https://github.com/rainbow-pi/u-boot-2011.09.git
[ $? -ne 0 ] && echo "download u-boot failed" && return 1
fi
(cd ${UBOOT_DIR} && ./build.sh -p sun8iw8p1_nor)
[ $? -ne 0 ] && echo "build u-boot Failed" && return 1
(cd ${UBOOT_DIR} && ./build.sh -p sun8iw8p1)
[ $? -ne 0 ] && echo "build u-boot Failed" && return 1
return 0
}
function build_uboot()
{
# build_uboot_norflash
echo "build_uboot ..."
if [ ! -f ${OUTPUT_DIR}.stamp_uboot_built ]; then
build_uboot_spinandflash_or_emmc
[ $? -ne 0 ] && return 1
touch ${OUTPUT_DIR}.stamp_uboot_built
fi
echo "build_uboot done!"
return 0
}
function build_kernel()
{
echo "build_kernel ..."
if [ ! -d ${KERNEL_DIR} ]; then
git clone https://github.com/rainbow-pi/linux-3.4.git
[ $? -ne 0 ] && echo "download kernel failed" && return 1
fi
(cd ${KERNEL_DIR}; ./build.sh kernel)
[ $? -ne 0 ] && echo "build kernel failed" && return 1
(cd ${KERNEL_DIR}; ./build.sh modules)
[ $? -ne 0 ] && echo "build kernel modules failed" && return 1
echo "build_kernel done!"
return 0
}
function build_kernel_modules()
{
(cd ${KERNEL_DIR}; ./build.sh modules)
[ $? -ne 0 ] && echo "build kernel modules failed" && return 1
return 0
}
function deploy_nfs()
{
# NFS for debug
export NFS_DIR=/home/dev/fs/nfs/rainbow-pi/
# copy
sudo rm -fr ${NFS_DIR}*
mkdir -p ${NFS_DIR} && \
sudo cp -dr ${ROOTFS_DIR}* ${NFS_DIR} && \
sudo chown -R ${USERNAME}:${GROUPNAME} ${NFS_DIR} &&
return 0
return 1
}
function print_error()
{
echo
echo -e "\033[47;31mERROR: $*\033[0m"
echo
}
function deploy_rootfs()
{
if [ ! -f ${BUILDROOT_ROOTFS_FILE} ]; then
print_error "*** ${BUILDROOT_ROOTFS_FILE} missing!"
print_error "You should build buildroot first."
print_error "run ./build.sh buildroot"
return 1
fi
sudo rm -fr ${ROOTFS_DIR} && \
mkdir ${ROOTFS_DIR} && \
sudo tar xjvf ${BUILDROOT_ROOTFS_FILE} -C ${ROOTFS_DIR} && \
sudo chown -R ${USERNAME}:${GROUPNAME} ${ROOTFS_DIR} && \
copy_file_to_rootfs && \
return 0
return 1
}
function build_rootfs_image()
{
echo "build_rootfs_image (ext4 image)..."
${HOSTTOOLS_DIR}make_ext4fs -s \
-l 90M \
${OUTPUT_DIR}image/rootfs-ext4.img \
${ROOTFS_DIR}
[ $? -ne 0 ] && echo "build rootfs image (ext4 image) failed" && return 1
echo "build_rootfs_image (ext4 image)... done!"
return 0
}
function pack()
{
echo "pack ..."
cd ${PACKTOOLS_DIR} && ./pack -c sun8iw8p1 -p camdroid -b ${BOARD} -e spinand
[ $? -ne 0 ] && echo "build rootfs image (ext4 image) failed" && return 1
echo "pack ... done!"
return 0
}
function clean()
{
echo
echo "Clean ......"
echo
# rm -f ${PACKTOOLS_DIR}chips/sun8iw8p1/bin/*
rm -f ${OUTPUT_DIR}image/*.img
rm -fr ${OUTPUT_DIR}rootfs/*
rm -f ${PACKTOOLS_DIR}rainbow-pi.img
rm -fr ${PACKTOOLS_DIR}out/*
# force rebuild uboot
rm -f ${OUTPUT_DIR}.stamp_*
# force rebuild kernel
make -C ${KERNEL_DIR} distclean
return 0
}
if [ $# == 0 ]; then
echo "Usage : ./build.sh all"
exit 0
elif [ $# -gt 0 ]; then
if [ $1 == 'buildroot' ]; then
build_buildroot
fi
if [ $1 == 'uboot' ]; then
build_uboot
fi
if [ $1 == 'uboot-rebuild' ]; then
rm -f ${OUTPUT_DIR}.stamp_uboot_built
build_uboot
fi
if [ $1 == 'kernel' ]; then
build_kernel
fi
if [ $1 == 'kernel-config' ]; then
if [ ! -f ${KERNEL_DIR}.config ]; then
echo "Copy linux config file."
cp ${KERNEL_DIR}arch/arm/configs/rainbowpi_defconfig
fi
(cd ${KERNEL_DIR} && make ARCH=arm menuconfig)
[ $? -ne 0 ] && echo "kernel menuconfig Failed" && cd ${RAINBOWPI_SDK_DIR}
cd ${RAINBOWPI_SDK_DIR}
fi
if [ $1 == 'rootfs' ]; then
deploy_rootfs && build_kernel
fi
if [ $1 == 'nfs' ]; then
deploy_nfs
fi
if [ $1 == 'image' ]; then
build_rootfs_image
fi
if [ $1 == 'pack' ]; then
pack
fi
if [ $1 == 'clean' ]; then
clean
fi
if [ $1 == 'all' ]; then
deploy_rootfs && build_uboot && build_kernel && build_rootfs_image && pack
fi
if [ $1 == 'rebuildall' ]; then
clean && deploy_rootfs && build_uboot && build_kernel && build_rootfs_image && pack
fi
fi