From patchwork Tue Feb 17 13:18:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dileep Katta X-Patchwork-Id: 44746 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 805F221557 for ; Tue, 17 Feb 2015 13:18:51 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf19627516wib.2 for ; Tue, 17 Feb 2015 05:18:50 -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:in-reply-to :references: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=fyxffODd1IdRvgWqru+c5DgT/0n90+GbuqgvW1s3MDg=; b=K60TzvFPMUVKaK77kjKC8c6S3tsOOuP0iNZsEvDRljZzCeO6tgk3QLjhdEQ2sxpJcO TOVK89BrPSaRCNMAK+MPWNkN5g+UohK03VBOvdvYdu3ti3l4BusICitXKwJKq90Rt5Kk Y8j3nvmZVMzte79/r8zdgyp1833upCTbJSumHTFDmX9b2tdRTANW32KForBis9whNxhI kpAmtKxTCmh7xKIyMReTN3ZYWmW0PRNyHQibA3eZw59ScqIC0PqmZ490Rr0EImCGP9Sm l82T8xZgYdCMNEd/ntMkiOnQiUo6Fd2DAUMClLfHVOcWR/JNVgivwlk8MC0S+537WVBJ M8Tw== X-Gm-Message-State: ALoCoQkwpjA1/fX12YWP/Dvb/gDwPIp7yfgxctPWN4OMNzx1PBs7LDhIKMAicVZUfeyoYqCmBz6s X-Received: by 10.180.186.101 with SMTP id fj5mr1766198wic.1.1424179130811; Tue, 17 Feb 2015 05:18:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.71 with SMTP id i7ls499564lai.44.gmail; Tue, 17 Feb 2015 05:18:50 -0800 (PST) X-Received: by 10.112.157.100 with SMTP id wl4mr28532716lbb.108.1424179130488; Tue, 17 Feb 2015 05:18:50 -0800 (PST) Received: from mail-lb0-f178.google.com (mail-lb0-f178.google.com. [209.85.217.178]) by mx.google.com with ESMTPS id oe5si10852278lbb.2.2015.02.17.05.18.50 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Feb 2015 05:18:50 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.178 as permitted sender) client-ip=209.85.217.178; Received: by lbiw7 with SMTP id w7so4347199lbi.10 for ; Tue, 17 Feb 2015 05:18:50 -0800 (PST) X-Received: by 10.112.56.139 with SMTP id a11mr28276715lbq.36.1424179130345; Tue, 17 Feb 2015 05:18:50 -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 h5csp2200017lbj; Tue, 17 Feb 2015 05:18:49 -0800 (PST) X-Received: by 10.180.81.233 with SMTP id d9mr42517574wiy.5.1424179129401; Tue, 17 Feb 2015 05:18:49 -0800 (PST) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id ds9si15549693wib.65.2015.02.17.05.18.48; Tue, 17 Feb 2015 05:18:49 -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 E97324B7C6; Tue, 17 Feb 2015 14:18:47 +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 hhNoY6xC9brX; Tue, 17 Feb 2015 14:18:47 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5FD774B7C2; Tue, 17 Feb 2015 14:18:47 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 91A664B7A9 for ; Tue, 17 Feb 2015 14:18:44 +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 V05FlrXJd62q for ; Tue, 17 Feb 2015 14:18:44 +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-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by theia.denx.de (Postfix) with ESMTPS id 1ED314B796 for ; Tue, 17 Feb 2015 14:18:41 +0100 (CET) Received: by padfb1 with SMTP id fb1so6280959pad.8 for ; Tue, 17 Feb 2015 05:18:40 -0800 (PST) X-Received: by 10.68.203.226 with SMTP id kt2mr47900446pbc.141.1424179120149; Tue, 17 Feb 2015 05:18:40 -0800 (PST) Received: from localhost.localdomain ([106.51.139.45]) by mx.google.com with ESMTPSA id k14sm17584865pbq.53.2015.02.17.05.18.37 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 17 Feb 2015 05:18:39 -0800 (PST) From: Dileep Katta To: u-boot@lists.denx.de, robherring2@gmail.com, trini@ti.com, rob.herring@linaro.org, srae@broadcom.com, l.majewski@samsung.com, angelabaker@ti.com Date: Tue, 17 Feb 2015 18:48:23 +0530 Message-Id: <1424179103-21702-1-git-send-email-dileep.katta@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: References: Cc: Dileep Katta Subject: [U-Boot] [PATCH v2 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.217.178 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 --- Changes in v2: - Removed unnecessary newline for error() messages - Made the command conditional on CONFIG_FASTBOOT_FLASH - Updated doc/README.android-fastboot to reflect the support common/fb_mmc.c | 56 +++++++++++++++++++++++++++++++++++++++++ doc/README.android-fastboot | 5 ++-- drivers/usb/gadget/f_fastboot.c | 25 ++++++++++++++++++ include/fb_mmc.h | 1 + 4 files changed, 84 insertions(+), 3 deletions(-) diff --git a/common/fb_mmc.c b/common/fb_mmc.c index 6ea3938..513b7ab 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,58 @@ 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"); + 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"); + fastboot_fail("invalid mmc device"); + return; + } + + ret = get_partition_info_efi_by_name(dev_desc, cmd, &info); + if (ret) { + error("cannot find partition: '%s'", cmd); + fastboot_fail("cannot find partition"); + return; + } + + /* 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", 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/doc/README.android-fastboot b/doc/README.android-fastboot index 1677609..5526a43 100644 --- a/doc/README.android-fastboot +++ b/doc/README.android-fastboot @@ -6,9 +6,8 @@ Overview The protocol that is used over USB is described in README.android-fastboot-protocol in same directory. -The current implementation does not yet support the erase command or the -"oem format" command, and there is minimal support for the flash command; -it only supports eMMC devices. +The current implementation is a minimal support of the erase command,the +"oem format" command and flash command;it only supports eMMC devices. Client installation =================== diff --git a/drivers/usb/gadget/f_fastboot.c b/drivers/usb/gadget/f_fastboot.c index f7d84bf..6138906 100644 --- a/drivers/usb/gadget/f_fastboot.c +++ b/drivers/usb/gadget/f_fastboot.c @@ -535,6 +535,28 @@ static void cb_oem(struct usb_ep *ep, struct usb_request *req) } } +#ifdef CONFIG_FASTBOOT_FLASH +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"); + 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); +} +#endif + struct cmd_dispatch_info { char *cmd; void (*cb)(struct usb_ep *ep, struct usb_request *req); @@ -561,6 +583,9 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = { { .cmd = "flash", .cb = cb_flash, + }, { + .cmd = "erase", + .cb = cb_erase, }, #endif { 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);