]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/Bds.c
ArmPkg: Introduce GetGlobalEnvironmentVariable() function.
[mirror_edk2.git] / ArmPlatformPkg / Bds / Bds.c
index 609a6f6f76d4069d3e50cc85d543824a4ea36566..fadba6e7a5c89f79acbd495c08fbe36bec717f37 100644 (file)
@@ -1,14 +1,14 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011, ARM Limited. All rights reserved.\r
-*  \r
-*  This program and the accompanying materials                          \r
-*  are licensed and made available under the terms and conditions of the BSD License         \r
-*  which accompanies this distribution.  The full text of the license may be found at        \r
-*  http://opensource.org/licenses/bsd-license.php                                            \r
+*  Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
 *\r
-*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     \r
-*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             \r
+*  This program and the accompanying materials\r
+*  are licensed and made available under the terms and conditions of the BSD License\r
+*  which accompanies this distribution.  The full text of the license may be found at\r
+*  http://opensource.org/licenses/bsd-license.php\r
+*\r
+*  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+*  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 *\r
 **/\r
 \r
@@ -39,8 +39,14 @@ GetConsoleDevicePathFromVariable (
   CHAR16*                   NextDevicePathStr;\r
   EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL  *EfiDevicePathFromTextProtocol;\r
 \r
-  Status = GetEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r
+  Status = GetGlobalEnvironmentVariable (ConsoleVarName, NULL, NULL, (VOID**)&DevicePathInstances);\r
   if (EFI_ERROR(Status)) {\r
+    // In case no default console device path has been defined we assume a driver handles the console (eg: SimpleTextInOutSerial)\r
+    if ((DefaultConsolePaths == NULL) || (DefaultConsolePaths[0] == L'\0')) {\r
+      *DevicePaths = NULL;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
     Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
     ASSERT_EFI_ERROR(Status);\r
 \r
@@ -89,7 +95,7 @@ GetConsoleDevicePathFromVariable (
   if (!EFI_ERROR(Status)) {\r
     *DevicePaths = DevicePathInstances;\r
   }\r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r
 \r
 STATIC\r
@@ -108,7 +114,7 @@ InitializeConsolePipe (
   EFI_DEVICE_PATH_PROTOCOL* DevicePath;\r
 \r
   // Connect all the Device Path Consoles\r
-  do {\r
+  while (ConsoleDevicePaths != NULL) {\r
     DevicePath = GetNextDevicePathInstance (&ConsoleDevicePaths, &Size);\r
 \r
     Status = BdsConnectDevicePath (DevicePath, Handle, NULL);\r
@@ -118,7 +124,7 @@ InitializeConsolePipe (
         EFI_DEVICE_PATH_TO_TEXT_PROTOCOL* DevicePathToTextProtocol;\r
         CHAR16* DevicePathTxt;\r
         EFI_STATUS Status;\r
-       \r
+\r
         Status = gBS->LocateProtocol(&gEfiDevicePathToTextProtocolGuid, NULL, (VOID **)&DevicePathToTextProtocol);\r
         if (!EFI_ERROR(Status)) {\r
           DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (DevicePath, TRUE, TRUE);\r
@@ -135,7 +141,7 @@ InitializeConsolePipe (
     if (!EFI_ERROR(Status) && (*Interface == NULL)) {\r
       Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
     }\r
-  } while (ConsoleDevicePaths != NULL);\r
+  }\r
 \r
   // No Device Path has been defined for this console interface. We take the first protocol implementation\r
   if (*Interface == NULL) {\r
@@ -171,11 +177,11 @@ InitializeConsole (
   // By getting the Console Device Paths from the environment variables before initializing the console pipe, we\r
   // create the 3 environment variables (ConIn, ConOut, ConErr) that allows to initialize all the console interface\r
   // of newly installed console drivers\r
-  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths),&ConOutDevicePaths);\r
+  Status = GetConsoleDevicePathFromVariable (L"ConOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConOutDevicePaths);\r
   ASSERT_EFI_ERROR (Status);\r
-  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths),&ConInDevicePaths);\r
+  Status = GetConsoleDevicePathFromVariable (L"ConIn", (CHAR16*)PcdGetPtr(PcdDefaultConInPaths), &ConInDevicePaths);\r
   ASSERT_EFI_ERROR (Status);\r
-  Status = GetConsoleDevicePathFromVariable (L"ConErr", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths),&ConErrDevicePaths);\r
+  Status = GetConsoleDevicePathFromVariable (L"ErrOut", (CHAR16*)PcdGetPtr(PcdDefaultConOutPaths), &ConErrDevicePaths);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   // Initialize the Consoles\r
@@ -190,6 +196,17 @@ InitializeConsole (
     gST->StdErr = gST->ConOut;\r
   }\r
 \r
+  // Free Memory allocated for reading the UEFI Variables\r
+  if (ConOutDevicePaths) {\r
+    FreePool (ConOutDevicePaths);\r
+  }\r
+  if (ConInDevicePaths) {\r
+    FreePool (ConInDevicePaths);\r
+  }\r
+  if (ConErrDevicePaths) {\r
+    FreePool (ConErrDevicePaths);\r
+  }\r
+\r
   return EFI_SUCCESS;\r
 }\r
 \r
@@ -290,13 +307,13 @@ StartDefaultBootOnTimeout (
   UINTN               BootOrderSize;\r
   UINTN               Index;\r
   CHAR16              BootVariableName[9];\r
-  EFI_STATUS           Status;\r
-  EFI_INPUT_KEY   Key;\r
+  EFI_STATUS          Status;\r
+  EFI_INPUT_KEY       Key;\r
 \r
   Size = sizeof(UINT16);\r
   Timeout = (UINT16)PcdGet16 (PcdPlatformBootTimeOut);\r
   TimeoutPtr = &Timeout;\r
-  GetEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);\r
+  GetGlobalEnvironmentVariable (L"Timeout", &Timeout, &Size, (VOID**)&TimeoutPtr);\r
 \r
   if (Timeout != 0xFFFF) {\r
     if (Timeout > 0) {\r
@@ -327,7 +344,7 @@ StartDefaultBootOnTimeout (
     // In case of Timeout we start the default boot selection\r
     if (Timeout == 0) {\r
       // Get the Boot Option Order from the environment variable (a default value should have been created)\r
-      GetEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
+      GetGlobalEnvironmentVariable (L"BootOrder", NULL, &BootOrderSize, (VOID**)&BootOrder);\r
 \r
       for (Index = 0; Index < BootOrderSize / sizeof (UINT16); Index++) {\r
         UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);\r
@@ -338,25 +355,26 @@ StartDefaultBootOnTimeout (
         }\r
         // In case of success, we should not return from this call.\r
       }\r
+      FreePool (BootOrder);\r
     }\r
   }\r
   return EFI_SUCCESS;\r
 }\r
 \r
 /**\r
-  This function uses policy data from the platform to determine what operating \r
-  system or system utility should be loaded and invoked.  This function call \r
-  also optionally make the use of user input to determine the operating system \r
-  or system utility to be loaded and invoked.  When the DXE Core has dispatched \r
-  all the drivers on the dispatch queue, this function is called.  This \r
-  function will attempt to connect the boot devices required to load and invoke \r
-  the selected operating system or system utility.  During this process, \r
-  additional firmware volumes may be discovered that may contain addition DXE \r
-  drivers that can be dispatched by the DXE Core.   If a boot device cannot be \r
-  fully connected, this function calls the DXE Service Dispatch() to allow the \r
-  DXE drivers from any newly discovered firmware volumes to be dispatched.  \r
-  Then the boot device connection can be attempted again.  If the same boot \r
-  device connection operation fails twice in a row, then that boot device has \r
+  This function uses policy data from the platform to determine what operating\r
+  system or system utility should be loaded and invoked.  This function call\r
+  also optionally make the use of user input to determine the operating system\r
+  or system utility to be loaded and invoked.  When the DXE Core has dispatched\r
+  all the drivers on the dispatch queue, this function is called.  This\r
+  function will attempt to connect the boot devices required to load and invoke\r
+  the selected operating system or system utility.  During this process,\r
+  additional firmware volumes may be discovered that may contain addition DXE\r
+  drivers that can be dispatched by the DXE Core.   If a boot device cannot be\r
+  fully connected, this function calls the DXE Service Dispatch() to allow the\r
+  DXE drivers from any newly discovered firmware volumes to be dispatched.\r
+  Then the boot device connection can be attempted again.  If the same boot\r
+  device connection operation fails twice in a row, then that boot device has\r
   failed, and should be skipped.  This function should never return.\r
 \r
   @param  This             The EFI_BDS_ARCH_PROTOCOL instance.\r
@@ -372,6 +390,9 @@ BdsEntry (
 {\r
   UINTN               Size;\r
   EFI_STATUS          Status;\r
+  UINT16             *BootNext;\r
+  UINTN               BootNextSize;\r
+  CHAR16              BootVariableName[9];\r
 \r
   PERF_END   (NULL, "DXE", NULL, 0);\r
 \r
@@ -386,16 +407,38 @@ BdsEntry (
   }\r
 \r
   // If BootNext environment variable is defined then we just load it !\r
-  Status = BdsStartBootOption (L"BootNext");\r
-  if (Status != EFI_NOT_FOUND) {\r
-    // BootNext has not been succeeded launched\r
-    if (EFI_ERROR(Status)) {\r
-      Print(L"Fail to start BootNext.\n");\r
+  BootNextSize = sizeof(UINT16);\r
+  Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);\r
+  if (!EFI_ERROR(Status)) {\r
+    ASSERT(BootNextSize == sizeof(UINT16));\r
+\r
+    // Generate the requested Boot Entry variable name\r
+    UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", *BootNext);\r
+\r
+    // Set BootCurrent variable\r
+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
+              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+              BootNextSize, BootNext);\r
+\r
+    FreePool (BootNext);\r
+\r
+    // Start the requested Boot Entry\r
+    Status = BdsStartBootOption (BootVariableName);\r
+    if (Status != EFI_NOT_FOUND) {\r
+      // BootNext has not been succeeded launched\r
+      if (EFI_ERROR(Status)) {\r
+        Print(L"Fail to start BootNext.\n");\r
+      }\r
+\r
+      // Delete the BootNext environment variable\r
+      gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,\r
+          EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+          0, NULL);\r
     }\r
 \r
-    // Delete the BootNext environment variable\r
-    gRT->SetVariable (L"BootNext", &gEfiGlobalVariableGuid,\r
-        EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+    // Clear BootCurrent variable\r
+    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
+        EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
         0, NULL);\r
   }\r
 \r