blob: d11882f90fd4d8338a4bbe2d6aca3b45483ce346 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# This file is part of U-Boot verified boot support and is intended to be
2# inherited from u-boot recipe and from kernel-fitimage.bbclass.
3#
4# The signature procedure requires the user to generate an RSA key and
5# certificate in a directory and to define the following variable:
6#
7# UBOOT_SIGN_KEYDIR = "/keys/directory"
8# UBOOT_SIGN_KEYNAME = "dev" # keys name in keydir (eg. "dev.crt", "dev.key")
9# UBOOT_MKIMAGE_DTCOPTS = "-I dts -O dtb -p 2000"
10# UBOOT_SIGN_ENABLE = "1"
11#
12# As verified boot depends on fitImage generation, following is also required:
13#
14# KERNEL_CLASSES ?= " kernel-fitimage "
15# KERNEL_IMAGETYPE ?= "fitImage"
16#
17# The signature support is limited to the use of CONFIG_OF_SEPARATE in U-Boot.
18#
19# The tasks sequence is set as below, using DEPLOY_IMAGE_DIR as common place to
20# treat the device tree blob:
21#
Brad Bishop19323692019-04-05 15:28:33 -040022# * u-boot:do_install_append
23# Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for
24# signing, and kernel will deploy UBOOT_DTB_BINARY after signs it.
25#
26# * virtual/kernel:do_assemble_fitimage
27# Sign the image
28#
29# * u-boot:do_deploy[postfuncs]
30# Deploy files like UBOOT_DTB_IMAGE, UBOOT_DTB_SYMLINK and others.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031#
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032# For more details on signature process, please refer to U-Boot documentation.
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050034# We need some variables from u-boot-config
35inherit uboot-config
36
37# Enable use of a U-Boot fitImage
38UBOOT_FITIMAGE_ENABLE ?= "0"
39
40# Signature activation - these require their respective fitImages
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041UBOOT_SIGN_ENABLE ?= "0"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050042SPL_SIGN_ENABLE ?= "0"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060043
44# Default value for deployment filenames.
45UBOOT_DTB_IMAGE ?= "u-boot-${MACHINE}-${PV}-${PR}.dtb"
46UBOOT_DTB_BINARY ?= "u-boot.dtb"
47UBOOT_DTB_SYMLINK ?= "u-boot-${MACHINE}.dtb"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050048UBOOT_NODTB_IMAGE ?= "u-boot-nodtb-${MACHINE}-${PV}-${PR}.bin"
49UBOOT_NODTB_BINARY ?= "u-boot-nodtb.bin"
50UBOOT_NODTB_SYMLINK ?= "u-boot-nodtb-${MACHINE}.bin"
51UBOOT_ITS_IMAGE ?= "u-boot-its-${MACHINE}-${PV}-${PR}"
52UBOOT_ITS ?= "u-boot.its"
53UBOOT_ITS_SYMLINK ?= "u-boot-its-${MACHINE}"
54UBOOT_FITIMAGE_IMAGE ?= "u-boot-fitImage-${MACHINE}-${PV}-${PR}"
55UBOOT_FITIMAGE_BINARY ?= "u-boot-fitImage"
56UBOOT_FITIMAGE_SYMLINK ?= "u-boot-fitImage-${MACHINE}"
57SPL_DIR ?= "spl"
58SPL_DTB_IMAGE ?= "u-boot-spl-${MACHINE}-${PV}-${PR}.dtb"
59SPL_DTB_BINARY ?= "u-boot-spl.dtb"
60SPL_DTB_SYMLINK ?= "u-boot-spl-${MACHINE}.dtb"
61SPL_NODTB_IMAGE ?= "u-boot-spl-nodtb-${MACHINE}-${PV}-${PR}.bin"
62SPL_NODTB_BINARY ?= "u-boot-spl-nodtb.bin"
63SPL_NODTB_SYMLINK ?= "u-boot-spl-nodtb-${MACHINE}.bin"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060064
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050065# U-Boot fitImage description
66UBOOT_FIT_DESC ?= "U-Boot fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"
67
68# Kernel / U-Boot fitImage Hash Algo
69FIT_HASH_ALG ?= "sha256"
70UBOOT_FIT_HASH_ALG ?= "sha256"
71
72# Kernel / U-Boot fitImage Signature Algo
73FIT_SIGN_ALG ?= "rsa2048"
74UBOOT_FIT_SIGN_ALG ?= "rsa2048"
75
76# Generate keys for signing Kernel / U-Boot fitImage
77FIT_GENERATE_KEYS ?= "0"
78UBOOT_FIT_GENERATE_KEYS ?= "0"
79
80# Size of private keys in number of bits
81FIT_SIGN_NUMBITS ?= "2048"
82UBOOT_FIT_SIGN_NUMBITS ?= "2048"
83
84# args to openssl genrsa (Default is just the public exponent)
85FIT_KEY_GENRSA_ARGS ?= "-F4"
86UBOOT_FIT_KEY_GENRSA_ARGS ?= "-F4"
87
88# args to openssl req (Default is -batch for non interactive mode and
89# -new for new certificate)
90FIT_KEY_REQ_ARGS ?= "-batch -new"
91UBOOT_FIT_KEY_REQ_ARGS ?= "-batch -new"
92
93# Standard format for public key certificate
94FIT_KEY_SIGN_PKCS ?= "-x509"
95UBOOT_FIT_KEY_SIGN_PKCS ?= "-x509"
96
97# Functions on this bbclass can apply to either U-boot or Kernel,
98# depending on the scenario
Brad Bishop19323692019-04-05 15:28:33 -040099UBOOT_PN = "${@d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'}"
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500100KERNEL_PN = "${@d.getVar('PREFERRED_PROVIDER_virtual/kernel')}"
101
102# We need u-boot-tools-native if we're creating a U-Boot fitImage
103python() {
104 if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1':
105 depends = d.getVar("DEPENDS")
106 depends = "%s u-boot-tools-native dtc-native" % depends
107 d.setVar("DEPENDS", depends)
108}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600109
Brad Bishopc342db32019-05-15 21:57:59 -0400110concat_dtb_helper() {
111 if [ -e "${UBOOT_DTB_BINARY}" ]; then
112 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_BINARY}
113 ln -sf ${UBOOT_DTB_IMAGE} ${DEPLOYDIR}/${UBOOT_DTB_SYMLINK}
114 fi
115
116 if [ -f "${UBOOT_NODTB_BINARY}" ]; then
117 install ${UBOOT_NODTB_BINARY} ${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}
118 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_SYMLINK}
119 ln -sf ${UBOOT_NODTB_IMAGE} ${DEPLOYDIR}/${UBOOT_NODTB_BINARY}
120 fi
121
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500122 # If we're not using a signed u-boot fit, concatenate SPL w/o DTB & U-Boot DTB
123 # with public key (otherwise it will be deployed by the equivalent
124 # concat_spl_dtb_helper function - cf. kernel-fitimage.bbclass for more details)
125 if [ "${SPL_SIGN_ENABLE}" != "1" ] ; then
126 deployed_uboot_dtb_binary='${DEPLOY_DIR_IMAGE}/${UBOOT_DTB_IMAGE}'
127 if [ "x${UBOOT_SUFFIX}" = "ximg" -o "x${UBOOT_SUFFIX}" = "xrom" ] && \
128 [ -e "$deployed_uboot_dtb_binary" ]; then
129 oe_runmake EXT_DTB=$deployed_uboot_dtb_binary
130 install ${UBOOT_BINARY} ${DEPLOYDIR}/${UBOOT_IMAGE}
131 elif [ -e "${DEPLOYDIR}/${UBOOT_NODTB_IMAGE}" -a -e "$deployed_uboot_dtb_binary" ]; then
132 cd ${DEPLOYDIR}
133 cat ${UBOOT_NODTB_IMAGE} $deployed_uboot_dtb_binary | tee ${B}/${CONFIG_B_PATH}/${UBOOT_BINARY} > ${UBOOT_IMAGE}
134 else
135 bbwarn "Failure while adding public key to u-boot binary. Verified boot won't be available."
136 fi
Brad Bishopc342db32019-05-15 21:57:59 -0400137 fi
138}
139
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500140concat_spl_dtb_helper() {
141
142 # We only deploy symlinks to the u-boot-spl.dtb,as the KERNEL_PN will
143 # be responsible for deploying the real file
144 if [ -e "${SPL_DIR}/${SPL_DTB_BINARY}" ] ; then
145 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_SYMLINK}
146 ln -sf ${SPL_DTB_IMAGE} ${DEPLOYDIR}/${SPL_DTB_BINARY}
147 fi
148
149 # Concatenate the SPL nodtb binary and u-boot.dtb
150 deployed_spl_dtb_binary='${DEPLOY_DIR_IMAGE}/${SPL_DTB_IMAGE}'
151 if [ -e "${DEPLOYDIR}/${SPL_NODTB_IMAGE}" -a -e "$deployed_spl_dtb_binary" ] ; then
152 cd ${DEPLOYDIR}
153 cat ${SPL_NODTB_IMAGE} $deployed_spl_dtb_binary | tee ${B}/${CONFIG_B_PATH}/${SPL_BINARY} > ${SPL_IMAGE}
154 else
155 bbwarn "Failure while adding public key to spl binary. Verified U-Boot boot won't be available."
156 fi
157}
158
159
Brad Bishop19323692019-04-05 15:28:33 -0400160concat_dtb() {
Brad Bishopc342db32019-05-15 21:57:59 -0400161 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" -a -n "${UBOOT_DTB_BINARY}" ]; then
Brad Bishop19323692019-04-05 15:28:33 -0400162 mkdir -p ${DEPLOYDIR}
Brad Bishopc342db32019-05-15 21:57:59 -0400163 if [ -n "${UBOOT_CONFIG}" ]; then
164 for config in ${UBOOT_MACHINE}; do
Brad Bishop96ff1982019-08-19 13:50:42 -0400165 CONFIG_B_PATH="${config}"
Brad Bishopc342db32019-05-15 21:57:59 -0400166 cd ${B}/${config}
167 concat_dtb_helper
168 done
169 else
Brad Bishop96ff1982019-08-19 13:50:42 -0400170 CONFIG_B_PATH=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600171 cd ${B}
Brad Bishopc342db32019-05-15 21:57:59 -0400172 concat_dtb_helper
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600173 fi
174 fi
175}
176
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500177concat_spl_dtb() {
178 if [ "${SPL_SIGN_ENABLE}" = "1" -a "${PN}" = "${UBOOT_PN}" -a -n "${SPL_DTB_BINARY}" ]; then
179 mkdir -p ${DEPLOYDIR}
180 if [ -n "${UBOOT_CONFIG}" ]; then
181 for config in ${UBOOT_MACHINE}; do
182 CONFIG_B_PATH="${config}"
183 cd ${B}/${config}
184 concat_spl_dtb_helper
185 done
186 else
187 CONFIG_B_PATH=""
188 cd ${B}
189 concat_spl_dtb_helper
190 fi
191 fi
192}
193
194
Brad Bishop19323692019-04-05 15:28:33 -0400195# Install UBOOT_DTB_BINARY to datadir, so that kernel can use it for
196# signing, and kernel will deploy UBOOT_DTB_BINARY after signs it.
Brad Bishopc342db32019-05-15 21:57:59 -0400197install_helper() {
198 if [ -f "${UBOOT_DTB_BINARY}" ]; then
199 install -d ${D}${datadir}
200 # UBOOT_DTB_BINARY is a symlink to UBOOT_DTB_IMAGE, so we
201 # need both of them.
202 install ${UBOOT_DTB_BINARY} ${D}${datadir}/${UBOOT_DTB_IMAGE}
203 ln -sf ${UBOOT_DTB_IMAGE} ${D}${datadir}/${UBOOT_DTB_BINARY}
204 else
205 bbwarn "${UBOOT_DTB_BINARY} not found"
206 fi
207}
208
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500209# Install SPL dtb and u-boot nodtb to datadir,
210install_spl_helper() {
211 if [ -f "${SPL_DIR}/${SPL_DTB_BINARY}" ]; then
212 install -d ${D}${datadir}
213 install ${SPL_DIR}/${SPL_DTB_BINARY} ${D}${datadir}/${SPL_DTB_IMAGE}
214 ln -sf ${SPL_DTB_IMAGE} ${D}${datadir}/${SPL_DTB_BINARY}
215 else
216 bbwarn "${SPL_DTB_BINARY} not found"
217 fi
218 if [ -f "${UBOOT_NODTB_BINARY}" ] ; then
219 install ${UBOOT_NODTB_BINARY} ${D}${datadir}/${UBOOT_NODTB_IMAGE}
220 ln -sf ${UBOOT_NODTB_IMAGE} ${D}${datadir}/${UBOOT_NODTB_BINARY}
221 else
222 bbwarn "${UBOOT_NODTB_BINARY} not found"
223 fi
224
225 # We need to install a 'stub' u-boot-fitimage + its to datadir,
226 # so that the KERNEL_PN can use the correct filename when
227 # assembling and deploying them
228 touch ${D}/${datadir}/${UBOOT_FITIMAGE_IMAGE}
229 touch ${D}/${datadir}/${UBOOT_ITS_IMAGE}
230}
231
Brad Bishop19323692019-04-05 15:28:33 -0400232do_install_append() {
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500233 if [ "${PN}" = "${UBOOT_PN}" ]; then
Brad Bishopc342db32019-05-15 21:57:59 -0400234 if [ -n "${UBOOT_CONFIG}" ]; then
235 for config in ${UBOOT_MACHINE}; do
236 cd ${B}/${config}
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500237 if [ "${UBOOT_SIGN_ENABLE}" = "1" -o "${UBOOT_FITIMAGE_ENABLE}" = "1" ] && \
238 [ -n "${UBOOT_DTB_BINARY}" ]; then
239 install_helper
240 fi
241 if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ]; then
242 install_spl_helper
243 fi
Brad Bishopc342db32019-05-15 21:57:59 -0400244 done
245 else
246 cd ${B}
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500247 if [ "${UBOOT_SIGN_ENABLE}" = "1" -o "${UBOOT_FITIMAGE_ENABLE}" = "1" ] && \
248 [ -n "${UBOOT_DTB_BINARY}" ]; then
249 install_helper
250 fi
251 if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ]; then
252 install_spl_helper
253 fi
Brad Bishop19323692019-04-05 15:28:33 -0400254 fi
255 fi
256}
257
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500258do_generate_rsa_keys() {
259 if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
260 bbwarn "FIT_GENERATE_KEYS is set to 1 even though UBOOT_SIGN_ENABLE is set to 0. The keys will not be generated as they won't be used."
261 fi
262
263 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
264
265 # Generate keys only if they don't already exist
266 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \
267 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt ]; then
268
269 # make directory if it does not already exist
270 mkdir -p "${UBOOT_SIGN_KEYDIR}"
271
272 echo "Generating RSA private key for signing fitImage"
273 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
274 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
275 "${FIT_SIGN_NUMBITS}"
276
277 echo "Generating certificate for signing fitImage"
278 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
279 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
280 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt
281 fi
282 fi
283
284 if [ "${SPL_SIGN_ENABLE}" = "0" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then
285 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."
286 fi
287
288 if [ "${SPL_SIGN_ENABLE}" = "1" ] && [ "${UBOOT_FIT_GENERATE_KEYS}" = "1" ]; then
289
290 # Generate keys only if they don't already exist
291 if [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key ] || \
292 [ ! -f "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt ]; then
293
294 # make directory if it does not already exist
295 mkdir -p "${SPL_SIGN_KEYDIR}"
296
297 echo "Generating RSA private key for signing U-Boot fitImage"
298 openssl genrsa ${UBOOT_FIT_KEY_GENRSA_ARGS} -out \
299 "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \
300 "${UBOOT_FIT_SIGN_NUMBITS}"
301
302 echo "Generating certificate for signing U-Boot fitImage"
303 openssl req ${FIT_KEY_REQ_ARGS} "${UBOOT_FIT_KEY_SIGN_PKCS}" \
304 -key "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".key \
305 -out "${SPL_SIGN_KEYDIR}/${SPL_SIGN_KEYNAME}".crt
306 fi
307 fi
308
309}
310
311addtask generate_rsa_keys before do_uboot_assemble_fitimage after do_compile
312
313# Create a ITS file for the U-boot FIT, for use when
314# we want to sign it so that the SPL can verify it
315uboot_fitimage_assemble() {
316 uboot_its="${1}"
317 uboot_nodtb_bin="${2}"
318 uboot_dtb="${3}"
319 uboot_bin="${4}"
320 spl_dtb="${5}"
321 uboot_csum="${UBOOT_FIT_HASH_ALG}"
322 uboot_sign_algo="${UBOOT_FIT_SIGN_ALG}"
323 uboot_sign_keyname="${SPL_SIGN_KEYNAME}"
324
325 rm -f ${uboot_its} ${uboot_bin}
326
327 # First we create the ITS script
328 cat << EOF >> ${uboot_its}
329/dts-v1/;
330
331/ {
332 description = "${UBOOT_FIT_DESC}";
333 #address-cells = <1>;
334
335 images {
336 uboot {
337 description = "U-Boot image";
338 data = /incbin/("${uboot_nodtb_bin}");
339 type = "standalone";
340 os = "u-boot";
341 arch = "${UBOOT_ARCH}";
342 compression = "none";
343 load = <${UBOOT_LOADADDRESS}>;
344 entry = <${UBOOT_ENTRYPOINT}>;
345EOF
346
347 if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
348 cat << EOF >> ${uboot_its}
349 signature {
350 algo = "${uboot_csum},${uboot_sign_algo}";
351 key-name-hint = "${uboot_sign_keyname}";
352 };
353EOF
354 fi
355
356 cat << EOF >> ${uboot_its}
357 };
358 fdt {
359 description = "U-Boot FDT";
360 data = /incbin/("${uboot_dtb}");
361 type = "flat_dt";
362 arch = "${UBOOT_ARCH}";
363 compression = "none";
364EOF
365
366 if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
367 cat << EOF >> ${uboot_its}
368 signature {
369 algo = "${uboot_csum},${uboot_sign_algo}";
370 key-name-hint = "${uboot_sign_keyname}";
371 };
372EOF
373 fi
374
375 cat << EOF >> ${uboot_its}
376 };
377 };
378
379 configurations {
380 default = "conf";
381 conf {
382 description = "Boot with signed U-Boot FIT";
383 loadables = "uboot";
384 fdt = "fdt";
385 };
386 };
387};
388EOF
389
390 #
391 # Assemble the U-boot FIT image
392 #
393 ${UBOOT_MKIMAGE} \
394 ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \
395 -f ${uboot_its} \
396 ${uboot_bin}
397
398 if [ "${SPL_SIGN_ENABLE}" = "1" ] ; then
399 #
400 # Sign the U-boot FIT image and add public key to SPL dtb
401 #
402 ${UBOOT_MKIMAGE_SIGN} \
403 ${@'-D "${SPL_MKIMAGE_DTCOPTS}"' if len('${SPL_MKIMAGE_DTCOPTS}') else ''} \
404 -F -k "${SPL_SIGN_KEYDIR}" \
405 -K "${spl_dtb}" \
406 -r ${uboot_bin} \
407 ${SPL_MKIMAGE_SIGN_ARGS}
408 fi
409
410}
411
412do_uboot_assemble_fitimage() {
413 # This function runs in KERNEL_PN context. The reason for that is that we need to
414 # support the scenario where UBOOT_SIGN_ENABLE is placing the Kernel fitImage's
415 # pubkey in the u-boot.dtb file, so that we can use it when building the U-Boot
416 # fitImage itself.
417 if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] && \
418 [ -n "${SPL_DTB_BINARY}" -a "${PN}" = "${KERNEL_PN}" ] ; then
419 if [ "${UBOOT_SIGN_ENABLE}" != "1" ]; then
420 # If we're not signing the Kernel fitImage, that means
421 # we need to copy the u-boot.dtb from staging ourselves
422 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
423 fi
424 # As we are in the kernel context, we need to copy u-boot-spl.dtb from staging first.
425 # Unfortunately, need to glob on top of ${SPL_DTB_BINARY} since _IMAGE and _SYMLINK
426 # will contain U-boot's PV
427 # Similarly, we need to get the filename for the 'stub' u-boot-fitimage + its in
428 # staging so that we can use it for creating the image with the correct filename
429 # in the KERNEL_PN context.
430 # As for the u-boot.dtb (with fitimage's pubkey), it should come from the dependent
431 # do_assemble_fitimage task
432 cp -P ${STAGING_DATADIR}/u-boot-spl*.dtb ${B}
433 cp -P ${STAGING_DATADIR}/u-boot-nodtb*.bin ${B}
434 rm -rf ${B}/u-boot-fitImage-* ${B}/u-boot-its-*
435 kernel_uboot_fitimage_name=`basename ${STAGING_DATADIR}/u-boot-fitImage-*`
436 kernel_uboot_its_name=`basename ${STAGING_DATADIR}/u-boot-its-*`
437 cd ${B}
438 uboot_fitimage_assemble ${kernel_uboot_its_name} ${UBOOT_NODTB_BINARY} \
439 ${UBOOT_DTB_BINARY} ${kernel_uboot_fitimage_name} \
440 ${SPL_DTB_BINARY}
441 fi
442}
443
444addtask uboot_assemble_fitimage before do_deploy after do_compile
445
Andrew Geissler475cb722020-07-10 16:00:51 -0500446do_deploy_prepend_pn-${UBOOT_PN}() {
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500447 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a -n "${UBOOT_DTB_BINARY}" ] ; then
Andrew Geissler475cb722020-07-10 16:00:51 -0500448 concat_dtb
449 fi
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500450
451 if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then
452 # Deploy the u-boot-nodtb binary and symlinks...
453 if [ -f "${SPL_DIR}/${SPL_NODTB_BINARY}" ] ; then
454 echo "Copying u-boot-nodtb binary..."
455 install -m 0644 ${SPL_DIR}/${SPL_NODTB_BINARY} ${DEPLOYDIR}/${SPL_NODTB_IMAGE}
456 ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_SYMLINK}
457 ln -sf ${SPL_NODTB_IMAGE} ${DEPLOYDIR}/${SPL_NODTB_BINARY}
458 fi
459
460
461 # We only deploy the symlinks to the uboot-fitImage and uboot-its
462 # images, as the KERNEL_PN will take care of deploying the real file
463 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_BINARY}
464 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_FITIMAGE_SYMLINK}
465 ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS}
466 ln -sf ${UBOOT_ITS_IMAGE} ${DEPLOYDIR}/${UBOOT_ITS_SYMLINK}
467 fi
468
469 if [ "${SPL_SIGN_ENABLE}" = "1" -a -n "${SPL_DTB_BINARY}" ] ; then
470 concat_spl_dtb
471 fi
472
473
474}
475
476do_deploy_append_pn-${UBOOT_PN}() {
477 # If we're creating a u-boot fitImage, point u-boot.bin
478 # symlink since it might get used by image recipes
479 if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" ] ; then
480 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_BINARY}
481 ln -sf ${UBOOT_FITIMAGE_IMAGE} ${DEPLOYDIR}/${UBOOT_SYMLINK}
482 fi
Andrew Geissler475cb722020-07-10 16:00:51 -0500483}
484
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600485python () {
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500486 if ( (d.getVar('UBOOT_SIGN_ENABLE') == '1'
487 or d.getVar('UBOOT_FITIMAGE_ENABLE') == '1')
488 and d.getVar('PN') == d.getVar('UBOOT_PN')
489 and d.getVar('UBOOT_DTB_BINARY')):
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600490
Brad Bishop19323692019-04-05 15:28:33 -0400491 # Make "bitbake u-boot -cdeploy" deploys the signed u-boot.dtb
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500492 # and/or the U-Boot fitImage
493 d.appendVarFlag('do_deploy', 'depends', ' %s:do_deploy' % d.getVar('KERNEL_PN'))
494
495 if d.getVar('UBOOT_FITIMAGE_ENABLE') == '1' and d.getVar('PN') == d.getVar('KERNEL_PN'):
496 # As the U-Boot fitImage is created by the KERNEL_PN, we need
497 # to make sure that the u-boot-spl.dtb and u-boot-spl-nodtb.bin
498 # files are in the staging dir for it's use
499 d.appendVarFlag('do_uboot_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % d.getVar('UBOOT_PN'))
500
501 # If the Kernel fitImage is being signed, we need to
502 # create the U-Boot fitImage after it
503 if d.getVar('UBOOT_SIGN_ENABLE') == '1':
504 d.appendVarFlag('do_uboot_assemble_fitimage', 'depends', ' %s:do_assemble_fitimage' % d.getVar('KERNEL_PN'))
505 d.appendVarFlag('do_uboot_assemble_fitimage', 'depends', ' %s:do_assemble_fitimage_initramfs' % d.getVar('KERNEL_PN'))
506
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600507}