From 3dcf6f9c47ab70b73c55da788b297772263b7fab Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Tue, 17 Jul 2018 16:41:37 +0300 Subject: Check size of the firmware image parts Prevent building unbootable firmware images. Resolves: openbmc/openbmc#3314 Tested: I checked builds for `palmetto` and `romulus`. To reproduce the problem I appended a big file to initramfs by modify `meta-phosphor/common/recipes-phosphor/initfs/obmc-phosphor-initfs.bb`. The building process failed with message about too large initramfs image. Change-Id: I0176e9c47a9cb26ce8ba588794e681b6426d567d Signed-off-by: Alexander Filippov --- meta-phosphor/classes/image_types_phosphor.bbclass | 56 +++++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'meta-phosphor/classes') diff --git a/meta-phosphor/classes/image_types_phosphor.bbclass b/meta-phosphor/classes/image_types_phosphor.bbclass index 19422fc05..243739010 100644 --- a/meta-phosphor/classes/image_types_phosphor.bbclass +++ b/meta-phosphor/classes/image_types_phosphor.bbclass @@ -183,24 +183,54 @@ do_make_ubi[depends] += " \ mtd-utils-native:do_populate_sysroot \ " -do_generate_static() { +do_mk_static_nor_image() { # Assemble the flash image mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE} - dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \ - if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \ - of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd +} + +python do_generate_static() { + import subprocess + + bb.build.exec_func("do_mk_static_nor_image", d) + + nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), + '%s.static.mtd' % d.getVar('IMAGE_NAME', True)) - dd bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} \ - if=${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} \ - of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd + def _append_image(imgpath, start_kb, finish_kb): + imgsize = os.path.getsize(imgpath) + if imgsize > (finish_kb - start_kb) * 1024: + bb.fatal("Image '%s' is too large!" % imgpath) - dd bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} \ - if=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} \ - of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd + subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc', + 'seek=%d' % start_kb, + 'if=%s' % imgpath, + 'of=%s' % nor_image]) + + _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), + 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)), + int(d.getVar('FLASH_UBOOT_OFFSET', True)), + int(d.getVar('FLASH_KERNEL_OFFSET', True))) + + _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), + d.getVar('FLASH_KERNEL_IMAGE', True)), + int(d.getVar('FLASH_KERNEL_OFFSET', True)), + int(d.getVar('FLASH_ROFS_OFFSET', True))) + + _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), + '%s.%s' % ( + d.getVar('IMAGE_LINK_NAME', True), + d.getVar('IMAGE_BASETYPE', True))), + int(d.getVar('FLASH_ROFS_OFFSET', True)), + int(d.getVar('FLASH_RWFS_OFFSET', True))) + + _append_image('rwfs.%s' % d.getVar('OVERLAY_BASETYPE', True), + int(d.getVar('FLASH_RWFS_OFFSET', True)), + int(d.getVar('FLASH_SIZE', True))) + + bb.build.exec_func("do_mk_static_symlinks", d) +} - dd bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} \ - if=rwfs.${OVERLAY_BASETYPE} \ - of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd +do_mk_static_symlinks() { # File needed for generating non-standard legacy links below cp rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/rwfs.${OVERLAY_BASETYPE} -- cgit v1.2.3