summaryrefslogtreecommitdiff
path: root/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
diff options
context:
space:
mode:
authorHaojian Zhuang <haojian.zhuang@linaro.org>2017-02-07 22:07:28 +0800
committerHaojian Zhuang <haojian.zhuang@linaro.org>2017-03-01 15:05:24 +0800
commit4e3a0e71d1870a9efcd2f00fbb133b3711f5e5b7 (patch)
tree452c6ae46028582d5170a343f3ec86d4bf1c48e8 /EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
parentd662660cb3ca5f6c93d822cba5ee4679ab000d67 (diff)
downloadedk2-4e3a0e71d1870a9efcd2f00fbb133b3711f5e5b7.tar.gz
EmbeddedPkg/AndroidBoot: boot android kernel from storage
Add an android kernel loader that could load kernel from storage device. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
Diffstat (limited to 'EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c')
-rw-r--r--EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
new file mode 100644
index 000000000..312bfd7df
--- /dev/null
+++ b/EmbeddedPkg/Application/AndroidBoot/AndroidBootApp.c
@@ -0,0 +1,118 @@
+/** @file
+
+ Copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
+ Copyright (c) 2017, Linaro. All rights reserved.
+
+ This program and the accompanying materials
+ are licensed and made available under the terms and conditions of the BSD License
+ which accompanies this distribution. The full text of the license may be found at
+ http://opensource.org/licenses/bsd-license.php
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <Library/BaseMemoryLib.h>
+#include <Library/BdsLib.h>
+#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/BlockIo.h>
+#include <Protocol/DevicePathFromText.h>
+
+#include "AndroidBootApp.h"
+
+#define IS_DEVICE_PATH_NODE(node,type,subtype) (((node)->Type == (type)) && ((node)->SubType == (subtype)))
+
+STATIC FASTBOOT_PLATFORM_PROTOCOL *mPlatform;
+
+EFI_STATUS
+EFIAPI
+AndroidBootAppEntryPoint (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ CHAR16 *BootPathStr;
+ EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *EfiDevicePathFromTextProtocol;
+ EFI_DEVICE_PATH *DevicePath;
+ EFI_DEVICE_PATH_PROTOCOL *Node, *NextNode;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ HARDDRIVE_DEVICE_PATH *PartitionPath;
+ UINT32 MediaId, BlockSize;
+ VOID *Buffer;
+ EFI_HANDLE Handle;
+
+ BootPathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
+ ASSERT (BootPathStr != NULL);
+ Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid, NULL, (VOID **)&EfiDevicePathFromTextProtocol);
+ ASSERT_EFI_ERROR(Status);
+ DevicePath = (EFI_DEVICE_PATH *)EfiDevicePathFromTextProtocol->ConvertTextToDevicePath (BootPathStr);
+ ASSERT (DevicePath != NULL);
+
+ /* Find DevicePath node of Partition */
+ NextNode = DevicePath;
+ while (1) {
+ Node = NextNode;
+ if (IS_DEVICE_PATH_NODE (Node, MEDIA_DEVICE_PATH, MEDIA_HARDDRIVE_DP)) {
+ PartitionPath = (HARDDRIVE_DEVICE_PATH *)Node;
+ break;
+ }
+ NextNode = NextDevicePathNode (Node);
+ }
+
+ Status = gBS->LocateDevicePath (&gEfiDevicePathProtocolGuid, &DevicePath, &Handle);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->OpenProtocol (
+ Handle,
+ &gEfiBlockIoProtocolGuid,
+ (VOID **) &BlockIo,
+ gImageHandle,
+ NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "Failed to get BlockIo: %r\n", Status));
+ return Status;
+ }
+
+ MediaId = BlockIo->Media->MediaId;
+ BlockSize = BlockIo->Media->BlockSize;
+ /* Both PartitionStart and PartitionSize are counted as block size. */
+ Buffer = AllocatePages (EFI_SIZE_TO_PAGES (PartitionPath->PartitionSize));
+ if (Buffer == NULL) {
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ /* Load header of boot.img */
+ Status = BlockIo->ReadBlocks (
+ BlockIo,
+ MediaId,
+ PartitionPath->PartitionStart / BlockSize,
+ PartitionPath->PartitionSize,
+ Buffer
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "Failed to read blocks: %r\n", Status));
+ goto EXIT;
+ }
+
+ Status = gBS->LocateProtocol (&gAndroidFastbootPlatformProtocolGuid, NULL, (VOID **) &mPlatform);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((EFI_D_ERROR, "Fastboot: Couldn't open Fastboot Platform Protocol: %r\n", Status));
+ goto EXIT;
+ }
+
+ Status = BootAndroidBootImg (mPlatform, PartitionPath->PartitionSize, Buffer);
+
+EXIT:
+ FreePages (Buffer, EFI_SIZE_TO_PAGES (PartitionPath->PartitionSize));
+ return Status;
+}