From patchwork Sat Apr 28 05:41:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 134645 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1517633lji; Fri, 27 Apr 2018 22:41:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpEbd/8b+lnDNe8dGSIBzYzgOMILR0zP08IBtT8ARlznXziz/tJGq/qk+IRb2TRteYrsUGe X-Received: by 2002:a17:902:70c9:: with SMTP id l9-v6mr2754872plt.382.1524894095498; Fri, 27 Apr 2018 22:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524894095; cv=none; d=google.com; s=arc-20160816; b=XRjEsLLj27TcV2+25gqVo4KxZU5P04YBZW5zOk9LusAv3CMKC6rZ58KW8/m1VVdKaa s0Om2qhi1a2QJWdqXw2Fl1teQf4UzdB3PMQUBeQ+nVanE+XfE49D6WQwINfps1bXsgt3 OOwFhvAjLV4TAJOcnAxOUEefg+FQVjGwPy7iQ8CxzGdrMWCF0WpBedA/8Fa8fbU32L6A Neo8LT7hp+aCk6DEP+tBU//fNanok1uAlbslRALSWy4bBit8UeIAojMdnbx3cjhBKN3Q /SuZfybXx0yHAmEbYd3Hnhi0OLamsdIcOIHnYe8hDxljOH2qp2sVUQawHAeSc+tT8IzL Blvg== 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=0wqZ0/6kFuFP7mHT3B/tGqbcHaKHDVsUPYBP9XwWrf8=; b=inxZdz+TRVOsbIjQBZ1mthp+ix3xC2bYA68O8WpzSWipKk9PmIs9ua2u1I8OsnHTkL dtM2EuOhQ/2xAipLENONqVdYnBEGW9LmhDchcx0YL0L9jAy/2xw45c/HpAZIGl/j+5AZ DE/3SzvYzhhghAOwlrV5/eZ2Vo8VUD7bbHh1JNKTLCp5B7JNBAF6xNCCR8bgO/aFzVdK dqkeYtVukgNzCc3MuSFa+4gY/MEg8MqjCUVjqTewm8QN/Sqei1s8teq39cnja4URVgVp pyV1X+wHSCouYIicgJ0ZKMpxUUpJdWWFgo8BMbfN9Ac6sGqvkeS8dNOUh1IzZI5GtKa+ BHGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KuPOTUFK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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. [2001:19d0:306:5::1]) by mx.google.com with ESMTPS id n2-v6si2527336pga.202.2018.04.27.22.41.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 22:41:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 as permitted sender) client-ip=2001:19d0:306:5::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KuPOTUFK; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 2001:19d0:306:5::1 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 19D7D2034C8A6; Fri, 27 Apr 2018 22:41:35 -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:c05::241; helo=mail-pg0-x241.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pg0-x241.google.com (mail-pg0-x241.google.com [IPv6:2607:f8b0:400e:c05::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 9F404207DF47F for ; Fri, 27 Apr 2018 22:41:33 -0700 (PDT) Received: by mail-pg0-x241.google.com with SMTP id m21-v6so2970657pgv.8 for ; Fri, 27 Apr 2018 22:41:33 -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=88bvUhriosAVIJXdWHHGp2/DAp327+5XhysX65FRBjU=; b=KuPOTUFKTVhOKKRaPz6VkmRg+vnsgGN7OkndKLgWEbrTo/ue/3LI5yyEvJQOzBDd2+ RKiEm4t3bp5Ys6+4XVbt8b69FR4FxbJwXxHY2r1SO1IVqVTcQth99V0m0Prx4n3mxtmm ZYm+bJIZHPp4iRSvlpm+b3yysqYbWAWyQ5M68= 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=88bvUhriosAVIJXdWHHGp2/DAp327+5XhysX65FRBjU=; b=PeXuBqEE+c9kjfCNjgmoUJaFUcx2gY39+BkzfFE3hi5vqFZE3sNtIkAmyb4Lsu5O5+ 0cA/RiK8OHZPIGQJUoR7QzybMH4ir0pFEYaIPDBjZA4E4e3Uw/XwmzIPKhzTIENRoEtH IgBlUR9JYm184rGE2PbJoT8fX7T91AnGk1/fDQoFRUBUSlp5+tN5VQWNNgP4yfiHcpW5 VZPObPB5wPq2PD3kGDMj+cJOG3LDCNkJUVNbCgZVI2YAe8a8tt27hBWbn5i8uHg55RvD 31nLww6OD5GxrU1wFHzLg9ejk39mEwZdMJdrH9lgvhD5zmZVkpPlrr7lQc+o3+xcAvRX wPDg== X-Gm-Message-State: ALQs6tBWUeRgG10KGprc30N4U5bs4es3oZq6SaBqZLdIYokT+ouCxqeI 96so25Ps3ulhTrOliylUsN2pv+l7lX8= X-Received: by 2002:a65:5686:: with SMTP id v6-v6mr4144179pgs.92.1524894092970; Fri, 27 Apr 2018 22:41:32 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.141]) by smtp.gmail.com with ESMTPSA id b89sm5983111pfd.85.2018.04.27.22.41.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 22:41:32 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Sat, 28 Apr 2018 13:41:20 +0800 Message-Id: <1524894081-17567-2-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524894081-17567-1-git-send-email-haojian.zhuang@linaro.org> References: <1524894081-17567-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v7 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 Acked-by: Laszlo Ersek 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 | 164 +++++++++++++++++++++ .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf | 11 ++ 4 files changed, 216 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..4097fbfd77f5 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)/\\EFI\\BOOT\\GRUBAA64.EFI" + 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..b76ac8b571e7 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,8 @@ #define DETECT_SW_FASTBOOT 68 // GPIO8_4 +#define HIKEY960_BOOT_OPTION_NUM 4 + typedef struct { UINT64 Magic; UINT64 Data; @@ -359,6 +367,152 @@ OnEndOfDxe ( } } +STATIC +EFI_STATUS +CreatePlatformBootOptionFromPath ( + IN CHAR16 *PathStr, + IN CHAR16 *Description, + IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH *DevicePath; + + DevicePath = (EFI_DEVICE_PATH *)ConvertTextToDevicePath (PathStr); + ASSERT (DevicePath != NULL); + Status = EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + Description, + DevicePath, + NULL, + 0 + ); + FreePool (DevicePath); + return Status; +} + +STATIC +EFI_STATUS +CreatePlatformBootOptionFromGuid ( + IN EFI_GUID *FileGuid, + IN CHAR16 *Description, + IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH *DevicePath; + EFI_DEVICE_PATH *TempDevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + + Status = gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + ASSERT_EFI_ERROR (Status); + EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid); + TempDevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle); + ASSERT (TempDevicePath != NULL); + DevicePath = AppendDevicePathNode ( + TempDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + ASSERT (DevicePath != NULL); + Status = EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + Description, + DevicePath, + NULL, + 0 + ); + FreePool (DevicePath); + return Status; +} + +STATIC +EFI_STATUS +GetPlatformBootOptionsAndKeys ( + OUT UINTN *BootCount, + OUT EFI_BOOT_MANAGER_LOAD_OPTION **BootOptions, + OUT EFI_INPUT_KEY **BootKeys + ) +{ + EFI_GUID *FileGuid; + CHAR16 *PathStr; + EFI_STATUS Status; + UINTN Size; + + Size = sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * HIKEY960_BOOT_OPTION_NUM; + *BootOptions = (EFI_BOOT_MANAGER_LOAD_OPTION *)AllocateZeroPool (Size); + if (*BootOptions == NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootOptions\n")); + return EFI_OUT_OF_RESOURCES; + } + Size = sizeof (EFI_INPUT_KEY) * HIKEY960_BOOT_OPTION_NUM; + *BootKeys = (EFI_INPUT_KEY *)AllocateZeroPool (Size); + if (*BootKeys == NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootKeys\n")); + Status = EFI_OUT_OF_RESOURCES; + goto Error; + } + + PathStr = (CHAR16 *)PcdGetPtr (PcdSdBootDevicePath); + ASSERT (PathStr != NULL); + Status = CreatePlatformBootOptionFromPath ( + PathStr, + L"Boot from SD", + &(*BootOptions)[0] + ); + ASSERT_EFI_ERROR (Status); + + PathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath); + ASSERT (PathStr != NULL); + Status = CreatePlatformBootOptionFromPath ( + PathStr, + L"Grub", + &(*BootOptions)[1] + ); + ASSERT_EFI_ERROR (Status); + + FileGuid = PcdGetPtr (PcdAndroidBootFile); + ASSERT (FileGuid != NULL); + Status = CreatePlatformBootOptionFromGuid ( + FileGuid, + L"Android Boot", + &(*BootOptions)[2] + ); + ASSERT_EFI_ERROR (Status); + + FileGuid = PcdGetPtr (PcdAndroidFastbootFile); + ASSERT (FileGuid != NULL); + Status = CreatePlatformBootOptionFromGuid ( + FileGuid, + L"Android Fastboot", + &(*BootOptions)[3] + ); + ASSERT_EFI_ERROR (Status); + (*BootKeys)[3].ScanCode = SCAN_NULL; + (*BootKeys)[3].UnicodeChar = 'f'; + + *BootCount = 4; + + return EFI_SUCCESS; +Error: + FreePool (*BootOptions); + return Status; +} + +PLATFORM_BOOT_MANAGER_PROTOCOL mPlatformBootManager = { + GetPlatformBootOptionsAndKeys +}; + EFI_STATUS EFIAPI VirtualKeyboardRegister ( @@ -487,5 +641,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 From patchwork Sat Apr 28 05:41:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 134646 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1517671lji; Fri, 27 Apr 2018 22:41:38 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqL2RUBgBe2D931wmlWwibaQt6T+BBXH7+MGkKgI4jnfDA4jhBCVdcRX2yk31hUtrMBEyRs X-Received: by 2002:a17:902:5ac1:: with SMTP id g1-v6mr4847506plm.43.1524894098684; Fri, 27 Apr 2018 22:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524894098; cv=none; d=google.com; s=arc-20160816; b=kHm//+HMoXoi+6KGu8YBO1JxFmTKHqnCDICerkfGXSud5UOoCOiTesKl+CUZFEhfY6 vRWXuUbR/eVTYn+3PJYaVCjUpN+FRaeE61zZL7dSZvce85e2MndR+0EkheTYdxIogH+u EOgfDtOGhCN/VGwOf997Znr+I8LLl8DSX4+7oBGRvo1KWMtDEsTbk+NBRp7J24RyNKz7 5q/QzfGcmoaE5Xz+9zb1KeERdL+T1VpT+Sg7pSQnlRMfPr1+7UI4EuuJfTYE5DakNwhB FE6Ybl//tAMeulZ9CpZxD9uP785kPlWqxY0dcP1yfQaDnPJuEiwx+d6Tl+5NfDklDy6M aUYw== 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=CUBGDzaYYALKKTIvopspnBFGPLXeH1fNdDUBnRPViUg=; b=FDBF2D3ID0EG2k3ApQ03342vVUXKpP6xjetHJ69hg4OKd9un9hx9l+isS9b2sy60fs 2u9ySC7NPCWoZuA0zlskmMuBV/BCW8iuT/Om/8b6YmoAHmp15IVpeTJ+IKRBEDuFRB90 fUSubmAGGqk+6IXk7xOTAgS6JRm5C+GpWmeXUy36eNJkrBQw71x62LWBWbG5OWvqn/pB j2C9nt3724QJroKKOW0FSRV1LyfwgknMmgemmD2SS5es5kXSTDmcMHmlEyzbc/TtPscb CZY+dpjhU9XzoBmjkoD4EXYmHjSfs0ganrfe4hnWoykMq+tawPblTwAlG7To+0ft8N0Z hMnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Xnc9lUMk; 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 y8si2834209pfd.47.2018.04.27.22.41.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Apr 2018 22:41:38 -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=Xnc9lUMk; 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 45E2D2034C8C7; Fri, 27 Apr 2018 22:41:38 -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::242; helo=mail-pf0-x242.google.com; envelope-from=haojian.zhuang@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (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 DB6CB207DF47F for ; Fri, 27 Apr 2018 22:41:36 -0700 (PDT) Received: by mail-pf0-x242.google.com with SMTP id z9so2969595pfe.6 for ; Fri, 27 Apr 2018 22:41:36 -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=Zll7B+VJPHo9Zcv7SM4y55xlSMxsdF0cOTf6gX3PU6M=; b=Xnc9lUMkQ4bikVy5GrDdBirTBbWS64CKMWNtJuQk+ec7tIPK7OpWVXu522SzWXdHxG H3cdN5bmVfjJNll2/mdFVQFPB22g51qUrRWL0tY/mRv4Ny4WcSa3stLLAZcn4y/fNQyS 0VgpvlD0uahddinic6+BKRCYoPcIZSRjsz0iM= 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=Zll7B+VJPHo9Zcv7SM4y55xlSMxsdF0cOTf6gX3PU6M=; b=o2ZoHJbfbTi2PcmWOEGd4x5cbxlK/eO7AF036qyyT/2aSQC5lR9tKhTrKNpz0xh87+ D25NDjGLnPglSUYLOLTOwcZ3LGDu4NLU/w6jxsUKwzi22bXziQaOcCUp5XdROgpmc5yU LGr3JEAJ5QmS1BHt3Dm4sVX5R6SNJlFN9iEcUcX8q8ZQmbc9Rnvod37lqrBTTWvFxq9d /IPMCFaoADm6C4mr9G5xx8uXHBKMxvQLgN7SiEx4r2+OfhNjRhwXqkud1u29k90wnJjE k293+P8IgC8lFPJ5xaxXnmbk32LNmeiyAJTdPxb6p27gVrGm/BQVdxpcv3TJOruIq0IA 2m8Q== X-Gm-Message-State: ALQs6tC4Y0zUVf/bEWjeqLaI73AMs6JSQB+td4jSIGBWMdomHMWxI5mn jinc712mNVm9kbPsWE9jTK/2olhnpNY= X-Received: by 2002:a17:902:bb06:: with SMTP id l6-v6mr4857235pls.255.1524894096210; Fri, 27 Apr 2018 22:41:36 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.141]) by smtp.gmail.com with ESMTPSA id b89sm5983111pfd.85.2018.04.27.22.41.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 22:41:35 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Sat, 28 Apr 2018 13:41:21 +0800 Message-Id: <1524894081-17567-3-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524894081-17567-1-git-send-email-haojian.zhuang@linaro.org> References: <1524894081-17567-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v7 2/2] Platform/HiKey: create 4 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 predefined boot options for HiKey. They're "Boot from SD", "Grub", "Android Boot" and "Android Fastboot". Cc: Laszlo Ersek Cc: Leif Lindholm Cc: Ard Biesheuvel Acked-by: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey/HiKey.dec | 8 +- Platform/Hisilicon/HiKey/HiKey.dsc | 7 ++ Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c | 163 +++++++++++++++++++++++++ Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf | 11 ++ 4 files changed, 186 insertions(+), 3 deletions(-) -- 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/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..9c1fc2e1b40d 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)/\\EFI\\BOOT\\GRUBAA64.EFI" + 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..b847ff8e2e87 100644 --- a/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c +++ b/Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.c @@ -18,12 +18,18 @@ #include #include #include +#include #include +#include #include #include #include +#include +#include #include +#include +#include #include #include @@ -42,6 +48,7 @@ #define ADB_REBOOT_BOOTLOADER 0x77665500 #define ADB_REBOOT_NONE 0x77665501 +#define HIKEY_BOOT_OPTION_NUM 4 typedef struct { UINT64 Magic; @@ -121,6 +128,152 @@ HiKeyInitPeripherals ( return EFI_SUCCESS; } +STATIC +EFI_STATUS +CreatePlatformBootOptionFromPath ( + IN CHAR16 *PathStr, + IN CHAR16 *Description, + IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH *DevicePath; + + DevicePath = (EFI_DEVICE_PATH *)ConvertTextToDevicePath (PathStr); + ASSERT (DevicePath != NULL); + Status = EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + Description, + DevicePath, + NULL, + 0 + ); + FreePool (DevicePath); + return Status; +} + +STATIC +EFI_STATUS +CreatePlatformBootOptionFromGuid ( + IN EFI_GUID *FileGuid, + IN CHAR16 *Description, + IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *BootOption + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH *DevicePath; + EFI_DEVICE_PATH *TempDevicePath; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + + Status = gBS->HandleProtocol ( + gImageHandle, + &gEfiLoadedImageProtocolGuid, + (VOID **) &LoadedImage + ); + ASSERT_EFI_ERROR (Status); + EfiInitializeFwVolDevicepathNode (&FileNode, FileGuid); + TempDevicePath = DevicePathFromHandle (LoadedImage->DeviceHandle); + ASSERT (TempDevicePath != NULL); + DevicePath = AppendDevicePathNode ( + TempDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &FileNode + ); + ASSERT (DevicePath != NULL); + Status = EfiBootManagerInitializeLoadOption ( + BootOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + LOAD_OPTION_ACTIVE, + Description, + DevicePath, + NULL, + 0 + ); + FreePool (DevicePath); + return Status; +} + +STATIC +EFI_STATUS +GetPlatformBootOptionsAndKeys ( + OUT UINTN *BootCount, + OUT EFI_BOOT_MANAGER_LOAD_OPTION **BootOptions, + OUT EFI_INPUT_KEY **BootKeys + ) +{ + EFI_GUID *FileGuid; + CHAR16 *PathStr; + EFI_STATUS Status; + UINTN Size; + + Size = sizeof (EFI_BOOT_MANAGER_LOAD_OPTION) * HIKEY_BOOT_OPTION_NUM; + *BootOptions = (EFI_BOOT_MANAGER_LOAD_OPTION *)AllocateZeroPool (Size); + if (*BootOptions == NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootOptions\n")); + return EFI_OUT_OF_RESOURCES; + } + Size = sizeof (EFI_INPUT_KEY) * HIKEY_BOOT_OPTION_NUM; + *BootKeys = (EFI_INPUT_KEY *)AllocateZeroPool (Size); + if (*BootKeys == NULL) { + DEBUG ((DEBUG_ERROR, "Failed to allocate memory for BootKeys\n")); + Status = EFI_OUT_OF_RESOURCES; + goto Error; + } + + PathStr = (CHAR16 *)PcdGetPtr (PcdSdBootDevicePath); + ASSERT (PathStr != NULL); + Status = CreatePlatformBootOptionFromPath ( + PathStr, + L"Boot from SD", + &(*BootOptions)[0] + ); + ASSERT_EFI_ERROR (Status); + + PathStr = (CHAR16 *)PcdGetPtr (PcdAndroidBootDevicePath); + ASSERT (PathStr != NULL); + Status = CreatePlatformBootOptionFromPath ( + PathStr, + L"Grub", + &(*BootOptions)[1] + ); + ASSERT_EFI_ERROR (Status); + + FileGuid = PcdGetPtr (PcdAndroidBootFile); + ASSERT (FileGuid != NULL); + Status = CreatePlatformBootOptionFromGuid ( + FileGuid, + L"Android Boot", + &(*BootOptions)[2] + ); + ASSERT_EFI_ERROR (Status); + + FileGuid = PcdGetPtr (PcdAndroidFastbootFile); + ASSERT (FileGuid != NULL); + Status = CreatePlatformBootOptionFromGuid ( + FileGuid, + L"Android Fastboot", + &(*BootOptions)[3] + ); + ASSERT_EFI_ERROR (Status); + (*BootKeys)[3].ScanCode = SCAN_NULL; + (*BootKeys)[3].UnicodeChar = 'f'; + + *BootCount = 4; + + return EFI_SUCCESS; +Error: + FreePool (*BootOptions); + return Status; +} + +PLATFORM_BOOT_MANAGER_PROTOCOL mPlatformBootManager = { + GetPlatformBootOptionsAndKeys +}; + EFI_STATUS EFIAPI VirtualKeyboardRegister ( @@ -225,5 +378,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