From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (NAM12-DM6-obe.outbound.protection.outlook.com [40.107.243.56]) by mx.groups.io with SMTP id smtpd.web08.1630.1630528113709556419 for ; Wed, 01 Sep 2021 13:28:34 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=uo0Eh7QI; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: nvidia.com, ip: 40.107.243.56, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yjnn6w90V5orfRdGixw0N+qDYTSaTvcj97IRldUgFDSLWXb7OfVVH3w1kxA4MDWBRAZqqmBO/vzpxRxaerBV64GjHDgOqDhjQ34AuQKTxas9Nt57nGi70puGY+WL/L8oIQJf4fAMuta7rjkCXC/VAFzZ3fjbmHUeK+2NcYrqQ1ozqC+HP99iYNuaSaGA7sJrQGQx3ihwvy4q4mX7hYLEJwXUy4wdph06y2xoKHWXLsvPOksvV3i84eqQ8zUol/v7aBau/f6t/iynmFFMAdorV1lLjt+W2JTmbZs1HvUcIESfJ6goNUUYLImIgTUM+jRz2o/BvEOy+uBV/m+iS9BXjg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=4fCn9FDDa34MHXnpT3UUux012h2hcHVkvJ5VMF5PZq4=; b=ICC7PyR0uYB4QP0RatOGz4n77PTL5JDXVJxBuMPk5qWm+bSNT/89VeIX0DaD9zcsgbTaUBMPXChn7jV1U4yOLgtRSFb1AZNAqIksyq7veTrX1vnLNZZbuT0fks7o0cMbS27sv6EKzq/raq8ttXJyEUEFguAbIb10EKTL9E2pn0W++zUyUV8yqEKgyG1EyIDWZpnZ85mB0dGMA40706nsQu2A0qdnvdadaCh0Yf+FdtlShO48We+sOmqRCbu43KRcdc+wY1CHLXTw8VS90XFLDWJsAAlUQxLtdxKnSXcUkO5a6WCk0j3nWJfRgtsAwmDjGee43s8a+AhG4AQfDwM1wA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=hpe.com smtp.mailfrom=nvidia.com; dmarc=pass (p=quarantine sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4fCn9FDDa34MHXnpT3UUux012h2hcHVkvJ5VMF5PZq4=; b=uo0Eh7QILChlEzzQDIuEyLDnjtQlp6rMgiIzV4z4oZIE69GuEJLQ0YgSoYYq+T9UbIIDbxH5S4+5NrPs+tWDoWspSAPoavtm4iJEC7MHQobsitUdKsV2Ms1HOJmd7CUyogQ99v0hffb7SADa+xzuWED51WkGmzTkDPn8ixbl/uBP+tgp0ay+eAk+tktdREUdbyCIIbrx2DpgNJ25fGA0OdKFHkMjR7glUW5m8daE1fCjZdXhwLykm1K0He/dl5ruMIEdE/uOss5xBhxkokixhghLjTJAYdvtdIWF3l1gX4faMxFZa9WojywGQMnrvsYsT3TcRfOnNQWAUR12IGFAbA== Received: from BN0PR02CA0030.namprd02.prod.outlook.com (2603:10b6:408:e4::35) by PH0PR12MB5419.namprd12.prod.outlook.com (2603:10b6:510:e9::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Wed, 1 Sep 2021 20:28:32 +0000 Received: from BN8NAM11FT047.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e4:cafe::d5) by BN0PR02CA0030.outlook.office365.com (2603:10b6:408:e4::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19 via Frontend Transport; Wed, 1 Sep 2021 20:28:32 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; hpe.com; dkim=none (message not signed) header.d=none;hpe.com; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT047.mail.protection.outlook.com (10.13.177.220) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4478.19 via Frontend Transport; Wed, 1 Sep 2021 20:28:31 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 1 Sep 2021 13:28:31 -0700 Received: from build-jbrasen-20210819T103534360.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.10) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 1 Sep 2021 20:28:31 +0000 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH v2 2/2] EmbeddedPkg: Add LoadFile2 for linux initrd Date: Wed, 1 Sep 2021 20:28:27 +0000 Message-ID: X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 In-Reply-To: References: X-NVConfidentiality: public Return-Path: jbrasen@nvidia.com X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ebfb7841-7326-4d1e-8fbf-08d96d8710e3 X-MS-TrafficTypeDiagnostic: PH0PR12MB5419: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sLCZhI3YGbqHNtPEqMm1pX/vUQ+uagg8pOw1hHpV9BtlLYGAaO1TXTK5eFDCCOhmue0pKQBGfu02NzXo5WLvHUgNWLaqNYtgubXSV8a/12S/Xyi8IowQper030jwwJ0XAkz9OJtzqILam/gDqsldnhXzN2FWV0+Q8AgBxu6TtTvgGY53mJLbNbVDZn3VxXR76PO3RwoXdJlEPrPcs7xs+x8rTRGsUpYJZ0oxXOJjCiQgiOoaVU9qtEItWCUhfXChisc0cpoH+JSFfcUZtvYJcXa7wEG7n1UVnEaPIbdh5Q24i/755UUPEY64kDhcQOmpCldPiM4YLHaQlVzoj4NtNSk1eerj45gEmd2KolB1RrMKpWCwxhOUnVa2xfaxCJ+R59tKMcxvUkDOw9mj8mvL26WnVQh5mVn8Oh0Q6hp61Z71tReZ76tYSHm04/wIUbIlyhmaJI1LDRGy1nlZtXWJgb6wL95XH0tUPsrvwFKLoGPUbP3X/UJdXwxfST3kvvg64xs7UE37CbHWvt8vCzL+K896qDvDeoeoLN2NiaaPFQPV3heWeqlCM2RizdBtl/JlHTI4EUgNaNkbRb2PVVhwF6sGHJ0nkW+Ey9BimT2B9N9fLu5NnlglyyN062z5gdOq/iBuU+Fj8RxjOOetSsmJ4U5ZkEHS0kH8eEj4ZatBqhIUxodYa3w3FLwxxE43rJfY9RfAaDYz/YLJgBTkJNTEf7klSoo/NPPW7S3s+Z+PNIw= X-Forefront-Antispam-Report: CIP:216.228.112.32;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:schybrid01.nvidia.com;CAT:NONE;SFS:(4636009)(396003)(136003)(346002)(39860400002)(376002)(36840700001)(46966006)(6916009)(36860700001)(70206006)(70586007)(82310400003)(47076005)(336012)(5660300002)(478600001)(8936002)(7636003)(356005)(82740400003)(426003)(83380400001)(7696005)(86362001)(107886003)(2616005)(8676002)(54906003)(316002)(296002)(6666004)(186003)(36756003)(4326008)(19627235002)(2906002)(26005)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Sep 2021 20:28:31.9338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ebfb7841-7326-4d1e-8fbf-08d96d8710e3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.112.32];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT047.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5419 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain Add support under a pcd feature for using the new interface to pass initrd to the linux kernel. Signed-off-by: Jeff Brasen --- EmbeddedPkg/EmbeddedPkg.dec | 1 + .../AndroidBootImgLib/AndroidBootImgLib.inf | 3 + .../AndroidBootImgLib/AndroidBootImgLib.c | 147 +++++++++++++++++- 3 files changed, 144 insertions(+), 7 deletions(-) diff --git a/EmbeddedPkg/EmbeddedPkg.dec b/EmbeddedPkg/EmbeddedPkg.dec index c2068ce5a8ce..7638aaaadeb8 100644 --- a/EmbeddedPkg/EmbeddedPkg.dec +++ b/EmbeddedPkg/EmbeddedPkg.dec @@ -86,6 +86,7 @@ [Ppis] [PcdsFeatureFlag.common] gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|FALSE|BO= OLEAN|0x0000001b gEmbeddedTokenSpaceGuid.PcdGdbSerial|FALSE|BOOLEAN|0x00000053 + gEmbeddedTokenSpaceGuid.PcdAndroidBootLoadFile2|FALSE|BOOLEAN|0x0000005b =20 [PcdsFixedAtBuild.common] gEmbeddedTokenSpaceGuid.PcdPrePiStackBase|0|UINT32|0x0000000b diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf b/= EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf index bfed4ba9dcd4..39d8abe72cd1 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf @@ -42,3 +42,6 @@ [Protocols] =20 [Guids] gFdtTableGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdAndroidBootLoadFile2 diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/Em= beddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c index 3c617649f735..635965690dc0 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -10,11 +10,15 @@ #include #include #include +#include #include #include =20 #include #include +#include + +#include =20 #include =20 @@ -25,7 +29,14 @@ typedef struct { EFI_DEVICE_PATH_PROTOCOL End; } MEMORY_DEVICE_PATH; =20 +typedef struct { + VENDOR_DEVICE_PATH VenMediaNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} RAMDISK_DEVICE_PATH; + STATIC ANDROID_BOOTIMG_PROTOCOL *mAndroidBootImg; +STATIC VOID *mRamdiskData =3D NULL; +STATIC UINTN mRamdiskSize =3D 0; =20 STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplate =3D { @@ -48,6 +59,99 @@ STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplat= e =3D } // End }; =20 +STATIC CONST RAMDISK_DEVICE_PATH mRamdiskDevicePath =3D +{ + { + { + MEDIA_DEVICE_PATH, + MEDIA_VENDOR_DP, + { sizeof (VENDOR_DEVICE_PATH), 0 } + }, + LINUX_EFI_INITRD_MEDIA_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 } + } +}; + +/** + Causes the driver to load a specified file. + + @param This Protocol instance pointer. + @param FilePath The device specific path of the file to load. + @param BootPolicy Should always be FALSE. + @param BufferSize On input the size of Buffer in bytes. On output with = a return + code of EFI_SUCCESS, the amount of data transferred t= o + Buffer. On output with a return code of EFI_BUFFER_TO= O_SMALL, + the size of Buffer required to retrieve the requested= file. + @param Buffer The memory buffer to transfer the file to. IF Buffer = is NULL, + then no the size of the requested file is returned in + BufferSize. + + @retval EFI_SUCCESS The file was loaded. + @retval EFI_UNSUPPORTED BootPolicy is TRUE. + @retval EFI_INVALID_PARAMETER FilePath is not a valid device path, or + BufferSize is NULL. + @retval EFI_NO_MEDIA No medium was present to load the file. + @retval EFI_DEVICE_ERROR The file was not loaded due to a device er= ror. + @retval EFI_NO_RESPONSE The remote system did not respond. + @retval EFI_NOT_FOUND The file was not found + @retval EFI_ABORTED The file load process was manually cancele= d. + @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the cu= rrent + directory entry. BufferSize has been updat= ed with + the size needed to complete the request. + + +**/ +EFI_STATUS +EFIAPI +AndroidBootImgLoadFile2 ( + IN EFI_LOAD_FILE2_PROTOCOL *This, + IN EFI_DEVICE_PATH_PROTOCOL *FilePath, + IN BOOLEAN BootPolicy, + IN OUT UINTN *BufferSize, + IN VOID *Buffer OPTIONAL + ) + +{ + // Verify if the valid parameters + if (This =3D=3D NULL || + BufferSize =3D=3D NULL || + FilePath =3D=3D NULL || + !IsDevicePathValid (FilePath, 0)) { + return EFI_INVALID_PARAMETER; + } + + if (BootPolicy) { + return EFI_UNSUPPORTED; + } + + // Check if the given buffer size is big enough + // EFI_BUFFER_TOO_SMALL to allow caller to allocate a bigger buffer + if (mRamdiskSize =3D=3D 0) { + return EFI_NOT_FOUND; + } + if (Buffer =3D=3D NULL || *BufferSize < mRamdiskSize) { + *BufferSize =3D mRamdiskSize; + return EFI_BUFFER_TOO_SMALL; + } + + // Copy InitRd + CopyMem (Buffer, mRamdiskData, mRamdiskSize); + *BufferSize =3D mRamdiskSize; + + return EFI_SUCCESS; +} + +/// +/// Load File Protocol instance +/// +STATIC EFI_LOAD_FILE2_PROTOCOL mAndroidBootImgLoadFile2 =3D { + AndroidBootImgLoadFile2 +}; + EFI_STATUS AndroidBootImgGetImgSize ( IN VOID *BootImg, @@ -383,6 +487,7 @@ AndroidBootImgBoot ( VOID *RamdiskData; UINTN RamdiskSize; IN VOID *FdtBase; + EFI_HANDLE RamDiskLoadFileHandle; =20 NewKernelArg =3D NULL; ImageHandle =3D NULL; @@ -423,14 +528,29 @@ AndroidBootImgBoot ( goto Exit; } =20 - Status =3D AndroidBootImgLocateFdt (Buffer, &FdtBase); - if (EFI_ERROR (Status)) { - goto Exit; - } + if (FeaturePcdGet (PcdAndroidBootLoadFile2)) { + RamDiskLoadFileHandle =3D NULL; + mRamdiskData =3D RamdiskData; + mRamdiskSize =3D RamdiskSize; + Status =3D gBS->InstallMultipleProtocolInterfaces (&RamDiskLoadFileHan= dle, + &gEfiLoadFile2Protoco= lGuid, + &mAndroidBootImgLoadF= ile2, + &gEfiDevicePathProtoc= olGuid, + &mRamdiskDevicePath, + NULL); + if (EFI_ERROR (Status)) { + goto Exit; + } + } else { + Status =3D AndroidBootImgLocateFdt (Buffer, &FdtBase); + if (EFI_ERROR (Status)) { + goto Exit; + } =20 - Status =3D AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, Ramdis= kSize); - if (EFI_ERROR (Status)) { - goto Exit; + Status =3D AndroidBootImgUpdateFdt (Buffer, FdtBase, RamdiskData, Ramd= iskSize); + if (EFI_ERROR (Status)) { + goto Exit; + } } =20 KernelDevicePath =3D mMemoryDevicePathTemplate; @@ -474,5 +594,18 @@ AndroidBootImgBoot ( NewKernelArg =3D NULL; } } + if (FeaturePcdGet (PcdAndroidBootLoadFile2)) { + mRamdiskData =3D NULL; + mRamdiskSize =3D 0; + if (RamDiskLoadFileHandle !=3D NULL) { + gBS->UninstallMultipleProtocolInterfaces (RamDiskLoadFileHandle, + &gEfiLoadFile2ProtocolGuid= , + &mAndroidBootImgLoadFile2, + &gEfiDevicePathProtocolGui= d, + &mRamdiskDevicePath, + NULL); + RamDiskLoadFileHandle =3D NULL; + } + } return Status; } --=20 2.17.1