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