From patchwork Thu Dec 6 13:49:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1008807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 439cSd0D7dz9s47 for ; Fri, 7 Dec 2018 00:50:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 439cSc4BXYzDqjy for ; Fri, 7 Dec 2018 00:50:56 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=redhat.com (client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lvivier@redhat.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 439cQc1FkwzDqtj for ; Fri, 7 Dec 2018 00:49:11 +1100 (AEDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D63E7F3E9; Thu, 6 Dec 2018 13:49:09 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-204-190.brq.redhat.com [10.40.204.190]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABCB160CD1; Thu, 6 Dec 2018 13:49:07 +0000 (UTC) From: Laurent Vivier To: Alexey Kardashevskiy , slof@lists.ozlabs.org Date: Thu, 6 Dec 2018 14:49:06 +0100 Message-Id: <20181206134906.18393-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 06 Dec 2018 13:49:09 +0000 (UTC) Subject: [SLOF] [PATCH] usb/storage: Implement block write support X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" 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 --- 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