On Fri, May 12, 2017 at 07:27:45AM +0200, Michele Curti wrote:
> 
> The efi_device_path_cmp() compares only a path node.
> I tried the following diff just to see if I undestood something, 
> hd0 is now set corrctly to the 29GB disk.
> 
> 
> Index: efiboot/efiboot.c
> ===================================================================
> RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.c,v
> retrieving revision 1.17
> diff -u -p -r1.17 efiboot.c
> --- efiboot/efiboot.c 3 Mar 2017 08:56:18 -0000       1.17
> +++ efiboot/efiboot.c 12 May 2017 05:23:21 -0000
> @@ -233,10 +233,21 @@ efi_device_path_cmp(EFI_DEVICE_PATH *dpa
>       }
>  
>       if (dpt_a && dpt_b) {
> -             cmp = DevicePathNodeLength(dpt_a) - DevicePathNodeLength(dpt_b);
> -             if (cmp)
> -                     return (cmp);
> -             return (memcmp(dpt_a, dpt_b, DevicePathNodeLength(dpt_a)));
> +             for (;!IsDevicePathEnd(dpt_a);) {
> +                     cmp = DevicePathNodeLength(dpt_a) - 
> DevicePathNodeLength(dpt_b);
> +                     if (cmp)
> +                             return (cmp);
> +                     cmp = memcmp(dpt_a, dpt_b, DevicePathNodeLength(dpt_a));
> +                     if (cmp)
> +                             return (cmp);
> +                     dpt_a = NextDevicePathNode(dpt_a);
> +                     dpt_b = NextDevicePathNode(dpt_b);
> +                     cmp = IsDevicePathEnd(dpt_a) - IsDevicePathEnd(dpt_b);
> +                     if (cmp)
> +                             return (cmp);
> +             }
> +
> +             return 0;
>       }
>  
>       return ((uintptr_t)dpt_a - (uintptr_t)dpt_b);

And something like this?


Index: efiboot/efiboot.c
===================================================================
RCS file: /cvs/src/sys/arch/amd64/stand/efiboot/efiboot.c,v
retrieving revision 1.17
diff -u -p -r1.17 efiboot.c
--- efiboot/efiboot.c   3 Mar 2017 08:56:18 -0000       1.17
+++ efiboot/efiboot.c   12 May 2017 07:02:10 -0000
@@ -52,7 +52,7 @@ static EFI_GUID                blkio_guid = BLOCK_IO_
 static EFI_GUID                 devp_guid = DEVICE_PATH_PROTOCOL;
 u_long                  efi_loadaddr;
 
-static int      efi_device_path_cmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *, int);
+static int      efi_device_path_cmp(EFI_DEVICE_PATH *, EFI_DEVICE_PATH *);
 static void     efi_heap_init(void);
 static void     efi_memprobe_internal(void);
 static void     efi_video_init(void);
@@ -199,9 +199,7 @@ efi_diskprobe(void)
                    (void **)&dp);
                if (EFI_ERROR(status))
                        goto next;
-               if (!efi_device_path_cmp(efi_bootdp, dp, HARDWARE_DEVICE_PATH)&&
-                   !efi_device_path_cmp(efi_bootdp, dp, ACPI_DEVICE_PATH) &&
-                   !efi_device_path_cmp(efi_bootdp, dp, MESSAGING_DEVICE_PATH))
+               if (efi_device_path_cmp(efi_bootdp, dp) == 0)
                        bootdev = 1;
 next:
                if (bootdev)
@@ -214,32 +212,29 @@ next:
 }
 
 static int
-efi_device_path_cmp(EFI_DEVICE_PATH *dpa, EFI_DEVICE_PATH *dpb, int dptype)
+efi_device_path_cmp(EFI_DEVICE_PATH *dpa, EFI_DEVICE_PATH *dpb)
 {
-       int              cmp;
-       EFI_DEVICE_PATH *dp, *dpt_a = NULL, *dpt_b = NULL;
+       int cmp;
 
-       for (dp = dpa; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
-               if (DevicePathType(dp) == dptype) {
-                       dpt_a = dp;
-                       break;
-               }
-       }
-       for (dp = dpb; !IsDevicePathEnd(dp); dp = NextDevicePathNode(dp)) {
-               if (DevicePathType(dp) == dptype) {
-                       dpt_b = dp;
-                       break;
-               }
-       }
-
-       if (dpt_a && dpt_b) {
-               cmp = DevicePathNodeLength(dpt_a) - DevicePathNodeLength(dpt_b);
-               if (cmp)
-                       return (cmp);
-               return (memcmp(dpt_a, dpt_b, DevicePathNodeLength(dpt_a)));
-       }
+       cmp = IsDevicePathEnd(dpa) - IsDevicePathEnd(dpb);
+       if (cmp)
+               return cmp;
+       if (IsDevicePathEnd(dpa))
+               return 0;
+       cmp = DevicePathType(dpa) - DevicePathType(dpb);
+       if (cmp)
+               return cmp;
+       cmp = DevicePathSubType(dpa) - DevicePathSubType(dpb);
+       if (cmp)
+               return cmp;
+       cmp = DevicePathNodeLength(dpa) - DevicePathNodeLength(dpb);
+       if (cmp)
+               return cmp;
+       cmp = memcmp(dpa, dpb, DevicePathNodeLength(dpa));
+       if (cmp)
+               return cmp;
 
-       return ((uintptr_t)dpt_a - (uintptr_t)dpt_b);
+       return efi_device_path_cmp(NextDevicePathNode(dpa), 
NextDevicePathNode(dpb));
 }
 
 /***********************************************************************

Reply via email to