2 Definition of the command set of USB Mass Storage Specification
3 for Bootability, Revision 1.0.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #ifndef _EFI_USB_MASS_BOOT_H_
17 #define _EFI_USB_MASS_BOOT_H_
20 // The opcodes of various USB boot commands:
21 // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified
22 // by Multi-Media Commands (MMC) set.
23 // Others are "Group 1 Timeout Commands". That is,
24 // they should be retried if driver is ready.
26 #define USB_BOOT_INQUIRY_OPCODE 0x12
27 #define USB_BOOT_REQUEST_SENSE_OPCODE 0x03
28 #define USB_BOOT_MODE_SENSE10_OPCODE 0x5A
29 #define USB_BOOT_READ_CAPACITY_OPCODE 0x25
30 #define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00
31 #define USB_BOOT_READ10_OPCODE 0x28
32 #define USB_BOOT_WRITE10_OPCODE 0x2A
34 #define USB_SCSI_MODE_SENSE6_OPCODE 0x1A
37 // The Sense Key part of the sense data. Sense data has three levels:
38 // Sense key, Additional Sense Code and Additional Sense Code Qualifier
40 #define USB_BOOT_SENSE_NO_SENSE 0x00 ///< No sense key
41 #define USB_BOOT_SENSE_RECOVERED 0x01 ///< Last command succeed with recovery actions
42 #define USB_BOOT_SENSE_NOT_READY 0x02 ///< Device not ready
43 #define USB_BOOT_SNESE_MEDIUM_ERROR 0X03 ///< Failed probably because flaw in the media
44 #define USB_BOOT_SENSE_HARDWARE_ERROR 0X04 ///< Non-recoverable hardware failure
45 #define USB_BOOT_SENSE_ILLEGAL_REQUEST 0X05 ///< Illegal parameters in the request
46 #define USB_BOOT_SENSE_UNIT_ATTENTION 0X06 ///< Removable medium may have been changed
47 #define USB_BOOT_SENSE_DATA_PROTECT 0X07 ///< Write protected
48 #define USB_BOOT_SENSE_BLANK_CHECK 0X08 ///< Blank/non-blank medium while reading/writing
49 #define USB_BOOT_SENSE_VENDOR 0X09 ///< Vendor specific sense key
50 #define USB_BOOT_SENSE_ABORTED 0X0B ///< Command aborted by the device
51 #define USB_BOOT_SENSE_VOLUME_OVERFLOW 0x0D ///< Partition overflow
52 #define USB_BOOT_SENSE_MISCOMPARE 0x0E ///< Source data mis-match while verfying.
54 #define USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00
55 #define USB_BOOT_ASC_NOT_READY 0x04
56 #define USB_BOOT_ASC_NO_MEDIA 0x3A
57 #define USB_BOOT_ASC_MEDIA_CHANGE 0x28
58 #define USB_BOOT_ASC_POWER_ON 0x29
61 // Supported PDT codes, or Peripheral Device Type
63 #define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device
64 #define USB_PDT_CDROM 0x05 ///< CDROM
65 #define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks
66 #define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device
69 // Other parameters, Max carried size is 512B * 128 = 64KB
71 #define USB_BOOT_IO_BLOCKS 128
74 // Retry mass command times, set by experience
76 #define USB_BOOT_COMMAND_RETRY 5
79 // Wait for unit ready command, set by experience
81 #define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)
84 // Mass command timeout, refers to specification[USB20-9.2.6.1]
86 // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,
87 // USB CD-Rom and iPod devices are much slower than USB key when reponse
88 // most of commands, So we set 5s as timeout here.
90 #define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)
93 // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,
94 // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA
95 // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY
96 // command to retrieve the disk gemotrics.
101 UINT8 Lun
; ///< Lun (high 3 bits)
106 } USB_BOOT_INQUIRY_CMD
;
109 UINT8 Pdt
; ///< Peripheral Device Type (low 5 bits)
110 UINT8 Removable
; ///< Removable Media (highest bit)
112 UINT8 AddLen
; ///< Additional length
116 UINT8 ProductRevision
[4];
117 } USB_BOOT_INQUIRY_DATA
;
124 } USB_BOOT_READ_CAPACITY_CMD
;
129 } USB_BOOT_READ_CAPACITY_DATA
;
136 } USB_BOOT_TEST_UNIT_READY_CMD
;
143 UINT8 ParaListLenMsb
;
144 UINT8 ParaListLenLsb
;
147 } USB_BOOT_MODE_SENSE10_CMD
;
150 UINT8 ModeDataLenMsb
;
151 UINT8 ModeDataLenLsb
;
155 } USB_BOOT_MODE_SENSE10_PARA_HEADER
;
159 UINT8 Lun
; ///< Lun (High 3 bits)
160 UINT8 Lba
[4]; ///< Logical block address
162 UINT8 TransferLen
[2]; ///< Transfer length
165 } USB_BOOT_READ10_CMD
;
172 UINT8 TransferLen
[2];
175 } USB_BOOT_WRITE10_CMD
;
179 UINT8 Lun
; ///< Lun (High 3 bits)
181 UINT8 AllocLen
; ///< Allocation length
184 } USB_BOOT_REQUEST_SENSE_CMD
;
189 UINT8 SenseKey
; ///< Sense key (low 4 bits)
191 UINT8 AddLen
; ///< Additional Sense length, 10
193 UINT8 Asc
; ///< Additional Sense Code
194 UINT8 Ascq
; ///< Additional Sense Code Qualifier
196 } USB_BOOT_REQUEST_SENSE_DATA
;
205 } USB_SCSI_MODE_SENSE6_CMD
;
212 } USB_SCSI_MODE_SENSE6_PARA_HEADER
;
216 // Convert a LUN number to that in the command
218 #define USB_BOOT_LUN(Lun) ((Lun) << 5)
221 // Get the removable, PDT, and sense key bits from the command data
223 #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)
224 #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
225 #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
228 Get the parameters for the USB mass storage media.
230 This function get the parameters for the USB mass storage media,
231 It is used both to initialize the media during the Start() phase
232 of Driver Binding Protocol and to re-initialize it when the media is
233 changed. Althought the RemoveableMedia is unlikely to change,
234 it is also included here.
236 @param UsbMass The device to retrieve disk gemotric.
238 @retval EFI_SUCCESS The disk gemotric is successfully retrieved.
239 @retval Other Failed to get the parameters.
244 IN USB_MASS_DEVICE
*UsbMass
248 Execute TEST UNIT READY command to check if the device is ready.
250 @param UsbMass The device to test
252 @retval EFI_SUCCESS The device is ready.
253 @retval Others Device not ready.
258 IN USB_MASS_DEVICE
*UsbMass
262 Detect whether the removable media is present and whether it has changed.
264 @param UsbMass The device to check.
266 @retval EFI_SUCCESS The media status is successfully checked.
267 @retval Other Failed to detect media.
272 IN USB_MASS_DEVICE
*UsbMass
276 Read some blocks from the device.
278 @param UsbMass The USB mass storage device to read from
279 @param Lba The start block number
280 @param TotalBlock Total block number to read
281 @param Buffer The buffer to read to
283 @retval EFI_SUCCESS Data are read into the buffer
284 @retval Others Failed to read all the data
289 IN USB_MASS_DEVICE
*UsbMass
,
296 Write some blocks to the device.
298 @param UsbMass The USB mass storage device to write to
299 @param Lba The start block number
300 @param TotalBlock Total block number to write
301 @param Buffer Pointer to the source buffer for the data.
303 @retval EFI_SUCCESS Data are written into the buffer
304 @retval Others Failed to write all the data
309 IN USB_MASS_DEVICE
*UsbMass
,
316 Read some blocks from the device by SCSI 16 byte cmd.
318 @param UsbMass The USB mass storage device to read from
319 @param Lba The start block number
320 @param TotalBlock Total block number to read
321 @param Buffer The buffer to read to
323 @retval EFI_SUCCESS Data are read into the buffer
324 @retval Others Failed to read all the data
328 UsbBootReadBlocks16 (
329 IN USB_MASS_DEVICE
*UsbMass
,
336 Write some blocks to the device by SCSI 16 byte cmd.
338 @param UsbMass The USB mass storage device to write to
339 @param Lba The start block number
340 @param TotalBlock Total block number to write
341 @param Buffer Pointer to the source buffer for the data.
343 @retval EFI_SUCCESS Data are written into the buffer
344 @retval Others Failed to write all the data
348 UsbBootWriteBlocks16 (
349 IN USB_MASS_DEVICE
*UsbMass
,
357 Use the USB clear feature control transfer to clear the endpoint stall condition.
359 @param UsbIo The USB I/O Protocol instance
360 @param EndpointAddr The endpoint to clear stall for
362 @retval EFI_SUCCESS The endpoint stall condition is cleared.
363 @retval Others Failed to clear the endpoint stall condition.
367 UsbClearEndpointStall (
368 IN EFI_USB_IO_PROTOCOL
*UsbIo
,
369 IN UINT8 EndpointAddr