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