blob: 1e2105ccb5e79377e0857c43cfba530273a30735 [file] [log] [blame]
Brad Bishopaf6768d2017-07-24 15:05:05 -04001# 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 II270cbb82016-01-20 15:36:27 -06005IMAGE_BASETYPE ?= "squashfs-xz"
Andrew Jeffery9fa01292016-02-23 23:46:58 +10306OVERLAY_BASETYPE ?= "jffs2"
Milton D. Miller II270cbb82016-01-20 15:36:27 -06007
Brad Bishopc5361472016-02-29 10:21:51 -05008IMAGE_TYPES += "overlay"
Milton D. Miller II270cbb82016-01-20 15:36:27 -06009
Brad Bishopc5361472016-02-29 10:21:51 -050010IMAGE_TYPEDEP_overlay = "${IMAGE_BASETYPE}"
Milton D. Miller II270cbb82016-01-20 15:36:27 -060011IMAGE_TYPES_MASKED += "overlay"
12
Rick Altherrc919f532017-01-11 17:33:47 -080013FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}.bin"
Rick Altherr0e7e7092017-01-04 17:25:18 -080014
15FLASH_UBOOT_OFFSET ?= "0"
16FLASH_KERNEL_OFFSET ?= "512"
Rick Altherr0e7e7092017-01-04 17:25:18 -080017FLASH_ROFS_OFFSET ?= "4864"
18FLASH_RWFS_OFFSET ?= "28672"
19RWFS_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.
25DISTROOVERRIDES .= ":rwfs-${OVERLAY_BASETYPE}"
26
27OVERLAY_MKFS_OPTS_rwfs-ext4 = "-b 4096 -F -O^huge_file"
28
29# $(( ${FLASH_SIZE} - ${FLASH_RWFS_OFFSET} ))
30
31mk_nor_image() {
Brad Bishop30304a52017-07-22 14:20:20 -040032 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 Altherr0e7e7092017-01-04 17:25:18 -080036}
37
38do_generate_flash() {
Brad Bishopaf6768d2017-07-24 15:05:05 -040039 ddir="${IMGDEPLOYDIR}"
Brad Bishop30304a52017-07-22 14:20:20 -040040 kernel="${FLASH_KERNEL_IMAGE}"
41 uboot="u-boot.${UBOOT_SUFFIX}"
42 rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
43 rwfs="rwfs.${OVERLAY_BASETYPE}"
Rick Altherr0e7e7092017-01-04 17:25:18 -080044
Brad Bishopaf6768d2017-07-24 15:05:05 -040045 flash="${IMAGE_NAME}.overlay"
Rick Altherr0e7e7092017-01-04 17:25:18 -080046
Brad Bishopaf6768d2017-07-24 15:05:05 -040047 mk_nor_image ${S}/$rwfs ${RWFS_SIZE}
Brad Bishop30304a52017-07-22 14:20:20 -040048 if [ "${OVERLAY_BASETYPE}" != jffs2 ]; then
Brad Bishopaf6768d2017-07-24 15:05:05 -040049 mkfs.${OVERLAY_BASETYPE} ${OVERLAY_MKFS_OPTS} ${S}/$rwfs || \
Brad Bishop30304a52017-07-22 14:20:20 -040050 bbfatal "mkfs rwfs"
51 fi
Rick Altherr0e7e7092017-01-04 17:25:18 -080052
Brad Bishopaf6768d2017-07-24 15:05:05 -040053 # Assemble the flash image
54 dst="$ddir/$flash"
Brad Bishop30304a52017-07-22 14:20:20 -040055 mk_nor_image $dst ${FLASH_SIZE}
Brad Bishopaf6768d2017-07-24 15:05:05 -040056 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 Bishop30304a52017-07-22 14:20:20 -040058 dd if=$ddir/$rootfs of=$dst bs=1k conv=notrunc seek=${FLASH_ROFS_OFFSET}
Brad Bishopaf6768d2017-07-24 15:05:05 -040059 dd if=${S}/$rwfs of=$dst bs=1k conv=notrunc seek=${FLASH_RWFS_OFFSET}
Rick Altherr0e7e7092017-01-04 17:25:18 -080060
Brad Bishopaf6768d2017-07-24 15:05:05 -040061 cd ${IMGDEPLOYDIR}
62 ln -sf $flash ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.overlay
Rick Altherr0e7e7092017-01-04 17:25:18 -080063
Brad Bishopaf6768d2017-07-24 15:05:05 -040064 # Maintain a number of non-standard name legacy links.
65 ln -sf $flash ${IMGDEPLOYDIR}/flash-${MACHINE}
Rick Altherr0e7e7092017-01-04 17:25:18 -080066}
Rick Altherr0e7e7092017-01-04 17:25:18 -080067
Brad Bishop027f16b2017-07-24 20:51:51 -040068make_overlay_tars() {
Brad Bishopaf6768d2017-07-24 15:05:05 -040069 ddir="${IMGDEPLOYDIR}"
70 kernel="${FLASH_KERNEL_IMAGE}"
71 uboot="u-boot.${UBOOT_SUFFIX}"
72 rootfs="${IMAGE_LINK_NAME}.${IMAGE_BASETYPE}"
73 rwfs="rwfs.${OVERLAY_BASETYPE}"
Milton D. Miller II270cbb82016-01-20 15:36:27 -060074
Brad Bishopaf6768d2017-07-24 15:05:05 -040075 flash="${IMAGE_NAME}.overlay"
76 alltar="${IMAGE_NAME}.all.tar"
77 tar="${IMAGE_NAME}.tar"
78
79 # Create some links to help make the tar archives
80 ln -sf $ddir/${IMAGE_LINK_NAME}.overlay ${S}/image-bmc
81 ln -sf ${DEPLOY_DIR_IMAGE}/$uboot ${S}/image-u-boot
82 ln -sf ${DEPLOY_DIR_IMAGE}/$kernel ${S}/image-kernel
83 ln -sf $ddir/$rootfs ${S}/image-rofs
84 ln -sf $rwfs ${S}/image-rwfs
85
86 # Create the tar archives
Brad Bishop027f16b2017-07-24 20:51:51 -040087 tar -h -cvf $ddir/$alltar -C ${S} image-bmc MANIFEST
88 tar -h -cvf $ddir/$tar -C ${S} image-u-boot image-kernel image-rofs image-rwfs MANIFEST
Brad Bishopaf6768d2017-07-24 15:05:05 -040089
90 cd ${IMGDEPLOYDIR}
91 ln -sf $alltar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.all.tar
92 ln -sf $tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.tar
93
94 # Maintain a number of non-standard name legacy links.
95 ln -sf $tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar
96 ln -sf $alltar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar
97}
98
Brad Bishop027f16b2017-07-24 20:51:51 -040099make_overlay_tars[vardepsexclude] = "DATETIME"
100
101def generate_manifest(d):
102 import configparser
103 import io
104 path = d.getVar('STAGING_DIR_HOST', True) + d.getVar('sysconfdir', True)
105 path = os.path.join(path, 'os-release')
106 parser = configparser.SafeConfigParser(strict=False)
107 parser.optionxform = str
108 version = ''
109 with open(path, 'r') as fd:
110 buf = '[root]\n' + fd.read()
111 fd = io.StringIO(buf)
112 parser.readfp(fd)
113 version = parser['root']['VERSION_ID']
114
115 with open(os.path.join(d.getVar('S', True), 'MANIFEST'), 'w') as fd:
116 fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n')
117 fd.write('version={}\n'.format(version.strip('"')))
118
119
120python do_generate_tars() {
121 generate_manifest(d)
122 bb.build.exec_func('make_overlay_tars', d)
123}
124
Brad Bishopaf6768d2017-07-24 15:05:05 -0400125
126do_generate_flash[depends] += " \
127 ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \
128 virtual/kernel:do_deploy \
129 u-boot:do_populate_sysroot \
130 "
131
132do_generate_tars[depends] += " \
133 ${PN}:do_generate_flash \
Brad Bishop027f16b2017-07-24 20:51:51 -0400134 os-release:do_populate_sysroot \
Brad Bishopaf6768d2017-07-24 15:05:05 -0400135 "
136
137addtask generate_flash before do_image_complete
138addtask generate_tars before do_image_complete