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