]>
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 |
99c1725e | 5 | Copyright (c) 2007 - 2012, 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 | |
54 | #define USB_BOOT_ASC_NOT_READY 0x04\r | |
55 | #define USB_BOOT_ASC_NO_MEDIA 0x3A\r | |
56 | #define USB_BOOT_ASC_MEDIA_CHANGE 0x28\r | |
57 | \r | |
58 | //\r | |
59 | // Supported PDT codes, or Peripheral Device Type\r | |
60 | //\r | |
61 | #define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device\r | |
62 | #define USB_PDT_CDROM 0x05 ///< CDROM\r | |
63 | #define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks\r | |
64 | #define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device\r | |
65 | \r | |
66 | //\r | |
67 | // Other parameters, Max carried size is 512B * 128 = 64KB\r | |
68 | //\r | |
69 | #define USB_BOOT_IO_BLOCKS 128\r | |
70 | \r | |
71 | //\r | |
72 | // Retry mass command times, set by experience\r | |
73 | //\r | |
74 | #define USB_BOOT_COMMAND_RETRY 5\r | |
1ccdbf2a | 75 | \r |
76 | //\r | |
77 | // Wait for unit ready command, set by experience\r | |
78 | //\r | |
79 | #define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)\r | |
80 | \r | |
81 | //\r | |
82 | // Mass command timeout, refers to specification[USB20-9.2.6.1]\r | |
83 | //\r | |
84 | // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy, \r | |
85 | // USB CD-Rom and iPod devices are much slower than USB key when reponse \r | |
86 | // most of commands, So we set 5s as timeout here.\r | |
87 | // \r | |
88 | #define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)\r | |
e237e7ae | 89 | \r |
90 | //\r | |
91 | // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r | |
92 | // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r | |
93 | // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r | |
41e8ff27 | 94 | // command to retrieve the disk gemotrics. \r |
e237e7ae | 95 | //\r |
96 | #pragma pack(1)\r | |
97 | typedef struct {\r | |
98 | UINT8 OpCode;\r | |
d80ed2a7 | 99 | UINT8 Lun; ///< Lun (high 3 bits)\r |
e237e7ae | 100 | UINT8 Reserved0[2];\r |
101 | UINT8 AllocLen;\r | |
102 | UINT8 Reserved1;\r | |
103 | UINT8 Pad[6];\r | |
104 | } USB_BOOT_INQUIRY_CMD;\r | |
105 | \r | |
106 | typedef struct {\r | |
d80ed2a7 | 107 | UINT8 Pdt; ///< Peripheral Device Type (low 5 bits)\r |
108 | UINT8 Removable; ///< Removable Media (highest bit)\r | |
e237e7ae | 109 | UINT8 Reserved0[2];\r |
d80ed2a7 | 110 | UINT8 AddLen; ///< Additional length\r |
e237e7ae | 111 | UINT8 Reserved1[3];\r |
112 | UINT8 VendorID[8];\r | |
113 | UINT8 ProductID[16];\r | |
114 | UINT8 ProductRevision[4];\r | |
115 | } USB_BOOT_INQUIRY_DATA;\r | |
116 | \r | |
117 | typedef struct {\r | |
118 | UINT8 OpCode;\r | |
119 | UINT8 Lun;\r | |
120 | UINT8 Reserved0[8];\r | |
121 | UINT8 Pad[2];\r | |
122 | } USB_BOOT_READ_CAPACITY_CMD;\r | |
123 | \r | |
124 | typedef struct {\r | |
125 | UINT8 LastLba[4];\r | |
126 | UINT8 BlockLen[4];\r | |
127 | } USB_BOOT_READ_CAPACITY_DATA;\r | |
128 | \r | |
129 | typedef struct {\r | |
130 | UINT8 OpCode;\r | |
131 | UINT8 Lun;\r | |
132 | UINT8 Reserved[4];\r | |
133 | UINT8 Pad[6];\r | |
134 | } USB_BOOT_TEST_UNIT_READY_CMD;\r | |
135 | \r | |
136 | typedef struct {\r | |
137 | UINT8 OpCode;\r | |
138 | UINT8 Lun;\r | |
139 | UINT8 PageCode;\r | |
140 | UINT8 Reserved0[4];\r | |
141 | UINT8 ParaListLenMsb;\r | |
142 | UINT8 ParaListLenLsb;\r | |
143 | UINT8 Reserved1;\r | |
144 | UINT8 Pad[2];\r | |
50fa1b3a | 145 | } USB_BOOT_MODE_SENSE10_CMD;\r |
e237e7ae | 146 | \r |
147 | typedef struct {\r | |
148 | UINT8 ModeDataLenMsb;\r | |
149 | UINT8 ModeDataLenLsb;\r | |
150 | UINT8 Reserved0[4];\r | |
151 | UINT8 BlkDesLenMsb;\r | |
152 | UINT8 BlkDesLenLsb;\r | |
50fa1b3a | 153 | } USB_BOOT_MODE_SENSE10_PARA_HEADER;\r |
e237e7ae | 154 | \r |
155 | typedef struct {\r | |
156 | UINT8 OpCode;\r | |
d80ed2a7 | 157 | UINT8 Lun; ///< Lun (High 3 bits)\r |
158 | UINT8 Lba[4]; ///< Logical block address\r | |
e237e7ae | 159 | UINT8 Reserved0;\r |
d80ed2a7 | 160 | UINT8 TransferLen[2]; ///< Transfer length\r |
e237e7ae | 161 | UINT8 Reserverd1;\r |
162 | UINT8 Pad[2];\r | |
163 | } USB_BOOT_READ10_CMD;\r | |
164 | \r | |
165 | typedef struct {\r | |
166 | UINT8 OpCode;\r | |
167 | UINT8 Lun;\r | |
168 | UINT8 Lba[4];\r | |
169 | UINT8 Reserved0;\r | |
170 | UINT8 TransferLen[2];\r | |
171 | UINT8 Reserverd1;\r | |
172 | UINT8 Pad[2];\r | |
173 | } USB_BOOT_WRITE10_CMD;\r | |
174 | \r | |
175 | typedef struct {\r | |
176 | UINT8 OpCode;\r | |
d80ed2a7 | 177 | UINT8 Lun; ///< Lun (High 3 bits)\r |
e237e7ae | 178 | UINT8 Reserved0[2];\r |
d80ed2a7 | 179 | UINT8 AllocLen; ///< Allocation length\r |
e237e7ae | 180 | UINT8 Reserved1;\r |
181 | UINT8 Pad[6];\r | |
182 | } USB_BOOT_REQUEST_SENSE_CMD;\r | |
183 | \r | |
184 | typedef struct {\r | |
185 | UINT8 ErrorCode;\r | |
186 | UINT8 Reserved0;\r | |
d80ed2a7 | 187 | UINT8 SenseKey; ///< Sense key (low 4 bits)\r |
e237e7ae | 188 | UINT8 Infor[4];\r |
d80ed2a7 | 189 | UINT8 AddLen; ///< Additional Sense length, 10\r |
e237e7ae | 190 | UINT8 Reserved1[4];\r |
1ccdbf2a | 191 | UINT8 Asc; ///< Additional Sense Code\r |
192 | UINT8 Ascq; ///< Additional Sense Code Qualifier\r | |
e237e7ae | 193 | UINT8 Reserverd2[4];\r |
194 | } USB_BOOT_REQUEST_SENSE_DATA;\r | |
50fa1b3a | 195 | \r |
196 | typedef struct {\r | |
197 | UINT8 OpCode;\r | |
198 | UINT8 Lun;\r | |
199 | UINT8 PageCode;\r | |
200 | UINT8 Reserved0;\r | |
201 | UINT8 AllocateLen;\r | |
202 | UINT8 Control;\r | |
203 | } USB_SCSI_MODE_SENSE6_CMD;\r | |
204 | \r | |
205 | typedef struct {\r | |
206 | UINT8 ModeDataLen;\r | |
41e8ff27 | 207 | UINT8 MediumType;\r |
50fa1b3a | 208 | UINT8 DevicePara;\r |
209 | UINT8 BlkDesLen;\r | |
210 | } USB_SCSI_MODE_SENSE6_PARA_HEADER;\r | |
e237e7ae | 211 | #pragma pack()\r |
212 | \r | |
213 | //\r | |
214 | // Convert a LUN number to that in the command\r | |
215 | //\r | |
216 | #define USB_BOOT_LUN(Lun) ((Lun) << 5)\r | |
217 | \r | |
218 | //\r | |
219 | // Get the removable, PDT, and sense key bits from the command data\r | |
220 | //\r | |
d80ed2a7 | 221 | #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)\r |
e237e7ae | 222 | #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r |
223 | #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r | |
224 | \r | |
cc5166ff | 225 | /**\r |
3e03cb4d | 226 | Get the parameters for the USB mass storage media.\r |
227 | \r | |
228 | This function get the parameters for the USB mass storage media,\r | |
229 | It is used both to initialize the media during the Start() phase\r | |
230 | of Driver Binding Protocol and to re-initialize it when the media is\r | |
cc5166ff | 231 | changed. Althought the RemoveableMedia is unlikely to change,\r |
3e03cb4d | 232 | it is also included here.\r |
cc5166ff | 233 | \r |
3e03cb4d | 234 | @param UsbMass The device to retrieve disk gemotric.\r |
cc5166ff | 235 | \r |
236 | @retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r | |
3e03cb4d | 237 | @retval Other Failed to get the parameters.\r |
cc5166ff | 238 | \r |
239 | **/\r | |
e237e7ae | 240 | EFI_STATUS\r |
241 | UsbBootGetParams (\r | |
242 | IN USB_MASS_DEVICE *UsbMass\r | |
243 | );\r | |
244 | \r | |
cc5166ff | 245 | /**\r |
3e03cb4d | 246 | Execute TEST UNIT READY command to check if the device is ready.\r |
cc5166ff | 247 | \r |
248 | @param UsbMass The device to test\r | |
249 | \r | |
3e03cb4d | 250 | @retval EFI_SUCCESS The device is ready.\r |
cc5166ff | 251 | @retval Others Device not ready.\r |
252 | \r | |
253 | **/\r | |
e237e7ae | 254 | EFI_STATUS\r |
255 | UsbBootIsUnitReady (\r | |
256 | IN USB_MASS_DEVICE *UsbMass\r | |
257 | );\r | |
258 | \r | |
cc5166ff | 259 | /**\r |
260 | Detect whether the removable media is present and whether it has changed.\r | |
cc5166ff | 261 | \r |
3e03cb4d | 262 | @param UsbMass The device to check.\r |
cc5166ff | 263 | \r |
3e03cb4d | 264 | @retval EFI_SUCCESS The media status is successfully checked.\r |
265 | @retval Other Failed to detect media.\r | |
cc5166ff | 266 | \r |
267 | **/\r | |
e237e7ae | 268 | EFI_STATUS\r |
269 | UsbBootDetectMedia (\r | |
270 | IN USB_MASS_DEVICE *UsbMass\r | |
271 | );\r | |
272 | \r | |
cc5166ff | 273 | /**\r |
274 | Read some blocks from the device.\r | |
275 | \r | |
276 | @param UsbMass The USB mass storage device to read from\r | |
277 | @param Lba The start block number\r | |
278 | @param TotalBlock Total block number to read\r | |
279 | @param Buffer The buffer to read to\r | |
280 | \r | |
281 | @retval EFI_SUCCESS Data are read into the buffer\r | |
282 | @retval Others Failed to read all the data\r | |
283 | \r | |
284 | **/\r | |
e237e7ae | 285 | EFI_STATUS\r |
286 | UsbBootReadBlocks (\r | |
287 | IN USB_MASS_DEVICE *UsbMass,\r | |
288 | IN UINT32 Lba,\r | |
289 | IN UINTN TotalBlock,\r | |
290 | OUT UINT8 *Buffer\r | |
291 | );\r | |
292 | \r | |
cc5166ff | 293 | /**\r |
294 | Write some blocks to the device.\r | |
295 | \r | |
296 | @param UsbMass The USB mass storage device to write to\r | |
297 | @param Lba The start block number\r | |
298 | @param TotalBlock Total block number to write\r | |
3e03cb4d | 299 | @param Buffer Pointer to the source buffer for the data.\r |
cc5166ff | 300 | \r |
301 | @retval EFI_SUCCESS Data are written into the buffer\r | |
302 | @retval Others Failed to write all the data\r | |
303 | \r | |
304 | **/\r | |
e237e7ae | 305 | EFI_STATUS\r |
306 | UsbBootWriteBlocks (\r | |
307 | IN USB_MASS_DEVICE *UsbMass,\r | |
308 | IN UINT32 Lba,\r | |
309 | IN UINTN TotalBlock,\r | |
3e03cb4d | 310 | IN UINT8 *Buffer\r |
e237e7ae | 311 | );\r |
3e03cb4d | 312 | \r |
99c1725e | 313 | /**\r |
314 | Read some blocks from the device by SCSI 16 byte cmd.\r | |
315 | \r | |
316 | @param UsbMass The USB mass storage device to read from\r | |
317 | @param Lba The start block number\r | |
318 | @param TotalBlock Total block number to read\r | |
319 | @param Buffer The buffer to read to\r | |
320 | \r | |
321 | @retval EFI_SUCCESS Data are read into the buffer\r | |
322 | @retval Others Failed to read all the data\r | |
323 | \r | |
324 | **/\r | |
325 | EFI_STATUS\r | |
326 | UsbBootReadBlocks16 (\r | |
327 | IN USB_MASS_DEVICE *UsbMass,\r | |
328 | IN UINT64 Lba,\r | |
329 | IN UINTN TotalBlock,\r | |
330 | OUT UINT8 *Buffer\r | |
331 | );\r | |
332 | \r | |
333 | /**\r | |
334 | Write some blocks to the device by SCSI 16 byte cmd.\r | |
335 | \r | |
336 | @param UsbMass The USB mass storage device to write to\r | |
337 | @param Lba The start block number\r | |
338 | @param TotalBlock Total block number to write\r | |
339 | @param Buffer Pointer to the source buffer for the data.\r | |
340 | \r | |
341 | @retval EFI_SUCCESS Data are written into the buffer\r | |
342 | @retval Others Failed to write all the data\r | |
343 | \r | |
344 | **/\r | |
345 | EFI_STATUS\r | |
346 | UsbBootWriteBlocks16 (\r | |
347 | IN USB_MASS_DEVICE *UsbMass,\r | |
348 | IN UINT64 Lba,\r | |
349 | IN UINTN TotalBlock,\r | |
350 | IN UINT8 *Buffer\r | |
351 | );\r | |
352 | \r | |
353 | \r | |
3e03cb4d | 354 | /**\r |
355 | Use the USB clear feature control transfer to clear the endpoint stall condition.\r | |
356 | \r | |
357 | @param UsbIo The USB I/O Protocol instance\r | |
358 | @param EndpointAddr The endpoint to clear stall for\r | |
359 | \r | |
360 | @retval EFI_SUCCESS The endpoint stall condition is cleared.\r | |
361 | @retval Others Failed to clear the endpoint stall condition.\r | |
362 | \r | |
363 | **/\r | |
364 | EFI_STATUS\r | |
365 | UsbClearEndpointStall (\r | |
366 | IN EFI_USB_IO_PROTOCOL *UsbIo,\r | |
367 | IN UINT8 EndpointAddr\r | |
368 | );\r | |
369 | \r | |
e237e7ae | 370 | #endif\r |
371 | \r |