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