merge of '178eac00dc5aa8338d42e8e203633bec7817bbf6'
[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
37 #
38 # Get a list of files containing tables of devices to be created.
39 # * IMAGE_DEVICE_TABLE is the old name to an absolute path to a device table file
40 # * IMAGE_DEVICE_TABLES is a new name for a file, or list of files, searched
41 #   for in the BBPATH
42 # If neither are specified then the default name of files/device_table-minimal.txt
43 # is searched for in the BBPATH (same as the old version.)
44 #
45 def get_devtable_list(d):
46         import bb
47         devtable = bb.data.getVar('IMAGE_DEVICE_TABLE', d, 1)
48         if devtable != None:
49                 return devtable
50         str = ""
51         devtables = bb.data.getVar('IMAGE_DEVICE_TABLES', d, 1)
52         if devtables == None:
53                 devtables = 'files/device_table-minimal.txt'
54         for devtable in devtables.split():
55                 str += " %s" % bb.which(bb.data.getVar('BBPATH', d, 1), devtable)
56         return str
57
58 IMAGE_POSTPROCESS_COMMAND ?= ""
59 MACHINE_POSTPROCESS_COMMAND ?= ""
60 ROOTFS_POSTPROCESS_COMMAND ?= ""
61
62 # some default locales
63 IMAGE_LINGUAS ?= "de-de fr-fr en-gb"
64
65 LINGUAS_INSTALL = "${@" ".join(map(lambda s: "locale-base-%s" % s, bb.data.getVar('IMAGE_LINGUAS', d, 1).split()))}"
66
67 do_rootfs[nostamp] = "1"
68 do_rootfs[dirs] = "${TOPDIR}"
69 do_build[nostamp] = "1"
70
71 # Must call real_do_rootfs() from inside here, rather than as a separate
72 # task, so that we have a single fakeroot context for the whole process.
73 fakeroot do_rootfs () {
74         set -x
75         rm -rf ${IMAGE_ROOTFS}
76         mkdir -p ${IMAGE_ROOTFS}
77
78         if [ "${USE_DEVFS}" != "1" ]; then
79                 for devtable in ${@get_devtable_list(d)}; do
80                         makedevs -r ${IMAGE_ROOTFS} -D $devtable
81                 done
82         fi
83
84         rootfs_${IMAGE_PKGTYPE}_do_rootfs
85
86         insert_feed_uris        
87
88         ${IMAGE_PREPROCESS_COMMAND}
89                 
90         export TOPDIR=${TOPDIR}
91         export DISTRO=${USERDISTRO}
92         export MACHINE=${MACHINE}
93
94         for type in ${IMAGE_FSTYPES}; do
95                 if test -z "$FAKEROOTKEY"; then
96                         fakeroot -i ${TMPDIR}/fakedb.image ${PYTHON} `which bbimage` -t $type -e ${FILE}
97                 else
98                         ${PYTHON} `which bbimage` -n "${IMAGE_NAME}" -t "$type" -e "${FILE}"
99                 fi
100
101                 cd ${DEPLOY_DIR_IMAGE}/
102                 rm -f ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.$type
103                 ln -s ${IMAGE_NAME}.rootfs.$type ${DEPLOY_DIR_IMAGE}/${IMAGE_LINK_NAME}.$type
104         done
105
106         ${IMAGE_POSTPROCESS_COMMAND}
107         
108         ${MACHINE_POSTPROCESS_COMMAND}
109 }
110
111 do_deploy_to[nostamp] = "1"
112 do_deploy_to () {
113         # A standalone task to deploy built image to the location specified
114         # by DEPLOY_TO variable (likely passed via environment).
115         # Assumes ${IMAGE_FSTYPES} is a single value!
116         cp "${DEPLOY_DIR_IMAGE}/${IMAGE_NAME}.rootfs.${IMAGE_FSTYPES}" ${DEPLOY_TO}
117 }
118
119 insert_feed_uris () {
120         
121         echo "Building feeds for [${DISTRO}].."
122                 
123         for line in ${FEED_URIS}
124         do
125                 # strip leading and trailing spaces/tabs, then split into name and uri
126                 line_clean="`echo "$line"|sed 's/^[ \t]*//;s/[ \t]*$//'`"
127                 feed_name="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\1/p'`"
128                 feed_uri="`echo "$line_clean" | sed -n 's/\(.*\)##\(.*\)/\2/p'`"                                        
129                 
130                 echo "Added $feed_name feed with URL $feed_uri"
131                 
132                 # insert new feed-sources
133                 echo "src/gz $feed_name $feed_uri" >> ${IMAGE_ROOTFS}/etc/opkg/${feed_name}-feed.conf
134         done                    
135
136         # Allow to use package deploy directory contents as quick devel-testing
137         # feed. This creates individual feed configs for each arch subdir of those
138         # specified as compatible for the current machine.
139         # NOTE: Development-helper feature, NOT a full-fledged feed.
140         if [ -n "${FEED_DEPLOYDIR_BASE_URI}" ]; then
141             for arch in ${PACKAGE_ARCHS}
142             do
143                 echo "src/gz local-$arch ${FEED_DEPLOYDIR_BASE_URI}/$arch" >> ${IMAGE_ROOTFS}/etc/opkg/local-$arch-feed.conf
144             done
145         fi
146 }
147
148 log_check() {
149         set +x
150         for target in $*
151         do
152                 lf_path="${WORKDIR}/temp/log.do_$target.${PID}"
153                 
154                 echo "log_check: Using $lf_path as logfile"
155                 
156                 if test -e "$lf_path"
157                 then
158                         rootfs_${IMAGE_PKGTYPE}_log_check $target $lf_path
159                 else
160                         echo "Cannot find logfile [$lf_path]"
161                 fi
162                 echo "Logfile is clean"         
163         done
164
165         set -x
166 }
167
168 # set '*' as the rootpassword so the images
169 # can decide if they want it or not
170
171 zap_root_password () {
172         sed 's%^root:[^:]*:%root:*:%' < ${IMAGE_ROOTFS}/etc/passwd >${IMAGE_ROOTFS}/etc/passwd.new
173         mv ${IMAGE_ROOTFS}/etc/passwd.new ${IMAGE_ROOTFS}/etc/passwd    
174
175
176 create_etc_timestamp() {
177         date +%2m%2d%2H%2M%Y >${IMAGE_ROOTFS}/etc/timestamp
178 }
179
180 # Turn any symbolic /sbin/init link into a file
181 remove_init_link () {
182         if [ -h ${IMAGE_ROOTFS}/sbin/init ]; then
183                 LINKFILE=${IMAGE_ROOTFS}`readlink ${IMAGE_ROOTFS}/sbin/init`
184                 rm ${IMAGE_ROOTFS}/sbin/init
185                 cp $LINKFILE ${IMAGE_ROOTFS}/sbin/init
186         fi
187 }
188
189 make_zimage_symlink_relative () {
190         if [ -L ${IMAGE_ROOTFS}/boot/zImage ]; then
191                 (cd ${IMAGE_ROOTFS}/boot/ && for i in `ls zImage-* | sort`; do ln -sf $i zImage; done)
192         fi
193 }
194
195 # Make login manager(s) enable automatic login.
196 # Useful for devices where we do not want to log in at all (e.g. phones)
197 set_image_autologin () {
198         sed -i 's%^AUTOLOGIN=\"false"%AUTOLOGIN="true"%g' ${IMAGE_ROOTFS}/etc/sysconfig/gpelogin
199 }
200
201 # Can be use to create /etc/timestamp during image construction to give a reasonably 
202 # sane default time setting
203 rootfs_update_timestamp () {
204         date "+%m%d%H%M%Y" >${IMAGE_ROOTFS}/etc/timestamp
205 }
206
207 # export the zap_root_password, create_etc_timestamp and remote_init_link
208 EXPORT_FUNCTIONS zap_root_password create_etc_timestamp remove_init_link do_rootfs make_zimage_symlink_relative set_image_autologin rootfs_update_timestamp
209
210 addtask rootfs before do_build after do_install
211 addtask deploy_to after do_rootfs