]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/Bds.c
ArmPlatformPkg/Bds: Early Console Initialization
[mirror_edk2.git] / ArmPlatformPkg / Bds / Bds.c
index e2f97307f64afa419e860488d5784fff073df2cc..4cea3cd531bbdc46e95625b4abe281d3dbc6168b 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+*  Copyright (c) 2011-2015, 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
@@ -19,6 +19,8 @@
 \r
 #include <Protocol/Bds.h>\r
 \r
+#include <Guid/EventGroup.h>\r
+\r
 #define EFI_SET_TIMER_TO_SECOND   10000000\r
 \r
 STATIC\r
@@ -153,8 +155,8 @@ InitializeConsolePipe (
       *Handle = Buffer[0];\r
       Status = gBS->HandleProtocol (*Handle, Protocol, Interface);\r
       ASSERT_EFI_ERROR(Status);\r
+      FreePool (Buffer);\r
     }\r
-    FreePool (Buffer);\r
   } else {\r
     Status = EFI_SUCCESS;\r
   }\r
@@ -218,12 +220,6 @@ DefineDefaultBootEntries (
   EFI_STATUS                          Status;\r
   EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL* EfiDevicePathFromTextProtocol;\r
   EFI_DEVICE_PATH*                    BootDevicePath;\r
-  UINT8*                              OptionalData;\r
-  UINTN                               OptionalDataSize;\r
-  ARM_BDS_LOADER_ARGUMENTS*           BootArguments;\r
-  ARM_BDS_LOADER_TYPE                 BootType;\r
-  EFI_DEVICE_PATH*                    InitrdPath;\r
-  UINTN                               InitrdSize;\r
   UINTN                               CmdLineSize;\r
   UINTN                               CmdLineAsciiSize;\r
   CHAR16*                             DefaultBootArgument;\r
@@ -256,15 +252,17 @@ DefineDefaultBootEntries (
       ASSERT_EFI_ERROR(Status);\r
       DevicePathTxt = DevicePathToTextProtocol->ConvertDevicePathToText (BootDevicePath, TRUE, TRUE);\r
 \r
-      ASSERT (StrCmp ((CHAR16*)PcdGetPtr(PcdDefaultBootDevicePath), DevicePathTxt) == 0);\r
+      if (StrCmp ((CHAR16*)PcdGetPtr (PcdDefaultBootDevicePath), DevicePathTxt) != 0) {\r
+        DEBUG ((EFI_D_ERROR, "Device Path given: '%s' Device Path expected: '%s'\n",\r
+            (CHAR16*)PcdGetPtr (PcdDefaultBootDevicePath), DevicePathTxt));\r
+        ASSERT_EFI_ERROR (EFI_INVALID_PARAMETER);\r
+      }\r
 \r
       FreePool (DevicePathTxt);\r
     DEBUG_CODE_END();\r
 \r
     // Create the entry is the Default values are correct\r
     if (BootDevicePath != NULL) {\r
-      BootType = (ARM_BDS_LOADER_TYPE)PcdGet32 (PcdDefaultBootType);\r
-\r
       // We do not support NULL pointer\r
       ASSERT (PcdGetPtr (PcdDefaultBootArgument) != NULL);\r
 \r
@@ -302,33 +300,11 @@ DefineDefaultBootEntries (
         AsciiStrToUnicodeStr (AsciiDefaultBootArgument, DefaultBootArgument);\r
       }\r
 \r
-      if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
-        InitrdPath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdDefaultBootInitrdPath));\r
-        InitrdSize = GetDevicePathSize (InitrdPath);\r
-\r
-        OptionalDataSize = sizeof(ARM_BDS_LOADER_ARGUMENTS) + CmdLineAsciiSize + InitrdSize;\r
-        BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)AllocatePool (OptionalDataSize);\r
-        if (BootArguments == NULL) {\r
-          return EFI_OUT_OF_RESOURCES;\r
-        }\r
-        BootArguments->LinuxArguments.CmdLineSize = CmdLineAsciiSize;\r
-        BootArguments->LinuxArguments.InitrdSize = InitrdSize;\r
-\r
-        CopyMem ((VOID*)(BootArguments + 1), AsciiDefaultBootArgument, CmdLineAsciiSize);\r
-        CopyMem ((VOID*)((UINTN)(BootArguments + 1) + CmdLineAsciiSize), InitrdPath, InitrdSize);\r
-\r
-        OptionalData = (UINT8*)BootArguments;\r
-      } else {\r
-        OptionalData = (UINT8*)DefaultBootArgument;\r
-        OptionalDataSize = CmdLineSize;\r
-      }\r
-\r
       BootOptionCreate (LOAD_OPTION_ACTIVE | LOAD_OPTION_CATEGORY_BOOT,\r
-        (CHAR16*)PcdGetPtr(PcdDefaultBootDescription),\r
+        (CHAR16*)PcdGetPtr (PcdDefaultBootDescription),\r
         BootDevicePath,\r
-        BootType,\r
-        OptionalData,\r
-        OptionalDataSize,\r
+        (UINT8 *)DefaultBootArgument, // OptionalData\r
+        CmdLineSize,                  // OptionalDataSize\r
         &BdsLoadOption\r
         );\r
       FreePool (BdsLoadOption);\r
@@ -391,7 +367,7 @@ StartDefaultBootOnTimeout (
       }\r
       // Discard key in the buffer\r
       do {\r
-       Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
+        Status = gST->ConIn->ReadKeyStroke (gST->ConIn, &Key);\r
       } while(!EFI_ERROR(Status));\r
       gBS->CloseEvent (WaitList[0]);\r
       Print(L"\n\r");\r
@@ -406,8 +382,8 @@ StartDefaultBootOnTimeout (
         UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOrder[Index]);\r
         Status = BdsStartBootOption (BootVariableName);\r
         if(!EFI_ERROR(Status)){\r
-               // Boot option returned successfully, hence don't need to start next boot option\r
-               break;\r
+          // Boot option returned successfully, hence don't need to start next boot option\r
+          break;\r
         }\r
         // In case of success, we should not return from this call.\r
       }\r
@@ -417,6 +393,24 @@ StartDefaultBootOnTimeout (
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  An empty function to pass error checking of CreateEventEx ().\r
+\r
+  @param  Event                 Event whose notification function is being invoked.\r
+  @param  Context               Pointer to the notification function's context,\r
+                                which is implementation-dependent.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+EmptyCallbackFunction (\r
+  IN EFI_EVENT                Event,\r
+  IN VOID                     *Context\r
+  )\r
+{\r
+  return;\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
@@ -449,6 +443,22 @@ BdsEntry (
   UINT16             *BootNext;\r
   UINTN               BootNextSize;\r
   CHAR16              BootVariableName[9];\r
+  EFI_EVENT           EndOfDxeEvent;\r
+\r
+  //\r
+  // Signal EndOfDxe PI Event\r
+  //\r
+  Status = gBS->CreateEventEx (\r
+      EVT_NOTIFY_SIGNAL,\r
+      TPL_NOTIFY,\r
+      EmptyCallbackFunction,\r
+      NULL,\r
+      &gEfiEndOfDxeEventGroupGuid,\r
+      &EndOfDxeEvent\r
+      );\r
+  if (!EFI_ERROR (Status)) {\r
+    gBS->SignalEvent (EndOfDxeEvent);\r
+  }\r
 \r
   PERF_END   (NULL, "DXE", NULL, 0);\r
 \r
@@ -469,6 +479,9 @@ BdsEntry (
   Status = gBS->CalculateCrc32 ((VOID*)gST, gST->Hdr.HeaderSize, &gST->Hdr.CRC32);\r
   ASSERT_EFI_ERROR (Status);\r
 \r
+  // Now we need to setup the EFI System Table with information about the console devices.\r
+  InitializeConsole ();\r
+\r
   // If BootNext environment variable is defined then we just load it !\r
   BootNextSize = sizeof(UINT16);\r
   Status = GetGlobalEnvironmentVariable (L"BootNext", NULL, &BootNextSize, (VOID**)&BootNext);\r
@@ -508,9 +521,6 @@ BdsEntry (
   // If Boot Order does not exist then create a default entry\r
   DefineDefaultBootEntries ();\r
 \r
-  // Now we need to setup the EFI System Table with information about the console devices.\r
-  InitializeConsole ();\r
-\r
   //\r
   // Update the CRC32 in the EFI System Table header\r
   //\r