From patchwork Mon Oct 14 08:10:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Babic X-Patchwork-Id: 1176056 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:4864:20::53e; helo=mail-ed1-x53e.google.com; envelope-from=swupdate+bncbcxploxj6ikrbcw4sdwqkgqes6na55q@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="NyOq1HtZ"; dkim-atps=neutral Received: from mail-ed1-x53e.google.com (mail-ed1-x53e.google.com [IPv6:2a00:1450:4864:20::53e]) (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 46sBBl2S1Vz9sPc for ; Mon, 14 Oct 2019 19:13:02 +1100 (AEDT) Received: by mail-ed1-x53e.google.com with SMTP id c23sf9731750edb.14 for ; Mon, 14 Oct 2019 01:13:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1571040779; cv=pass; d=google.com; s=arc-20160816; b=ELmZ9PFC2c6hN/9PQCbe655mPYT659HweZCCxtVPpQ2M+HzhXLaHZ0RfBAZMEOSToL D6VGvXXUkzrnJIQJ2I49wYDDE5iBuK0YsKqWrPfCBBlQzhyHVEQIsSF9Jds2QzFyyWXz eCp5WLskrTwT9EVOmKbAyIJ7ZJLS5qs8t5sRjSPOEFba1bPegq4JFsXoEqlG1KpSy47L ZJHGdVNgQKcoUhCMxsm8ijV1h2oq94XLzp4s0p/pc6tZjSP+fCfq5gCj4BTqss5ydGfT uATSBahj6cDqa8ezyqnhzkhd4SamGx5FMuZMx6TFgTwwx9e1U2xMcChsiJtdbw1I556s 6mRQ== 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 :mime-version:sender:dkim-signature; bh=PHwjGkFSdTMvsGzi6Gu6Vvn21YbE3zebBPiGWpAebvM=; b=TEYhYV5DWhhDT6HeL3HUzKMQuT/0G/jX5yWBjxukcOFBbiv57UwSU5DPxnzm/fAX2E MKXWSJkjZPZTBZNUzG8vFhGhDvwD53PievLEezSQevpTE59benK406td6YWG8Zg+/LA9 jqe4Thn1st3X11vOTWEwTIKTLqV7EZERg2ll0N448YTOUZfPsLB1w0XXq5PfCPbM4mVB mFJC3feXb/ViYDoPY0tOZ6XBE2qI0UEe5BEGjD71c26KCwkkqsqomlWxp8YPv3M3Xtpn /eP0cRs0VIww4ecF3Yy24k6B51DvWQWecw67b/I9a04fivuTCSyg0vnOIkCvhcmi6vFo r3Nw== ARC-Authentication-Results: i=2; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 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=PHwjGkFSdTMvsGzi6Gu6Vvn21YbE3zebBPiGWpAebvM=; b=NyOq1HtZaPbA/atTUVEqKKTpkHOGnvVVWJ6IM1BM64DyqCOGRYG9VHWKtQftKX6qbY wCW9zmPOjmxsnyhUroTvNm2l0jB1gRmaPVmseyhwtlEFdTAl89NGwpbsz6T4eEr1vuSB Py9vliTOVr0AjeAq/CFXOqYO0QMrFOmGIDpgDXfBEJdKe6a/5gsy4Br+H1QNx2NlyL4S P5x5fpMCP4LTs1fZENL2hz+kjtlUh206I0k7oZu+zwbjn6vXPH9witx+Kaa6OKuRm7Lh kqJsrk8HPJtIb9AYXI3dWzi32Sa1ubfPhXYaR4FwlWU9ub9LgO6L+EkRaqF9mM109IVQ wAFA== 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=PHwjGkFSdTMvsGzi6Gu6Vvn21YbE3zebBPiGWpAebvM=; b=Z8wtrskSBNYIHOuXCorkgKdyq4ZzOePWFqsDfwIBsRssHvMlx758XeaFO208ayt1S4 7QZhRuX1i121Ws1z84dS7GHmcNr9pcfDCJSUlxeoHFGIvARvor3TCB9nQOkhTpefsk4L 13RiWoa+JIqhyDj2SC1XM1mjfBh2NAM4sJfPbTFFkdxermZzgYvfNb6aEgRO3OaEsUUK B+vdG64lpVyP2jEAnW2EOI1qSzTLD6W/ZF1kfxhgK0HZzgsbmQysi67CIb+e5HIjrHLy ZvAon+N3T2vrsuWo29lZ81APMjrcsWdrkHsIdyBGyHJOYkX4YnYmKopl+F77ETr5+d16 b20A== Sender: swupdate@googlegroups.com X-Gm-Message-State: APjAAAVmAwF2+xTWySRVpkgxUVTgbJdjD5HqGD6e1VmtlQ5+UnUbBPsg zdEx+dftiI7ldp5d+Unw3/8= X-Google-Smtp-Source: APXvYqyQacBaTNg6tgidRpRDKtbshctz+FrYijgtry/Rh1jy3RLIjTsRieFnsy12xZv4guV7rLqhdA== X-Received: by 2002:a17:906:4908:: with SMTP id b8mr27011096ejq.83.1571040779091; Mon, 14 Oct 2019 01:12:59 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: swupdate@googlegroups.com Received: by 2002:a17:906:6957:: with SMTP id c23ls3571951ejs.9.gmail; Mon, 14 Oct 2019 01:12:58 -0700 (PDT) X-Received: by 2002:a17:906:27ca:: with SMTP id k10mr16621327ejc.21.1571040778590; Mon, 14 Oct 2019 01:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571040778; cv=none; d=google.com; s=arc-20160816; b=AdFpx9mQ5Cug72s4fNuW7N2vZno02XflbEMolccnIQBJ/dwEnmoDa9oUyjj2R6S4SQ ME4W06c1mvXc0oo2e91tICFiZpnL3EJXP1LLNmGP0o5ETDO8Db7CfC3WZjYrWSj+Y0e1 XH27xM8fMUYXp9+2ctRcCwCALYp9stC5OyvfIChQfilonvQMa3sfdNal6jeHQPLRzpM9 EQZ2mlOk0U3T6MVstscRYOXTrn+jpS+LQ4fcDnsRkbBewME4fzLbJ1UvTJFUnOXdU7Jh QSVROObrJuxzgK5OR6SN9iRfogwQGFGcbcHmVWrcmusNHIAoOLTPJTTOu53sZRu9+LlO Lvmg== 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; bh=Dpxk3oooK1PCESEcncd2Rji8HKLLWRqp9F0ZRLPASpY=; b=0wlwWTkv5F3eORHFwLGU40iQykUceFrSLbuVHU6cMEphysZjuKZcbNZ1G50LuZ96Hb lR09lHLgUxhvgn+w0MbjOC2bMzNuco72LSjIVcm70bIkkpRADmSdpfSulQib9lGdRAzX qzym4zvPjnb1R3Y0R3brDQcmwjTSMuHgLF3YAvoPU3Cy+qKrN2Yd3aaZIvLmyigyXkv9 VFi/b6rp5qXQMmAk5it7UH/mMt/z4FOvXpHCTD3zTTsZgymz90QO4qqFmn1bg9G2FUjH 6810LYq0rf8SauNpvKSlmn9XqeDUeyVSBrn/4gMy9375fJzTH72pdeCM+svZdOcNf5MR LT5Q== ARC-Authentication-Results: i=1; gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 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. [212.18.0.9]) by gmr-mx.google.com with ESMTPS id q8si863233edn.5.2019.10.14.01.12.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Oct 2019 01:12:58 -0700 (PDT) Received-SPF: neutral (google.com: 212.18.0.9 is neither permitted nor denied by best guess record for domain of sbabic@denx.de) client-ip=212.18.0.9; Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 46sBBf2WyFz1rD8t; Mon, 14 Oct 2019 10:12:58 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 46sBBf2KrGz1qqkC; Mon, 14 Oct 2019 10:12:58 +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 ifnSYcTB2Fdn; Mon, 14 Oct 2019 10:12:57 +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; Mon, 14 Oct 2019 10:12:57 +0200 (CEST) Received: from localhost (mail.babic.homelinux.org [127.0.0.1]) by babic.homelinux.org (Postfix) with ESMTP id 3774A4540432; Mon, 14 Oct 2019 10:12:57 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at babic.homelinux.org Received: from babic.homelinux.org ([IPv6:::1]) by localhost (mail.babic.homelinux.org [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id QXtll3lwMv1H; Mon, 14 Oct 2019 10:12:50 +0200 (CEST) Received: from localhost.localdomain (papero.fritz.box [192.168.178.132]) by babic.homelinux.org (Postfix) with ESMTP id 4AA994540430; Mon, 14 Oct 2019 10:12:50 +0200 (CEST) From: Stefano Babic To: swupdate@googlegroups.com Cc: Stefano Babic Subject: [swupdate] [PATCH] handler: add a copy handler Date: Mon, 14 Oct 2019 10:10:44 +0200 Message-Id: <20191014081044.12972-1-sbabic@denx.de> X-Mailer: git-send-email 2.17.1 X-Original-Sender: sbabic@denx.de X-Original-Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 212.18.0.9 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: , This can be used for incrementing update. It performs a copy from something (a device) before applying some other image. Signed-off-by: Stefano Babic --- handlers/raw_handler.c | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/handlers/raw_handler.c b/handlers/raw_handler.c index 410ef94..ba87191 100644 --- a/handlers/raw_handler.c +++ b/handlers/raw_handler.c @@ -9,6 +9,9 @@ #include #include #include +#include +#include + #include #include @@ -22,6 +25,7 @@ void raw_image_handler(void); void raw_file_handler(void); +void raw_copyimage_handler(void); static int install_raw_image(struct img_type *img, void __attribute__ ((__unused__)) *data) @@ -45,6 +49,58 @@ static int install_raw_image(struct img_type *img, return ret; } +static int copy_raw_image(struct img_type *img, + void __attribute__ ((__unused__)) *data) +{ + int ret; + int fdout, fdin; + struct dict_list *proplist; + struct dict_list_elem *entry; + uint32_t checksum; + unsigned long offset = 0; + size_t size; + + proplist = dict_get_list(&img->properties, "copyfrom"); + + if (!proplist || !(entry = LIST_FIRST(proplist))) { + ERROR("MIssing source device, no copyfrom property"); + return -EINVAL; + } + fdin = open(entry->value, O_RDONLY); + if (fdin < 0) { + TRACE("Device %s cannot be opened: %s", + entry->value, strerror(errno)); + return -ENODEV; + } + + if (ioctl(fdin, BLKGETSIZE64, &size) < 0) { + ERROR("Cannot get size of %s", entry->value); + } + + fdout = open(img->device, O_RDWR); + if (fdout < 0) { + TRACE("Device %s cannot be opened: %s", + img->device, strerror(errno)); + close(fdin); + return -ENODEV; + } + + ret = copyfile(fdin, + &fdout, + size, + &offset, + 0, + 0, /* no skip */ + 0, /* no compressed */ + &checksum, + 0, /* no sha256 */ + 0, /* no encrypted */ + NULL); + + close(fdout); + return ret; +} + static int install_raw_file(struct img_type *img, void __attribute__ ((__unused__)) *data) { @@ -122,3 +178,10 @@ void raw_file_handler(void) register_handler("rawfile", install_raw_file, FILE_HANDLER, NULL); } + +__attribute__((constructor)) +void raw_copyimage_handler(void) +{ + register_handler("rawcopy", copy_raw_image, + IMAGE_HANDLER | NO_DATA_HANDLER, NULL); +}