blob: 78ff846f629c2d1721e263f9bf02bb0839b7d8a4 [file] [log] [blame]
Brad Bishop97cce002017-07-22 14:49:25 -04001# Base image class extension, inlined into every image.
2
3def build_uboot(d):
4 fstypes = d.getVar('IMAGE_FSTYPES', True).split()
5 if any([x.endswith('u-boot') for x in fstypes]):
6 return 'image_types_uboot'
7 return ''
8
9
10# Inherit u-boot classes if legacy uboot images are in use.
11IMAGE_TYPE_uboot = '${@build_uboot(d)}'
12inherit ${IMAGE_TYPE_uboot}
Saqib Khan41723472017-09-22 10:21:30 -050013inherit image_version
Brad Bishop97cce002017-07-22 14:49:25 -040014
Brad Bishop19fc4f82017-08-04 23:38:54 -040015# Phosphor image types
16#
Brad Bishop3aa1ef62017-08-04 23:48:12 -040017# Phosphor OpenBMC supports a fixed partition mtd layout,
18# A dynamic mtd with ubi layout, and a tar file for use with
19# The reference BMC software update implementation.
Brad Bishop19fc4f82017-08-04 23:38:54 -040020
21# Image composition
Brad Bishop8623bbe2018-03-09 00:04:00 -050022FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin"
23FLASH_KERNEL_IMAGE_df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin"
24
Brad Bishop19fc4f82017-08-04 23:38:54 -040025IMAGE_BASETYPE ?= "squashfs-xz"
26OVERLAY_BASETYPE ?= "jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040027FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}"
28FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs"
Brad Bishop19fc4f82017-08-04 23:38:54 -040029
Brad Bishop3aa1ef62017-08-04 23:48:12 -040030IMAGE_TYPES += "overlay mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040031
Brad Bishop3aa1ef62017-08-04 23:48:12 -040032IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040033IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}"
34IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}"
35IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040036IMAGE_TYPEDEP_mtd-ubi = "${FLASH_UBI_BASETYPE}"
37IMAGE_TYPEDEP_mtd-ubi-tar = "${FLASH_UBI_BASETYPE}"
38IMAGE_TYPES_MASKED += "overlay mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040039
Brad Bishop3aa1ef62017-08-04 23:48:12 -040040# Flash characteristics in KB unless otherwise noted
Brad Bishop19fc4f82017-08-04 23:38:54 -040041FLASH_SIZE ?= "32768"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040042FLASH_PEB_SIZE ?= "64"
43# Flash page and overhead sizes in bytes
44FLASH_PAGE_SIZE ?= "1"
45FLASH_NOR_UBI_OVERHEAD ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040046
47# Fixed partition offsets
48FLASH_UBOOT_OFFSET ?= "0"
49FLASH_KERNEL_OFFSET ?= "512"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040050FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040051FLASH_ROFS_OFFSET ?= "4864"
52FLASH_RWFS_OFFSET ?= "28672"
53
Brad Bishop3aa1ef62017-08-04 23:48:12 -040054# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060055FLASH_UBI_RWFS_SIZE ?= "6144"
56FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040057
58python() {
59 # Compute rwfs LEB count and LEB size.
60 page_size = d.getVar('FLASH_PAGE_SIZE', True)
61 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
62 overhead_size = max(int(page_size), int(nor_overhead_size))
63 peb_size = d.getVar('FLASH_PEB_SIZE', True)
64 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
65 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
66
67 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
68 rwfs_size = int(rwfs_size) * 1024
69 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
70 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
71}
72
Brad Bishop19fc4f82017-08-04 23:38:54 -040073# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
74# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
75# reserved for the primary image (and setting them currently breaks the build).
76# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
77DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040078DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040079
80JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=rwfs.jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040081UBIFS_RWFS_CMD = "mkfs.ubifs -r ubifs -c ${FLASH_UBI_RWFS_LEBS} -m ${FLASH_PAGE_SIZE} -e ${FLASH_LEB_SIZE} rwfs.ubifs"
Brad Bishop19fc4f82017-08-04 23:38:54 -040082
83FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040084FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
85FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040086
87mk_nor_image() {
88 image_dst="$1"
89 image_size_kb=$2
90 dd if=/dev/zero bs=1k count=$image_size_kb \
91 | tr '\000' '\377' > $image_dst
92}
93
94make_rwfs() {
95 type=$1
96 cmd=$2
97 shift
98 shift
99 opts="$@"
100
101 rm -f rwfs.$type
102 rm -rf $type
103 mkdir $type
104
105 $cmd $opts
106}
107
108do_generate_rwfs_static() {
109 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
110}
111do_generate_rwfs_static[dirs] = " ${S}/static"
112do_generate_rwfs_static[depends] += " \
113 mtd-utils-native:do_populate_sysroot \
114 "
115
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400116do_generate_rwfs_ubi() {
117 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
118}
119do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
120do_generate_rwfs_ubi[depends] += " \
121 mtd-utils-native:do_populate_sysroot \
122 "
123
124add_volume() {
125 config_file=$1
126 vol_id=$2
127 vol_type=$3
128 vol_name=$4
129 image=$5
130 vol_size=$6
131
132 echo \[$vol_name\] >> $config_file
133 echo mode=ubi >> $config_file
134 echo image=$image >> $config_file
135 echo vol_type=$vol_type >> $config_file
136 echo vol_name=$vol_name >> $config_file
137 echo vol_id=$vol_id >> $config_file
138 if [ ! -z $vol_size ]; then
139 echo vol_size=$vol_size >> $config_file
140 fi
141}
142
Saqib Khan41723472017-09-22 10:21:30 -0500143python do_generate_ubi() {
144 version_id = do_get_versionID(d)
145 d.setVar('VERSION_ID', version_id)
146 bb.build.exec_func("do_make_ubi", d)
147}
148do_generate_ubi[dirs] = "${S}/ubi"
149do_generate_ubi[depends] += " \
150 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
151 virtual/kernel:do_deploy \
152 u-boot:do_populate_sysroot \
153 mtd-utils-native:do_populate_sysroot \
154 "
155
156do_make_ubi() {
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400157 cfg=ubinize-${IMAGE_NAME}.cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400158 rm -f $cfg ubi-img
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400159 # Construct the ubinize config file
Saqib Khan41723472017-09-22 10:21:30 -0500160 add_volume $cfg 0 static kernel-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400161 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
162
Saqib Khan41723472017-09-22 10:21:30 -0500163 add_volume $cfg 1 static rofs-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400164 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
165
166 add_volume $cfg 2 dynamic rwfs rwfs.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE}
167
168 # Build the ubi partition image
169 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
170
171 # Concatenate the uboot and ubi partitions
172 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
173 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
174 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
175 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
176 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
177 if=ubi-img \
178 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
179
180 cd ${IMGDEPLOYDIR}
181 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
182}
Saqib Khan41723472017-09-22 10:21:30 -0500183do_make_ubi[dirs] = "${S}/ubi"
184do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400185 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
186 virtual/kernel:do_deploy \
187 u-boot:do_populate_sysroot \
188 mtd-utils-native:do_populate_sysroot \
189 "
190
Brad Bishop19fc4f82017-08-04 23:38:54 -0400191do_generate_static() {
192 # Assemble the flash image
193 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
194 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
195 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
196 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
197
198 dd bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} \
199 if=${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} \
200 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
201
202 dd bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} \
203 if=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} \
204 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
205
206 dd bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} \
207 if=rwfs.${OVERLAY_BASETYPE} \
208 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
209 # File needed for generating non-standard legacy links below
210 cp rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/rwfs.${OVERLAY_BASETYPE}
211
212 cd ${IMGDEPLOYDIR}
213 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
214
215 # Maintain non-standard legacy links
216 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
217 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
218 ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
219 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
220 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
221 ln -sf rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
222}
223do_generate_static[dirs] = "${S}/static"
224do_generate_static[depends] += " \
225 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
226 virtual/kernel:do_deploy \
227 u-boot:do_populate_sysroot \
228 "
229
230do_generate_static_alltar() {
231 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
232 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar image-bmc
233
234 cd ${IMGDEPLOYDIR}
235
236 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
237 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
238
239 # Maintain non-standard legacy link.
240 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
241 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
242}
243do_generate_static_alltar[vardepsexclude] = "DATETIME"
244do_generate_static_alltar[dirs] = "${S}/static"
245
246make_tar_of_images() {
247 rwfs=$1
248 rofs=$2
249 type=$3
250 shift
251 shift
252 shift
253 extra_files="$@"
254
255 # Create some links to help make the tar archive
256 ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
257 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
258 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
259 ln -sf rwfs.$rwfs image-rwfs
260
261 # Create the tar archive
262 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
263 image-u-boot image-kernel image-rofs image-rwfs $extra_files
264
265 cd ${IMGDEPLOYDIR}
266 ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
267}
268
269do_generate_static_tar() {
270 make_tar_of_images ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE} static
271
272 # Maintain non-standard legacy link.
273 cd ${IMGDEPLOYDIR}
274 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
275}
276do_generate_static_tar[dirs] = " ${S}/static"
277do_generate_static_tar[depends] += " \
278 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
279 virtual/kernel:do_deploy \
280 u-boot:do_populate_sysroot \
281 "
282do_generate_static_tar[vardepsexclude] = "DATETIME"
283
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400284do_generate_ubi_tar() {
285 ln -sf ${S}/MANIFEST MANIFEST
286 make_tar_of_images ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE} ubi MANIFEST
287}
288do_generate_ubi_tar[dirs] = " ${S}/ubi"
289do_generate_ubi_tar[depends] += " \
290 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
291 virtual/kernel:do_deploy \
292 u-boot:do_populate_sysroot \
293 "
294
Brad Bishop19fc4f82017-08-04 23:38:54 -0400295python do_generate_phosphor_manifest() {
Saqib Khan41723472017-09-22 10:21:30 -0500296 version = do_get_version(d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400297 with open('MANIFEST', 'w') as fd:
298 fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
299 fd.write('version={}\n'.format(version.strip('"')))
300}
301do_generate_phosphor_manifest[dirs] = "${S}"
302do_generate_phosphor_manifest[depends] += " \
303 os-release:do_populate_sysroot \
304 "
305
306addtask generate_phosphor_manifest after do_rootfs
307addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400308addtask generate_rwfs_ubi after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400309
310python() {
311 types = d.getVar('IMAGE_FSTYPES', True).split()
312
313 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
314 bb.build.addtask(
315 'do_generate_static',
316 'do_image_complete',
317 'do_generate_rwfs_static', d)
318 if 'mtd-static-alltar' in types:
319 bb.build.addtask(
320 'do_generate_static_alltar',
321 'do_image_complete',
322 'do_generate_static', d)
323 if 'mtd-static-tar' in types:
324 bb.build.addtask(
325 'do_generate_static_tar',
326 'do_image_complete',
327 'do_generate_rwfs_static', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400328
329 if 'mtd-ubi' in types:
330 bb.build.addtask(
331 'do_generate_ubi',
332 'do_image_complete',
333 'do_generate_rwfs_ubi', d)
334 if 'mtd-ubi-tar' in types:
335 bb.build.addtask(
336 'do_generate_ubi_tar',
337 'do_image_complete',
338 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400339}