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 |
|
|
45 |
export BRANCH=$BSP_VER |
|
46 |
export KER_PATH=$PRJ_PATH/linux-imx |
|
47 |
|
|
48 |
export JOBS=`cat /proc/cpuinfo | grep processor | wc -l` |
|
49 |
export ARCH=arm64 |
|
50 |
export SRCS="linux-imx" |
|
51 |
} |
|
52 |
|
|
53 |
function build_kernel() |
|
54 |
{ |
|
55 |
PATCH_FILE=$PRJ_PATH/patches/$BOARD/linux-imx-$BSP_VER.patch |
|
56 |
|
|
57 |
cd $PRJ_PATH |
|
58 |
|
|
59 |
if [ -d $KER_PATH ] ; then |
|
60 |
pr_info "linux kernel source code fetched already" |
|
61 |
else |
|
62 |
pr_info "start fetch linux kernel source code" |
|
63 |
git clone $GIT_URL/linux-imx.git -b $BRANCH --depth=1 |
|
64 |
|
|
65 |
if [ -s $PATCH_FILE ] ; then |
|
66 |
pr_warn "do patch for $KER_PATH now..." |
|
67 |
cd $KER_PATH |
|
68 |
patch -p1 < $PATCH_FILE |
|
69 |
fi |
|
70 |
fi |
|
71 |
|
|
72 |
pr_info "Start build linux kernel source code" |
|
73 |
|
|
74 |
cd $KER_PATH |
|
75 |
|
|
76 |
defconfig=${BOARD}_defconfig |
|
77 |
if [ ! -s .config ] ; then |
|
78 |
make ${defconfig} |
|
79 |
fi |
|
80 |
|
|
81 |
make -j ${JOBS} |
|
82 |
} |
|
83 |
|
|
84 |
function do_install() |
|
85 |
{ |
|
86 |
pr_info "start install linux kernel images" |
|
87 |
|
|
88 |
cd $KER_PATH |
|
89 |
|
|
90 |
if [ -d $PRFX_PATH ] ; then |
|
91 |
rm -rf $PRFX_PATH/* |
|
92 |
else |
|
93 |
mkdir -p $PRFX_PATH |
|
94 |
fi |
|
95 |
|
|
96 |
# Install image |
|
97 |
cp arch/arm64/boot/Image $PRFX_PATH |
|
98 |
cp arch/arm64/boot/dts/freescale/${BOARD}.dtb $PRFX_PATH |
|
99 |
|
|
100 |
# Install kernel modules |
|
101 |
make modules_install INSTALL_MOD_PATH=$PRFX_PATH INSTALL_MOD_STRIP=1 |
|
102 |
|
|
103 |
echo "" |
|
104 |
pr_info "linux kernel installed to '$PRFX_PATH'" |
|
105 |
ls $PRFX_PATH && echo "" |
|
106 |
|
|
107 |
if [[ -n "$INST_PATH" && -w $INST_PATH ]] ; then |
|
108 |
pr_info "install linux kernel to '$INST_PATH'" |
|
109 |
cp $PRFX_PATH/Image $INST_PATH |
|
110 |
cp $PRFX_PATH/${BOARD}.dtb $INST_PATH |
|
111 |
fi |
|
112 |
} |
|
113 |
|
|
114 |
function do_build() |
|
115 |
{ |
|
116 |
cd $PRJ_PATH |
|
117 |
|
|
118 |
build_kernel |
|
119 |
|
|
120 |
do_install |
|
121 |
} |
|
122 |
|
|
123 |
function do_clean() |
|
124 |
{ |
|
125 |
cd $PRJ_PATH |
|
126 |
|
|
127 |
for d in $SRCS |
|
128 |
do |
|
129 |
rm -rf $PRJ_PATH/$d |
|
130 |
done |
|
131 |
|
|
132 |
rm -rf $PRFX_PATH |
|
133 |
} |
|
134 |
|
|
135 |
#+-------------------------+ |
|
136 |
#| Shell script body entry | |
|
137 |
#+-------------------------+ |
|
138 |
|
|
139 |
export_env |
|
140 |
|
|
141 |
if [[ $# == 1 && $1 == -c ]] ;then |
|
142 |
pr_warn "start clean linux kernel" |
|
143 |
do_clean |
|
144 |
exit; |
|
145 |
fi |
|
146 |
|
|
147 |
pr_warn "start build linux kernel for ${BOARD}" |
|
148 |
|
|
149 |
do_build |
|
150 |
|