summaryrefslogtreecommitdiffstats
path: root/sys/boot/efi/libefi
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2014-04-03 21:39:59 +0000
committeremaste <emaste@FreeBSD.org>2014-04-03 21:39:59 +0000
commit2c5d789700e0e7fadcc4c2957e40806303e165ae (patch)
tree988a2e8ffd6eae8e98a10af6e64d5e6b8e25881d /sys/boot/efi/libefi
parent0470c71c03439e9219b8148ad52729fbd805a336 (diff)
downloadFreeBSD-src-2c5d789700e0e7fadcc4c2957e40806303e165ae.zip
FreeBSD-src-2c5d789700e0e7fadcc4c2957e40806303e165ae.tar.gz
Merge efilib changes from projects/uefi
r247216: Add the ability for a device to have an "alias" handle. r247379: Fix network device registration. r247380: Adjust our load device when we boot from CD under UEFI. The process for booting from a CD under UEFI involves adding a FAT filesystem containing your loader code as an El Torito boot image. When UEFI detects this, it provides a block IO instance that points at the FAT filesystem as a child of the device that represents the CD itself. The problem being that the CD device is flagged as a "raw device" while the boot image is flagged as a "logical partition". The existing EFI partition code only looks for logical partitions and so the CD filesystem was rendered invisible. To fix this, check the type of each block IO device. If it's found to be a CD, and thus an El Torito boot image, look up its parent device and add that instead so that the loader will then load the kernel from the CD filesystem. This is done by using the handle for the boot filesystem as an alias. Something similar to this will be required for booting from other media as well as the loader will live in the EFI system partition, not on the partition containing the kernel. r247381: Remove a scatalogical debug printf that crept in.
Diffstat (limited to 'sys/boot/efi/libefi')
-rw-r--r--sys/boot/efi/libefi/efinet.c2
-rw-r--r--sys/boot/efi/libefi/efipart.c40
-rw-r--r--sys/boot/efi/libefi/handles.c10
3 files changed, 45 insertions, 7 deletions
diff --git a/sys/boot/efi/libefi/efinet.c b/sys/boot/efi/libefi/efinet.c
index 5b3e401..3f08ed2 100644
--- a/sys/boot/efi/libefi/efinet.c
+++ b/sys/boot/efi/libefi/efinet.c
@@ -274,7 +274,7 @@ efinet_dev_init()
if (EFI_ERROR(status))
return (efi_status_to_errno(status));
nifs = sz / sizeof(EFI_HANDLE);
- err = efi_register_handles(&efinet_dev, handles, nifs);
+ err = efi_register_handles(&efinet_dev, handles, NULL, nifs);
free(handles);
if (err != 0)
return (err);
diff --git a/sys/boot/efi/libefi/efipart.c b/sys/boot/efi/libefi/efipart.c
index 264a2a4..d170c86 100644
--- a/sys/boot/efi/libefi/efipart.c
+++ b/sys/boot/efi/libefi/efipart.c
@@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
#include <efiprot.h>
static EFI_GUID blkio_guid = BLOCK_IO_PROTOCOL;
+static EFI_GUID devpath_guid = DEVICE_PATH_PROTOCOL;
static int efipart_init(void);
static int efipart_strategy(void *, int, daddr_t, size_t, char *, size_t *);
@@ -62,9 +63,11 @@ static int
efipart_init(void)
{
EFI_BLOCK_IO *blkio;
- EFI_HANDLE *hin, *hout;
+ EFI_DEVICE_PATH *devpath, *node;
+ EFI_HANDLE *hin, *hout, *aliases, handle;
EFI_STATUS status;
UINTN sz;
+ CHAR16 *path;
u_int n, nin, nout;
int err;
@@ -72,7 +75,7 @@ efipart_init(void)
hin = NULL;
status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0);
if (status == EFI_BUFFER_TOO_SMALL) {
- hin = (EFI_HANDLE *)malloc(sz * 2);
+ hin = (EFI_HANDLE *)malloc(sz * 3);
status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz,
hin);
if (EFI_ERROR(status))
@@ -84,19 +87,48 @@ efipart_init(void)
/* Filter handles to only include FreeBSD partitions. */
nin = sz / sizeof(EFI_HANDLE);
hout = hin + nin;
+ aliases = hout + nin;
nout = 0;
+ bzero(aliases, nin * sizeof(EFI_HANDLE));
+
for (n = 0; n < nin; n++) {
+ status = BS->HandleProtocol(hin[n], &devpath_guid, &devpath);
+ if (EFI_ERROR(status)) {
+ continue;
+ }
+ node = devpath;
+ while (!IsDevicePathEnd(NextDevicePathNode(node)))
+ node = NextDevicePathNode(node);
status = BS->HandleProtocol(hin[n], &blkio_guid, &blkio);
if (EFI_ERROR(status))
continue;
if (!blkio->Media->LogicalPartition)
continue;
- hout[nout] = hin[n];
+
+ /*
+ * If we come across a logical partition of subtype CDROM
+ * it doesn't refer to the CD filesystem itself, but rather
+ * to any usable El Torito boot image on it. In this case
+ * we try to find the parent device and add that instead as
+ * that will be the CD filesystem.
+ */
+ if (DevicePathType(node) == MEDIA_DEVICE_PATH &&
+ DevicePathSubType(node) == MEDIA_CDROM_DP) {
+ node->Type = END_DEVICE_PATH_TYPE;
+ node->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ status = BS->LocateDevicePath(&blkio_guid, &devpath,
+ &handle);
+ if (EFI_ERROR(status))
+ continue;
+ hout[nout] = handle;
+ aliases[nout] = hin[n];
+ } else
+ hout[nout] = hin[n];
nout++;
}
- err = efi_register_handles(&efipart_dev, hout, nout);
+ err = efi_register_handles(&efipart_dev, hout, aliases, nout);
free(hin);
return (err);
}
diff --git a/sys/boot/efi/libefi/handles.c b/sys/boot/efi/libefi/handles.c
index 7c78a15..b15c0a5 100644
--- a/sys/boot/efi/libefi/handles.c
+++ b/sys/boot/efi/libefi/handles.c
@@ -32,6 +32,7 @@ __FBSDID("$FreeBSD$");
struct entry {
EFI_HANDLE handle;
+ EFI_HANDLE alias;
struct devsw *dev;
int unit;
};
@@ -40,7 +41,8 @@ struct entry *entry;
int nentries;
int
-efi_register_handles(struct devsw *sw, EFI_HANDLE *handles, int count)
+efi_register_handles(struct devsw *sw, EFI_HANDLE *handles,
+ EFI_HANDLE *aliases, int count)
{
size_t sz;
int idx, unit;
@@ -51,6 +53,10 @@ efi_register_handles(struct devsw *sw, EFI_HANDLE *handles, int count)
entry = (entry == NULL) ? malloc(sz) : realloc(entry, sz);
for (unit = 0; idx < nentries; idx++, unit++) {
entry[idx].handle = handles[unit];
+ if (aliases != NULL)
+ entry[idx].alias = aliases[unit];
+ else
+ entry[idx].alias = NULL;
entry[idx].dev = sw;
entry[idx].unit = unit;
}
@@ -78,7 +84,7 @@ efi_handle_lookup(EFI_HANDLE h, struct devsw **dev, int *unit)
int idx;
for (idx = 0; idx < nentries; idx++) {
- if (entry[idx].handle != h)
+ if (entry[idx].handle != h && entry[idx].alias != h)
continue;
if (dev != NULL)
*dev = entry[idx].dev;
OpenPOWER on IntegriCloud