From patchwork Sat Nov 2 22:02:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Freihofer, Adrian" X-Patchwork-Id: 1188476 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::440; helo=mail-wr1-x440.google.com; envelope-from=swupdate+bncbaabb5hz67wqkgqetpee7ba@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="q4HaYeIC"; dkim-atps=neutral Received: from mail-wr1-x440.google.com (mail-wr1-x440.google.com [IPv6:2a00:1450:4864:20::440]) (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 475Cj35XhDz9sP3 for ; Sun, 3 Nov 2019 09:02:31 +1100 (AEDT) Received: by mail-wr1-x440.google.com with SMTP id f16sf7536584wrr.16 for ; Sat, 02 Nov 2019 15:02:31 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1572732148; cv=pass; d=google.com; s=arc-20160816; b=DFqFeidjOxKDtIfF9Nyy77As7XSds3GI2oAA4wo6FJ0sk6V/k7XuMItBbH+nCyHwkU wNW+eYTs5vn2/TmSrZc+tzmlDdU4c/ILX3JL0DaLF++rYt2cUmRelmAHHJdkFs1YX3u8 RZZ8BTCJNZTHxTdzARQOEsTlD6f+qxMNLIVbgm7kmzwfUz+4l0uJQs7sSAKbMHSALkk2 cUK0i3ZozrI2ZbeJWLjJp8IKts7nzTNpNKCozNISl1+TuAlof9SWCuSEfpAMYdDo3f5e 7n41QiT5uHIrcBz0DzAmaVwy7EwUb76JXmOnJOA3MgZQa2fUpsTv6J6FC8WcT3IvmLYt 0Qtw== 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=tNTx+PgUwI+zVU239Ghxj6qOLcVnk0Y12wTFAwBC29E=; b=IWKf0aEdVtE8fLrx63LtF7a6q0hzzxqn7jxM0/4we+ecdaFOCZLNSlguvI5u9b/nqy yDGMro63iQVF8MCqO1Znv0tbKh7BQ6FjwKoD3bI0PeZ+W4OCW0aPcRTUpvhPqilg/FC6 gPuddjCOh0xepd481B8mHlor7NE0KH4jE0ptIa32hj+w2ZOGDm66TxRH+olWyPWqKfjU EEs92MHzCByQANafyCKsWAJNtZIqos09azoDebVsuj3KOdx3lYYAQ9mMqccD4iLVYQSi OIXh7nHG5MpeKcArQqME5U3BNuVwXeIhhqPkfRiVxb/yGM+/4qzra1jVOIVaMRhM4Crl ud9g== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 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=tNTx+PgUwI+zVU239Ghxj6qOLcVnk0Y12wTFAwBC29E=; b=q4HaYeICD78z8FRRji0BaIObwrcjQHAzKHEbBS29qMNEdpAdTYf4QOIcL5EesHu3ZH xY8woYOys46HNdYlJH/I1QCqLH4AUJeYMWFxxXLPbU7FUBXUBebyCFBl+0RHKU1NW2dR 6U7zWMf6XAFu4x7JWY4+CyUpkExT3tfpOUAJNv4NreNyPPP1y8rnWIOxav4m3rVaJehB 68uA2giAjm3x4E8DZsjh+scredjaG8kowYDzI8VeS/CW/hJ7mYIsPoz5pTCcOfi3keH2 1QpWxs2svR8b6+DNldB2SoIgzkMVs3IHkyRnbRfhLND8EUYT3c3KKj2JYZvV8MCyG/F6 f2UA== 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=tNTx+PgUwI+zVU239Ghxj6qOLcVnk0Y12wTFAwBC29E=; b=a6Yiqu2QJ7cENe29iHoxtL2NpNRXmpZa5FUAr0FtNjN1uoUWJ3ZzXBABRaFAbqQQMR R9wnmaVnIrY3LGYG01Ym5nCCrETCs40yJ2Qqr5oq6v4f7e50lO5bxnSl5xpKtf0qeKCT wz5K9fZOFK+aXzcRyn6sypn5qKp3bQu0KzRTbLfaB9/+bD+Brh2Brg/SRLALhHXk/UVZ VUGmF3q6NvlRUY7n49jWM5Wp762op7R4gSfTkU6ExdRdZAKEtdyHgzcUabIwneJ7fMiO k/pboU+mkXH2XQLbM+5TwIKdCwCMIyVd8/RblG1jJCU2SfVs58A1UPgbJzY6PMXB6fiR Qd/g== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAVFm9UscaLVWUqXzW9AIeMBxLX9PrZl1yoJYSX1ykdQFdY46BYf uFgDgYFGn2ImDPNbAHDD9f8= X-Google-Smtp-Source: APXvYqwJdXq1vWgQHM+txdSpydXrXFeA21Z9CDIFffj2V1badp73nVViVipO8PkRYahwNmIRcigGfA== X-Received: by 2002:adf:d4cc:: with SMTP id w12mr16948835wrk.93.1572732148132; Sat, 02 Nov 2019 15:02:28 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a1c:7406:: with SMTP id p6ls2237455wmc.2.gmail; Sat, 02 Nov 2019 15:02:27 -0700 (PDT) X-Received: by 2002:a1c:e91a:: with SMTP id q26mr3423686wmc.88.1572732147721; Sat, 02 Nov 2019 15:02:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572732147; cv=none; d=google.com; s=arc-20160816; b=pFxZhhqayeIjm1XSkVakdSOob18EHE6H8knAgDgzgHyzb+U4TMxNE5Ejbxl7Z4SKM8 FB/H1nHDgNhKBmmVrlz5eV1U8kQfgvk5SFalbuJ+qMNjik1iAqvPHX+rruFrwCEsaG9A ephj2ImCkYfwjWU1J2cL+1efNZukUpwyy/1FJH+whHQVLGGp6Ho30YuwPTr1gLvjhE6s dIZw3+g5iBOctCDhSCp1pkOB0SzKBEVcs4VdN+y2TbVzPA9sG+oIEj2uAME9d5jHnOmp 6a/u7gs6p2c2P6HOSeNU5mdynWdO0Go3Q77RYzC6fxqogl1UuRDlYDwq8J1dvZdV0u5c 2exQ== 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=QbdwV6/GfZsCsbHUu0lD/8ddaSNc+x01TbKE7u42kpHuwsMmFrm7oaCl+fOZfNtaq8 RSw7K3MdLLVjzXdZRK6NxPwCj51i8NgGpJHKw63Q6YQfGSPjWpDLR8NT4phNlT+G3hKo CJraNcpePETnlL+RjOIOellbgvoy5SknJ1P9uoOv+FF70N1L8dbt7dlWumfn5vtY2+AP nzDIQd08fHD2LpSBuHK76fVXtPZu/kpWU0Clx9QJI+4es86NA5EUXmgjwiQu7EM3gG7C AxvGU4Haoxllc0kVEXoEJ8ipfBvZS/gk56QY1y8Gh/X/FLJqsMWD+fH6Qj/GbkrAqIVl 62og== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 as permitted sender) smtp.mailfrom=adrian.freihofer@siemens.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=siemens.com Received: from goliath.siemens.de (goliath.siemens.de. [192.35.17.28]) by gmr-mx.google.com with ESMTPS id e17si544104wre.3.2019.11.02.15.02.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 02 Nov 2019 15:02:27 -0700 (PDT) Received-SPF: pass (google.com: domain of adrian.freihofer@siemens.com designates 192.35.17.28 as permitted sender) client-ip=192.35.17.28; Received: from mail1.siemens.de (mail1.siemens.de [139.23.33.14]) by goliath.siemens.de (8.15.2/8.15.2) with ESMTPS id xA2M2Ric015951 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Sat, 2 Nov 2019 23:02:27 +0100 Received: from dev.vm6.ccp.siemens.com ([139.22.33.134]) by mail1.siemens.de (8.15.2/8.15.2) with ESMTP id xA2M2QbO004871; Sat, 2 Nov 2019 23:02:26 +0100 Received: from dev.localdomain (localhost [127.0.0.1]) by dev.vm6.ccp.siemens.com (Postfix) with ESMTP id BEDB72353A50; Sat, 2 Nov 2019 23:02:25 +0100 (CET) From: Adrian Freihofer To: swupdate@googlegroups.com Cc: Adrian Freihofer Subject: [swupdate] [PATCH v4 2/2] swupdate: simplify find images added to swu Date: Sat, 2 Nov 2019 23:02:19 +0100 Message-Id: <20191102220219.10648-3-adrian.freihofer@siemens.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20191102220219.10648-1-adrian.freihofer@siemens.com> References: <20191102220219.10648-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.28 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 --- 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)