]>
Commit | Line | Data |
---|---|---|
e237e7ae | 1 | /** @file\r |
2 | \r | |
3 | Copyright (c) 2007, Intel Corporation\r | |
4 | All rights reserved. This program and the accompanying materials\r | |
5 | are licensed and made available under the terms and conditions of the BSD License\r | |
6 | which accompanies this distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | UsbMassBoot.h\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | The definition of command and data of the USB mass storage for\r | |
19 | bootability command set.\r | |
20 | \r | |
21 | Revision History\r | |
22 | \r | |
23 | \r | |
24 | **/\r | |
25 | \r | |
26 | #ifndef _EFI_USB_MASS_BOOT_H_\r | |
27 | #define _EFI_USB_MASS_BOOT_H_\r | |
28 | \r | |
29 | enum {\r | |
30 | //\r | |
31 | // The opcodes of various usb boot commands:\r | |
32 | // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r | |
33 | // by MMC command set. Others are "Group 1 Timeout Commands". That\r | |
41e8ff27 | 34 | // is they should be retried if driver is ready. \r |
35 | // We can't use the Peripheral Device Type in Inquiry data to \r | |
e237e7ae | 36 | // determine the timeout used. For example, both floppy and flash\r |
37 | // are likely set their PDT to 0, or Direct Access Device.\r | |
38 | //\r | |
39 | USB_BOOT_INQUIRY_OPCODE = 0x12,\r | |
40 | USB_BOOT_REQUEST_SENSE_OPCODE = 0x03,\r | |
50fa1b3a | 41 | USB_BOOT_MODE_SENSE10_OPCODE = 0x5A,\r |
e237e7ae | 42 | USB_BOOT_READ_CAPACITY_OPCODE = 0x25,\r |
43 | USB_BOOT_TEST_UNIT_READY_OPCODE = 0x00,\r | |
44 | USB_BOOT_READ10_OPCODE = 0x28,\r | |
50fa1b3a | 45 | USB_BOOT_WRITE10_OPCODE = 0x2A,\r |
e237e7ae | 46 | \r |
50fa1b3a | 47 | USB_SCSI_MODE_SENSE6_OPCODE = 0x1A,\r |
48 | \r | |
e237e7ae | 49 | //\r |
50 | // The Sense Key part of the sense data. Sense data has three levels:\r | |
51 | // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r | |
52 | //\r | |
53 | USB_BOOT_SENSE_NO_SENSE = 0x00, // No sense key\r | |
54 | USB_BOOT_SENSE_RECOVERED = 0x01, // Last command succeed with recovery actions\r | |
55 | USB_BOOT_SENSE_NOT_READY = 0x02, // Device not ready\r | |
56 | USB_BOOT_SNESE_MEDIUM_ERROR = 0X03, // Failed probably because flaw in the media\r | |
57 | USB_BOOT_SENSE_HARDWARE_ERROR = 0X04, // Non-recoverable hardware failure\r | |
58 | USB_BOOT_SENSE_ILLEGAL_REQUEST = 0X05, // Illegal parameters in the request\r | |
59 | USB_BOOT_SENSE_UNIT_ATTENTION = 0X06, // Removable medium may have been changed\r | |
60 | USB_BOOT_SNESE_DATA_PROTECT = 0X07, // Write protected\r | |
61 | USB_BOOT_SENSE_BLANK_CHECK = 0X08, // Blank/non-blank medium while reading/writing\r | |
62 | USB_BOOT_SENSE_VENDOR = 0X09, // Vendor specific sense key\r | |
63 | USB_BOOT_SENSE_ABORTED = 0X0B, // Command aborted by the device\r | |
64 | USB_BOOT_SENSE_VOLUME_OVERFLOW = 0x0D, // Partition overflow\r | |
65 | USB_BOOT_SENSE_MISCOMPARE = 0x0E, // Source data mis-match while verfying.\r | |
66 | \r | |
67 | USB_BOOT_ASC_NOT_READY = 0x04,\r | |
e237e7ae | 68 | USB_BOOT_ASC_NO_MEDIA = 0x3A,\r |
69 | USB_BOOT_ASC_MEDIA_CHANGE = 0x28,\r | |
70 | \r | |
e237e7ae | 71 | //\r |
41e8ff27 | 72 | // Supported PDT codes, or Peripheral Device Type\r |
73 | //\r | |
74 | USB_PDT_DIRECT_ACCESS = 0x00, // Direct access device\r | |
75 | USB_PDT_CDROM = 0x05, // CDROM\r | |
76 | USB_PDT_OPTICAL = 0x07, // Non-CD optical disks\r | |
77 | USB_PDT_SIMPLE_DIRECT = 0x0E, // Simplified direct access device\r | |
78 | \r | |
79 | //\r | |
80 | // Other parameters, Max carried size is 512B * 128 = 64KB\r | |
e237e7ae | 81 | //\r |
41e8ff27 | 82 | USB_BOOT_IO_BLOCKS = 128,\r |
e237e7ae | 83 | \r |
84 | //\r | |
41e8ff27 | 85 | // Retry mass command times, set by experience\r |
e237e7ae | 86 | //\r |
87 | USB_BOOT_COMMAND_RETRY = 5,\r | |
41e8ff27 | 88 | USB_BOOT_INIT_MEDIA_RETRY = 5,\r |
e237e7ae | 89 | \r |
90 | //\r | |
41e8ff27 | 91 | // Wait for unit ready command, set by experience\r |
e237e7ae | 92 | //\r |
41e8ff27 | 93 | USB_BOOT_RETRY_UNIT_READY_STALL = 500 * USB_MASS_1_MILLISECOND,\r |
e237e7ae | 94 | \r |
95 | //\r | |
41e8ff27 | 96 | // Mass command timeout, refers to specification[USB20-9.2.6.1]\r |
e237e7ae | 97 | //\r |
50fa1b3a | 98 | // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy, \r |
99 | // USB CD-Rom and iPod devices are much slower than USB key when reponse \r | |
100 | // most of commands, So we set 5s as timeout here.\r | |
101 | // \r | |
102 | //\r | |
23c326c2 | 103 | USB_BOOT_GENERAL_CMD_TIMEOUT = 5 * USB_MASS_1_SECOND\r |
e237e7ae | 104 | };\r |
105 | \r | |
106 | //\r | |
107 | // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r | |
108 | // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r | |
109 | // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r | |
41e8ff27 | 110 | // command to retrieve the disk gemotrics. \r |
e237e7ae | 111 | //\r |
112 | #pragma pack(1)\r | |
113 | typedef struct {\r | |
114 | UINT8 OpCode;\r | |
115 | UINT8 Lun; // Lun (high 3 bits)\r | |
116 | UINT8 Reserved0[2];\r | |
117 | UINT8 AllocLen;\r | |
118 | UINT8 Reserved1;\r | |
119 | UINT8 Pad[6];\r | |
120 | } USB_BOOT_INQUIRY_CMD;\r | |
121 | \r | |
122 | typedef struct {\r | |
123 | UINT8 Pdt; // Peripheral Device Type (low 5 bits)\r | |
124 | UINT8 Removable; // Removable Media (highest bit)\r | |
125 | UINT8 Reserved0[2];\r | |
126 | UINT8 AddLen; // Additional length\r | |
127 | UINT8 Reserved1[3];\r | |
128 | UINT8 VendorID[8];\r | |
129 | UINT8 ProductID[16];\r | |
130 | UINT8 ProductRevision[4];\r | |
131 | } USB_BOOT_INQUIRY_DATA;\r | |
132 | \r | |
133 | typedef struct {\r | |
134 | UINT8 OpCode;\r | |
135 | UINT8 Lun;\r | |
136 | UINT8 Reserved0[8];\r | |
137 | UINT8 Pad[2];\r | |
138 | } USB_BOOT_READ_CAPACITY_CMD;\r | |
139 | \r | |
140 | typedef struct {\r | |
141 | UINT8 LastLba[4];\r | |
142 | UINT8 BlockLen[4];\r | |
143 | } USB_BOOT_READ_CAPACITY_DATA;\r | |
144 | \r | |
145 | typedef struct {\r | |
146 | UINT8 OpCode;\r | |
147 | UINT8 Lun;\r | |
148 | UINT8 Reserved[4];\r | |
149 | UINT8 Pad[6];\r | |
150 | } USB_BOOT_TEST_UNIT_READY_CMD;\r | |
151 | \r | |
152 | typedef struct {\r | |
153 | UINT8 OpCode;\r | |
154 | UINT8 Lun;\r | |
155 | UINT8 PageCode;\r | |
156 | UINT8 Reserved0[4];\r | |
157 | UINT8 ParaListLenMsb;\r | |
158 | UINT8 ParaListLenLsb;\r | |
159 | UINT8 Reserved1;\r | |
160 | UINT8 Pad[2];\r | |
50fa1b3a | 161 | } USB_BOOT_MODE_SENSE10_CMD;\r |
e237e7ae | 162 | \r |
163 | typedef struct {\r | |
164 | UINT8 ModeDataLenMsb;\r | |
165 | UINT8 ModeDataLenLsb;\r | |
166 | UINT8 Reserved0[4];\r | |
167 | UINT8 BlkDesLenMsb;\r | |
168 | UINT8 BlkDesLenLsb;\r | |
50fa1b3a | 169 | } USB_BOOT_MODE_SENSE10_PARA_HEADER;\r |
e237e7ae | 170 | \r |
171 | typedef struct {\r | |
172 | UINT8 OpCode;\r | |
173 | UINT8 Lun; // Lun (High 3 bits)\r | |
174 | UINT8 Lba[4]; // Logical block address\r | |
175 | UINT8 Reserved0;\r | |
176 | UINT8 TransferLen[2]; // Transfer length\r | |
177 | UINT8 Reserverd1;\r | |
178 | UINT8 Pad[2];\r | |
179 | } USB_BOOT_READ10_CMD;\r | |
180 | \r | |
181 | typedef struct {\r | |
182 | UINT8 OpCode;\r | |
183 | UINT8 Lun;\r | |
184 | UINT8 Lba[4];\r | |
185 | UINT8 Reserved0;\r | |
186 | UINT8 TransferLen[2];\r | |
187 | UINT8 Reserverd1;\r | |
188 | UINT8 Pad[2];\r | |
189 | } USB_BOOT_WRITE10_CMD;\r | |
190 | \r | |
191 | typedef struct {\r | |
192 | UINT8 OpCode;\r | |
193 | UINT8 Lun; // Lun (High 3 bits)\r | |
194 | UINT8 Reserved0[2];\r | |
195 | UINT8 AllocLen; // Allocation length\r | |
196 | UINT8 Reserved1;\r | |
197 | UINT8 Pad[6];\r | |
198 | } USB_BOOT_REQUEST_SENSE_CMD;\r | |
199 | \r | |
200 | typedef struct {\r | |
201 | UINT8 ErrorCode;\r | |
202 | UINT8 Reserved0;\r | |
203 | UINT8 SenseKey; // Sense key (low 4 bits)\r | |
204 | UINT8 Infor[4];\r | |
205 | UINT8 AddLen; // Additional Sense length, 10\r | |
206 | UINT8 Reserved1[4];\r | |
207 | UINT8 ASC; // Additional Sense Code\r | |
208 | UINT8 ASCQ; // Additional Sense Code Qualifier\r | |
209 | UINT8 Reserverd2[4];\r | |
210 | } USB_BOOT_REQUEST_SENSE_DATA;\r | |
50fa1b3a | 211 | \r |
212 | typedef struct {\r | |
213 | UINT8 OpCode;\r | |
214 | UINT8 Lun;\r | |
215 | UINT8 PageCode;\r | |
216 | UINT8 Reserved0;\r | |
217 | UINT8 AllocateLen;\r | |
218 | UINT8 Control;\r | |
219 | } USB_SCSI_MODE_SENSE6_CMD;\r | |
220 | \r | |
221 | typedef struct {\r | |
222 | UINT8 ModeDataLen;\r | |
41e8ff27 | 223 | UINT8 MediumType;\r |
50fa1b3a | 224 | UINT8 DevicePara;\r |
225 | UINT8 BlkDesLen;\r | |
226 | } USB_SCSI_MODE_SENSE6_PARA_HEADER;\r | |
e237e7ae | 227 | #pragma pack()\r |
228 | \r | |
229 | //\r | |
230 | // Convert a LUN number to that in the command\r | |
231 | //\r | |
232 | #define USB_BOOT_LUN(Lun) ((Lun) << 5)\r | |
233 | \r | |
234 | //\r | |
235 | // Get the removable, PDT, and sense key bits from the command data\r | |
236 | //\r | |
237 | #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)\r | |
238 | #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r | |
239 | #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r | |
240 | \r | |
241 | //\r | |
242 | // Swap the byte sequence of a UINT32. Intel CPU uses little endian\r | |
243 | // in UEFI environment, but USB boot uses big endian.\r | |
244 | //\r | |
245 | #define USB_BOOT_SWAP32(Data32) \\r | |
246 | ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \\r | |
41e8ff27 | 247 | (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8)) \r |
e237e7ae | 248 | \r |
249 | #define USB_BOOT_SWAP16(Data16) \\r | |
250 | ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))\r | |
251 | \r | |
252 | EFI_STATUS\r | |
253 | UsbBootGetParams (\r | |
254 | IN USB_MASS_DEVICE *UsbMass\r | |
255 | );\r | |
256 | \r | |
257 | EFI_STATUS\r | |
258 | UsbBootIsUnitReady (\r | |
259 | IN USB_MASS_DEVICE *UsbMass\r | |
260 | );\r | |
261 | \r | |
262 | EFI_STATUS\r | |
263 | UsbBootDetectMedia (\r | |
264 | IN USB_MASS_DEVICE *UsbMass\r | |
265 | );\r | |
266 | \r | |
267 | EFI_STATUS\r | |
268 | UsbBootReadBlocks (\r | |
269 | IN USB_MASS_DEVICE *UsbMass,\r | |
270 | IN UINT32 Lba,\r | |
271 | IN UINTN TotalBlock,\r | |
272 | OUT UINT8 *Buffer\r | |
273 | );\r | |
274 | \r | |
275 | EFI_STATUS\r | |
276 | UsbBootWriteBlocks (\r | |
277 | IN USB_MASS_DEVICE *UsbMass,\r | |
278 | IN UINT32 Lba,\r | |
279 | IN UINTN TotalBlock,\r | |
280 | OUT UINT8 *Buffer\r | |
281 | );\r | |
282 | #endif\r | |
283 | \r |