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