From owner-svn-src-head@FreeBSD.ORG Thu Apr 3 21:40:00 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 60D7B95A; Thu, 3 Apr 2014 21:40:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4CD40195; Thu, 3 Apr 2014 21:40:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s33Le0Wl005793; Thu, 3 Apr 2014 21:40:00 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s33LdxnT005742; Thu, 3 Apr 2014 21:39:59 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201404032139.s33LdxnT005742@svn.freebsd.org> From: Ed Maste Date: Thu, 3 Apr 2014 21:39:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r264088 - in head/sys/boot/efi: include libefi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Apr 2014 21:40:00 -0000 Author: emaste Date: Thu Apr 3 21:39:59 2014 New Revision: 264088 URL: http://svnweb.freebsd.org/changeset/base/264088 Log: 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. Modified: head/sys/boot/efi/include/efilib.h head/sys/boot/efi/libefi/efinet.c head/sys/boot/efi/libefi/efipart.c head/sys/boot/efi/libefi/handles.c Modified: head/sys/boot/efi/include/efilib.h ============================================================================== --- head/sys/boot/efi/include/efilib.h Thu Apr 3 21:18:03 2014 (r264087) +++ head/sys/boot/efi/include/efilib.h Thu Apr 3 21:39:59 2014 (r264088) @@ -41,7 +41,7 @@ extern struct netif_driver efinetif; void *efi_get_table(EFI_GUID *tbl); void efi_main(EFI_HANDLE image_handle, EFI_SYSTEM_TABLE *system_table); -int efi_register_handles(struct devsw *, EFI_HANDLE *, int); +int efi_register_handles(struct devsw *, EFI_HANDLE *, EFI_HANDLE *, int); EFI_HANDLE efi_find_handle(struct devsw *, int); int efi_handle_lookup(EFI_HANDLE, struct devsw **, int *); Modified: head/sys/boot/efi/libefi/efinet.c ============================================================================== --- head/sys/boot/efi/libefi/efinet.c Thu Apr 3 21:18:03 2014 (r264087) +++ head/sys/boot/efi/libefi/efinet.c Thu Apr 3 21:39:59 2014 (r264088) @@ -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); Modified: head/sys/boot/efi/libefi/efipart.c ============================================================================== --- head/sys/boot/efi/libefi/efipart.c Thu Apr 3 21:18:03 2014 (r264087) +++ head/sys/boot/efi/libefi/efipart.c Thu Apr 3 21:39:59 2014 (r264088) @@ -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; + 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); } Modified: head/sys/boot/efi/libefi/handles.c ============================================================================== --- head/sys/boot/efi/libefi/handles.c Thu Apr 3 21:18:03 2014 (r264087) +++ head/sys/boot/efi/libefi/handles.c Thu Apr 3 21:39:59 2014 (r264088) @@ -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, E 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 d 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;