From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by mx.groups.io with SMTP id smtpd.web10.21588.1675961850628888662 for ; Thu, 09 Feb 2023 08:57:31 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QZc1FwIf; spf=pass (domain: kernel.org, ip: 145.40.68.75, mailfrom: ardb@kernel.org) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7B6DEB82249 for ; Thu, 9 Feb 2023 16:57:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32631C433EF for ; Thu, 9 Feb 2023 16:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675961847; bh=/urhzvHlx9gXxINCCM6OVVJ2vLQ8ofpLE7qrmtS5P1M=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=QZc1FwIftIPC4sERyKoFkoZoHYSyzJmBFQH46ZPinPFYIFYxd2ko6141MrTbuVneN uz3wBxQCC7guRLNR53L1mu4ewUSJ+gHVLuAEAobi7WEWQUtUZFe758Ao0YXG4bw29L LMfFch0d6hzg3XgNQdSJIKvhKLUcrvvgW1LdYGjYJ41HR5cJ7ecRlOSUYv1FpH2EBq JxtCw4/OSqpHeV7F2UXfPnrLKbwFM4ftrB3uI385fg545dQyrM6ghnDKCycDAC9+33 lVUx87m0CV1iK0vIk6NVCD3T7Y7jSBEsQQYtr2CTdHeAVEvgQeT7z4Uz7w4w1Zxbts icnWonDPytQhA== Received: by mail-lj1-f180.google.com with SMTP id g14so2751844ljh.10 for ; Thu, 09 Feb 2023 08:57:27 -0800 (PST) X-Gm-Message-State: AO0yUKWKb3GUw0TlwCqxEPmWr7zcGM6BUvNfqyUriBJjiCjZGq0dh6fk HWP5IYE+ZaDad1fyOfiPoK7SmxH1Bans51vE5IY= X-Google-Smtp-Source: AK7set/w7TZZCgYNdVcizpuNw+9N8JjQvQodgRpZHs3SqJ9pqp6lWtQZDwVzrs2syBCTQhS0og+D1yPqsCeHV6TElHY= X-Received: by 2002:a2e:95d4:0:b0:293:2b74:efd3 with SMTP id y20-20020a2e95d4000000b002932b74efd3mr919705ljh.178.1675961845119; Thu, 09 Feb 2023 08:57:25 -0800 (PST) MIME-Version: 1.0 References: <20230207090653.395992-1-pierre.gondois@arm.com> In-Reply-To: <20230207090653.395992-1-pierre.gondois@arm.com> From: "Ard Biesheuvel" Date: Thu, 9 Feb 2023 17:57:13 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/1] ArmPkg/PlatformBootManagerLib: Add path to boot UEFI Shell over UiApp To: pierre.gondois@arm.com Cc: devel@edk2.groups.io, ardb+tianocore@kernel.org, leif@nuviainc.com, sami.mujawar@arm.com, patrik.berglund@arm.com Content-Type: text/plain; charset="UTF-8" On Tue, 7 Feb 2023 at 10:07, wrote: > > From: Pierre Gondois > > The UEFI Shell is a non-active boot option, at the opposite of UiApp. > If no valid boot option is found, UiApp is selected. UiApp requires a > human interaction. When installing a new EDKII image in CIs or when > scripting is required, this is problematic. > > If no valid boot option is discovered, add a path to directly go to > the UEFI Shell where the startup.nsh script is automatically executed. > The UEFI Shell is launched after connecting possible devices, but > before the reset that is meant to automatically make them visible. > > The new PcdUefiShellDefaultBootEnable must be set to TRUE to enable > this behaviour. The Pcd is set to false by default. > Is this similar to how we implemented this on RPi4? IIRC, a similar issue came up there as well. > Signed-off-by: Pierre Gondois > --- > ArmPkg/ArmPkg.dec | 9 ++- > .../PlatformBootManagerLib/PlatformBm.c | 69 ++++++++++++++++++- > .../PlatformBootManagerLib.inf | 4 +- > 3 files changed, 79 insertions(+), 3 deletions(-) > > diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec > index f17ba913e6de..2444457ae58a 100644 > --- a/ArmPkg/ArmPkg.dec > +++ b/ArmPkg/ArmPkg.dec > @@ -2,7 +2,7 @@ > # ARM processor package. > # > # Copyright (c) 2009 - 2010, Apple Inc. All rights reserved.
> -# Copyright (c) 2011 - 2022, ARM Limited. All rights reserved. > +# Copyright (c) 2011 - 2023, ARM Limited. All rights reserved. > # Copyright (c) 2021, Ampere Computing LLC. All rights reserved. > # > # SPDX-License-Identifier: BSD-2-Clause-Patent > @@ -221,6 +221,13 @@ [PcdsFixedAtBuild.common] > # > gArmTokenSpaceGuid.PcdArmDmaDeviceOffset|0x0|UINT64|0x0000044 > > + # > + # Boot the Uefi Shell instead of UiApp when no valid boot option is found. > + # This is useful in CI environment so that startup.nsh can be launched. > + # The default value is FALSE. > + # > + gArmTokenSpaceGuid.PcdUefiShellDefaultBootEnable|FALSE|BOOLEAN|0x0000052 > + > [PcdsFixedAtBuild.common, PcdsPatchableInModule.common] > gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B > gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D > diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c > index 2fb1a4aa4fb8..9bdc44d86b54 100644 > --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c > +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBm.c > @@ -2,7 +2,7 @@ > Implementation for PlatformBootManagerLib library class interfaces. > > Copyright (C) 2015-2016, Red Hat, Inc. > - Copyright (c) 2014 - 2021, ARM Ltd. All rights reserved.
> + Copyright (c) 2014 - 2023, Arm Ltd. All rights reserved.
> Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.
> Copyright (c) 2016, Linaro Ltd. All rights reserved.
> Copyright (c) 2021, Semihalf All rights reserved.
> @@ -470,6 +470,61 @@ PlatformRegisterFvBootOption ( > EfiBootManagerFreeLoadOptions (BootOptions, BootOptionCount); > } > > +/** Boot a Fv Boot Option. > + * > + * This function is useful for booting the UEFI Shell as it is loaded > + * as a non active boot option. > + * > + * @param[in] FileGuid The File GUID. > + * @param[in] Description String describing the Boot Option. > + */ > +STATIC > +VOID > +PlatformBootFvBootOption ( > + IN CONST EFI_GUID *FileGuid, > + IN CHAR16 *Description > + ) > +{ > + EFI_STATUS Status; > + EFI_BOOT_MANAGER_LOAD_OPTION NewOption; > + 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, > + LOAD_OPTION_ACTIVE, > + Description, > + DevicePath, > + NULL, > + 0 > + ); > + ASSERT_EFI_ERROR (Status); > + FreePool (DevicePath); > + > + for ( ; ;) { > + EfiBootManagerBoot (&NewOption); > + } > +} > + > STATIC > VOID > GetPlatformOptions ( > @@ -1075,6 +1130,18 @@ PlatformBootManagerUnableToBoot ( > EfiBootManagerConnectAll (); > EfiBootManagerRefreshAllBootOption (); > > + // > + // Boot the 'UEFI Shell'. If the Pcd is not set, the UEFI Shell is not > + // an active boot option and must be manually selected through UiApp > + // (at least during the fist boot). > + // > + if (FixedPcdGetBool (PcdUefiShellDefaultBootEnable)) { > + PlatformBootFvBootOption ( > + &gUefiShellFileGuid, > + L"UEFI Shell (default)" > + ); > + } > + > // > // Record the updated number of boot configured boot options > // > diff --git a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > index 86751b45f82b..05ed46456cc4 100644 > --- a/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > +++ b/ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf > @@ -2,7 +2,7 @@ > # Implementation for PlatformBootManagerLib library class interfaces. > # > # Copyright (C) 2015-2016, Red Hat, Inc. > -# Copyright (c) 2014, ARM Ltd. All rights reserved.
> +# Copyright (c) 2014 - 2023, Arm Ltd. All rights reserved.
> # Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
> # Copyright (c) 2016, Linaro Ltd. All rights reserved.
> # > @@ -29,6 +29,7 @@ [Sources] > PlatformBm.h > > [Packages] > + ArmPkg/ArmPkg.dec > EmbeddedPkg/EmbeddedPkg.dec > MdeModulePkg/MdeModulePkg.dec > MdePkg/MdePkg.dec > @@ -55,6 +56,7 @@ [FeaturePcd] > gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport > > [FixedPcd] > + gArmTokenSpaceGuid.PcdUefiShellDefaultBootEnable > gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvModeEnable > gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString > gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate > -- > 2.25.1 >