All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alberto Panizzo <alberto@amarulasolutions.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 4/7] usb: rockchip: implement K_FW_LBA_READ_10 command
Date: Wed, 4 Jul 2018 15:36:25 +0200	[thread overview]
Message-ID: <20180704133623.GA2892@change> (raw)
In-Reply-To: <20180703234211.1a1bffd6@jawa>

Hi Lukasz,

On Tue, Jul 03, 2018 at 11:42:11PM +0200, Lukasz Majewski wrote:
> Hi Alberto,
> 
> > It is now possible to read from block device al logic layer.
> 						  ^^^^^^^ - what do you
> 						  mean by logic layer?
>

This does refer to rockusb nomenclature: where with rkdeveloptool
from workstation we use the "rl" command using LBA addresses.

I'll rephrase.
 
> I suppose this code is to read N blocks (512B) from eMMC device?
> 
> NOTE:
> 
> Please consider adding tests into test/py/tests/ as we already have
> such tests for test_ums.py and test_dfu.py

I'll try, it's on my TODO

> 
> > Corresponding command on workstation is:
> > rkdeveloptool rl <start_blk> <blk_cnt> <file>
> > 
> > Signed-off-by: Alberto Panizzo <alberto@amarulasolutions.com>
> > ---
> >  arch/arm/include/asm/arch-rockchip/f_rockusb.h |   2 +
> >  drivers/usb/gadget/f_rockusb.c                 | 102
> > ++++++++++++++++++++++++- 2 files changed, 103 insertions(+), 1
> > deletion(-)
> > 
> > diff --git a/arch/arm/include/asm/arch-rockchip/f_rockusb.h
> > b/arch/arm/include/asm/arch-rockchip/f_rockusb.h index
> > f5cad8e..f04d401 100644 ---
> > a/arch/arm/include/asm/arch-rockchip/f_rockusb.h +++
> > b/arch/arm/include/asm/arch-rockchip/f_rockusb.h @@ -120,6 +120,8 @@
> > struct f_rockusb { unsigned int lba;
> >  	unsigned int dl_size;
> >  	unsigned int dl_bytes;
> > +	unsigned int ul_size;
> > +	unsigned int ul_bytes;
> 
> We had similar problem with Samsung's THOR. unsigned int may be too
> little in a while (we got int) ...
> 
> >  	struct blk_desc *desc;
> >  	int reboot_flag;
> >  	void *buf;
> > diff --git a/drivers/usb/gadget/f_rockusb.c
> > b/drivers/usb/gadget/f_rockusb.c index 7612871..dbf31cb 100644
> > --- a/drivers/usb/gadget/f_rockusb.c
> > +++ b/drivers/usb/gadget/f_rockusb.c
> > @@ -340,6 +340,7 @@ static int rockusb_tx_write(const char *buffer,
> > unsigned int buffer_size) 
> >  	memcpy(in_req->buf, buffer, buffer_size);
> >  	in_req->length = buffer_size;
> > +	debug("Transferring 0x%x bytes\n", buffer_size);
> >  	usb_ep_dequeue(rockusb_func->in_ep, in_req);
> >  	ret = usb_ep_queue(rockusb_func->in_ep, in_req, 0);
> >  	if (ret)
> > @@ -434,6 +435,79 @@ static unsigned int rx_bytes_expected(struct
> > usb_ep *ep) return rx_remain;
> >  }
> >  
> > +/* usb_request complete call back to handle upload image */
> > +static void tx_handler_ul_image(struct usb_ep *ep, struct
> > usb_request *req) +{
> > +#define RBUFFER_SIZE	4096
> 
> This can be moved to header file.
> 
> > +	ALLOC_CACHE_ALIGN_BUFFER(char, rbuffer, RBUFFER_SIZE);
> > +	struct f_rockusb *f_rkusb = get_rkusb();
> > +	struct usb_request *in_req = rockusb_func->in_req;
> > +	int ret;
> > +
> > +	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, 0,
> > CSW_FAIL,
> > +					     USB_BULK_CS_WRAP_LEN);
> > +			return;
> > +		}
> > +	}
> > +
> > +	/* Print error status of previous transfer */
> > +	if (req->status)
> > +		debug("status: %d ep '%s' trans: %d len %d\n",
> > req->status,
> > +		      ep->name, req->actual, req->length);
> > +
> > +	/* On transfer complete reset in_req and feedback host with
> > CSW_GOOD */
> > +	if (f_rkusb->ul_bytes >= f_rkusb->ul_size) {
> > +		in_req->length = 0;
> > +		in_req->complete = rockusb_complete;
> > +
> > +		rockusb_tx_write_csw(f_rkusb->tag, 0, CSW_GOOD,
> > +				     USB_BULK_CS_WRAP_LEN);
> > +		return;
> > +	}
> > +
> > +	/* Proceed with current chunk */
> > +	unsigned int transfer_size = f_rkusb->ul_size -
> > f_rkusb->ul_bytes; +
> > +	if (transfer_size > RBUFFER_SIZE)
> > +		transfer_size = RBUFFER_SIZE;
> > +	/* Read at least one block */
> > +	unsigned int blkcount = (transfer_size + 511) / 512;
> > +
> > +	debug("ul %x bytes, %x blks, read lba %x, ul_size:%x,
> > ul_bytes:%x, ",
> > +	      transfer_size, blkcount, f_rkusb->lba,
> > +	      f_rkusb->ul_size, f_rkusb->ul_bytes);
> > +
> > +	int blks = blk_dread(f_rkusb->desc, f_rkusb->lba, blkcount,
> > rbuffer); +
> > +	if (blks != blkcount) {
> > +		printf("failed reading from device %s: %d\n",
> > +		       f_rkusb->dev_type, f_rkusb->dev_index);
> > +		rockusb_tx_write_csw(f_rkusb->tag, 0, CSW_FAIL,
> > +				     USB_BULK_CS_WRAP_LEN);
> > +		return;
> > +	}
> > +	f_rkusb->lba += blkcount;
> > +	f_rkusb->ul_bytes += transfer_size;
> > +
> > +	/* Proceed with USB request */
> > +	memcpy(in_req->buf, rbuffer, transfer_size);
> > +	in_req->length = transfer_size;
> > +	in_req->complete = tx_handler_ul_image;
> > +	printf("Uploading 0x%x bytes\n", transfer_size);
> > +	usb_ep_dequeue(rockusb_func->in_ep, in_req);
> > +	ret = usb_ep_queue(rockusb_func->in_ep, in_req, 0);
> > +	if (ret)
> > +		printf("Error %d on queue\n", ret);
> > +}
> > +
> >  /* usb_request complete call back to handle down load image */
> >  static void rx_handler_dl_image(struct usb_ep *ep, struct
> > usb_request *req) {
> > @@ -568,6 +642,32 @@ static void cb_get_chip_version(struct usb_ep
> > *ep, struct usb_request *req) CSW_GOOD);
> >  }
> >  
> > +static void cb_read_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;
> > +
> > +	memcpy((char *)cbw, req->buf, USB_BULK_CB_WRAP_LEN);
> > +	sector_count = (int)get_unaligned_be16(&cbw->CDB[7]);
> > +	f_rkusb->lba = get_unaligned_be32(&cbw->CDB[2]);
> > +	f_rkusb->ul_size = sector_count * 512;
> > +	f_rkusb->ul_bytes = 0;
> > +	f_rkusb->tag = cbw->tag;
> > +	debug("require read %x bytes, %x sectors from lba %x\n",
> > +	      f_rkusb->ul_size, sector_count, f_rkusb->lba);
> > +
> > +	if (f_rkusb->ul_size == 0)  {
> > +		rockusb_tx_write_csw(cbw->tag,
> > cbw->data_transfer_length,
> > +				     CSW_FAIL, USB_BULK_CS_WRAP_LEN);
> > +		return;
> > +	}
> > +
> > +	/* Start right now sending first chunk */
> > +	tx_handler_ul_image(ep, req);
> > +}
> > +
> >  static void cb_write_lba(struct usb_ep *ep, struct usb_request *req)
> >  {
> >  	ALLOC_CACHE_ALIGN_BUFFER(struct fsg_bulk_cb_wrap, cbw,
> > @@ -678,7 +778,7 @@ static const struct cmd_dispatch_info
> > cmd_dispatch_info[] = { },
> >  	{
> >  		.cmd = K_FW_LBA_READ_10,
> > -		.cb = cb_not_support,
> > +		.cb = cb_read_lba,
> 
> Please add entry explaining this part of the protocol into
> README.rockusb
>

Yes.

Best Regards,

Alberto Panizzo

--
Presidente CDA
Amarula Solutions SRL                     Via le Canevare 30 31100 Treviso Italy
CTO - Co-Founder
Amarula Solutions BV           Cruquiuskade 47 Amsterdam 1018 AM The Netherlands
Phone. +31(0)851119171 Fax. +31(0)204106211             www.amarulasolutions.com

 
> >  	},
> >  	{
> >  		.cmd = K_FW_LBA_WRITE_10,
> 
> 
> 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

  reply	other threads:[~2018-07-04 13:36 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 [this message]
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
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=20180704133623.GA2892@change \
    --to=alberto@amarulasolutions.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.