]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/GenericBdsLib/BdsMisc.c
De-Unicode
[mirror_edk2.git] / MdeModulePkg / Library / GenericBdsLib / BdsMisc.c
CommitLineData
897f0eee 1/** @file\r
2 Misc BDS library function\r
3\r
4Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
5All rights reserved. This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "InternalBdsLib.h"\r
16\r
17\r
18#define MAX_STRING_LEN 200\r
19\r
11ef23f9 20BOOLEAN mFeaturerSwitch = TRUE;\r
ec8cd35c 21BOOLEAN mResetRequired = FALSE;\r
897f0eee 22\r
23extern UINT16 gPlatformBootTimeOutDefault;\r
24\r
25\r
26/**\r
27 Return the default value for system Timeout variable.\r
28\r
29 @return Timeout value.\r
30\r
31**/\r
32UINT16\r
33EFIAPI\r
34BdsLibGetTimeout (\r
35 VOID\r
36 )\r
37{\r
38 UINT16 Timeout;\r
39 UINTN Size;\r
40 EFI_STATUS Status;\r
41\r
42 //\r
43 // Return Timeout variable or 0xffff if no valid\r
44 // Timeout variable exists.\r
45 //\r
46 Size = sizeof (UINT16);\r
47 Status = gRT->GetVariable (L"Timeout", &gEfiGlobalVariableGuid, NULL, &Size, &Timeout);\r
0ef93eb7 48 if (EFI_ERROR (Status)) {\r
49 //\r
50 // According to UEFI 2.0 spec, it should treat the Timeout value as 0xffff\r
51 // (default value PcdPlatformBootTimeOutDefault) when L"Timeout" variable is not present.\r
52 // To make the current EFI Automatic-Test activity possible, platform can choose other value\r
53 // for automatic boot when the variable is not present.\r
54 //\r
55 Timeout = PcdGet16 (PcdPlatformBootTimeOutDefault);\r
897f0eee 56 }\r
897f0eee 57\r
897f0eee 58 return Timeout;\r
59}\r
60\r
897f0eee 61/**\r
62 The function will go through the driver optoin link list, load and start\r
63 every driver the driver optoin device path point to.\r
64\r
65 @param BdsDriverLists The header of the current driver option link list\r
66\r
67**/\r
68VOID\r
69EFIAPI\r
70BdsLibLoadDrivers (\r
71 IN LIST_ENTRY *BdsDriverLists\r
72 )\r
73{\r
74 EFI_STATUS Status;\r
75 LIST_ENTRY *Link;\r
76 BDS_COMMON_OPTION *Option;\r
77 EFI_HANDLE ImageHandle;\r
78 EFI_LOADED_IMAGE_PROTOCOL *ImageInfo;\r
79 UINTN ExitDataSize;\r
80 CHAR16 *ExitData;\r
81 BOOLEAN ReconnectAll;\r
82\r
83 ReconnectAll = FALSE;\r
84\r
85 //\r
86 // Process the driver option\r
87 //\r
88 for (Link = BdsDriverLists->ForwardLink; Link != BdsDriverLists; Link = Link->ForwardLink) {\r
89 Option = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);\r
ec8cd35c 90 \r
897f0eee 91 //\r
92 // If a load option is not marked as LOAD_OPTION_ACTIVE,\r
93 // the boot manager will not automatically load the option.\r
94 //\r
95 if (!IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_ACTIVE)) {\r
96 continue;\r
97 }\r
ec8cd35c 98 \r
897f0eee 99 //\r
100 // If a driver load option is marked as LOAD_OPTION_FORCE_RECONNECT,\r
101 // then all of the EFI drivers in the system will be disconnected and\r
102 // reconnected after the last driver load option is processed.\r
103 //\r
104 if (IS_LOAD_OPTION_TYPE (Option->Attribute, LOAD_OPTION_FORCE_RECONNECT)) {\r
105 ReconnectAll = TRUE;\r
106 }\r
ec8cd35c 107 \r
897f0eee 108 //\r
109 // Make sure the driver path is connected.\r
110 //\r
111 BdsLibConnectDevicePath (Option->DevicePath);\r
112\r
113 //\r
114 // Load and start the image that Driver#### describes\r
115 //\r
116 Status = gBS->LoadImage (\r
117 FALSE,\r
118 mBdsImageHandle,\r
119 Option->DevicePath,\r
120 NULL,\r
121 0,\r
122 &ImageHandle\r
123 );\r
124\r
125 if (!EFI_ERROR (Status)) {\r
126 gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &ImageInfo);\r
127\r
128 //\r
129 // Verify whether this image is a driver, if not,\r
130 // exit it and continue to parse next load option\r
131 //\r
132 if (ImageInfo->ImageCodeType != EfiBootServicesCode && ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {\r
133 gBS->Exit (ImageHandle, EFI_INVALID_PARAMETER, 0, NULL);\r
134 continue;\r
135 }\r
136\r
137 if (Option->LoadOptionsSize != 0) {\r
138 ImageInfo->LoadOptionsSize = Option->LoadOptionsSize;\r
139 ImageInfo->LoadOptions = Option->LoadOptions;\r
140 }\r
141 //\r
142 // Before calling the image, enable the Watchdog Timer for\r
143 // the 5 Minute period\r
144 //\r
145 gBS->SetWatchdogTimer (5 * 60, 0x0000, 0x00, NULL);\r
146\r
147 Status = gBS->StartImage (ImageHandle, &ExitDataSize, &ExitData);\r
148 DEBUG ((DEBUG_INFO | DEBUG_LOAD, "Driver Return Status = %r\n", Status));\r
149\r
150 //\r
151 // Clear the Watchdog Timer after the image returns\r
152 //\r
153 gBS->SetWatchdogTimer (0x0000, 0x0000, 0x0000, NULL);\r
154 }\r
155 }\r
ec8cd35c 156 \r
897f0eee 157 //\r
158 // Process the LOAD_OPTION_FORCE_RECONNECT driver option\r
159 //\r
160 if (ReconnectAll) {\r
161 BdsLibDisconnectAllEfi ();\r
162 BdsLibConnectAll ();\r
163 }\r
164\r
165}\r
166\r
897f0eee 167/**\r
11ef23f9 168 Get the Option Number that does not used.\r
169 Try to locate the specific option variable one by one untile find a free number.\r
897f0eee 170\r
171 @param VariableName Indicate if the boot#### or driver#### option\r
172\r
173 @return The Minimal Free Option Number\r
174\r
175**/\r
176UINT16\r
177BdsLibGetFreeOptionNumber (\r
178 IN CHAR16 *VariableName\r
179 )\r
180{\r
897f0eee 181 UINTN Index;\r
182 CHAR16 StrTemp[10];\r
183 UINT16 *OptionBuffer;\r
184 UINTN OptionSize;\r
185\r
186 //\r
187 // Try to find the minimum free number from 0, 1, 2, 3....\r
188 //\r
189 Index = 0;\r
190 do {\r
191 if (*VariableName == 'B') {\r
192 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Boot%04x", Index);\r
193 } else {\r
194 UnicodeSPrint (StrTemp, sizeof (StrTemp), L"Driver%04x", Index);\r
195 }\r
196 //\r
197 // try if the option number is used\r
198 //\r
199 OptionBuffer = BdsLibGetVariableAndSize (\r
ec8cd35c 200 StrTemp,\r
201 &gEfiGlobalVariableGuid,\r
202 &OptionSize\r
203 );\r
897f0eee 204 if (OptionBuffer == NULL) {\r
205 break;\r
206 }\r
ec8cd35c 207 Index ++;\r
208 } while (TRUE);\r
897f0eee 209\r
ec8cd35c 210 return ((UINT16) Index);\r
897f0eee 211}\r
212\r
213\r
214/**\r
215 This function will register the new boot#### or driver#### option base on\r
216 the VariableName. The new registered boot#### or driver#### will be linked\r
217 to BdsOptionList and also update to the VariableName. After the boot#### or\r
218 driver#### updated, the BootOrder or DriverOrder will also be updated.\r
219\r
220 @param BdsOptionList The header of the boot#### or driver#### link list\r
221 @param DevicePath The device path which the boot#### or driver####\r
222 option present\r
223 @param String The description of the boot#### or driver####\r
224 @param VariableName Indicate if the boot#### or driver#### option\r
225\r
226 @retval EFI_SUCCESS The boot#### or driver#### have been success\r
227 registered\r
228 @retval EFI_STATUS Return the status of gRT->SetVariable ().\r
229\r
230**/\r
231EFI_STATUS\r
232EFIAPI\r
233BdsLibRegisterNewOption (\r
234 IN LIST_ENTRY *BdsOptionList,\r
235 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
236 IN CHAR16 *String,\r
237 IN CHAR16 *VariableName\r
238 )\r
239{\r
240 EFI_STATUS Status;\r
241 UINTN Index;\r
242 UINT16 RegisterOptionNumber;\r
243 UINT16 *TempOptionPtr;\r
244 UINTN TempOptionSize;\r
245 UINT16 *OptionOrderPtr;\r
246 VOID *OptionPtr;\r
247 UINTN OptionSize;\r
248 UINT8 *TempPtr;\r
249 EFI_DEVICE_PATH_PROTOCOL *OptionDevicePath;\r
250 CHAR16 *Description;\r
251 CHAR16 OptionName[10];\r
252 BOOLEAN UpdateDescription;\r
253 UINT16 BootOrderEntry;\r
254 UINTN OrderItemNum;\r
255\r
256\r
257 OptionPtr = NULL;\r
258 OptionSize = 0;\r
259 TempPtr = NULL;\r
260 OptionDevicePath = NULL;\r
261 Description = NULL;\r
262 OptionOrderPtr = NULL;\r
263 UpdateDescription = FALSE;\r
ec8cd35c 264 Status = EFI_SUCCESS;\r
897f0eee 265 ZeroMem (OptionName, sizeof (OptionName));\r
266\r
267 TempOptionSize = 0;\r
268 TempOptionPtr = BdsLibGetVariableAndSize (\r
269 VariableName,\r
270 &gEfiGlobalVariableGuid,\r
271 &TempOptionSize\r
272 );\r
273\r
274 //\r
275 // Compare with current option variable\r
276 //\r
277 for (Index = 0; Index < TempOptionSize / sizeof (UINT16); Index++) {\r
278\r
279 if (*VariableName == 'B') {\r
280 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", TempOptionPtr[Index]);\r
281 } else {\r
282 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", TempOptionPtr[Index]);\r
283 }\r
284\r
285 OptionPtr = BdsLibGetVariableAndSize (\r
286 OptionName,\r
287 &gEfiGlobalVariableGuid,\r
288 &OptionSize\r
289 );\r
290 if (OptionPtr == NULL) {\r
291 continue;\r
292 }\r
ec8cd35c 293 TempPtr = OptionPtr;\r
294 TempPtr += sizeof (UINT32) + sizeof (UINT16);\r
295 Description = (CHAR16 *) TempPtr;\r
296 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
297 OptionDevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
897f0eee 298\r
299 //\r
300 // Notes: the description may will change base on the GetStringToken\r
301 //\r
302 if (CompareMem (OptionDevicePath, DevicePath, GetDevicePathSize (OptionDevicePath)) == 0) {\r
303 if (CompareMem (Description, String, StrSize (Description)) == 0) { \r
304 //\r
305 // Got the option, so just return\r
306 //\r
676df92c 307 FreePool (OptionPtr);\r
308 FreePool (TempOptionPtr);\r
897f0eee 309 return EFI_SUCCESS;\r
310 } else {\r
311 //\r
312 // Option description changed, need update.\r
313 //\r
314 UpdateDescription = TRUE;\r
676df92c 315 FreePool (OptionPtr);\r
897f0eee 316 break;\r
317 }\r
318 }\r
319\r
676df92c 320 FreePool (OptionPtr);\r
897f0eee 321 }\r
322\r
323 OptionSize = sizeof (UINT32) + sizeof (UINT16) + StrSize (String);\r
ec8cd35c 324 OptionSize += GetDevicePathSize (DevicePath);\r
897f0eee 325 OptionPtr = AllocateZeroPool (OptionSize);\r
676df92c 326 ASSERT (OptionPtr != NULL);\r
327 \r
897f0eee 328 TempPtr = OptionPtr;\r
329 *(UINT32 *) TempPtr = LOAD_OPTION_ACTIVE;\r
ec8cd35c 330 TempPtr += sizeof (UINT32);\r
897f0eee 331 *(UINT16 *) TempPtr = (UINT16) GetDevicePathSize (DevicePath);\r
ec8cd35c 332 TempPtr += sizeof (UINT16);\r
897f0eee 333 CopyMem (TempPtr, String, StrSize (String));\r
ec8cd35c 334 TempPtr += StrSize (String);\r
897f0eee 335 CopyMem (TempPtr, DevicePath, GetDevicePathSize (DevicePath));\r
336\r
337 if (UpdateDescription) {\r
338 //\r
339 // The number in option#### to be updated\r
340 //\r
341 RegisterOptionNumber = TempOptionPtr[Index];\r
342 } else {\r
343 //\r
344 // The new option#### number\r
345 //\r
346 RegisterOptionNumber = BdsLibGetFreeOptionNumber(VariableName);\r
347 }\r
348\r
349 if (*VariableName == 'B') {\r
350 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", RegisterOptionNumber);\r
351 } else {\r
352 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", RegisterOptionNumber);\r
353 }\r
354\r
355 Status = gRT->SetVariable (\r
356 OptionName,\r
357 &gEfiGlobalVariableGuid,\r
358 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
359 OptionSize,\r
360 OptionPtr\r
361 );\r
362 //\r
363 // Return if only need to update a changed description or fail to set option.\r
364 //\r
365 if (EFI_ERROR (Status) || UpdateDescription) {\r
676df92c 366 FreePool (OptionPtr);\r
367 FreePool (TempOptionPtr);\r
897f0eee 368 return Status;\r
369 }\r
370\r
676df92c 371 FreePool (OptionPtr);\r
897f0eee 372\r
373 //\r
374 // Update the option order variable\r
375 //\r
376\r
377 //\r
378 // If no option order\r
379 //\r
380 if (TempOptionSize == 0) {\r
381 BootOrderEntry = 0;\r
382 Status = gRT->SetVariable (\r
383 VariableName,\r
384 &gEfiGlobalVariableGuid,\r
385 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
386 sizeof (UINT16),\r
387 &BootOrderEntry\r
388 );\r
676df92c 389 FreePool (TempOptionPtr);\r
ec8cd35c 390 return Status;\r
897f0eee 391 }\r
392\r
393 //\r
394 // Append the new option number to the original option order\r
395 //\r
396 OrderItemNum = (TempOptionSize / sizeof (UINT16)) + 1 ;\r
397 OptionOrderPtr = AllocateZeroPool ( OrderItemNum * sizeof (UINT16));\r
676df92c 398 ASSERT (OptionOrderPtr!= NULL);\r
399 \r
897f0eee 400 CopyMem (OptionOrderPtr, TempOptionPtr, (OrderItemNum - 1) * sizeof (UINT16));\r
401\r
402 OptionOrderPtr[Index] = RegisterOptionNumber;\r
403\r
404 Status = gRT->SetVariable (\r
405 VariableName,\r
406 &gEfiGlobalVariableGuid,\r
407 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
408 OrderItemNum * sizeof (UINT16),\r
409 OptionOrderPtr\r
410 );\r
676df92c 411 FreePool (TempOptionPtr);\r
412 FreePool (OptionOrderPtr);\r
897f0eee 413\r
ec8cd35c 414 return Status;\r
897f0eee 415}\r
416\r
417\r
418/**\r
419 Build the boot#### or driver#### option from the VariableName, the\r
11ef23f9 420 build boot#### or driver#### will also be linked to BdsCommonOptionList.\r
897f0eee 421\r
422 @param BdsCommonOptionList The header of the boot#### or driver#### option\r
423 link list\r
424 @param VariableName EFI Variable name indicate if it is boot#### or\r
425 driver####\r
426\r
427 @retval BDS_COMMON_OPTION Get the option just been created\r
428 @retval NULL Failed to get the new option\r
429\r
430**/\r
431BDS_COMMON_OPTION *\r
432EFIAPI\r
433BdsLibVariableToOption (\r
434 IN OUT LIST_ENTRY *BdsCommonOptionList,\r
435 IN CHAR16 *VariableName\r
436 )\r
437{\r
438 UINT32 Attribute;\r
439 UINT16 FilePathSize;\r
440 UINT8 *Variable;\r
441 UINT8 *TempPtr;\r
442 UINTN VariableSize;\r
443 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
444 BDS_COMMON_OPTION *Option;\r
445 VOID *LoadOptions;\r
446 UINT32 LoadOptionsSize;\r
447 CHAR16 *Description;\r
448 UINT8 NumOff;\r
449 //\r
450 // Read the variable. We will never free this data.\r
451 //\r
452 Variable = BdsLibGetVariableAndSize (\r
453 VariableName,\r
454 &gEfiGlobalVariableGuid,\r
455 &VariableSize\r
456 );\r
457 if (Variable == NULL) {\r
458 return NULL;\r
459 }\r
460 //\r
461 // Notes: careful defined the variable of Boot#### or\r
462 // Driver####, consider use some macro to abstract the code\r
463 //\r
464 //\r
465 // Get the option attribute\r
466 //\r
ec8cd35c 467 TempPtr = Variable;\r
468 Attribute = *(UINT32 *) Variable;\r
469 TempPtr += sizeof (UINT32);\r
897f0eee 470\r
471 //\r
472 // Get the option's device path size\r
473 //\r
ec8cd35c 474 FilePathSize = *(UINT16 *) TempPtr;\r
475 TempPtr += sizeof (UINT16);\r
897f0eee 476\r
477 //\r
478 // Get the option's description string\r
479 //\r
480 Description = (CHAR16 *) TempPtr;\r
481\r
482 //\r
483 // Get the option's description string size\r
484 //\r
ec8cd35c 485 TempPtr += StrSize ((CHAR16 *) TempPtr);\r
897f0eee 486\r
487 //\r
488 // Get the option's device path\r
489 //\r
ec8cd35c 490 DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) TempPtr;\r
491 TempPtr += FilePathSize;\r
897f0eee 492\r
493 LoadOptions = TempPtr;\r
494 LoadOptionsSize = (UINT32) (VariableSize - (UINTN) (TempPtr - Variable));\r
495\r
496 //\r
497 // The Console variables may have multiple device paths, so make\r
498 // an Entry for each one.\r
499 //\r
500 Option = AllocateZeroPool (sizeof (BDS_COMMON_OPTION));\r
501 if (Option == NULL) {\r
502 return NULL;\r
503 }\r
504\r
505 Option->Signature = BDS_LOAD_OPTION_SIGNATURE;\r
506 Option->DevicePath = AllocateZeroPool (GetDevicePathSize (DevicePath));\r
507 CopyMem (Option->DevicePath, DevicePath, GetDevicePathSize (DevicePath));\r
508 Option->Attribute = Attribute;\r
509 Option->Description = AllocateZeroPool (StrSize (Description));\r
510 CopyMem (Option->Description, Description, StrSize (Description));\r
511 Option->LoadOptions = AllocateZeroPool (LoadOptionsSize);\r
512 CopyMem (Option->LoadOptions, LoadOptions, LoadOptionsSize);\r
513 Option->LoadOptionsSize = LoadOptionsSize;\r
514\r
515 //\r
516 // Get the value from VariableName Unicode string\r
517 // since the ISO standard assumes ASCII equivalent abbreviations, we can be safe in converting this\r
518 // Unicode stream to ASCII without any loss in meaning.\r
519 //\r
520 if (*VariableName == 'B') {\r
521 NumOff = sizeof (L"Boot")/sizeof(CHAR16) -1 ;\r
522 Option->BootCurrent = (UINT16) ((VariableName[NumOff] -'0') * 0x1000);\r
523 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+1]-'0') * 0x100));\r
524 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+2]-'0') * 0x10));\r
525 Option->BootCurrent = (UINT16) (Option->BootCurrent + ((VariableName[NumOff+3]-'0')));\r
526 }\r
527 //\r
528 // Insert active entry to BdsDeviceList\r
529 //\r
530 if ((Option->Attribute & LOAD_OPTION_ACTIVE) == LOAD_OPTION_ACTIVE) {\r
531 InsertTailList (BdsCommonOptionList, &Option->Link);\r
676df92c 532 FreePool (Variable);\r
897f0eee 533 return Option;\r
534 }\r
535\r
676df92c 536 FreePool (Variable);\r
537 FreePool (Option);\r
897f0eee 538 return NULL;\r
539\r
540}\r
541\r
897f0eee 542/**\r
543 Process BootOrder, or DriverOrder variables, by calling\r
544 BdsLibVariableToOption () for each UINT16 in the variables.\r
545\r
546 @param BdsCommonOptionList The header of the option list base on variable\r
547 VariableName\r
548 @param VariableName EFI Variable name indicate the BootOrder or\r
549 DriverOrder\r
550\r
551 @retval EFI_SUCCESS Success create the boot option or driver option\r
552 list\r
553 @retval EFI_OUT_OF_RESOURCES Failed to get the boot option or driver option list\r
554\r
555**/\r
556EFI_STATUS\r
557EFIAPI\r
558BdsLibBuildOptionFromVar (\r
559 IN LIST_ENTRY *BdsCommonOptionList,\r
560 IN CHAR16 *VariableName\r
561 )\r
562{\r
563 UINT16 *OptionOrder;\r
564 UINTN OptionOrderSize;\r
565 UINTN Index;\r
566 BDS_COMMON_OPTION *Option;\r
567 CHAR16 OptionName[20];\r
568\r
569 //\r
570 // Zero Buffer in order to get all BOOT#### variables\r
571 //\r
572 ZeroMem (OptionName, sizeof (OptionName));\r
573\r
574 //\r
575 // Read the BootOrder, or DriverOrder variable.\r
576 //\r
577 OptionOrder = BdsLibGetVariableAndSize (\r
578 VariableName,\r
579 &gEfiGlobalVariableGuid,\r
580 &OptionOrderSize\r
581 );\r
582 if (OptionOrder == NULL) {\r
583 return EFI_OUT_OF_RESOURCES;\r
584 }\r
585\r
586 for (Index = 0; Index < OptionOrderSize / sizeof (UINT16); Index++) {\r
587 if (*VariableName == 'B') {\r
588 UnicodeSPrint (OptionName, sizeof (OptionName), L"Boot%04x", OptionOrder[Index]);\r
589 } else {\r
590 UnicodeSPrint (OptionName, sizeof (OptionName), L"Driver%04x", OptionOrder[Index]);\r
591 }\r
592\r
593 Option = BdsLibVariableToOption (BdsCommonOptionList, OptionName);\r
594 Option->BootCurrent = OptionOrder[Index];\r
595\r
596 }\r
597\r
676df92c 598 FreePool (OptionOrder);\r
897f0eee 599\r
600 return EFI_SUCCESS;\r
601}\r
602\r
897f0eee 603/**\r
604 Get boot mode by looking up configuration table and parsing HOB list\r
605\r
606 @param BootMode Boot mode from PEI handoff HOB.\r
607\r
608 @retval EFI_SUCCESS Successfully get boot mode\r
609\r
610**/\r
611EFI_STATUS\r
612EFIAPI\r
613BdsLibGetBootMode (\r
614 OUT EFI_BOOT_MODE *BootMode\r
615 )\r
616{\r
617 *BootMode = GetBootModeHob ();\r
618\r
619 return EFI_SUCCESS;\r
620}\r
621\r
897f0eee 622/**\r
623 Read the EFI variable (VendorGuid/Name) and return a dynamically allocated\r
624 buffer, and the size of the buffer. If failure return NULL.\r
625\r
626 @param Name String part of EFI variable name\r
627 @param VendorGuid GUID part of EFI variable name\r
628 @param VariableSize Returns the size of the EFI variable that was read\r
629\r
630 @return Dynamically allocated memory that contains a copy of the EFI variable.\r
631 @return Caller is responsible freeing the buffer.\r
632 @retval NULL Variable was not read\r
633\r
634**/\r
635VOID *\r
636EFIAPI\r
637BdsLibGetVariableAndSize (\r
638 IN CHAR16 *Name,\r
639 IN EFI_GUID *VendorGuid,\r
640 OUT UINTN *VariableSize\r
641 )\r
642{\r
643 EFI_STATUS Status;\r
644 UINTN BufferSize;\r
645 VOID *Buffer;\r
646\r
647 Buffer = NULL;\r
648\r
649 //\r
650 // Pass in a zero size buffer to find the required buffer size.\r
651 //\r
652 BufferSize = 0;\r
653 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
654 if (Status == EFI_BUFFER_TOO_SMALL) {\r
655 //\r
656 // Allocate the buffer to return\r
657 //\r
658 Buffer = AllocateZeroPool (BufferSize);\r
659 if (Buffer == NULL) {\r
660 return NULL;\r
661 }\r
662 //\r
663 // Read variable into the allocated buffer.\r
664 //\r
665 Status = gRT->GetVariable (Name, VendorGuid, NULL, &BufferSize, Buffer);\r
666 if (EFI_ERROR (Status)) {\r
667 BufferSize = 0;\r
668 }\r
669 }\r
670\r
671 *VariableSize = BufferSize;\r
672 return Buffer;\r
673}\r
674\r
897f0eee 675/**\r
676 Delete the instance in Multi which matches partly with Single instance\r
677\r
678 @param Multi A pointer to a multi-instance device path data\r
679 structure.\r
680 @param Single A pointer to a single-instance device path data\r
681 structure.\r
682\r
683 @return This function will remove the device path instances in Multi which partly\r
684 match with the Single, and return the result device path. If there is no\r
685 remaining device path as a result, this function will return NULL.\r
686\r
687**/\r
688EFI_DEVICE_PATH_PROTOCOL *\r
689EFIAPI\r
690BdsLibDelPartMatchInstance (\r
691 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
692 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
693 )\r
694{\r
695 EFI_DEVICE_PATH_PROTOCOL *Instance;\r
696 EFI_DEVICE_PATH_PROTOCOL *NewDevicePath;\r
697 EFI_DEVICE_PATH_PROTOCOL *TempNewDevicePath;\r
698 UINTN InstanceSize;\r
699 UINTN SingleDpSize;\r
700 UINTN Size;\r
701\r
702 NewDevicePath = NULL;\r
703 TempNewDevicePath = NULL;\r
704\r
705 if (Multi == NULL || Single == NULL) {\r
706 return Multi;\r
707 }\r
708\r
709 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
710 SingleDpSize = GetDevicePathSize (Single) - END_DEVICE_PATH_LENGTH;\r
711 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
712\r
713 while (Instance != NULL) {\r
714\r
715 Size = (SingleDpSize < InstanceSize) ? SingleDpSize : InstanceSize;\r
716\r
717 if ((CompareMem (Instance, Single, Size) != 0)) {\r
718 //\r
719 // Append the device path instance which does not match with Single\r
720 //\r
721 TempNewDevicePath = NewDevicePath;\r
722 NewDevicePath = AppendDevicePathInstance (NewDevicePath, Instance);\r
676df92c 723 if (TempNewDevicePath != NULL) {\r
724 FreePool(TempNewDevicePath);\r
725 }\r
897f0eee 726 }\r
676df92c 727 FreePool(Instance);\r
897f0eee 728 Instance = GetNextDevicePathInstance (&Multi, &InstanceSize);\r
729 InstanceSize -= END_DEVICE_PATH_LENGTH;\r
730 }\r
731\r
732 return NewDevicePath;\r
733}\r
734\r
897f0eee 735/**\r
736 Function compares a device path data structure to that of all the nodes of a\r
737 second device path instance.\r
738\r
739 @param Multi A pointer to a multi-instance device path data\r
740 structure.\r
741 @param Single A pointer to a single-instance device path data\r
742 structure.\r
743\r
744 @retval TRUE If the Single is contained within Multi\r
745 @retval FALSE The Single is not match within Multi\r
746\r
747**/\r
748BOOLEAN\r
749EFIAPI\r
750BdsLibMatchDevicePaths (\r
751 IN EFI_DEVICE_PATH_PROTOCOL *Multi,\r
752 IN EFI_DEVICE_PATH_PROTOCOL *Single\r
753 )\r
754{\r
755 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
756 EFI_DEVICE_PATH_PROTOCOL *DevicePathInst;\r
757 UINTN Size;\r
758\r
11ef23f9 759 if (Multi != NULL || Single != NULL) {\r
897f0eee 760 return FALSE;\r
761 }\r
762\r
763 DevicePath = Multi;\r
764 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
765\r
766 //\r
767 // Search for the match of 'Single' in 'Multi'\r
768 //\r
769 while (DevicePathInst != NULL) {\r
770 //\r
771 // If the single device path is found in multiple device paths,\r
772 // return success\r
773 //\r
774 if (CompareMem (Single, DevicePathInst, Size) == 0) {\r
676df92c 775 FreePool (DevicePathInst);\r
897f0eee 776 return TRUE;\r
777 }\r
778\r
676df92c 779 FreePool (DevicePathInst);\r
897f0eee 780 DevicePathInst = GetNextDevicePathInstance (&DevicePath, &Size);\r
781 }\r
782\r
783 return FALSE;\r
784}\r
785\r
897f0eee 786/**\r
787 This function prints a series of strings.\r
788\r
789 @param ConOut Pointer to EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL\r
790 @param ... A variable argument list containing series of\r
791 strings, the last string must be NULL.\r
792\r
793 @retval EFI_SUCCESS Success print out the string using ConOut.\r
794 @retval EFI_STATUS Return the status of the ConOut->OutputString ().\r
795\r
796**/\r
797EFI_STATUS\r
798EFIAPI\r
799BdsLibOutputStrings (\r
800 IN EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut,\r
801 ...\r
802 )\r
803{\r
11ef23f9 804 VA_LIST Args;\r
897f0eee 805 EFI_STATUS Status;\r
806 CHAR16 *String;\r
807\r
808 Status = EFI_SUCCESS;\r
11ef23f9 809 VA_START (Args, ConOut);\r
897f0eee 810\r
811 while (!EFI_ERROR (Status)) {\r
812 //\r
813 // If String is NULL, then it's the end of the list\r
814 //\r
11ef23f9 815 String = VA_ARG (Args, CHAR16 *);\r
816 if (String != NULL) {\r
897f0eee 817 break;\r
818 }\r
819\r
820 Status = ConOut->OutputString (ConOut, String);\r
821\r
822 if (EFI_ERROR (Status)) {\r
823 break;\r
824 }\r
825 }\r
826\r
827 return Status;\r
828}\r
829\r
830//\r
831// Following are BDS Lib functions which contain all the code about setup browser reset reminder feature.\r
832// Setup Browser reset reminder feature is that an reset reminder will be given before user leaves the setup browser if\r
833// user change any option setting which needs a reset to be effective, and the reset will be applied according to the user selection.\r
834//\r
835\r
836\r
837/**\r
838 Enable the setup browser reset reminder feature.\r
839 This routine is used in platform tip. If the platform policy need the feature, use the routine to enable it.\r
840\r
841**/\r
842VOID\r
843EFIAPI\r
844EnableResetReminderFeature (\r
845 VOID\r
846 )\r
847{\r
848 mFeaturerSwitch = TRUE;\r
849}\r
850\r
851\r
852/**\r
853 Disable the setup browser reset reminder feature.\r
854 This routine is used in platform tip. If the platform policy do not want the feature, use the routine to disable it.\r
855\r
856**/\r
857VOID\r
858EFIAPI\r
859DisableResetReminderFeature (\r
860 VOID\r
861 )\r
862{\r
863 mFeaturerSwitch = FALSE;\r
864}\r
865\r
866\r
867/**\r
868 Record the info that a reset is required.\r
869 A module boolean variable is used to record whether a reset is required.\r
870\r
871**/\r
872VOID\r
873EFIAPI\r
874EnableResetRequired (\r
875 VOID\r
876 )\r
877{\r
878 mResetRequired = TRUE;\r
879}\r
880\r
881\r
882/**\r
883 Record the info that no reset is required.\r
884 A module boolean variable is used to record whether a reset is required.\r
885\r
886**/\r
887VOID\r
888EFIAPI\r
889DisableResetRequired (\r
890 VOID\r
891 )\r
892{\r
893 mResetRequired = FALSE;\r
894}\r
895\r
896\r
897/**\r
898 Check whether platform policy enable the reset reminder feature. The default is enabled.\r
899\r
900**/\r
901BOOLEAN\r
902EFIAPI\r
903IsResetReminderFeatureEnable (\r
904 VOID\r
905 )\r
906{\r
907 return mFeaturerSwitch;\r
908}\r
909\r
910\r
911/**\r
912 Check if user changed any option setting which needs a system reset to be effective.\r
913\r
914**/\r
915BOOLEAN\r
916EFIAPI\r
917IsResetRequired (\r
918 VOID\r
919 )\r
920{\r
921 return mResetRequired;\r
922}\r
923\r
924\r
925/**\r
926 Check whether a reset is needed, and finish the reset reminder feature.\r
927 If a reset is needed, Popup a menu to notice user, and finish the feature\r
928 according to the user selection.\r
929\r
930**/\r
931VOID\r
932EFIAPI\r
933SetupResetReminder (\r
934 VOID\r
935 )\r
936{\r
937 EFI_INPUT_KEY Key;\r
938 CHAR16 *StringBuffer1;\r
939 CHAR16 *StringBuffer2;\r
940\r
941\r
942 //\r
943 //check any reset required change is applied? if yes, reset system\r
944 //\r
945 if (IsResetReminderFeatureEnable ()) {\r
946 if (IsResetRequired ()) {\r
947\r
948 StringBuffer1 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
949 ASSERT (StringBuffer1 != NULL);\r
950 StringBuffer2 = AllocateZeroPool (MAX_STRING_LEN * sizeof (CHAR16));\r
951 ASSERT (StringBuffer2 != NULL);\r
952 StrCpy (StringBuffer1, L"Configuration changed. Reset to apply it Now ? ");\r
953 StrCpy (StringBuffer2, L"Enter (YES) / Esc (NO)");\r
954 //\r
955 // Popup a menu to notice user\r
956 //\r
957 do {\r
958 IfrLibCreatePopUp (2, &Key, StringBuffer1, StringBuffer2);\r
959 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
960\r
676df92c 961 FreePool (StringBuffer1);\r
962 FreePool (StringBuffer2);\r
897f0eee 963 //\r
964 // If the user hits the YES Response key, reset\r
965 //\r
966 if ((Key.UnicodeChar == CHAR_CARRIAGE_RETURN)) {\r
967 gRT->ResetSystem (EfiResetCold, EFI_SUCCESS, 0, NULL);\r
968 }\r
969 gST->ConOut->ClearScreen (gST->ConOut);\r
970 }\r
971 }\r
972}\r
973\r
897f0eee 974/**\r
11ef23f9 975 Get the headers (dos, image, optional header) from an image.\r
897f0eee 976\r
977 @param Device SimpleFileSystem device handle\r
978 @param FileName File name for the image\r
979 @param DosHeader Pointer to dos header\r
11ef23f9 980 @param Hdr Pointer to optional header\r
897f0eee 981\r
982 @retval EFI_SUCCESS Successfully get the machine type.\r
983 @retval EFI_NOT_FOUND The file is not found.\r
984 @retval EFI_LOAD_ERROR File is not a valid image file.\r
985\r
986**/\r
987EFI_STATUS\r
988EFIAPI\r
989BdsLibGetImageHeader (\r
990 IN EFI_HANDLE Device,\r
991 IN CHAR16 *FileName,\r
992 OUT EFI_IMAGE_DOS_HEADER *DosHeader,\r
993 OUT EFI_IMAGE_OPTIONAL_HEADER_PTR_UNION Hdr\r
994 )\r
995{\r
996 EFI_STATUS Status;\r
997 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Volume;\r
998 EFI_FILE_HANDLE Root;\r
999 EFI_FILE_HANDLE ThisFile;\r
1000 UINTN BufferSize;\r
1001 UINT64 FileSize;\r
1002 EFI_FILE_INFO *Info;\r
1003\r
1004 Root = NULL;\r
1005 ThisFile = NULL;\r
1006 //\r
1007 // Handle the file system interface to the device\r
1008 //\r
1009 Status = gBS->HandleProtocol (\r
1010 Device,\r
1011 &gEfiSimpleFileSystemProtocolGuid,\r
1012 (VOID *) &Volume\r
1013 );\r
1014 if (EFI_ERROR (Status)) {\r
1015 goto Done;\r
1016 }\r
1017\r
1018 Status = Volume->OpenVolume (\r
1019 Volume,\r
1020 &Root\r
1021 );\r
1022 if (EFI_ERROR (Status)) {\r
676df92c 1023 Root = NULL;\r
897f0eee 1024 goto Done;\r
1025 }\r
1026\r
1027 Status = Root->Open (Root, &ThisFile, FileName, EFI_FILE_MODE_READ, 0);\r
1028 if (EFI_ERROR (Status)) {\r
1029 goto Done;\r
1030 }\r
1031\r
1032 //\r
1033 // Get file size\r
1034 //\r
1035 BufferSize = SIZE_OF_EFI_FILE_INFO + 200;\r
1036 do {\r
1037 Info = NULL;\r
1038 Status = gBS->AllocatePool (EfiBootServicesData, BufferSize, (VOID **) &Info);\r
1039 if (EFI_ERROR (Status)) {\r
1040 goto Done;\r
1041 }\r
1042 Status = ThisFile->GetInfo (\r
1043 ThisFile,\r
1044 &gEfiFileInfoGuid,\r
1045 &BufferSize,\r
1046 Info\r
1047 );\r
1048 if (!EFI_ERROR (Status)) {\r
1049 break;\r
1050 }\r
1051 if (Status != EFI_BUFFER_TOO_SMALL) {\r
676df92c 1052 FreePool (Info);\r
897f0eee 1053 goto Done;\r
1054 }\r
676df92c 1055 FreePool (Info);\r
897f0eee 1056 } while (TRUE);\r
1057\r
1058 FileSize = Info->FileSize;\r
676df92c 1059 FreePool (Info);\r
897f0eee 1060\r
1061 //\r
1062 // Read dos header\r
1063 //\r
1064 BufferSize = sizeof (EFI_IMAGE_DOS_HEADER);\r
1065 Status = ThisFile->Read (ThisFile, &BufferSize, DosHeader);\r
1066 if (EFI_ERROR (Status) ||\r
1067 BufferSize < sizeof (EFI_IMAGE_DOS_HEADER) ||\r
1068 FileSize <= DosHeader->e_lfanew ||\r
1069 DosHeader->e_magic != EFI_IMAGE_DOS_SIGNATURE) {\r
1070 Status = EFI_LOAD_ERROR;\r
1071 goto Done;\r
1072 }\r
1073\r
1074 //\r
1075 // Move to PE signature\r
1076 //\r
1077 Status = ThisFile->SetPosition (ThisFile, DosHeader->e_lfanew);\r
1078 if (EFI_ERROR (Status)) {\r
1079 Status = EFI_LOAD_ERROR;\r
1080 goto Done;\r
1081 }\r
1082\r
1083 //\r
1084 // Read and check PE signature\r
1085 //\r
1086 BufferSize = sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION);\r
1087 Status = ThisFile->Read (ThisFile, &BufferSize, Hdr.Pe32);\r
1088 if (EFI_ERROR (Status) ||\r
1089 BufferSize < sizeof (EFI_IMAGE_OPTIONAL_HEADER_UNION) ||\r
1090 Hdr.Pe32->Signature != EFI_IMAGE_NT_SIGNATURE) {\r
1091 Status = EFI_LOAD_ERROR;\r
1092 goto Done;\r
1093 }\r
1094\r
1095 //\r
1096 // Check PE32 or PE32+ magic\r
1097 //\r
1098 if (Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR32_MAGIC &&\r
1099 Hdr.Pe32->OptionalHeader.Magic != EFI_IMAGE_NT_OPTIONAL_HDR64_MAGIC) {\r
1100 Status = EFI_LOAD_ERROR;\r
1101 goto Done;\r
1102 }\r
1103\r
1104 Done:\r
1105 if (ThisFile != NULL) {\r
1106 ThisFile->Close (ThisFile);\r
1107 }\r
1108 if (Root != NULL) {\r
1109 Root->Close (Root);\r
1110 }\r
1111 return Status;\r
1112}\r
1113\r
11ef23f9 1114/**\r
897f0eee 1115\r
1116 This routine is a notification function for legayc boot or exit boot\r
1117 service event. It will adjust the memory information for different\r
11ef23f9 1118 memory type and save them into the variables for next boot.\r
897f0eee 1119\r
897f0eee 1120\r
11ef23f9 1121 @param Event The event that triggered this notification function.\r
1122 @param Context Pointer to the notification functions context.\r
897f0eee 1123\r
11ef23f9 1124**/\r
1125VOID\r
1126EFIAPI\r
1127BdsSetMemoryTypeInformationVariable (\r
1128 EFI_EVENT Event,\r
1129 VOID *Context\r
1130 )\r
897f0eee 1131{\r
1132 EFI_STATUS Status;\r
1133 EFI_MEMORY_TYPE_INFORMATION *PreviousMemoryTypeInformation;\r
1134 EFI_MEMORY_TYPE_INFORMATION *CurrentMemoryTypeInformation;\r
1135 UINTN VariableSize;\r
1136 BOOLEAN UpdateRequired;\r
1137 UINTN Index;\r
1138 UINTN Index1;\r
1139 UINT32 Previous;\r
1140 UINT32 Current;\r
1141 UINT32 Next;\r
1142 EFI_HOB_GUID_TYPE *GuidHob;\r
1143\r
1144 UpdateRequired = FALSE;\r
1145\r
1146 //\r
1147 // Retrieve the current memory usage statistics. If they are not found, then\r
1148 // no adjustments can be made to the Memory Type Information variable.\r
1149 //\r
1150 Status = EfiGetSystemConfigurationTable (\r
1151 &gEfiMemoryTypeInformationGuid,\r
1152 (VOID **) &CurrentMemoryTypeInformation\r
1153 );\r
1154 if (EFI_ERROR (Status)) {\r
1155 return;\r
1156 }\r
1157\r
1158 //\r
1159 // Get the Memory Type Information settings from Hob if they exist,\r
1160 // PEI is responsible for getting them from variable and build a Hob to save them.\r
1161 // If the previous Memory Type Information is not available, then set defaults\r
1162 //\r
1163 GuidHob = GetFirstGuidHob (&gEfiMemoryTypeInformationGuid);\r
1164 if (GuidHob == NULL) {\r
1165 //\r
1166 // If Platform has not built Memory Type Info into the Hob, just return.\r
1167 //\r
1168 return;\r
1169 }\r
1170 PreviousMemoryTypeInformation = GET_GUID_HOB_DATA (GuidHob);\r
1171 VariableSize = GET_GUID_HOB_DATA_SIZE (GuidHob);\r
1172\r
1173 //\r
1174 // Use a heuristic to adjust the Memory Type Information for the next boot\r
1175 //\r
1176 for (Index = 0; PreviousMemoryTypeInformation[Index].Type != EfiMaxMemoryType; Index++) {\r
1177\r
1178 Current = 0;\r
1179 for (Index1 = 0; CurrentMemoryTypeInformation[Index1].Type != EfiMaxMemoryType; Index1++) {\r
1180 if (PreviousMemoryTypeInformation[Index].Type == CurrentMemoryTypeInformation[Index1].Type) {\r
1181 Current = CurrentMemoryTypeInformation[Index1].NumberOfPages;\r
1182 break;\r
1183 }\r
1184 }\r
1185\r
1186 if (CurrentMemoryTypeInformation[Index1].Type == EfiMaxMemoryType) {\r
1187 continue;\r
1188 }\r
1189\r
1190 Previous = PreviousMemoryTypeInformation[Index].NumberOfPages;\r
1191\r
1192 //\r
1193 // Write next varible to 125% * current and Inconsistent Memory Reserved across bootings may lead to S4 fail\r
1194 //\r
1195 if (Current > Previous) {\r
1196 Next = Current + (Current >> 2);\r
1197 } else {\r
1198 Next = Previous;\r
1199 }\r
1200 if (Next > 0 && Next < 4) {\r
1201 Next = 4;\r
1202 }\r
1203\r
1204 if (Next != Previous) {\r
1205 PreviousMemoryTypeInformation[Index].NumberOfPages = Next;\r
1206 UpdateRequired = TRUE;\r
1207 }\r
1208\r
1209 }\r
1210\r
1211 //\r
1212 // If any changes were made to the Memory Type Information settings, then set the new variable value\r
1213 //\r
1214 if (UpdateRequired) {\r
1215 Status = gRT->SetVariable (\r
1216 EFI_MEMORY_TYPE_INFORMATION_VARIABLE_NAME,\r
1217 &gEfiMemoryTypeInformationGuid,\r
1218 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
1219 VariableSize,\r
1220 PreviousMemoryTypeInformation\r
1221 );\r
1222 }\r
1223\r
1224 return;\r
1225}\r
1226\r
897f0eee 1227/**\r
1228 This routine register a function to adjust the different type memory page number just before booting\r
11ef23f9 1229 and save the updated info into the variable for next boot to use.\r
897f0eee 1230\r
1231**/\r
1232VOID\r
1233EFIAPI\r
1234BdsLibSaveMemoryTypeInformation (\r
1235 VOID\r
1236 )\r
1237{\r
1238 EFI_STATUS Status;\r
1239 EFI_EVENT ReadyToBootEvent;\r
1240\r
1241 Status = EfiCreateEventReadyToBootEx (\r
1242 TPL_CALLBACK,\r
1243 BdsSetMemoryTypeInformationVariable,\r
1244 NULL,\r
1245 &ReadyToBootEvent\r
1246 );\r
1247 if (EFI_ERROR (Status)) {\r
1248 DEBUG ((DEBUG_ERROR,"Bds Set Memory Type Informationa Variable Fails\n"));\r
1249 }\r
1250\r
1251}\r
1252\r
1253\r