From patchwork Thu May 10 08:52:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 911316 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=googlegroups.com (client-ip=2a00:1450:400c:c0c::23f; helo=mail-wr0-x23f.google.com; envelope-from=swupdate+bncbcxploxj6ikrb3uq2dlqkgqesbgeuqi@googlegroups.com; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b="dcQ30rWI"; dkim-atps=neutral Received: from mail-wr0-x23f.google.com (mail-wr0-x23f.google.com [IPv6:2a00:1450:400c:c0c::23f]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40hRnt0VFLz9s3Z for ; Thu, 10 May 2018 18:53:05 +1000 (AEST) Received: by mail-wr0-x23f.google.com with SMTP id 54-v6sf946767wrw.1 for ; Thu, 10 May 2018 01:53:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1525942383; cv=pass; d=google.com; s=arc-20160816; b=L5iDffjgYlVUSnknGN325409/MyJz1SwJCms4OTQlXMB7By9/oo1Z4Cxx2sqQ3kbV4 V5L0gg4KxNpArHYRQ7ZC8QUeUrHK5qfyyzTLDoHM/rpQh9B+G0lH3hMPJcT1NC/smOwf oDv9++eLFzZX2zz6d1Y3lNHXeaYjnXSIykqFLWAdagt89q43AtRBpTNu4M7Kml1OLen7 7LbGQU34CBYofPC7hW3/3rpIPRMtmq3mG2EO2izWeKhhvmbNThIF0SkhWjAwgT7psUTZ OvhHlZwZ7eoXBiyBx5jqE9G1w24jAhK2i5P+s0EAXsh4q7N/2IKbBXPUrU7G3FcvjO1t gJkQ== 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:arc-authentication-results :arc-message-signature:mime-version:sender:dkim-signature :arc-authentication-results; bh=xeaLxvbhBAZJvT1jmE8wHb2qx8bQ7PVLZmeIYr4MsRw=; b=ET1TlXDZ23W6Wdk2ibWFQ1sbBWF/p3K7ohE2auixbf+VMQOmInwdCSpeWCQtNmznm0 G8bJUNrM3798gmr04Qex7hPpwTtxEwYBO7XDLsN/KgM5vTSJUeIWpdtykaK5ySy1IbbC mHye4vSHDBFAnq2Sy71N/KvisVvHiJo2ZfSnlneYWrily1sXt8C0RcCICiiHpxt8PKbU xzNPCgs8xH6tHDlbWfgdnAFNbWt2xGxwWBxjAfWj6Jpzwa+YQCgpUb5F0WMgqWq7xwP8 EV7LBPzhz7p0QHTGhIdikCQ7tiEbGlg11jyz21RfYAn6i7ttjXb3YbnHv0OYj76KwFZM Ku9Q== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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=xeaLxvbhBAZJvT1jmE8wHb2qx8bQ7PVLZmeIYr4MsRw=; b=dcQ30rWIT/5pTRrAO5BZd3Gw0Ni1dlRjEoJwHOoB73G0tvsUSK4+H8W3TMxlq4t4xv 0X4tM1woXAsYldhJfL6ADNeoFf2844kFXu2wVgakAvENDpMdiQQYLYqZPa442tNO8Eu4 m4v7fgL223vGoCpUEH2MMAgQdfPatiCmvyqWMdoc+26DDVE2m/6UbHumg4JyVtpFBN5I WEZFXOGnjrcD4kcgk+bPKRItGdvWcocwg2RttI1l8w19g5m8sZhus6OfNxq9kHCzK9Jx MOom6UFe1yqpMHmDc8aRJURcOkHccXKcq4yPZJtnk3mp0dLZyHA7JYuyXAFKqMd78hyq TBIA== 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=xeaLxvbhBAZJvT1jmE8wHb2qx8bQ7PVLZmeIYr4MsRw=; b=Qfokjus9SlS2ygPUxgUoua7gKiuP2MORL6AV9GCc8syP9PgZRxFj7TYEG16wWoRHRS uXhmx7/LOL45wkBInyvgef9EkOnroS4v1rk4SLnD57spVaSlmkQxV4GvebNhqJ4mhd/G VpWVwVuswhJNP05MZgwySp9uIDrx9ylSnBQmKeBxUEIT+VVInv+uLGP7Dj6nw7u9wuFB i4fUgQnaIJx3X8Sec8av9vnjsGxqO2zswcdeS4OJ2oCDeMRLtjJjI+9VJhkkg80ca6uh izDB+1HTQXTacNBsXBi8eP6j3denHzxHlc2tmO9A65eCLO6M5IZ0eM8qYsaZAnesk9Y0 Y8bw== Sender: swupdate@googlegroups.com X-Gm-Message-State: ALKqPweDsdDsCwPAaYOk7kyocjsa38KtBP5K7XzayimQ6WdWfSBPK7Oj YTpCDRFRueZ+NPVUbyKWLr8= X-Google-Smtp-Source: AB8JxZrRA1nun9UQ9Tvthc5AWzhwYcXMdDZ0rsuiDhX+er8iEh1MSk1F5XFzL/zJqRCRjA3yyVGB+A== X-Received: by 2002:a1c:304c:: with SMTP id w73-v6mr8123wmw.4.1525942383076; Thu, 10 May 2018 01:53:03 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:aa7:d5d2:: with SMTP id d18-v6ls3376156eds.0.gmail; Thu, 10 May 2018 01:53:02 -0700 (PDT) X-Received: by 2002:aa7:c611:: with SMTP id h17-v6mr295632edq.7.1525942382523; Thu, 10 May 2018 01:53:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525942382; cv=none; d=google.com; s=arc-20160816; b=yujxR98Bg1HXoBSczbnAvG+uXm+y7S8fMfLE+7lFwP1+2rLfL5JtYJ5aRsscCY3+34 68we9B4hkfB8Z0WV0wqk/nG1PS6uLJ3yCt7+lWKGsaz3W816rCg/5LAug6M9hd0zVt0I 27KViwTeD+DRN123yCYnzaudaeNs7pNn1xB3JvqwkF3Cawn4cVrHM2QAjFH/XEMsImfQ O71rSRg/DZeK+kT6/a/NxnDUTvnl+2WkGnlq2ccmRGph0wJn6zCFVTouiU6oebP7ILXN g2n6fyzeM07ngSY1AGtDzw6WoREswhnVuUvWJwuj+J7gwpuZKwxoV84U4SDa41uZ2SLa +VTw== 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 :arc-authentication-results; bh=vbjSaNSHCHM2f5YMQCk+advRLcqjNS4XwvcDAm2+Kjw=; b=KpBevDqfiG4+T1wMxFTSpEkDEzqckPU7NI6aY8EUiG5tNhIYmyKNacWlvnqpIWhsEv x6GTk3Cq3hXJMcyogoGxdq/glcUiqyBNlBmcCpA3tzkR58djz5mofK/QvyaG08r8DBGK r2goFOKO44Sddwb6h0ORAO65m4FqULZaycHtIstgAX6mLB6IxrE3fD4W/cHKZj21j40u AwIbixrph5RFrd5dK5LOBGhJ0BGUPfWHJmq0C8B5jrtOD3pmnA2L7Ny3PBCeLeU5g8kd Q8jPwR5h+b3RhLS1dwUC+rWTA0Oo/ICc9No8wwczopdMQ8TL4DSfqyQbI+xsi+5kxQtP 3shQ== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de Received: from mail-out.m-online.net (mail-out.m-online.net. [2001:a60:0:28:0:1:25:1]) by gmr-mx.google.com with ESMTPS id v28-v6si23869edd.1.2018.05.10.01.53.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 May 2018 01:53:02 -0700 (PDT) Received-SPF: neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=2001:a60:0:28:0:1:25:1; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 40hRnp1smCz1qwfM; Thu, 10 May 2018 10:53:02 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 40hRnp1lxVz1qrg6; Thu, 10 May 2018 10:53:02 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id SHzJAcOwRiNL; Thu, 10 May 2018 10:53:01 +0200 (CEST) Received: from babic.homelinux.org (host-88-217-136-221.customer.m-online.net [88.217.136.221]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPS; Thu, 10 May 2018 10:53:01 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id DD3594540060; Thu, 10 May 2018 10:53:00 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([127.0.0.1]) by localhost (mail.babic.homelinux.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id V3BSAyKkDecW; Thu, 10 May 2018 10:52:57 +0200 (CEST) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 0C8B14540325; Thu, 10 May 2018 10:52:57 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 2/2] Add a dry-run option to SWUpdate Date: Thu, 10 May 2018 10:52:50 +0200 Message-Id: <1525942370-17439-2-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1525942370-17439-1-git-send-email-sbabic@denx.de> References: <1525942370-17439-1-git-send-email-sbabic@denx.de> X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 2001:a60:0:28:0:1:25:1 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) smtp.mailfrom=sbabic@denx.de 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: , Add a dry run option to allow to run SWUpdate first without any change to Hardware. This can be also used during the build to check the SWU before testing on the target. During a dry-run mode, all handlers are exchanged with the dummy handler, that skips the image without doing anything. Signed-off-by: Stefano Babic --- core/swupdate.c | 7 ++++++- corelib/installer.c | 29 +++++++++++++++++++++++------ corelib/stream_interface.c | 4 ++-- doc/source/swupdate.rst | 2 ++ include/installer.h | 2 +- include/swupdate.h | 1 + 6 files changed, 35 insertions(+), 10 deletions(-) diff --git a/core/swupdate.c b/core/swupdate.c index adc0df1..6228801 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -77,6 +77,7 @@ static struct option long_options[] = { {"syslog", no_argument, NULL, 'L' }, {"select", required_argument, NULL, 'e'}, {"output", required_argument, NULL, 'o'}, + {"dry-to-run", no_argument, NULL, 'n'}, #ifdef CONFIG_SIGNED_IMAGES {"key", required_argument, NULL, 'k'}, #endif @@ -129,6 +130,7 @@ static void usage(char *programname) " -K, --key-aes : the file contains the symmetric key to be used\n" " to decrypt images\n" #endif + " -n, --dry-to-run : run SWUpdate without installing the software\n" " -o, --output : saves the incoming stream\n" " -v, --verbose : be verbose, set maximum loglevel\n" #ifdef CONFIG_HW_COMPATIBILITY @@ -550,7 +552,7 @@ int main(int argc, char **argv) #endif memset(main_options, 0, sizeof(main_options)); memset(image_url, 0, sizeof(image_url)); - strcpy(main_options, "vhi:e:l:Lcf:p:o:"); + strcpy(main_options, "vhni:e:l:Lcf:p:o:"); #ifdef CONFIG_MTD strcat(main_options, "b:"); #endif @@ -666,6 +668,9 @@ int main(int argc, char **argv) case 'l': loglevel = strtoul(optarg, NULL, 10); break; + case 'n': + swcfg.globals.dry_run = 1; + break; case 'L': swcfg.globals.syslog_enabled = 1; break; diff --git a/corelib/installer.c b/corelib/installer.c index ec6f180..3d33fe2 100644 --- a/corelib/installer.c +++ b/corelib/installer.c @@ -215,11 +215,18 @@ static int update_bootloader_env(void) return ret; } -int install_single_image(struct img_type *img) +int install_single_image(struct img_type *img, int dry_run) { struct installer_handler *hnd; int ret; + /* + * in case of dry run, replace the handler + * with a dummy doing nothing + */ + if (dry_run) + strcpy(img->type, "dummy"); + hnd = find_handler(img); if (!hnd) { TRACE("Image Type %s not supported", img->type); @@ -255,6 +262,7 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) struct filehdr fdh; struct stat buf; const char* TMPDIR = get_tmpdir(); + int dry_run = sw->globals.dry_run; /* Extract all scripts, preinstall scripts must be run now */ const char* tmpdir_scripts = get_tmpdirscripts(); @@ -266,10 +274,12 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) } /* Scripts must be run before installing images */ - ret = run_prepost_scripts(&sw->scripts, PREINSTALL); - if (ret) { - ERROR("execute preinstall scripts failed"); - return ret; + if (dry_run) { + ret = run_prepost_scripts(&sw->scripts, PREINSTALL); + if (ret) { + ERROR("execute preinstall scripts failed"); + return ret; + } } /* Update u-boot environment */ @@ -339,7 +349,7 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) free_image(img); ret = 0; } else { - ret = install_single_image(img); + ret = install_single_image(img, dry_run); } if (!fromfile) @@ -350,6 +360,13 @@ int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile) } + /* + * Skip scripts in dry-run mode + */ + if (dry_run) { + return ret; + } + ret = run_prepost_scripts(&sw->scripts, POSTINSTALL); if (ret) { ERROR("execute postinstall scripts failed"); diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c index adc6363..267944f 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -238,7 +238,7 @@ static int extract_files(int fd, struct swupdate_cfg *software) && (!strcmp(part->type, "ubipartition")) ) { TRACE("Need to adjust partition %s before streaming %s", part->volname, img->fname); - if (install_single_image(part)) { + if (install_single_image(part, software->globals.dry_run)) { ERROR("Error adjusting partition %s", part->volname); return -1; } @@ -247,7 +247,7 @@ static int extract_files(int fd, struct swupdate_cfg *software) } } img->fdin = fd; - if (install_single_image(img)) { + if (install_single_image(img, software->globals.dry_run)) { ERROR("Error streaming %s", img->fname); return -1; } diff --git a/doc/source/swupdate.rst b/doc/source/swupdate.rst index 6481a20..630108d 100644 --- a/doc/source/swupdate.rst +++ b/doc/source/swupdate.rst @@ -498,6 +498,8 @@ Command line parameters +-------------+----------+--------------------------------------------+ | -i | string | run SWUpdate with a local .swu file | +-------------+----------+--------------------------------------------+ +| -n | - | run SWUpdate in dry-run mode. | ++-------------+----------+--------------------------------------------+ | -o | string | saves the stream (SWU) on a file | +-------------+----------+--------------------------------------------+ | -v | - | activate verbose output | diff --git a/include/installer.h b/include/installer.h index ab83691..9956d7d 100644 --- a/include/installer.h +++ b/include/installer.h @@ -17,7 +17,7 @@ int check_if_required(struct imglist *list, struct filehdr *pfdh, const char *destdir, struct img_type **pimg); int install_images(struct swupdate_cfg *sw, int fdsw, int fromfile); -int install_single_image(struct img_type *img); +int install_single_image(struct img_type *img, int dry_run); int postupdate(struct swupdate_cfg *swcfg, const char *info); void cleanup_files(struct swupdate_cfg *software); diff --git a/include/swupdate.h b/include/swupdate.h index 6f57fab..36bce0c 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -106,6 +106,7 @@ struct swupdate_global_cfg { char mtdblacklist[SWUPDATE_GENERAL_STRING_SIZE]; int loglevel; int syslog_enabled; + int dry_run; char publickeyfname[SWUPDATE_GENERAL_STRING_SIZE]; char aeskeyfname[SWUPDATE_GENERAL_STRING_SIZE]; char postupdatecmd[SWUPDATE_GENERAL_STRING_SIZE];