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