[SLOF] [PATCH] usb/storage: Implement block write support

Laurent Vivier lvivier at redhat.com
Fri Dec 7 00:49:06 AEDT 2018


The only missing parts were to manage the transfer direction in
do-bulk-command and to copy the data to the buffer before the
write operation.

This is needed as GRUB2 wants to write the grubenv file at start
and hangs because the data are not provided to the disk controller.

I've checked the file is correctly modified by modifying an environment
variable in GRUB2 with "set saved_entry=2" then "save_env saved_entry"
and checking the result in linux with "grub2-editenv list".

Fixes: Fixes: a0b96fe66fcd991b407c1d67ca842921e477a6fd
       (Provide "write" function in the disk-label package)
Signed-off-by: Laurent Vivier <lvivier at redhat.com>
---
 slof/fs/usb/dev-storage.fs | 55 ++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/slof/fs/usb/dev-storage.fs b/slof/fs/usb/dev-storage.fs
index 94f8421..923a8f6 100644
--- a/slof/fs/usb/dev-storage.fs
+++ b/slof/fs/usb/dev-storage.fs
@@ -103,27 +103,33 @@ scsi-open
 \ if sense-len is 0 then no sense data is actually present
 \
 
-: do-bulk-command ( resp-buffer resp-size -- TRUE | FALSE )
+: do-bulk-command ( dir resp-buffer resp-size -- TRUE | FALSE )
     TO resp-size
     TO resp-buffer
     udev USB_PIPE_OUT td-buf td-buf-phys dma-buf-phys usb>cmd 1F
-    usb-transfer-bulk IF \ transfer CBW
-	resp-size IF
-	    d# 125 us
-	    udev USB_PIPE_IN td-buf td-buf-phys resp-buffer resp-size
-	    usb-transfer-bulk 1 = not IF \ transfer data
-	        usb-disk-debug?	IF ." Data phase failed " cr THEN
-		\ FALSE EXIT
-		\ in case of a stall/halted endpoint we clear the halt
-		\ Fall through and try reading the CSW
-	    THEN
-	THEN
+    usb-transfer-bulk 1 = not IF \ transfer CBW
+	FALSE EXIT
+    THEN
+    resp-size IF
 	d# 125 us
-	udev USB_PIPE_IN td-buf td-buf-phys dma-buf-phys usb>csw 0D
-	usb-transfer-bulk \ transfer CSW
+	IF
+	    udev USB_PIPE_IN
+	ELSE
+	    udev USB_PIPE_OUT
+	THEN
+	td-buf td-buf-phys resp-buffer resp-size
+	usb-transfer-bulk 1 = not IF \ transfer data
+	    usb-disk-debug?	IF ." Data phase failed " cr THEN
+	    \ FALSE EXIT
+	    \ in case of a stall/halted endpoint we clear the halt
+	    \ Fall through and try reading the CSW
+	THEN
     ELSE
-	FALSE EXIT
+	drop
     THEN
+    d# 125 us
+    udev USB_PIPE_IN td-buf td-buf-phys dma-buf-phys usb>csw 0D
+    usb-transfer-bulk \ transfer CSW
 ;
 
 STRUCT \ cbw
@@ -182,20 +188,29 @@ CONSTANT cbw-length
     build-cbw
     1 tag + to tag
 
+    \ copy command
     usb-cmd-addr
     dma-buf usb>cmd SCSI-COMMAND-OFFSET +
     usb-cmd-len
     move
 
+    \ copy data to write
+    usb-dir not IF
+        usb-buf-addr dma-buf usb>data usb-buf-len move
+    THEN
+
     \ Send it
-    dma-buf-phys usb>data usb-buf-len
-    do-bulk-command IF
-	dma-buf usb>data usb-buf-addr usb-buf-len move
-    ELSE
-        ." USB-DISK: Bulk commad failed!" cr
+    usb-dir dma-buf-phys usb>data usb-buf-len
+    do-bulk-command 1 = not IF
+        ." USB-DISK: Bulk command failed!" cr
         0 0 -1 EXIT
     THEN
 
+    \ copy read data
+    usb-dir IF
+        dma-buf usb>data usb-buf-addr usb-buf-len move
+    THEN
+
     dma-buf usb>csw to csw-addr
     csw-addr csw>sig l@ 55534253 <> IF
 	." USB-DISK: CSW signature invalid " cr
-- 
2.19.2



More information about the SLOF mailing list