From patchwork Tue Oct 29 10:01:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Freihofer, Adrian" X-Patchwork-Id: 1185945 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:4864:20::13f; helo=mail-lf1-x13f.google.com; envelope-from=swupdate+bncbaabbzm44dwqkgqeb2vtkuy@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=siemens.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="m1MAgHHU"; dkim-atps=neutral Received: from mail-lf1-x13f.google.com (mail-lf1-x13f.google.com [IPv6:2a00:1450:4864:20::13f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 472Rx50rRhz9sPh for ; Tue, 29 Oct 2019 21:03:20 +1100 (AEDT) Received: by mail-lf1-x13f.google.com with SMTP id s30sf2610921lfo.9 for ; Tue, 29 Oct 2019 03:03:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1572343397; cv=pass; d=google.com; s=arc-20160816; b=dTKInwggPyXmuWwrJ6q/kHWbpfm8vMujXLCEznOvu18Pg6dkDGtvOP1jKFP32fklLf mWqw1XMgsJ9MRDXl+ODYkNpkXR9Ietdp8IC1ry7vdWOfKHJlS1T5cjveAWLZkmkys37m JRsMG7YjfZBg9d4eVuqDgNHg/dZltGdTrKvFt43m6xhELzSEcPkyZtxrpUnrX8fgQb5G VUNtsrVn3CReSnFRptrBfqh6HVMujvG3Utn0qiFsD5FitF+ReNOc63gfzYzu4Q1tNhPS EYpK4ZhLvjvB5ChdVXts1JJ/bFgZGxrsMCFyqhepo1hdSbuf0KftF7C6WQSu5QgkJ50P 80yQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:mime-version:sender:dkim-signature; bh=ELstm2R/eYKSBHZ766h9WjOr0o3TH6HFi1SkRl+oOZI=; b=wqae0jfnxXhvgzdLC+5t2HHzwYkD9IqUQ5qnadtUNIAs7AXMl/8Nuhq9DTJJV2ORtr AS97KO3hEP3NZSpp06YYERz/WDCF1EylC5M4T7DPx+e0if7aKxzgatZv5xXUFCODa7md C4QpWSNfB86ZSHRlpAGpQZ1/0h8lglaZtlZBIjI8V77FcHR63mZOsdi4B0HQ6If9WqoO HcfSFqPVWh4ZockbjW75PK7J5bHuYuWmokZaINGRzSpM0HkGhcBXJ6R/ya2sIBxZ8KKV 7K3mhQ6v4ArMBHZz6tkYkLkO76X6o0SClIICJMFjUUphI0GCZ+BcNfBMKoWlM7Qfct5/ bgQA== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:mime-version:from:to:cc:subject:date:message-id:in-reply-to :references:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=ELstm2R/eYKSBHZ766h9WjOr0o3TH6HFi1SkRl+oOZI=; b=m1MAgHHUe/WuFGqDznND/sJB/fA/pI27IAPKqGbQjlSLTdunDLv8uo/EFQkFYGXVh9 U/+bdamTnpWgVcbO9DPR7o351FMDqUEPaE8sH9jUvvK86BCh4BEGXVGyflf/zddAzML0 EeH4JfD47xeh0uqL5kyhSng+A6/ZYeshtf/YCRRiZCi7hhGGzSzd/hlEz88mmQZq5HWZ bCu3ZSJ9vMZNGd1vt1dy9jB+I9hDfw/zorHUDPHGdU+uuRcIvdQIfH+OX/BLweLldIWm mTYy1IKm1M0b5Q5PQVuJ8+m99oyKJ2YzVl0Gqf+I03TCIR98z+J1aXa0hZbjO+UaC4bk Rt5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:mime-version:from:to:cc:subject:date :message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-spam-checked-in-group:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=ELstm2R/eYKSBHZ766h9WjOr0o3TH6HFi1SkRl+oOZI=; b=F7eyI8Ry5H7+E8cXfauHZR+NZz5NXN/KJqjG7y9xDdYF5g9RSVrwzQTmP8jfvZXyzI OMhbw6jGRDiHSEcp3r8dxxDNaXgvhkk3SpV5fBs7OLNz2FBuTqDe1U2xWjCknF9wbONX KPMT/XatHfaxlDmfvzl5X/h9QJCCExAI6GFR+wGmnCozjfysw+MO7QlMT7eFbH0ySJVU M/kkcFMktNf+aHl8oyEWMlbaffLCXYOlBMBeq/x+qGj6vXmg93pXquLGBI3FaEgmPMUy mgcWNH6Cj9PLHM9o0cI7lj5pA9Xo+0YvJeT65Yl4tG4PuHtoLWWwGPSzR3U6t+rAWOy5 5seQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAVEFlHNtSsRedsEXYhbuqGEjEX0uDuuUqdSJUpruYUajzDVCte6 4zCN9PRp1yFIMezgRiCHLMs= X-Google-Smtp-Source: APXvYqwQ0W62vzatlp978FHxh7A0Lb/KmJY1NMp1WVcIkB1GVY3EwuPBSVGmuHkn1foVCrNLAZhglA== X-Received: by 2002:a2e:420a:: with SMTP id p10mr1999845lja.16.1572343397328; Tue, 29 Oct 2019 03:03:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a2e:3013:: with SMTP id w19ls1358582ljw.6.gmail; Tue, 29 Oct 2019 03:03:16 -0700 (PDT) X-Received: by 2002:a2e:9e4c:: with SMTP id g12mr1991460ljk.103.1572343396865; Tue, 29 Oct 2019 03:03:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572343396; cv=none; d=google.com; s=arc-20160816; b=urDl3ugIAB/meo5pIZXJObHQae7RmqUqNpgwdVoRacAl6bQdEcNpYS1n/w6buFHFX4 J1+g9jFLXzGAiUJLqiJupZYezPkkmHC5w7LqI36Frl6Di8nXuMba6NzwQ6N6e9ZCRIZm 8CAXWSc3iBmdaey7focehYlpWoKhyDls09IHVosjyACPbT9aU8v6BriFmAYNHhbjwVUJ OYWe3bLvzQm1gom5cpB0wVFX2pEfmjkntfV78dNV2Yyju/qiSwt2t9nnYoJQhI+cL2Dq O86V738zMtHvtQo+CqKek9ldHH0c2vCYpe5vbSawpAEyl48tpdvpi1qur1xpacA3ALGh t/ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=8wCN/g93qVnZfEiIXAogWMkIzlPI89McS8z13qsfkTk=; b=kD5imWD7wXDOY/RjVhbfsZeRf3SpGpO9CAUHI0AZlvVOoxFbE5fgBl0G9W/MSZLynF 4eVXt6NzPhbI8UQrwIuMylnb8+Jv6Hlj0Wh0GjIu/zOk+YQLeIdZ2RWlAX5W5CpXvYJD onhMppI9K6fH/XDwTBDj9tYgJGpQwx1dHaOxpt2OmRWW9TQ+w2igNGzZvLECvKbeuYh9 K/p6t8YFMnq1/Af6/09DLFOBKODGppKSfnVsNKzk/irxYAxc9hCvPgzD1K3tT+1yvOjH KxPQt2NkjkbU66lLczWkP4jUq0dh24C5qtXkCoYMPX5yo9ZIQuyDPyQnJwz4vClwZ7sx TUuw== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from david.siemens.de (david.siemens.de. [192.35.17.14]) by gmr-mx.google.com with ESMTPS id z9si667136ljj.4.2019.10.29.03.03.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2019 03:03:16 -0700 (PDT) Received-SPF: pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) client-ip=192.35.17.14; Received: from mail2.siemens.de (mail2.siemens.de [139.25.208.11]) by david.siemens.de (8.15.2/8.15.2) with ESMTPS id x9TA3Gcr031386 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Tue, 29 Oct 2019 11:03:16 +0100 Received: from dev.vm6.ccp.siemens.com (md1w1dqc.ad001.siemens.net [139.16.76.146] (may be forged)) by mail2.siemens.de (8.15.2/8.15.2) with ESMTP id x9TA3EAD025642; Tue, 29 Oct 2019 11:03:14 +0100 Received: from dev.vm6.ccp.siemens.com (localhost [127.0.0.1]) by dev.vm6.ccp.siemens.com (Postfix) with ESMTP id B0A6A2353A51; Tue, 29 Oct 2019 11:03:14 +0100 (CET) From: Adrian Freihofer To: swupdate@googlegroups.com Cc: Adrian Freihofer Subject: [swupdate] [PATCH v3 2/3] swupdate: simplify find images added to swu Date: Tue, 29 Oct 2019 11:01:12 +0100 Message-Id: <20191029100113.27287-3-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191029100113.27287-1-adrian.freihofer@siemens.com> References: <20191029100113.27287-1-adrian.freihofer@siemens.com> X-Original-Sender: adrian.freihofer@siemens.com X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.14 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Precedence: list Mailing-list: list swupdate@googlegroups.com; contact swupdate+owners@googlegroups.com List-ID: X-Spam-Checked-In-Group: swupdate@googlegroups.com X-Google-Group-Id: 605343134186 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Try to make the swupdate.bbclass a little bit smarter in finding the image files added to the swu archive. The implementation is also a bit more Yocto like. By default, files are searched automatically whereas MACHINE specific files get priority over files without the MACHINE in the filename. This makes the SWUPDATE_IMAGES_NOAPPEND_MACHINE VarFlag more optional. Most standard use cases are expected to "just work" without setting this flag. Add support for files in a sub-folder of DEPLOY_DIR_IMAGE. Add documentation to the header of the swupdate.bbclass file. Signed-off-by: Adrian Freihofer Acked-by: Stefano Babic --- classes/swupdate.bbclass | 77 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 23 deletions(-) diff --git a/classes/swupdate.bbclass b/classes/swupdate.bbclass index 1d74eef..79c9aae 100644 --- a/classes/swupdate.bbclass +++ b/classes/swupdate.bbclass @@ -7,10 +7,30 @@ # in field. # See also http://sbabic.github.io/swupdate/ # +# To use this class, add swupdate to the inherit clause of the update image bb file. +# The generated output file is an swu archive ready to be uploaded to a device running +# swupdate. # -# To use, add swupdate to the inherit clause and set -# set the images (all of them must be found in deploy directory) -# that are part of the compound image. +# Files listed in the SRC_URI variable are added the the swu archive. +# +# For each entry in the SWUPDATE_IMAGES variable an image file is searched for in the +# ${DEPLOY_DIR_IMAGE} folder and added to the swu archive. Different types of entries +# are supported: +# * image name(s) and fstype(s): +# Example: +# SWUPDATE_IMAGES = "core-image-full-cmdline" +# SWUPDATE_IMAGES_FSTYPES[core-image-full-cmdline] = ".ext4.gz" +# For this example either a file core-image-full-cmdline-${MACHINE}.ext4.gz or a file +# core-image-full-cmdline.ext4.gz gets added the swu archive. Optionally the variable +# SWUPDATE_IMAGES_NOAPPEND_MACHINE allows to explicitley define if the MACHINE name +# must be part of the image file name or not. +# * image file name(s) +# Example: +# SWUPDATE_IMAGES = "core-image-full-cmdline.ext4.gz" +# If SWUPDATE_IMAGES_FSTYPES is not defined for an entry in SWUPDATE_IMAGES or the +# corresponding image files cannot be found in the ${DEPLOY_DIR_IMAGE} folder, an +# image file with exactly the name as specified in SWUPDATE_IMAGES is searched for. + inherit swupdate-common.bbclass S = "${WORKDIR}/${PN}" @@ -74,6 +94,7 @@ python do_swuimage () { if d.getVar('SWUPDATE_SIGNING', True): list_for_cpio.append('sw-description.sig') + # Add files listed in SRC_URI to the swu file for url in fetch.urls: local = fetch.localpath(url) filename = os.path.basename(local) @@ -81,30 +102,40 @@ python do_swuimage () { shutil.copyfile(local, os.path.join(s, "%s" % filename )) list_for_cpio.append(filename) -# SWUPDATE_IMAGES refers to images in the DEPLOY directory -# If they are not there, additional file can be added -# by fetching from URLs + def add_image_to_swu(deploydir, imagename, s): + src = os.path.join(deploydir, imagename) + if not os.path.isfile(src): + return False + target_imagename = os.path.basename(imagename) # allow images in subfolders of DEPLOY_DIR_IMAGE + dst = os.path.join(s, target_imagename) + shutil.copyfile(src, dst) + list_for_cpio.append(target_imagename) + return True + + # Search for images listed in SWUPDATE_IMAGES in the DEPLOY directory. deploydir = d.getVar('DEPLOY_DIR_IMAGE', True) imgdeploydir = d.getVar('IMGDEPLOYDIR', True) - for image in images: fstypes = (d.getVarFlag("SWUPDATE_IMAGES_FSTYPES", image, True) or "").split() - if not fstypes: - fstypes = [""] - - for fstype in fstypes: - - appendmachine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) - if appendmachine == None: - imagebase = image + '-' + d.getVar('MACHINE', True) - else: - imagebase = image - - imagename = imagebase + fstype - src = os.path.join(deploydir, "%s" % imagename) - dst = os.path.join(s, "%s" % imagename) - shutil.copyfile(src, dst) - list_for_cpio.append(imagename) + if fstypes: + noappend_machine = d.getVarFlag("SWUPDATE_IMAGES_NOAPPEND_MACHINE", image, True) + if noappend_machine == False: # Search for a file explicitely with MACHINE + imagebases = [ image + '-' + d.getVar('MACHINE', True) ] + elif noappend_machine == True: # Search for a file explicitely without MACHINE + imagebases = [ image ] + else: # None, means auto mode. Just try to find an image file with MACHINE or without MACHINE + imagebases = [ image + '-' + d.getVar('MACHINE', True), image ] + for fstype in fstypes: + image_found = False + for imagebase in imagebases: + image_found = add_image_to_swu(deploydir, imagebase + fstype, s) + if image_found: + break + if not image_found: + bb.fatal("swupdate cannot find image file: %s" % os.path.join(deploydir, imagebase + fstype)) + else: # Allow also complete entries like "image.ext4.gz" in SWUPDATE_IMAGES + if not add_image_to_swu(deploydir, image, s): + bb.fatal("swupdate cannot find %s image file" % image) prepare_sw_description(d, s, list_for_cpio)