]> git.proxmox.com Git - mirror_edk2.git/blob - EmbeddedPkg/Application/AndroidFastboot/Arm/BootAndroidBootImg.c
ArmPlatformPkg/Bds: Remove any use of the "Fdt" UEFI variable
[mirror_edk2.git] / EmbeddedPkg / Application / AndroidFastboot / Arm / BootAndroidBootImg.c
1 /** @file
2
3 Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
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 "AndroidFastbootApp.h"
16
17 #include <Protocol/DevicePath.h>
18
19 #include <Library/BdsLib.h>
20 #include <Library/DevicePathLib.h>
21
22 #include <Guid/ArmGlobalVariableHob.h>
23
24 // Device Path representing an image in memory
25 #pragma pack(1)
26 typedef struct {
27 MEMMAP_DEVICE_PATH Node1;
28 EFI_DEVICE_PATH_PROTOCOL End;
29 } MEMORY_DEVICE_PATH;
30 #pragma pack()
31
32 STATIC CONST MEMORY_DEVICE_PATH MemoryDevicePathTemplate =
33 {
34 {
35 {
36 HARDWARE_DEVICE_PATH,
37 HW_MEMMAP_DP,
38 {
39 (UINT8)(sizeof (MEMMAP_DEVICE_PATH)),
40 (UINT8)((sizeof (MEMMAP_DEVICE_PATH)) >> 8),
41 },
42 }, // Header
43 0, // StartingAddress (set at runtime)
44 0 // EndingAddress (set at runtime)
45 }, // Node1
46 {
47 END_DEVICE_PATH_TYPE,
48 END_ENTIRE_DEVICE_PATH_SUBTYPE,
49 { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
50 } // End
51 };
52
53 EFI_STATUS
54 BootAndroidBootImg (
55 IN UINTN BufferSize,
56 IN VOID *Buffer
57 )
58 {
59 EFI_STATUS Status;
60 CHAR8 KernelArgs[BOOTIMG_KERNEL_ARGS_SIZE];
61 VOID *Kernel;
62 UINTN KernelSize;
63 VOID *Ramdisk;
64 UINTN RamdiskSize;
65 MEMORY_DEVICE_PATH KernelDevicePath;
66 MEMORY_DEVICE_PATH* RamdiskDevicePath;
67
68 Status = ParseAndroidBootImg (
69 Buffer,
70 &Kernel,
71 &KernelSize,
72 &Ramdisk,
73 &RamdiskSize,
74 KernelArgs
75 );
76 if (EFI_ERROR (Status)) {
77 return Status;
78 }
79
80 KernelDevicePath = MemoryDevicePathTemplate;
81
82 // Have to cast to UINTN before casting to EFI_PHYSICAL_ADDRESS in order to
83 // appease GCC.
84 KernelDevicePath.Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel;
85 KernelDevicePath.Node1.EndingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Kernel + KernelSize;
86
87 RamdiskDevicePath = NULL;
88 if (RamdiskSize != 0) {
89 RamdiskDevicePath = (MEMORY_DEVICE_PATH*)DuplicateDevicePath ((EFI_DEVICE_PATH_PROTOCOL*) &MemoryDevicePathTemplate);
90
91 RamdiskDevicePath->Node1.StartingAddress = (EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk;
92 RamdiskDevicePath->Node1.EndingAddress = ((EFI_PHYSICAL_ADDRESS)(UINTN) Ramdisk) + RamdiskSize;
93 }
94
95 Status = BdsBootLinuxFdt (
96 (EFI_DEVICE_PATH_PROTOCOL *) &KernelDevicePath,
97 (EFI_DEVICE_PATH_PROTOCOL *) RamdiskDevicePath,
98 KernelArgs
99 );
100 if (EFI_ERROR (Status)) {
101 DEBUG ((EFI_D_ERROR, "Couldn't Boot Linux: %d\n", Status));
102 return EFI_DEVICE_ERROR;
103 }
104
105 if (RamdiskDevicePath) {
106 FreePool (RamdiskDevicePath);
107 }
108
109 // If we got here we do a confused face because BootLinuxFdt returned,
110 // reporting success.
111 DEBUG ((EFI_D_ERROR, "WARNING: BdsBootLinuxFdt returned EFI_SUCCESS.\n"));
112 return EFI_SUCCESS;
113 }