]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
usb: rockchip: implement K_FW_LBA_ERASE_10 command
authorAlberto Panizzo <alberto@amarulasolutions.com>
Thu, 12 Jul 2018 11:05:45 +0000 (13:05 +0200)
committerMarek Vasut <marex@denx.de>
Wed, 8 Aug 2018 20:22:07 +0000 (22:22 +0200)
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 <alberto@amarulasolutions.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
arch/arm/include/asm/arch-rockchip/f_rockusb.h
doc/README.rockusb
drivers/usb/gadget/f_rockusb.c

index 3f2e763e96703cf8b5df8c42c69a636e52438169..9772321023b3c757736cee439c562897e4b9f5de 100644 (file)
@@ -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,
index 7f58296303a6ac33cd27ba2cb22a78d0c07df14b..66437e17e46bbd61f721c82a5fdfc62e15ece377 100644 (file)
@@ -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
 -----
index 82f421cee11a31c5a41ac27243f6fbee5e16a093..bcdc2bac868fce3d002a44936c39a4c0cefef1af 100644 (file)
@@ -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();
@@ -823,6 +867,10 @@ static const struct cmd_dispatch_info cmd_dispatch_info[] = {
                .cmd = K_FW_SPI_WRITE_10,
                .cb = cb_not_support,
        },
+       {
+               .cmd = K_FW_LBA_ERASE_10,
+               .cb = cb_erase_lba,
+       },
        {
                .cmd = K_FW_SESSION,
                .cb = cb_not_support,