]> git.proxmox.com Git - mirror_edk2.git/blame - ArmPkg/Application/LinuxLoader/LinuxFdtLoader.c
ArmPlatformPkg/Bds: Remove any use of the "Fdt" UEFI variable
[mirror_edk2.git] / ArmPkg / Application / LinuxLoader / LinuxFdtLoader.c
CommitLineData
75e4db2d 1/** @file\r
2*\r
3* Copyright (c) 2011, ARM Limited. All rights reserved.\r
4*\r
5* This program and the accompanying materials\r
6* are licensed and made available under the terms and conditions of the BSD License\r
7* which accompanies this distribution. The full text of the license may be found at\r
8* http://opensource.org/licenses/bsd-license.php\r
9*\r
10* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12*\r
13**/\r
14\r
15#include "LinuxInternal.h"\r
16\r
17#include <Library/PrintLib.h>\r
18#include <Library/UefiApplicationEntryPoint.h>\r
19\r
20/**\r
21 The user Entry Point for Application. The user code starts with this function\r
22 as the real entry point for the application.\r
23\r
24 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
25 @param[in] SystemTable A pointer to the EFI System Table.\r
26\r
27 @retval EFI_SUCCESS The entry point is executed successfully.\r
28 @retval other Some error occurs when executing this entry point.\r
29\r
30**/\r
31EFI_STATUS\r
32EFIAPI\r
33UefiMain (\r
34 IN EFI_HANDLE ImageHandle,\r
35 IN EFI_SYSTEM_TABLE *SystemTable\r
36 )\r
37{\r
38 EFI_STATUS Status;\r
39 EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;\r
40 LINUX_LOADER_OPTIONAL_DATA* LinuxOptionalData;\r
41 EFI_DEVICE_PATH* DevicePathKernel;\r
75e4db2d 42 EFI_DEVICE_PATH* InitrdDevicePath;\r
43 CHAR16* OptionalDataInitrd;\r
44 CHAR8* OptionalDataArguments;\r
45 CHAR16* Initrd;\r
46\r
47 Status = gBS->HandleProtocol (ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **)&LoadedImage);\r
48 ASSERT_EFI_ERROR (Status);\r
49\r
50 if (LoadedImage->LoadOptionsSize == 0) {\r
51 Status = LinuxLoaderConfig (LoadedImage);\r
52 } else {\r
53 // Ensure the signature is correct\r
54 LinuxOptionalData = (LINUX_LOADER_OPTIONAL_DATA*)LoadedImage->LoadOptions;\r
55 if (LinuxOptionalData->Signature != LINUX_LOADER_SIGNATURE) {\r
56 return EFI_UNSUPPORTED;\r
57 }\r
58\r
6332ffb0 59 // Generate the File Path Node for the Linux Kernel\r
75e4db2d 60 DevicePathKernel = FileDevicePath (LoadedImage->DeviceHandle, LINUX_KERNEL_NAME);\r
75e4db2d 61\r
62 if (LinuxOptionalData->CmdLineLength > 0) {\r
63 OptionalDataArguments = (CHAR8*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA);\r
64 } else {\r
65 OptionalDataArguments = NULL;\r
66 }\r
67\r
68 if (LinuxOptionalData->InitrdPathListLength > 0) {\r
69 if (OptionalDataArguments != NULL) {\r
70 OptionalDataInitrd = (CHAR16*)(OptionalDataArguments + LinuxOptionalData->CmdLineLength);\r
71 } else {\r
72 OptionalDataInitrd = (CHAR16*)LinuxOptionalData + sizeof(LINUX_LOADER_OPTIONAL_DATA);\r
73 }\r
74\r
75 // If pointer not aligned\r
76 if ((UINTN)OptionalDataInitrd & 0x1) {\r
77 Initrd = (CHAR16*)AllocateCopyPool (LinuxOptionalData->InitrdPathListLength, OptionalDataInitrd);\r
78 } else {\r
79 Initrd = OptionalDataInitrd;\r
80 }\r
81\r
82 InitrdDevicePath = FileDevicePath (LoadedImage->DeviceHandle, Initrd);\r
83 } else {\r
84 OptionalDataInitrd = NULL;\r
85 InitrdDevicePath = NULL;\r
86 Initrd = NULL;\r
87 }\r
88\r
89 // Load and Start the Linux Kernel (we should never return)\r
6332ffb0 90 Status = BdsBootLinuxFdt (DevicePathKernel, InitrdDevicePath, OptionalDataArguments);\r
75e4db2d 91\r
92 if ((UINTN)OptionalDataInitrd & 0x1) {\r
93 FreePool (Initrd);\r
94 }\r
95\r
96 FreePool (DevicePathKernel);\r
97 if (InitrdDevicePath) {\r
98 FreePool (InitrdDevicePath);\r
99 }\r
100 }\r
101\r
102 return Status;\r
103}\r