public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 5/7] usb: rockchip: implement K_FW_LBA_ERASE_10 command
Date: Tue, 3 Jul 2018 23:47:37 +0200	[thread overview]
Message-ID: <20180703234737.78918851@jawa> (raw)
In-Reply-To: <1530644652-12537-6-git-send-email-alberto@amarulasolutions.com>

Hi Alberto,

> This command is part of the write LBA sector sequence performed by
> rkdeveloptool

You mentioned the LBA sector and the need of erasing it.

AFAIK, block devices (eMMC) perform internally erase on write.

Is this protocol also supposed to work with NAND flash? If yes, please
adjust the patch description.

Also, please extend the README.rockusb file.

> 
> Signed-off-by: Alberto Panizzo <alberto@amarulasolutions.com>
> ---
>  arch/arm/include/asm/arch-rockchip/f_rockusb.h |  1 +
>  drivers/usb/gadget/f_rockusb.c                 | 46
> ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
> 
> diff --git a/arch/arm/include/asm/arch-rockchip/f_rockusb.h
> b/arch/arm/include/asm/arch-rockchip/f_rockusb.h index
> f04d401..77c3a87 100644 ---
> a/arch/arm/include/asm/arch-rockchip/f_rockusb.h +++
> b/arch/arm/include/asm/arch-rockchip/f_rockusb.h @@ -62,6 +62,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/drivers/usb/gadget/f_rockusb.c
> b/drivers/usb/gadget/f_rockusb.c index dbf31cb..230fbec 100644
> --- a/drivers/usb/gadget/f_rockusb.c
> +++ b/drivers/usb/gadget/f_rockusb.c
> @@ -693,6 +693,48 @@ 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]);
> +	lba = get_unaligned_be32(&cbw->CDB[2]);
> +	f_rkusb->tag = cbw->tag;
> +	debug("require erase %x sectors from lba %x\n",
> +	      sector_count, lba);
> +
> +	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) {
> +			puts("invalid mmc device\n");
> +			rockusb_tx_write_csw(f_rkusb->tag,
> +				cbw->data_transfer_length, CSW_FAIL,
> +				USB_BULK_CS_WRAP_LEN);
> +			return;
> +		}
> +	}
> +	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();
> @@ -825,6 +867,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,
>  	},


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20180703/c9f4dc86/attachment.sig>

  reply	other threads:[~2018-07-03 21:47 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 19:02 [U-Boot] [PATCH 0/7] Improve rockusb support in U-Boot Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 1/7] usb: rockchip: fix command failed on host side due to missing data Alberto Panizzo
2018-07-03 21:24   ` Lukasz Majewski
2018-07-04 10:11     ` Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 2/7] usb: rockchip: implement skeleton for K_FW_GET_CHIP_VER command Alberto Panizzo
2018-07-03 21:33   ` Lukasz Majewski
2018-07-04 13:27     ` Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 3/7] rockchip: rk3288: implement reading chip version from bootrom code Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 4/7] usb: rockchip: implement K_FW_LBA_READ_10 command Alberto Panizzo
2018-07-03 21:42   ` Lukasz Majewski
2018-07-04 13:36     ` Alberto Panizzo
2018-07-05  1:19   ` Kever Yang
2018-07-05  8:52     ` Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 5/7] usb: rockchip: implement K_FW_LBA_ERASE_10 command Alberto Panizzo
2018-07-03 21:47   ` Lukasz Majewski [this message]
2018-07-03 19:02 ` [U-Boot] [PATCH 6/7] usb: rockchip: be quiet on serial port while transferring data Alberto Panizzo
2018-07-03 21:49   ` Lukasz Majewski
2018-07-04 13:44     ` Alberto Panizzo
2018-07-03 19:02 ` [U-Boot] [PATCH 7/7] usb: rockchip: boost up write speed from 4MB/s to 15MB/s Alberto Panizzo
2018-07-05  1:15 ` [U-Boot] [PATCH 0/7] Improve rockusb support in U-Boot Kever Yang
2018-07-05  8:39   ` Alberto Panizzo
2018-07-05  9:07     ` Lukasz Majewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180703234737.78918851@jawa \
    --to=lukma@denx.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox