]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOption.c
ArmPkg/BdsLib: Remove Linux loader from BdsLib
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOption.c
index 6f84ed9b6331c76884b826891de5d6cd61df9979..342d441f056bbcae16f931897548f6af134890e7 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 *\r
-*  Copyright (c) 2011-2013, 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
 #include <Guid/ArmGlobalVariableHob.h>\r
 #include "BdsInternal.h"\r
 \r
-extern EFI_HANDLE mImageHandle;\r
-\r
 EFI_STATUS\r
 BootOptionStart (\r
   IN BDS_LOAD_OPTION *BootOption\r
   )\r
 {\r
   EFI_STATUS                            Status;\r
-  EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL*   EfiDevicePathFromTextProtocol;\r
   UINT32                                LoaderType;\r
   ARM_BDS_LOADER_OPTIONAL_DATA*         OptionalData;\r
-  ARM_BDS_LINUX_ARGUMENTS*              LinuxArguments;\r
-  EFI_DEVICE_PATH_PROTOCOL*             FdtDevicePath;\r
-  EFI_DEVICE_PATH_PROTOCOL*             DefaultFdtDevicePath;\r
-  UINTN                                 FdtDevicePathSize;\r
-  UINTN                                 CmdLineSize;\r
-  UINTN                                 InitrdSize;\r
-  EFI_DEVICE_PATH*                      Initrd;\r
   UINT16                                LoadOptionIndexSize;\r
 \r
   if (IS_ARM_BDS_BOOTENTRY (BootOption)) {\r
@@ -41,62 +31,30 @@ BootOptionStart (
     LoaderType = ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
 \r
     if (LoaderType == BDS_LOADER_EFI_APPLICATION) {\r
-      // Need to connect every drivers to ensure no dependencies are missing for the application\r
-      BdsConnectAllDrivers();\r
-\r
-      Status = BdsStartEfiApplication (mImageHandle, BootOption->FilePathList, 0, NULL);\r
-    } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) {\r
-      LinuxArguments = &(OptionalData->Arguments.LinuxArguments);\r
-      CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
-      InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
-\r
-      if (InitrdSize > 0) {\r
-        Initrd = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize));\r
-      } else {\r
-        Initrd = NULL;\r
+      if ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_APP) {\r
+        // Need to connect every drivers to ensure no dependencies are missing for the application\r
+        BdsConnectAllDrivers ();\r
       }\r
 \r
-      Status = BdsBootLinuxAtag (BootOption->FilePathList,\r
-                                 Initrd, // Initrd\r
-                                 (CHAR8*)(LinuxArguments + 1)); // CmdLine\r
+      Status = BdsStartEfiApplication (gImageHandle, BootOption->FilePathList, 0, NULL);\r
+    } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_ATAG) {\r
+      ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
     } else if (LoaderType == BDS_LOADER_KERNEL_LINUX_FDT) {\r
-      LinuxArguments = &(OptionalData->Arguments.LinuxArguments);\r
-      CmdLineSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->CmdLineSize);\r
-      InitrdSize = ReadUnaligned16 ((CONST UINT16*)&LinuxArguments->InitrdSize);\r
-\r
-      if (InitrdSize > 0) {\r
-        Initrd = GetAlignedDevicePath ((EFI_DEVICE_PATH*)((UINTN)(LinuxArguments + 1) + CmdLineSize));\r
-      } else {\r
-        Initrd = NULL;\r
-      }\r
-\r
-      // Get the default FDT device path\r
-      Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);\r
-      ASSERT_EFI_ERROR(Status);\r
-      DefaultFdtDevicePath = EfiDevicePathFromTextProtocol->ConvertTextToDevicePath ((CHAR16*)PcdGetPtr(PcdFdtDevicePath));\r
-\r
-      // Get the FDT device path\r
-      FdtDevicePathSize = GetDevicePathSize (DefaultFdtDevicePath);\r
-      Status = GetEnvironmentVariable ((CHAR16 *)L"Fdt", &gArmGlobalVariableGuid,\r
-                 DefaultFdtDevicePath, &FdtDevicePathSize, (VOID **)&FdtDevicePath);\r
-      ASSERT_EFI_ERROR(Status);\r
-\r
-      Status = BdsBootLinuxFdt (BootOption->FilePathList,\r
-                                Initrd, // Initrd\r
-                                (CHAR8*)(LinuxArguments + 1),\r
-                                FdtDevicePath);\r
-\r
-      FreePool (DefaultFdtDevicePath);\r
-      FreePool (FdtDevicePath);\r
+      ASSERT_EFI_ERROR (EFI_UNSUPPORTED);\r
     }\r
   } else {\r
+    // Connect all the drivers if the EFI Application is not a EFI OS Loader\r
+    if ((BootOption->Attributes & LOAD_OPTION_CATEGORY) == LOAD_OPTION_CATEGORY_APP) {\r
+      BdsConnectAllDrivers ();\r
+    }\r
+\r
     // Set BootCurrent variable\r
     LoadOptionIndexSize = sizeof(UINT16);\r
     gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
               EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
               LoadOptionIndexSize, &(BootOption->LoadOptionIndex));\r
 \r
-    Status = BdsStartEfiApplication (mImageHandle, BootOption->FilePathList, BootOption->OptionalDataSize, BootOption->OptionalData);\r
+    Status = BdsStartEfiApplication (gImageHandle, BootOption->FilePathList, BootOption->OptionalDataSize, BootOption->OptionalData);\r
 \r
     // Clear BootCurrent variable\r
     LoadOptionIndexSize = sizeof(UINT16);\r
@@ -154,7 +112,7 @@ BootOptionSetFields (
   IN UINTN                      OptionalDataSize\r
   )\r
 {\r
-  EFI_LOAD_OPTION               EfiLoadOption;\r
+  EFI_LOAD_OPTION               *EfiLoadOption;\r
   UINTN                         EfiLoadOptionSize;\r
   UINTN                         BootDescriptionSize;\r
   UINT16                        FilePathListLength;\r
@@ -181,8 +139,8 @@ BootOptionSetFields (
 \r
   // Allocate the memory for the EFI Load Option\r
   EfiLoadOptionSize = sizeof(UINT32) + sizeof(UINT16) + BootDescriptionSize + FilePathListLength + OptionalDataSize;\r
-  EfiLoadOption = (EFI_LOAD_OPTION)AllocatePool(EfiLoadOptionSize);\r
-  EfiLoadOptionPtr = EfiLoadOption;\r
+  EfiLoadOption = (EFI_LOAD_OPTION *)AllocatePool(EfiLoadOptionSize);\r
+  EfiLoadOptionPtr = (UINT8 *)EfiLoadOption;\r
 \r
   //\r
   // Populate the EFI Load Option and BDS Boot Option structures\r
@@ -216,6 +174,8 @@ BootOptionSetFields (
     WriteUnaligned32 ((UINT32 *)EfiLoadOptionPtr, ARM_BDS_OPTIONAL_DATA_SIGNATURE);\r
     WriteUnaligned32 ((UINT32 *)(EfiLoadOptionPtr + 4), BootType);\r
 \r
+    // OptionalData should have been initialized by the caller of this function\r
+    ASSERT (OptionalData != NULL);\r
     BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)OptionalData;\r
     SrcLinuxArguments = &(BootArguments->LinuxArguments);\r
     DestLinuxArguments = &((ARM_BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments.LinuxArguments;\r
@@ -232,7 +192,9 @@ BootOptionSetFields (
       CopyMem (InitrdPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize), SrcLinuxArguments->InitrdSize);\r
     }\r
   } else {\r
-    CopyMem (BootOption->OptionalData, OptionalData, OptionalDataSize);\r
+    if (OptionalData != NULL) {\r
+      CopyMem (BootOption->OptionalData, OptionalData, OptionalDataSize);\r
+    }\r
   }\r
   BootOption->OptionalDataSize = OptionalDataSize;\r
 \r
@@ -362,6 +324,7 @@ BootOptionDelete (
   UINTN         BootOrderSize;\r
   UINT16*       BootOrder;\r
   UINTN         BootOrderCount;\r
+  CHAR16        BootVariableName[9];\r
   EFI_STATUS    Status;\r
 \r
   // Remove the entry from the BootOrder environment variable\r
@@ -394,7 +357,17 @@ BootOptionDelete (
         );\r
   }\r
 \r
+  // Delete Boot#### environment variable\r
+  UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BootOption->LoadOptionIndex);\r
+  Status = gRT->SetVariable (\r
+      BootVariableName,\r
+      &gEfiGlobalVariableGuid,\r
+      EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+      0,\r
+      NULL\r
+      );\r
+\r
   FreePool (BootOrder);\r
 \r
-  return EFI_SUCCESS;\r
+  return Status;\r
 }\r