Index: trunk/i386/libsaio/Makefile =================================================================== --- trunk/i386/libsaio/Makefile (revision 43) +++ trunk/i386/libsaio/Makefile (revision 44) @@ -42,7 +42,8 @@ cpu.o platform.o dsdt_patcher.o \ smbios_patcher.o fake_efi.o ext2fs.o \ hpet.o spd.o usb.o pci_setup.o \ - device_inject.o nvidia.o ati.o pci_root.o mem.o + device_inject.o nvidia.o ati.o pci_root.o \ + convert.o mem.o SAIO_EXTERN_OBJS = console.o Index: trunk/i386/libsaio/device_inject.c =================================================================== --- trunk/i386/libsaio/device_inject.c (revision 43) +++ trunk/i386/libsaio/device_inject.c (revision 44) @@ -11,8 +11,8 @@ #include "pci.h" #include "pci_root.h" #include "device_inject.h" +#include "convert.h" - #ifndef DEBUG_INJECT #define DEBUG_INJECT 0 #endif @@ -39,82 +39,6 @@ return NULL; } -/* XXX AsereBLN replace by strtoul */ -uint32_t ascii_hex_to_int(char *buff) -{ - uint32_t value = 0, i, digit; - for(i = 0; i < strlen(buff); i++) - { - if (buff[i] >= 48 && buff[i] <= 57) // '0' through '9' - digit = buff[i] - 48; - else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' - digit = buff[i] - 55; - else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' - digit = buff[i] - 87; - else - return value; - - value = digit + 16 * value; - } - return value; -} - -void *convertHexStr2Binary(const char *hexStr, int *outLength) -{ - int len; - char hexNibble; - char hexByte[2]; - uint8_t binChar; - uint8_t *binStr; - int hexStrIdx, binStrIdx, hexNibbleIdx; - - len = strlen(hexStr); - if (len > 1) - { - // the resulting binary will be the half size of the input hex string - binStr = malloc(len / 2); - binStrIdx = 0; - hexNibbleIdx = 0; - for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) - { - hexNibble = hexStr[hexStrIdx]; - - // ignore all chars except valid hex numbers - if (hexNibble >= '0' && hexNibble <= '9' - || hexNibble >= 'A' && hexNibble <= 'F' - || hexNibble >= 'a' && hexNibble <= 'f') - { - hexByte[hexNibbleIdx++] = hexNibble; - - // found both two nibbles, convert to binary - if (hexNibbleIdx == 2) - { - binChar = 0; - - for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) - { - if (hexNibbleIdx > 0) binChar = binChar << 4; - - if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; - else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); - else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); - } - - binStr[binStrIdx++] = binChar; - hexNibbleIdx = 0; - } - } - } - *outLength = binStrIdx; - return binStr; - } - else - { - *outLength = 0; - return NULL; - } -} - void setupDeviceProperties(Node *node) { const char *val; @@ -144,19 +68,6 @@ } } -uint16_t dp_swap16(uint16_t toswap) -{ - return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8)); -} - -uint32_t dp_swap32(uint32_t toswap) -{ - return ((toswap & 0x000000FF) << 24) | - ((toswap & 0x0000FF00) << 8 ) | - ((toswap & 0x00FF0000) >> 8 ) | - ((toswap & 0xFF000000) >> 24); -} - struct DevPropString *devprop_create_string(void) { string = (struct DevPropString*)malloc(sizeof(struct DevPropString)); Index: trunk/i386/libsaio/device_inject.h =================================================================== --- trunk/i386/libsaio/device_inject.h (revision 43) +++ trunk/i386/libsaio/device_inject.h (revision 44) @@ -15,7 +15,7 @@ extern struct DevPropString *string; extern uint8_t *stringdata; extern uint32_t stringlength; -extern void *convertHexStr2Binary(const char *hexStr, int *outLength); + extern void setupDeviceProperties(Node *node); struct ACPIDevPath { Index: trunk/i386/libsaio/platform.c =================================================================== --- trunk/i386/libsaio/platform.c (revision 43) +++ trunk/i386/libsaio/platform.c (revision 44) @@ -44,12 +44,5 @@ scan_cpu(&Platform); scan_memory(&Platform); scan_spd(&Platform); - Platform.Type = 1; /* Desktop */ - if (getValueForKey(kSystemType, &value, &len, &bootInfo->bootConfig) && value != NULL) { - Platform.Type = (unsigned char) strtoul(value, NULL, 10); - if (Platform.Type > 6) { - verbose("Error: system-type must be 0..6. Defaulting to 1!\n"); - Platform.Type = 1; - } - } + } Index: trunk/i386/libsaio/convert.c =================================================================== --- trunk/i386/libsaio/convert.c (revision 0) +++ trunk/i386/libsaio/convert.c (revision 44) @@ -0,0 +1,151 @@ +/* + * Convert.c + * Implement conversion utility functions + * Create UUID parsing functions and gather other conversion routines + * --Rek + */ + +#include "convert.h" + +/** Transform a 16 bytes hexadecimal value UUID to a string */ +const char * getStringFromUUID(const EFI_CHAR8* uuid) +{ + static char msg[UUID_LEN*2 + 8] = ""; + if (uuid) sprintf(msg, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + (int)uuid[0], (int)uuid[1], (int)uuid[2], (int)uuid[3], + (int)uuid[4], (int)uuid[5], (int)uuid[6], (int)uuid[7], + (int)uuid[8], (int)uuid[9], (int)uuid[10],(int)uuid[11], + (int)uuid[12],(int)uuid[13],(int)uuid[14],(int)uuid[15]); + return uuid ? msg : ""; +} + +/** Parse an UUID string into an (EFI_CHAR8*) buffer */ +EFI_CHAR8* getUUIDFromString(const char *source) +{ + if (!source) return 0; + + char *p = (char *)source; + int i; + char buf[3]; + static EFI_CHAR8 uuid[UUID_LEN+1]=""; + + buf[2] = '\0'; + for (i=0; i= 48 && buff[i] <= 57) // '0' through '9' + digit = buff[i] - 48; + else if (buff[i] >= 65 && buff[i] <= 70) // 'A' through 'F' + digit = buff[i] - 55; + else if (buff[i] >= 97 && buff[i] <= 102) // 'a' through 'f' + digit = buff[i] - 87; + else + return value; + + value = digit + 16 * value; + } + return value; +} + +void *convertHexStr2Binary(const char *hexStr, int *outLength) +{ + int len; + char hexNibble; + char hexByte[2]; + uint8_t binChar; + uint8_t *binStr; + int hexStrIdx, binStrIdx, hexNibbleIdx; + + len = strlen(hexStr); + if (len > 1) + { + // the resulting binary will be the half size of the input hex string + binStr = malloc(len / 2); + binStrIdx = 0; + hexNibbleIdx = 0; + for (hexStrIdx = 0; hexStrIdx < len; hexStrIdx++) + { + hexNibble = hexStr[hexStrIdx]; + + // ignore all chars except valid hex numbers + if (hexNibble >= '0' && hexNibble <= '9' + || hexNibble >= 'A' && hexNibble <= 'F' + || hexNibble >= 'a' && hexNibble <= 'f') + { + hexByte[hexNibbleIdx++] = hexNibble; + + // found both two nibbles, convert to binary + if (hexNibbleIdx == 2) + { + binChar = 0; + + for (hexNibbleIdx = 0; hexNibbleIdx < sizeof(hexByte); hexNibbleIdx++) + { + if (hexNibbleIdx > 0) binChar = binChar << 4; + + if (hexByte[hexNibbleIdx] <= '9') binChar += hexByte[hexNibbleIdx] - '0'; + else if (hexByte[hexNibbleIdx] <= 'F') binChar += hexByte[hexNibbleIdx] - ('A' - 10); + else if (hexByte[hexNibbleIdx] <= 'f') binChar += hexByte[hexNibbleIdx] - ('a' - 10); + } + + binStr[binStrIdx++] = binChar; + hexNibbleIdx = 0; + } + } + } + *outLength = binStrIdx; + return binStr; + } + else + { + *outLength = 0; + return NULL; + } +} + +// FIXME: can't use my original code here, +// Ironically, trying to reuse convertHexStr2Binary() would RESET the system! +/* +static EFI_CHAR8* getUUIDFromString2(const char * szInUUID) +{ + char szUUID[UUID_LEN+1], *p=szUUID; + int size=0; + void* ret; + + if (!szInUUID || strlen(szInUUID) to valid UUID.\n", szUUID); + return (EFI_CHAR8*) 0; + } + return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin +} +*/ Index: trunk/i386/libsaio/convert.h =================================================================== --- trunk/i386/libsaio/convert.h (revision 0) +++ trunk/i386/libsaio/convert.h (revision 44) @@ -0,0 +1,33 @@ +/* + * Convert.h + * Declare conversion utility functions + * --Rek + */ + +#ifndef __CONVERT_H +#define __CONVERT_H +#include "libsaio.h" +#include "efi.h" + +#define UUID_LEN 16 + +const char * getStringFromUUID(const EFI_CHAR8* uuid); +EFI_CHAR8* getUUIDFromString(const char *source); +void *convertHexStr2Binary(const char *hexStr, int *outLength); +uint32_t ascii_hex_to_int(char *buff); + +static inline uint16_t dp_swap16(uint16_t toswap) +{ + return (((toswap & 0x00FF) << 8) | ((toswap & 0xFF00) >> 8)); +} + +static inline uint32_t dp_swap32(uint32_t toswap) +{ + return ((toswap & 0x000000FF) << 24) | + ((toswap & 0x0000FF00) << 8 ) | + ((toswap & 0x00FF0000) >> 8 ) | + ((toswap & 0xFF000000) >> 24); +} + + +#endif Index: trunk/i386/libsaio/fake_efi.c =================================================================== --- trunk/i386/libsaio/fake_efi.c (revision 43) +++ trunk/i386/libsaio/fake_efi.c (revision 44) @@ -14,6 +14,7 @@ #include "dsdt_patcher.h" #include "smbios_patcher.h" #include "device_inject.h" +#include "convert.h" #include "pci.h" #include "sl.h" @@ -327,7 +328,6 @@ static const char const SYSTEM_TYPE_PROP[] = "system-type"; static const char const MODEL_PROP[] = "Model"; -#define UUID_LEN 16 /* Get an smbios option string option to convert to EFI_CHAR16 string */ static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len) @@ -338,11 +338,11 @@ if (!key || !(*key) || !len || !src) return 0; - *len = strlen(src)+1; - dst = (EFI_CHAR16*) malloc( (*len) * 2 ); - for (; i < (*len) - 1; i++) dst[i] = src[i]; - dst[(*len) - 1] = '\0'; - + *len = strlen(src); + dst = (EFI_CHAR16*) malloc( ((*len)+1) * 2 ); + for (; i < (*len); i++) dst[i] = src[i]; + dst[(*len)] = '\0'; + *len = ((*len)+1)*2; // return the CHAR16 bufsize in cluding zero terminated CHAR16 return dst; } @@ -404,65 +404,10 @@ } memcpy(uuid, p, UUID_LEN+1); + uuid[UUID_LEN]=0; return uuid; } -/* Parse an UUID string into an (EFI_CHAR8*) buffer */ -static EFI_CHAR8* getUUIDFromString(const char *source) -{ - if (!source) return 0; - - char *p = (char *)source; - int i; - char buf[3]; - static EFI_CHAR8 uuid[UUID_LEN+1]=""; - - buf[2] = '\0'; - for (i=0; i to valid UUID.\n", szUUID); - return (EFI_CHAR8*) 0; - } - return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin -} -*/ - /* return a binary UUID value from the overriden SystemID and SMUUID if found, * or from the bios if not, or from a fixed value if no bios value is found */ @@ -476,12 +421,12 @@ if(!sysId || !ret) { // try bios dmi info UUID extraction ret = getSmbiosUUID(); - sysId=0; + sysId = getStringFromUUID(ret); } if(!ret) // no bios dmi UUID available, set a fixed value for system-id ret=getUUIDFromString((sysId = (const char*) SYSTEM_ID)); - verbose("Customizing SystemID with : %s\n", sysId ? sysId :"BIOS internal UUID"); + verbose("Customizing SystemID with : %s\n", sysId); return ret; } @@ -497,9 +442,17 @@ if (node == 0) stop("Couldn't get root node"); - /* Export system-type */ - verbose("Using system-type=0x%02x\n", Platform.Type); - DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(Platform.Type), &Platform.Type); + /* Export system-type only if it has been overrriden by the SystemType option */ + Platform.Type = 1; /* Desktop */ + if (getValueForKey(kSystemType, &value, &len, &bootInfo->bootConfig) && value != NULL) + { + if (Platform.Type > 6) + verbose("Error: system-type must be 0..6. Defaulting to 1!\n"); + else + Platform.Type = (unsigned char) strtoul(value, NULL, 10); + verbose("Using system-type=0x%02x\n", Platform.Type); + DT__AddProperty(node, SYSTEM_TYPE_PROP, sizeof(Platform.Type), &Platform.Type); + } /* We could also just do DT__FindNode("/efi/platform", true) * But I think eventually we want to fill stuff in the efi node Index: trunk/i386/boot2/graphics.c =================================================================== --- trunk/i386/boot2/graphics.c (revision 43) +++ trunk/i386/boot2/graphics.c (revision 44) @@ -1207,7 +1207,7 @@ { if (currentIndicator >= kNumIndicators) currentIndicator = 0; string[0] = indicator[currentIndicator++]; - printf(string); + verbose(string); } }