BdsEntry.c revision ff8438477f2dcea28149514de25368ac0b2c02ee
15c08e1173703234cc2913757f237ee916087498aklu/** @file
2128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm  This module produce main entry for BDS phase - BdsEntry.
35c08e1173703234cc2913757f237ee916087498aklu  When this module was dispatched by DxeCore, gEfiBdsArchProtocolGuid will be installed
45c08e1173703234cc2913757f237ee916087498aklu  which contains interface of BdsEntry.
55c08e1173703234cc2913757f237ee916087498aklu  After DxeCore finish DXE phase, gEfiBdsArchProtocolGuid->BdsEntry will be invoked
65c08e1173703234cc2913757f237ee916087498aklu  to enter BDS phase.
75c08e1173703234cc2913757f237ee916087498aklu
8d2b9b337374b3641226f833919323f016cb83314ydongCopyright (c) 2004 - 2013, Intel Corporation. All rights reserved.<BR>
9180a5a35cb49699bd249dee19e41cee34c856a58hhtianThis program and the accompanying materials
105c08e1173703234cc2913757f237ee916087498akluare licensed and made available under the terms and conditions of the BSD License
115c08e1173703234cc2913757f237ee916087498akluwhich accompanies this distribution.  The full text of the license may be found at
125c08e1173703234cc2913757f237ee916087498akluhttp://opensource.org/licenses/bsd-license.php
135c08e1173703234cc2913757f237ee916087498aklu
145c08e1173703234cc2913757f237ee916087498akluTHE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
155c08e1173703234cc2913757f237ee916087498akluWITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
165c08e1173703234cc2913757f237ee916087498aklu
175c08e1173703234cc2913757f237ee916087498aklu**/
185c08e1173703234cc2913757f237ee916087498aklu
195c08e1173703234cc2913757f237ee916087498aklu#include "Bds.h"
205c08e1173703234cc2913757f237ee916087498aklu#include "Language.h"
215c08e1173703234cc2913757f237ee916087498aklu#include "FrontPage.h"
225c08e1173703234cc2913757f237ee916087498aklu#include "Hotkey.h"
235c08e1173703234cc2913757f237ee916087498aklu#include "HwErrRecSupport.h"
245c08e1173703234cc2913757f237ee916087498aklu
255c08e1173703234cc2913757f237ee916087498aklu///
265c08e1173703234cc2913757f237ee916087498aklu/// BDS arch protocol instance initial value.
275c08e1173703234cc2913757f237ee916087498aklu///
285c08e1173703234cc2913757f237ee916087498aklu/// Note: Current BDS not directly get the BootMode, DefaultBoot,
295c08e1173703234cc2913757f237ee916087498aklu/// TimeoutDefault, MemoryTestLevel value from the BDS arch protocol.
30128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm/// Please refer to the library useage of BdsLibGetBootMode, BdsLibGetTimeout
315c08e1173703234cc2913757f237ee916087498aklu/// and PlatformBdsDiagnostics in BdsPlatform.c
325c08e1173703234cc2913757f237ee916087498aklu///
33f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinneyEFI_HANDLE  gBdsHandle = NULL;
34f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney
35f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinneyEFI_BDS_ARCH_PROTOCOL  gBds = {
36f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney  BdsEntry
375c08e1173703234cc2913757f237ee916087498aklu};
385c08e1173703234cc2913757f237ee916087498aklu
395c08e1173703234cc2913757f237ee916087498akluUINT16                          *mBootNext = NULL;
405c08e1173703234cc2913757f237ee916087498aklu
41ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu///
42ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu/// The read-only variables defined in UEFI Spec.
43ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu///
44ff8438477f2dcea28149514de25368ac0b2c02eeniruiyuCHAR16  *mReadOnlyVariables[] = {
45ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  L"PlatformLangCodes",
46ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  L"LangCodes",
47ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  L"BootOptionSupport",
48ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  L"HwErrRecSupport",
49ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  L"OsIndicationsSupported"
50ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  };
51ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu
525c08e1173703234cc2913757f237ee916087498aklu/**
535c08e1173703234cc2913757f237ee916087498aklu
545c08e1173703234cc2913757f237ee916087498aklu  Install Boot Device Selection Protocol
555c08e1173703234cc2913757f237ee916087498aklu
565c08e1173703234cc2913757f237ee916087498aklu  @param ImageHandle     The image handle.
575c08e1173703234cc2913757f237ee916087498aklu  @param SystemTable     The system table.
585c08e1173703234cc2913757f237ee916087498aklu
595c08e1173703234cc2913757f237ee916087498aklu  @retval  EFI_SUCEESS  BDS has finished initializing.
605c08e1173703234cc2913757f237ee916087498aklu                        Return the dispatcher and recall BDS.Entry
615c08e1173703234cc2913757f237ee916087498aklu  @retval  Other        Return status from AllocatePool() or gBS->InstallProtocolInterface
625c08e1173703234cc2913757f237ee916087498aklu
635c08e1173703234cc2913757f237ee916087498aklu**/
645c08e1173703234cc2913757f237ee916087498akluEFI_STATUS
655c08e1173703234cc2913757f237ee916087498akluEFIAPI
665c08e1173703234cc2913757f237ee916087498akluBdsInitialize (
675c08e1173703234cc2913757f237ee916087498aklu  IN EFI_HANDLE                            ImageHandle,
685c08e1173703234cc2913757f237ee916087498aklu  IN EFI_SYSTEM_TABLE                      *SystemTable
695c08e1173703234cc2913757f237ee916087498aklu  )
705c08e1173703234cc2913757f237ee916087498aklu{
715c08e1173703234cc2913757f237ee916087498aklu  EFI_STATUS  Status;
725c08e1173703234cc2913757f237ee916087498aklu
735c08e1173703234cc2913757f237ee916087498aklu  //
745c08e1173703234cc2913757f237ee916087498aklu  // Install protocol interface
755c08e1173703234cc2913757f237ee916087498aklu  //
76f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney  Status = gBS->InstallMultipleProtocolInterfaces (
77f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney                  &gBdsHandle,
78f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney                  &gEfiBdsArchProtocolGuid, &gBds,
79f7cdf5cdd38d0b5740046c26c7ca22f3d19ecb41mdkinney                  NULL
805c08e1173703234cc2913757f237ee916087498aklu                  );
815c08e1173703234cc2913757f237ee916087498aklu  ASSERT_EFI_ERROR (Status);
825c08e1173703234cc2913757f237ee916087498aklu
835c08e1173703234cc2913757f237ee916087498aklu  return Status;
845c08e1173703234cc2913757f237ee916087498aklu}
855c08e1173703234cc2913757f237ee916087498aklu
865676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
875676ccca070b261ff70e93bc32b5f7496c1b8c83czhang/**
885676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  An empty function to pass error checking of CreateEventEx ().
895676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
905676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  @param  Event                 Event whose notification function is being invoked.
915676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  @param  Context               Pointer to the notification function's context,
925676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                                which is implementation-dependent.
935676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
945676ccca070b261ff70e93bc32b5f7496c1b8c83czhang**/
955676ccca070b261ff70e93bc32b5f7496c1b8c83czhangVOID
965676ccca070b261ff70e93bc32b5f7496c1b8c83czhangEFIAPI
975676ccca070b261ff70e93bc32b5f7496c1b8c83czhangBdsEmptyCallbackFunction (
985676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  IN EFI_EVENT                Event,
995676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  IN VOID                     *Context
1005676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  )
1015676ccca070b261ff70e93bc32b5f7496c1b8c83czhang{
1025676ccca070b261ff70e93bc32b5f7496c1b8c83czhang}
1035676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
1045c08e1173703234cc2913757f237ee916087498aklu/**
1055c08e1173703234cc2913757f237ee916087498aklu
1065c08e1173703234cc2913757f237ee916087498aklu  This function attempts to boot for the boot order specified
1075c08e1173703234cc2913757f237ee916087498aklu  by platform policy.
1085c08e1173703234cc2913757f237ee916087498aklu
1095c08e1173703234cc2913757f237ee916087498aklu**/
1105c08e1173703234cc2913757f237ee916087498akluVOID
1115c08e1173703234cc2913757f237ee916087498akluBdsBootDeviceSelect (
1125c08e1173703234cc2913757f237ee916087498aklu  VOID
1135c08e1173703234cc2913757f237ee916087498aklu  )
1145c08e1173703234cc2913757f237ee916087498aklu{
1155c08e1173703234cc2913757f237ee916087498aklu  EFI_STATUS        Status;
1165c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        *Link;
1175c08e1173703234cc2913757f237ee916087498aklu  BDS_COMMON_OPTION *BootOption;
1185c08e1173703234cc2913757f237ee916087498aklu  UINTN             ExitDataSize;
1195c08e1173703234cc2913757f237ee916087498aklu  CHAR16            *ExitData;
1205c08e1173703234cc2913757f237ee916087498aklu  UINT16            Timeout;
1215c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        BootLists;
1225c08e1173703234cc2913757f237ee916087498aklu  CHAR16            Buffer[20];
1235c08e1173703234cc2913757f237ee916087498aklu  BOOLEAN           BootNextExist;
1245c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY        *LinkBootNext;
1255676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  EFI_EVENT         ConnectConInEvent;
1265c08e1173703234cc2913757f237ee916087498aklu
1275c08e1173703234cc2913757f237ee916087498aklu  //
1285c08e1173703234cc2913757f237ee916087498aklu  // Got the latest boot option
1295c08e1173703234cc2913757f237ee916087498aklu  //
1305c08e1173703234cc2913757f237ee916087498aklu  BootNextExist = FALSE;
1315c08e1173703234cc2913757f237ee916087498aklu  LinkBootNext  = NULL;
1325676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  ConnectConInEvent = NULL;
1335c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&BootLists);
1345c08e1173703234cc2913757f237ee916087498aklu
1355c08e1173703234cc2913757f237ee916087498aklu  //
1365c08e1173703234cc2913757f237ee916087498aklu  // First check the boot next option
1375c08e1173703234cc2913757f237ee916087498aklu  //
1385c08e1173703234cc2913757f237ee916087498aklu  ZeroMem (Buffer, sizeof (Buffer));
1395c08e1173703234cc2913757f237ee916087498aklu
1405676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  //
1415676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  // Create Event to signal ConIn connection request
1425676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  //
1435676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  if (PcdGetBool (PcdConInConnectOnDemand)) {
1445676ccca070b261ff70e93bc32b5f7496c1b8c83czhang    Status = gBS->CreateEventEx (
1455676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    EVT_NOTIFY_SIGNAL,
1465676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    TPL_CALLBACK,
1475676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    BdsEmptyCallbackFunction,
1485676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    NULL,
1495676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    &gConnectConInEventGuid,
1505676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    &ConnectConInEvent
1515676ccca070b261ff70e93bc32b5f7496c1b8c83czhang                    );
1525676ccca070b261ff70e93bc32b5f7496c1b8c83czhang    if (EFI_ERROR(Status)) {
1535676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      ConnectConInEvent = NULL;
1545676ccca070b261ff70e93bc32b5f7496c1b8c83czhang    }
1555676ccca070b261ff70e93bc32b5f7496c1b8c83czhang  }
1565676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
1575c08e1173703234cc2913757f237ee916087498aklu  if (mBootNext != NULL) {
1585c08e1173703234cc2913757f237ee916087498aklu    //
1595c08e1173703234cc2913757f237ee916087498aklu    // Indicate we have the boot next variable, so this time
1605c08e1173703234cc2913757f237ee916087498aklu    // boot will always have this boot option
1615c08e1173703234cc2913757f237ee916087498aklu    //
1625c08e1173703234cc2913757f237ee916087498aklu    BootNextExist = TRUE;
1635c08e1173703234cc2913757f237ee916087498aklu
1645c08e1173703234cc2913757f237ee916087498aklu    //
1655c08e1173703234cc2913757f237ee916087498aklu    // Clear the this variable so it's only exist in this time boot
1665c08e1173703234cc2913757f237ee916087498aklu    //
1675c08e1173703234cc2913757f237ee916087498aklu    gRT->SetVariable (
1685c08e1173703234cc2913757f237ee916087498aklu          L"BootNext",
1695c08e1173703234cc2913757f237ee916087498aklu          &gEfiGlobalVariableGuid,
1705c08e1173703234cc2913757f237ee916087498aklu          EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
1715c08e1173703234cc2913757f237ee916087498aklu          0,
1725c08e1173703234cc2913757f237ee916087498aklu          mBootNext
1735c08e1173703234cc2913757f237ee916087498aklu          );
1745c08e1173703234cc2913757f237ee916087498aklu
1755c08e1173703234cc2913757f237ee916087498aklu    //
1765c08e1173703234cc2913757f237ee916087498aklu    // Add the boot next boot option
1775c08e1173703234cc2913757f237ee916087498aklu    //
1785c08e1173703234cc2913757f237ee916087498aklu    UnicodeSPrint (Buffer, sizeof (Buffer), L"Boot%04x", *mBootNext);
1795c08e1173703234cc2913757f237ee916087498aklu    BootOption = BdsLibVariableToOption (&BootLists, Buffer);
180128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm
1815c08e1173703234cc2913757f237ee916087498aklu    //
1825c08e1173703234cc2913757f237ee916087498aklu    // If fail to get boot option from variable, just return and do nothing.
1835c08e1173703234cc2913757f237ee916087498aklu    //
1845c08e1173703234cc2913757f237ee916087498aklu    if (BootOption == NULL) {
1855c08e1173703234cc2913757f237ee916087498aklu      return;
1865c08e1173703234cc2913757f237ee916087498aklu    }
187128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm
1885c08e1173703234cc2913757f237ee916087498aklu    BootOption->BootCurrent = *mBootNext;
1895c08e1173703234cc2913757f237ee916087498aklu  }
1905c08e1173703234cc2913757f237ee916087498aklu  //
1915c08e1173703234cc2913757f237ee916087498aklu  // Parse the boot order to get boot option
1925c08e1173703234cc2913757f237ee916087498aklu  //
1935c08e1173703234cc2913757f237ee916087498aklu  BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
194d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu
195d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  //
196d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  // When we didn't have chance to build boot option variables in the first
197d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  // full configuration boot (e.g.: Reset in the first page or in Device Manager),
198d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  // we have no boot options in the following mini configuration boot.
199d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  // Give the last chance to enumerate the boot options.
200d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  //
201d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  if (IsListEmpty (&BootLists)) {
202d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu    BdsLibEnumerateAllBootOption (&BootLists);
203d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu  }
204d860010877dd3229fe111d7d4e8f61b8a6b45b83niruiyu
2055c08e1173703234cc2913757f237ee916087498aklu  Link = BootLists.ForwardLink;
2065c08e1173703234cc2913757f237ee916087498aklu
2075c08e1173703234cc2913757f237ee916087498aklu  //
2085c08e1173703234cc2913757f237ee916087498aklu  // Parameter check, make sure the loop will be valid
2095c08e1173703234cc2913757f237ee916087498aklu  //
2105c08e1173703234cc2913757f237ee916087498aklu  if (Link == NULL) {
2115c08e1173703234cc2913757f237ee916087498aklu    return ;
2125c08e1173703234cc2913757f237ee916087498aklu  }
2135c08e1173703234cc2913757f237ee916087498aklu  //
2145c08e1173703234cc2913757f237ee916087498aklu  // Here we make the boot in a loop, every boot success will
2155c08e1173703234cc2913757f237ee916087498aklu  // return to the front page
2165c08e1173703234cc2913757f237ee916087498aklu  //
2175c08e1173703234cc2913757f237ee916087498aklu  for (;;) {
2185c08e1173703234cc2913757f237ee916087498aklu    //
2195c08e1173703234cc2913757f237ee916087498aklu    // Check the boot option list first
2205c08e1173703234cc2913757f237ee916087498aklu    //
2215c08e1173703234cc2913757f237ee916087498aklu    if (Link == &BootLists) {
2225c08e1173703234cc2913757f237ee916087498aklu      //
2235676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      // When LazyConIn enabled, signal connect ConIn event before enter UI
2245676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      //
2255676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {
2265676ccca070b261ff70e93bc32b5f7496c1b8c83czhang        gBS->SignalEvent (ConnectConInEvent);
2275676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      }
2285676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
2295676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      //
2305c08e1173703234cc2913757f237ee916087498aklu      // There are two ways to enter here:
2315c08e1173703234cc2913757f237ee916087498aklu      // 1. There is no active boot option, give user chance to
2325c08e1173703234cc2913757f237ee916087498aklu      //    add new boot option
2335c08e1173703234cc2913757f237ee916087498aklu      // 2. All the active boot option processed, and there is no
2345c08e1173703234cc2913757f237ee916087498aklu      //    one is success to boot, then we back here to allow user
2355c08e1173703234cc2913757f237ee916087498aklu      //    add new active boot option
2365c08e1173703234cc2913757f237ee916087498aklu      //
2375c08e1173703234cc2913757f237ee916087498aklu      Timeout = 0xffff;
2385c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsEnterFrontPage (Timeout, FALSE);
2395c08e1173703234cc2913757f237ee916087498aklu      InitializeListHead (&BootLists);
2405c08e1173703234cc2913757f237ee916087498aklu      BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
2415c08e1173703234cc2913757f237ee916087498aklu      Link = BootLists.ForwardLink;
2425c08e1173703234cc2913757f237ee916087498aklu      continue;
2435c08e1173703234cc2913757f237ee916087498aklu    }
2445c08e1173703234cc2913757f237ee916087498aklu    //
2455c08e1173703234cc2913757f237ee916087498aklu    // Get the boot option from the link list
2465c08e1173703234cc2913757f237ee916087498aklu    //
2475c08e1173703234cc2913757f237ee916087498aklu    BootOption = CR (Link, BDS_COMMON_OPTION, Link, BDS_LOAD_OPTION_SIGNATURE);
2485c08e1173703234cc2913757f237ee916087498aklu
2495c08e1173703234cc2913757f237ee916087498aklu    //
2505c08e1173703234cc2913757f237ee916087498aklu    // According to EFI Specification, if a load option is not marked
2515c08e1173703234cc2913757f237ee916087498aklu    // as LOAD_OPTION_ACTIVE, the boot manager will not automatically
2525c08e1173703234cc2913757f237ee916087498aklu    // load the option.
2535c08e1173703234cc2913757f237ee916087498aklu    //
2545c08e1173703234cc2913757f237ee916087498aklu    if (!IS_LOAD_OPTION_TYPE (BootOption->Attribute, LOAD_OPTION_ACTIVE)) {
2555c08e1173703234cc2913757f237ee916087498aklu      //
256baf46e70a58d125b30b62fa24a59dd321b283fdcgikidy      // skip the header of the link list, because it has no boot option
2575c08e1173703234cc2913757f237ee916087498aklu      //
2585c08e1173703234cc2913757f237ee916087498aklu      Link = Link->ForwardLink;
2595c08e1173703234cc2913757f237ee916087498aklu      continue;
2605c08e1173703234cc2913757f237ee916087498aklu    }
2615c08e1173703234cc2913757f237ee916087498aklu    //
2625c08e1173703234cc2913757f237ee916087498aklu    // Make sure the boot option device path connected,
2635c08e1173703234cc2913757f237ee916087498aklu    // but ignore the BBS device path
2645c08e1173703234cc2913757f237ee916087498aklu    //
2655c08e1173703234cc2913757f237ee916087498aklu    if (DevicePathType (BootOption->DevicePath) != BBS_DEVICE_PATH) {
2665c08e1173703234cc2913757f237ee916087498aklu      //
2675c08e1173703234cc2913757f237ee916087498aklu      // Notes: the internal shell can not been connected with device path
2685c08e1173703234cc2913757f237ee916087498aklu      // so we do not check the status here
2695c08e1173703234cc2913757f237ee916087498aklu      //
2705c08e1173703234cc2913757f237ee916087498aklu      BdsLibConnectDevicePath (BootOption->DevicePath);
2715c08e1173703234cc2913757f237ee916087498aklu    }
2722df686c67c7819e01a1487dd703faffef2b59dceczhang
2732df686c67c7819e01a1487dd703faffef2b59dceczhang    //
2742df686c67c7819e01a1487dd703faffef2b59dceczhang    // Restore to original mode before launching boot option.
2752df686c67c7819e01a1487dd703faffef2b59dceczhang    //
2762df686c67c7819e01a1487dd703faffef2b59dceczhang    BdsSetConsoleMode (FALSE);
2772df686c67c7819e01a1487dd703faffef2b59dceczhang
2785c08e1173703234cc2913757f237ee916087498aklu    //
2795c08e1173703234cc2913757f237ee916087498aklu    // All the driver options should have been processed since
2805c08e1173703234cc2913757f237ee916087498aklu    // now boot will be performed.
2815c08e1173703234cc2913757f237ee916087498aklu    //
2825c08e1173703234cc2913757f237ee916087498aklu    Status = BdsLibBootViaBootOption (BootOption, BootOption->DevicePath, &ExitDataSize, &ExitData);
28359b9d73e5ff2331330805756aa4a32039670d097niruiyu    if (Status != EFI_SUCCESS) {
2845c08e1173703234cc2913757f237ee916087498aklu      //
2855c08e1173703234cc2913757f237ee916087498aklu      // Call platform action to indicate the boot fail
2865c08e1173703234cc2913757f237ee916087498aklu      //
2875c08e1173703234cc2913757f237ee916087498aklu      BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_FAILED));
2885c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsBootFail (BootOption, Status, ExitData, ExitDataSize);
2895c08e1173703234cc2913757f237ee916087498aklu
2905c08e1173703234cc2913757f237ee916087498aklu      //
2915c08e1173703234cc2913757f237ee916087498aklu      // Check the next boot option
2925c08e1173703234cc2913757f237ee916087498aklu      //
2935c08e1173703234cc2913757f237ee916087498aklu      Link = Link->ForwardLink;
2945c08e1173703234cc2913757f237ee916087498aklu
2955c08e1173703234cc2913757f237ee916087498aklu    } else {
2965c08e1173703234cc2913757f237ee916087498aklu      //
2975c08e1173703234cc2913757f237ee916087498aklu      // Call platform action to indicate the boot success
2985c08e1173703234cc2913757f237ee916087498aklu      //
299128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm      BootOption->StatusString = GetStringById (STRING_TOKEN (STR_BOOT_SUCCEEDED));
3005c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsBootSuccess (BootOption);
3015c08e1173703234cc2913757f237ee916087498aklu
3025c08e1173703234cc2913757f237ee916087498aklu      //
3035c08e1173703234cc2913757f237ee916087498aklu      // Boot success, then stop process the boot order, and
3045c08e1173703234cc2913757f237ee916087498aklu      // present the boot manager menu, front page
3055c08e1173703234cc2913757f237ee916087498aklu      //
3065676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
3075676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      //
3085676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      // When LazyConIn enabled, signal connect ConIn Event before enter UI
3095676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      //
3105676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      if (PcdGetBool (PcdConInConnectOnDemand) && ConnectConInEvent != NULL) {
3115676ccca070b261ff70e93bc32b5f7496c1b8c83czhang        gBS->SignalEvent (ConnectConInEvent);
3125676ccca070b261ff70e93bc32b5f7496c1b8c83czhang      }
3135676ccca070b261ff70e93bc32b5f7496c1b8c83czhang
3145c08e1173703234cc2913757f237ee916087498aklu      Timeout = 0xffff;
3155c08e1173703234cc2913757f237ee916087498aklu      PlatformBdsEnterFrontPage (Timeout, FALSE);
3165c08e1173703234cc2913757f237ee916087498aklu
3175c08e1173703234cc2913757f237ee916087498aklu      //
318baf46e70a58d125b30b62fa24a59dd321b283fdcgikidy      // Rescan the boot option list, avoid potential risk of the boot
3195c08e1173703234cc2913757f237ee916087498aklu      // option change in front page
3205c08e1173703234cc2913757f237ee916087498aklu      //
3215c08e1173703234cc2913757f237ee916087498aklu      if (BootNextExist) {
3225c08e1173703234cc2913757f237ee916087498aklu        LinkBootNext = BootLists.ForwardLink;
3235c08e1173703234cc2913757f237ee916087498aklu      }
3245c08e1173703234cc2913757f237ee916087498aklu
3255c08e1173703234cc2913757f237ee916087498aklu      InitializeListHead (&BootLists);
3265c08e1173703234cc2913757f237ee916087498aklu      if (LinkBootNext != NULL) {
3275c08e1173703234cc2913757f237ee916087498aklu        //
3285c08e1173703234cc2913757f237ee916087498aklu        // Reserve the boot next option
3295c08e1173703234cc2913757f237ee916087498aklu        //
3305c08e1173703234cc2913757f237ee916087498aklu        InsertTailList (&BootLists, LinkBootNext);
3315c08e1173703234cc2913757f237ee916087498aklu      }
3325c08e1173703234cc2913757f237ee916087498aklu
3335c08e1173703234cc2913757f237ee916087498aklu      BdsLibBuildOptionFromVar (&BootLists, L"BootOrder");
3345c08e1173703234cc2913757f237ee916087498aklu      Link = BootLists.ForwardLink;
3355c08e1173703234cc2913757f237ee916087498aklu    }
3365c08e1173703234cc2913757f237ee916087498aklu  }
3375c08e1173703234cc2913757f237ee916087498aklu
3385c08e1173703234cc2913757f237ee916087498aklu}
3395c08e1173703234cc2913757f237ee916087498aklu
3405c08e1173703234cc2913757f237ee916087498aklu/**
3417ea22852094257713c3d7f31f1c02b0433c2729fydong
3427ea22852094257713c3d7f31f1c02b0433c2729fydong  Validate input console variable data.
3437ea22852094257713c3d7f31f1c02b0433c2729fydong
3447ea22852094257713c3d7f31f1c02b0433c2729fydong  If found the device path is not a valid device path, remove the variable.
3457ea22852094257713c3d7f31f1c02b0433c2729fydong
3467ea22852094257713c3d7f31f1c02b0433c2729fydong  @param VariableName             Input console variable name.
3477ea22852094257713c3d7f31f1c02b0433c2729fydong
3487ea22852094257713c3d7f31f1c02b0433c2729fydong**/
3497ea22852094257713c3d7f31f1c02b0433c2729fydongVOID
3507ea22852094257713c3d7f31f1c02b0433c2729fydongBdsFormalizeConsoleVariable (
3517ea22852094257713c3d7f31f1c02b0433c2729fydong  IN  CHAR16          *VariableName
3527ea22852094257713c3d7f31f1c02b0433c2729fydong  )
3537ea22852094257713c3d7f31f1c02b0433c2729fydong{
3547ea22852094257713c3d7f31f1c02b0433c2729fydong  EFI_DEVICE_PATH_PROTOCOL  *DevicePath;
3557ea22852094257713c3d7f31f1c02b0433c2729fydong  UINTN                     VariableSize;
3567ea22852094257713c3d7f31f1c02b0433c2729fydong  EFI_STATUS                Status;
3577ea22852094257713c3d7f31f1c02b0433c2729fydong
3587ea22852094257713c3d7f31f1c02b0433c2729fydong  DevicePath = BdsLibGetVariableAndSize (
3597ea22852094257713c3d7f31f1c02b0433c2729fydong                      VariableName,
3607ea22852094257713c3d7f31f1c02b0433c2729fydong                      &gEfiGlobalVariableGuid,
3617ea22852094257713c3d7f31f1c02b0433c2729fydong                      &VariableSize
3627ea22852094257713c3d7f31f1c02b0433c2729fydong                      );
36398b241d634c652bb615e1fd33cc2e4bb8efc7216niruiyu  if ((DevicePath != NULL) && !IsDevicePathValid (DevicePath, VariableSize)) {
3647ea22852094257713c3d7f31f1c02b0433c2729fydong    Status = gRT->SetVariable (
3657ea22852094257713c3d7f31f1c02b0433c2729fydong                    VariableName,
3667ea22852094257713c3d7f31f1c02b0433c2729fydong                    &gEfiGlobalVariableGuid,
3677ea22852094257713c3d7f31f1c02b0433c2729fydong                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
3687ea22852094257713c3d7f31f1c02b0433c2729fydong                    0,
3697ea22852094257713c3d7f31f1c02b0433c2729fydong                    NULL
3707ea22852094257713c3d7f31f1c02b0433c2729fydong                    );
3717ea22852094257713c3d7f31f1c02b0433c2729fydong    ASSERT_EFI_ERROR (Status);
3727ea22852094257713c3d7f31f1c02b0433c2729fydong  }
3737ea22852094257713c3d7f31f1c02b0433c2729fydong}
3747ea22852094257713c3d7f31f1c02b0433c2729fydong
3757ea22852094257713c3d7f31f1c02b0433c2729fydong/**
3767ea22852094257713c3d7f31f1c02b0433c2729fydong
37718cf3950226cb7e279f19978ea441ce6639f7bb3czhang  Formalize Bds global variables.
3787ea22852094257713c3d7f31f1c02b0433c2729fydong
37918cf3950226cb7e279f19978ea441ce6639f7bb3czhang 1. For ConIn/ConOut/ConErr, if found the device path is not a valid device path, remove the variable.
38018cf3950226cb7e279f19978ea441ce6639f7bb3czhang 2. For OsIndicationsSupported, Create a BS/RT/UINT64 variable to report caps
38118cf3950226cb7e279f19978ea441ce6639f7bb3czhang 3. Delete OsIndications variable if it is not NV/BS/RT UINT64
38218cf3950226cb7e279f19978ea441ce6639f7bb3czhang Item 3 is used to solve case when OS corrupts OsIndications. Here simply delete this NV variable.
38318cf3950226cb7e279f19978ea441ce6639f7bb3czhang
3847ea22852094257713c3d7f31f1c02b0433c2729fydong**/
3857ea22852094257713c3d7f31f1c02b0433c2729fydongVOID
3867ea22852094257713c3d7f31f1c02b0433c2729fydongBdsFormalizeEfiGlobalVariable (
3877ea22852094257713c3d7f31f1c02b0433c2729fydong  VOID
3887ea22852094257713c3d7f31f1c02b0433c2729fydong  )
3897ea22852094257713c3d7f31f1c02b0433c2729fydong{
39018cf3950226cb7e279f19978ea441ce6639f7bb3czhang  EFI_STATUS Status;
39118cf3950226cb7e279f19978ea441ce6639f7bb3czhang  UINT64     OsIndicationSupport;
39218cf3950226cb7e279f19978ea441ce6639f7bb3czhang  UINT64     OsIndication;
39318cf3950226cb7e279f19978ea441ce6639f7bb3czhang  UINTN      DataSize;
39418cf3950226cb7e279f19978ea441ce6639f7bb3czhang  UINT32     Attributes;
39518cf3950226cb7e279f19978ea441ce6639f7bb3czhang
3967ea22852094257713c3d7f31f1c02b0433c2729fydong  //
3977ea22852094257713c3d7f31f1c02b0433c2729fydong  // Validate Console variable.
3987ea22852094257713c3d7f31f1c02b0433c2729fydong  //
3997ea22852094257713c3d7f31f1c02b0433c2729fydong  BdsFormalizeConsoleVariable (L"ConIn");
4007ea22852094257713c3d7f31f1c02b0433c2729fydong  BdsFormalizeConsoleVariable (L"ConOut");
4017ea22852094257713c3d7f31f1c02b0433c2729fydong  BdsFormalizeConsoleVariable (L"ErrOut");
40218cf3950226cb7e279f19978ea441ce6639f7bb3czhang
40318cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //
40418cf3950226cb7e279f19978ea441ce6639f7bb3czhang  // OS indicater support variable
40518cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //
40618cf3950226cb7e279f19978ea441ce6639f7bb3czhang  OsIndicationSupport = EFI_OS_INDICATIONS_BOOT_TO_FW_UI;
40718cf3950226cb7e279f19978ea441ce6639f7bb3czhang  Status = gRT->SetVariable (
40818cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  L"OsIndicationsSupported",
40918cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &gEfiGlobalVariableGuid,
41018cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
41118cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  sizeof(UINT64),
41218cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &OsIndicationSupport
41318cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  );
41418cf3950226cb7e279f19978ea441ce6639f7bb3czhang  ASSERT_EFI_ERROR (Status);
41518cf3950226cb7e279f19978ea441ce6639f7bb3czhang
41618cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //
41718cf3950226cb7e279f19978ea441ce6639f7bb3czhang  // If OsIndications is invalid, remove it.
41818cf3950226cb7e279f19978ea441ce6639f7bb3czhang  // Invalid case
41918cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //   1. Data size != UINT64
42018cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //   2. OsIndication value inconsistence
42118cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //   3. OsIndication attribute inconsistence
42218cf3950226cb7e279f19978ea441ce6639f7bb3czhang  //
42318cf3950226cb7e279f19978ea441ce6639f7bb3czhang  OsIndication = 0;
42418cf3950226cb7e279f19978ea441ce6639f7bb3czhang  Attributes = 0;
42518cf3950226cb7e279f19978ea441ce6639f7bb3czhang  DataSize = sizeof(UINT64);
42618cf3950226cb7e279f19978ea441ce6639f7bb3czhang  Status = gRT->GetVariable (
42718cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  L"OsIndications",
42818cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &gEfiGlobalVariableGuid,
42918cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &Attributes,
43018cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &DataSize,
43118cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  &OsIndication
43218cf3950226cb7e279f19978ea441ce6639f7bb3czhang                  );
43318cf3950226cb7e279f19978ea441ce6639f7bb3czhang
43418cf3950226cb7e279f19978ea441ce6639f7bb3czhang  if (!EFI_ERROR(Status)) {
43518cf3950226cb7e279f19978ea441ce6639f7bb3czhang    if (DataSize != sizeof(UINT64) ||
43618cf3950226cb7e279f19978ea441ce6639f7bb3czhang        (OsIndication & ~OsIndicationSupport) != 0 ||
43718cf3950226cb7e279f19978ea441ce6639f7bb3czhang        Attributes != (EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE)){
43818cf3950226cb7e279f19978ea441ce6639f7bb3czhang
43918cf3950226cb7e279f19978ea441ce6639f7bb3czhang      DEBUG ((EFI_D_ERROR, "Unformalized OsIndications variable exists. Delete it\n"));
44018cf3950226cb7e279f19978ea441ce6639f7bb3czhang      Status = gRT->SetVariable (
44118cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      L"OsIndications",
44218cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      &gEfiGlobalVariableGuid,
44318cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      Attributes,
44418cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      0,
44518cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      &OsIndication
44618cf3950226cb7e279f19978ea441ce6639f7bb3czhang                      );
44718cf3950226cb7e279f19978ea441ce6639f7bb3czhang      ASSERT_EFI_ERROR (Status);
44818cf3950226cb7e279f19978ea441ce6639f7bb3czhang    }
44918cf3950226cb7e279f19978ea441ce6639f7bb3czhang  }
45018cf3950226cb7e279f19978ea441ce6639f7bb3czhang
4517ea22852094257713c3d7f31f1c02b0433c2729fydong}
4527ea22852094257713c3d7f31f1c02b0433c2729fydong
4537ea22852094257713c3d7f31f1c02b0433c2729fydong/**
4545c08e1173703234cc2913757f237ee916087498aklu
4555c08e1173703234cc2913757f237ee916087498aklu  Service routine for BdsInstance->Entry(). Devices are connected, the
4565c08e1173703234cc2913757f237ee916087498aklu  consoles are initialized, and the boot options are tried.
4575c08e1173703234cc2913757f237ee916087498aklu
4585c08e1173703234cc2913757f237ee916087498aklu  @param This             Protocol Instance structure.
4595c08e1173703234cc2913757f237ee916087498aklu
4605c08e1173703234cc2913757f237ee916087498aklu**/
4615c08e1173703234cc2913757f237ee916087498akluVOID
4625c08e1173703234cc2913757f237ee916087498akluEFIAPI
4635c08e1173703234cc2913757f237ee916087498akluBdsEntry (
4645c08e1173703234cc2913757f237ee916087498aklu  IN EFI_BDS_ARCH_PROTOCOL  *This
4655c08e1173703234cc2913757f237ee916087498aklu  )
4665c08e1173703234cc2913757f237ee916087498aklu{
4675c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY                      DriverOptionList;
4685c08e1173703234cc2913757f237ee916087498aklu  LIST_ENTRY                      BootOptionList;
4695c08e1173703234cc2913757f237ee916087498aklu  UINTN                           BootNextSize;
4709a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  CHAR16                          *FirmwareVendor;
471e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  EFI_STATUS                      Status;
472e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  UINT16                          BootTimeOut;
473ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  UINTN                           Index;
474ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  EDKII_VARIABLE_LOCK_PROTOCOL    *VariableLock;
4755c08e1173703234cc2913757f237ee916087498aklu
4765c08e1173703234cc2913757f237ee916087498aklu  //
4775c08e1173703234cc2913757f237ee916087498aklu  // Insert the performance probe
4785c08e1173703234cc2913757f237ee916087498aklu  //
479128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm  PERF_END (NULL, "DXE", NULL, 0);
480128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm  PERF_START (NULL, "BDS", NULL, 0);
4815c08e1173703234cc2913757f237ee916087498aklu
4825c08e1173703234cc2913757f237ee916087498aklu  //
4835c08e1173703234cc2913757f237ee916087498aklu  // Initialize the global system boot option and driver option
4845c08e1173703234cc2913757f237ee916087498aklu  //
4855c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&DriverOptionList);
4865c08e1173703234cc2913757f237ee916087498aklu  InitializeListHead (&BootOptionList);
4875c08e1173703234cc2913757f237ee916087498aklu
4885c08e1173703234cc2913757f237ee916087498aklu  //
4895c08e1173703234cc2913757f237ee916087498aklu  // Initialize hotkey service
4905c08e1173703234cc2913757f237ee916087498aklu  //
4915c08e1173703234cc2913757f237ee916087498aklu  InitializeHotkeyService ();
4925c08e1173703234cc2913757f237ee916087498aklu
4935c08e1173703234cc2913757f237ee916087498aklu  //
4949a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  // Fill in FirmwareVendor and FirmwareRevision from PCDs
4959a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  //
4969a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  FirmwareVendor = (CHAR16 *)PcdGetPtr (PcdFirmwareVendor);
4979a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  gST->FirmwareVendor = AllocateRuntimeCopyPool (StrSize (FirmwareVendor), FirmwareVendor);
4989a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  ASSERT (gST->FirmwareVendor != NULL);
4999a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  gST->FirmwareRevision = PcdGet32 (PcdFirmwareRevision);
5009a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney
5019a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  //
5029a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  // Fixup Tasble CRC after we updated Firmware Vendor and Revision
5039a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  //
504d2b9b337374b3641226f833919323f016cb83314ydong  gST->Hdr.CRC32 = 0;
5059a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  gBS->CalculateCrc32 ((VOID *)gST, sizeof(EFI_SYSTEM_TABLE), &gST->Hdr.CRC32);
5069a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney
5079a6b4de21d53c3acf85e1948bf0d3a5e5576172cmdkinney  //
5087ea22852094257713c3d7f31f1c02b0433c2729fydong  // Validate Variable.
5097ea22852094257713c3d7f31f1c02b0433c2729fydong  //
5107ea22852094257713c3d7f31f1c02b0433c2729fydong  BdsFormalizeEfiGlobalVariable();
5117ea22852094257713c3d7f31f1c02b0433c2729fydong
5127ea22852094257713c3d7f31f1c02b0433c2729fydong  //
513ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  // Mark the read-only variables if the Variable Lock protocol exists
514ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  //
515ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  Status = gBS->LocateProtocol (&gEdkiiVariableLockProtocolGuid, NULL, (VOID **) &VariableLock);
516ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  DEBUG ((EFI_D_INFO, "[BdsDxe] Locate Variable Lock protocol - %r\n", Status));
517ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  if (!EFI_ERROR (Status)) {
518ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu    for (Index = 0; Index < sizeof (mReadOnlyVariables) / sizeof (mReadOnlyVariables[0]); Index++) {
519ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu      Status = VariableLock->RequestToLock (VariableLock, mReadOnlyVariables[Index], &gEfiGlobalVariableGuid);
520ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu      ASSERT_EFI_ERROR (Status);
521ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu    }
522ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  }
523ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu
524ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  //
525cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin  // Report Status Code to indicate connecting drivers will happen
526cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin  //
527cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin  REPORT_STATUS_CODE (
528cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin    EFI_PROGRESS_CODE,
529cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin    (EFI_SOFTWARE_DXE_BS_DRIVER | EFI_SW_DXE_BS_PC_BEGIN_CONNECTING_DRIVERS)
530cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin    );
531cb38c322f037a9a5d2751a4c7e351b0ee7302e96li-elvin
532a2b35995cac983b676296fcb95fde0e9121319f6klu  InitializeHwErrRecSupport();
533128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm
5345c08e1173703234cc2913757f237ee916087498aklu  //
535e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  // Initialize L"Timeout" EFI global variable.
536e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  //
537e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  BootTimeOut = PcdGet16 (PcdPlatformBootTimeOut);
538e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  if (BootTimeOut != 0xFFFF) {
539e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    //
540e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    // If time out value equal 0xFFFF, no need set to 0xFFFF to variable area because UEFI specification
541e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    // define same behavior between no value or 0xFFFF value for L"Timeout".
542e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    //
543e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    Status = gRT->SetVariable (
544e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    L"Timeout",
545e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    &gEfiGlobalVariableGuid,
546e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
547e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    sizeof (UINT16),
548e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    &BootTimeOut
549e1e91b73d12cb87cac0472b86a6df167db0a057flzeng                    );
550e1e91b73d12cb87cac0472b86a6df167db0a057flzeng    ASSERT_EFI_ERROR(Status);
551e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  }
552e1e91b73d12cb87cac0472b86a6df167db0a057flzeng
553e1e91b73d12cb87cac0472b86a6df167db0a057flzeng  //
5545c08e1173703234cc2913757f237ee916087498aklu  // bugbug: platform specific code
5555c08e1173703234cc2913757f237ee916087498aklu  // Initialize the platform specific string and language
5565c08e1173703234cc2913757f237ee916087498aklu  //
5575c08e1173703234cc2913757f237ee916087498aklu  InitializeStringSupport ();
5585c08e1173703234cc2913757f237ee916087498aklu  InitializeLanguage (TRUE);
5595c08e1173703234cc2913757f237ee916087498aklu  InitializeFrontPage (TRUE);
5605c08e1173703234cc2913757f237ee916087498aklu
5615c08e1173703234cc2913757f237ee916087498aklu  //
562ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  // Do the platform init, can be customized by OEM/IBV
563ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  //
564ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  PERF_START (NULL, "PlatformBds", "BDS", 0);
565ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  PlatformBdsInit ();
566ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu
567ff8438477f2dcea28149514de25368ac0b2c02eeniruiyu  //
5685c08e1173703234cc2913757f237ee916087498aklu  // Set up the device list based on EFI 1.1 variables
5695c08e1173703234cc2913757f237ee916087498aklu  // process Driver#### and Load the driver's in the
5705c08e1173703234cc2913757f237ee916087498aklu  // driver option list
5715c08e1173703234cc2913757f237ee916087498aklu  //
5725c08e1173703234cc2913757f237ee916087498aklu  BdsLibBuildOptionFromVar (&DriverOptionList, L"DriverOrder");
5735c08e1173703234cc2913757f237ee916087498aklu  if (!IsListEmpty (&DriverOptionList)) {
5745c08e1173703234cc2913757f237ee916087498aklu    BdsLibLoadDrivers (&DriverOptionList);
5755c08e1173703234cc2913757f237ee916087498aklu  }
5765c08e1173703234cc2913757f237ee916087498aklu  //
5775c08e1173703234cc2913757f237ee916087498aklu  // Check if we have the boot next option
5785c08e1173703234cc2913757f237ee916087498aklu  //
5795c08e1173703234cc2913757f237ee916087498aklu  mBootNext = BdsLibGetVariableAndSize (
5805c08e1173703234cc2913757f237ee916087498aklu                L"BootNext",
5815c08e1173703234cc2913757f237ee916087498aklu                &gEfiGlobalVariableGuid,
5825c08e1173703234cc2913757f237ee916087498aklu                &BootNextSize
5835c08e1173703234cc2913757f237ee916087498aklu                );
5845c08e1173703234cc2913757f237ee916087498aklu
5855c08e1173703234cc2913757f237ee916087498aklu  //
5865c08e1173703234cc2913757f237ee916087498aklu  // Setup some platform policy here
5875c08e1173703234cc2913757f237ee916087498aklu  //
58819bf20e11acd88a02922201f97e6d64edcd16390lgao  PlatformBdsPolicyBehavior (&DriverOptionList, &BootOptionList, BdsProcessCapsules, BdsMemoryTest);
589128efbbcc2e3e8d4ee3c269563a5e2ee461dc3e3darylm  PERF_END (NULL, "PlatformBds", "BDS", 0);
5905c08e1173703234cc2913757f237ee916087498aklu
5915c08e1173703234cc2913757f237ee916087498aklu  //
5925c08e1173703234cc2913757f237ee916087498aklu  // BDS select the boot device to load OS
5935c08e1173703234cc2913757f237ee916087498aklu  //
5945c08e1173703234cc2913757f237ee916087498aklu  BdsBootDeviceSelect ();
5955c08e1173703234cc2913757f237ee916087498aklu
5965c08e1173703234cc2913757f237ee916087498aklu  //
5975c08e1173703234cc2913757f237ee916087498aklu  // Only assert here since this is the right behavior, we should never
5985c08e1173703234cc2913757f237ee916087498aklu  // return back to DxeCore.
5995c08e1173703234cc2913757f237ee916087498aklu  //
6005c08e1173703234cc2913757f237ee916087498aklu  ASSERT (FALSE);
6015c08e1173703234cc2913757f237ee916087498aklu
6025c08e1173703234cc2913757f237ee916087498aklu  return ;
6035c08e1173703234cc2913757f237ee916087498aklu}
604