3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
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 "AndroidFastbootApp.h"
17 #include <Protocol/DevicePath.h>
19 #include <Library/BdsLib.h>
20 #include <Library/DevicePathLib.h>
22 #include <Guid/ArmGlobalVariableHob.h>
24 // Device Path representing an image in memory
27 MEMMAP_DEVICE_PATH Node1
;
28 EFI_DEVICE_PATH_PROTOCOL End
;
32 STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate
=
39 (UINT8
)(sizeof (MEMMAP_DEVICE_PATH
)),
40 (UINT8
)((sizeof (MEMMAP_DEVICE_PATH
)) >> 8),
43 0, // StartingAddress (set at runtime)
44 0 // EndingAddress (set at runtime)
48 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
49 sizeof (EFI_DEVICE_PATH_PROTOCOL
),
60 EFI_DEVICE_PATH_PROTOCOL
*FdtDevicePath
;
62 CHAR8 KernelArgs
[BOOTIMG_KERNEL_ARGS_SIZE
];
67 MEMORY_DEVICE_PATH KernelDevicePath
;
68 MEMORY_DEVICE_PATH
* RamdiskDevicePath
;
70 Status
= ParseAndroidBootImg (
78 if (EFI_ERROR (Status
)) {
82 KernelDevicePath
= MemoryDevicePathTemplate
;
84 // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to
86 KernelDevicePath
.Node1
.StartingAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Kernel
;
87 KernelDevicePath
.Node1
.EndingAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Kernel
+ KernelSize
;
89 RamdiskDevicePath
= NULL
;
90 if (RamdiskSize
!= 0) {
91 RamdiskDevicePath
= (MEMORY_DEVICE_PATH
*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL
*) &MemoryDevicePathTemplate
);
93 RamdiskDevicePath
->Node1
.StartingAddress
= (EFI_PHYSICAL_ADDRESS
)(UINTN
) Ramdisk
;
94 RamdiskDevicePath
->Node1
.EndingAddress
= ((EFI_PHYSICAL_ADDRESS
)(UINTN
) Ramdisk
) + RamdiskSize
;
97 // Get the default FDT device path
98 Status
= GetEnvironmentVariable ((CHAR16
*)L
"Fdt", &gArmGlobalVariableGuid
,
99 NULL
, 0, (VOID
**)&FdtDevicePath
);
100 if (Status
== EFI_NOT_FOUND
) {
101 DEBUG ((EFI_D_ERROR
, "Error: Please update FDT path in boot manager\n"));
102 return EFI_DEVICE_ERROR
;
104 ASSERT_EFI_ERROR (Status
);
106 Status
= BdsBootLinuxFdt (
107 (EFI_DEVICE_PATH_PROTOCOL
*) &KernelDevicePath
,
108 (EFI_DEVICE_PATH_PROTOCOL
*) RamdiskDevicePath
,
112 if (EFI_ERROR (Status
)) {
113 DEBUG ((EFI_D_ERROR
, "Couldn't Boot Linux: %d\n", Status
));
114 return EFI_DEVICE_ERROR
;
117 if (RamdiskDevicePath
) {
118 FreePool (RamdiskDevicePath
);
121 // If we got here we do a confused face because BootLinuxFdt returned,
122 // reporting success.
123 DEBUG ((EFI_D_ERROR
, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));