From 7da1dcd03e3fc3a187c7222178a220fcb074b055 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Mon, 16 Feb 2009 10:51:24 -0500 Subject: [PATCH] Enhance boot menu to allow user to select which CD drive to boot from. --- src/boot.c | 28 +++++++++++++++++++--------- src/boot.h | 2 +- src/cdrom.c | 43 +++++++++++-------------------------------- src/disk.h | 2 +- 4 files changed, 32 insertions(+), 43 deletions(-) diff --git a/src/boot.c b/src/boot.c index 404b043..6b4e985 100644 --- a/src/boot.c +++ b/src/boot.c @@ -48,7 +48,6 @@ boot_setup() } IPL.bevcount = ie - IPL.bev; - IPL.bcv_override = -1; SET_EBDA(boot_sequence, 0xffff); if (CONFIG_COREBOOT) { // XXX - hardcode defaults for coreboot. @@ -148,7 +147,7 @@ menu_show_harddisk(struct ipl_entry_s *ie, int menupos) switch (ie->type) { case IPL_TYPE_HARDDISK: printf("%d. ata%d-%d %s\n", menupos + i - , ie->vector / 2, ie->vector %2, ie->description); + , ie->vector / 2, ie->vector % 2, ie->description); break; default: menu_show_default(ie, menupos+i); @@ -162,9 +161,13 @@ menu_show_harddisk(struct ipl_entry_s *ie, int menupos) static int menu_show_cdrom(struct ipl_entry_s *ie, int menupos) { - if (!ATA.cdcount) - return 0; - return menu_show_default(ie, menupos); + int i; + for (i = 0; i < ATA.cdcount; i++) { + int driveid = ATA.idmap[1][i]; + printf("%d. CD-Rom [ata%d-%d %s]\n", menupos + i + , driveid / 2, driveid % 2, ATA.devices[driveid].model); + } + return ATA.cdcount; } // Show IPL option menu. @@ -229,9 +232,16 @@ interactive_bootmenu() bev++; } - // A harddrive request enables a BCV order. - if (IPL.bev[bev].type == IPL_TYPE_HARDDISK) + switch (IPL.bev[bev].type) { + case IPL_TYPE_HARDDISK: + // A harddrive request enables a BCV order. IPL.bcv_override = choice-1; + break; + case IPL_TYPE_CDROM: + // Select cdrom to boot from. + IPL.cdrom_override = choice-1; + break; + } // Add user choice to the boot order. IPL.bootorder = (IPL.bootorder << 4) | (bev+1); @@ -266,7 +276,7 @@ boot_prep() // Run BCVs int override = IPL.bcv_override; - if (override >= 0) + if (override < IPL.bcvcount) run_bcv(&IPL.bcv[override]); int i; for (i=0; i= CONFIG_MAX_ATA_DEVICES) - return 0; - - if (GET_GLOBAL(ATA.devices[device].type) != ATA_TYPE_ATAPI) - return 0; - - if (GET_GLOBAL(ATA.devices[device].device) != ATA_DEVICE_CDROM) - return 0; - - return 1; -} - // Compare a string on the stack to one in the code segment. static int streq_cs(u8 *s1, char *cs_s2) @@ -420,25 +405,23 @@ streq_cs(u8 *s1, char *cs_s2) } int -cdrom_boot() +cdrom_boot(int cdid) { - // Find out the first cdrom - u8 device; - for (device=0; device= CONFIG_MAX_ATA_DEVICES) - // cdrom not found + // Verify device is a cdrom. + if (cdid >= ATA.cdcount) + return 1; + int driveid = GET_GLOBAL(ATA.idmap[1][cdid]); + if (GET_GLOBAL(ATA.devices[driveid].device) != ATA_DEVICE_CDROM) return 2; - int ret = atapi_is_ready(device); + int ret = atapi_is_ready(driveid); if (ret) dprintf(1, "atapi_is_ready returned %d\n", ret); // Read the Boot Record Volume Descriptor u8 buffer[2048]; struct disk_op_s dop; - dop.driveid = device; + dop.driveid = driveid; dop.lba = 0x11; dop.count = 1; dop.buf_fl = MAKE_FLATPTR(GET_SEG(SS), buffer); @@ -479,8 +462,8 @@ cdrom_boot() u8 media = buffer[0x21]; SET_EBDA2(ebda_seg, cdemu.media, media); - SET_EBDA2(ebda_seg, cdemu.controller_index, device/2); - SET_EBDA2(ebda_seg, cdemu.device_spec, device%2); + SET_EBDA2(ebda_seg, cdemu.controller_index, driveid/2); + SET_EBDA2(ebda_seg, cdemu.device_spec, driveid%2); u16 boot_segment = *(u16*)&buffer[0x22]; if (!boot_segment) @@ -504,11 +487,7 @@ cdrom_boot() if (media == 0) { // No emulation requested - return success. - - // FIXME ElTorito Hardcoded. cdrom is hardcoded as device 0xE0. - // Win2000 cd boot needs to know it booted from cd - SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0xE0); - + SET_EBDA2(ebda_seg, cdemu.emulated_drive, 0xE0 + cdid); return 0; } diff --git a/src/disk.h b/src/disk.h index 2774cde..3661d27 100644 --- a/src/disk.h +++ b/src/disk.h @@ -230,6 +230,6 @@ void disk_13XX(struct bregs *regs, u8 device); void cdrom_13(struct bregs *regs, u8 device); void cdemu_13(struct bregs *regs); void cdemu_134b(struct bregs *regs); -int cdrom_boot(); +int cdrom_boot(int cdid); #endif // disk.h -- 2.25.1