tzh
2024-08-22 c7d0944258c7d0943aa7b2211498fd612971ce27
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
#!/bin/bash
 
#
#build.sh for uboot/spl
#wangwei@allwinnertech
#
set -e
 
TOP_DIR=$(cd `dirname $0`;pwd;cd - >/dev/null 2>&1)
BRANDY_SPL_DIR=$TOP_DIR/spl
CONFIG_SYS_CONFIG_NAME=$(cat "u-boot-2018/.config" | grep -w "CONFIG_SYS_CONFIG_NAME" | awk -F= '{printf $$2}' | sed "s/\"//g")
CONFIG_SYS_CONFIG_NAME=${CONFIG_SYS_CONFIG_NAME#*=}
show_help()
{
   printf "\nbuild.sh - Top level build scritps\n"
   echo "Valid Options:"
   echo "  -h  Show help message"
   echo "  -t install gcc tools chain"
   echo "  -o build,e.g. uboot,spl,clean"
   echo "  -p <platform> platform, e.g. sun8iw18p1,  sun5i, sun6i, sun8iw1p1, sun8iw3p1, sun9iw1p1"
   echo "  -m mode,e.g. nand,mmc,nor"
    echo "example:"
    echo "./build.sh -o uboot -p sun8iw18p1"
    echo "./build.sh -o spl -p sun8iw18p1 -m nand"
   printf "\n\n"
}
 
prepare_toolchain()
{
        local ARCH="arm";
        local GCC="";
        local GCC_PREFIX="";
        local toolchain_archive_arm="./tools/toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz";
        local tooldir_arm="./tools/toolchain/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi";
 
        echo "Prepare toolchain ..."
 
        if [ ! -d "${tooldir_arm}" ]; then
                mkdir -p ${tooldir_arm} || exit 1
                tar --strip-components=1 -xf ${toolchain_archive_arm} -C ${tooldir_arm} || exit 1
        fi
}
 
function build_clean(){
    cd $TOP_DIR/spl
    make distclean
    cd - >/dev/null 2>&1
    cd $TOP_DIR/u-boot-2018
    make distclean
    cd - >/dev/null 2>&1
}
 
build_uboot_once()
{
    local defconfig=$1
    if [ "x${defconfig}" = "x" ];then
        echo "please set defconfig"
        exit 1
    fi
    echo build for ${defconfig} ...
   cd u-boot-2018/
   if [ -f .config ];then
       if [ "x${CONFIG_SYS_CONFIG_NAME}" != "x${PLATFORM}" ];then
           make distclean
       fi
   else
       make distclean
   fi
   make ${defconfig}
   make -j16
 
   cd - 1>/dev/null
}
 
function build_uboot(){
    if [ "x${PLATFORM}" = "xall" ];then
        for defconfig in `ls ${TOP_DIR}/u-boot-2018/configs`;do
            if [[ $defconfig =~ .*_defconfig$ ]];then
                build_uboot_once $defconfig
            fi
        done
    else
        build_uboot_once ${PLATFORM}_defconfig
        if [ -e ${TOP_DIR}/u-boot-2018/configs/${PLATFORM}_nor_defconfig ]; then
            build_uboot_once ${PLATFORM}_nor_defconfig
        fi
    fi
}
 
function build_spl_once(){
    platform=$1
    mode=$2
    cd spl
    if [ "x${mode}" = "xall" ];then
        echo --------build for platform:${platform}-------------------
        make distclean
        make p=${platform}
        make -j
    else
        echo --------build for platform:${platform} mode:${mode}-------------------
        make distclean
        make p=${platform} m=${mode}
        case ${mode} in
            nand | mmc | spinor)
                make ${mode} -j
                ;;
            sboot_nor)
                echo "Neednot build sboot_nor ..."
                ;;
            *)
                make ${mode} -j
                ;;
        esac
    fi
    cd - > /dev/null 2>&1
}
 
function build_spl(){
    if [ ! -d $TOP_DIR/spl/board/${PLATFORM} ] && [ "x${PLATFORM}" != "xall" ];then
   PLATFORM=${CONFIG_SYS_CONFIG_NAME}
    fi
    if [ "x${PLATFORM}" = "xall" ];then
        for platform in `ls $TOP_DIR/spl/board`;do
            if [ "x${MODE}" = "xall" ];then
                build_spl_once ${platform} all
            else
                build_spl_once $platform ${MODE}
            fi
        done
    elif [ "x${MODE}" = "xall" ];then
        build_spl_once ${PLATFORM} all
    else
        build_spl_once ${PLATFORM} ${MODE}
    fi
}
 
function build_all(){
    build_uboot
 
    if [ -d ${BRANDY_SPL_DIR} ] ; then
        build_spl
   fi
}
 
while getopts to:p:m: OPTION
do
   case $OPTION in
   t)
       prepare_toolchain
       exit $?
       ;;
    o)
        prepare_toolchain
       if [ "x$OPTARG" == "xboot0" ]; then
           command="build_spl"
       else
           command="build_$OPTARG"
       fi
        ;;
 
   p)
       PLATFORM=$OPTARG
       ;;
   m)
       MODE=$OPTARG
        ;;
   *)
        show_help
       exit $?
       ;;
    esac
done
 
if [ "x${PLATFORM}" = "x" ];then
    PLATFORM=all
fi
if [ "x${MODE}" = "x" ];then
    MODE=all
fi
if [ "x$command" != "x" ];then
    $command
else
    build_all
fi
exit $?