Convert NT32 to use PCD settings for UEFI Timeout and language variables as a POC...
[mirror_edk2.git] / Nt32Pkg / PlatformBdsDxe / Generic / Language.c
1 /*++
2
3 Copyright (c) 2006 - 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13
14 language.c
15
16 Abstract:
17
18 Language settings
19
20 Revision History
21
22 --*/
23
24 //
25 // Include common header file for this module.
26 //
27 #include "CommonHeader.h"
28
29 #include "BdsString.h"
30 #include "Language.h"
31
32
33 VOID
34 InitializeLanguage (
35 BOOLEAN LangCodesSettingRequired
36 )
37 /*++
38
39 Routine Description:
40 Determine the current language that will be used
41 based on language related EFI Variables
42
43 Arguments:
44 LangCodesSettingRequired - If required to set LangCode variable
45
46 Returns:
47
48 --*/
49 {
50 EFI_STATUS Status;
51 UINTN Size;
52 CHAR8 *Lang;
53 CHAR8 LangCode[ISO_639_2_ENTRY_SIZE];
54 CHAR8 *LangCodes;
55 CHAR8 *PlatformLang;
56 CHAR8 *PlatformLangCodes;
57 UINTN Index;
58 BOOLEAN Invalid;
59
60
61 LangCodes = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLangCodes);
62 if (LangCodesSettingRequired) {
63 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDepricate)) {
64 //
65 // UEFI 2.1 depricated this variable so we support turning it off
66 //
67 Status = gRT->SetVariable (
68 L"LangCodes",
69 &gEfiGlobalVariableGuid,
70 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
71 AsciiStrLen (LangCodes),
72 LangCodes
73 );
74 }
75
76
77 PlatformLangCodes = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes);
78 Status = gRT->SetVariable (
79 L"PlatformLangCodes",
80 &gEfiGlobalVariableGuid,
81 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
82 AsciiStrSize (PlatformLangCodes),
83 PlatformLangCodes
84 );
85 }
86
87 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDepricate)) {
88 //
89 // UEFI 2.1 depricated this variable so we support turning it off
90 //
91
92 //
93 // Find current LangCode from Lang NV Variable
94 //
95 Size = ISO_639_2_ENTRY_SIZE;
96 Status = gRT->GetVariable (
97 L"Lang",
98 &gEfiGlobalVariableGuid,
99 NULL,
100 &Size,
101 &LangCode
102 );
103 if (!EFI_ERROR (Status)) {
104 Status = EFI_NOT_FOUND;
105 for (Index = 0; LangCodes[Index] != 0; Index += ISO_639_2_ENTRY_SIZE) {
106 if (CompareMem (&LangCodes[Index], LangCode, ISO_639_2_ENTRY_SIZE) == 0) {
107 Status = EFI_SUCCESS;
108 break;
109 }
110 }
111 }
112
113 //
114 // If we cannot get language code from Lang variable,
115 // or LangCode cannot be found from language table,
116 // set the mDefaultLangCode to Lang variable.
117 //
118 if (EFI_ERROR (Status)) {
119 Lang = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultLang);
120 Status = gRT->SetVariable (
121 L"Lang",
122 &gEfiGlobalVariableGuid,
123 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
124 ISO_639_2_ENTRY_SIZE,
125 Lang
126 );
127 }
128 }
129
130 Invalid = FALSE;
131 PlatformLang = BdsLibGetVariableAndSize (L"PlatformLang", &gEfiGlobalVariableGuid, &Size);
132 if (PlatformLang != NULL) {
133 //
134 // Check Current PlatformLang value against PlatformLangCode. Need a library that is TBD
135 // Set Invalid based on state of PlatformLang.
136 //
137
138 FreePool (PlatformLang);
139 } else {
140 // No valid variable is set
141 Invalid = TRUE;
142 }
143
144 if (Invalid) {
145 PlatformLang = (CHAR8 *)PcdGetPtr (PcdUefiVariableDefaultPlatformLang);
146 Status = gRT->SetVariable (
147 L"PlatformLang",
148 &gEfiGlobalVariableGuid,
149 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
150 AsciiStrSize (PlatformLang),
151 PlatformLang
152 );
153 }
154 }