]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
kernel-fitimage: skip FDT section creation for applicable symlinks
authorAhmad Fatoum <a.fatoum@pengutronix.de>
Wed, 26 Oct 2022 13:22:19 +0000 (15:22 +0200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 28 Oct 2022 08:44:48 +0000 (09:44 +0100)
When building a FIT image with device trees, each device tree lands in a
FIT section and is referenced by a FIT configuration node.

FIT images however also allow referencing the same device tree from
multiple configurations. This can be useful to reduce FIT image size
while staying compatible with existing bootloaders. Allow
kernel-fitimage.bbclass users to take advantage of this by mapping
each symlink to a regular device tree included in the FIT to a
configuration that references a common device tree section.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/classes-recipe/kernel-fitimage.bbclass

index 6307e3c50a3f230f9e8a3152316f5570d57acafb..7980910aa8c4d103a0a20a1a66931b96c283bc2d 100644 (file)
@@ -354,6 +354,27 @@ EOF
        fi
 }
 
+#
+# echoes symlink destination if it points below directory
+#
+# $1 ... file that's a potential symlink
+# $2 ... expected parent directory
+symlink_points_below() {
+       file="$2/$1"
+       dir=$2
+
+       if ! [ -L "$file" ]; then
+               return
+       fi
+
+       realpath="$(realpath --relative-to=$dir $file)"
+       if [ -z "${realpath%%../*}" ]; then
+               return
+       fi
+
+       echo "$realpath"
+}
+
 #
 # Emit the fitImage ITS configuration section
 #
@@ -392,7 +413,13 @@ fitimage_emit_section_config() {
        setup_line=""
        default_line=""
 
+       dtb_image_sect=$(symlink_points_below $dtb_image "${EXTERNAL_KERNEL_DEVICETREE}")
+       if [ -z "$dtb_image_sect" ]; then
+               dtb_image_sect=$dtb_image
+       fi
+
        dtb_image=$(echo $dtb_image | tr '/' '_')
+       dtb_image_sect=$(echo "${dtb_image_sect}" | tr '/' '_')
 
        # conf node name is selected based on dtb ID if it is present,
        # otherwise its selected based on kernel ID
@@ -411,7 +438,7 @@ fitimage_emit_section_config() {
        if [ -n "$dtb_image" ]; then
                conf_desc="$conf_desc${sep}FDT blob"
                sep=", "
-               fdt_line="fdt = \"fdt-$dtb_image\";"
+               fdt_line="fdt = \"fdt-$dtb_image_sect\";"
        fi
 
        if [ -n "$ramdisk_id" ]; then
@@ -568,6 +595,10 @@ fitimage_assemble() {
                        echo "$DTBS" | tr ' ' '\n' | grep -xq "$DTB" && continue
 
                        DTBS="$DTBS $DTB"
+
+                       # Also skip if a symlink. We'll later have each config section point at it
+                       [ $(symlink_points_below $DTB "${EXTERNAL_KERNEL_DEVICETREE}") ] && continue
+
                        DTB=$(echo $DTB | tr '/' '_')
                        fitimage_emit_section_dtb $1 $DTB "${EXTERNAL_KERNEL_DEVICETREE}/$DTB"
                done