From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.93]) by mx.groups.io with SMTP id smtpd.web12.4055.1607505894275926472 for ; Wed, 09 Dec 2020 01:24:54 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=cjgz4gPg; spf=pass (domain: os.amperecomputing.com, ip: 40.107.220.93, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L6sQ8BLozzUh/3oauyOH3n8mjgYlK3Zkp9ayGUStrvks5+aMI4srtdSjc87u0x4nmGGt4uvVsiBlDQtjmYhnbMqtA/Av56+UEz7n8eonjSiAOVSEvmelPCCyrLqv1evQZ/sVghP9iAC1Fb1zcJi3Io1kzHG2fLZuNFx32m0Tu5GFa+v7r6RkvMVhE5wSvypdFm65tARnw4Qqv8Uz6+gwK3cC6IqyjRQv6ro7MdmYmCHbY6KvbjOJhBlnEExf/1TxjCkafQy5FeUKFAgxTbz5WsfEERLPSSwkwslPk9sVjF4vqSeKem0QyfyOHWjtnmtfuKlUEo86omb0dhgRujGXcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0sHS9STAv7cHGm9617rSzPTD/if/vyEXEZa1uETjdGU=; b=bq7VP8URC0hccgzoN9im50LTffMLxvXXlhi5tC+LqcHH0XFiSNuC+GJTgDLHlgO71sz6B1WivBlMN+aasus8FEoZcsdxcPm2vlZ9E1vRX5zAv4HpF/7theTVjiOI9Sd9P/xaKm7zcLLU0XRGnbyYKG28D3cWJ9tjd4eCGCGFt497v6XOAXEIp/+fZjv90bNxIiUoMmweaI8yq2vtHcMon0bC04re0bKoO3+VAELgYp/iJ0TvDgfi7ru2/PbT0f7wJUUJJIhQZdq6wnYtKjx1uB+TzMeekq3lYBV2sDPHxLo1kk/981PSPaRLHMZit7Au11Krrb3lGyL9mjiDWI3OLA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0sHS9STAv7cHGm9617rSzPTD/if/vyEXEZa1uETjdGU=; b=cjgz4gPgtw9y3aYh97gY06QqzbaJc6inmV5cPvH0Yy+mrnnGm5ujaFQCJgdTABEo/jkVSWxxRTf4X4TVXWmG7VmVjhdTDzQ3fjLuspVwzKv6zgwSC7ahOeTgFqtP94lBLsdI9Mi1C5tkskXOK/aNJEUQv90MrPt4OsxxZiQpvTQ= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM6PR01MB5609.prod.exchangelabs.com (2603:10b6:5:157::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.21; Wed, 9 Dec 2020 09:24:53 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::c814:9a08:5c2e:4076%5]) with mapi id 15.20.3632.023; Wed, 9 Dec 2020 09:24:53 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: Nhi Pham Subject: [edk2-platforms][PATCH 28/34] Silicon/Ampere: Implement PlatformBootManagerLib for LinuxBoot Date: Wed, 9 Dec 2020 16:25:25 +0700 Message-Id: <20201209092531.30867-29-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201209092531.30867-1-nhi@os.amperecomputing.com> References: <20201209092531.30867-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sw004.amperecomputing.com (118.69.219.201) by HK0PR01CA0054.apcprd01.prod.exchangelabs.com (2603:1096:203:a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3654.12 via Frontend Transport; Wed, 9 Dec 2020 09:24:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 49bf8e08-48aa-44b8-813b-08d89c244923 X-MS-TrafficTypeDiagnostic: DM6PR01MB5609: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pjzbKAopw/KftJwYGp9U22Hk4WrXjZZp65XKxdemDHGRjRJC5tWUG69knaXa0lMLznpj70fWg5Z2GmdtIqocz3mDrLyxysbmqeJE1ISfUqWjojUV4BKT0X0f3QLUkIOUFxhH1Yx9H5ppZcXiyFf+y+F/So6pQPO6c24psS90uPtuFAWzMYoLQ9FQbgChko62OM4vMf2KeSq8WNrOh3kSANkjcXtiavKLoLDlUEHDA0SIJ9j2lu3kHnKbxh8qqx2M4EuH4fdLTD1XFmrbdJoQlUP5m3NXIYAqAXONGfITeOeAJsSdeehZMbICL0OS+/foJe20mLmLg+t9KTG7Fv+JwxPky70tC5W5MgVGOBO807KlAXWFbKZMSgZtJI0i5EIy X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(136003)(346002)(366004)(5660300002)(956004)(508600001)(52116002)(66946007)(6916009)(2616005)(1076003)(86362001)(6512007)(66476007)(26005)(8936002)(16526019)(107886003)(6666004)(186003)(6486002)(8676002)(6506007)(83380400001)(2906002)(34490700003)(66556008)(4326008);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?shP225mbqwbY1iFAQ7uY8MGxmVljzII83pbZ+pIeIFk8aEKEE/Cis4uWzpIe?= =?us-ascii?Q?ve5jCyTEBxTLMfJ5q5JSXP/Zu7iWMh+4HnNDmC711eJdP6jlQ47aa2rY7unI?= =?us-ascii?Q?lwrzDoxrqIo19fL1hjwonk5gWe1cIlh4JkweHS1QNqgu5bmZh/WrRncdCisR?= =?us-ascii?Q?wvEAxtilD7cLMzBwOKJMiTMd+iZMu822wSCuX1uCWVzl0r5tvMd+BHfkUlwg?= =?us-ascii?Q?Gne/P3BsMb9+HcRX4ZzSj0zHY/nWw5q+ZUAlRcoDdoy304u4OXv9/f9XbDwe?= =?us-ascii?Q?4I8yrgGplFv74ShAGEdeuFwnEMz0AhNe5rZwaPpJEPLBgKkl50BISVqVzp5f?= =?us-ascii?Q?pYwLT3l3fwQjGRAx5IJmntt4SxjUTN23HesCMabkvTJX2vP3G3RLEp+hbpmT?= =?us-ascii?Q?/Zr20mjDvyZYqTRak79mNyusn8OY95PTDfu8aTXI5nRg2D+MaoJ/k67GMAyo?= =?us-ascii?Q?LevQf0MCMynGPnziCVMeYGQ3a9IHbS3Fenrtc9bylD9KzyijjoQAE5ebDQCz?= =?us-ascii?Q?1Kg46hYfzMmZQsRaudBiQ69J+s1MDFshv3CSF14VwVcKrROhU96b9q03CbxC?= =?us-ascii?Q?RP6aV7381UP1Ure/JpfpaBMr7rydYZ8iXSiRfH5bjPcOaxHZI0uXlgbfl1O3?= =?us-ascii?Q?B0izguk3sAUWC83oGVPAvE9/wSlGA4UQpKmhNDsmJkdFPTuvqsCWtycW73Yi?= =?us-ascii?Q?s9rmlL3JuLk8mzr6v8n3b6YSc1NORuQzcUp88Zgx/ajKQPbjvJOKtjdHS8Wi?= =?us-ascii?Q?nkH1J8sMCN+695eIp2Xfx2UBDOcR1N6DwOLa2jjGmTTqhnkwOfEGRvwz7lXU?= =?us-ascii?Q?Oft3v2jMheV+WILbWW71CioFy4Ic92bdTWd8oasa1HwvcmIMJJnGWCgwha2K?= =?us-ascii?Q?xYnZhbAqEOLCErVBD7PP99w23DKRwcy6E4DV4f2IJLvN6j2OkMG90MSXcfTt?= =?us-ascii?Q?f4qaDG97mtjKzmSyguXzqaI53+LZpGDv/0/n6WpPaCR/DMmXgEQdhg4YhdVf?= =?us-ascii?Q?oHLT?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Dec 2020 09:24:53.1964 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-Network-Message-Id: 49bf8e08-48aa-44b8-813b-08d89c244923 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: QP7XlxLmdmcc784pWzAZy0cdXS2x3mvYFDI2uaSvT/Lpx2q/pwLLkh/OB2DswdTN30aZdp6Kv1q1kcPl+AOqQsauByRNphhmjlJJQ7WYcL4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB5609 Content-Type: text/plain This PlatformBootManagerLib is based on the ArmPkg version. It is modified to support to boot LinuxBoot Shell immediately from an active boot option, without entering UiApp Setup Screen. Signed-off-by: Nhi Pham --- Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf | 54 +++++++ Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBm.c | 163 ++++++++++++++++++++ 2 files changed, 217 insertions(+) diff --git a/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf b/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf new file mode 100644 index 000000000000..1285e2ae3e06 --- /dev/null +++ b/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf @@ -0,0 +1,54 @@ +## @file +# Implementation for PlatformBootManagerLib library class interfaces. +# +# Copyright (C) 2015-2016, Red Hat, Inc. +# Copyright (c) 2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2016, Linaro Ltd. All rights reserved.
+# Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LinuxBootBootManagerLib + FILE_GUID = 1FA91547-DB23-4F6A-8AF8-3B9782A7F917 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = PlatformBootManagerLib|DXE_DRIVER + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = ARM AARCH64 +# + +[Sources] + LinuxBootBm.c + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + ShellPkg/ShellPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + UefiLib + PrintLib + DebugLib + MemoryAllocationLib + UefiBootManagerLib + UefiBootServicesTableLib + UefiRuntimeServicesTableLib + +[Pcd] + +[Guids] + gEfiEndOfDxeEventGroupGuid + gUefiShellFileGuid + +[Protocols] + gEfiLoadedImageProtocolGuid diff --git a/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBm.c b/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBm.c new file mode 100644 index 000000000000..65bd24de58a1 --- /dev/null +++ b/Silicon/Ampere/Library/LinuxBootBootManagerLib/LinuxBootBm.c @@ -0,0 +1,163 @@ +/** @file + Implementation for PlatformBootManagerLib library class interfaces. + + Copyright (C) 2015-2016, Red Hat, Inc. + Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.
+ Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
+ Copyright (c) 2016, Linaro Ltd. All rights reserved.
+ Copyright (c) 2020, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +STATIC +VOID +RegisterFvBootOption ( + CONST EFI_GUID *FileGuid, + CHAR16 *Description, + UINT32 Attributes + ) +{ + EFI_STATUS Status; + INTN OptionIndex; + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; + EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions; + UINTN BootOptionCount; + MEDIA_FW_VOL_FILEPATH_DEVICE_PATH FileNode; + EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + + 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 ( + &NewOption, + LoadOptionNumberUnassigned, + LoadOptionTypeBoot, + Attributes, + Description, + DevicePath, + NULL, + 0 + ); + ASSERT_EFI_ERROR (Status); + FreePool (DevicePath); + + BootOptions = EfiBootManagerGetLoadOptions ( + &BootOptionCount, LoadOptionTypeBoot + ); + + OptionIndex = EfiBootManagerFindLoadOption ( + &NewOption, BootOptions, BootOptionCount + ); + + if (OptionIndex == -1) { + Status = EfiBootManagerAddLoadOptionVariable (&NewOption, MAX_UINTN); + ASSERT_EFI_ERROR (Status); + } + EfiBootManagerFreeLoadOption (&NewOption); + EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); +} + +/** + Do the platform specific action before the console is connected. + + Such as: + Update console variable; + Register new Driver#### or Boot####; + Signal ReadyToLock event. +**/ +VOID +EFIAPI +PlatformBootManagerBeforeConsole ( + VOID + ) +{ + // + // Signal EndOfDxe PI Event + // + EfiEventGroupSignal (&gEfiEndOfDxeEventGroupGuid); +} + +/** + Do the platform specific action after the console is connected. + + Such as: + Dynamically switch output mode; + Signal console ready platform customized event; + Run diagnostics like memory testing; + Connect certain devices; + Dispatch additional option roms. +**/ +VOID +EFIAPI +PlatformBootManagerAfterConsole ( + VOID + ) +{ + // + // Register UEFI Shell + // + RegisterFvBootOption ( + &gUefiShellFileGuid, L"UEFI Shell", LOAD_OPTION_ACTIVE + ); +} + +/** + This function is called each second during the boot manager waits the + timeout. + + @param TimeoutRemain The remaining timeout. +**/ +VOID +EFIAPI +PlatformBootManagerWaitCallback ( + UINT16 TimeoutRemain + ) +{ + return; +} + +/** + The function is called when no boot option could be launched, + including platform recovery options and options pointing to applications + built into firmware volumes. + + If this function returns, BDS attempts to enter an infinite loop. +**/ +VOID +EFIAPI +PlatformBootManagerUnableToBoot ( + VOID + ) +{ + return; +} -- 2.17.1