]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/BdsLib/Arm/BdsLinuxLoader.c
ArmPkg/BdsLib: Remove Linux loader from BdsLib
[mirror_edk2.git] / ArmPkg / Library / BdsLib / Arm / BdsLinuxLoader.c
diff --git a/ArmPkg/Library/BdsLib/Arm/BdsLinuxLoader.c b/ArmPkg/Library/BdsLib/Arm/BdsLinuxLoader.c
deleted file mode 100644 (file)
index e5fda08..0000000
+++ /dev/null
@@ -1,323 +0,0 @@
-/** @file\r
-*\r
-*  Copyright (c) 2011-2014, 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
-*\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
-#include <Guid/Fdt.h>\r
-#include <libfdt.h>\r
-\r
-#include "BdsInternal.h"\r
-#include "BdsLinuxLoader.h"\r
-\r
-#define ALIGN32_BELOW(addr)   ALIGN_POINTER(addr - 32,32)\r
-\r
-#define IS_ADDRESS_IN_REGION(RegionStart, RegionSize, Address) \\r
-    (((UINTN)(RegionStart) <= (UINTN)(Address)) && ((UINTN)(Address) <= ((UINTN)(RegionStart) + (UINTN)(RegionSize))))\r
-\r
-STATIC\r
-EFI_STATUS\r
-PreparePlatformHardware (\r
-  VOID\r
-  )\r
-{\r
-  //Note: Interrupts will be disabled by the GIC driver when ExitBootServices() will be called.\r
-\r
-  // Clean before Disable else the Stack gets corrupted with old data.\r
-  ArmCleanDataCache ();\r
-  ArmDisableDataCache ();\r
-  // Invalidate all the entries that might have snuck in.\r
-  ArmInvalidateDataCache ();\r
-\r
-  // Invalidate and disable the Instruction cache\r
-  ArmDisableInstructionCache ();\r
-  ArmInvalidateInstructionCache ();\r
-\r
-  // Turn off MMU\r
-  ArmDisableMmu();\r
-\r
-  return EFI_SUCCESS;\r
-}\r
-\r
-STATIC\r
-EFI_STATUS\r
-StartLinux (\r
-  IN  EFI_PHYSICAL_ADDRESS  LinuxImage,\r
-  IN  UINTN                 LinuxImageSize,\r
-  IN  EFI_PHYSICAL_ADDRESS  KernelParamsAddress,\r
-  IN  UINTN                 KernelParamsSize,\r
-  IN  UINT32                MachineType\r
-  )\r
-{\r
-  EFI_STATUS            Status;\r
-  LINUX_KERNEL          LinuxKernel;\r
-\r
-  // Shut down UEFI boot services. ExitBootServices() will notify every driver that created an event on\r
-  // ExitBootServices event. Example the Interrupt DXE driver will disable the interrupts on this event.\r
-  Status = ShutdownUefiBootServices ();\r
-  if(EFI_ERROR(Status)) {\r
-    DEBUG((EFI_D_ERROR,"ERROR: Can not shutdown UEFI boot services. Status=0x%X\n", Status));\r
-    goto Exit;\r
-  }\r
-\r
-  // Move the kernel parameters to any address inside the first 1MB.\r
-  // This is necessary because the ARM Linux kernel requires\r
-  // the FTD / ATAG List to reside entirely inside the first 1MB of\r
-  // physical memory.\r
-  //Note: There is no requirement on the alignment\r
-  if (MachineType != ARM_FDT_MACHINE_TYPE) {\r
-    if (((UINTN)KernelParamsAddress > LINUX_ATAG_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxAtagMaxOffset))) {\r
-      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_ATAG_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);\r
-    }\r
-  } else {\r
-    if (((UINTN)KernelParamsAddress > LINUX_FDT_MAX_OFFSET) && (KernelParamsSize < PcdGet32(PcdArmLinuxFdtMaxOffset))) {\r
-      KernelParamsAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)CopyMem (ALIGN32_BELOW(LINUX_FDT_MAX_OFFSET - KernelParamsSize), (VOID*)(UINTN)KernelParamsAddress, KernelParamsSize);\r
-    }\r
-  }\r
-\r
-  if ((UINTN)LinuxImage > LINUX_KERNEL_MAX_OFFSET) {\r
-    //Note: There is no requirement on the alignment\r
-    LinuxKernel = (LINUX_KERNEL)CopyMem (ALIGN32_BELOW(LINUX_KERNEL_MAX_OFFSET - LinuxImageSize), (VOID*)(UINTN)LinuxImage, LinuxImageSize);\r
-  } else {\r
-    LinuxKernel = (LINUX_KERNEL)(UINTN)LinuxImage;\r
-  }\r
-\r
-  // Check if the Linux Image is a uImage\r
-  if (*(UINT32*)LinuxKernel == LINUX_UIMAGE_SIGNATURE) {\r
-    // Assume the Image Entry Point is just after the uImage header (64-byte size)\r
-    LinuxKernel = (LINUX_KERNEL)((UINTN)LinuxKernel + 64);\r
-    LinuxImageSize -= 64;\r
-  }\r
-\r
-  // Check there is no overlapping between kernel and its parameters\r
-  // We can only assert because it is too late to fallback to UEFI (ExitBootServices has been called).\r
-  ASSERT (!IS_ADDRESS_IN_REGION(LinuxKernel, LinuxImageSize, KernelParamsAddress) &&\r
-          !IS_ADDRESS_IN_REGION(LinuxKernel, LinuxImageSize, KernelParamsAddress + KernelParamsSize));\r
-\r
-  //\r
-  // Switch off interrupts, caches, mmu, etc\r
-  //\r
-  Status = PreparePlatformHardware ();\r
-  ASSERT_EFI_ERROR(Status);\r
-\r
-  // Register and print out performance information\r
-  PERF_END (NULL, "BDS", NULL, 0);\r
-  if (PerformanceMeasurementEnabled ()) {\r
-    PrintPerformance ();\r
-  }\r
-\r
-  //\r
-  // Start the Linux Kernel\r
-  //\r
-\r
-  // Outside BootServices, so can't use Print();\r
-  DEBUG((EFI_D_ERROR, "\nStarting the kernel:\n\n"));\r
-\r
-  // Jump to kernel with register set\r
-  LinuxKernel ((UINTN)0, MachineType, (UINTN)KernelParamsAddress);\r
-\r
-  // Kernel should never exit\r
-  // After Life services are not provided\r
-  ASSERT(FALSE);\r
-\r
-Exit:\r
-  // Only be here if we fail to start Linux\r
-  Print (L"ERROR  : Can not start the kernel. Status=0x%X\n", Status);\r
-\r
-  // Free Runtimee Memory (kernel and FDT)\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Start a Linux kernel from a Device Path\r
-\r
-  @param  LinuxKernel           Device Path to the Linux Kernel\r
-  @param  Parameters            Linux kernel arguments\r
-  @param  Fdt                   Device Path to the Flat Device Tree\r
-\r
-  @retval EFI_SUCCESS           All drivers have been connected\r
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
-\r
-**/\r
-EFI_STATUS\r
-BdsBootLinuxAtag (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,\r
-  IN  CONST CHAR8*              CommandLineArguments\r
-  )\r
-{\r
-  EFI_STATUS            Status;\r
-  UINT32                LinuxImageSize;\r
-  UINT32                InitrdImageBaseSize = 0;\r
-  UINT32                InitrdImageSize = 0;\r
-  UINT32                AtagSize;\r
-  EFI_PHYSICAL_ADDRESS  AtagBase;\r
-  EFI_PHYSICAL_ADDRESS  LinuxImage;\r
-  EFI_PHYSICAL_ADDRESS  InitrdImageBase = 0;\r
-  EFI_PHYSICAL_ADDRESS  InitrdImage = 0;\r
-\r
-  PERF_START (NULL, "BDS", NULL, 0);\r
-\r
-  // Load the Linux kernel from a device path\r
-  LinuxImage = LINUX_KERNEL_MAX_OFFSET;\r
-  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);\r
-  if (EFI_ERROR(Status)) {\r
-    Print (L"ERROR: Did not find Linux kernel.\n");\r
-    return Status;\r
-  }\r
-\r
-  if (InitrdDevicePath) {\r
-    // Load the initrd near to the Linux kernel\r
-    InitrdImageBase = LINUX_KERNEL_MAX_OFFSET;\r
-    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImageBase, &InitrdImageBaseSize);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
-      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImageBase, &InitrdImageBaseSize);\r
-    }\r
-    if (EFI_ERROR(Status)) {\r
-      Print (L"ERROR: Did not find initrd image.\n");\r
-      goto EXIT_FREE_LINUX;\r
-    }\r
-\r
-    // Check if the initrd is a uInitrd\r
-    if (*(UINT32*)((UINTN)InitrdImageBase) == LINUX_UIMAGE_SIGNATURE) {\r
-      // Skip the 64-byte image header\r
-      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImageBase + 64);\r
-      InitrdImageSize = InitrdImageBaseSize - 64;\r
-    } else {\r
-      InitrdImage = InitrdImageBase;\r
-      InitrdImageSize = InitrdImageBaseSize;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Setup the Linux Kernel Parameters\r
-  //\r
-\r
-  // By setting address=0 we leave the memory allocation to the function\r
-  Status = PrepareAtagList (CommandLineArguments, InitrdImage, InitrdImageSize, &AtagBase, &AtagSize);\r
-  if (EFI_ERROR(Status)) {\r
-    Print(L"ERROR: Can not prepare ATAG list. Status=0x%X\n", Status);\r
-    goto EXIT_FREE_INITRD;\r
-  }\r
-\r
-  return StartLinux (LinuxImage, LinuxImageSize, AtagBase, AtagSize, PcdGet32(PcdArmMachineType));\r
-\r
-EXIT_FREE_INITRD:\r
-  if (InitrdDevicePath) {\r
-    gBS->FreePages (InitrdImageBase, EFI_SIZE_TO_PAGES (InitrdImageBaseSize));\r
-  }\r
-\r
-EXIT_FREE_LINUX:\r
-  gBS->FreePages (LinuxImage, EFI_SIZE_TO_PAGES (LinuxImageSize));\r
-\r
-  return Status;\r
-}\r
-\r
-/**\r
-  Start a Linux kernel from a Device Path\r
-\r
-  @param  LinuxKernelDevicePath  Device Path to the Linux Kernel\r
-  @param  InitrdDevicePath       Device Path to the Initrd\r
-  @param  CommandLineArguments   Linux command line\r
-\r
-  @retval EFI_SUCCESS           All drivers have been connected\r
-  @retval EFI_NOT_FOUND         The Linux kernel Device Path has not been found\r
-  @retval EFI_OUT_OF_RESOURCES  There is not enough resource memory to store the matching results.\r
-\r
-**/\r
-EFI_STATUS\r
-BdsBootLinuxFdt (\r
-  IN  EFI_DEVICE_PATH_PROTOCOL* LinuxKernelDevicePath,\r
-  IN  EFI_DEVICE_PATH_PROTOCOL* InitrdDevicePath,\r
-  IN  CONST CHAR8*              CommandLineArguments\r
-  )\r
-{\r
-  EFI_STATUS               Status;\r
-  UINT32                   LinuxImageSize;\r
-  UINT32                   InitrdImageBaseSize = 0;\r
-  UINT32                   InitrdImageSize = 0;\r
-  VOID                     *InstalledFdtBase;\r
-  UINT32                   FdtBlobSize;\r
-  EFI_PHYSICAL_ADDRESS     FdtBlobBase;\r
-  EFI_PHYSICAL_ADDRESS     LinuxImage;\r
-  EFI_PHYSICAL_ADDRESS     InitrdImageBase = 0;\r
-  EFI_PHYSICAL_ADDRESS     InitrdImage = 0;\r
-\r
-  PERF_START (NULL, "BDS", NULL, 0);\r
-\r
-  // Load the Linux kernel from a device path\r
-  LinuxImage = LINUX_KERNEL_MAX_OFFSET;\r
-  Status = BdsLoadImage (LinuxKernelDevicePath, AllocateMaxAddress, &LinuxImage, &LinuxImageSize);\r
-  if (EFI_ERROR(Status)) {\r
-    Print (L"ERROR: Did not find Linux kernel.\n");\r
-    return Status;\r
-  }\r
-\r
-  if (InitrdDevicePath) {\r
-    InitrdImageBase = LINUX_KERNEL_MAX_OFFSET;\r
-    Status = BdsLoadImage (InitrdDevicePath, AllocateMaxAddress, &InitrdImageBase, &InitrdImageBaseSize);\r
-    if (Status == EFI_OUT_OF_RESOURCES) {\r
-      Status = BdsLoadImage (InitrdDevicePath, AllocateAnyPages, &InitrdImageBase, &InitrdImageBaseSize);\r
-    }\r
-    if (EFI_ERROR(Status)) {\r
-      Print (L"ERROR: Did not find initrd image.\n");\r
-      goto EXIT_FREE_LINUX;\r
-    }\r
-\r
-    // Check if the initrd is a uInitrd\r
-    if (*(UINT32*)((UINTN)InitrdImageBase) == LINUX_UIMAGE_SIGNATURE) {\r
-      // Skip the 64-byte image header\r
-      InitrdImage = (EFI_PHYSICAL_ADDRESS)((UINTN)InitrdImageBase + 64);\r
-      InitrdImageSize = InitrdImageBaseSize - 64;\r
-    } else {\r
-      InitrdImage = InitrdImageBase;\r
-      InitrdImageSize = InitrdImageBaseSize;\r
-    }\r
-  }\r
-\r
-  //\r
-  // Get the FDT from the Configuration Table.\r
-  // The FDT will be reloaded in PrepareFdt() to a more appropriate\r
-  // location for the Linux Kernel.\r
-  //\r
-  Status = EfiGetSystemConfigurationTable (&gFdtTableGuid, &InstalledFdtBase);\r
-  if (EFI_ERROR (Status)) {\r
-    Print (L"ERROR: Did not get the Device Tree blob (%r).\n", Status);\r
-    goto EXIT_FREE_INITRD;\r
-  }\r
-  FdtBlobBase = (EFI_PHYSICAL_ADDRESS)(UINTN)InstalledFdtBase;\r
-  FdtBlobSize = fdt_totalsize (InstalledFdtBase);\r
-\r
-  // Update the Fdt with the Initrd information. The FDT will increase in size.\r
-  // By setting address=0 we leave the memory allocation to the function\r
-  Status = PrepareFdt (CommandLineArguments, InitrdImage, InitrdImageSize, &FdtBlobBase, &FdtBlobSize);\r
-  if (EFI_ERROR(Status)) {\r
-    Print(L"ERROR: Can not load kernel with FDT. Status=%r\n", Status);\r
-    goto EXIT_FREE_FDT;\r
-  }\r
-\r
-  return StartLinux (LinuxImage, LinuxImageSize, FdtBlobBase, FdtBlobSize, ARM_FDT_MACHINE_TYPE);\r
-\r
-EXIT_FREE_FDT:\r
-  gBS->FreePages (FdtBlobBase, EFI_SIZE_TO_PAGES (FdtBlobSize));\r
-\r
-EXIT_FREE_INITRD:\r
-  if (InitrdDevicePath) {\r
-    gBS->FreePages (InitrdImageBase, EFI_SIZE_TO_PAGES (InitrdImageBaseSize));\r
-  }\r
-\r
-EXIT_FREE_LINUX:\r
-  gBS->FreePages (LinuxImage, EFI_SIZE_TO_PAGES (LinuxImageSize));\r
-\r
-  return Status;\r
-}\r
-\r