]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPlatformPkg/Bds/BootOption.c
SecurityPkg: Add TPM PTP support in TPM2 device lib.
[mirror_edk2.git] / ArmPlatformPkg / Bds / BootOption.c
index 52c9d831b77bab7963ec90abdc8c9eb5830022ab..32a5679762f91f4328ea1ac4f0ede5434c6ecf14 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
 *\r
 **/\r
 \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
-    Status = EFI_UNSUPPORTED;\r
-    OptionalData = BootOption->OptionalData;\r
-    LoaderType = ReadUnaligned32 ((CONST UINT32*)&OptionalData->Header.LoaderType);\r
-\r
-    if (LoaderType == BDS_LOADER_EFI_APPLICATION) {\r
-      if ((BootOption->Attributes & LOAD_OPTION_CATEGORY_BOOT) == 0) {\r
-        // Need to connect every drivers to ensure no dependencies are missing for the application\r
-        BdsConnectAllDrivers ();\r
-      }\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
-      }\r
-\r
-      Status = BdsBootLinuxAtag (BootOption->FilePathList,\r
-                                 Initrd, // Initrd\r
-                                 (CHAR8*)(LinuxArguments + 1)); // CmdLine\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
+  EFI_STATUS Status;\r
+  UINT16     LoadOptionIndexSize;\r
 \r
-      Status = BdsBootLinuxFdt (BootOption->FilePathList,\r
-                                Initrd, // Initrd\r
-                                (CHAR8*)(LinuxArguments + 1),\r
-                                FdtDevicePath);\r
-\r
-      FreePool (DefaultFdtDevicePath);\r
-      FreePool (FdtDevicePath);\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_BOOT) == 0) {\r
-      BdsConnectAllDrivers ();\r
-    }\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
+  // 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
-    gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
-              EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
-              0, NULL);\r
-  }\r
+  // Clear BootCurrent variable\r
+  LoadOptionIndexSize = sizeof (UINT16);\r
+  gRT->SetVariable (L"BootCurrent", &gEfiGlobalVariableGuid,\r
+            EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,\r
+            0, NULL);\r
 \r
   return Status;\r
 }\r
@@ -156,20 +85,15 @@ BootOptionSetFields (
   IN UINT32                     Attributes,\r
   IN CHAR16*                    BootDescription,\r
   IN EFI_DEVICE_PATH_PROTOCOL*  DevicePath,\r
-  IN ARM_BDS_LOADER_TYPE        BootType,\r
   IN UINT8*                     OptionalData,\r
   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
   UINT8*                        EfiLoadOptionPtr;\r
-  UINT8*                        InitrdPathListPtr;\r
-  ARM_BDS_LINUX_ARGUMENTS*      DestLinuxArguments;\r
-  ARM_BDS_LINUX_ARGUMENTS*      SrcLinuxArguments;\r
-  ARM_BDS_LOADER_ARGUMENTS*     BootArguments;\r
 \r
   // If we are overwriting an existent Boot Option then we have to free previously allocated memory\r
   if (BootOption->LoadOption) {\r
@@ -178,18 +102,13 @@ BootOptionSetFields (
 \r
   BootDescriptionSize = StrSize (BootDescription);\r
 \r
-  // Fixup the size in case of entry specific to ArmPlatformPkg/Bds\r
-  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
-    OptionalDataSize += sizeof(ARM_BDS_LOADER_OPTIONAL_DATA_HEADER);\r
-  }\r
-\r
   // Compute the size of the FilePath list\r
   FilePathListLength = GetUnalignedDevicePathSize (DevicePath);\r
 \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
@@ -218,29 +137,10 @@ BootOptionSetFields (
   // Optional Data fields, Do unaligned writes\r
   BootOption->OptionalData = EfiLoadOptionPtr;\r
 \r
-  if ((BootType == BDS_LOADER_KERNEL_LINUX_ATAG) || (BootType == BDS_LOADER_KERNEL_LINUX_FDT)) {\r
-    // Write the header\r
-    WriteUnaligned32 ((UINT32 *)EfiLoadOptionPtr, ARM_BDS_OPTIONAL_DATA_SIGNATURE);\r
-    WriteUnaligned32 ((UINT32 *)(EfiLoadOptionPtr + 4), BootType);\r
-\r
-    BootArguments = (ARM_BDS_LOADER_ARGUMENTS*)OptionalData;\r
-    SrcLinuxArguments = &(BootArguments->LinuxArguments);\r
-    DestLinuxArguments = &((ARM_BDS_LOADER_OPTIONAL_DATA*)EfiLoadOptionPtr)->Arguments.LinuxArguments;\r
-\r
-    WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->CmdLineSize), SrcLinuxArguments->CmdLineSize);\r
-    WriteUnaligned16 ((UINT16 *)&(DestLinuxArguments->InitrdSize), SrcLinuxArguments->InitrdSize);\r
-\r
-    if (SrcLinuxArguments->CmdLineSize > 0) {\r
-      CopyMem ((VOID*)(DestLinuxArguments + 1), (VOID*)(SrcLinuxArguments + 1), SrcLinuxArguments->CmdLineSize);\r
-    }\r
-\r
-    if (SrcLinuxArguments->InitrdSize > 0) {\r
-      InitrdPathListPtr = (UINT8*)((UINTN)(DestLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize);\r
-      CopyMem (InitrdPathListPtr, (VOID*)((UINTN)(SrcLinuxArguments + 1) + SrcLinuxArguments->CmdLineSize), SrcLinuxArguments->InitrdSize);\r
-    }\r
-  } else {\r
+  if (OptionalData != NULL) {\r
     CopyMem (BootOption->OptionalData, OptionalData, OptionalDataSize);\r
   }\r
+\r
   BootOption->OptionalDataSize = OptionalDataSize;\r
 \r
   // If this function is called at the creation of the Boot Device entry (not at the update) the\r
@@ -261,7 +161,6 @@ BootOptionCreate (
   IN  UINT32                    Attributes,\r
   IN  CHAR16*                   BootDescription,\r
   IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,\r
-  IN  ARM_BDS_LOADER_TYPE       BootType,\r
   IN  UINT8*                    OptionalData,\r
   IN  UINTN                     OptionalDataSize,\r
   OUT BDS_LOAD_OPTION**         BdsLoadOption\r
@@ -282,7 +181,7 @@ BootOptionCreate (
   BootOptionEntry->BdsLoadOption = (BDS_LOAD_OPTION*)AllocateZeroPool (sizeof(BDS_LOAD_OPTION));\r
 \r
   BootOption = BootOptionEntry->BdsLoadOption;\r
-  BootOptionSetFields (BootOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r
+  BootOptionSetFields (BootOption, Attributes, BootDescription, DevicePath, OptionalData, OptionalDataSize);\r
 \r
   //\r
   // Set the related environment variables\r
@@ -335,7 +234,6 @@ BootOptionUpdate (
   IN  UINT32                    Attributes,\r
   IN  CHAR16*                   BootDescription,\r
   IN  EFI_DEVICE_PATH_PROTOCOL* DevicePath,\r
-  IN  ARM_BDS_LOADER_TYPE       BootType,\r
   IN UINT8*                     OptionalData,\r
   IN UINTN                      OptionalDataSize\r
   )\r
@@ -344,7 +242,7 @@ BootOptionUpdate (
   CHAR16          BootVariableName[9];\r
 \r
   // Update the BDS Load Option structure\r
-  BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, BootType, OptionalData, OptionalDataSize);\r
+  BootOptionSetFields (BdsLoadOption, Attributes, BootDescription, DevicePath, OptionalData, OptionalDataSize);\r
 \r
   // Update the related environment variables\r
   UnicodeSPrint (BootVariableName, 9 * sizeof(CHAR16), L"Boot%04X", BdsLoadOption->LoadOptionIndex);\r
@@ -369,6 +267,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
@@ -401,7 +300,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