凌云实验室IGKBoard开发板BSP开发相关文件
guowenxue
2023-11-07 f270b35145097e9ca4ef0bb1adce741e601d2e76
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
#!/bin/bash
 
# this project absolute path
PRJ_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
 
# top project absolute path
TOP_PATH=$(realpath $PRJ_PATH/..)
 
# binaries install path
INST_PATH=$PRJ_PATH/install
 
# download taballs path
TARBALL_PATH=$PRJ_PATH/tarballs
 
# config file path
CONF_FILE=$TOP_PATH/config.json
 
# shell script will exit once get command error
set -e
 
#+-------------------------+
#| Shell script functions  |
#+-------------------------+
 
function pr_error() {
    echo -e "\033[40;31m $1 \033[0m"
}
 
function pr_warn() {
    echo -e "\033[40;33m $1 \033[0m"
}
 
function pr_info() {
    echo -e "\033[40;32m $1 \033[0m"
}
 
# parser configure file and export environment variable
function export_env()
{
    export BOARD=`jq -r ".bsp.board" $CONF_FILE | tr 'A-Z' 'a-z'`
    export BSP_VER=`jq -r ".bsp.version" $CONF_FILE | tr 'A-Z' 'a-z'`
    export URL=`jq -r ".bsp.download" $CONF_FILE | tr 'A-Z' 'a-z'`
    export CROSS_COMPILE=`jq -r ".bsp.crosstool" $CONF_FILE | tr 'A-Z' 'a-z'`
    export JOBS=`cat /proc/cpuinfo | grep processor | wc -l`
    export KER_PATH=$PRJ_PATH/linux-imx
 
    if [[ $BOARD =~ 6ull ]] ; then
 
        export ARCH=arm
        export SRCS="linux-imx"
 
    elif [[ $BOARD =~ 8mp ]] ; then
 
        export ARCH=arm64
        export SRCS="linux-imx"
 
    else
 
        pr_error "\nERROR: Unknow board name $BOARD"
        exit;
 
    fi
}
 
# decompress a packet to destination path
function do_unpack()
{
    tarball=$1
    dstpath=`pwd`
 
    if [[ $# == 2 ]] ; then
        dstpath=$2
    fi
 
    pr_info "decompress $tarball => $dstpath"
 
    mkdir -p $dstpath
    case $tarball in
        *.tar.gz)
            tar -xzf $tarball -C $dstpath
            ;;
 
        *.tar.bz2)
            tar -xjf $tarball -C $dstpath
            ;;
 
        *.tar.xz)
            tar -xJf $tarball -C $dstpath
            ;;
 
        *.tar.zst)
            tar -I zstd -xf $tarball -C $dstpath
            ;;
 
        *.tar)
            tar -xf $tarball -C $dstpath
            ;;
 
        *.zip)
            unzip -qo $tarball -d $dstpath
            ;;
 
        *)
            pr_error "decompress Unsupport packet: $tarball"
            return 1;
            ;;
    esac
}
 
function do_fetch()
{
    mkdir -p $TARBALL_PATH
    cd $PRJ_PATH
 
    for src in $SRCS
    do
        if [ -d $src ] ; then
            pr_info "$src fetched already"
            continue
        fi
 
        # Download source code packet
        if [ ! -s $TARBALL_PATH/$src.tar.xz ] ; then
            pr_info "start fetch $src source code"
            wget $URL/bsp/$BSP_VER/$src.tar.xz -P $TARBALL_PATH
        fi
 
        # decompress source code packet
        do_unpack $TARBALL_PATH/$src.tar.xz
 
        # do patch if patch file exist
        patch_path=$PRJ_PATH/patches/$BOARD
        patch_file=$patch_path/${src}-${BSP_VER}.patch
        if [ -f $patch_file ] ; then
            pr_info "found and patch for $src"
            patch -p0 < $patch_file
        fi
 
    done
 
    rm -f *.tar.*
}
 
 
function build_kernel()
{
    SRC=linux-imx
 
    pr_info "Start build linux kernel source code"
    cd $PRJ_PATH/${SRC}
 
    if [ ! -s .config ] ; then
        make ARCH=${ARCH} ${BOARD}_defconfig
    fi
 
    make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} -j ${JOBS}
}
 
function build_driver_wifi()
{
    cd $PRJ_PATH/drivers
 
    if [[ $BOARD =~ 6ull ]] ; then
        SRC=rtl8188fu
 
        pr_info "Start build $SRC driver for $BOARD"
 
        if [ ! -d $SRC ] ; then
            if [ ! -s $TARBALL_PATH/$SRC.tar.xz ] ; then
                pr_info "start fetch $SRC source code"
                wget $URL/bsp/misc/$SRC.tar.xz -P $TARBALL_PATH
            fi
 
            do_unpack $TARBALL_PATH/$SRC.tar.xz
        fi
 
        cd $SRC
 
        # Remove noisy debug print information
        sed -i "s|^#define CONFIG_DEBUG|//#define CONFIG_DEBUG|g" include/autoconf.h
        sed -i "/nolinked power/d" core/rtw_pwrctrl.c
        sed -i "/request firmware/d" hal/rtl8188f/rtl8188f_hal_init.c
 
        make KSRC=$KER_PATH M=$PWD -j ${JOBS}
        make -C $KER_PATH M=$PWD modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
 
        mkdir -p $INST_PATH/lib/firmware/rtlwifi/
        cp firmware/rtl8188fufw.bin $INST_PATH/lib/firmware/rtlwifi/
    fi
}
 
function build_driver_user()
{
    cd $PRJ_PATH/drivers/user
 
    pr_info "Start build user driver for $BOARD"
    make -C $KER_PATH M=$PWD
    make -C $KER_PATH M=$PWD modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
}
 
function install_drv_kernel()
{
    # Install linux kernel modules
 
    cd $KER_PATH
    make ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE} modules_install INSTALL_MOD_PATH=$INST_PATH INSTALL_MOD_STRIP=1
}
 
function build_driver()
{
    install_drv_kernel
 
    build_driver_user
 
    build_driver_wifi
}
 
function do_install()
{
    pr_info "Start install linux kernel images"
 
    # Cleanup install path
    if [ -d $INST_PATH ] ; then
        rm -rf $INST_PATH/*
    fi
    mkdir -p $INST_PATH/overlays
    cd $KER_PATH
 
    # Install system image and device tree binaries
    if [[ $BOARD =~ 6ull ]] ; then
        set -x
        cp arch/${ARCH}/boot/zImage $INST_PATH
        cp arch/${ARCH}/boot/dts/${BOARD}.dtb $INST_PATH
        cp arch/${ARCH}/boot/dts/${BOARD}/*.dtbo $INST_PATH/overlays
        set +x
    elif [[ $BOARD =~ 8mp ]] ; then
        set -x
        cp arch/${ARCH}/boot/Image $INST_PATH
        cp arch/${ARCH}/boot/dts/freescale/${BOARD}.dtb $INST_PATH
        cp arch/${ARCH}/boot/dts/freescale/${BOARD}/*.dtbo $INST_PATH/overlays
        set +x
    fi
 
    # List install information
    pr_info "\nlinux kernel installed to '$INST_PATH'"
    ls $INST_PATH && echo ""
}
 
function do_build()
{
    cd $PRJ_PATH
 
    build_kernel
 
    do_install
 
    build_driver
}
 
function do_clean()
{
    cd $PRJ_PATH
 
    for d in $SRCS
    do
        rm -rf $PRJ_PATH/$d
    done
 
    rm -rf drivers/rtl8188fu/
    rm -rf $TARBALL_PATH
    rm -rf $INST_PATH
}
 
#+-------------------------+
#| Shell script body entry |
#+-------------------------+
 
cd $PRJ_PATH
 
export_env
 
if [[ $# == 1 && $1 == -c ]] ;then
    pr_warn "start clean linux kernel"
    do_clean
    exit;
fi
 
pr_warn "start build linux kernel for ${BOARD}"
 
do_fetch
 
do_build