diff mbox series

[10/14] kernel-fitimage: refactor creation of linux.bin

Message ID 20240704071013.2982700-11-adrian.freihofer@gmail.com
State New
Headers show
Series Use the kernel from sstate when building fitImages | expand

Commit Message

Adrian Freihofer July 4, 2024, 7:09 a.m. UTC
From: Adrian Freihofer <adrian.freihofer@siemens.com>

Assembling the fitImage with initramfs requires the linux.bin and the
corresponding DTB files. To avoid that the kernel gets re-built from
scratch whenever the initramfs changes, these files must be sstate
cached after the kernel is built, before the fitImage gets assembled.

Therefore the uboot_prep_kimage needs to be split:
- a function creating the linux.bin artifact
- a function which can find the linux.bin file from an independent task
  later on.

This will allow to run the do_assemble_fitimage_initramfs task from the
deploy folder where the linux.bin and the DTBs are provided via
sstate-cache.

Signed-off-by: Adrian Freihofer <adrian.freihofer@siemens.com>
---
 meta/classes-recipe/kernel-fitimage.bbclass |  8 ++++----
 meta/classes-recipe/kernel-uboot.bbclass    | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/meta/classes-recipe/kernel-fitimage.bbclass b/meta/classes-recipe/kernel-fitimage.bbclass
index e084dc57573..64836f6bef0 100644
--- a/meta/classes-recipe/kernel-fitimage.bbclass
+++ b/meta/classes-recipe/kernel-fitimage.bbclass
@@ -165,12 +165,12 @@  EOF
 # $1 ... .its filename
 # $2 ... Image counter
 # $3 ... Path to kernel image
-# $4 ... Compression type
 fitimage_emit_section_kernel() {
 
 	kernel_csum="${FIT_HASH_ALG}"
 	kernel_sign_algo="${FIT_SIGN_ALG}"
 	kernel_sign_keyname="${UBOOT_SIGN_IMG_KEYNAME}"
+	get_linux_comp
 
 	ENTRYPOINT="${UBOOT_ENTRYPOINT}"
 	if [ -n "${UBOOT_ENTRYSYMBOL}" ]; then
@@ -186,7 +186,7 @@  fitimage_emit_section_kernel() {
                         type = "${UBOOT_MKIMAGE_KERNEL_TYPE}";
                         arch = "${UBOOT_ARCH}";
                         os = "linux";
-                        compression = "$4";
+                        compression = "$linux_comp";
                         load = <${UBOOT_LOADADDRESS}>;
                         entry = <$ENTRYPOINT>;
                         hash-1 {
@@ -585,8 +585,6 @@  fitimage_assemble() {
 	# Step 1: Prepare a kernel image section.
 	#
 	fitimage_emit_section_maint $1 imagestart
-
-	uboot_prep_kimage
 	fitimage_emit_section_kernel $1 $kernelcount "$(readlink -f linux.bin)" "$linux_comp"
 
 	#
@@ -785,6 +783,7 @@  fitimage_assemble() {
 do_assemble_fitimage() {
 	if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage"; then
 		cd ${B}
+		uboot_prep_kimage
 		fitimage_assemble fit-image.its "${KERNEL_OUTPUT_DIR}/fitImage-none" ""
 		if [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ]; then
 			ln -sf fitImage-none "${B}/${KERNEL_OUTPUT_DIR}/fitImage"
@@ -806,6 +805,7 @@  do_assemble_fitimage_initramfs() {
 	if echo ${KERNEL_IMAGETYPES} | grep -wq "fitImage" && \
 		test -n "${INITRAMFS_IMAGE}" ; then
 		cd ${B}
+		uboot_prep_kimage
 		if [ "${INITRAMFS_IMAGE_BUNDLE}" = "1" ]; then
 			fitimage_assemble "fit-image-${INITRAMFS_IMAGE}.its" "${KERNEL_OUTPUT_DIR}/fitImage-bundle" ""
 			ln -sf fitImage-bundle "${B}/${KERNEL_OUTPUT_DIR}/fitImage"
diff --git a/meta/classes-recipe/kernel-uboot.bbclass b/meta/classes-recipe/kernel-uboot.bbclass
index 30a85ccc287..e692ca27cdd 100644
--- a/meta/classes-recipe/kernel-uboot.bbclass
+++ b/meta/classes-recipe/kernel-uboot.bbclass
@@ -47,3 +47,20 @@  uboot_prep_kimage() {
 
 	echo "${linux_comp}"
 }
+
+# Get the linux_comp variable back from the linux.bin file
+# which was created by uboot_prep_kimage
+get_linux_comp() {
+	if [ ! -e linux.bin ]; then
+	    bbfatal "linux.bin does not exist $(pwd)"
+	fi
+
+	linux_comp=none
+	if gzip -l linux.bin> /dev/null 2>&1; then
+		linux_comp=gzip
+	elif lzop -l linux.bin> /dev/null 2>&1; then
+		linux_comp=lzo
+	fi
+
+	echo "${linux_comp}"
+}