commit | author | age
|
849fbd
|
1 |
#!/bin/bash |
G |
2 |
|
|
3 |
# this project absolute path |
|
4 |
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) |
|
5 |
|
|
6 |
# top project absolute path |
|
7 |
TOP_PATH=$(realpath $PRJ_PATH/..) |
|
8 |
|
|
9 |
# binaries build prefix install path |
|
10 |
PRFX_PATH=$PRJ_PATH/install |
|
11 |
|
|
12 |
# binaries finally install path if needed |
|
13 |
#INST_PATH=/tftp |
|
14 |
|
|
15 |
# config file path |
|
16 |
CONF_FILE=$TOP_PATH/config.json |
|
17 |
|
|
18 |
# shell script will exit once get command error |
|
19 |
set -e |
|
20 |
|
|
21 |
#+-------------------------+ |
|
22 |
#| Shell script functions | |
|
23 |
#+-------------------------+ |
|
24 |
|
|
25 |
function pr_error() { |
|
26 |
echo -e "\033[40;31m $1 \033[0m" |
|
27 |
} |
|
28 |
|
|
29 |
function pr_warn() { |
|
30 |
echo -e "\033[40;33m $1 \033[0m" |
|
31 |
} |
|
32 |
|
|
33 |
function pr_info() { |
|
34 |
echo -e "\033[40;32m $1 \033[0m" |
|
35 |
} |
|
36 |
|
|
37 |
# parser configure file and export environment variable |
|
38 |
function export_env() |
|
39 |
{ |
|
40 |
export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
41 |
export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
42 |
export GIT_URL=`jq -r ".bsp.giturl" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
43 |
export CROSS_COMPILE=`jq -r ".bsp.cortexAtool" $CONF_FILE | tr 'A-Z' 'a-z'` |
|
44 |
|
d80f34
|
45 |
export SRCS="linux-imx" |
849fbd
|
46 |
export BRANCH=$BSP_VER |
G |
47 |
export KER_PATH=$PRJ_PATH/linux-imx |
|
48 |
|
|
49 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
d80f34
|
50 |
|
G |
51 |
if [[ $BOARD =~ mx6ull ]] ; then |
|
52 |
export ARCH=arm |
|
53 |
else |
|
54 |
export ARCH=arm64 |
|
55 |
fi |
849fbd
|
56 |
} |
G |
57 |
|
|
58 |
function build_kernel() |
|
59 |
{ |
b05652
|
60 |
defconfig=${BOARD}_defconfig |
G |
61 |
patch_file=$PRJ_PATH/patches/$BOARD/linux-imx-$BSP_VER.patch |
849fbd
|
62 |
|
G |
63 |
cd $PRJ_PATH |
|
64 |
|
|
65 |
if [ -d $KER_PATH ] ; then |
|
66 |
pr_info "linux kernel source code fetched already" |
|
67 |
else |
|
68 |
pr_info "start fetch linux kernel source code" |
|
69 |
git clone $GIT_URL/linux-imx.git -b $BRANCH --depth=1 |
|
70 |
fi |
|
71 |
|
|
72 |
pr_info "Start build linux kernel source code" |
|
73 |
|
|
74 |
cd $KER_PATH |
|
75 |
|
d80f34
|
76 |
if [ ! -s arch/$ARCH/configs/$defconfig -a -s $patch_file ] ; then |
b05652
|
77 |
pr_warn "do patch for $KER_PATH now..." |
G |
78 |
patch -p1 < $patch_file |
|
79 |
fi |
|
80 |
|
849fbd
|
81 |
if [ ! -s .config ] ; then |
G |
82 |
make ${defconfig} |
|
83 |
fi |
|
84 |
|
|
85 |
make -j ${JOBS} |
|
86 |
} |
|
87 |
|
|
88 |
function do_install() |
|
89 |
{ |
|
90 |
pr_info "start install linux kernel images" |
|
91 |
|
|
92 |
cd $KER_PATH |
|
93 |
|
|
94 |
if [ -d $PRFX_PATH ] ; then |
|
95 |
rm -rf $PRFX_PATH/* |
|
96 |
fi |
|
97 |
|
d80f34
|
98 |
mkdir -p $PRFX_PATH/overlays |
G |
99 |
|
|
100 |
# Install system image and device tree binaries |
|
101 |
|
|
102 |
if [[ $BOARD =~ 6ull ]] ; then |
|
103 |
set -x |
|
104 |
cp -f arch/${ARCH}/boot/zImage $PRFX_PATH |
|
105 |
cp -f arch/${ARCH}/boot/dts/${BOARD}.dtb $PRFX_PATH |
|
106 |
cp -f arch/${ARCH}/boot/dts/${BOARD}/*.dtbo $PRFX_PATH/overlays |
|
107 |
set +x |
|
108 |
else |
|
109 |
set -x |
|
110 |
cp -f arch/${ARCH}/boot/Image $PRFX_PATH |
|
111 |
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}.dtb $PRFX_PATH |
|
112 |
cp -f arch/${ARCH}/boot/dts/freescale/${BOARD}/*.dtbo $PRFX_PATH/overlays |
|
113 |
set +x |
|
114 |
fi |
849fbd
|
115 |
|
G |
116 |
# Install kernel modules |
|
117 |
make modules_install INSTALL_MOD_PATH=$PRFX_PATH INSTALL_MOD_STRIP=1 |
|
118 |
|
|
119 |
echo "" |
|
120 |
pr_info "linux kernel installed to '$PRFX_PATH'" |
|
121 |
ls $PRFX_PATH && echo "" |
|
122 |
|
|
123 |
if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then |
|
124 |
pr_info "install linux kernel to '$INST_PATH'" |
d80f34
|
125 |
cp -f $PRFX_PATH/*Image $INST_PATH |
G |
126 |
cp -f $PRFX_PATH/${BOARD}.dtb $INST_PATH |
849fbd
|
127 |
fi |
G |
128 |
} |
|
129 |
|
|
130 |
function do_build() |
|
131 |
{ |
|
132 |
cd $PRJ_PATH |
|
133 |
|
|
134 |
build_kernel |
|
135 |
|
|
136 |
do_install |
|
137 |
} |
|
138 |
|
|
139 |
function do_clean() |
|
140 |
{ |
|
141 |
cd $PRJ_PATH |
|
142 |
|
|
143 |
for d in $SRCS |
|
144 |
do |
|
145 |
rm -rf $PRJ_PATH/$d |
|
146 |
done |
|
147 |
|
|
148 |
rm -rf $PRFX_PATH |
|
149 |
} |
|
150 |
|
|
151 |
#+-------------------------+ |
|
152 |
#| Shell script body entry | |
|
153 |
#+-------------------------+ |
|
154 |
|
|
155 |
export_env |
|
156 |
|
|
157 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
158 |
pr_warn "start clean linux kernel" |
|
159 |
do_clean |
|
160 |
exit; |
|
161 |
fi |
|
162 |
|
|
163 |
pr_warn "start build linux kernel for ${BOARD}" |
|
164 |
|
|
165 |
do_build |
|
166 |
|