From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.120]) by mx.groups.io with SMTP id smtpd.web08.6384.1630685272630104908 for ; Fri, 03 Sep 2021 09:07:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@os.amperecomputing.com header.s=selector2 header.b=WkTnnRT5; spf=pass (domain: os.amperecomputing.com, ip: 40.107.243.120, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=POmi7lu5wQNZUbSDcfHARsC6Pqnnj5a7uVAjul8C3dIzkGoX4t43vrtsFr2q4Nu9+ppyzttZqzc+8FDUPe7kKrbljs+TZ6YjKvNXqzjXETyrQBdNFqZe6WMumB6ZAhwrH1cxPXuKLJ8HRcypZ5RBYSaSbm6fZedANBoTc6DrRAiNw7PzDgBB5HUzxEVjcDvFnnW7LQoROOdk3kxGaNcVoMd0gonWG8qjhnzXdT3aFq96763SMEovLSryzop+rC1BqI/BuZm8uQs9zYFIg8oBKHd56/494TJwuP0OLgNxggsLM/tl3EH4fqSv/T9L+VPQJe60nA7omLOa5f3C06eaBg== 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=toYpqfHbuakkNlmLwDLlLtKyIcdEParvDcvHBQG5Nv4=; b=lbqWcL4EMDjd1bk81vANdsRZeft9JrfPHqaQDDbWh4r/jIv+NQkaQ1qMAZmroFeay3/yqTLKCg6yM7WF1ymvw8lcX/DthqvbppLGTFHTPblL4UDFRSffal2DyyKiguTjdPNdg/j3xFzAqJD8fVNvmBKBRXlDoAJEf92kBgaGgN2DpigqVaDjnYS0Aq1CxNI8wdyNjiuDnU4BdGfH1qqYeaH+rqNk0B3V4Q6sruQAXRfgznmKRvG7TDjMgZINUgj+6i3vtL+WYN+2kamw+ZrlEsbznBqmHehVPD05P4pFbo7wNnY613oKTFCERfPBG93wrMzWKdBwlioRHv12t/YkgA== 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=toYpqfHbuakkNlmLwDLlLtKyIcdEParvDcvHBQG5Nv4=; b=WkTnnRT5/i2UnEOR7QN1ew82xPkxZHUmrSUpD9keQTkG1BBBLN3PqI0KwtjqSoesCqpG/jLYNcRmt7W7SRm1JpvgDwOAbXl9ibW0PTsXk8jO/pKtOhP49A5pJW5dacdfY3XnevLKMKCsdF//OwmJ1qTRqzIHlaBfhmR5xlLNfeQ= 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 DM6PR01MB4729.prod.exchangelabs.com (2603:10b6:5:6c::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.23; Fri, 3 Sep 2021 16:07:50 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::8eb:704f:2ba7:9bc3%4]) with mapi id 15.20.4478.022; Fri, 3 Sep 2021 16:07:50 +0000 From: "Nhi Pham" To: devel@edk2.groups.io Cc: patches@amperecomputing.com, Nhi Pham , Leif Lindholm , Ard Biesheuvel Subject: [PATCH 1/1] ArmPkg: Implement PlatformBootManagerLib for LinuxBoot Date: Fri, 3 Sep 2021 23:05:29 +0700 Message-Id: <20210903160529.4531-1-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 X-ClientProxiedBy: HKAPR04CA0017.apcprd04.prod.outlook.com (2603:1096:203:d0::27) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from localhost.localdomain (118.69.219.201) by HKAPR04CA0017.apcprd04.prod.outlook.com (2603:1096:203:d0::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Fri, 3 Sep 2021 16:07:48 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d455cceb-7b7f-487c-6fc2-08d96ef4fa40 X-MS-TrafficTypeDiagnostic: DM6PR01MB4729: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2SMKq5N/sdo+roC5L/7BKwd/pgm1EonuyPB3JoAfebZYjzI5sluYdG89MzvRbCbm7aoBRlpLZ4ztZv6VU+7cjeZwS2ajIbkMZThDwYbyAwnJh7gqVt5WfRhgSgTEg9Wuns/gU3jzhIm1QgyNWUb68IYSoo17a0/2fmeextquI+djkwFP9elSgItRt7QhsgD5Away9/BW+XgUcrsywT7COcvXQpFrkQODed2fHCJnfHfleKLftI+FrrNMSKGThHqPW2GgVXDocIoJjk0YoT4dFsyMABzRXnfoOXj591tmBD1wqkFNyATF4MATR4CIeRxyDtH8kp41OFKw2c9AJcfMvf24pyYeCWKqTcjAmp27dFXntM04UtKWuQqaJBgaU5jSJonBExkwm/yc3A2Bb/HFBTHu8BDHNKzi4hcOPursNrnWyaA3pRtE7P1cfVsqW0njZPKL1RbtQbJzV3fcmq8lZIXV/Ksny5+SwSuF8VM4NBFP4ilCIkkYbxkKxGuhrHOLqLdbbuGtlXVpxeaskmOrOhZV+EwU78+pJUpIiHE4iONtepvTGW8vEpjOR+xL2w0ynscaxhyZOrUnZEtf9ddYoX0WS0sfB2ZeDAXwTaa7geQKvQHcRSlJYM0lug8DyiphDKd/pn7k2+/jp46WIzsAC0UHRf6nqETehahaHrNzb6q/THzdHjPEDw5olofyaTNz2Uf+J+w/dkmnoqoKG5Q6Tw== 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)(396003)(136003)(376002)(366004)(39850400004)(346002)(6916009)(83380400001)(4326008)(66476007)(186003)(66556008)(52116002)(6486002)(6512007)(38350700002)(38100700002)(54906003)(956004)(6666004)(45080400002)(2616005)(316002)(66946007)(86362001)(5660300002)(478600001)(26005)(8936002)(1076003)(8676002)(6506007)(2906002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?w8Q/5AhnbYg64hvNN5j+2WR6wLGeVOwnmlpfbQmerxK9jWl9meJy/1IyYJmC?= =?us-ascii?Q?WkU1aMWU8SnSFzaN7QEqZYBRMA2CnONXV8wQlJtSnzoGaI0bkPRgdYyHtY5w?= =?us-ascii?Q?KtvtwJSht/ZxVx9XNwmkmjPqNOA1m/O/41AadyXiqiQsk8C6Z33aKfzabG5X?= =?us-ascii?Q?AxeDD4ip4TNvsZtccHjsgocRYo9obIM6rUDBUlFHG5vMA7Eefjbav/nv/KCa?= =?us-ascii?Q?bb1Jd8sNMBbyaFlRecr9iIhz3fHj7Ly99IS4OWBOz7EBCSO4kaSW4DplnIED?= =?us-ascii?Q?ZbiBsvJCyAPlFm/KmO8zyezLq7z+cMTFCuBrw7cBuTeK7yiKljXysJBr66e+?= =?us-ascii?Q?Eb0mOuzjnymJdZakLYeZh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q?QMffuML5hF0QTBUEVsDus9f8gjdUlzFjBrBfPbRQ10TEgrKFSbekZxJd0kD3?= =?us-ascii?Q?8xOozboxUJnspJhBAf5itqN8?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: d455cceb-7b7f-487c-6fc2-08d96ef4fa40 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2021 16:07:50.3076 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PicVYuL+76FIY4484kJuRHLGe+mclvU6Z75H6ELdViEM3KqjKT0f7DKkdBKnSq6mp50ru9XOLHTXM4cj+KlsXwpzwS+Ll16mQy59k2iIMqM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR01MB4729 Content-Type: text/plain LinuxBoot is a firmware that replaces specific firmware functionality like the UEFI DXE phase with a Linux kernel and runtime. It is built-in UEFI image like an application as it will be executed at the end of DXE phase. This PlatformBootManagerLib instance registers only a GUID defined by gArmTokenSpaceGuid.PcdLinuxBootFileGuid for LinuxBoot Payload as active boot option. It allows BDS to jump to the LinuxBoot Shell immediately with skipping the UiApp Setup Screen or UEFI Shell. The PlatformBootManagerLib library derived from ArmPkg/Library/PlatformBootManagerLib. Cc: Leif Lindholm Cc: Ard Biesheuvel Signed-off-by: Nhi Pham --- ArmPkg/ArmPkg.dec | 8 + ArmPkg/ArmPkg.dsc | 2 + ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf | 58 +++++++ ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c | 178 ++++++++++++++++++++ 4 files changed, 246 insertions(+) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 214b2f589217..f68e6ee00860 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -3,6 +3,7 @@ # # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.
# Copyright (c) 2011 - 2021, ARM Limited. All rights reserved. +# Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -382,3 +383,10 @@ [PcdsFixedAtBuild.common, PcdsDynamic.common] # gArmTokenSpaceGuid.PcdPciBusMin|0x0|UINT32|0x00000059 gArmTokenSpaceGuid.PcdPciBusMax|0x0|UINT32|0x0000005A + +[PcdsDynamicEx] + # + # This dynamic PCD hold the GUID of a firmware FFS which contains + # the LinuxBoot payload. + # + gArmTokenSpaceGuid.PcdLinuxBootFileGuid|{0x0}|VOID*|0x0000005C diff --git a/ArmPkg/ArmPkg.dsc b/ArmPkg/ArmPkg.dsc index 926986cf7fbb..ffb1c261861e 100644 --- a/ArmPkg/ArmPkg.dsc +++ b/ArmPkg/ArmPkg.dsc @@ -5,6 +5,7 @@ # Copyright (c) 2011 - 2021, Arm Limited. All rights reserved.
# Copyright (c) 2016, Linaro Ltd. All rights reserved.
# Copyright (c) Microsoft Corporation.
+# Copyright (c) 2021, Ampere Computing LLC. All rights reserved. # # SPDX-License-Identifier: BSD-2-Clause-Patent # @@ -150,6 +151,7 @@ [Components.common] ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf ArmPkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf ArmPkg/Drivers/ArmCrashDumpDxe/ArmCrashDumpDxe.inf ArmPkg/Drivers/ArmScmiDxe/ArmScmiDxe.inf diff --git a/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf new file mode 100644 index 000000000000..139b6171990a --- /dev/null +++ b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf @@ -0,0 +1,58 @@ +## @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 - 2021, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION = 0x0001001B + 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] + ArmPkg/ArmPkg.dec + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + ShellPkg/ShellPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PcdLib + PrintLib + UefiBootManagerLib + UefiBootServicesTableLib + UefiLib + UefiRuntimeServicesTableLib + +[Pcd] + gArmTokenSpaceGuid.PcdLinuxBootFileGuid + +[Guids] + gEfiEndOfDxeEventGroupGuid + gUefiShellFileGuid + gZeroGuid + +[Protocols] + gEfiLoadedImageProtocolGuid diff --git a/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c new file mode 100644 index 000000000000..f4941780efcd --- /dev/null +++ b/ArmPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c @@ -0,0 +1,178 @@ +/** @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 - 2021, 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 +#include + +STATIC +VOID +PlatformRegisterFvBootOption ( + 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 + ) +{ + EFI_GUID LinuxBootFileGuid; + + CopyGuid (&LinuxBootFileGuid, PcdGetPtr (PcdLinuxBootFileGuid)); + + if (!CompareGuid (&LinuxBootFileGuid, &gZeroGuid)) { + // + // Register LinuxBoot + // + PlatformRegisterFvBootOption ( + &LinuxBootFileGuid, + L"LinuxBoot", + LOAD_OPTION_ACTIVE + ); + } else { + DEBUG ((DEBUG_ERROR, "%a: PcdLinuxBootFileGuid was not set!\n", __FUNCTION__)); + } +} + +/** + 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