Root/
Source at commit 1492 created 12 years 10 months ago. By blackosx, re-enable copying of SetFile, add line to copy fdisk440 to relevant package script folders. Add correct path to where fdisk440 for script to work. Next problem to sort is find where org.chameleon.Boot.plist is created?? | |
---|---|
1 | /*␊ |
2 | * Copyright 2009 netkas␊ |
3 | */␊ |
4 | ␊ |
5 | #include "libsaio.h"␊ |
6 | #include "boot.h"␊ |
7 | #include "bootstruct.h"␊ |
8 | ␊ |
9 | #ifndef DEBUG_PCIROOT␊ |
10 | #define DEBUG_PCIROOT 1␊ |
11 | #endif␊ |
12 | ␊ |
13 | #if DEBUG_PCIROOT␊ |
14 | #define DBG(x...) printf(x)␊ |
15 | #else␊ |
16 | #define DBG(x...)␊ |
17 | #endif␊ |
18 | ␊ |
19 | static int rootuid = 10; //value means function wasnt ran yet␊ |
20 | ␊ |
21 | static unsigned int findrootuid(unsigned char * dsdt, int len)␊ |
22 | {␊ |
23 | ␉int i;␊ |
24 | ␉for (i=0; i<64 && i<len-5; i++) //not far than 64 symbols from pci root ␊ |
25 | ␉{␊ |
26 | ␉␉if(dsdt[i] == '_' && dsdt[i+1] == 'U' && dsdt[i+2] == 'I' && dsdt[i+3] == 'D' && dsdt[i+5] == 0x08)␊ |
27 | ␉␉{␊ |
28 | ␉␉␉return dsdt[i+4];␊ |
29 | ␉␉}␊ |
30 | ␉}␊ |
31 | ␉return 11;␊ |
32 | }␊ |
33 | ␊ |
34 | static unsigned int findpciroot(unsigned char * dsdt,int len)␊ |
35 | {␊ |
36 | ␉int i;␊ |
37 | ␊ |
38 | ␉for (i=0; i<len-4; i++) {␊ |
39 | ␉␉if(dsdt[i] == 'P' && dsdt[i+1] == 'C' && dsdt[i+2] == 'I' && (dsdt[i+3] == 0x08 || dsdt [i+4] == 0x08)) {␊ |
40 | ␉␉␉return findrootuid(dsdt+i, len-i);␊ |
41 | ␉␉}␊ |
42 | ␉}␊ |
43 | ␉return 10;␊ |
44 | }␊ |
45 | ␊ |
46 | int getPciRootUID(void)␊ |
47 | {␊ |
48 | ␉char dsdt_dirSpec[128];␊ |
49 | ␊ |
50 | ␉void *new_dsdt;␊ |
51 | ␉const char *val;␊ |
52 | ␉int len,fsize;␊ |
53 | ␉const char * dsdt_filename=NULL;␊ |
54 | ␉extern int search_and_get_acpi_fd(const char *, const char **);␊ |
55 | ␊ |
56 | ␉if (rootuid < 10) return rootuid;␊ |
57 | ␉rootuid = 0;␉/* default uid = 0 */␊ |
58 | ␊ |
59 | ␉if (getValueForKey(kPCIRootUID, &val, &len, &bootInfo->chameleonConfig)) {␊ |
60 | ␉␉if (isdigit(val[0])) rootuid = val[0] - '0';␊ |
61 | ␉␉goto out;␊ |
62 | ␉}␊ |
63 | ␉/* Chameleon compatibility */␊ |
64 | ␉else if (getValueForKey("PciRoot", &val, &len, &bootInfo->chameleonConfig)) {␊ |
65 | ␉␉if (isdigit(val[0])) rootuid = val[0] - '0';␊ |
66 | ␉␉goto out;␊ |
67 | ␉}␊ |
68 | ␉/* PCEFI compatibility */␊ |
69 | ␉else if (getValueForKey("-pci0", &val, &len, &bootInfo->chameleonConfig)) {␊ |
70 | ␉␉rootuid = 0;␊ |
71 | ␉␉goto out;␊ |
72 | ␉}␊ |
73 | ␉else if (getValueForKey("-pci1", &val, &len, &bootInfo->chameleonConfig)) {␊ |
74 | ␉␉rootuid = 1;␊ |
75 | ␉␉goto out;␊ |
76 | ␉}␊ |
77 | ␊ |
78 | ␉␊ |
79 | ␉// Try using the file specified with the DSDT option␊ |
80 | ␉if (getValueForKey(kDSDT, &dsdt_filename, &len, &bootInfo->chameleonConfig))␊ |
81 | ␉{␊ |
82 | ␉␉sprintf(dsdt_dirSpec, dsdt_filename);␊ |
83 | ␉}␊ |
84 | ␉else␊ |
85 | ␉{␊ |
86 | ␉␉sprintf(dsdt_dirSpec, "DSDT.aml");␊ |
87 | ␉}␊ |
88 | ␉␊ |
89 | ␉int fd = search_and_get_acpi_fd(dsdt_dirSpec, &dsdt_filename);␊ |
90 | ␊ |
91 | ␉// Check booting partition␊ |
92 | ␉if (fd<0)␊ |
93 | ␉{␉ ␊ |
94 | ␉ verbose("No DSDT found, using 0 as uid value.\n");␊ |
95 | ␉ rootuid = 0;␊ |
96 | ␉ goto out;␊ |
97 | ␉}␊ |
98 | ␉␊ |
99 | ␉fsize = file_size(fd);␊ |
100 | ␊ |
101 | ␉if ((new_dsdt = malloc(fsize)) == NULL) {␊ |
102 | ␉␉verbose("[ERROR] alloc DSDT memory failed\n");␊ |
103 | ␉␉close (fd);␊ |
104 | ␉␉goto out;␊ |
105 | ␉}␊ |
106 | ␉if (read (fd, new_dsdt, fsize) != fsize) {␊ |
107 | ␉␉verbose("[ERROR] read %s failed\n", dsdt_filename);␊ |
108 | ␉␉close (fd);␊ |
109 | ␉␉goto out;␊ |
110 | ␉}␊ |
111 | ␉close (fd);␊ |
112 | ␊ |
113 | ␉rootuid = findpciroot(new_dsdt, fsize);␊ |
114 | ␉free(new_dsdt);␊ |
115 | ␊ |
116 | ␉// make sure it really works: ␊ |
117 | ␉if (rootuid == 11) rootuid=0; //usually when _UID isnt present, it means uid is zero␊ |
118 | ␉else if (rootuid < 0 || rootuid > 9) ␊ |
119 | ␉{␊ |
120 | ␉␉printf("PciRoot uid value wasnt found, using 0, if you want it to be 1, use -PciRootUID flag");␊ |
121 | ␉␉rootuid = 0;␊ |
122 | ␉}␊ |
123 | out:␊ |
124 | ␉verbose("Using PCI-Root-UID value: %d\n", rootuid);␊ |
125 | ␉return rootuid;␊ |
126 | }␊ |
127 |