Index: branches/ErmaC/Enoch/i386/libsaio/bootstruct.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/bootstruct.c (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/bootstruct.c (revision 2564) @@ -119,7 +119,7 @@ void reserveKernBootStruct(void) { - if ( LION || MOUNTAIN_LION || MAVERICKS || YOSEMITE ) + if ( MacOSVerCurrent >= MacOSVer2Int("10.7") ) // OS X 10.7 and newer { // for 10.7 10.8 10.9 10.10 void *oldAddr = bootArgs; Index: branches/ErmaC/Enoch/i386/libsaio/bootargs.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/bootargs.h (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/bootargs.h (revision 2564) @@ -222,6 +222,4 @@ } boot_args_pre_lion; -extern char gMacOSVersion[8]; - #endif /* _PEXPERT_I386_BOOT_H */ Index: branches/ErmaC/Enoch/i386/libsaio/sys.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/sys.c (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/sys.c (revision 2564) @@ -374,12 +374,16 @@ return -1; } - // Return 0 on success, or -1 if there are no additional entries. + if (bvr->fs_getdirentry) + { + // Returns 0 on success or -1 when there are no additional entries. + return bvr->fs_getdirentry( bvr, + /* dirPath */ (char *)dirPath, + /* dirIndex */ dirIndex, + /* dirEntry */ (char **)name, flags, time, 0, 0 ); + } - return bvr->fs_getdirentry( bvr, - /* dirPath */ (char *)dirPath, - /* dirIndex */ dirIndex, - /* dirEntry */ (char **)name, flags, time, 0, 0 ); + return -1; } //========================================================================== @@ -953,7 +957,12 @@ { bool filteredChain = false; bool foundPrimary = false; - BVRef bvr, bvr1 = 0, bvr2 = 0; + BVRef bvr = NULL; + BVRef bvr1 = NULL; + BVRef bvr2 = NULL; + char dirSpec[] = "hd(%d,%d)/", fileSpec[] = "Volumes", *label; + u_int32_t time, lasttime = 0; + long flags; if (chain->filtered) { @@ -971,6 +980,8 @@ if ( (bvr->part_no == multiboot_partition) && (bvr->biosdev == gBIOSDev) ) { + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("Multiboot partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } } @@ -994,12 +1005,42 @@ if (matchVolumeToString(bvr, val, false)) { free(val); + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("User default partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } } free(val); } + // Bungo: select last booted partition as the boot volume + // TODO: support other OSes (foreign boot) + for (bvr = chain; bvr; bvr = bvr->next) { + if (bvr->flags & (kBVFlagSystemVolume | kBVFlagForeignBoot)) + { + time = 0; + flags = 0; + sprintf(dirSpec, "hd(%d,%d)/", BIOS_DEV_UNIT(bvr), bvr->part_no); + if ((GetFileInfo(dirSpec, fileSpec, &flags, &time) == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory)) + { + if (time > lasttime) + { + lasttime = time; + bvr1 = bvr; + label = bvr1->label[0] ? bvr1->label : (bvr1->altlabel[0] ? bvr1->altlabel : (bvr1->name[0] ? bvr1->name : "Untitled")); + } + } + } + } + + if (bvr1) + { + DBG("Last booted volume: hd(%d,%d) '%s' set as default partition\n\n", BIOS_DEV_UNIT(bvr1), bvr1->part_no, label); + return bvr1; + } + // Bungo: code below selects first partition in the chain (last partition on disk), + // in my case Recovery HD, as boot volume, so I would prefer last booted partition + // as default boot volume - see the code above /* * Scannig the volume chain backwards and trying to find * a HFS+ volume with valid boot record signature. @@ -1069,9 +1110,9 @@ } } - bvr = bvr2 ? bvr2 : - bvr1 ? bvr1 : chain; - + bvr = bvr2 ? bvr2 : (bvr1 ? bvr1 : chain); + label = bvr->label[0] ? bvr->label : (bvr->altlabel[0] ? bvr->altlabel : (bvr->name[0] ? bvr->name : "Untitled")); + DBG("Default partition set: hd(%d,%d) '%s'\n", BIOS_DEV_UNIT(bvr), bvr->part_no, label); return bvr; } Index: branches/ErmaC/Enoch/i386/libsaio/smbios.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios.c (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/smbios.c (revision 2564) @@ -807,14 +807,14 @@ char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field) { - if (!field) + if (!field || !structHeader) { return NULL; } uint8_t *stringPtr = (uint8_t *)structHeader + structHeader->length; - for (field--; field != 0 && strlen((char *)stringPtr) > 0; + for (field--; (field > 0) && (*stringPtr > 0) &&(*(uint16_t *)stringPtr != 0); field--, stringPtr = (uint8_t *)((uint32_t)stringPtr + strlen((char *)stringPtr) + 1)); return (char *)stringPtr; @@ -1269,15 +1269,15 @@ addSMBEndOfTable(structPtr); } -// Bungo: does fix system uuid in SMBIOS (and EFI) instead of in EFI only -uint8_t *FixSystemUUID() +// Bungo: does fix system uuid in SMBIOS & EFI instead of in EFI (IODT/efi/platform/system-id) only +uint8_t *fixSystemUUID() { uint8_t *ptr = (uint8_t *)neweps->dmi.tableAddress; SMBStructHeader *structHeader = (SMBStructHeader *)ptr; int i, isZero, isOnes; - uint8_t FixedUUID[UUID_LEN] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F}; - const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist); - uint8_t *ret = (uint8_t *)getUUIDFromString(sysId); + uint8_t fixedUUID[UUID_LEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; + const char *sysId = getStringForKey(kSMBSystemInformationUUIDKey, SMBPlist); // try to get user's uuid from smbios.plist + uint8_t *ret = (uint8_t *)getUUIDFromString(sysId); // convert user's uuid from string for (;(structHeader->type != kSMBTypeSystemInformation);) // find System Information Table (Type 1) in patched SMBIOS { @@ -1315,8 +1315,8 @@ if (isZero || isOnes) // if empty or setable... { - verbose("No UUID present in SMBIOS System Information Table\n"); - ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F + verbose("System UUID: incorrect or not present. Fixing [00112233-4455-6677-8899-AABBCCDDEEFF]\n"); + ret = fixedUUID; // ...set a fixed value for system uuid: <00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF> } memcpy(ptr, ret, UUID_LEN); // save uuid into the patched SMBIOS Table 1 @@ -1398,7 +1398,7 @@ memcpy((void *)neweps->dmi.tableAddress, buffer, tableLength); - Platform.UUID = FixSystemUUID(); // Bungo: fix System UUID + Platform.UUID = fixSystemUUID(); // Bungo: fix System UUID neweps->dmi.checksum = 0; neweps->dmi.checksum = 0x100 - checksum8(&neweps->dmi, sizeof(DMIEntryPoint)); @@ -1449,31 +1449,31 @@ switch (structHeader->type) { case kSMBTypeSystemInformation: - Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // get factory system uuid + Platform.UUID = ((SMBSystemInformation *)structHeader)->uuid; // save factory system uuid break; case kSMBTypeSystemEnclosure: // Bungo: determine platform type switch (((SMBSystemEnclosure *)structHeader)->chassisType) { - case kSMBchassisDesktop: - case kSMBchassisLPDesktop: - case kSMBchassisAllInOne: - case kSMBchassisLunchBox: - PlatformType = 1; // desktop (iMac, MacMini) - break; case kSMBchassisPortable: case kSMBchassisLaptop: case kSMBchassisNotebook: case kSMBchassisHandHeld: case kSMBchassisSubNotebook: - PlatformType = 2; // notebook (Mac Books) - break; - default: + PlatformType = 2; // notebook (MacBooks/Pros) + break; + case kSMBchassisMiniTower: + case kSMBchassisTower: + case kSMBchassisBlade: + case kSMBchassisBladeEnclosing: PlatformType = 3; // workstation (Mac Pro, Xserve) break; + default: + PlatformType = 1; // defulting to 1 desktop (iMac, MacMini) + break; } break; - // + case kSMBTypePhysicalMemoryArray: Platform.DMI.MaxMemorySlots += ((SMBPhysicalMemoryArray *)structHeader)->numMemoryDevices; break; Index: branches/ErmaC/Enoch/i386/libsaio/smbios.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/smbios.h (revision 2564) @@ -239,7 +239,9 @@ kSMBchassisSubNotebook = 0x0E, // ... fill up if needed ;-) kSMBchassisLunchBox = 0x10, + kSMBchassisMainServer = 0x11, // ... fill up if needed ;-) + kSMBchassisBlade = 0x1C, kSMBchassisBladeEnclosing = 0x1D } MISC_CHASSIS_TYPE; @@ -283,7 +285,7 @@ SMBByte height; // Height of the enclosure, in 'U's SMBByte numberOfPowerCords; // Number of power cords associated with the enclosure or chassis SMBByte containedElementCount; // Number of Contained Element record that follow, in the range 0 to 255 - // SMBByte containedElementRecord; // Byte leght of each Contained Element record that follow, in the range 0 to 255 + SMBByte containedElementRecord; // Byte leght of each Contained Element record that follow, in the range 0 to 255 // SMBByte containedElements; // Elements, possibly defined by other SMBIOS structures present in chassis // 2.7+ // SMBString skuNumber; // Number of null-terminated string describing the chassis or enclosure SKU number Index: branches/ErmaC/Enoch/i386/libsaio/convert.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/convert.c (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/convert.c (revision 2564) @@ -29,8 +29,14 @@ return 0; } + int i = strlen(source); + if (i != 36) + { // e.g 00112233-4455-6677-8899-AABBCCDDEEFF + verbose("[ERROR] UUID='%s' has incorrect length=%d. Use format: 00112233-4455-6677-8899-AABBCCDDEEFF.\n", source, i); + return 0; + } + char *p = (char *)source; - int i; char buf[3]; static EFI_CHAR8 uuid[UUID_LEN+1] = ""; Index: branches/ErmaC/Enoch/i386/libsaio/saio_types.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/saio_types.h (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/saio_types.h (revision 2564) @@ -182,7 +182,8 @@ BVRef dir_bvr; /* volume reference */ }; -#define BVSTRLEN 32 +#define BVSTRLEN 36 // changed from 32 to 36 due to gpt partition name length +#define OSVERSTRLEN 9 struct BootVolume { BVRef next; /* list linkage pointer */ @@ -209,9 +210,9 @@ char altlabel[BVSTRLEN]; /* alternate partition volume label */ bool filtered; /* newFilteredBVChain() will set to TRUE */ bool visible; /* will shown in the device list */ - char OSVersion[8]; + char OSVersion[OSVERSTRLEN]; /* Null terminated string from '/System/Library/CoreServices/SystemVersion.plist/ProductVersion' e.g. "10.10.10" - hope will not reach e.g. 111.222.333 soon:) If so, OSVERSTRLEN 9 change to 12 */ bool OSisServer; /* 1 = OS X server , 0 = OS X client */ - bool OSisInstaller; /* 1 = OS X Install partition / recover partition , 0 = OS X Install */ + bool OSisInstaller; /* 1 = OS X Install partition / recovery partition , 0 = OS X Install */ }; Index: branches/ErmaC/Enoch/i386/libsaio/fake_efi.c =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/fake_efi.c (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/fake_efi.c (revision 2564) @@ -585,9 +585,13 @@ // too so we might as well create it so we have a pointer for it too. node = DT__AddChild(node, "efi"); /* Bungo - if (archCpuType == CPU_TYPE_I386) { + if (archCpuType == CPU_TYPE_I386) + { DT__AddProperty(node, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_32_PROP_VALUE), (char*)FIRMWARE_ABI_32_PROP_VALUE); - } else { */ + } + else + { + */ DT__AddProperty(node, FIRMWARE_ABI_PROP, sizeof(FIRMWARE_ABI_64_PROP_VALUE), (char *)FIRMWARE_ABI_64_PROP_VALUE); // } @@ -602,14 +606,17 @@ // is set up. That is, name and table properties Node *runtimeServicesNode = DT__AddChild(node, "runtime-services"); - if (archCpuType == CPU_TYPE_I386) { + if (archCpuType == CPU_TYPE_I386) + { // The value of the table property is the 32-bit physical address for the RuntimeServices table. // Since the EFI system table already has a pointer to it, we simply use the address of that pointer // for the pointer to the property data. Warning.. DT finalization calls free on that but we're not // the only thing to use a non-malloc'd pointer for something in the DT DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST32->RuntimeServices); - } else { + } + else + { DT__AddProperty(runtimeServicesNode, "table", sizeof(uint64_t), &gST64->RuntimeServices); } @@ -717,7 +724,7 @@ DT__AddProperty(chosenNode, "machine-signature", sizeof(EFI_UINT32), (EFI_UINT32 *)&MachineSig); - if(YOSEMITE) + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) { // // Pike R. Alpha - 12 October 2014 @@ -729,7 +736,7 @@ EFI_UINT32 rcx, rdx, rsi, rdi; randomValue = tempValue = ecx = esi = edi = 0; // xor %ecx, %ecx - rcx = rdx = rsi = rdi = cpuTick = 0; + cpuTick = rcx = rdx = rsi = rdi = 0; // LEAF_1 - Feature Information (Function 01h). if (Platform.CPU.CPUID[CPUID_1][2] & 0x40000000) // Checking ecx:bit-30 @@ -895,7 +902,7 @@ */ void setupFakeEfi(void) { - // Generate efi device strings + // Generate efi device strings setup_pci_devs(root_pci_dev); readSMBIOSInfo(getSmbios(SMBIOS_ORIGINAL)); Index: branches/ErmaC/Enoch/i386/libsaio/saio_internal.h =================================================================== --- branches/ErmaC/Enoch/i386/libsaio/saio_internal.h (revision 2563) +++ branches/ErmaC/Enoch/i386/libsaio/saio_internal.h (revision 2564) @@ -224,4 +224,9 @@ // Base64-decode.c char *BASE64Decode(const char* src, int in_len, int* out_len); +// options.c +extern char gMacOSVersion[OSVERSTRLEN]; +extern uint32_t MacOSVerCurrent; +extern uint32_t MacOSVer2Int(const char *osver); + #endif /* !__LIBSAIO_SAIO_INTERNAL_H */ Index: branches/ErmaC/Enoch/i386/boot2/drivers.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2563) +++ branches/ErmaC/Enoch/i386/boot2/drivers.c (revision 2564) @@ -116,8 +116,8 @@ static char *gFileSpec; static char *gTempSpec; static char *gFileName; -// Bungo -char *gDarwinBuildVerStr = "Darwin Kernel Version"; +// Bungo: +char gDarwinBuildVerStr[256] = "Darwin Kernel Version"; /*static*/ unsigned long Adler32( unsigned char *buffer, long length ) @@ -249,7 +249,7 @@ } else { - if ( MAVERICKS || YOSEMITE ) // issue 352 + if (MacOSVerCurrent >= MacOSVer2Int("10.9")) // issue 352 { strlcpy(gExtensionsSpec, dirSpec, 4087); /* 4096 - sizeof("Library/") */ strcat(gExtensionsSpec, "Library/"); @@ -981,12 +981,21 @@ ret = ThinFatFile(&binary, &len); } - // Bungo: no range checking, sorry - size = 0; - while (memcmp((uint8_t *)binary + size, (uint8_t *)gDarwinBuildVerStr, 21)) { - size++; + // Bungo: scan binary for Darwin Kernel Version string + uint32_t offset = 0; + strncpy(gDarwinBuildVerStr, "Darwin Kernel Version", sizeof(gDarwinBuildVerStr)); + while ((offset < 0xFFFFFFFF - (uint32_t)binary - 256) && memcmp(binary + offset, gDarwinBuildVerStr, 21)) + { + offset++; } - gDarwinBuildVerStr = (char *)binary + size; + if (offset < 0xFFFFFFFF - (uint32_t)binary - 256) + { + strncpy(gDarwinBuildVerStr, (char *)(binary + offset), sizeof(gDarwinBuildVerStr)); + } + else + { + strcat(gDarwinBuildVerStr, ": Unknown"); + } // Notify modules that the kernel has been decompressed, thinned and is about to be decoded execute_hook("DecodeKernel", (void *)binary, NULL, NULL, NULL); Index: branches/ErmaC/Enoch/i386/boot2/boot.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/boot.c (revision 2563) +++ branches/ErmaC/Enoch/i386/boot2/boot.c (revision 2564) @@ -84,7 +84,6 @@ char gRootDevice[ROOT_DEVICE_SIZE]; char gMKextName[512]; -char gMacOSVersion[8]; int bvCount = 0; int gDeviceCount = 0; //int menucount = 0; @@ -220,10 +219,10 @@ finalizeBootStruct(); // Jump to kernel's entry point. There's no going back now. - if ( LION || MOUNTAIN_LION || MAVERICKS || YOSEMITE ) + if (MacOSVerCurrent >= MacOSVer2Int("10.7")) { // Notify modules that the kernel is about to be started - execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL); + execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL); // Masking out so that Lion doesn't doublefault @@ -267,18 +266,19 @@ } else { - if ( LION || MOUNTAIN_LION || MAVERICKS || YOSEMITE) + // Lion, Mountain Lion, Mavericks and Yosemite prelink kernel cache file + if (MacOSVerCurrent >= MacOSVer2Int("10.7")) // OSX is Lion (10.7) or newer { - // Lion, Mountain Lion, Mavericks, and Yosemite prelink kernel cache file - // for 10.7 10.8 10.9 10.10 snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow); - verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);; + verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile); } // Snow Leopard prelink kernel cache file - else if ( SNOW_LEOPARD ) + else { - snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s", - (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); + if (MacOSVerCurrent >= MacOSVer2Int("10.6")) // OSX is Snow (10.6) + { + snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s", + (archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64"); int lnam = strlen(kernelCacheFile) + 9; //with adler32 char *name; @@ -304,12 +304,14 @@ } else { - // Reset cache name. - bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64); - snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile); - adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler)); - snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32); - verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);; + // Leopard prelink kernel cache file + // Reset cache name. + bzero(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64); + snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile); + adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler)); + snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32); + verbose("Reseted kernel cache file path: %s\n", kernelCacheFile); + } } } @@ -386,7 +388,7 @@ } // Since the kernel cache file exists and is the most recent try to load it - DBG("Loading Kernel Cache from: '%s'\n", kernelCachePath); + DBG("Loading Kernel Cache from: '%s%s' (%s)\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name); ret = LoadThinFatFile(kernelCachePath, binary); return ret; // ret contain the length of the binary @@ -604,8 +606,12 @@ if (getValueForKey(karch, &val, &len, &bootInfo->chameleonConfig)) { - if (strncmp(val, "i386", 4) == 0) + if (strncmp(val, "x86_64", 4) == 0) { + archCpuType = CPU_TYPE_X86_64; + } + else if (strncmp(val, "i386", 4) == 0) + { archCpuType = CPU_TYPE_I386; } else @@ -745,13 +751,13 @@ // bootFile must start with a / if it not start with a device name if (!bootFileWithDevice && (bootInfo->bootFile)[0] != '/') { - if ( !YOSEMITE ) + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) // OSX is 10.10 or newer { - snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading / + snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos "%s", bootInfo->bootFile); // Yosemite } else { - snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite + snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading '/' } } else @@ -782,7 +788,7 @@ strlcpy(bootFilePath, bootFile, sizeof(bootFilePath)); } - DBG("Loading kernel from: '%s'\n", bootFilePath); + DBG("Loading kernel from: '%s' (%s)\n", gBootVolume->label, gBootVolume->type_name); ret = LoadThinFatFile(bootFilePath, &binary); if (ret <= 0 && archCpuType == CPU_TYPE_X86_64) { @@ -871,6 +877,12 @@ } } +uint32_t getMacOSVerCurrent() +{ + MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion); + return MacOSVerCurrent; +} + #define BASE 65521L /* largest prime smaller than 65536 */ #define NMAX 5000 // NMAX (was 5521) the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 Index: branches/ErmaC/Enoch/i386/boot2/boot.h =================================================================== --- branches/ErmaC/Enoch/i386/boot2/boot.h (revision 2563) +++ branches/ErmaC/Enoch/i386/boot2/boot.h (revision 2564) @@ -30,13 +30,13 @@ #include "libsaio.h" // OS X Versions -#define YOSEMITE checkOSVersion("10.10") // Yosemite -#define MAVERICKS checkOSVersion("10.9") // Mavericks -#define MOUNTAIN_LION checkOSVersion("10.8") // Mountain Lion -#define LION checkOSVersion("10.7") // Lion -#define SNOW_LEOPARD checkOSVersion("10.6") // Snow Leopard -#define LEOPARD checkOSVersion("10.5") // Leopard -#define TIGER checkOSVersion("10.4") // Tiger +//#define YOSEMITE checkOSVersion("10.10") // Yosemite +//#define MAVERICKS checkOSVersion("10.9") // Mavericks +//#define MOUNTAIN_LION checkOSVersion("10.8") // Mountain Lion +//#define LION checkOSVersion("10.7") // Lion +//#define SNOW_LEOPARD checkOSVersion("10.6") // Snow Leopard +//#define LEOPARD checkOSVersion("10.5") // Leopard +//#define TIGER checkOSVersion("10.4") // Tiger /* * Paths used by chameleon @@ -191,10 +191,10 @@ /* ErmaC: added these keys */ #define kEnableDualLink "EnableDualLink" /* ati.c && nvidia.c && gma.c*/ #define kNvidiaGeneric "NvidiaGeneric" /* nvidia.c */ -#define kSkipIntelGfx "SkipIntelGfx" /* pci_setup.c */ +#define kSkipIntelGfx "SkipIntelGfx" /* pci_setup.c */ #define kSkipNvidiaGfx "SkipNvidiaGfx" /* pci_setup.c */ #define kSkipAtiGfx "SkipAtiGfx" /* pci_setup.c */ -//#define kUsbInject "USBInject" /* usb.c */ +//#define kUsbInject "USBInject" /* usb.c */ #define kIntelCapriFB "IntelCapriFB" /* gma.c was HD4K-ig */ #define kIntelAzulFB "IntelAzulFB" /* gma.c was HD5K-ig */ #define kAAPLCustomIG "InjectIntel-ig" /* gma.c */ @@ -257,7 +257,9 @@ extern void initialize_runtime(); extern void common_boot(int biosdev); -bool checkOSVersion(const char * version); +extern bool checkOSVersion(const char * version); +extern uint32_t getMacOSVerCurrent(); + /* * usb.c */ @@ -303,8 +305,8 @@ extern long LoadDrivers(char * dirSpec); extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize); typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin); -// Bungo -extern char *gDarwinBuildVerStr; +// Bungo: +extern char gDarwinBuildVerStr[256]; /*! Hookable function pointer called during the driver loading phase that Index: branches/ErmaC/Enoch/i386/boot2/options.c =================================================================== --- branches/ErmaC/Enoch/i386/boot2/options.c (revision 2563) +++ branches/ErmaC/Enoch/i386/boot2/options.c (revision 2564) @@ -38,8 +38,10 @@ #define DBG(x...) msglog(x) #endif -bool showBootBanner = true; //Azi:showinfo -static bool shouldboot = false; +char gMacOSVersion[OSVERSTRLEN]; +uint32_t MacOSVerCurrent = 0; +bool showBootBanner = true; //Azi:showinfo +static bool shouldboot = false; extern int multiboot_timeout; extern int multiboot_timeout_set; @@ -65,6 +67,53 @@ //========================================================================== +// MacOSVer2Int - converts OS ver. string to uint32 (e.g "10.9.5" -> 0x0A090500) for easy comparing +uint32_t MacOSVer2Int(const char *osver) +{ + uint32_t result = 0; + uint8_t *resptr = (uint8_t *)&result; + uint8_t len = strlen(osver); + uint8_t i, j, m; +#define CHR2UINT(c) ((uint8_t)(c - '0')) +#define ISDIGIT(c) ((c >= '0') && (c <= '9')) +#define ISDOT(c) (c == '.') + + if (!osver || (len < 4) || (len > OSVERSTRLEN - 1) || !ISDIGIT(osver[0]) || !ISDOT(osver[2]) || !ISDIGIT(osver[len - 1])) + { + verbose("ERROR: wrong Mac OS version string syntax: '%s'\n", osver); + return 0; + } + + for (i = 0, j = 3, m = 1; i < len; i++) + { + if (ISDIGIT(osver[i])) + { + resptr[j] = resptr[j] * m + CHR2UINT(osver[i]); + m = 10; + } + else if (ISDOT(osver[i])) + { + if (j > 0) + { + j--; + } + else + { + return 0; + } + m = 1; + } + else + { + return 0; + } + } + + return result; +} + +//========================================================================== + typedef struct { int x; int y; @@ -1230,8 +1279,18 @@ return -1; } - // Find out which version mac os we're booting. - strncpy(gMacOSVersion, gBootVolume->OSVersion, sizeof(gMacOSVersion)); + // Save a version of mac os we're booting. + MacOSVerCurrent = MacOSVer2Int(gBootVolume->OSVersion); + // so copy it and trim + gMacOSVersion[0] = 0; + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) + { + strncat(gMacOSVersion, gBootVolume->OSVersion, 5); + } + else + { + strncat(gMacOSVersion, gBootVolume->OSVersion, 4); + } // Load config table specified by the user, or use the default. @@ -1267,37 +1326,25 @@ } else { - if( YOSEMITE ) // is 10.10 + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) // OS X is 10.10 or newer { strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) ); } else - { // OSX is not 10.10 - + { + // or 10.9 and previous strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) ); } } } - if (!YOSEMITE) // not 10.10 so 10.9 and previus + if ((strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) && (strcmp( bootInfo->bootFile, kOSXKernel ) != 0)) { - if (strcmp( bootInfo->bootFile, kDefaultKernel ) != 0) - { - //printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile); - gOverrideKernel = true; - } + gOverrideKernel = true; } - else - { // OSX is 10.10 - if (strcmp( bootInfo->bootFile, kOSXKernel ) != 0) - { - //printf(HEADER "org.chameleon.Boot.plist found path for custom '%s' found!\n", bootInfo->bootFile); - gOverrideKernel = true; - } - } // Ermac : Inject "kext-dev-mode=1" if OS X 10.10 is detected - if( YOSEMITE ) // is 10.10 + if (MacOSVerCurrent >= MacOSVer2Int("10.10")) // OS X is 10.10 or newer { addBootArg("kext-dev-mode=1"); } @@ -1349,9 +1396,9 @@ if (!strlen(gBootUUIDString) && gBootVolume->fs_getuuid) { gBootVolume->fs_getuuid(gBootVolume, gBootUUIDString); - DBG("boot-uuid: %s\n", gBootUUIDString); } } + DBG("Boot UUID [%s (%s), %s]: %s\n", gBootVolume->label, gBootVolume->altlabel, gBootVolume->type_name, gBootUUIDString); if (!processBootArgument(kRootDeviceKey, cp, configKernelFlags, bootInfo->config, &argP, &cntRemaining, gRootDevice, ROOT_DEVICE_SIZE)) @@ -1363,27 +1410,32 @@ cnt++; strlcpy(valueBuffer + 1, val, cnt); val = valueBuffer; + if (cnt > 0) + { + copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); + } } else - { /* + { if (strlen(gBootUUIDString)) { val = "*uuid"; cnt = 5; } else - { */ + { // Don't set "rd=.." if there is no boot device key // and no UUID. val = ""; cnt = 0; - /* } */ + } } - +/* Bungo if (cnt > 0) { copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining); } +*/ strlcpy(gRootDevice, val, (cnt + 1)); } Index: branches/ErmaC/Enoch/CHANGES =================================================================== --- branches/ErmaC/Enoch/CHANGES (revision 2563) +++ branches/ErmaC/Enoch/CHANGES (revision 2564) @@ -1,3 +1,7 @@ +- Bungo : Added ability to auto-select last booted partition as the boot volume. +- Bungo : Added MacOSVerCurrent and MacOSVer2Int function to use instead of macros. +- Bungo : Fixed bug in gDarwinBuildVerStr extracting. +- Bungo : Fixed fixedUUID function (convert.c smbios.c). - Bungo : Added Logging start time. - Bungo : Added getRTCdatetime() Int 1Ah function 02h - RTC service. - Zenith432 : Use caching with ExFat filesystem.