[edk2-devel] [edk2-platforms][PATCH v2 30/32] AmpereSiliconPkg: Implement PlatformBootManagerLib for LinuxBoot

Nhi Pham via groups.io nhi=os.amperecomputing.com at groups.io
Wed Jun 9 15:21:11 UTC 2021


On 6/8/21 06:50, Leif Lindholm wrote:
> On Wed, May 26, 2021 at 17:07:22 +0700, Nhi Pham wrote:
>> The PlatformBootManagerLib library derived from
>> ArmPkg/Library/PlatformBootManagerLib.
>>
>> This implementation registers only a common GUID for LinuxBoot Payload
>> ("D834A5AD-459C-4AED-B0D0-8CBCB28838D7") as a active boot option. This
>> allows BDS to jump to the LinuxBoot Shell immediately without entering
>> the UiApp Setup Screen or UEFI Shell.
> This driver does not look spectacularly platform specific to me,
> although the GUID handling could posibly do with some additional
> engineering if this was to be shared with others.
>
> Would you consider submitting it for ArmPkg for now? (Unless it's
> something for MinPlatformPkg?)

Ok, I will separate this driver and submit it for ArmPkg for now.

Best regards,

Nhi

>
> /
>      Leif
>
>> Cc: Thang Nguyen <thang at os.amperecomputing.com>
>> Cc: Chuong Tran <chuong at os.amperecomputing.com>
>> Cc: Phong Vo <phong at os.amperecomputing.com>
>> Cc: Leif Lindholm <leif at nuviainc.com>
>> Cc: Michael D Kinney <michael.d.kinney at intel.com>
>> Cc: Ard Biesheuvel <ardb+tianocore at kernel.org>
>> Cc: Nate DeSimone <nathaniel.l.desimone at intel.com>
>>
>> Signed-off-by: Nhi Pham <nhi at os.amperecomputing.com>
>> ---
>>   Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf |  54 ++++++
>>   Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c               | 173 ++++++++++++++++++++
>>   2 files changed, 227 insertions(+)
>>
>> diff --git a/Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf b/Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBootManagerLib.inf
>> new file mode 100644
>> index 000000000000..cb4ade210117
>> --- /dev/null
>> +++ b/Silicon/Ampere/AmpereSiliconPkg/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.<BR>
>> +#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
>> +#  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
>> +#  Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
>> +#
>> +#  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
>> +  DebugLib
>> +  MemoryAllocationLib
>> +  PrintLib
>> +  UefiBootManagerLib
>> +  UefiBootServicesTableLib
>> +  UefiLib
>> +  UefiRuntimeServicesTableLib
>> +
>> +[Pcd]
>> +
>> +[Guids]
>> +  gEfiEndOfDxeEventGroupGuid
>> +  gUefiShellFileGuid
>> +
>> +[Protocols]
>> +  gEfiLoadedImageProtocolGuid
>> diff --git a/Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c b/Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
>> new file mode 100644
>> index 000000000000..2d0f087477d6
>> --- /dev/null
>> +++ b/Silicon/Ampere/AmpereSiliconPkg/Library/LinuxBootBootManagerLib/LinuxBootBm.c
>> @@ -0,0 +1,173 @@
>> +/** @file
>> +  Implementation for PlatformBootManagerLib library class interfaces.
>> +
>> +  Copyright (C) 2015-2016, Red Hat, Inc.
>> +  Copyright (c) 2014 - 2019, ARM Ltd. All rights reserved.<BR>
>> +  Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
>> +  Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
>> +  Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
>> +
>> +  SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +**/
>> +
>> +#include <Uefi.h>
>> +
>> +#include <Guid/EventGroup.h>
>> +#include <Library/BaseLib.h>
>> +#include <Library/BaseMemoryLib.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/DevicePathLib.h>
>> +#include <Library/MemoryAllocationLib.h>
>> +#include <Library/UefiBootManagerLib.h>
>> +#include <Library/UefiBootServicesTableLib.h>
>> +#include <Library/UefiLib.h>
>> +#include <Library/UefiRuntimeServicesTableLib.h>
>> +#include <Protocol/LoadedImage.h>
>> +#include <Protocol/PlatformBootManager.h>
>> +
>> +// This GUID must match the FILE_GUID in the LinuxBootPkg/LinuxBoot.inf file.
>> +// GUID: D834A5AD-459C-4AED-B0D0-8CBCB28838D7
>> +EFI_GUID mLinuxBootFileGuid = { 0xD834A5AD, 0x459C, 0x4AED, { 0xB0, 0xD0, 0x8C, 0xBC, 0xB2, 0x88, 0x38, 0xD7 } };
>> +
>> +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 LinuxBoot
>> +  //
>> +  RegisterFvBootOption (
>> +    &mLinuxBootFileGuid,
>> +    L"LinuxBoot",
>> +    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
>>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#76281): https://edk2.groups.io/g/devel/message/76281
Mute This Topic: https://groups.io/mt/83097179/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-





More information about the edk2-devel-archive mailing list