From patchwork Wed Apr 25 04:59:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 134216 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp400940lji; Tue, 24 Apr 2018 21:59:53 -0700 (PDT) X-Google-Smtp-Source: AIpwx489x64T2ZK6lsxuykjZ52DLtjyqx17IMvsMxUpDo4yuUqJ/v4RA8w2TdLfD87KUQvreVwWP X-Received: by 10.98.141.65 with SMTP id z62mr26670032pfd.144.1524632393190; Tue, 24 Apr 2018 21:59:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524632393; cv=none; d=google.com; s=arc-20160816; b=eRXpqva1Lu9T108ZE3ow7+lsCtP5vKnhCdrck/NtUsSEDUicg2oOgnBtTeFzaU/Wq9 5R+fiBnZAv/7ZeCaErbYGVGTLcf9GHb+F8O9SdWhDgL0XBod//1gDusm/WoMqxnTzzjK 3HHAu1raYddgGbOil1o/6gA8G6c6n6eM8prs1DWSg9kuX2JqiNac93ZOKll5/Co5Bo3S TGtChF0H1rpJKCUyN5/+CjUdqsGNxNX6V1b1/jfvaTP0iACBotSTi80jI6jAaJIuN255 ivQclx24C+dV3sYdNuZ7nJs7gwCpP2ZY8x07RXlmQVl+1RnCA0QLiN/4jWNerhFpchsQ yIUw== 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=b0p6qKYCGqZjk77y+1KJvX1AOdaYo2ZeRzv1Uo4U2CI=; b=f4dnJ1JRxekhxG20UpjKEYBiQ7ZAmco7AD8xzpJQDJDo5CClv31Q5LBvMZDzDkOE1s ExjbSoS3m/KSJvx/0rYQcS49blYngM6rPgHkeqZNWQ4grllbwmQd0LzisecD0RNQ/5pX lGMbJonmJtG7UKvcTNaSIT84x9TlRqqQZt+6o82i8T4qqwgpGAfr629UrvRtUAKz17sC KWlLH9dSJaWNhs5y2M/eMtsdnq08Z8UBTF74cCOXet5Ti0Xj7lDKfn+0QW3jxcIoKU0a NbNEfhf3O7C0Y9PvUCIqhynLGSH7vxlDZlbGL3raACbgvCuBYIygXpLPztSZbEkHZumx Hmrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=IHeiJ4Tq; 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 f14si13334063pgr.486.2018.04.24.21.59.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 Apr 2018 21:59:53 -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=IHeiJ4Tq; 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 C6B742277AF0D; Tue, 24 Apr 2018 21:59:52 -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 99C9B220E8E16 for ; Tue, 24 Apr 2018 21:59:51 -0700 (PDT) Received: by mail-pf0-x242.google.com with SMTP id a14so3647645pfi.1 for ; Tue, 24 Apr 2018 21:59:51 -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=kdm/N3Pm04hD9KAFFE4fxZUJ31eeBD5cnLVb0RFts6g=; b=IHeiJ4TqenBEDkK8ClTyMhfjL1AlP68Ibm50KY2jxdfICJdFhKncoDxBwMksv5HL3P S5xN+FsAFge1dt9HcJ1IT/AsUNDVTFrmpUqUyWDjGOnkRubbcmDG4lnY6scjjTLrdL3w f08f359NExLdfI6jhm796RFt5RK/kjk18mEEU= 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=kdm/N3Pm04hD9KAFFE4fxZUJ31eeBD5cnLVb0RFts6g=; b=SGFRLGxd45oDTJ8tAnx0updZ/xeFcRJ2UJHGGGGkq1JjV5sfJ4oeWaDlUjMAXLJyxE mjT4+ET/sX/QHlXvC7CPwttl/mdUhltRg8Nic6og3B53plOP/JF/bdksWMOD9apZw7md a5lIyFLTI6X1qOKfP+L0nHeDG0g44LAEkJus1B76BFS91p4zRfJMZ8zD75uXl9aScA1l EYQ7MDJSs/QgUpArVBbUlT3rRV2Y99a+vHtSbnSKhmxIyRZea6Jb+GFSCtzwWcRLveoJ 9FFgJc7cNrGVv1Yf53zzeg0qkhGDQguca+tBv5OmDbBjvGULhExqjdhjsjkG0rriVk9H PKxQ== X-Gm-Message-State: ALQs6tC3KEflIMDvIPdVJAWr030WU6RCU39KxTPV9f/hdQvgADEbUWDV ZYpz+V/XVQqbPa3ZbmKcMWReUzQqFzk= X-Received: by 10.101.82.133 with SMTP id y5mr22313959pgp.27.1524632390897; Tue, 24 Apr 2018 21:59:50 -0700 (PDT) Received: from localhost.localdomain ([64.64.108.65]) by smtp.gmail.com with ESMTPSA id 142sm18061455pgg.86.2018.04.24.21.59.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Apr 2018 21:59:50 -0700 (PDT) From: Haojian Zhuang To: edk2-devel@lists.01.org Date: Wed, 25 Apr 2018 12:59:36 +0800 Message-Id: <1524632376-23501-3-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524632376-23501-1-git-send-email-haojian.zhuang@linaro.org> References: <1524632376-23501-1-git-send-email-haojian.zhuang@linaro.org> Subject: [edk2] [PATCH edk2-platforms v5 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 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 | 171 +++++++++++++++++++++++++ Platform/Hisilicon/HiKey/HiKeyDxe/HiKeyDxe.inf | 11 ++ 4 files changed, 194 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..e20538bd77bf 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,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,158 @@ 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 + ); + if (EFI_ERROR (Status)) { + return Status; + } + 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 + ); + if (EFI_ERROR (Status)) { + return Status; + } + 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 +386,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