1 inherit rootfs_${IMAGE_PKGTYPE}
8 # udev, devfsd, busybox-mdev (from busybox) or none
10 IMAGE_DEV_MANAGER ?= "${@base_contains("MACHINE_FEATURES", "kernel26", "udev","",d)} "
14 IMAGE_INIT_MANAGER ?= "sysvinit sysvinit-pidof"
15 IMAGE_INITSCRIPTS ?= "initscripts"
19 IMAGE_LOGIN_MANAGER ?= "tinylogin"
21 # set sane default for the SPLASH variable
24 IMAGE_KEEPROOTFS ?= ""
25 IMAGE_KEEPROOTFS[doc] = "Set to non-empty to keep ${IMAGE_ROOTFS} around after image creation."
27 IMAGE_BOOT ?= "${IMAGE_INITSCRIPTS} \
28 ${IMAGE_DEV_MANAGER} \
29 ${IMAGE_INIT_MANAGER} \
30 ${IMAGE_LOGIN_MANAGER}"
32 # some default locales
33 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
36 LINGUAS_INSTALL_linux = "glibc-localedata-i18n"
37 LINGUAS_INSTALL_linux += "${@' '.join(map(lambda s: 'locale-base-%s' % s, '${IMAGE_LINGUAS}'.split()))}"
38 LINGUAS_INSTALL_linux-gnueabi = "${LINGUAS_INSTALL_linux}"
40 PACKAGE_INSTALL = "${@' '.join(oe.packagegroup.required_packages('${IMAGE_FEATURES}'.split(), d))}"
41 PACKAGE_INSTALL_ATTEMPTONLY = "${@' '.join(oe.packagegroup.optional_packages('${IMAGE_FEATURES}'.split(), d))}"
42 RDEPENDS += "${@' '.join(oe.packagegroup.active_packages('${IMAGE_FEATURES}'.split(), d))}"
46 IMAGE_FEATURES_prepend = "image_base "
48 # Define our always included package group
49 PACKAGE_GROUP_image_base = "${IMAGE_INSTALL} ${IMAGE_BOOT} ${LINGUAS_INSTALL}"
51 # The following package groups allow one to add debugging, development, and
52 # documentation files for all packages installed in the image.
54 def string_set(iterable):
55 return ' '.join(set(iterable))
57 def image_features_noextras(d):
58 for f in d.getVar("IMAGE_FEATURES", True).split():
59 if not f in ('dbg', 'dev', 'doc'):
63 from itertools import chain
65 features = image_features_noextras(d)
66 return string_set("%s-dbg" % pkg
67 for pkg in chain(oe.packagegroup.active_packages(features, d),
68 oe.packagegroup.active_recipes(features, d)))
70 PACKAGE_GROUP_dbg = "${@dbg_packages(d)}"
71 PACKAGE_GROUP_dbg[optional] = "1"
72 PACKAGE_GROUP_dev = "${@string_set('%s-dev' % pn for pn in oe.packagegroup.active_recipes(image_features_noextras(d), d))}"
73 PACKAGE_GROUP_dev[optional] = "1"
74 PACKAGE_GROUP_doc = "${@string_set('%s-doc' % pn for pn in oe.packagegroup.active_recipes(image_features_noextras(d), d))}"
75 PACKAGE_GROUP_doc[optional] = "1"
77 # "export IMAGE_BASENAME" not supported at this time
78 IMAGE_BASENAME[export] = "1"
80 # We need to recursively follow RDEPENDS and RRECOMMENDS for images
81 do_rootfs[recrdeptask] += "do_deploy do_populate_sysroot"
83 # Images are generally built explicitly, do not need to be part of world.
84 EXCLUDE_FROM_WORLD = "1"
88 PID = "${@os.getpid()}"
90 PACKAGE_ARCH = "${MACHINE_ARCH}"
92 do_rootfs[depends] += "makedevs-native:do_populate_sysroot fakeroot-native:do_populate_sysroot"
97 deps = bb.data.getVarFlag('do_rootfs', 'depends', d) or ""
98 for type in (bb.data.getVar('IMAGE_FSTYPES', d, True) or "").split():
99 for dep in ((bb.data.getVar('IMAGE_DEPENDS_%s' % type, d) or "").split() or []):
100 deps += " %s:do_populate_sysroot" % dep
101 for dep in (bb.data.getVar('EXTRA_IMAGEDEPENDS', d, True) or "").split():
102 deps += " %s:do_populate_sysroot" % dep
103 bb.data.setVarFlag('do_rootfs', 'depends', deps, d)
105 runtime_mapping_rename("PACKAGE_INSTALL", d)
106 runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", d)
110 # Get a list of files containing tables of devices to be created.
111 # * IMAGE_DEVICE_TABLE is the old name to an absolute path to a device table file
112 # * IMAGE_DEVICE_TABLES is a new name for a file, or list of files, searched
114 # If neither are specified then the default name of files/device_table-minimal.txt
115 # is searched for in the BBPATH (same as the old version.)
117 def get_devtable_list(d):
119 devtable = bb.data.getVar('IMAGE_DEVICE_TABLE', d, 1)
122 devtables = bb.data.getVar('IMAGE_DEVICE_TABLES', d, 1)
123 if devtables == None:
124 devtables = 'files/device_table-minimal.txt'
125 return " ".join([ bb.which(bb.data.getVar('BBPATH', d, 1), devtable)
126 for devtable in devtables.split() ])
128 def get_imagecmds(d):
131 old_overrides = bb.data.getVar('OVERRIDES', d, 0)
132 for type in bb.data.getVar('IMAGE_FSTYPES', d, True).split():
133 localdata = bb.data.createCopy(d)
134 bb.data.setVar('OVERRIDES', '%s:%s' % (type, old_overrides), localdata)
135 bb.data.update_data(localdata)
136 cmd = "\t#Code for image type " + type + "\n"
137 cmd += "\t${IMAGE_CMD_" + type + "}\n"
138 cmd += "\tcd ${DEPLOY_DIR_IMAGE}/\n"
139 cmd += "\trm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}." + type + "\n"
140 cmd += "\tln -s ${IMAGE_NAME}.rootfs." + type + " ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}." + type + "\n\n"
141 cmds += bb.data.expand(cmd, localdata)
144 IMAGE_POSTPROCESS_COMMAND ?= ""
145 MACHINE_POSTPROCESS_COMMAND ?= ""
146 ROOTFS_POSTPROCESS_COMMAND ?= ""
148 do_rootfs[nostamp] = "1"
149 do_rootfs[dirs] = "${TOPDIR}"
150 do_build[nostamp] = "1"
152 # Must call real_do_rootfs() from inside here, rather than as a separate
153 # task, so that we have a single fakeroot context for the whole process.
154 fakeroot do_rootfs () {
156 rm -rf ${IMAGE_ROOTFS}
157 mkdir -p ${IMAGE_ROOTFS}
158 mkdir -p ${DEPLOY_DIR_IMAGE}
160 mkdir -p ${IMAGE_ROOTFS}/etc
162 if [ "${USE_DEVFS}" != "1" ]; then
163 rm -rf ${IMAGE_ROOTFS}/etc/device_table
164 for devtable in ${@get_devtable_list(d)}; do
165 cat $devtable >> ${IMAGE_ROOTFS}/etc/device_table
166 makedevs -r ${IMAGE_ROOTFS} -D $devtable
170 rootfs_${IMAGE_PKGTYPE}_do_rootfs
174 ${IMAGE_PREPROCESS_COMMAND}
176 ROOTFS_SIZE=`du -ks ${IMAGE_ROOTFS}|awk '{size = ${IMAGE_EXTRA_SPACE} + $1; print (size > ${IMAGE_ROOTFS_SIZE} ? size : ${IMAGE_ROOTFS_SIZE}) }'`
179 ${IMAGE_POSTPROCESS_COMMAND}
181 ${MACHINE_POSTPROCESS_COMMAND}
182 ${@['rm -rf ${IMAGE_ROOTFS}', ''][bool(d.getVar("IMAGE_KEEPROOTFS", 1))]}
185 do_deploy_to[nostamp] = "1"
187 # A standalone task to deploy built image to the location specified
188 # by DEPLOY_TO variable (likely passed via environment).
189 # Assumes ${IMAGE_FSTYPES} is a single value!
190 cp "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.${IMAGE_FSTYPES}" ${DEPLOY_TO}
193 insert_feed_uris () {
195 echo "Building feeds for [${DISTRO}].."
197 for line in ${FEED_URIS}
199 # strip leading and trailing spaces/tabs, then split into name and uri
200 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
201 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
202 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
204 echo "Added $feed_name feed with URL $feed_uri"
206 # insert new feed-sources
207 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
210 # Allow to use package deploy directory contents as quick devel-testing
211 # feed. This creates individual feed configs for each arch subdir of those
212 # specified as compatible for the current machine.
213 # NOTE: Development-helper feature, NOT a full-fledged feed.
214 if [ -n "${FEED_DEPLOYDIR_BASE_URI}" ]; then
215 for arch in ${PACKAGE_ARCHS}
217 echo "src/gz local-$arch ${FEED_DEPLOYDIR_BASE_URI}/$arch" >> ${IMAGE_ROOTFS}/etc/opkg/local-$arch-feed.conf
226 lf_path="${WORKDIR}/temp/log.do_$target.${PID}"
228 echo "log_check: Using $lf_path as logfile"
230 if test -e "$lf_path"
232 rootfs_${IMAGE_PKGTYPE}_log_check $target $lf_path
234 echo "Cannot find logfile [$lf_path]"
236 echo "Logfile is clean"
242 # set '*' as the rootpassword so the images
243 # can decide if they want it or not
245 zap_root_password () {
246 sed 's%^root:[^:]*:%root::%' < ${IMAGE_ROOTFS}/etc/passwd >${IMAGE_ROOTFS}/etc/passwd.new
247 mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
250 create_etc_timestamp() {
251 date +%2m%2d%2H%2M%Y >${IMAGE_ROOTFS}/etc/timestamp
254 # Turn any symbolic /sbin/init link into a file
255 remove_init_link () {
256 if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
257 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
258 rm ${IMAGE_ROOTFS}/sbin/init
259 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
263 make_zimage_symlink_relative () {
264 if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
265 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
269 # Make login manager(s) enable automatic login.
270 # Useful for devices where we do not want to log in at all (e.g. phones)
271 set_image_autologin () {
272 sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
275 # Can be use to create /etc/timestamp during image construction to give a reasonably
276 # sane default time setting
277 rootfs_update_timestamp () {
278 date "+%m%d%H%M%Y" >${IMAGE_ROOTFS}/etc/timestamp
281 # Install locales into image for every entry in IMAGE_LINGUAS
283 if [ -e ${IMAGE_ROOTFS}/usr/bin/opkg-cl ] ; then
284 OPKG="opkg-cl ${IPKG_ARGS}"
286 ${OPKG} update || true
287 ${OPKG} list_installed | awk '{print $1}' |sort | uniq > /tmp/installed-packages
289 for i in $(cat /tmp/installed-packages | grep -v locale) ; do
290 for translation in ${IMAGE_LINGUAS}; do
291 translation_split=$(echo ${translation} | awk -F '-' '{print $1}')
292 echo ${i}-locale-${translation}
293 echo ${i}-locale-${translation_split}
295 done | sort | uniq > /tmp/wanted-locale-packages
297 ${OPKG} list | awk '{print $1}' |grep locale |sort | uniq > /tmp/available-locale-packages
299 cat /tmp/wanted-locale-packages /tmp/available-locale-packages | sort | uniq -d > /tmp/pending-locale-packages
301 if [ -s /tmp/pending-locale-packages ] ; then
302 cat /tmp/pending-locale-packages | xargs ${OPKG} -nodeps install
304 rm -f ${IMAGE_ROOTFS}${libdir}/opkg/lists/*
306 for i in ${IMAGE_ROOTFS}${libdir}/opkg/info/*.preinst; do
307 if [ -f $i ] && ! sh $i; then
308 opkg-cl ${IPKG_ARGS} flag unpacked `basename $i .preinst`
312 for i in ${IMAGE_ROOTFS}${libdir}/opkg/info/*.postinst; do
313 if [ -f $i ] && ! sh $i configure; then
314 opkg-cl ${IPKG_ARGS} flag unpacked `basename $i .postinst`
321 # export the zap_root_password, create_etc_timestamp and remote_init_link
322 EXPORT_FUNCTIONS zap_root_password create_etc_timestamp remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp install_linguas
324 addtask rootfs before do_build after do_install
325 addtask deploy_to after do_rootfs