Chameleon

Chameleon Commit Details

Date:2010-01-29 20:04:02 (9 years 5 months ago)
Author:Rekursor
Commit:44
Parents: 43
Message:- Fixed SystemType was forced to 1 and injected by default, now it is only injected if overriden - fixed potential side effect when using the new getSmbiosChar16() api - fixed graphics would cause garbage to cursor in boot2/graphics.c, now verbose is used as suggested by DrHurt - created a new convert module, added existing conversion functions and added a new getStringFromUUID() function. - used the getStringToUUID() function to display the binary returned value from bios uuid.
Changes:
A/trunk/i386/libsaio/convert.h
A/trunk/i386/libsaio/convert.c
M/trunk/i386/boot2/graphics.c
M/trunk/i386/libsaio/platform.c
M/trunk/i386/libsaio/fake_efi.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/libsaio/Makefile
M/trunk/i386/libsaio/device_inject.h

File differences

trunk/i386/libsaio/Makefile
4242
4343
4444
45
45
46
4647
4748
4849
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
trunk/i386/libsaio/device_inject.c
1111
1212
1313
14
1415
15
1616
1717
1818
......
3939
4040
4141
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
11842
11943
12044
......
14468
14569
14670
147
148
149
150
151
152
153
154
155
156
157
158
159
16071
16172
16273
#include "pci.h"
#include "pci_root.h"
#include "device_inject.h"
#include "convert.h"
#ifndef DEBUG_INJECT
#define DEBUG_INJECT 0
#endif
return NULL;
}
/* XXX AsereBLN replace by strtoul */
uint32_t ascii_hex_to_int(char *buff)
{
uint32_tvalue = 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;
}
returnvalue;
}
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;
}
}
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));
trunk/i386/libsaio/device_inject.h
1515
1616
1717
18
18
1919
2020
2121
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 {
trunk/i386/libsaio/platform.c
4444
4545
4646
47
48
49
50
51
52
53
54
47
5548
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;
}
}
}
trunk/i386/libsaio/convert.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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;
inti;
charbuf[3];
static EFI_CHAR8 uuid[UUID_LEN+1]="";
buf[2] = '\0';
for (i=0; i<UUID_LEN; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
buf[0] = *p++;
buf[1] = *p++;
uuid[i] = (unsigned char) strtoul(buf, NULL, 16);
if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1) {
p++;
}
}
uuid[UUID_LEN]='\0';
if (*p != '\0') {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
return uuid;
}
/** XXX AsereBLN replace by strtoul */
uint32_t ascii_hex_to_int(char *buff)
{
uint32_tvalue = 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;
}
returnvalue;
}
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)<UUID_LEN) return (EFI_CHAR8*) 0;
while(*szInUUID) if (*szInUUID!='-') *p++=*szInUUID++; else szInUUID++;
*p='\0';
ret = convertHexStr2Binary(szUUID, &size);
if (!ret || size!=UUID_LEN)
{
verbose("UUID: cannot convert string <%s> to valid UUID.\n", szUUID);
return (EFI_CHAR8*) 0;
}
return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin
}
*/
trunk/i386/libsaio/convert.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
* Convert.h
* Declare conversion utility functions
* --Rek
*/
#ifndef __CONVERT_H
#define __CONVERT_H
#include "libsaio.h"
#include "efi.h"
#define UUID_LEN16
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
trunk/i386/libsaio/fake_efi.c
1414
1515
1616
17
1718
1819
1920
......
327328
328329
329330
330
331331
332332
333333
......
338338
339339
340340
341
342
343
344
345
341
342
343
344
345
346346
347347
348348
......
404404
405405
406406
407
407408
408409
409410
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466411
467412
468413
......
476421
477422
478423
479
424
480425
481426
482427
483428
484
429
485430
486431
487432
......
497442
498443
499444
500
501
502
445
446
447
448
449
450
451
452
453
454
455
503456
504457
505458
#include "dsdt_patcher.h"
#include "smbios_patcher.h"
#include "device_inject.h"
#include "convert.h"
#include "pci.h"
#include "sl.h"
static const char const SYSTEM_TYPE_PROP[] = "system-type";
static const char const MODEL_PROP[] = "Model";
#define UUID_LEN16
/* Get an smbios option string option to convert to EFI_CHAR16 string */
static EFI_CHAR16* getSmbiosChar16(const char * key, size_t* len)
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;
}
}
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;
inti;
charbuf[3];
static EFI_CHAR8 uuid[UUID_LEN+1]="";
buf[2] = '\0';
for (i=0; i<UUID_LEN; i++) {
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
buf[0] = *p++;
buf[1] = *p++;
uuid[i] = (unsigned char) strtoul(buf, NULL, 16);
if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1) {
p++;
}
}
uuid[UUID_LEN]='\0';
if (*p != '\0') {
verbose("[ERROR] UUID='%s' syntax error\n", source);
return 0;
}
return uuid;
}
// 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)<UUID_LEN) return (EFI_CHAR8*) 0;
while(*szInUUID) if (*szInUUID!='-') *p++=*szInUUID++; else szInUUID++;
*p='\0';
ret = convertHexStr2Binary(szUUID, &size);
if (!ret || size!=UUID_LEN)
{
verbose("UUID: cannot convert string <%s> 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
*/
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;
}
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
trunk/i386/boot2/graphics.c
12071207
12081208
12091209
1210
1210
12111211
12121212
12131213
{
if (currentIndicator >= kNumIndicators) currentIndicator = 0;
string[0] = indicator[currentIndicator++];
printf(string);
verbose(string);
}
}

Archive Download the corresponding diff file

Revision: 44