TianoCore EDK2 master
Loading...
Searching...
No Matches
UsbMassBoot.h
Go to the documentation of this file.
1
10#ifndef _EFI_USB_MASS_BOOT_H_
11#define _EFI_USB_MASS_BOOT_H_
12
13//
14// The opcodes of various USB boot commands:
15// INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified
16// by Multi-Media Commands (MMC) set.
17// Others are "Group 1 Timeout Commands". That is,
18// they should be retried if driver is ready.
19//
20#define USB_BOOT_INQUIRY_OPCODE 0x12
21#define USB_BOOT_REQUEST_SENSE_OPCODE 0x03
22#define USB_BOOT_MODE_SENSE10_OPCODE 0x5A
23#define USB_BOOT_READ_CAPACITY_OPCODE 0x25
24#define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00
25#define USB_BOOT_READ10_OPCODE 0x28
26#define USB_BOOT_WRITE10_OPCODE 0x2A
27
28#define USB_SCSI_MODE_SENSE6_OPCODE 0x1A
29
30//
31// The Sense Key part of the sense data. Sense data has three levels:
32// Sense key, Additional Sense Code and Additional Sense Code Qualifier
33//
34#define USB_BOOT_SENSE_NO_SENSE 0x00
35#define USB_BOOT_SENSE_RECOVERED 0x01
36#define USB_BOOT_SENSE_NOT_READY 0x02
37#define USB_BOOT_SNESE_MEDIUM_ERROR 0X03
38#define USB_BOOT_SENSE_HARDWARE_ERROR 0X04
39#define USB_BOOT_SENSE_ILLEGAL_REQUEST 0X05
40#define USB_BOOT_SENSE_UNIT_ATTENTION 0X06
41#define USB_BOOT_SENSE_DATA_PROTECT 0X07
42#define USB_BOOT_SENSE_BLANK_CHECK 0X08
43#define USB_BOOT_SENSE_VENDOR 0X09
44#define USB_BOOT_SENSE_ABORTED 0X0B
45#define USB_BOOT_SENSE_VOLUME_OVERFLOW 0x0D
46#define USB_BOOT_SENSE_MISCOMPARE 0x0E
47
48#define USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00
49#define USB_BOOT_ASC_NOT_READY 0x04
50#define USB_BOOT_ASC_NO_MEDIA 0x3A
51#define USB_BOOT_ASC_MEDIA_CHANGE 0x28
52
53//
54// Supported PDT codes, or Peripheral Device Type
55//
56#define USB_PDT_DIRECT_ACCESS 0x00
57#define USB_PDT_CDROM 0x05
58#define USB_PDT_OPTICAL 0x07
59#define USB_PDT_SIMPLE_DIRECT 0x0E
60
61//
62// Other parameters, Max carried size is 64KB.
63//
64#define USB_BOOT_MAX_CARRY_SIZE SIZE_64KB
65
66//
67// Retry mass command times, set by experience
68//
69#define USB_BOOT_COMMAND_RETRY 5
70
71//
72// Wait for unit ready command, set by experience
73//
74#define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)
75
76//
77// Mass command timeout, refers to specification[USB20-9.2.6.1]
78//
79// USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,
80// USB CD-Rom and iPod devices are much slower than USB key when response
81// most of commands, So we set 5s as timeout here.
82//
83#define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)
84
85//
86// The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,
87// READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA
88// so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY
89// command to retrieve the disk gemotrics.
90//
91#pragma pack(1)
92typedef struct {
93 UINT8 OpCode;
94 UINT8 Lun;
95 UINT8 Reserved0[2];
96 UINT8 AllocLen;
97 UINT8 Reserved1;
98 UINT8 Pad[6];
100
101typedef struct {
102 UINT8 Pdt;
103 UINT8 Removable;
104 UINT8 Reserved0[2];
105 UINT8 AddLen;
106 UINT8 Reserved1[3];
107 UINT8 VendorID[8];
108 UINT8 ProductID[16];
109 UINT8 ProductRevision[4];
111
112typedef struct {
113 UINT8 OpCode;
114 UINT8 Lun;
115 UINT8 Reserved0[8];
116 UINT8 Pad[2];
118
119typedef struct {
120 UINT8 LastLba[4];
121 UINT8 BlockLen[4];
123
124typedef struct {
125 UINT8 OpCode;
126 UINT8 Lun;
127 UINT8 Reserved[4];
128 UINT8 Pad[6];
130
131typedef struct {
132 UINT8 OpCode;
133 UINT8 Lun;
134 UINT8 PageCode;
135 UINT8 Reserved0[4];
136 UINT8 ParaListLenMsb;
137 UINT8 ParaListLenLsb;
138 UINT8 Reserved1;
139 UINT8 Pad[2];
141
142typedef struct {
143 UINT8 ModeDataLenMsb;
144 UINT8 ModeDataLenLsb;
145 UINT8 Reserved0[4];
146 UINT8 BlkDesLenMsb;
147 UINT8 BlkDesLenLsb;
149
150typedef struct {
151 UINT8 OpCode;
152 UINT8 Lun;
153 UINT8 Lba[4];
154 UINT8 Reserved0;
155 UINT8 TransferLen[2];
156 UINT8 Reserverd1;
157 UINT8 Pad[2];
159
160typedef struct {
161 UINT8 OpCode;
162 UINT8 Lun;
163 UINT8 Reserved0[2];
164 UINT8 AllocLen;
165 UINT8 Reserved1;
166 UINT8 Pad[6];
168
169typedef struct {
170 UINT8 ErrorCode;
171 UINT8 Reserved0;
172 UINT8 SenseKey;
173 UINT8 Infor[4];
174 UINT8 AddLen;
175 UINT8 Reserved1[4];
176 UINT8 Asc;
177 UINT8 Ascq;
178 UINT8 Reserverd2[4];
180
181typedef struct {
182 UINT8 OpCode;
183 UINT8 Lun;
184 UINT8 PageCode;
185 UINT8 Reserved0;
186 UINT8 AllocateLen;
187 UINT8 Control;
189
190typedef struct {
191 UINT8 ModeDataLen;
192 UINT8 MediumType;
193 UINT8 DevicePara;
194 UINT8 BlkDesLen;
196#pragma pack()
197
198//
199// Convert a LUN number to that in the command
200//
201#define USB_BOOT_LUN(Lun) ((Lun) << 5)
202
203//
204// Get the removable, PDT, and sense key bits from the command data
205//
206#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)
207#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
208#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
209
227 IN USB_MASS_DEVICE *UsbMass
228 );
229
241 IN USB_MASS_DEVICE *UsbMass
242 );
243
255 IN USB_MASS_DEVICE *UsbMass
256 );
257
272 IN USB_MASS_DEVICE *UsbMass,
273 IN UINT32 Lba,
274 IN UINTN TotalBlock,
275 OUT UINT8 *Buffer
276 );
277
293 IN USB_MASS_DEVICE *UsbMass,
294 IN BOOLEAN Write,
295 IN UINT32 Lba,
296 IN UINTN TotalBlock,
297 IN OUT UINT8 *Buffer
298 );
299
314 IN USB_MASS_DEVICE *UsbMass,
315 IN BOOLEAN Write,
316 IN UINT64 Lba,
317 IN UINTN TotalBlock,
318 IN OUT UINT8 *Buffer
319 );
320
333 IN EFI_USB_IO_PROTOCOL *UsbIo,
334 IN UINT8 EndpointAddr
335 );
336
337#endif
UINT64 UINTN
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS UsbBootGetParams(IN USB_MASS_DEVICE *UsbMass)
Definition: UsbMassBoot.c:624
EFI_STATUS UsbBootIsUnitReady(IN USB_MASS_DEVICE *UsbMass)
Definition: UsbMassBoot.c:322
EFI_STATUS UsbBootReadWriteBlocks(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT32 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
Definition: UsbMassBoot.c:810
EFI_STATUS UsbBootReadBlocks(IN USB_MASS_DEVICE *UsbMass, IN UINT32 Lba, IN UINTN TotalBlock, OUT UINT8 *Buffer)
EFI_STATUS UsbBootReadWriteBlocks16(IN USB_MASS_DEVICE *UsbMass, IN BOOLEAN Write, IN UINT64 Lba, IN UINTN TotalBlock, IN OUT UINT8 *Buffer)
Definition: UsbMassBoot.c:896
EFI_STATUS UsbBootDetectMedia(IN USB_MASS_DEVICE *UsbMass)
Definition: UsbMassBoot.c:682
EFI_STATUS UsbClearEndpointStall(IN EFI_USB_IO_PROTOCOL *UsbIo, IN UINT8 EndpointAddr)
Definition: UsbMassBoot.c:977
UINT8 Lun
Lun (high 3 bits)
Definition: UsbMassBoot.h:94
UINT8 Pdt
Peripheral Device Type (low 5 bits)
Definition: UsbMassBoot.h:102
UINT8 AddLen
Additional length.
Definition: UsbMassBoot.h:105
UINT8 Removable
Removable Media (highest bit)
Definition: UsbMassBoot.h:103
UINT8 Lun
Lun (High 3 bits)
Definition: UsbMassBoot.h:152
UINT8 AllocLen
Allocation length.
Definition: UsbMassBoot.h:164
UINT8 Lun
Lun (High 3 bits)
Definition: UsbMassBoot.h:162
UINT8 Ascq
Additional Sense Code Qualifier.
Definition: UsbMassBoot.h:177
UINT8 Asc
Additional Sense Code.
Definition: UsbMassBoot.h:176
UINT8 SenseKey
Sense key (low 4 bits)
Definition: UsbMassBoot.h:172
UINT8 AddLen
Additional Sense length, 10.
Definition: UsbMassBoot.h:174