Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 1 | # Constructs a bootable, fixed-offset mtd image with u-boot |
| 2 | # bootloader, kernel fitimage, read only root filesystem, |
| 3 | # and writeable overlay filesystem. |
| 4 | |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 5 | IMAGE_BASETYPE ?= "squashfs-xz" |
Andrew Jeffery | 9fa0129 | 2016-02-23 23:46:58 +1030 | [diff] [blame] | 6 | OVERLAY_BASETYPE ?= "jffs2" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 7 | |
Brad Bishop | c536147 | 2016-02-29 10:21:51 -0500 | [diff] [blame] | 8 | IMAGE_TYPES += "overlay" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 9 | |
Brad Bishop | c536147 | 2016-02-29 10:21:51 -0500 | [diff] [blame] | 10 | IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 11 | IMAGE_TYPES_MASKED += "overlay" |
| 12 | |
Rick Altherr | c919f53 | 2017-01-11 17:33:47 -0800 | [diff] [blame] | 13 | FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 14 | |
| 15 | FLASH_UBOOT_OFFSET ?= "0" |
| 16 | FLASH_KERNEL_OFFSET ?= "512" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 17 | FLASH_ROFS_OFFSET ?= "4864" |
| 18 | FLASH_RWFS_OFFSET ?= "28672" |
| 19 | RWFS_SIZE ?= "4096" |
| 20 | |
| 21 | # Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However, |
| 22 | # avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are |
| 23 | # reserved for the primary image (and setting them currently breaks the build). |
| 24 | # Instead, prefix the overlay override value with 'rwfs-' to avoid collisions. |
| 25 | DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}" |
| 26 | |
| 27 | OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file" |
| 28 | |
| 29 | # $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} )) |
| 30 | |
| 31 | mk_nor_image() { |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 32 | image_dst="$1" |
| 33 | image_size_kb=$2 |
| 34 | dd if=/dev/zero bs=1k count=$image_size_kb \ |
| 35 | | tr '\000' '\377' > $image_dst |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | do_generate_flash() { |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 39 | ddir="${IMGDEPLOYDIR}" |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 40 | kernel="${FLASH_KERNEL_IMAGE}" |
| 41 | uboot="u-boot.${UBOOT_SUFFIX}" |
| 42 | rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}" |
| 43 | rwfs="rwfs.${OVERLAY_BASETYPE}" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 44 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 45 | flash="${IMAGE_NAME}.overlay" |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 46 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 47 | mk_nor_image ${S}/$rwfs ${RWFS_SIZE} |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 48 | if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 49 | mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} ${S}/$rwfs || \ |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 50 | bbfatal "mkfs rwfs" |
| 51 | fi |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 52 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 53 | # Assemble the flash image |
| 54 | dst="$ddir/$flash" |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 55 | mk_nor_image $dst ${FLASH_SIZE} |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 56 | dd if=${DEPLOY_DIR_IMAGE}/$uboot of=$dst bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} |
| 57 | dd if=${DEPLOY_DIR_IMAGE}/$kernel of=$dst bs=1k conv=notrunc seek=${FLASH_KERNEL_OFFSET} |
Brad Bishop | 30304a5 | 2017-07-22 14:20:20 -0400 | [diff] [blame] | 58 | dd if=$ddir/$rootfs of=$dst bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET} |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 59 | dd if=${S}/$rwfs of=$dst bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET} |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 60 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 61 | cd ${IMGDEPLOYDIR} |
| 62 | ln -sf $flash ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.overlay |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 63 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 64 | # Maintain a number of non-standard name legacy links. |
| 65 | ln -sf $flash ${IMGDEPLOYDIR}/flash-${MACHINE} |
Adriana Kobylak | 59d3ea2 | 2017-08-08 11:44:16 -0500 | [diff] [blame] | 66 | ln -sf $flash ${IMGDEPLOYDIR}/image-bmc |
| 67 | ln -sf $uboot ${IMGDEPLOYDIR}/image-u-boot |
| 68 | ln -sf $kernel ${IMGDEPLOYDIR}/image-kernel |
| 69 | ln -sf $rootfs ${IMGDEPLOYDIR}/image-rofs |
| 70 | cp ${S}/$rwfs ${IMGDEPLOYDIR}/$rwfs |
| 71 | ln -sf $rwfs ${IMGDEPLOYDIR}/image-rwfs |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 72 | } |
Rick Altherr | 0e7e709 | 2017-01-04 17:25:18 -0800 | [diff] [blame] | 73 | |
Brad Bishop | 027f16b | 2017-07-24 20:51:51 -0400 | [diff] [blame] | 74 | make_overlay_tars() { |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 75 | ddir="${IMGDEPLOYDIR}" |
| 76 | kernel="${FLASH_KERNEL_IMAGE}" |
| 77 | uboot="u-boot.${UBOOT_SUFFIX}" |
| 78 | rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}" |
| 79 | rwfs="rwfs.${OVERLAY_BASETYPE}" |
Milton D. Miller II | 270cbb8 | 2016-01-20 15:36:27 -0600 | [diff] [blame] | 80 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 81 | flash="${IMAGE_NAME}.overlay" |
| 82 | alltar="${IMAGE_NAME}.all.tar" |
| 83 | tar="${IMAGE_NAME}.tar" |
| 84 | |
| 85 | # Create some links to help make the tar archives |
| 86 | ln -sf $ddir/${IMAGE_LINK_NAME}.overlay ${S}/image-bmc |
| 87 | ln -sf ${DEPLOY_DIR_IMAGE}/$uboot ${S}/image-u-boot |
| 88 | ln -sf ${DEPLOY_DIR_IMAGE}/$kernel ${S}/image-kernel |
| 89 | ln -sf $ddir/$rootfs ${S}/image-rofs |
| 90 | ln -sf $rwfs ${S}/image-rwfs |
| 91 | |
| 92 | # Create the tar archives |
Brad Bishop | 027f16b | 2017-07-24 20:51:51 -0400 | [diff] [blame] | 93 | tar -h -cvf $ddir/$alltar -C ${S} image-bmc MANIFEST |
| 94 | tar -h -cvf $ddir/$tar -C ${S} image-u-boot image-kernel image-rofs image-rwfs MANIFEST |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 95 | |
| 96 | cd ${IMGDEPLOYDIR} |
| 97 | ln -sf $alltar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.all.tar |
| 98 | ln -sf $tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.tar |
| 99 | |
| 100 | # Maintain a number of non-standard name legacy links. |
| 101 | ln -sf $tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar |
| 102 | ln -sf $alltar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar |
| 103 | } |
| 104 | |
Brad Bishop | 027f16b | 2017-07-24 20:51:51 -0400 | [diff] [blame] | 105 | make_overlay_tars[vardepsexclude] = "DATETIME" |
| 106 | |
| 107 | def generate_manifest(d): |
| 108 | import configparser |
| 109 | import io |
| 110 | path = d.getVar('STAGING_DIR_HOST', True) + d.getVar('sysconfdir', True) |
| 111 | path = os.path.join(path, 'os-release') |
| 112 | parser = configparser.SafeConfigParser(strict=False) |
| 113 | parser.optionxform = str |
| 114 | version = '' |
| 115 | with open(path, 'r') as fd: |
| 116 | buf = '[root]\n' + fd.read() |
| 117 | fd = io.StringIO(buf) |
| 118 | parser.readfp(fd) |
| 119 | version = parser['root']['VERSION_ID'] |
| 120 | |
| 121 | with open(os.path.join(d.getVar('S', True), 'MANIFEST'), 'w') as fd: |
| 122 | fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n') |
| 123 | fd.write('version={}\n'.format(version.strip('"'))) |
| 124 | |
| 125 | |
| 126 | python do_generate_tars() { |
| 127 | generate_manifest(d) |
| 128 | bb.build.exec_func('make_overlay_tars', d) |
| 129 | } |
| 130 | |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 131 | |
| 132 | do_generate_flash[depends] += " \ |
| 133 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 134 | virtual/kernel:do_deploy \ |
| 135 | u-boot:do_populate_sysroot \ |
| 136 | " |
| 137 | |
| 138 | do_generate_tars[depends] += " \ |
| 139 | ${PN}:do_generate_flash \ |
Brad Bishop | 027f16b | 2017-07-24 20:51:51 -0400 | [diff] [blame] | 140 | os-release:do_populate_sysroot \ |
Brad Bishop | af6768d | 2017-07-24 15:05:05 -0400 | [diff] [blame] | 141 | " |
| 142 | |
| 143 | addtask generate_flash before do_image_complete |
| 144 | addtask generate_tars before do_image_complete |