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