Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 1 | inherit uboot-config |
| 2 | |
| 3 | CONVERSIONTYPES += "fitImage" |
| 4 | |
Patrick Williams | 1dc6b4a | 2023-08-04 10:41:33 -0500 | [diff] [blame] | 5 | CONVERSION_CMD:fitImage = "run_assemble_fitimage ${IMAGE_NAME}.${type}" |
| 6 | INITRAMFS_IMAGE="${IMAGE_NAME}.cpio.${INITRAMFS_CTYPE}" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 7 | KERNEL_OUTPUT_DIR="${DEPLOY_DIR_IMAGE}" |
| 8 | |
| 9 | do_image_cpio[depends] += "virtual/kernel:do_deploy" |
| 10 | |
| 11 | run_assemble_fitimage() { |
| 12 | export linux_comp="none" |
| 13 | fitimage_assemble $1.its $1.fitImage 1 |
| 14 | |
| 15 | # The fitimage_assemble puts the image into DEPLOY_DIR_NAME due to |
| 16 | # KERNEL_OUTPUT_DIR, but we really want it still in ${IMGDEPLOYDIR}, so |
| 17 | # move it. |
| 18 | mv ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}.fitImage . |
| 19 | # Delete the spurious linux.bin created by our stubbed uboot_prep_kimage. |
| 20 | rm linux.bin |
| 21 | } |
| 22 | |
| 23 | UBOOT_MKIMAGE_KERNEL_TYPE ?= "kernel" |
| 24 | uboot_prep_kimage() { |
| 25 | cp ${DEPLOY_DIR_IMAGE}/${KERNEL_IMAGETYPE} linux.bin |
| 26 | } |
| 27 | |
| 28 | DEPENDS:append = " u-boot-tools-native dtc-native virtual/${TARGET_PREFIX}binutils" |
| 29 | |
| 30 | # Description string |
| 31 | FIT_DESC ?= "Kernel fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" |
| 32 | |
| 33 | # Kernel fitImage Hash Algo |
| 34 | FIT_HASH_ALG ?= "sha256" |
| 35 | |
| 36 | # Kernel fitImage Signature Algo |
| 37 | FIT_SIGN_ALG ?= "rsa2048" |
| 38 | |
| 39 | # Kernel / U-Boot fitImage Padding Algo |
| 40 | FIT_PAD_ALG ?= "pkcs-1.5" |
| 41 | |
| 42 | # Generate keys for signing Kernel fitImage |
| 43 | FIT_GENERATE_KEYS ?= "0" |
| 44 | |
| 45 | # Size of private keys in number of bits |
| 46 | FIT_SIGN_NUMBITS ?= "2048" |
| 47 | |
| 48 | # args to openssl genrsa (Default is just the public exponent) |
| 49 | FIT_KEY_GENRSA_ARGS ?= "-F4" |
| 50 | |
| 51 | # args to openssl req (Default is -batch for non interactive mode and |
| 52 | # -new for new certificate) |
| 53 | FIT_KEY_REQ_ARGS ?= "-batch -new" |
| 54 | |
| 55 | # Standard format for public key certificate |
| 56 | FIT_KEY_SIGN_PKCS ?= "-x509" |
| 57 | |
| 58 | # Sign individual images as well |
| 59 | FIT_SIGN_INDIVIDUAL ?= "0" |
| 60 | |
| 61 | FIT_CONF_PREFIX ?= "conf-" |
| 62 | FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name" |
| 63 | |
| 64 | FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst cpio.gz ext2.gz cpio" |
| 65 | |
| 66 | # |
| 67 | # Emit the fitImage ITS header |
| 68 | # |
| 69 | # $1 ... .its filename |
| 70 | fitimage_emit_fit_header() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 71 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 72 | /dts-v1/; |
| 73 | |
| 74 | / { |
| 75 | description = "${FIT_DESC}"; |
| 76 | #address-cells = <1>; |
| 77 | EOF |
| 78 | } |
| 79 | |
| 80 | # |
| 81 | # Emit the fitImage section bits |
| 82 | # |
| 83 | # $1 ... .its filename |
| 84 | # $2 ... Section bit type: imagestart - image section start |
| 85 | # confstart - configuration section start |
| 86 | # sectend - section end |
| 87 | # fitend - fitimage end |
| 88 | # |
| 89 | fitimage_emit_section_maint() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 90 | case $2 in |
| 91 | imagestart) |
| 92 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 93 | |
| 94 | images { |
| 95 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 96 | ;; |
| 97 | confstart) |
| 98 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 99 | |
| 100 | configurations { |
| 101 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 102 | ;; |
| 103 | sectend) |
| 104 | cat << EOF >> $1 |
| 105 | }; |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 106 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 107 | ;; |
| 108 | fitend) |
| 109 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 110 | }; |
| 111 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 112 | ;; |
| 113 | esac |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | # |
| 118 | # Emit the fitImage ITS kernel section |
| 119 | # |
| 120 | # $1 ... .its filename |
| 121 | # $2 ... Image counter |
| 122 | # $3 ... Path to kernel image |
| 123 | # $4 ... Compression type |
| 124 | fitimage_emit_section_kernel() { |
| 125 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 126 | kernel_csum="${FIT_HASH_ALG}" |
| 127 | kernel_sign_algo="${FIT_SIGN_ALG}" |
| 128 | kernel_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 129 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 130 | ENTRYPOINT="${UBOOT_ENTRYPOINT}" |
| 131 | if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then |
| 132 | ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \ |
| 133 | awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'` |
| 134 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 135 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 136 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 137 | kernel-$2 { |
| 138 | description = "Linux kernel"; |
| 139 | data = /incbin/("$3"); |
| 140 | type = "${UBOOT_MKIMAGE_KERNEL_TYPE}"; |
| 141 | arch = "${UBOOT_ARCH}"; |
| 142 | os = "linux"; |
| 143 | compression = "$4"; |
| 144 | load = <${UBOOT_LOADADDRESS}>; |
| 145 | entry = <$ENTRYPOINT>; |
| 146 | hash-1 { |
| 147 | algo = "$kernel_csum"; |
| 148 | }; |
| 149 | }; |
| 150 | EOF |
| 151 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 152 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$kernel_sign_keyname" ] ; then |
| 153 | sed -i '$ d' $1 |
| 154 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 155 | signature-1 { |
| 156 | algo = "$kernel_csum,$kernel_sign_algo"; |
| 157 | key-name-hint = "$kernel_sign_keyname"; |
| 158 | }; |
| 159 | }; |
| 160 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 161 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | # |
| 165 | # Emit the fitImage ITS DTB section |
| 166 | # |
| 167 | # $1 ... .its filename |
| 168 | # $2 ... Image counter |
| 169 | # $3 ... Path to DTB image |
| 170 | fitimage_emit_section_dtb() { |
| 171 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 172 | dtb_csum="${FIT_HASH_ALG}" |
| 173 | dtb_sign_algo="${FIT_SIGN_ALG}" |
| 174 | dtb_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 175 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 176 | dtb_loadline="" |
| 177 | dtb_ext=${DTB##*.} |
| 178 | if [ "${dtb_ext}" = "dtbo" ]; then |
| 179 | if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then |
| 180 | dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;" |
| 181 | fi |
| 182 | elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then |
| 183 | dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;" |
| 184 | fi |
| 185 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 186 | fdt-$2 { |
| 187 | description = "Flattened Device Tree blob"; |
| 188 | data = /incbin/("$3"); |
| 189 | type = "flat_dt"; |
| 190 | arch = "${UBOOT_ARCH}"; |
| 191 | compression = "none"; |
| 192 | $dtb_loadline |
| 193 | hash-1 { |
| 194 | algo = "$dtb_csum"; |
| 195 | }; |
| 196 | }; |
| 197 | EOF |
| 198 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 199 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$dtb_sign_keyname" ] ; then |
| 200 | sed -i '$ d' $1 |
| 201 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 202 | signature-1 { |
| 203 | algo = "$dtb_csum,$dtb_sign_algo"; |
| 204 | key-name-hint = "$dtb_sign_keyname"; |
| 205 | }; |
| 206 | }; |
| 207 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 208 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | # |
| 212 | # Emit the fitImage ITS u-boot script section |
| 213 | # |
| 214 | # $1 ... .its filename |
| 215 | # $2 ... Image counter |
| 216 | # $3 ... Path to boot script image |
| 217 | fitimage_emit_section_boot_script() { |
| 218 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 219 | bootscr_csum="${FIT_HASH_ALG}" |
| 220 | bootscr_sign_algo="${FIT_SIGN_ALG}" |
| 221 | bootscr_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 222 | |
| 223 | cat << EOF >> $1 |
| 224 | bootscr-$2 { |
| 225 | description = "U-boot script"; |
| 226 | data = /incbin/("$3"); |
| 227 | type = "script"; |
| 228 | arch = "${UBOOT_ARCH}"; |
| 229 | compression = "none"; |
| 230 | hash-1 { |
| 231 | algo = "$bootscr_csum"; |
| 232 | }; |
| 233 | }; |
| 234 | EOF |
| 235 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 236 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$bootscr_sign_keyname" ] ; then |
| 237 | sed -i '$ d' $1 |
| 238 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 239 | signature-1 { |
| 240 | algo = "$bootscr_csum,$bootscr_sign_algo"; |
| 241 | key-name-hint = "$bootscr_sign_keyname"; |
| 242 | }; |
| 243 | }; |
| 244 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 245 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | # |
| 249 | # Emit the fitImage ITS setup section |
| 250 | # |
| 251 | # $1 ... .its filename |
| 252 | # $2 ... Image counter |
| 253 | # $3 ... Path to setup image |
| 254 | fitimage_emit_section_setup() { |
| 255 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 256 | setup_csum="${FIT_HASH_ALG}" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 257 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 258 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 259 | setup-$2 { |
| 260 | description = "Linux setup.bin"; |
| 261 | data = /incbin/("$3"); |
| 262 | type = "x86_setup"; |
| 263 | arch = "${UBOOT_ARCH}"; |
| 264 | os = "linux"; |
| 265 | compression = "none"; |
| 266 | load = <0x00090000>; |
| 267 | entry = <0x00090000>; |
| 268 | hash-1 { |
| 269 | algo = "$setup_csum"; |
| 270 | }; |
| 271 | }; |
| 272 | EOF |
| 273 | } |
| 274 | |
| 275 | # |
| 276 | # Emit the fitImage ITS ramdisk section |
| 277 | # |
| 278 | # $1 ... .its filename |
| 279 | # $2 ... Image counter |
| 280 | # $3 ... Path to ramdisk image |
| 281 | fitimage_emit_section_ramdisk() { |
| 282 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 283 | ramdisk_csum="${FIT_HASH_ALG}" |
| 284 | ramdisk_sign_algo="${FIT_SIGN_ALG}" |
| 285 | ramdisk_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}" |
| 286 | ramdisk_loadline="" |
| 287 | ramdisk_entryline="" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 288 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 289 | if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then |
| 290 | ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;" |
| 291 | fi |
| 292 | if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then |
| 293 | ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;" |
| 294 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 295 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 296 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 297 | ramdisk-$2 { |
| 298 | description = "${INITRAMFS_IMAGE}"; |
| 299 | data = /incbin/("$3"); |
| 300 | type = "ramdisk"; |
| 301 | arch = "${UBOOT_ARCH}"; |
| 302 | os = "linux"; |
| 303 | compression = "none"; |
| 304 | $ramdisk_loadline |
| 305 | $ramdisk_entryline |
| 306 | hash-1 { |
| 307 | algo = "$ramdisk_csum"; |
| 308 | }; |
| 309 | }; |
| 310 | EOF |
| 311 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 312 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$ramdisk_sign_keyname" ] ; then |
| 313 | sed -i '$ d' $1 |
| 314 | cat << EOF >> $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 315 | signature-1 { |
| 316 | algo = "$ramdisk_csum,$ramdisk_sign_algo"; |
| 317 | key-name-hint = "$ramdisk_sign_keyname"; |
| 318 | }; |
| 319 | }; |
| 320 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 321 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | # |
| 325 | # echoes symlink destination if it points below directory |
| 326 | # |
| 327 | # $1 ... file that's a potential symlink |
| 328 | # $2 ... expected parent directory |
| 329 | symlink_points_below() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 330 | file="$2/$1" |
| 331 | dir=$2 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 332 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 333 | if ! [ -L "$file" ]; then |
| 334 | return |
| 335 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 336 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 337 | realpath="$(realpath --relative-to=$dir $file)" |
| 338 | if [ -z "${realpath%%../*}" ]; then |
| 339 | return |
| 340 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 341 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 342 | echo "$realpath" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | # |
| 346 | # Emit the fitImage ITS configuration section |
| 347 | # |
| 348 | # $1 ... .its filename |
| 349 | # $2 ... Linux kernel ID |
| 350 | # $3 ... DTB image name |
| 351 | # $4 ... ramdisk ID |
| 352 | # $5 ... u-boot script ID |
| 353 | # $6 ... config ID |
| 354 | # $7 ... default flag |
| 355 | fitimage_emit_section_config() { |
| 356 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 357 | conf_csum="${FIT_HASH_ALG}" |
| 358 | conf_sign_algo="${FIT_SIGN_ALG}" |
| 359 | conf_padding_algo="${FIT_PAD_ALG}" |
| 360 | if [ "${UBOOT_SIGN_ENABLE}" = "1" ] ; then |
| 361 | conf_sign_keyname="${UBOOT_SIGN_KEYNAME}" |
| 362 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 363 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 364 | its_file="$1" |
| 365 | kernel_id="$2" |
| 366 | dtb_image="$3" |
| 367 | ramdisk_id="$4" |
| 368 | bootscr_id="$5" |
| 369 | config_id="$6" |
| 370 | default_flag="$7" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 371 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 372 | # Test if we have any DTBs at all |
| 373 | sep="" |
| 374 | conf_desc="" |
| 375 | conf_node="${FIT_CONF_PREFIX}" |
| 376 | kernel_line="" |
| 377 | fdt_line="" |
| 378 | ramdisk_line="" |
| 379 | bootscr_line="" |
| 380 | setup_line="" |
| 381 | default_line="" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 382 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 383 | dtb_image_sect=$(symlink_points_below $dtb_image "${EXTERNAL_KERNEL_DEVICETREE}") |
| 384 | if [ -z "$dtb_image_sect" ]; then |
| 385 | dtb_image_sect=$dtb_image |
| 386 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 387 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 388 | dtb_image=$(echo $dtb_image | tr '/' '_') |
| 389 | dtb_image_sect=$(echo "${dtb_image_sect}" | tr '/' '_') |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 390 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 391 | # conf node name is selected based on dtb ID if it is present, |
| 392 | # otherwise its selected based on kernel ID |
| 393 | if [ -n "$dtb_image" ]; then |
| 394 | conf_node=$conf_node$dtb_image |
| 395 | else |
| 396 | conf_node=$conf_node$kernel_id |
| 397 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 398 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 399 | if [ -n "$kernel_id" ]; then |
| 400 | conf_desc="Linux kernel" |
| 401 | sep=", " |
| 402 | kernel_line="kernel = \"kernel-$kernel_id\";" |
| 403 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 404 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 405 | if [ -n "$dtb_image" ]; then |
| 406 | conf_desc="$conf_desc${sep}FDT blob" |
| 407 | sep=", " |
| 408 | fdt_line="fdt = \"fdt-$dtb_image_sect\";" |
| 409 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 410 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 411 | if [ -n "$ramdisk_id" ]; then |
| 412 | conf_desc="$conf_desc${sep}ramdisk" |
| 413 | sep=", " |
| 414 | ramdisk_line="ramdisk = \"ramdisk-$ramdisk_id\";" |
| 415 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 416 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 417 | if [ -n "$bootscr_id" ]; then |
| 418 | conf_desc="$conf_desc${sep}u-boot script" |
| 419 | sep=", " |
| 420 | bootscr_line="bootscr = \"bootscr-$bootscr_id\";" |
| 421 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 422 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 423 | if [ -n "$config_id" ]; then |
| 424 | conf_desc="$conf_desc${sep}setup" |
| 425 | setup_line="setup = \"setup-$config_id\";" |
| 426 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 427 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 428 | if [ "$default_flag" = "1" ]; then |
| 429 | # default node is selected based on dtb ID if it is present, |
| 430 | # otherwise its selected based on kernel ID |
| 431 | if [ -n "$dtb_image" ]; then |
| 432 | default_line="default = \"${FIT_CONF_PREFIX}$dtb_image\";" |
| 433 | else |
| 434 | default_line="default = \"${FIT_CONF_PREFIX}$kernel_id\";" |
| 435 | fi |
| 436 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 437 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 438 | cat << EOF >> $its_file |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 439 | $default_line |
| 440 | $conf_node { |
| 441 | description = "$default_flag $conf_desc"; |
| 442 | $kernel_line |
| 443 | $fdt_line |
| 444 | $ramdisk_line |
| 445 | $bootscr_line |
| 446 | $setup_line |
| 447 | hash-1 { |
| 448 | algo = "$conf_csum"; |
| 449 | }; |
| 450 | EOF |
| 451 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 452 | if [ -n "$conf_sign_keyname" ] ; then |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 453 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 454 | sign_line="sign-images = " |
| 455 | sep="" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 456 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 457 | if [ -n "$kernel_id" ]; then |
| 458 | sign_line="$sign_line${sep}\"kernel\"" |
| 459 | sep=", " |
| 460 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 461 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 462 | if [ -n "$dtb_image" ]; then |
| 463 | sign_line="$sign_line${sep}\"fdt\"" |
| 464 | sep=", " |
| 465 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 466 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 467 | if [ -n "$ramdisk_id" ]; then |
| 468 | sign_line="$sign_line${sep}\"ramdisk\"" |
| 469 | sep=", " |
| 470 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 471 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 472 | if [ -n "$bootscr_id" ]; then |
| 473 | sign_line="$sign_line${sep}\"bootscr\"" |
| 474 | sep=", " |
| 475 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 476 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 477 | if [ -n "$config_id" ]; then |
| 478 | sign_line="$sign_line${sep}\"setup\"" |
| 479 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 480 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 481 | sign_line="$sign_line;" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 482 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 483 | cat << EOF >> $its_file |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 484 | signature-1 { |
| 485 | algo = "$conf_csum,$conf_sign_algo"; |
| 486 | key-name-hint = "$conf_sign_keyname"; |
| 487 | padding = "$conf_padding_algo"; |
| 488 | $sign_line |
| 489 | }; |
| 490 | EOF |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 491 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 492 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 493 | cat << EOF >> $its_file |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 494 | }; |
| 495 | EOF |
| 496 | } |
| 497 | |
| 498 | # |
| 499 | # Assemble fitImage |
| 500 | # |
| 501 | # $1 ... .its filename |
| 502 | # $2 ... fitImage name |
| 503 | # $3 ... include ramdisk |
| 504 | fitimage_assemble() { |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 505 | kernelcount=1 |
| 506 | dtbcount="" |
| 507 | DTBS="" |
| 508 | ramdiskcount=$3 |
| 509 | setupcount="" |
| 510 | bootscr_id="" |
| 511 | rm -f $1 ${KERNEL_OUTPUT_DIR}/$2 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 512 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 513 | if [ -n "${UBOOT_SIGN_IMG_KEYNAME}" -a "${UBOOT_SIGN_KEYNAME}" = "${UBOOT_SIGN_IMG_KEYNAME}" ]; then |
| 514 | bbfatal "Keys used to sign images and configuration nodes must be different." |
| 515 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 516 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 517 | fitimage_emit_fit_header $1 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 518 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 519 | # |
| 520 | # Step 1: Prepare a kernel image section. |
| 521 | # |
| 522 | fitimage_emit_section_maint $1 imagestart |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 523 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 524 | uboot_prep_kimage |
| 525 | fitimage_emit_section_kernel $1 $kernelcount linux.bin "$linux_comp" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 526 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 527 | # |
| 528 | # Step 2: Prepare a DTB image section |
| 529 | # |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 530 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 531 | if [ -n "${KERNEL_DEVICETREE}" ]; then |
| 532 | dtbcount=1 |
| 533 | for DTB in ${KERNEL_DEVICETREE}; do |
| 534 | if echo $DTB | grep -q '/dts/'; then |
| 535 | bbwarn "$DTB contains the full path to the the dts file, but only the dtb name should be used." |
| 536 | DTB=`basename $DTB | sed 's,\.dts$,.dtb,g'` |
| 537 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 538 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 539 | # Skip ${DTB} if it's also provided in ${EXTERNAL_KERNEL_DEVICETREE} |
| 540 | if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -s ${EXTERNAL_KERNEL_DEVICETREE}/${DTB} ]; then |
| 541 | continue |
| 542 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 543 | |
Andrew Geissler | 0cb5bb5 | 2023-09-14 08:37:27 -0400 | [diff] [blame] | 544 | # For non-vendored DTBs, we need to strip off the vendor path. |
| 545 | if "${@'false' if oe.types.boolean(d.getVar('KERNEL_DTBVENDORED')) else 'true'}"; then |
| 546 | DTB=`basename $DTB` |
| 547 | fi |
| 548 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 549 | DTB_PATH="${KERNEL_OUTPUT_DIR}/dts/$DTB" |
| 550 | if [ ! -e "$DTB_PATH" ]; then |
| 551 | DTB_PATH="${KERNEL_OUTPUT_DIR}/$DTB" |
| 552 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 553 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 554 | # Skip DTB if we've picked it up previously |
| 555 | echo "$DTBS" | tr ' ' '\n' | grep -xq "$DTB" && continue |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 556 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 557 | DTBS="$DTBS $DTB" |
| 558 | DTB=$(echo $DTB | tr '/' '_') |
| 559 | fitimage_emit_section_dtb $1 $DTB $DTB_PATH |
| 560 | done |
| 561 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 562 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 563 | if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then |
| 564 | dtbcount=1 |
| 565 | for DTB in $(find "${EXTERNAL_KERNEL_DEVICETREE}" \( -name '*.dtb' -o -name '*.dtbo' \) -printf '%P\n' | sort); do |
| 566 | # Skip DTB if we've picked it up previously |
| 567 | echo "$DTBS" | tr ' ' '\n' | grep -xq "$DTB" && continue |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 568 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 569 | DTBS="$DTBS $DTB" |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 570 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 571 | # Also skip if a symlink. We'll later have each config section point at it |
| 572 | [ $(symlink_points_below $DTB "${EXTERNAL_KERNEL_DEVICETREE}") ] && continue |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 573 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 574 | DTB=$(echo $DTB | tr '/' '_') |
| 575 | fitimage_emit_section_dtb $1 $DTB "${EXTERNAL_KERNEL_DEVICETREE}/$DTB" |
| 576 | done |
| 577 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 578 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 579 | # |
| 580 | # Step 3: Prepare a u-boot script section |
| 581 | # |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 582 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 583 | if [ -n "${UBOOT_ENV}" ] && [ -d "${STAGING_DIR_HOST}/boot" ]; then |
| 584 | if [ -e "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY}" ]; then |
| 585 | cp ${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} ${B} |
| 586 | bootscr_id="${UBOOT_ENV_BINARY}" |
| 587 | fitimage_emit_section_boot_script $1 "$bootscr_id" ${UBOOT_ENV_BINARY} |
| 588 | else |
| 589 | bbwarn "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} not found." |
| 590 | fi |
| 591 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 592 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 593 | # |
| 594 | # Step 4: Prepare a setup section. (For x86) |
| 595 | # |
| 596 | if [ -e ${KERNEL_OUTPUT_DIR}/setup.bin ]; then |
| 597 | setupcount=1 |
| 598 | fitimage_emit_section_setup $1 $setupcount ${KERNEL_OUTPUT_DIR}/setup.bin |
| 599 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 600 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 601 | # |
| 602 | # Step 5: Prepare a ramdisk section. |
| 603 | # |
| 604 | if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then |
| 605 | # Find and use the first initramfs image archive type we find |
| 606 | found= |
| 607 | for img in ${FIT_SUPPORTED_INITRAMFS_FSTYPES}; do |
| 608 | initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" |
| 609 | if [ -e "$initramfs_path" ]; then |
| 610 | bbnote "Found initramfs image: $initramfs_path" |
| 611 | found=true |
| 612 | fitimage_emit_section_ramdisk $1 "$ramdiskcount" "$initramfs_path" |
| 613 | break |
| 614 | else |
| 615 | bbnote "Did not find initramfs image: $initramfs_path" |
| 616 | fi |
| 617 | done |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 618 | |
| 619 | if [ -z "$found" ] && [ -e ${INITRAMFS_IMAGE} ]; then |
| 620 | found=true |
| 621 | bbnote "Found initramfs image: ${INITRAMFS_IMAGE}" |
| 622 | fitimage_emit_section_ramdisk $1 "$ramdiskcount" "${INITRAMFS_IMAGE}" |
| 623 | fi |
| 624 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 625 | if [ -z "$found" ]; then |
| 626 | bbfatal "Could not find a valid initramfs type for ${INITRAMFS_IMAGE_NAME}, the supported types are: ${FIT_SUPPORTED_INITRAMFS_FSTYPES}" |
| 627 | fi |
| 628 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 629 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 630 | fitimage_emit_section_maint $1 sectend |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 631 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 632 | # Force the first Kernel and DTB in the default config |
| 633 | kernelcount=1 |
| 634 | if [ -n "$dtbcount" ]; then |
| 635 | dtbcount=1 |
| 636 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 637 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 638 | # |
| 639 | # Step 6: Prepare a configurations section |
| 640 | # |
| 641 | fitimage_emit_section_maint $1 confstart |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 642 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 643 | # kernel-fitimage.bbclass currently only supports a single kernel (no less or |
| 644 | # more) to be added to the FIT image along with 0 or more device trees and |
| 645 | # 0 or 1 ramdisk. |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 646 | # It is also possible to include an initramfs bundle (kernel and rootfs in one binary) |
| 647 | # When the initramfs bundle is used ramdisk is disabled. |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 648 | # If a device tree is to be part of the FIT image, then select |
| 649 | # the default configuration to be used is based on the dtbcount. If there is |
| 650 | # no dtb present than select the default configuation to be based on |
| 651 | # the kernelcount. |
| 652 | if [ -n "$DTBS" ]; then |
| 653 | i=1 |
| 654 | for DTB in ${DTBS}; do |
| 655 | dtb_ext=${DTB##*.} |
| 656 | if [ "$dtb_ext" = "dtbo" ]; then |
| 657 | fitimage_emit_section_config $1 "" "$DTB" "" "$bootscr_id" "" "`expr $i = $dtbcount`" |
| 658 | else |
| 659 | fitimage_emit_section_config $1 $kernelcount "$DTB" "$ramdiskcount" "$bootscr_id" "$setupcount" "`expr $i = $dtbcount`" |
| 660 | fi |
| 661 | i=`expr $i + 1` |
| 662 | done |
| 663 | else |
| 664 | defaultconfigcount=1 |
| 665 | fitimage_emit_section_config $1 $kernelcount "" "$ramdiskcount" "$bootscr_id" "$setupcount" $defaultconfigcount |
| 666 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 667 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 668 | fitimage_emit_section_maint $1 sectend |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 669 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 670 | fitimage_emit_section_maint $1 fitend |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 671 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 672 | # |
| 673 | # Step 7: Assemble the image |
| 674 | # |
| 675 | ${UBOOT_MKIMAGE} \ |
| 676 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 677 | -f $1 \ |
| 678 | ${KERNEL_OUTPUT_DIR}/$2 |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 679 | |
Patrick Williams | af48f63 | 2023-03-20 10:13:55 -0500 | [diff] [blame] | 680 | # |
| 681 | # Step 8: Sign the image |
| 682 | # |
| 683 | if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then |
| 684 | ${UBOOT_MKIMAGE_SIGN} \ |
| 685 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 686 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
| 687 | -r ${KERNEL_OUTPUT_DIR}/$2 \ |
| 688 | ${UBOOT_MKIMAGE_SIGN_ARGS} |
| 689 | fi |
Patrick Williams | e479e92 | 2023-01-06 13:45:20 -0600 | [diff] [blame] | 690 | } |