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