- DEBUG ((EFI_D_BLKIO, "UsbBootReadBlocks: LBA (0x%x), Blk (0x%x)\n", Lba, Count));\r
- Lba += Count;\r
- Buffer += Count * BlockSize;\r
- TotalBlock -= Count;\r
- }\r
-\r
- return Status;\r
-}\r
-\r
-\r
-/**\r
- Write some blocks to the device.\r
-\r
- @param UsbMass The USB mass storage device to write to\r
- @param Lba The start block number\r
- @param TotalBlock Total block number to write\r
- @param Buffer Pointer to the source buffer for the data.\r
-\r
- @retval EFI_SUCCESS Data are written into the buffer\r
- @retval Others Failed to write all the data\r
-\r
-**/\r
-EFI_STATUS\r
-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
- 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 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 < CountMax) ? TotalBlock : CountMax);\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