Skip to contentSkip to conversation

kernel-fitimage: dtb sections named by their filenames and one config section for each dtb

PATCH In review Florian Wickert 2 participants 2 messages Mar 17, 2017 – Mar 12, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-fitimage: dtb sections named by their filenames and one config section for each dtb

Before this, dtb sections were named by their position index in KERNEL_DEVICETREE. Also there was only one item in the config section, so only the first dtb was seen by the bootloader. This patch adds a config section for each dtb named by the dtb filename. This is what bootloaders usually know about the machine they run on.

---
 meta/classes/kernel-fitimage.bbclass | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
meta/classes/kernel-fitimage.bbclass +21 -7
index 1c3b4b7..9c998cc 100644
@@ -229,9 +229,10 @@ EOF
 #
 # $1 ... .its filename
 # $2 ... Linux kernel ID
-# $3 ... DTB image ID
+# $3 ... DTB image name
 # $4 ... ramdisk ID
 # $5 ... config ID
+# $6 ... default flag
 fitimage_emit_section_config() {
 
 	conf_csum="sha1"
@@ -244,6 +245,8 @@ fitimage_emit_section_config() {
 	kernel_line="kernel = \"kernel@${2}\";"
 	fdt_line=""
 	ramdisk_line=""
+	setup_line=""
+	default_line=""
 
 	if [ -n "${3}" ]; then
 		conf_desc="${conf_desc}, FDT blob"
@@ -260,10 +263,14 @@ fitimage_emit_section_config() {
 		setup_line="setup = \"setup@${5}\";"
 	fi
 
+	if [ "${6}" = "1" ]; then
+		default_line="default = \"conf@${3}\";"
+	fi
+
 	cat << EOF >> ${1}
-                default = "conf@1";
-                conf@1 {
-                        description = "${conf_desc}";
+                ${default_line}
+                conf@${3} {
+			description = "${6} ${conf_desc}";
 			${kernel_line}
 			${fdt_line}
 			${ramdisk_line}
@@ -314,6 +321,7 @@ EOF
 fitimage_assemble() {
 	kernelcount=1
 	dtbcount=""
+	DTBS=""
 	ramdiskcount=${3}
 	setupcount=""
 	rm -f ${1} arch/${ARCH}/boot/${2}
@@ -343,8 +351,8 @@ fitimage_assemble() {
 				DTB_PATH="arch/${ARCH}/boot/${DTB}"
 			fi
 
-			fitimage_emit_section_dtb ${1} ${dtbcount} ${DTB_PATH}
-			dtbcount=`expr ${dtbcount} + 1`
+			DTBS="${DTBS} ${DTB}"
+			fitimage_emit_section_dtb ${1} ${DTB} ${DTB_PATH}
 		done
 	fi
 
@@ -384,7 +392,13 @@ fitimage_assemble() {
 	#
 	fitimage_emit_section_maint ${1} confstart
 
-	fitimage_emit_section_config ${1} "${kernelcount}" "${dtbcount}" "${ramdiskcount}" "${setupcount}"
+	if test -n "${DTBS}"; then
+		i=1
+		for DTB in ${DTBS}; do
+			fitimage_emit_section_config ${1} "${kernelcount}" "${DTB}" "${ramdiskcount}" "${setupcount}" "`expr ${i} = ${dtbcount}`"
+			i=`expr ${i} + 1`
+		done
+	fi
 
 	fitimage_emit_section_maint ${1} sectend
 
Signature · 1 line
2.1.4
#1 lore raw

I added some .dtso overlay files to KERNEL_DEVICETREE in order to have them added to my fitimage file through the kernel-fitimage.class.

This seems to work, as long as corresponding .dtso files are added to the right subdir with SRC_URI in the linux kernel recipe. The dtbo becomes included in the fitimage. config sections are emitted.

However, the config sections in the fitimage become weird. One config section is emitted for each dtb or dtbo file. Does this make sense? Shouldn't there be one config section for each .dtb file, and then dtbo references be added to these sections? The most simple alternative would be to add every .dtbo file in KERNEL_DEVICETREE to ever .dtb config section, but probably there should be some way to select which overlays to add to each dtb.

It currently looks like this:

```
        configurations {
                default = "conf-rk3588s-rock-5a.dtb";
                conf-rk3588s-rock-5a.dtb {
                        description = "1 Linux kernel, FDT blob";
                        
                        kernel = "kernel-1";
                        fdt = "fdt-rk3588s-rock-5a.dtb";
                        
                        
                        
                        hash-1 {
                                algo = "sha256";
                        };
                };
                
                conf-rock-5a-radxa-camera-4k.dtbo {
                        description = "0 FDT blob";
                        
                        
                        fdt = "fdt-rock-5a-radxa-camera-4k.dtbo";
                        
                        
                        
                        hash-1 {
                                algo = "sha256";
                        };
                };
        };
```
but I would have expected it to look like this:
```
        configurations {
                default = "conf-rk3588s-rock-5a.dtb";
                conf-rk3588s-rock-5a.dtb {
                        description = "1 Linux kernel, FDT blob";
                        
                        kernel = "kernel-1";
                        fdt = "fdt-rk3588s-rock-5a.dtb", "fdt-rock-5a-radxa-camera-4k.dtbo";;
                        
                        
                        
                        hash-1 {
                                algo = "sha256";
                        };
                };
        };
```

As in this example from u-boot/doc/uImage.FIT/overlay-fdt-boot.txt:

```
	/dts-v1/;
	/ {
		images {
			kernel {
				data = /incbin/("./zImage");
				type = "kernel";
				arch = "arm";
				os = "linux";
				load = <0x82000000>;
				entry = <0x82000000>;
			};
			fdt-1 {
				data = /incbin/("./foo.dtb");
				type = "flat_dt";
				arch = "arm";
				load = <0x87f00000>;
			};
			fdt-2 {
				data = /incbin/("./reva.dtbo");
				type = "flat_dt";
				arch = "arm";
				load = <0x87fc0000>;
			};
			fdt-3 {
				data = /incbin/("./revb.dtbo");
				type = "flat_dt";
				arch = "arm";
				load = <0x87fc0000>;
			};
			fdt-4 {
				data = /incbin/("./bar.dtbo");
				type = "flat_dt";
				arch = "arm";
				load = <0x87fc0000>;
			};
			fdt-5 {
				data = /incbin/("./baz.dtbo");
				type = "flat_dt";
				arch = "arm";
				load = <0x87fc0000>;
			};
		};

		configurations {
			default = "foo-reva.dtb;
			foo-reva.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-2";
			};
			foo-revb.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-3";
			};
			foo-reva-bar.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-2", "fdt-4";
			};
			foo-revb-bar.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-3", "fdt-4";
			};
			foo-revb-baz.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-3", "fdt-5";
			};
			foo-revb-bar-baz.dtb {
				kernel = "kernel";
				fdt = "fdt-1", "fdt-3", "fdt-4", "fdt-5";
			};
			bar {
				fdt = "fdt-4";
			};
			baz {
				fdt = "fdt-5";
			};
		};
	};
```