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 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 5 | FIT_IMAGE_INHERIT="" |
| 6 | FIT_IMAGE_INHERIT:df-obmc-static-norootfs = "fit-image" |
| 7 | inherit ${FIT_IMAGE_INHERIT} |
| 8 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 9 | # Phosphor image types |
| 10 | # |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 11 | # Phosphor OpenBMC supports a fixed partition mtd layout, |
| 12 | # A dynamic mtd with ubi layout, and a tar file for use with |
| 13 | # The reference BMC software update implementation. |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 14 | |
| 15 | # Image composition |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 16 | FLASH_KERNEL_IMAGE ?= "fitImage-${INITRAMFS_IMAGE}-${MACHINE}-${MACHINE}" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 17 | FLASH_KERNEL_IMAGE:df-obmc-ubi-fs ?= "fitImage-${MACHINE}.bin" |
Brad Bishop | 8623bbe | 2018-03-09 00:04:00 -0500 | [diff] [blame] | 18 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 19 | IMAGE_BASETYPE ?= "squashfs-xz" |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 20 | IMAGE_BASETYPE:df-obmc-static-norootfs ?= "cpio" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 21 | OVERLAY_BASETYPE ?= "jffs2" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 22 | FLASH_UBI_BASETYPE ?= "${IMAGE_BASETYPE}" |
| 23 | FLASH_UBI_OVERLAY_BASETYPE ?= "ubifs" |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 24 | FLASH_EXT4_BASETYPE ?= "ext4" |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 25 | FLASH_EXT4_OVERLAY_BASETYPE ?= "ext4" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 26 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 27 | PHOSPHOR_IMAGE_TYPES += " \ |
| 28 | mtd-static \ |
| 29 | mtd-static-alltar \ |
| 30 | mtd-static-tar \ |
| 31 | mtd-static-norootfs \ |
| 32 | mtd-ubi \ |
| 33 | mtd-ubi-tar \ |
| 34 | mmc-ext4-tar \ |
| 35 | " |
| 36 | IMAGE_TYPES += "${PHOSPHOR_IMAGE_TYPES}" |
| 37 | IMAGE_TYPES_MASKED += "${PHOSPHOR_IMAGE_TYPES}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 38 | |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 39 | IMAGE_TYPEDEP:mtd-static = "${IMAGE_BASETYPE}" |
| 40 | IMAGE_TYPEDEP:mtd-static-tar = "${IMAGE_BASETYPE}" |
| 41 | IMAGE_TYPEDEP:mtd-static-alltar = "mtd-static" |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 42 | IMAGE_TYPEDEP:mtd-static-norootfs = "${IMAGE_BASETYPE}" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 43 | IMAGE_TYPEDEP:mtd-ubi = "${FLASH_UBI_BASETYPE}" |
| 44 | IMAGE_TYPEDEP:mtd-ubi-tar = "${FLASH_UBI_BASETYPE}" |
| 45 | IMAGE_TYPEDEP:mmc-ext4-tar = "${FLASH_EXT4_BASETYPE}" |
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 | # Flash characteristics in KB unless otherwise noted |
Brad Bishop | dcd861c | 2019-09-24 21:16:09 -0400 | [diff] [blame] | 48 | DISTROOVERRIDES .= ":flash-${FLASH_SIZE}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 49 | FLASH_SIZE ?= "32768" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 50 | FLASH_PEB_SIZE ?= "64" |
| 51 | # Flash page and overhead sizes in bytes |
| 52 | FLASH_PAGE_SIZE ?= "1" |
| 53 | FLASH_NOR_UBI_OVERHEAD ?= "64" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 54 | |
| 55 | # Fixed partition offsets |
Adriana Kobylak | e913dd8 | 2020-04-13 13:56:41 -0500 | [diff] [blame] | 56 | FLASH_UBOOT_SPL_SIZE ?= "64" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 57 | FLASH_UBOOT_OFFSET ?= "0" |
Patrick Williams | 80dccc8 | 2023-03-27 09:58:33 -0500 | [diff] [blame] | 58 | FLASH_MANIFEST_OFFSET ?= "380" |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 59 | FLASH_MANIFEST_OFFSET:flash-65536 ?= "888" |
| 60 | FLASH_MANIFEST_OFFSET:flash-131072 ?= "888" |
Patrick Williams | 2e37529 | 2023-03-10 12:18:56 -0600 | [diff] [blame] | 61 | FLASH_UBOOT_ENV_OFFSET ?= "384" |
| 62 | FLASH_UBOOT_ENV_OFFSET:flash-65536 ?= "896" |
| 63 | FLASH_UBOOT_ENV_OFFSET:flash-131072 ?= "896" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 64 | FLASH_KERNEL_OFFSET ?= "512" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 65 | FLASH_KERNEL_OFFSET:flash-65536 ?= "1024" |
| 66 | FLASH_KERNEL_OFFSET:flash-131072 ?= "1024" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 67 | FLASH_UBI_OFFSET ?= "${FLASH_KERNEL_OFFSET}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 68 | FLASH_ROFS_OFFSET ?= "4864" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 69 | FLASH_ROFS_OFFSET:flash-65536 ?= "10240" |
| 70 | FLASH_ROFS_OFFSET:flash-131072 ?= "10240" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 71 | FLASH_RWFS_OFFSET ?= "28672" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 72 | FLASH_RWFS_OFFSET:flash-65536 ?= "43008" |
| 73 | FLASH_RWFS_OFFSET:flash-131072 ?= "98304" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 74 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 75 | # UBI volume sizes in KB unless otherwise noted. |
Adriana Kobylak | b70005d | 2018-02-14 16:35:30 -0600 | [diff] [blame] | 76 | FLASH_UBI_RWFS_SIZE ?= "6144" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 77 | FLASH_UBI_RWFS_SIZE:flash-131072 ?= "32768" |
Adriana Kobylak | b70005d | 2018-02-14 16:35:30 -0600 | [diff] [blame] | 78 | FLASH_UBI_RWFS_TXT_SIZE ?= "6MiB" |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 79 | FLASH_UBI_RWFS_TXT_SIZE:flash-131072 ?= "32MiB" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 80 | |
Adriana Kobylak | 45a5795 | 2020-07-01 16:23:11 -0500 | [diff] [blame] | 81 | # eMMC sizes in KB unless otherwise noted. |
Adriana Kobylak | 55681e4 | 2020-11-11 15:06:50 -0600 | [diff] [blame] | 82 | MMC_UBOOT_SIZE ?= "1024" |
Adriana Kobylak | 45a5795 | 2020-07-01 16:23:11 -0500 | [diff] [blame] | 83 | MMC_BOOT_PARTITION_SIZE ?= "65536" |
| 84 | |
Lei YU | 444782b | 2023-01-18 17:35:03 +0800 | [diff] [blame] | 85 | SIGNING_PUBLIC_KEY ?= "" |
| 86 | SIGNING_PUBLIC_KEY_TYPE = "${@os.path.splitext(os.path.basename('${SIGNING_PUBLIC_KEY}'))[0]}" |
| 87 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 88 | SIGNING_KEY ?= "${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv" |
| 89 | INSECURE_KEY = "${@'${SIGNING_KEY}' == '${STAGING_DIR_NATIVE}${datadir}/OpenBMC.priv'}" |
| 90 | SIGNING_KEY_DEPENDS = "${@oe.utils.conditional('INSECURE_KEY', 'True', 'phosphor-insecure-signing-key-native:do_populate_sysroot', '', d)}" |
| 91 | |
Adriana Kobylak | fb62a68 | 2019-10-28 16:03:12 -0500 | [diff] [blame] | 92 | VERSION_PURPOSE ?= "xyz.openbmc_project.Software.Version.VersionPurpose.BMC" |
| 93 | |
Brad Bishop | 3e37d38 | 2018-03-31 12:17:28 -0400 | [diff] [blame] | 94 | UBOOT_SUFFIX ?= "bin" |
| 95 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 96 | python() { |
| 97 | # Compute rwfs LEB count and LEB size. |
| 98 | page_size = d.getVar('FLASH_PAGE_SIZE', True) |
| 99 | nor_overhead_size = d.getVar('FLASH_NOR_UBI_OVERHEAD', True) |
| 100 | overhead_size = max(int(page_size), int(nor_overhead_size)) |
| 101 | peb_size = d.getVar('FLASH_PEB_SIZE', True) |
| 102 | leb_size = (int(peb_size) * 1024) - (2 * overhead_size) |
| 103 | d.setVar('FLASH_LEB_SIZE', str(leb_size)) # In bytes |
| 104 | |
| 105 | rwfs_size = d.getVar('FLASH_UBI_RWFS_SIZE', True) |
| 106 | rwfs_size = int(rwfs_size) * 1024 |
| 107 | lebs = int((rwfs_size + leb_size - 1) / leb_size) # Rounding up |
| 108 | d.setVar('FLASH_UBI_RWFS_LEBS', str(lebs)) |
| 109 | } |
| 110 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 111 | # Allow rwfs mkfs configuration through OVERLAY_MKFS_OPTS and OVERRIDES. However, |
| 112 | # avoid setting 'ext4' or 'jffs2' in OVERRIDES as such raw filesystem types are |
| 113 | # reserved for the primary image (and setting them currently breaks the build). |
| 114 | # Instead, prefix the overlay override value with 'rwfs-' to avoid collisions. |
| 115 | DISTROOVERRIDES .= ":static-rwfs-${OVERLAY_BASETYPE}" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 116 | DISTROOVERRIDES .= ":ubi-rwfs-${FLASH_UBI_OVERLAY_BASETYPE}" |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 117 | DISTROOVERRIDES .= ":mmc-rwfs-${FLASH_EXT4_OVERLAY_BASETYPE}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 118 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 119 | JFFS2_RWFS_CMD = "mkfs.jffs2 --root=jffs2 --faketime --output=${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.jffs2" |
| 120 | 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" |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 121 | EXT4_RWFS_CMD = "mkfs.ext4 -F ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 122 | |
Patrick Williams | 12fc939 | 2021-08-06 09:16:53 -0500 | [diff] [blame] | 123 | FLASH_STATIC_RWFS_CMD:static-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" |
| 124 | FLASH_UBI_RWFS_CMD:ubi-rwfs-jffs2 = "${JFFS2_RWFS_CMD}" |
| 125 | FLASH_UBI_RWFS_CMD:ubi-rwfs-ubifs = "${UBIFS_RWFS_CMD}" |
| 126 | FLASH_EXT4_RWFS_CMD:mmc-rwfs-ext4 = "${EXT4_RWFS_CMD}" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 127 | |
Adriana Kobylak | 661cf39 | 2019-07-29 14:39:00 -0500 | [diff] [blame] | 128 | mk_empty_image() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 129 | image_dst="$1" |
| 130 | image_size_kb=$2 |
| 131 | dd if=/dev/zero bs=1k count=$image_size_kb \ |
| 132 | | tr '\000' '\377' > $image_dst |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Adriana Kobylak | 55681e4 | 2020-11-11 15:06:50 -0600 | [diff] [blame] | 135 | mk_empty_image_zeros() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 136 | image_dst="$1" |
| 137 | image_size_kb=$2 |
| 138 | dd if=/dev/zero of=$image_dst bs=1k count=$image_size_kb |
Adriana Kobylak | 55681e4 | 2020-11-11 15:06:50 -0600 | [diff] [blame] | 139 | } |
| 140 | |
Adriana Kobylak | f494bb5 | 2019-07-29 16:14:11 -0500 | [diff] [blame] | 141 | clean_rwfs() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 142 | type=$1 |
| 143 | shift |
Adriana Kobylak | f494bb5 | 2019-07-29 16:14:11 -0500 | [diff] [blame] | 144 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 145 | rm -f ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type |
| 146 | rm -rf $type |
| 147 | mkdir $type |
Adriana Kobylak | f494bb5 | 2019-07-29 16:14:11 -0500 | [diff] [blame] | 148 | } |
| 149 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 150 | make_rwfs() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 151 | type=$1 |
| 152 | cmd=$2 |
| 153 | shift |
| 154 | shift |
| 155 | opts="$@" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 156 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 157 | mkdir -p $type |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 158 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 159 | $cmd $opts |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | do_generate_rwfs_static() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 163 | clean_rwfs ${OVERLAY_BASETYPE} |
| 164 | make_rwfs ${OVERLAY_BASETYPE} "${FLASH_STATIC_RWFS_CMD}" ${OVERLAY_MKFS_OPTS} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 165 | } |
| 166 | do_generate_rwfs_static[dirs] = " ${S}/static" |
| 167 | do_generate_rwfs_static[depends] += " \ |
| 168 | mtd-utils-native:do_populate_sysroot \ |
| 169 | " |
| 170 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 171 | do_generate_rwfs_ubi() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 172 | clean_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} |
| 173 | make_rwfs ${FLASH_UBI_OVERLAY_BASETYPE} "${FLASH_UBI_RWFS_CMD}" |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 174 | } |
| 175 | do_generate_rwfs_ubi[dirs] = " ${S}/ubi" |
| 176 | do_generate_rwfs_ubi[depends] += " \ |
| 177 | mtd-utils-native:do_populate_sysroot \ |
| 178 | " |
| 179 | |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 180 | do_generate_rwfs_ext4() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 181 | clean_rwfs rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} |
| 182 | mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.ext4 1024 |
| 183 | make_rwfs ${FLASH_EXT4_OVERLAY_BASETYPE} "${FLASH_EXT4_RWFS_CMD}" ${OVERLAY_MKFS_OPTS} |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 184 | } |
| 185 | do_generate_rwfs_ext4[dirs] = " ${S}/ext4" |
| 186 | do_generate_rwfs_ext4[depends] += " \ |
| 187 | e2fsprogs-native:do_populate_sysroot \ |
| 188 | " |
| 189 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 190 | add_volume() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 191 | config_file=$1 |
| 192 | vol_id=$2 |
| 193 | vol_type=$3 |
| 194 | vol_name=$4 |
| 195 | image=$5 |
| 196 | vol_size=$6 |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 197 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 198 | echo \[$vol_name\] >> $config_file |
| 199 | echo mode=ubi >> $config_file |
| 200 | echo image=$image >> $config_file |
| 201 | echo vol_type=$vol_type >> $config_file |
| 202 | echo vol_name=$vol_name >> $config_file |
| 203 | echo vol_id=$vol_id >> $config_file |
| 204 | if [ ! -z $vol_size ]; then |
| 205 | echo vol_size=$vol_size >> $config_file |
| 206 | fi |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 207 | } |
| 208 | |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 209 | python do_generate_ubi() { |
| 210 | version_id = do_get_versionID(d) |
| 211 | d.setVar('VERSION_ID', version_id) |
| 212 | bb.build.exec_func("do_make_ubi", d) |
| 213 | } |
| 214 | do_generate_ubi[dirs] = "${S}/ubi" |
| 215 | do_generate_ubi[depends] += " \ |
| 216 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 217 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 218 | u-boot:do_deploy \ |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 219 | mtd-utils-native:do_populate_sysroot \ |
| 220 | " |
| 221 | |
| 222 | do_make_ubi() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 223 | cfg=ubinize-${IMAGE_NAME}.cfg |
| 224 | rm -f $cfg ubi-img |
| 225 | # Construct the ubinize config file |
| 226 | add_volume $cfg 0 static kernel-${VERSION_ID} \ |
| 227 | ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 228 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 229 | add_volume $cfg 1 static rofs-${VERSION_ID} \ |
| 230 | ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_UBI_BASETYPE} |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 231 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 232 | 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] | 233 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 234 | # Build the ubi partition image |
| 235 | ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ubi-img $cfg |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 236 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 237 | # Concatenate the uboot and ubi partitions |
| 238 | mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd ${FLASH_SIZE} |
| 239 | dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \ |
| 240 | if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \ |
| 241 | of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd |
| 242 | dd bs=1k conv=notrunc seek=${FLASH_UBI_OFFSET} \ |
| 243 | if=ubi-img \ |
| 244 | of=${IMGDEPLOYDIR}/${IMAGE_NAME}.ubi.mtd |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 245 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 246 | cd ${IMGDEPLOYDIR} |
| 247 | ln -sf ${IMAGE_NAME}.ubi.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.ubi.mtd |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 248 | } |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 249 | do_make_ubi[dirs] = "${S}/ubi" |
| 250 | do_make_ubi[depends] += " \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 251 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 252 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 253 | u-boot:do_deploy \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 254 | mtd-utils-native:do_populate_sysroot \ |
| 255 | " |
| 256 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 257 | do_mk_static_nor_image() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 258 | # Assemble the flash image |
| 259 | mk_empty_image ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd ${FLASH_SIZE} |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 260 | } |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 261 | |
Adriana Kobylak | f1954f0 | 2020-04-27 15:20:35 -0500 | [diff] [blame] | 262 | do_generate_image_uboot_file() { |
| 263 | image_dst="$1" |
| 264 | uboot_offset=${FLASH_UBOOT_OFFSET} |
| 265 | |
| 266 | if [ ! -z ${SPL_BINARY} ]; then |
| 267 | dd bs=1k conv=notrunc seek=${FLASH_UBOOT_OFFSET} \ |
| 268 | if=${DEPLOY_DIR_IMAGE}/u-boot-spl.${UBOOT_SUFFIX} \ |
| 269 | of=${image_dst} |
| 270 | uboot_offset=${FLASH_UBOOT_SPL_SIZE} |
| 271 | fi |
| 272 | |
| 273 | dd bs=1k conv=notrunc seek=${uboot_offset} \ |
| 274 | if=${DEPLOY_DIR_IMAGE}/u-boot.${UBOOT_SUFFIX} \ |
| 275 | of=${image_dst} |
| 276 | } |
| 277 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 278 | python do_generate_static() { |
| 279 | import subprocess |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 280 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 281 | bb.build.exec_func("do_mk_static_nor_image", d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 282 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 283 | nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 284 | '%s.static.mtd' % d.getVar('IMAGE_NAME', True)) |
| 285 | |
| 286 | def _append_image(imgpath, start_kb, finish_kb): |
| 287 | imgsize = os.path.getsize(imgpath) |
Josh Lehan | 0a5ef2a | 2020-02-26 12:11:33 -0800 | [diff] [blame] | 288 | maxsize = (finish_kb - start_kb) * 1024 |
| 289 | bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath) |
| 290 | bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K') |
| 291 | bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize)) |
| 292 | if imgsize > maxsize: |
Joel Stanley | 909f33e | 2023-01-18 18:56:17 +1030 | [diff] [blame] | 293 | bb.fatal("Image '%s' is %d bytes too large!" % (imgpath, imgsize - maxsize)) |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 294 | |
| 295 | subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc', |
| 296 | 'seek=%d' % start_kb, |
| 297 | 'if=%s' % imgpath, |
| 298 | 'of=%s' % nor_image]) |
| 299 | |
Adriana Kobylak | e913dd8 | 2020-04-13 13:56:41 -0500 | [diff] [blame] | 300 | uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True)) |
| 301 | |
| 302 | spl_binary = d.getVar('SPL_BINARY', True) |
| 303 | if spl_binary: |
| 304 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 305 | 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)), |
| 306 | int(d.getVar('FLASH_UBOOT_OFFSET', True)), |
| 307 | int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))) |
| 308 | uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)) |
| 309 | |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 310 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 311 | 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)), |
Adriana Kobylak | e913dd8 | 2020-04-13 13:56:41 -0500 | [diff] [blame] | 312 | uboot_offset, |
Patrick Williams | 2e37529 | 2023-03-10 12:18:56 -0600 | [diff] [blame] | 313 | int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True))) |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 314 | |
| 315 | _append_image(os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
| 316 | d.getVar('FLASH_KERNEL_IMAGE', True)), |
| 317 | int(d.getVar('FLASH_KERNEL_OFFSET', True)), |
| 318 | int(d.getVar('FLASH_ROFS_OFFSET', True))) |
| 319 | |
| 320 | _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 321 | '%s.%s' % ( |
| 322 | d.getVar('IMAGE_LINK_NAME', True), |
| 323 | d.getVar('IMAGE_BASETYPE', True))), |
| 324 | int(d.getVar('FLASH_ROFS_OFFSET', True)), |
| 325 | int(d.getVar('FLASH_RWFS_OFFSET', True))) |
| 326 | |
William A. Kennington III | c230ab3 | 2019-09-16 17:44:48 -0700 | [diff] [blame] | 327 | _append_image(os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 328 | '%s.%s' % ( |
| 329 | d.getVar('IMAGE_LINK_NAME', True), |
| 330 | d.getVar('OVERLAY_BASETYPE', True))), |
Alexander Filippov | 3dcf6f9 | 2018-07-17 16:41:37 +0300 | [diff] [blame] | 331 | int(d.getVar('FLASH_RWFS_OFFSET', True)), |
| 332 | int(d.getVar('FLASH_SIZE', True))) |
| 333 | |
| 334 | bb.build.exec_func("do_mk_static_symlinks", d) |
| 335 | } |
| 336 | |
| 337 | do_mk_static_symlinks() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 338 | cd ${IMGDEPLOYDIR} |
| 339 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 340 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 341 | # Maintain non-standard legacy links |
| 342 | do_generate_image_uboot_file ${IMGDEPLOYDIR}/image-u-boot |
| 343 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/flash-${MACHINE} |
| 344 | ln -sf ${IMAGE_NAME}.static.mtd ${IMGDEPLOYDIR}/image-bmc |
| 345 | ln -sf ${FLASH_KERNEL_IMAGE} ${IMGDEPLOYDIR}/image-kernel |
| 346 | ln -sf ${IMAGE_LINK_NAME}.${IMAGE_BASETYPE} ${IMGDEPLOYDIR}/image-rofs |
| 347 | ln -sf ${IMAGE_LINK_NAME}.${OVERLAY_BASETYPE} ${IMGDEPLOYDIR}/image-rwfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 348 | } |
| 349 | do_generate_static[dirs] = "${S}/static" |
| 350 | do_generate_static[depends] += " \ |
| 351 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 352 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 353 | u-boot:do_deploy \ |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 354 | " |
| 355 | |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 356 | make_signatures() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 357 | signing_key="${SIGNING_KEY}" |
George Liu | f0afcf8 | 2020-12-15 09:46:10 +0800 | [diff] [blame] | 358 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 359 | if [ "${INSECURE_KEY}" == "True" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then |
| 360 | echo "Using SIGNING_PUBLIC_KEY" |
| 361 | signing_key="" |
| 362 | fi |
Lei YU | 444782b | 2023-01-18 17:35:03 +0800 | [diff] [blame] | 363 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 364 | if [ -n "${signing_key}" ] && [ -n "${SIGNING_PUBLIC_KEY}" ]; then |
| 365 | echo "Both SIGNING_KEY and SIGNING_PUBLIC_KEY are defined, expecting only one" |
| 366 | exit 1 |
| 367 | fi |
Lei YU | 444782b | 2023-01-18 17:35:03 +0800 | [diff] [blame] | 368 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 369 | signature_files="" |
| 370 | if [ -n "${signing_key}" ]; then |
| 371 | for file in "$@"; do |
| 372 | openssl dgst -sha256 -sign ${signing_key} -out "${file}.sig" $file |
| 373 | signature_files="${signature_files} ${file}.sig" |
| 374 | done |
Lei YU | 444782b | 2023-01-18 17:35:03 +0800 | [diff] [blame] | 375 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 376 | if [ -n "${signature_files}" ]; then |
| 377 | sort_signature_files=$(echo "${signature_files}" | tr ' ' '\n' | sort | tr '\n' ' ') |
| 378 | cat ${sort_signature_files} > image-full |
| 379 | openssl dgst -sha256 -sign ${signing_key} -out image-full.sig image-full |
| 380 | signature_files="${signature_files} image-full.sig" |
| 381 | fi |
| 382 | fi |
Lei YU | f207221 | 2018-06-20 13:27:34 +0800 | [diff] [blame] | 383 | } |
| 384 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 385 | do_generate_static_alltar() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 386 | ln -sf ${S}/MANIFEST MANIFEST |
| 387 | ln -sf ${S}/publickey publickey |
| 388 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd image-bmc |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 389 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 390 | make_signatures image-bmc MANIFEST publickey |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 391 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 392 | tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.static.mtd.all.tar \ |
| 393 | image-bmc MANIFEST publickey ${signature_files} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 394 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 395 | cd ${IMGDEPLOYDIR} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 396 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 397 | ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ |
| 398 | ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.static.mtd.all.tar |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 399 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 400 | # Maintain non-standard legacy link. |
| 401 | ln -sf ${IMAGE_NAME}.static.mtd.all.tar \ |
| 402 | ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.all.tar |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 403 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 404 | } |
| 405 | do_generate_static_alltar[vardepsexclude] = "DATETIME" |
| 406 | do_generate_static_alltar[dirs] = "${S}/static" |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 407 | do_generate_static_alltar[depends] += " \ |
| 408 | openssl-native:do_populate_sysroot \ |
| 409 | ${SIGNING_KEY_DEPENDS} \ |
| 410 | ${PN}:do_copy_signing_pubkey \ |
| 411 | " |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 412 | |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 413 | make_image_links() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 414 | rwfs=$1 |
| 415 | rofs=$2 |
| 416 | shift |
| 417 | shift |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 418 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 419 | # Create some links to help make the tar archive in the format |
| 420 | # expected by phosphor-bmc-code-mgmt. |
| 421 | do_generate_image_uboot_file image-u-boot |
| 422 | ln -sf ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} image-kernel |
| 423 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rofs image-rofs |
| 424 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$rwfs image-rwfs |
Brad Bishop | de65938 | 2018-03-30 01:46:16 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | make_tar_of_images() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 428 | type=$1 |
| 429 | shift |
| 430 | extra_files="$@" |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 431 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 432 | # Create the tar archive |
| 433 | tar -h -cvf ${IMGDEPLOYDIR}/${IMAGE_NAME}.$type.tar \ |
| 434 | image-u-boot image-kernel image-rofs image-rwfs $extra_files |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 435 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 436 | cd ${IMGDEPLOYDIR} |
| 437 | ln -sf ${IMAGE_NAME}.$type.tar ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.$type.tar |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | do_generate_static_tar() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 441 | ln -sf ${S}/MANIFEST MANIFEST |
| 442 | ln -sf ${S}/publickey publickey |
| 443 | make_image_links ${OVERLAY_BASETYPE} ${IMAGE_BASETYPE} |
| 444 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey |
| 445 | make_tar_of_images static.mtd MANIFEST publickey ${signature_files} |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 446 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 447 | # Maintain non-standard legacy link. |
| 448 | cd ${IMGDEPLOYDIR} |
| 449 | ln -sf ${IMAGE_NAME}.static.mtd.tar ${IMGDEPLOYDIR}/${MACHINE}-${DATETIME}.tar |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 450 | } |
| 451 | do_generate_static_tar[dirs] = " ${S}/static" |
| 452 | do_generate_static_tar[depends] += " \ |
| 453 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 454 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 455 | u-boot:do_deploy \ |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 456 | openssl-native:do_populate_sysroot \ |
| 457 | ${SIGNING_KEY_DEPENDS} \ |
| 458 | ${PN}:do_copy_signing_pubkey \ |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 459 | " |
| 460 | do_generate_static_tar[vardepsexclude] = "DATETIME" |
| 461 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 462 | python do_generate_static_norootfs() { |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 463 | import hashlib |
| 464 | import json |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 465 | import subprocess |
| 466 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 467 | manifest = { |
| 468 | "type": "phosphor-image-manifest", |
| 469 | "version": 1, |
| 470 | "info": { |
| 471 | "purpose": d.getVar('VERSION_PURPOSE', True), |
| 472 | "machine": d.getVar('MACHINE', True), |
| 473 | "version": do_get_version(d).strip('"'), |
| 474 | "build-id": do_get_buildID(d).strip('"'), |
| 475 | }, |
| 476 | "partitions": [], |
| 477 | # Create an empty hash-value so that the dictionary can be emitted, |
| 478 | # hashed, and then updated. |
| 479 | "manifest-sha256": "", |
| 480 | } |
| 481 | extended_version = do_get_extended_version(d).strip('"') |
| 482 | if extended_version: |
| 483 | manifest["info"]["extended-version"] = extended_version |
| 484 | compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True) |
| 485 | if compatible_names: |
| 486 | manifest["info"]["compatible-names"] = compatible_names.split() |
| 487 | |
| 488 | manifest_json_file = os.path.join(d.getVar('IMGDEPLOYDIR', True), |
| 489 | "phosphor-image-manifest.json") |
| 490 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 491 | nor_image_basename = '%s.static.mtd' % d.getVar('IMAGE_NAME', True) |
| 492 | nor_image = os.path.join(d.getVar('IMGDEPLOYDIR', True), nor_image_basename) |
| 493 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 494 | def _add_manifest(partname, typename, offset, size, sha256_value = None): |
| 495 | manifest["partitions"].append( |
| 496 | { |
| 497 | "name": partname, |
| 498 | "type": typename, |
| 499 | "offset": offset, |
| 500 | "size": size, |
| 501 | } |
| 502 | ) |
| 503 | if typename == "fit": |
| 504 | if "u-boot-fit" == partname: |
| 505 | manifest["partitions"][-1]["num-nodes"] = 1 |
| 506 | elif "os-fit" == partname: |
| 507 | manifest["partitions"][-1]["num-nodes"] = 3 |
| 508 | else: |
| 509 | bb.fatal(f"Unknown FIT partition type: {partname}") |
| 510 | if sha256_value: |
| 511 | manifest["partitions"][-1]["sha256"] = sha256_value |
| 512 | |
| 513 | |
| 514 | def _append_image(partname, typename, imgpath, start_kb, finish_kb): |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 515 | imgsize = os.path.getsize(imgpath) |
| 516 | maxsize = (finish_kb - start_kb) * 1024 |
| 517 | bb.debug(1, 'Considering file size=' + str(imgsize) + ' name=' + imgpath) |
| 518 | bb.debug(1, 'Spanning start=' + str(start_kb) + 'K end=' + str(finish_kb) + 'K') |
| 519 | bb.debug(1, 'Compare needed=' + str(imgsize) + ' available=' + str(maxsize) + ' margin=' + str(maxsize - imgsize)) |
| 520 | if imgsize > maxsize: |
| 521 | bb.fatal("Image '%s' is too large!" % imgpath) |
| 522 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 523 | with open(imgpath, "rb") as fp: |
| 524 | sha256 = hashlib.sha256(fp.read()).hexdigest() |
| 525 | |
| 526 | _add_manifest(partname, typename, start_kb * 1024, imgsize, sha256) |
| 527 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 528 | subprocess.check_call(['dd', 'bs=1k', 'conv=notrunc', |
| 529 | 'seek=%d' % start_kb, |
| 530 | 'if=%s' % imgpath, |
| 531 | 'of=%s' % nor_image]) |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 532 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 533 | uboot_offset = int(d.getVar('FLASH_UBOOT_OFFSET', True)) |
| 534 | |
| 535 | spl_binary = d.getVar('SPL_BINARY', True) |
| 536 | if spl_binary: |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 537 | _append_image("spl", "u-boot", |
| 538 | os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 539 | 'u-boot-spl.%s' % d.getVar('UBOOT_SUFFIX',True)), |
| 540 | int(d.getVar('FLASH_UBOOT_OFFSET', True)), |
| 541 | int(d.getVar('FLASH_UBOOT_SPL_SIZE', True))) |
| 542 | uboot_offset += int(d.getVar('FLASH_UBOOT_SPL_SIZE', True)) |
| 543 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 544 | _append_image("u-boot-fit", "fit", |
| 545 | os.path.join(d.getVar('DEPLOY_DIR_IMAGE', True), |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 546 | 'u-boot.%s' % d.getVar('UBOOT_SUFFIX',True)), |
| 547 | uboot_offset, |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 548 | int(d.getVar('FLASH_MANIFEST_OFFSET', True))) |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 549 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 550 | _add_manifest("manifest", "json", |
| 551 | int(d.getVar('FLASH_MANIFEST_OFFSET', True)) * 1024, |
| 552 | (int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) - |
| 553 | int(d.getVar('FLASH_MANIFEST_OFFSET', True))) * 1024) |
| 554 | |
| 555 | _add_manifest("u-boot-env", "data", |
| 556 | int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True)) * 1024, |
| 557 | (int(d.getVar('FLASH_KERNEL_OFFSET', True)) - |
| 558 | int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True))) * 1024) |
| 559 | |
| 560 | _append_image("os-fit", "fit", |
| 561 | os.path.join(d.getVar('IMGDEPLOYDIR', True), |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 562 | '%s.cpio.%s.fitImage' % ( |
| 563 | d.getVar('IMAGE_LINK_NAME', True), |
| 564 | d.getVar('INITRAMFS_CTYPE', True))), |
| 565 | int(d.getVar('FLASH_KERNEL_OFFSET', True)), |
| 566 | int(d.getVar('FLASH_RWFS_OFFSET', True))) |
| 567 | |
Patrick Williams | 917fab2 | 2023-03-10 16:58:50 -0600 | [diff] [blame] | 568 | _add_manifest("rwfs", "data", |
| 569 | int(d.getVar('FLASH_RWFS_OFFSET', True)) * 1024, |
| 570 | (int(d.getVar('FLASH_SIZE', True)) - |
| 571 | int(d.getVar('FLASH_RWFS_OFFSET', True))) * 1024) |
| 572 | |
| 573 | # Calculate the sha256 of the current manifest and update. |
| 574 | manifest_raw = json.dumps(manifest, indent=4) |
| 575 | manifest_raw = manifest_raw[:manifest_raw.find("manifest-sha256")] |
| 576 | manifest["manifest-sha256"] = hashlib.sha256( |
| 577 | manifest_raw.encode('utf-8')).hexdigest() |
| 578 | |
| 579 | # Write the final manifest json and add it to the image. |
| 580 | with open(manifest_json_file, "wb") as fp: |
| 581 | fp.write(json.dumps(manifest, indent=4).encode('utf-8')) |
| 582 | _append_image("manifest", "json", manifest_json_file, |
| 583 | int(d.getVar('FLASH_MANIFEST_OFFSET', True)), |
| 584 | int(d.getVar('FLASH_UBOOT_ENV_OFFSET', True))) |
| 585 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 586 | flash_symlink = os.path.join( |
| 587 | d.getVar('IMGDEPLOYDIR', True), |
| 588 | 'flash-%s' % d.getVar('MACHINE', True)) |
| 589 | if os.path.exists(flash_symlink): |
| 590 | os.remove(flash_symlink) |
| 591 | os.symlink(nor_image_basename, flash_symlink) |
| 592 | } |
| 593 | do_generate_static_norootfs[depends] += " \ |
| 594 | ${PN}:do_image_${@d.getVar('IMAGE_BASETYPE', True).replace('-', '_')} \ |
| 595 | u-boot:do_deploy \ |
| 596 | " |
| 597 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 598 | do_generate_ubi_tar() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 599 | ln -sf ${S}/MANIFEST MANIFEST |
| 600 | ln -sf ${S}/publickey publickey |
| 601 | make_image_links ${FLASH_UBI_OVERLAY_BASETYPE} ${FLASH_UBI_BASETYPE} |
| 602 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey |
| 603 | make_tar_of_images ubi.mtd MANIFEST publickey ${signature_files} |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 604 | } |
| 605 | do_generate_ubi_tar[dirs] = " ${S}/ubi" |
| 606 | do_generate_ubi_tar[depends] += " \ |
| 607 | ${PN}:do_image_${@d.getVar('FLASH_UBI_BASETYPE', True).replace('-', '_')} \ |
| 608 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 609 | u-boot:do_deploy \ |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 610 | openssl-native:do_populate_sysroot \ |
| 611 | ${SIGNING_KEY_DEPENDS} \ |
| 612 | ${PN}:do_copy_signing_pubkey \ |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 613 | " |
| 614 | |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 615 | do_generate_ext4_tar() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 616 | # Generate the U-Boot image |
| 617 | mk_empty_image_zeros image-u-boot ${MMC_UBOOT_SIZE} |
| 618 | do_generate_image_uboot_file image-u-boot |
Adriana Kobylak | 45a5795 | 2020-07-01 16:23:11 -0500 | [diff] [blame] | 619 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 620 | # Generate a compressed ext4 filesystem with the fitImage file in it to be |
| 621 | # flashed to the boot partition of the eMMC |
| 622 | install -d boot-image |
| 623 | install -m 644 ${DEPLOY_DIR_IMAGE}/${FLASH_KERNEL_IMAGE} boot-image/fitImage |
| 624 | mk_empty_image_zeros boot-image.${FLASH_EXT4_BASETYPE} ${MMC_BOOT_PARTITION_SIZE} |
| 625 | mkfs.ext4 -F -i 4096 -d boot-image boot-image.${FLASH_EXT4_BASETYPE} |
| 626 | # Error codes 0-3 indicate successfull operation of fsck |
| 627 | fsck.ext4 -pvfD boot-image.${FLASH_EXT4_BASETYPE} || [ $? -le 3 ] |
| 628 | zstd -f -k -T0 -c ${ZSTD_COMPRESSION_LEVEL} boot-image.${FLASH_EXT4_BASETYPE} > boot-image.${FLASH_EXT4_BASETYPE}.zst |
Adriana Kobylak | 45a5795 | 2020-07-01 16:23:11 -0500 | [diff] [blame] | 629 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 630 | # Generate the compressed ext4 rootfs |
| 631 | zstd -f -k -T0 -c ${ZSTD_COMPRESSION_LEVEL} ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE} > ${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE}.zst |
Adriana Kobylak | 45a5795 | 2020-07-01 16:23:11 -0500 | [diff] [blame] | 632 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 633 | ln -sf boot-image.${FLASH_EXT4_BASETYPE}.zst image-kernel |
| 634 | ln -sf ${IMAGE_LINK_NAME}.${FLASH_EXT4_BASETYPE}.zst image-rofs |
| 635 | ln -sf ${IMGDEPLOYDIR}/${IMAGE_LINK_NAME}.rwfs.${FLASH_EXT4_OVERLAY_BASETYPE} image-rwfs |
| 636 | ln -sf ${S}/MANIFEST MANIFEST |
| 637 | ln -sf ${S}/publickey publickey |
Adriana Kobylak | 81846a2 | 2020-07-12 15:12:36 -0500 | [diff] [blame] | 638 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 639 | hostfw_update_file="${DEPLOY_DIR_IMAGE}/hostfw/update/image-hostfw" |
| 640 | if [ -e "${hostfw_update_file}" ]; then |
| 641 | ln -sf "${hostfw_update_file}" image-hostfw |
| 642 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey image-hostfw |
| 643 | make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files} image-hostfw |
| 644 | else |
| 645 | make_signatures image-u-boot image-kernel image-rofs image-rwfs MANIFEST publickey |
| 646 | make_tar_of_images ext4.mmc MANIFEST publickey ${signature_files} |
| 647 | fi |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 648 | } |
| 649 | do_generate_ext4_tar[dirs] = " ${S}/ext4" |
| 650 | do_generate_ext4_tar[depends] += " \ |
Adriana Kobylak | 4cc866b | 2020-03-28 13:43:33 -0500 | [diff] [blame] | 651 | zstd-native:do_populate_sysroot \ |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 652 | ${PN}:do_image_${FLASH_EXT4_BASETYPE} \ |
| 653 | virtual/kernel:do_deploy \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 654 | u-boot:do_deploy \ |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 655 | openssl-native:do_populate_sysroot \ |
| 656 | ${SIGNING_KEY_DEPENDS} \ |
| 657 | ${PN}:do_copy_signing_pubkey \ |
Brad Bishop | 209ed52 | 2020-11-02 12:36:04 -0500 | [diff] [blame] | 658 | phosphor-hostfw-image:do_deploy \ |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 659 | " |
| 660 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 661 | def get_pubkey_basedir(d): |
| 662 | return os.path.join( |
| 663 | d.getVar('STAGING_DIR_TARGET', True), |
| 664 | d.getVar('sysconfdir', True).strip(os.sep), |
| 665 | 'activationdata') |
| 666 | |
| 667 | def get_pubkey_type(d): |
| 668 | return os.listdir(get_pubkey_basedir(d))[0] |
| 669 | |
| 670 | def get_pubkey_path(d): |
| 671 | return os.path.join( |
| 672 | get_pubkey_basedir(d), |
| 673 | get_pubkey_type(d), |
| 674 | 'publickey') |
| 675 | |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 676 | python do_generate_phosphor_manifest() { |
Adriana Kobylak | fb62a68 | 2019-10-28 16:03:12 -0500 | [diff] [blame] | 677 | purpose = d.getVar('VERSION_PURPOSE', True) |
Saqib Khan | 4172347 | 2017-09-22 10:21:30 -0500 | [diff] [blame] | 678 | version = do_get_version(d) |
Adriana Kobylak | cdd91ad | 2021-10-25 15:58:19 +0000 | [diff] [blame] | 679 | build_id = do_get_buildID(d) |
Vijay Khemka | ae614bd | 2019-09-18 12:28:46 -0700 | [diff] [blame] | 680 | target_machine = d.getVar('MACHINE', True) |
Adriana Kobylak | bde7dbe | 2022-08-04 09:13:26 -0500 | [diff] [blame] | 681 | extended_version = do_get_extended_version(d) |
Justin Ledford | b4de16d | 2022-03-24 17:27:17 -0700 | [diff] [blame] | 682 | compatible_names = d.getVar('OBMC_COMPATIBLE_NAMES', True) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 683 | with open('MANIFEST', 'w') as fd: |
Adriana Kobylak | fb62a68 | 2019-10-28 16:03:12 -0500 | [diff] [blame] | 684 | fd.write('purpose={}\n'.format(purpose)) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 685 | fd.write('version={}\n'.format(version.strip('"'))) |
Adriana Kobylak | cdd91ad | 2021-10-25 15:58:19 +0000 | [diff] [blame] | 686 | fd.write('BuildId={}\n'.format(build_id.strip('"'))) |
Justin Ledford | b4de16d | 2022-03-24 17:27:17 -0700 | [diff] [blame] | 687 | if extended_version: |
| 688 | fd.write('ExtendedVersion={}\n'.format(extended_version)) |
| 689 | if compatible_names: |
| 690 | for name in compatible_names.split(): |
| 691 | fd.write('CompatibleName={}\n'.format(name)) |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 692 | fd.write('KeyType={}\n'.format(get_pubkey_type(d))) |
| 693 | fd.write('HashType=RSA-SHA256\n') |
Vijay Khemka | ae614bd | 2019-09-18 12:28:46 -0700 | [diff] [blame] | 694 | fd.write('MachineName={}\n'.format(target_machine)) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 695 | } |
| 696 | do_generate_phosphor_manifest[dirs] = "${S}" |
| 697 | do_generate_phosphor_manifest[depends] += " \ |
| 698 | os-release:do_populate_sysroot \ |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 699 | phosphor-image-signing:do_populate_sysroot \ |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 700 | " |
| 701 | |
Eddie James | b2b7ff6 | 2018-02-09 11:59:18 -0600 | [diff] [blame] | 702 | python do_copy_signing_pubkey() { |
| 703 | with open(get_pubkey_path(d), 'r') as read_fd: |
| 704 | with open('publickey', 'w') as write_fd: |
| 705 | write_fd.write(read_fd.read()) |
| 706 | } |
| 707 | |
| 708 | do_copy_signing_pubkey[dirs] = "${S}" |
| 709 | do_copy_signing_pubkey[depends] += " \ |
| 710 | phosphor-image-signing:do_populate_sysroot \ |
| 711 | " |
| 712 | |
| 713 | addtask copy_signing_pubkey after do_rootfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 714 | addtask generate_phosphor_manifest after do_rootfs |
| 715 | addtask generate_rwfs_static after do_rootfs |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 716 | addtask generate_rwfs_ubi after do_rootfs |
Adriana Kobylak | 5a5753a | 2019-07-30 11:27:46 -0500 | [diff] [blame] | 717 | addtask generate_rwfs_ext4 after do_rootfs |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 718 | |
| 719 | python() { |
| 720 | types = d.getVar('IMAGE_FSTYPES', True).split() |
| 721 | |
| 722 | if any([x in types for x in ['mtd-static', 'mtd-static-alltar']]): |
| 723 | bb.build.addtask( |
| 724 | 'do_generate_static', |
| 725 | 'do_image_complete', |
| 726 | 'do_generate_rwfs_static', d) |
| 727 | if 'mtd-static-alltar' in types: |
| 728 | bb.build.addtask( |
| 729 | 'do_generate_static_alltar', |
| 730 | 'do_image_complete', |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 731 | 'do_generate_static do_generate_phosphor_manifest', d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 732 | if 'mtd-static-tar' in types: |
| 733 | bb.build.addtask( |
| 734 | 'do_generate_static_tar', |
| 735 | 'do_image_complete', |
Lei YU | a467494 | 2018-05-23 14:01:14 +0800 | [diff] [blame] | 736 | 'do_generate_rwfs_static do_generate_phosphor_manifest', d) |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 737 | |
Patrick Williams | b9e124c | 2022-12-14 09:10:49 -0600 | [diff] [blame] | 738 | if 'mtd-static-norootfs' in types: |
| 739 | bb.build.addtask( |
| 740 | 'do_generate_static_norootfs', |
| 741 | 'do_image_complete', |
| 742 | 'do_image_cpio', d) |
| 743 | |
Brad Bishop | 3aa1ef6 | 2017-08-04 23:48:12 -0400 | [diff] [blame] | 744 | if 'mtd-ubi' in types: |
| 745 | bb.build.addtask( |
| 746 | 'do_generate_ubi', |
| 747 | 'do_image_complete', |
| 748 | 'do_generate_rwfs_ubi', d) |
| 749 | if 'mtd-ubi-tar' in types: |
| 750 | bb.build.addtask( |
| 751 | 'do_generate_ubi_tar', |
| 752 | 'do_image_complete', |
| 753 | 'do_generate_rwfs_ubi do_generate_phosphor_manifest', d) |
Adriana Kobylak | 9b7197e | 2019-07-29 15:25:33 -0500 | [diff] [blame] | 754 | |
| 755 | if 'mmc-ext4-tar' in types: |
| 756 | bb.build.addtask( |
| 757 | 'do_generate_ext4_tar', |
| 758 | 'do_image_complete', |
| 759 | 'do_generate_rwfs_ext4 do_generate_phosphor_manifest', d) |
Brad Bishop | 19fc4f8 | 2017-08-04 23:38:54 -0400 | [diff] [blame] | 760 | } |