]>
Commit | Line | Data |
---|---|---|
e237e7ae | 1 | /** @file\r |
d80ed2a7 | 2 | Definition of the command set of USB Mass Storage Specification\r |
3 | for Bootability, Revision 1.0.\r | |
e237e7ae | 4 | \r |
d1102dba | 5 | Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
9d510e61 | 6 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
e237e7ae | 7 | \r |
e237e7ae | 8 | **/\r |
9 | \r | |
10 | #ifndef _EFI_USB_MASS_BOOT_H_\r | |
11 | #define _EFI_USB_MASS_BOOT_H_\r | |
12 | \r | |
1ccdbf2a | 13 | //\r |
14 | // The opcodes of various USB boot commands:\r | |
15 | // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r | |
16 | // by Multi-Media Commands (MMC) set.\r | |
17 | // Others are "Group 1 Timeout Commands". That is,\r | |
d1102dba | 18 | // they should be retried if driver is ready.\r |
1ccdbf2a | 19 | //\r |
20 | #define USB_BOOT_INQUIRY_OPCODE 0x12\r | |
21 | #define USB_BOOT_REQUEST_SENSE_OPCODE 0x03\r | |
22 | #define USB_BOOT_MODE_SENSE10_OPCODE 0x5A\r | |
23 | #define USB_BOOT_READ_CAPACITY_OPCODE 0x25\r | |
24 | #define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00\r | |
25 | #define USB_BOOT_READ10_OPCODE 0x28\r | |
26 | #define USB_BOOT_WRITE10_OPCODE 0x2A\r | |
27 | \r | |
28 | #define USB_SCSI_MODE_SENSE6_OPCODE 0x1A\r | |
29 | \r | |
30 | //\r | |
31 | // The Sense Key part of the sense data. Sense data has three levels:\r | |
32 | // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r | |
33 | //\r | |
34 | #define USB_BOOT_SENSE_NO_SENSE 0x00 ///< No sense key\r | |
35 | #define USB_BOOT_SENSE_RECOVERED 0x01 ///< Last command succeed with recovery actions\r | |
36 | #define USB_BOOT_SENSE_NOT_READY 0x02 ///< Device not ready\r | |
37 | #define USB_BOOT_SNESE_MEDIUM_ERROR 0X03 ///< Failed probably because flaw in the media\r | |
38 | #define USB_BOOT_SENSE_HARDWARE_ERROR 0X04 ///< Non-recoverable hardware failure\r | |
39 | #define USB_BOOT_SENSE_ILLEGAL_REQUEST 0X05 ///< Illegal parameters in the request\r | |
40 | #define USB_BOOT_SENSE_UNIT_ATTENTION 0X06 ///< Removable medium may have been changed\r | |
41 | #define USB_BOOT_SENSE_DATA_PROTECT 0X07 ///< Write protected\r | |
42 | #define USB_BOOT_SENSE_BLANK_CHECK 0X08 ///< Blank/non-blank medium while reading/writing\r | |
43 | #define USB_BOOT_SENSE_VENDOR 0X09 ///< Vendor specific sense key\r | |
44 | #define USB_BOOT_SENSE_ABORTED 0X0B ///< Command aborted by the device\r | |
45 | #define USB_BOOT_SENSE_VOLUME_OVERFLOW 0x0D ///< Partition overflow\r | |
46 | #define USB_BOOT_SENSE_MISCOMPARE 0x0E ///< Source data mis-match while verfying.\r | |
47 | \r | |
275b96da MK |
48 | #define USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00\r |
49 | #define USB_BOOT_ASC_NOT_READY 0x04\r | |
50 | #define USB_BOOT_ASC_NO_MEDIA 0x3A\r | |
51 | #define USB_BOOT_ASC_MEDIA_CHANGE 0x28\r | |
1ccdbf2a | 52 | \r |
53 | //\r | |
54 | // Supported PDT codes, or Peripheral Device Type\r | |
55 | //\r | |
56 | #define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device\r | |
57 | #define USB_PDT_CDROM 0x05 ///< CDROM\r | |
58 | #define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks\r | |
59 | #define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device\r | |
60 | \r | |
61 | //\r | |
824b6e3b | 62 | // Other parameters, Max carried size is 64KB.\r |
1ccdbf2a | 63 | //\r |
824b6e3b | 64 | #define USB_BOOT_MAX_CARRY_SIZE SIZE_64KB\r |
1ccdbf2a | 65 | \r |
66 | //\r | |
67 | // Retry mass command times, set by experience\r | |
68 | //\r | |
69 | #define USB_BOOT_COMMAND_RETRY 5\r | |
1ccdbf2a | 70 | \r |
71 | //\r | |
72 | // Wait for unit ready command, set by experience\r | |
73 | //\r | |
74 | #define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)\r | |
75 | \r | |
76 | //\r | |
77 | // Mass command timeout, refers to specification[USB20-9.2.6.1]\r | |
78 | //\r | |
d1102dba | 79 | // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,\r |
957ca631 | 80 | // USB CD-Rom and iPod devices are much slower than USB key when response\r |
1ccdbf2a | 81 | // most of commands, So we set 5s as timeout here.\r |
d1102dba | 82 | //\r |
1ccdbf2a | 83 | #define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)\r |
e237e7ae | 84 | \r |
85 | //\r | |
86 | // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r | |
87 | // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r | |
88 | // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r | |
d1102dba | 89 | // command to retrieve the disk gemotrics.\r |
e237e7ae | 90 | //\r |
91 | #pragma pack(1)\r | |
92 | typedef struct {\r | |
93 | UINT8 OpCode;\r | |
d80ed2a7 | 94 | UINT8 Lun; ///< Lun (high 3 bits)\r |
e237e7ae | 95 | UINT8 Reserved0[2];\r |
96 | UINT8 AllocLen;\r | |
97 | UINT8 Reserved1;\r | |
98 | UINT8 Pad[6];\r | |
99 | } USB_BOOT_INQUIRY_CMD;\r | |
100 | \r | |
101 | typedef struct {\r | |
d80ed2a7 | 102 | UINT8 Pdt; ///< Peripheral Device Type (low 5 bits)\r |
103 | UINT8 Removable; ///< Removable Media (highest bit)\r | |
e237e7ae | 104 | UINT8 Reserved0[2];\r |
d80ed2a7 | 105 | UINT8 AddLen; ///< Additional length\r |
e237e7ae | 106 | UINT8 Reserved1[3];\r |
107 | UINT8 VendorID[8];\r | |
108 | UINT8 ProductID[16];\r | |
109 | UINT8 ProductRevision[4];\r | |
110 | } USB_BOOT_INQUIRY_DATA;\r | |
111 | \r | |
112 | typedef struct {\r | |
113 | UINT8 OpCode;\r | |
114 | UINT8 Lun;\r | |
115 | UINT8 Reserved0[8];\r | |
116 | UINT8 Pad[2];\r | |
117 | } USB_BOOT_READ_CAPACITY_CMD;\r | |
118 | \r | |
119 | typedef struct {\r | |
120 | UINT8 LastLba[4];\r | |
121 | UINT8 BlockLen[4];\r | |
122 | } USB_BOOT_READ_CAPACITY_DATA;\r | |
123 | \r | |
124 | typedef struct {\r | |
125 | UINT8 OpCode;\r | |
126 | UINT8 Lun;\r | |
127 | UINT8 Reserved[4];\r | |
128 | UINT8 Pad[6];\r | |
129 | } USB_BOOT_TEST_UNIT_READY_CMD;\r | |
130 | \r | |
131 | typedef struct {\r | |
132 | UINT8 OpCode;\r | |
133 | UINT8 Lun;\r | |
134 | UINT8 PageCode;\r | |
135 | UINT8 Reserved0[4];\r | |
136 | UINT8 ParaListLenMsb;\r | |
137 | UINT8 ParaListLenLsb;\r | |
138 | UINT8 Reserved1;\r | |
139 | UINT8 Pad[2];\r | |
50fa1b3a | 140 | } USB_BOOT_MODE_SENSE10_CMD;\r |
e237e7ae | 141 | \r |
142 | typedef struct {\r | |
143 | UINT8 ModeDataLenMsb;\r | |
144 | UINT8 ModeDataLenLsb;\r | |
145 | UINT8 Reserved0[4];\r | |
146 | UINT8 BlkDesLenMsb;\r | |
147 | UINT8 BlkDesLenLsb;\r | |
50fa1b3a | 148 | } USB_BOOT_MODE_SENSE10_PARA_HEADER;\r |
e237e7ae | 149 | \r |
150 | typedef struct {\r | |
151 | UINT8 OpCode;\r | |
d80ed2a7 | 152 | UINT8 Lun; ///< Lun (High 3 bits)\r |
153 | UINT8 Lba[4]; ///< Logical block address\r | |
e237e7ae | 154 | UINT8 Reserved0;\r |
d80ed2a7 | 155 | UINT8 TransferLen[2]; ///< Transfer length\r |
e237e7ae | 156 | UINT8 Reserverd1;\r |
157 | UINT8 Pad[2];\r | |
e59db6a7 | 158 | } USB_BOOT_READ_WRITE_10_CMD;\r |
e237e7ae | 159 | \r |
160 | typedef struct {\r | |
161 | UINT8 OpCode;\r | |
d80ed2a7 | 162 | UINT8 Lun; ///< Lun (High 3 bits)\r |
e237e7ae | 163 | UINT8 Reserved0[2];\r |
d80ed2a7 | 164 | UINT8 AllocLen; ///< Allocation length\r |
e237e7ae | 165 | UINT8 Reserved1;\r |
166 | UINT8 Pad[6];\r | |
167 | } USB_BOOT_REQUEST_SENSE_CMD;\r | |
168 | \r | |
169 | typedef struct {\r | |
170 | UINT8 ErrorCode;\r | |
171 | UINT8 Reserved0;\r | |
d80ed2a7 | 172 | UINT8 SenseKey; ///< Sense key (low 4 bits)\r |
e237e7ae | 173 | UINT8 Infor[4];\r |
d80ed2a7 | 174 | UINT8 AddLen; ///< Additional Sense length, 10\r |
e237e7ae | 175 | UINT8 Reserved1[4];\r |
1ccdbf2a | 176 | UINT8 Asc; ///< Additional Sense Code\r |
177 | UINT8 Ascq; ///< Additional Sense Code Qualifier\r | |
e237e7ae | 178 | UINT8 Reserverd2[4];\r |
179 | } USB_BOOT_REQUEST_SENSE_DATA;\r | |
50fa1b3a | 180 | \r |
181 | typedef struct {\r | |
182 | UINT8 OpCode;\r | |
183 | UINT8 Lun;\r | |
184 | UINT8 PageCode;\r | |
185 | UINT8 Reserved0;\r | |
186 | UINT8 AllocateLen;\r | |
187 | UINT8 Control;\r | |
188 | } USB_SCSI_MODE_SENSE6_CMD;\r | |
189 | \r | |
190 | typedef struct {\r | |
191 | UINT8 ModeDataLen;\r | |
41e8ff27 | 192 | UINT8 MediumType;\r |
50fa1b3a | 193 | UINT8 DevicePara;\r |
194 | UINT8 BlkDesLen;\r | |
195 | } USB_SCSI_MODE_SENSE6_PARA_HEADER;\r | |
e237e7ae | 196 | #pragma pack()\r |
197 | \r | |
198 | //\r | |
199 | // Convert a LUN number to that in the command\r | |
200 | //\r | |
201 | #define USB_BOOT_LUN(Lun) ((Lun) << 5)\r | |
202 | \r | |
203 | //\r | |
204 | // Get the removable, PDT, and sense key bits from the command data\r | |
205 | //\r | |
d80ed2a7 | 206 | #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)\r |
e237e7ae | 207 | #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r |
208 | #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r | |
209 | \r | |
cc5166ff | 210 | /**\r |
3e03cb4d | 211 | Get the parameters for the USB mass storage media.\r |
212 | \r | |
213 | This function get the parameters for the USB mass storage media,\r | |
214 | It is used both to initialize the media during the Start() phase\r | |
215 | of Driver Binding Protocol and to re-initialize it when the media is\r | |
957ca631 | 216 | changed. Although the RemoveableMedia is unlikely to change,\r |
3e03cb4d | 217 | it is also included here.\r |
cc5166ff | 218 | \r |
3e03cb4d | 219 | @param UsbMass The device to retrieve disk gemotric.\r |
cc5166ff | 220 | \r |
221 | @retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r | |
3e03cb4d | 222 | @retval Other Failed to get the parameters.\r |
cc5166ff | 223 | \r |
224 | **/\r | |
e237e7ae | 225 | EFI_STATUS\r |
226 | UsbBootGetParams (\r | |
227 | IN USB_MASS_DEVICE *UsbMass\r | |
228 | );\r | |
229 | \r | |
cc5166ff | 230 | /**\r |
3e03cb4d | 231 | Execute TEST UNIT READY command to check if the device is ready.\r |
cc5166ff | 232 | \r |
233 | @param UsbMass The device to test\r | |
234 | \r | |
3e03cb4d | 235 | @retval EFI_SUCCESS The device is ready.\r |
cc5166ff | 236 | @retval Others Device not ready.\r |
237 | \r | |
238 | **/\r | |
e237e7ae | 239 | EFI_STATUS\r |
240 | UsbBootIsUnitReady (\r | |
241 | IN USB_MASS_DEVICE *UsbMass\r | |
242 | );\r | |
243 | \r | |
cc5166ff | 244 | /**\r |
245 | Detect whether the removable media is present and whether it has changed.\r | |
cc5166ff | 246 | \r |
3e03cb4d | 247 | @param UsbMass The device to check.\r |
cc5166ff | 248 | \r |
3e03cb4d | 249 | @retval EFI_SUCCESS The media status is successfully checked.\r |
250 | @retval Other Failed to detect media.\r | |
cc5166ff | 251 | \r |
252 | **/\r | |
e237e7ae | 253 | EFI_STATUS\r |
254 | UsbBootDetectMedia (\r | |
255 | IN USB_MASS_DEVICE *UsbMass\r | |
256 | );\r | |
257 | \r | |
cc5166ff | 258 | /**\r |
259 | Read some blocks from the device.\r | |
260 | \r | |
261 | @param UsbMass The USB mass storage device to read from\r | |
262 | @param Lba The start block number\r | |
263 | @param TotalBlock Total block number to read\r | |
264 | @param Buffer The buffer to read to\r | |
265 | \r | |
266 | @retval EFI_SUCCESS Data are read into the buffer\r | |
267 | @retval Others Failed to read all the data\r | |
268 | \r | |
269 | **/\r | |
e237e7ae | 270 | EFI_STATUS\r |
271 | UsbBootReadBlocks (\r | |
272 | IN USB_MASS_DEVICE *UsbMass,\r | |
273 | IN UINT32 Lba,\r | |
274 | IN UINTN TotalBlock,\r | |
275 | OUT UINT8 *Buffer\r | |
276 | );\r | |
277 | \r | |
cc5166ff | 278 | /**\r |
e59db6a7 | 279 | Read or write some blocks from the device.\r |
cc5166ff | 280 | \r |
e59db6a7 RN |
281 | @param UsbMass The USB mass storage device to access\r |
282 | @param Write TRUE for write operation.\r | |
cc5166ff | 283 | @param Lba The start block number\r |
e59db6a7 RN |
284 | @param TotalBlock Total block number to read or write\r |
285 | @param Buffer The buffer to read to or write from\r | |
cc5166ff | 286 | \r |
e59db6a7 RN |
287 | @retval EFI_SUCCESS Data are read into the buffer or writen into the device.\r |
288 | @retval Others Failed to read or write all the data\r | |
cc5166ff | 289 | \r |
290 | **/\r | |
e237e7ae | 291 | EFI_STATUS\r |
e59db6a7 RN |
292 | UsbBootReadWriteBlocks (\r |
293 | IN USB_MASS_DEVICE *UsbMass,\r | |
294 | IN BOOLEAN Write,\r | |
295 | IN UINT32 Lba,\r | |
296 | IN UINTN TotalBlock,\r | |
297 | IN OUT UINT8 *Buffer\r | |
e237e7ae | 298 | );\r |
3e03cb4d | 299 | \r |
99c1725e | 300 | /**\r |
e59db6a7 | 301 | Read or write some blocks from the device by SCSI 16 byte cmd.\r |
99c1725e | 302 | \r |
e59db6a7 RN |
303 | @param UsbMass The USB mass storage device to access\r |
304 | @param Write TRUE for write operation.\r | |
99c1725e | 305 | @param Lba The start block number\r |
e59db6a7 RN |
306 | @param TotalBlock Total block number to read or write\r |
307 | @param Buffer The buffer to read to or write from\r | |
99c1725e | 308 | \r |
e59db6a7 RN |
309 | @retval EFI_SUCCESS Data are read into the buffer or writen into the device.\r |
310 | @retval Others Failed to read or write all the data\r | |
99c1725e | 311 | **/\r |
312 | EFI_STATUS\r | |
e59db6a7 | 313 | UsbBootReadWriteBlocks16 (\r |
99c1725e | 314 | IN USB_MASS_DEVICE *UsbMass,\r |
e59db6a7 | 315 | IN BOOLEAN Write,\r |
99c1725e | 316 | IN UINT64 Lba,\r |
317 | IN UINTN TotalBlock,\r | |
e59db6a7 | 318 | IN OUT UINT8 *Buffer\r |
99c1725e | 319 | );\r |
320 | \r | |
3e03cb4d | 321 | /**\r |
322 | Use the USB clear feature control transfer to clear the endpoint stall condition.\r | |
323 | \r | |
324 | @param UsbIo The USB I/O Protocol instance\r | |
325 | @param EndpointAddr The endpoint to clear stall for\r | |
326 | \r | |
327 | @retval EFI_SUCCESS The endpoint stall condition is cleared.\r | |
328 | @retval Others Failed to clear the endpoint stall condition.\r | |
329 | \r | |
330 | **/\r | |
331 | EFI_STATUS\r | |
332 | UsbClearEndpointStall (\r | |
333 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
334 | IN UINT8 EndpointAddr\r | |
335 | );\r | |
336 | \r | |
e237e7ae | 337 | #endif\r |
338 | \r |