Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | inherit kernel-uboot 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 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 138 | cat << EOF >> ${1} |
| 139 | fdt@${2} { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | description = "Flattened Device Tree blob"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 141 | data = /incbin/("${3}"); |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | type = "flat_dt"; |
| 143 | arch = "${UBOOT_ARCH}"; |
| 144 | compression = "none"; |
| 145 | hash@1 { |
| 146 | algo = "${dtb_csum}"; |
| 147 | }; |
| 148 | }; |
| 149 | EOF |
| 150 | } |
| 151 | |
| 152 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | # Emit the fitImage ITS setup section |
| 154 | # |
| 155 | # $1 ... .its filename |
| 156 | # $2 ... Image counter |
| 157 | # $3 ... Path to setup image |
| 158 | fitimage_emit_section_setup() { |
| 159 | |
| 160 | setup_csum="sha1" |
| 161 | |
| 162 | cat << EOF >> ${1} |
| 163 | setup@${2} { |
| 164 | description = "Linux setup.bin"; |
| 165 | data = /incbin/("${3}"); |
| 166 | type = "x86_setup"; |
| 167 | arch = "${UBOOT_ARCH}"; |
| 168 | os = "linux"; |
| 169 | compression = "none"; |
| 170 | load = <0x00090000>; |
| 171 | entry = <0x00090000>; |
| 172 | hash@1 { |
| 173 | algo = "${setup_csum}"; |
| 174 | }; |
| 175 | }; |
| 176 | EOF |
| 177 | } |
| 178 | |
| 179 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 180 | # Emit the fitImage ITS ramdisk section |
| 181 | # |
| 182 | # $1 ... .its filename |
| 183 | # $2 ... Image counter |
| 184 | # $3 ... Path to ramdisk image |
| 185 | fitimage_emit_section_ramdisk() { |
| 186 | |
| 187 | ramdisk_csum="sha1" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 188 | ramdisk_ctype="none" |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 189 | ramdisk_loadline="" |
| 190 | ramdisk_entryline="" |
| 191 | |
| 192 | if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then |
| 193 | ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;" |
| 194 | fi |
| 195 | if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then |
| 196 | ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;" |
| 197 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 198 | |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 199 | case $3 in |
| 200 | *.gz) |
| 201 | ramdisk_ctype="gzip" |
| 202 | ;; |
| 203 | *.bz2) |
| 204 | ramdisk_ctype="bzip2" |
| 205 | ;; |
| 206 | *.lzma) |
| 207 | ramdisk_ctype="lzma" |
| 208 | ;; |
| 209 | *.lzo) |
| 210 | ramdisk_ctype="lzo" |
| 211 | ;; |
| 212 | *.lz4) |
| 213 | ramdisk_ctype="lz4" |
| 214 | ;; |
| 215 | esac |
| 216 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 217 | cat << EOF >> ${1} |
| 218 | ramdisk@${2} { |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 219 | description = "${INITRAMFS_IMAGE}"; |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 220 | data = /incbin/("${3}"); |
| 221 | type = "ramdisk"; |
| 222 | arch = "${UBOOT_ARCH}"; |
| 223 | os = "linux"; |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 224 | compression = "${ramdisk_ctype}"; |
Nathan Rossi | b4a4dc0 | 2016-10-21 22:07:27 +1000 | [diff] [blame] | 225 | ${ramdisk_loadline} |
| 226 | ${ramdisk_entryline} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 227 | hash@1 { |
| 228 | algo = "${ramdisk_csum}"; |
| 229 | }; |
| 230 | }; |
| 231 | EOF |
| 232 | } |
| 233 | |
| 234 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 235 | # Emit the fitImage ITS configuration section |
| 236 | # |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 237 | # $1 ... .its filename |
| 238 | # $2 ... Linux kernel ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 239 | # $3 ... DTB image name |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 240 | # $4 ... ramdisk ID |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 241 | # $5 ... config ID |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 242 | # $6 ... default flag |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | fitimage_emit_section_config() { |
| 244 | |
| 245 | conf_csum="sha1" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 246 | if [ -n "${UBOOT_SIGN_ENABLE}" ] ; then |
| 247 | conf_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
| 248 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | |
| 250 | # Test if we have any DTBs at all |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 251 | conf_desc="Linux kernel" |
| 252 | kernel_line="kernel = \"kernel@${2}\";" |
| 253 | fdt_line="" |
| 254 | ramdisk_line="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 255 | setup_line="" |
| 256 | default_line="" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 257 | |
| 258 | if [ -n "${3}" ]; then |
| 259 | conf_desc="${conf_desc}, FDT blob" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 260 | fdt_line="fdt = \"fdt@${3}\";" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 261 | fi |
| 262 | |
| 263 | if [ -n "${4}" ]; then |
| 264 | conf_desc="${conf_desc}, ramdisk" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 265 | ramdisk_line="ramdisk = \"ramdisk@${4}\";" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 266 | fi |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 267 | |
| 268 | if [ -n "${5}" ]; then |
| 269 | conf_desc="${conf_desc}, setup" |
| 270 | setup_line="setup = \"setup@${5}\";" |
| 271 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 273 | if [ "${6}" = "1" ]; then |
| 274 | default_line="default = \"conf@${3}\";" |
| 275 | fi |
| 276 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 277 | cat << EOF >> ${1} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 278 | ${default_line} |
| 279 | conf@${3} { |
| 280 | description = "${6} ${conf_desc}"; |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | ${kernel_line} |
| 282 | ${fdt_line} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 283 | ${ramdisk_line} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 284 | ${setup_line} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | hash@1 { |
| 286 | algo = "${conf_csum}"; |
| 287 | }; |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 288 | EOF |
| 289 | |
| 290 | if [ ! -z "${conf_sign_keyname}" ] ; then |
| 291 | |
| 292 | sign_line="sign-images = \"kernel\"" |
| 293 | |
| 294 | if [ -n "${3}" ]; then |
| 295 | sign_line="${sign_line}, \"fdt\"" |
| 296 | fi |
| 297 | |
| 298 | if [ -n "${4}" ]; then |
| 299 | sign_line="${sign_line}, \"ramdisk\"" |
| 300 | fi |
| 301 | |
| 302 | if [ -n "${5}" ]; then |
| 303 | sign_line="${sign_line}, \"setup\"" |
| 304 | fi |
| 305 | |
| 306 | sign_line="${sign_line};" |
| 307 | |
| 308 | cat << EOF >> ${1} |
| 309 | signature@1 { |
| 310 | algo = "${conf_csum},rsa2048"; |
| 311 | key-name-hint = "${conf_sign_keyname}"; |
| 312 | ${sign_line} |
| 313 | }; |
| 314 | EOF |
| 315 | fi |
| 316 | |
| 317 | cat << EOF >> ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 318 | }; |
| 319 | EOF |
| 320 | } |
| 321 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 322 | # |
| 323 | # Assemble fitImage |
| 324 | # |
| 325 | # $1 ... .its filename |
| 326 | # $2 ... fitImage name |
| 327 | # $3 ... include ramdisk |
| 328 | fitimage_assemble() { |
| 329 | kernelcount=1 |
| 330 | dtbcount="" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 331 | DTBS="" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 332 | ramdiskcount=${3} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 333 | setupcount="" |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 334 | rm -f ${1} arch/${ARCH}/boot/${2} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 335 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 336 | fitimage_emit_fit_header ${1} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 337 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 338 | # |
| 339 | # Step 1: Prepare a kernel image section. |
| 340 | # |
| 341 | fitimage_emit_section_maint ${1} imagestart |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 342 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 343 | uboot_prep_kimage |
| 344 | fitimage_emit_section_kernel ${1} "${kernelcount}" linux.bin "${linux_comp}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 345 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 346 | # |
| 347 | # Step 2: Prepare a DTB image section |
| 348 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 349 | if [ -n "${KERNEL_DEVICETREE}" ]; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 350 | dtbcount=1 |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 351 | for DTB in ${KERNEL_DEVICETREE}; do |
| 352 | if echo ${DTB} | grep -q '/dts/'; then |
| 353 | bbwarn "${DTB} contains the full path to the the dts file, but only the dtb name should be used." |
| 354 | DTB=`basename ${DTB} | sed 's,\.dts$,.dtb,g'` |
| 355 | fi |
| 356 | DTB_PATH="arch/${ARCH}/boot/dts/${DTB}" |
| 357 | if [ ! -e "${DTB_PATH}" ]; then |
| 358 | DTB_PATH="arch/${ARCH}/boot/${DTB}" |
| 359 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 361 | DTB=$(echo "${DTB}" | tr '/' '_') |
| 362 | DTBS="${DTBS} ${DTB}" |
| 363 | fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 364 | done |
| 365 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 366 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 367 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 368 | # Step 3: Prepare a setup section. (For x86) |
| 369 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 370 | if [ -e arch/${ARCH}/boot/setup.bin ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 371 | setupcount=1 |
| 372 | fitimage_emit_section_setup ${1} "${setupcount}" arch/${ARCH}/boot/setup.bin |
| 373 | fi |
| 374 | |
| 375 | # |
| 376 | # Step 4: Prepare a ramdisk section. |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 377 | # |
| 378 | if [ "x${ramdiskcount}" = "x1" ] ; then |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 379 | # Find and use the first initramfs image archive type we find |
| 380 | for img in cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.gz cpio; do |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 381 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.${img}" |
Rick Altherr | bc1b880 | 2017-01-20 11:28:53 -0800 | [diff] [blame] | 382 | echo "Using $initramfs_path" |
| 383 | if [ -e "${initramfs_path}" ]; then |
| 384 | fitimage_emit_section_ramdisk ${1} "${ramdiskcount}" "${initramfs_path}" |
| 385 | break |
| 386 | fi |
| 387 | done |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 388 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 389 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 390 | fitimage_emit_section_maint ${1} sectend |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 391 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 392 | # Force the first Kernel and DTB in the default config |
| 393 | kernelcount=1 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 394 | if [ -n "${dtbcount}" ]; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 395 | dtbcount=1 |
| 396 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 397 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 398 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 399 | # Step 5: Prepare a configurations section |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 400 | # |
| 401 | fitimage_emit_section_maint ${1} confstart |
| 402 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 403 | if [ -n "${DTBS}" ]; then |
| 404 | i=1 |
| 405 | for DTB in ${DTBS}; do |
| 406 | fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`" |
| 407 | i=`expr ${i} + 1` |
| 408 | done |
| 409 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 410 | |
| 411 | fitimage_emit_section_maint ${1} sectend |
| 412 | |
| 413 | fitimage_emit_section_maint ${1} fitend |
| 414 | |
| 415 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 416 | # Step 6: Assemble the image |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 417 | # |
| 418 | uboot-mkimage \ |
| 419 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 420 | -f ${1} \ |
| 421 | arch/${ARCH}/boot/${2} |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 422 | |
| 423 | # |
| 424 | # Step 7: Sign the image and add public key to U-Boot dtb |
| 425 | # |
| 426 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
| 427 | uboot-mkimage \ |
| 428 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 429 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
| 430 | -K "${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_BINARY}" \ |
| 431 | -r arch/${ARCH}/boot/${2} |
| 432 | fi |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | do_assemble_fitimage() { |
| 436 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
| 437 | cd ${B} |
| 438 | fitimage_assemble fit-image.its fitImage |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 439 | fi |
| 440 | } |
| 441 | |
| 442 | addtask assemble_fitimage before do_install after do_compile |
| 443 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 444 | do_assemble_fitimage_initramfs() { |
| 445 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \ |
| 446 | test -n "${INITRAMFS_IMAGE}" ; then |
| 447 | cd ${B} |
| 448 | fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1 |
| 449 | fi |
| 450 | } |
| 451 | |
| 452 | addtask assemble_fitimage_initramfs before do_deploy after do_install |
| 453 | |
| 454 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 455 | kernel_do_deploy[vardepsexclude] = "DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 456 | kernel_do_deploy_append() { |
| 457 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 458 | if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 459 | cd ${B} |
| 460 | echo "Copying fit-image.its source file..." |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 461 | its_base_name="fitImage-its-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 462 | its_symlink_name=fitImage-its-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 463 | install -m 0644 fit-image.its ${DEPLOYDIR}/${its_base_name}.its |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 464 | linux_bin_base_name="fitImage-linux.bin-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 465 | linux_bin_symlink_name=fitImage-linux.bin-${MACHINE} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 466 | install -m 0644 linux.bin ${DEPLOYDIR}/${linux_bin_base_name}.bin |
| 467 | |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 468 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 469 | echo "Copying fit-image-${INITRAMFS_IMAGE}.its source file..." |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 470 | its_initramfs_base_name="fitImage-its-${INITRAMFS_IMAGE_NAME}-${PV}-${PR}-${DATETIME}" |
| 471 | its_initramfs_symlink_name=fitImage-its-${INITRAMFS_IMAGE_NAME} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 472 | install -m 0644 fit-image-${INITRAMFS_IMAGE}.its ${DEPLOYDIR}/${its_initramfs_base_name}.its |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 473 | fit_initramfs_base_name="fitImage-${INITRAMFS_IMAGE_NAME}-${PV}-${PR}-${DATETIME}" |
| 474 | fit_initramfs_symlink_name=fitImage-${INITRAMFS_IMAGE_NAME} |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 475 | install -m 0644 arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} ${DEPLOYDIR}/${fit_initramfs_base_name}.bin |
| 476 | fi |
| 477 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 478 | cd ${DEPLOYDIR} |
| 479 | ln -sf ${its_base_name}.its ${its_symlink_name}.its |
| 480 | ln -sf ${linux_bin_base_name}.bin ${linux_bin_symlink_name}.bin |
George McCollister | 185c8ae | 2016-05-26 08:55:16 -0500 | [diff] [blame] | 481 | |
| 482 | if [ -n "${INITRAMFS_IMAGE}" ]; then |
| 483 | ln -sf ${its_initramfs_base_name}.its ${its_initramfs_symlink_name}.its |
| 484 | ln -sf ${fit_initramfs_base_name}.bin ${fit_initramfs_symlink_name}.bin |
| 485 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 486 | fi |
| 487 | } |