Obsolete unused backup project such as OK6410
guowenxue
2019-07-28 21f18dcd728d13b23dc5e19ff4bc0dcbbd8156e2
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
#!/bin/bash
# Description: This shell script used to build linux system SDK. You can 
#              use command line argument to specify build target, or select 
#              it by hand if no argument given by command line. More detail
#              information can refer to the help message.
#
#      Author: guowenxue <guowenxue@gmail.com>
#     Version: 1.0.0  
 
 
PROJ_PATH=`pwd`
 
PACK_PATH=${PROJ_PATH}/tarballs
PATCH_PATH=${PROJ_PATH}/patches
PATCH_SUFIX=ok335x.patch
 
 
LINUX_SRC=linux-3.2.0
UBOOT_SRC=u-boot-2011.09
ROOTFS_SRC=rootfs
 
ROOTFS_IMG=ubifs.img
 
TFTP_PATH=/tftp
IMGS_PATH=images
 
target=
 
set -e
 
function show_help()
{
    printf "Usage: $1 [system/u-boot/kernel/rootfs/clean]\n\n"
 
    echo "system: build all source code "
    echo "u-boot: just build u-boot "
    echo "kernel: just build linux kernel "
    echo "rootfs: just build rootfs images"
    printf "clean : clean the source code\n\n"
 
    exit 0;
}
 
function show_banner()
{
    echo "+---------------------------------------------+" 
    printf "$1\n"
    echo "+---------------------------------------------+"
}
 
function select_target()
{
    targets=("" "system" "u-boot" "kernel" "rootfs" "clean")
    echo "Please select a build target:"
    echo "1 <system>, build all source code "
    echo "2 <u-boot>, just build u-boot "
    echo "3 <kernel>, just build linux kernel "
    echo "4 <rootfs>, just build rootfs image"
    echo "5 <clean>,  clean the source code"
    echo ""
 
    stty erase '^H'
    read -p "Enter your choise [1-5] : " choice
 
    if [ $choice -gt 5 ] ; then
        echo "ERROR: Invalid input choice, exit now..."
        exit 1;
    fi
 
    target=${targets[$choice]}
}
 
function build_uboot()
{
    if [ ! -d ${UBOOT_SRC} ] ; then
        tar -xJf ${PACK_PATH}/${UBOOT_SRC}.tar.xz 
        cd ${UBOOT_SRC} 
        patch -p1 < ${PATCH_PATH}/${UBOOT_SRC}-${PATCH_SUFIX}
    else
        cd ${UBOOT_SRC} 
    fi
 
 
    show_banner "|          start uboot build task...          |"
    bash build.sh
    show_banner "|           uboot build task over!            |"
 
    cd -
}
 
 
function build_kernel()
{
    if [ ! -d ${ROOTFS_SRC} ] ; then 
        echo "WARNNING: Maybe need input sudo passwd here: "
        sudo tar -xJf ${PACK_PATH}/${ROOTFS_SRC}.tar.xz
    fi
 
    if [ ! -d ${LINUX_SRC} ] ; then
        tar -xJf ${PACK_PATH}/${LINUX_SRC}.tar.xz 
        cd ${LINUX_SRC}
        patch -p1 < ${PATCH_PATH}/${LINUX_SRC}-${PATCH_SUFIX}
    else
        cd ${LINUX_SRC}
    fi
 
    show_banner "|           start kernel build task...        |"
    echo "WARNNING: Maybe need input sudo passwd here: "
    sudo bash build.sh
    show_banner "|            kernel build task over!          |"
 
    cd -
}
 
function build_ubifs()
{
    mkfs.ubifs –F -q -r ${ROOTFS_SRC} -m 2048 -e 126976 -c 2047 -o ubi.img
    cat > ubinize.cfg <<EOF
[ubifs]
mode=ubi
image=ubi.img
vol_id=0
vol_size=231MiB
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize
EOF
 
    ubinize -o ${ROOTFS_IMG} -m 2048 -p 128KiB ubinize.cfg
    rm -f ubi.img  ubinize.cfg
 
    chmod a+x ${ROOTFS_IMG}
}
 
function build_rootfs()
{
    if [ ! -d ${ROOTFS_SRC} ] ; then 
        echo "WARNNING: Maybe need input sudo passwd here: "
        sudo tar -xJf ${PACK_PATH}/${ROOTFS_SRC}.tar.xz
    fi
 
    show_banner "|           start build rootfs image...        |"
    build_ubifs
    show_banner "|           rootfs image build over!          |"
 
    if [ -d ${IMGS_PATH} ] ; then
        cp -f ${ROOTFS_IMG} ${IMGS_PATH}
    fi
 
    if [ -d ${TFTP_PATH} ] ; then
        cp -f ${ROOTFS_IMG} ${TFTP_PATH}
    fi
}
 
 
function do_clean()
{
    show_banner "|         clean project source code           |"
 
    # cleanup rootfs image
    rm -rf ${ROOTFS_SRC} ${ROOTFS_IMG}
 
 
    # cleanup u-boot source code    
    if [ -d ${UBOOT_SRC} ] ; then
 
        cd ${UBOOT_SRC}
        bash build.sh clean
        cd -
 
    fi
    
    # cleanup linux kernel source code
    if [ -d ${LINUX_SRC} ] ; then
 
        cd ${LINUX_SRC}
        bash build.sh clean
        cd -
 
    fi
}
 
 
function do_build()
{
    if   [ "$target" = "system" ] ; then
        build_uboot
        build_rootfs
        build_kernel
 
    elif [ "$target" = "u-boot" ] ; then
        build_uboot
 
    elif [ "$target" = "kernel" ] ; then
        build_kernel
 
    elif [ "$target" = "rootfs" ] ; then
        build_rootfs
 
    elif [ "$target" = "clean" ] ; then
        do_clean
 
    else
        show_help
    fi
}
 
mkdir -p ${IMGS_PATH}
 
# check input arguments for build target
if [ $# -ge 1 ] ; then
    target=$1
else 
    select_target
fi
show_banner "|        choose build target [$target]         |"
 
do_build