From: "Ni, Ray" <ray.ni@intel.com>
To: 'Gary Lin' <glin@suse.com>,
"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>
Cc: "Zeng, Star" <star.zeng@intel.com>,
"Wang, Jian J" <jian.j.wang@intel.com>,
"Wu, Hao A" <hao.a.wu@intel.com>
Subject: Re: [PATCH] MdeModulePkg/UefiBootManagerLib: Match the nested partitions
Date: Tue, 22 Jan 2019 16:01:57 +0000 [thread overview]
Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BFCEAA9@SHSMSX103.ccr.corp.intel.com> (raw)
In-Reply-To: <20190115094548.10214-1-glin@suse.com>
(Send again. Previous mail might be lost.)
Gary,
I have two comments:
1. Do you need to consider the case when the multiple partition nodes might not be adjacent?
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.
> -----Original Message-----
> From: Gary Lin <glin@suse.com>
> Sent: Tuesday, January 15, 2019 5:46 PM
> To: edk2-devel@lists.01.org
> Cc: Ni, Ray <ray.ni@intel.com>; Zeng, Star <star.zeng@intel.com>; Wang, Jian J
> <jian.j.wang@intel.com>; Wu, Hao A <hao.a.wu@intel.com>
> 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.efi)
> PCI()/SATA(sdb)/Partition(sdb1)/Partition(md0p1)/File(bootloader.efi)
>
> 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 <ruiyu.ni@intel.com>
> Cc: Star Zeng <star.zeng@intel.com>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao Wu <hao.a.wu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Gary Lin <glin@suse.com>
> ---
> .../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 = (HARDDRIVE_DEVICE_PATH *) BlockIoDevicePath;
> + do {
> + //
> + // See if the harddrive device path in blockio matches the orig Hard Drive
> Node
> + //
> + Node = (HARDDRIVE_DEVICE_PATH *) BlockIoDevicePath;
>
> - //
> - // Match Signature and PartitionNumber.
> - // Unused bytes in Signature are initiaized with zeros.
> - //
> - return (BOOLEAN) (
> - (Node->PartitionNumber == HardDriveDevicePath->PartitionNumber) &&
> - (Node->MBRType == HardDriveDevicePath->MBRType) &&
> - (Node->SignatureType == HardDriveDevicePath->SignatureType) &&
> - (CompareMem (Node->Signature, HardDriveDevicePath->Signature, sizeof
> (Node->Signature)) == 0)
> - );
> + //
> + // Match Signature and PartitionNumber.
> + // Unused bytes in Signature are initiaized with zeros.
> + //
> + if ((Node->PartitionNumber == HardDriveDevicePath->PartitionNumber) &&
> + (Node->MBRType == HardDriveDevicePath->MBRType) &&
> + (Node->SignatureType == HardDriveDevicePath->SignatureType) &&
> + (CompareMem (Node->Signature, HardDriveDevicePath->Signature, sizeof
> (Node->Signature)) == 0)) {
> + return TRUE;
> + }
> +
> + // See if a nested partition exists
> + BlockIoDevicePath = NextDevicePathNode (BlockIoDevicePath); }
> + while (!IsDevicePathEnd (BlockIoDevicePath) &&
> + (DevicePathType (BlockIoDevicePath) == MEDIA_DEVICE_PATH) &&
> + (DevicePathSubType (BlockIoDevicePath) ==
> + MEDIA_HARDDRIVE_DP));
> +
> + return FALSE;
> }
>
> /**
> --
> 2.20.1
next prev parent reply other threads:[~2019-01-22 16:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-15 9:45 [PATCH] MdeModulePkg/UefiBootManagerLib: Match the nested partitions Gary Lin
2019-01-15 11:58 ` Laszlo Ersek
2019-01-16 2:16 ` Gary Lin
2019-01-16 9:02 ` Laszlo Ersek
2019-01-22 16:01 ` Ni, Ray [this message]
2019-01-23 2:12 ` Gary Lin
2019-01-23 3:48 ` Ni, Ray
2019-01-23 3:49 ` Ni, Ray
2019-01-23 4:02 ` Gary Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=734D49CCEBEEF84792F5B80ED585239D5BFCEAA9@SHSMSX103.ccr.corp.intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox