From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.115; helo=mga14.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B643A211B85D7 for ; Tue, 22 Jan 2019 20:53:31 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 20:53:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,509,1539673200"; d="scan'208";a="269150347" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga004.jf.intel.com with ESMTP; 22 Jan 2019 20:53:31 -0800 Received: from fmsmsx155.amr.corp.intel.com (10.18.116.71) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 22 Jan 2019 20:53:30 -0800 Received: from shsmsx153.ccr.corp.intel.com (10.239.6.53) by FMSMSX155.amr.corp.intel.com (10.18.116.71) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 22 Jan 2019 20:53:30 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.150]) by SHSMSX153.ccr.corp.intel.com ([169.254.12.67]) with mapi id 14.03.0415.000; Wed, 23 Jan 2019 12:53:28 +0800 From: "Ni, Ray" To: 'Gary Lin' , "edk2-devel@lists.01.org" CC: "Zeng, Star" , "Wang, Jian J" , "Wu, Hao A" Thread-Topic: [PATCH v2] MdeModulePkg/UefiBootManagerLib: Match the nested partitions Thread-Index: AQHUstXCfF/UBZ3sSEyZYAZ5eUzBUKW8SdiQ Date: Wed, 23 Jan 2019 04:53:28 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BFCFB1B@SHSMSX103.ccr.corp.intel.com> References: <20190123044004.31925-1-glin@suse.com> In-Reply-To: <20190123044004.31925-1-glin@suse.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] MdeModulePkg/UefiBootManagerLib: Match the nested partitions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 04:53:32 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Much much better. Even better than recursive call. Thanks! Reviewed-by: Ray Ni > -----Original Message----- > From: Gary Lin > Sent: Wednesday, January 23, 2019 12:40 PM > To: edk2-devel@lists.01.org > Cc: Ni, Ray ; Zeng, Star ; Wang, > Jian J ; Wu, Hao A > Subject: [PATCH v2] MdeModulePkg/UefiBootManagerLib: Match the > nested partitions >=20 > In some cases, such as MD RAID1 in Linux, the bootloader may be in a nest= ed > EFI system partition partition. For example, sda1 and sdb1 are combined a= s > md0 and the first partition of md0, md0p1, is an EFI system partition. Th= en, > the bootloader can be located by the following device > paths: >=20 > PCI()/SATA(sda)/Partition(sda1)/Partition(md0p1)/File(bootloader.efi) > PCI()/SATA(sdb)/Partition(sdb1)/Partition(md0p1)/File(bootloader.efi) >=20 > To make the boot option more resilient, we may create a boot option with > the short-form device path like "Partition(md0p1)/File(bootloader.efi)". >=20 > However, BmMatchPartitionDevicePathNode() only matched the first > partition node and ignored the nested partitions, so the firmware would > refuse to load bootloader.efi since "Partition(md0p1)" doesn't match eith= er > "Partition(sda1)" or "Partition(sda2)". >=20 > This commit modifies BmMatchPartitionDevicePathNode() to iterate all > nested partitions so that the above boot option could work. >=20 > v2 - Simplify the node matching logic >=20 > Cc: Ruiyu Ni > Cc: Star Zeng > Cc: Jian J Wang > Cc: Hao Wu > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Gary Lin > --- > .../Library/UefiBootManagerLib/BmBoot.c | 38 +++++++++---------- > 1 file changed, 17 insertions(+), 21 deletions(-) >=20 > diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > index 6a23477eb873..2284ce1a5646 100644 > --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > @@ -1979,37 +1979,33 @@ BmMatchPartitionDevicePathNode ( > } >=20 > // > - // find the partition device path node > + // Match all the partition device path nodes including the nested > + partition nodes > // > while (!IsDevicePathEnd (BlockIoDevicePath)) { > if ((DevicePathType (BlockIoDevicePath) =3D=3D MEDIA_DEVICE_PATH) && > (DevicePathSubType (BlockIoDevicePath) =3D=3D MEDIA_HARDDRIVE_DP= ) > ) { > - break; > + // > + // See if the harddrive device path in blockio matches the orig Ha= rd Drive > Node > + // > + Node =3D (HARDDRIVE_DEVICE_PATH *) BlockIoDevicePath; > + > + // > + // Match Signature and PartitionNumber. > + // Unused bytes in Signature are initiaized with zeros. > + // > + if ((Node->PartitionNumber =3D=3D HardDriveDevicePath->PartitionNu= mber) > && > + (Node->MBRType =3D=3D HardDriveDevicePath->MBRType) && > + (Node->SignatureType =3D=3D HardDriveDevicePath->SignatureType= ) && > + (CompareMem (Node->Signature, HardDriveDevicePath->Signature, > sizeof (Node->Signature)) =3D=3D 0)) { > + return TRUE; > + } > } >=20 > BlockIoDevicePath =3D NextDevicePathNode (BlockIoDevicePath); > } >=20 > - if (IsDevicePathEnd (BlockIoDevicePath)) { > - return FALSE; > - } > - > - // > - // See if the harddrive device path in blockio matches the orig Hard D= rive > Node > - // > - Node =3D (HARDDRIVE_DEVICE_PATH *) BlockIoDevicePath; > - > - // > - // Match Signature and PartitionNumber. > - // Unused bytes in Signature are initiaized with zeros. > - // > - return (BOOLEAN) ( > - (Node->PartitionNumber =3D=3D HardDriveDevicePath->PartitionNumber) = && > - (Node->MBRType =3D=3D HardDriveDevicePath->MBRType) && > - (Node->SignatureType =3D=3D HardDriveDevicePath->SignatureType) && > - (CompareMem (Node->Signature, HardDriveDevicePath->Signature, > sizeof (Node->Signature)) =3D=3D 0) > - ); > + return FALSE; > } >=20 > /** > -- > 2.20.1