From patchwork Tue Feb 10 08:49:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dileep Katta X-Patchwork-Id: 44524 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C00262151F for ; Tue, 10 Feb 2015 08:50:49 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id c13sf10882399eek.1 for ; Tue, 10 Feb 2015 00:50:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:cc:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=bqd4Kn4Z72q1qXw0u9BtHf7m25vrIsllAhH9GhUgHR0=; b=mKsoA1HU0gHQ8VcsjV50QrJTQ2qBtJH7aO4F3zitD6OMoh01XBpM00MPceBMlmfoUZ 7jBMEEF4SyZwc0v+8ZWftqJrqnBvL2IwMZ07H45kkSDajFGHBiAfvq83XapYpgQrkFaE Br6VgwgIIGKZawQCtZHYRxzG8T1h6LNz7IojCFeBRNO7Oi1IuyWhvCfpJilYuazw+sB2 kNatr51tNVkduj/h/qDY7qkvTikoRU1lTdXbox+doBybtY0XgaD/whtwhUFq6l9kpNTC zpRifEQj97OMiIQt/RzatQzNNBf1XmYcx6QmJ2i9vqO3hI+qI/KJ6/RJDzcuf2tYNKUD +4Hg== X-Gm-Message-State: ALoCoQmxB35lpOoOQ6AWoK1wwRFKVb6st+0MM2Pf/YeB7B3TNBlmi14MkXVhkcsIyn5u3WKHqAp+ X-Received: by 10.112.35.135 with SMTP id h7mr2539952lbj.23.1423558248612; Tue, 10 Feb 2015 00:50:48 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.234 with SMTP id r10ls610069lal.94.gmail; Tue, 10 Feb 2015 00:50:48 -0800 (PST) X-Received: by 10.152.5.167 with SMTP id t7mr22376850lat.32.1423558248470; Tue, 10 Feb 2015 00:50:48 -0800 (PST) Received: from mail-la0-f54.google.com (mail-la0-f54.google.com. [209.85.215.54]) by mx.google.com with ESMTPS id lc2si3783376lbb.21.2015.02.10.00.50.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Feb 2015 00:50:48 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) client-ip=209.85.215.54; Received: by labhv19 with SMTP id hv19so18671669lab.10 for ; Tue, 10 Feb 2015 00:50:48 -0800 (PST) X-Received: by 10.152.88.44 with SMTP id bd12mr21841852lab.86.1423558248389; Tue, 10 Feb 2015 00:50:48 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.35.133 with SMTP id h5csp472376lbj; Tue, 10 Feb 2015 00:50:47 -0800 (PST) X-Received: by 10.194.185.68 with SMTP id fa4mr49471560wjc.111.1423558247834; Tue, 10 Feb 2015 00:50:47 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id ex1si27994986wjd.71.2015.02.10.00.50.47; Tue, 10 Feb 2015 00:50:47 -0800 (PST) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4214C4B670; Tue, 10 Feb 2015 09:50:46 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Hn4rofK1xhX1; Tue, 10 Feb 2015 09:50:45 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 66C594B662; Tue, 10 Feb 2015 09:50:45 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 59E224B662 for ; Tue, 10 Feb 2015 09:50:40 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 4Up2tq4rO6aH for ; Tue, 10 Feb 2015 09:50:40 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by theia.denx.de (Postfix) with ESMTPS id DC1504A046 for ; Tue, 10 Feb 2015 09:50:37 +0100 (CET) Received: by mail-pa0-f53.google.com with SMTP id lf10so32323975pab.12 for ; Tue, 10 Feb 2015 00:50:35 -0800 (PST) X-Received: by 10.66.156.229 with SMTP id wh5mr3410900pab.119.1423558235251; Tue, 10 Feb 2015 00:50:35 -0800 (PST) Received: from localhost.localdomain ([210.177.145.249]) by mx.google.com with ESMTPSA id z12sm6523764pdk.2.2015.02.10.00.50.32 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 10 Feb 2015 00:50:34 -0800 (PST) From: Dileep Katta To: u-boot@lists.denx.de, trini@ti.com, rob.herring@linaro.org, srae@broadcom.com, l.majewski@samsung.com, angelabaker@ti.com Date: Tue, 10 Feb 2015 16:49:38 +0800 Message-Id: <1423558178-23105-1-git-send-email-dileep.katta@linaro.org> X-Mailer: git-send-email 1.8.3.2 Cc: Dileep Katta Subject: [U-Boot] [PATCH v1 1/1] usb: gadget: fastboot: Add fastboot erase X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: 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" X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: dileep.katta@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.54 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Adds the fastboot erase functionality, to erase a partition specified by name. The erase is performed based on erase group size, to avoid erasing other partitions. The start address and the size is aligned to the erase group size for this. Currently only supports erasing from eMMC. Signed-off-by: Dileep Katta --- Note: The changes are on top of oem command support added by robh@kernel.org common/fb_mmc.c | 58 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/gadget/f_fastboot.c | 23 ++++++++++++++++ include/fb_mmc.h | 1 + 3 files changed, 82 insertions(+) diff --git a/common/fb_mmc.c b/common/fb_mmc.c index 6ea3938..3911989 100644 --- a/common/fb_mmc.c +++ b/common/fb_mmc.c @@ -10,6 +10,7 @@ #include #include #include +#include #ifndef CONFIG_FASTBOOT_GPT_NAME #define CONFIG_FASTBOOT_GPT_NAME GPT_ENTRY_NAME @@ -110,3 +111,60 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, write_raw_image(dev_desc, &info, cmd, download_buffer, download_bytes); } + +void fb_mmc_erase(const char *cmd, char *response) +{ + int ret; + block_dev_desc_t *dev_desc; + disk_partition_t info; + lbaint_t blks, blks_start, blks_size, grp_size; + struct mmc *mmc = find_mmc_device(CONFIG_FASTBOOT_FLASH_MMC_DEV); + + if (mmc == NULL) { + error("invalid mmc device\n"); + fastboot_fail("invalid mmc device"); + return; + } + + /* initialize the response buffer */ + response_str = response; + + dev_desc = get_dev("mmc", CONFIG_FASTBOOT_FLASH_MMC_DEV); + if (!dev_desc || dev_desc->type == DEV_TYPE_UNKNOWN) { + error("invalid mmc device\n"); + fastboot_fail("invalid mmc device"); + return; + } + + ret = get_partition_info_efi_by_name(dev_desc, cmd, &info); + if (ret) { + error("cannot find partition: '%s'\n", cmd); + fastboot_fail("cannot find partition"); + return; + } + + puts("Erasing partition\n"); + + /* Align blocks to erase group size to avoid erasing other partitions */ + grp_size = mmc->erase_grp_size; + blks_start = (info.start + grp_size - 1) & ~(grp_size - 1); + if (info.size >= grp_size) + blks_size = (info.size - (blks_start - info.start)) & + (~(grp_size - 1)); + else + blks_size = 0; + + printf("Erasing blocks " LBAFU " to " LBAFU " due to alignment\n", + blks_start, blks_start + blks_size); + + blks = dev_desc->block_erase(dev_desc->dev, blks_start, blks_size); + if (blks != blks_size) { + error("failed erasing from device %d\n", dev_desc->dev); + fastboot_fail("failed erasing from device"); + return; + } + + printf("........ erased " LBAFU " bytes from '%s'\n", + blks_size * info.blksz, cmd); + fastboot_okay(""); +} diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f7d84bf..a8d8205 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -535,6 +535,26 @@ static void cb_oem(struct usb_ep *ep, struct usb_request *req) } } +static void cb_erase(struct usb_ep *ep, struct usb_request *req) +{ + char *cmd = req->buf; + char response[RESPONSE_LEN]; + + strsep(&cmd, ":"); + if (!cmd) { + error("missing partition name\n"); + fastboot_tx_write_str("FAILmissing partition name"); + return; + } + + strcpy(response, "FAILno flash device defined"); + +#ifdef CONFIG_FASTBOOT_FLASH_MMC_DEV + fb_mmc_erase(cmd, response); +#endif + fastboot_tx_write_str(response); +} + struct cmd_dispatch_info { char *cmd; void (*cb)(struct usb_ep *ep, struct usb_request *req); @@ -566,6 +586,9 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = { { .cmd = "oem", .cb = cb_oem, + }, { + .cmd = "erase", + .cb = cb_erase, }, }; diff --git a/include/fb_mmc.h b/include/fb_mmc.h index 1ad1d13..402ba9b 100644 --- a/include/fb_mmc.h +++ b/include/fb_mmc.h @@ -6,3 +6,4 @@ void fb_mmc_flash_write(const char *cmd, void *download_buffer, unsigned int download_bytes, char *response); +void fb_mmc_erase(const char *cmd, char *response);