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