images_types: isolate the write of UBI configuration

Message ID 20220520083528.194295-1-kory.maincent@bootlin.com
State Accepted, archived
Commit 601294b35c83faa134e26844c65db59b42d5052f
Headers show
Series images_types: isolate the write of UBI configuration | expand

Commit Message

Köry Maincent May 20, 2022, 8:35 a.m. UTC
From: Kory Maincent <kory.maincent@bootlin.com>

Isolate the writing of the UBI configuration in a separate function.
This allows to use a custom configuration easily by overriding the
function.

Replace the echo functions by a cat to have a more readable configuration.

Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 meta/classes/image_types.bbclass | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

Patch

diff --git a/meta/classes/image_types.bbclass b/meta/classes/image_types.bbclass
index 89a9c92db7..0ffea91195 100644
--- a/meta/classes/image_types.bbclass
+++ b/meta/classes/image_types.bbclass
@@ -142,6 +142,24 @@  UBI_VOLNAME ?= "${MACHINE}-rootfs"
 UBI_VOLTYPE ?= "dynamic"
 UBI_IMGTYPE ?= "ubifs"
 
+write_ubi_config() {
+	if [ -z "$1" ]; then
+		local vname=""
+	else
+		local vname="_$1"
+	fi
+
+	cat <<EOF > ubinize${vname}-${IMAGE_NAME}.cfg
+[ubifs]
+mode=ubi
+image=${IMGDEPLOYDIR}/${IMAGE_NAME}${vname}${IMAGE_NAME_SUFFIX}.${UBI_IMGTYPE}
+vol_id=0
+vol_type=${UBI_VOLTYPE}
+vol_name=${UBI_VOLNAME}
+vol_flags=autoresize
+EOF
+}
+
 multiubi_mkfs() {
 	local mkubifs_args="$1"
 	local ubinize_args="$2"
@@ -151,19 +169,8 @@  multiubi_mkfs() {
             bbfatal "MKUBIFS_ARGS and UBINIZE_ARGS have to be set, see http://www.linux-mtd.infradead.org/faq/ubifs.html for details"
         fi
 
-	if [ -z "$3" ]; then
-		local vname=""
-	else
-		local vname="_$3"
-	fi
+	write_ubi_config "$3"
 
-	echo \[ubifs\] > ubinize${vname}-${IMAGE_NAME}.cfg
-	echo mode=ubi >> ubinize${vname}-${IMAGE_NAME}.cfg
-	echo image=${IMGDEPLOYDIR}/${IMAGE_NAME}${vname}${IMAGE_NAME_SUFFIX}.${UBI_IMGTYPE} >> ubinize${vname}-${IMAGE_NAME}.cfg
-	echo vol_id=0 >> ubinize${vname}-${IMAGE_NAME}.cfg
-	echo vol_type=${UBI_VOLTYPE} >> ubinize${vname}-${IMAGE_NAME}.cfg
-	echo vol_name=${UBI_VOLNAME} >> ubinize${vname}-${IMAGE_NAME}.cfg
-	echo vol_flags=autoresize >> ubinize${vname}-${IMAGE_NAME}.cfg
 	if [ -n "$vname" ]; then
 		mkfs.ubifs -r ${IMAGE_ROOTFS} -o ${IMGDEPLOYDIR}/${IMAGE_NAME}${vname}${IMAGE_NAME_SUFFIX}.ubifs ${mkubifs_args}
 	fi