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