-UsbBootWriteBlocks (\r
- IN USB_MASS_DEVICE *UsbMass,\r
- IN UINT32 Lba,\r
- IN UINTN TotalBlock,\r
- IN UINT8 *Buffer\r
- )\r
-{\r
- USB_BOOT_WRITE10_CMD WriteCmd;\r
- EFI_STATUS Status;\r
- UINT16 Count;\r
- UINT32 BlockSize;\r
- UINT32 ByteSize;\r
- UINT32 Timeout;\r
-\r
- BlockSize = UsbMass->BlockIoMedia.BlockSize;\r
- Status = EFI_SUCCESS;\r
-\r
- while (TotalBlock > 0) {\r
- //\r
- // Split the total blocks into smaller pieces to ease the pressure\r
- // 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
- ByteSize = (UINT32)Count * BlockSize;\r
-\r
- //\r
- // USB command's upper limit timeout is 5s. [USB2.0-9.2.6.1]\r
- //\r
- Timeout = (UINT32) USB_BOOT_GENERAL_CMD_TIMEOUT;\r
-\r
- //\r
- // Fill in the write10 command block\r
- //\r
- ZeroMem (&WriteCmd, sizeof (USB_BOOT_WRITE10_CMD));\r
-\r
- WriteCmd.OpCode = USB_BOOT_WRITE10_OPCODE;\r
- WriteCmd.Lun = (UINT8) (USB_BOOT_LUN (UsbMass->Lun));\r
- WriteUnaligned32 ((UINT32 *) WriteCmd.Lba, SwapBytes32 (Lba));\r
- WriteUnaligned16 ((UINT16 *) WriteCmd.TransferLen, SwapBytes16 (Count));\r
-\r
- Status = UsbBootExecCmdWithRetry (\r
- UsbMass,\r
- &WriteCmd,\r
- (UINT8) sizeof (USB_BOOT_WRITE10_CMD),\r
- EfiUsbDataOut,\r
- Buffer,\r
- ByteSize,\r
- Timeout\r
- );\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- DEBUG ((EFI_D_BLKIO, "UsbBootWriteBlocks: LBA (0x%x), Blk (0x%x)\n", Lba, Count));\r
-\r
- Lba += Count;\r
- Buffer += Count * BlockSize;\r
- TotalBlock -= Count;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-/**\r
- Read some blocks from the device by SCSI 16 byte cmd.\r
-\r
- @param UsbMass The USB mass storage device to read from\r
- @param Lba The start block number\r
- @param TotalBlock Total block number to read\r
- @param Buffer The buffer to read to\r
-\r
- @retval EFI_SUCCESS Data are read into the buffer\r
- @retval Others Failed to read all the data\r
-\r
-**/\r
-EFI_STATUS\r
-UsbBootReadBlocks16 (\r