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