blob: 4f939991453b3809c491217432cb86e5d5077c9a [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 Bishop3aa1ef62017-08-04 23:48:12 -040049FLASH_PEB_SIZE ?= "64"
50# Flash page and overhead sizes in bytes
51FLASH_PAGE_SIZE ?= "1"
52FLASH_NOR_UBI_OVERHEAD ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040053
54# Fixed partition offsets
Adriana Kobylake913dd82020-04-13 13:56:41 -050055FLASH_UBOOT_SPL_SIZE ?= "64"
Brad Bishop19fc4f82017-08-04 23:38:54 -040056FLASH_UBOOT_OFFSET ?= "0"
Patrick Williams80dccc82023-03-27 09:58:33 -050057FLASH_MANIFEST_OFFSET ?= "380"
Patrick Williams917fab22023-03-10 16:58:50 -060058FLASH_MANIFEST_OFFSET:flash-65536 ?= "888"
59FLASH_MANIFEST_OFFSET:flash-131072 ?= "888"
Patrick Williams2e375292023-03-10 12:18:56 -060060FLASH_UBOOT_ENV_OFFSET ?= "384"
61FLASH_UBOOT_ENV_OFFSET:flash-65536 ?= "896"
62FLASH_UBOOT_ENV_OFFSET:flash-131072 ?= "896"
Brad Bishop19fc4f82017-08-04 23:38:54 -040063FLASH_KERNEL_OFFSET ?= "512"
Patrick Williams12fc9392021-08-06 09:16:53 -050064FLASH_KERNEL_OFFSET:flash-65536 ?= "1024"
65FLASH_KERNEL_OFFSET:flash-131072 ?= "1024"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040066FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040067FLASH_ROFS_OFFSET ?= "4864"
Patrick Williams12fc9392021-08-06 09:16:53 -050068FLASH_ROFS_OFFSET:flash-65536 ?= "10240"
69FLASH_ROFS_OFFSET:flash-131072 ?= "10240"
Brad Bishop19fc4f82017-08-04 23:38:54 -040070FLASH_RWFS_OFFSET ?= "28672"
Patrick Williams12fc9392021-08-06 09:16:53 -050071FLASH_RWFS_OFFSET:flash-65536 ?= "43008"
72FLASH_RWFS_OFFSET:flash-131072 ?= "98304"
Brad Bishop19fc4f82017-08-04 23:38:54 -040073
Brad Bishop3aa1ef62017-08-04 23:48:12 -040074# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060075FLASH_UBI_RWFS_SIZE ?= "6144"
Patrick Williams12fc9392021-08-06 09:16:53 -050076FLASH_UBI_RWFS_SIZE:flash-131072 ?= "32768"
Adriana Kobylakb70005d2018-02-14 16:35:30 -060077FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Patrick Williams12fc9392021-08-06 09:16:53 -050078FLASH_UBI_RWFS_TXT_SIZE:flash-131072 ?= "32MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040079
Adriana Kobylak45a57952020-07-01 16:23:11 -050080# eMMC sizes in KB unless otherwise noted.
Adriana Kobylak55681e42020-11-11 15:06:50 -060081MMC_UBOOT_SIZE ?= "1024"
Adriana Kobylak45a57952020-07-01 16:23:11 -050082MMC_BOOT_PARTITION_SIZE ?= "65536"
83
Lei YU444782b2023-01-18 17:35:03 +080084SIGNING_PUBLIC_KEY ?= ""
85SIGNING_PUBLIC_KEY_TYPE = "${@os.path.splitext(os.path.basename('${SIGNING_PUBLIC_KEY}'))[0]}"
86
Eddie Jamesb2b7ff62018-02-09 11:59:18 -060087SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv"
88INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}"
89SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}"
90
Adriana Kobylakfb62a682019-10-28 16:03:12 -050091VERSION_PURPOSE ?= "xyz.openbmc_project.Software.Version.VersionPurpose.BMC"
92
Brad Bishop3e37d382018-03-31 12:17:28 -040093UBOOT_SUFFIX ?= "bin"
94
Patrick Williams1dc6b4a2023-08-04 10:41:33 -050095IMAGE_NAME_SUFFIX=""
96
Brad Bishop3aa1ef62017-08-04 23:48:12 -040097python() {
98 # Compute rwfs LEB count and LEB size.
99 page_size = d.getVar('FLASH_PAGE_SIZE', True)
100 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
101 overhead_size = max(int(page_size), int(nor_overhead_size))
102 peb_size = d.getVar('FLASH_PEB_SIZE', True)
103 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
104 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
105
106 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
107 rwfs_size = int(rwfs_size) * 1024
108 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
109 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
110}
111
Brad Bishop19fc4f82017-08-04 23:38:54 -0400112# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
113# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
114# reserved for the primary image (and setting them currently breaks the build).
115# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
116DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400117DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500118DISTROOVERRIDES .= ":mmc-rwfs-${FLASH_EXT4_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400119
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700120JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2"
121UBIFS_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 -0500122EXT4_RWFS_CMD = "mkfs.ext4 -F ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400123
Patrick Williams12fc9392021-08-06 09:16:53 -0500124FLASH_STATIC_RWFS_CMD:static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
125FLASH_UBI_RWFS_CMD:ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
126FLASH_UBI_RWFS_CMD:ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
127FLASH_EXT4_RWFS_CMD:mmc-rwfs-ext4 = "${EXT4_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400128
Adriana Kobylak661cf392019-07-29 14:39:00 -0500129mk_empty_image() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500130 image_dst="$1"
131 image_size_kb=$2
132 dd if=/dev/zero bs=1k count=$image_size_kb \
133 | tr '\000' '\377' > $image_dst
Brad Bishop19fc4f82017-08-04 23:38:54 -0400134}
135
Adriana Kobylak55681e42020-11-11 15:06:50 -0600136mk_empty_image_zeros() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500137 image_dst="$1"
138 image_size_kb=$2
139 dd if=/dev/zero of=$image_dst bs=1k count=$image_size_kb
Adriana Kobylak55681e42020-11-11 15:06:50 -0600140}
141
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500142clean_rwfs() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500143 type=$1
144 shift
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500145
Patrick Williamsaf48f632023-03-20 10:13:55 -0500146 rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type
147 rm -rf $type
148 mkdir $type
Adriana Kobylakf494bb52019-07-29 16:14:11 -0500149}
150
Brad Bishop19fc4f82017-08-04 23:38:54 -0400151make_rwfs() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500152 type=$1
153 cmd=$2
154 shift
155 shift
156 opts="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400157
Patrick Williamsaf48f632023-03-20 10:13:55 -0500158 mkdir -p $type
Brad Bishop19fc4f82017-08-04 23:38:54 -0400159
Patrick Williamsaf48f632023-03-20 10:13:55 -0500160 $cmd $opts
Brad Bishop19fc4f82017-08-04 23:38:54 -0400161}
162
163do_generate_rwfs_static() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500164 clean_rwfs ${OVERLAY_BASETYPE}
165 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400166}
167do_generate_rwfs_static[dirs] = " ${S}/static"
168do_generate_rwfs_static[depends] += " \
169 mtd-utils-native:do_populate_sysroot \
170 "
171
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400172do_generate_rwfs_ubi() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500173 clean_rwfs ${FLASH_UBI_OVERLAY_BASETYPE}
174 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400175}
176do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
177do_generate_rwfs_ubi[depends] += " \
178 mtd-utils-native:do_populate_sysroot \
179 "
180
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500181do_generate_rwfs_ext4() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500182 clean_rwfs rwfs.${FLASH_EXT4_OVERLAY_BASETYPE}
183 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4 1024
184 make_rwfs ${FLASH_EXT4_OVERLAY_BASETYPE} "${FLASH_EXT4_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500185}
186do_generate_rwfs_ext4[dirs] = " ${S}/ext4"
187do_generate_rwfs_ext4[depends] += " \
188 e2fsprogs-native:do_populate_sysroot \
189 "
190
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400191add_volume() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500192 config_file=$1
193 vol_id=$2
194 vol_type=$3
195 vol_name=$4
196 image=$5
197 vol_size=$6
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400198
Patrick Williamsaf48f632023-03-20 10:13:55 -0500199 echo \[$vol_name\] >> $config_file
200 echo mode=ubi >> $config_file
201 echo image=$image >> $config_file
202 echo vol_type=$vol_type >> $config_file
203 echo vol_name=$vol_name >> $config_file
204 echo vol_id=$vol_id >> $config_file
205 if [ ! -z $vol_size ]; then
206 echo vol_size=$vol_size >> $config_file
207 fi
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400208}
209
Saqib Khan41723472017-09-22 10:21:30 -0500210python do_generate_ubi() {
211 version_id = do_get_versionID(d)
212 d.setVar('VERSION_ID', version_id)
213 bb.build.exec_func("do_make_ubi", d)
214}
215do_generate_ubi[dirs] = "${S}/ubi"
216do_generate_ubi[depends] += " \
217 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
218 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500219 u-boot:do_deploy \
Saqib Khan41723472017-09-22 10:21:30 -0500220 mtd-utils-native:do_populate_sysroot \
221 "
222
223do_make_ubi() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500224 cfg=ubinize-${IMAGE_NAME}.cfg
225 rm -f $cfg ubi-img
226 # Construct the ubinize config file
227 add_volume $cfg 0 static kernel-${VERSION_ID} \
228 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400229
Patrick Williamsaf48f632023-03-20 10:13:55 -0500230 add_volume $cfg 1 static rofs-${VERSION_ID} \
231 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400232
Patrick Williamsaf48f632023-03-20 10:13:55 -0500233 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 -0400234
Patrick Williamsaf48f632023-03-20 10:13:55 -0500235 # Build the ubi partition image
236 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400237
Patrick Williamsaf48f632023-03-20 10:13:55 -0500238 # Concatenate the uboot and ubi partitions
239 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
240 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
241 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
242 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
243 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
244 if=ubi-img \
245 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400246
Patrick Williamsaf48f632023-03-20 10:13:55 -0500247 cd ${IMGDEPLOYDIR}
248 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400249}
Saqib Khan41723472017-09-22 10:21:30 -0500250do_make_ubi[dirs] = "${S}/ubi"
251do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400252 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
253 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500254 u-boot:do_deploy \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400255 mtd-utils-native:do_populate_sysroot \
256 "
257
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300258do_mk_static_nor_image() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500259 # Assemble the flash image
260 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300261}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400262
Adriana Kobylakf1954f02020-04-27 15:20:35 -0500263do_generate_image_uboot_file() {
264 image_dst="$1"
265 uboot_offset=${FLASH_UBOOT_OFFSET}
266
267 if [ ! -z ${SPL_BINARY} ]; then
268 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
269 if=${DEPLOY_DIR_IMAGE}/u-boot-spl.${UBOOT_SUFFIX} \
270 of=${image_dst}
271 uboot_offset=${FLASH_UBOOT_SPL_SIZE}
272 fi
273
274 dd bs=1k conv=notrunc seek=${uboot_offset} \
275 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
276 of=${image_dst}
277}
278
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300279python do_generate_static() {
280 import subprocess
Brad Bishop19fc4f82017-08-04 23:38:54 -0400281
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300282 bb.build.exec_func("do_mk_static_nor_image", d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400283
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300284 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True),
285 '%s.static.mtd' % d.getVar('IMAGE_NAME', True))
286
287 def _append_image(imgpath, start_kb, finish_kb):
288 imgsize = os.path.getsize(imgpath)
Josh Lehan0a5ef2a2020-02-26 12:11:33 -0800289 maxsize = (finish_kb - start_kb) * 1024
290 bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath)
291 bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K')
292 bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize))
293 if imgsize > maxsize:
Joel Stanley909f33e2023-01-18 18:56:17 +1030294 bb.fatal("Image '%s' is %d bytes too large!" % (imgpath, imgsize - maxsize))
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300295
296 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc',
297 'seek=%d' % start_kb,
298 'if=%s' % imgpath,
299 'of=%s' % nor_image])
300
Adriana Kobylake913dd82020-04-13 13:56:41 -0500301 uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True))
302
303 spl_binary = d.getVar('SPL_BINARY', True)
304 if spl_binary:
305 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
306 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)),
307 int(d.getVar('FLASH_UBOOT_OFFSET', True)),
308 int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)))
309 uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))
310
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300311 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
312 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
Adriana Kobylake913dd82020-04-13 13:56:41 -0500313 uboot_offset,
Patrick Williams2e375292023-03-10 12:18:56 -0600314 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)))
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300315
316 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
317 d.getVar('FLASH_KERNEL_IMAGE', True)),
318 int(d.getVar('FLASH_KERNEL_OFFSET', True)),
319 int(d.getVar('FLASH_ROFS_OFFSET', True)))
320
321 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
322 '%s.%s' % (
323 d.getVar('IMAGE_LINK_NAME', True),
324 d.getVar('IMAGE_BASETYPE', True))),
325 int(d.getVar('FLASH_ROFS_OFFSET', True)),
326 int(d.getVar('FLASH_RWFS_OFFSET', True)))
327
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700328 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
329 '%s.%s' % (
330 d.getVar('IMAGE_LINK_NAME', True),
331 d.getVar('OVERLAY_BASETYPE', True))),
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300332 int(d.getVar('FLASH_RWFS_OFFSET', True)),
333 int(d.getVar('FLASH_SIZE', True)))
334
335 bb.build.exec_func("do_mk_static_symlinks", d)
336}
337
338do_mk_static_symlinks() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500339 cd ${IMGDEPLOYDIR}
340 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
Brad Bishop19fc4f82017-08-04 23:38:54 -0400341
Patrick Williamsaf48f632023-03-20 10:13:55 -0500342 # Maintain non-standard legacy links
343 do_generate_image_uboot_file ${IMGDEPLOYDIR}/image-u-boot
344 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
345 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
346 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
347 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
348 ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400349}
350do_generate_static[dirs] = "${S}/static"
351do_generate_static[depends] += " \
352 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
353 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500354 u-boot:do_deploy \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400355 "
356
Lei YUf2072212018-06-20 13:27:34 +0800357make_signatures() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500358 signing_key="${SIGNING_KEY}"
George Liuf0afcf82020-12-15 09:46:10 +0800359
Lei YU88ed2732023-06-16 14:40:22 +0800360 if [ "${INSECURE_KEY}" = "True" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then
Patrick Williamsaf48f632023-03-20 10:13:55 -0500361 echo "Using SIGNING_PUBLIC_KEY"
362 signing_key=""
363 fi
Lei YU444782b2023-01-18 17:35:03 +0800364
Patrick Williamsaf48f632023-03-20 10:13:55 -0500365 if [ -n "${signing_key}" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then
366 echo "Both SIGNING_KEY and SIGNING_PUBLIC_KEY are defined, expecting only one"
367 exit 1
368 fi
Lei YU444782b2023-01-18 17:35:03 +0800369
Patrick Williamsaf48f632023-03-20 10:13:55 -0500370 signature_files=""
371 if [ -n "${signing_key}" ]; then
372 for file in "$@"; do
373 openssl dgst -sha256 -sign ${signing_key} -out "${file}.sig" $file
374 signature_files="${signature_files} ${file}.sig"
375 done
Lei YU444782b2023-01-18 17:35:03 +0800376
Patrick Williamsaf48f632023-03-20 10:13:55 -0500377 if [ -n "${signature_files}" ]; then
378 sort_signature_files=$(echo "${signature_files}" | tr ' ' '\n' | sort | tr '\n' ' ')
379 cat ${sort_signature_files} > image-full
380 openssl dgst -sha256 -sign ${signing_key} -out image-full.sig image-full
381 signature_files="${signature_files} image-full.sig"
382 fi
383 fi
Lei YUf2072212018-06-20 13:27:34 +0800384}
385
Brad Bishop19fc4f82017-08-04 23:38:54 -0400386do_generate_static_alltar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500387 ln -sf ${S}/MANIFEST MANIFEST
388 ln -sf ${S}/publickey publickey
389 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
Lei YUa4674942018-05-23 14:01:14 +0800390
Patrick Williamsaf48f632023-03-20 10:13:55 -0500391 make_signatures image-bmc MANIFEST publickey
Lei YUa4674942018-05-23 14:01:14 +0800392
Patrick Williamsaf48f632023-03-20 10:13:55 -0500393 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \
394 image-bmc MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400395
Patrick Williamsaf48f632023-03-20 10:13:55 -0500396 cd ${IMGDEPLOYDIR}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400397
Patrick Williamsaf48f632023-03-20 10:13:55 -0500398 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
399 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400400
Patrick Williamsaf48f632023-03-20 10:13:55 -0500401 # Maintain non-standard legacy link.
402 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
403 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
Lei YUa4674942018-05-23 14:01:14 +0800404
Brad Bishop19fc4f82017-08-04 23:38:54 -0400405}
406do_generate_static_alltar[vardepsexclude] = "DATETIME"
407do_generate_static_alltar[dirs] = "${S}/static"
Lei YUa4674942018-05-23 14:01:14 +0800408do_generate_static_alltar[depends] += " \
409 openssl-native:do_populate_sysroot \
410 ${SIGNING_KEY_DEPENDS} \
411 ${PN}:do_copy_signing_pubkey \
412 "
Brad Bishop19fc4f82017-08-04 23:38:54 -0400413
Brad Bishopde659382018-03-30 01:46:16 -0400414make_image_links() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500415 rwfs=$1
416 rofs=$2
417 shift
418 shift
Brad Bishop19fc4f82017-08-04 23:38:54 -0400419
Patrick Williamsaf48f632023-03-20 10:13:55 -0500420 # Create some links to help make the tar archive in the format
421 # expected by phosphor-bmc-code-mgmt.
422 do_generate_image_uboot_file image-u-boot
423 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
424 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
425 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs
Brad Bishopde659382018-03-30 01:46:16 -0400426}
427
428make_tar_of_images() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500429 type=$1
430 shift
431 extra_files="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400432
Patrick Williamsaf48f632023-03-20 10:13:55 -0500433 # Create the tar archive
434 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.tar \
435 image-u-boot image-kernel image-rofs image-rwfs $extra_files
Brad Bishop19fc4f82017-08-04 23:38:54 -0400436
Patrick Williamsaf48f632023-03-20 10:13:55 -0500437 cd ${IMGDEPLOYDIR}
438 ln -sf ${IMAGE_NAME}.$type.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400439}
440
441do_generate_static_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500442 ln -sf ${S}/MANIFEST MANIFEST
443 ln -sf ${S}/publickey publickey
444 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
445 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
446 make_tar_of_images static.mtd MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400447
Patrick Williamsaf48f632023-03-20 10:13:55 -0500448 # Maintain non-standard legacy link.
449 cd ${IMGDEPLOYDIR}
450 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
Brad Bishop19fc4f82017-08-04 23:38:54 -0400451}
452do_generate_static_tar[dirs] = " ${S}/static"
453do_generate_static_tar[depends] += " \
454 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
455 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500456 u-boot:do_deploy \
Lei YUa4674942018-05-23 14:01:14 +0800457 openssl-native:do_populate_sysroot \
458 ${SIGNING_KEY_DEPENDS} \
459 ${PN}:do_copy_signing_pubkey \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400460 "
461do_generate_static_tar[vardepsexclude] = "DATETIME"
462
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600463python do_generate_static_norootfs() {
Patrick Williams917fab22023-03-10 16:58:50 -0600464 import hashlib
465 import json
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600466 import subprocess
467
Patrick Williams917fab22023-03-10 16:58:50 -0600468 manifest = {
469 "type": "phosphor-image-manifest",
470 "version": 1,
471 "info": {
472 "purpose": d.getVar('VERSION_PURPOSE', True),
473 "machine": d.getVar('MACHINE', True),
474 "version": do_get_version(d).strip('"'),
475 "build-id": do_get_buildID(d).strip('"'),
476 },
477 "partitions": [],
478 # Create an empty hash-value so that the dictionary can be emitted,
479 # hashed, and then updated.
480 "manifest-sha256": "",
481 }
482 extended_version = do_get_extended_version(d).strip('"')
483 if extended_version:
484 manifest["info"]["extended-version"] = extended_version
485 compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True)
486 if compatible_names:
487 manifest["info"]["compatible-names"] = compatible_names.split()
488
489 manifest_json_file = os.path.join(d.getVar('IMGDEPLOYDIR', True),
490 "phosphor-image-manifest.json")
491
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600492 nor_image_basename = '%s.static.mtd' % d.getVar('IMAGE_NAME', True)
493 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), nor_image_basename)
494
Patrick Williams917fab22023-03-10 16:58:50 -0600495 def _add_manifest(partname, typename, offset, size, sha256_value = None):
496 manifest["partitions"].append(
497 {
498 "name": partname,
499 "type": typename,
500 "offset": offset,
501 "size": size,
502 }
503 )
504 if typename == "fit":
505 if "u-boot-fit" == partname:
506 manifest["partitions"][-1]["num-nodes"] = 1
507 elif "os-fit" == partname:
508 manifest["partitions"][-1]["num-nodes"] = 3
509 else:
510 bb.fatal(f"Unknown FIT partition type: {partname}")
511 if sha256_value:
512 manifest["partitions"][-1]["sha256"] = sha256_value
513
514
515 def _append_image(partname, typename, imgpath, start_kb, finish_kb):
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600516 imgsize = os.path.getsize(imgpath)
517 maxsize = (finish_kb - start_kb) * 1024
518 bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath)
519 bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K')
520 bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize))
521 if imgsize > maxsize:
522 bb.fatal("Image '%s' is too large!" % imgpath)
523
Patrick Williams917fab22023-03-10 16:58:50 -0600524 with open(imgpath, "rb") as fp:
525 sha256 = hashlib.sha256(fp.read()).hexdigest()
526
527 _add_manifest(partname, typename, start_kb * 1024, imgsize, sha256)
528
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600529 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc',
530 'seek=%d' % start_kb,
531 'if=%s' % imgpath,
532 'of=%s' % nor_image])
Patrick Williams917fab22023-03-10 16:58:50 -0600533
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600534 uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True))
535
536 spl_binary = d.getVar('SPL_BINARY', True)
537 if spl_binary:
Patrick Williams917fab22023-03-10 16:58:50 -0600538 _append_image("spl", "u-boot",
539 os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600540 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)),
541 int(d.getVar('FLASH_UBOOT_OFFSET', True)),
542 int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)))
543 uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))
544
Patrick Williams917fab22023-03-10 16:58:50 -0600545 _append_image("u-boot-fit", "fit",
546 os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600547 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
548 uboot_offset,
Patrick Williams917fab22023-03-10 16:58:50 -0600549 int(d.getVar('FLASH_MANIFEST_OFFSET', True)))
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600550
Patrick Williams917fab22023-03-10 16:58:50 -0600551 _add_manifest("manifest", "json",
552 int(d.getVar('FLASH_MANIFEST_OFFSET', True)) * 1024,
553 (int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) -
554 int(d.getVar('FLASH_MANIFEST_OFFSET', True))) * 1024)
555
556 _add_manifest("u-boot-env", "data",
557 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) * 1024,
558 (int(d.getVar('FLASH_KERNEL_OFFSET', True)) -
559 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True))) * 1024)
560
561 _append_image("os-fit", "fit",
562 os.path.join(d.getVar('IMGDEPLOYDIR', True),
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600563 '%s.cpio.%s.fitImage' % (
564 d.getVar('IMAGE_LINK_NAME', True),
565 d.getVar('INITRAMFS_CTYPE', True))),
566 int(d.getVar('FLASH_KERNEL_OFFSET', True)),
567 int(d.getVar('FLASH_RWFS_OFFSET', True)))
568
Patrick Williams917fab22023-03-10 16:58:50 -0600569 _add_manifest("rwfs", "data",
570 int(d.getVar('FLASH_RWFS_OFFSET', True)) * 1024,
571 (int(d.getVar('FLASH_SIZE', True)) -
572 int(d.getVar('FLASH_RWFS_OFFSET', True))) * 1024)
573
574 # Calculate the sha256 of the current manifest and update.
575 manifest_raw = json.dumps(manifest, indent=4)
576 manifest_raw = manifest_raw[:manifest_raw.find("manifest-sha256")]
577 manifest["manifest-sha256"] = hashlib.sha256(
578 manifest_raw.encode('utf-8')).hexdigest()
579
580 # Write the final manifest json and add it to the image.
581 with open(manifest_json_file, "wb") as fp:
582 fp.write(json.dumps(manifest, indent=4).encode('utf-8'))
583 _append_image("manifest", "json", manifest_json_file,
584 int(d.getVar('FLASH_MANIFEST_OFFSET', True)),
585 int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)))
586
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600587 flash_symlink = os.path.join(
588 d.getVar('IMGDEPLOYDIR', True),
589 'flash-%s' % d.getVar('MACHINE', True))
590 if os.path.exists(flash_symlink):
591 os.remove(flash_symlink)
592 os.symlink(nor_image_basename, flash_symlink)
593}
594do_generate_static_norootfs[depends] += " \
595 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
596 u-boot:do_deploy \
597 "
598
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400599do_generate_ubi_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500600 ln -sf ${S}/MANIFEST MANIFEST
601 ln -sf ${S}/publickey publickey
602 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE}
603 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
604 make_tar_of_images ubi.mtd MANIFEST publickey ${signature_files}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400605}
606do_generate_ubi_tar[dirs] = " ${S}/ubi"
607do_generate_ubi_tar[depends] += " \
608 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
609 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500610 u-boot:do_deploy \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600611 openssl-native:do_populate_sysroot \
612 ${SIGNING_KEY_DEPENDS} \
613 ${PN}:do_copy_signing_pubkey \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400614 "
615
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500616do_generate_ext4_tar() {
Patrick Williamsaf48f632023-03-20 10:13:55 -0500617 # Generate the U-Boot image
618 mk_empty_image_zeros image-u-boot ${MMC_UBOOT_SIZE}
619 do_generate_image_uboot_file image-u-boot
Adriana Kobylak45a57952020-07-01 16:23:11 -0500620
Patrick Williamsaf48f632023-03-20 10:13:55 -0500621 # Generate a compressed ext4 filesystem with the fitImage file in it to be
622 # flashed to the boot partition of the eMMC
623 install -d boot-image
624 install -m 644 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} boot-image/fitImage
625 mk_empty_image_zeros boot-image.${FLASH_EXT4_BASETYPE} ${MMC_BOOT_PARTITION_SIZE}
626 mkfs.ext4 -F -i 4096 -d boot-image boot-image.${FLASH_EXT4_BASETYPE}
627 # Error codes 0-3 indicate successfull operation of fsck
628 fsck.ext4 -pvfD boot-image.${FLASH_EXT4_BASETYPE} || [ $? -le 3 ]
629 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 -0500630
Patrick Williamsaf48f632023-03-20 10:13:55 -0500631 # Generate the compressed ext4 rootfs
632 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 -0500633
Patrick Williamsaf48f632023-03-20 10:13:55 -0500634 ln -sf boot-image.${FLASH_EXT4_BASETYPE}.zst image-kernel
635 ln -sf ${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE}.zst image-rofs
636 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} image-rwfs
637 ln -sf ${S}/MANIFEST MANIFEST
638 ln -sf ${S}/publickey publickey
Adriana Kobylak81846a22020-07-12 15:12:36 -0500639
Patrick Williamsaf48f632023-03-20 10:13:55 -0500640 hostfw_update_file="${DEPLOY_DIR_IMAGE}/hostfw/update/image-hostfw"
641 if [ -e "${hostfw_update_file}" ]; then
642 ln -sf "${hostfw_update_file}" image-hostfw
643 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey image-hostfw
644 make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files} image-hostfw
645 else
646 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
647 make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files}
648 fi
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500649}
650do_generate_ext4_tar[dirs] = " ${S}/ext4"
651do_generate_ext4_tar[depends] += " \
Adriana Kobylak4cc866b2020-03-28 13:43:33 -0500652 zstd-native:do_populate_sysroot \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500653 ${PN}:do_image_${FLASH_EXT4_BASETYPE} \
654 virtual/kernel:do_deploy \
Brad Bishop209ed522020-11-02 12:36:04 -0500655 u-boot:do_deploy \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500656 openssl-native:do_populate_sysroot \
657 ${SIGNING_KEY_DEPENDS} \
658 ${PN}:do_copy_signing_pubkey \
Brad Bishop209ed522020-11-02 12:36:04 -0500659 phosphor-hostfw-image:do_deploy \
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500660 "
661
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600662def get_pubkey_basedir(d):
663 return os.path.join(
664 d.getVar('STAGING_DIR_TARGET', True),
665 d.getVar('sysconfdir', True).strip(os.sep),
666 'activationdata')
667
668def get_pubkey_type(d):
669 return os.listdir(get_pubkey_basedir(d))[0]
670
671def get_pubkey_path(d):
672 return os.path.join(
673 get_pubkey_basedir(d),
674 get_pubkey_type(d),
675 'publickey')
676
Brad Bishop19fc4f82017-08-04 23:38:54 -0400677python do_generate_phosphor_manifest() {
Adriana Kobylakfb62a682019-10-28 16:03:12 -0500678 purpose = d.getVar('VERSION_PURPOSE', True)
Saqib Khan41723472017-09-22 10:21:30 -0500679 version = do_get_version(d)
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +0000680 build_id = do_get_buildID(d)
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700681 target_machine = d.getVar('MACHINE', True)
Adriana Kobylakbde7dbe2022-08-04 09:13:26 -0500682 extended_version = do_get_extended_version(d)
Justin Ledfordb4de16d2022-03-24 17:27:17 -0700683 compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400684 with open('MANIFEST', 'w') as fd:
Adriana Kobylakfb62a682019-10-28 16:03:12 -0500685 fd.write('purpose={}\n'.format(purpose))
Brad Bishop19fc4f82017-08-04 23:38:54 -0400686 fd.write('version={}\n'.format(version.strip('"')))
Adriana Kobylakcdd91ad2021-10-25 15:58:19 +0000687 fd.write('BuildId={}\n'.format(build_id.strip('"')))
Justin Ledfordb4de16d2022-03-24 17:27:17 -0700688 if extended_version:
689 fd.write('ExtendedVersion={}\n'.format(extended_version))
690 if compatible_names:
691 for name in compatible_names.split():
692 fd.write('CompatibleName={}\n'.format(name))
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600693 fd.write('KeyType={}\n'.format(get_pubkey_type(d)))
694 fd.write('HashType=RSA-SHA256\n')
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700695 fd.write('MachineName={}\n'.format(target_machine))
Brad Bishop19fc4f82017-08-04 23:38:54 -0400696}
697do_generate_phosphor_manifest[dirs] = "${S}"
698do_generate_phosphor_manifest[depends] += " \
699 os-release:do_populate_sysroot \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600700 phosphor-image-signing:do_populate_sysroot \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400701 "
702
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600703python do_copy_signing_pubkey() {
704 with open(get_pubkey_path(d), 'r') as read_fd:
705 with open('publickey', 'w') as write_fd:
706 write_fd.write(read_fd.read())
707}
708
709do_copy_signing_pubkey[dirs] = "${S}"
710do_copy_signing_pubkey[depends] += " \
711 phosphor-image-signing:do_populate_sysroot \
712 "
713
714addtask copy_signing_pubkey after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400715addtask generate_phosphor_manifest after do_rootfs
716addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400717addtask generate_rwfs_ubi after do_rootfs
Adriana Kobylak5a5753a2019-07-30 11:27:46 -0500718addtask generate_rwfs_ext4 after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400719
720python() {
721 types = d.getVar('IMAGE_FSTYPES', True).split()
722
723 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
724 bb.build.addtask(
725 'do_generate_static',
726 'do_image_complete',
727 'do_generate_rwfs_static', d)
728 if 'mtd-static-alltar' in types:
729 bb.build.addtask(
730 'do_generate_static_alltar',
731 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800732 'do_generate_static do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400733 if 'mtd-static-tar' in types:
734 bb.build.addtask(
735 'do_generate_static_tar',
736 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800737 'do_generate_rwfs_static do_generate_phosphor_manifest', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400738
Patrick Williamsb9e124c2022-12-14 09:10:49 -0600739 if 'mtd-static-norootfs' in types:
740 bb.build.addtask(
741 'do_generate_static_norootfs',
742 'do_image_complete',
743 'do_image_cpio', d)
744
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400745 if 'mtd-ubi' in types:
746 bb.build.addtask(
747 'do_generate_ubi',
748 'do_image_complete',
749 'do_generate_rwfs_ubi', d)
750 if 'mtd-ubi-tar' in types:
751 bb.build.addtask(
752 'do_generate_ubi_tar',
753 'do_image_complete',
754 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Adriana Kobylak9b7197e2019-07-29 15:25:33 -0500755
756 if 'mmc-ext4-tar' in types:
757 bb.build.addtask(
758 'do_generate_ext4_tar',
759 'do_image_complete',
760 'do_generate_rwfs_ext4 do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400761}