aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/creat-lsb-image
blob: 71d9215d41cff3f9b78886c08afbfde8796529ee (plain)
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
#!/bin/bash
#
# Copyright (c) 2005-2010 Wind River Systems, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA


red='\E[31;40m'
green='\E[32;40m'
USER=`whoami`
MACHINE=$1
IMAGE_PATH=../build/tmp/deploy/images/


ECHO()
{
    echo -e "${green}$@"
    tput sgr0
}

exit_check()
{
    if [ ! $? -eq 0 ]; then
        exit $?
    fi
}

usage()
{
    ECHO "${red}usage:you should input one of the next commmands according to detailed target platform:"
    ECHO "creat-lsb-image qemux86"
    ECHO "creat-lsb-image qemux86-64"
    ECHO "creat-lsb-image qemuppc"
}

#There should be a patameter to get machine type
if [ $# -ne 1 ]; then
    usage
    exit 1
fi

#check lsb image
if [ ! -d $IMAGE_PATH ];then
    ECHO "${red}There isn't image directory"
    exit 1
fi
ECHO "Enter directory $IMAGE_PATH"
cd $IMAGE_PATH

#get architecture
case $MACHINE in
    qemux86)
        ARCH=ia32
        PN=`find . -name poky-image-lsb-${MACHINE}\*.rootfs.tar.bz2 -type f | awk -F- 'BEGIN{ max=0;} {if( NR!=0 && $5>max ) max=$5 }END{ printf "%d" ,max ;}'`
        if [ "XPN" == "X" ];then
            ECHO "${red}Don't find lsb image on platform, Please run \"poky-image-lsb\" to generate lsb image"
            exit 1
        fi
    ;;
    qemux86-64)
        ARCH=x86_64
        PN=`find . -nam! e poky-image-lsb-${MACHINE}\*.rootfs.tar.bz2 -type f | awk -F- 'BEGIN{ max=0; } {if( NR!=0 && $6>max ) max=$6 }END{ printf "%d" ,max ;}'`
        if [ "X${PN}" == "X" ];then
            ECHO "${red}Don't find lsb image on platform, Please run \"poky-image-lsb\" to generate lsb image"
            exit 1
        fi
    ;;
    qemuppc)
        ARCH=ppc32
        PN=`find . -name poky-image-lsb-${MACHINE}\*.rootfs.tar.bz2 -type f | awk -F- 'BEGIN{ max=0;} {if( NR!=0 && $5>max ) max=$5 }END{ printf "%d" ,max ;}'`
        if [ "XPN" == "X" ];then
            ECHO "${red}Don't find lsb image on platform, Please run \"poky-image-lsb\" to generate lsb image"
		fi
    ;;
    *)
        ECHO "${red}Don't support lsb test for platform ${MACHINE}"
        exit 1
esac

if [ $PN -eq 0 ];then
	ECHO "${red}Can't ${MACHINE} rootfs.tar.gz,Please run poky-image-lsb to get lsb image"
	exit 1
fi

#download lsb test suite
if [ ! -f lsb-dist-testkit-4.0.2-1.${ARCH}.tar.gz ];then
	ECHO "Download lsb test suite, it could take some time..."
    wget -c -t 5  http://ftp.linuxfoundation.org/pub/lsb/bundles/released-4.0.0/dist-testkit/lsb-dist-testkit-4.0.2-1.${ARCH}.tar.gz
    exit_check
else
	ECHO "Find lsb test suite for ${MACHINE}"
fi

#if [ -L poky-image-lsb-${MACHINE}.ext3 ];then
#    /bin/rm poky-image-lsb-${MACHINE}.ext3
#    exit_check
#fi

#creat lsb image
if [ -f poky-image-lsb-${MACHINE}-test.ext3 ];then
	if [ -d lsbtmp ];then
    	sudo umount lsbtmp
	fi
	ECHO "Remove old lsb image..."
	/bin/rm poky-image-lsb-${MACHINE}-test.ext3
fi	
ECHO "creat a big ext3 file for lsb image with 3G..."
dd if=/dev/zero of=poky-image-lsb-${MACHINE}-test.ext3 bs=1M count=3000
exit_check
ECHO "Format ext3 image,please input \"y\""
mkfs.ext3 poky-image-lsb-${MACHINE}-test.ext3
tune2fs -j  poky-image-lsb-${MACHINE}-test.ext3


ECHO "get a lsb image with lsb test suite"
if [ ! -d lsbtmp ];then
	mkdir lsbtmp
fi


#install file system and lsb test suite to lsb image
sudo mount -o loop poky-image-lsb-${MACHINE}-test.ext3 lsbtmp
exit_check

ECHO "  ->Install file system..."
sudo tar jxf poky-image-lsb-${MACHINE}-${PN}.rootfs.tar.bz2 -C lsbtmp
exit_check

ECHO "  ->Install lsb test suite..."
sudo tar zxf lsb-dist-testkit-4.0.2-1.${ARCH}.tar.gz -C lsbtmp
exit_check

if [ -f modules-*-${MACHINE}.tgz ];then
ECHO "  ->Install moules of driver..."	
	sudo tar zxf modules-*-${MACHINE}.tgz -C lsbtmp/
fi


#mount lsbtmp
sudo umount lsbtmp
exit_check
sudo rm -rf lsbtmp

#change file attribute
sudo chown ${USER}:${USER} poky-image-lsb-${MACHINE}-test.ext3 
exit_check
sudo chmod 755 poky-image-lsb-${MACHINE}-test.ext3
exit_check

#set up link
if [ -L poky-image-lsb-${MACHINE}.ext3 ];then
ECHO "Set up link"
    /bin/rm poky-image-lsb-${MACHINE}.ext3
    exit_check
fi
ln -s poky-image-lsb-${MACHINE}-test.ext3 poky-image-lsb-${MACHINE}.ext3

ECHO "LSB test environment is set successfully, Please run \"poky-qemu ${MACHINE}\" to start up lsb-image"