blob: 8c1599c5b4ff3c63e3aa7c940778390ece65b3dc [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 Bishop3aa1ef62017-08-04 23:48:12 -040020IMAGE_TYPES += "overlay mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040021
Brad Bishop3aa1ef62017-08-04 23:48:12 -040022IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040023IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}"
24IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}"
25IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040026IMAGE_TYPEDEP_mtd-ubi = "${FLASH_UBI_BASETYPE}"
27IMAGE_TYPEDEP_mtd-ubi-tar = "${FLASH_UBI_BASETYPE}"
28IMAGE_TYPES_MASKED += "overlay mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar"
Brad Bishop19fc4f82017-08-04 23:38:54 -040029
Brad Bishop3aa1ef62017-08-04 23:48:12 -040030# Flash characteristics in KB unless otherwise noted
Brad Bishop19fc4f82017-08-04 23:38:54 -040031FLASH_SIZE ?= "32768"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040032FLASH_PEB_SIZE ?= "64"
33# Flash page and overhead sizes in bytes
34FLASH_PAGE_SIZE ?= "1"
35FLASH_NOR_UBI_OVERHEAD ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040036
37# Fixed partition offsets
38FLASH_UBOOT_OFFSET ?= "0"
39FLASH_KERNEL_OFFSET ?= "512"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040040FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040041FLASH_ROFS_OFFSET ?= "4864"
42FLASH_RWFS_OFFSET ?= "28672"
43
Brad Bishop3aa1ef62017-08-04 23:48:12 -040044# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060045FLASH_UBI_RWFS_SIZE ?= "6144"
46FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040047
48python() {
49 # Compute rwfs LEB count and LEB size.
50 page_size = d.getVar('FLASH_PAGE_SIZE', True)
51 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
52 overhead_size = max(int(page_size), int(nor_overhead_size))
53 peb_size = d.getVar('FLASH_PEB_SIZE', True)
54 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
55 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
56
57 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
58 rwfs_size = int(rwfs_size) * 1024
59 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
60 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
61}
62
Brad Bishop19fc4f82017-08-04 23:38:54 -040063# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
64# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
65# reserved for the primary image (and setting them currently breaks the build).
66# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
67DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040068DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040069
70JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=rwfs.jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040071UBIFS_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 -040072
73FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040074FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
75FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040076
77mk_nor_image() {
78 image_dst="$1"
79 image_size_kb=$2
80 dd if=/dev/zero bs=1k count=$image_size_kb \
81 | tr '\000' '\377' > $image_dst
82}
83
84make_rwfs() {
85 type=$1
86 cmd=$2
87 shift
88 shift
89 opts="$@"
90
91 rm -f rwfs.$type
92 rm -rf $type
93 mkdir $type
94
95 $cmd $opts
96}
97
98do_generate_rwfs_static() {
99 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
100}
101do_generate_rwfs_static[dirs] = " ${S}/static"
102do_generate_rwfs_static[depends] += " \
103 mtd-utils-native:do_populate_sysroot \
104 "
105
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400106do_generate_rwfs_ubi() {
107 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
108}
109do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
110do_generate_rwfs_ubi[depends] += " \
111 mtd-utils-native:do_populate_sysroot \
112 "
113
114add_volume() {
115 config_file=$1
116 vol_id=$2
117 vol_type=$3
118 vol_name=$4
119 image=$5
120 vol_size=$6
121
122 echo \[$vol_name\] >> $config_file
123 echo mode=ubi >> $config_file
124 echo image=$image >> $config_file
125 echo vol_type=$vol_type >> $config_file
126 echo vol_name=$vol_name >> $config_file
127 echo vol_id=$vol_id >> $config_file
128 if [ ! -z $vol_size ]; then
129 echo vol_size=$vol_size >> $config_file
130 fi
131}
132
Saqib Khan41723472017-09-22 10:21:30 -0500133python do_generate_ubi() {
134 version_id = do_get_versionID(d)
135 d.setVar('VERSION_ID', version_id)
136 bb.build.exec_func("do_make_ubi", d)
137}
138do_generate_ubi[dirs] = "${S}/ubi"
139do_generate_ubi[depends] += " \
140 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
141 virtual/kernel:do_deploy \
142 u-boot:do_populate_sysroot \
143 mtd-utils-native:do_populate_sysroot \
144 "
145
146do_make_ubi() {
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400147 cfg=ubinize-${IMAGE_NAME}.cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400148 rm -f $cfg ubi-img
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400149 # Construct the ubinize config file
Saqib Khan41723472017-09-22 10:21:30 -0500150 add_volume $cfg 0 static kernel-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400151 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
152
Saqib Khan41723472017-09-22 10:21:30 -0500153 add_volume $cfg 1 static rofs-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400154 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
155
156 add_volume $cfg 2 dynamic rwfs rwfs.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE}
157
158 # Build the ubi partition image
159 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
160
161 # Concatenate the uboot and ubi partitions
162 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
163 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
164 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
165 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
166 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
167 if=ubi-img \
168 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
169
170 cd ${IMGDEPLOYDIR}
171 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
172}
Saqib Khan41723472017-09-22 10:21:30 -0500173do_make_ubi[dirs] = "${S}/ubi"
174do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400175 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
176 virtual/kernel:do_deploy \
177 u-boot:do_populate_sysroot \
178 mtd-utils-native:do_populate_sysroot \
179 "
180
Brad Bishop19fc4f82017-08-04 23:38:54 -0400181do_generate_static() {
182 # Assemble the flash image
183 mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
184 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
185 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
186 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
187
188 dd bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} \
189 if=${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} \
190 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
191
192 dd bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} \
193 if=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} \
194 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
195
196 dd bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} \
197 if=rwfs.${OVERLAY_BASETYPE} \
198 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
199 # File needed for generating non-standard legacy links below
200 cp rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/rwfs.${OVERLAY_BASETYPE}
201
202 cd ${IMGDEPLOYDIR}
203 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
204
205 # Maintain non-standard legacy links
206 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
207 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
208 ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
209 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
210 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
211 ln -sf rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
212}
213do_generate_static[dirs] = "${S}/static"
214do_generate_static[depends] += " \
215 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
216 virtual/kernel:do_deploy \
217 u-boot:do_populate_sysroot \
218 "
219
220do_generate_static_alltar() {
221 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
222 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar image-bmc
223
224 cd ${IMGDEPLOYDIR}
225
226 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
227 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
228
229 # Maintain non-standard legacy link.
230 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
231 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
232}
233do_generate_static_alltar[vardepsexclude] = "DATETIME"
234do_generate_static_alltar[dirs] = "${S}/static"
235
Brad Bishopde659382018-03-30 01:46:16 -0400236make_image_links() {
Brad Bishop19fc4f82017-08-04 23:38:54 -0400237 rwfs=$1
238 rofs=$2
Brad Bishop19fc4f82017-08-04 23:38:54 -0400239 shift
240 shift
Brad Bishop19fc4f82017-08-04 23:38:54 -0400241
Brad Bishopde659382018-03-30 01:46:16 -0400242 # Create some links to help make the tar archive in the format
243 # expected by phosphor-bmc-code-mgmt.
Brad Bishop19fc4f82017-08-04 23:38:54 -0400244 ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
245 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
246 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
247 ln -sf rwfs.$rwfs image-rwfs
Brad Bishopde659382018-03-30 01:46:16 -0400248}
249
250make_tar_of_images() {
251 type=$1
252 shift
253 extra_files="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400254
255 # Create the tar archive
256 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
257 image-u-boot image-kernel image-rofs image-rwfs $extra_files
258
259 cd ${IMGDEPLOYDIR}
260 ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
261}
262
263do_generate_static_tar() {
Brad Bishopde659382018-03-30 01:46:16 -0400264 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
265 make_tar_of_images static
Brad Bishop19fc4f82017-08-04 23:38:54 -0400266
267 # Maintain non-standard legacy link.
268 cd ${IMGDEPLOYDIR}
269 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
270}
271do_generate_static_tar[dirs] = " ${S}/static"
272do_generate_static_tar[depends] += " \
273 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
274 virtual/kernel:do_deploy \
275 u-boot:do_populate_sysroot \
276 "
277do_generate_static_tar[vardepsexclude] = "DATETIME"
278
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400279do_generate_ubi_tar() {
280 ln -sf ${S}/MANIFEST MANIFEST
Brad Bishopde659382018-03-30 01:46:16 -0400281 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE}
282 make_tar_of_images ubi MANIFEST
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400283}
284do_generate_ubi_tar[dirs] = " ${S}/ubi"
285do_generate_ubi_tar[depends] += " \
286 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
287 virtual/kernel:do_deploy \
288 u-boot:do_populate_sysroot \
289 "
290
Brad Bishop19fc4f82017-08-04 23:38:54 -0400291python do_generate_phosphor_manifest() {
Saqib Khan41723472017-09-22 10:21:30 -0500292 version = do_get_version(d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400293 with open('MANIFEST', 'w') as fd:
294 fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
295 fd.write('version={}\n'.format(version.strip('"')))
296}
297do_generate_phosphor_manifest[dirs] = "${S}"
298do_generate_phosphor_manifest[depends] += " \
299 os-release:do_populate_sysroot \
300 "
301
302addtask generate_phosphor_manifest after do_rootfs
303addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400304addtask generate_rwfs_ubi after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400305
306python() {
307 types = d.getVar('IMAGE_FSTYPES', True).split()
308
309 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
310 bb.build.addtask(
311 'do_generate_static',
312 'do_image_complete',
313 'do_generate_rwfs_static', d)
314 if 'mtd-static-alltar' in types:
315 bb.build.addtask(
316 'do_generate_static_alltar',
317 'do_image_complete',
318 'do_generate_static', d)
319 if 'mtd-static-tar' in types:
320 bb.build.addtask(
321 'do_generate_static_tar',
322 'do_image_complete',
323 'do_generate_rwfs_static', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400324
325 if 'mtd-ubi' in types:
326 bb.build.addtask(
327 'do_generate_ubi',
328 'do_image_complete',
329 'do_generate_rwfs_ubi', d)
330 if 'mtd-ubi-tar' in types:
331 bb.build.addtask(
332 'do_generate_ubi_tar',
333 'do_image_complete',
334 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400335}