Add support for finding the boot priority of USB drives.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 31 Dec 2010 19:38:10 +0000 (14:38 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 1 Jan 2011 16:01:19 +0000 (11:01 -0500)
Use the device path of the USB device to find a bootorder entry.

src/boot.c
src/boot.h
src/usb-msc.c

index 2e2aea59c1561022ca9be16c4bb9b7eb7a81e232..e5475a2f2f75e98eff75951fb4615d39d7f4a49d 100644 (file)
@@ -162,6 +162,21 @@ int bootprio_find_named_rom(const char *name, int instance)
     return find_prio(desc);
 }
 
+int bootprio_find_usb(int bdf, u64 path)
+{
+    // Find usb - for example: /pci@i0cf8/usb@1,2/hub@1/network@0/ethernet@0
+    int i;
+    char desc[256], *p;
+    p = build_pci_path(desc, sizeof(desc), "usb", bdf);
+    for (i=56; i>0; i-=8) {
+        int port = (path >> i) & 0xff;
+        if (port != 0xff)
+            p += snprintf(p, desc+sizeof(desc)-p, "/hub@%x", port);
+    }
+    snprintf(p, desc+sizeof(desc)-p, "/*@%x", (u32)(path & 0xff));
+    return find_prio(desc);
+}
+
 
 /****************************************************************
  * Boot setup
index 8f56ccf1de751547152d6608207c9d489a92c373..62f4b2b8db6ddb3e9d181ca8ceae7d7f39ad5124 100644 (file)
@@ -15,8 +15,9 @@ void boot_add_cbfs(void *data, const char *desc, int prio);
 void boot_prep(void);
 int bootprio_find_pci_device(int bdf);
 int bootprio_find_ata_device(int bdf, int chanid, int slave);
-int bootprio_find_fdc_device(int bfd, int port, int fdid);
+int bootprio_find_fdc_device(int bdf, int port, int fdid);
 int bootprio_find_pci_rom(int bdf, int instance);
 int bootprio_find_named_rom(const char *name, int instance);
+int bootprio_find_usb(int bdf, u64 path);
 
 #endif // __BOOT_H
index d5fe7bad95803bc69523f1083034d97c210e83fb..58a5d144ae5d7d02026345314166757c74671690 100644 (file)
@@ -143,7 +143,10 @@ setup_drive_cdrom(struct disk_op_s *op, char *desc)
 {
     op->drive_g->blksize = CDROM_SECTOR_SIZE;
     op->drive_g->sectors = (u64)-1;
-    boot_add_cd(op->drive_g, desc, -1);
+    struct usb_pipe *pipe = container_of(
+        op->drive_g, struct usbdrive_s, drive)->bulkout;
+    int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
+    boot_add_cd(op->drive_g, desc, prio);
     return 0;
 }
 
@@ -168,7 +171,10 @@ setup_drive_hd(struct disk_op_s *op, char *desc)
     dprintf(1, "USB MSC blksize=%d sectors=%d\n", blksize, sectors);
 
     // Register with bcv system.
-    boot_add_hd(op->drive_g, desc, -1);
+    struct usb_pipe *pipe = container_of(
+        op->drive_g, struct usbdrive_s, drive)->bulkout;
+    int prio = bootprio_find_usb(pipe->cntl->bdf, pipe->path);
+    boot_add_hd(op->drive_g, desc, prio);
 
     return 0;
 }