From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6651890004294369280 X-Received: by 2002:a50:86d3:: with SMTP id 19mr596146edu.5.1548763831941; Tue, 29 Jan 2019 04:10:31 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:906:628b:: with SMTP id t11ls1271816ejk.1.gmail; Tue, 29 Jan 2019 04:10:31 -0800 (PST) X-Google-Smtp-Source: ALg8bN4hwzM+ySbECYoKDuvJDy+owqVrsprVAWUHksQ55R8So+2pWuFV4b+w2j/GBxwgqT09QvDs X-Received: by 2002:a17:906:46ca:: with SMTP id k10mr566997ejs.2.1548763831547; Tue, 29 Jan 2019 04:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548763831; cv=none; d=google.com; s=arc-20160816; b=lXM9Hj131+Sr5iooWNAdiZMZIcmT7KoRxaxCGDWxyRCYMrmMTc7mzNmHv8vfqH6Sza XZfXFtbluTmjucmIuW5Yg1aHK56H50VxaPC0IAX3MylaynGzQZ4RbCoU4PMDaVs6BuxZ deKI6bItLV52e4Y4yKA50wim2qSV9oodM+TIwRMpvkDeg/CEmKbQpZN7YnEHBc+JRwpM Jz48ie7ZvzOLus2BJ6m+G0HA58nM0sCjhCrRGvA5/XghA7bNKb8IIhBv75s/bgAPhgZh 3evnFyYs65kt0wEwQfhRRKzfdd0Q9g7Uz/h/aY+PiyAFmqJX19oSOEwJxoN5lAHDMeRF 3cuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=pCbeKxvV6H7hlCcZERtE19FXQWBXPoTGTB61MiWRp8o=; b=hi4nMVLeuJ5Nb7VP/2hOLSwQKPYbA71TRtghzAXD6zH8GtRDDeJfbnfe/Mod96i5Ie hTg0iNCQVWJVa0Trff1IiwzSH/OL7OdvLzDmyDpshhWqUIxEycrcCbZIwmcrMw1Dxcpw 9hjjMmjBZj1Wqa6CKSi1t9JV7vVkK1tXaubHb1+YMTWYo2+RBNF3Y7lu2JsPp+8p7ECL 2JBQPtraxxJoN1/PrkscxOc5Fup/u2sEznsUF9rNBMwsXa2QcNF7TUZa4VOKmDqMHpVx aELApvTUWbDX+DNNT2fQdtZV470nKtEI9jeCczt3eSlG4DpavQPZvZRyS+1vbea0EOz6 xvPA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from gecko.sbs.de (gecko.sbs.de. [194.138.37.40]) by gmr-mx.google.com with ESMTPS id m24si1581071edc.3.2019.01.29.04.10.31 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 04:10:31 -0800 (PST) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) client-ip=194.138.37.40; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.40 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by gecko.sbs.de (8.15.2/8.15.2) with ESMTPS id x0TCAUP8010610 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 29 Jan 2019 13:10:30 +0100 Received: from ring.ppmd.siemens.net (linux-ses-ext02.ppmd.siemens.net [139.25.69.181]) by mail1.sbs.de (8.15.2/8.15.2) with ESMTP id x0TCAThW021516; Tue, 29 Jan 2019 13:10:30 +0100 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [RFC PATCH 1/2] meta/classes: added ubi-img class Date: Tue, 29 Jan 2019 13:10:19 +0100 Message-Id: <20190129121020.30845-2-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190129121020.30845-1-claudius.heine.ext@siemens.com> References: <20190129121020.30845-1-claudius.heine.ext@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: v8oSHO8ac+qn From: Claudius Heine 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 --- 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