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