From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (NAM04-MW2-obe.outbound.protection.outlook.com [40.107.101.87]) by mx.groups.io with SMTP id smtpd.web12.2499.1631575142671395723 for ; Mon, 13 Sep 2021 16:19:02 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@nvidia.com header.s=selector2 header.b=BRJwXzJy; 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.101.87, mailfrom: jbrasen@nvidia.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=itOiGYWsG3J9RzdMUqauNdqhgUKzlEd2ZclT+1lJbmVPIKNMf+f5LXaUH19LMB02EqD3jmi2swVY1N7JrdhOtMglcm9oEiK2H7TOIa1HABEVTISgOVRp3rutsAI6q+JzPzErinvJLJQ9M0DLb7MtlxTYEqgB7CNxZC0YAVJi9vvzuHIbjjvRS7vv5N2DFeniNWJQctuYJ/sH25aOCKxmBG1C2KPhVWtAoMF6HKuwy55rjy4No7KMKGc4qo7Plqgb+BVG5vffB1fR1mlhUedl7ZsDQlLp4FmPver/BMyCtT+FIM8VI5yzb7hHnt6NItdZph/Ucqkzwlvd6CgfM47dhA== 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=cuyl2/OZPjMdQ5AdxMO5Lzu6yYg+mG+CimKKMko15Jw=; b=mC0SzRoHPsQkOzamoPke6T/GrgbGBPYHktXC/D98KwG9Z9521ZvgKRLjiO4innfQ26KBCmWJVNtysR1LSL4IAGPKUce2xt88mTRaQ+tsipaWxxE2r2OC0hg2H2D4tf/bDn6BddxTTVW9gav/jF7fnsYMY6AFatpTczRSLcr7TJp1zRjfRQxflO3mlPfTVOZAcJX0MB1Xxy1hYlsGyw5r5WFbnkPY0DKAptx15VtagQXZ1/ZNevfnBiCRCu9yQp3Mk+J9l/wKhEp7tSgUoNXHNt2StVQ8hWbRT/3X35JGHNEQKv9/tX41q2tnfSsmPvyIawTtEjQYiYvZ1Fp76t2eHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=kernel.org 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=cuyl2/OZPjMdQ5AdxMO5Lzu6yYg+mG+CimKKMko15Jw=; b=BRJwXzJytwaw/c/WQ9MwmngXD+1Mt+xlnCU2of5v2PKZtF7mF5ACJ/aYxfGNgwTMaIO0Sj2FBd4EblpEYtZFCSSRV2scmb1aXRVwFl7k/xYiEjjGrKzu2QsYe5E5z0uaXfYbMIz2KFW5DdTKRRbZGXnWY/zkbFBlprXmSvYcaZn0/wGzPag5+hQl/0FC+NE9iCasKHwmOYXA/OtJFCSZxnvMCMpYC94GMTKty5jrqKZuNFh6l3TuunDJmuSYfTAARQWppu0XYPGfZ/x2uNCKU3QAyicd71OlB0cy4x+xRY0JD7vItHnzZrPENKU1dxoMQabgsUPylqvUGdWoEUan3A== Received: from MWHPR17CA0095.namprd17.prod.outlook.com (2603:10b6:300:c2::33) by BN8PR12MB4595.namprd12.prod.outlook.com (2603:10b6:408:72::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14; Mon, 13 Sep 2021 23:19:00 +0000 Received: from CO1NAM11FT056.eop-nam11.prod.protection.outlook.com (2603:10b6:300:c2:cafe::7b) by MWHPR17CA0095.outlook.office365.com (2603:10b6:300:c2::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 23:19:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; kernel.org; dkim=none (message not signed) header.d=none;kernel.org; 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 CO1NAM11FT056.mail.protection.outlook.com (10.13.175.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4500.14 via Frontend Transport; Mon, 13 Sep 2021 23:19:00 +0000 Received: from HQMAIL111.nvidia.com (172.20.187.18) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 13 Sep 2021 16:18:59 -0700 Received: from build-jbrasen-20210913T102602203.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.18) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Mon, 13 Sep 2021 23:18:59 +0000 From: "Jeff Brasen" To: CC: , , , , Jeff Brasen Subject: [PATCH v3 4/4] EmbeddedPkg: Add LoadFile2 for linux initrd Date: Mon, 13 Sep 2021 23:18:51 +0000 Message-ID: <4a3a25bb7c33faab9d20bb7ca045c72f92207b98.1631574815.git.jbrasen@nvidia.com> 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: 1c604bea-52ed-4300-d145-08d9770cde52 X-MS-TrafficTypeDiagnostic: BN8PR12MB4595: 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: E2TnqrVNGMbDNMnvcw1QJtiiJ3y8R7ixtSKCg2hY70PpjUvkXXIth0f7iycfZPksCJTAnlZB4PaoYbDvQshrRyh2xVtP9cmxC93mw0IY3MVVcrXzpLQELU6Pbs+EVlg+H3N+tSVoN2dS/R+5dAw4Sg8DbvWkyxaiH8N+yGLCXxVMsbLHPMKJjM2SO8BYCmug8BWmBQGg7rq0Zb4jDVppO0BIItg3zQ0McjpsXHe61jaJaLdX08neL0kugEHZVCkHa5mE5Gjl2JhY8BK1iDm8Vz7e1tcZm0NC2NenK8jg+p1MQiiyVYji1FbLaS/FpOkK1vQWM89H8mF9Yt8HkiJsPkFfusD/S38Bw8xhwqV2Dd1LRlmMjt1IpODYLp1Aku5pMxfKDiwYjjfsXgwH09wiZ5d1AKYYnxpn8JRN/4NmLmF1KUCKFzmeXuATHDR/w1FkXP1X3i76aL3/i9itg5g8GOTIm7I5RQFKU0ua9V5aD5gymWbLB3Oa3sg16gLcFkYozzI/G6d5v3CuVSoiHjjFXmkoh+8HRNby79WgkZ/NtzQIRpRvzlWrzTFuSQN1ZvHnvRAULmIOW6W/QyIw2EIhZM8oeVw4INaohpTGEaX+aQ8wG9lyhSStm4f0wzqaji3IY9hBBUST8Bbs3W0SrdwB8wEhDDxhAWkCRmKzrRWOTRSi/wwkctoyJeaBJsVaNbFi8x4EWyqsi+ZpWJTJ5RLZS1dXXCpGusLc2MpwWEe70eo= 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)(36840700001)(46966006)(2616005)(6666004)(19627235002)(26005)(356005)(36756003)(107886003)(7696005)(70586007)(54906003)(70206006)(5660300002)(36860700001)(316002)(4326008)(7636003)(82310400003)(8936002)(508600001)(83380400001)(86362001)(336012)(2906002)(47076005)(8676002)(426003)(6916009)(186003)(44824005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Sep 2021 23:19:00.1728 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1c604bea-52ed-4300-d145-08d9770cde52 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: CO1NAM11FT056.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB4595 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 instead of via device tree. This feature is also enabled if ACPI tables are present, and will skip locating and installation of device tree. Signed-off-by: Jeff Brasen --- EmbeddedPkg/EmbeddedPkg.dec | 1 + .../AndroidBootImgLib/AndroidBootImgLib.inf | 4 + .../AndroidBootImgLib/AndroidBootImgLib.c | 218 ++++++++++++++++-- 3 files changed, 201 insertions(+), 22 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..affde50f617a 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.inf @@ -41,4 +41,8 @@ [Protocols] gEfiLoadedImageProtocolGuid =20 [Guids] + gEfiAcpiTableGuid gFdtTableGuid + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdAndroidBootLoadFile2 diff --git a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c b/Em= beddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c index 4f8ff5b261ca..cc39fef4895c 100644 --- a/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c +++ b/EmbeddedPkg/Library/AndroidBootImgLib/AndroidBootImgLib.c @@ -10,12 +10,16 @@ #include #include #include +#include #include #include =20 #include +#include #include =20 +#include + #define FDT_ADDITIONAL_ENTRIES_SIZE 0x400 =20 typedef struct { @@ -23,7 +27,15 @@ typedef struct { EFI_DEVICE_PATH_PROTOCOL End; } MEMORY_DEVICE_PATH; =20 +typedef struct { + VENDOR_DEVICE_PATH VendorMediaNode; + EFI_DEVICE_PATH_PROTOCOL EndNode; +} RAMDISK_DEVICE_PATH; + STATIC ANDROID_BOOTIMG_PROTOCOL *mAndroidBootImg; +STATIC VOID *mRamdiskData =3D NULL; +STATIC UINTN mRamdiskSize =3D 0; +STATIC EFI_HANDLE mRamDiskLoadFileHandle =3D= NULL; =20 STATIC CONST MEMORY_DEVICE_PATH mMemoryDevicePathTemplate =3D { @@ -46,6 +58,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, @@ -214,6 +319,60 @@ AndroidBootImgUpdateArgs ( return Status; } =20 +EFI_STATUS +AndroidBootImgInstallLoadFile2 ( + IN VOID *RamdiskData, + IN UINTN RamdiskSize + ) +{ + mRamDiskLoadFileHandle =3D NULL; + mRamdiskData =3D RamdiskData; + mRamdiskSize =3D RamdiskSize; + return gBS->InstallMultipleProtocolInterfaces ( + &mRamDiskLoadFileHandle, + &gEfiLoadFile2ProtocolGuid, + &mAndroidBootImgLoadFile2, + &gEfiDevicePathProtocolGuid, + &mRamdiskDevicePath, + NULL + ); +} + +EFI_STATUS +AndroidBootImgUninstallLoadFile2 ( + VOID + ) +{ + EFI_STATUS Status; + + Status =3D EFI_SUCCESS; + mRamdiskData =3D NULL; + mRamdiskSize =3D 0; + if (mRamDiskLoadFileHandle !=3D NULL) { + Status =3D gBS->UninstallMultipleProtocolInterfaces ( + mRamDiskLoadFileHandle, + &gEfiLoadFile2ProtocolGuid, + &mAndroidBootImgLoadFile2, + &gEfiDevicePathProtocolGuid, + &mRamdiskDevicePath, + NULL + ); + mRamDiskLoadFileHandle =3D NULL; + } + return Status; +} + +BOOLEAN AndroidBootImgAcpiSupported ( + VOID + ) +{ + EFI_STATUS Status; + VOID *AcpiTable; + + Status =3D EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, &AcpiTabl= e); + return !EFI_ERROR (Status); +} + EFI_STATUS AndroidBootImgLocateFdt ( IN VOID *BootImg, @@ -325,23 +484,30 @@ AndroidBootImgUpdateFdt ( goto Fdt_Exit; } =20 - ChosenNode =3D AndroidBootImgGetChosenNode(UpdatedFdtBase); - if (!ChosenNode) { - goto Fdt_Exit; - } + if (FeaturePcdGet (PcdAndroidBootLoadFile2)) { + Status =3D AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } + } else { + ChosenNode =3D AndroidBootImgGetChosenNode(UpdatedFdtBase); + if (!ChosenNode) { + goto Fdt_Exit; + } =20 - Status =3D AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, - "linux,initrd-start", - (UINTN)RamdiskData); - if (EFI_ERROR (Status)) { - goto Fdt_Exit; - } + Status =3D AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, + "linux,initrd-start", + (UINTN)RamdiskData); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } =20 - Status =3D AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, - "linux,initrd-end", - (UINTN)RamdiskData + RamdiskSize); - if (EFI_ERROR (Status)) { - goto Fdt_Exit; + Status =3D AndroidBootImgSetProperty64 (UpdatedFdtBase, ChosenNode, + "linux,initrd-end", + (UINTN)RamdiskData + RamdiskSize= ); + if (EFI_ERROR (Status)) { + goto Fdt_Exit; + } } =20 if (mAndroidBootImg->UpdateDtb) { @@ -422,14 +588,21 @@ AndroidBootImgBoot ( goto Exit; } =20 - Status =3D AndroidBootImgLocateFdt (Buffer, &FdtBase); - if (EFI_ERROR (Status)) { - goto Exit; - } + if (AndroidBootImgAcpiSupported ()) { + Status =3D AndroidBootImgInstallLoadFile2 (RamdiskData, RamdiskSize); + 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; @@ -473,5 +646,6 @@ AndroidBootImgBoot ( NewKernelArg =3D NULL; } } + AndroidBootImgUninstallLoadFile2 (); return Status; } --=20 2.17.1