summaryrefslogtreecommitdiffstats
path: root/meta/classes/image.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/image.bbclass')
-rw-r--r--meta/classes/image.bbclass408
1 files changed, 408 insertions, 0 deletions
diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
new file mode 100644
index 0000000..79de5a2
--- /dev/null
+++ b/meta/classes/image.bbclass
@@ -0,0 +1,408 @@
1inherit rootfs_${IMAGE_PKGTYPE}
2
3inherit populate_sdk_base
4
5TOOLCHAIN_TARGET_TASK += "${PACKAGE_INSTALL}"
6TOOLCHAIN_TARGET_TASK_ATTEMPTONLY += "${PACKAGE_INSTALL_ATTEMPTONLY}"
7POPULATE_SDK_POST_TARGET_COMMAND += "rootfs_sysroot_relativelinks; "
8
9inherit gzipnative
10
11LICENSE = "MIT"
12PACKAGES = ""
13DEPENDS += "${MLPREFIX}qemuwrapper-cross ${MLPREFIX}depmodwrapper-cross"
14RDEPENDS += "${PACKAGE_INSTALL} ${LINGUAS_INSTALL}"
15RRECOMMENDS += "${PACKAGE_INSTALL_ATTEMPTONLY}"
16
17INHIBIT_DEFAULT_DEPS = "1"
18
19TESTIMAGECLASS = "${@base_conditional('TEST_IMAGE', '1', 'testimage-auto', '', d)}"
20inherit ${TESTIMAGECLASS}
21
22# IMAGE_FEATURES may contain any available package group
23IMAGE_FEATURES ?= ""
24IMAGE_FEATURES[type] = "list"
25IMAGE_FEATURES[validitems] += "debug-tweaks read-only-rootfs"
26
27# rootfs bootstrap install
28ROOTFS_BOOTSTRAP_INSTALL = "${@base_contains("IMAGE_FEATURES", "package-management", "", "${ROOTFS_PKGMANAGE_BOOTSTRAP}",d)}"
29
30# packages to install from features
31FEATURE_INSTALL = "${@' '.join(oe.packagegroup.required_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
32FEATURE_INSTALL_OPTIONAL = "${@' '.join(oe.packagegroup.optional_packages(oe.data.typed_value('IMAGE_FEATURES', d), d))}"
33
34# Define some very basic feature package groups
35FEATURE_PACKAGES_package-management = "${ROOTFS_PKGMANAGE}"
36SPLASH ?= "psplash"
37FEATURE_PACKAGES_splash = "${SPLASH}"
38
39IMAGE_INSTALL_COMPLEMENTARY = '${@complementary_globs("IMAGE_FEATURES", d)}'
40
41def check_image_features(d):
42 valid_features = (d.getVarFlag('IMAGE_FEATURES', 'validitems', True) or "").split()
43 valid_features += d.getVarFlags('COMPLEMENTARY_GLOB').keys()
44 for var in d:
45 if var.startswith("PACKAGE_GROUP_"):
46 bb.warn("PACKAGE_GROUP is deprecated, please use FEATURE_PACKAGES instead")
47 valid_features.append(var[14:])
48 elif var.startswith("FEATURE_PACKAGES_"):
49 valid_features.append(var[17:])
50 valid_features.sort()
51
52 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
53 for feature in features:
54 if feature not in valid_features:
55 bb.fatal("'%s' in IMAGE_FEATURES is not a valid image feature. Valid features: %s" % (feature, ' '.join(valid_features)))
56
57IMAGE_INSTALL ?= ""
58IMAGE_INSTALL[type] = "list"
59export PACKAGE_INSTALL ?= "${IMAGE_INSTALL} ${ROOTFS_BOOTSTRAP_INSTALL} ${FEATURE_INSTALL}"
60PACKAGE_INSTALL_ATTEMPTONLY ?= "${FEATURE_INSTALL_OPTIONAL}"
61
62# Images are generally built explicitly, do not need to be part of world.
63EXCLUDE_FROM_WORLD = "1"
64
65USE_DEVFS ?= "1"
66
67PID = "${@os.getpid()}"
68
69PACKAGE_ARCH = "${MACHINE_ARCH}"
70
71LDCONFIGDEPEND ?= "ldconfig-native:do_populate_sysroot"
72LDCONFIGDEPEND_libc-uclibc = ""
73
74do_rootfs[depends] += "makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND}"
75do_rootfs[depends] += "virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot"
76do_rootfs[recrdeptask] += "do_packagedata"
77do_rootfs[vardeps] += "BAD_RECOMMENDATIONS NO_RECOMMENDATIONS"
78
79do_build[depends] += "virtual/kernel:do_deploy"
80
81def build_live(d):
82 if base_contains("IMAGE_FSTYPES", "live", "live", "0", d) == "0": # live is not set but hob might set iso or hddimg
83 d.setVar('NOISO', base_contains('IMAGE_FSTYPES', "iso", "0", "1", d))
84 d.setVar('NOHDD', base_contains('IMAGE_FSTYPES', "hddimg", "0", "1", d))
85 if d.getVar('NOISO', True) == "0" or d.getVar('NOHDD', True) == "0":
86 return "image-live"
87 return ""
88 return "image-live"
89
90IMAGE_TYPE_live = "${@build_live(d)}"
91
92inherit ${IMAGE_TYPE_live}
93IMAGE_TYPE_vmdk = '${@base_contains("IMAGE_FSTYPES", "vmdk", "image-vmdk", "", d)}'
94inherit ${IMAGE_TYPE_vmdk}
95
96python () {
97 deps = " " + imagetypes_getdepends(d)
98 d.appendVarFlag('do_rootfs', 'depends', deps)
99
100 deps = ""
101 for dep in (d.getVar('EXTRA_IMAGEDEPENDS', True) or "").split():
102 deps += " %s:do_populate_sysroot" % dep
103 d.appendVarFlag('do_build', 'depends', deps)
104
105 #process IMAGE_FEATURES, we must do this before runtime_mapping_rename
106 #Check for replaces image features
107 features = set(oe.data.typed_value('IMAGE_FEATURES', d))
108 remain_features = features.copy()
109 for feature in features:
110 replaces = set((d.getVar("IMAGE_FEATURES_REPLACES_%s" % feature, True) or "").split())
111 remain_features -= replaces
112
113 #Check for conflict image features
114 for feature in remain_features:
115 conflicts = set((d.getVar("IMAGE_FEATURES_CONFLICTS_%s" % feature, True) or "").split())
116 temp = conflicts & remain_features
117 if temp:
118 bb.fatal("%s contains conflicting IMAGE_FEATURES %s %s" % (d.getVar('PN', True), feature, ' '.join(list(temp))))
119
120 d.setVar('IMAGE_FEATURES', ' '.join(list(remain_features)))
121
122 # Ensure we have the vendor list for complementary package handling
123 ml_vendor_list = ""
124 multilibs = d.getVar('MULTILIBS', True) or ""
125 for ext in multilibs.split():
126 eext = ext.split(':')
127 if len(eext) > 1 and eext[0] == 'multilib':
128 localdata = bb.data.createCopy(d)
129 vendor = localdata.getVar("TARGET_VENDOR_virtclass-multilib-" + eext[1], False)
130 ml_vendor_list += " " + vendor
131 d.setVar('MULTILIB_VENDORS', ml_vendor_list)
132
133 check_image_features(d)
134 initramfs_image = d.getVar('INITRAMFS_IMAGE', True) or ""
135 if initramfs_image != "":
136 d.appendVarFlag('do_build', 'depends', " %s:do_bundle_initramfs" % d.getVar('PN', True))
137 d.appendVarFlag('do_bundle_initramfs', 'depends', " %s:do_rootfs" % initramfs_image)
138}
139
140IMAGE_CLASSES ?= "image_types"
141inherit ${IMAGE_CLASSES}
142
143IMAGE_POSTPROCESS_COMMAND ?= ""
144MACHINE_POSTPROCESS_COMMAND ?= ""
145# Allow dropbear/openssh to accept logins from accounts with an empty password string if debug-tweaks is enabled
146ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks", "ssh_allow_empty_password; ", "",d)}'
147# Enable postinst logging if debug-tweaks is enabled
148ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("IMAGE_FEATURES", "debug-tweaks", "postinst_enable_logging; ", "",d)}'
149# Write manifest
150IMAGE_MANIFEST = "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.manifest"
151ROOTFS_POSTPROCESS_COMMAND =+ "write_image_manifest ; "
152# Set default postinst log file
153POSTINST_LOGFILE ?= "${localstatedir}/log/postinstall.log"
154# Set default target for systemd images
155SYSTEMD_DEFAULT_TARGET ?= '${@base_contains("IMAGE_FEATURES", "x11-base", "graphical.target", "multi-user.target", d)}'
156ROOTFS_POSTPROCESS_COMMAND += '${@base_contains("DISTRO_FEATURES", "systemd", "set_systemd_default_target; ", "", d)}'
157
158# some default locales
159IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
160
161LINGUAS_INSTALL ?= "${@" ".join(map(lambda s: "locale-base-%s" % s, d.getVar('IMAGE_LINGUAS', True).split()))}"
162
163PSEUDO_PASSWD = "${IMAGE_ROOTFS}"
164
165do_rootfs[dirs] = "${TOPDIR}"
166do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock"
167do_rootfs[cleandirs] += "${S}"
168
169# Must call real_do_rootfs() from inside here, rather than as a separate
170# task, so that we have a single fakeroot context for the whole process.
171do_rootfs[umask] = "022"
172
173# A hook function to support read-only-rootfs IMAGE_FEATURES
174# Currently, it only supports sysvinit system.
175read_only_rootfs_hook () {
176 if ${@base_contains("DISTRO_FEATURES", "sysvinit", "true", "false", d)}; then
177 # Tweak the mount option and fs_passno for rootfs in fstab
178 sed -i -e '/^[#[:space:]]*\/dev\/root/{s/defaults/ro/;s/\([[:space:]]*[[:digit:]]\)\([[:space:]]*\)[[:digit:]]$/\1\20/}' ${IMAGE_ROOTFS}/etc/fstab
179 # Change the value of ROOTFS_READ_ONLY in /etc/default/rcS to yes
180 if [ -e ${IMAGE_ROOTFS}/etc/default/rcS ]; then
181 sed -i 's/ROOTFS_READ_ONLY=no/ROOTFS_READ_ONLY=yes/' ${IMAGE_ROOTFS}/etc/default/rcS
182 fi
183 # Run populate-volatile.sh at rootfs time to set up basic files
184 # and directories to support read-only rootfs.
185 if [ -x ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh ]; then
186 ${IMAGE_ROOTFS}/etc/init.d/populate-volatile.sh
187 fi
188 # If we're using openssh and the /etc/ssh directory has no pre-generated keys,
189 # we should configure openssh to use the configuration file /etc/ssh/sshd_config_readonly
190 # and the keys under /var/run/ssh.
191 if [ -d ${IMAGE_ROOTFS}/etc/ssh ]; then
192 if [ -e ${IMAGE_ROOTFS}/etc/ssh/ssh_host_rsa_key ]; then
193 echo "SYSCONFDIR=/etc/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
194 echo "SSHD_OPTS=" >> ${IMAGE_ROOTFS}/etc/default/ssh
195 else
196 echo "SYSCONFDIR=/var/run/ssh" >> ${IMAGE_ROOTFS}/etc/default/ssh
197 echo "SSHD_OPTS='-f /etc/ssh/sshd_config_readonly'" >> ${IMAGE_ROOTFS}/etc/default/ssh
198 fi
199 fi
200 fi
201}
202
203PACKAGE_EXCLUDE ??= ""
204PACKAGE_EXCLUDE[type] = "list"
205
206python rootfs_process_ignore() {
207 excl_pkgs = d.getVar("PACKAGE_EXCLUDE", True).split()
208 inst_pkgs = d.getVar("PACKAGE_INSTALL", True).split()
209 inst_attempt_pkgs = d.getVar("PACKAGE_INSTALL_ATTEMPTONLY", True).split()
210
211 d.setVar('PACKAGE_INSTALL_ORIG', ' '.join(inst_pkgs))
212 d.setVar('PACKAGE_INSTALL_ATTEMPTONLY', ' '.join(inst_attempt_pkgs))
213
214 for pkg in excl_pkgs:
215 if pkg in inst_pkgs:
216 bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL (%s). It will be removed from the list." % (pkg, d.getVar('PN', True), inst_pkgs))
217 inst_pkgs.remove(pkg)
218
219 if pkg in inst_attempt_pkgs:
220 bb.warn("Package %s, set to be excluded, is in %s PACKAGE_INSTALL_ATTEMPTONLY (%s). It will be removed from the list." % (pkg, d.getVar('PN', True), inst_pkgs))
221 inst_attempt_pkgs.remove(pkg)
222
223 d.setVar("PACKAGE_INSTALL", ' '.join(inst_pkgs))
224 d.setVar("PACKAGE_INSTALL_ATTEMPTONLY", ' '.join(inst_attempt_pkgs))
225}
226do_rootfs[prefuncs] += "rootfs_process_ignore"
227
228# We have to delay the runtime_mapping_rename until just before rootfs runs
229# otherwise, the multilib renaming could step in and squash any fixups that
230# may have occurred.
231python rootfs_runtime_mapping() {
232 pn = d.getVar('PN', True)
233 runtime_mapping_rename("PACKAGE_INSTALL", pn, d)
234 runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", pn, d)
235 runtime_mapping_rename("BAD_RECOMMENDATIONS", pn, d)
236}
237do_rootfs[prefuncs] += "rootfs_runtime_mapping"
238
239fakeroot python do_rootfs () {
240 from oe.rootfs import create_rootfs
241 from oe.image import create_image
242 from oe.manifest import create_manifest
243
244 # generate the initial manifest
245 create_manifest(d)
246
247 # generate rootfs
248 create_rootfs(d)
249
250 # generate final images
251 create_image(d)
252}
253
254insert_feed_uris () {
255
256 echo "Building feeds for [${DISTRO}].."
257
258 for line in ${FEED_URIS}
259 do
260 # strip leading and trailing spaces/tabs, then split into name and uri
261 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
262 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
263 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
264
265 echo "Added $feed_name feed with URL $feed_uri"
266
267 # insert new feed-sources
268 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
269 done
270}
271
272MULTILIBRE_ALLOW_REP =. "${base_bindir}|${base_sbindir}|${bindir}|${sbindir}|${libexecdir}|${sysconfdir}|${nonarch_base_libdir}/udev|/lib/modules/[^/]*/modules.*|"
273MULTILIB_CHECK_FILE = "${WORKDIR}/multilib_check.py"
274MULTILIB_TEMP_ROOTFS = "${WORKDIR}/multilib"
275
276# This function is intended to disallow empty root password if 'debug-tweaks' is not in IMAGE_FEATURES.
277zap_empty_root_password () {
278 if [ -e ${IMAGE_ROOTFS}/etc/shadow ]; then
279 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/shadow
280 elif [ -e ${IMAGE_ROOTFS}/etc/passwd ]; then
281 sed -i 's%^root::%root:*:%' ${IMAGE_ROOTFS}/etc/passwd
282 fi
283}
284
285# allow dropbear/openssh to accept root logins and logins from accounts with an empty password string
286ssh_allow_empty_password () {
287 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
288 sed -i 's/^[#[:space:]]*PermitRootLogin.*/PermitRootLogin yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
289 sed -i 's/^[#[:space:]]*PermitEmptyPasswords.*/PermitEmptyPasswords yes/' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
290 fi
291
292 if [ -e ${IMAGE_ROOTFS}${sbindir}/dropbear ] ; then
293 if grep -q DROPBEAR_EXTRA_ARGS ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear 2>/dev/null ; then
294 if ! grep -q "DROPBEAR_EXTRA_ARGS=.*-B" ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear ; then
295 sed -i 's/^DROPBEAR_EXTRA_ARGS="*\([^"]*\)"*/DROPBEAR_EXTRA_ARGS="\1 -B"/' ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
296 fi
297 else
298 printf '\nDROPBEAR_EXTRA_ARGS="-B"\n' >> ${IMAGE_ROOTFS}${sysconfdir}/default/dropbear
299 fi
300 fi
301
302 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/pam.d ] ; then
303 sed -i 's/nullok_secure/nullok/' ${IMAGE_ROOTFS}${sysconfdir}/pam.d/*
304 fi
305}
306
307# Disable DNS lookups, the SSH_DISABLE_DNS_LOOKUP can be overridden to allow
308# distros to choose not to take this change
309SSH_DISABLE_DNS_LOOKUP ?= " ssh_disable_dns_lookup ; "
310ROOTFS_POSTPROCESS_COMMAND_append_qemuall = "${SSH_DISABLE_DNS_LOOKUP}"
311ssh_disable_dns_lookup () {
312 if [ -e ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config ]; then
313 sed -i -e 's:#UseDNS yes:UseDNS no:' ${IMAGE_ROOTFS}${sysconfdir}/ssh/sshd_config
314 fi
315}
316
317# Enable postinst logging if debug-tweaks is enabled
318postinst_enable_logging () {
319 mkdir -p ${IMAGE_ROOTFS}${sysconfdir}/default
320 echo "POSTINST_LOGGING=1" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
321 echo "LOGFILE=${POSTINST_LOGFILE}" >> ${IMAGE_ROOTFS}${sysconfdir}/default/postinst
322}
323
324# Modify systemd default target
325set_systemd_default_target () {
326 if [ -d ${IMAGE_ROOTFS}${sysconfdir}/systemd/system -a -e ${IMAGE_ROOTFS}${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ]; then
327 ln -sf ${systemd_unitdir}/system/${SYSTEMD_DEFAULT_TARGET} ${IMAGE_ROOTFS}${sysconfdir}/systemd/system/default.target
328 fi
329}
330
331# Turn any symbolic /sbin/init link into a file
332remove_init_link () {
333 if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
334 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
335 rm ${IMAGE_ROOTFS}/sbin/init
336 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
337 fi
338}
339
340make_zimage_symlink_relative () {
341 if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
342 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
343 fi
344}
345
346python write_image_manifest () {
347 from oe.rootfs import image_list_installed_packages
348 with open(d.getVar('IMAGE_MANIFEST', True), 'w+') as image_manifest:
349 image_manifest.write(image_list_installed_packages(d, 'ver'))
350}
351
352# Make login manager(s) enable automatic login.
353# Useful for devices where we do not want to log in at all (e.g. phones)
354set_image_autologin () {
355 sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
356}
357
358# Can be use to create /etc/timestamp during image construction to give a reasonably
359# sane default time setting
360rootfs_update_timestamp () {
361 date -u +%4Y%2m%2d%2H%2M >${IMAGE_ROOTFS}/etc/timestamp
362}
363
364# Prevent X from being started
365rootfs_no_x_startup () {
366 if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
367 chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
368 fi
369}
370
371rootfs_trim_schemas () {
372 for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
373 do
374 # Need this in case no files exist
375 if [ -e $schema ]; then
376 oe-trim-schemas $schema > $schema.new
377 mv $schema.new $schema
378 fi
379 done
380}
381
382# Make any absolute links in a sysroot relative
383rootfs_sysroot_relativelinks () {
384 sysroot-relativelinks.py ${SDK_OUTPUT}/${SDKTARGETSYSROOT}
385}
386
387do_fetch[noexec] = "1"
388do_unpack[noexec] = "1"
389do_patch[noexec] = "1"
390do_configure[noexec] = "1"
391do_compile[noexec] = "1"
392do_install[noexec] = "1"
393do_populate_sysroot[noexec] = "1"
394do_package[noexec] = "1"
395do_packagedata[noexec] = "1"
396do_package_write_ipk[noexec] = "1"
397do_package_write_deb[noexec] = "1"
398do_package_write_rpm[noexec] = "1"
399
400addtask rootfs before do_build
401# Allow the kernel to be repacked with the initramfs and boot image file as a single file
402do_bundle_initramfs[depends] += "virtual/kernel:do_bundle_initramfs"
403do_bundle_initramfs[nostamp] = "1"
404do_bundle_initramfs[noexec] = "1"
405do_bundle_initramfs () {
406 :
407}
408addtask bundle_initramfs after do_rootfs