From patchwork Tue Apr 17 05:14:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 133507 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp4323047ljb; Mon, 16 Apr 2018 22:14:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+/gyH5EYnfx6h/QyOATwoenSmkQX4XT8e+OC5Hsvxo9++552uwg9Ud/Ckz8nU/jGl5G801 X-Received: by 10.101.96.47 with SMTP id p15mr601112pgu.430.1523942069693; Mon, 16 Apr 2018 22:14:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523942069; cv=none; d=google.com; s=arc-20160816; b=iXfxIeiBi8MMmn6atOqtCkpCwSDCU4ok70Uf9f1cWKlv2r71bR+3q+X1L4R3Tnkd5r z37na7bJhb01DdGqZxytn1ySnVCV1WQkhDyOJVVKEus8EcHxi32ptMH37Eo0B4Gkf6oz H7QhPQoMLRES/qJxJwRroz9BB/VkKzjwDuUJ4eMA/pzAZY8Q1ZT9fxSqhMTZZicBNPsf NCLgCEtyr2rtXEAi05dY7s/4MJK5APuD/Phmy9U8fV1f6C8DcDXkZjMx4Shnd3iFzHuR QATgrkQO1AubDf0WdRn4w7K3fdPmob5+8XoFVGRgPJ+CrARHhwyL6lxNOSF6Nr2N8/u+ 1q+A== 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:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=J6OZKtoYZGjP5w87sWZaJ9agIKqASwHgbklnIw+iimU=; b=iNfzJhuxhfZ/+snX/ZODfnde4rrN+JEyl5sjkvUmoNfIEYdv+eCm+gwl77YmUL9m61 W1miOtd2hCLskZePJ0ofxObNLQrEt06N7CutaJPRlXOT0OBERUHfizGrCOXjAs0sOVw3 wywtN2pN4zIaylT+p5pLGUbADqf2QRcAfEd7Sshik6ua1t3lYH/JQVmcvZ65iW0CDjYQ 1A+MM6GzRJiKXIVBSasYKy0U4MkD+K3n6NOaFUoW1wHUYPtDX7SUW+lRE1YYku54Emis dmlhsfnYNCUfC2gei1Io9bD4vbmtJjVqsKr/+bTokyc11+Ss4LKBb+Pz42NfNe12QWfH gfAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=a3Eyr446; 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 c23-v6si13634625plk.245.2018.04.16.22.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Apr 2018 22:14:29 -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=a3Eyr446; 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 211F2220E8CBD; Mon, 16 Apr 2018 22:14:29 -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 A9DA322590E17 for ; Mon, 16 Apr 2018 22:14:27 -0700 (PDT) Received: by mail-pf0-x242.google.com with SMTP id g14so11623330pfh.3 for ; Mon, 16 Apr 2018 22:14:27 -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; bh=n5IJF6C9rAxmr0PhlU0JBzmARrx1LDJsUm68NRsrXrM=; b=a3Eyr4464mVQBpO3TwHe9K7k7NY40Rj8XhgmZ9iBjbn1CpOpT65ojcG3i/h2oZKA6e kMWdrzvfb0CP/a4CGzzbzlCnyXnBxgjSQ12Zh7B6FWkQZW+9QSTipDyXeChkHS4o0WWi fyUOrGzTwGi3fgn1BhFCSHezizgydgBbzzZpk= 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; bh=n5IJF6C9rAxmr0PhlU0JBzmARrx1LDJsUm68NRsrXrM=; b=nr54IUBh6xTmSXc5ePwhsovxtgSA3sorWW5cY8OsIwMGQYnAh/TUErug1xjAX4j2Av hBQbutvUHb5U+enSPSJMAtGtRZCCVBkvt/CfrWt/hCQmwv0APD/SxJAQhxN1ojUMLIW2 sAPLTUnmOdZIitTqKZgXf/l5XVD+n8tGnFAs8m7ClZciGTqnofi3JuSddiU/TOR3qhwg ch344CRNc5LBVnLSwRTu+zXEg2DVfp40colxXdwcbWU4S0kCFeSo9DmUyG1xzovI6itK jtqi1ToBojEux4cmlr4K2f9KsxQ93VnWK5suPxZDOCLTA9KiEn/mZMoc9JYgnCRlrz8p oTFQ== X-Gm-Message-State: ALQs6tAoqoBDhKV7hpXtPHhLpY7hqkejDH9RrKMBo5l7QhXMAtBoLdWg XIEIXnIro5tDPTTSFlJQz3edrlTymqY= X-Received: by 10.99.120.202 with SMTP id t193mr432959pgc.255.1523942067022; Mon, 16 Apr 2018 22:14:27 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.57]) by smtp.gmail.com with ESMTPSA id e73sm39122794pfj.186.2018.04.16.22.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Apr 2018 22:14:26 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Tue, 17 Apr 2018 13:14:18 +0800 Message-Id: <1523942058-16301-1-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [edk2] [edk2-platforms PATCH v2 1/1] 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". Contributed-under: TianoCore Contribution Agreement 1.1 Cc: Leif Lindholm Cc: Ard Biesheuvel Cc: Laszlo Ersek Signed-off-by: Haojian Zhuang --- Platform/Hisilicon/HiKey960/HiKey960.dsc | 6 + .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.c | 145 +++++++++++++++++++++ .../Hisilicon/HiKey960/HiKey960Dxe/HiKey960Dxe.inf | 11 ++ 3 files changed, 162 insertions(+) -- 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.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..84bd76b5cae9 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,131 @@ OnEndOfDxe ( } } +STATIC +EFI_STATUS +RegisterPlatformBootOptions ( + OUT EFI_BOOT_MANAGER_LOAD_OPTION **BootOptions, + OUT EFI_INPUT_KEY **BootKeys + ) +{ + EFI_BOOT_MANAGER_LOAD_OPTION *Option; + EFI_INPUT_KEY *Key; + 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; + } + Option = *BootOptions; + Key = *BootKeys; + + Option[0].Description = L"Boot from SD"; + 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); + Option[0].FilePath = DevicePath; + + Option[1].Description = L"Grub"; + 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); + } + Option[1].FilePath = DevicePath; + + Option[2].Description = L"Android Boot"; + 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); + Option[2].FilePath = DevicePath; + + Option[3].Description = L"Android Fastboot"; + 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); + Option[3].FilePath = DevicePath; + Key[3].ScanCode = SCAN_NULL; + Key[3].UnicodeChar = 'f'; + + return EFI_SUCCESS; +} + +PLATFORM_BOOT_MANAGER_PROTOCOL mPlatformBootManager = { + RegisterPlatformBootOptions +}; + EFI_STATUS EFIAPI VirtualKeyboardRegister ( @@ -487,5 +622,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