From patchwork Fri Apr 6 06:34:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 132933 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1200060ljb; Fri, 6 Apr 2018 12:59:22 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/quxPuDrWkP90sht/7CZyvY3B2/CEKdYxBXPu/Sq8t758lsN5gWWbXzY6V4odlYFhZVCuw X-Received: by 10.80.149.212 with SMTP id x20mr8507450eda.258.1523044762430; Fri, 06 Apr 2018 12:59:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523044762; cv=none; d=google.com; s=arc-20160816; b=SM6RB3zPZv5Pd90+4loO36KCPPaZeM6z9sJVHs/TiABcwpSNbzF2D1Wgo21faR5xpr rfILP6w9O+AFUocPj+qQkeZpZR7ynmtjulQnoCPstjC5n46mI82ujIcGNAGrEHP3ddh1 mlz8H/9ApuQ8Kr5VY40MMQYEJg7mWRiXSz5GBdWn/Iv+6mwNQflslubwHC91ugUx6jSc I1ZM3UoJGpxSaNxFk2w0EDfRrGGDQ9AVamVxl7KySsvK6WNM3Ff9TkNW0C9xUR2hvHzR c+lk0RgORqWPA2qt5e2TpO/Lf/VFwY8FRvqvLJovYrsOlJbjF9GnGA+mBpO44xNTfRCW nY7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=85inoJ/GS/YfenVdkRpBAPR8ORSVi9G31FYn1UJyL+0=; b=gXIOccFmiiBxSc0JGkXIiXDvabjp1UjKDXiFSQLEK5plOp2IWt9vXDFN2BvZrvv18o fmCN184x1yLfq3ZkA1QgH3kRz9UeMxJKElAM1kqhUOfV0u1BFqa2wcRPcWe/2P9Ir8+I t07XrU4j0T9cvhkeWnJCnOz6FNwCcDEJwY+K0UtvMtGoIV22Dhi65YEij4dt2Dq58mJP vVzW0xCHAj5mEFiq274N07g1ahpDtoxGuUPep5xfjY1H1agh9t3LdjluJL9P0ZFYETD5 RxPxyrSthWNxDgFQ+4+k8RjQkcdVWVf/2idIo5Wy8nx9BGjOerVSgvEGTo8hBrmxq9ij Fk0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VtqeVIqv; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 33si2279912edf.27.2018.04.06.12.59.22; Fri, 06 Apr 2018 12:59:22 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=VtqeVIqv; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: by lists.denx.de (Postfix, from userid 105) id 0037AC21DCA; Fri, 6 Apr 2018 19:57:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A5426C21DB6; Fri, 6 Apr 2018 19:57:14 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5C3B5C21C51; Fri, 6 Apr 2018 06:35:05 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by lists.denx.de (Postfix) with ESMTPS id B6C3EC21C29 for ; Fri, 6 Apr 2018 06:35:04 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id b6-v6so64724pla.11 for ; Thu, 05 Apr 2018 23:35:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n0RuumO5To2JJ8WgHS+pjdVn0FaMSuPgByM6zx7Wypo=; b=VtqeVIqv4RISQVYh7OjlbkF6GAfcQxwvg9+MBcDeRe5Q3FSmCKa9uvpGzuwRIF1bAN yA3NqbE9FqBoUfpMbghB46UHX2A2epoRc3mQ7n+sW7ZvAAyyM54/iob2DBkLsBHUPM8d SLpkwHXMpFexK3+uAhgLZry0bkg8gPMm0JVqZpnvo+oIUuO/FkaOGB2JAuJw3ekJtzuW Tj4CD6OtHpOmUa9PNCgFDnENgMdWhOFI+EZ+fdr5bA07bL6mOktyl2dhpNd+h/hLzXPx hy7feL8mo279jB986Vw+bRWFpmmgYg2k9FbbDfoEHlnb++s0gq7tgtroe8ynjwJGGtfE YZKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=n0RuumO5To2JJ8WgHS+pjdVn0FaMSuPgByM6zx7Wypo=; b=kxIDHXY60sGyIr93S1sywvM5VH9pZDx2kcQFIHMQTMX65aD4aN2K6hw8viOiV6wOTB 0OZH7icksfI+5HINz6I3VNL5qhtl5JUPuq8xOmPnh6YscQ8zx1pdh71dgOopfvc3jgLV mAm60jyOwjGsxpfAWW7mJDPdV6X2iPDEcOWJFjZMQvP7AbnodPbm/p76qmL0oRUXPMd0 3//ObEK/vy3UypSuYX6o42iu4CasQ20q9IUidGGuRTFdNaWOIJPWKX2b4CE9XzOq7s7W v0qHapEcbW2eQrN2b3ThQn2ZwkkJiVJscAvOqYxJAn7R7X1HLkKkyD4RbecG8Z+7ostA MN1w== X-Gm-Message-State: ALQs6tCtm2OYNyPUNWfkY+jTFVuku78gs/6rQuSVsXJp38CFZauTPYtV DP6AenpgZ+9y4cQ5hhOAo+9Aw5Hm X-Received: by 2002:a17:902:4324:: with SMTP id i33-v6mr13006649pld.379.1522996503120; Thu, 05 Apr 2018 23:35:03 -0700 (PDT) Received: from localhost.localdomain ([112.196.109.116]) by smtp.gmail.com with ESMTPSA id e130sm17106035pfh.85.2018.04.05.23.34.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 23:35:02 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 6 Apr 2018 12:04:52 +0530 Message-Id: <1522996492-23274-1-git-send-email-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> References: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> X-Mailman-Approved-At: Fri, 06 Apr 2018 19:57:12 +0000 Cc: srae@broadcom.com, masami.hiramatsu@linaro.org, Jassi Brar Subject: [U-Boot] [PATCH 1/3] fastboot: sparse: remove redundant argument to write_sparse_image X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jassi Brar 'sz' has no use for write_sparse_image, remove it simplifying the api. Signed-off-by: Jassi Brar --- common/fb_mmc.c | 3 +-- common/fb_nand.c | 3 +-- common/image-sparse.c | 2 +- include/image-sparse.h | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/common/fb_mmc.c b/common/fb_mmc.c index cf5b77c..6993309 100644 --- a/common/fb_mmc.c +++ b/common/fb_mmc.c @@ -343,8 +343,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, sparse.start); sparse.priv = &sparse_priv; - write_sparse_image(&sparse, cmd, download_buffer, - download_bytes); + write_sparse_image(&sparse, cmd, download_buffer); } else { write_raw_image(dev_desc, &info, cmd, download_buffer, download_bytes); diff --git a/common/fb_nand.c b/common/fb_nand.c index aa28046..6130612 100644 --- a/common/fb_nand.c +++ b/common/fb_nand.c @@ -180,8 +180,7 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, sparse.start); sparse.priv = &sparse_priv; - write_sparse_image(&sparse, cmd, download_buffer, - download_bytes); + write_sparse_image(&sparse, cmd, download_buffer); } else { printf("Flashing raw image at offset 0x%llx\n", part->offset); diff --git a/common/image-sparse.c b/common/image-sparse.c index ddf5772..8ebd647 100644 --- a/common/image-sparse.c +++ b/common/image-sparse.c @@ -51,7 +51,7 @@ void write_sparse_image( struct sparse_storage *info, const char *part_name, - void *data, unsigned sz) + void *data) { lbaint_t blk; lbaint_t blkcnt; diff --git a/include/image-sparse.h b/include/image-sparse.h index b0cc500..d92d0f3 100644 --- a/include/image-sparse.h +++ b/include/image-sparse.h @@ -37,4 +37,4 @@ static inline int is_sparse_image(void *buf) } void write_sparse_image(struct sparse_storage *info, const char *part_name, - void *data, unsigned sz); + void *data); From patchwork Fri Apr 6 06:35:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 132932 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1199887ljb; Fri, 6 Apr 2018 12:59:09 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XEv9ayNQWKIKmMY0myC6kO9tR6YVTBMDjQVEzXR24Y2YUddHXpMZIdoGigsITVMv4lBo0 X-Received: by 10.80.249.133 with SMTP id q5mr8576629edn.171.1523044749124; Fri, 06 Apr 2018 12:59:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523044749; cv=none; d=google.com; s=arc-20160816; b=SiyLHOE9MRoiaeWMNmhZMl7yQkJKsXHOQt1eO5fGkgBE0Nn5N1THUCjLutDOdV4qEk +mbpnmA4Wh5YafqcNbJ90deGZyqOz+0tA80ThlpA2lG1XOIadxMRqx3wqOvLkJh7YT9i 5XSBBQW5v8MqE5HNhTx2kb4czPV2QXNxhRGGW7CwArLH+WeQ018zWyZc/tMgl++0n5vf HUBijrS+PmJO5bGBoRSXUqoRz9hwhb/WSO2FZkX26v03MD+NljHnC/948jNdZdnmCKDz WL7tGyFycwq1rw71RZCUePIMUYS6hZzBbIoMUCAoKJj8yquWZZiYoTkrrcibE+pXJSTj Ldww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=vrdOtswV0x8/Rc71IBATb79BFnGu3EyLToJ0g5xM2Ag=; b=sZ0OEATPfOiY3r/OSkf0j4Hx6GuxCzojCT7ADqKYIbHhuY3hFo1NsKZ20vQp2g99Df 0NByD9yRoBGuwz2fxeSfEMm2RfWDcq1rFmP1aOporFlQB8nIqiYDvMBDX2hngNqtXCbd zxm9mm9aG+AHMgAovV2D7d38k3kPyAScZErkFd8xBLjJfevhPvjGrdRDnaVJUVt10nXT hXFpNgoGNlYTJ0nQUE6o22247KzEZN0gucRkjHZDx3ToNSI9yfk8jgCmxzc/2k3hdsx+ W/P+FT35zogIosjhjKW4ywhcLVa8oBhV6GVmilEnFRxSKvBMr9Fj1I4aDrmNzs/isIO+ /TAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=gzIDzcSK; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id e41si1616593ede.98.2018.04.06.12.59.08; Fri, 06 Apr 2018 12:59:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=gzIDzcSK; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: by lists.denx.de (Postfix, from userid 105) id A5AA0C21DB3; Fri, 6 Apr 2018 19:57:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 9BC4BC21DF3; Fri, 6 Apr 2018 19:57:15 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E6283C21C8B; Fri, 6 Apr 2018 06:35:19 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) by lists.denx.de (Postfix) with ESMTPS id 3088CC21C51 for ; Fri, 6 Apr 2018 06:35:19 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id z5-v6so77071pln.1 for ; Thu, 05 Apr 2018 23:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZvA8XM3X/sfyAaeDf+3w3HXyvAnIDuSIJXi7lvMYUMM=; b=gzIDzcSKY1Jtm6KPoKwTxmm8uWNefr8wln/rLcU03yadg+H908cSXUeJNTJydYjPSb Jqk+LB56+LmRqeWbtCTOfKmaJIu4e7gG41X7FDXZDU8EKk2aas/RxhT125tNRIYH06Vs 3Ir3MTVKDwvSZ8+rdwy+oADNvnk+Oug2GSnyttIW7V/TcekkjAsGm2RtiL1LzYOiQlBG 2fHFETKuApsy0ppePpvvLILJAZrzbUmBU8VAQGCBaVyRE2ybUi3pe/kZO2TK4LxyG4ly jn8rfk0YBe5YRuPewrSq54FlnR1iYtwDObAnJVFLpFf0NHES7mKR1U1qRX20Bp+XG1ry upqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZvA8XM3X/sfyAaeDf+3w3HXyvAnIDuSIJXi7lvMYUMM=; b=MdSaFZ5qzV5vkEfjlV0f4E9ULBI2PEOD5XHUS8HJUBjbAj2VnxT5H/kHOnazu13EsJ ftCAOmljQlLEPN63YOWe4I1Ne3V8xCzlsIJCymlIWFAr7dIBRKr4bvY6TpMvTkX9gM0n gHO+Q9Jutuc6KEfairFxhWCBAy7lKaAKo71lbTmISeGoxBlePHmgPWnPH19bsOAQk+mE F7g6Br4VS2GjGJfFSmBF1PI0E4sfl2vjIXRLfAC8/94ldpHyH1bRn3vGClKX1CUayaw1 BEfGOvRaVgePJpDqASPro/NCHObYRgc1shuha6alO/6Hnft84WZYWJBM5jcVUq+zaKdq +jRg== X-Gm-Message-State: AElRT7H0Od5DHt8sxQztN7jcHuiQ0VtEj+Ao6LywMsXzLrwLDlmHWbSh TvYSUzpG1L4GNzyYXr8OY93xFjuY X-Received: by 2002:a17:902:8:: with SMTP id 8-v6mr25614469pla.291.1522996517548; Thu, 05 Apr 2018 23:35:17 -0700 (PDT) Received: from localhost.localdomain ([112.196.109.116]) by smtp.gmail.com with ESMTPSA id x3sm14091655pgv.86.2018.04.05.23.35.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 23:35:16 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 6 Apr 2018 12:05:09 +0530 Message-Id: <1522996509-23324-1-git-send-email-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> References: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> X-Mailman-Approved-At: Fri, 06 Apr 2018 19:57:13 +0000 Cc: srae@broadcom.com, masami.hiramatsu@linaro.org, Jassi Brar Subject: [U-Boot] [PATCH 2/3] fastboot: sparse: make write_sparse_image useable for non-fastboot X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jassi Brar write_sparse_image could be useful for non-fastboot users. For ex a platform, without usb-device/fastboot support, could get sparse images over tftp and write using the mmc command. Or non-android systems could also leverage the sparse format. Towards that, this patch removes anything fastboot specific from the write_sparse_image implementation. Which includes making the function return integer as error code and calls for fastboot logging via an optional callback function 'mssg'. Signed-off-by: Jassi Brar --- common/fb_mmc.c | 6 ++++- common/fb_nand.c | 5 +++- common/image-sparse.c | 69 +++++++++++++++++++++++--------------------------- include/image-sparse.h | 6 +++-- 4 files changed, 45 insertions(+), 41 deletions(-) diff --git a/common/fb_mmc.c b/common/fb_mmc.c index 6993309..d14b22f 100644 --- a/common/fb_mmc.c +++ b/common/fb_mmc.c @@ -330,6 +330,7 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, if (is_sparse_image(download_buffer)) { struct fb_mmc_sparse sparse_priv; struct sparse_storage sparse; + int err; sparse_priv.dev_desc = dev_desc; @@ -338,12 +339,15 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, sparse.size = info.size; sparse.write = fb_mmc_sparse_write; sparse.reserve = fb_mmc_sparse_reserve; + sparse.mssg = fastboot_fail; printf("Flashing sparse image at offset " LBAFU "\n", sparse.start); sparse.priv = &sparse_priv; - write_sparse_image(&sparse, cmd, download_buffer); + err = write_sparse_image(&sparse, cmd, download_buffer); + if (!err) + fastboot_okay(""); } else { write_raw_image(dev_desc, &info, cmd, download_buffer, download_bytes); diff --git a/common/fb_nand.c b/common/fb_nand.c index 6130612..ad2b112 100644 --- a/common/fb_nand.c +++ b/common/fb_nand.c @@ -175,12 +175,15 @@ void fb_nand_flash_write(const char *cmd, void *download_buffer, sparse.size = part->size / sparse.blksz; sparse.write = fb_nand_sparse_write; sparse.reserve = fb_nand_sparse_reserve; + sparse.mssg = fastboot_fail; printf("Flashing sparse image at offset " LBAFU "\n", sparse.start); sparse.priv = &sparse_priv; - write_sparse_image(&sparse, cmd, download_buffer); + ret = write_sparse_image(&sparse, cmd, download_buffer); + if (!ret) + fastboot_okay(""); } else { printf("Flashing raw image at offset 0x%llx\n", part->offset); diff --git a/common/image-sparse.c b/common/image-sparse.c index 8ebd647..9223b9a 100644 --- a/common/image-sparse.c +++ b/common/image-sparse.c @@ -41,7 +41,6 @@ #include #include #include -#include #include @@ -49,9 +48,10 @@ #define CONFIG_FASTBOOT_FLASH_FILLBUF_SIZE (1024 * 512) #endif -void write_sparse_image( - struct sparse_storage *info, const char *part_name, - void *data) +static void default_log(const char *ignored) {} + +int write_sparse_image(struct sparse_storage *info, + const char *part_name, void *data) { lbaint_t blk; lbaint_t blkcnt; @@ -83,6 +83,9 @@ void write_sparse_image( data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t)); } + if (!info->mssg) + info->mssg = default_log; + debug("=== Sparse Image Header ===\n"); debug("magic: 0x%x\n", sparse_header->magic); debug("major_version: 0x%x\n", sparse_header->major_version); @@ -101,8 +104,8 @@ void write_sparse_image( if (offset) { printf("%s: Sparse image block size issue [%u]\n", __func__, sparse_header->blk_sz); - fastboot_fail("sparse image block size issue"); - return; + info->mssg("sparse image block size issue"); + return -1; } puts("Flashing Sparse Image\n"); @@ -136,18 +139,16 @@ void write_sparse_image( case CHUNK_TYPE_RAW: if (chunk_header->total_sz != (sparse_header->chunk_hdr_sz + chunk_data_sz)) { - fastboot_fail( - "Bogus chunk size for chunk type Raw"); - return; + info->mssg("Bogus chunk size for chunk type Raw"); + return -1; } if (blk + blkcnt > info->start + info->size) { printf( "%s: Request would exceed partition size!\n", __func__); - fastboot_fail( - "Request would exceed partition size!"); - return; + info->mssg("Request would exceed partition size!"); + return -1; } blks = info->write(info, blk, blkcnt, data); @@ -156,9 +157,8 @@ void write_sparse_image( printf("%s: %s" LBAFU " [" LBAFU "]\n", __func__, "Write failed, block #", blk, blks); - fastboot_fail( - "flash write failure"); - return; + info->mssg("flash write failure"); + return -1; } blk += blks; bytes_written += blkcnt * info->blksz; @@ -169,9 +169,8 @@ void write_sparse_image( case CHUNK_TYPE_FILL: if (chunk_header->total_sz != (sparse_header->chunk_hdr_sz + sizeof(uint32_t))) { - fastboot_fail( - "Bogus chunk size for chunk type FILL"); - return; + info->mssg("Bogus chunk size for chunk type FILL"); + return -1; } fill_buf = (uint32_t *) @@ -180,9 +179,8 @@ void write_sparse_image( info->blksz * fill_buf_num_blks, ARCH_DMA_MINALIGN)); if (!fill_buf) { - fastboot_fail( - "Malloc failed for: CHUNK_TYPE_FILL"); - return; + info->mssg("Malloc failed for: CHUNK_TYPE_FILL"); + return -1; } fill_val = *(uint32_t *)data; @@ -198,9 +196,8 @@ void write_sparse_image( printf( "%s: Request would exceed partition size!\n", __func__); - fastboot_fail( - "Request would exceed partition size!"); - return; + info->mssg("Request would exceed partition size!"); + return -1; } for (i = 0; i < blkcnt;) { @@ -214,10 +211,9 @@ void write_sparse_image( __func__, "Write failed, block #", blk, j); - fastboot_fail( - "flash write failure"); + info->mssg("flash write failure"); free(fill_buf); - return; + return -1; } blk += blks; i += j; @@ -235,9 +231,8 @@ void write_sparse_image( case CHUNK_TYPE_CRC32: if (chunk_header->total_sz != sparse_header->chunk_hdr_sz) { - fastboot_fail( - "Bogus chunk size for chunk type Dont Care"); - return; + info->mssg("Bogus chunk size for chunk type Dont Care"); + return -1; } total_blocks += chunk_header->chunk_sz; data += chunk_data_sz; @@ -246,8 +241,8 @@ void write_sparse_image( default: printf("%s: Unknown chunk type: %x\n", __func__, chunk_header->chunk_type); - fastboot_fail("Unknown chunk type"); - return; + info->mssg("Unknown chunk type"); + return -1; } } @@ -255,10 +250,10 @@ void write_sparse_image( total_blocks, sparse_header->total_blks); printf("........ wrote %u bytes to '%s'\n", bytes_written, part_name); - if (total_blocks != sparse_header->total_blks) - fastboot_fail("sparse image write failure"); - else - fastboot_okay(""); + if (total_blocks != sparse_header->total_blks) { + info->mssg("sparse image write failure"); + return -1; + } - return; + return 0; } diff --git a/include/image-sparse.h b/include/image-sparse.h index d92d0f3..d2b1c2e 100644 --- a/include/image-sparse.h +++ b/include/image-sparse.h @@ -23,6 +23,8 @@ struct sparse_storage { lbaint_t (*reserve)(struct sparse_storage *info, lbaint_t blk, lbaint_t blkcnt); + + void (*mssg)(const char *str); }; static inline int is_sparse_image(void *buf) @@ -36,5 +38,5 @@ static inline int is_sparse_image(void *buf) return 0; } -void write_sparse_image(struct sparse_storage *info, const char *part_name, - void *data); +int write_sparse_image(struct sparse_storage *info, const char *part_name, + void *data); From patchwork Fri Apr 6 06:35:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jassi Brar X-Patchwork-Id: 132934 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp1201191ljb; Fri, 6 Apr 2018 13:00:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx49PeXuYBztXBvQxN6LJ9XEivVqTAmUWvfcifWFhWW0gqNbFhTE2pNHHb4Y031ZfFqslg4Es X-Received: by 10.80.147.89 with SMTP id n25mr8543842eda.189.1523044828007; Fri, 06 Apr 2018 13:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523044828; cv=none; d=google.com; s=arc-20160816; b=yg4JUSi2XJc22BCkTNts0umtilt8na6bi0ET7ph+xLLZNzgaISRynJ6Gbz2pj6sV7F 0pMvNDOoUmF5/8yg2MQWG3I3D47OTbe2A1yp2XNA4XyoDb2ePVMHai6MwcfrELfheK2H OIDnjV0xtEKBGFXnQP3oU8b8CVzWnvuttP+gX1hQSbVaI3nVoq93/Z80D8f2F/og2qfy afceW9CyD5BPeDlmo3MndeCLhJI/TTAwBPQL04yWHinAxC5FFYPM+m1OUgctBUQBlvY5 5OKhWi41xsNb0EWElWD+GeLD4O3uCpuGysEH78GoxKP87f63rj6GYvPxvuSDCChpRAWq WtNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:references:in-reply-to:message-id :date:to:from:dkim-signature:arc-authentication-results; bh=Uk6FkxlpIDQgB8oihQxFcbcqbRe77HfCalKIomxztVc=; b=0bUZL5Y9TBfw0RNFPUYLdtxeVIKm+WlCBuIjxBWxeppKmOrx0u0x9q2Vd6y52Ex6WF 2nWko8LLdKoTf3w+Qlwqy4hXFAQS0LDGwqIWwK+iWxMpQYvMbm8ajrqsyhYzyYQL2Xcv KgJwmLCOXmLtRQxP6Q5U6pdBh5DE7Pe6e3h/MJGDQair4m5OSOqFruDN8wMOH77yt4Tb hcv4T4pE/ODQq2d2t2hLFXxdhscV1nVjOSXfiIOA2/1MY1Pl+syD8Wlyhji3OPNA+Zbh DghdBxM3lfcIeUddw5aaBPrDLkv353R1dsI4wvL6Jg3E9F0y09OeTdURL9JVHR1XzkuD 7QsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=d25l5S24; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id j4si2907866edd.324.2018.04.06.13.00.27; Fri, 06 Apr 2018 13:00:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=d25l5S24; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: by lists.denx.de (Postfix, from userid 105) id 9EA37C21DEC; Fri, 6 Apr 2018 19:58:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4ED11C21DDC; Fri, 6 Apr 2018 19:57:17 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CF5D8C21C51; Fri, 6 Apr 2018 06:35:34 +0000 (UTC) Received: from mail-pf0-f195.google.com (mail-pf0-f195.google.com [209.85.192.195]) by lists.denx.de (Postfix) with ESMTPS id 2D9ACC21C29 for ; Fri, 6 Apr 2018 06:35:34 +0000 (UTC) Received: by mail-pf0-f195.google.com with SMTP id h69so75515pfe.13 for ; Thu, 05 Apr 2018 23:35:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YSX0mx4i3T5xUqKc63ITR6HmUSRuROxHka5us3L57SI=; b=d25l5S24glCxiYoyWG7fYMsdRce31i5iBZoKZoTsFfa87aDeK4fWvqHAD5WiwEaQL3 Fwe7+39UP2hnIg+OUUViDhpNDzlyllsK2hD6OYVPUtzbBCS2hjfhstWXJBtv1C63i476 myumH2j7Z+nVRG92EbKtgd1OP5B1LrhWOA8k9a3rFdSd1ifn9oEPgdePRWcIikmDT5zZ 7iZTu6V3CkRa0sxvsEHv14Lt6TqiTIioVMarRdsagPliR0Du/Gl+ebhI3vFSjufhm6qU L0sLlkYDvrEstmsMBVBnfUiJtk3lOIpgUYX1Q9U4BDkFJTix3qyGgt98+dkPTPfXSw5c jt3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YSX0mx4i3T5xUqKc63ITR6HmUSRuROxHka5us3L57SI=; b=Pjm4mP5DiItiFzkf69IDSF8ln3kEoj74g5wbSALhUblRhEBAnNU87XjAoNQk8VqT/F SC/QuSmtTi30Xd3yqhaoK4pVlAr5+shwoj0ruAUerj8dKeM+ZnSUgPhUz/nmE11oZsQt 8VhJUv8tPdlum+Sk5YVk84F22tJBNMr/HmPdZhtyCeODNUr+L8ZfB8Nrhi04nDeQ1Fea Ff8whCoQ7Vkl4tHJnEykE2LAFZqw2u2+//jUHDZthEoRIE8ALFwMRwDj8MMtdC6qWJhx eXEACVYY6ErO1RZTRhwO7Kv0mTyjVB/X+v8oNsspdQIJTWThS5E0zk4pYusAPDZXBi52 9ZDA== X-Gm-Message-State: AElRT7Ga+75uGp1y2yLMA4NwKBD0pzuCpGmyjeFQTwt7Vg/PY+i/bK7c 6dSljMbqBiRw08VTsxqOnH+j5ss8 X-Received: by 10.99.141.200 with SMTP id z191mr16791383pgd.418.1522996532130; Thu, 05 Apr 2018 23:35:32 -0700 (PDT) Received: from localhost.localdomain ([112.196.109.116]) by smtp.gmail.com with ESMTPSA id a12sm9173027pfe.78.2018.04.05.23.35.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 23:35:31 -0700 (PDT) From: jassisinghbrar@gmail.com To: u-boot@lists.denx.de, trini@konsulko.com Date: Fri, 6 Apr 2018 12:05:24 +0530 Message-Id: <1522996524-23376-1-git-send-email-jassisinghbrar@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> References: <1522996457-23191-1-git-send-email-jassisinghbrar@gmail.com> X-Mailman-Approved-At: Fri, 06 Apr 2018 19:57:13 +0000 Cc: srae@broadcom.com, masami.hiramatsu@linaro.org, Jassi Brar Subject: [U-Boot] [PATCH 3/3] mmc: support writing sparse images X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" From: Jassi Brar Provide an alternate path for sparse-images to be written to MMC. For example, via tftp on platforms that don't support fastboot protocol. Or when an image is to written at some offset, rather than the start of a partition. Signed-off-by: Jassi Brar --- cmd/mmc.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/cmd/mmc.c b/cmd/mmc.c index 58fdc36..5ced6e7 100644 --- a/cmd/mmc.c +++ b/cmd/mmc.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include static int curr_device = -1; @@ -308,6 +310,69 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag, } #if CONFIG_IS_ENABLED(MMC_WRITE) +static lbaint_t mmc_sparse_write(struct sparse_storage *info, lbaint_t blk, + lbaint_t blkcnt, const void *buffer) +{ + struct blk_desc *dev_desc = info->priv; + + return blk_dwrite(dev_desc, blk, blkcnt, buffer); +} + +static lbaint_t mmc_sparse_reserve(struct sparse_storage *info, + lbaint_t blk, lbaint_t blkcnt) +{ + return blkcnt; +} + +static int do_mmc_sparse_write(cmd_tbl_t *cmdtp, int flag, + int argc, char * const argv[]) +{ + struct sparse_storage sparse; + struct blk_desc *dev_desc; + struct mmc *mmc; + char dest[11]; + void *addr; + u32 blk; + + if (argc != 3) + return CMD_RET_USAGE; + + addr = (void *)simple_strtoul(argv[1], NULL, 16); + blk = simple_strtoul(argv[2], NULL, 16); + + if (!is_sparse_image(addr)) { + printf("Not a sparse image\n"); + return CMD_RET_FAILURE; + } + + mmc = init_mmc_device(curr_device, false); + if (!mmc) + return CMD_RET_FAILURE; + + printf("\nMMC Sparse write: dev # %d, block # %d ... ", + curr_device, blk); + + if (mmc_getwp(mmc) == 1) { + printf("Error: card is write protected!\n"); + return CMD_RET_FAILURE; + } + + dev_desc = mmc_get_blk_desc(mmc); + sparse.priv = dev_desc; + sparse.blksz = 512; + sparse.start = blk; + sparse.size = dev_desc->lba - blk; + sparse.write = mmc_sparse_write; + sparse.reserve = mmc_sparse_reserve; + sparse.mssg = NULL; + sprintf(dest, "0x%08lX", sparse.start * sparse.blksz); + + if (write_sparse_image(&sparse, dest, addr)) + return CMD_RET_FAILURE; + else + return CMD_RET_SUCCESS; +} + static int do_mmc_write(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { @@ -802,6 +867,7 @@ static cmd_tbl_t cmd_mmc[] = { U_BOOT_CMD_MKENT(read, 4, 1, do_mmc_read, "", ""), #if CONFIG_IS_ENABLED(MMC_WRITE) U_BOOT_CMD_MKENT(write, 4, 0, do_mmc_write, "", ""), + U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""), U_BOOT_CMD_MKENT(erase, 3, 0, do_mmc_erase, "", ""), #endif U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), @@ -858,6 +924,7 @@ U_BOOT_CMD( "info - display info of the current MMC device\n" "mmc read addr blk# cnt\n" "mmc write addr blk# cnt\n" + "mmc swrite addr blk#\n" "mmc erase blk# cnt\n" "mmc rescan\n" "mmc part - lists available partition on current mmc device\n"