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} |
| 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}>; |
| 173 | hash@1 { |
| 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} |
| 182 | signature@1 { |
| 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} |
| 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} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | hash@1 { |
| 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} |
| 229 | signature@1 { |
| 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} |
| 286 | setup@${2} { |
| 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>; |
| 295 | hash@1 { |
| 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} |
| 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} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 333 | hash@1 { |
| 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} |
| 342 | signature@1 { |
| 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 | 635e0e4 | 2020-08-21 15:58:33 -0500 | [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 | d1e8949 | 2021-02-12 15:35:20 -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 | d1e8949 | 2021-02-12 15:35:20 -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 | d1e8949 | 2021-02-12 15:35:20 -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 | d1e8949 | 2021-02-12 15:35:20 -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 |
| 429 | default_line="default = \"conf@${dtb_image}\";" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 430 | else |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -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} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 444 | hash@1 { |
| 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} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -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 | |
| 538 | if [ -z "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -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 |
| 545 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 546 | if [ ! -e "${DTB_PATH}" ]; then |
| 547 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 548 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 549 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 550 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 551 | DTBS="${DTBS} ${DTB}" |
| 552 | fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 553 | done |
| 554 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 555 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 556 | if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then |
| 557 | dtbcount=1 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 558 | 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] | 559 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 560 | DTBS="${DTBS} ${DTB}" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 561 | fitimage_emit_section_dtb ${1} ${DTB} "${EXTERNAL_KERNEL_DEVICETREE}/${DTB}" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 562 | done |
| 563 | fi |
| 564 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 565 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 566 | # Step 3: Prepare a u-boot script section |
| 567 | # |
| 568 | |
| 569 | if [ -n "${UBOOT_ENV}" ] && [ -d "${STAGING_DIR_HOST}/boot" ]; then |
| 570 | if [ -e "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY}" ]; then |
| 571 | cp ${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} ${B} |
| 572 | bootscr_id="${UBOOT_ENV_BINARY}" |
| 573 | fitimage_emit_section_boot_script ${1} "${bootscr_id}" ${UBOOT_ENV_BINARY} |
| 574 | else |
| 575 | bbwarn "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} not found." |
| 576 | fi |
| 577 | fi |
| 578 | |
| 579 | # |
| 580 | # Step 4: Prepare a setup section. (For x86) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 581 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 582 | if [ -e arch/${ARCH}/boot/setup.bin ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 583 | setupcount=1 |
| 584 | fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin |
| 585 | fi |
| 586 | |
| 587 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 588 | # Step 5: Prepare a ramdisk section. |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 589 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 590 | if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 591 | # Find and use the first initramfs image archive type we find |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 592 | 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] | 593 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 594 | echo "Using $initramfs_path" |
| 595 | if [ -e "${initramfs_path}" ]; then |
| 596 | fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}" |
| 597 | break |
| 598 | fi |
| 599 | done |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 600 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 601 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 602 | fitimage_emit_section_maint ${1} sectend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 603 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 604 | # Force the first Kernel and DTB in the default config |
| 605 | kernelcount=1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 606 | if [ -n "${dtbcount}" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 607 | dtbcount=1 |
| 608 | fi |
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 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 611 | # Step 6: Prepare a configurations section |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 612 | # |
| 613 | fitimage_emit_section_maint ${1} confstart |
| 614 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 615 | # kernel-fitimage.bbclass currently only supports a single kernel (no less or |
| 616 | # more) to be added to the FIT image along with 0 or more device trees and |
| 617 | # 0 or 1 ramdisk. |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 618 | # It is also possible to include an initramfs bundle (kernel and rootfs in one binary) |
| 619 | # When the initramfs bundle is used ramdisk is disabled. |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 620 | # If a device tree is to be part of the FIT image, then select |
| 621 | # the default configuration to be used is based on the dtbcount. If there is |
| 622 | # no dtb present than select the default configuation to be based on |
| 623 | # the kernelcount. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 624 | if [ -n "${DTBS}" ]; then |
| 625 | i=1 |
| 626 | for DTB in ${DTBS}; do |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 627 | dtb_ext=${DTB##*.} |
| 628 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 629 | fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" |
| 630 | else |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 631 | 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] | 632 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 633 | i=`expr ${i} + 1` |
| 634 | done |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 635 | else |
| 636 | defaultconfigcount=1 |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 637 | fitimage_emit_section_config ${1} "${kernelcount}" "" "${ramdiskcount}" "${bootscr_id}" "${setupcount}" "${defaultconfigcount}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 638 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 639 | |
| 640 | fitimage_emit_section_maint ${1} sectend |
| 641 | |
| 642 | fitimage_emit_section_maint ${1} fitend |
| 643 | |
| 644 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 645 | # Step 7: Assemble the image |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 646 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 647 | ${UBOOT_MKIMAGE} \ |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 648 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 649 | -f ${1} \ |
| 650 | arch/${ARCH}/boot/${2} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 651 | |
| 652 | # |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 653 | # 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] | 654 | # |
| 655 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 656 | add_key_to_u_boot="" |
| 657 | if [ -n "${UBOOT_DTB_BINARY}" ]; then |
| 658 | # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy |
| 659 | # both of them, and don't dereference the symlink. |
| 660 | cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B} |
| 661 | add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}" |
| 662 | fi |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 663 | ${UBOOT_MKIMAGE_SIGN} \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 664 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 665 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 666 | $add_key_to_u_boot \ |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 667 | -r arch/${ARCH}/boot/${2} \ |
| 668 | ${UBOOT_MKIMAGE_SIGN_ARGS} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 669 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | do_assemble_fitimage() { |
| 673 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
| 674 | cd ${B} |
| 675 | fitimage_assemble fit-image.its fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 676 | fi |
| 677 | } |
| 678 | |
| 679 | addtask assemble_fitimage before do_install after do_compile |
| 680 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 681 | do_assemble_fitimage_initramfs() { |
| 682 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
| 683 | test -n "${INITRAMFS_IMAGE}" ; then |
| 684 | cd ${B} |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 685 | if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then |
| 686 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage "" |
| 687 | else |
| 688 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 |
| 689 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 690 | fi |
| 691 | } |
| 692 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 693 | addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 694 | |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 695 | do_generate_rsa_keys() { |
| 696 | if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then |
| 697 | 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." |
| 698 | fi |
| 699 | |
| 700 | if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then |
| 701 | |
| 702 | # Generate keys only if they don't already exist |
| 703 | if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \ |
| 704 | [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt]; then |
| 705 | |
| 706 | # make directory if it does not already exist |
| 707 | mkdir -p "${UBOOT_SIGN_KEYDIR}" |
| 708 | |
| 709 | echo "Generating RSA private key for signing fitImage" |
| 710 | openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \ |
| 711 | "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ |
| 712 | "${FIT_SIGN_NUMBITS}" |
| 713 | |
| 714 | echo "Generating certificate for signing fitImage" |
| 715 | openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \ |
| 716 | -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \ |
| 717 | -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt |
| 718 | fi |
| 719 | fi |
| 720 | } |
| 721 | |
| 722 | addtask generate_rsa_keys before do_assemble_fitimage after do_compile |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 723 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 724 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 725 | kernel_do_deploy_append() { |
| 726 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 727 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 728 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 729 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
| 730 | echo "Copying fit-image.its source file..." |
| 731 | install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its" |
| 732 | ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}" |
| 733 | |
| 734 | echo "Copying linux.bin file..." |
| 735 | install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin |
| 736 | ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}" |
| 737 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 738 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 739 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 740 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 741 | install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its" |
| 742 | 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] | 743 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 744 | if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
| 745 | echo "Copying fitImage-${INITRAMFS_IMAGE} file..." |
| 746 | install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin" |
| 747 | ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}" |
| 748 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 749 | fi |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 750 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
| 751 | # UBOOT_DTB_IMAGE is a realfile, but we can't use |
| 752 | # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed |
| 753 | # for u-boot, but we are in kernel env now. |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 754 | install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 755 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 756 | fi |
| 757 | } |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame^] | 758 | |
| 759 | # The function below performs the following in case of initramfs bundles: |
| 760 | # - Removes do_assemble_fitimage. FIT generation is done through |
| 761 | # do_assemble_fitimage_initramfs. do_assemble_fitimage is not needed |
| 762 | # and should not be part of the tasks to be executed. |
| 763 | # - Since do_generate_rsa_keys is inserted by default |
| 764 | # between do_compile and do_assemble_fitimage, this is |
| 765 | # not suitable in case of initramfs bundles. do_generate_rsa_keys |
| 766 | # should be between do_bundle_initramfs and do_assemble_fitimage_initramfs. |
| 767 | python () { |
| 768 | if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1": |
| 769 | bb.build.deltask('do_assemble_fitimage', d) |
| 770 | bb.build.deltask('generate_rsa_keys', d) |
| 771 | bb.build.addtask('generate_rsa_keys', 'do_assemble_fitimage_initramfs', 'do_bundle_initramfs', d) |
| 772 | } |