blob: d5ace1610a23b5e88ee57ba5f311afabc2707d08 [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 Bishop1a4b7ee2018-12-16 17:11:34 -080012FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE}"
Brad Bishop8623bbe2018-03-09 00:04:00 -050013FLASH_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 Bishopdcd861c2019-09-24 21:16:09 -040030DISTROOVERRIDES .= ":flash-${FLASH_SIZE}"
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 Bishopdcd861c2019-09-24 21:16:09 -040040FLASH_KERNEL_OFFSET_flash-131072 ?= "1024"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040041FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040042FLASH_ROFS_OFFSET ?= "4864"
Brad Bishopdcd861c2019-09-24 21:16:09 -040043FLASH_ROFS_OFFSET_flash-131072 ?= "10240"
Brad Bishop19fc4f82017-08-04 23:38:54 -040044FLASH_RWFS_OFFSET ?= "28672"
Brad Bishopdcd861c2019-09-24 21:16:09 -040045FLASH_RWFS_OFFSET_flash-131072 ?= "98304"
Brad Bishop19fc4f82017-08-04 23:38:54 -040046
Brad Bishop3aa1ef62017-08-04 23:48:12 -040047# UBI volume sizes in KB unless otherwise noted.
Adriana Kobylakb70005d2018-02-14 16:35:30 -060048FLASH_UBI_RWFS_SIZE ?= "6144"
Brad Bishopdcd861c2019-09-24 21:16:09 -040049FLASH_UBI_RWFS_SIZE_flash-131072 ?= "32768"
Adriana Kobylakb70005d2018-02-14 16:35:30 -060050FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB"
Brad Bishopdcd861c2019-09-24 21:16:09 -040051FLASH_UBI_RWFS_TXT_SIZE_flash-131072 ?= "32MiB"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040052
Eddie Jamesb2b7ff62018-02-09 11:59:18 -060053SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv"
54INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}"
55SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}"
56
Brad Bishop3e37d382018-03-31 12:17:28 -040057UBOOT_SUFFIX ?= "bin"
58
Brad Bishop3aa1ef62017-08-04 23:48:12 -040059python() {
60 # Compute rwfs LEB count and LEB size.
61 page_size = d.getVar('FLASH_PAGE_SIZE', True)
62 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True)
63 overhead_size = max(int(page_size), int(nor_overhead_size))
64 peb_size = d.getVar('FLASH_PEB_SIZE', True)
65 leb_size = (int(peb_size) * 1024) - (2 * overhead_size)
66 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes
67
68 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True)
69 rwfs_size = int(rwfs_size) * 1024
70 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up
71 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs))
72}
73
Brad Bishop19fc4f82017-08-04 23:38:54 -040074# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
75# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
76# reserved for the primary image (and setting them currently breaks the build).
77# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
78DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040079DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040080
William A. Kennington IIIc230ab32019-09-16 17:44:48 -070081JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2"
82UBIFS_RWFS_CMD = "mkfs.ubifs -r ubifs -c ${FLASH_UBI_RWFS_LEBS} -m ${FLASH_PAGE_SIZE} -e ${FLASH_LEB_SIZE} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubifs"
Brad Bishop19fc4f82017-08-04 23:38:54 -040083
84FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
Brad Bishop3aa1ef62017-08-04 23:48:12 -040085FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
86FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}"
Brad Bishop19fc4f82017-08-04 23:38:54 -040087
Adriana Kobylak661cf392019-07-29 14:39:00 -050088mk_empty_image() {
Brad Bishop19fc4f82017-08-04 23:38:54 -040089 image_dst="$1"
90 image_size_kb=$2
91 dd if=/dev/zero bs=1k count=$image_size_kb \
92 | tr '\000' '\377' > $image_dst
93}
94
95make_rwfs() {
96 type=$1
97 cmd=$2
98 shift
99 shift
100 opts="$@"
101
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700102 rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type
Brad Bishop19fc4f82017-08-04 23:38:54 -0400103 rm -rf $type
104 mkdir $type
105
106 $cmd $opts
107}
108
109do_generate_rwfs_static() {
110 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
111}
112do_generate_rwfs_static[dirs] = " ${S}/static"
113do_generate_rwfs_static[depends] += " \
114 mtd-utils-native:do_populate_sysroot \
115 "
116
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400117do_generate_rwfs_ubi() {
118 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}"
119}
120do_generate_rwfs_ubi[dirs] = " ${S}/ubi"
121do_generate_rwfs_ubi[depends] += " \
122 mtd-utils-native:do_populate_sysroot \
123 "
124
125add_volume() {
126 config_file=$1
127 vol_id=$2
128 vol_type=$3
129 vol_name=$4
130 image=$5
131 vol_size=$6
132
133 echo \[$vol_name\] >> $config_file
134 echo mode=ubi >> $config_file
135 echo image=$image >> $config_file
136 echo vol_type=$vol_type >> $config_file
137 echo vol_name=$vol_name >> $config_file
138 echo vol_id=$vol_id >> $config_file
139 if [ ! -z $vol_size ]; then
140 echo vol_size=$vol_size >> $config_file
141 fi
142}
143
Saqib Khan41723472017-09-22 10:21:30 -0500144python do_generate_ubi() {
145 version_id = do_get_versionID(d)
146 d.setVar('VERSION_ID', version_id)
147 bb.build.exec_func("do_make_ubi", d)
148}
149do_generate_ubi[dirs] = "${S}/ubi"
150do_generate_ubi[depends] += " \
151 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
152 virtual/kernel:do_deploy \
153 u-boot:do_populate_sysroot \
154 mtd-utils-native:do_populate_sysroot \
155 "
156
157do_make_ubi() {
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400158 cfg=ubinize-${IMAGE_NAME}.cfg
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400159 rm -f $cfg ubi-img
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400160 # Construct the ubinize config file
Saqib Khan41723472017-09-22 10:21:30 -0500161 add_volume $cfg 0 static kernel-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400162 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE}
163
Saqib Khan41723472017-09-22 10:21:30 -0500164 add_volume $cfg 1 static rofs-${VERSION_ID} \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400165 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE}
166
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700167 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 -0400168
169 # Build the ubi partition image
170 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg
171
172 # Concatenate the uboot and ubi partitions
Adriana Kobylak661cf392019-07-29 14:39:00 -0500173 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400174 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \
175 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \
176 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
177 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \
178 if=ubi-img \
179 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd
180
181 cd ${IMGDEPLOYDIR}
182 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd
183}
Saqib Khan41723472017-09-22 10:21:30 -0500184do_make_ubi[dirs] = "${S}/ubi"
185do_make_ubi[depends] += " \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400186 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
187 virtual/kernel:do_deploy \
188 u-boot:do_populate_sysroot \
189 mtd-utils-native:do_populate_sysroot \
190 "
191
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300192do_mk_static_nor_image() {
Brad Bishop19fc4f82017-08-04 23:38:54 -0400193 # Assemble the flash image
Adriana Kobylak661cf392019-07-29 14:39:00 -0500194 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE}
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300195}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400196
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300197python do_generate_static() {
198 import subprocess
Brad Bishop19fc4f82017-08-04 23:38:54 -0400199
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300200 bb.build.exec_func("do_mk_static_nor_image", d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400201
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300202 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True),
203 '%s.static.mtd' % d.getVar('IMAGE_NAME', True))
204
205 def _append_image(imgpath, start_kb, finish_kb):
206 imgsize = os.path.getsize(imgpath)
207 if imgsize > (finish_kb - start_kb) * 1024:
208 bb.fatal("Image '%s' is too large!" % imgpath)
209
210 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc',
211 'seek=%d' % start_kb,
212 'if=%s' % imgpath,
213 'of=%s' % nor_image])
214
215 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
216 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)),
217 int(d.getVar('FLASH_UBOOT_OFFSET', True)),
218 int(d.getVar('FLASH_KERNEL_OFFSET', True)))
219
220 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True),
221 d.getVar('FLASH_KERNEL_IMAGE', True)),
222 int(d.getVar('FLASH_KERNEL_OFFSET', True)),
223 int(d.getVar('FLASH_ROFS_OFFSET', True)))
224
225 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
226 '%s.%s' % (
227 d.getVar('IMAGE_LINK_NAME', True),
228 d.getVar('IMAGE_BASETYPE', True))),
229 int(d.getVar('FLASH_ROFS_OFFSET', True)),
230 int(d.getVar('FLASH_RWFS_OFFSET', True)))
231
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700232 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True),
233 '%s.%s' % (
234 d.getVar('IMAGE_LINK_NAME', True),
235 d.getVar('OVERLAY_BASETYPE', True))),
Alexander Filippov3dcf6f92018-07-17 16:41:37 +0300236 int(d.getVar('FLASH_RWFS_OFFSET', True)),
237 int(d.getVar('FLASH_SIZE', True)))
238
239 bb.build.exec_func("do_mk_static_symlinks", d)
240}
241
242do_mk_static_symlinks() {
Brad Bishop19fc4f82017-08-04 23:38:54 -0400243 cd ${IMGDEPLOYDIR}
244 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
245
246 # Maintain non-standard legacy links
247 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
248 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
249 ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
250 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
251 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700252 ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400253}
254do_generate_static[dirs] = "${S}/static"
255do_generate_static[depends] += " \
256 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
257 virtual/kernel:do_deploy \
258 u-boot:do_populate_sysroot \
259 "
260
Lei YUf2072212018-06-20 13:27:34 +0800261make_signatures() {
262 signature_files=""
263 for file in "$@"; do
264 openssl dgst -sha256 -sign ${SIGNING_KEY} -out "${file}.sig" $file
265 signature_files="${signature_files} ${file}.sig"
266 done
267}
268
Brad Bishop19fc4f82017-08-04 23:38:54 -0400269do_generate_static_alltar() {
Lei YUa4674942018-05-23 14:01:14 +0800270 ln -sf ${S}/MANIFEST MANIFEST
271 ln -sf ${S}/publickey publickey
Brad Bishop19fc4f82017-08-04 23:38:54 -0400272 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
Lei YUa4674942018-05-23 14:01:14 +0800273
Lei YUf2072212018-06-20 13:27:34 +0800274 make_signatures image-bmc MANIFEST publickey
Lei YUa4674942018-05-23 14:01:14 +0800275
276 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \
277 image-bmc MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400278
279 cd ${IMGDEPLOYDIR}
280
281 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
282 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
283
284 # Maintain non-standard legacy link.
285 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
286 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
Lei YUa4674942018-05-23 14:01:14 +0800287
Brad Bishop19fc4f82017-08-04 23:38:54 -0400288}
289do_generate_static_alltar[vardepsexclude] = "DATETIME"
290do_generate_static_alltar[dirs] = "${S}/static"
Lei YUa4674942018-05-23 14:01:14 +0800291do_generate_static_alltar[depends] += " \
292 openssl-native:do_populate_sysroot \
293 ${SIGNING_KEY_DEPENDS} \
294 ${PN}:do_copy_signing_pubkey \
295 "
Brad Bishop19fc4f82017-08-04 23:38:54 -0400296
Brad Bishopde659382018-03-30 01:46:16 -0400297make_image_links() {
Brad Bishop19fc4f82017-08-04 23:38:54 -0400298 rwfs=$1
299 rofs=$2
Brad Bishop19fc4f82017-08-04 23:38:54 -0400300 shift
301 shift
Brad Bishop19fc4f82017-08-04 23:38:54 -0400302
Brad Bishopde659382018-03-30 01:46:16 -0400303 # Create some links to help make the tar archive in the format
304 # expected by phosphor-bmc-code-mgmt.
Brad Bishop19fc4f82017-08-04 23:38:54 -0400305 ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
306 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
307 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
William A. Kennington IIIc230ab32019-09-16 17:44:48 -0700308 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs
Brad Bishopde659382018-03-30 01:46:16 -0400309}
310
311make_tar_of_images() {
312 type=$1
313 shift
314 extra_files="$@"
Brad Bishop19fc4f82017-08-04 23:38:54 -0400315
316 # Create the tar archive
317 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
318 image-u-boot image-kernel image-rofs image-rwfs $extra_files
319
320 cd ${IMGDEPLOYDIR}
321 ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
322}
323
324do_generate_static_tar() {
Lei YUa4674942018-05-23 14:01:14 +0800325 ln -sf ${S}/MANIFEST MANIFEST
326 ln -sf ${S}/publickey publickey
Brad Bishopde659382018-03-30 01:46:16 -0400327 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE}
Lei YUf2072212018-06-20 13:27:34 +0800328 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
Lei YUa4674942018-05-23 14:01:14 +0800329 make_tar_of_images static MANIFEST publickey ${signature_files}
Brad Bishop19fc4f82017-08-04 23:38:54 -0400330
331 # Maintain non-standard legacy link.
332 cd ${IMGDEPLOYDIR}
333 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
334}
335do_generate_static_tar[dirs] = " ${S}/static"
336do_generate_static_tar[depends] += " \
337 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
338 virtual/kernel:do_deploy \
339 u-boot:do_populate_sysroot \
Lei YUa4674942018-05-23 14:01:14 +0800340 openssl-native:do_populate_sysroot \
341 ${SIGNING_KEY_DEPENDS} \
342 ${PN}:do_copy_signing_pubkey \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400343 "
344do_generate_static_tar[vardepsexclude] = "DATETIME"
345
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400346do_generate_ubi_tar() {
347 ln -sf ${S}/MANIFEST MANIFEST
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600348 ln -sf ${S}/publickey publickey
Brad Bishopde659382018-03-30 01:46:16 -0400349 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE}
Lei YUf2072212018-06-20 13:27:34 +0800350 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey
351 make_tar_of_images ubi MANIFEST publickey ${signature_files}
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400352}
353do_generate_ubi_tar[dirs] = " ${S}/ubi"
354do_generate_ubi_tar[depends] += " \
355 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \
356 virtual/kernel:do_deploy \
357 u-boot:do_populate_sysroot \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600358 openssl-native:do_populate_sysroot \
359 ${SIGNING_KEY_DEPENDS} \
360 ${PN}:do_copy_signing_pubkey \
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400361 "
362
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600363def get_pubkey_basedir(d):
364 return os.path.join(
365 d.getVar('STAGING_DIR_TARGET', True),
366 d.getVar('sysconfdir', True).strip(os.sep),
367 'activationdata')
368
369def get_pubkey_type(d):
370 return os.listdir(get_pubkey_basedir(d))[0]
371
372def get_pubkey_path(d):
373 return os.path.join(
374 get_pubkey_basedir(d),
375 get_pubkey_type(d),
376 'publickey')
377
Brad Bishop19fc4f82017-08-04 23:38:54 -0400378python do_generate_phosphor_manifest() {
Saqib Khan41723472017-09-22 10:21:30 -0500379 version = do_get_version(d)
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700380 target_machine = d.getVar('MACHINE', True)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400381 with open('MANIFEST', 'w') as fd:
382 fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
383 fd.write('version={}\n'.format(version.strip('"')))
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600384 fd.write('KeyType={}\n'.format(get_pubkey_type(d)))
385 fd.write('HashType=RSA-SHA256\n')
Vijay Khemkaae614bd2019-09-18 12:28:46 -0700386 fd.write('MachineName={}\n'.format(target_machine))
Brad Bishop19fc4f82017-08-04 23:38:54 -0400387}
388do_generate_phosphor_manifest[dirs] = "${S}"
389do_generate_phosphor_manifest[depends] += " \
390 os-release:do_populate_sysroot \
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600391 phosphor-image-signing:do_populate_sysroot \
Brad Bishop19fc4f82017-08-04 23:38:54 -0400392 "
393
Eddie Jamesb2b7ff62018-02-09 11:59:18 -0600394python do_copy_signing_pubkey() {
395 with open(get_pubkey_path(d), 'r') as read_fd:
396 with open('publickey', 'w') as write_fd:
397 write_fd.write(read_fd.read())
398}
399
400do_copy_signing_pubkey[dirs] = "${S}"
401do_copy_signing_pubkey[depends] += " \
402 phosphor-image-signing:do_populate_sysroot \
403 "
404
405addtask copy_signing_pubkey after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400406addtask generate_phosphor_manifest after do_rootfs
407addtask generate_rwfs_static after do_rootfs
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400408addtask generate_rwfs_ubi after do_rootfs
Brad Bishop19fc4f82017-08-04 23:38:54 -0400409
410python() {
411 types = d.getVar('IMAGE_FSTYPES', True).split()
412
413 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
414 bb.build.addtask(
415 'do_generate_static',
416 'do_image_complete',
417 'do_generate_rwfs_static', d)
418 if 'mtd-static-alltar' in types:
419 bb.build.addtask(
420 'do_generate_static_alltar',
421 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800422 'do_generate_static do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400423 if 'mtd-static-tar' in types:
424 bb.build.addtask(
425 'do_generate_static_tar',
426 'do_image_complete',
Lei YUa4674942018-05-23 14:01:14 +0800427 'do_generate_rwfs_static do_generate_phosphor_manifest', d)
Brad Bishop3aa1ef62017-08-04 23:48:12 -0400428
429 if 'mtd-ubi' in types:
430 bb.build.addtask(
431 'do_generate_ubi',
432 'do_image_complete',
433 'do_generate_rwfs_ubi', d)
434 if 'mtd-ubi-tar' in types:
435 bb.build.addtask(
436 'do_generate_ubi_tar',
437 'do_image_complete',
438 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d)
Brad Bishop19fc4f82017-08-04 23:38:54 -0400439}