Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 27 Feb 2013 05:01:08 +0000 (UTC)
From:      Benno Rice <benno@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r247380 - projects/uefi/sys/boot/efi/libefi
Message-ID:  <201302270501.r1R519S4011536@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: benno
Date: Wed Feb 27 05:01:08 2013
New Revision: 247380
URL: http://svnweb.freebsd.org/changeset/base/247380

Log:
  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.

Modified:
  projects/uefi/sys/boot/efi/libefi/efipart.c

Modified: projects/uefi/sys/boot/efi/libefi/efipart.c
==============================================================================
--- projects/uefi/sys/boot/efi/libefi/efipart.c	Wed Feb 27 04:55:55 2013	(r247379)
+++ projects/uefi/sys/boot/efi/libefi/efipart.c	Wed Feb 27 05:01:08 2013	(r247380)
@@ -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, *aliases;
+	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;
 
@@ -90,12 +93,38 @@ efipart_init(void) 
 	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);
+			hout[nout] = handle;
+			aliases[nout] = hin[n];
+			if (EFI_ERROR(status))
+				printf("shit\n");
+		} else
+			hout[nout] = hin[n];
 		nout++;
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201302270501.r1R519S4011536>