1# Base image class extension, inlined into every image. 2 3inherit image_version 4 5# Phosphor image types 6# 7# 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. 10 11# Image composition 12FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE}" 13FLASH_KERNEL_IMAGE_df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin" 14 15IMAGE_BASETYPE ?= "squashfs-xz" 16OVERLAY_BASETYPE ?= "jffs2" 17FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}" 18FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs" 19FLASH_EXT4_BASETYPE ?= "ext4" 20FLASH_EXT4_OVERLAY_BASETYPE ?= "ext4" 21 22IMAGE_TYPES += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar mmc-verity mmc-ext4-tar" 23 24IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}" 25IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}" 26IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static" 27IMAGE_TYPEDEP_mtd-ubi = "${FLASH_UBI_BASETYPE}" 28IMAGE_TYPEDEP_mtd-ubi-tar = "${FLASH_UBI_BASETYPE}" 29IMAGE_TYPEDEP_mmc-verity = "${FLASH_EXT4_BASETYPE}" 30IMAGE_TYPEDEP_mmc-ext4-tar = "${FLASH_EXT4_BASETYPE}" 31IMAGE_TYPES_MASKED += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar mmc-verity mmc-ext4-tar" 32 33IMAGE_BLOCK_SIZE ?= "4096" 34EXTRA_IMAGECMD_ext4 = "-b ${IMAGE_BLOCK_SIZE}" 35 36# Flash characteristics in KB unless otherwise noted 37DISTROOVERRIDES .= ":flash-${FLASH_SIZE}" 38FLASH_SIZE ?= "32768" 39FLASH_PEB_SIZE ?= "64" 40# Flash page and overhead sizes in bytes 41FLASH_PAGE_SIZE ?= "1" 42FLASH_NOR_UBI_OVERHEAD ?= "64" 43 44# Fixed partition offsets 45FLASH_UBOOT_SPL_SIZE ?= "64" 46FLASH_UBOOT_OFFSET ?= "0" 47FLASH_KERNEL_OFFSET ?= "512" 48FLASH_KERNEL_OFFSET_flash-131072 ?= "1024" 49FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}" 50FLASH_ROFS_OFFSET ?= "4864" 51FLASH_ROFS_OFFSET_flash-131072 ?= "10240" 52FLASH_RWFS_OFFSET ?= "28672" 53FLASH_RWFS_OFFSET_flash-131072 ?= "98304" 54 55# UBI volume sizes in KB unless otherwise noted. 56FLASH_UBI_RWFS_SIZE ?= "6144" 57FLASH_UBI_RWFS_SIZE_flash-131072 ?= "32768" 58FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB" 59FLASH_UBI_RWFS_TXT_SIZE_flash-131072 ?= "32MiB" 60 61SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv" 62INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}" 63SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}" 64 65VERSION_PURPOSE ?= "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" 66 67UBOOT_SUFFIX ?= "bin" 68 69python() { 70 # Compute rwfs LEB count and LEB size. 71 page_size = d.getVar('FLASH_PAGE_SIZE', True) 72 nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True) 73 overhead_size = max(int(page_size), int(nor_overhead_size)) 74 peb_size = d.getVar('FLASH_PEB_SIZE', True) 75 leb_size = (int(peb_size) * 1024) - (2 * overhead_size) 76 d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes 77 78 rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True) 79 rwfs_size = int(rwfs_size) * 1024 80 lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up 81 d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs)) 82} 83 84# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However, 85# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are 86# reserved for the primary image (and setting them currently breaks the build). 87# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions. 88DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}" 89DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}" 90DISTROOVERRIDES .= ":mmc-rwfs-${FLASH_EXT4_OVERLAY_BASETYPE}" 91 92JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2" 93UBIFS_RWFS_CMD = "mkfs.ubifs -r ubifs -c ${FLASH_UBI_RWFS_LEBS} -m ${FLASH_PAGE_SIZE} -e ${FLASH_LEB_SIZE} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubifs" 94EXT4_RWFS_CMD = "mkfs.ext4 -F ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4" 95 96FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" 97FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" 98FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}" 99FLASH_EXT4_RWFS_CMD_mmc-rwfs-ext4 = "${EXT4_RWFS_CMD}" 100 101mk_empty_image() { 102 image_dst="$1" 103 image_size_kb=$2 104 dd if=/dev/zero bs=1k count=$image_size_kb \ 105 | tr '\000' '\377' > $image_dst 106} 107 108clean_rwfs() { 109 type=$1 110 shift 111 112 rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type 113 rm -rf $type 114 mkdir $type 115} 116 117make_rwfs() { 118 type=$1 119 cmd=$2 120 shift 121 shift 122 opts="$@" 123 124 mkdir -p $type 125 126 $cmd $opts 127} 128 129do_generate_rwfs_static() { 130 clean_rwfs ${OVERLAY_BASETYPE} 131 make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS} 132} 133do_generate_rwfs_static[dirs] = " ${S}/static" 134do_generate_rwfs_static[depends] += " \ 135 mtd-utils-native:do_populate_sysroot \ 136 " 137 138do_generate_rwfs_ubi() { 139 clean_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} 140 make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}" 141} 142do_generate_rwfs_ubi[dirs] = " ${S}/ubi" 143do_generate_rwfs_ubi[depends] += " \ 144 mtd-utils-native:do_populate_sysroot \ 145 " 146 147do_generate_rwfs_ext4() { 148 clean_rwfs rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} 149 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4 1024 150 make_rwfs ${FLASH_EXT4_OVERLAY_BASETYPE} "${FLASH_EXT4_RWFS_CMD}" ${OVERLAY_MKFS_OPTS} 151} 152do_generate_rwfs_ext4[dirs] = " ${S}/ext4" 153do_generate_rwfs_ext4[depends] += " \ 154 e2fsprogs-native:do_populate_sysroot \ 155 " 156 157add_volume() { 158 config_file=$1 159 vol_id=$2 160 vol_type=$3 161 vol_name=$4 162 image=$5 163 vol_size=$6 164 165 echo \[$vol_name\] >> $config_file 166 echo mode=ubi >> $config_file 167 echo image=$image >> $config_file 168 echo vol_type=$vol_type >> $config_file 169 echo vol_name=$vol_name >> $config_file 170 echo vol_id=$vol_id >> $config_file 171 if [ ! -z $vol_size ]; then 172 echo vol_size=$vol_size >> $config_file 173 fi 174} 175 176python do_generate_ubi() { 177 version_id = do_get_versionID(d) 178 d.setVar('VERSION_ID', version_id) 179 bb.build.exec_func("do_make_ubi", d) 180} 181do_generate_ubi[dirs] = "${S}/ubi" 182do_generate_ubi[depends] += " \ 183 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ 184 virtual/kernel:do_deploy \ 185 u-boot:do_populate_sysroot \ 186 mtd-utils-native:do_populate_sysroot \ 187 " 188 189do_make_ubi() { 190 cfg=ubinize-${IMAGE_NAME}.cfg 191 rm -f $cfg ubi-img 192 # Construct the ubinize config file 193 add_volume $cfg 0 static kernel-${VERSION_ID} \ 194 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} 195 196 add_volume $cfg 1 static rofs-${VERSION_ID} \ 197 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE} 198 199 add_volume $cfg 2 dynamic rwfs ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE} 200 201 # Build the ubi partition image 202 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg 203 204 # Concatenate the uboot and ubi partitions 205 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE} 206 dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \ 207 if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \ 208 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd 209 dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \ 210 if=ubi-img \ 211 of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd 212 213 cd ${IMGDEPLOYDIR} 214 ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd 215} 216do_make_ubi[dirs] = "${S}/ubi" 217do_make_ubi[depends] += " \ 218 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ 219 virtual/kernel:do_deploy \ 220 u-boot:do_populate_sysroot \ 221 mtd-utils-native:do_populate_sysroot \ 222 " 223 224python do_generate_mmc_verity() { 225 import os 226 import subprocess 227 228 rootfs_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), 229 '%s.%s' % ( 230 d.getVar('IMAGE_LINK_NAME', True), 231 d.getVar('FLASH_EXT4_BASETYPE', True))) 232 233 verity_image = 'verity-%s.%s' % ( 234 d.getVar('IMAGE_LINK_NAME', True), 235 d.getVar('FLASH_EXT4_BASETYPE', True)) 236 237 subprocess.check_call(['dd', 238 'if=%s' % rootfs_image, 239 'of=%s' % verity_image]) 240 241 # dm-verity values 242 sector_size = 512 243 block_size = int(d.getVar('IMAGE_BLOCK_SIZE', True)) 244 verity_algo = "sha256" 245 rootfs_image_size = os.stat(rootfs_image).st_size 246 247 def align_up(number, boundary): 248 return ((number + (boundary - 1)) // boundary) * boundary 249 250 # verity metadata must be aligned on the block boundary subsequent to the 251 # end of the data 252 verity_hash_offset = align_up(rootfs_image_size, block_size) 253 254 verity_hash_blocks = verity_hash_offset // block_size 255 256 # the output of 'veritysetup format' looks like: 257 # VERITY header information for obmc-phosphor-image-witherspoon.squashfs-xz 258 # UUID: 269b5934-de5b-45b0-99a3-56b219a7b544 259 # Hash type: 1 260 # Data blocks: 4523 261 # Data block size: 4096 262 # Hash block size: 4096 263 # Hash algorithm: sha256 264 # Salt: 8fca9eff342fc0cf2964057257ea80813a223cb2e540a38458142edeb190e12e 265 # Root hash: 38ef00d23fa89300dcf66e7494d25246d03bf846b4119b34e7b1587c0b6fe1d9 266 verity_hash_file = "verity-hash-verification-data" 267 with open(verity_hash_file, 'w') as f: 268 subprocess.check_call(['veritysetup', 269 'format', 270 '--hash=%s'% verity_algo, 271 '--data-block-size=%i' % block_size, 272 '--hash-block-size=%i' % block_size, 273 '--hash-offset=%i' % verity_hash_offset, 274 '%s' % verity_image, 275 '%s' % verity_image], stdout=f, stderr=f) 276 277 for line in open(verity_hash_file, "r"): 278 if "Salt" in line: 279 verity_salt = line.split()[-1] 280 if "Root" in line: 281 verity_root = line.split()[-1] 282 283 verity_image_size = os.stat(verity_image).st_size 284 285 # Make an appropriately sized image for MMC 286 mmc_image_name = "%s.mmc" % d.getVar('IMAGE_NAME', True) 287 mmc_image_path = os.path.join(d.getVar('IMGDEPLOYDIR', True), 288 '%s' % mmc_image_name) 289 290 # CSD size accommodates MMC limitations that are relevant to QEMU 291 csd_size = (1 << (9 + 9 - 1 + 2)) 292 293 with open(mmc_image_path, 'w') as fd: 294 os.posix_fallocate(fd.fileno(), 0, align_up(verity_image_size, csd_size)) 295 subprocess.check_call(['dd', 296 'if=%s' % verity_image, 297 'of=%s' % mmc_image_path, 298 'conv=notrunc']) 299 300 os.chdir("%s" % d.getVar('IMGDEPLOYDIR', True)) 301 mmc_link_name = os.path.join(d.getVar('IMGDEPLOYDIR', True), 302 '%s.mmc' % d.getVar('IMAGE_LINK_NAME', True)) 303 if os.path.lexists(mmc_link_name): 304 os.remove(mmc_link_name) 305 os.symlink(mmc_image_name, mmc_link_name) 306} 307do_generate_mmc_verity[dirs] = "${S}/mmc" 308do_generate_mmc_verity[depends] += " \ 309 ${PN}:do_image_${FLASH_EXT4_BASETYPE} \ 310 cryptsetup-native:do_populate_sysroot \ 311 " 312 313do_mk_static_nor_image() { 314 # Assemble the flash image 315 mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE} 316} 317 318python do_generate_static() { 319 import subprocess 320 321 bb.build.exec_func("do_mk_static_nor_image", d) 322 323 nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), 324 '%s.static.mtd' % d.getVar('IMAGE_NAME', True)) 325 326 def _append_image(imgpath, start_kb, finish_kb): 327 imgsize = os.path.getsize(imgpath) 328 maxsize = (finish_kb - start_kb) * 1024 329 bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath) 330 bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K') 331 bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize)) 332 if imgsize > maxsize: 333 bb.fatal("Image '%s' is too large!" % imgpath) 334 335 subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc', 336 'seek=%d' % start_kb, 337 'if=%s' % imgpath, 338 'of=%s' % nor_image]) 339 340 uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True)) 341 342 spl_binary = d.getVar('SPL_BINARY', True) 343 if spl_binary: 344 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 345 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)), 346 int(d.getVar('FLASH_UBOOT_OFFSET', True)), 347 int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))) 348 uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)) 349 350 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 351 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)), 352 uboot_offset, 353 int(d.getVar('FLASH_KERNEL_OFFSET', True))) 354 355 _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), 356 d.getVar('FLASH_KERNEL_IMAGE', True)), 357 int(d.getVar('FLASH_KERNEL_OFFSET', True)), 358 int(d.getVar('FLASH_ROFS_OFFSET', True))) 359 360 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), 361 '%s.%s' % ( 362 d.getVar('IMAGE_LINK_NAME', True), 363 d.getVar('IMAGE_BASETYPE', True))), 364 int(d.getVar('FLASH_ROFS_OFFSET', True)), 365 int(d.getVar('FLASH_RWFS_OFFSET', True))) 366 367 _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), 368 '%s.%s' % ( 369 d.getVar('IMAGE_LINK_NAME', True), 370 d.getVar('OVERLAY_BASETYPE', True))), 371 int(d.getVar('FLASH_RWFS_OFFSET', True)), 372 int(d.getVar('FLASH_SIZE', True))) 373 374 bb.build.exec_func("do_mk_static_symlinks", d) 375} 376 377do_mk_static_symlinks() { 378 cd ${IMGDEPLOYDIR} 379 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd 380 381 # Maintain non-standard legacy links 382 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE} 383 ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc 384 ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot 385 ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel 386 ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs 387 ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs 388} 389do_generate_static[dirs] = "${S}/static" 390do_generate_static[depends] += " \ 391 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ 392 virtual/kernel:do_deploy \ 393 u-boot:do_populate_sysroot \ 394 " 395 396make_signatures() { 397 signature_files="" 398 for file in "$@"; do 399 openssl dgst -sha256 -sign ${SIGNING_KEY} -out "${file}.sig" $file 400 signature_files="${signature_files} ${file}.sig" 401 done 402} 403 404do_generate_static_alltar() { 405 ln -sf ${S}/MANIFEST MANIFEST 406 ln -sf ${S}/publickey publickey 407 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc 408 409 make_signatures image-bmc MANIFEST publickey 410 411 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \ 412 image-bmc MANIFEST publickey ${signature_files} 413 414 cd ${IMGDEPLOYDIR} 415 416 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ 417 ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar 418 419 # Maintain non-standard legacy link. 420 ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ 421 ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar 422 423} 424do_generate_static_alltar[vardepsexclude] = "DATETIME" 425do_generate_static_alltar[dirs] = "${S}/static" 426do_generate_static_alltar[depends] += " \ 427 openssl-native:do_populate_sysroot \ 428 ${SIGNING_KEY_DEPENDS} \ 429 ${PN}:do_copy_signing_pubkey \ 430 " 431 432make_image_links() { 433 rwfs=$1 434 rofs=$2 435 shift 436 shift 437 438 # Create some links to help make the tar archive in the format 439 # expected by phosphor-bmc-code-mgmt. 440 ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot 441 ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel 442 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs 443 ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs 444} 445 446make_tar_of_images() { 447 type=$1 448 shift 449 extra_files="$@" 450 451 # Create the tar archive 452 tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.tar \ 453 image-u-boot image-kernel image-rofs image-rwfs $extra_files 454 455 cd ${IMGDEPLOYDIR} 456 ln -sf ${IMAGE_NAME}.$type.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.tar 457} 458 459do_generate_static_tar() { 460 ln -sf ${S}/MANIFEST MANIFEST 461 ln -sf ${S}/publickey publickey 462 make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE} 463 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey 464 make_tar_of_images static.mtd MANIFEST publickey ${signature_files} 465 466 # Maintain non-standard legacy link. 467 cd ${IMGDEPLOYDIR} 468 ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar 469} 470do_generate_static_tar[dirs] = " ${S}/static" 471do_generate_static_tar[depends] += " \ 472 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ 473 virtual/kernel:do_deploy \ 474 u-boot:do_populate_sysroot \ 475 openssl-native:do_populate_sysroot \ 476 ${SIGNING_KEY_DEPENDS} \ 477 ${PN}:do_copy_signing_pubkey \ 478 " 479do_generate_static_tar[vardepsexclude] = "DATETIME" 480 481do_generate_ubi_tar() { 482 ln -sf ${S}/MANIFEST MANIFEST 483 ln -sf ${S}/publickey publickey 484 make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE} 485 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey 486 make_tar_of_images ubi.mtd MANIFEST publickey ${signature_files} 487} 488do_generate_ubi_tar[dirs] = " ${S}/ubi" 489do_generate_ubi_tar[depends] += " \ 490 ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ 491 virtual/kernel:do_deploy \ 492 u-boot:do_populate_sysroot \ 493 openssl-native:do_populate_sysroot \ 494 ${SIGNING_KEY_DEPENDS} \ 495 ${PN}:do_copy_signing_pubkey \ 496 " 497 498do_generate_ext4_tar() { 499 ln -sf ${S}/MANIFEST MANIFEST 500 ln -sf ${S}/publickey publickey 501 make_image_links rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} ${FLASH_EXT4_BASETYPE} 502 make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey 503 make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files} 504} 505do_generate_ext4_tar[dirs] = " ${S}/ext4" 506do_generate_ext4_tar[depends] += " \ 507 ${PN}:do_image_${FLASH_EXT4_BASETYPE} \ 508 virtual/kernel:do_deploy \ 509 u-boot:do_populate_sysroot \ 510 openssl-native:do_populate_sysroot \ 511 ${SIGNING_KEY_DEPENDS} \ 512 ${PN}:do_copy_signing_pubkey \ 513 " 514 515def get_pubkey_basedir(d): 516 return os.path.join( 517 d.getVar('STAGING_DIR_TARGET', True), 518 d.getVar('sysconfdir', True).strip(os.sep), 519 'activationdata') 520 521def get_pubkey_type(d): 522 return os.listdir(get_pubkey_basedir(d))[0] 523 524def get_pubkey_path(d): 525 return os.path.join( 526 get_pubkey_basedir(d), 527 get_pubkey_type(d), 528 'publickey') 529 530python do_generate_phosphor_manifest() { 531 purpose = d.getVar('VERSION_PURPOSE', True) 532 version = do_get_version(d) 533 target_machine = d.getVar('MACHINE', True) 534 with open('MANIFEST', 'w') as fd: 535 fd.write('purpose={}\n'.format(purpose)) 536 fd.write('version={}\n'.format(version.strip('"'))) 537 fd.write('KeyType={}\n'.format(get_pubkey_type(d))) 538 fd.write('HashType=RSA-SHA256\n') 539 fd.write('MachineName={}\n'.format(target_machine)) 540} 541do_generate_phosphor_manifest[dirs] = "${S}" 542do_generate_phosphor_manifest[depends] += " \ 543 os-release:do_populate_sysroot \ 544 phosphor-image-signing:do_populate_sysroot \ 545 " 546 547python do_copy_signing_pubkey() { 548 with open(get_pubkey_path(d), 'r') as read_fd: 549 with open('publickey', 'w') as write_fd: 550 write_fd.write(read_fd.read()) 551} 552 553do_copy_signing_pubkey[dirs] = "${S}" 554do_copy_signing_pubkey[depends] += " \ 555 phosphor-image-signing:do_populate_sysroot \ 556 " 557 558addtask copy_signing_pubkey after do_rootfs 559addtask generate_phosphor_manifest after do_rootfs 560addtask generate_rwfs_static after do_rootfs 561addtask generate_rwfs_ubi after do_rootfs 562addtask generate_rwfs_ext4 after do_rootfs 563 564python() { 565 types = d.getVar('IMAGE_FSTYPES', True).split() 566 567 if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]): 568 bb.build.addtask( 569 'do_generate_static', 570 'do_image_complete', 571 'do_generate_rwfs_static', d) 572 if 'mtd-static-alltar' in types: 573 bb.build.addtask( 574 'do_generate_static_alltar', 575 'do_image_complete', 576 'do_generate_static do_generate_phosphor_manifest', d) 577 if 'mtd-static-tar' in types: 578 bb.build.addtask( 579 'do_generate_static_tar', 580 'do_image_complete', 581 'do_generate_rwfs_static do_generate_phosphor_manifest', d) 582 583 if 'mtd-ubi' in types: 584 bb.build.addtask( 585 'do_generate_ubi', 586 'do_image_complete', 587 'do_generate_rwfs_ubi', d) 588 if 'mtd-ubi-tar' in types: 589 bb.build.addtask( 590 'do_generate_ubi_tar', 591 'do_image_complete', 592 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d) 593 594 if 'mmc-verity' in types: 595 bb.build.addtask( 596 'do_generate_mmc_verity', 597 'do_image_complete','', d) 598 if 'mmc-ext4-tar' in types: 599 bb.build.addtask( 600 'do_generate_ext4_tar', 601 'do_image_complete', 602 'do_generate_rwfs_ext4 do_generate_phosphor_manifest', d) 603} 604