public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: claudius.heine.ext@siemens.com
To: isar-users@googlegroups.com
Cc: Claudius Heine <ch@denx.de>
Subject: [RFC PATCH 1/2] meta/classes: added ubi-img class
Date: Tue, 29 Jan 2019 13:10:19 +0100	[thread overview]
Message-ID: <20190129121020.30845-2-claudius.heine.ext@siemens.com> (raw)
In-Reply-To: <20190129121020.30845-1-claudius.heine.ext@siemens.com>

From: Claudius Heine <ch@denx.de>

This class implements a new image type for UBI formatted nand flashes.

It allows custom ubinize configuration file templates to be placed into
the SRC_URI of the image recipe and has mechanims to replace variables
within those. It does this by using `envsubst` from the gettext project.

The interface for custom template variables is implemented via the
`UBINIZE_CFG_TMPL_VARS` bitbake variable. The value of this variable is
an array of template variable names. Each template variable name
corresponds to a flag of the `UBINIZE_CFG_TMPL_VARS` variable, with
which the value can be set.

Signed-off-by: Claudius Heine <ch@denx.de>
---
 meta/classes/ubi-img.bbclass | 71 ++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)
 create mode 100644 meta/classes/ubi-img.bbclass

diff --git a/meta/classes/ubi-img.bbclass b/meta/classes/ubi-img.bbclass
new file mode 100644
index 0000000..58059e3
--- /dev/null
+++ b/meta/classes/ubi-img.bbclass
@@ -0,0 +1,71 @@
+# This software is a part of ISAR.
+# Copyright (c) Siemens AG, 2018
+
+python() {
+    if not d.getVar("UBINIZE_ARGS"):
+        bb.fatal("UBINIZE_ARGS must be set")
+}
+
+UBINIZE_CFG_TMPL ??= "ubinize.cfg.tmpl"
+UBINIZE_CFG_TMPL_VARS ??= ""
+UBINIZE_CFG ??= "ubinize.cfg"
+
+inherit image
+
+UBI_IMAGE_FILE ?= "${IMAGE_FULLNAME}.ubi.img"
+
+IMAGER_INSTALL += "mtd-utils"
+
+PP = "/home/builder/${PN}"
+PP_DEPLOY = "${PP}/deploy"
+PP_ROOTFS = "${PP}/rootfs"
+PP_WORK = "${PP}/work"
+
+BUILDROOT = "${BUILDCHROOT_DIR}${PP}"
+BUILDROOT_DEPLOY = "${BUILDCHROOT_DIR}${PP_DEPLOY}"
+BUILDROOT_ROOTFS = "${BUILDCHROOT_DIR}${PP_ROOTFS}"
+BUILDROOT_WORK = "${BUILDCHROOT_DIR}${PP_WORK}"
+
+do_ubi_image[stamp-extra-info] = "${DISTRO}-${MACHINE}"
+
+def get_ubi_exports(d):
+    template_vars = (d.getVar("UBINIZE_CFG_TMPL_VARS", True) or "").split()
+    template_vars_flags = (d.getVarFlags("UBINIZE_CFG_TMPL_VARS") or {})
+    return " ".join("{}=\"{}\"".format(name, template_vars_flags[name])
+                    for name in template_vars)
+
+def get_envsubst_args(d):
+    template_vars = (d.getVar("UBINIZE_CFG_TMPL_VARS", True) or "").split()
+    return " ".join("\\${{{}}}".format(name)
+                    for name in template_vars)
+
+# Generate ubi filesystem image
+do_ubi_image() {
+    if [ ! -e "${WORKDIR}/${UBINIZE_CFG_TMPL}" -a \
+         ! -e "${WORKDIR}/${UBINIZE_CFG}" ]; then
+        die "Neigher UBINIZE_CFG_TMPL nor UBINIZE_CFG contain existing" \
+            "ubinize configuration file"
+    fi
+
+    rm -f ${DEPLOY_DIR_IMAGE}/${UBI_IMAGE_FILE}
+
+    buildchroot_do_mounts
+
+    sudo flock ${MOUNT_LOCKFILE} -c ' \
+        mkdir -p ${BUILDROOT_DEPLOY} ${BUILDROOT_ROOTFS} ${BUILDROOT_WORK}
+        mount --bind ${DEPLOY_DIR_IMAGE} ${BUILDROOT_DEPLOY}
+        mount --bind ${IMAGE_ROOTFS} ${BUILDROOT_ROOTFS}
+        mount --bind ${WORKDIR} ${BUILDROOT_WORK}
+    '
+
+    if [ -e "${WORKDIR}/${UBINIZE_CFG_TMPL}" ]; then
+        export ${@get_ubi_exports(d)}
+        envsubst "${@get_envsubst_args(d)}" \
+            < ${WORKDIR}/${UBINIZE_CFG_TMPL} > ${WORKDIR}/${UBINIZE_CFG} 
+    fi
+
+    # Create ubi image using buildchroot tools
+    sudo chroot ${BUILDCHROOT_DIR} /usr/sbin/ubinize ${UBINIZE_ARGS} \
+                -o "${PP_DEPLOY}/${UBI_IMAGE_FILE}" "${PP_WORK}/${UBINIZE_CFG}"
+}
+addtask ubi_image before do_build after do_copy_boot_files do_install_imager_deps do_unpack
-- 
2.20.1


  reply	other threads:[~2019-01-29 12:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-29 12:10 [RFC PATCH 0/2] Implementation of UBI claudius.heine.ext
2019-01-29 12:10 ` claudius.heine.ext [this message]
2019-01-29 12:10 ` [RFC PATCH 2/2] meta-isar: added qemusabrelite example to demonstrate UBI use claudius.heine.ext

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190129121020.30845-2-claudius.heine.ext@siemens.com \
    --to=claudius.heine.ext@siemens.com \
    --cc=ch@denx.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox