image.bbclass 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. inherit rootfs_${IMAGE_PKGTYPE}
  2. IMAGETEST ?= "dummy"
  3. inherit imagetest-${IMAGETEST}
  4. LICENSE = "MIT"
  5. PACKAGES = ""
  6. RDEPENDS += "${IMAGE_INSTALL}"
  7. INHIBIT_DEFAULT_DEPS = "1"
  8. # "export IMAGE_BASENAME" not supported at this time
  9. IMAGE_BASENAME[export] = "1"
  10. export PACKAGE_INSTALL ?= "${IMAGE_INSTALL}"
  11. PACKAGE_INSTALL_ATTEMPTONLY ?= ""
  12. # Images are generally built explicitly, do not need to be part of world.
  13. EXCLUDE_FROM_WORLD = "1"
  14. USE_DEVFS ?= "0"
  15. PID = "${@os.getpid()}"
  16. PACKAGE_ARCH = "${MACHINE_ARCH}"
  17. LDCONFIGDEPEND = "ldconfig-native:do_populate_sysroot"
  18. LDCONFIGDEPEND_linux-uclibc = ""
  19. LDCONFIGDEPEND_linux-uclibceabi = ""
  20. do_rootfs[depends] += "makedevs-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot ${LDCONFIGDEPEND}"
  21. do_rootfs[depends] += "virtual/update-alternatives-native:do_populate_sysroot update-rc.d-native:do_populate_sysroot"
  22. python () {
  23. deps = bb.data.getVarFlag('do_rootfs', 'depends', d) or ""
  24. for type in (bb.data.getVar('IMAGE_FSTYPES', d, True) or "").split():
  25. for dep in ((bb.data.getVar('IMAGE_DEPENDS_%s' % type, d) or "").split() or []):
  26. deps += " %s:do_populate_sysroot" % dep
  27. for dep in (bb.data.getVar('EXTRA_IMAGEDEPENDS', d, True) or "").split():
  28. deps += " %s:do_populate_sysroot" % dep
  29. bb.data.setVarFlag('do_rootfs', 'depends', deps, d)
  30. # If we don't do this we try and run the mapping hooks while parsing which is slow
  31. # bitbake should really provide something to let us know this...
  32. if bb.data.getVar('BB_WORKERCONTEXT', d, True) is not None:
  33. runtime_mapping_rename("PACKAGE_INSTALL", d)
  34. runtime_mapping_rename("PACKAGE_INSTALL_ATTEMPTONLY", d)
  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. devtable = bb.data.getVar('IMAGE_DEVICE_TABLE', d, 1)
  46. if devtable != None:
  47. return devtable
  48. str = ""
  49. devtables = bb.data.getVar('IMAGE_DEVICE_TABLES', d, 1)
  50. if devtables == None:
  51. devtables = 'files/device_table-minimal.txt'
  52. for devtable in devtables.split():
  53. str += " %s" % bb.which(bb.data.getVar('BBPATH', d, 1), devtable)
  54. return str
  55. inherit image_types
  56. IMAGE_POSTPROCESS_COMMAND ?= ""
  57. MACHINE_POSTPROCESS_COMMAND ?= ""
  58. ROOTFS_POSTPROCESS_COMMAND ?= ""
  59. # some default locales
  60. IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
  61. LINGUAS_INSTALL = "${@" ".join(map(lambda s: "locale-base-%s" % s, bb.data.getVar('IMAGE_LINGUAS', d, 1).split()))}"
  62. do_rootfs[nostamp] = "1"
  63. do_rootfs[dirs] = "${TOPDIR}"
  64. do_rootfs[lockfiles] += "${IMAGE_ROOTFS}.lock"
  65. do_build[nostamp] = "1"
  66. # Must call real_do_rootfs() from inside here, rather than as a separate
  67. # task, so that we have a single fakeroot context for the whole process.
  68. fakeroot do_rootfs () {
  69. #set -x
  70. rm -rf ${IMAGE_ROOTFS}
  71. mkdir -p ${IMAGE_ROOTFS}
  72. mkdir -p ${DEPLOY_DIR_IMAGE}
  73. if [ "${USE_DEVFS}" != "1" ]; then
  74. for devtable in ${@get_devtable_list(d)}; do
  75. makedevs -r ${IMAGE_ROOTFS} -D $devtable
  76. done
  77. fi
  78. rootfs_${IMAGE_PKGTYPE}_do_rootfs
  79. insert_feed_uris
  80. if [ "x${LDCONFIGDEPEND}" != "x" ]; then
  81. # Run ldconfig on the image to create a valid cache
  82. # (new format for cross arch compatibility)
  83. echo executing: ldconfig -r ${IMAGE_ROOTFS} -c new -v
  84. ldconfig -r ${IMAGE_ROOTFS} -c new -v
  85. fi
  86. # (re)create kernel modules dependencies
  87. # This part is done by kernel-module-* postinstall scripts but if image do
  88. # not contains modules at all there are few moments in boot sequence with
  89. # "unable to open modules.dep" message.
  90. if [ -e ${STAGING_KERNEL_DIR}/kernel-abiversion ]; then
  91. KERNEL_VERSION=`cat ${STAGING_KERNEL_DIR}/kernel-abiversion`
  92. mkdir -p ${IMAGE_ROOTFS}/lib/modules/$KERNEL_VERSION
  93. ${TARGET_SYS}-depmod-2.6 -a -b ${IMAGE_ROOTFS} -F ${STAGING_KERNEL_DIR}/System.map-$KERNEL_VERSION $KERNEL_VERSION
  94. fi
  95. ${IMAGE_PREPROCESS_COMMAND}
  96. ${@get_imagecmds(d)}
  97. ${IMAGE_POSTPROCESS_COMMAND}
  98. ${MACHINE_POSTPROCESS_COMMAND}
  99. }
  100. insert_feed_uris () {
  101. echo "Building feeds for [${DISTRO}].."
  102. for line in ${FEED_URIS}
  103. do
  104. # strip leading and trailing spaces/tabs, then split into name and uri
  105. line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
  106. feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
  107. feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"
  108. echo "Added $feed_name feed with URL $feed_uri"
  109. # insert new feed-sources
  110. echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
  111. done
  112. }
  113. log_check() {
  114. for target in $*
  115. do
  116. lf_path="${WORKDIR}/temp/log.do_$target.${PID}"
  117. echo "log_check: Using $lf_path as logfile"
  118. if test -e "$lf_path"
  119. then
  120. ${IMAGE_PKGTYPE}_log_check $target $lf_path
  121. else
  122. echo "Cannot find logfile [$lf_path]"
  123. fi
  124. echo "Logfile is clean"
  125. done
  126. }
  127. # set '*' as the rootpassword so the images
  128. # can decide if they want it or not
  129. zap_root_password () {
  130. sed 's%^root:[^:]*:%root:*:%' < ${IMAGE_ROOTFS}/etc/passwd >${IMAGE_ROOTFS}/etc/passwd.new
  131. mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd
  132. }
  133. # Turn any symbolic /sbin/init link into a file
  134. remove_init_link () {
  135. if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
  136. LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
  137. rm ${IMAGE_ROOTFS}/sbin/init
  138. cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
  139. fi
  140. }
  141. make_zimage_symlink_relative () {
  142. if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
  143. (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
  144. fi
  145. }
  146. write_image_manifest () {
  147. rootfs_${IMAGE_PKGTYPE}_write_manifest
  148. rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.manifest
  149. ln -s ${IMAGE_NAME}.rootfs.manifest ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.manifest
  150. }
  151. # Make login manager(s) enable automatic login.
  152. # Useful for devices where we do not want to log in at all (e.g. phones)
  153. set_image_autologin () {
  154. sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
  155. }
  156. # Can be use to create /etc/timestamp during image construction to give a reasonably
  157. # sane default time setting
  158. rootfs_update_timestamp () {
  159. date -u +%2m%2d%2H%2M%4Y >${IMAGE_ROOTFS}/etc/timestamp
  160. }
  161. # Prevent X from being started
  162. rootfs_no_x_startup () {
  163. if [ -f ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm ]; then
  164. chmod a-x ${IMAGE_ROOTFS}/etc/init.d/xserver-nodm
  165. fi
  166. }
  167. rootfs_trim_schemas () {
  168. for schema in ${IMAGE_ROOTFS}/etc/gconf/schemas/*.schemas
  169. do
  170. # Need this in case no files exist
  171. if [ -e $schema ]; then
  172. oe-trim-schemas $schema > $schema.new
  173. mv $schema.new $schema
  174. fi
  175. done
  176. }
  177. # export the zap_root_password, and remote_init_link
  178. EXPORT_FUNCTIONS zap_root_password remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp rootfs_no_x_startup
  179. addtask rootfs before do_build after do_install