blob: 717c4536dce51ec5f3dd1749134f79d463189ea6 [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
Patrick Williamsb9e124c2022-12-14 09:10:49 -06005FIT_IMAGE_INHERIT=""
6FIT_IMAGE_INHERIT:df-obmc-static-norootfs = "fit-image"
7inherit ${FIT_IMAGE_INHERIT}
8
Brad Bishop19fc4f82017-08-04 23:38:54 -04009# Phosphor image types
10#
Brad Bishop3aa1ef62017-08-04 23:48:12 -040011# Phosphor OpenBMC supports a fixed partition mtd layout,
12# A dynamic mtd with ubi layout, and a tar file for use with
13# The reference BMC software update implementation.
Brad Bishop19fc4f82017-08-04 23:38:54 -040014
15# Image composition
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080016FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE}"
Patrick Williams12fc9392021-08-06 09:16:53 -050017FLASH_KERNEL_IMAGE:df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin"
Brad Bishop8623bbe2018-03-09 00:04:00 -050018
Brad Bishop19fc4f82017-08-04 23:38:54 -040019IMAGE_BASETYPE ?= "squashfs-xz"
Patrick Williamsb9e124c2022-12-14 09:10:49 -060020IMAGE_BASETYPE:df-obmc-static-norootfs ?= "cpio"
Brad Bishop19fc4f82017-08-04 23:38:54 -040021OVERLAY_BASETYPE ?= "jffs2"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040022FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}"
23FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs"
Adriana Kobylak9b7197e2019-07-29 15:25:33 -050024FLASH_EXT4_BASETYPE ?= "ext4"
Adriana Kobylak5a5753a2019-07-30 11:27:46 -050025FLASH_EXT4_OVERLAY_BASETYPE ?= "ext4"
Brad Bishop19fc4f82017-08-04 23:38:54 -040026
Patrick Williamsb9e124c2022-12-14 09:10:49 -060027PHOSPHOR_IMAGE_TYPES += " \
28 mtd-static \
29 mtd-static-alltar \
30 mtd-static-tar \
31 mtd-static-norootfs \
32 mtd-ubi \
33 mtd-ubi-tar \
34 mmc-ext4-tar \
35"
36IMAGE_TYPES += "${PHOSPHOR_IMAGE_TYPES}"
37IMAGE_TYPES_MASKED += "${PHOSPHOR_IMAGE_TYPES}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040038
Patrick Williams12fc9392021-08-06 09:16:53 -050039IMAGE_TYPEDEP:mtd-static = "${IMAGE_BASETYPE}"
40IMAGE_TYPEDEP:mtd-static-tar = "${IMAGE_BASETYPE}"
41IMAGE_TYPEDEP:mtd-static-alltar = "mtd-static"
Patrick Williamsb9e124c2022-12-14 09:10:49 -060042IMAGE_TYPEDEP:mtd-static-norootfs = "${IMAGE_BASETYPE}"
Patrick Williams12fc9392021-08-06 09:16:53 -050043IMAGE_TYPEDEP:mtd-ubi = "${FLASH_UBI_BASETYPE}"
44IMAGE_TYPEDEP:mtd-ubi-tar = "${FLASH_UBI_BASETYPE}"
45IMAGE_TYPEDEP:mmc-ext4-tar = "${FLASH_EXT4_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040046
Brad Bishop3aa1ef62017-08-04 23:48:12 -040047# Flash characteristics in KB unless otherwise noted
Brad Bishopdcd861c2019-09-24 21:16:09 -040048DISTROOVERRIDES .= ":flash-${FLASH_SIZE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040049FLASH_SIZE ?= "32768"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040050FLASH_PEB_SIZE ?= "64"
51# Flash page and overhead sizes in bytes
52FLASH_PAGE_SIZE ?= "1"
53FLASH_NOR_UBI_OVERHEAD ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040054
55# Fixed partition offsets
Adriana Kobylake913dd82020-04-13 13:56:41 -050056FLASH_UBOOT_SPL_SIZE ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040057FLASH_UBOOT_OFFSET ?= "0"
Patrick Williams80dccc82023-03-27 09:58:33 -050058FLASH_MANIFEST_OFFSET ?= "380"
Patrick Williams917fab22023-03-10 16:58:50 -060059FLASH_MANIFEST_OFFSET:flash-65536 ?= "888"
60FLASH_MANIFEST_OFFSET:flash-131072 ?= "888"
Patrick Williams2e375292023-03-10 12:18:56 -060061FLASH_UBOOT_ENV_OFFSET ?= "384"
62FLASH_UBOOT_ENV_OFFSET:flash-65536 ?= "896"
63FLASH_UBOOT_ENV_OFFSET:flash-131072 ?= "896"
Brad Bishop19fc4f82017-08-04 23:38:54 -040064FLASH_KERNEL_OFFSET ?= "512"
Patrick Williams12fc9392021-08-06 09:16:53 -050065FLASH_KERNEL_OFFSET:flash-65536 ?= "1024"
66FLASH_KERNEL_OFFSET:flash-131072 ?= "1024"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040067FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040068FLASH_ROFS_OFFSET ?= "4864"
Patrick Williams12fc9392021-08-06 09:16:53 -050069FLASH_ROFS_OFFSET:flash-65536 ?= "10240"
70FLASH_ROFS_OFFSET:flash-131072 ?= "10240"
Brad Bishop19fc4f82017-08-04 23:38:54 -040071FLASH_RWFS_OFFSET ?= "28672"
Patrick Williams12fc9392021-08-06 09:16:53 -050072FLASH_RWFS_OFFSET:flash-65536 ?= "43008"
73FLASH_RWFS_OFFSET:flash-131072 ?= "98304"
Brad Bishop19fc4f82017-08-04 23:38:54 -040074
Brad Bishop3aa1ef62017-08-04 23:48:12 -040075# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060076FLASH_UBI_RWFS_SIZE ?= "6144"
Patrick Williams12fc9392021-08-06 09:16:53 -050077FLASH_UBI_RWFS_SIZE:flash-131072 ?= "32768"
Adriana Kobylakb70005d2018-02-14 16:35:30 -060078FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Patrick Williams12fc9392021-08-06 09:16:53 -050079FLASH_UBI_RWFS_TXT_SIZE:flash-131072 ?= "32MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040080
Adriana Kobylak45a57952020-07-01 16:23:11 -050081# eMMC sizes in KB unless otherwise noted.
Adriana Kobylak55681e42020-11-11 15:06:50 -060082MMC_UBOOT_SIZE ?= "1024"
Adriana Kobylak45a57952020-07-01 16:23:11 -050083MMC_BOOT_PARTITION_SIZE ?= "65536"
84
Lei YU444782b2023-01-18 17:35:03 +080085SIGNING_PUBLIC_KEY ?= ""
86SIGNING_PUBLIC_KEY_TYPE = "${@os.path.splitext(os.path.basename('${SIGNING_PUBLIC_KEY}'))[0]}"
87
Eddie Jamesb2b7ff62018-02-09 11:59:18 -060088SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv"
89INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}"
90SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}"
91
Adriana Kobylakfb62a682019-10-28 16:03:12 -050092VERSION_PURPOSE ?= "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
93
Brad Bishop3e37d382018-03-31 12:17:28 -040094UBOOT_SUFFIX ?= "bin"
95
Brad Bishop3aa1ef62017-08-04 23:48:12 -040096python() {
97 # Compute rwfs LEB count and LEB size.
98 page_size = d.getVar('FLASH_PAGE_SIZE', True)
99 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
100 overhead_size = max(int(page_size), int(nor_overhead_size))
101 peb_size = d.getVar('FLASH_PEB_SIZE', True)
102 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
103 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
104
105 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
106 rwfs_size = int(rwfs_size) * 1024
107 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
108 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
109}
110
Brad Bishop19fc4f82017-08-04 23:38:54 -0400111# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
112# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
113# reserved for the primary image (and setting them currently breaks the build).
114# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
115DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400116DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500117DISTROOVERRIDES .= ":mmc-rwfs-${FLASH_EXT4_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400118
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700119JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2"
120UBIFS_RWFS_CMD = "mkfs.ubifs -r ubifs -c ${FLASH_UBI_RWFS_LEBS} -m ${FLASH_PAGE_SIZE} -e ${FLASH_LEB_SIZE} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubifs"
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500121EXT4_RWFS_CMD = "mkfs.ext4 -F ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400122
Patrick Williams12fc9392021-08-06 09:16:53 -0500123FLASH_STATIC_RWFS_CMD:static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
124FLASH_UBI_RWFS_CMD:ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
125FLASH_UBI_RWFS_CMD:ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
126FLASH_EXT4_RWFS_CMD:mmc-rwfs-ext4 = "${EXT4_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400127
Adriana Kobylak661cf392019-07-29 14:39:00 -0500128mk_empty_image() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500129 image_dst="$1"
130 image_size_kb=$2
131 dd if=/dev/zero bs=1k count=$image_size_kb \
132 | tr '\000' '\377' > $image_dst
Brad Bishop19fc4f82017-08-04 23:38:54 -0400133}
134
Adriana Kobylak55681e42020-11-11 15:06:50 -0600135mk_empty_image_zeros() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500136 image_dst="$1"
137 image_size_kb=$2
138 dd if=/dev/zero of=$image_dst bs=1k count=$image_size_kb
Adriana Kobylak55681e42020-11-11 15:06:50 -0600139}
140
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500141clean_rwfs() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500142 type=$1
143 shift
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500144
Patrick Williamsaf48f632023-03-20 10:13:55 -0500145 rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type
146 rm -rf $type
147 mkdir $type
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500148}
149
Brad Bishop19fc4f82017-08-04 23:38:54 -0400150make_rwfs() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500151 type=$1
152 cmd=$2
153 shift
154 shift
155 opts="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400156
Patrick Williamsaf48f632023-03-20 10:13:55 -0500157 mkdir -p $type
Brad Bishop19fc4f82017-08-04 23:38:54 -0400158
Patrick Williamsaf48f632023-03-20 10:13:55 -0500159 $cmd $opts
Brad Bishop19fc4f82017-08-04 23:38:54 -0400160}
161
162do_generate_rwfs_static() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500163 clean_rwfs ${OVERLAY_BASETYPE}
164 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400165}
166do_generate_rwfs_static[dirs] = " ${S}/static"
167do_generate_rwfs_static[depends] += " \
168 mtd-utils-native:do_populate_sysroot \
169 "
170
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400171do_generate_rwfs_ubi() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500172 clean_rwfs ${FLASH_UBI_OVERLAY_BASETYPE}
173 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400174}
175do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
176do_generate_rwfs_ubi[depends] += " \
177 mtd-utils-native:do_populate_sysroot \
178 "
179
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500180do_generate_rwfs_ext4() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500181 clean_rwfs rwfs.${FLASH_EXT4_OVERLAY_BASETYPE}
182 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4 1024
183 make_rwfs ${FLASH_EXT4_OVERLAY_BASETYPE} "${FLASH_EXT4_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500184}
185do_generate_rwfs_ext4[dirs] = " ${S}/ext4"
186do_generate_rwfs_ext4[depends] += " \
187 e2fsprogs-native:do_populate_sysroot \
188 "
189
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400190add_volume() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500191 config_file=$1
192 vol_id=$2
193 vol_type=$3
194 vol_name=$4
195 image=$5
196 vol_size=$6
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400197
Patrick Williamsaf48f632023-03-20 10:13:55 -0500198 echo \[$vol_name\] >> $config_file
199 echo mode=ubi >> $config_file
200 echo image=$image >> $config_file
201 echo vol_type=$vol_type >> $config_file
202 echo vol_name=$vol_name >> $config_file
203 echo vol_id=$vol_id >> $config_file
204 if [ ! -z $vol_size ]; then
205 echo vol_size=$vol_size >> $config_file
206 fi
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400207}
208
Saqib Khan41723472017-09-22 10:21:30 -0500209python do_generate_ubi() {
210 version_id = do_get_versionID(d)
211 d.setVar('VERSION_ID', version_id)
212 bb.build.exec_func("do_make_ubi", d)
213}
214do_generate_ubi[dirs] = "${S}/ubi"
215do_generate_ubi[depends] += " \
216 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
217 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500218 u-boot:do_deploy \
Saqib Khan41723472017-09-22 10:21:30 -0500219 mtd-utils-native:do_populate_sysroot \
220 "
221
222do_make_ubi() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500223 cfg=ubinize-${IMAGE_NAME}.cfg
224 rm -f $cfg ubi-img
225 # Construct the ubinize config file
226 add_volume $cfg 0 static kernel-${VERSION_ID} \
227 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400228
Patrick Williamsaf48f632023-03-20 10:13:55 -0500229 add_volume $cfg 1 static rofs-${VERSION_ID} \
230 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400231
Patrick Williamsaf48f632023-03-20 10:13:55 -0500232 add_volume $cfg 2 dynamic rwfs ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400233
Patrick Williamsaf48f632023-03-20 10:13:55 -0500234 # Build the ubi partition image
235 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400236
Patrick Williamsaf48f632023-03-20 10:13:55 -0500237 # Concatenate the uboot and ubi partitions
238 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
239 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
240 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
241 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
242 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
243 if=ubi-img \
244 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400245
Patrick Williamsaf48f632023-03-20 10:13:55 -0500246 cd ${IMGDEPLOYDIR}
247 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400248}
Saqib Khan41723472017-09-22 10:21:30 -0500249do_make_ubi[dirs] = "${S}/ubi"
250do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400251 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
252 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500253 u-boot:do_deploy \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400254 mtd-utils-native:do_populate_sysroot \
255 "
256
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300257do_mk_static_nor_image() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500258 # Assemble the flash image
259 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300260}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400261
Adriana Kobylakf1954f02020-04-27 15:20:35 -0500262do_generate_image_uboot_file() {
263 image_dst="$1"
264 uboot_offset=${FLASH_UBOOT_OFFSET}
265
266 if [ ! -z ${SPL_BINARY} ]; then
267 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
268 if=${DEPLOY_DIR_IMAGE}/u-boot-spl.${UBOOT_SUFFIX} \
269 of=${image_dst}
270 uboot_offset=${FLASH_UBOOT_SPL_SIZE}
271 fi
272
273 dd bs=1k conv=notrunc seek=${uboot_offset} \
274 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
275 of=${image_dst}
276}
277
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300278python do_generate_static() {
279 import subprocess
Brad Bishop19fc4f82017-08-04 23:38:54 -0400280
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300281 bb.build.exec_func("do_mk_static_nor_image", d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400282
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300283 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True),
284 '%s.static.mtd' % d.getVar('IMAGE_NAME', True))
285
286 def _append_image(imgpath, start_kb, finish_kb):
287 imgsize = os.path.getsize(imgpath)
Josh Lehan0a5ef2a2020-02-26 12:11:33 -0800288 maxsize = (finish_kb - start_kb) * 1024
289 bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath)
290 bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K')
291 bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize))
292 if imgsize > maxsize:
Joel Stanley909f33e2023-01-18 18:56:17 +1030293 bb.fatal("Image '%s' is %d bytes too large!" % (imgpath, imgsize - maxsize))
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300294
295 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc',
296 'seek=%d' % start_kb,
297 'if=%s' % imgpath,
298 'of=%s' % nor_image])
299
Adriana Kobylake913dd82020-04-13 13:56:41 -0500300 uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True))
301
302 spl_binary = d.getVar('SPL_BINARY', True)
303 if spl_binary:
304 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
305 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)),
306 int(d.getVar('FLASH_UBOOT_OFFSET', True)),
307 int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)))
308 uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))
309
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300310 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
311 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
Adriana Kobylake913dd82020-04-13 13:56:41 -0500312 uboot_offset,
Patrick Williams2e375292023-03-10 12:18:56 -0600313 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)))
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300314
315 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
316 d.getVar('FLASH_KERNEL_IMAGE', True)),
317 int(d.getVar('FLASH_KERNEL_OFFSET', True)),
318 int(d.getVar('FLASH_ROFS_OFFSET', True)))
319
320 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
321 '%s.%s' % (
322 d.getVar('IMAGE_LINK_NAME', True),
323 d.getVar('IMAGE_BASETYPE', True))),
324 int(d.getVar('FLASH_ROFS_OFFSET', True)),
325 int(d.getVar('FLASH_RWFS_OFFSET', True)))
326
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700327 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
328 '%s.%s' % (
329 d.getVar('IMAGE_LINK_NAME', True),
330 d.getVar('OVERLAY_BASETYPE', True))),
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300331 int(d.getVar('FLASH_RWFS_OFFSET', True)),
332 int(d.getVar('FLASH_SIZE', True)))
333
334 bb.build.exec_func("do_mk_static_symlinks", d)
335}
336
337do_mk_static_symlinks() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500338 cd ${IMGDEPLOYDIR}
339 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
Brad Bishop19fc4f82017-08-04 23:38:54 -0400340
Patrick Williamsaf48f632023-03-20 10:13:55 -0500341 # Maintain non-standard legacy links
342 do_generate_image_uboot_file ${IMGDEPLOYDIR}/image-u-boot
343 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
344 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
345 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
346 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
347 ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400348}
349do_generate_static[dirs] = "${S}/static"
350do_generate_static[depends] += " \
351 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
352 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500353 u-boot:do_deploy \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400354 "
355
Lei YUf2072212018-06-20 13:27:34 +0800356make_signatures() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500357 signing_key="${SIGNING_KEY}"
George Liuf0afcf82020-12-15 09:46:10 +0800358
Patrick Williamsaf48f632023-03-20 10:13:55 -0500359 if [ "${INSECURE_KEY}" == "True" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then
360 echo "Using SIGNING_PUBLIC_KEY"
361 signing_key=""
362 fi
Lei YU444782b2023-01-18 17:35:03 +0800363
Patrick Williamsaf48f632023-03-20 10:13:55 -0500364 if [ -n "${signing_key}" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then
365 echo "Both SIGNING_KEY and SIGNING_PUBLIC_KEY are defined, expecting only one"
366 exit 1
367 fi
Lei YU444782b2023-01-18 17:35:03 +0800368
Patrick Williamsaf48f632023-03-20 10:13:55 -0500369 signature_files=""
370 if [ -n "${signing_key}" ]; then
371 for file in "$@"; do
372 openssl dgst -sha256 -sign ${signing_key} -out "${file}.sig" $file
373 signature_files="${signature_files} ${file}.sig"
374 done
Lei YU444782b2023-01-18 17:35:03 +0800375
Patrick Williamsaf48f632023-03-20 10:13:55 -0500376 if [ -n "${signature_files}" ]; then
377 sort_signature_files=$(echo "${signature_files}" | tr ' ' '\n' | sort | tr '\n' ' ')
378 cat ${sort_signature_files} > image-full
379 openssl dgst -sha256 -sign ${signing_key} -out image-full.sig image-full
380 signature_files="${signature_files} image-full.sig"
381 fi
382 fi
Lei YUf2072212018-06-20 13:27:34 +0800383}
384
Brad Bishop19fc4f82017-08-04 23:38:54 -0400385do_generate_static_alltar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500386 ln -sf ${S}/MANIFEST MANIFEST
387 ln -sf ${S}/publickey publickey
388 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
Lei YUa4674942018-05-23 14:01:14 +0800389
Patrick Williamsaf48f632023-03-20 10:13:55 -0500390 make_signatures image-bmc MANIFEST publickey
Lei YUa4674942018-05-23 14:01:14 +0800391
Patrick Williamsaf48f632023-03-20 10:13:55 -0500392 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \
393 image-bmc MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400394
Patrick Williamsaf48f632023-03-20 10:13:55 -0500395 cd ${IMGDEPLOYDIR}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400396
Patrick Williamsaf48f632023-03-20 10:13:55 -0500397 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
398 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400399
Patrick Williamsaf48f632023-03-20 10:13:55 -0500400 # Maintain non-standard legacy link.
401 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
402 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
Lei YUa4674942018-05-23 14:01:14 +0800403
Brad Bishop19fc4f82017-08-04 23:38:54 -0400404}
405do_generate_static_alltar[vardepsexclude] = "DATETIME"
406do_generate_static_alltar[dirs] = "${S}/static"
Lei YUa4674942018-05-23 14:01:14 +0800407do_generate_static_alltar[depends] += " \
408 openssl-native:do_populate_sysroot \
409 ${SIGNING_KEY_DEPENDS} \
410 ${PN}:do_copy_signing_pubkey \
411 "
Brad Bishop19fc4f82017-08-04 23:38:54 -0400412
Brad Bishopde659382018-03-30 01:46:16 -0400413make_image_links() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500414 rwfs=$1
415 rofs=$2
416 shift
417 shift
Brad Bishop19fc4f82017-08-04 23:38:54 -0400418
Patrick Williamsaf48f632023-03-20 10:13:55 -0500419 # Create some links to help make the tar archive in the format
420 # expected by phosphor-bmc-code-mgmt.
421 do_generate_image_uboot_file image-u-boot
422 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
423 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
424 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs
Brad Bishopde659382018-03-30 01:46:16 -0400425}
426
427make_tar_of_images() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500428 type=$1
429 shift
430 extra_files="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400431
Patrick Williamsaf48f632023-03-20 10:13:55 -0500432 # Create the tar archive
433 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.tar \
434 image-u-boot image-kernel image-rofs image-rwfs $extra_files
Brad Bishop19fc4f82017-08-04 23:38:54 -0400435
Patrick Williamsaf48f632023-03-20 10:13:55 -0500436 cd ${IMGDEPLOYDIR}
437 ln -sf ${IMAGE_NAME}.$type.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400438}
439
440do_generate_static_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500441 ln -sf ${S}/MANIFEST MANIFEST
442 ln -sf ${S}/publickey publickey
443 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
444 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
445 make_tar_of_images static.mtd MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400446
Patrick Williamsaf48f632023-03-20 10:13:55 -0500447 # Maintain non-standard legacy link.
448 cd ${IMGDEPLOYDIR}
449 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400450}
451do_generate_static_tar[dirs] = " ${S}/static"
452do_generate_static_tar[depends] += " \
453 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
454 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500455 u-boot:do_deploy \
Lei YUa4674942018-05-23 14:01:14 +0800456 openssl-native:do_populate_sysroot \
457 ${SIGNING_KEY_DEPENDS} \
458 ${PN}:do_copy_signing_pubkey \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400459 "
460do_generate_static_tar[vardepsexclude] = "DATETIME"
461
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600462python do_generate_static_norootfs() {
Patrick Williams917fab22023-03-10 16:58:50 -0600463 import hashlib
464 import json
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600465 import subprocess
466
Patrick Williams917fab22023-03-10 16:58:50 -0600467 manifest = {
468 "type": "phosphor-image-manifest",
469 "version": 1,
470 "info": {
471 "purpose": d.getVar('VERSION_PURPOSE', True),
472 "machine": d.getVar('MACHINE', True),
473 "version": do_get_version(d).strip('"'),
474 "build-id": do_get_buildID(d).strip('"'),
475 },
476 "partitions": [],
477 # Create an empty hash-value so that the dictionary can be emitted,
478 # hashed, and then updated.
479 "manifest-sha256": "",
480 }
481 extended_version = do_get_extended_version(d).strip('"')
482 if extended_version:
483 manifest["info"]["extended-version"] = extended_version
484 compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True)
485 if compatible_names:
486 manifest["info"]["compatible-names"] = compatible_names.split()
487
488 manifest_json_file = os.path.join(d.getVar('IMGDEPLOYDIR', True),
489 "phosphor-image-manifest.json")
490
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600491 nor_image_basename = '%s.static.mtd' % d.getVar('IMAGE_NAME', True)
492 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), nor_image_basename)
493
Patrick Williams917fab22023-03-10 16:58:50 -0600494 def _add_manifest(partname, typename, offset, size, sha256_value = None):
495 manifest["partitions"].append(
496 {
497 "name": partname,
498 "type": typename,
499 "offset": offset,
500 "size": size,
501 }
502 )
503 if typename == "fit":
504 if "u-boot-fit" == partname:
505 manifest["partitions"][-1]["num-nodes"] = 1
506 elif "os-fit" == partname:
507 manifest["partitions"][-1]["num-nodes"] = 3
508 else:
509 bb.fatal(f"Unknown FIT partition type: {partname}")
510 if sha256_value:
511 manifest["partitions"][-1]["sha256"] = sha256_value
512
513
514 def _append_image(partname, typename, imgpath, start_kb, finish_kb):
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600515 imgsize = os.path.getsize(imgpath)
516 maxsize = (finish_kb - start_kb) * 1024
517 bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath)
518 bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K')
519 bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize))
520 if imgsize > maxsize:
521 bb.fatal("Image '%s' is too large!" % imgpath)
522
Patrick Williams917fab22023-03-10 16:58:50 -0600523 with open(imgpath, "rb") as fp:
524 sha256 = hashlib.sha256(fp.read()).hexdigest()
525
526 _add_manifest(partname, typename, start_kb * 1024, imgsize, sha256)
527
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600528 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc',
529 'seek=%d' % start_kb,
530 'if=%s' % imgpath,
531 'of=%s' % nor_image])
Patrick Williams917fab22023-03-10 16:58:50 -0600532
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600533 uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True))
534
535 spl_binary = d.getVar('SPL_BINARY', True)
536 if spl_binary:
Patrick Williams917fab22023-03-10 16:58:50 -0600537 _append_image("spl", "u-boot",
538 os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600539 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)),
540 int(d.getVar('FLASH_UBOOT_OFFSET', True)),
541 int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)))
542 uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))
543
Patrick Williams917fab22023-03-10 16:58:50 -0600544 _append_image("u-boot-fit", "fit",
545 os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600546 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
547 uboot_offset,
Patrick Williams917fab22023-03-10 16:58:50 -0600548 int(d.getVar('FLASH_MANIFEST_OFFSET', True)))
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600549
Patrick Williams917fab22023-03-10 16:58:50 -0600550 _add_manifest("manifest", "json",
551 int(d.getVar('FLASH_MANIFEST_OFFSET', True)) * 1024,
552 (int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) -
553 int(d.getVar('FLASH_MANIFEST_OFFSET', True))) * 1024)
554
555 _add_manifest("u-boot-env", "data",
556 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) * 1024,
557 (int(d.getVar('FLASH_KERNEL_OFFSET', True)) -
558 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True))) * 1024)
559
560 _append_image("os-fit", "fit",
561 os.path.join(d.getVar('IMGDEPLOYDIR', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600562 '%s.cpio.%s.fitImage' % (
563 d.getVar('IMAGE_LINK_NAME', True),
564 d.getVar('INITRAMFS_CTYPE', True))),
565 int(d.getVar('FLASH_KERNEL_OFFSET', True)),
566 int(d.getVar('FLASH_RWFS_OFFSET', True)))
567
Patrick Williams917fab22023-03-10 16:58:50 -0600568 _add_manifest("rwfs", "data",
569 int(d.getVar('FLASH_RWFS_OFFSET', True)) * 1024,
570 (int(d.getVar('FLASH_SIZE', True)) -
571 int(d.getVar('FLASH_RWFS_OFFSET', True))) * 1024)
572
573 # Calculate the sha256 of the current manifest and update.
574 manifest_raw = json.dumps(manifest, indent=4)
575 manifest_raw = manifest_raw[:manifest_raw.find("manifest-sha256")]
576 manifest["manifest-sha256"] = hashlib.sha256(
577 manifest_raw.encode('utf-8')).hexdigest()
578
579 # Write the final manifest json and add it to the image.
580 with open(manifest_json_file, "wb") as fp:
581 fp.write(json.dumps(manifest, indent=4).encode('utf-8'))
582 _append_image("manifest", "json", manifest_json_file,
583 int(d.getVar('FLASH_MANIFEST_OFFSET', True)),
584 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)))
585
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600586 flash_symlink = os.path.join(
587 d.getVar('IMGDEPLOYDIR', True),
588 'flash-%s' % d.getVar('MACHINE', True))
589 if os.path.exists(flash_symlink):
590 os.remove(flash_symlink)
591 os.symlink(nor_image_basename, flash_symlink)
592}
593do_generate_static_norootfs[depends] += " \
594 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
595 u-boot:do_deploy \
596 "
597
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400598do_generate_ubi_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500599 ln -sf ${S}/MANIFEST MANIFEST
600 ln -sf ${S}/publickey publickey
601 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE}
602 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
603 make_tar_of_images ubi.mtd MANIFEST publickey ${signature_files}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400604}
605do_generate_ubi_tar[dirs] = " ${S}/ubi"
606do_generate_ubi_tar[depends] += " \
607 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
608 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500609 u-boot:do_deploy \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600610 openssl-native:do_populate_sysroot \
611 ${SIGNING_KEY_DEPENDS} \
612 ${PN}:do_copy_signing_pubkey \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400613 "
614
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500615do_generate_ext4_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500616 # Generate the U-Boot image
617 mk_empty_image_zeros image-u-boot ${MMC_UBOOT_SIZE}
618 do_generate_image_uboot_file image-u-boot
Adriana Kobylak45a57952020-07-01 16:23:11 -0500619
Patrick Williamsaf48f632023-03-20 10:13:55 -0500620 # Generate a compressed ext4 filesystem with the fitImage file in it to be
621 # flashed to the boot partition of the eMMC
622 install -d boot-image
623 install -m 644 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} boot-image/fitImage
624 mk_empty_image_zeros boot-image.${FLASH_EXT4_BASETYPE} ${MMC_BOOT_PARTITION_SIZE}
625 mkfs.ext4 -F -i 4096 -d boot-image boot-image.${FLASH_EXT4_BASETYPE}
626 # Error codes 0-3 indicate successfull operation of fsck
627 fsck.ext4 -pvfD boot-image.${FLASH_EXT4_BASETYPE} || [ $? -le 3 ]
628 zstd -f -k -T0 -c ${ZSTD_COMPRESSION_LEVEL} boot-image.${FLASH_EXT4_BASETYPE} > boot-image.${FLASH_EXT4_BASETYPE}.zst
Adriana Kobylak45a57952020-07-01 16:23:11 -0500629
Patrick Williamsaf48f632023-03-20 10:13:55 -0500630 # Generate the compressed ext4 rootfs
631 zstd -f -k -T0 -c ${ZSTD_COMPRESSION_LEVEL} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE} > ${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE}.zst
Adriana Kobylak45a57952020-07-01 16:23:11 -0500632
Patrick Williamsaf48f632023-03-20 10:13:55 -0500633 ln -sf boot-image.${FLASH_EXT4_BASETYPE}.zst image-kernel
634 ln -sf ${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE}.zst image-rofs
635 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} image-rwfs
636 ln -sf ${S}/MANIFEST MANIFEST
637 ln -sf ${S}/publickey publickey
Adriana Kobylak81846a22020-07-12 15:12:36 -0500638
Patrick Williamsaf48f632023-03-20 10:13:55 -0500639 hostfw_update_file="${DEPLOY_DIR_IMAGE}/hostfw/update/image-hostfw"
640 if [ -e "${hostfw_update_file}" ]; then
641 ln -sf "${hostfw_update_file}" image-hostfw
642 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey image-hostfw
643 make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files} image-hostfw
644 else
645 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
646 make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files}
647 fi
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500648}
649do_generate_ext4_tar[dirs] = " ${S}/ext4"
650do_generate_ext4_tar[depends] += " \
Adriana Kobylak4cc866b2020-03-28 13:43:33 -0500651 zstd-native:do_populate_sysroot \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500652 ${PN}:do_image_${FLASH_EXT4_BASETYPE} \
653 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500654 u-boot:do_deploy \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500655 openssl-native:do_populate_sysroot \
656 ${SIGNING_KEY_DEPENDS} \
657 ${PN}:do_copy_signing_pubkey \
Brad Bishop209ed522020-11-02 12:36:04 -0500658 phosphor-hostfw-image:do_deploy \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500659 "
660
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600661def get_pubkey_basedir(d):
662 return os.path.join(
663 d.getVar('STAGING_DIR_TARGET', True),
664 d.getVar('sysconfdir', True).strip(os.sep),
665 'activationdata')
666
667def get_pubkey_type(d):
668 return os.listdir(get_pubkey_basedir(d))[0]
669
670def get_pubkey_path(d):
671 return os.path.join(
672 get_pubkey_basedir(d),
673 get_pubkey_type(d),
674 'publickey')
675
Brad Bishop19fc4f82017-08-04 23:38:54 -0400676python do_generate_phosphor_manifest() {
Adriana Kobylakfb62a682019-10-28 16:03:12 -0500677 purpose = d.getVar('VERSION_PURPOSE', True)
Saqib Khan41723472017-09-22 10:21:30 -0500678 version = do_get_version(d)
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +0000679 build_id = do_get_buildID(d)
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700680 target_machine = d.getVar('MACHINE', True)
Adriana Kobylakbde7dbe2022-08-04 09:13:26 -0500681 extended_version = do_get_extended_version(d)
Justin Ledfordb4de16d2022-03-24 17:27:17 -0700682 compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400683 with open('MANIFEST', 'w') as fd:
Adriana Kobylakfb62a682019-10-28 16:03:12 -0500684 fd.write('purpose={}\n'.format(purpose))
Brad Bishop19fc4f82017-08-04 23:38:54 -0400685 fd.write('version={}\n'.format(version.strip('"')))
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +0000686 fd.write('BuildId={}\n'.format(build_id.strip('"')))
Justin Ledfordb4de16d2022-03-24 17:27:17 -0700687 if extended_version:
688 fd.write('ExtendedVersion={}\n'.format(extended_version))
689 if compatible_names:
690 for name in compatible_names.split():
691 fd.write('CompatibleName={}\n'.format(name))
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600692 fd.write('KeyType={}\n'.format(get_pubkey_type(d)))
693 fd.write('HashType=RSA-SHA256\n')
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700694 fd.write('MachineName={}\n'.format(target_machine))
Brad Bishop19fc4f82017-08-04 23:38:54 -0400695}
696do_generate_phosphor_manifest[dirs] = "${S}"
697do_generate_phosphor_manifest[depends] += " \
698 os-release:do_populate_sysroot \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600699 phosphor-image-signing:do_populate_sysroot \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400700 "
701
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600702python do_copy_signing_pubkey() {
703 with open(get_pubkey_path(d), 'r') as read_fd:
704 with open('publickey', 'w') as write_fd:
705 write_fd.write(read_fd.read())
706}
707
708do_copy_signing_pubkey[dirs] = "${S}"
709do_copy_signing_pubkey[depends] += " \
710 phosphor-image-signing:do_populate_sysroot \
711 "
712
713addtask copy_signing_pubkey after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400714addtask generate_phosphor_manifest after do_rootfs
715addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400716addtask generate_rwfs_ubi after do_rootfs
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500717addtask generate_rwfs_ext4 after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400718
719python() {
720 types = d.getVar('IMAGE_FSTYPES', True).split()
721
722 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
723 bb.build.addtask(
724 'do_generate_static',
725 'do_image_complete',
726 'do_generate_rwfs_static', d)
727 if 'mtd-static-alltar' in types:
728 bb.build.addtask(
729 'do_generate_static_alltar',
730 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800731 'do_generate_static do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400732 if 'mtd-static-tar' in types:
733 bb.build.addtask(
734 'do_generate_static_tar',
735 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800736 'do_generate_rwfs_static do_generate_phosphor_manifest', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400737
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600738 if 'mtd-static-norootfs' in types:
739 bb.build.addtask(
740 'do_generate_static_norootfs',
741 'do_image_complete',
742 'do_image_cpio', d)
743
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400744 if 'mtd-ubi' in types:
745 bb.build.addtask(
746 'do_generate_ubi',
747 'do_image_complete',
748 'do_generate_rwfs_ubi', d)
749 if 'mtd-ubi-tar' in types:
750 bb.build.addtask(
751 'do_generate_ubi_tar',
752 'do_image_complete',
753 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500754
755 if 'mmc-ext4-tar' in types:
756 bb.build.addtask(
757 'do_generate_ext4_tar',
758 'do_image_complete',
759 'do_generate_rwfs_ext4 do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400760}