From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 6517147827419742208 X-Received: by 10.46.25.221 with SMTP id 90mr1731498ljz.17.1517391724399; Wed, 31 Jan 2018 01:42:04 -0800 (PST) X-BeenThere: isar-users@googlegroups.com Received: by 10.46.116.6 with SMTP id p6ls494297ljc.7.gmail; Wed, 31 Jan 2018 01:42:03 -0800 (PST) X-Google-Smtp-Source: AH8x226sPJ0S4c5PvItdNvPr+zvWMtCet7l4yiK8oE1QQXYvnAAPH83m5FCDrfzHFCJ4ej5yVgnM X-Received: by 10.25.31.66 with SMTP id f63mr2391585lff.42.1517391723182; Wed, 31 Jan 2018 01:42:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517391723; cv=none; d=google.com; s=arc-20160816; b=omIQzVhRKRYa4gCm2Ly6SOdaLrvQIkh+pjSKgod6x2JzdAAgpeXXu6gEhbnKYRNVKW BbeC4lt5TBykikBDalqSsJxFhx1qZhJoBD9kQH/0aIF9SKtr84zoxXvtmXijoHOKiYbM cJEjAQwrT4YxdrWAhtr7aftg2PmhpK5wHeI4XX6hmIHerhx9RhMbrBNXIp8YohfmvzHM e+xAd4ZG489aWuOQWYKIi1qBCY3l2RKQLO2Bhe0Mq4WjO2cXbkIKcBvKj3+iTUcKBFC5 opv2/IGYz4Nvqqc1oewbr1O81yxcfLmZU1hbFDG/wKOBTPCtVRmTQDJVypsTHpElt/L7 HLiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=oNH0LgrpKMDaUE58TV4BEW6pVkBI9QK+2OWO26HRLC0=; b=F2PKW8025WAA7pnQLLhqiJTJDYBqm6Z+x9sQPcVB3fLQTIqiQBHRK09tJtsWp2IhV3 MA8K9ivPzWTJUlSf/c83QHCbeq3WKiOfk2HET+kMgNMzkbLTrcBH9cKAzMLR22I8BZOj fOBl0xBYAy0u9MHLj1zYcqnz7Lfv5n/eP7dkonNBM2f/hmRs/FMZkWvf1mhofkMB9p5f mw/b1jHAIrNeW1wuDzfBFw5iLt+Eoh2DIpgqmbQVhix7+JDnD+PJQ9+AF3Ub218nDPk0 kYkrXvHRMi3EKnGpu5XWORsbQreIKs4EBHlnKiyH6Gs1vU86DSqtyOIWsNjpKFBkHptJ xI+w== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Return-Path: Received: from thoth.sbs.de (thoth.sbs.de. [192.35.17.2]) by gmr-mx.google.com with ESMTPS id y16si1191476lje.2.2018.01.31.01.42.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 01:42:03 -0800 (PST) Received-SPF: pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) client-ip=192.35.17.2; Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of henning.schild@siemens.com designates 192.35.17.2 as permitted sender) smtp.mailfrom=henning.schild@siemens.com Received: from mail3.siemens.de (mail3.siemens.de [139.25.208.14]) by thoth.sbs.de (8.15.2/8.15.2) with ESMTPS id w0V9g2CS008794 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 31 Jan 2018 10:42:02 +0100 Received: from md1pvb1c.ad001.siemens.net (md1pvb1c.ad001.siemens.net [139.25.68.40] (may be forged)) by mail3.siemens.de (8.15.2/8.15.2) with ESMTP id w0V9g1aW008484; Wed, 31 Jan 2018 10:42:02 +0100 From: Henning Schild To: isar-users@googlegroups.com Cc: Henning Schild Subject: [PATCH 2/9] images: new class wic-img for wic intregration Date: Wed, 31 Jan 2018 10:41:53 +0100 Message-Id: <122454433490bad5b449b9a984c4578da525a03a.1517390790.git.henning.schild@siemens.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: References: In-Reply-To: References: X-TUID: x1ybw1sNik6N This patch integrates wic into the bitbake workflow, wic will be used for the imaging step, no need to call it manually. The target of this patch is to work with an unmodified wic, that is why it contains a few wic-specifics, mostly taken from OE. There is one major difference to OE, we assume that wic is run as root. And we smuggle in a wrapper that patches calls to an fsck that does not behave like the one on OE. Issues: - wic was never integrated - you always had to build an ext4-img to create a wic image later - there was never a way to control the size of wic disks/partition, only directly in the wks Impact: The patch solves the Issues without changing the default behaviour of Isar. Signed-off-by: Henning Schild --- meta/classes/wic-img.bbclass | 64 ++++++++++++++++++++++++++++++++++++++++++++ scripts/wic_fakeroot | 37 +++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 meta/classes/wic-img.bbclass create mode 100755 scripts/wic_fakeroot diff --git a/meta/classes/wic-img.bbclass b/meta/classes/wic-img.bbclass new file mode 100644 index 0000000..e8d2678 --- /dev/null +++ b/meta/classes/wic-img.bbclass @@ -0,0 +1,64 @@ +# This software is a part of ISAR. +# Copyright (C) 2018 Siemens AG +# +# this class is heavily inspired by OEs ./meta/classes/image_types_wic.bbclass +# + +WKS_FILE ?= "sdimage-efi" + +# TODO here we leak buildenv into the image +# this needs to come from buildchroot +# and the isar efi plugin has the same problem +# syslinux in debian has different folder structure, need to for those plugins +STAGING_DATADIR ?= "/usr/share/" +STAGING_LIBDIR ?= "/usr/lib/" +STAGING_DIR ?= "${TMPDIR}" +IMAGE_BASENAME ?= "multiconfig:${MACHINE}-${DISTRO}:${PN}" +FAKEROOTCMD ?= "wic_fakeroot" +RECIPE_SYSROOT_NATIVE ?= "/" + +do_wic_image[stamp-extra-info] = "${DISTRO}-${MACHINE}" + +WIC_CREATE_EXTRA_ARGS ?= "" + +WICVARS ?= "\ + BBLAYERS IMGDEPLOYDIR DEPLOY_DIR_IMAGE FAKEROOTCMD IMAGE_BASENAME IMAGE_BOOT_FILES \ + IMAGE_LINK_NAME IMAGE_ROOTFS INITRAMFS_FSTYPES INITRD INITRD_LIVE ISODIR RECIPE_SYSROOT_NATIVE \ + ROOTFS_SIZE STAGING_DATADIR STAGING_DIR STAGING_LIBDIR TARGET_SYS TRANSLATED_TARGET_ARCH" + +# Isar specific vars used in our plugins +WICVARS += "KERNEL_IMAGE INITRD_IMAGE DISTRO_ARCH" + +python do_rootfs_wicenv () { + wicvars = d.getVar('WICVARS', True) + if not wicvars: + return + + stdir = d.getVar('STAGING_DIR', True) + outdir = os.path.join(stdir, d.getVar('MACHINE', True), 'imgdata') + bb.utils.mkdirhier(outdir) + basename = d.getVar('IMAGE_BASENAME', True) + with open(os.path.join(outdir, basename) + '.env', 'w') as envf: + for var in wicvars.split(): + value = d.getVar(var, True) + if value: + envf.write('%s="%s"\n' % (var, value.strip())) + + # this part is stolen from OE ./meta/recipes-core/meta/wic-tools.bb + with open(os.path.join(outdir, "wic-tools.env"), 'w') as envf: + for var in ('RECIPE_SYSROOT_NATIVE', 'STAGING_DATADIR', 'STAGING_LIBDIR'): + envf.write('%s="%s"\n' % (var, d.getVar(var, True).strip())) + +} + +addtask do_rootfs_wicenv after do_copy_boot_files before do_wic_image +do_rootfs_wicenv[vardeps] += "${WICVARS}" +do_rootfs_wicenv[prefuncs] = 'set_image_size' + +do_wic_image() { + export BUILDDIR="${BUILDDIR}" + + sudo -E PATH="$PATH:/builder/isar/bitbake/bin:/builder/isar/scripts" /builder/isar/scripts/wic create ${WKS_FILE} --vars "${STAGING_DIR}/${MACHINE}/imgdata/" -o ${DEPLOY_DIR_IMAGE} -e ${IMAGE_BASENAME} ${WIC_CREATE_EXTRA_ARGS} +} + +addtask wic_image before do_build after do_copy_boot_files diff --git a/scripts/wic_fakeroot b/scripts/wic_fakeroot new file mode 100755 index 0000000..9e01c38 --- /dev/null +++ b/scripts/wic_fakeroot @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# +# wic needs a FAKEROOT cmd to run, the default is pseudo. In Isar we do/can not +# use pseudo. And we call wic as root to begin with, so this script could be a +# dummy doing nothing. It is almost a dummy ... +# +# If the fsck hack ever becomes obsolete, FAKEROOTCMD ?= "true;" can be used +# +# This software is a part of Isar. +# Copyright (C) 2018 Siemens AG +# +import os +import sys +import shutil +import subprocess + +args = sys.argv +args.pop(0) +cmd = args[0] + +# expect to be running as root +# we could loosen that and execv(sudo, args) but even some early +# "du"s fail, which do not use the fakeroot-wrapper +# i.e. in wics partition.py the "du -ks" fails on +# var/cache/apt/archives/partial +# rootfs/root ... +assert 'root' == os.environ["USER"] + +# e2fsck <= 1.43.5 returns 1 on non-errors (stretch and before affected) +# treat 1 as safe ... the filesystem was successfully repaired and is OK +if cmd.startswith('fsck.'): + ret = subprocess.call(args) + if ret == 0 or ret == 1: + sys.exit(0) + sys.exit(ret) + +os.execv(shutil.which(cmd), args) -- 2.13.6