Brad Bishop | 97cce00 | 2017-07-22 14:49:25 -0400 | [diff] [blame] | 1 | # Base image class extension, inlined into every image. |
| 2 | |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 3 | inherit image_version |
Brad Bishop | 97cce00 | 2017-07-22 14:49:25 -0400 | [diff] [blame] | 4 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 5 | # Phosphor image types |
| 6 | # |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 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. |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 10 | |
| 11 | # Image composition |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 12 | FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE}" |
Brad Bishop | 8623bbe | 2018-03-09 00:04:00 -0500 | [diff] [blame] | 13 | FLASH_KERNEL_IMAGE_df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin" |
| 14 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 15 | IMAGE_BASETYPE ?= "squashfs-xz" |
| 16 | OVERLAY_BASETYPE ?= "jffs2" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 17 | FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}" |
| 18 | FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 19 | |
Brad Bishop | 02ee6ae | 2018-03-30 08:43:23 -0400 | [diff] [blame] | 20 | IMAGE_TYPES += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 21 | |
| 22 | IMAGE_TYPEDEP_mtd-static = "${IMAGE_BASETYPE}" |
| 23 | IMAGE_TYPEDEP_mtd-static-tar = "${IMAGE_BASETYPE}" |
| 24 | IMAGE_TYPEDEP_mtd-static-alltar = "mtd-static" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 25 | IMAGE_TYPEDEP_mtd-ubi = "${FLASH_UBI_BASETYPE}" |
| 26 | IMAGE_TYPEDEP_mtd-ubi-tar = "${FLASH_UBI_BASETYPE}" |
Brad Bishop | 02ee6ae | 2018-03-30 08:43:23 -0400 | [diff] [blame] | 27 | IMAGE_TYPES_MASKED += "mtd-static mtd-static-alltar mtd-static-tar mtd-ubi mtd-ubi-tar" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 28 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 29 | # Flash characteristics in KB unless otherwise noted |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 30 | DISTROOVERRIDES .= ":flash-${FLASH_SIZE}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 31 | FLASH_SIZE ?= "32768" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 32 | FLASH_PEB_SIZE ?= "64" |
| 33 | # Flash page and overhead sizes in bytes |
| 34 | FLASH_PAGE_SIZE ?= "1" |
| 35 | FLASH_NOR_UBI_OVERHEAD ?= "64" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 36 | |
| 37 | # Fixed partition offsets |
| 38 | FLASH_UBOOT_OFFSET ?= "0" |
| 39 | FLASH_KERNEL_OFFSET ?= "512" |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 40 | FLASH_KERNEL_OFFSET_flash-131072 ?= "1024" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 41 | FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 42 | FLASH_ROFS_OFFSET ?= "4864" |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 43 | FLASH_ROFS_OFFSET_flash-131072 ?= "10240" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 44 | FLASH_RWFS_OFFSET ?= "28672" |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 45 | FLASH_RWFS_OFFSET_flash-131072 ?= "98304" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 46 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 47 | # UBI volume sizes in KB unless otherwise noted. |
Adriana Kobylak | b70005d | 2018-02-14 16:35:30 -0600 | [diff] [blame] | 48 | FLASH_UBI_RWFS_SIZE ?= "6144" |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 49 | FLASH_UBI_RWFS_SIZE_flash-131072 ?= "32768" |
Adriana Kobylak | b70005d | 2018-02-14 16:35:30 -0600 | [diff] [blame] | 50 | FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB" |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 51 | FLASH_UBI_RWFS_TXT_SIZE_flash-131072 ?= "32MiB" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 52 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 53 | SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv" |
| 54 | INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}" |
| 55 | SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}" |
| 56 | |
Brad Bishop | 3e37d38 | 2018-03-31 12:17:28 -0400 | [diff] [blame] | 57 | UBOOT_SUFFIX ?= "bin" |
| 58 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 59 | python() { |
| 60 | # Compute rwfs LEB count and LEB size. |
| 61 | page_size = d.getVar('FLASH_PAGE_SIZE', True) |
| 62 | nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True) |
| 63 | overhead_size = max(int(page_size), int(nor_overhead_size)) |
| 64 | peb_size = d.getVar('FLASH_PEB_SIZE', True) |
| 65 | leb_size = (int(peb_size) * 1024) - (2 * overhead_size) |
| 66 | d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes |
| 67 | |
| 68 | rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True) |
| 69 | rwfs_size = int(rwfs_size) * 1024 |
| 70 | lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up |
| 71 | d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs)) |
| 72 | } |
| 73 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 74 | # Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However, |
| 75 | # avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are |
| 76 | # reserved for the primary image (and setting them currently breaks the build). |
| 77 | # Instead, prefix the overlay override value with 'rwfs-' to avoid collisions. |
| 78 | DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 79 | DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 80 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 81 | JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2" |
| 82 | UBIFS_RWFS_CMD = "mkfs.ubifs -r ubifs -c ${FLASH_UBI_RWFS_LEBS} -m ${FLASH_PAGE_SIZE} -e ${FLASH_LEB_SIZE} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubifs" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 83 | |
| 84 | FLASH_STATIC_RWFS_CMD_static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 85 | FLASH_UBI_RWFS_CMD_ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" |
| 86 | FLASH_UBI_RWFS_CMD_ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 87 | |
| 88 | mk_nor_image() { |
| 89 | image_dst="$1" |
| 90 | image_size_kb=$2 |
| 91 | dd if=/dev/zero bs=1k count=$image_size_kb \ |
| 92 | | tr '\000' '\377' > $image_dst |
| 93 | } |
| 94 | |
| 95 | make_rwfs() { |
| 96 | type=$1 |
| 97 | cmd=$2 |
| 98 | shift |
| 99 | shift |
| 100 | opts="$@" |
| 101 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 102 | rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 103 | rm -rf $type |
| 104 | mkdir $type |
| 105 | |
| 106 | $cmd $opts |
| 107 | } |
| 108 | |
| 109 | do_generate_rwfs_static() { |
| 110 | make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS} |
| 111 | } |
| 112 | do_generate_rwfs_static[dirs] = " ${S}/static" |
| 113 | do_generate_rwfs_static[depends] += " \ |
| 114 | mtd-utils-native:do_populate_sysroot \ |
| 115 | " |
| 116 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 117 | do_generate_rwfs_ubi() { |
| 118 | make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}" |
| 119 | } |
| 120 | do_generate_rwfs_ubi[dirs] = " ${S}/ubi" |
| 121 | do_generate_rwfs_ubi[depends] += " \ |
| 122 | mtd-utils-native:do_populate_sysroot \ |
| 123 | " |
| 124 | |
| 125 | add_volume() { |
| 126 | config_file=$1 |
| 127 | vol_id=$2 |
| 128 | vol_type=$3 |
| 129 | vol_name=$4 |
| 130 | image=$5 |
| 131 | vol_size=$6 |
| 132 | |
| 133 | echo \[$vol_name\] >> $config_file |
| 134 | echo mode=ubi >> $config_file |
| 135 | echo image=$image >> $config_file |
| 136 | echo vol_type=$vol_type >> $config_file |
| 137 | echo vol_name=$vol_name >> $config_file |
| 138 | echo vol_id=$vol_id >> $config_file |
| 139 | if [ ! -z $vol_size ]; then |
| 140 | echo vol_size=$vol_size >> $config_file |
| 141 | fi |
| 142 | } |
| 143 | |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 144 | python do_generate_ubi() { |
| 145 | version_id = do_get_versionID(d) |
| 146 | d.setVar('VERSION_ID', version_id) |
| 147 | bb.build.exec_func("do_make_ubi", d) |
| 148 | } |
| 149 | do_generate_ubi[dirs] = "${S}/ubi" |
| 150 | do_generate_ubi[depends] += " \ |
| 151 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 152 | virtual/kernel:do_deploy \ |
| 153 | u-boot:do_populate_sysroot \ |
| 154 | mtd-utils-native:do_populate_sysroot \ |
| 155 | " |
| 156 | |
| 157 | do_make_ubi() { |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 158 | cfg=ubinize-${IMAGE_NAME}.cfg |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 159 | rm -f $cfg ubi-img |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 160 | # Construct the ubinize config file |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 161 | add_volume $cfg 0 static kernel-${VERSION_ID} \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 162 | ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} |
| 163 | |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 164 | add_volume $cfg 1 static rofs-${VERSION_ID} \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 165 | ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE} |
| 166 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 167 | add_volume $cfg 2 dynamic rwfs ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_RWFS_TXT_SIZE} |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 168 | |
| 169 | # Build the ubi partition image |
| 170 | ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg |
| 171 | |
| 172 | # Concatenate the uboot and ubi partitions |
| 173 | mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE} |
| 174 | dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \ |
| 175 | if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \ |
| 176 | of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd |
| 177 | dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \ |
| 178 | if=ubi-img \ |
| 179 | of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd |
| 180 | |
| 181 | cd ${IMGDEPLOYDIR} |
| 182 | ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd |
| 183 | } |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 184 | do_make_ubi[dirs] = "${S}/ubi" |
| 185 | do_make_ubi[depends] += " \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 186 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 187 | virtual/kernel:do_deploy \ |
| 188 | u-boot:do_populate_sysroot \ |
| 189 | mtd-utils-native:do_populate_sysroot \ |
| 190 | " |
| 191 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 192 | do_mk_static_nor_image() { |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 193 | # Assemble the flash image |
| 194 | mk_nor_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE} |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 195 | } |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 196 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 197 | python do_generate_static() { |
| 198 | import subprocess |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 199 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 200 | bb.build.exec_func("do_mk_static_nor_image", d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 201 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 202 | nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 203 | '%s.static.mtd' % d.getVar('IMAGE_NAME', True)) |
| 204 | |
| 205 | def _append_image(imgpath, start_kb, finish_kb): |
| 206 | imgsize = os.path.getsize(imgpath) |
| 207 | if imgsize > (finish_kb - start_kb) * 1024: |
| 208 | bb.fatal("Image '%s' is too large!" % imgpath) |
| 209 | |
| 210 | subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc', |
| 211 | 'seek=%d' % start_kb, |
| 212 | 'if=%s' % imgpath, |
| 213 | 'of=%s' % nor_image]) |
| 214 | |
| 215 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 216 | 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)), |
| 217 | int(d.getVar('FLASH_UBOOT_OFFSET', True)), |
| 218 | int(d.getVar('FLASH_KERNEL_OFFSET', True))) |
| 219 | |
| 220 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 221 | d.getVar('FLASH_KERNEL_IMAGE', True)), |
| 222 | int(d.getVar('FLASH_KERNEL_OFFSET', True)), |
| 223 | int(d.getVar('FLASH_ROFS_OFFSET', True))) |
| 224 | |
| 225 | _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 226 | '%s.%s' % ( |
| 227 | d.getVar('IMAGE_LINK_NAME', True), |
| 228 | d.getVar('IMAGE_BASETYPE', True))), |
| 229 | int(d.getVar('FLASH_ROFS_OFFSET', True)), |
| 230 | int(d.getVar('FLASH_RWFS_OFFSET', True))) |
| 231 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 232 | _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 233 | '%s.%s' % ( |
| 234 | d.getVar('IMAGE_LINK_NAME', True), |
| 235 | d.getVar('OVERLAY_BASETYPE', True))), |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 236 | int(d.getVar('FLASH_RWFS_OFFSET', True)), |
| 237 | int(d.getVar('FLASH_SIZE', True))) |
| 238 | |
| 239 | bb.build.exec_func("do_mk_static_symlinks", d) |
| 240 | } |
| 241 | |
| 242 | do_mk_static_symlinks() { |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 243 | cd ${IMGDEPLOYDIR} |
| 244 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd |
| 245 | |
| 246 | # Maintain non-standard legacy links |
| 247 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE} |
| 248 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc |
| 249 | ln -sf u-boot.${UBOOT_SUFFIX} ${IMGDEPLOYDIR}/image-u-boot |
| 250 | ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel |
| 251 | ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 252 | ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 253 | } |
| 254 | do_generate_static[dirs] = "${S}/static" |
| 255 | do_generate_static[depends] += " \ |
| 256 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 257 | virtual/kernel:do_deploy \ |
| 258 | u-boot:do_populate_sysroot \ |
| 259 | " |
| 260 | |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 261 | make_signatures() { |
| 262 | signature_files="" |
| 263 | for file in "$@"; do |
| 264 | openssl dgst -sha256 -sign ${SIGNING_KEY} -out "${file}.sig" $file |
| 265 | signature_files="${signature_files} ${file}.sig" |
| 266 | done |
| 267 | } |
| 268 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 269 | do_generate_static_alltar() { |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 270 | ln -sf ${S}/MANIFEST MANIFEST |
| 271 | ln -sf ${S}/publickey publickey |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 272 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 273 | |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 274 | make_signatures image-bmc MANIFEST publickey |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 275 | |
| 276 | tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \ |
| 277 | image-bmc MANIFEST publickey ${signature_files} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 278 | |
| 279 | cd ${IMGDEPLOYDIR} |
| 280 | |
| 281 | ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ |
| 282 | ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar |
| 283 | |
| 284 | # Maintain non-standard legacy link. |
| 285 | ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ |
| 286 | ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 287 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 288 | } |
| 289 | do_generate_static_alltar[vardepsexclude] = "DATETIME" |
| 290 | do_generate_static_alltar[dirs] = "${S}/static" |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 291 | do_generate_static_alltar[depends] += " \ |
| 292 | openssl-native:do_populate_sysroot \ |
| 293 | ${SIGNING_KEY_DEPENDS} \ |
| 294 | ${PN}:do_copy_signing_pubkey \ |
| 295 | " |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 296 | |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 297 | make_image_links() { |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 298 | rwfs=$1 |
| 299 | rofs=$2 |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 300 | shift |
| 301 | shift |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 302 | |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 303 | # Create some links to help make the tar archive in the format |
| 304 | # expected by phosphor-bmc-code-mgmt. |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 305 | ln -sf ${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} image-u-boot |
| 306 | ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel |
| 307 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 308 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | make_tar_of_images() { |
| 312 | type=$1 |
| 313 | shift |
| 314 | extra_files="$@" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 315 | |
| 316 | # Create the tar archive |
| 317 | tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.mtd.tar \ |
| 318 | image-u-boot image-kernel image-rofs image-rwfs $extra_files |
| 319 | |
| 320 | cd ${IMGDEPLOYDIR} |
| 321 | ln -sf ${IMAGE_NAME}.$type.mtd.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.mtd.tar |
| 322 | } |
| 323 | |
| 324 | do_generate_static_tar() { |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 325 | ln -sf ${S}/MANIFEST MANIFEST |
| 326 | ln -sf ${S}/publickey publickey |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 327 | make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE} |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 328 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 329 | make_tar_of_images static MANIFEST publickey ${signature_files} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 330 | |
| 331 | # Maintain non-standard legacy link. |
| 332 | cd ${IMGDEPLOYDIR} |
| 333 | ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar |
| 334 | } |
| 335 | do_generate_static_tar[dirs] = " ${S}/static" |
| 336 | do_generate_static_tar[depends] += " \ |
| 337 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 338 | virtual/kernel:do_deploy \ |
| 339 | u-boot:do_populate_sysroot \ |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 340 | openssl-native:do_populate_sysroot \ |
| 341 | ${SIGNING_KEY_DEPENDS} \ |
| 342 | ${PN}:do_copy_signing_pubkey \ |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 343 | " |
| 344 | do_generate_static_tar[vardepsexclude] = "DATETIME" |
| 345 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 346 | do_generate_ubi_tar() { |
| 347 | ln -sf ${S}/MANIFEST MANIFEST |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 348 | ln -sf ${S}/publickey publickey |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 349 | make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE} |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 350 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey |
| 351 | make_tar_of_images ubi MANIFEST publickey ${signature_files} |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 352 | } |
| 353 | do_generate_ubi_tar[dirs] = " ${S}/ubi" |
| 354 | do_generate_ubi_tar[depends] += " \ |
| 355 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 356 | virtual/kernel:do_deploy \ |
| 357 | u-boot:do_populate_sysroot \ |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 358 | openssl-native:do_populate_sysroot \ |
| 359 | ${SIGNING_KEY_DEPENDS} \ |
| 360 | ${PN}:do_copy_signing_pubkey \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 361 | " |
| 362 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 363 | def get_pubkey_basedir(d): |
| 364 | return os.path.join( |
| 365 | d.getVar('STAGING_DIR_TARGET', True), |
| 366 | d.getVar('sysconfdir', True).strip(os.sep), |
| 367 | 'activationdata') |
| 368 | |
| 369 | def get_pubkey_type(d): |
| 370 | return os.listdir(get_pubkey_basedir(d))[0] |
| 371 | |
| 372 | def get_pubkey_path(d): |
| 373 | return os.path.join( |
| 374 | get_pubkey_basedir(d), |
| 375 | get_pubkey_type(d), |
| 376 | 'publickey') |
| 377 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 378 | python do_generate_phosphor_manifest() { |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 379 | version = do_get_version(d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 380 | with open('MANIFEST', 'w') as fd: |
| 381 | fd.write('purpose=xyz.openbmc_project.Software.Version.VersionPurpose.BMC\n') |
| 382 | fd.write('version={}\n'.format(version.strip('"'))) |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 383 | fd.write('KeyType={}\n'.format(get_pubkey_type(d))) |
| 384 | fd.write('HashType=RSA-SHA256\n') |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 385 | } |
| 386 | do_generate_phosphor_manifest[dirs] = "${S}" |
| 387 | do_generate_phosphor_manifest[depends] += " \ |
| 388 | os-release:do_populate_sysroot \ |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 389 | phosphor-image-signing:do_populate_sysroot \ |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 390 | " |
| 391 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 392 | python do_copy_signing_pubkey() { |
| 393 | with open(get_pubkey_path(d), 'r') as read_fd: |
| 394 | with open('publickey', 'w') as write_fd: |
| 395 | write_fd.write(read_fd.read()) |
| 396 | } |
| 397 | |
| 398 | do_copy_signing_pubkey[dirs] = "${S}" |
| 399 | do_copy_signing_pubkey[depends] += " \ |
| 400 | phosphor-image-signing:do_populate_sysroot \ |
| 401 | " |
| 402 | |
| 403 | addtask copy_signing_pubkey after do_rootfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 404 | addtask generate_phosphor_manifest after do_rootfs |
| 405 | addtask generate_rwfs_static after do_rootfs |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 406 | addtask generate_rwfs_ubi after do_rootfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 407 | |
| 408 | python() { |
| 409 | types = d.getVar('IMAGE_FSTYPES', True).split() |
| 410 | |
| 411 | if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]): |
| 412 | bb.build.addtask( |
| 413 | 'do_generate_static', |
| 414 | 'do_image_complete', |
| 415 | 'do_generate_rwfs_static', d) |
| 416 | if 'mtd-static-alltar' in types: |
| 417 | bb.build.addtask( |
| 418 | 'do_generate_static_alltar', |
| 419 | 'do_image_complete', |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 420 | 'do_generate_static do_generate_phosphor_manifest', d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 421 | if 'mtd-static-tar' in types: |
| 422 | bb.build.addtask( |
| 423 | 'do_generate_static_tar', |
| 424 | 'do_image_complete', |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 425 | 'do_generate_rwfs_static do_generate_phosphor_manifest', d) |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 426 | |
| 427 | if 'mtd-ubi' in types: |
| 428 | bb.build.addtask( |
| 429 | 'do_generate_ubi', |
| 430 | 'do_image_complete', |
| 431 | 'do_generate_rwfs_ubi', d) |
| 432 | if 'mtd-ubi-tar' in types: |
| 433 | bb.build.addtask( |
| 434 | 'do_generate_ubi_tar', |
| 435 | 'do_image_complete', |
| 436 | 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 437 | } |