From patchwork Fri Mar 9 14:24:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 883662 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:4010:c07::23e; helo=mail-lf0-x23e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbqvsrlkqkgqesh4oadq@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="o31eYM99"; dkim-atps=neutral Received: from mail-lf0-x23e.google.com (mail-lf0-x23e.google.com [IPv6:2a00:1450:4010:c07::23e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zyV5f68dSz9sbX for ; Sat, 10 Mar 2018 01:25:09 +1100 (AEDT) Received: by mail-lf0-x23e.google.com with SMTP id 95-v6sf1266156lfv.12 for ; Fri, 09 Mar 2018 06:25:09 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1520605506; cv=pass; d=google.com; s=arc-20160816; b=Z1Ea5FCCq2t8rpbMbS000VTXxoSnwE+fQKHo2ZIJvM1AondpJq95RuYZKJ1DE5u603 D+9heLJ7GerqFWYXWk//evi+FwBtjal5NVeARK6+5+xlSxFT+Ysi91vxRuG/F3Ox64+v WjRSQBJExJD3LjksDN1Tzo9AEYOEJBaJOAebNusMNUJq0otuTy6asRVsBEjAoD90BxyV HrqDwnKJAPi1cdxTdmfc1iR9cJ6Jfm2/zC4iSSd8tbEOppL4Mr2IWdKFUAQf+4yLv4x7 bIBgmshRskxXTPAz8mlDhebA2iBshw/A7CQ82wCt9A8ow1UQfNVswCM1gQeKOy1N2rRI bXlw== 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:message-id:date:subject:cc:to:from :arc-authentication-results:arc-message-signature:mime-version :sender:dkim-signature:arc-authentication-results; bh=ELDc3/60wS7S7MGqSFpXQ0tDR1skSi2OJ0M5S2Nr4ew=; b=sg6zdZ7dyPCnXRtbFysF/aKTmn0sevFZmKa+mWPMsFeda+zedu7ofQDU0+pM1MVheH A7x3Laht7aFC8uMrQyAu02WJfuXzTKmtHgnzf1KzFPa/m73PwO3QCWXSQR2/egvoqUd3 1FoLuF3kjyL1MbNoXt6owpUIpQH44vDezzs7iYy+EpIDUXxyP6YrFjAqQNHTC41baFyp W313HpT77ax1Z853fEw2/tUitXoeuktgbsDOJmjKC+/PlZWQ3jpw47J34ijKSGd4Lw1v ElyP/W6KAQ3tx9TUMKVmKBh+4nwYPNJUvN9bBJfFKJP5Yjd56WnoueG95yBYkDLD63VZ jRnw== 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 :x-original-sender:x-original-authentication-results:precedence :mailing-list:list-id:list-post:list-help:list-archive :list-subscribe:list-unsubscribe; bh=ELDc3/60wS7S7MGqSFpXQ0tDR1skSi2OJ0M5S2Nr4ew=; b=o31eYM99UnSn5z+67I1Eomvzdo7hd313AZ+Cbn7uLQCiS1NynstLNu4mBJobtRaSN6 2KOGZXV3G1BBtxEUpMke5vpAPvdt81+hKg1lnsI6qI9mjXXeOh6CBhVDL5LgYvphtbx+ BWZtTYSHDXKLElq9N4zAePV25HAKbIYv+S5eRoVxlZvQgYB+L+WJDVFfdp2bdTANRSq3 +pJYK4nsV7fwy1DXpEZrZGRq7XqdvdFDGDfGQwYJS7txjv0cJoSF9e9AU7Z6VddZ0erX YbMG5lyNbVOwIOpwmusYf34L4skou1Jmm/P/4gj4tbhr3nMByvb1AyY8U2hM7PXgvAUX ocCw== 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: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=ELDc3/60wS7S7MGqSFpXQ0tDR1skSi2OJ0M5S2Nr4ew=; b=RbuyWPEO2G1PAN3Gy1EHZ1x5Vkpu2kVcwPKd5EyXv6C4xpe+JE4GHAv+wmd1z7mECU vVPgntAac6YmK01RPyEEhYVZDjt9gas2qiDPlA95woHlDV/78m0L1OWVH3XIqYb4evqC zDVzm6aA6JSUkyNzYn/VgJ/gNQtB9b1R1dlNAb2eVrRiHlbsMSt81sw3c9A2bsOWDW5P lVgGuuEuNAv2tIPbLbxCI21wzKjPUUzYObBRskhl02NbIa4GTFH8vAmbp5XANwQWQZdk 1kb/CXoufJHLm1mswbVbKsrJxcbrraUUi5f6zW7xt4//5pDduvndD/73bm5vUv5TFyGv LeYQ== Sender: swupdate@googlegroups.com X-Gm-Message-State: APf1xPBP0/B9BaqdV0LRMq5NpVljlggK4EjQp9/K+NxzbbgdXJjfJDaJ fqv8z7Gq6gp5eELAOEyHhMw= X-Google-Smtp-Source: AG47ELsM39kH8lE6hL85pG9ZFlwv89T6uar+9PEnQx3NEgl14QVBf0k+4h2oQ/QsEt6UFyyBkfeQ8A== X-Received: by 10.46.62.16 with SMTP id l16mr91205lja.5.1520605506654; Fri, 09 Mar 2018 06:25:06 -0800 (PST) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a19:1942:: with SMTP id 63-v6ls843456lfz.6.gmail; Fri, 09 Mar 2018 06:25:05 -0800 (PST) X-Received: by 10.25.206.143 with SMTP id e137mr2163779lfg.21.1520605505723; Fri, 09 Mar 2018 06:25:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520605505; cv=none; d=google.com; s=arc-20160816; b=XyASr3n3Mf7vrCt87TIdVa7wGZikauNZJP6HeYAxjdS78ITeniuDONh058+HLKt0Qo 69AC8jkxGyg7TW2WizCWuT3zBAY9BvcftalhmRDzE+Dwng5iLMQ8r1tR8AYGdhxLaNkr T0tagYQK/CkzMm6JAWSFb5G22eGdVkWVa0tNFV9kN7lwOPc63yfTxTYBBLLALG4tXmla WIlSa0+a3U1eeRDESM804kL62g1Lzya+6V1xLPf/tmCrOPf6LRSpQjLXzGxPL0IJFcnB hesL58sqE7UB8TjrxGT+1h+uhhCcySrs7ywSm6h5W2YiaOhopgdN1p6Iw+iEGQfyr63W ObaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:arc-authentication-results; bh=2TOpnDYwAl989UqFWHbMBsNO/dxDfib8M6lDmaomLbs=; b=Tj4AMCuK1cJqpYdjfBkofl1HEz3tXhjCQxwbssjkn+S2FNhQieRu1qnwSEAHQtAnWe /TFeJD0EpK0ACkeNy7063VnXLzViP4Xn3ylk5R9hlEBqRNl7PJlv7lu4g38sZ+jU0BD/ 8pR2ytFnsmzDag4BxJJSvGVA1pPAWpaam1UupheQUsxC+90mXpzZu0g7S2pAv8wpYEVU ymqG+Fr6r31litGnJUBfqUuDeB6PxnqhsIMnzZ0Onw4Xgnbfw4yhGe80wZZ2xX6JHtlr tQFA2EuXh01tUrq9E6HvFWT00+JAspn0Loj0Kn8uDqB+NTyrFExu6isoKFadFZI2n48M PvdQ== 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 w7-v6si35968lfc.2.2018.03.09.06.25.05 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Mar 2018 06:25:05 -0800 (PST) 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 3zyV5Y03FBz1qtPD; Fri, 9 Mar 2018 15:25:05 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 3zyV5X6wGNz1qqkr; Fri, 9 Mar 2018 15:25:04 +0100 (CET) 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 5Miva0rRtxcp; Fri, 9 Mar 2018 15:25:04 +0100 (CET) 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; Fri, 9 Mar 2018 15:25:03 +0100 (CET) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 7BEC5454041A; Fri, 9 Mar 2018 15:25:03 +0100 (CET) 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 aY1IOhaeDXrB; Fri, 9 Mar 2018 15:25:00 +0100 (CET) Received: from papero.fritz.box (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 28D2E4540417; Fri, 9 Mar 2018 15:25:00 +0100 (CET) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH 1/2] Add command line for output image Date: Fri, 9 Mar 2018 15:24:55 +0100 Message-Id: <1520605496-19708-1-git-send-email-sbabic@denx.de> X-Mailer: git-send-email 2.7.4 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: , Some use cases require to save the incoming stream to a local file. Add command line parameter (-o or --output) Signed-off-by: Stefano Babic --- core/cpio_utils.c | 6 +++++- core/swupdate.c | 13 ++++++++++++- corelib/stream_interface.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ include/swupdate.h | 1 + include/util.h | 1 + 5 files changed, 66 insertions(+), 2 deletions(-) diff --git a/core/cpio_utils.c b/core/cpio_utils.c index 15c1374..79d1c79 100644 --- a/core/cpio_utils.c +++ b/core/cpio_utils.c @@ -76,7 +76,11 @@ static int fill_buffer(int fd, unsigned char *buf, unsigned int nbytes, unsigned return count; } -static int copy_write(void *out, const void *buf, unsigned int len) +/* + * Export this to be used in other modules + * It just copy a buffer to a file + */ +int copy_write(void *out, const void *buf, unsigned int len) { int ret; int fd = (out != NULL) ? *(int *)out : -1; diff --git a/core/swupdate.c b/core/swupdate.c index c5511dc..e08659e 100644 --- a/core/swupdate.c +++ b/core/swupdate.c @@ -76,6 +76,7 @@ static struct option long_options[] = { {"loglevel", required_argument, NULL, 'l'}, {"syslog", no_argument, NULL, 'L' }, {"select", required_argument, NULL, 'e'}, + {"output", required_argument, NULL, 'o'}, #ifdef CONFIG_SIGNED_IMAGES {"key", required_argument, NULL, 'k'}, #endif @@ -548,7 +549,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:"); + strcpy(main_options, "vhi:e:l:Lcf:p:o:"); #ifdef CONFIG_MTD strcat(main_options, "b:"); #endif @@ -658,6 +659,9 @@ int main(int argc, char **argv) strncpy(fname, optarg, sizeof(fname)); opt_i = 1; break; + case 'o': + strncpy(swcfg.output, optarg, sizeof(swcfg.output)); + break; case 'l': loglevel = strtoul(optarg, NULL, 10); break; @@ -750,6 +754,13 @@ int main(int argc, char **argv) exit(1); } + if (opt_i && strlen(swcfg.output)) { + fprintf(stderr, + "Output just from network - do you know cp ?\n"); + usage(argv[0]); + exit(1); + } + #ifdef CONFIG_SURICATTA if (opt_u && (opt_c || opt_i)) { fprintf(stderr, "invalid mode combination with suricatta.\n"); diff --git a/corelib/stream_interface.c b/corelib/stream_interface.c index 91f523f..adc6363 100644 --- a/corelib/stream_interface.c +++ b/corelib/stream_interface.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -281,6 +282,32 @@ static int extract_files(int fd, struct swupdate_cfg *software) } } +static int save_stream(int fdin, const char *output) +{ + char *buf; + int fdout, ret, len; + const int bufsize = 16 * 1024; + + fdout = openfileoutput(output); + if (fdout < 0) + return -1; + + buf = (char *)malloc(bufsize); + if (!buf) + return -ENOMEM; + + for (;;) { + len = read(fdin, buf, bufsize); + if (len == 0) + break; + ret = copy_write(&fdout, buf, len); + if (ret < 0) + return -EIO; + } + + return 0; +} + void *network_initializer(void *data) { int ret; @@ -306,6 +333,26 @@ void *network_initializer(void *data) pthread_mutex_unlock(&stream_mutex); notify(START, RECOVERY_NO_ERROR, INFOLEVEL, "Software Update started !"); + /* + * Check if the stream should be saved + */ + if (strlen(software->output)) { + ret = save_stream(inst.fd, software->output); + if (ret < 0) { + notify(FAILURE, RECOVERY_ERROR, ERRORLEVEL, + "Image invalid or corrupted. Not installing ..."); + continue; + } + + /* + * now replace the file descriptor with + * the saved file + */ + close(inst.fd); + inst.fd = open(software->output, O_RDONLY, S_IRUSR); + } + + #ifdef CONFIG_MTD mtd_cleanup(); scan_mtd_devices(); diff --git a/include/swupdate.h b/include/swupdate.h index 7de096a..10010f5 100644 --- a/include/swupdate.h +++ b/include/swupdate.h @@ -116,6 +116,7 @@ struct swupdate_cfg { char version[SWUPDATE_GENERAL_STRING_SIZE]; char software_set[SWUPDATE_GENERAL_STRING_SIZE]; char running_mode[SWUPDATE_GENERAL_STRING_SIZE]; + char output[SWUPDATE_GENERAL_STRING_SIZE]; struct hw_type hw; struct hwlist hardware; struct swver installed_sw_list; diff --git a/include/util.h b/include/util.h index bff9436..2ac4139 100644 --- a/include/util.h +++ b/include/util.h @@ -131,6 +131,7 @@ char *sdup(const char *str); typedef int (*writeimage) (void *out, const void *buf, unsigned int len); int openfile(const char *filename); +int copy_write(void *out, const void *buf, unsigned int len); int copyfile(int fdin, void *out, unsigned int nbytes, unsigned long *offs, unsigned long long seek, int skip_file, int compressed, uint32_t *checksum,