Obsolete unused backup project such as OK6410
guowenxue
2019-07-29 4816dc1cfe9ae844a61c4c45f384f3d096605d21
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
#!/bin/sh
# Descripion:  This shell script used to choose a linux kernel version to cross compile
#     Author:  GuoWenxue<guowenxue@gmail.com>
#  ChangeLog:
#       1, Version 1.0.0(2011.04.01), initialize first version 
#
 
PWD=`pwd`
PACKET_DIR=$PWD
PATCH_DIR=$PWD/patch
INST_PATH=$PWD/../../bin
SRC_NAME=linux-3.0
ARCH=s3c6410
#unset ARCH
 
#===============================================================
#               Functions forward definition                   =
#===============================================================
function disp_banner()
{
   echo ""
   echo "+------------------------------------------+"
   echo "|      Build $SRC_NAME for $ARCH            "
   echo "+------------------------------------------+"
   echo ""
}
 
sup_ver=("" "linux-3.0")
function select_version()
{
   echo "Current support linux kernel version:"
   i=1
   len=${#sup_ver[*]} 
 
   while [ $i -lt $len ]; do
       echo "$i: ${sup_ver[$i]}"
       let i++;
   done
 
   echo "Please select: "
   index=
   read index 
 
   SRC_NAME=${sup_ver[$index]}
}
 
sup_arch=("" "s3c6410")
function select_arch()
{
   echo "Current support S3C64X0 ARCH:"
   i=1
   len=${#sup_arch[*]}
 
 
   while [ $i -lt $len ]; do
       echo "$i: ${sup_arch[$i]}"
       let i++;
   done
 
   echo "Please select: "
   index=
   read index
 
   ARCH=${sup_arch[$index]}
}
 
#===============================================================
#                   Script excute body start                   =
#===============================================================
 
# If not define default version, then let user choose a one
if [ -z $SRC_NAME ] ; then
    select_version
fi
 
# If don't set the ARCH, then select one
if [ -z $ARCH ] ; then
   select_arch
fi
 
 
if [ -z "$CROSS" ] ; then
    CROSS=/opt/buildroot-2012.08/arm1176jzfs/usr/bin/arm-linux-
fi
 
# If $SRC_NAME not set, then abort this cross compile
if [ -z $SRC_NAME ] ; then 
    echo "ERROR: Please choose a valid version to cross compile"
    exit 1;
fi
 
disp_banner    #Display this shell script banner
 
 
# Check patche file exist or not
PATCH_FILE=$PATCH_DIR/$SRC_NAME-${ARCH}.patch
if [ ! -f $PATCH_FILE ] ; then
    echo "ERROR:$SRC_NAME patch file doesn't exist!"
    echo "PATH: \"$PATCH_FILE\"" 
    exit
fi
 
# Check original source code packet exist or not
SRC_ORIG_PACKET=$PACKET_DIR/$SRC_NAME.tar.bz2
if [ ! -s $SRC_ORIG_PACKET ] ; then
    echo "========================================================================="
    echo "ERROR:$SRC_NAME source code patcket doesn't exist."
    echo "PATH: \"$SRC_ORIG_PACKET\""
    echo ""
    
    MAJOR=`echo $SRC_NAME | awk -F "-" '{print $2}' | awk -F "." '{print $1}'`
    if [ $MAJOR == 3 ] ; then
        DL_ADDR=http://www.kernel.org/pub/linux/kernel/v3.x/$SRC_NAME.tar.bz2
    elif [ $MAJOR == 2 ] ; then
        DL_ADDR=http://www.kernel.org/pub/linux/kernel/v2.6/$SRC_NAME.tar.bz2
    fi
 
    echo "Download $DL_ADDR now..."
    echo "========================================================================="
 
    wget $DL_ADDR
 
    if [ ! -s $SRC_ORIG_PACKET ] ; then
        echo "Download $DL_ADDR failure, exit now..."
        exit
    fi
fi
 
 
#decompress the source code packet and patch
echo "*  Decompress the source code patcket and patch now...  *"
 
if [ -d $SRC_NAME ] ; then
    rm -rf $SRC_NAME
fi
 
if [ ! -d $INST_PATH ] ; then
    mkdir -p $INST_PATH
fi
 
#Remove old source code
tar -xjf $SRC_ORIG_PACKET
 
#Start to cross compile the source code and install it now
cd $SRC_NAME
   patch -p1 < $PATCH_FILE
   cp .cfg-$ARCH .config
   #Modify the cross tool in Makefile
   line=`sed -n '/CROSS_COMPILE    ?= /=' Makefile`
   sed -i -e ${line}s"|.*|CROSS_COMPILE    ?= $CROSS|" Makefile
   make
 
   set -x
   cp -af linuxrom-$ARCH.bin $INST_PATH
   cp -af linuxrom-$ARCH.bin /tftp
cd -