MdeModulePkg/Usb: Replace macro USB_BOOT_IO_BLOCKS
authorMing Huang <ming.huang@linaro.org>
Thu, 22 Mar 2018 07:44:26 +0000 (15:44 +0800)
committerStar Zeng <star.zeng@intel.com>
Mon, 26 Mar 2018 03:02:43 +0000 (11:02 +0800)
Booting from USB may fail while the macro USB_BOOT_IO_BLOCKS
set to 128 because the block size of some USB devices are exceeded
512, like some virtual CD-ROM from BMC, the block size is 2048.
So,the count blocks to transfer should be calculated by block
size of the USB devices.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ming Huang <ming.huang@linaro.org>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.c
MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h

index b84bfd2d729034417dfe689f78119fdd5052ad36..3bf6e6a81f3c122dcfdc4819a26c4e365fea3d64 100644 (file)
@@ -814,11 +814,13 @@ UsbBootReadBlocks (
   USB_BOOT_READ10_CMD       ReadCmd;\r
   EFI_STATUS                Status;\r
   UINT16                    Count;\r
+  UINT16                    CountMax;\r
   UINT32                    BlockSize;\r
   UINT32                    ByteSize;\r
   UINT32                    Timeout;\r
 \r
   BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
+  CountMax = (UINT16)(USB_BOOT_MAX_CARRY_SIZE / BlockSize);\r
   Status    = EFI_SUCCESS;\r
 \r
   while (TotalBlock > 0) {\r
@@ -827,7 +829,7 @@ UsbBootReadBlocks (
     // on the device. We must split the total block because the READ10\r
     // command only has 16 bit transfer length (in the unit of block).\r
     //\r
-    Count     = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
+    Count     = (UINT16)((TotalBlock < CountMax) ? TotalBlock : CountMax);\r
     ByteSize  = (UINT32)Count * BlockSize;\r
 \r
     //\r
@@ -890,11 +892,13 @@ UsbBootWriteBlocks (
   USB_BOOT_WRITE10_CMD  WriteCmd;\r
   EFI_STATUS            Status;\r
   UINT16                Count;\r
+  UINT16                CountMax;\r
   UINT32                BlockSize;\r
   UINT32                ByteSize;\r
   UINT32                Timeout;\r
 \r
   BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
+  CountMax = (UINT16)(USB_BOOT_MAX_CARRY_SIZE / BlockSize);\r
   Status    = EFI_SUCCESS;\r
 \r
   while (TotalBlock > 0) {\r
@@ -903,7 +907,7 @@ UsbBootWriteBlocks (
     // on the device. We must split the total block because the WRITE10\r
     // command only has 16 bit transfer length (in the unit of block).\r
     //\r
-    Count     = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
+    Count     = (UINT16)((TotalBlock < CountMax) ? TotalBlock : CountMax);\r
     ByteSize  = (UINT32)Count * BlockSize;\r
 \r
     //\r
@@ -966,18 +970,20 @@ UsbBootReadBlocks16 (
   UINT8                     ReadCmd[16];\r
   EFI_STATUS                Status;\r
   UINT16                    Count;\r
+  UINT16                    CountMax;\r
   UINT32                    BlockSize;\r
   UINT32                    ByteSize;\r
   UINT32                    Timeout;\r
 \r
   BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
+  CountMax = (UINT16)(USB_BOOT_MAX_CARRY_SIZE / BlockSize);\r
   Status    = EFI_SUCCESS;\r
 \r
   while (TotalBlock > 0) {\r
     //\r
     // Split the total blocks into smaller pieces.\r
     //\r
-    Count     = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
+    Count     = (UINT16)((TotalBlock < CountMax) ? TotalBlock : CountMax);\r
     ByteSize  = (UINT32)Count * BlockSize;\r
 \r
     //\r
@@ -1040,18 +1046,20 @@ UsbBootWriteBlocks16 (
   UINT8                 WriteCmd[16];\r
   EFI_STATUS            Status;\r
   UINT16                Count;\r
+  UINT16                CountMax;\r
   UINT32                BlockSize;\r
   UINT32                ByteSize;\r
   UINT32                Timeout;\r
 \r
   BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
+  CountMax = (UINT16)(USB_BOOT_MAX_CARRY_SIZE / BlockSize);\r
   Status    = EFI_SUCCESS;\r
 \r
   while (TotalBlock > 0) {\r
     //\r
     // Split the total blocks into smaller pieces.\r
     //\r
-    Count     = (UINT16)((TotalBlock < USB_BOOT_IO_BLOCKS) ? TotalBlock : USB_BOOT_IO_BLOCKS);\r
+    Count     = (UINT16)((TotalBlock < CountMax) ? TotalBlock : CountMax);\r
     ByteSize  = (UINT32)Count * BlockSize;\r
 \r
     //\r
index 13a926035ceb4b6b5709ea3c86f6ea9b8134be5f..f8a0708350c70dbd1fc6f74f4f662e1a56a05c56 100644 (file)
@@ -65,9 +65,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #define USB_PDT_SIMPLE_DIRECT           0x0E       ///< Simplified direct access device\r
 \r
 //\r
-// Other parameters, Max carried size is 512B * 128 = 64KB\r
+// Other parameters, Max carried size is 64KB.\r
 //\r
-#define USB_BOOT_IO_BLOCKS              128\r
+#define USB_BOOT_MAX_CARRY_SIZE         SIZE_64KB\r
 \r
 //\r
 // Retry mass command times, set by experience\r