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 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | # |
| 57 | # Emit the fitImage ITS header |
| 58 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 59 | # $1 ... .its filename |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | fitimage_emit_fit_header() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 61 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 62 | /dts-v1/; |
| 63 | |
| 64 | / { |
| 65 | description = "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"; |
| 66 | #address-cells = <1>; |
| 67 | EOF |
| 68 | } |
| 69 | |
| 70 | # |
| 71 | # Emit the fitImage section bits |
| 72 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 73 | # $1 ... .its filename |
| 74 | # $2 ... Section bit type: imagestart - image section start |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | # confstart - configuration section start |
| 76 | # sectend - section end |
| 77 | # fitend - fitimage end |
| 78 | # |
| 79 | fitimage_emit_section_maint() { |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 80 | case $2 in |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | imagestart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 82 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 83 | |
| 84 | images { |
| 85 | EOF |
| 86 | ;; |
| 87 | confstart) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 88 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 89 | |
| 90 | configurations { |
| 91 | EOF |
| 92 | ;; |
| 93 | sectend) |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 94 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | }; |
| 96 | EOF |
| 97 | ;; |
| 98 | fitend) |
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 | }; |
| 101 | EOF |
| 102 | ;; |
| 103 | esac |
| 104 | } |
| 105 | |
| 106 | # |
| 107 | # Emit the fitImage ITS kernel section |
| 108 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 109 | # $1 ... .its filename |
| 110 | # $2 ... Image counter |
| 111 | # $3 ... Path to kernel image |
| 112 | # $4 ... Compression type |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 113 | fitimage_emit_section_kernel() { |
| 114 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 115 | kernel_csum="${FIT_HASH_ALG}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | ENTRYPOINT="${UBOOT_ENTRYPOINT}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then |
| 119 | ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \ |
| 120 | awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'` |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 121 | fi |
| 122 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 123 | cat << EOF >> ${1} |
| 124 | kernel@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | description = "Linux kernel"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 126 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 127 | type = "kernel"; |
| 128 | arch = "${UBOOT_ARCH}"; |
| 129 | os = "linux"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 130 | compression = "${4}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 131 | load = <${UBOOT_LOADADDRESS}>; |
| 132 | entry = <${ENTRYPOINT}>; |
| 133 | hash@1 { |
| 134 | algo = "${kernel_csum}"; |
| 135 | }; |
| 136 | }; |
| 137 | EOF |
| 138 | } |
| 139 | |
| 140 | # |
| 141 | # Emit the fitImage ITS DTB section |
| 142 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 143 | # $1 ... .its filename |
| 144 | # $2 ... Image counter |
| 145 | # $3 ... Path to DTB image |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 146 | fitimage_emit_section_dtb() { |
| 147 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 148 | dtb_csum="${FIT_HASH_ALG}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 149 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 150 | dtb_loadline="" |
| 151 | dtb_ext=${DTB##*.} |
| 152 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 153 | if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then |
| 154 | dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;" |
| 155 | fi |
| 156 | elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then |
| 157 | dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;" |
| 158 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 159 | cat << EOF >> ${1} |
| 160 | fdt@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 161 | description = "Flattened Device Tree blob"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 162 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 | type = "flat_dt"; |
| 164 | arch = "${UBOOT_ARCH}"; |
| 165 | compression = "none"; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 166 | ${dtb_loadline} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 167 | hash@1 { |
| 168 | algo = "${dtb_csum}"; |
| 169 | }; |
| 170 | }; |
| 171 | EOF |
| 172 | } |
| 173 | |
| 174 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 175 | # Emit the fitImage ITS setup section |
| 176 | # |
| 177 | # $1 ... .its filename |
| 178 | # $2 ... Image counter |
| 179 | # $3 ... Path to setup image |
| 180 | fitimage_emit_section_setup() { |
| 181 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 182 | setup_csum="${FIT_HASH_ALG}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 183 | |
| 184 | cat << EOF >> ${1} |
| 185 | setup@${2} { |
| 186 | description = "Linux setup.bin"; |
| 187 | data = /incbin/("${3}"); |
| 188 | type = "x86_setup"; |
| 189 | arch = "${UBOOT_ARCH}"; |
| 190 | os = "linux"; |
| 191 | compression = "none"; |
| 192 | load = <0x00090000>; |
| 193 | entry = <0x00090000>; |
| 194 | hash@1 { |
| 195 | algo = "${setup_csum}"; |
| 196 | }; |
| 197 | }; |
| 198 | EOF |
| 199 | } |
| 200 | |
| 201 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 202 | # Emit the fitImage ITS ramdisk section |
| 203 | # |
| 204 | # $1 ... .its filename |
| 205 | # $2 ... Image counter |
| 206 | # $3 ... Path to ramdisk image |
| 207 | fitimage_emit_section_ramdisk() { |
| 208 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 209 | ramdisk_csum="${FIT_HASH_ALG}" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 210 | ramdisk_ctype="none" |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 211 | ramdisk_loadline="" |
| 212 | ramdisk_entryline="" |
| 213 | |
| 214 | if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then |
| 215 | ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;" |
| 216 | fi |
| 217 | if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then |
| 218 | ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;" |
| 219 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 220 | |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 221 | case $3 in |
| 222 | *.gz) |
| 223 | ramdisk_ctype="gzip" |
| 224 | ;; |
| 225 | *.bz2) |
| 226 | ramdisk_ctype="bzip2" |
| 227 | ;; |
| 228 | *.lzma) |
| 229 | ramdisk_ctype="lzma" |
| 230 | ;; |
| 231 | *.lzo) |
| 232 | ramdisk_ctype="lzo" |
| 233 | ;; |
| 234 | *.lz4) |
| 235 | ramdisk_ctype="lz4" |
| 236 | ;; |
| 237 | esac |
| 238 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 239 | cat << EOF >> ${1} |
| 240 | ramdisk@${2} { |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 241 | description = "${INITRAMFS_IMAGE}"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 242 | data = /incbin/("${3}"); |
| 243 | type = "ramdisk"; |
| 244 | arch = "${UBOOT_ARCH}"; |
| 245 | os = "linux"; |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 246 | compression = "${ramdisk_ctype}"; |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 247 | ${ramdisk_loadline} |
| 248 | ${ramdisk_entryline} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 249 | hash@1 { |
| 250 | algo = "${ramdisk_csum}"; |
| 251 | }; |
| 252 | }; |
| 253 | EOF |
| 254 | } |
| 255 | |
| 256 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | # Emit the fitImage ITS configuration section |
| 258 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 259 | # $1 ... .its filename |
| 260 | # $2 ... Linux kernel ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | # $3 ... DTB image name |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 262 | # $4 ... ramdisk ID |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 263 | # $5 ... config ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 264 | # $6 ... default flag |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 265 | fitimage_emit_section_config() { |
| 266 | |
Brad Bishop | f3fd288 | 2019-06-21 08:06:37 -0400 | [diff] [blame] | 267 | conf_csum="${FIT_HASH_ALG}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 268 | if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then |
| 269 | conf_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
| 270 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 271 | |
| 272 | # Test if we have any DTBs at all |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 273 | sep="" |
| 274 | conf_desc="" |
| 275 | kernel_line="" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 276 | fdt_line="" |
| 277 | ramdisk_line="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 278 | setup_line="" |
| 279 | default_line="" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 280 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 281 | if [ -n "${2}" ]; then |
| 282 | conf_desc="Linux kernel" |
| 283 | sep=", " |
| 284 | kernel_line="kernel = \"kernel@${2}\";" |
| 285 | fi |
| 286 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 287 | if [ -n "${3}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 288 | conf_desc="${conf_desc}${sep}FDT blob" |
| 289 | sep=", " |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 290 | fdt_line="fdt = \"fdt@${3}\";" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | fi |
| 292 | |
| 293 | if [ -n "${4}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 294 | conf_desc="${conf_desc}${sep}ramdisk" |
| 295 | sep=", " |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 296 | ramdisk_line="ramdisk = \"ramdisk@${4}\";" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 297 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 298 | |
| 299 | if [ -n "${5}" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 300 | conf_desc="${conf_desc}${sep}setup" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 301 | setup_line="setup = \"setup@${5}\";" |
| 302 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 303 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 304 | if [ "${6}" = "1" ]; then |
| 305 | default_line="default = \"conf@${3}\";" |
| 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} |
| 310 | conf@${3} { |
| 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 { |
| 349 | algo = "${conf_csum},rsa2048"; |
| 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 |
| 409 | for DTBFILE in ${EXTERNAL_KERNEL_DEVICETREE}/*.dtb; do |
| 410 | DTB=`basename ${DTBFILE}` |
| 411 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 412 | DTBS="${DTBS} ${DTB}" |
| 413 | fitimage_emit_section_dtb ${1} ${DTB} ${DTBFILE} |
| 414 | done |
| 415 | fi |
| 416 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 417 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 418 | # Step 3: Prepare a setup section. (For x86) |
| 419 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 420 | if [ -e arch/${ARCH}/boot/setup.bin ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 421 | setupcount=1 |
| 422 | fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin |
| 423 | fi |
| 424 | |
| 425 | # |
| 426 | # Step 4: Prepare a ramdisk section. |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 427 | # |
| 428 | if [ "x${ramdiskcount}" = "x1" ] ; then |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 429 | # Find and use the first initramfs image archive type we find |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 430 | 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] | 431 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 432 | echo "Using $initramfs_path" |
| 433 | if [ -e "${initramfs_path}" ]; then |
| 434 | fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}" |
| 435 | break |
| 436 | fi |
| 437 | done |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 438 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 439 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 440 | fitimage_emit_section_maint ${1} sectend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 441 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 442 | # Force the first Kernel and DTB in the default config |
| 443 | kernelcount=1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 444 | if [ -n "${dtbcount}" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 445 | dtbcount=1 |
| 446 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 447 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 448 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 449 | # Step 5: Prepare a configurations section |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 450 | # |
| 451 | fitimage_emit_section_maint ${1} confstart |
| 452 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 453 | if [ -n "${DTBS}" ]; then |
| 454 | i=1 |
| 455 | for DTB in ${DTBS}; do |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 456 | dtb_ext=${DTB##*.} |
| 457 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 458 | fitimage_emit_section_config ${1} "" "${DTB}" "" "" "`expr ${i} = ${dtbcount}`" |
| 459 | else |
| 460 | fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`" |
| 461 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 462 | i=`expr ${i} + 1` |
| 463 | done |
| 464 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 465 | |
| 466 | fitimage_emit_section_maint ${1} sectend |
| 467 | |
| 468 | fitimage_emit_section_maint ${1} fitend |
| 469 | |
| 470 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 471 | # Step 6: Assemble the image |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 472 | # |
| 473 | uboot-mkimage \ |
| 474 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 475 | -f ${1} \ |
| 476 | arch/${ARCH}/boot/${2} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 477 | |
| 478 | # |
| 479 | # Step 7: Sign the image and add public key to U-Boot dtb |
| 480 | # |
| 481 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 482 | add_key_to_u_boot="" |
| 483 | if [ -n "${UBOOT_DTB_BINARY}" ]; then |
| 484 | # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy |
| 485 | # both of them, and don't dereference the symlink. |
| 486 | cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B} |
| 487 | add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}" |
| 488 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 489 | uboot-mkimage \ |
| 490 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 491 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 492 | $add_key_to_u_boot \ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 493 | -r arch/${ARCH}/boot/${2} |
| 494 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | do_assemble_fitimage() { |
| 498 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
| 499 | cd ${B} |
| 500 | fitimage_assemble fit-image.its fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 501 | fi |
| 502 | } |
| 503 | |
| 504 | addtask assemble_fitimage before do_install after do_compile |
| 505 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 506 | do_assemble_fitimage_initramfs() { |
| 507 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
| 508 | test -n "${INITRAMFS_IMAGE}" ; then |
| 509 | cd ${B} |
| 510 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 |
| 511 | fi |
| 512 | } |
| 513 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 514 | addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 515 | |
| 516 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 517 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 518 | kernel_do_deploy_append() { |
| 519 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 520 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 521 | echo "Copying fit-image.its source file..." |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 522 | install -m 0644 ${B}/fit-image.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_NAME}.its |
| 523 | ln -snf fitImage-its-${KERNEL_FIT_NAME}.its ${DEPLOYDIR}/fitImage-its-${KERNEL_FIT_LINK_NAME} |
| 524 | |
| 525 | echo "Copying linux.bin file..." |
| 526 | install -m 0644 ${B}/linux.bin ${DEPLOYDIR}/fitImage-linux.bin-${KERNEL_FIT_NAME}.bin |
| 527 | 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] | 528 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 529 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 530 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 531 | install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its |
| 532 | 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] | 533 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 534 | echo "Copying fitImage-${INITRAMFS_IMAGE} file..." |
| 535 | install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.bin |
| 536 | 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] | 537 | fi |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 538 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
| 539 | # UBOOT_DTB_IMAGE is a realfile, but we can't use |
| 540 | # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed |
| 541 | # for u-boot, but we are in kernel env now. |
| 542 | install -m 0644 ${B}/u-boot-${MACHINE}*.dtb ${DEPLOYDIR}/ |
| 543 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 544 | fi |
| 545 | } |