overlay: Prepare for multiple image types
More refactoring in preparation for ubi based mtd images.
Promote tar file generation to a real image_fstype. This allows tar
generation to be turned on or off as needed.
Move image-overlay function to image_types_phosphor. Perhaps phosphor
is not the best name but for now we only have a handful of image types and
the generation logic is to interdependant to warrant seperate classes
for each.
Attempt to improve readability throughout.
Drop ext4 override to discourage mtd block emulation.
Change-Id: Idbdc03444549b955ef2180622d133904cb191b28
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/classes/image-overlay.bbclass b/classes/image-overlay.bbclass
deleted file mode 100644
index 443c271..0000000
--- a/classes/image-overlay.bbclass
+++ /dev/null
@@ -1,144 +0,0 @@
-# Constructs a bootable, fixed-offset mtd image with u-boot
-# bootloader, kernel fitimage, read only root filesystem,
-# and writeable overlay filesystem.
-
-IMAGE_BASETYPE ?= "squashfs-xz"
-OVERLAY_BASETYPE ?= "jffs2"
-
-IMAGE_TYPES += "overlay"
-
-IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}"
-IMAGE_TYPES_MASKED += "overlay"
-
-FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin"
-
-FLASH_UBOOT_OFFSET ?= "0"
-FLASH_KERNEL_OFFSET ?= "512"
-FLASH_ROFS_OFFSET ?= "4864"
-FLASH_RWFS_OFFSET ?= "28672"
-RWFS_SIZE ?= "4096"
-
-# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
-# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
-# reserved for the primary image (and setting them currently breaks the build).
-# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
-DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}"
-
-OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file"
-
-# $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} ))
-
-mk_nor_image() {
- image_dst="$1"
- image_size_kb=$2
- dd if=/dev/zero bs=1k count=$image_size_kb \
- | tr '\000' '\377' > $image_dst
-}
-
-do_generate_flash() {
- ddir="${IMGDEPLOYDIR}"
- kernel="${FLASH_KERNEL_IMAGE}"
- uboot="u-boot.${UBOOT_SUFFIX}"
- rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
- rwfs="rwfs.${OVERLAY_BASETYPE}"
-
- flash="${IMAGE_NAME}.overlay"
-
- mk_nor_image ${S}/$rwfs ${RWFS_SIZE}
- if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then
- mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} ${S}/$rwfs || \
- bbfatal "mkfs rwfs"
- fi
-
- # Assemble the flash image
- dst="$ddir/$flash"
- mk_nor_image $dst ${FLASH_SIZE}
- dd if=${DEPLOY_DIR_IMAGE}/$uboot of=$dst bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET}
- dd if=${DEPLOY_DIR_IMAGE}/$kernel of=$dst bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET}
- dd if=$ddir/$rootfs of=$dst bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET}
- dd if=${S}/$rwfs of=$dst bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET}
-
- cd ${IMGDEPLOYDIR}
- ln -sf $flash ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.overlay
-
- # Maintain a number of non-standard name legacy links.
- ln -sf $flash ${IMGDEPLOYDIR}/flash-${MACHINE}
- ln -sf $flash ${IMGDEPLOYDIR}/image-bmc
- ln -sf $uboot ${IMGDEPLOYDIR}/image-u-boot
- ln -sf $kernel ${IMGDEPLOYDIR}/image-kernel
- ln -sf $rootfs ${IMGDEPLOYDIR}/image-rofs
- cp ${S}/$rwfs ${IMGDEPLOYDIR}/$rwfs
- ln -sf $rwfs ${IMGDEPLOYDIR}/image-rwfs
-}
-
-make_overlay_tars() {
- ddir="${IMGDEPLOYDIR}"
- kernel="${FLASH_KERNEL_IMAGE}"
- uboot="u-boot.${UBOOT_SUFFIX}"
- rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
- rwfs="rwfs.${OVERLAY_BASETYPE}"
-
- flash="${IMAGE_NAME}.overlay"
- alltar="${IMAGE_NAME}.all.tar"
- tar="${IMAGE_NAME}.tar"
-
- # Create some links to help make the tar archives
- ln -sf $ddir/${IMAGE_LINK_NAME}.overlay ${S}/image-bmc
- ln -sf ${DEPLOY_DIR_IMAGE}/$uboot ${S}/image-u-boot
- ln -sf ${DEPLOY_DIR_IMAGE}/$kernel ${S}/image-kernel
- ln -sf $ddir/$rootfs ${S}/image-rofs
- ln -sf $rwfs ${S}/image-rwfs
-
- # Create the tar archives
- tar -h -cvf $ddir/$alltar -C ${S} image-bmc MANIFEST
- tar -h -cvf $ddir/$tar -C ${S} image-u-boot image-kernel image-rofs image-rwfs MANIFEST
-
- cd ${IMGDEPLOYDIR}
- ln -sf $alltar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.all.tar
- ln -sf $tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.tar
-
- # Maintain a number of non-standard name legacy links.
- ln -sf $tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
- ln -sf $alltar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
-}
-
-make_overlay_tars[vardepsexclude] = "DATETIME"
-
-def generate_manifest(d):
- import configparser
- import io
- path = d.getVar('STAGING_DIR_HOST', True) + d.getVar('sysconfdir', True)
- path = os.path.join(path, 'os-release')
- parser = configparser.SafeConfigParser(strict=False)
- parser.optionxform = str
- version = ''
- with open(path, 'r') as fd:
- buf = '[root]\n' + fd.read()
- fd = io.StringIO(buf)
- parser.readfp(fd)
- version = parser['root']['VERSION_ID']
-
- with open(os.path.join(d.getVar('S', True), 'MANIFEST'), 'w') as fd:
- fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
- fd.write('version={}\n'.format(version.strip('"')))
-
-
-python do_generate_tars() {
- generate_manifest(d)
- bb.build.exec_func('make_overlay_tars', d)
-}
-
-
-do_generate_flash[depends] += " \
- ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
- virtual/kernel:do_deploy \
- u-boot:do_populate_sysroot \
- "
-
-do_generate_tars[depends] += " \
- ${PN}:do_generate_flash \
- os-release:do_populate_sysroot \
- "
-
-addtask generate_flash before do_image_complete
-addtask generate_tars before do_image_complete
diff --git a/classes/image_types_phosphor.bbclass b/classes/image_types_phosphor.bbclass
index eef1b1c..51259df 100644
--- a/classes/image_types_phosphor.bbclass
+++ b/classes/image_types_phosphor.bbclass
@@ -11,6 +11,205 @@
IMAGE_TYPE_uboot = '${@build_uboot(d)}'
inherit ${IMAGE_TYPE_uboot}
-# Inherit the overlay class if overlay is in use.
-IMAGE_TYPE_overlay = '${@bb.utils.contains("IMAGE_FSTYPES", "overlay", "image-overlay", "", d)}'
-inherit ${IMAGE_TYPE_overlay}
+# Phosphor image types
+#
+# Phosphor OpenBMC supports a fixed partition mtd layout.
+
+# Image composition
+FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin"
+IMAGE_BASETYPE ?= "squashfs-xz"
+OVERLAY_BASETYPE ?= "jffs2"
+
+IMAGE_TYPES += "mtd-static mtd-static-alltar mtd-static-tar"
+
+IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}"
+IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}"
+IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static"
+IMAGE_TYPES_MASKED += "mtd-static mtd-static-alltar mtd-static-tar"
+
+# Flash characteristics
+FLASH_SIZE ?= "32768"
+
+# Fixed partition offsets
+FLASH_UBOOT_OFFSET ?= "0"
+FLASH_KERNEL_OFFSET ?= "512"
+FLASH_ROFS_OFFSET ?= "4864"
+FLASH_RWFS_OFFSET ?= "28672"
+
+# Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However,
+# avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are
+# reserved for the primary image (and setting them currently breaks the build).
+# Instead, prefix the overlay override value with 'rwfs-' to avoid collisions.
+DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}"
+
+JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=rwfs.jffs2"
+
+FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}"
+
+mk_nor_image() {
+ image_dst="$1"
+ image_size_kb=$2
+ dd if=/dev/zero bs=1k count=$image_size_kb \
+ | tr '\000' '\377' > $image_dst
+}
+
+make_rwfs() {
+ type=$1
+ cmd=$2
+ shift
+ shift
+ opts="$@"
+
+ rm -f rwfs.$type
+ rm -rf $type
+ mkdir $type
+
+ $cmd $opts
+}
+
+do_generate_rwfs_static() {
+ make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS}
+}
+do_generate_rwfs_static[dirs] = " ${S}/static"
+do_generate_rwfs_static[depends] += " \
+ mtd-utils-native:do_populate_sysroot \
+ "
+
+do_generate_static() {
+ # 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
+
+ dd bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} \
+ if=${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} \
+ of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
+
+ dd bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} \
+ if=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} \
+ of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
+
+ dd bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} \
+ if=rwfs.${OVERLAY_BASETYPE} \
+ of=${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd
+ # File needed for generating non-standard legacy links below
+ cp rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/rwfs.${OVERLAY_BASETYPE}
+
+ cd ${IMGDEPLOYDIR}
+ ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd
+
+ # Maintain non-standard legacy links
+ ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE}
+ ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc
+ ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot
+ ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel
+ ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs
+ ln -sf rwfs.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs
+}
+do_generate_static[dirs] = "${S}/static"
+do_generate_static[depends] += " \
+ ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
+ virtual/kernel:do_deploy \
+ u-boot:do_populate_sysroot \
+ "
+
+do_generate_static_alltar() {
+ ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc
+ tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar image-bmc
+
+ cd ${IMGDEPLOYDIR}
+
+ ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
+ ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar
+
+ # Maintain non-standard legacy link.
+ ln -sf ${IMAGE_NAME}.static.mtd.all.tar \
+ ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
+}
+do_generate_static_alltar[vardepsexclude] = "DATETIME"
+do_generate_static_alltar[dirs] = "${S}/static"
+
+make_tar_of_images() {
+ rwfs=$1
+ rofs=$2
+ type=$3
+ shift
+ shift
+ shift
+ extra_files="$@"
+
+ # Create some links to help make the tar archive
+ ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot
+ ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel
+ ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs
+ ln -sf rwfs.$rwfs image-rwfs
+
+ # Create the tar archive
+ tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \
+ image-u-boot image-kernel image-rofs image-rwfs $extra_files
+
+ cd ${IMGDEPLOYDIR}
+ ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar
+}
+
+do_generate_static_tar() {
+ make_tar_of_images ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE} static
+
+ # Maintain non-standard legacy link.
+ cd ${IMGDEPLOYDIR}
+ ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
+}
+do_generate_static_tar[dirs] = " ${S}/static"
+do_generate_static_tar[depends] += " \
+ ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
+ virtual/kernel:do_deploy \
+ u-boot:do_populate_sysroot \
+ "
+do_generate_static_tar[vardepsexclude] = "DATETIME"
+
+python do_generate_phosphor_manifest() {
+ import configparser
+ import io
+ path = d.getVar('STAGING_DIR_HOST', True) + d.getVar('sysconfdir', True)
+ path = os.path.join(path, 'os-release')
+ parser = configparser.SafeConfigParser(strict=False)
+ parser.optionxform = str
+ version = ''
+ with open(path, 'r') as fd:
+ buf = '[root]\n' + fd.read()
+ fd = io.StringIO(buf)
+ parser.readfp(fd)
+ version = parser['root']['VERSION_ID']
+
+ with open('MANIFEST', 'w') as fd:
+ fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
+ fd.write('version={}\n'.format(version.strip('"')))
+}
+do_generate_phosphor_manifest[dirs] = "${S}"
+do_generate_phosphor_manifest[depends] += " \
+ os-release:do_populate_sysroot \
+ "
+
+addtask generate_phosphor_manifest after do_rootfs
+addtask generate_rwfs_static after do_rootfs
+
+python() {
+ types = d.getVar('IMAGE_FSTYPES', True).split()
+
+ if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]):
+ bb.build.addtask(
+ 'do_generate_static',
+ 'do_image_complete',
+ 'do_generate_rwfs_static', d)
+ if 'mtd-static-alltar' in types:
+ bb.build.addtask(
+ 'do_generate_static_alltar',
+ 'do_image_complete',
+ 'do_generate_static', d)
+ if 'mtd-static-tar' in types:
+ bb.build.addtask(
+ 'do_generate_static_tar',
+ 'do_image_complete',
+ 'do_generate_rwfs_static', d)
+}
diff --git a/conf/machine/include/obmc-bsp-common.inc b/conf/machine/include/obmc-bsp-common.inc
index 03e73b3..63c5e1a 100644
--- a/conf/machine/include/obmc-bsp-common.inc
+++ b/conf/machine/include/obmc-bsp-common.inc
@@ -10,7 +10,7 @@
MACHINEOVERRIDES =. "openbmc:"
-IMAGE_FSTYPES += "cpio.${INITRAMFS_CTYPE}.u-boot overlay"
+IMAGE_FSTYPES += "cpio.${INITRAMFS_CTYPE}.u-boot mtd-static mtd-static-tar mtd-static-alltar"
OBMC_IMAGE_EXTRA_INSTALL_append = " u-boot-fw-utils"
INITRAMFS_CTYPE ?= "lzma"