Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | inherit kernel-uboot kernel-artifact-names uboot-sign |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | python __anonymous () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 4 | kerneltypes = d.getVar('KERNEL_IMAGETYPES') or "" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 5 | if 'fitImage' in kerneltypes.split(): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 6 | depends = d.getVar("DEPENDS") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 7 | depends = "%s u-boot-tools-native dtc-native" % depends |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | d.setVar("DEPENDS", depends) |
| 9 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | uarch = d.getVar("UBOOT_ARCH") |
| 11 | if uarch == "arm64": |
| 12 | replacementtype = "Image" |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 13 | elif uarch == "riscv": |
| 14 | replacementtype = "Image" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 15 | elif uarch == "mips": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | replacementtype = "vmlinuz.bin" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 17 | elif uarch == "x86": |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 18 | replacementtype = "bzImage" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 19 | elif uarch == "microblaze": |
| 20 | replacementtype = "linux.bin" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | else: |
| 22 | replacementtype = "zImage" |
| 23 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 24 | # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal |
| 25 | # to kernel.bbclass . We have to override it, since we pack zImage |
| 26 | # (at least for now) into the fitImage . |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or "" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 28 | if 'fitImage' in typeformake.split(): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 29 | d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', replacementtype)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | image = d.getVar('INITRAMFS_IMAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | if image: |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 33 | d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
| 34 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 35 | #check if there are any dtb providers |
| 36 | providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb") |
| 37 | if providerdtb: |
| 38 | d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot') |
| 39 | d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot') |
| 40 | d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree") |
| 41 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 42 | # Verified boot will sign the fitImage and append the public key to |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 43 | # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 44 | # the fitImage: |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 45 | if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 46 | uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot' |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 47 | d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | } |
| 49 | |
Yannick Gicquel | d5813b4 | 2016-04-27 16:20:55 +0200 | [diff] [blame] | 50 | # Options for the device tree compiler passed to mkimage '-D' feature: |
| 51 | UBOOT_MKIMAGE_DTCOPTS ??= "" |
| 52 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 53 | # fitImage Hash Algo |
| 54 | FIT_HASH_ALG ?= "sha256" |
| 55 | |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 56 | # fitImage Signature Algo |
| 57 | FIT_SIGN_ALG ?= "rsa2048" |
| 58 | |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 59 | # Generate keys for signing fitImage |
| 60 | FIT_GENERATE_KEYS ?= "0" |
| 61 | |
| 62 | # Size of private key in number of bits |
| 63 | FIT_SIGN_NUMBITS ?= "2048" |
| 64 | |
| 65 | # args to openssl genrsa (Default is just the public exponent) |
| 66 | FIT_KEY_GENRSA_ARGS ?= "-F4" |
| 67 | |
| 68 | # args to openssl req (Default is -batch for non interactive mode and |
| 69 | # -new for new certificate) |
| 70 | FIT_KEY_REQ_ARGS ?= "-batch -new" |
| 71 | |
| 72 | # Standard format for public key certificate |
| 73 | FIT_KEY_SIGN_PKCS ?= "-x509" |
| 74 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 75 | # Description string |
| 76 | FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" |
| 77 | |
| 78 | # Sign individual images as well |
| 79 | FIT_SIGN_INDIVIDUAL ?= "0" |
| 80 | |
| 81 | # mkimage command |
| 82 | UBOOT_MKIMAGE ?= "uboot-mkimage" |
| 83 | UBOOT_MKIMAGE_SIGN ?= "${UBOOT_MKIMAGE}" |
| 84 | |
| 85 | # Arguments passed to mkimage for signing |
| 86 | UBOOT_MKIMAGE_SIGN_ARGS ?= "" |
| 87 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 88 | # |
| 89 | # Emit the fitImage ITS header |
| 90 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 91 | # $1 ... .its filename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | fitimage_emit_fit_header() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 93 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 94 | /dts-v1/; |
| 95 | |
| 96 | / { |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 97 | description = "${FIT_DESC}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | #address-cells = <1>; |
| 99 | EOF |
| 100 | } |
| 101 | |
| 102 | # |
| 103 | # Emit the fitImage section bits |
| 104 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 105 | # $1 ... .its filename |
| 106 | # $2 ... Section bit type: imagestart - image section start |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 107 | # confstart - configuration section start |
| 108 | # sectend - section end |
| 109 | # fitend - fitimage end |
| 110 | # |
| 111 | fitimage_emit_section_maint() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 112 | case $2 in |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | imagestart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 114 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 115 | |
| 116 | images { |
| 117 | EOF |
| 118 | ;; |
| 119 | confstart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 120 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | |
| 122 | configurations { |
| 123 | EOF |
| 124 | ;; |
| 125 | sectend) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 126 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | }; |
| 128 | EOF |
| 129 | ;; |
| 130 | fitend) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 131 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | }; |
| 133 | EOF |
| 134 | ;; |
| 135 | esac |
| 136 | } |
| 137 | |
| 138 | # |
| 139 | # Emit the fitImage ITS kernel section |
| 140 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 141 | # $1 ... .its filename |
| 142 | # $2 ... Image counter |
| 143 | # $3 ... Path to kernel image |
| 144 | # $4 ... Compression type |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | fitimage_emit_section_kernel() { |
| 146 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 147 | kernel_csum="${FIT_HASH_ALG}" |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 148 | kernel_sign_algo="${FIT_SIGN_ALG}" |
| 149 | kernel_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 151 | ENTRYPOINT="${UBOOT_ENTRYPOINT}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 152 | if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then |
| 153 | ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \ |
| 154 | awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'` |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 155 | fi |
| 156 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 157 | cat << EOF >> ${1} |
| 158 | kernel@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | description = "Linux kernel"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 160 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | type = "kernel"; |
| 162 | arch = "${UBOOT_ARCH}"; |
| 163 | os = "linux"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 164 | compression = "${4}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | load = <${UBOOT_LOADADDRESS}>; |
| 166 | entry = <${ENTRYPOINT}>; |
| 167 | hash@1 { |
| 168 | algo = "${kernel_csum}"; |
| 169 | }; |
| 170 | }; |
| 171 | EOF |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 172 | |
| 173 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${kernel_sign_keyname}" ] ; then |
| 174 | sed -i '$ d' ${1} |
| 175 | cat << EOF >> ${1} |
| 176 | signature@1 { |
| 177 | algo = "${kernel_csum},${kernel_sign_algo}"; |
| 178 | key-name-hint = "${kernel_sign_keyname}"; |
| 179 | }; |
| 180 | }; |
| 181 | EOF |
| 182 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | # |
| 186 | # Emit the fitImage ITS DTB section |
| 187 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 188 | # $1 ... .its filename |
| 189 | # $2 ... Image counter |
| 190 | # $3 ... Path to DTB image |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | fitimage_emit_section_dtb() { |
| 192 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 193 | dtb_csum="${FIT_HASH_ALG}" |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 194 | dtb_sign_algo="${FIT_SIGN_ALG}" |
| 195 | dtb_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 197 | dtb_loadline="" |
| 198 | dtb_ext=${DTB##*.} |
| 199 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 200 | if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then |
| 201 | dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;" |
| 202 | fi |
| 203 | elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then |
| 204 | dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;" |
| 205 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 206 | cat << EOF >> ${1} |
| 207 | fdt@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | description = "Flattened Device Tree blob"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 209 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 210 | type = "flat_dt"; |
| 211 | arch = "${UBOOT_ARCH}"; |
| 212 | compression = "none"; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 213 | ${dtb_loadline} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | hash@1 { |
| 215 | algo = "${dtb_csum}"; |
| 216 | }; |
| 217 | }; |
| 218 | EOF |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 219 | |
| 220 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${dtb_sign_keyname}" ] ; then |
| 221 | sed -i '$ d' ${1} |
| 222 | cat << EOF >> ${1} |
| 223 | signature@1 { |
| 224 | algo = "${dtb_csum},${dtb_sign_algo}"; |
| 225 | key-name-hint = "${dtb_sign_keyname}"; |
| 226 | }; |
| 227 | }; |
| 228 | EOF |
| 229 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 233 | # Emit the fitImage ITS setup section |
| 234 | # |
| 235 | # $1 ... .its filename |
| 236 | # $2 ... Image counter |
| 237 | # $3 ... Path to setup image |
| 238 | fitimage_emit_section_setup() { |
| 239 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 240 | setup_csum="${FIT_HASH_ALG}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 241 | |
| 242 | cat << EOF >> ${1} |
| 243 | setup@${2} { |
| 244 | description = "Linux setup.bin"; |
| 245 | data = /incbin/("${3}"); |
| 246 | type = "x86_setup"; |
| 247 | arch = "${UBOOT_ARCH}"; |
| 248 | os = "linux"; |
| 249 | compression = "none"; |
| 250 | load = <0x00090000>; |
| 251 | entry = <0x00090000>; |
| 252 | hash@1 { |
| 253 | algo = "${setup_csum}"; |
| 254 | }; |
| 255 | }; |
| 256 | EOF |
| 257 | } |
| 258 | |
| 259 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 260 | # Emit the fitImage ITS ramdisk section |
| 261 | # |
| 262 | # $1 ... .its filename |
| 263 | # $2 ... Image counter |
| 264 | # $3 ... Path to ramdisk image |
| 265 | fitimage_emit_section_ramdisk() { |
| 266 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 267 | ramdisk_csum="${FIT_HASH_ALG}" |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 268 | ramdisk_sign_algo="${FIT_SIGN_ALG}" |
| 269 | ramdisk_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 270 | ramdisk_loadline="" |
| 271 | ramdisk_entryline="" |
| 272 | |
| 273 | if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then |
| 274 | ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;" |
| 275 | fi |
| 276 | if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then |
| 277 | ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;" |
| 278 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 279 | |
| 280 | cat << EOF >> ${1} |
| 281 | ramdisk@${2} { |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 282 | description = "${INITRAMFS_IMAGE}"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 283 | data = /incbin/("${3}"); |
| 284 | type = "ramdisk"; |
| 285 | arch = "${UBOOT_ARCH}"; |
| 286 | os = "linux"; |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 287 | compression = "none"; |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 288 | ${ramdisk_loadline} |
| 289 | ${ramdisk_entryline} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 290 | hash@1 { |
| 291 | algo = "${ramdisk_csum}"; |
| 292 | }; |
| 293 | }; |
| 294 | EOF |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 295 | |
| 296 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "${ramdisk_sign_keyname}" ] ; then |
| 297 | sed -i '$ d' ${1} |
| 298 | cat << EOF >> ${1} |
| 299 | signature@1 { |
| 300 | algo = "${ramdisk_csum},${ramdisk_sign_algo}"; |
| 301 | key-name-hint = "${ramdisk_sign_keyname}"; |
| 302 | }; |
| 303 | }; |
| 304 | EOF |
| 305 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 309 | # Emit the fitImage ITS configuration section |
| 310 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 311 | # $1 ... .its filename |
| 312 | # $2 ... Linux kernel ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 313 | # $3 ... DTB image name |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 314 | # $4 ... ramdisk ID |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 315 | # $5 ... config ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 316 | # $6 ... default flag |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 317 | fitimage_emit_section_config() { |
| 318 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 319 | conf_csum="${FIT_HASH_ALG}" |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 320 | conf_sign_algo="${FIT_SIGN_ALG}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 321 | if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then |
| 322 | conf_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
| 323 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 325 | its_file="${1}" |
| 326 | kernel_id="${2}" |
| 327 | dtb_image="${3}" |
| 328 | ramdisk_id="${4}" |
| 329 | config_id="${5}" |
| 330 | default_flag="${6}" |
| 331 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 332 | # Test if we have any DTBs at all |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 333 | sep="" |
| 334 | conf_desc="" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 335 | conf_node="conf@" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 336 | kernel_line="" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 337 | fdt_line="" |
| 338 | ramdisk_line="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 339 | setup_line="" |
| 340 | default_line="" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 341 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 342 | # conf node name is selected based on dtb ID if it is present, |
| 343 | # otherwise its selected based on kernel ID |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 344 | if [ -n "${dtb_image}" ]; then |
| 345 | conf_node=$conf_node${dtb_image} |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 346 | else |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 347 | conf_node=$conf_node${kernel_id} |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 348 | fi |
| 349 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 350 | if [ -n "${kernel_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 351 | conf_desc="Linux kernel" |
| 352 | sep=", " |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 353 | kernel_line="kernel = \"kernel@${kernel_id}\";" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 354 | fi |
| 355 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 356 | if [ -n "${dtb_image}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 357 | conf_desc="${conf_desc}${sep}FDT blob" |
| 358 | sep=", " |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 359 | fdt_line="fdt = \"fdt@${dtb_image}\";" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 360 | fi |
| 361 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 362 | if [ -n "${ramdisk_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 363 | conf_desc="${conf_desc}${sep}ramdisk" |
| 364 | sep=", " |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 365 | ramdisk_line="ramdisk = \"ramdisk@${ramdisk_id}\";" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 366 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 367 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 368 | if [ -n "${config_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 369 | conf_desc="${conf_desc}${sep}setup" |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 370 | setup_line="setup = \"setup@${config_id}\";" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 371 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 373 | if [ "${default_flag}" = "1" ]; then |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 374 | # default node is selected based on dtb ID if it is present, |
| 375 | # otherwise its selected based on kernel ID |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 376 | if [ -n "${dtb_image}" ]; then |
| 377 | default_line="default = \"conf@${dtb_image}\";" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 378 | else |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 379 | default_line="default = \"conf@${kernel_id}\";" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 380 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 381 | fi |
| 382 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 383 | cat << EOF >> ${its_file} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 384 | ${default_line} |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 385 | $conf_node { |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 386 | description = "${default_flag} ${conf_desc}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 387 | ${kernel_line} |
| 388 | ${fdt_line} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 389 | ${ramdisk_line} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 390 | ${setup_line} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | hash@1 { |
| 392 | algo = "${conf_csum}"; |
| 393 | }; |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 394 | EOF |
| 395 | |
| 396 | if [ ! -z "${conf_sign_keyname}" ] ; then |
| 397 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 398 | sign_line="sign-images = " |
| 399 | sep="" |
| 400 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 401 | if [ -n "${kernel_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 402 | sign_line="${sign_line}${sep}\"kernel\"" |
| 403 | sep=", " |
| 404 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 405 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 406 | if [ -n "${dtb_image}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 407 | sign_line="${sign_line}${sep}\"fdt\"" |
| 408 | sep=", " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 409 | fi |
| 410 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 411 | if [ -n "${ramdisk_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 412 | sign_line="${sign_line}${sep}\"ramdisk\"" |
| 413 | sep=", " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 414 | fi |
| 415 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 416 | if [ -n "${config_id}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 417 | sign_line="${sign_line}${sep}\"setup\"" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 418 | fi |
| 419 | |
| 420 | sign_line="${sign_line};" |
| 421 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 422 | cat << EOF >> ${its_file} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 423 | signature@1 { |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 424 | algo = "${conf_csum},${conf_sign_algo}"; |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 425 | key-name-hint = "${conf_sign_keyname}"; |
| 426 | ${sign_line} |
| 427 | }; |
| 428 | EOF |
| 429 | fi |
| 430 | |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 431 | cat << EOF >> ${its_file} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 432 | }; |
| 433 | EOF |
| 434 | } |
| 435 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 436 | # |
| 437 | # Assemble fitImage |
| 438 | # |
| 439 | # $1 ... .its filename |
| 440 | # $2 ... fitImage name |
| 441 | # $3 ... include ramdisk |
| 442 | fitimage_assemble() { |
| 443 | kernelcount=1 |
| 444 | dtbcount="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 445 | DTBS="" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 446 | ramdiskcount=${3} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 447 | setupcount="" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 448 | rm -f ${1} arch/${ARCH}/boot/${2} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 449 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 450 | fitimage_emit_fit_header ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 451 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 452 | # |
| 453 | # Step 1: Prepare a kernel image section. |
| 454 | # |
| 455 | fitimage_emit_section_maint ${1} imagestart |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 456 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 457 | uboot_prep_kimage |
| 458 | fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 459 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 460 | # |
| 461 | # Step 2: Prepare a DTB image section |
| 462 | # |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 463 | |
| 464 | if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -n "${KERNEL_DEVICETREE}" ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 465 | dtbcount=1 |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 466 | for DTB in ${KERNEL_DEVICETREE}; do |
| 467 | if echo ${DTB} | grep -q '/dts/'; then |
| 468 | bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." |
| 469 | DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` |
| 470 | fi |
| 471 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 472 | if [ ! -e "${DTB_PATH}" ]; then |
| 473 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 474 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 475 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 476 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 477 | DTBS="${DTBS} ${DTB}" |
| 478 | fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 479 | done |
| 480 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 481 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 482 | if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then |
| 483 | dtbcount=1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 484 | for DTB in $(find "${EXTERNAL_KERNEL_DEVICETREE}" \( -name '*.dtb' -o -name '*.dtbo' \) -printf '%P\n' | sort); do |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 485 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 486 | DTBS="${DTBS} ${DTB}" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 487 | fitimage_emit_section_dtb ${1} ${DTB} "${EXTERNAL_KERNEL_DEVICETREE}/${DTB}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 488 | done |
| 489 | fi |
| 490 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 491 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 492 | # Step 3: Prepare a setup section. (For x86) |
| 493 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 494 | if [ -e arch/${ARCH}/boot/setup.bin ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 495 | setupcount=1 |
| 496 | fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin |
| 497 | fi |
| 498 | |
| 499 | # |
| 500 | # Step 4: Prepare a ramdisk section. |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 501 | # |
| 502 | if [ "x${ramdiskcount}" = "x1" ] ; then |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 503 | # Find and use the first initramfs image archive type we find |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 504 | for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz ext2.gz cpio; do |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 505 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 506 | echo "Using $initramfs_path" |
| 507 | if [ -e "${initramfs_path}" ]; then |
| 508 | fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}" |
| 509 | break |
| 510 | fi |
| 511 | done |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 512 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 513 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 514 | fitimage_emit_section_maint ${1} sectend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 515 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 516 | # Force the first Kernel and DTB in the default config |
| 517 | kernelcount=1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 518 | if [ -n "${dtbcount}" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 519 | dtbcount=1 |
| 520 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 521 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 522 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 523 | # Step 5: Prepare a configurations section |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 524 | # |
| 525 | fitimage_emit_section_maint ${1} confstart |
| 526 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 527 | # kernel-fitimage.bbclass currently only supports a single kernel (no less or |
| 528 | # more) to be added to the FIT image along with 0 or more device trees and |
| 529 | # 0 or 1 ramdisk. |
| 530 | # If a device tree is to be part of the FIT image, then select |
| 531 | # the default configuration to be used is based on the dtbcount. If there is |
| 532 | # no dtb present than select the default configuation to be based on |
| 533 | # the kernelcount. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 534 | if [ -n "${DTBS}" ]; then |
| 535 | i=1 |
| 536 | for DTB in ${DTBS}; do |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 537 | dtb_ext=${DTB##*.} |
| 538 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 539 | fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" |
| 540 | else |
| 541 | fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`" |
| 542 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 543 | i=`expr ${i} + 1` |
| 544 | done |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 545 | else |
| 546 | defaultconfigcount=1 |
| 547 | fitimage_emit_section_config ${1} "${kernelcount}" "" "${ramdiskcount}" "${setupcount}" "${defaultconfigcount}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 548 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 549 | |
| 550 | fitimage_emit_section_maint ${1} sectend |
| 551 | |
| 552 | fitimage_emit_section_maint ${1} fitend |
| 553 | |
| 554 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 555 | # Step 6: Assemble the image |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 556 | # |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 557 | ${UBOOT_MKIMAGE} \ |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 558 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 559 | -f ${1} \ |
| 560 | arch/${ARCH}/boot/${2} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 561 | |
| 562 | # |
| 563 | # Step 7: Sign the image and add public key to U-Boot dtb |
| 564 | # |
| 565 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 566 | add_key_to_u_boot="" |
| 567 | if [ -n "${UBOOT_DTB_BINARY}" ]; then |
| 568 | # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy |
| 569 | # both of them, and don't dereference the symlink. |
| 570 | cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B} |
| 571 | add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}" |
| 572 | fi |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 573 | ${UBOOT_MKIMAGE_SIGN} \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 574 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 575 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 576 | $add_key_to_u_boot \ |
Andrew Geissler | c723b72 | 2021-01-08 16:14:09 -0600 | [diff] [blame] | 577 | -r arch/${ARCH}/boot/${2} \ |
| 578 | ${UBOOT_MKIMAGE_SIGN_ARGS} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 579 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | do_assemble_fitimage() { |
| 583 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
| 584 | cd ${B} |
| 585 | fitimage_assemble fit-image.its fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 586 | fi |
| 587 | } |
| 588 | |
| 589 | addtask assemble_fitimage before do_install after do_compile |
| 590 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 591 | do_assemble_fitimage_initramfs() { |
| 592 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
| 593 | test -n "${INITRAMFS_IMAGE}" ; then |
| 594 | cd ${B} |
| 595 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 |
| 596 | fi |
| 597 | } |
| 598 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 599 | addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 600 | |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 601 | do_generate_rsa_keys() { |
| 602 | if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then |
| 603 | bbwarn "FIT_GENERATE_KEYS is set to 1 eventhough UBOOT_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used." |
| 604 | fi |
| 605 | |
| 606 | if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then |
| 607 | |
| 608 | # Generate keys only if they don't already exist |
| 609 | if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \ |
| 610 | [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt]; then |
| 611 | |
| 612 | # make directory if it does not already exist |
| 613 | mkdir -p "${UBOOT_SIGN_KEYDIR}" |
| 614 | |
| 615 | echo "Generating RSA private key for signing fitImage" |
| 616 | openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \ |
| 617 | "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ |
| 618 | "${FIT_SIGN_NUMBITS}" |
| 619 | |
| 620 | echo "Generating certificate for signing fitImage" |
| 621 | openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \ |
| 622 | -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ |
| 623 | -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt |
| 624 | fi |
| 625 | fi |
| 626 | } |
| 627 | |
| 628 | addtask generate_rsa_keys before do_assemble_fitimage after do_compile |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 629 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 630 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 631 | kernel_do_deploy_append() { |
| 632 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 633 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 634 | echo "Copying fit-image.its source file..." |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 635 | install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its" |
| 636 | ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 637 | |
| 638 | echo "Copying linux.bin file..." |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 639 | install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin |
| 640 | ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 641 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 642 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 643 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 644 | install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" |
| 645 | ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 646 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 647 | echo "Copying fitImage-${INITRAMFS_IMAGE} file..." |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 648 | install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin" |
| 649 | ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 650 | fi |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 651 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
| 652 | # UBOOT_DTB_IMAGE is a realfile, but we can't use |
| 653 | # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed |
| 654 | # for u-boot, but we are in kernel env now. |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 655 | install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 656 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 657 | fi |
| 658 | } |