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