Merge branch 'org.openembedded.dev' of git@git.openembedded.net:openembedded into...
[vuplus_openembedded] / classes / image.bbclass
1 inherit rootfs_${IMAGE_PKGTYPE}
2
3 LICENSE = "MIT"
4 PACKAGES = ""
5 RDEPENDS += "${IMAGE_INSTALL}"
6
7 # "export IMAGE_BASENAME" not supported at this time
8 IMAGE_BASENAME[export] = "1"
9 export PACKAGE_INSTALL ?= "${IMAGE_INSTALL}"
10
11 # We need to recursively follow RDEPENDS and RRECOMMENDS for images
12 do_rootfs[recrdeptask] += "do_deploy do_populate_staging"
13
14 # Images are generally built explicitly, do not need to be part of world.
15 EXCLUDE_FROM_WORLD = "1"
16
17 USE_DEVFS ?= "0"
18
19 #
20 # udev, devfsd, busybox-mdev (from busybox) or none
21 #
22 IMAGE_DEV_MANAGER ?= "${@base_contains("MACHINE_FEATURES", "kernel26",  "udev","",d)} "
23 #
24 # sysvinit, upstart
25 #
26 IMAGE_INIT_MANAGER ?= "sysvinit sysvinit-pidof"
27 IMAGE_INITSCRIPTS ?= "initscripts"
28 #
29 # tinylogin, getty
30 #
31 IMAGE_LOGIN_MANAGER ?= "tinylogin" 
32
33 IMAGE_VARS = "${IMAGE_INITSCRIPTS} \
34 ${IMAGE_DEV_MANAGER} \
35 ${IMAGE_INIT_MANAGER} \
36 ${IMAGE_LOGIN_MANAGER} "
37
38 RDEPENDS += "${IMAGE_VARS}"
39 PACKAGE_INSTALL += "${IMAGE_VARS}"
40
41 PID = "${@os.getpid()}"
42
43 PACKAGE_ARCH = "${MACHINE_ARCH}"
44
45 do_rootfs[depends] += "makedevs-native:do_populate_staging fakeroot-native:do_populate_staging"
46
47 python () {
48     import bb
49
50     deps = bb.data.getVarFlag('do_rootfs', 'depends', d) or ""
51     for type in (bb.data.getVar('IMAGE_FSTYPES', d, True) or "").split():
52         for dep in ((bb.data.getVar('IMAGE_DEPENDS_%s' % type, d) or "").split() or []):
53             deps += " %s:do_populate_staging" % dep
54     for dep in (bb.data.getVar('EXTRA_IMAGEDEPENDS', d, True) or "").split():
55         deps += " %s:do_populate_staging" % dep
56     bb.data.setVarFlag('do_rootfs', 'depends', deps, d)
57
58     runtime_mapping_rename("PACKAGE_INSTALL", d)
59 }
60
61 #
62 # Get a list of files containing tables of devices to be created.
63 # * IMAGE_DEVICE_TABLE is the old name to an absolute path to a device table file
64 # * IMAGE_DEVICE_TABLES is a new name for a file, or list of files, searched
65 #   for in the BBPATH
66 # If neither are specified then the default name of files/device_table-minimal.txt
67 # is searched for in the BBPATH (same as the old version.)
68 #
69 def get_devtable_list(d):
70     import bb
71     devtable = bb.data.getVar('IMAGE_DEVICE_TABLE', d, 1)
72     if devtable != None:
73         return devtable
74     str = ""
75     devtables = bb.data.getVar('IMAGE_DEVICE_TABLES', d, 1)
76     if devtables == None:
77         devtables = 'files/device_table-minimal.txt'
78     for devtable in devtables.split():
79         str += " %s" % bb.which(bb.data.getVar('BBPATH', d, 1), devtable)
80     return str
81
82 def get_imagecmds(d):
83     import bb
84     cmds = "\n"
85     old_overrides = bb.data.getVar('OVERRIDES', d, 0)
86     for type in bb.data.getVar('IMAGE_FSTYPES', d, True).split():
87         localdata = bb.data.createCopy(d)
88         bb.data.setVar('OVERRIDES', '%s:%s' % (type, old_overrides), localdata)
89         bb.data.update_data(localdata)
90         cmd  = "\t#Code for image type " + type + "\n"
91         cmd += "\t${IMAGE_CMD_" + type + "}\n"
92         cmd += "\tcd ${DEPLOY_DIR_IMAGE}/\n"
93         cmd += "\trm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}." + type + "\n"
94         cmd += "\tln -s ${IMAGE_NAME}.rootfs." + type + " ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}." + type + "\n\n"
95         cmds += bb.data.expand(cmd, localdata)
96     return cmds
97
98 IMAGE_POSTPROCESS_COMMAND ?= ""
99 MACHINE_POSTPROCESS_COMMAND ?= ""
100 ROOTFS_POSTPROCESS_COMMAND ?= ""
101
102 # some default locales
103 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
104
105 LINGUAS_INSTALL = "${@" ".join(map(lambda s: "locale-base-%s" % s, bb.data.getVar('IMAGE_LINGUAS', d, 1).split()))}"
106
107 do_rootfs[nostamp] = "1"
108 do_rootfs[dirs] = "${TOPDIR}"
109 do_rootfs[lockfiles] = "${IMAGE_ROOTFS}.lock"
110 do_build[nostamp] = "1"
111
112 # Must call real_do_rootfs() from inside here, rather than as a separate
113 # task, so that we have a single fakeroot context for the whole process.
114 fakeroot do_rootfs () {
115         set -x
116         rm -rf ${IMAGE_ROOTFS}
117         mkdir -p ${IMAGE_ROOTFS}
118         mkdir -p ${DEPLOY_DIR_IMAGE}
119
120         if [ "${USE_DEVFS}" != "1" ]; then
121                 for devtable in ${@get_devtable_list(d)}; do
122                         makedevs -r ${IMAGE_ROOTFS} -D $devtable
123                 done
124         fi
125
126         rootfs_${IMAGE_PKGTYPE}_do_rootfs
127
128         insert_feed_uris
129
130         ${IMAGE_PREPROCESS_COMMAND}
131
132         ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{size = ${IMAGE_EXTRA_SPACE} + $1; print (size > ${IMAGE_ROOTFS_SIZE} ? size : ${IMAGE_ROOTFS_SIZE}) }'`
133         ${@get_imagecmds(d)}
134
135         ${IMAGE_POSTPROCESS_COMMAND}
136         
137         ${MACHINE_POSTPROCESS_COMMAND}
138 }
139
140 do_deploy_to[nostamp] = "1"
141 do_deploy_to () {
142         # A standalone task to deploy built image to the location specified
143         # by DEPLOY_TO variable (likely passed via environment).
144         # Assumes ${IMAGE_FSTYPES} is a single value!
145         cp "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.${IMAGE_FSTYPES}" ${DEPLOY_TO}
146 }
147
148 insert_feed_uris () {
149         
150         echo "Building feeds for [${DISTRO}].."
151
152         for line in ${FEED_URIS}
153         do
154                 # strip leading and trailing spaces/tabs, then split into name and uri
155                 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
156                 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
157                 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
158                 
159                 echo "Added $feed_name feed with URL $feed_uri"
160                 
161                 # insert new feed-sources
162                 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
163         done
164
165         # Allow to use package deploy directory contents as quick devel-testing
166         # feed. This creates individual feed configs for each arch subdir of those
167         # specified as compatible for the current machine.
168         # NOTE: Development-helper feature, NOT a full-fledged feed.
169         if [ -n "${FEED_DEPLOYDIR_BASE_URI}" ]; then
170             for arch in ${PACKAGE_ARCHS}
171             do
172                 echo "src/gz local-$arch ${FEED_DEPLOYDIR_BASE_URI}/$arch" >> ${IMAGE_ROOTFS}/etc/opkg/local-$arch-feed.conf
173             done
174         fi
175 }
176
177 log_check() {
178         set +x
179         for target in $*
180         do
181                 lf_path="${WORKDIR}/temp/log.do_$target.${PID}"
182                 
183                 echo "log_check: Using $lf_path as logfile"
184                 
185                 if test -e "$lf_path"
186                 then
187                         rootfs_${IMAGE_PKGTYPE}_log_check $target $lf_path
188                 else
189                         echo "Cannot find logfile [$lf_path]"
190                 fi
191                 echo "Logfile is clean"
192         done
193
194         set -x
195 }
196
197 # set '*' as the rootpassword so the images
198 # can decide if they want it or not
199
200 zap_root_password () {
201         sed 's%^root:[^:]*:%root:*:%' < ${IMAGE_ROOTFS}/etc/passwd >${IMAGE_ROOTFS}/etc/passwd.new
202         mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
203
204
205 create_etc_timestamp() {
206         date +%2m%2d%2H%2M%Y >${IMAGE_ROOTFS}/etc/timestamp
207 }
208
209 # Turn any symbolic /sbin/init link into a file
210 remove_init_link () {
211         if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
212                 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
213                 rm ${IMAGE_ROOTFS}/sbin/init
214                 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
215         fi
216 }
217
218 make_zimage_symlink_relative () {
219         if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
220                 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
221         fi
222 }
223
224 # Make login manager(s) enable automatic login.
225 # Useful for devices where we do not want to log in at all (e.g. phones)
226 set_image_autologin () {
227         sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
228 }
229
230 # Can be use to create /etc/timestamp during image construction to give a reasonably 
231 # sane default time setting
232 rootfs_update_timestamp () {
233         date "+%m%d%H%M%Y" >${IMAGE_ROOTFS}/etc/timestamp
234 }
235
236 # export the zap_root_password, create_etc_timestamp and remote_init_link
237 EXPORT_FUNCTIONS zap_root_password create_etc_timestamp remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp
238
239 addtask rootfs before do_build after do_install
240 addtask deploy_to after do_rootfs