3 * Copyright (c) 2011, ARM Limited. All rights reserved.
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
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.
15 #include "LinuxInternal.h"
17 #include <Library/PrintLib.h>
18 #include <Library/UefiApplicationEntryPoint.h>
21 The user Entry Point for Application. The user code starts with this function
22 as the real entry point for the application.
24 @param[in] ImageHandle The firmware allocated handle for the EFI image.
25 @param[in] SystemTable A pointer to the EFI System Table.
27 @retval EFI_SUCCESS The entry point is executed successfully.
28 @retval other Some error occurs when executing this entry point.
34 IN EFI_HANDLE ImageHandle
,
35 IN EFI_SYSTEM_TABLE
*SystemTable
39 EFI_LOADED_IMAGE_PROTOCOL
*LoadedImage
;
40 LINUX_LOADER_OPTIONAL_DATA
* LinuxOptionalData
;
41 EFI_DEVICE_PATH
* DevicePathKernel
;
42 EFI_DEVICE_PATH
* DevicePathFdt
;
43 EFI_DEVICE_PATH
* InitrdDevicePath
;
44 CHAR16
* OptionalDataInitrd
;
45 CHAR8
* OptionalDataArguments
;
48 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&LoadedImage
);
49 ASSERT_EFI_ERROR (Status
);
51 if (LoadedImage
->LoadOptionsSize
== 0) {
52 Status
= LinuxLoaderConfig (LoadedImage
);
54 // Ensure the signature is correct
55 LinuxOptionalData
= (LINUX_LOADER_OPTIONAL_DATA
*)LoadedImage
->LoadOptions
;
56 if (LinuxOptionalData
->Signature
!= LINUX_LOADER_SIGNATURE
) {
57 return EFI_UNSUPPORTED
;
60 // Generate the File Path Node for the Linux Kernel & Device Tree blobl
61 DevicePathKernel
= FileDevicePath (LoadedImage
->DeviceHandle
, LINUX_KERNEL_NAME
);
62 DevicePathFdt
= FileDevicePath (LoadedImage
->DeviceHandle
, FDT_NAME
);
64 if (LinuxOptionalData
->CmdLineLength
> 0) {
65 OptionalDataArguments
= (CHAR8
*)LinuxOptionalData
+ sizeof(LINUX_LOADER_OPTIONAL_DATA
);
67 OptionalDataArguments
= NULL
;
70 if (LinuxOptionalData
->InitrdPathListLength
> 0) {
71 if (OptionalDataArguments
!= NULL
) {
72 OptionalDataInitrd
= (CHAR16
*)(OptionalDataArguments
+ LinuxOptionalData
->CmdLineLength
);
74 OptionalDataInitrd
= (CHAR16
*)LinuxOptionalData
+ sizeof(LINUX_LOADER_OPTIONAL_DATA
);
77 // If pointer not aligned
78 if ((UINTN
)OptionalDataInitrd
& 0x1) {
79 Initrd
= (CHAR16
*)AllocateCopyPool (LinuxOptionalData
->InitrdPathListLength
, OptionalDataInitrd
);
81 Initrd
= OptionalDataInitrd
;
84 InitrdDevicePath
= FileDevicePath (LoadedImage
->DeviceHandle
, Initrd
);
86 OptionalDataInitrd
= NULL
;
87 InitrdDevicePath
= NULL
;
91 // Load and Start the Linux Kernel (we should never return)
92 Status
= BdsBootLinuxFdt (DevicePathKernel
, InitrdDevicePath
, OptionalDataArguments
, DevicePathFdt
);
94 if ((UINTN
)OptionalDataInitrd
& 0x1) {
98 FreePool (DevicePathKernel
);
99 if (InitrdDevicePath
) {
100 FreePool (InitrdDevicePath
);