blob: de1883f3f130f365481787498cc936bb461bc487 [file] [log] [blame]
Brad Bishop97cce002017-07-22 14:49:25 -04001# Base image class extension, inlined into every image.
2
Saqib Khan41723472017-09-22 10:21:30 -05003inherit image_version
Brad Bishop97cce002017-07-22 14:49:25 -04004
Brad Bishop19fc4f82017-08-04 23:38:54 -04005# Phosphor image types
6#
Brad Bishop3aa1ef62017-08-04 23:48:12 -04007# Phosphor OpenBMC supports a fixed partition mtd layout,
8# A dynamic mtd with ubi layout, and a tar file for use with
9# The reference BMC software update implementation.
Brad Bishop19fc4f82017-08-04 23:38:54 -040010
11# Image composition
Brad Bishop8623bbe2018-03-09 00:04:00 -050012FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin"
13FLASH_KERNEL_IMAGE_df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin"
14
Brad Bishop19fc4f82017-08-04 23:38:54 -040015IMAGE_BASETYPE ?= "squashfs-xz"
16OVERLAY_BASETYPE ?= "jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040017FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}"
18FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs"
Brad Bishop19fc4f82017-08-04 23:38:54 -040019
Brad Bishop02ee6ae2018-03-30 08:43:23 -040020IMAGE_TYPES += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040021
22IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}"
23IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}"
24IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040025IMAGE_TYPEDEP_mtd-ubi = "${FLASH_UBI_BASETYPE}"
26IMAGE_TYPEDEP_mtd-ubi-tar = "${FLASH_UBI_BASETYPE}"
Brad Bishop02ee6ae2018-03-30 08:43:23 -040027IMAGE_TYPES_MASKED += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040028
Brad Bishop3aa1ef62017-08-04 23:48:12 -040029# Flash characteristics in KB unless otherwise noted
Brad Bishop19fc4f82017-08-04 23:38:54 -040030FLASH_SIZE ?= "32768"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040031FLASH_PEB_SIZE ?= "64"
32# Flash page and overhead sizes in bytes
33FLASH_PAGE_SIZE ?= "1"
34FLASH_NOR_UBI_OVERHEAD ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040035
36# Fixed partition offsets
37FLASH_UBOOT_OFFSET ?= "0"
38FLASH_KERNEL_OFFSET ?= "512"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040039FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040040FLASH_ROFS_OFFSET ?= "4864"
41FLASH_RWFS_OFFSET ?= "28672"
42
Brad Bishop3aa1ef62017-08-04 23:48:12 -040043# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060044FLASH_UBI_RWFS_SIZE ?= "6144"
45FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040046
47python() {
48 # Compute rwfs LEB count and LEB size.
49 page_size = d.getVar('FLASH_PAGE_SIZE', True)
50 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
51 overhead_size = max(int(page_size), int(nor_overhead_size))
52 peb_size = d.getVar('FLASH_PEB_SIZE', True)
53 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
54 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
55
56 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
57 rwfs_size = int(rwfs_size) * 1024
58 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
59 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
60}
61
Brad Bishop19fc4f82017-08-04 23:38:54 -040062# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
63# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
64# reserved for the primary image (and setting them currently breaks the build).
65# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
66DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040067DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040068
69JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=rwfs.jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040070UBIFS_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 -040071
72FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040073FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
74FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040075
76mk_nor_image() {
77 image_dst="$1"
78 image_size_kb=$2
79 dd if=/dev/zero bs=1k count=$image_size_kb \
80 | tr '\000' '\377' > $image_dst
81}
82
83make_rwfs() {
84 type=$1
85 cmd=$2
86 shift
87 shift
88 opts="$@"
89
90 rm -f rwfs.$type
91 rm -rf $type
92 mkdir $type
93
94 $cmd $opts
95}
96
97do_generate_rwfs_static() {
98 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
99}
100do_generate_rwfs_static[dirs] = " ${S}/static"
101do_generate_rwfs_static[depends] += " \
102 mtd-utils-native:do_populate_sysroot \
103 "
104
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400105do_generate_rwfs_ubi() {
106 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
107}
108do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
109do_generate_rwfs_ubi[depends] += " \
110 mtd-utils-native:do_populate_sysroot \
111 "
112
113add_volume() {
114 config_file=$1
115 vol_id=$2
116 vol_type=$3
117 vol_name=$4
118 image=$5
119 vol_size=$6
120
121 echo \[$vol_name\] >> $config_file
122 echo mode=ubi >> $config_file
123 echo image=$image >> $config_file
124 echo vol_type=$vol_type >> $config_file
125 echo vol_name=$vol_name >> $config_file
126 echo vol_id=$vol_id >> $config_file
127 if [ ! -z $vol_size ]; then
128 echo vol_size=$vol_size >> $config_file
129 fi
130}
131
Saqib Khan41723472017-09-22 10:21:30 -0500132python do_generate_ubi() {
133 version_id = do_get_versionID(d)
134 d.setVar('VERSION_ID', version_id)
135 bb.build.exec_func("do_make_ubi", d)
136}
137do_generate_ubi[dirs] = "${S}/ubi"
138do_generate_ubi[depends] += " \
139 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
140 virtual/kernel:do_deploy \
141 u-boot:do_populate_sysroot \
142 mtd-utils-native:do_populate_sysroot \
143 "
144
145do_make_ubi() {
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400146 cfg=ubinize-${IMAGE_NAME}.cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400147 rm -f $cfg ubi-img
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400148 # Construct the ubinize config file
Saqib Khan41723472017-09-22 10:21:30 -0500149 add_volume $cfg 0 static kernel-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400150 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
151
Saqib Khan41723472017-09-22 10:21:30 -0500152 add_volume $cfg 1 static rofs-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400153 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
154
155 add_volume $cfg 2 dynamic rwfs rwfs.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE}
156
157 # Build the ubi partition image
158 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
159
160 # Concatenate the uboot and ubi partitions
161 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
162 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
163 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
164 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
165 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
166 if=ubi-img \
167 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
168
169 cd ${IMGDEPLOYDIR}
170 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
171}
Saqib Khan41723472017-09-22 10:21:30 -0500172do_make_ubi[dirs] = "${S}/ubi"
173do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400174 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
175 virtual/kernel:do_deploy \
176 u-boot:do_populate_sysroot \
177 mtd-utils-native:do_populate_sysroot \
178 "
179
Brad Bishop19fc4f82017-08-04 23:38:54 -0400180do_generate_static() {
181 # Assemble the flash image
182 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
183 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
184 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
185 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
186
187 dd bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} \
188 if=${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} \
189 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
190
191 dd bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} \
192 if=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} \
193 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
194
195 dd bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} \
196 if=rwfs.${OVERLAY_BASETYPE} \
197 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
198 # File needed for generating non-standard legacy links below
199 cp rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/rwfs.${OVERLAY_BASETYPE}
200
201 cd ${IMGDEPLOYDIR}
202 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
203
204 # Maintain non-standard legacy links
205 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
206 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
207 ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
208 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
209 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
210 ln -sf rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
211}
212do_generate_static[dirs] = "${S}/static"
213do_generate_static[depends] += " \
214 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
215 virtual/kernel:do_deploy \
216 u-boot:do_populate_sysroot \
217 "
218
219do_generate_static_alltar() {
220 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
221 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar image-bmc
222
223 cd ${IMGDEPLOYDIR}
224
225 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
226 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
227
228 # Maintain non-standard legacy link.
229 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
230 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
231}
232do_generate_static_alltar[vardepsexclude] = "DATETIME"
233do_generate_static_alltar[dirs] = "${S}/static"
234
Brad Bishopde659382018-03-30 01:46:16 -0400235make_image_links() {
Brad Bishop19fc4f82017-08-04 23:38:54 -0400236 rwfs=$1
237 rofs=$2
Brad Bishop19fc4f82017-08-04 23:38:54 -0400238 shift
239 shift
Brad Bishop19fc4f82017-08-04 23:38:54 -0400240
Brad Bishopde659382018-03-30 01:46:16 -0400241 # Create some links to help make the tar archive in the format
242 # expected by phosphor-bmc-code-mgmt.
Brad Bishop19fc4f82017-08-04 23:38:54 -0400243 ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
244 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
245 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
246 ln -sf rwfs.$rwfs image-rwfs
Brad Bishopde659382018-03-30 01:46:16 -0400247}
248
249make_tar_of_images() {
250 type=$1
251 shift
252 extra_files="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400253
254 # Create the tar archive
255 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
256 image-u-boot image-kernel image-rofs image-rwfs $extra_files
257
258 cd ${IMGDEPLOYDIR}
259 ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
260}
261
262do_generate_static_tar() {
Brad Bishopde659382018-03-30 01:46:16 -0400263 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
264 make_tar_of_images static
Brad Bishop19fc4f82017-08-04 23:38:54 -0400265
266 # Maintain non-standard legacy link.
267 cd ${IMGDEPLOYDIR}
268 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
269}
270do_generate_static_tar[dirs] = " ${S}/static"
271do_generate_static_tar[depends] += " \
272 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
273 virtual/kernel:do_deploy \
274 u-boot:do_populate_sysroot \
275 "
276do_generate_static_tar[vardepsexclude] = "DATETIME"
277
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400278do_generate_ubi_tar() {
279 ln -sf ${S}/MANIFEST MANIFEST
Brad Bishopde659382018-03-30 01:46:16 -0400280 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE}
281 make_tar_of_images ubi MANIFEST
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400282}
283do_generate_ubi_tar[dirs] = " ${S}/ubi"
284do_generate_ubi_tar[depends] += " \
285 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
286 virtual/kernel:do_deploy \
287 u-boot:do_populate_sysroot \
288 "
289
Brad Bishop19fc4f82017-08-04 23:38:54 -0400290python do_generate_phosphor_manifest() {
Saqib Khan41723472017-09-22 10:21:30 -0500291 version = do_get_version(d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400292 with open('MANIFEST', 'w') as fd:
293 fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
294 fd.write('version={}\n'.format(version.strip('"')))
295}
296do_generate_phosphor_manifest[dirs] = "${S}"
297do_generate_phosphor_manifest[depends] += " \
298 os-release:do_populate_sysroot \
299 "
300
301addtask generate_phosphor_manifest after do_rootfs
302addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400303addtask generate_rwfs_ubi after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400304
305python() {
306 types = d.getVar('IMAGE_FSTYPES', True).split()
307
308 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
309 bb.build.addtask(
310 'do_generate_static',
311 'do_image_complete',
312 'do_generate_rwfs_static', d)
313 if 'mtd-static-alltar' in types:
314 bb.build.addtask(
315 'do_generate_static_alltar',
316 'do_image_complete',
317 'do_generate_static', d)
318 if 'mtd-static-tar' in types:
319 bb.build.addtask(
320 'do_generate_static_tar',
321 'do_image_complete',
322 'do_generate_rwfs_static', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400323
324 if 'mtd-ubi' in types:
325 bb.build.addtask(
326 'do_generate_ubi',
327 'do_image_complete',
328 'do_generate_rwfs_ubi', d)
329 if 'mtd-ubi-tar' in types:
330 bb.build.addtask(
331 'do_generate_ubi_tar',
332 'do_image_complete',
333 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400334}