From patchwork Thu Apr 19 10:43:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 133743 Delivered-To: patch@linaro.org Received: by 10.46.66.142 with SMTP id h14csp478409ljf; Thu, 19 Apr 2018 03:43:21 -0700 (PDT) X-Google-Smtp-Source: AIpwx48Wvh/tWUO7nJcIeLI8xQx9RzdxXBeZTjSnuWGwFwRvmXCWIvr6g7oTDdIWBhfWDVF87Xhm X-Received: by 10.99.143.3 with SMTP id n3mr4704834pgd.136.1524134601365; Thu, 19 Apr 2018 03:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524134601; cv=none; d=google.com; s=arc-20160816; b=ujk42QPOkiNkDXwVbZIZ5lui3JMCWFV43bGbYzy83OaSUwaoxL2sgAqFA5u04RfZSt Ixs144rzKoKLVCvIn6ti1LuY4ApW8Xp5c/JTjOb3W7IgDPdjRjuVHKGAVsC4Ji7cbseP BrSr1jjLSSY1hXMatFYXetCtK3VE2d81fFZsMukjqBJWpA6LDmjkDHR0pvxbH4XBloPL Eq/CGoF8kVowJTCYz5nc9ekVvTQ4mQiLSjZq8+uvqNaZiQsjpN6JiGubEXdlSZ51qgrq WypyTlaFPpfkVdLPGznArYxm1PCMXMs1+tfWuOZNGCnJOll7KOxwt6cPlaniDHkSI9Dd /5dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=vE7m7ehdSzcZVCr6eerPjn0++v0NRDRiXHI4zOaa+6g=; b=O0oacMQWkTWYjqiVbDeB1a9SDs+O9pmxS7ODet3AmVsm2cUWBqtA7ePUi9J9Sc7+5U E5Bx/GwQ5lBCVujk7g1ojpF7KNQpucXzjWLiiBebxMLN0Duyb5wedxz1f67ELwXkwapD n43hUQDHUTwRhlESD9H15nu0j87gMj4vIyj47t3YH9Jxf5EER5Qt3GVL1K0VTgoJvXfn WGk99KqXJDBrlPV/Zl6Zk9q1Mqt9qhBDnb4yAfb9/2QJKS8uE21SKOJjjXF59YcfQGmi JyPZaG2e89j1NeLHbFALMPj5wtM+0zaa9hYxyVubFpu2ps58kvDhMGYe8uR9b6SYA1Bp Kn5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iv2+7qho; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id h80si3074919pfj.129.2018.04.19.03.43.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Apr 2018 03:43:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=iv2+7qho; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EE83C226C7C57; Thu, 19 Apr 2018 03:43:20 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2607:f8b0:400e:c00::241; helo=mail-pf0-x241.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x241.google.com (mail-pf0-x241.google.com [IPv6:2607:f8b0:400e:c00::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 432EF226847A6 for ; Thu, 19 Apr 2018 03:43:19 -0700 (PDT) Received: by mail-pf0-x241.google.com with SMTP id y69so2441018pfb.5 for ; Thu, 19 Apr 2018 03:43:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zmz8jmCd0iBOHfvzYXzAQ4VbnZ3fQP/5uWhRScEmrO0=; b=iv2+7qho/u2UdHW4sF7vmbL6GhTKodQAz3fUqLl5R5KszVpNdHI8hKdwO6Lufbw3rY thdPBQc5Gl7xs6LiTl6lVN318uqeQkOutT3lzQEHE9zPaK9rQXh10lwTI+YmTBHgYxM+ TnXs0Y3cr9LztS6jcDl6QvFx+wPLu0JGwc03M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zmz8jmCd0iBOHfvzYXzAQ4VbnZ3fQP/5uWhRScEmrO0=; b=Lp0Zx81l6hTqI0TUYopTl74p/myN2wCXHtrcbQaVvISCrzMRIq6ch38V5VlrxT6qyw wYAGRat1A4oEg2YYLEWcQKpHuU5IhNXhmGaCGNjtEvMJTvMLRnvOsIxmxPLgphlahgRR jD9IPsf6xuetBk6h6wJgaBkAEyMpIhwORg2aU1RmPHeN6Z4WnszC2RPUYIpcYoj4plcH mLBUGYscUdUXwjPmnGCYE3fvayM4s7VJiy8WxTXttfv2glWed10kD9wU/tu21iOBsfdi PyTGGLzHVgVtxceULXRAZI/Tgs4SA36BVTrn790XEwQdnbgPgf81EogekxSQRJo2jRyB kKwQ== X-Gm-Message-State: ALQs6tAnKcYlsCwy44f/CrmGvqq85Ewe5XTsnEdLmmphenDRaxT2n+Aa oQfAmR4pvLC0eErzD48TaU9Orc9t7XU= X-Received: by 10.99.119.201 with SMTP id s192mr4715212pgc.51.1524134598454; Thu, 19 Apr 2018 03:43:18 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.105]) by smtp.gmail.com with ESMTPSA id o64sm7353228pfb.62.2018.04.19.03.43.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Apr 2018 03:43:17 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Thu, 19 Apr 2018 18:43:02 +0800 Message-Id: <1524134583-1324-2-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524134583-1324-1-git-send-email-haojian.zhuang@linaro.org> References: <1524134583-1324-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v3 1/2] Platform/HiKey960: register predefined boot options X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Haojian Zhuang , Leif Lindholm , Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Create 4 boot options on HiKey960 platform. They're "Boot from SD", "Grub", "Android Boot" and "Android Fastboot". Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Ard Biesheuvel Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey960/HiKey960.dec | 35 ++++ Platform/Hisilicon/HiKey960/HiKey960.dsc | 6 + .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c | 185 +++++++++++++++++++++ .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf | 11 ++ 4 files changed, 237 insertions(+) create mode 100644 Platform/Hisilicon/HiKey960/HiKey960.dec -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dec b/Platform/Hisilicon/HiKey960/HiKey960.dec new file mode 100644 index 000000000000..922d7199c5a5 --- /dev/null +++ b/Platform/Hisilicon/HiKey960/HiKey960.dec @@ -0,0 +1,35 @@ +# +# Copyright (c) 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 +# 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. +# + +[Defines] + DEC_SPECIFICATION = 0x00010019 + PACKAGE_NAME = HiKey960 + PACKAGE_GUID = 1892b5b5-d18d-47a3-8fab-e3ae6b4226b0 + PACKAGE_VERSION = 0.1 + +################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Guids.common] + gHiKey960TokenSpaceGuid = { 0x99a14446, 0xaad7, 0xe460, {0xb4, 0xe5, 0x1f, 0x79, 0xaa, 0xa4, 0x93, 0xfd } } + +[PcdsFixedAtBuild.common] + gHiKey960TokenSpaceGuid.PcdAndroidBootDevicePath|L""|VOID*|0x00000001 + gHiKey960TokenSpaceGuid.PcdAndroidBootFile|{ 0x36, 0x8b, 0x73, 0x3a, 0xc5, 0xb9, 0x63, 0x47, 0xab, 0xbd, 0x6c, 0xbd, 0x4b, 0x25, 0xf9, 0xff }|VOID*|0x00000002 + gHiKey960TokenSpaceGuid.PcdAndroidFastbootFile|{ 0x2a, 0x50, 0x88, 0x95, 0x70, 0x53, 0xe3, 0x11, 0x86, 0x31, 0xd7, 0xc5, 0x95, 0x13, 0x64, 0xc8 }|VOID*|0x00000003 + gHiKey960TokenSpaceGuid.PcdSdBootDevicePath|L""|VOID*|0x00000004 diff --git a/Platform/Hisilicon/HiKey960/HiKey960.dsc b/Platform/Hisilicon/HiKey960/HiKey960.dsc index 859ab84f8415..475d39916262 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960.dsc +++ b/Platform/Hisilicon/HiKey960/HiKey960.dsc @@ -132,6 +132,12 @@ [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbVendorId|0x18d1 gEmbeddedTokenSpaceGuid.PcdAndroidFastbootUsbProductId|0xd00d + # + # Android Loader + # + gHiKey960TokenSpaceGuid.PcdAndroidBootDevicePath|L"VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,00003BFF0000000000)/UFS(0x0,0x3)/HD(7,GPT,D3340696-9B95-4C64-8DF6-E6D4548FBA41,0x12100,0x4000)" + gHiKey960TokenSpaceGuid.PcdSdBootDevicePath|L"VenHw(0D51905B-B77E-452A-A2C0-ECA0CC8D514A,00F037FF0000000000)/SD(0x0)" + ################################################################################ # # Components Section - list of all EDK II Modules needed by this Platform diff --git a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c index 473d61ed384e..44b3711dfbe1 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c @@ -30,10 +30,16 @@ #include #include #include +#include #include +#include #include +#include +#include #include +#include +#include #include #define ADC_ADCIN0 0 @@ -86,6 +92,10 @@ #define DETECT_SW_FASTBOOT 68 // GPIO8_4 +#define HIKEY960_BOOT_OPTION_NUM 4 + +#define GRUB_FILE_NAME L"\\EFI\\BOOT\\GRUBAA64.EFI" + typedef struct { UINT64 Magic; UINT64 Data; @@ -359,6 +369,171 @@ OnEndOfDxe ( } } +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) * (HIKEY960_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) * (HIKEY960_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 ( @@ -487,5 +662,15 @@ HiKey960EntryPoint ( 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/HiKey960/HiKey960Dxe/HiKey960Dxe.inf b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf index cc517656b340..5adedd79d3e8 100644 --- a/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf +++ b/Platform/Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf @@ -25,6 +25,7 @@ [Packages] EmbeddedPkg/EmbeddedPkg.dec MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec + Platform/Hisilicon/HiKey960/HiKey960.dec [LibraryClasses] BaseMemoryLib @@ -37,15 +38,25 @@ [LibraryClasses] PrintLib SerialPortLib TimerLib + UefiBootManagerLib UefiBootServicesTableLib UefiDriverEntryPoint UefiLib UefiRuntimeServicesTableLib [Protocols] + gEfiDevicePathFromTextProtocolGuid + gEfiLoadedImageProtocolGuid gEmbeddedGpioProtocolGuid + gPlatformBootManagerProtocolGuid gPlatformVirtualKeyboardProtocolGuid +[Pcd] + gHiKey960TokenSpaceGuid.PcdAndroidBootDevicePath + gHiKey960TokenSpaceGuid.PcdAndroidBootFile + gHiKey960TokenSpaceGuid.PcdAndroidFastbootFile + gHiKey960TokenSpaceGuid.PcdSdBootDevicePath + [Guids] gEfiEndOfDxeEventGroupGuid gEfiFileInfoGuid