From: Haojian Zhuang <haojian.zhuang@linaro.org>
To: edk2-devel@lists.01.org
Cc: Haojian Zhuang <haojian.zhuang@linaro.org>,
Laszlo Ersek <lersek@redhat.com>,
Leif Lindholm <leif.lindholm@linaro.org>,
Ard Biesheuvel <ard.biesheuvel@linaro.org>
Subject: [PATCH edk2-platforms v3 2/2] Platform/HiKey: create 4 boot options
Date: Thu, 19 Apr 2018 18:43:03 +0800 [thread overview]
Message-ID: <1524134583-1324-3-git-send-email-haojian.zhuang@linaro.org> (raw)
In-Reply-To: <1524134583-1324-1-git-send-email-haojian.zhuang@linaro.org>
Create 4 predefined boot options for HiKey. They're
"Boot from SD", "Grub", "Android Boot" and "Android Fastboot".
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>
---
Platform/Hisilicon/HiKey/HiKey.dec | 8 +-
Platform/Hisilicon/HiKey/HiKey.dsc | 7 +
Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c | 184 +++++++++++++++++++++++++
Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf | 11 ++
4 files changed, 207 insertions(+), 3 deletions(-)
diff --git a/Platform/Hisilicon/HiKey/HiKey.dec b/Platform/Hisilicon/HiKey/HiKey.dec
index 537138eb45a1..bb94c5cab13f 100644
--- a/Platform/Hisilicon/HiKey/HiKey.dec
+++ b/Platform/Hisilicon/HiKey/HiKey.dec
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2014-2017, Linaro Limited. All rights reserved.
+# Copyright (c) 2014-2018, Linaro Limited. All rights reserved.
#
# This program and the accompanying materials
# are licensed and made available under the terms and conditions of the BSD License
@@ -32,5 +32,7 @@ [Guids.common]
gHiKeyTokenSpaceGuid = { 0x91148425, 0xcdd2, 0x4830, { 0x8b, 0xd0, 0xc6, 0x1c, 0x6d, 0xea, 0x36, 0x21 } }
[PcdsFixedAtBuild.common]
- gHiKeyTokenSpaceGuid.PcdAndroidFastbootNvmDevicePath|L""|VOID*|0x00000001
- gHiKeyTokenSpaceGuid.PcdArmFastbootFlashLimit|L""|VOID*|0x00000002
+ gHiKeyTokenSpaceGuid.PcdAndroidBootDevicePath|L""|VOID*|0x00000001
+ gHiKeyTokenSpaceGuid.PcdAndroidBootFile|{ 0x36, 0x8b, 0x73, 0x3a, 0xc5, 0xb9, 0x63, 0x47, 0xab, 0xbd, 0x6c, 0xbd, 0x4b, 0x25, 0xf9, 0xff }|VOID*|0x00000002
+ gHiKeyTokenSpaceGuid.PcdAndroidFastbootFile|{ 0x2a, 0x50, 0x88, 0x95, 0x70, 0x53, 0xe3, 0x11, 0x86, 0x31, 0xd7, 0xc5, 0x95, 0x13, 0x64, 0xc8 }|VOID*|0x00000003
+ gHiKeyTokenSpaceGuid.PcdSdBootDevicePath|L""|VOID*|0x00000004
diff --git a/Platform/Hisilicon/HiKey/HiKey.dsc b/Platform/Hisilicon/HiKey/HiKey.dsc
index 83dd68a820b1..5b5dc48a693a 100644
--- a/Platform/Hisilicon/HiKey/HiKey.dsc
+++ b/Platform/Hisilicon/HiKey/HiKey.dsc
@@ -138,6 +138,13 @@ [PcdsFixedAtBuild.common]
gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbVendorId|0x18d1
gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbProductId|0xd00d
+ #
+ # Android Loader
+ #
+ gHiKeyTokenSpaceGuid.PcdAndroidBootDevicePath|L"VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,00D023F70000000000)/eMMC(0x0)/Ctrl(0x0)/HD(6,GPT,5C0F213C-17E1-4149-88C8-8B50FB4EC70E,0x7000,0x20000)"
+ gHiKeyTokenSpaceGuid.PcdSdBootDevicePath|L"VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,00E023F70000000000)/SD(0x0)"
+
+
################################################################################
#
# Components Section - list of all EDK II Modules needed by this Platform
diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c
index 65e800116b76..223affa33635 100644
--- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c
+++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c
@@ -18,12 +18,18 @@
#include <Library/DevicePathLib.h>
#include <Library/IoLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PrintLib.h>
+#include <Library/UefiBootManagerLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/DevicePathFromText.h>
#include <Protocol/EmbeddedGpio.h>
+#include <Protocol/LoadedImage.h>
+#include <Protocol/PlatformBootManager.h>
#include <Protocol/PlatformVirtualKeyboard.h>
#include <Hi6220.h>
@@ -42,6 +48,9 @@
#define ADB_REBOOT_BOOTLOADER 0x77665500
#define ADB_REBOOT_NONE 0x77665501
+#define HIKEY_BOOT_OPTION_NUM 4
+
+#define GRUB_FILE_NAME L"\\EFI\\BOOT\\GRUBAA64.EFI"
typedef struct {
UINT64 Magic;
@@ -121,6 +130,171 @@ HiKeyInitPeripherals (
return EFI_SUCCESS;
}
+STATIC
+EFI_STATUS
+GetPlatformBootOptionsAndKeys (
+ OUT EFI_BOOT_MANAGER_LOAD_OPTION **BootOptions,
+ OUT EFI_INPUT_KEY **BootKeys
+ )
+{
+ EFI_DEVICE_PATH *DevicePath;
+ EFI_DEVICE_PATH *FileDevicePath;
+ EFI_DEVICE_PATH_FROM_TEXT_PROTOCOL *DPProtocol;
+ FILEPATH_DEVICE_PATH *FilePath;
+ EFI_GUID *FileGuid;
+ EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
+ MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode;
+ CHAR16 *PathStr;
+ EFI_STATUS Status;
+ UINTN Size;
+
+ if ((BootOptions == NULL) || (BootKeys == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ //
+ // Leave the last entry as empty
+ //
+ Size = sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * (HIKEY_BOOT_OPTION_NUM + 1);
+ *BootOptions = (EFI_BOOT_MANAGER_LOAD_OPTION *)AllocateZeroPool (Size);
+ if (*BootOptions == NULL) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootOptions\n"));
+ return EFI_BUFFER_TOO_SMALL;
+ }
+ //
+ // Leave the last entry as empty
+ //
+ Size = sizeof (EFI_INPUT_KEY) * (HIKEY_BOOT_OPTION_NUM + 1);
+ *BootKeys = (EFI_INPUT_KEY *)AllocateZeroPool (Size);
+ if (*BootKeys == NULL) {
+ DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootKeys\n"));
+ FreePool (*BootOptions);
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ PathStr = (CHAR16 *)PcdGetPtr (PcdSdBootDevicePath);
+ ASSERT (PathStr != NULL);
+ Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid,
+ NULL,
+ (VOID **)&DPProtocol
+ );
+ ASSERT_EFI_ERROR (Status);
+ DevicePath = (EFI_DEVICE_PATH *)DPProtocol->ConvertTextToDevicePath (PathStr);
+ ASSERT (DevicePath != NULL);
+ Status = EfiBootManagerInitializeLoadOption (
+ &(*BootOptions)[0],
+ LoadOptionNumberUnassigned,
+ LoadOptionTypeBoot,
+ LOAD_OPTION_ACTIVE,
+ L"Boot from SD",
+ DevicePath,
+ NULL,
+ 0
+ );
+ ASSERT_EFI_ERROR (Status);
+ FreePool (DevicePath);
+
+ PathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath);
+ ASSERT (PathStr != NULL);
+ Status = gBS->LocateProtocol (&gEfiDevicePathFromTextProtocolGuid,
+ NULL,
+ (VOID **)&DPProtocol
+ );
+ ASSERT_EFI_ERROR (Status);
+ DevicePath = (EFI_DEVICE_PATH *)DPProtocol->ConvertTextToDevicePath (PathStr);
+ ASSERT (DevicePath != NULL);
+ Size = StrSize (GRUB_FILE_NAME);
+ FileDevicePath = AllocatePool (Size + SIZE_OF_FILEPATH_DEVICE_PATH + END_DEVICE_PATH_LENGTH);
+ if (FileDevicePath != NULL) {
+ FilePath = (FILEPATH_DEVICE_PATH *) FileDevicePath;
+ FilePath->Header.Type = MEDIA_DEVICE_PATH;
+ FilePath->Header.SubType = MEDIA_FILEPATH_DP;
+ CopyMem (&FilePath->PathName, GRUB_FILE_NAME, Size);
+ SetDevicePathNodeLength (&FilePath->Header, Size + SIZE_OF_FILEPATH_DEVICE_PATH);
+ SetDevicePathEndNode (NextDevicePathNode (&FilePath->Header));
+
+ DevicePath = AppendDevicePath (DevicePath, FileDevicePath);
+ FreePool (FileDevicePath);
+ }
+ Status = EfiBootManagerInitializeLoadOption (
+ &(*BootOptions)[1],
+ LoadOptionNumberUnassigned,
+ LoadOptionTypeBoot,
+ LOAD_OPTION_ACTIVE,
+ L"Grub",
+ DevicePath,
+ NULL,
+ 0
+ );
+ ASSERT_EFI_ERROR (Status);
+ FreePool (DevicePath);
+
+ FileGuid = PcdGetPtr (PcdAndroidBootFile);
+ ASSERT (FileGuid != NULL);
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **) &LoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
+ EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
+ DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
+ ASSERT (DevicePath != NULL);
+ DevicePath = AppendDevicePathNode (
+ DevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
+ );
+ ASSERT (DevicePath != NULL);
+ Status = EfiBootManagerInitializeLoadOption (
+ &(*BootOptions)[2],
+ LoadOptionNumberUnassigned,
+ LoadOptionTypeBoot,
+ LOAD_OPTION_ACTIVE,
+ L"Android Boot",
+ DevicePath,
+ NULL,
+ 0
+ );
+ ASSERT_EFI_ERROR (Status);
+ FreePool (DevicePath);
+
+ FileGuid = PcdGetPtr (PcdAndroidFastbootFile);
+ ASSERT (FileGuid != NULL);
+ Status = gBS->HandleProtocol (
+ gImageHandle,
+ &gEfiLoadedImageProtocolGuid,
+ (VOID **) &LoadedImage
+ );
+ ASSERT_EFI_ERROR (Status);
+ EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid);
+ DevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle);
+ ASSERT (DevicePath != NULL);
+ DevicePath = AppendDevicePathNode (
+ DevicePath,
+ (EFI_DEVICE_PATH_PROTOCOL *) &FileNode
+ );
+ ASSERT (DevicePath != NULL);
+ Status = EfiBootManagerInitializeLoadOption (
+ &(*BootOptions)[3],
+ LoadOptionNumberUnassigned,
+ LoadOptionTypeBoot,
+ LOAD_OPTION_ACTIVE,
+ L"Android Fastboot",
+ DevicePath,
+ NULL,
+ 0
+ );
+ ASSERT_EFI_ERROR (Status);
+ FreePool (DevicePath);
+ (*BootKeys)[3].ScanCode = SCAN_NULL;
+ (*BootKeys)[3].UnicodeChar = 'f';
+
+ return EFI_SUCCESS;
+}
+
+PLATFORM_BOOT_MANAGER_PROTOCOL mPlatformBootManager = {
+ GetPlatformBootOptionsAndKeys
+};
+
EFI_STATUS
EFIAPI
VirtualKeyboardRegister (
@@ -225,5 +399,15 @@ HiKeyEntryPoint (
EFI_NATIVE_INTERFACE,
&mVirtualKeyboard
);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ Status = gBS->InstallProtocolInterface (
+ &ImageHandle,
+ &gPlatformBootManagerProtocolGuid,
+ EFI_NATIVE_INTERFACE,
+ &mPlatformBootManager
+ );
return Status;
}
diff --git a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
index 702fdb1eebf0..e97afab8785a 100644
--- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
+++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf
@@ -27,6 +27,7 @@ [Packages]
EmbeddedPkg/EmbeddedPkg.dec
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
+ Platform/Hisilicon/HiKey/HiKey.dec
[LibraryClasses]
BaseMemoryLib
@@ -40,15 +41,25 @@ [LibraryClasses]
PrintLib
SerialPortLib
TimerLib
+ UefiBootManagerLib
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
UefiLib
UefiDriverEntryPoint
[Protocols]
+ gEfiDevicePathFromTextProtocolGuid
+ gEfiLoadedImageProtocolGuid
gEmbeddedGpioProtocolGuid
+ gPlatformBootManagerProtocolGuid
gPlatformVirtualKeyboardProtocolGuid
+[Pcd]
+ gHiKeyTokenSpaceGuid.PcdAndroidBootDevicePath
+ gHiKeyTokenSpaceGuid.PcdAndroidBootFile
+ gHiKeyTokenSpaceGuid.PcdAndroidFastbootFile
+ gHiKeyTokenSpaceGuid.PcdSdBootDevicePath
+
[Guids]
gEfiEndOfDxeEventGroupGuid
gEfiFileInfoGuid
--
2.7.4
prev parent reply other threads:[~2018-04-19 10:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 10:43 [PATCH edk2-platforms v3 0/2] add platform boot options Haojian Zhuang
2018-04-19 10:43 ` [PATCH edk2-platforms v3 1/2] Platform/HiKey960: register predefined " Haojian Zhuang
2018-04-19 10:43 ` Haojian Zhuang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524134583-1324-3-git-send-email-haojian.zhuang@linaro.org \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox