Signed-off-by: Gleb Natapov gleb@redhat.com --- src/boot.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/src/boot.c b/src/boot.c index 5c35555..e754930 100644 --- a/src/boot.c +++ b/src/boot.c @@ -379,6 +379,41 @@ run_bcv(struct ipl_entry_s *ie) } }
+/* Bubble sort! Should be good enough for 8 elements */ +static void sort_ipls(struct ipl_entry_s *ipls, int iplscount) +{ + int stop; + + if (iplscount == 0) + return; + + do { + int i; + stop = 1; + for (i = 0; i < iplscount - 1; i++) { + if (ipls[i].prio > ipls[i+1].prio) { + struct ipl_entry_s tmp; + tmp = ipls[i]; + ipls[i] = ipls[i+1]; + ipls[i+1] = tmp; + stop = 0; + } + } + } while (!stop); +} + +static void order_boot_devices(void) +{ + if (IPL.fw_bootorder_count == 0) + return; + + sort_ipls(IPL.bcv, IPL.bcvcount); + /* Hard disk IPL inherits priority of the bootable bcv */ + IPL.bev[1].prio = IPL.bcv[0].prio; + sort_ipls(IPL.bev, IPL.bevcount); + IPL.bootorder = 0x87654321; +} + // Prepare for boot - show menu and run bcvs. void boot_prep(void) @@ -390,24 +425,38 @@ boot_prep(void)
// XXX - show available drives?
+ order_boot_devices(); + // Allow user to modify BCV/IPL order. interactive_bootmenu(); wait_threads();
- // Setup floppy boot order - int override = IPL.bev[0].subchoice; - struct drive_s *tmp = Drives.idmap[EXTTYPE_FLOPPY][0]; - Drives.idmap[EXTTYPE_FLOPPY][0] = Drives.idmap[EXTTYPE_FLOPPY][override]; - Drives.idmap[EXTTYPE_FLOPPY][override] = tmp; - - // Run BCVs - override = IPL.bev[1].subchoice; - if (override < IPL.bcvcount) - run_bcv(&IPL.bcv[override]); - int i; - for (i=0; i<IPL.bcvcount; i++) - if (i != override) - run_bcv(&IPL.bcv[i]); + int j; + for (j = 0; j < IPL.bevcount; j++) { + int override; + switch (IPL.bev[j].type) { + case IPL_TYPE_FLOPPY: + // Setup floppy boot order + override = IPL.bev[j].subchoice; + struct drive_s *tmp = Drives.idmap[EXTTYPE_FLOPPY][0]; + Drives.idmap[EXTTYPE_FLOPPY][0] = + Drives.idmap[EXTTYPE_FLOPPY][override]; + Drives.idmap[EXTTYPE_FLOPPY][override] = tmp; + break; + case IPL_TYPE_HARDDISK: + // Run BCVs + override = IPL.bev[j].subchoice; + if (override < IPL.bcvcount) + run_bcv(&IPL.bcv[override]); + int i; + for (i=0; i<IPL.bcvcount; i++) + if (i != override) + run_bcv(&IPL.bcv[i]); + break; + default: + break; + } + } }