From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.24; helo=mga09.intel.com; envelope-from=ray.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 E81E7211B6C1A for ; Tue, 22 Jan 2019 19:49:18 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Jan 2019 19:49:18 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,509,1539673200"; d="scan'208";a="293630878" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga005.jf.intel.com with ESMTP; 22 Jan 2019 19:49:18 -0800 Received: from fmsmsx116.amr.corp.intel.com (10.18.116.20) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 22 Jan 2019 19:49:17 -0800 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx116.amr.corp.intel.com (10.18.116.20) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 22 Jan 2019 19:49:17 -0800 Received: from shsmsx103.ccr.corp.intel.com ([169.254.4.150]) by SHSMSX104.ccr.corp.intel.com ([169.254.5.159]) with mapi id 14.03.0415.000; Wed, 23 Jan 2019 11:49:16 +0800 From: "Ni, Ray" To: 'Gary Lin' CC: "'edk2-devel@lists.01.org'" , "Zeng, Star" , "Wang, Jian J" , "Wu, Hao A" Thread-Topic: [PATCH] MdeModulePkg/UefiBootManagerLib: Match the nested partitions Thread-Index: AQHUrLc/dbAL75tJHk2lV7q/514ebqW7fqiAgAAkE4CAAKA/AIAAAUgg Date: Wed, 23 Jan 2019 03:49:16 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BFCFA2E@SHSMSX103.ccr.corp.intel.com> References: <20190115094548.10214-1-glin@suse.com> <734D49CCEBEEF84792F5B80ED585239D5BFCEAA9@SHSMSX103.ccr.corp.intel.com> <20190123021148.GX3972@GaryWorkstation> <734D49CCEBEEF84792F5B80ED585239D5BFCFA08@SHSMSX103.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5BFCFA08@SHSMSX103.ccr.corp.intel.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] 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 03:49:19 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Ni, Ray > Sent: Wednesday, January 23, 2019 11:48 AM > To: 'Gary Lin' > Cc: edk2-devel@lists.01.org; Zeng, Star ; Wang, Jian= J > ; Wu, Hao A > Subject: RE: [PATCH] MdeModulePkg/UefiBootManagerLib: Match the > nested partitions >=20 >=20 >=20 > > -----Original Message----- > > From: Gary Lin > > Sent: Wednesday, January 23, 2019 10:13 AM > > To: Ni, Ray > > Cc: edk2-devel@lists.01.org; Zeng, Star ; Wang, > > Jian J ; Wu, Hao A > > Subject: Re: [PATCH] MdeModulePkg/UefiBootManagerLib: Match the > nested > > partitions > > > > On Tue, Jan 22, 2019 at 04:01:57PM +0000, Ni, Ray wrote: > > > (Send again. Previous mail might be lost.) Gary, > > Hi Ray, > > > > > I have two comments: > > > 1. Do you need to consider the case when the multiple partition > > > nodes > > might not be adjacent? > > In my cases, they are all partitions based on another partition, so > > all those nested partitions are adjacent to the "root" partition. > > > > I'm not sure if it's possible to create the node other than a nested > > partition node or a file node on a partition node. > Sure. Let's just assume the multiple partition nodes are adjacent. >=20 > > > > > 2. Maybe you could recursively call the function itself instead of > > > using a > > loop. In this new way, you might be able to save some code. > > Since my targets are the partition nodes after a partition, loop > > brings a bit better performance by skipping the non-partition node > > check and saves the overhead of function call. > > If you prefer recursive call, I'll modify the patch accordingly. > I just want to avoid having two code blocks to check device path node aga= inst > END and partition node. > First one is in original while(). Second one is introduced by this patch. If we can avoid the duplicated code, using loop is also fine. >=20 > > > > Thanks, > > > > Gary Lin > > > > > > -----Original Message----- > > > > From: Gary Lin > > > > Sent: Tuesday, January 15, 2019 5:46 PM > > > > To: edk2-devel@lists.01.org > > > > Cc: Ni, Ray ; Zeng, Star ; > > > > Wang, Jian J ; Wu, Hao A > > > > > > > > Subject: [PATCH] MdeModulePkg/UefiBootManagerLib: Match the > > nested > > > > partitions > > > > > > > > In some cases, such as MD RAID1 in Linux, the bootloader may be in > > > > a nested EFI system partition partition. For example, sda1 and > > > > sdb1 are combined as md0 and the first partition of md0, md0p1, is > > > > an EFI system partition. Then, the bootloader can be located by > > > > the following device > > > > paths: > > > > > > > > PCI()/SATA(sda)/Partition(sda1)/Partition(md0p1)/File(bootloader.e > > > > fi > > > > ) > > > > PCI()/SATA(sdb)/Partition(sdb1)/Partition(md0p1)/File(bootloader.e > > > > fi > > > > ) > > > > > > > > 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)". > > > > > > > > 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 either "Partition(sda1)" or "Partition(sda2)". > > > > > > > > This commit modifies BmMatchPartitionDevicePathNode() to iterate > > > > all nested partitions so that the above boot option could work. > > > > > > > > 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 | 37 ++++++++++++---= --- > - > > > > 1 file changed, 23 insertions(+), 14 deletions(-) > > > > > > > > diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > > > > b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > > > > index 6a23477eb873..8354c2af674b 100644 > > > > --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > > > > +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBoot.c > > > > @@ -1995,21 +1995,30 @@ BmMatchPartitionDevicePathNode ( > > > > return FALSE; > > > > } > > > > > > > > - // > > > > - // See if the harddrive device path in blockio matches the orig > > > > Hard Drive Node > > > > - // > > > > - Node =3D (HARDDRIVE_DEVICE_PATH *) BlockIoDevicePath; > > > > + do { > > > > + // > > > > + // See if the harddrive device path in blockio matches the > > > > + orig Hard Drive > > > > 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) > > > > - ); > > > > + // > > > > + // Match Signature and PartitionNumber. > > > > + // Unused bytes in Signature are initiaized with zeros. > > > > + // > > > > + if ((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 TRUE; > > > > + } > > > > + > > > > + // See if a nested partition exists > > > > + BlockIoDevicePath =3D NextDevicePathNode (BlockIoDevicePath); > > > > + } while (!IsDevicePathEnd (BlockIoDevicePath) && > > > > + (DevicePathType (BlockIoDevicePath) =3D=3D > > > > + MEDIA_DEVICE_PATH) > > && > > > > + (DevicePathSubType (BlockIoDevicePath) =3D=3D > > > > + MEDIA_HARDDRIVE_DP)); > > > > + > > > > + return FALSE; > > > > } > > > > > > > > /** > > > > -- > > > > 2.20.1 > > > > > >