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
* InitrdDevicePath
;
43 CHAR16
* OptionalDataInitrd
;
44 CHAR8
* OptionalDataArguments
;
47 Status
= gBS
->HandleProtocol (ImageHandle
, &gEfiLoadedImageProtocolGuid
, (VOID
**)&LoadedImage
);
48 ASSERT_EFI_ERROR (Status
);
50 if (LoadedImage
->LoadOptionsSize
== 0) {
51 Status
= LinuxLoaderConfig (LoadedImage
);
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
;
59 // Generate the File Path Node for the Linux Kernel
60 DevicePathKernel
= FileDevicePath (LoadedImage
->DeviceHandle
, LINUX_KERNEL_NAME
);
62 if (LinuxOptionalData
->CmdLineLength
> 0) {
63 OptionalDataArguments
= (CHAR8
*)LinuxOptionalData
+ sizeof(LINUX_LOADER_OPTIONAL_DATA
);
65 OptionalDataArguments
= NULL
;
68 if (LinuxOptionalData
->InitrdPathListLength
> 0) {
69 if (OptionalDataArguments
!= NULL
) {
70 OptionalDataInitrd
= (CHAR16
*)(OptionalDataArguments
+ LinuxOptionalData
->CmdLineLength
);
72 OptionalDataInitrd
= (CHAR16
*)LinuxOptionalData
+ sizeof(LINUX_LOADER_OPTIONAL_DATA
);
75 // If pointer not aligned
76 if ((UINTN
)OptionalDataInitrd
& 0x1) {
77 Initrd
= (CHAR16
*)AllocateCopyPool (LinuxOptionalData
->InitrdPathListLength
, OptionalDataInitrd
);
79 Initrd
= OptionalDataInitrd
;
82 InitrdDevicePath
= FileDevicePath (LoadedImage
->DeviceHandle
, Initrd
);
84 OptionalDataInitrd
= NULL
;
85 InitrdDevicePath
= NULL
;
89 // Load and Start the Linux Kernel (we should never return)
90 Status
= BdsBootLinuxAtag (DevicePathKernel
, InitrdDevicePath
, OptionalDataArguments
);
92 if ((UINTN
)OptionalDataInitrd
& 0x1) {
96 FreePool (DevicePathKernel
);
97 if (InitrdDevicePath
) {
98 FreePool (InitrdDevicePath
);