Chameleon

Chameleon Commit Details

Date:2010-04-16 21:03:34 (9 years 6 months ago)
Author:Andy Vandijck
Commit:141
Parents: 140
Message:
Changes:
M/branches/andyvand/i386/libsaio/device_inject.c
M/branches/andyvand/i386/libsaio/pci_setup.c
M/branches/andyvand/i386/libsaio/saio_internal.h
M/branches/andyvand/i386/libsaio/bootstruct.h
M/branches/andyvand/i386/boot2/options.c
M/branches/andyvand/i386/libsa/string.c
M/branches/andyvand/i386/libsaio/stringTable.c
M/branches/andyvand/i386/libsaio/device_inject.h
M/branches/andyvand/i386/boot2/drivers.c
M/branches/andyvand/revision
M/branches/andyvand/i386/libsaio/saio_types.h
M/branches/andyvand/i386/boot2/boot.c
M/branches/andyvand/i386/libsa/libsa.h

File differences

branches/andyvand/i386/libsaio/bootstruct.h
125125
126126
127127
128
129128
130129
131130
132131
132
133133
134134
135135
char config[CONFIG_SIZE];
config_file_t bootConfig; // boot.plist
config_file_t overrideConfig; // additional boot.plist which can override bootConfig keys
config_file_t themeConfig; // theme.plist
config_file_t smbiosConfig; // smbios.plist
config_file_t helperConfig; // boot helper partition's boot.plist
config_file_t ramdiskConfig; // RAMDisk.plist
config_file_t pciConfig; // pci.plist
} PrivateBootInfo_t;
extern PrivateBootInfo_t *bootInfo;
branches/andyvand/i386/libsaio/device_inject.c
2929
3030
3131
32
33
34
35
36
37
38
39
40
41
3242
3343
3444
......
8696
8797
8898
99
89100
90101
91102
......
177188
178189
179190
191
192
193
194
195
196
197
180198
181199
182200
......
358376
359377
360378
379
380
381
382
383
384
385
386
387
388
389
390
uint8_t *stringdata = 0;
uint32_t stringlength = 0;
typedef struct DeviceEntryStruct DeviceEntry_t;
struct DeviceEntryStruct {
DeviceEntry_t* next;
const char* path;
struct DevPropDevice* device;
};
DeviceEntry_t* TheDeviceRegistry = NULL;
char *efi_inject_get_devprop_string(uint32_t *len)
{
if(string) {
struct DevPropDevice*device;
const charpciroot_string[] = "PciRoot(0x";
const charpci_device_string[] = "Pci(0x";
DeviceEntry_t* newDeviceEntry;
if (string == NULL || path == NULL) {
return NULL;
string->entries[string->numentries++] = (struct DevPropDevice*)malloc(sizeof(device));
string->entries[string->numentries-1] = device;
// Register the device to the device entries
newDeviceEntry = malloc(sizeof(DeviceEntry_t));
newDeviceEntry->next = TheDeviceRegistry;
TheDeviceRegistry = newDeviceEntry;
newDeviceEntry->path = strdup(path);
newDeviceEntry->device = device;
return device;
}
}
}
}
struct DevPropDevice *devprop_find_device(char *path)
{
DeviceEntry_t* entry;
for (entry = TheDeviceRegistry; entry; entry = entry->next)
if (strcmp(entry->path, path) == 0)
return entry->device;
return NULL;
}
branches/andyvand/i386/libsaio/device_inject.h
7070
7171
7272
73
7374
7475
intdevprop_add_value(struct DevPropDevice *device, char *nm, uint8_t *vl, uint32_t len);
char*devprop_generate_string(struct DevPropString *string);
voiddevprop_free_string(struct DevPropString *string);
struct DevPropDevice *devprop_find_device(char *path);
#endif /* !__LIBSAIO_DEVICE_INJECT_H */
branches/andyvand/i386/libsaio/pci_setup.c
55
66
77
8
89
910
1011
......
1213
1314
1415
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
1549
1650
1751
1852
1953
54
55
56
57
58
59
60
2061
2162
2263
......
3172
3273
3374
75
76
77
78
79
80
81
82
83
3484
3585
3686
......
91141
92142
93143
94
95
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
96190
#include "nvidia.h"
#include "ati.h"
#include "gma.h"
#include "device_inject.h"
extern void set_eth_builtin(pci_dt_t *eth_dev);
extern int ehci_acquire(pci_dt_t *pci_dev);
extern int uhci_reset(pci_dt_t *pci_dev);
extern void force_enable_hpet(pci_dt_t *lpc_dev);
static int PciToEfiOverride(const char * propKey,
unsigned long numbers[],
unsigned long maxArrayCount )
{
char * propStr;
unsigned long count = 0;
propStr = newStringForKey( (char *) propKey , &bootInfo->pciConfig );
if ( propStr )
{
char * delimiter = propStr;
char * p = propStr;
while ( count < maxArrayCount && *p != '\0' )
{
unsigned long val = strtoul( p, &delimiter, 16 );
if ( p != delimiter )
{
numbers[count++] = val;
p = delimiter;
}
while ( ( *p != '\0' ) && !isdigit(*p) )
p++;
}
free( propStr );
}
return count;
}
int hasPciToEfiMapping = -1;/* -1: not loaded, 0: does not exist, 1: loaded */
void setup_pci_devs(pci_dt_t *pci_dt)
{
char *devicepath;
bool do_eth_devprop, do_gfx_devprop, fix_ehci, fix_legoff, fix_uhci, fix_usb, do_enable_hpet;
pci_dt_t *current = pci_dt;
char override_key[512];
unsigned long id_array[4];
int id_count;
char* id_keys[4] = { "vendor-id", "device-id", "subsystem-vendor-id", "subsystem-id" };
int i;
struct DevPropDevice* device;
struct DevPropString *deviceString;
do_eth_devprop = do_gfx_devprop = fix_ehci = fix_legoff = fix_uhci = fix_usb = do_enable_hpet = false;
getBoolForKey(kUSBLegacyOff, &fix_legoff, &bootInfo->bootConfig);
getBoolForKey(kForceHPET, &do_enable_hpet, &bootInfo->bootConfig);
// Get some PCI stuff
if (hasPciToEfiMapping == -1)
{
hasPciToEfiMapping = (loadSystemConfig("", &bootInfo->pciConfig, "pci.plist", true) == 0 ? 1 : 0);
if (hasPciToEfiMapping)
verbose("pci.plist is found.\n");
}
while (current)
{
devicepath = get_pci_dev_path(current);
}
setup_pci_devs(current->children);
current = current->next;
}
if (hasPciToEfiMapping)
{
/* Device ID override injection */
memset(id_array, sizeof(id_array), 0);
sprintf(override_key, "pci%04x,%04x", current->vendor_id, current->device_id);
id_count = PciToEfiOverride(override_key, id_array, 4);
device = NULL;
for (i = 0; i < id_count; i++)
{
uint8_t fourOctets[4];
uint32_t id = id_array[i];
if (id == 0)
{
if (i == 0)
id = current->vendor_id;
else if (i == 1)
id = current->device_id;
else
continue;
}
fourOctets[0] = id;
fourOctets[1] = id >> 8;
fourOctets[2] = 0;
fourOctets[3] = 0;
if (id != 0)
{
if (device == NULL)
{
device = devprop_find_device(devicepath);
if (device == NULL)
{
deviceString = devprop_create_string();
device = devprop_add_device(deviceString, devicepath);
}
}
devprop_add_value(device, id_keys[i], fourOctets, sizeof(fourOctets));
verbose("%s: %s 0x%02x\n", override_key, id_keys[i], id);
}
}
}
current = current->next;
}
}
branches/andyvand/i386/libsaio/stringTable.c
481481
482482
483483
484
485
486
487
488484
489485
490486
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
487
519488
520489
521490
......
601570
602571
603572
573
574
575
576
577
578
579
604580
605581
606582
607
583
584
585
608586
609
610
611
612
613
614
615
587
588
589
590
591
592
593
594
595
596
597
616598
617599
618
600
601
602
603
604
605
606
607
608
609
619610
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
611
652612
653613
654614
655
615
656616
657617
658
618
619
620
621
659622
660
623
624
625
626
627
628
629
661630
662
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
663655
656
657
658
659
660
664661
665662
666663
667664
668665
669666
670
671
672
667
668
669
673670
674671
675
672
676673
677674
678675
......
770767
771768
772769
770
771
bool getValueForKey( const char *key, const char **val, int *size, config_file_t *config )
{
const char *overrideVal;
int overrideSize;
bool override, ret;
if (getValueForBootKey(bootArgs->CommandLine, key, val, size))
return true;
ret = getValueForConfigTableKey(config, key, val, size);
// Try to find alternate keys in bootInfo->overrideConfig
// and prefer its values with the exceptions for
// "Kernel"="mach_kernel" and "Kernel Flags"="".
if (config->canOverride)
{
if (getValueForConfigTableKey(&bootInfo->overrideConfig, key, &overrideVal, &overrideSize))
{
override = true;
if (ret && (strcmp(key, "Kernel") == 0) && (strcmp(overrideVal, "mach_kernel") == 0))
override = false;
if (ret && (strcmp(key, "Kernel Flags") == 0) && (overrideSize == 0))
override = false;
if (override)
{
*val = overrideVal;
*size = overrideSize;
return true;
}
}
}
return ret;
return getValueForConfigTableKey(config, key, val, size);
}
/* loadSystemConfig
*
* filename == NULL:
* You are loading from com.apple.Boot.plist somewhere in the universe.
* Also, bootarg's "config=" is considerd as replacement name.
*
* filename != NULL:
* Use it as file name.
*
* Returns 0 - successful.
* -1 - unsuccesful.
*/
int loadSystemConfig(config_file_t *config)
#define MAX_DIRSPECS (8)
int loadSystemConfig(const char* bootargs, config_file_t *config, const char* filename, bool override)
{
char *dirspec[] = {
"/Extra/com.apple.Boot.plist",
"bt(0,0)/Extra/com.apple.Boot.plist",
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
char config_filename[512];// Will be filled with the name of boot.plist
char *defaultDirspec[MAX_DIRSPECS] = {
"/Extra/",
"bt(0,0)/Extra/",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
int i, fd, count, ret=-1;
char *overrideDirspec[MAX_DIRSPECS] = {
"rd(0,0)/Extra/",
"/Extra/",
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
{
if ((fd = open(dirspec[i], 0)) >= 0)
{
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret=0;
// enable canOverride flag
config->canOverride = true;
break;
}
}
return ret;
}
/* loadOverrideConfig
*
* Returns 0 - successful.
* -1 - unsuccesful.
*/
int loadOverrideConfig(config_file_t *config)
{
char *dirspec[] = {
"rd(0,0)/Extra/com.apple.Boot.plist",
"/Extra/com.apple.Boot.plist",
char* moreBootPlist[4] = {
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.P/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.R/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist"
"/com.apple.boot.S/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",
};
int i, fd, count, ret=-1;
int i, j, fd, count, size;
const char* val;
char filespec[512];
char *dirspec[MAX_DIRSPECS];
for(i = 0; i< sizeof(dirspec)/sizeof(dirspec[0]); i++)
if (override)
memcpy(dirspec, overrideDirspec, sizeof(overrideDirspec));
else
memcpy(dirspec, defaultDirspec, sizeof(defaultDirspec));
if (filename)
{
if ((fd = open(dirspec[i], 0)) >= 0)
strcpy(config_filename, filename);
}
else
{
strcpy(config_filename, "com.apple.Boot.plist");
for (j = 0; dirspec[j]; j++) /* noop */;
memcpy(&dirspec[j], moreBootPlist, sizeof(moreBootPlist));
// If there is a config designated, point boot.plist to something else.
if (bootargs && getValueForBootKey(bootargs, "config", &val, &size))
{
if (size > 480) size = 480;
if (size > 0)
{
memcpy(config_filename, val, size);
config_filename[size] = 0;
}
}
}
for(i = 0; dirspec[i]; i++)
{
strcpy(filespec, dirspec[i]);
/* If the last char is / then append the boot.plist name */
if (filespec[strlen(filespec)-1] == '/')
{
strcat(filespec, config_filename);
}
if ((fd = open(filespec, 0)) >= 0)
{
// read file
count = read(fd, config->plist, IO_CONFIG_DATA_SIZE);
close(fd);
// build xml dictionary
ParseXMLFile(config->plist, &config->dictionary);
sysConfigValid = true;
ret=0;
break;
sysConfigValid=true;
verbose("Config file %s loaded\n", filespec);
return 0;
}
}
return ret;
return -1;
}
/* loadHelperConfig
return ptr;
}
branches/andyvand/i386/libsaio/saio_types.h
6464
6565
6666
67
6867
6968
7069
typedef struct {
charplist[4096];// buffer for plist
TagPtrdictionary;// buffer for xml dictionary
bool canOverride; // flag to mark a dictionary can be overriden
} config_file_t;
/*
branches/andyvand/i386/libsaio/saio_internal.h
156156
157157
158158
159
159
160160
161
162161
163162
164163
......
204203
205204
206205
206
207
208
207209
208210
209211
extern bool getColorForKey(const char *key, unsigned int *val, config_file_t *configBuff);
extern bool getDimensionForKey( const char *key, unsigned int *value, config_file_t *config, unsigned int dimension_max, unsigned int object_size );
extern int loadConfigFile(const char *configFile, config_file_t *configBuff);
extern int loadSystemConfig(config_file_t *configBuff);
extern int loadSystemConfig(const char* bootargs, config_file_t *configBuff, const char* filename, bool override);
extern int loadHelperConfig(config_file_t *configBuff);
extern int loadOverrideConfig(config_file_t *configBuff);
extern char * newString(const char *oldString);
extern char * getNextArg(char ** ptr, char * val);
extern int ParseXMLFile( char * buffer, TagPtr * dict );
extern BVRef gBootVolume;
extern BVRef gBIOSBootVolume;
/* pci_root.c */
extern int search_and_get_acpi_fd(const char * filename, const char ** outDirspec);
// Function pointer to be filled in if ramdisks are available
extern int (*p_get_ramdisk_info)(int biosdev, struct driveInfo *dip);
extern int (*p_ramdiskReadBytes)( int biosdev, unsigned int blkno,
branches/andyvand/i386/boot2/boot.c
266266
267267
268268
269
270
269
270
271
272
271273
272274
273275
bvChain = getBVChainForBIOSDev(gBIOSDev);
setBootGlobals(bvChain);
// Load boot.plist config file
status = loadSystemConfig(&bootInfo->bootConfig);
// Load boot.plist config file.
// At this point, since the boot args are not typed in yet, just use
// empty string so that loadSystemConfig gets the default.
status = loadSystemConfig("", &bootInfo->bootConfig, NULL, false);
if (getBoolForKey(kQuietBootKey, &quiet, &bootInfo->bootConfig) && quiet) {
gBootMode |= kBootModeQuiet;
branches/andyvand/i386/boot2/drivers.c
163163
164164
165165
166
167
166168
167169
168170
......
198200
199201
200202
203
201204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
202222
203223
204224
......
216236
217237
218238
239
219240
220241
221242
long LoadDrivers( char * dirSpec )
{
int len, i;
const char *string;
char dirSpecExtra[1024];
bool loadTestDrivers = false;
}
// Next try to load Extra extensions from the selected root partition.
for (i = 0 ; i < 2; i++) {
strcpy(dirSpecExtra, "/Extra/");
if (i == 1) {
len = 0;
// Second time around, see if I really want to load
if (!getValueForKey( "AdditionalExtensions", &string, &len, &bootInfo->bootConfig )) {
len = 0;
}
// Make sure there is something there.
if (len > 0 && string) {
strcpy(dirSpecExtra, string);
if (dirSpecExtra[strlen(dirSpecExtra)-1] != '/') strcat(dirSpecExtra, "/");
}
else {
break;
}
}
if (FileLoadDrivers(dirSpecExtra, 0) != 0)
{
// If failed, then try to load Extra extensions from the boot partition
}
}
}
}
// Also try to load Extensions from boot helper partitions.
strcpy(dirSpecExtra, "/com.apple.boot.P/System/Library/");
branches/andyvand/i386/boot2/options.c
11801180
11811181
11821182
1183
1184
1185
1183
1184
11861185
1187
1188
11891186
11901187
11911188
cnt = 0;
}
// Load com.apple.Boot.plist from the selected volume
// and use its contents to override default bootConfig.
// This is not a mandatory opeartion anymore.
// reload the config, this time with the boot arg
loadSystemConfig(gBootArgs, &bootInfo->bootConfig, NULL, true);
loadOverrideConfig(&bootInfo->overrideConfig);
// Use the kernel name specified by the user, or fetch the name
// in the config table, or use the default if not specified.
// Specifying a kernel name on the command line, or specifying
branches/andyvand/i386/libsa/libsa.h
105105
106106
107107
108
109
110
111
108112
109113
110114
extern char * strerror(int errnum);
/*
* strdup.c
*/
extern char * strdup (const char * str);
/*
* strtol.c
*/
extern long strtol(const char * nptr, char ** endptr, int base);
branches/andyvand/i386/libsa/string.c
241241
242242
243243
244
245
246
247
248
249
250
251
252
253
254
255
244256
245257
246258
......
264276
265277
266278
267
return(strncat(s1, s2, strlen(s2)));
}
char * strdup (const char * str)
{
char *clone;
size_t size;
size = strlen (str) + 1;
clone = malloc (size);
memcpy (clone, str, size);
return clone;
}
#if STRNCASECMP
int strncasecmp(const char *s1, const char *s2, size_t len)
{
return csum;
}
branches/andyvand/revision
1
1
69:119
69:140

Archive Download the corresponding diff file

Revision: 141