From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6652197203295076352 X-Received: by 2002:a17:906:a483:: with SMTP id m3mr1100560ejz.9.1548835356954; Wed, 30 Jan 2019 00:02:36 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 2002:a17:906:1fd4:: with SMTP id e20ls284523ejt.4.gmail; Wed, 30 Jan 2019 00:02:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN5DaeqsjoDkBsZVJYY6Op3/cHS/owgY6oi3MYWFW24/wb9OCEiYefW1NdCWuoSENbYTwvHr X-Received: by 2002:a17:906:6006:: with SMTP id o6-v6mr1113824ejj.4.1548835356556; Wed, 30 Jan 2019 00:02:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548835356; cv=none; d=google.com; s=arc-20160816; b=hkLzTQVDFbAYa9EBaXq64oWNN9khnBMNlwDASz4Is5MVtZ0IyhQoUKjOxts6hDQhj8 iD3Z9ulrQOp3VUj2pumbHKQ0LSxQ89tDKA6b5dnFzrIPaQod+NcPvPAfj/NcrATLGuLm mi1MyRX0vW+jfkEsXKxK1df0DCDboi4tAvlf4UoefWNk3bfJf8rD+tyLE+S487MF7tJd zztTKGz/VxGNELpDmvNM+z39NF9jCev7kz00Bpuv+7/xtca9XITAo7gBXR1nK4hl9Viz NyG2znG3/1nYpiV/gaohAN3eT7H7m5i8nLhocfTKdNhTWtJpJoFesBaNvXIENbSMIpHX h7hA== 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=d8cJ84eFZh6iH7Wmv/KCDhnClSvJdN2xE2z1awYcdic=; b=yAJU7JILJVgDunYn1XkuTfTQunVYpeNIM/E4wCJ9ErMGh5mwqaZ7haa5R8fT8B7zm9 Fpoc5SlVjjQb2Yw/lmRU8Z1tB8+XjoBLfF14UReLJks2VE6FhjXxeA9nF/7ivHf7gqPL wVsQ4JINdi+eFjZRTORTK77KO+Rhu00E+7D7WfzLoPnl0jyaN/BhjT8U+ezXeorr5Rl3 5y6SOfYtkJAYpQ1MckeUcmwwmgyWCvp26Kb+y82KI3MvHCPIyQ06u/2OZyd6c8hqQ/XR N53TZy0Kncn6SMq1q/DAoLpdJQqEi/6D6jEPAaNK8xO1vxBLQciaBkxoBrNKUsSjl/5Q 7hQA== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Return-Path: Received: from lizzard.sbs.de (lizzard.sbs.de. [194.138.37.39]) by gmr-mx.google.com with ESMTPS id i17si51020edg.2.2019.01.30.00.02.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 Jan 2019 00:02:36 -0800 (PST) Received-SPF: pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.39 as permitted sender) client-ip=194.138.37.39; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of claudius.heine.ext@siemens.com designates 194.138.37.39 as permitted sender) smtp.mailfrom=claudius.heine.ext@siemens.com Received: from mail1.sbs.de (mail1.sbs.de [192.129.41.35]) by lizzard.sbs.de (8.15.2/8.15.2) with ESMTPS id x0U82ZBt015368 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 09:02:35 +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 x0U82Yn9015973; Wed, 30 Jan 2019 09:02:35 +0100 From: claudius.heine.ext@siemens.com To: isar-users@googlegroups.com Cc: Claudius Heine Subject: [PATCH v2 3/4] meta/classes: added ubi-img class Date: Wed, 30 Jan 2019 09:02:28 +0100 Message-Id: <20190130080229.604-4-claudius.heine.ext@siemens.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190130080229.604-1-claudius.heine.ext@siemens.com> References: <20190130080229.604-1-claudius.heine.ext@siemens.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUID: vOcTBLp35UU1 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 --- doc/user_manual.md | 2 + meta/classes/ubi-img.bbclass | 73 ++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 meta/classes/ubi-img.bbclass diff --git a/doc/user_manual.md b/doc/user_manual.md index c9924ad..c9e18e0 100644 --- a/doc/user_manual.md +++ b/doc/user_manual.md @@ -350,6 +350,7 @@ Isar can generate various images types for specific machine. The type of the ima - `ext4` - Raw ext4 filesystem image (default option for `qemuarm` machine). - `rpi-sdimg` - A complete, partitioned Raspberry Pi SD card image (default option for the `rpi` machine). - `wic-img` - A full disk image with user-specified partitions created and populated using the wic tool. + - `ubi-img` - A image for use on mtd nand partitions employing UBI --- @@ -477,6 +478,7 @@ Isar contains additional image type classes that can be used as reference: - `rpi-sdimg` - `targz-img` - `ubifs-img` + - `ubi-img` - `wic-img` --- diff --git a/meta/classes/ubi-img.bbclass b/meta/classes/ubi-img.bbclass new file mode 100644 index 0000000..078293e --- /dev/null +++ b/meta/classes/ubi-img.bbclass @@ -0,0 +1,73 @@ +# This software is a part of ISAR. +# Copyright (C) Siemens AG, 2019 +# +# SPDX-License-Identifier: MIT + +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