Update EdkShellPkg to remove the external Shell directory from EDK shell project.
[mirror_edk2.git] / EdkShellPkg / ShellHotFix.patch
CommitLineData
0fe4decf 1Index: drivers/drivers.c\r
2===================================================================\r
3--- drivers/drivers.c (revision 30)\r
4+++ drivers/drivers.c (working copy)\r
5@@ -130,6 +130,7 @@\r
6 UINTN StringIndex;
7 UINTN Index;
8 CHAR8 *Language;
9+ CHAR8 *PlatformLanguage;
10 UINTN DriverImageHandleCount;
11 EFI_HANDLE *DriverImageHandleBuffer;
12 UINTN HandleIndex;
13@@ -152,6 +153,7 @@\r
14 SHELL_VAR_CHECK_PACKAGE ChkPck;
15
16 Language = NULL;
17+ PlatformLanguage = NULL;
18 DriverImageHandleCount = 0;
19 DriverImageHandleBuffer = NULL;
20 IsHelp = FALSE;
21@@ -241,7 +243,7 @@\r
22 goto Done;
23 }
24
25- Language = LibGetVariableLang ();
26+ Language = LibGetVariable (L"Lang", &gEfiGlobalVariableGuid);
27 if (Language == NULL) {
28 Language = (CHAR8 *)AllocateZeroPool(strlena(LanguageCodeEnglish) + 1);
29 if (Language == NULL) {
30@@ -250,6 +252,15 @@\r
31 strcpya(Language, LanguageCodeEnglish);
32 }
33
34+ PlatformLanguage = LibGetVariable (L"PlatformLang", &gEfiGlobalVariableGuid);
35+ if (PlatformLanguage == NULL) {
36+ PlatformLanguage = (CHAR8 *)AllocateZeroPool(strlena(PlatformLanguageCodeEnglish) + 1);
37+ if (PlatformLanguage == NULL) {
38+ return EFI_OUT_OF_RESOURCES;
39+ }
40+ strcpya(PlatformLanguage, PlatformLanguageCodeEnglish);
41+ }
42+
43 Item = LibCheckVarGetFlag (&ChkPck, L"-l");
44 if (Item) {
45 if (Language != NULL) {
46@@ -314,14 +325,6 @@\r
47 EFI_OPEN_PROTOCOL_GET_PROTOCOL
48 );
49
50- ComponentName = NULL;
51- ComponentName2 = NULL;
52- Status = LibGetComponentNameProtocol (
53- DriverImageHandleBuffer[Index],
54- &ComponentName,
55- &ComponentName2
56- );
57-
58 DiagnosticsStatus = BS->OpenProtocol (
59 DriverImageHandleBuffer[Index],
60 &gEfiDriverDiagnostics2ProtocolGuid,
61@@ -418,37 +421,73 @@\r
62 } else {
63 PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_D), HiiHandle, NumberOfChildren);
64 }
65-
66- Status = EFI_SUCCESS;
67+
68 DriverName = L"<UNKNOWN>";
69- SupportedLanguage = NULL;
70- if (ComponentName != NULL) {
71- if (ComponentName->GetDriverName != NULL) {
72- SupportedLanguage = LibConvertSupportedLanguage (ComponentName->SupportedLanguages, Language);
73+ Status = BS->OpenProtocol (
74+ DriverImageHandleBuffer[Index],
75+ &gEfiComponentName2ProtocolGuid,
76+ (VOID **) &ComponentName2,
77+ NULL,
78+ NULL,
79+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
80+ );
81+ if (!EFI_ERROR (Status)) {
82+ //
83+ // Driver has Component Name 2 Protocol is available, we get the
84+ // driver name var RFC 3066 language code
85+ //
86+ Status = ComponentName2->GetDriverName (
87+ ComponentName2,
88+ PlatformLanguage,
89+ &DriverName
90+ );
91+ if (EFI_ERROR (Status)) {
92+ //
93+ // Current RFC3066 language code fails, we then extract the supported
94+ // language from Component Name 2 protocol interface.
95+ //
96+ SupportedLanguage = ExtractSupportedLanguage(ComponentName2->SupportedLanguages, Language);
97+ if (SupportedLanguage != NULL) {
98+ Status = ComponentName2->GetDriverName (
99+ ComponentName2,
100+ SupportedLanguage,
101+ &DriverName
102+ );
103+ FreePool(SupportedLanguage);
104+ }
105+ }
106+ }
107+ if (EFI_ERROR (Status)) {
108+ //
109+ // In case Component Name 2 protocol is not available or some error occurs
110+ // when getting driver name from Component Name 2 protocol, we get driver
111+ // name from Component Name protocol.
112+ //
113+ Status = BS->OpenProtocol (
114+ DriverImageHandleBuffer[Index],
115+ &gEfiComponentNameProtocolGuid,
116+ (VOID **) &ComponentName,
117+ NULL,
118+ NULL,
119+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
120+ );
121+ if (!EFI_ERROR (Status)) {
122 Status = ComponentName->GetDriverName (
123 ComponentName,
124- SupportedLanguage,
125+ Language,
126 &DriverName
127 );
128 }
129- } else if (ComponentName2 != NULL) {
130- if (ComponentName2->GetDriverName != NULL) {
131- SupportedLanguage = LibConvertSupportedLanguage (ComponentName2->SupportedLanguages, Language);
132- Status = ComponentName2->GetDriverName (
133- ComponentName2,
134- SupportedLanguage,
135- &DriverName
136- );
137- }
138 }
139- if (SupportedLanguage != NULL) {
140- FreePool (SupportedLanguage);
141- }
142-
143 if (EFI_ERROR (Status)) {
144+ //
145+ // Fails to get driver name from either Component Name 2 & Component Name
146+ // Protocol, we show "<UNKNOWN>" string as driver name.
147+ //
148 DriverName = L"<UNKNOWN>";
149 }
150
151+
152 for (StringIndex = 0; StringIndex < StrLen (DriverName) && StringIndex < 35; StringIndex++) {
153 FormattedDriverName[StringIndex] = DriverName[StringIndex];
154 }
155@@ -491,6 +530,10 @@\r
156 FreePool (Language);
157 }
158
159+ if (PlatformLanguage != NULL) {
160+ FreePool (PlatformLanguage);
161+ }
162+
163 ShellCloseHandleEnumerator ();
164 LibCheckVarFreeVarList (&ChkPck);
165 LibUnInitializeStrings ();
f8a6b282 166Index: edit/libFileBuffer.c\r
167===================================================================\r
168--- edit/libFileBuffer.c (revision 30)\r
169+++ edit/libFileBuffer.c (working copy)\r
170@@ -735,7 +735,7 @@\r
171 UINTN LineSize;
172 VOID *Buffer;
173 CHAR16 *UnicodeBuffer;
174- CHAR8 *AsciiBuffer;
175+ UINT8 *AsciiBuffer;
176 UINTN FileSize;
177 EFI_FILE_HANDLE Handle;
178 BOOLEAN CreateFile;
179@@ -1047,7 +1047,7 @@\r
180 //
181 // Unicode file
182 //
183- if (AsciiBuffer[0] == 0xff && AsciiBuffer[1] == 0xfe) {
184+ if ((FileSize >= 2) && (*((UINT16 *) Buffer) == EFI_UNICODE_BYTE_ORDER_MARK)) {
185 //
186 // Unicode file's size should be even
187 //
0fe4decf 188Index: Library/EfiShellLib.h\r
189===================================================================\r
190--- Library/EfiShellLib.h (revision 30)\r
191+++ Library/EfiShellLib.h (working copy)\r
192@@ -174,22 +174,23 @@\r
193 //
194 // Environment variable name constants
195 //
196-#define VarLanguageCodes L"LangCodes"
197-#define VarLanguage L"Lang"
198-#define VarTimeout L"Timeout"
199-#define VarConsoleIn L"ConIn"
200-#define VarConsoleOut L"ConOut"
201-#define VarErrorOut L"ErrOut"
202-#define VarBootOption L"Boot%04x"
203-#define VarBootOrder L"BootOrder"
204-#define VarBootNext L"BootNext"
205-#define VarBootCurrent L"BootCurrent"
206-#define VarDriverOption L"Driver%04x"
207-#define VarDriverOrder L"DriverOrder"
208-#define VarConsoleInpDev L"ConInDev"
209-#define VarConsoleOutDev L"ConOutDev"
210-#define VarErrorOutDev L"ErrOutDev"
211-#define LanguageCodeEnglish "eng"
212+#define VarLanguageCodes L"LangCodes"
213+#define VarLanguage L"Lang"
214+#define VarTimeout L"Timeout"
215+#define VarConsoleIn L"ConIn"
216+#define VarConsoleOut L"ConOut"
217+#define VarErrorOut L"ErrOut"
218+#define VarBootOption L"Boot%04x"
219+#define VarBootOrder L"BootOrder"
220+#define VarBootNext L"BootNext"
221+#define VarBootCurrent L"BootCurrent"
222+#define VarDriverOption L"Driver%04x"
223+#define VarDriverOrder L"DriverOrder"
224+#define VarConsoleInpDev L"ConInDev"
225+#define VarConsoleOutDev L"ConOutDev"
226+#define VarErrorOutDev L"ErrOutDev"
227+#define LanguageCodeEnglish "eng"
228+#define PlatformLanguageCodeEnglish "en-US"
229
230 #define ISO_639_2_ENTRY_SIZE 3
231 #define RFC_3066_ENTRY_SIZE 12
232@@ -333,4 +334,10 @@\r
233 IN CHAR8 *LangCode
234 );
235
236+CHAR8 *
237+ExtractSupportedLanguage (
238+ IN CONST CHAR8 *SupportedLanguages,
239+ IN CONST CHAR8 *Language
240+ );
241+
242 #endif
243Index: Library/Misc.c\r
244===================================================================\r
245--- Library/Misc.c (revision 30)\r
246+++ Library/Misc.c (working copy)\r
247@@ -1905,13 +1905,13 @@\r
248 IN VOID *UserData
249 )
250 {
251- CHAR8 *Data;
252+ UINT8 *Data;
253
254 CHAR8 Val[50];
255
256 CHAR8 Str[20];
257
258- CHAR8 c;
259+ UINT8 c;
260 UINTN Size;
261 UINTN Index;
262
263@@ -2271,3 +2271,76 @@\r
264 }
265 return Lang;
266 }
267+
268+CHAR8 *
269+ExtractSupportedLanguage (
270+ IN CONST CHAR8 *SupportedLanguages,
271+ IN CONST CHAR8 *Language
272+ )
273+/*++
274+
275+ Routine Description:
276+
277+ This function matches the major language code (first two characters) in the
278+ SupportedLanguages. The first language code in the SupportedLanguages that
279+ matches first two characters of the input Language is returned. If there is no
280+ such match, then NULL is returned.
281+
282+ Arguments:
283+
284+ SupportedLanguages - A Null-terminated ASCII string that contains one
285+ or more supported language codes.
286+
287+ LangCode - A pointer to a Null-terminated ASCII string
288+ array indicating the RFC 3066 language.
289+
290+ Returns:
291+
292+ The RFC3066 language code that matches the major language.
293+
294+--*/
295+{
296+ CONST CHAR8 *CurrentLanguage;
297+ CHAR8 *SupportedLanguage;
298+ UINTN LanguageLen;
299+
300+ CurrentLanguage = SupportedLanguages;
301+
302+ while (CurrentLanguage != '\0') {
303+ //
304+ // Search till the end of current language.
305+ //
306+ LanguageLen = 0;
307+ while (CurrentLanguage[LanguageLen] != ';' && CurrentLanguage[LanguageLen] != '\0') {
308+ LanguageLen++;
309+ }
310+
311+ //
312+ // should use AsciiStrnCmp(CurrentLanguage, Language, 2) == 0
313+ //
314+ if ((CurrentLanguage[0] == Language[0]) && (CurrentLanguage[1] == Language[1])) {
315+ //
316+ // Match the major language code, then return a new copy of
317+ // NULL-terminated SupportedLanguage.
318+ //
319+ SupportedLanguage = AllocatePool (LanguageLen + 1);
320+ CopyMem (SupportedLanguage, (VOID *) CurrentLanguage, LanguageLen);
321+
322+ SupportedLanguage[LanguageLen] = '\0';
323+
324+ return SupportedLanguage;
325+ }
326+ //
327+ // Make CurrentLangue point to the next candiate language code.
328+ //
329+ CurrentLanguage += LanguageLen;
330+ if (*CurrentLanguage == ';') {
331+ CurrentLanguage++;
332+ }
333+ }
334+
335+ return NULL;
336+}
337+
338+
339+
f8a6b282 340Index: shellenv/batch.c\r
341===================================================================\r
342--- shellenv/batch.c (revision 30)\r
343+++ shellenv/batch.c (working copy)\r
344@@ -2074,17 +2074,17 @@\r
345 --*/
346 {
347 //
348- // UNICODE byte-order-mark is two bytes
349+ // UNICODE byte-order-mark is 16 bits
350 //
351- CHAR8 Buffer8[2];
352+ UINT16 Uint16;
353 UINTN BufSize;
354 EFI_STATUS Status;
355
356 //
357 // Read the first two bytes to check for byte order mark
358 //
359- BufSize = sizeof (Buffer8);
360- Status = File->Read (File, &BufSize, Buffer8);
361+ BufSize = sizeof (Uint16);
362+ Status = File->Read (File, &BufSize, &Uint16);
363 if (EFI_ERROR (Status)) {
364 return Status;
365 }
366@@ -2098,9 +2098,8 @@\r
367 // otherwise assume it is ASCII. UNICODE byte order mark on
368 // IA little endian is first byte 0xff and second byte 0xfe
369 //
370- if ((Buffer8[0] | (Buffer8[1] << 8)) == EFI_UNICODE_BYTE_ORDER_MARK) {
371+ if ((BufSize == 2) && (Uint16 == EFI_UNICODE_BYTE_ORDER_MARK)) {
372 *IsAscii = FALSE;
373-
374 } else {
375 *IsAscii = TRUE;
376 }
0fe4decf 377Index: SmbiosView/PrintInfo.c\r
378===================================================================\r
379--- SmbiosView/PrintInfo.c (revision 30)\r
380+++ SmbiosView/PrintInfo.c (working copy)\r
381@@ -1779,7 +1779,7 @@\r
382 //
383 // MaxSize is determined by follow formula
384 //
385- MaxSize = 1 << Size;
386+ MaxSize = (UINTN) 1 << Size;
387 PrintToken (STRING_TOKEN (STR_SMBIOSVIEW_PRINTINFO_ONE_VAR_MB), HiiHandle, MaxSize);
388
389 if (Option >= SHOW_DETAIL) {
390Index: SmbiosView/Smbios.h\r
391===================================================================\r
392--- SmbiosView/Smbios.h (revision 30)\r
393+++ SmbiosView/Smbios.h (working copy)\r
394@@ -34,11 +34,6 @@\r
395
396 extern EFI_HII_HANDLE HiiHandle;
397
398-#define EFI_SMBIOS_TABLE_GUID \
399- { \
400- 0xeb9d2d31, 0x2d88, 0x11d3, 0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d \
401- }
402
403-extern EFI_GUID gEfiSmbiosTableGuid;
404
405 #endif