propagate from branch 'org.openembedded.dev' (head ab0d9a488e49d9ec307f6d034845a25a15...
[vuplus_openembedded] / classes / image.bbclass
1 inherit rootfs_${IMAGE_PKGTYPE}
2
3 LICENSE = "MIT"
4 PACKAGES = ""
5 RDEPENDS += "${IMAGE_INSTALL}"
6
7 IMAGE_BASENAME[export] = "1"
8 export PACKAGE_INSTALL ?= "${IMAGE_INSTALL}"
9
10 # We need to recursively follow RDEPENDS and RRECOMMENDS for images
11 do_rootfs[recrdeptask] += "do_deploy do_populate_staging"
12
13 # Images are generally built explicitly, do not need to be part of world.
14 EXCLUDE_FROM_WORLD = "1"
15
16 USE_DEVFS ?= "0"
17
18 PID = "${@os.getpid()}"
19
20 PACKAGE_ARCH = "${MACHINE_ARCH}"
21
22 do_rootfs[depends] += "makedevs-native:do_populate_staging fakeroot-native:do_populate_staging"
23
24 python () {
25     import bb
26
27     deps = bb.data.getVarFlag('do_rootfs', 'depends', d) or ""
28     for type in (bb.data.getVar('IMAGE_FSTYPES', d, True) or "").split():
29         for dep in ((bb.data.getVar('IMAGE_DEPENDS_%s' % type, d) or "").split() or []):
30             deps += " %s:do_populate_staging" % dep
31     for dep in (bb.data.getVar('EXTRA_IMAGEDEPENDS', d, True) or "").split():
32         deps += " %s:do_populate_staging" % dep
33     bb.data.setVarFlag('do_rootfs', 'depends', deps, d)
34 }
35
36 #
37 # Get a list of files containing device tables to create.
38 # * IMAGE_DEVICE_TABLE is the old name to an absolute path to a device table file
39 # * IMAGE_DEVICE_TABLES is a new name for a file, or list of files, seached
40 #   for in the BBPATH
41 # If neither are specified then the default name of files/device_table-minimal.txt
42 # is searched for in the BBPATH (same as the old version.)
43 #
44 def get_devtable_list(d):
45         import bb
46         devtable = bb.data.getVar('IMAGE_DEVICE_TABLE', d, 1)
47         if devtable != None:
48                 return devtable
49         str = ""
50         devtables = bb.data.getVar('IMAGE_DEVICE_TABLES', d, 1)
51         if devtables == None:
52                 devtables = 'files/device_table-minimal.txt'
53         for devtable in devtables.split():
54                 str += " %s" % bb.which(bb.data.getVar('BBPATH', d, 1), devtable)
55         return str
56
57 IMAGE_POSTPROCESS_COMMAND ?= ""
58 MACHINE_POSTPROCESS_COMMAND ?= ""
59 ROOTFS_POSTPROCESS_COMMAND ?= ""
60
61 # some default locales
62 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
63
64 LINGUAS_INSTALL = "${@" ".join(map(lambda s: "locale-base-%s" % s, bb.data.getVar('IMAGE_LINGUAS', d, 1).split()))}"
65
66 do_rootfs[nostamp] = "1"
67 do_rootfs[dirs] = "${TOPDIR}"
68 do_build[nostamp] = "1"
69
70 # Must call real_do_rootfs() from inside here, rather than as a separate
71 # task, so that we have a single fakeroot context for the whole process.
72 fakeroot do_rootfs () {
73         set -x
74         rm -rf ${IMAGE_ROOTFS}
75         mkdir -p ${IMAGE_ROOTFS}
76
77         if [ "${USE_DEVFS}" != "1" ]; then
78                 for devtable in ${@get_devtable_list(d)}; do
79                         makedevs -r ${IMAGE_ROOTFS} -D $devtable
80                 done
81         fi
82
83         rootfs_${IMAGE_PKGTYPE}_do_rootfs
84
85         insert_feed_uris        
86
87         rm -f ${IMAGE_ROOTFS}${libdir}/ipkg/lists/*
88         
89         ${IMAGE_PREPROCESS_COMMAND}
90                 
91         export TOPDIR=${TOPDIR}
92         export MACHINE=${MACHINE}
93
94         for type in ${IMAGE_FSTYPES}; do
95                 if test -z "$FAKEROOTKEY"; then
96                         fakeroot -i ${TMPDIR}/fakedb.image ${PYTHON} `which bbimage` -t $type -e ${FILE}
97                 else
98                         ${PYTHON} `which bbimage` -n "${IMAGE_NAME}" -t "$type" -e "${FILE}"
99                 fi
100
101                 cd ${DEPLOY_DIR_IMAGE}/
102                 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.$type
103                 ln -s ${IMAGE_NAME}.rootfs.$type ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.$type
104         done
105
106         ${IMAGE_POSTPROCESS_COMMAND}
107         
108         ${MACHINE_POSTPROCESS_COMMAND}
109 }
110
111 insert_feed_uris () {
112         
113         echo "Building feeds for [${DISTRO}].."
114                 
115         for line in ${FEED_URIS}
116         do
117                 # strip leading and trailing spaces/tabs, then split into name and uri
118                 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
119                 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
120                 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"                                        
121                 
122                 echo "Added $feed_name feed with URL $feed_uri"
123                 
124                 # insert new feed-sources
125                 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/ipkg/${feed_name}-feed.conf
126         done                    
127 }
128
129 log_check() {
130         set +x
131         for target in $*
132         do
133                 lf_path="${WORKDIR}/temp/log.do_$target.${PID}"
134                 
135                 echo "log_check: Using $lf_path as logfile"
136                 
137                 if test -e "$lf_path"
138                 then
139                         rootfs_${IMAGE_PKGTYPE}_log_check $target $lf_path
140                 else
141                         echo "Cannot find logfile [$lf_path]"
142                 fi
143                 echo "Logfile is clean"         
144         done
145
146         set -x
147 }
148
149 # set '*' as the rootpassword so the images
150 # can decide if they want it or not
151
152 zap_root_password () {
153         sed 's%^root:[^:]*:%root:*:%' < ${IMAGE_ROOTFS}/etc/passwd >${IMAGE_ROOTFS}/etc/passwd.new
154         mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd    
155
156
157 create_etc_timestamp() {
158         date +%2m%2d%2H%2M%Y >${IMAGE_ROOTFS}/etc/timestamp
159 }
160
161 # Turn any symbolic /sbin/init link into a file
162 remove_init_link () {
163         if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
164                 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
165                 rm ${IMAGE_ROOTFS}/sbin/init
166                 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
167         fi
168 }
169
170 make_zimage_symlink_relative () {
171         if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
172                 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
173         fi
174 }
175
176 # Make login manager(s) enable automatic login.
177 # Useful for devices where we do not want to log in at all (e.g. phones)
178 set_image_autologin () {
179         sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
180 }
181
182
183 # export the zap_root_password, create_etc_timestamp and remote_init_link
184 EXPORT_FUNCTIONS zap_root_password create_etc_timestamp remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin
185
186 addtask rootfs before do_build after do_install