public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Laszlo Ersek" <lersek@redhat.com>
To: devel@edk2.groups.io, kraxel@redhat.com
Cc: Jiewen Yao <jiewen.yao@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Michael Roth <michael.roth@amd.com>,
	Erdem Aktas <erdemaktas@google.com>, Min Xu <min.m.xu@intel.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Oliver Steffen <osteffen@redhat.com>
Subject: Re: [edk2-devel] [PATCH 02/11] OvmfPkg: add ShellLibs.dsc.inc
Date: Thu, 25 Jan 2024 14:14:23 +0100	[thread overview]
Message-ID: <53e77c3c-86ad-b3fb-9474-0a4a7cdcb80f@redhat.com> (raw)
In-Reply-To: <20240124163802.2160303-3-kraxel@redhat.com>

I have several comments on this one:

On 1/24/24 17:37, Gerd Hoffmann wrote:
> Move EFI Shell libraries from OvmfPkgX64.dsc to
> the new ShellComponents.dsc.inc include file.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  OvmfPkg/Include/Dsc/ShellLibs.dsc.inc | 11 +++++++++++
>  OvmfPkg/OvmfPkgX64.dsc                | 11 +++++------
>  2 files changed, 16 insertions(+), 6 deletions(-)
>  create mode 100644 OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
>
> diff --git a/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc b/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
> new file mode 100644
> index 000000000000..2e0bac74a261
> --- /dev/null
> +++ b/OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
> @@ -0,0 +1,11 @@
> +##
> +#    SPDX-License-Identifier: BSD-2-Clause-Patent
> +##
> +
> +!if $(BUILD_SHELL) == TRUE
> +
> +[LibraryClasses]
> +  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
> +  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
> +
> +!endif

(1) First, in general, I don't agree with including section headers such
as [LibraryClasses] in include files. As far as I can remember, my
opinion has always been that the include files should not attempt to
specify context; the context spec (i.e., the section header, and the
placement of the !include directive) is up to the top-level DSC file
itself.

(

The idea being that, if an include file provides its own section header,
then the !include directive *changes* the context for the subsequent
parts of the including DSC file. That can be very annoying / surprising,
and I'd only really want to accept it *if* we established a hard rule
that *any* !include directive in any DSC or FDF etc file should
unconditionally be followed by an explicit section header -- even if
that section header were the same as the one just before the !include
directive. Like:

[LibraryClasses]
  FooLib|FooPkg/Library/BaseFooLib/FooLib.inf

!include OtherLibs.inc

[LibraryClasses]
  BarLib|BarPkg/Library/BaseBarLib/BarLib.inf

)

My preferred style is observed for example in:

- NetworkPkg/NetworkLibs.dsc.inc
- RedfishPkg/RedfishLibs.dsc.inc

Alas, it is not observed in:

- MdePkg/MdeLibs.dsc.inc
- OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc

At least, from the last two, OvmfTpmLibs.dsc.inc has an excuse: it
provides library class resolutions for different module types.

So here I'd kind of prefer if we *didn't* include the [LibraryClasses]
header. There's no reason to.


(2) This change makes the ShellCEntryLib resolution dependent on
BUILD_SHELL, which is a functional change, and it is not justified,
AFAICT.

(That's why you have to compensate for it in a module scope lib class
resolution, under "EnrollDefaultKeys.inf".)

There are three "levels" of applications in edk2:
- bare bones
- shell
- libc


(2.1) "Bare bones" is for example
"MdeModulePkg/Application/SmiHandlerProfileInfo/SmiHandlerProfileInfo.inf".

Any module qualifies that has (a) MODULE_TYPE=UEFI_APPLICATION and (b)
ENTRY_POINT=FunctionName and (c) UefiApplicationEntryPoint listed under
[LibraryClasses].

These applications have entry point functions like

  EFI_STATUS
  EFIAPI
  FunctionName (
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
    )

If they want to parse their "command line parameters", they have to open
EFI_LOADED_IMAGE_PROTOCOL on their ImageHandle, and parse
LoadOptionsSize and LoadOptions manually.


(2.2) shell app is for example
"OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf".

Any module qualifies that has (a) MODULE_TYPE=UEFI_APPLICATION, (b)
ENTRY_POINT=ShellCEntryLib, and (c) ShellCEntryLib listed under
[LibraryClasses].

These apps are launched like this:

- the shell loads the image with gBS->LoadImage()

- the shell installs an EFI_SHELL_PARAMETERS_PROTOCOL instance on the
resultant image handle. This protocol interface contains broken-out Argv
and Argc members, prepared by the shell, from the command line that
invokes the app.

- the shell launches the image with gBS->StartImage()

- the image is entered in the ShellCEntryLib() function (from the sole
"ShellCEntryLib" library instance), per ENTRY_POINT define:

  EFI_STATUS
  EFIAPI
  ShellCEntryLib (
    IN EFI_HANDLE        ImageHandle,
    IN EFI_SYSTEM_TABLE  *SystemTable
    )

- ShellCEntryLib() opens EFI_SHELL_PARAMETERS_PROTOCOL on the image
handle, and calls ShellAppMain():

  INTN
  EFIAPI
  ShellAppMain (
    IN UINTN   Argc,
    IN CHAR16  **Argv
    );

with

    ReturnFromMain = ShellAppMain (
                       EfiShellParametersProtocol->Argc,
                       EfiShellParametersProtocol->Argv
                       );

- That is where the actual application code starts running. The actual
application source includes "ShellPkg/Include/Library/ShellCEntryLib.h"
for declaring ShellAppMain().

If such an application is launched outside of the shell, then the
EFI_SHELL_PARAMETERS_PROTOCOL lookup on the image handle fails in
ShellCEntryLib(), and ShellAppMain() can not be called.

The point is that the "ShellPkg/Application/Shell/Shell.inf" binary
itself is of type (2.1), not type (2.2). The shell itself cannot depend
on EFI_SHELL_PARAMETERS_PROTOCOL.

Our BUILD_SHELL macro controls whether we build the shell itself, but
that is independent of whether we build applications that require the
shell to launch them. Making the ShellCEntryLib class resolution
dependent on BUILD_SHELL would only be valid if we also built all the
shell applications dependent on the BUILD_SHELL macro -- which is not
the case.


(2.3) "libc apps", for completeness: these live at
<https://github.com/tianocore/edk2-libc.git>; for example
"AppPkg/Applications/Main/Main.inf".

Any module qualifies that has MODULE_TYPE=UEFI_APPLICATION,
ENTRY_POINT=ShellCEntryLib, and lists LibC under [LibraryClasses].

The sole LibC instance (StdLib/LibC/Main/Main.c) provides a
ShellAppMain() function, for ShellCEntryLib() to call, that mangles Argc
and Argv so they can be passed to the actual application entry point
function main().


> diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
> index 043b0a7a67e0..eae025bd0163 100644
> --- a/OvmfPkg/OvmfPkgX64.dsc
> +++ b/OvmfPkg/OvmfPkgX64.dsc
> @@ -258,16 +258,12 @@ [LibraryClasses]
>    TlsLib|CryptoPkg/Library/TlsLib/TlsLib.inf
>  !endif
>
> -!if $(BUILD_SHELL) == TRUE
> -  ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
> -!endif
> -  ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
> -
>    S3BootScriptLib|MdeModulePkg/Library/PiDxeS3BootScriptLib/DxeS3BootScriptLib.inf
>    SmbusLib|MdePkg/Library/BaseSmbusLibNull/BaseSmbusLibNull.inf
>    OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLib/BaseOrderedCollectionRedBlackTreeLib.inf
>
>  !include OvmfPkg/Include/Dsc/OvmfTpmLibs.dsc.inc
> +!include OvmfPkg/Include/Dsc/ShellLibs.dsc.inc
>
>  [LibraryClasses.common]
>    BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
> @@ -960,7 +956,10 @@ [Components]
>
>  !if $(SECURE_BOOT_ENABLE) == TRUE
>    SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.inf
> -  OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf
> +  OvmfPkg/EnrollDefaultKeys/EnrollDefaultKeys.inf {
> +    <LibraryClasses>
> +    ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
> +  }
>  !endif
>
>    OvmfPkg/PlatformDxe/Platform.inf

(3) Side comment (because this part should go away anyway): the
"ShellCEntryLib|..." line should be indented by two more space
characters.

Summary:

- please consider dropping the [LibraryClasses] header from the include
file

- the ShellCEntryLib class should be resolved regardless of BUILD_SHELL
(and so that resolution may not even belong in the ShellLibs.dsc.inc
file?)

- EnrollDefaultKeys.inf needs no module-scope lib class resolution

Thanks,
Laszlo



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#114402): https://edk2.groups.io/g/devel/message/114402
Mute This Topic: https://groups.io/mt/103935344/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/12367111/7686176/1913456212/xyzzy [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  reply	other threads:[~2024-01-25 13:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-24 16:37 [edk2-devel] [PATCH 00/11] OvmfPkg: tweak shell builds Gerd Hoffmann
2024-01-24 16:37 ` [edk2-devel] [PATCH 01/11] OvmfPkg: add ShellComponents.dsc.inc Gerd Hoffmann
2024-01-25 11:49   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 02/11] OvmfPkg: add ShellLibs.dsc.inc Gerd Hoffmann
2024-01-25 13:14   ` Laszlo Ersek [this message]
2024-01-26 13:59     ` Gerd Hoffmann
2024-01-29 11:25       ` Laszlo Ersek
2024-01-29 12:25         ` Gerd Hoffmann
2024-01-29 12:40           ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 03/11] OvmfPkg: add ShellDxe.fdf.inc Gerd Hoffmann
2024-01-25 13:21   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 04/11] OvmfPkg: Shell*.inc: allow building without network support Gerd Hoffmann
2024-01-25 13:53   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 05/11] OvmfPkg: ShellDxe.fdf.inc: add VariablePolicyDynamicCommand to FV Gerd Hoffmann
2024-01-25 16:46   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 06/11] OvmfPkg: switch OvmfPkgIa32 to new shell include files Gerd Hoffmann
2024-01-25 16:56   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 07/11] OvmfPkg: switch OvmfPkgIa32X64 " Gerd Hoffmann
2024-01-25 16:57   ` Laszlo Ersek
2024-01-24 16:37 ` [edk2-devel] [PATCH 08/11] OvmfPkg: switch AmdSevX64 " Gerd Hoffmann
2024-01-25 17:02   ` Laszlo Ersek
2024-02-14 14:24     ` Gerd Hoffmann
2024-01-24 16:38 ` [edk2-devel] [PATCH 09/11] OvmfPkg: switch IntelTdxX64 " Gerd Hoffmann
2024-01-25 17:04   ` Laszlo Ersek
2024-01-24 16:38 ` [edk2-devel] [PATCH 10/11] OvmfPkg: switch MicrovmX64 " Gerd Hoffmann
2024-01-25 17:05   ` Laszlo Ersek
2024-01-24 16:38 ` [edk2-devel] [PATCH 11/11] OvmfPkg/CI: copy shell to virtual drive Gerd Hoffmann
2024-01-25 17:07   ` Laszlo Ersek
2024-01-25  3:09 ` [edk2-devel] [PATCH 00/11] OvmfPkg: tweak shell builds Yao, Jiewen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=53e77c3c-86ad-b3fb-9474-0a4a7cdcb80f@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox