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"