From owner-svn-src-projects@FreeBSD.ORG Wed Feb 27 05:01:09 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3C59D516; Wed, 27 Feb 2013 05:01:09 +0000 (UTC) (envelope-from benno@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 20E3F976; Wed, 27 Feb 2013 05:01:09 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1R519ix011537; Wed, 27 Feb 2013 05:01:09 GMT (envelope-from benno@svn.freebsd.org) Received: (from benno@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1R519S4011536; Wed, 27 Feb 2013 05:01:09 GMT (envelope-from benno@svn.freebsd.org) Message-Id: <201302270501.r1R519S4011536@svn.freebsd.org> From: Benno Rice Date: Wed, 27 Feb 2013 05:01:08 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r247380 - projects/uefi/sys/boot/efi/libefi X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Feb 2013 05:01:09 -0000 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 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++; }