blob: 2112ae4cfa415526479636c06ffa50562765d484 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001inherit kernel-uboot kernel-artifact-names uboot-sign
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Andrew Geissler9aee5002022-03-30 16:27:02 +00003def get_fit_replacement_type(d):
Brad Bishop6e60e8b2018-02-01 10:27:11 -05004 kerneltypes = d.getVar('KERNEL_IMAGETYPES') or ""
Andrew Geissler9aee5002022-03-30 16:27:02 +00005 replacementtype = ""
He Zhefe76b1e2016-05-25 04:47:16 -04006 if 'fitImage' in kerneltypes.split():
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007 uarch = d.getVar("UBOOT_ARCH")
8 if uarch == "arm64":
9 replacementtype = "Image"
Brad Bishopc342db32019-05-15 21:57:59 -040010 elif uarch == "riscv":
11 replacementtype = "Image"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012 elif uarch == "mips":
Brad Bishop6e60e8b2018-02-01 10:27:11 -050013 replacementtype = "vmlinuz.bin"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014 elif uarch == "x86":
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015 replacementtype = "bzImage"
Brad Bishop316dfdd2018-06-25 12:45:53 -040016 elif uarch == "microblaze":
17 replacementtype = "linux.bin"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060018 else:
19 replacementtype = "zImage"
Andrew Geissler9aee5002022-03-30 16:27:02 +000020 return replacementtype
Patrick Williamsc0f7c042017-02-23 20:41:17 -060021
Andrew Geissler9aee5002022-03-30 16:27:02 +000022KERNEL_IMAGETYPE_REPLACEMENT ?= "${@get_fit_replacement_type(d)}"
23DEPENDS:append = " ${@'u-boot-tools-native dtc-native' if 'fitImage' in (d.getVar('KERNEL_IMAGETYPES') or '').split() else ''}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -060024
Andrew Geissler9aee5002022-03-30 16:27:02 +000025python __anonymous () {
Brad Bishop19323692019-04-05 15:28:33 -040026 # Override KERNEL_IMAGETYPE_FOR_MAKE variable, which is internal
27 # to kernel.bbclass . We have to override it, since we pack zImage
28 # (at least for now) into the fitImage .
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 typeformake = d.getVar("KERNEL_IMAGETYPE_FOR_MAKE") or ""
He Zhefe76b1e2016-05-25 04:47:16 -040030 if 'fitImage' in typeformake.split():
Andrew Geissler9aee5002022-03-30 16:27:02 +000031 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake.replace('fitImage', d.getVar('KERNEL_IMAGETYPE_REPLACEMENT')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
Brad Bishop6e60e8b2018-02-01 10:27:11 -050033 image = d.getVar('INITRAMFS_IMAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 if image:
George McCollister185c8ae2016-05-26 08:55:16 -050035 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
36
Andrew Geissler7e0e3c02022-02-25 20:34:39 +000037 ubootenv = d.getVar('UBOOT_ENV')
38 if ubootenv:
39 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/bootloader:do_populate_sysroot')
40
Brad Bishop19323692019-04-05 15:28:33 -040041 #check if there are any dtb providers
42 providerdtb = d.getVar("PREFERRED_PROVIDER_virtual/dtb")
43 if providerdtb:
44 d.appendVarFlag('do_assemble_fitimage', 'depends', ' virtual/dtb:do_populate_sysroot')
45 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' virtual/dtb:do_populate_sysroot')
46 d.setVar('EXTERNAL_KERNEL_DEVICETREE', "${RECIPE_SYSROOT}/boot/devicetree")
47
Patrick Williamsc0f7c042017-02-23 20:41:17 -060048 # Verified boot will sign the fitImage and append the public key to
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 # U-Boot dtb. We ensure the U-Boot dtb is deployed before assembling
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050 # the fitImage:
Brad Bishop15ae2502019-06-18 21:44:24 -040051 if d.getVar('UBOOT_SIGN_ENABLE') == "1" and d.getVar('UBOOT_DTB_BINARY'):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 uboot_pn = d.getVar('PREFERRED_PROVIDER_u-boot') or 'u-boot'
Brad Bishop19323692019-04-05 15:28:33 -040053 d.appendVarFlag('do_assemble_fitimage', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
Andrew Geisslerd1e89492021-02-12 15:35:20 -060054 if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1":
55 d.appendVarFlag('do_assemble_fitimage_initramfs', 'depends', ' %s:do_populate_sysroot' % uboot_pn)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056}
57
Andrew Geisslerf0343792020-11-18 10:42:21 -060058
Andrew Geisslerd1e89492021-02-12 15:35:20 -060059# Description string
Andrew Geissler3b8a17c2021-04-15 15:55:55 -050060FIT_DESC ?= "Kernel fitImage for ${DISTRO_NAME}/${PV}/${MACHINE}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -060061
62# Sign individual images as well
63FIT_SIGN_INDIVIDUAL ?= "0"
64
Andrew Geissler9aee5002022-03-30 16:27:02 +000065FIT_CONF_PREFIX ?= "conf-"
66FIT_CONF_PREFIX[doc] = "Prefix to use for FIT configuration node name"
67
68FIT_SUPPORTED_INITRAMFS_FSTYPES ?= "cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst cpio.gz ext2.gz cpio"
69
Patrick Williams0ca19cc2021-08-16 14:03:13 -050070# Keys used to sign individually image nodes.
71# The keys to sign image nodes must be different from those used to sign
72# configuration nodes, otherwise the "required" property, from
73# UBOOT_DTB_BINARY, will be set to "conf", because "conf" prevails on "image".
74# Then the images signature checking will not be mandatory and no error will be
75# raised in case of failure.
76# UBOOT_SIGN_IMG_KEYNAME = "dev2" # keys name in keydir (eg. "dev2.crt", "dev2.key")
77
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078#
79# Emit the fitImage ITS header
80#
George McCollister185c8ae2016-05-26 08:55:16 -050081# $1 ... .its filename
Patrick Williamsc124f4f2015-09-15 14:41:29 -050082fitimage_emit_fit_header() {
Andrew Geisslereff27472021-10-29 15:35:00 -050083 cat << EOF >> $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084/dts-v1/;
85
86/ {
Andrew Geisslerd1e89492021-02-12 15:35:20 -060087 description = "${FIT_DESC}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 #address-cells = <1>;
89EOF
90}
91
92#
93# Emit the fitImage section bits
94#
George McCollister185c8ae2016-05-26 08:55:16 -050095# $1 ... .its filename
96# $2 ... Section bit type: imagestart - image section start
Patrick Williamsc124f4f2015-09-15 14:41:29 -050097# confstart - configuration section start
98# sectend - section end
99# fitend - fitimage end
100#
101fitimage_emit_section_maint() {
George McCollister185c8ae2016-05-26 08:55:16 -0500102 case $2 in
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500103 imagestart)
Andrew Geisslereff27472021-10-29 15:35:00 -0500104 cat << EOF >> $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105
106 images {
107EOF
108 ;;
109 confstart)
Andrew Geisslereff27472021-10-29 15:35:00 -0500110 cat << EOF >> $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500111
112 configurations {
113EOF
114 ;;
115 sectend)
Andrew Geisslereff27472021-10-29 15:35:00 -0500116 cat << EOF >> $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500117 };
118EOF
119 ;;
120 fitend)
Andrew Geisslereff27472021-10-29 15:35:00 -0500121 cat << EOF >> $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122};
123EOF
124 ;;
125 esac
126}
127
128#
129# Emit the fitImage ITS kernel section
130#
George McCollister185c8ae2016-05-26 08:55:16 -0500131# $1 ... .its filename
132# $2 ... Image counter
133# $3 ... Path to kernel image
134# $4 ... Compression type
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500135fitimage_emit_section_kernel() {
136
Brad Bishopf3fd2882019-06-21 08:06:37 -0400137 kernel_csum="${FIT_HASH_ALG}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600138 kernel_sign_algo="${FIT_SIGN_ALG}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500139 kernel_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140
Brad Bishop316dfdd2018-06-25 12:45:53 -0400141 ENTRYPOINT="${UBOOT_ENTRYPOINT}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
143 ENTRYPOINT=`${HOST_PREFIX}nm vmlinux | \
144 awk '$3=="${UBOOT_ENTRYSYMBOL}" {print "0x"$1;exit}'`
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 fi
146
Andrew Geisslereff27472021-10-29 15:35:00 -0500147 cat << EOF >> $1
148 kernel-$2 {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500149 description = "Linux kernel";
Andrew Geisslereff27472021-10-29 15:35:00 -0500150 data = /incbin/("$3");
Andrew Geissler615f2f12022-07-15 14:00:58 -0500151 type = "${UBOOT_MKIMAGE_KERNEL_TYPE}";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152 arch = "${UBOOT_ARCH}";
153 os = "linux";
Andrew Geisslereff27472021-10-29 15:35:00 -0500154 compression = "$4";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155 load = <${UBOOT_LOADADDRESS}>;
Andrew Geisslereff27472021-10-29 15:35:00 -0500156 entry = <$ENTRYPOINT>;
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600157 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500158 algo = "$kernel_csum";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159 };
160 };
161EOF
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600162
Andrew Geisslereff27472021-10-29 15:35:00 -0500163 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$kernel_sign_keyname" ] ; then
164 sed -i '$ d' $1
165 cat << EOF >> $1
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600166 signature-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500167 algo = "$kernel_csum,$kernel_sign_algo";
168 key-name-hint = "$kernel_sign_keyname";
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600169 };
170 };
171EOF
172 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173}
174
175#
176# Emit the fitImage ITS DTB section
177#
George McCollister185c8ae2016-05-26 08:55:16 -0500178# $1 ... .its filename
179# $2 ... Image counter
180# $3 ... Path to DTB image
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500181fitimage_emit_section_dtb() {
182
Brad Bishopf3fd2882019-06-21 08:06:37 -0400183 dtb_csum="${FIT_HASH_ALG}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600184 dtb_sign_algo="${FIT_SIGN_ALG}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500185 dtb_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800187 dtb_loadline=""
188 dtb_ext=${DTB##*.}
189 if [ "${dtb_ext}" = "dtbo" ]; then
190 if [ -n "${UBOOT_DTBO_LOADADDRESS}" ]; then
191 dtb_loadline="load = <${UBOOT_DTBO_LOADADDRESS}>;"
192 fi
193 elif [ -n "${UBOOT_DTB_LOADADDRESS}" ]; then
194 dtb_loadline="load = <${UBOOT_DTB_LOADADDRESS}>;"
195 fi
Andrew Geisslereff27472021-10-29 15:35:00 -0500196 cat << EOF >> $1
197 fdt-$2 {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 description = "Flattened Device Tree blob";
Andrew Geisslereff27472021-10-29 15:35:00 -0500199 data = /incbin/("$3");
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500200 type = "flat_dt";
201 arch = "${UBOOT_ARCH}";
202 compression = "none";
Andrew Geisslereff27472021-10-29 15:35:00 -0500203 $dtb_loadline
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600204 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500205 algo = "$dtb_csum";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 };
207 };
208EOF
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600209
Andrew Geisslereff27472021-10-29 15:35:00 -0500210 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$dtb_sign_keyname" ] ; then
211 sed -i '$ d' $1
212 cat << EOF >> $1
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600213 signature-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500214 algo = "$dtb_csum,$dtb_sign_algo";
215 key-name-hint = "$dtb_sign_keyname";
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600216 };
217 };
218EOF
219 fi
220}
221
222#
223# Emit the fitImage ITS u-boot script section
224#
225# $1 ... .its filename
226# $2 ... Image counter
227# $3 ... Path to boot script image
228fitimage_emit_section_boot_script() {
229
Andrew Geisslereff27472021-10-29 15:35:00 -0500230 bootscr_csum="${FIT_HASH_ALG}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600231 bootscr_sign_algo="${FIT_SIGN_ALG}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500232 bootscr_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600233
Andrew Geisslereff27472021-10-29 15:35:00 -0500234 cat << EOF >> $1
235 bootscr-$2 {
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600236 description = "U-boot script";
Andrew Geisslereff27472021-10-29 15:35:00 -0500237 data = /incbin/("$3");
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600238 type = "script";
239 arch = "${UBOOT_ARCH}";
240 compression = "none";
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700241 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500242 algo = "$bootscr_csum";
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600243 };
244 };
245EOF
246
Andrew Geisslereff27472021-10-29 15:35:00 -0500247 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$bootscr_sign_keyname" ] ; then
248 sed -i '$ d' $1
249 cat << EOF >> $1
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700250 signature-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500251 algo = "$bootscr_csum,$bootscr_sign_algo";
252 key-name-hint = "$bootscr_sign_keyname";
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600253 };
254 };
255EOF
256 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257}
258
259#
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600260# Emit the fitImage ITS setup section
261#
262# $1 ... .its filename
263# $2 ... Image counter
264# $3 ... Path to setup image
265fitimage_emit_section_setup() {
266
Brad Bishopf3fd2882019-06-21 08:06:37 -0400267 setup_csum="${FIT_HASH_ALG}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600268
Andrew Geisslereff27472021-10-29 15:35:00 -0500269 cat << EOF >> $1
270 setup-$2 {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600271 description = "Linux setup.bin";
Andrew Geisslereff27472021-10-29 15:35:00 -0500272 data = /incbin/("$3");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600273 type = "x86_setup";
274 arch = "${UBOOT_ARCH}";
275 os = "linux";
276 compression = "none";
277 load = <0x00090000>;
278 entry = <0x00090000>;
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600279 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500280 algo = "$setup_csum";
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600281 };
282 };
283EOF
284}
285
286#
George McCollister185c8ae2016-05-26 08:55:16 -0500287# Emit the fitImage ITS ramdisk section
288#
289# $1 ... .its filename
290# $2 ... Image counter
291# $3 ... Path to ramdisk image
292fitimage_emit_section_ramdisk() {
293
Brad Bishopf3fd2882019-06-21 08:06:37 -0400294 ramdisk_csum="${FIT_HASH_ALG}"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600295 ramdisk_sign_algo="${FIT_SIGN_ALG}"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500296 ramdisk_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}"
Nathan Rossib4a4dc02016-10-21 22:07:27 +1000297 ramdisk_loadline=""
298 ramdisk_entryline=""
299
300 if [ -n "${UBOOT_RD_LOADADDRESS}" ]; then
301 ramdisk_loadline="load = <${UBOOT_RD_LOADADDRESS}>;"
302 fi
303 if [ -n "${UBOOT_RD_ENTRYPOINT}" ]; then
304 ramdisk_entryline="entry = <${UBOOT_RD_ENTRYPOINT}>;"
305 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500306
Andrew Geisslereff27472021-10-29 15:35:00 -0500307 cat << EOF >> $1
308 ramdisk-$2 {
Rick Altherrbc1b8802017-01-20 11:28:53 -0800309 description = "${INITRAMFS_IMAGE}";
Andrew Geisslereff27472021-10-29 15:35:00 -0500310 data = /incbin/("$3");
George McCollister185c8ae2016-05-26 08:55:16 -0500311 type = "ramdisk";
312 arch = "${UBOOT_ARCH}";
313 os = "linux";
Brad Bishop00e122a2019-10-05 11:10:57 -0400314 compression = "none";
Andrew Geisslereff27472021-10-29 15:35:00 -0500315 $ramdisk_loadline
316 $ramdisk_entryline
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600317 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500318 algo = "$ramdisk_csum";
George McCollister185c8ae2016-05-26 08:55:16 -0500319 };
320 };
321EOF
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600322
Andrew Geisslereff27472021-10-29 15:35:00 -0500323 if [ "${UBOOT_SIGN_ENABLE}" = "1" -a "${FIT_SIGN_INDIVIDUAL}" = "1" -a -n "$ramdisk_sign_keyname" ] ; then
324 sed -i '$ d' $1
325 cat << EOF >> $1
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600326 signature-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500327 algo = "$ramdisk_csum,$ramdisk_sign_algo";
328 key-name-hint = "$ramdisk_sign_keyname";
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600329 };
330 };
331EOF
332 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500333}
334
335#
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500336# Emit the fitImage ITS configuration section
337#
George McCollister185c8ae2016-05-26 08:55:16 -0500338# $1 ... .its filename
339# $2 ... Linux kernel ID
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500340# $3 ... DTB image name
George McCollister185c8ae2016-05-26 08:55:16 -0500341# $4 ... ramdisk ID
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600342# $5 ... u-boot script ID
343# $6 ... config ID
344# $7 ... default flag
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345fitimage_emit_section_config() {
346
Brad Bishopf3fd2882019-06-21 08:06:37 -0400347 conf_csum="${FIT_HASH_ALG}"
Brad Bishop64c979e2019-11-04 13:55:29 -0500348 conf_sign_algo="${FIT_SIGN_ALG}"
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700349 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] ; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600350 conf_sign_keyname="${UBOOT_SIGN_KEYNAME}"
351 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500352
Andrew Geisslereff27472021-10-29 15:35:00 -0500353 its_file="$1"
354 kernel_id="$2"
355 dtb_image="$3"
356 ramdisk_id="$4"
357 bootscr_id="$5"
358 config_id="$6"
359 default_flag="$7"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600360
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 # Test if we have any DTBs at all
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800362 sep=""
363 conf_desc=""
Andrew Geissler9aee5002022-03-30 16:27:02 +0000364 conf_node="${FIT_CONF_PREFIX}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800365 kernel_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600366 fdt_line=""
367 ramdisk_line=""
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600368 bootscr_line=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500369 setup_line=""
370 default_line=""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600371
Andrew Geissler635e0e42020-08-21 15:58:33 -0500372 # conf node name is selected based on dtb ID if it is present,
373 # otherwise its selected based on kernel ID
Andrew Geisslereff27472021-10-29 15:35:00 -0500374 if [ -n "$dtb_image" ]; then
375 conf_node=$conf_node$dtb_image
Andrew Geissler635e0e42020-08-21 15:58:33 -0500376 else
Andrew Geisslereff27472021-10-29 15:35:00 -0500377 conf_node=$conf_node$kernel_id
Andrew Geissler635e0e42020-08-21 15:58:33 -0500378 fi
379
Andrew Geisslereff27472021-10-29 15:35:00 -0500380 if [ -n "$kernel_id" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800381 conf_desc="Linux kernel"
382 sep=", "
Andrew Geisslereff27472021-10-29 15:35:00 -0500383 kernel_line="kernel = \"kernel-$kernel_id\";"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800384 fi
385
Andrew Geisslereff27472021-10-29 15:35:00 -0500386 if [ -n "$dtb_image" ]; then
387 conf_desc="$conf_desc${sep}FDT blob"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800388 sep=", "
Andrew Geisslereff27472021-10-29 15:35:00 -0500389 fdt_line="fdt = \"fdt-$dtb_image\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600390 fi
391
Andrew Geisslereff27472021-10-29 15:35:00 -0500392 if [ -n "$ramdisk_id" ]; then
393 conf_desc="$conf_desc${sep}ramdisk"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800394 sep=", "
Andrew Geisslereff27472021-10-29 15:35:00 -0500395 ramdisk_line="ramdisk = \"ramdisk-$ramdisk_id\";"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500396 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600397
Andrew Geisslereff27472021-10-29 15:35:00 -0500398 if [ -n "$bootscr_id" ]; then
399 conf_desc="$conf_desc${sep}u-boot script"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600400 sep=", "
Andrew Geisslereff27472021-10-29 15:35:00 -0500401 bootscr_line="bootscr = \"bootscr-$bootscr_id\";"
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600402 fi
403
Andrew Geisslereff27472021-10-29 15:35:00 -0500404 if [ -n "$config_id" ]; then
405 conf_desc="$conf_desc${sep}setup"
406 setup_line="setup = \"setup-$config_id\";"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600407 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500408
Andrew Geisslereff27472021-10-29 15:35:00 -0500409 if [ "$default_flag" = "1" ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500410 # default node is selected based on dtb ID if it is present,
411 # otherwise its selected based on kernel ID
Andrew Geisslereff27472021-10-29 15:35:00 -0500412 if [ -n "$dtb_image" ]; then
Andrew Geissler9aee5002022-03-30 16:27:02 +0000413 default_line="default = \"${FIT_CONF_PREFIX}$dtb_image\";"
Andrew Geissler635e0e42020-08-21 15:58:33 -0500414 else
Andrew Geissler9aee5002022-03-30 16:27:02 +0000415 default_line="default = \"${FIT_CONF_PREFIX}$kernel_id\";"
Andrew Geissler635e0e42020-08-21 15:58:33 -0500416 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 fi
418
Andrew Geisslereff27472021-10-29 15:35:00 -0500419 cat << EOF >> $its_file
420 $default_line
Andrew Geissler635e0e42020-08-21 15:58:33 -0500421 $conf_node {
Andrew Geisslereff27472021-10-29 15:35:00 -0500422 description = "$default_flag $conf_desc";
423 $kernel_line
424 $fdt_line
425 $ramdisk_line
426 $bootscr_line
427 $setup_line
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600428 hash-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500429 algo = "$conf_csum";
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500430 };
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600431EOF
432
Andrew Geisslereff27472021-10-29 15:35:00 -0500433 if [ -n "$conf_sign_keyname" ] ; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600434
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800435 sign_line="sign-images = "
436 sep=""
437
Andrew Geisslereff27472021-10-29 15:35:00 -0500438 if [ -n "$kernel_id" ]; then
439 sign_line="$sign_line${sep}\"kernel\""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800440 sep=", "
441 fi
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600442
Andrew Geisslereff27472021-10-29 15:35:00 -0500443 if [ -n "$dtb_image" ]; then
444 sign_line="$sign_line${sep}\"fdt\""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800445 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600446 fi
447
Andrew Geisslereff27472021-10-29 15:35:00 -0500448 if [ -n "$ramdisk_id" ]; then
449 sign_line="$sign_line${sep}\"ramdisk\""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800450 sep=", "
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600451 fi
452
Andrew Geisslereff27472021-10-29 15:35:00 -0500453 if [ -n "$bootscr_id" ]; then
454 sign_line="$sign_line${sep}\"bootscr\""
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600455 sep=", "
456 fi
457
Andrew Geisslereff27472021-10-29 15:35:00 -0500458 if [ -n "$config_id" ]; then
459 sign_line="$sign_line${sep}\"setup\""
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600460 fi
461
Andrew Geisslereff27472021-10-29 15:35:00 -0500462 sign_line="$sign_line;"
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600463
Andrew Geisslereff27472021-10-29 15:35:00 -0500464 cat << EOF >> $its_file
Andrew Geissler90fd73c2021-03-05 15:25:55 -0600465 signature-1 {
Andrew Geisslereff27472021-10-29 15:35:00 -0500466 algo = "$conf_csum,$conf_sign_algo";
467 key-name-hint = "$conf_sign_keyname";
468 $sign_line
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600469 };
470EOF
471 fi
472
Andrew Geisslereff27472021-10-29 15:35:00 -0500473 cat << EOF >> $its_file
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500474 };
475EOF
476}
477
George McCollister185c8ae2016-05-26 08:55:16 -0500478#
479# Assemble fitImage
480#
481# $1 ... .its filename
482# $2 ... fitImage name
483# $3 ... include ramdisk
484fitimage_assemble() {
485 kernelcount=1
486 dtbcount=""
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500487 DTBS=""
Andrew Geisslereff27472021-10-29 15:35:00 -0500488 ramdiskcount=$3
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600489 setupcount=""
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600490 bootscr_id=""
Andrew Geisslereff27472021-10-29 15:35:00 -0500491 rm -f $1 arch/${ARCH}/boot/$2
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500492
Andrew Geisslereff27472021-10-29 15:35:00 -0500493 if [ -n "${UBOOT_SIGN_IMG_KEYNAME}" -a "${UBOOT_SIGN_KEYNAME}" = "${UBOOT_SIGN_IMG_KEYNAME}" ]; then
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500494 bbfatal "Keys used to sign images and configuration nodes must be different."
495 fi
496
Andrew Geisslereff27472021-10-29 15:35:00 -0500497 fitimage_emit_fit_header $1
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500498
George McCollister185c8ae2016-05-26 08:55:16 -0500499 #
500 # Step 1: Prepare a kernel image section.
501 #
Andrew Geisslereff27472021-10-29 15:35:00 -0500502 fitimage_emit_section_maint $1 imagestart
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500503
George McCollister185c8ae2016-05-26 08:55:16 -0500504 uboot_prep_kimage
Andrew Geisslereff27472021-10-29 15:35:00 -0500505 fitimage_emit_section_kernel $1 $kernelcount linux.bin "$linux_comp"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500506
George McCollister185c8ae2016-05-26 08:55:16 -0500507 #
508 # Step 2: Prepare a DTB image section
509 #
Brad Bishop19323692019-04-05 15:28:33 -0400510
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500511 if [ -n "${KERNEL_DEVICETREE}" ]; then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500512 dtbcount=1
George McCollister185c8ae2016-05-26 08:55:16 -0500513 for DTB in ${KERNEL_DEVICETREE}; do
Andrew Geisslereff27472021-10-29 15:35:00 -0500514 if echo $DTB | grep -q '/dts/'; then
515 bbwarn "$DTB contains the full path to the the dts file, but only the dtb name should be used."
516 DTB=`basename $DTB | sed 's,\.dts$,.dtb,g'`
George McCollister185c8ae2016-05-26 08:55:16 -0500517 fi
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500518
519 # Skip ${DTB} if it's also provided in ${EXTERNAL_KERNEL_DEVICETREE}
520 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ] && [ -s ${EXTERNAL_KERNEL_DEVICETREE}/${DTB} ]; then
521 continue
522 fi
523
Andrew Geisslereff27472021-10-29 15:35:00 -0500524 DTB_PATH="arch/${ARCH}/boot/dts/$DTB"
525 if [ ! -e "$DTB_PATH" ]; then
526 DTB_PATH="arch/${ARCH}/boot/$DTB"
George McCollister185c8ae2016-05-26 08:55:16 -0500527 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500528
Andrew Geisslereff27472021-10-29 15:35:00 -0500529 DTB=$(echo "$DTB" | tr '/' '_')
530 DTBS="$DTBS $DTB"
531 fitimage_emit_section_dtb $1 $DTB $DTB_PATH
George McCollister185c8ae2016-05-26 08:55:16 -0500532 done
533 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500534
Brad Bishop19323692019-04-05 15:28:33 -0400535 if [ -n "${EXTERNAL_KERNEL_DEVICETREE}" ]; then
536 dtbcount=1
Andrew Geissler82c905d2020-04-13 13:39:40 -0500537 for DTB in $(find "${EXTERNAL_KERNEL_DEVICETREE}" \( -name '*.dtb' -o -name '*.dtbo' \) -printf '%P\n' | sort); do
Andrew Geisslereff27472021-10-29 15:35:00 -0500538 DTB=$(echo "$DTB" | tr '/' '_')
539 DTBS="$DTBS $DTB"
540 fitimage_emit_section_dtb $1 $DTB "${EXTERNAL_KERNEL_DEVICETREE}/$DTB"
Brad Bishop19323692019-04-05 15:28:33 -0400541 done
542 fi
543
George McCollister185c8ae2016-05-26 08:55:16 -0500544 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600545 # Step 3: Prepare a u-boot script section
546 #
547
548 if [ -n "${UBOOT_ENV}" ] && [ -d "${STAGING_DIR_HOST}/boot" ]; then
549 if [ -e "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY}" ]; then
550 cp ${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} ${B}
551 bootscr_id="${UBOOT_ENV_BINARY}"
Andrew Geisslereff27472021-10-29 15:35:00 -0500552 fitimage_emit_section_boot_script $1 "$bootscr_id" ${UBOOT_ENV_BINARY}
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600553 else
554 bbwarn "${STAGING_DIR_HOST}/boot/${UBOOT_ENV_BINARY} not found."
555 fi
556 fi
557
558 #
559 # Step 4: Prepare a setup section. (For x86)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600560 #
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500561 if [ -e arch/${ARCH}/boot/setup.bin ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600562 setupcount=1
Andrew Geisslereff27472021-10-29 15:35:00 -0500563 fitimage_emit_section_setup $1 $setupcount arch/${ARCH}/boot/setup.bin
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600564 fi
565
566 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600567 # Step 5: Prepare a ramdisk section.
George McCollister185c8ae2016-05-26 08:55:16 -0500568 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600569 if [ "x${ramdiskcount}" = "x1" ] && [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
Rick Altherrbc1b8802017-01-20 11:28:53 -0800570 # Find and use the first initramfs image archive type we find
Andrew Geissler9aee5002022-03-30 16:27:02 +0000571 found=
572 for img in ${FIT_SUPPORTED_INITRAMFS_FSTYPES}; do
Andrew Geisslereff27472021-10-29 15:35:00 -0500573 initramfs_path="${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img"
Andrew Geisslereff27472021-10-29 15:35:00 -0500574 if [ -e "$initramfs_path" ]; then
Andrew Geissler9aee5002022-03-30 16:27:02 +0000575 bbnote "Found initramfs image: $initramfs_path"
576 found=true
Andrew Geisslereff27472021-10-29 15:35:00 -0500577 fitimage_emit_section_ramdisk $1 "$ramdiskcount" "$initramfs_path"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800578 break
Andrew Geisslereff27472021-10-29 15:35:00 -0500579 else
Andrew Geissler9aee5002022-03-30 16:27:02 +0000580 bbnote "Did not find initramfs image: $initramfs_path"
Rick Altherrbc1b8802017-01-20 11:28:53 -0800581 fi
582 done
Andrew Geissler9aee5002022-03-30 16:27:02 +0000583
584 if [ -z "$found" ]; then
585 bbfatal "Could not find a valid initramfs type for ${INITRAMFS_IMAGE_NAME}, the supported types are: ${FIT_SUPPORTED_INITRAMFS_FSTYPES}"
586 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500587 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500588
Andrew Geisslereff27472021-10-29 15:35:00 -0500589 fitimage_emit_section_maint $1 sectend
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500590
George McCollister185c8ae2016-05-26 08:55:16 -0500591 # Force the first Kernel and DTB in the default config
592 kernelcount=1
Andrew Geisslereff27472021-10-29 15:35:00 -0500593 if [ -n "$dtbcount" ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600594 dtbcount=1
595 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500596
George McCollister185c8ae2016-05-26 08:55:16 -0500597 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600598 # Step 6: Prepare a configurations section
George McCollister185c8ae2016-05-26 08:55:16 -0500599 #
Andrew Geisslereff27472021-10-29 15:35:00 -0500600 fitimage_emit_section_maint $1 confstart
George McCollister185c8ae2016-05-26 08:55:16 -0500601
Andrew Geissler635e0e42020-08-21 15:58:33 -0500602 # kernel-fitimage.bbclass currently only supports a single kernel (no less or
603 # more) to be added to the FIT image along with 0 or more device trees and
604 # 0 or 1 ramdisk.
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600605 # It is also possible to include an initramfs bundle (kernel and rootfs in one binary)
606 # When the initramfs bundle is used ramdisk is disabled.
Andrew Geissler635e0e42020-08-21 15:58:33 -0500607 # If a device tree is to be part of the FIT image, then select
608 # the default configuration to be used is based on the dtbcount. If there is
609 # no dtb present than select the default configuation to be based on
610 # the kernelcount.
Andrew Geisslereff27472021-10-29 15:35:00 -0500611 if [ -n "$DTBS" ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500612 i=1
613 for DTB in ${DTBS}; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800614 dtb_ext=${DTB##*.}
Andrew Geisslereff27472021-10-29 15:35:00 -0500615 if [ "$dtb_ext" = "dtbo" ]; then
616 fitimage_emit_section_config $1 "" "$DTB" "" "$bootscr_id" "" "`expr $i = $dtbcount`"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800617 else
Andrew Geisslereff27472021-10-29 15:35:00 -0500618 fitimage_emit_section_config $1 $kernelcount "$DTB" "$ramdiskcount" "$bootscr_id" "$setupcount" "`expr $i = $dtbcount`"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800619 fi
Andrew Geisslereff27472021-10-29 15:35:00 -0500620 i=`expr $i + 1`
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500621 done
Andrew Geissler635e0e42020-08-21 15:58:33 -0500622 else
623 defaultconfigcount=1
Andrew Geisslereff27472021-10-29 15:35:00 -0500624 fitimage_emit_section_config $1 $kernelcount "" "$ramdiskcount" "$bootscr_id" "$setupcount" $defaultconfigcount
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500625 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500626
Andrew Geisslereff27472021-10-29 15:35:00 -0500627 fitimage_emit_section_maint $1 sectend
George McCollister185c8ae2016-05-26 08:55:16 -0500628
Andrew Geisslereff27472021-10-29 15:35:00 -0500629 fitimage_emit_section_maint $1 fitend
George McCollister185c8ae2016-05-26 08:55:16 -0500630
631 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600632 # Step 7: Assemble the image
George McCollister185c8ae2016-05-26 08:55:16 -0500633 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600634 ${UBOOT_MKIMAGE} \
George McCollister185c8ae2016-05-26 08:55:16 -0500635 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
Andrew Geisslereff27472021-10-29 15:35:00 -0500636 -f $1 \
637 arch/${ARCH}/boot/$2
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600638
639 #
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600640 # Step 8: Sign the image and add public key to U-Boot dtb
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600641 #
642 if [ "x${UBOOT_SIGN_ENABLE}" = "x1" ] ; then
Brad Bishop19323692019-04-05 15:28:33 -0400643 add_key_to_u_boot=""
644 if [ -n "${UBOOT_DTB_BINARY}" ]; then
645 # The u-boot.dtb is a symlink to UBOOT_DTB_IMAGE, so we need copy
646 # both of them, and don't dereference the symlink.
647 cp -P ${STAGING_DATADIR}/u-boot*.dtb ${B}
648 add_key_to_u_boot="-K ${B}/${UBOOT_DTB_BINARY}"
649 fi
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600650 ${UBOOT_MKIMAGE_SIGN} \
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600651 ${@'-D "${UBOOT_MKIMAGE_DTCOPTS}"' if len('${UBOOT_MKIMAGE_DTCOPTS}') else ''} \
652 -F -k "${UBOOT_SIGN_KEYDIR}" \
Brad Bishop19323692019-04-05 15:28:33 -0400653 $add_key_to_u_boot \
Andrew Geisslereff27472021-10-29 15:35:00 -0500654 -r arch/${ARCH}/boot/$2 \
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600655 ${UBOOT_MKIMAGE_SIGN_ARGS}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600656 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500657}
658
659do_assemble_fitimage() {
660 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
661 cd ${B}
Andrew Geisslereff27472021-10-29 15:35:00 -0500662 fitimage_assemble fit-image.its fitImage ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500663 fi
664}
665
666addtask assemble_fitimage before do_install after do_compile
667
George McCollister185c8ae2016-05-26 08:55:16 -0500668do_assemble_fitimage_initramfs() {
669 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
670 test -n "${INITRAMFS_IMAGE}" ; then
671 cd ${B}
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600672 if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then
673 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage ""
674 else
675 fitimage_assemble fit-image-${INITRAMFS_IMAGE}.its fitImage-${INITRAMFS_IMAGE} 1
676 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500677 fi
678}
679
Brad Bishop19323692019-04-05 15:28:33 -0400680addtask assemble_fitimage_initramfs before do_deploy after do_bundle_initramfs
George McCollister185c8ae2016-05-26 08:55:16 -0500681
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700682do_kernel_generate_rsa_keys() {
683 if [ "${UBOOT_SIGN_ENABLE}" = "0" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
684 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."
685 fi
686
687 if [ "${UBOOT_SIGN_ENABLE}" = "1" ] && [ "${FIT_GENERATE_KEYS}" = "1" ]; then
688
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500689 # Generate keys to sign configuration nodes, only if they don't already exist
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700690 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key ] || \
691 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt ]; then
692
693 # make directory if it does not already exist
694 mkdir -p "${UBOOT_SIGN_KEYDIR}"
695
Andrew Geissler9aee5002022-03-30 16:27:02 +0000696 bbnote "Generating RSA private key for signing fitImage"
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700697 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
698 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
699 "${FIT_SIGN_NUMBITS}"
700
Andrew Geissler9aee5002022-03-30 16:27:02 +0000701 bbnote "Generating certificate for signing fitImage"
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700702 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
703 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".key \
704 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_KEYNAME}".crt
705 fi
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500706
707 # Generate keys to sign image nodes, only if they don't already exist
708 if [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key ] || \
709 [ ! -f "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".crt ]; then
710
711 # make directory if it does not already exist
712 mkdir -p "${UBOOT_SIGN_KEYDIR}"
713
Andrew Geissler9aee5002022-03-30 16:27:02 +0000714 bbnote "Generating RSA private key for signing fitImage"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500715 openssl genrsa ${FIT_KEY_GENRSA_ARGS} -out \
716 "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key \
717 "${FIT_SIGN_NUMBITS}"
718
Andrew Geissler9aee5002022-03-30 16:27:02 +0000719 bbnote "Generating certificate for signing fitImage"
Patrick Williams0ca19cc2021-08-16 14:03:13 -0500720 openssl req ${FIT_KEY_REQ_ARGS} "${FIT_KEY_SIGN_PKCS}" \
721 -key "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".key \
722 -out "${UBOOT_SIGN_KEYDIR}/${UBOOT_SIGN_IMG_KEYNAME}".crt
723 fi
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700724 fi
725}
726
727addtask kernel_generate_rsa_keys before do_assemble_fitimage after do_compile
George McCollister185c8ae2016-05-26 08:55:16 -0500728
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500729kernel_do_deploy[vardepsexclude] = "DATETIME"
Patrick Williams213cb262021-08-07 19:21:33 -0500730kernel_do_deploy:append() {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500731 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400732 if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800733
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600734 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
Andrew Geissler9aee5002022-03-30 16:27:02 +0000735 bbnote "Copying fit-image.its source file..."
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600736 install -m 0644 ${B}/fit-image.its "$deployDir/fitImage-its-${KERNEL_FIT_NAME}.its"
Andrew Geissler595f6302022-01-24 19:11:47 +0000737 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
738 ln -snf fitImage-its-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${KERNEL_FIT_LINK_NAME}"
739 fi
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600740
Andrew Geissler9aee5002022-03-30 16:27:02 +0000741 bbnote "Copying linux.bin file..."
Andrew Geissler595f6302022-01-24 19:11:47 +0000742 install -m 0644 ${B}/linux.bin $deployDir/fitImage-linux.bin-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT}
743 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
744 ln -snf fitImage-linux.bin-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT} "$deployDir/fitImage-linux.bin-${KERNEL_FIT_LINK_NAME}"
745 fi
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600746 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500747
George McCollister185c8ae2016-05-26 08:55:16 -0500748 if [ -n "${INITRAMFS_IMAGE}" ]; then
Andrew Geissler9aee5002022-03-30 16:27:02 +0000749 bbnote "Copying fit-image-${INITRAMFS_IMAGE}.its source file..."
Brad Bishop64c979e2019-11-04 13:55:29 -0500750 install -m 0644 ${B}/fit-image-${INITRAMFS_IMAGE}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its"
Andrew Geissler595f6302022-01-24 19:11:47 +0000751 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
752 ln -snf fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}.its "$deployDir/fitImage-its-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
753 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500754
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600755 if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
Andrew Geissler9aee5002022-03-30 16:27:02 +0000756 bbnote "Copying fitImage-${INITRAMFS_IMAGE} file..."
Andrew Geissler595f6302022-01-24 19:11:47 +0000757 install -m 0644 ${B}/arch/${ARCH}/boot/fitImage-${INITRAMFS_IMAGE} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT}"
758 if [ -n "${KERNEL_FIT_LINK_NAME}" ] ; then
759 ln -snf fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_NAME}${KERNEL_FIT_BIN_EXT} "$deployDir/fitImage-${INITRAMFS_IMAGE_NAME}-${KERNEL_FIT_LINK_NAME}"
760 fi
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600761 fi
George McCollister185c8ae2016-05-26 08:55:16 -0500762 fi
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500763 fi
764 if [ "${UBOOT_SIGN_ENABLE}" = "1" -o "${UBOOT_FITIMAGE_ENABLE}" = "1" ] && \
765 [ -n "${UBOOT_DTB_BINARY}" ] ; then
766 # UBOOT_DTB_IMAGE is a realfile, but we can't use
767 # ${UBOOT_DTB_IMAGE} since it contains ${PV} which is aimed
768 # for u-boot, but we are in kernel env now.
769 install -m 0644 ${B}/u-boot-${MACHINE}*.dtb "$deployDir/"
770 fi
771 if [ "${UBOOT_FITIMAGE_ENABLE}" = "1" -a -n "${UBOOT_BINARY}" -a -n "${SPL_DTB_BINARY}" ] ; then
772 # If we're also creating and/or signing the uboot fit, now we need to
773 # deploy it, it's its file, as well as u-boot-spl.dtb
774 install -m 0644 ${B}/u-boot-spl-${MACHINE}*.dtb "$deployDir/"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000775 bbnote "Copying u-boot-fitImage file..."
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500776 install -m 0644 ${B}/u-boot-fitImage-* "$deployDir/"
Andrew Geissler9aee5002022-03-30 16:27:02 +0000777 bbnote "Copying u-boot-its file..."
Andrew Geissler3b8a17c2021-04-15 15:55:55 -0500778 install -m 0644 ${B}/u-boot-its-* "$deployDir/"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500779 fi
780}
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600781
782# The function below performs the following in case of initramfs bundles:
783# - Removes do_assemble_fitimage. FIT generation is done through
784# do_assemble_fitimage_initramfs. do_assemble_fitimage is not needed
785# and should not be part of the tasks to be executed.
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700786# - Since do_kernel_generate_rsa_keys is inserted by default
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600787# between do_compile and do_assemble_fitimage, this is
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700788# not suitable in case of initramfs bundles. do_kernel_generate_rsa_keys
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600789# should be between do_bundle_initramfs and do_assemble_fitimage_initramfs.
790python () {
791 if d.getVar('INITRAMFS_IMAGE_BUNDLE') == "1":
792 bb.build.deltask('do_assemble_fitimage', d)
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700793 bb.build.deltask('kernel_generate_rsa_keys', d)
794 bb.build.addtask('kernel_generate_rsa_keys', 'do_assemble_fitimage_initramfs', 'do_bundle_initramfs', d)
Andrew Geissler95ac1b82021-03-31 14:34:31 -0500795}