Index: trunk/i386/libsaio/sys.c =================================================================== --- trunk/i386/libsaio/sys.c (revision 263) +++ trunk/i386/libsaio/sys.c (revision 264) @@ -97,6 +97,12 @@ { 0, 0 } }; +// Pseudo BIOS devices +enum { + kPseudoBIOSDevRAMDisk = 0x100, + kPseudoBIOSDevBooter = 0x101 +}; + /* * Max number of file descriptors. */ @@ -110,10 +116,6 @@ BVRef gBIOSBootVolume = NULL; BVRef gBootVolume; -// zef - ramdisk variables -//extern BVRef gRAMDiskVolume; -//extern bool gRAMDiskBTAliased; - //static BVRef getBootVolumeRef( const char * path, const char ** outPath ); static BVRef newBootVolumeRef( int biosdev, int partno ); @@ -513,17 +515,7 @@ } } } - // turbo - bt(0,0) hook - if ((dp->biosdev + unit) == 0x101) { - // zef - use the ramdisk if available and the alias is active. - if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) { - bvr = gRAMDiskVolume; - } else { - bvr = gBIOSBootVolume; - } - } else { - bvr = newBootVolumeRef(dp->biosdev + unit, partition); - } + bvr = newBootVolumeRef(dp->biosdev + unit, partition); return open_bvr(bvr, path, flags); } } @@ -1014,21 +1006,8 @@ if (*cp == RP) cp++; biosdev = dp->biosdev + unit; + bvr = newBootVolumeRef(biosdev, part); - // turbo - bt(0,0) hook - if (biosdev == 0x101) - { - // zef - use the ramdisk if available and the alias is active. - if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) - bvr = gRAMDiskVolume; - else - bvr = gBIOSBootVolume; - } - else - { - bvr = newBootVolumeRef(biosdev, part); - } - if(bvr == NULL) return NULL; } @@ -1051,29 +1030,46 @@ } //========================================================================== - // Function name is a misnomer as scanBootVolumes usually calls diskScanBootVolumes // which caches the information. So it's only allocated on the first run. static BVRef newBootVolumeRef( int biosdev, int partno ) { - BVRef bvr, bvr1, bvrChain; + BVRef bvr, bvr1, bvrChain; - // Fetch the volume list from the device. + bvr = bvr1 = NULL; - scanBootVolumes( biosdev, NULL ); - bvrChain = getBVChainForBIOSDev(biosdev); + // Try resolving "rd" and "bt" devices first. + if (biosdev == kPseudoBIOSDevRAMDisk) + { + if (gRAMDiskVolume) + bvr1 = gRAMDiskVolume; + } + else if (biosdev == kPseudoBIOSDevBooter) + { + if (gRAMDiskVolume != NULL && gRAMDiskBTAliased) + bvr1 = gRAMDiskVolume; + else + bvr1 = gBIOSBootVolume; + } + else + { + // Fetch the volume list from the device. - // Look for a perfect match based on device and partition number. + scanBootVolumes( biosdev, NULL ); + bvrChain = getBVChainForBIOSDev(biosdev); - for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) - { - if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) continue; - - bvr1 = bvr; - if ( bvr->part_no == partno ) break; - } + // Look for a perfect match based on device and partition number. - return bvr ? bvr : bvr1; + for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next ) + { + if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) continue; + + bvr1 = bvr; + if ( bvr->part_no == partno ) break; + } + } + + return bvr ? bvr : bvr1; } //========================================================================== Index: trunk/i386/boot2/ramdisk.c =================================================================== --- trunk/i386/boot2/ramdisk.c (revision 263) +++ trunk/i386/boot2/ramdisk.c (revision 264) @@ -16,7 +16,6 @@ bool gRAMDiskBTAliased = false; char gRAMDiskFile[512]; - // Notify OS X that a ramdisk has been setup. XNU with attach this to /dev/md0 void md0Ramdisk() { @@ -35,46 +34,36 @@ if(fh < 0) { - if(gRAMDiskVolume && !gRAMDiskBTAliased) - { - sprintf(filename, "rd(0,0)/Extra/%s", override_filename); - fh = open(filename, 0); - } - + sprintf(filename, "rd(0,0)/Extra/%s", override_filename); + fh = open(filename, 0); + if(fh < 0) { sprintf(filename, "/Extra/%s", override_filename); fh = open(filename, 0); - } } } - - + if(fh < 0) { - // Fallback to Postboot.img - if(gRAMDiskVolume && !gRAMDiskBTAliased) - { - sprintf(filename, "rd(0,0)/Extra/Postboot.img"); - fh = open(filename, 0); - } - + sprintf(filename, "rd(0,0)/Extra/Postboot.img"); + fh = open(filename, 0); + if(fh < 0) { sprintf(filename, "/Extra/Postboot.img"); // Check /Extra if not in rd(0,0) fh = open(filename, 0); - } } - + if (fh >= 0) { verbose("Enabling ramdisk %s\n", filename); ramdiskPtr.size = file_size(fh); ramdiskPtr.base = AllocateKernelMemory(ramdiskPtr.size); - + if(ramdiskPtr.size && ramdiskPtr.base) { // Read new ramdisk image contents in kernel memory. @@ -85,232 +74,236 @@ if(node != NULL) { DT__AddProperty(node, "RAMDisk", sizeof(RAMDiskParam), (void*)&ramdiskPtr); - } else { verbose("Unable to notify Mac OS X of the ramdisk %s.\n", filename); } - } - else { + else + { verbose("Unable to read md0 image %s.\n", filename); - } - - } else { + } + } + else + { verbose("md0 image %s is empty.\n", filename); } - - + close(fh); - + } } - void umountRAMDisk() { - if (gRAMDiskMI != NULL) - { - // Release ramdisk BVRef and DiskBVMap. - struct DiskBVMap *oldMap = diskResetBootVolumes(0x100); - CacheReset(); - diskFreeMap(oldMap); - - // Free multiboot info and module structures. - if ((void *)gRAMDiskMI->mi_mods_addr != NULL) free((void *)gRAMDiskMI->mi_mods_addr); - if (gRAMDiskMI != NULL) free(gRAMDiskMI); - - // Reset multiboot structures. - gMI = gRAMDiskMI = NULL; - *gRAMDiskFile = '\0'; + if (gRAMDiskMI != NULL) + { + // Release ramdisk BVRef and DiskBVMap. + struct DiskBVMap *oldMap = diskResetBootVolumes(0x100); + CacheReset(); + diskFreeMap(oldMap); - // Release ramdisk driver hooks. - p_get_ramdisk_info = NULL; - p_ramdiskReadBytes = NULL; - - printf("\nunmounting: done"); - } + // Free multiboot info and module structures. + if ((void *)gRAMDiskMI->mi_mods_addr != NULL) free((void *)gRAMDiskMI->mi_mods_addr); + if (gRAMDiskMI != NULL) free(gRAMDiskMI); + + // Reset multiboot structures. + gMI = gRAMDiskMI = NULL; + *gRAMDiskFile = '\0'; + + // Release ramdisk driver hooks. + p_get_ramdisk_info = NULL; + p_ramdiskReadBytes = NULL; + + // Reset ramdisk bvr + gRAMDiskVolume = NULL; + printf("\nunmounting: done"); + } } int mountRAMDisk(const char * param) { - int fh = 0, ramDiskSize; - int error = 0; + int fh = 0, ramDiskSize; + int error = 0; - // Get file handle for ramdisk file. - fh = open(param, 0); - if (fh != -1) - { - printf("\nreading ramdisk image: %s", param); + // Get file handle for ramdisk file. + fh = open(param, 0); + if (fh != -1) + { + printf("\nreading ramdisk image: %s", param); - ramDiskSize = file_size(fh); - if (ramDiskSize > 0) - { - // Unmount previously mounted image if exists. - umountRAMDisk(); - - // Read new ramdisk image contents into PREBOOT_DATA area. - if (read(fh, (char *)PREBOOT_DATA, ramDiskSize) != ramDiskSize) error = -1; - } - else error = -1; + ramDiskSize = file_size(fh); + if (ramDiskSize > 0) + { + // Unmount previously mounted image if exists. + umountRAMDisk(); - close(fh); - } - else error = -1; - - if (error == 0) - { - // Save filename in gRAMDiskFile to display information. - strcpy(gRAMDiskFile, param); + // Read new ramdisk image contents into PREBOOT_DATA area. + if (read(fh, (char *)PREBOOT_DATA, ramDiskSize) != ramDiskSize) error = -1; + } + else error = -1; - // Set gMI as well for the multiboot ramdisk driver hook. - gMI = gRAMDiskMI = malloc(sizeof(multiboot_info)); - struct multiboot_module * ramdisk_module = malloc(sizeof(multiboot_module)); - - // Fill in multiboot info and module structures. - if (gRAMDiskMI != NULL && ramdisk_module != NULL) - { - gRAMDiskMI->mi_mods_count = 1; - gRAMDiskMI->mi_mods_addr = (uint32_t)ramdisk_module; - ramdisk_module->mm_mod_start = PREBOOT_DATA; - ramdisk_module->mm_mod_end = PREBOOT_DATA + ramDiskSize; - - // Set ramdisk driver hooks. - p_get_ramdisk_info = &multiboot_get_ramdisk_info; - p_ramdiskReadBytes = &multibootRamdiskReadBytes; - - int partCount; // unused - // Save bvr of the mounted image. - gRAMDiskVolume = diskScanBootVolumes(0x100, &partCount); - if(gRAMDiskVolume == NULL) - { - umountRAMDisk(); - printf("\nRamdisk contains no partitions."); - } - else - { - char dirSpec[128]; + close(fh); + } + else error = -1; - // Reading ramdisk configuration. - strcpy(dirSpec, RAMDISKCONFIG_FILENAME); - - if (loadConfigFile(dirSpec, &bootInfo->ramdiskConfig) == 0) - { - getBoolForKey("BTAlias", &gRAMDiskBTAliased, &bootInfo->ramdiskConfig); - } - else - { - printf("\nno ramdisk config...\n"); - } - - printf("\nmounting: done"); - } - } + if (error == 0) + { + // Save filename in gRAMDiskFile to display information. + strcpy(gRAMDiskFile, param); - } - - return error; + // Set gMI as well for the multiboot ramdisk driver hook. + gMI = gRAMDiskMI = malloc(sizeof(multiboot_info)); + struct multiboot_module * ramdisk_module = malloc(sizeof(multiboot_module)); + + // Fill in multiboot info and module structures. + if (gRAMDiskMI != NULL && ramdisk_module != NULL) + { + gRAMDiskMI->mi_mods_count = 1; + gRAMDiskMI->mi_mods_addr = (uint32_t)ramdisk_module; + ramdisk_module->mm_mod_start = PREBOOT_DATA; + ramdisk_module->mm_mod_end = PREBOOT_DATA + ramDiskSize; + + // Set ramdisk driver hooks. + p_get_ramdisk_info = &multiboot_get_ramdisk_info; + p_ramdiskReadBytes = &multibootRamdiskReadBytes; + + int partCount; // unused + // Save bvr of the mounted image. + gRAMDiskVolume = diskScanBootVolumes(0x100, &partCount); + if(gRAMDiskVolume == NULL) + { + umountRAMDisk(); + printf("\nRamdisk contains no partitions."); + } + else + { + char dirSpec[128]; + + // Reading ramdisk configuration. + strcpy(dirSpec, RAMDISKCONFIG_FILENAME); + + if (loadConfigFile(dirSpec, &bootInfo->ramdiskConfig) == 0) + { + getBoolForKey("BTAlias", &gRAMDiskBTAliased, &bootInfo->ramdiskConfig); + } + else + { + printf("\nno ramdisk config...\n"); + } + + printf("\nmounting: done"); + } + } + } + + return error; } void setRAMDiskBTHook(bool mode) { - gRAMDiskBTAliased = mode; - if (mode) { - printf("\nEnabled bt(0,0) alias."); - } else { - printf("\nDisabled bt(0,0) alias."); - } + gRAMDiskBTAliased = mode; + if (mode) + { + printf("\nEnabled bt(0,0) alias."); + } + else + { + printf("\nDisabled bt(0,0) alias."); + } } void showInfoRAMDisk(void) { - int len; - const char *val; + int len; + const char *val; - if (gRAMDiskMI != NULL) - { - struct multiboot_module * ramdisk_module = (void *)gRAMDiskMI->mi_mods_addr; + if (gRAMDiskMI != NULL) + { + struct multiboot_module * ramdisk_module = (void *)gRAMDiskMI->mi_mods_addr; - printf("\nfile: %s %d", gRAMDiskFile, - ramdisk_module->mm_mod_end - ramdisk_module->mm_mod_start); - printf("\nalias: %s", gRAMDiskBTAliased ? "enabled" : "disabled"); + printf("\nfile: %s %d", gRAMDiskFile, + ramdisk_module->mm_mod_end - ramdisk_module->mm_mod_start); + printf("\nalias: %s", gRAMDiskBTAliased ? "enabled" : "disabled"); - // Display ramdisk information if available. - - if (getValueForKey("Info", &val, &len, &bootInfo->ramdiskConfig)) - printf("\ninfo: %s", val); - else - printf("\nramdisk info not available."); - - } - else - { - printf("\nNo ramdisk mounted."); - } + // Display ramdisk information if available. + if (getValueForKey("Info", &val, &len, &bootInfo->ramdiskConfig)) + { + printf("\ninfo: %s", val); + } + else + { + printf("\nramdisk info not available."); + } + } + else + { + printf("\nNo ramdisk mounted."); + } } int loadPrebootRAMDisk() { - mountRAMDisk("bt(0,0)/Extra/Preboot.dmg"); - if (gRAMDiskMI != NULL) - { - printf("\n"); - return 0; - } - else - { - return -1; - } + mountRAMDisk("bt(0,0)/Extra/Preboot.dmg"); + if (gRAMDiskMI != NULL) + { + printf("\n"); + return 0; + } + else + { + return -1; + } } void processRAMDiskCommand(char ** argPtr, const char * cmd) { - char * ptr = *argPtr; - char param[1024]; - getNextArg(&ptr, param); - - if (strcmp(cmd, "m") == 0) - { - mountRAMDisk(param); - sleep(2); - } - else if (strcmp(cmd, "u") == 0) - { - umountRAMDisk(); - sleep(2); - } - else if (strcmp(cmd, "e") == 0) - { - setRAMDiskBTHook(1); - sleep(2); - } - else if (strcmp(cmd, "d") == 0) - { - setRAMDiskBTHook(0); - sleep(2); - } - else if (strcmp(cmd, "i") == 0) - { - setActiveDisplayPage(1); - clearScreenRows(0, 24); - setCursorPosition(0, 0, 1); - showInfoRAMDisk(); - printf("\n\nPress any key to continue.\n"); - getc(); - setActiveDisplayPage(0); - } - else - { - setActiveDisplayPage(1); - clearScreenRows(0, 24); - setCursorPosition(0, 0, 1); - printf("\nusage:\n"); - printf("\n?rd i - display ramdisk information"); - printf("\n?rd m - mount ramdisk image\n?rd u - unmount ramdisk image"); - printf("\n?rd e - enable bt(0,0) alias\n?rd d - disable bt(0,0) alias"); - printf("\n\nPress any key to continue.\n"); - getc(); - setActiveDisplayPage(0); - } + char * ptr = *argPtr; + char param[1024]; + getNextArg(&ptr, param); + + if (strcmp(cmd, "m") == 0) + { + mountRAMDisk(param); + sleep(2); + } + else if (strcmp(cmd, "u") == 0) + { + umountRAMDisk(); + sleep(2); + } + else if (strcmp(cmd, "e") == 0) + { + setRAMDiskBTHook(true); + sleep(2); + } + else if (strcmp(cmd, "d") == 0) + { + setRAMDiskBTHook(false); + sleep(2); + } + else if (strcmp(cmd, "i") == 0) + { + setActiveDisplayPage(1); + clearScreenRows(0, 24); + setCursorPosition(0, 0, 1); + showInfoRAMDisk(); + printf("\n\nPress any key to continue.\n"); + getc(); + setActiveDisplayPage(0); + } + else + { + setActiveDisplayPage(1); + clearScreenRows(0, 24); + setCursorPosition(0, 0, 1); + printf("\nusage:\n"); + printf("\n?rd i - display ramdisk information"); + printf("\n?rd m - mount ramdisk image\n?rd u - unmount ramdisk image"); + printf("\n?rd e - enable bt(0,0) alias\n?rd d - disable bt(0,0) alias"); + printf("\n\nPress any key to continue.\n"); + getc(); + setActiveDisplayPage(0); + } }