From patchwork Thu Jul 12 11:05:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alberto Panizzo X-Patchwork-Id: 942928 X-Patchwork-Delegate: philipp.tomsich@theobroma-systems.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=amarulasolutions.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=amarulasolutions.com header.i=@amarulasolutions.com header.b="YJjVDGkK"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41RCxY4fZYz9rxx for ; Thu, 12 Jul 2018 21:14:09 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 4BB75C21F49; Thu, 12 Jul 2018 11:11:28 +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=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 39132C21FB7; Thu, 12 Jul 2018 11:07:12 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B7170C21F37; Thu, 12 Jul 2018 11:07:06 +0000 (UTC) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by lists.denx.de (Postfix) with ESMTPS id A3BEBC21F9A for ; Thu, 12 Jul 2018 11:07:00 +0000 (UTC) Received: by mail-wm0-f67.google.com with SMTP id z13-v6so5593765wma.5 for ; Thu, 12 Jul 2018 04:07:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=sR6BwZ9/Cm7AKWHrJaO33BAJ98uow12ZCpDjjs8UI2Y=; b=YJjVDGkKLJWgjubENcZfAr0qiMwCNxrsbWsh6Z7E9imvqyGWvJqC1IqePLaX0S+wOc UJpyrQqhQ0cHfUTGYmfHAXI/TZfg92TOW0EtCJyu+14V0IjAp4myymL46Gmw91BvsEqI DUzyoONUEMjh062ly4QSR7nraJbYixxl7DJtE= 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=sR6BwZ9/Cm7AKWHrJaO33BAJ98uow12ZCpDjjs8UI2Y=; b=ifEA3skEO2hswjsDiVWeC1K0Z0+xC7rXs7NYkM9k+N85EeY3NyK7JmHDj260qIA05j jb+PNJh3/1mkYbTCMAzNpqzxc2KvMbnvPU0TNG7AJJW2bThgwhxfL/BMy1o4nZzbtHLf 8/V7lw8RNVSumg2GeF9U21vn6JaBfU4faxNFKbzlO0u9ryvo4U1150/2i3mzZ0bg8sBI W6QoQvy/Ps7Wv+XhStCvmDdp4FhPfJ+qTVxObJHuyzfGwHuyxBpj1ivt1WH0r2I9ajtH GFHhVAsqvd1LET4vqNWVXnSQUqSI2lAYCODA5aJPiorREa8vYZQYuP8Z8exCGarWkIj0 FQXw== X-Gm-Message-State: AOUpUlG8exN6F6B2iXcTe4QkG+mhdjCtPxKWja2Qxi/iLMMhuLCnf/iQ OxPSPJbtvmof6wgXEHR344sLa0jC X-Google-Smtp-Source: AAOMgpd1GV02h3ZdmdB0x0RxuwYQ2TW0Z7ilVAxscDCNK3prwUjfmvo5gOLqbB2YlIpH3WbpSkSSXw== X-Received: by 2002:a1c:5fc1:: with SMTP id t184-v6mr1066499wmb.8.1531393620161; Thu, 12 Jul 2018 04:07:00 -0700 (PDT) Received: from localhost.localdomain (host-9473-86-113.popwifi.it. [94.73.86.113]) by smtp.googlemail.com with ESMTPSA id t140-v6sm6982421wmd.14.2018.07.12.04.06.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 12 Jul 2018 04:06:59 -0700 (PDT) From: Alberto Panizzo To: u-boot@lists.denx.de Date: Thu, 12 Jul 2018 13:05:45 +0200 Message-Id: <1531393559-28958-6-git-send-email-alberto@amarulasolutions.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1531393559-28958-1-git-send-email-alberto@amarulasolutions.com> References: <1531393559-28958-1-git-send-email-alberto@amarulasolutions.com> Cc: Marek Vasut Subject: [U-Boot] [PATCH v3 5/9] usb: rockchip: implement K_FW_LBA_ERASE_10 command 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" This command is part of the write partition sequence performed by rkdeveloptool: one partition is first completely erased and than wrote. Signed-off-by: Alberto Panizzo Reviewed-by: Simon Glass Reviewed-by: Philipp Tomsich --- arch/arm/include/asm/arch-rockchip/f_rockusb.h | 1 + doc/README.rockusb | 1 + drivers/usb/gadget/f_rockusb.c | 48 ++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/arch/arm/include/asm/arch-rockchip/f_rockusb.h b/arch/arm/include/asm/arch-rockchip/f_rockusb.h index 3f2e763..9772321 100644 --- a/arch/arm/include/asm/arch-rockchip/f_rockusb.h +++ b/arch/arm/include/asm/arch-rockchip/f_rockusb.h @@ -63,6 +63,7 @@ K_FW_LOW_FORMAT = 0x1C, K_FW_SET_RESET_FLAG = 0x1E, K_FW_SPI_READ_10 = 0x21, K_FW_SPI_WRITE_10 = 0x22, +K_FW_LBA_ERASE_10 = 0x25, K_FW_SESSION = 0X30, K_FW_RESET = 0xff, diff --git a/doc/README.rockusb b/doc/README.rockusb index 7f58296..66437e1 100644 --- a/doc/README.rockusb +++ b/doc/README.rockusb @@ -49,6 +49,7 @@ Current set of rkdeveloptool commands supported: - td : Test Device Ready - rl : Read blocks using LBA - wl : Write blocks using LBA +- wlx: Write partition To do ----- diff --git a/drivers/usb/gadget/f_rockusb.c b/drivers/usb/gadget/f_rockusb.c index 82f421c..bcdc2ba 100644 --- a/drivers/usb/gadget/f_rockusb.c +++ b/drivers/usb/gadget/f_rockusb.c @@ -692,6 +692,50 @@ static void cb_write_lba(struct usb_ep *ep, struct usb_request *req) } } +static void cb_erase_lba(struct usb_ep *ep, struct usb_request *req) +{ + ALLOC_CACHE_ALIGN_BUFFER(struct fsg_bulk_cb_wrap, cbw, + sizeof(struct fsg_bulk_cb_wrap)); + struct f_rockusb *f_rkusb = get_rkusb(); + int sector_count, lba, blks; + + memcpy((char *)cbw, req->buf, USB_BULK_CB_WRAP_LEN); + sector_count = (int)get_unaligned_be16(&cbw->CDB[7]); + f_rkusb->tag = cbw->tag; + + if (!f_rkusb->desc) { + char *type = f_rkusb->dev_type; + int index = f_rkusb->dev_index; + + f_rkusb->desc = blk_get_dev(type, index); + if (!f_rkusb->desc || + f_rkusb->desc->type == DEV_TYPE_UNKNOWN) { + printf("invalid device \"%s\", %d\n", type, index); + rockusb_tx_write_csw(f_rkusb->tag, 0, CSW_FAIL, + USB_BULK_CS_WRAP_LEN); + return; + } + } + + lba = get_unaligned_be32(&cbw->CDB[2]); + + debug("require erase %x sectors from lba %x\n", + sector_count, lba); + + blks = blk_derase(f_rkusb->desc, lba, sector_count); + if (blks != sector_count) { + printf("failed erasing device %s: %d\n", f_rkusb->dev_type, + f_rkusb->dev_index); + rockusb_tx_write_csw(f_rkusb->tag, + cbw->data_transfer_length, CSW_FAIL, + USB_BULK_CS_WRAP_LEN); + return; + } + + rockusb_tx_write_csw(cbw->tag, cbw->data_transfer_length, CSW_GOOD, + USB_BULK_CS_WRAP_LEN); +} + void __weak rkusb_set_reboot_flag(int flag) { struct f_rockusb *f_rkusb = get_rkusb(); @@ -824,6 +868,10 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = { .cb = cb_not_support, }, { + .cmd = K_FW_LBA_ERASE_10, + .cb = cb_erase_lba, + }, + { .cmd = K_FW_SESSION, .cb = cb_not_support, },