Obsolete unused backup project such as OK6410
guowenxue
2019-08-04 a4f1135ccbefab1bb5564de7634d1f2b490d8071
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
#!/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...          |"
    chmod a+x build.sh
    bash build.sh
    show_banner "|           uboot build task over!            |"
 
    cd -
}
 
 
function build_kernel()
{
    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...        |"
    chmod a+x build.sh
    bash build.sh
    show_banner "|            kernel build task over!          |"
 
    cd -
}
 
#/tmp >: ubiattach -m 5 -d 5 /dev/ubi_ctrl
#[  822.268210] UBI: attaching mtd5 to ubi5
#[  822.272237] UBI: physical eraseblock size:   131072 bytes (128 KiB)
#[  822.278848] UBI: logical eraseblock size:    126976 bytes
#[  822.284479] UBI: smallest flash I/O unit:    2048
#[  822.289398] UBI: VID header offset:          2048 (aligned 2048)
#[  822.295665] UBI: data offset:                4096
 
function build_ubifs()
{
    ubinize_cfg=ubinize.cfg 
    ubimg_tmp=ubi.img
 
    partition_size=140  # MiB 
 
    # PEB counter: PartitionSize / PagesPerBlock(64) / PageSize(2K)
    partition_peb_cnt=`expr $partition_size \* 1024 / 64 / 2`
 
    # LEB counter need reserved some blocks for UBI badblock used.
    partition_leb_cnt=`expr $partition_peb_cnt - 20`
 
    echo "Parition size ${partition_size}MiB set LEB=$partition_leb_cnt"
    set -x
    mkfs.ubifs -F -d ${ROOTFS_SRC} -m 2048 -e 126976 -c $partition_leb_cnt -o ubi.img
    set +x
 
    printf "[ubifs] \nmode=ubi \nimage=${ubimg_tmp} \nvol_id=0 \nvol_size=${partition_size}MiB\n" > $ubinize_cfg 
    printf "vol_type=dynamic \nvol_name=rootfs \nvol_flags=autoresize\n" >> $ubinize_cfg
 
    ubinize -o ${ROOTFS_IMG} -m 2048 -p 128KiB $ubinize_cfg
    rm -f $ubimg_tmp $ubinize_cfg
 
    chmod a+x ${ROOTFS_IMG}
}
 
function build_rootfs()
{
    if [ ! -d ${ROOTFS_SRC} ] ; then 
        echo "WARNNING: decompress rootfs 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
 
    rm -f ${ROOTFS_IMG}
    ls ${IMGS_PATH}
}
 
 
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