Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | # This file is part of U-Boot verified boot support and is intended to be |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 8 | # inherited from the u-boot recipe. |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 9 | # |
| 10 | # The signature procedure requires the user to generate an RSA key and |
| 11 | # certificate in a directory and to define the following variable: |
| 12 | # |
| 13 | # UBOOT_SIGN_KEYDIR = "/keys/directory" |
| 14 | # UBOOT_SIGN_KEYNAME = "dev" # keys name in keydir (eg. "dev.crt", "dev.key") |
| 15 | # UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000" |
| 16 | # UBOOT_SIGN_ENABLE = "1" |
| 17 | # |
| 18 | # As verified boot depends on fitImage generation, following is also required: |
| 19 | # |
| 20 | # KERNEL_CLASSES ?= " kernel-fitimage " |
| 21 | # KERNEL_IMAGETYPE ?= "fitImage" |
| 22 | # |
| 23 | # The signature support is limited to the use of CONFIG_OF_SEPARATE in U-Boot. |
| 24 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 25 | # For more details on signature process, please refer to U-Boot documentation. |
| 26 | |
| 27 | # We need some variables from u-boot-config |
| 28 | inherit uboot-config |
| 29 | |
| 30 | # Enable use of a U-Boot fitImage |
| 31 | UBOOT_FITIMAGE_ENABLE ?= "0" |
| 32 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 33 | # Signature activation - this requires UBOOT_FITIMAGE_ENABLE = "1" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 34 | SPL_SIGN_ENABLE ?= "0" |
| 35 | |
| 36 | # Default value for deployment filenames. |
| 37 | UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb" |
| 38 | UBOOT_DTB_BINARY ?= "u-boot.dtb" |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 39 | UBOOT_DTB_SIGNED ?= "${UBOOT_DTB_BINARY}-signed" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 40 | UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb" |
| 41 | UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.bin" |
| 42 | UBOOT_NODTB_BINARY ?= "u-boot-nodtb.bin" |
| 43 | UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.bin" |
| 44 | UBOOT_ITS_IMAGE ?= "u-boot-its-${MACHINE}-${PV}-${PR}" |
| 45 | UBOOT_ITS ?= "u-boot.its" |
| 46 | UBOOT_ITS_SYMLINK ?= "u-boot-its-${MACHINE}" |
| 47 | UBOOT_FITIMAGE_IMAGE ?= "u-boot-fitImage-${MACHINE}-${PV}-${PR}" |
| 48 | UBOOT_FITIMAGE_BINARY ?= "u-boot-fitImage" |
| 49 | UBOOT_FITIMAGE_SYMLINK ?= "u-boot-fitImage-${MACHINE}" |
| 50 | SPL_DIR ?= "spl" |
| 51 | SPL_DTB_IMAGE ?= "u-boot-spl-${MACHINE}-${PV}-${PR}.dtb" |
| 52 | SPL_DTB_BINARY ?= "u-boot-spl.dtb" |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 53 | SPL_DTB_SIGNED ?= "${SPL_DTB_BINARY}-signed" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 54 | SPL_DTB_SYMLINK ?= "u-boot-spl-${MACHINE}.dtb" |
| 55 | SPL_NODTB_IMAGE ?= "u-boot-spl-nodtb-${MACHINE}-${PV}-${PR}.bin" |
| 56 | SPL_NODTB_BINARY ?= "u-boot-spl-nodtb.bin" |
| 57 | SPL_NODTB_SYMLINK ?= "u-boot-spl-nodtb-${MACHINE}.bin" |
| 58 | |
| 59 | # U-Boot fitImage description |
| 60 | UBOOT_FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}" |
| 61 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 62 | # U-Boot fitImage Hash Algo |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 63 | UBOOT_FIT_HASH_ALG ?= "sha256" |
| 64 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 65 | # U-Boot fitImage Signature Algo |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 66 | UBOOT_FIT_SIGN_ALG ?= "rsa2048" |
| 67 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 68 | # Generate keys for signing U-Boot fitImage |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 69 | UBOOT_FIT_GENERATE_KEYS ?= "0" |
| 70 | |
| 71 | # Size of private keys in number of bits |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 72 | UBOOT_FIT_SIGN_NUMBITS ?= "2048" |
| 73 | |
| 74 | # args to openssl genrsa (Default is just the public exponent) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 75 | UBOOT_FIT_KEY_GENRSA_ARGS ?= "-F4" |
| 76 | |
| 77 | # args to openssl req (Default is -batch for non interactive mode and |
| 78 | # -new for new certificate) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 79 | UBOOT_FIT_KEY_REQ_ARGS ?= "-batch -new" |
| 80 | |
| 81 | # Standard format for public key certificate |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 82 | UBOOT_FIT_KEY_SIGN_PKCS ?= "-x509" |
| 83 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 84 | # This is only necessary for determining the signing configuration |
| 85 | KERNEL_PN = "${PREFERRED_PROVIDER_virtual/kernel}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 86 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 87 | python() { |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 88 | # We need u-boot-tools-native if we're creating a U-Boot fitImage |
| 89 | sign = d.getVar('UBOOT_SIGN_ENABLE') == '1' |
| 90 | if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' or sign: |
| 91 | d.appendVar('DEPENDS', " u-boot-tools-native dtc-native") |
| 92 | if sign: |
| 93 | d.appendVar('DEPENDS', " " + d.getVar('KERNEL_PN')) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 94 | } |
| 95 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 96 | concat_dtb() { |
| 97 | type="$1" |
| 98 | binary="$2" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 99 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 100 | if [ -e "${UBOOT_DTB_BINARY}" ]; then |
| 101 | # Re-sign the kernel in order to add the keys to our dtb |
| 102 | ${UBOOT_MKIMAGE_SIGN} \ |
| 103 | ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \ |
| 104 | -F -k "${UBOOT_SIGN_KEYDIR}" \ |
| 105 | -K "${UBOOT_DTB_BINARY}" \ |
| 106 | -r ${B}/fitImage-linux \ |
| 107 | ${UBOOT_MKIMAGE_SIGN_ARGS} |
| 108 | cp ${UBOOT_DTB_BINARY} ${UBOOT_DTB_SIGNED} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 109 | fi |
| 110 | |
| 111 | # If we're not using a signed u-boot fit, concatenate SPL w/o DTB & U-Boot DTB |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 112 | # with public key (otherwise U-Boot will be packaged by uboot_fitimage_assemble) |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 113 | if [ "${SPL_SIGN_ENABLE}" != "1" ] ; then |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 114 | if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \ |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 115 | [ -e "${UBOOT_DTB_BINARY}" ]; then |
| 116 | oe_runmake EXT_DTB="${UBOOT_DTB_SIGNED}" ${UBOOT_MAKE_TARGET} |
| 117 | if [ -n "${binary}" ]; then |
| 118 | cp ${binary} ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX} |
| 119 | fi |
| 120 | elif [ -e "${UBOOT_NODTB_BINARY}" -a -e "${UBOOT_DTB_BINARY}" ]; then |
| 121 | if [ -n "${binary}" ]; then |
| 122 | cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} | tee ${binary} > \ |
| 123 | ${UBOOT_BINARYNAME}-${type}.${UBOOT_SUFFIX} |
| 124 | else |
| 125 | cat ${UBOOT_NODTB_BINARY} ${UBOOT_DTB_SIGNED} > ${UBOOT_BINARY} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 126 | fi |
| 127 | else |
| 128 | bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available." |
| 129 | fi |
| 130 | fi |
| 131 | } |
| 132 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 133 | deploy_dtb() { |
| 134 | type="$1" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 135 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 136 | if [ -n "${type}" ]; then |
| 137 | uboot_dtb_binary="u-boot-${type}-${PV}-${PR}.dtb" |
| 138 | uboot_nodtb_binary="u-boot-nodtb-${type}-${PV}-${PR}.bin" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 139 | else |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 140 | uboot_dtb_binary="${UBOOT_DTB_IMAGE}" |
| 141 | uboot_nodtb_binary="${UBOOT_NODTB_IMAGE}" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 142 | fi |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 143 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 144 | if [ -e "${UBOOT_DTB_SIGNED}" ]; then |
| 145 | install -Dm644 ${UBOOT_DTB_SIGNED} ${DEPLOYDIR}/${uboot_dtb_binary} |
| 146 | if [ -n "${type}" ]; then |
| 147 | ln -sf ${uboot_dtb_binary} ${DEPLOYDIR}/${UBOOT_DTB_IMAGE} |
| 148 | fi |
| 149 | fi |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 150 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 151 | if [ -f "${UBOOT_NODTB_BINARY}" ]; then |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 152 | install -Dm644 ${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${uboot_nodtb_binary} |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 153 | if [ -n "${type}" ]; then |
| 154 | ln -sf ${uboot_nodtb_binary} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 155 | fi |
| 156 | fi |
| 157 | } |
| 158 | |
| 159 | concat_spl_dtb() { |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 160 | if [ -e "${SPL_DIR}/${SPL_NODTB_BINARY}" -a -e "${SPL_DIR}/${SPL_DTB_BINARY}" ] ; then |
| 161 | cat ${SPL_DIR}/${SPL_NODTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED} > "${SPL_BINARY}" |
| 162 | else |
| 163 | bbwarn "Failure while adding public key to spl binary. Verified U-Boot boot won't be available." |
| 164 | fi |
| 165 | } |
| 166 | |
| 167 | deploy_spl_dtb() { |
| 168 | type="$1" |
| 169 | |
| 170 | if [ -n "${type}" ]; then |
| 171 | spl_dtb_binary="u-boot-spl-${type}-${PV}-${PR}.dtb" |
| 172 | spl_nodtb_binary="u-boot-spl-nodtb-${type}-${PV}-${PR}.bin" |
| 173 | else |
| 174 | spl_dtb_binary="${SPL_DTB_IMAGE}" |
| 175 | spl_nodtb_binary="${SPL_NODTB_IMAGE}" |
| 176 | fi |
| 177 | |
| 178 | if [ -e "${SPL_DIR}/${SPL_DTB_SIGNED}" ] ; then |
| 179 | install -Dm644 ${SPL_DIR}/${SPL_DTB_SIGNED} ${DEPLOYDIR}/${spl_dtb_binary} |
| 180 | if [ -n "${type}" ]; then |
| 181 | ln -sf ${spl_dtb_binary} ${DEPLOYDIR}/${SPL_DTB_IMAGE} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 182 | fi |
| 183 | fi |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 184 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 185 | if [ -f "${SPL_DIR}/${SPL_NODTB_BINARY}" ] ; then |
| 186 | install -Dm644 ${SPL_DIR}/${SPL_NODTB_BINARY} ${DEPLOYDIR}/${spl_nodtb_binary} |
| 187 | if [ -n "${type}" ]; then |
| 188 | ln -sf ${spl_nodtb_binary} ${DEPLOYDIR}/${SPL_NODTB_IMAGE} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 189 | fi |
| 190 | fi |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 191 | |
| 192 | # For backwards compatibility... |
| 193 | install -Dm644 ${SPL_BINARY} ${DEPLOYDIR}/${SPL_IMAGE} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | do_uboot_generate_rsa_keys() { |
| 197 | if [ "${SPL_SIGN_ENABLE}" = "0" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then |
| 198 | bbwarn "UBOOT_FIT_GENERATE_KEYS is set to 1 eventhough SPL_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used." |
| 199 | fi |
| 200 | |
| 201 | if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then |
| 202 | |
| 203 | # Generate keys only if they don't already exist |
| 204 | if [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key ] || \ |
| 205 | [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt ]; then |
| 206 | |
| 207 | # make directory if it does not already exist |
| 208 | mkdir -p "${SPL_SIGN_KEYDIR}" |
| 209 | |
| 210 | echo "Generating RSA private key for signing U-Boot fitImage" |
| 211 | openssl genrsa ${UBOOT_FIT_KEY_GENRSA_ARGS} -out \ |
| 212 | "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \ |
| 213 | "${UBOOT_FIT_SIGN_NUMBITS}" |
| 214 | |
| 215 | echo "Generating certificate for signing U-Boot fitImage" |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 216 | openssl req ${UBOOT_FIT_KEY_REQ_ARGS} "${UBOOT_FIT_KEY_SIGN_PKCS}" \ |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 217 | -key "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \ |
| 218 | -out "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt |
| 219 | fi |
| 220 | fi |
| 221 | |
| 222 | } |
| 223 | |
| 224 | addtask uboot_generate_rsa_keys before do_uboot_assemble_fitimage after do_compile |
| 225 | |
| 226 | # Create a ITS file for the U-boot FIT, for use when |
| 227 | # we want to sign it so that the SPL can verify it |
| 228 | uboot_fitimage_assemble() { |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 229 | rm -f ${UBOOT_ITS} ${UBOOT_FITIMAGE_BINARY} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 230 | |
| 231 | # First we create the ITS script |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 232 | cat << EOF >> ${UBOOT_ITS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 233 | /dts-v1/; |
| 234 | |
| 235 | / { |
| 236 | description = "${UBOOT_FIT_DESC}"; |
| 237 | #address-cells = <1>; |
| 238 | |
| 239 | images { |
| 240 | uboot { |
| 241 | description = "U-Boot image"; |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 242 | data = /incbin/("${UBOOT_NODTB_BINARY}"); |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 243 | type = "standalone"; |
| 244 | os = "u-boot"; |
| 245 | arch = "${UBOOT_ARCH}"; |
| 246 | compression = "none"; |
| 247 | load = <${UBOOT_LOADADDRESS}>; |
| 248 | entry = <${UBOOT_ENTRYPOINT}>; |
| 249 | EOF |
| 250 | |
| 251 | if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 252 | cat << EOF >> ${UBOOT_ITS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 253 | signature { |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 254 | algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}"; |
| 255 | key-name-hint = "${SPL_SIGN_KEYNAME}"; |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 256 | }; |
| 257 | EOF |
| 258 | fi |
| 259 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 260 | cat << EOF >> ${UBOOT_ITS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 261 | }; |
| 262 | fdt { |
| 263 | description = "U-Boot FDT"; |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 264 | data = /incbin/("${UBOOT_DTB_BINARY}"); |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 265 | type = "flat_dt"; |
| 266 | arch = "${UBOOT_ARCH}"; |
| 267 | compression = "none"; |
| 268 | EOF |
| 269 | |
| 270 | if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 271 | cat << EOF >> ${UBOOT_ITS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 272 | signature { |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 273 | algo = "${UBOOT_FIT_HASH_ALG},${UBOOT_FIT_SIGN_ALG}"; |
| 274 | key-name-hint = "${SPL_SIGN_KEYNAME}"; |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 275 | }; |
| 276 | EOF |
| 277 | fi |
| 278 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 279 | cat << EOF >> ${UBOOT_ITS} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 280 | }; |
| 281 | }; |
| 282 | |
| 283 | configurations { |
| 284 | default = "conf"; |
| 285 | conf { |
| 286 | description = "Boot with signed U-Boot FIT"; |
| 287 | loadables = "uboot"; |
| 288 | fdt = "fdt"; |
| 289 | }; |
| 290 | }; |
| 291 | }; |
| 292 | EOF |
| 293 | |
| 294 | # |
| 295 | # Assemble the U-boot FIT image |
| 296 | # |
| 297 | ${UBOOT_MKIMAGE} \ |
| 298 | ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \ |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 299 | -f ${UBOOT_ITS} \ |
| 300 | ${UBOOT_FITIMAGE_BINARY} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 301 | |
| 302 | if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then |
| 303 | # |
| 304 | # Sign the U-boot FIT image and add public key to SPL dtb |
| 305 | # |
| 306 | ${UBOOT_MKIMAGE_SIGN} \ |
| 307 | ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \ |
| 308 | -F -k "${SPL_SIGN_KEYDIR}" \ |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 309 | -K "${SPL_DIR}/${SPL_DTB_BINARY}" \ |
| 310 | -r ${UBOOT_FITIMAGE_BINARY} \ |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 311 | ${SPL_MKIMAGE_SIGN_ARGS} |
| 312 | fi |
| 313 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 314 | cp ${SPL_DIR}/${SPL_DTB_BINARY} ${SPL_DIR}/${SPL_DTB_SIGNED} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 315 | } |
| 316 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 317 | uboot_assemble_fitimage_helper() { |
| 318 | type="$1" |
| 319 | binary="$2" |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 320 | |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 321 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 322 | concat_dtb $type $binary |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 323 | fi |
| 324 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 325 | if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ]; then |
| 326 | uboot_fitimage_assemble |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 327 | fi |
| 328 | |
| 329 | if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then |
| 330 | concat_spl_dtb |
| 331 | fi |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 332 | } |
| 333 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 334 | do_uboot_assemble_fitimage() { |
| 335 | if [ "${UBOOT_SIGN_ENABLE}" = "1" ] ; then |
| 336 | cp "${STAGING_DIR_HOST}/sysroot-only/fitImage" "${B}/fitImage-linux" |
| 337 | fi |
| 338 | |
| 339 | if [ -n "${UBOOT_CONFIG}" ]; then |
| 340 | unset i j k |
| 341 | for config in ${UBOOT_MACHINE}; do |
| 342 | i=$(expr $i + 1); |
| 343 | for type in ${UBOOT_CONFIG}; do |
| 344 | j=$(expr $j + 1); |
| 345 | if [ $j -eq $i ]; then |
| 346 | break; |
| 347 | fi |
| 348 | done |
| 349 | |
| 350 | for binary in ${UBOOT_BINARIES}; do |
| 351 | k=$(expr $j + 1); |
| 352 | if [ $k -eq $i ]; then |
| 353 | break; |
| 354 | fi |
| 355 | done |
| 356 | |
| 357 | cd ${B}/${config} |
| 358 | uboot_assemble_fitimage_helper ${type} ${binary} |
| 359 | done |
| 360 | else |
| 361 | cd ${B} |
| 362 | uboot_assemble_fitimage_helper "" ${UBOOT_BINARY} |
| 363 | fi |
| 364 | } |
| 365 | |
| 366 | addtask uboot_assemble_fitimage before do_install do_deploy after do_compile |
| 367 | |
| 368 | deploy_helper() { |
| 369 | type="$1" |
| 370 | |
| 371 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_SIGNED}" ] ; then |
| 372 | deploy_dtb $type |
| 373 | fi |
| 374 | |
| 375 | if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ]; then |
| 376 | if [ -n "${type}" ]; then |
| 377 | uboot_its_image="u-boot-its-${type}-${PV}-${PR}" |
| 378 | uboot_fitimage_image="u-boot-fitImage-${type}-${PV}-${PR}" |
| 379 | else |
| 380 | uboot_its_image="${UBOOT_ITS_IMAGE}" |
| 381 | uboot_fitimage_image="${UBOOT_FITIMAGE_IMAGE}" |
| 382 | fi |
| 383 | |
| 384 | install -Dm644 ${UBOOT_FITIMAGE_BINARY} ${DEPLOYDIR}/$uboot_fitimage_image |
| 385 | install -Dm644 ${UBOOT_ITS} ${DEPLOYDIR}/$uboot_its_image |
| 386 | |
| 387 | if [ -n "${type}" ]; then |
| 388 | ln -sf $uboot_its_image ${DEPLOYDIR}/${UBOOT_ITS_IMAGE} |
| 389 | ln -sf $uboot_fitimage_image ${DEPLOYDIR}/${UBOOT_FITIMAGE_IMAGE} |
| 390 | fi |
| 391 | fi |
| 392 | |
| 393 | if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_SIGNED}" ] ; then |
| 394 | deploy_spl_dtb $type |
| 395 | fi |
| 396 | } |
| 397 | |
| 398 | do_deploy:prepend() { |
| 399 | if [ -n "${UBOOT_CONFIG}" ]; then |
| 400 | unset i j k |
| 401 | for config in ${UBOOT_MACHINE}; do |
| 402 | i=$(expr $i + 1); |
| 403 | for type in ${UBOOT_CONFIG}; do |
| 404 | j=$(expr $j + 1); |
| 405 | if [ $j -eq $i ]; then |
| 406 | cd ${B}/${config} |
| 407 | deploy_helper ${type} |
| 408 | fi |
| 409 | done |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 410 | unset j |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 411 | done |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 412 | unset i |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 413 | else |
| 414 | cd ${B} |
| 415 | deploy_helper "" |
| 416 | fi |
| 417 | |
| 418 | if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then |
| 419 | ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY} |
| 420 | ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK} |
| 421 | ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK} |
| 422 | ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_BINARY} |
| 423 | fi |
| 424 | |
| 425 | if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then |
| 426 | ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS} |
| 427 | ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS_SYMLINK} |
| 428 | ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_BINARY} |
| 429 | ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_SYMLINK} |
| 430 | fi |
| 431 | |
| 432 | if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then |
| 433 | ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_SYMLINK} |
| 434 | ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_BINARY} |
| 435 | ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_SYMLINK} |
| 436 | ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_BINARY} |
| 437 | fi |
| 438 | } |
| 439 | |
| 440 | do_deploy:append() { |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 441 | # If we're creating a u-boot fitImage, point u-boot.bin |
| 442 | # symlink since it might get used by image recipes |
| 443 | if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then |
| 444 | ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_BINARY} |
| 445 | ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_SYMLINK} |
| 446 | fi |
| 447 | } |