From 36e02f255607caeea61d91ebaa9ddac55595a107 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Mon, 31 Jul 2017 14:04:54 +0000 Subject: Back out previous commit but handle the case where the device path consists of a single MEDIA_DEVICE_PATH component specially to cater for U-Boot's somewhat broken device path handling. Add comments to prevent confusion in the future. Bump the version number once again. ok brynet@ --- sys/arch/amd64/stand/efiboot/conf.c | 4 ++-- sys/arch/amd64/stand/efiboot/efiboot.c | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'sys/arch') diff --git a/sys/arch/amd64/stand/efiboot/conf.c b/sys/arch/amd64/stand/efiboot/conf.c index ba75269acc6..1c82abe5f48 100644 --- a/sys/arch/amd64/stand/efiboot/conf.c +++ b/sys/arch/amd64/stand/efiboot/conf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conf.c,v 1.9 2017/07/29 19:52:29 kettenis Exp $ */ +/* $OpenBSD: conf.c,v 1.10 2017/07/31 14:04:52 kettenis Exp $ */ /* * Copyright (c) 1996 Michael Shalayeff @@ -38,7 +38,7 @@ #include "efiboot.h" #include "efidev.h" -const char version[] = "3.34"; +const char version[] = "3.35"; #ifdef EFI_DEBUG int debug = 0; diff --git a/sys/arch/amd64/stand/efiboot/efiboot.c b/sys/arch/amd64/stand/efiboot/efiboot.c index 4114f9137b5..0ff0f53fc50 100644 --- a/sys/arch/amd64/stand/efiboot/efiboot.c +++ b/sys/arch/amd64/stand/efiboot/efiboot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: efiboot.c,v 1.21 2017/07/29 19:52:29 kettenis Exp $ */ +/* $OpenBSD: efiboot.c,v 1.22 2017/07/31 14:04:53 kettenis Exp $ */ /* * Copyright (c) 2015 YASUOKA Masahiko @@ -185,6 +185,15 @@ efi_diskprobe(void) if (efi_bootdp != NULL) depth = efi_device_path_depth(efi_bootdp, MEDIA_DEVICE_PATH); + /* + * U-Boot incorrectly represents devices with a single + * MEDIA_DEVICE_PATH component. In that case include that + * component into the matching, otherwise we'll blindly select + * the first device. + */ + if (depth == 0) + depth = 1; + for (i = 0; i < sz / sizeof(EFI_HANDLE); i++) { status = EFI_CALL(BS->HandleProtocol, handles[i], &blkio_guid, (void **)&blkio); @@ -215,6 +224,10 @@ next: free(handles, sz); } +/* + * Determine the number of nodes up to, but not including, the first + * node of the specified type. + */ static int efi_device_path_depth(EFI_DEVICE_PATH *dp, int dptype) { @@ -222,7 +235,7 @@ efi_device_path_depth(EFI_DEVICE_PATH *dp, int dptype) for (i = 0; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp), i++) { if (DevicePathType(dp) == dptype) - return (i + 1); + return (i); } return (-1); -- cgit v1.2.3