From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55329+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55329+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244086; cv=none; d=zohomail.com; s=zohoarc; b=WHwqtUPxbqQ9SiN3waXuGXRZLc0PT9HRYsRpt+7Un6YrSx96BsGttwRuOVu/mlTUjL/F/JzaJPO/NIn/oZXbWMw49rUj0+PLiergmSGNZH3dwLhlTTUfmjeAh8PUzAPpldVz84cIAg5EzQ1SW5nEKhkcgKlRgEyjzvI5Vf2iV3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244086; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=fHAS1NtvO/OGz+GBwFunY/snUzDVKzlw1t47RYAnzlU=; b=a1r7xkMOrhAPX9o1046t+lvqmF0UTYnfEkZYwAGTnFYEZdUG/qEyLaLapUQgNmkDla+Cc7Oq94HiB2cslZiHxUojpVwZYmIuYV7sw8ru7wkotGw0PWrQ2WF7qcAxdR2YvOUVniAHa6iBy3KzuhWNytWGkgZRDHm3Va2T+1GR+nM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55329+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244086568915.5150894099148; Tue, 3 Mar 2020 06:01:26 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id Cx11YY1788612xcpeU1wMBlv; Tue, 03 Mar 2020 06:01:25 -0800 X-Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by mx.groups.io with SMTP id smtpd.web12.4074.1583244084720932093 for ; Tue, 03 Mar 2020 06:01:25 -0800 X-Received: by mail-wm1-f65.google.com with SMTP id j1so1507337wmi.4 for ; Tue, 03 Mar 2020 06:01:24 -0800 (PST) X-Gm-Message-State: mW1MLYXfDs71nRw7vZnSSyHWx1787277AA= X-Google-Smtp-Source: ADFU+vt4nkGdEh0UxHZ67y1ysIvBrlzWL3k7Hv7zEm2QEnsHQhigrDJoWVVioR6Yj2g6hdyTqFP+Fg== X-Received: by 2002:a7b:cc6a:: with SMTP id n10mr4456312wmj.170.1583244082963; Tue, 03 Mar 2020 06:01:22 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:22 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 1/7] OvmfPkg: add definition of LINUX_EFI_INITRD_MEDIA_GUID Date: Tue, 3 Mar 2020 15:01:11 +0100 Message-Id: <20200303140117.7288-2-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244085; bh=dGvsp2/kDcZDPnb3IfAfCnzRNjf7fGukgn5hawRkov8=; h=Cc:Date:From:Reply-To:Subject:To; b=sd+OPBZz83afvcPJpI7XCsbNzffNJqjuxUjqat2tVEqa6JPznI3GYK3AzcV9c28Xd1o 6TqUdfYBBYf89MR7FImXxCoM/3qFiUyHdCoaE8d7SEuA5FQh5vR06JxH13s45ycZpgdtl Vxx3Mc4TUe8WHW2/vrPU6U1ctnJLRe9jk1A= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add LINUX_EFI_INITRD_MEDIA_GUID to our collection of GUID definitions, it can be used in a media device path to specify a Linux style initrd that can be loaded by the OS using the LoadFile2 protocol. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/Include/Guid/LinuxEfiInitrdMedia.h | 17 +++++++++++++++++ OvmfPkg/OvmfPkg.dec | 1 + 2 files changed, 18 insertions(+) diff --git a/OvmfPkg/Include/Guid/LinuxEfiInitrdMedia.h b/OvmfPkg/Include/G= uid/LinuxEfiInitrdMedia.h new file mode 100644 index 000000000000..83fc3fc79aa6 --- /dev/null +++ b/OvmfPkg/Include/Guid/LinuxEfiInitrdMedia.h @@ -0,0 +1,17 @@ +/** @file + GUID definition for the Linux Initrd media device path + + Copyright (c) 2020, Arm, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#ifndef LINUX_EFI_INITRD_MEDIA_GUID_H__ +#define LINUX_EFI_INITRD_MEDIA_GUID_H__ + +#define LINUX_EFI_INITRD_MEDIA_GUID \ + {0x5568e427, 0x68fc, 0x4f3d, {0xac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, = 0x68}} + +extern EFI_GUID gLinuxEfiInitrdMediaGuid; + +#endif diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 4c5b6511cb97..6849a79cd8b0 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -86,6 +86,7 @@ [Guids] gMicrosoftVendorGuid =3D {0x77fa9abd, 0x0359, 0x4d32, {0x= bd, 0x60, 0x28, 0xf4, 0xe7, 0x8f, 0x78, 0x4b}} gEfiLegacyBiosGuid =3D {0x2E3044AC, 0x879F, 0x490F, {0x= 97, 0x60, 0xBB, 0xDF, 0xAF, 0x69, 0x5F, 0x50}} gEfiLegacyDevOrderVariableGuid =3D {0xa56074db, 0x65fe, 0x45f7, {0x= bd, 0x21, 0x2d, 0x2b, 0xdd, 0x8e, 0x96, 0x52}} + gLinuxEfiInitrdMediaGuid =3D {0x5568e427, 0x68fc, 0x4f3d, {0x= ac, 0x74, 0xca, 0x55, 0x52, 0x31, 0xcc, 0x68}} =20 [Protocols] gVirtioDeviceProtocolGuid =3D {0xfa920010, 0x6785, 0x4941, {0x= b6, 0xec, 0x49, 0x8c, 0x57, 0x9f, 0x16, 0x0a}} --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55329): https://edk2.groups.io/g/devel/message/55329 Mute This Topic: https://groups.io/mt/71700581/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55330+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55330+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244088; cv=none; d=zohomail.com; s=zohoarc; b=OP3YNMyHnSrzon7S9D/I/afDAc+3BQitUzLmqZuKnjPWkZ4jw0G3oMsPofokpL6YsJFnteADT4x7E/CUXa0IXU2x8VtyMS7bomSr448zfycAXS8yJ15rSqDem7r9jjecYhS2tIMfnh+fMK/SiZVj2Ph07m9rmHuuzmEEOVlwva4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244088; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=0kdGeLLJJ151Wr6s/dqW1V8XYzkYMnlyQhMKsa+pXFc=; b=gh3jlQfA0VTxor46UuF8iYVxR0uCJ9Vuh943aXJWehcCzFYeL52FBJV/NT0CvBZMQPItz2z0FboaP0ofyQ3XYPu6OLNwbutzbeLcP5nUXeswePDvM2zGv2n4Mbq17i4eiaU/hu62KAuWciA5BXtgfDoQDymY2o1rjSrqOIx+CVI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55330+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244088308924.1966944359349; Tue, 3 Mar 2020 06:01:28 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id q9QHYY1788612xXMyv0tcUnl; Tue, 03 Mar 2020 06:01:27 -0800 X-Received: from mail-wm1-f68.google.com (mail-wm1-f68.google.com [209.85.128.68]) by mx.groups.io with SMTP id smtpd.web11.4060.1583244086356471539 for ; Tue, 03 Mar 2020 06:01:26 -0800 X-Received: by mail-wm1-f68.google.com with SMTP id e26so2939254wme.5 for ; Tue, 03 Mar 2020 06:01:26 -0800 (PST) X-Gm-Message-State: asKUA0VNRXJEA8zeTmoNmuBEx1787277AA= X-Google-Smtp-Source: ADFU+vsSyY65bgaa+SHuF8Bytoc335E+lN53fchBICVrVw6C/lFKzBIH/sdEo/WdCpysUAI8IP7bkA== X-Received: by 2002:a05:600c:22d3:: with SMTP id 19mr4312074wmg.169.1583244084267; Tue, 03 Mar 2020 06:01:24 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:23 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 2/7] OvmfPkg: add 'initrd' shell command to expose Linux initrd via device path Date: Tue, 3 Mar 2020 15:01:12 +0100 Message-Id: <20200303140117.7288-3-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244087; bh=CjhKm8NTOu6AuhdSazD81Xk78Z9WeuKtb07mEMpIP3c=; h=Cc:Date:From:Reply-To:Subject:To; b=Shukgcp8ht1D1L6Y+Lug5FWn2FfLFJcqKdPAlJrj3MLEDVIVIvd3PdSft1HythB2WUk JDBr2xKx46HG+8iXJJrXt/sg5XAYsWQMIG96O95TOarX3tP/dQDlC7lxJdvYP1qeeEax6 q3JfujJS74txxnfljQcwIbAy5pIxCzPjPhU= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a new 'initrd' command to the UEFI Shell that allows any file that is accessible to the shell to be registered as the initrd that is returned when Linux's EFI stub loader invokes the LoadFile2 protocol on its special vendor media device path. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c = | 429 ++++++++++++++++++++ OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.inf = | 53 +++ OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni = | 49 +++ 3 files changed, 531 insertions(+) diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShell= Command.c b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellC= ommand.c new file mode 100644 index 000000000000..47ed26b50d3a --- /dev/null +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .c @@ -0,0 +1,429 @@ +/** @file + Provides 'initrd' dynamic UEFI shell command to load a Linux initrd + via its GUIDed vendor media path + + Copyright (c) 2020, Arm, Ltd. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +#pragma pack (1) +typedef struct { + VENDOR_DEVICE_PATH VenMediaNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} SINGLE_NODE_VENDOR_MEDIA_DEVPATH; +#pragma pack () + +STATIC EFI_HII_HANDLE mLinuxInitrdShellCommandHiiHandle; +STATIC EFI_PHYSICAL_ADDRESS mInitrdFileAddress; +STATIC UINTN mInitrdFileSize; +STATIC EFI_HANDLE mInitrdLoadFile2Handle; + +STATIC CONST SHELL_PARAM_ITEM ParamList[] =3D { + {L"-u", TypeFlag}, + {NULL, TypeMax} + }; + +STATIC CONST SINGLE_NODE_VENDOR_MEDIA_DEVPATH mInitrdDevicePath =3D { + { + { + MEDIA_DEVICE_PATH, MEDIA_VENDOR_DP, { sizeof (VENDOR_DEVICE_PATH) } + }, + LINUX_EFI_INITRD_MEDIA_GUID + }, { + END_DEVICE_PATH_TYPE, END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL) } + } +}; + +STATIC +EFI_STATUS +EFIAPI +InitrdLoadFile2 ( + IN EFI_LOAD_FILE2_PROTOCOL *This, + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN BOOLEAN BootPolicy, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer OPTIONAL + ) +{ + if (BootPolicy) { + return EFI_UNSUPPORTED; + } + + if (BufferSize =3D=3D NULL || !IsDevicePathValid (FilePath, 0)) { + return EFI_INVALID_PARAMETER; + } + + if (FilePath->Type !=3D END_DEVICE_PATH_TYPE || + FilePath->SubType !=3D END_ENTIRE_DEVICE_PATH_SUBTYPE || + mInitrdFileSize =3D=3D 0) { + return EFI_NOT_FOUND; + } + + if (Buffer =3D=3D NULL || *BufferSize < mInitrdFileSize) { + *BufferSize =3D mInitrdFileSize; + return EFI_BUFFER_TOO_SMALL; + } + + ASSERT (mInitrdFileAddress !=3D 0); + + gBS->CopyMem (Buffer, (VOID *)(UINTN)mInitrdFileAddress, mInitrdFileSize= ); + *BufferSize =3D mInitrdFileSize; + return EFI_SUCCESS; +} + +STATIC CONST EFI_LOAD_FILE2_PROTOCOL mInitrdLoadFile2 =3D { + InitrdLoadFile2, +}; + +STATIC +EFI_STATUS +UninstallLoadFile2Protocol ( + VOID + ) +{ + EFI_STATUS Status; + + if (mInitrdLoadFile2Handle !=3D NULL) { + Status =3D gBS->UninstallMultipleProtocolInterfaces (mInitrdLoadFile2H= andle, + &gEfiDevicePathProtocolGuid, &mInitrdDevicePath, + &gEfiLoadFile2ProtocolGuid, &mInitrdLoadFile2, + NULL); + if (!EFI_ERROR (Status)) { + mInitrdLoadFile2Handle =3D NULL; + } + } + return Status; +} + +STATIC +VOID +FreeInitrdFile ( + VOID + ) +{ + if (mInitrdFileSize !=3D 0) { + gBS->FreePages (mInitrdFileAddress, EFI_SIZE_TO_PAGES (mInitrdFileSize= )); + mInitrdFileSize =3D 0; + } +} + +STATIC +EFI_STATUS +CacheInitrdFile ( + IN SHELL_FILE_HANDLE FileHandle + ) +{ + EFI_STATUS Status; + UINT64 FileSize; + UINTN ReadSize; + + Status =3D gEfiShellProtocol->GetFileSize (FileHandle, &FileSize); + if (EFI_ERROR (Status)) { + return Status; + } + + if (FileSize =3D=3D 0 || FileSize > MAX_UINTN) { + return EFI_UNSUPPORTED; + } + + Status =3D gBS->AllocatePages (AllocateAnyPages, EfiLoaderData, + EFI_SIZE_TO_PAGES ((UINTN)FileSize), &mInitrdFileAddress= ); + if (EFI_ERROR (Status)) { + return Status; + } + + ReadSize =3D (UINTN)FileSize; + Status =3D gEfiShellProtocol->ReadFile (FileHandle, &ReadSize, + (VOID *)(UINTN)mInitrdFileAddress); + if (EFI_ERROR (Status) || ReadSize < FileSize) { + DEBUG ((DEBUG_WARN, "%a: failed to read initrd file - %r 0x%lx 0x%lx\n= ", + __FUNCTION__, Status, (UINT64)ReadSize, FileSize)); + goto FreeMemory; + } + + if (mInitrdLoadFile2Handle =3D=3D NULL) { + Status =3D gBS->InstallMultipleProtocolInterfaces (&mInitrdLoadFile2Ha= ndle, + &gEfiDevicePathProtocolGuid, &mInitrdDevicePath, + &gEfiLoadFile2ProtocolGuid, &mInitrdLoadFile2, + NULL); + ASSERT_EFI_ERROR (Status); + } + + mInitrdFileSize =3D FileSize; + return EFI_SUCCESS; + +FreeMemory: + gBS->FreePages (mInitrdFileAddress, EFI_SIZE_TO_PAGES ((UINTN)FileSize)); + return Status; +} + +/** + Function for 'initrd' command. + + @param[in] ImageHandle Handle to the Image (NULL if Internal). + @param[in] SystemTable Pointer to the System Table (NULL if Internal). +**/ +STATIC +SHELL_STATUS +EFIAPI +RunInitrd ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + LIST_ENTRY *Package; + CHAR16 *ProblemParam; + CONST CHAR16 *Param; + CHAR16 *Filename; + SHELL_STATUS ShellStatus; + SHELL_FILE_HANDLE FileHandle; + + ProblemParam =3D NULL; + ShellStatus =3D SHELL_SUCCESS; + + Status =3D ShellInitialize (); + ASSERT_EFI_ERROR (Status); + + // + // parse the command line + // + Status =3D ShellCommandLineParse (ParamList, &Package, &ProblemParam, TR= UE); + if (EFI_ERROR (Status)) { + if (Status =3D=3D EFI_VOLUME_CORRUPTED && ProblemParam !=3D NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), + mLinuxInitrdShellCommandHiiHandle, L"initrd", ProblemParam); + FreePool (ProblemParam); + ShellStatus =3D SHELL_INVALID_PARAMETER; + } else { + ASSERT(FALSE); + } + } else { + if (ShellCommandLineGetCount (Package) > 2) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), + mLinuxInitrdShellCommandHiiHandle, L"initrd"); + ShellStatus =3D SHELL_INVALID_PARAMETER; + } else if (ShellCommandLineGetCount (Package) < 2) { + if (ShellCommandLineGetFlag (Package, L"-u")) { + FreeInitrdFile (); + UninstallLoadFile2Protocol (); + } else { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), + mLinuxInitrdShellCommandHiiHandle, L"initrd"); + ShellStatus =3D SHELL_INVALID_PARAMETER; + } + } else { + Param =3D ShellCommandLineGetRawValue (Package, 1); + ASSERT (Param !=3D NULL); + + Filename =3D ShellFindFilePath (Param); + if (Filename =3D=3D NULL) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FIND_FAIL), + mLinuxInitrdShellCommandHiiHandle, L"initrd", Param); + ShellStatus =3D SHELL_NOT_FOUND; + } else { + Status =3D ShellOpenFileByName (Filename, &FileHandle, + EFI_FILE_MODE_READ, 0); + if (!EFI_ERROR (Status)) { + FreeInitrdFile (); + Status =3D CacheInitrdFile (FileHandle); + ShellCloseFile (&FileHandle); + } + if (EFI_ERROR (Status)) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_F= AIL), + mLinuxInitrdShellCommandHiiHandle, L"initrd", Param); + ShellStatus =3D SHELL_NOT_FOUND; + } + FreePool (Filename); + } + } + } + return ShellStatus; +} + + +/** + This is the shell command handler function pointer callback type. This + function handles the command when it is invoked in the shell. + + @param[in] This The instance of the + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL. + @param[in] SystemTable The pointer to the system table. + @param[in] ShellParameters The parameters associated with the com= mand. + @param[in] Shell The instance of the shell protocol use= d in + the context of processing this command. + + @return EFI_SUCCESS the operation was successful + @return other the operation failed. +**/ +SHELL_STATUS +EFIAPI +LinuxInitrdCommandHandler ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN EFI_SYSTEM_TABLE *SystemTable, + IN EFI_SHELL_PARAMETERS_PROTOCOL *ShellParameters, + IN EFI_SHELL_PROTOCOL *Shell + ) +{ + gEfiShellParametersProtocol =3D ShellParameters; + gEfiShellProtocol =3D Shell; + + return RunInitrd (gImageHandle, SystemTable); +} + +/** + This is the command help handler function pointer callback type. This + function is responsible for displaying help information for the associat= ed + command. + + @param[in] This The instance of the + EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL. + @param[in] Language The pointer to the language string to = use. + + @return string Pool allocated help string, must be fr= eed + by caller +**/ +STATIC +CHAR16 * +EFIAPI +LinuxInitrdGetHelp ( + IN EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL *This, + IN CONST CHAR8 *Language + ) +{ + return HiiGetString (mLinuxInitrdShellCommandHiiHandle, + STRING_TOKEN (STR_GET_HELP_INITRD), Language); +} + +STATIC EFI_SHELL_DYNAMIC_COMMAND_PROTOCOL mLinuxInitrdDynamicCommand =3D { + L"initrd", + LinuxInitrdCommandHandler, + LinuxInitrdGetHelp +}; + +/** + Retrieve HII package list from ImageHandle and publish to HII database. + + @param ImageHandle The image handle of the process. + + @return HII handle. +**/ +STATIC +EFI_HII_HANDLE +InitializeHiiPackage ( + EFI_HANDLE ImageHandle + ) +{ + EFI_STATUS Status; + EFI_HII_PACKAGE_LIST_HEADER *PackageList; + EFI_HII_HANDLE HiiHandle; + + // + // Retrieve HII package list from ImageHandle + // + Status =3D gBS->OpenProtocol (ImageHandle, &gEfiHiiPackageListProtocolGu= id, + (VOID **)&PackageList, ImageHandle, NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + + // + // Publish HII package list to HII Database. + // + Status =3D gHiiDatabase->NewPackageList (gHiiDatabase, PackageList, NULL, + &HiiHandle); + ASSERT_EFI_ERROR (Status); + if (EFI_ERROR (Status)) { + return NULL; + } + return HiiHandle; +} + +/** + Entry point of Linux Initrd dynamic UEFI Shell command. + + Produce the DynamicCommand protocol to handle "initrd" command. + + @param ImageHandle The image handle of the process. + @param SystemTable The EFI System Table pointer. + + @retval EFI_SUCCESS Initrd command is executed successfully. + @retval EFI_ABORTED HII package was failed to initialize. + @retval others Other errors when executing Initrd command. +**/ +EFI_STATUS +EFIAPI +LinuxInitrdDynamicShellCommandEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + + mLinuxInitrdShellCommandHiiHandle =3D InitializeHiiPackage (ImageHandle); + if (mLinuxInitrdShellCommandHiiHandle =3D=3D NULL) { + return EFI_ABORTED; + } + + Status =3D gBS->InstallProtocolInterface (&ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + EFI_NATIVE_INTERFACE, + &mLinuxInitrdDynamicCommand); + ASSERT_EFI_ERROR (Status); + return Status; +} + +/** + Unload the dynamic UEFI Shell command. + + @param ImageHandle The image handle of the process. + + @retval EFI_SUCCESS The image is unloaded. + @retval Others Failed to unload the image. +**/ +EFI_STATUS +EFIAPI +LinuxInitrdDynamicShellCommandUnload ( + IN EFI_HANDLE ImageHandle +) +{ + EFI_STATUS Status; + + FreeInitrdFile (); + + Status =3D UninstallLoadFile2Protocol (); + if (EFI_ERROR (Status)) { + return Status; + } + + Status =3D gBS->UninstallProtocolInterface (ImageHandle, + &gEfiShellDynamicCommandProtocolGuid, + &mLinuxInitrdDynamicCommand); + if (EFI_ERROR (Status)) { + return Status; + } + + HiiRemovePackages (mLinuxInitrdShellCommandHiiHandle); + return EFI_SUCCESS; +} diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShell= Command.inf b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShel= lCommand.inf new file mode 100644 index 000000000000..6da6ef6d7818 --- /dev/null +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf @@ -0,0 +1,53 @@ +## @file +# Provides 'initrd' dynamic UEFI shell command to load a Linux initrd +# via its GUIDed vendor media path +# +# Copyright (c) 2020, Arm, Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D LinuxInitrdDynamicShellCommand + FILE_GUID =3D 2f30da26-f51b-4b6f-85c4-31873c281bca + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D LinuxInitrdDynamicShellCommandEntryPo= int + UNLOAD_IMAGE =3D LinuxInitrdDynamicShellCommandUnload + UEFI_HII_RESOURCE_SECTION =3D TRUE + +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 EBC +# + +[Sources.common] + LinuxInitrdDynamicShellCommand.c + LinuxInitrdDynamicShellCommand.uni + +[Packages] + MdePkg/MdePkg.dec + ShellPkg/ShellPkg.dec + MdeModulePkg/MdeModulePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + DevicePathLib + HiiLib + MemoryAllocationLib + ShellLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiHiiServicesLib + +[Protocols] + gEfiDevicePathProtocolGuid ## SOMETIMES_PRODUCES + gEfiHiiPackageListProtocolGuid ## CONSUMES + gEfiLoadFile2ProtocolGuid ## SOMETIMES_PRODUCES + gEfiShellDynamicCommandProtocolGuid ## PRODUCES + +[DEPEX] + TRUE diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShell= Command.uni b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShel= lCommand.uni new file mode 100644 index 000000000000..a88fa6e3641b --- /dev/null +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .uni @@ -0,0 +1,49 @@ +// /** +// +// Copyright (c) 2020, Arm, Ltd. All rights reserved.
+// SPDX-License-Identifier: BSD-2-Clause-Patent +// +// Module Name: +// +// LinuxInitrdDynamicShellCommand.uni +// +// Abstract: +// +// String definitions for 'initrd' UEFI Shell command +// +// **/ + +/=3D# + +#langdef en-US "english" + +#string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - = '%H%s%N'\r\n" +#string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many argume= nts.\r\n" +#string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few argumen= ts.\r\n" +#string STR_GEN_FIND_FAIL #language en-US "%H%s%N: File not found = - '%H%s%N'\r\n" +#string STR_GEN_FILE_OPEN_FAIL #language en-US "%H%s%N: Cannot open fil= e - '%H%s%N'\r\n" + +#string STR_GET_HELP_INITRD #language en-US "" +".TH initrd 0 "Registers or unregisters a file as Linux initrd."\r\n" +".SH NAME\r\n" +"Registers or unregisters a file as Linux initrd.\r\n" +".SH SYNOPSIS\r\n" +" \r\n" +"initrd \r\n" +"initrd -u\r\n" +".SH OPTIONS\r\n" +" \r\n" +" FileName - Specifies a file to register as initrd.\r\n" +" -u - Unregisters any previously registered initrd files.\r\n" +".SH DESCRIPTION\r\n" +" \r\n" +"NOTES:\r\n" +" 1. Only a single file can be loaded as initrd at any given time. Using = the\r\n" +" command twice with a option will result in the first file= to\r\n" +" be unloaded again, regardless of whether the second invocation succe= eded\r\n" +" or not.\r\n" +" 2. The initrd is not unloaded when the shell exits, and will remain act= ive\r\n" +" until it is unloaded again by a different invocation of the shell.\r= \n" +" Consumers of the LoadFile2 protocol on the LINUX_EFI_INITRD_MEDIA_GU= ID\r\n" +" device path that are started via means other than the shell will be = able\r\n" +" to locate the protocol and invoke it.\r\n" --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55330): https://edk2.groups.io/g/devel/message/55330 Mute This Topic: https://groups.io/mt/71700582/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55331+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55331+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244089; cv=none; d=zohomail.com; s=zohoarc; b=JPoPKliXgc+3t4U1ZB41RApt2HBn8sc/mOh8RbrK+ctkQV+quYANUO6A7OTWbn7SyhFF/hpSrXVshQl/S+r4emEuxfpC6ZTPzzqDunVWE9uHTMjtv7a9up1jXgyJmBt0ZqhYQbb2LbSotVFuQ8N1hrkn9mDyxS1kAFa0QmGl4EE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244089; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=K2Um0STxqn88V2lMBVFKxMCV2ZEJlBJae5eGn61Rcqg=; b=do7wwL4/PBjeCs84oNqRPDqvRPYGmIOxQMUDRBItwasT9t92GL2WqPCGCMY91y5g4HrzVYR2/jGmC5phZOmgX9q8R1zh2jwmMFLBOt6Ubu7IgD0yz3qykuF/avj4wzkuD6sLGwoui4ue/aADRe/zj5LOojan8c3EAwnTS2cGvzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55331+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244089916377.7407222377054; Tue, 3 Mar 2020 06:01:29 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id a3wNYY1788612xOrFJsb75Xp; Tue, 03 Mar 2020 06:01:28 -0800 X-Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by mx.groups.io with SMTP id smtpd.web10.4145.1583244087527076673 for ; Tue, 03 Mar 2020 06:01:27 -0800 X-Received: by mail-wr1-f66.google.com with SMTP id x7so4518050wrr.0 for ; Tue, 03 Mar 2020 06:01:27 -0800 (PST) X-Gm-Message-State: 72xKuFa7GcjWIQ8Y8ystWUQ9x1787277AA= X-Google-Smtp-Source: ADFU+vuU71g4DqaehK8mz9ogisXAl7iO4RguC0g2BZ0LoQwVku+fIlHffPxRziQsq83Wyge+NW95pg== X-Received: by 2002:a5d:69d1:: with SMTP id s17mr5673462wrw.339.1583244085397; Tue, 03 Mar 2020 06:01:25 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:24 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 3/7] ArmVirtPkg: add the 'initrd' dynamic shell command Date: Tue, 3 Mar 2020 15:01:13 +0100 Message-Id: <20200303140117.7288-4-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244088; bh=U8EXTPYphV0BDF8vnICaGXm88CIj/aKzo/9ScCbiuRU=; h=Cc:Date:From:Reply-To:Subject:To; b=U1OLDSmemGzQfsPoAAFs12m+kPzphK94+CYYG6m/E2cBx3kOWr4Xoh9g0GgAaGXW+Sn d42LjKo5lWzl4RaHmYH8KGRWiwOXZgG9DRZavfIuuIYFwBR655s51ja6w1o59uNH2j8Oo 1MR+5go9cw9mtrxGOjaDeplxkcROfS6dsd0= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the 'initrd' dynamic shell command to the build so we can load Linux initrds straight from the shell using the new generic protocol, which does not rely on initrd=3D being passed on the command line. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- ArmVirtPkg/ArmVirt.dsc.inc | 4 ++++ ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 + ArmVirtPkg/ArmVirtXen.fdf | 1 + 3 files changed, 6 insertions(+) diff --git a/ArmVirtPkg/ArmVirt.dsc.inc b/ArmVirtPkg/ArmVirt.dsc.inc index 10037c938eb8..42ecd5ce1d52 100644 --- a/ArmVirtPkg/ArmVirt.dsc.inc +++ b/ArmVirtPkg/ArmVirt.dsc.inc @@ -379,6 +379,10 @@ [Components.common] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/Application/Shell/Shell.inf { ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuF= vMain.fdf.inc index 31f615a9d0f9..bfa380815f1a 100644 --- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc @@ -103,6 +103,7 @@ [FV.FvMain] # INF ShellPkg/Application/Shell/Shell.inf INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf + INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellComman= d.inf =20 # # Bds diff --git a/ArmVirtPkg/ArmVirtXen.fdf b/ArmVirtPkg/ArmVirtXen.fdf index 38d4cc163524..6a97bceeacbc 100644 --- a/ArmVirtPkg/ArmVirtXen.fdf +++ b/ArmVirtPkg/ArmVirtXen.fdf @@ -182,6 +182,7 @@ [FV.FvMain] # INF ShellPkg/Application/Shell/Shell.inf INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf + INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellComman= d.inf =20 # # Bds --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55331): https://edk2.groups.io/g/devel/message/55331 Mute This Topic: https://groups.io/mt/71700583/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55332+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55332+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244090; cv=none; d=zohomail.com; s=zohoarc; b=lhrmHQJn1hqH6Wr7YHgZhJVsLrho9XyS7VwB1eWAZQ8Xucsc88R4nhslaIMoXFmH1Z15Pkv0iphKvGoz4h9aWYbYFXzOslw/hWrxr6HDREYpnmLwG2Jwl3Fkicz1LxJKa+Q57TTJkFJ8nqzLFxIt9X6OjKZhUWFRa+J8eWssWdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244090; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=wmKtQhwH6NqJSzsP+KQ/w+wfvlFXVZdpv9rfMHCkb/E=; b=dRBWmP5bKgRA3u5SdqEI8VimOnSN/BQapEyq0paH5eh4gBrz2koOgwmgGkB+CwSzd2hC9LhEjwURKcaBGSt4rIEM/hS0+qBaGVVmmS/f1eVTsMoHl5aSaH4o5qId5jqfi3xylaTuXQfQnHTjpTUTWeW/12zAYwHKyCBm/LEMoXA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55332+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244090947621.0474417150675; Tue, 3 Mar 2020 06:01:30 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5ByxYY1788612xSWZQkLt6U8; Tue, 03 Mar 2020 06:01:29 -0800 X-Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web10.4146.1583244089036962954 for ; Tue, 03 Mar 2020 06:01:29 -0800 X-Received: by mail-wm1-f66.google.com with SMTP id a25so2435106wmm.0 for ; Tue, 03 Mar 2020 06:01:28 -0800 (PST) X-Gm-Message-State: WUh1HJvte9dWriMOQ666ajdRx1787277AA= X-Google-Smtp-Source: ADFU+vvraXNXiByQrP7asKI+wXseFOpw/9Nfk2NckOUQRvKUk7sFnqsYth/z1AEXd2DGc8TG65u3fw== X-Received: by 2002:a1c:9a51:: with SMTP id c78mr4433355wme.130.1583244087282; Tue, 03 Mar 2020 06:01:27 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:26 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 4/7] OvmfPkg: add the 'initrd' dynamic shell command Date: Tue, 3 Mar 2020 15:01:14 +0100 Message-Id: <20200303140117.7288-5-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244089; bh=ScazFSUgHNBCf1GUXnvPBk4bAWQu79sNd8dY4zkiUnA=; h=Cc:Date:From:Reply-To:Subject:To; b=soeCizrtCSBGpVG/NBBYS7bPTljayaZA3KsmdLW4WNMoB7yIRvWU3rAhF/anmXMqEZQ urljsZNizp1mIDyafmJyEYHy9QC5tfh6wFKQKtT9zECuUG4oMwTYqKCFjq7kdFZWL/zKN Ujn1LfB9I1P5hdi7UT9QuFQMsWlw5VgOLDg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add the 'initrd' dynamic shell command to the build so we can load Linux initrds straight from the shell using the new generic protocol, which does not rely on initrd=3D being passed on the command line. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/OvmfPkgIa32.dsc | 4 ++++ OvmfPkg/OvmfPkgIa32.fdf | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 4 ++++ OvmfPkg/OvmfPkgIa32X64.fdf | 1 + OvmfPkg/OvmfPkgX64.dsc | 4 ++++ OvmfPkg/OvmfPkgX64.fdf | 1 + OvmfPkg/OvmfXen.dsc | 4 ++++ OvmfPkg/OvmfXen.fdf | 1 + 8 files changed, 20 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 19728f20b34e..76e52a3de120 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -821,6 +821,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } !endif + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/Application/Shell/Shell.inf { ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index 63607551ed75..6c342823d206 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -281,6 +281,7 @@ [FV.DXEFV] !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif +INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf INF ShellPkg/Application/Shell/Shell.inf =20 INF MdeModulePkg/Logo/LogoDxe.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 3c0c229e3a72..842b4a028913 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -834,6 +834,10 @@ [Components.X64] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } !endif + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/Application/Shell/Shell.inf { ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.fdf b/OvmfPkg/OvmfPkgIa32X64.fdf index 0488e5d95ffe..69c133ec08d5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.fdf +++ b/OvmfPkg/OvmfPkgIa32X64.fdf @@ -282,6 +282,7 @@ [FV.DXEFV] !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif +INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf INF ShellPkg/Application/Shell/Shell.inf =20 INF MdeModulePkg/Logo/LogoDxe.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index f6c1d8d228c6..0b1e45d1f15a 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -832,6 +832,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } !endif + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/Application/Shell/Shell.inf { ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf diff --git a/OvmfPkg/OvmfPkgX64.fdf b/OvmfPkg/OvmfPkgX64.fdf index 0488e5d95ffe..69c133ec08d5 100644 --- a/OvmfPkg/OvmfPkgX64.fdf +++ b/OvmfPkg/OvmfPkgX64.fdf @@ -282,6 +282,7 @@ [FV.DXEFV] !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif +INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf INF ShellPkg/Application/Shell/Shell.inf =20 INF MdeModulePkg/Logo/LogoDxe.inf diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 5751ff1f0352..d476694b18d5 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -692,6 +692,10 @@ [Components] gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE } !endif + OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.in= f { + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + } ShellPkg/Application/Shell/Shell.inf { ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellComman= dLib.inf diff --git a/OvmfPkg/OvmfXen.fdf b/OvmfPkg/OvmfXen.fdf index 05138ffc5b4f..5ca8081c0265 100644 --- a/OvmfPkg/OvmfXen.fdf +++ b/OvmfPkg/OvmfXen.fdf @@ -364,6 +364,7 @@ [FV.DXEFV] !if $(TOOL_CHAIN_TAG) !=3D "XCODE5" INF ShellPkg/DynamicCommand/TftpDynamicCommand/TftpDynamicCommand.inf !endif +INF OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .inf INF ShellPkg/Application/Shell/Shell.inf =20 INF MdeModulePkg/Logo/LogoDxe.inf --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55332): https://edk2.groups.io/g/devel/message/55332 Mute This Topic: https://groups.io/mt/71700585/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55333+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55333+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244092; cv=none; d=zohomail.com; s=zohoarc; b=gbcpyGwAUXbU+hzAL0paoYFrNW4i4pjdZowmdz4RPNvUNupXnz/AvdgYkig51/ledKkOYqxeoEHAbfflwtTmjGkWKf48W2aOh4EXmqZY+swiI/8c3ulbtX3EGGm/c7wJkGsZACjYcdBTBH1UULhfj/a02QIbEFoMP5tBIanwXnM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244092; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=KEuqMqswBlD6L2EG+CfeSiE4n6kr274XIddG3+Dqvs4=; b=bA6DE0ZL4rpTogJxJ91nIWrPRYdQm8tgLcp3ZSQCr83M+dUPwY/jJDtJuSsoT3IWTvHgccoYVDQYzR7BTXjdmgRLWBwSL6GHYoklhWbq8x7FduiuMQg/9YZFpBu2xBGbjGSfGQt/t1waFc3gzl8TxPISVefCQX7S4rN9Nqr3dEU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55333+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 158324409210157.20324655695515; Tue, 3 Mar 2020 06:01:32 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id LM0HYY1788612x3oZVC9Pta9; Tue, 03 Mar 2020 06:01:31 -0800 X-Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web11.4061.1583244090519517761 for ; Tue, 03 Mar 2020 06:01:30 -0800 X-Received: by mail-wr1-f65.google.com with SMTP id j7so4395608wrp.13 for ; Tue, 03 Mar 2020 06:01:30 -0800 (PST) X-Gm-Message-State: hAlHt8rlkCZyKplI5h5fXAJkx1787277AA= X-Google-Smtp-Source: ADFU+vtjW0RynelW6Z6fSVVIEuHtfYryu72XafQBZZYaeaMbhDaULi/z1nmmuwiZ2NkUHd7WB43tZA== X-Received: by 2002:adf:de85:: with SMTP id w5mr5290876wrl.323.1583244088692; Tue, 03 Mar 2020 06:01:28 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:27 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 5/7] MdeModulePkg/DxeCore: defer PE/COFF emulator registration to StartImage Date: Tue, 3 Mar 2020 15:01:15 +0100 Message-Id: <20200303140117.7288-6-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244091; bh=tsCVpTya+0uXpJaKCPUUv9LwaTwR+65mH+WojjpiaqM=; h=Cc:Date:From:Reply-To:Subject:To; b=TpCk6QLdAXS5cxvvtTJJepwEVtqNW/rC2nRWF2oPm5CpDxZEpVDgcowSy97PZVyUKo4 AS7AxcPR0saKEf9gsim+xb7f79Sga9wQdAszVm12KeZgnvcTAMvHFx5QzOgRDN6shjASP T9XHqeJI1oTppuN8GDQkZxmOQYCkZKrlnNM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" EDK2's implementation of the LoadImage() boot service permits non-native binaries to be loaded (i.e., X64 images on IA32 firmware), but any attempts to start such an image using StartImage() will return EFI_UNSUPPORTED. The integration of the PE/COFF emulator protocol into the DXE core deviates slightly from this paradigm, given that its IsImageSupported hook as well as its RegisterImage hook are invoked from LoadImage, and by the time StartImage is called, no opportunity is given to the provider of the PE/COFF emulator protocol to prevent an image from being started if it only supports loading it. To address this disparity, let's move the invocation of RegisterImage() to the implementation of the StartImage() boot service, allowing the emulator to permit LoadImage() but reject StartImage() on images that turn out not to meet the requirements of the emulator as it is being started. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Acked-by: Liming Gao --- MdeModulePkg/Core/Dxe/Image/Image.c | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/MdeModulePkg/Core/Dxe/Image/Image.c b/MdeModulePkg/Core/Dxe/Im= age/Image.c index 22a87ecf6d7c..d86da89ee704 100644 --- a/MdeModulePkg/Core/Dxe/Image/Image.c +++ b/MdeModulePkg/Core/Dxe/Image/Image.c @@ -756,17 +756,6 @@ CoreLoadPeImage ( // Get the image entry point. // Image->EntryPoint =3D (EFI_IMAGE_ENTRY_POINT)(UINTN)Image->ImageContex= t.EntryPoint; - if (Image->PeCoffEmu !=3D NULL) { - Status =3D Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, - Image->ImageBasePage, - EFI_PAGES_TO_SIZE (Image->NumberOfPages), - &Image->EntryPoint); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_LOAD | DEBUG_ERROR, - "CoreLoadPeImage: Failed to register foreign image with emulator.\= n")); - goto Done; - } - } =20 // // Fill in the image information for the Loaded Image Protocol @@ -1603,6 +1592,19 @@ CoreStartImage ( return EFI_UNSUPPORTED; } =20 + if (Image->PeCoffEmu !=3D NULL) { + Status =3D Image->PeCoffEmu->RegisterImage (Image->PeCoffEmu, + Image->ImageBasePage, + EFI_PAGES_TO_SIZE (Image->NumberOfPages), + &Image->EntryPoint); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_LOAD | DEBUG_ERROR, + "CoreLoadPeImage: Failed to register foreign image with emulator -= %r\n", + Status)); + return Status; + } + } + PERF_START_IMAGE_BEGIN (Handle); =20 =20 --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55333): https://edk2.groups.io/g/devel/message/55333 Mute This Topic: https://groups.io/mt/71700587/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55334+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55334+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244093; cv=none; d=zohomail.com; s=zohoarc; b=ZHnEwgFIS0Dfxj7XPwKAKU5oFtpE2VSPUFS7/rhUtljEGLSwuTcwAzRfQ3E5KamJKyyTqzSpbT42zBbdSp3YLr5GX9Kp05muUF6soP1K3dc9FSiDPukSorwGXeG05vH2YRJEGLvWOuhibVtslGxTAEvfUdQFKoqU4pwh59OZzbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244093; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=rNt7L1b+9i40/c5C2QOExIZsI+VAS2liXqJy01D+oL8=; b=UJUgKtdNOwS4BqDMszLVg3TPPQpCMUpOBtnfSfw6uEqpU+QAUVyWXT17a+LeRYg5HFIDdB7fbSweGM341aurv2H5tC2repJhCclTMRiv6bxH/rX7eCfBEJE/DHHfzT3JUSAycBKvPEGMDgrIvxLSv9331uc0JdRHAocmc+0YjBg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55334+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244093813977.7772059561674; Tue, 3 Mar 2020 06:01:33 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id AGJfYY1788612xOTmYBqcLOe; Tue, 03 Mar 2020 06:01:32 -0800 X-Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by mx.groups.io with SMTP id smtpd.web09.4030.1583244092050122130 for ; Tue, 03 Mar 2020 06:01:32 -0800 X-Received: by mail-wm1-f67.google.com with SMTP id i9so1914615wml.4 for ; Tue, 03 Mar 2020 06:01:31 -0800 (PST) X-Gm-Message-State: nQYxF57iXAuN9p3We9pMgOgkx1787277AA= X-Google-Smtp-Source: ADFU+vuU3c9jNq0yEz4RQWcTTse7Dptzc7oJ15qfdZBnkCwHhidkoOd2IVBC2d7wmCtnpwdNWrtnDQ== X-Received: by 2002:a1c:df45:: with SMTP id w66mr4405683wmg.171.1583244090132; Tue, 03 Mar 2020 06:01:30 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:29 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 6/7] OvmfPkg IA32: add support for loading X64 images Date: Tue, 3 Mar 2020 15:01:16 +0100 Message-Id: <20200303140117.7288-7-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244092; bh=uJib8tiC5yz4rbwnz+3Kj0ECp6u1S9S8e6ZHV5vl8ic=; h=Cc:Date:From:Reply-To:Subject:To; b=Xqwifs8lppHW4HJZn1sLMn4mfiEWHg8g7PYW3xQDjs7Oy3zISbBDb3aUDbTpyn0IEmT lSlfkJ1QlDH3penw8EpZzPM9MaUS2prwjyGcK8joWp5lYf+IVFScP6s6kpHdZpyLdAa6y Wr8RyKUDwDliIsMZ49P3c/0JFcItDVe3TVw= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This is the UEFI counterpart to my Linux series which generalizes mixed mode support into a feature that requires very little internal knowledge about the architecture specifics of booting Linux on the part of the bootloader or firmware. Instead, we add a .compat PE/COFF header containing an array of PE_COMPAT nodes containing tuples that describe alternate entrypoints into the image for different native machine types, e.g., IA-32 in a 64-bit image so it can be booted from IA-32 firmware. This patch implements the PE/COFF emulator protocol to take this new section into account, so that such images can simply be loaded via LoadImage/StartImage, e.g., straight from the shell. This feature is based on the EDK2 specific PE/COFF emulator protocol that was introduced in commit 57df17fe26cd ("MdeModulePkg/DxeCore: invoke the emulator protocol for foreign images", 2019-04-14). Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Acked-by: Laszlo Ersek --- OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.c | 143 ++++++++++++++= ++++++ OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf | 37 +++++ OvmfPkg/OvmfPkgIa32.dsc | 5 + OvmfPkg/OvmfPkgIa32.fdf | 4 + 4 files changed, 189 insertions(+) diff --git a/OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.c b/OvmfPkg/= CompatImageLoaderDxe/CompatImageLoaderDxe.c new file mode 100644 index 000000000000..ae47917f1589 --- /dev/null +++ b/OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.c @@ -0,0 +1,143 @@ +/** @file + * PE/COFF emulator protocol implementation to start Linux kernel + * images from non-native firmware + * + * Copyright (c) 2020, ARM Ltd. All rights reserved.
+ * + * SPDX-License-Identifier: BSD-2-Clause-Patent + * + */ + +#include + +#include +#include +#include +#include + +#include + +#pragma pack (1) +typedef struct { + UINT8 Type; + UINT8 Size; + UINT16 MachineType; + UINT32 EntryPoint; +} PE_COMPAT_TYPE1; +#pragma pack () + +STATIC +BOOLEAN +EFIAPI +IsImageSupported ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN UINT16 ImageType, + IN EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL + ) +{ + return ImageType =3D=3D EFI_IMAGE_SUBSYSTEM_EFI_APPLICATION; +} + +STATIC +EFI_IMAGE_ENTRY_POINT +EFIAPI +GetCompatEntryPoint ( + IN EFI_PHYSICAL_ADDRESS ImageBase + ) +{ + EFI_IMAGE_DOS_HEADER *DosHdr; + UINTN PeCoffHeaderOffset; + EFI_IMAGE_NT_HEADERS32 *Pe32; + EFI_IMAGE_SECTION_HEADER *Section; + UINTN NumberOfSections; + PE_COMPAT_TYPE1 *PeCompat; + VOID *PeCompatEnd; + + DosHdr =3D (EFI_IMAGE_DOS_HEADER *)(UINTN)ImageBase; + if (DosHdr->e_magic !=3D EFI_IMAGE_DOS_SIGNATURE) { + return NULL; + } + + PeCoffHeaderOffset =3D DosHdr->e_lfanew; + Pe32 =3D (EFI_IMAGE_NT_HEADERS32 *)((UINTN)ImageBase + PeCoffHeaderOffse= t); + + Section =3D (EFI_IMAGE_SECTION_HEADER *)((UINTN)&Pe32->OptionalHeader + + Pe32->FileHeader.SizeOfOptionalHe= ader); + NumberOfSections =3D (UINTN)Pe32->FileHeader.NumberOfSections; + + while (NumberOfSections--) { + if (!CompareMem (Section->Name, ".compat", sizeof (Section->Name))) { + // + // Dereference the section contents to find the mixed mode entry poi= nt + // + PeCompat =3D (PE_COMPAT_TYPE1 *)((UINTN)ImageBase + Section->Virtual= Address); + PeCompatEnd =3D (UINT8 *)PeCompat + Section->Misc.VirtualSize; + + while (PeCompat->Type !=3D 0 && (VOID *)PeCompat < PeCompatEnd) { + if (PeCompat->Type =3D=3D 1 && + PeCompat->Size >=3D sizeof (PE_COMPAT_TYPE1) && + EFI_IMAGE_MACHINE_TYPE_SUPPORTED (PeCompat->MachineType)) { + + return (EFI_IMAGE_ENTRY_POINT)((UINTN)ImageBase + PeCompat->Entr= yPoint); + } + PeCompat =3D (PE_COMPAT_TYPE1 *)((UINTN)PeCompat + PeCompat->Size); + ASSERT ((VOID *)PeCompat < PeCompatEnd); + } + } + Section++; + } + return NULL; +} + +STATIC +EFI_STATUS +EFIAPI +RegisterImage ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS ImageBase, + IN UINT64 ImageSize, + IN OUT EFI_IMAGE_ENTRY_POINT *EntryPoint + ) +{ + EFI_IMAGE_ENTRY_POINT CompatEntryPoint; + + CompatEntryPoint =3D GetCompatEntryPoint (ImageBase); + if (CompatEntryPoint =3D=3D NULL) { + return EFI_UNSUPPORTED; + } + + *EntryPoint =3D CompatEntryPoint; + return EFI_SUCCESS; +} + +STATIC +EFI_STATUS +EFIAPI +UnregisterImage ( + IN EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL *This, + IN EFI_PHYSICAL_ADDRESS ImageBase + ) +{ + return EFI_SUCCESS; +} + +STATIC EDKII_PECOFF_IMAGE_EMULATOR_PROTOCOL mCompatLoaderPeCoffEmuProtocol= =3D { + IsImageSupported, + RegisterImage, + UnregisterImage, + EDKII_PECOFF_IMAGE_EMULATOR_VERSION, + EFI_IMAGE_MACHINE_X64 +}; + +EFI_STATUS +EFIAPI +CompatImageLoaderDxeEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->InstallProtocolInterface (&ImageHandle, + &gEdkiiPeCoffImageEmulatorProtocolGuid, + EFI_NATIVE_INTERFACE, + &mCompatLoaderPeCoffEmuProtocol); +} diff --git a/OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf b/OvmfPk= g/CompatImageLoaderDxe/CompatImageLoaderDxe.inf new file mode 100644 index 000000000000..74f06c64bfbf --- /dev/null +++ b/OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf @@ -0,0 +1,37 @@ +## @file +# PE/COFF emulator protocol implementation to start Linux kernel +# images from non-native firmware +# +# Copyright (c) 2020, ARM Ltd. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 1.27 + BASE_NAME =3D CompatImageLoaderDxe + FILE_GUID =3D 1019f54a-2560-41b2-87b0-6750b98f3eff + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D CompatImageLoaderDxeEntryPoint + +[Sources] + CompatImageLoaderDxe.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + BaseMemoryLib + DebugLib + PeCoffLib + UefiBootServicesTableLib + UefiDriverEntryPoint + +[Protocols] + gEdkiiPeCoffImageEmulatorProtocolGuid ## PRODUCES + +[Depex] + TRUE diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 76e52a3de120..8d91903f8b4e 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -33,6 +33,7 @@ [Defines] DEFINE SOURCE_DEBUG_ENABLE =3D FALSE DEFINE TPM2_ENABLE =3D FALSE DEFINE TPM2_CONFIG_ENABLE =3D FALSE + DEFINE LOAD_X64_ON_IA32_ENABLE =3D FALSE =20 # # Network definition @@ -932,3 +933,7 @@ [Components] SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigDxe.inf !endif !endif + +!if $(LOAD_X64_ON_IA32_ENABLE) =3D=3D TRUE + OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf +!endif diff --git a/OvmfPkg/OvmfPkgIa32.fdf b/OvmfPkg/OvmfPkgIa32.fdf index 6c342823d206..f57de4a26f92 100644 --- a/OvmfPkg/OvmfPkgIa32.fdf +++ b/OvmfPkg/OvmfPkgIa32.fdf @@ -354,6 +354,10 @@ [FV.DXEFV] !endif !endif =20 +!if $(LOAD_X64_ON_IA32_ENABLE) =3D=3D TRUE +INF OvmfPkg/CompatImageLoaderDxe/CompatImageLoaderDxe.inf +!endif + ##########################################################################= ###### =20 [FV.FVMAIN_COMPACT] --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55334): https://edk2.groups.io/g/devel/message/55334 Mute This Topic: https://groups.io/mt/71700588/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Wed May 1 01:21:07 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+55335+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55335+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1583244095; cv=none; d=zohomail.com; s=zohoarc; b=QR9grt+S9sc+QCYHUqOHoXf+NALTRMcO3lt1prPlQRjZ5Xi4IkbhG86/guiBEkMabV0rCZcyIsxHtgsOK8ejX3YYB0537i5/k2HHutgGfo2JYIxO3mTakzAbt90Al0coKhBt0NnmizCQreO6NebuELaXcnlK1180aRqWJBvdKzc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1583244095; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=Lu18rOvVeDVdyyTH4QHtWqLXPDfO4DvMcCmh6qtNh7o=; b=CL3bm2NNfaEMJ64RIfZDMiuUwY/o7lLCHuoBg+9SylQauNxHA5wJChO+unGri3B/Bnn1i2uvHIl6HpWe4Qw+oDfxfzYRcXHHLfrXxe947K0VbqJkDsNF7omZGHq7okLsdqFoUaRY4wxN6NiN4/7dBmQNQ8/girOumXDe/BuoaU8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+55335+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1583244095162134.12899561140784; Tue, 3 Mar 2020 06:01:35 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id tqDFYY1788612xf3t5J7exMU; Tue, 03 Mar 2020 06:01:34 -0800 X-Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by mx.groups.io with SMTP id smtpd.web10.4147.1583244093373974117 for ; Tue, 03 Mar 2020 06:01:33 -0800 X-Received: by mail-wm1-f66.google.com with SMTP id j1so1507965wmi.4 for ; Tue, 03 Mar 2020 06:01:33 -0800 (PST) X-Gm-Message-State: XBlD9N0boysVXJU5GeORtzPex1787277AA= X-Google-Smtp-Source: ADFU+vtKO2ubeP/1gg5Zf99P2RQi+AU6SIXROoiUuw3ZiA/8tFCJFgF2k7MVFR9Hh6ONHY67DuSA7A== X-Received: by 2002:a1c:4c03:: with SMTP id z3mr4639511wmf.133.1583244091678; Tue, 03 Mar 2020 06:01:31 -0800 (PST) X-Received: from e123331-lin.home ([2a01:cb1d:112:6f00:816e:ff0d:fb69:f613]) by smtp.gmail.com with ESMTPSA id i10sm27575122wrn.53.2020.03.03.06.01.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2020 06:01:30 -0800 (PST) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: Ard Biesheuvel , lersek@redhat.com, leif@nuviainc.com, Liming Gao Subject: [edk2-devel] [PATCH v4 7/7] OvmfPkg/LinuxInitrdDynamicShellCommand: bail if initrd already exists Date: Tue, 3 Mar 2020 15:01:17 +0100 Message-Id: <20200303140117.7288-8-ard.biesheuvel@linaro.org> In-Reply-To: <20200303140117.7288-1-ard.biesheuvel@linaro.org> References: <20200303140117.7288-1-ard.biesheuvel@linaro.org> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1583244094; bh=Zugqo4PEbtwRhZ0rT3XBMScJmkPy5NvLwK0XQckwtPU=; h=Cc:Date:From:Reply-To:Subject:To; b=LLqmTVBUarBucvRMsouYafk5D4nTIGs1NcL5TPvtXOIurk5KEn6uoP8mP6BgpSm7qEf /04DTmfDPnSQ70JrKdoxprUWaJNR9mrf/v6apCPm3qUNTlAI89Fi0qV233g6YEQpisKMk BN8VSeN6nKkDymbFb9IlXN9uJpmwV42aaNQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Before taking any actions, check if an instance of the LoadFile2 exists already on the Linux initrd media GUID device path, and whether it was provided by this command. If so, abort, since no duplicate instances of the device path should exist. Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2564 Signed-off-by: Ard Biesheuvel Reviewed-by: Laszlo Ersek --- OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.c = | 31 ++++++++++++++++++++ OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand.uni = | 3 ++ 2 files changed, 34 insertions(+) diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShell= Command.c b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellC= ommand.c index 47ed26b50d3a..ed8fbaa77069 100644 --- a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .c +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .c @@ -53,6 +53,33 @@ STATIC CONST SINGLE_NODE_VENDOR_MEDIA_DEVPATH mInitrdDev= icePath =3D { } }; =20 +STATIC +BOOLEAN +IsOtherInitrdDevicePathAlreadyInstalled ( + VOID + ) +{ + EFI_STATUS Status; + EFI_DEVICE_PATH_PROTOCOL *DevicePath; + EFI_HANDLE Handle; + + DevicePath =3D (EFI_DEVICE_PATH_PROTOCOL *)&mInitrdDevicePath; + Status =3D gBS->LocateDevicePath (&gEfiLoadFile2ProtocolGuid, &DevicePat= h, + &Handle); + if (EFI_ERROR (Status)) { + return FALSE; + } + + // + // Check whether the existing instance is one that we installed during + // a previous invocation. + // + if (Handle =3D=3D mInitrdLoadFile2Handle) { + return FALSE; + } + return TRUE; +} + STATIC EFI_STATUS EFIAPI @@ -217,6 +244,10 @@ RunInitrd ( } else { ASSERT(FALSE); } + } else if (IsOtherInitrdDevicePathAlreadyInstalled ()) { + ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_ALREADY_INSTALLED= ), + mLinuxInitrdShellCommandHiiHandle, L"initrd"); + ShellStatus =3D SHELL_UNSUPPORTED; } else { if (ShellCommandLineGetCount (Package) > 2) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), diff --git a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShell= Command.uni b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShel= lCommand.uni index a88fa6e3641b..4b6b1285fffd 100644 --- a/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .uni +++ b/OvmfPkg/LinuxInitrdDynamicShellCommand/LinuxInitrdDynamicShellCommand= .uni @@ -18,6 +18,7 @@ #langdef en-US "english" =20 #string STR_GEN_PROBLEM #language en-US "%H%s%N: Unknown flag - = '%H%s%N'\r\n" +#string STR_GEN_ALREADY_INSTALLED #language en-US "%H%s%N: Linux initrd al= ready provided by platform\r\n" #string STR_GEN_TOO_MANY #language en-US "%H%s%N: Too many argume= nts.\r\n" #string STR_GEN_TOO_FEW #language en-US "%H%s%N: Too few argumen= ts.\r\n" #string STR_GEN_FIND_FAIL #language en-US "%H%s%N: File not found = - '%H%s%N'\r\n" @@ -47,3 +48,5 @@ " Consumers of the LoadFile2 protocol on the LINUX_EFI_INITRD_MEDIA_GU= ID\r\n" " device path that are started via means other than the shell will be = able\r\n" " to locate the protocol and invoke it.\r\n" +" 3. Exposing an initrd using this command is only supported if no initrd= is\r\n" +" already being exposed by another driver on the platform.\r\n" --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#55335): https://edk2.groups.io/g/devel/message/55335 Mute This Topic: https://groups.io/mt/71700589/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-