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