Chameleon

Chameleon Commit Details

Date:2015-02-27 00:31:29 (9 years 1 month ago)
Author:ErmaC
Commit:2587
Parents: 2586
Message:sync with trunk (r.2584)
Changes:
M/branches/ErmaC/Enoch/i386/libsaio/smbios.h
M/branches/ErmaC/Enoch/i386/boot2/graphics.c
M/branches/ErmaC/Enoch/i386/libsaio/gma.c
M/branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall
M/branches/ErmaC/Enoch/i386/libsaio/nvidia_helper.c
M/branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall
M/branches/ErmaC/Enoch/i386/libsaio/pci.c
M/branches/ErmaC/Enoch/i386/boot2/modules.c
M/branches/ErmaC/Enoch/i386/libsaio/pci_root.c
M/branches/ErmaC/Enoch/i386/boot2/modules.h
M/branches/ErmaC/Enoch/i386/libsaio/msdos.c
M/branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall
M/branches/ErmaC/Enoch/i386/boot2/gui.c
M/branches/ErmaC/Enoch/i386/libsaio/md5c.c
M/branches/ErmaC/Enoch/i386/boot2/lzvn.c
M/branches/ErmaC/Enoch/i386/modules/Resolution/Resolution.c
M/branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall
M/branches/ErmaC/Enoch/i386/libsaio/fake_efi.h
M/branches/ErmaC/Enoch/i386/boot2/Makefile
M/branches/ErmaC/Enoch/i386/libsaio/xml.c
M/branches/ErmaC/Enoch/i386/boot2/graphic_utils.c
M/branches/ErmaC/Enoch/i386/modules/Keylayout/Keylayout.c
M/branches/ErmaC/Enoch/i386/util/segsize.c
M/branches/ErmaC/Enoch/i386/libsaio/xml.h
M/branches/ErmaC/Enoch/i386/libsaio/efi.h
M/branches/ErmaC/Enoch/i386/modules/AcpiCodec/acpi_codec.c
M/branches/ErmaC/Enoch/package/buildpkg.sh
M/branches/ErmaC/Enoch/i386/libsaio/nvidia.c
M/branches/ErmaC/Enoch/i386/libsaio/vbe.c
M/branches/ErmaC/Enoch/i386/libsaio/ati.c
M/branches/ErmaC/Enoch/i386/libsaio/device_tree.c
M/branches/ErmaC/Enoch/i386/libsaio/load.c
M/branches/ErmaC/Enoch/i386/libsaio/hfs.c
M/branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall
M/branches/ErmaC/Enoch/i386/boot2/drivers.c
M/branches/ErmaC/Enoch/i386/boot2/mboot.c
M/branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall
M/branches/ErmaC/Enoch/i386/libsaio/spd.c
M/branches/ErmaC/Enoch/i386/libsaio/networking.c
M/branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall
M/branches/ErmaC/Enoch/i386/libsaio/disk.c
M/branches/ErmaC/Enoch/i386/libsaio/pci_setup.c

File differences

branches/ErmaC/Enoch/i386/libsaio/fake_efi.h
2929
3030
3131
32
32
3333
3434
3535
#define __LIBSAIO_FAKE_EFI_H
/* Set up space for up to 10 configuration table entries */
#define MAX_CONFIGURATION_TABLE_ENTRIES 10
#define MAX_CONFIGURATION_TABLE_ENTRIES (uint32_t)10
extern void setupFakeEfi(void);
branches/ErmaC/Enoch/i386/libsaio/xml.c
22
33
44
5
5
66
7
7
88
99
1010
1111
1212
13
13
1414
1515
1616
......
1818
1919
2020
21
21
2222
2323
2424
......
2727
2828
2929
30
31
32
33
34
35
36
37
38
39
3040
3141
3242
33
43
3444
35
45
3646
3747
38
48
3949
4050
4151
......
4959
5060
5161
52
62
5363
5464
5565
5666
5767
58
68
5969
60
70
6171
6272
6373
......
127137
128138
129139
130
131
140
132141
133142
134143
135
136
144
145
146
137147
138148
139149
......
142152
143153
144154
145
155
156
146157
147158
148159
149
160
161
150162
151163
152164
153
165
154166
155167
156168
157169
158170
159
160
171
161172
162173
163
164
174
175
176
165177
166178
167179
......
173185
174186
175187
176
188
189
177190
178191
179192
180193
181
194
195
182196
183197
184198
......
188202
189203
190204
191
205
206
192207
193208
194209
......
204219
205220
206221
207
222
223
208224
209225
210226
......
214230
215231
216232
217
233
218234
219235
220
236
237
221238
222239
223
240
224241
225242
226243
227244
228
245
229246
230247
231248
232249
233250
234
251
252
235253
236254
237255
......
243261
244262
245263
246
264
247265
248266
267
249268
269
270
271
272
273
250274
251
252
275
276
277
278
279
280
281
282
283
284
285
286
253287
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268288
269289
270290
271291
272
292
293
273294
274295
275296
......
277298
278299
279300
280
301
302
281303
282304
283305
284306
285307
286308
287
309
310
288311
289312
290313
291314
292
315
316
293317
294318
295319
......
303327
304328
305329
306
307330
308331
309332
......
311334
312335
313336
314
315
337
316338
317
318
319
320
339
340
341
342
321343
322344
323345
324346
347
325348
326349
327350
328351
329
330
331
332
352
353
354
355
333356
334
357
335358
336
337
338
339
340
359
360
361
362
363
364
365
366
367
368
369
370
341371
342
343
344
345
346
372
373
374
375
376
377
347378
348
349379
350380
351381
352
353
354
382
383
355384
356
357
385
386
387
358388
359389
360
390
391
361392
362393
363394
364395
365
396
397
366398
367399
368400
369401
370402
371
403
372404
373405
374
406
407
408
375409
376
410
411
412
377413
378414
379415
380
416
417
381418
382419
383420
384421
385
422
423
386424
387
425
426
427
388428
389
429
430
390431
391432
392433
393434
394435
395436
396
397
437
438
439
440
398441
399
442
443
444
400445
401446
402447
403448
404449
405450
406
451
407452
408
453
454
455
409456
410457
411458
412459
413460
414461
415
416
462
463
464
465
417466
418
467
468
469
419470
420471
421472
......
430481
431482
432483
433
484
434485
435486
436487
437488
438489
439490
440
491
492
441493
442
443
494
495
496
497
498
444499
445500
446501
447502
448503
449504
450
451
505
506
507
508
452509
453
510
511
512
454513
455514
456515
457516
458517
459518
460
519
461520
462
521
522
523
463524
464525
465526
466527
467528
468529
469
470
530
531
532
533
471534
472
535
536
537
473538
474539
475540
476541
477542
478543
479
544
480545
546
547
548
549
550
481551
482552
483553
......
485555
486556
487557
488
558
489559
490560
491
561
562
563
492564
493565
494566
495567
496568
497569
498
570
571
499572
500573
501574
502575
503
576
577
504578
505579
506580
......
511585
512586
513587
514
588
589
515590
516
591
592
593
517594
518
595
596
597
598
519599
520600
521601
522602
523
603
604
524605
525
526
606
607
608
609
527610
528611
529
612
613
530614
531
615
616
617
532618
533619
534620
535621
536
537
538
622
623
624
625
539626
540627
541628
542
629
630
543631
544632
545633
......
549637
550638
551639
552
553
640
554641
555
556
642
643
644
645
646
557647
558
559
560
561
562
648
649
650
651
563652
564
653
654
565655
566656
567657
568658
569659
570660
571
661
662
572663
573664
574665
575666
576667
577668
578
669
670
579671
580672
581673
582674
583675
584676
585
677
678
586679
587680
588681
......
601694
602695
603696
604
605
697
606698
607
608
609
699
700
701
702
703
610704
611705
612
706
707
613708
614709
615710
616711
617
712
713
618714
619715
620716
621717
622
718
719
623720
624721
625722
626723
627724
628
725
726
629727
630728
631729
......
638736
639737
640738
641
739
642740
643741
644742
645743
646744
647745
648
649
746
650747
651
652
748
749
653750
654751
655
752
753
656754
657755
658756
659757
660
758
759
661760
662761
663
762
664763
665
764
765
666766
667767
668768
669769
670770
671771
672
772
773
673774
674
675775
676776
677777
......
680780
681781
682782
683
684
783
685784
686785
687786
......
704803
705804
706805
707
806
708807
709
808
809
710810
711811
712812
713813
714814
715
815
816
716817
717818
718819
719820
720
821
822
721823
722
723
724
824
825
826
827
725828
726
829
830
831
727832
728
833
834
835
729836
730
837
838
839
731840
732841
733842
734843
735844
736845
737
738
846
847
848
849
850
739851
740852
741853
742854
743855
744
745
746
856
857
858
859
860
861
747862
748863
749864
......
760875
761876
762877
763
878
764879
765
880
766881
767882
768883
......
772887
773888
774889
775
776
890
777891
778
779
780
892
893
894
895
781896
782897
783
898
899
900
901
784902
785903
786
904
905
906
907
787908
788909
789910
790911
791912
792
913
793914
794915
795
916
917
796918
797
798919
920
921
799922
800923
801924
......
804927
805928
806929
807
808
930
809931
810
811
932
933
812934
813935
814
936
937
938
939
815940
816941
817
942
943
944
945
818946
819947
820948
821949
822950
823
824
951
952
953
825954
826
827955
828956
829957
......
833961
834962
835963
836
837
964
838965
839966
840967
841968
842
969
970
971
972
843973
844974
845
846
975
976
977
847978
848
849979
980
850981
851982
852983
......
855986
856987
857988
858
859
989
860990
861
991
992
862993
863
994
995
864996
865997
866998
867999
8681000
869
870
1001
1002
1003
1004
1005
1006
1007
8711008
8721009
8731010
8741011
875
876
1012
1013
1014
1015
1016
1017
1018
8771019
8781020
8791021
8801022
8811023
8821024
883
1025
1026
8841027
8851028
8861029
......
8931036
8941037
8951038
896
897
1039
8981040
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
9151066
9161067
9171068
......
9191070
9201071
9211072
922
923
924
925
1073
1074
9261075
927
928
1076
1077
9291078
930
931
932
933
934
935
936
937
938
939
940
941
942
943
1079
1080
1081
1082
1083
1084
1085
9441086
945
946
1087
1088
1089
1090
1091
1092
1093
1094
1095
9471096
948
949
950
951
1097
1098
1099
1100
1101
1102
1103
9521104
9531105
9541106
9551107
9561108
957
958
1109
9591110
9601111
961
1112
1113
9621114
9631115
9641116
965
1117
1118
9661119
9671120
9681121
......
9711124
9721125
9731126
974
975
1127
1128
9761129
9771130
9781131
......
9921145
9931146
9941147
995
1148
9961149
997
1150
9981151
9991152
10001153
10011154
1002
1003
1155
10041156
10051157
1006
10071158
1159
1160
10081161
10091162
10101163
1011
1012
1164
1165
1166
10131167
1014
1168
1169
10151170
10161171
10171172
......
10271182
10281183
10291184
1030
1185
1186
10311187
10321188
10331189
......
10381194
10391195
10401196
1041
1042
1197
10431198
10441199
1045
1200
10461201
10471202
10481203
1049
1204
1205
10501206
10511207
10521208
10531209
10541210
10551211
1056
1212
1213
10571214
10581215
10591216
10601217
1061
1218
1219
10621220
1063
1221
1222
1223
10641224
10651225
10661226
......
10721232
10731233
10741234
1075
1076
1235
10771236
10781237
1079
1238
1239
1240
1241
1242
1243
10801244
1081
1245
10821246
1083
1084
1247
1248
1249
1250
10851251
10861252
10871253
......
10891255
10901256
10911257
1092
1258
1259
10931260
10941261
10951262
......
10981265
10991266
11001267
1101
1268
1269
11021270
11031271
11041272
......
11121280
11131281
11141282
1115
1283
1284
11161285
11171286
1118
1287
1288
1289
11191290
11201291
11211292
......
11341305
11351306
11361307
1137
1308
1309
11381310
11391311
1140
1312
1313
1314
11411315
1142
1316
1317
1318
11431319
11441320
11451321
......
11491325
11501326
11511327
1152
1328
11531329
1154
1330
1331
11551332
11561333
11571334
1158
1335
1336
11591337
11601338
11611339
11621340
11631341
11641342
1165
1343
11661344
1167
1345
1346
11681347
11691348
11701349
1171
1350
1351
11721352
11731353
11741354
......
11791359
11801360
11811361
1182
1362
1363
11831364
1184
1365
1366
1367
11851368
11861369
11871370
......
11931376
11941377
11951378
1196
1379
1380
11971381
11981382
1199
1383
1384
1385
12001386
12011387
12021388
......
12091395
12101396
12111397
1212
1398
1399
12131400
12141401
12151402
1216
1403
1404
1405
12171406
12181407
12191408
12201409
12211410
1222
1411
12231412
1224
1413
1414
12251415
12261416
12271417
......
12291419
12301420
12311421
1232
1422
1423
12331424
12341425
12351426
12361427
1237
1428
1429
12381430
12391431
12401432
......
12461438
12471439
12481440
1249
1441
1442
12501443
12511444
12521445
12531446
12541447
1255
1448
1449
12561450
12571451
12581452
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* Reserved.
* Reserved.
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 2.0 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
#include "sl.h"
#include "xml.h"
#ifndef DEBUG_XML
#define DEBUG_XML 0
#endif
#if DEBUG_XML
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
string_ref *ref_strings = NULL;
/// TODO: remove below
static char* buffer_start = NULL;
static char *buffer_start = NULL;
// TODO: redo the next two functions
void SaveRefString(char* string, int id)
void SaveRefString(char *string, int id)
{
//printf("Adding Ref String %d (%s)\n", id, string);
string_ref* tmp = ref_strings;
string_ref *tmp = ref_strings;
while(tmp)
{
if(tmp->id == id)
string_ref* new_ref = malloc(sizeof(string_ref));
new_ref->string = malloc(strlen(string)+1);
sprintf(new_ref->string, "%s", string);
snprintf(new_ref->string, (strlen(string)+1)* sizeof(char),"%s", string);
new_ref->id = id;
new_ref->next = ref_strings;
ref_strings = new_ref;
}
char* GetRefString(int id)
char *GetRefString(int id)
{
string_ref* tmp = ref_strings;
string_ref *tmp = ref_strings;
while(tmp)
{
if(tmp->id == id) return tmp->string;
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetProperty(TagPtr dict, const char * key)
TagPtr XMLGetProperty(TagPtr dict, const char *key)
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) {
return 0;
if (dict->type != kTagTypeDict)
{
return NULL;
}
tag = 0;
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
if ((tag->type != kTagTypeKey) || (tag->string == 0))
{
continue;
}
if (!strcmp(tag->string, key)) {
if (!strcmp(tag->string, key))
{
return tag->tag;
}
}
return 0;
return NULL;
}
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetKey( TagPtr dict, int id )
TagPtr XMLGetKey( TagPtr dict, int id )
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) {
if (dict->type != kTagTypeDict)
{
return 0;
}
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
if ((tag->type != kTagTypeKey) || (tag->string == 0))
{
continue;
}
element++;
if(id == element) {
if(id == element)
{
return tag;
}
TagPtr XMLGetValueForKey(TagPtr key)
{
if (!key || key->type != kTagTypeKey) {
if (!key || key->type != kTagTypeKey)
{
return 0;
}
int count = 0;
TagPtr tagList, tag;
if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) {
if (dict->type != kTagTypeDict && dict->type != kTagTypeArray)
{
return 0;
}
{
tag = tagList;
tagList = tag->tagNext;
if (((tag->type != kTagTypeKey) && ((tag->string == 0) || (tag->string[0] == 0)))
&& (dict->type != kTagTypeArray)// If we are an array, any element is valid
) {
)
{
continue;
}
//if(tag->type == kTagTypeKey) printf("Located key %s\n", tag->string);
count++;
}
return count;
}
TagPtr XMLGetElement( TagPtr dict, int id )
{
if(dict->type != kTagTypeArray) {
if(dict->type != kTagTypeArray)
{
return 0;
}
element++;
tmp = tmp->tagNext;
}
return tmp;
}
/* Function for basic XML character entities parsing */
typedef const struct XMLEntity {
const char *name;
size_t nameLen;
char value;
} XMLEntity;
char*
XMLDecode(const char* src)
/* This is ugly, but better than specifying the lengths by hand */
// <!-- a comment XML -->
#define _e(str,c) {str,sizeof(str)-1,c}
const XMLEntity ents[] = {
_e("quot;",'"'), // double quotation mark
_e("apos;",'\''), // ampersand
_e("lt;", '<'), // apostrophe (apostrophe-quote)
_e("gt;", '>'), // less-than sign
_e("amp;", '&') // greater-than sign
};
char *XMLDecode(const char *src)
{
typedef const struct XMLEntity {
const char* name;
size_t nameLen;
char value;
} XMLEntity;
/* This is ugly, but better than specifying the lengths by hand */
#define _e(str,c) {str,sizeof(str)-1,c}
const XMLEntity ents[] = {
_e("quot;",'"'), _e("apos;",'\''),
_e("lt;", '<'), _e("gt;", '>'),
_e("amp;", '&')
};
size_t len;
const char *s;
char *out, *o;
if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) ) {
if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) )
{
return 0;
}
s = src;
while (s <= src+len) /* Make sure the terminator is also copied */
{
if ( *s == '&' ) {
if ( *s == '&' )
{
bool entFound = false;
int i;
s++;
for ( i = 0; i < sizeof(ents)/sizeof(ents[0]); i++)
{
if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 ) {
if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 )
{
entFound = true;
break;
}
}
if ( entFound ) {
if ( entFound )
{
*o++ = ents[i].value;
s += ents[i].nameLen;
return out;
}
//#if UNUSED
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file, the final pos will be returned
// Puts the first dictionary it finds in the
// tag pointer and returns the end of the dic, or returns -1 if not found.
//
long
XMLParseFile( char * buffer, TagPtr * dict )
long XMLParseFile( char * buffer, TagPtr *dict )
{
long length, pos;
TagPtr tag;
pos = 0;
char *configBuffer;
longlength;
longpos = 0;
TagPtrtag;
char*configBuffer;
int strlength = strlen(buffer);
configBuffer = malloc(strlength+1);
bcopy(buffer, configBuffer, strlength);
configBuffer[strlength] = 0;
buffer_start = configBuffer;
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
pos += length;
pos += length;
if (tag == 0) continue;
if (tag->type == kTagTypeDict) break;
XMLFreeTag(tag);
}
if (tag == 0)
{
continue;
}
if (tag->type == kTagTypeDict)
{
break;
}
XMLFreeTag(tag);
}
free(configBuffer);
if (length < 0) {
return -1;
}
*dict = tag;
return pos;
if (length < 0)
{
return -1;
}
*dict = tag;
return pos;
}
//#endif /* UNUSED */
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
long XMLParseNextTag( char *buffer, TagPtr *tag )
{
long length, pos;
char * tagName;
longlength = 0;
longpos = 0;
char*tagName = NULL;
length = GetNextTag(buffer, &tagName, 0);
if (length == -1) {
if (length == -1)
{
return -1;
}
pos = length;
if (!strncmp(tagName, kXMLTagPList, 6)) {
if (!strncmp(tagName, kXMLTagPList, 6))
{
length = 0;
// just a header; nothing to parse
// return-via-reference tag should be left alone
}
/***** dict ****/
else if (!strcmp(tagName, kXMLTagDict))
else if (!strncmp(tagName, kXMLTagDict, sizeof(kXMLTagDict)))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
} else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') {
}
else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
} else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) {
}
else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey)) {
else if (!strncmp(tagName, kXMLTagKey, sizeof(kXMLTagKey)))
{
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString)) {
else if (!strncmp(tagName, kXMLTagString, sizeof(kXMLTagString)))
{
length = ParseTagString(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) {
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
// TODO: save tag if if found
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) {
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
} else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
}
/***** integer ****/
else if (!strcmp(tagName, kXMLTagInteger)) {
else if (!strncmp(tagName, kXMLTagInteger, sizeof(kXMLTagInteger)))
{
length = ParseTagInteger(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) {
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) {
}
else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
{
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
} else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
if (tmpTag == 0)
{
return -1;
}
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
} else {
}
else
{
length = ParseTagInteger(buffer + pos, tag);
}
}
/***** false ****/
else if (!strcmp(tagName, kXMLTagFalse)) {
else if (!strncmp(tagName, kXMLTagFalse, sizeof(kXMLTagFalse)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strcmp(tagName, kXMLTagTrue)) {
else if (!strncmp(tagName, kXMLTagTrue, sizeof(kXMLTagTrue)))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** data ****/
else if (!strcmp(tagName, kXMLTagData)) {
else if (!strncmp(tagName, kXMLTagData, sizeof(kXMLTagData)))
{
length = ParseTagData(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) {
}
else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
{
length = ParseTagData(buffer + pos, tag);
} else if (!strcmp(tagName, kXMLTagDate)) {
}
else if (!strncmp(tagName, kXMLTagDate, sizeof(kXMLTagDate)))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) {
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
{
length = ParseTagDate(buffer + pos, tag);
}/***** array ****/
else if (!strcmp(tagName, kXMLTagArray)) {
}
/***** array ****/
else if (!strncmp(tagName, kXMLTagArray, sizeof(kXMLTagArray) ))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) {
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
} else if (!strcmp(tagName, kXMLTagArray "/")) {
}
else if (!strncmp(tagName, kXMLTagArray "/", strlen(kXMLTagArray "/")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
/***** unknown ****/
else {
// it wasn't parsed so we consumed no additional characters
*tag = 0;
else
{
// it wasn't parsed so we consumed no additional characters
*tag = NULL;
length = 0;
}
if (length == -1) {
if (length == -1)
{
return -1;
}
//==========================================================================
// ParseTagList
static long
ParseTagList( char * buffer, TagPtr * tag, long type, long empty )
static long ParseTagList( char *buffer, TagPtr *tag, long type, long empty )
{
long length, pos;
TagPtr tagList, tmpTag;
longpos = 0;
longlength = 0;
TagPtrtagList = NULL;
TagPtrtmpTag;
tagList = 0;
pos = 0;
if (!empty) {
while (1) {
if (!empty)
{
while (1)
{
length = XMLParseNextTag(buffer + pos, &tmpTag);
if (length == -1) {
if (length == -1)
{
break;
}
pos += length;
// detect end of list
if (tmpTag == 0) {
if (tmpTag == NULL)
{
break;
}
tmpTag->tagNext = tagList;
tagList = tmpTag;
}
if (length == -1) {
if (length == -1)
{
XMLFreeTag(tagList);
return -1;
}
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == NULL)
{
XMLFreeTag(tagList);
return -1;
}
//==========================================================================
// ParseTagKey
static long
ParseTagKey( char * buffer, TagPtr * tag )
static long ParseTagKey( char *buffer, TagPtr *tag )
{
long length, length2;
char *string;
TagPtr tmpTag, subTag;
longlength = 0;
longlength2 = 0;
char*string;
TagPtrtmpTag;
TagPtrsubTag;
length = FixDataMatchingTag(buffer, kXMLTagKey);
if (length == -1) {
if (length == -1)
{
return -1;
}
length2 = XMLParseNextTag(buffer + length, &subTag);
if (length2 == -1) {
if (length2 == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == NULL)
{
XMLFreeTag(subTag);
return -1;
}
string = NewSymbol(buffer);
if (string == 0) {
if (string == NULL)
{
XMLFreeTag(subTag);
XMLFreeTag(tmpTag);
return -1;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length + length2;
}
//==========================================================================
// ParseTagString
static long
ParseTagString( char * buffer, TagPtr * tag )
static long ParseTagString( char *buffer, TagPtr *tag )
{
long length;
char * string;
longlength = 0;
char*string;
length = FixDataMatchingTag(buffer, kXMLTagString);
if (length == -1) {
if (length == -1)
{
return -1;
}
TagPtr tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == NULL)
{
return -1;
}
string = NewSymbol(buffer);
if (string == 0) {
if (string == NULL)
{
XMLFreeTag(tmpTag);
return -1;
}
tmpTag->type = kTagTypeString;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->tag = NULL;
tmpTag->tagNext = NULL;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
//==========================================================================
// ParseTagInteger
static long
ParseTagInteger( char * buffer, TagPtr * tag )
static long ParseTagInteger( char *buffer, TagPtr *tag )
{
long length, integer;
bool negative = false;
return 0;
}
size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
if (length == -1) {
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
return -1;
}
integer = 0;
if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value
if(size > 1 && (val[1] == 'x' || val[1] == 'X'))// Hex value
{
val += 2;
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
integer = (integer * 16) + (*val++ - '0');
} else if ((*val >= 'a' && *val <= 'f')) { // a - f
}
else if ((*val >= 'a' && *val <= 'f'))// a - f
{
integer = (integer * 16) + (*val++ - 'a' + 10);
} else if ((*val >= 'A' && *val <= 'F')) { // A - F
}
else if ((*val >= 'A' && *val <= 'F'))// A - F
{
integer = (integer * 16) + (*val++ - 'A' + 10);
} else {
}
else
{
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
XMLFreeTag(tmpTag);
return -1;
}
}
} else if ( size ) { // Decimal value
if (*val == '-') {
}
else if ( size )// Decimal value
{
if (*val == '-')
{
negative = true;
val++;
size--;
}
for (integer = 0; size > 0; size--) {
if(*val) { // UGLY HACK, fix me.
if (*val < '0' || *val > '9') {
for (integer = 0; size > 0; size--)
{
if(*val) // UGLY HACK, fix me.
{
if (*val < '0' || *val > '9')
{
printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char *)integer;
tmpTag->tag = 0;
tmpTag->tag = NULL;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
tmpTag->tagNext = NULL;
*tag = tmpTag;
//==========================================================================
// ParseTagData
static long
ParseTagData( char * buffer, TagPtr * tag )
static long ParseTagData( char *buffer, TagPtr *tag )
{
int actuallen = 0;
long length;
TagPtr tmpTag;
intactuallen = 0;
longlength = 0;
TagPtrtmpTag;
char*string;
length = FixDataMatchingTag(buffer, kXMLTagData);
if (length == -1) return -1;
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == NULL)
{
return -1;
}
//printf("ParseTagData unimplimented\n");
//printf("Data: %s\n", buffer);
//getchar();
char* string = BASE64Decode(buffer, strlen(buffer), &actuallen);
string = BASE64Decode(buffer, strlen(buffer), &actuallen);
tmpTag->type = kTagTypeData;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->tag = NULL;
tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
tmpTag->tagNext = NULL;
*tag = tmpTag;
return length;
//==========================================================================
// ParseTagDate
static long
ParseTagDate( char * buffer, TagPtr * tag )
static long ParseTagDate( char *buffer, TagPtr *tag )
{
long length;
TagPtr tmpTag;
longlength = 0;
TagPtrtmpTag;
length = FixDataMatchingTag(buffer, kXMLTagDate);
if (length == -1) return -1;
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == NULL)
{
return -1;
}
printf("ParseTagDate unimplimented\n");
getchar();
tmpTag->type = kTagTypeDate;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->string = NULL;
tmpTag->tag = NULL;
tmpTag->tagNext = NULL;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
//==========================================================================
// ParseTagBoolean
long
ParseTagBoolean( char * buffer, TagPtr * tag, long type )
long ParseTagBoolean( char *buffer, TagPtr *tag, long type )
{
TagPtr tmpTag;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == NULL)
{
return -1;
}
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->string = NULL;
tmpTag->tag = NULL;
tmpTag->tagNext = NULL;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return 0;
//==========================================================================
// GetNextTag
static long
GetNextTag( char * buffer, char ** tag, long * start )
static long GetNextTag( char *buffer, char **tag, long *start )
{
long cnt, cnt2;
longcnt;
longcnt2;
if (tag == 0) {
if (tag == NULL)
{
return -1;
}
// Find the start of the tag.
cnt = 0;
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
if (buffer[cnt] == '\0') {
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<'))
{
cnt++;
}
if (buffer[cnt] == '\0')
{
return -1;
}
// Find the end of the tag.
cnt2 = cnt + 1;
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
if (buffer[cnt2] == '\0') {
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>'))
{
cnt2++;
}
if (buffer[cnt2] == '\0')
{
return -1;
}
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) {
if (start)
{
*start = cnt;
}
// Returns the length of the data found, counting the end tag,
// or -1 if the end tag was not found.
static long
FixDataMatchingTag( char * buffer, char * tag )
static long FixDataMatchingTag( char *buffer, char *tag )
{
long length, start, stop;
char * endTag;
start = 0;
while (1)
{
length = GetNextTag(buffer + start, &endTag, &stop);
if (length == -1) return -1;
if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break;
start += length;
}
buffer[start + stop] = '\0';
return start + length;
longlength;
longstart;
longstop;
char*endTag;
start = 0;
while (1)
{
length = GetNextTag(buffer + start, &endTag, &stop);
if (length == -1)
{
return -1;
}
if ((*endTag == '/') && !strcmp(endTag + 1, tag))
{
break;
}
start += length;
}
buffer[start + stop] = '\0';
return start + length;
}
//==========================================================================
#define kTagsPerBlock (0x1000)
static TagPtr gTagsFree;
static TagPtr
NewTag( void )
static TagPtr gTagsFree= NULL;
static TagPtr NewTag( void )
{
long cnt;
TagPtr tag;
longcnt;
TagPtrtag;
if (gTagsFree == 0)
{
tag = (TagPtr)malloc(kTagsPerBlock * sizeof(Tag));
if (tag == 0) return 0;
// Initalize the new tags.
for (cnt = 0; cnt < kTagsPerBlock; cnt++)
{
tag[cnt].type = kTagTypeNone;
tag[cnt].string = 0;
tag[cnt].tag = 0;
tag[cnt].tagNext = tag + cnt + 1;
}
tag[kTagsPerBlock - 1].tagNext = 0;
if (gTagsFree == NULL)
{
tag = (TagPtr)malloc(kTagsPerBlock *sizeof(Tag));
if (tag == NULL)
{
return NULL;
}
gTagsFree = tag;
}
// Initalize the new tags.
for (cnt = 0; cnt < kTagsPerBlock; cnt++)
{
tag[cnt].type = kTagTypeNone;
tag[cnt].string = 0;
tag[cnt].tag = 0;
tag[cnt].tagNext = tag + cnt + 1;
}
tag[kTagsPerBlock - 1].tagNext = 0;
tag = gTagsFree;
gTagsFree = tag->tagNext;
return tag;
gTagsFree = tag;
}
tag = gTagsFree;
gTagsFree = tag->tagNext;
return tag;
}
//==========================================================================
// XMLFreeTag
void
XMLFreeTag( TagPtr tag )
void XMLFreeTag( TagPtr tag )
{
#if DOFREE
if (tag == 0) {
if (tag == NULL)
{
return;
}
if (!XMLIsInteger(tag) && tag->string) {
if (!XMLIsInteger(tag) && tag->string)
{
FreeSymbol(tag->string);
}
// Clear and free the tag.
tag->type = kTagTypeNone;
tag->string = 0;
tag->tag = 0;
tag->string = NULL;
tag->tag = NULL;
tag->offset = 0;
tag->tagNext = gTagsFree;
gTagsFree = tag;
};
typedef struct Symbol Symbol, *SymbolPtr;
static SymbolPtr FindSymbol(char * string, SymbolPtr * prevSymbol);
static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol);
static SymbolPtr gSymbolsHead;
static SymbolPtr gSymbolsHead= NULL;
//==========================================================================
// NewSymbol
static char *
NewSymbol( char * string )
static char *NewSymbol( char *string )
{
static SymbolPtr lastGuy = 0;
SymbolPtr symbol;
SymbolPtrsymbol;
// Look for string in the list of symbols.
symbol = FindSymbol(string, 0);
// Add the new symbol.
if (symbol == 0) {
// Add the new symbol.
if (symbol == NULL)
{
symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string));
if (symbol == 0) { //return 0;
if (symbol == NULL)
{
stop("NULL symbol!");
}
// Update the refCount and return the string.
symbol->refCount++;
if (lastGuy && lastGuy->next != 0) {
if (lastGuy && lastGuy->next != 0)
{
stop("last guy not last!");
}
// FreeSymbol
#if DOFREE
static void
FreeSymbol( char * string )
static void FreeSymbol( char *string )
{
SymbolPtr symbol, prev;
prev = 0;
prev = NULL;
// Look for string in the list of symbols.
symbol = FindSymbol(string, &prev);
if (symbol == 0) {
if (symbol == NULL)
{
return;
}
// Update the refCount.
symbol->refCount--;
if (symbol->refCount != 0) {
if (symbol->refCount != 0)
{
return;
}
// Remove the symbol from the list.
if (prev != 0) {
if (prev != NULL)
{
prev->next = symbol->next;
} else {
}
else
{
gSymbolsHead = symbol->next;
}
//==========================================================================
// FindSymbol
static SymbolPtr
FindSymbol( char * string, SymbolPtr * prevSymbol )
static SymbolPtr FindSymbol( char *string, SymbolPtr *prevSymbol )
{
SymbolPtr symbol, prev;
if (string == NULL)
{
return NULL;
}
symbol = gSymbolsHead;
prev = 0;
prev = NULL;
while (symbol != 0) {
if (!strcmp(symbol->string, string)) {
while (symbol != NULL)
{
if (!strcmp(symbol->string, string))
{
break;
}
symbol = symbol->next;
}
if ((symbol != 0) && (prevSymbol != 0)) {
if ((symbol != NULL) && (prevSymbol != NULL))
{
*prevSymbol = prev;
}
bool XMLIsType(TagPtr dict, enum xmltype type)
{
if(!dict) {
if(!dict)
{
return (type == kTagTypeNone);
}
return (dict->type == type);
TagPtr XMLCastArray(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if(dict->type == kTagTypeArray) {
if(dict->type == kTagTypeArray)
{
return dict;
} else {
return NULL;
TagPtr XMLCastDict(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if(dict->type == kTagTypeDict) {
if(dict->type == kTagTypeDict)
{
return dict;
} else {
}
else
{
return NULL;
}
}
return entry && ((entry->type == kTagTypeString) || (entry->type == kTagTypeKey));
}
char* XMLCastString(TagPtr dict)
char *XMLCastString(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) {
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))
{
return dict->string;
}
return NULL;
}
char* XMLCastData(TagPtr dict, int* length)
char *XMLCastData(TagPtr dict, int* length)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) {
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey))
{
*length = dict->offset;
return dict->string;
}
long XMLCastStringOffset(TagPtr dict)
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) {
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)))
{
return dict->offset;
} else {
}
else
{
return -1;
}
}
bool XMLCastBoolean(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return false;
}
if(dict->type == kTagTypeTrue) {
if(dict->type == kTagTypeTrue)
{
return true;
}
return false;
int XMLCastInteger(TagPtr dict)
{
if(!dict) {
if(!dict)
{
//printf("XMLCastInteger: null dict\n");
return 0;
}
if(dict->type == kTagTypeInteger) {
if(dict->type == kTagTypeInteger)
{
return (int)(dict->string);
}
return 0;
}
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value)
bool XMLAddTagToDictionary(TagPtr dict, char *key, TagPtr value)
{
if (!dict || dict->type != kTagTypeDict) {
if (!dict || dict->type != kTagTypeDict)
{
return false;
}
char* string;
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
return false;
}
string = NewSymbol(key);
if (string == 0) {
if (string == 0)
{
XMLFreeTag(tmpTag);
return false;
}
tmpTag->tagNext = 0;
TagPtr tagList = dict->tag;
if(!tagList) {
if(!tagList)
{
// First tag
dict->tag = tmpTag;
return true;
}
while(tagList && tagList->tagNext) tagList = tagList->tagNext;
if(tagList) {
if(tagList)
{
tagList->tagNext = tmpTag;
return true;
}
branches/ErmaC/Enoch/i386/libsaio/xml.h
22
33
44
5
5
66
77
88
......
1010
1111
1212
13
13
1414
1515
1616
......
1818
1919
2020
21
21
2222
2323
2424
......
4040
4141
4242
43
43
4444
45
45
4646
4747
4848
49
49
5050
5151
5252
......
6363
6464
6565
66
67
68
69
70
71
66
67
68
69
70
71
7272
73
74
75
76
77
78
79
80
81
82
8373
8474
8575
86
76
8777
8878
8979
......
9888
9989
10090
101
91
10292
10393
10494
......
10898
10999
110100
111
101
112102
113103
114104
......
119109
120110
121111
122
112
123113
124114
125115
126
116
127117
128118
129119
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
struct string_ref
{
char* string;
char *string;
int id;
struct string_ref* next;
struct string_ref *next;
};
typedef struct string_ref string_ref;
extern string_ref* ref_strings;
extern string_ref *ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLStringID "ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
#define kPropOSBundleLibraries ("OSBundleLibraries")
#define kPropIOKitPersonalities ("IOKitPersonalities")
#define kPropIONameMatch ("IONameMatch")
#define kPropCFBundleIdentifier("CFBundleIdentifier")
#define kPropCFBundleExecutable("CFBundleExecutable")
#define kPropOSBundleRequired("OSBundleRequired")
#define kPropOSBundleLibraries("OSBundleLibraries")
#define kPropIOKitPersonalities("IOKitPersonalities")
#define kPropIONameMatch("IONameMatch")
/*
struct Tag {
long type;
char *string;
struct Tag *tag;
struct Tag *tagNext;
};
typedef struct Tag Tag, *TagPtr;
*/
extern long gImageFirstBootXAddr;
extern long gImageLastKernelAddr;
TagPtr XMLGetProperty( TagPtr dict, const char * key );
TagPtr XMLGetProperty( TagPtr dict, const char *key );
TagPtr XMLGetElement( TagPtr dict, int id );
TagPtr XMLGetKey( TagPtr dict, int id );
TagPtr XMLGetValueForKey(TagPtr key);
int XMLCastInteger ( TagPtr dict );
TagPtr XMLCastDict ( TagPtr dict );
TagPtr XMLCastArray( TagPtr dict );
char* XMLCastData( TagPtr dict, int* length );
char* XMLCastData( TagPtr dict, int *length );
bool XMLIsBoolean(TagPtr entry);
bool XMLIsString (TagPtr entry);
bool XMLIsData (TagPtr entry);
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value);
bool XMLAddTagToDictionary(TagPtr dict, char *key, TagPtr value);
long XMLParseNextTag(char *buffer, TagPtr *tag);
void XMLFreeTag(TagPtr tag);
// Puts the first dictionary it finds in the
// tag pointer and returns 0, or returns -1 if not found.
//
long XMLParseFile( char * buffer, TagPtr * dict );
long XMLParseFile( char *buffer, TagPtr *dict );
//==========================================================================
// ParseTag*
long ParseTagBoolean( char * buffer, TagPtr * tag, long type );
long ParseTagBoolean( char *buffer, TagPtr *tag, long type );
#endif /* __LIBSAIO_XML_H */
branches/ErmaC/Enoch/i386/libsaio/efi.h
254254
255255
256256
257
257
258258
259259
260260
......
262262
263263
264264
265
265
266266
267267
268268
......
281281
282282
283283
284
284
285285
286286
287287
......
290290
291291
292292
293
293
294294
295295
296296
......
301301
302302
303303
304
304
305305
306306
307307
......
318318
319319
320320
321
321
322322
323323
324324
325325
326326
327327
328
328
329329
330330
331331
......
334334
335335
336336
337
337
338338
339339
340340
......
342342
343343
344344
345
345
346346
347347
348348
......
363363
364364
365365
366
366
367367
368368
369369
......
391391
392392
393393
394
394
395395
396396
397397
IN EFI_UINTN DescriptorSize,
IN EFI_UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR * VirtualMap
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
(EFIAPI *EFI_CONVERT_POINTER) (
IN EFI_UINTN DebugDisposition,
IN OUT VOID **Address
);
) __attribute__((regparm(0)));
// Variable attributes
OUT EFI_UINT32 * Attributes OPTIONAL,
IN OUT EFI_UINTN * DataSize,
OUT VOID * Data
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN OUT EFI_UINTN * VariableNameSize,
IN OUT EFI_CHAR16 * VariableName,
IN OUT EFI_GUID * VendorGuid
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN EFI_UINT32 Attributes,
IN EFI_UINTN DataSize,
IN VOID * Data
);
) __attribute__((regparm(0)));
// EFI Time
(EFIAPI *EFI_GET_TIME) (
OUT EFI_TIME * Time,
OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_TIME) (
IN EFI_TIME * Time
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
OUT EFI_BOOLEAN * Enabled,
OUT EFI_BOOLEAN * Pending,
OUT EFI_TIME * Time
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
(EFIAPI *EFI_SET_WAKEUP_TIME) (
IN EFI_BOOLEAN Enable,
IN EFI_TIME * Time OPTIONAL
);
) __attribute((regparm(0)));
typedef enum {
EfiResetCold,
IN EFI_STATUS ResetStatus,
IN EFI_UINTN DataSize,
IN EFI_CHAR16 * ResetData OPTIONAL
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN EFI_UINT32 Instance,
IN EFI_GUID * CallerId OPTIONAL,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
);
) __attribute__((regparm(0)));
#endif
//
branches/ErmaC/Enoch/i386/libsaio/vbe.c
129129
130130
131131
132
132
133133
134134
135135
#define kC 30.0 // C = (C'-J) * (K/256) + J
#define kM 300.0 // M = K/256 * M'
int Round(double f)
static int Round(double f)
{
return (int)(f + 0.5);
}
branches/ErmaC/Enoch/i386/libsaio/device_tree.c
8282
8383
8484
85
86
85
8786
8887
8988
......
143142
144143
145144
146
147
145
148146
149147
150148
......
206204
207205
208206
209
210
207
211208
212209
213210
......
215212
216213
217214
218
219
215
220216
221217
222218
......
224220
225221
226222
227
228
223
229224
230225
231226
......
246241
247242
248243
249
250
244
251245
252246
253247
......
280274
281275
282276
283
284
277
285278
286279
287280
......
325318
326319
327320
328
329
321
330322
331323
332324
......
378370
379371
380372
381
382
373
383374
384375
385376
......
400391
401392
402393
403
404
394
405395
406396
407397
......
418408
419409
420410
421
422
411
423412
424413
425414
......
486475
487476
488477
489
490
478
491479
492480
493481
......
524512
525513
526514
527
528
515
529516
530517
531518
......
539526
540527
541528
542
543
529
544530
545531
546532
......
548534
549535
550536
551
552
537
553538
554539
555540
......
580565
581566
582567
583
584
568
585569
586570
587571
......
602586
603587
604588
605
606
589
607590
608591
609592
610593
611594
612595
613
614
596
615597
616598
617599
//==============================================================================
Property *
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
Property *DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
{
Property *prop;
//==============================================================================
Node *
DT__AddChild(Node *parent, const char *name)
Node *DT__AddChild(Node *parent, const char *name)
{
Node *node;
//==============================================================================
void
DT__FreeProperty(Property *prop)
void DT__FreeProperty(Property *prop)
{
prop->next = freeProperties;
freeProperties = prop;
//==============================================================================
void
DT__FreeNode(Node *node)
void DT__FreeNode(Node *node)
{
node->next = freeNodes;
freeNodes = node;
//==============================================================================
void
DT__Initialize(void)
void DT__Initialize(void)
{
DPRINTF("DT__Initialize\n");
/*
* Free up memory used by in-memory representation of device tree.
*/
void
DT__Finalize(void)
void DT__Finalize(void)
{
Node *node;
Property *prop;
//==============================================================================
static void *
FlattenNodes(Node *node, void *buffer)
static void *FlattenNodes(Node *node, void *buffer)
{
Property *prop;
DeviceTreeNode *flatNode;
* To use your own buffer, call with *result = &buffer.
*/
void
DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
void DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
{
uint32_t totalSize;
void * buf;
//==============================================================================
char *
DT__GetName(Node *node)
char *DT__GetName(Node *node)
{
Property *prop;
//==============================================================================
// Bungo
Property *
DT__GetProperty(Node *node, const char *name)
Property *DT__GetProperty(Node *node, const char *name)
{
Property *prop;
//==============================================================================
Node *
DT__FindNode(const char *path, bool createIfMissing)
Node *DT__FindNode(const char *path, bool createIfMissing)
{
Node *node, *child;
DTPropertyNameBuf nameBuf;
//==============================================================================
void
DT__PrintNode(Node *node, int level)
void DT__PrintNode(Node *node, int level)
{
char spaces[10], *cp = spaces;
Property *prop;
//==============================================================================
static void
_PrintTree(Node *node, int level)
static void _PrintTree(Node *node, int level)
{
DT__PrintNode(node, level);
//==============================================================================
void
DT__PrintTree(Node *node)
void DT__PrintTree(Node *node)
{
if (node == 0) node = rootNode;
_PrintTree(node, 0);
//==============================================================================
void
DT__PrintFlattenedNode(DTEntry entry, int level)
void DT__PrintFlattenedNode(DTEntry entry, int level)
{
char spaces[10], *cp = spaces;
DTPropertyIterator propIter;
//==============================================================================
static void
_PrintFlattenedTree(DTEntry entry, int level)
static void _PrintFlattenedTree(DTEntry entry, int level)
{
DTEntryIterator entryIter;
//==============================================================================
void
DT__PrintFlattenedTree(DTEntry entry)
void DT__PrintFlattenedTree(DTEntry entry)
{
_PrintFlattenedTree(entry, 0);
}
//==============================================================================
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
DTEntrydtEntry;
DTPropertyIteratorpropIter;
branches/ErmaC/Enoch/i386/libsaio/hfs.c
295295
296296
297297
298
298
299299
300300
301301
......
647647
648648
649649
650
651
650652
651653
652654
......
920922
921923
922924
925
926
927
928
929
930
923931
924932
925933
......
9921000
9931001
9941002
995
1003
9961004
9971005
9981006
......
10181026
10191027
10201028
1029
1030
10211031
10221032
10231033
char entry[512];
char devStr[12];
u_int32_t dirID;
long result, flags;
long result, flags = 0;
if (HFSInitPartition(ih) == -1)
{
*flags = kFileTypeUnknown;
tmpTime = 0;
break;
default:
break;
}
if (time != 0)
curNode = SWAP_BE32(gBTHeaders[btree]->rootNode);
nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
if (!nodeBuf)
{
return -1;
}
node = (BTNodeDescriptor *)nodeBuf;
while (1)
}
// Return error if the file was not found.
if (result != 0)
if (result != 0 || !recordData)
{
free(nodeBuf);
return -1;
break;
case kHFSPlusFileThreadRecord : entrySize = 264;
break;
default:
break;
}
}
else
branches/ErmaC/Enoch/i386/libsaio/spd.c
126126
127127
128128
129
129
130130
131131
132132
......
232232
233233
234234
235
235
236236
237237
238238
#define READ_SPD(spd, base, slot, x) spd[x] = smb_read_byte_intel(base, 0x50 + slot, x)
/** Read from spd *used* values only*/
static void init_spd(char * spd, uint32_t base, int slot)
static void init_spd(char *spd, uint32_t base, int slot)
{
int i;
for (i = 0; i < SPD_INDEXES_SIZE; i++)
#define SLST(a) ((uint8_t)(spd[a] & 0x0f))
/* Get DDR3 or DDR2 serial number, 0 most of the times, always return a valid ptr */
const char *getDDRSerial(const char* spd)
const char *getDDRSerial(const char *spd)
{
static char asciiSerial[17];
branches/ErmaC/Enoch/i386/libsaio/networking.c
2222
2323
2424
25
25
26
2627
2728
2829
2930
3031
31
32
3233
3334
34
35
3536
3637
3738
3839
3940
40
41
42
4143
4244
4345
44
46
47
4548
4649
4750
51
4852
4953
5054
......
111115
112116
113117
114
115
116
118
119
120
117121
118
122
119123
120124
121125
122126
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
141144
142145
143146
144147
145
146
147
148
149
148
149
150
151
152
150153
151
154
152155
153156
154157
......
163166
164167
165168
166
169
167170
168
169
171
172
173
170174
171175
172176
173
177
174178
175179
176180
......
197201
198202
199203
200
204
201205
202206
203
207
204208
205
209
206210
207211
208212
......
215219
216220
217221
218
219
222
220223
221224
222
223
224
225
226
227
225228
226229
227230
228231
229232
230
233
234
231235
232236
233237
234238
235239
236
240
237241
238242
239
243
240244
241245
242246
#define DBG(x...)
#endif
uint32_t builtin_set= 0;
uint32_t builtin_set= 0;
uint8_t builtin= 0;
extern uint32_t devices_number;
//extern uint32_t onboard_number;
int devprop_add_network_template(DevPropDevice *device, uint16_t vendor_id)
{
uint8_t builtin = 0x00;
builtin = 0;
if(device)
{
if((vendor_id != 0x168c) && (builtin_set == 0))
{
builtin_set = 1;
builtin = 0x01;
}
if(!devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 8))
if(!devprop_add_value(device, "built-in", (uint8_t *)&builtin, 1))
{
return 0;
}
if(!devprop_add_value(device, "built-in", (uint8_t*)&builtin, 1))
if(!devprop_add_value(device, "device_type", (uint8_t *)"Ethernet Controller", 20))
{
return 0;
}
devices_number++;
return 1;
}
static network_device generic_ethernet_cards[] =
{
{ 0x0000, 0x0000, "Generic Ethernet Controller" },
{ 0x10EC, 0x0000, "Realtek Ethernet Controller" },
{ 0x11AB, 0x0000, "Marvell Ethernet Controller" },
{ 0x0000, 0x0000, "Generic Ethernet Controller" },
{ 0x10EC, 0x0000, "Realtek Ethernet Controller" },
{ 0x11AB, 0x0000, "Marvell Ethernet Controller" },
{ 0x1969, 0x0000, "Atheros Ethernet Controller" },
{ 0x8086, 0x0000, "Intel(R) Ethernet Controller" },
{ 0x8086, 0x0000, "Intel(R) Ethernet Controller" },
};
char *get_ethernet_model(uint32_t vendor_id, uint32_t device_id)
{
int i = 0;
for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++)
{
if(vendor_id == known_ethernet_cards[i].vendor_id &&
device_id == known_ethernet_cards[i].device_id)
{
return known_ethernet_cards[i].model;
}
}
i = 0;
for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++)
{
if (vendor_id == generic_ethernet_cards[i].vendor_id)
{
return generic_ethernet_cards[i].model;
}
}
return generic_ethernet_cards[0].model;
int i = 0;
for( ; i < sizeof(known_ethernet_cards) / sizeof(known_ethernet_cards[0]); i++)
{
if(vendor_id == known_ethernet_cards[i].vendor_id && device_id == known_ethernet_cards[i].device_id)
{
return known_ethernet_cards[i].model;
}
}
i = 0;
for ( ; i < sizeof(generic_ethernet_cards) / sizeof(generic_ethernet_cards[0]); i++)
{
if (vendor_id == generic_ethernet_cards[i].vendor_id)
{
return generic_ethernet_cards[i].model;
}
}
return generic_ethernet_cards[0].model;
}
void setup_eth_builtin(pci_dt_t *eth_dev)
{
char *devicepath = get_pci_dev_path(eth_dev);
char *name_model = NULL;
DevPropDevice *device = (DevPropDevice*)malloc(sizeof(DevPropDevice));
char *devicepath= get_pci_dev_path(eth_dev);
char *name_model= NULL;
DevPropDevice *device = (DevPropDevice *)malloc(sizeof(DevPropDevice));
verbose("LAN Controller [%04x:%04x] :: %s\n", eth_dev->vendor_id, eth_dev->device_id, devicepath);
if (!string)
{
string = devprop_create_string();
{
verbose("Setting up lan keys\n");
name_model = get_ethernet_model(eth_dev->vendor_id, eth_dev->device_id);
devprop_add_network_template(device, eth_dev->vendor_id);
devprop_add_value(device, "model", (uint8_t*)name_model, (strlen(name_model) + 1));
devprop_add_value(device, "device_type", (uint8_t*)"ethernet", 9);
devprop_add_value(device, "model", (uint8_t *)name_model, (strlen(name_model) + 1));
devprop_add_value(device, "device_type", (uint8_t *)"Ethernet Controller", 20);
stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
if(stringdata)
{
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
memcpy(stringdata, (uint8_t *)devprop_generate_string(string), string->length);
stringlength = string->length;
}
}
void setup_wifi_airport(pci_dt_t *wlan_dev) // ARPT
{
char tmp[16];
uint8_tBuiltIn = 0x00;
builtin = 0;
DevPropDevice *device ;
char *devicepath = get_pci_dev_path(wlan_dev);
verbose("Wifi Controller [%04x:%04x]\n", wlan_dev->vendor_id, wlan_dev->device_id);
if (!string)
{
string = devprop_create_string();
device = devprop_add_device(string, devicepath);
if(device)
{
//sprintf(tmp, sizeof(tmp),"Airport");
sprintf(tmp, "AirPort");
snprintf(tmp, sizeof(tmp),"Airport");
devprop_add_value(device, "AAPL,slot-name", (uint8_t *) tmp, strlen(tmp) + 1);
devprop_add_value(device, "device_type", (uint8_t *) tmp, strlen(tmp) + 1);
devprop_add_value(device, "built-in", (uint8_t *)&BuiltIn, 1);
int i = 0;
devprop_add_value(device, "built-in", (uint8_t *)&builtin, 1);
unsigned int i = 0;
for( ; i < sizeof(known_wifi_cards) / sizeof(known_wifi_cards[0]); i++)
{
if(wlan_dev->vendor_id == known_wifi_cards[i].vendor_id && wlan_dev->device_id == known_wifi_cards[i].device_id)
{
verbose("Setting up wifi keys\n");
devprop_add_value(device, "model", (uint8_t*)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));
devprop_add_value(device, "model", (uint8_t *)known_wifi_cards[i].model, (strlen(known_wifi_cards[i].model) + 1));
// NOTE: I would set the subsystem id and subsystem vendor id here,
// however, those values seem to be ovverriden in the boot process.
// A better method would be injecting the DTGP dsdt method
// and then injecting the subsystem id there.
stringdata = (uint8_t*)malloc(sizeof(uint8_t) * string->length);
stringdata = (uint8_t *)malloc(sizeof(uint8_t) *string->length);
if(stringdata)
{
memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length);
memcpy(stringdata, (uint8_t *)devprop_generate_string(string), string->length);
stringlength = string->length;
}
return;
branches/ErmaC/Enoch/i386/libsaio/gma.c
630630
631631
632632
633
633
634634
635635
636636
637
637
638638
639639
640640
case GMA_HASWELL_ULT_M_GT2: // 0a16
case GMA_HASWELL_ULT_E_GT2: // 0a1e
verbose("Injecting a valid desktop GPU device id (0x0412) instead of patching kexts.\n");
device_id = 0x0412;// Inject a valid desktop GPU device id (0x0412) instead of patching kexts
device_id = 0x00000412;// Inject a valid desktop GPU device id (0x0412) instead of patching kexts
devprop_add_value(device, "vendor-id",(uint8_t *)INTEL_VENDORID, 4);
devprop_add_value(device, "device-id",(uint8_t *)&device_id, sizeof(device_id));
devprop_add_value(device, "compatible",(uint8_t *)"pci8086,0412", 13); // GT2 Desktop
devprop_add_value(device, "IOName",(uint8_t *)"pci8086,0412", 13); // GT2 Desktop
//devprop_add_value(device, "IOName",(uint8_t *)"pci8086,0412", 13); // GT2 Desktop
devprop_add_value(device, "name",(uint8_t *)"pci8086,0412", 13); // GT2 Desktop
verbose("Injeting done: was [%04x:%04x] now is [%04x:%04x]\n", gma_dev->vendor_id, gma_dev->device_id, gma_dev->vendor_id, device_id);
branches/ErmaC/Enoch/i386/libsaio/pci_root.c
4949
5050
5151
52
52
5353
5454
5555
void *new_dsdt;
const char *val;
int len,fsize;
int len, fsize;
const char * dsdt_filename = NULL;
extern int search_and_get_acpi_fd(const char *, const char **);
branches/ErmaC/Enoch/i386/libsaio/nvidia.c
23222322
23232323
23242324
2325
2326
2327
2328
2329
2325
2326
2327
2328
2329
23302330
23312331
23322332
devprop_add_nvidia_template(device);
devprop_add_value(device, "NVCAP", default_NVCAP, NVCAP_LEN);
devprop_add_value(device, "NVPM", default_NVPM, NVPM_LEN);
devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&videoRam, 4);
devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1);
devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1);
devprop_add_value(device, "@0,display-cfg", default_dcfg_0, DCFG0_LEN);
devprop_add_value(device, "@1,display-cfg", default_dcfg_1, DCFG1_LEN);
devprop_add_value(device, "VRAM,totalsize", (uint8_t *)&videoRam, 4);
devprop_add_value(device, "model", (uint8_t *)model, strlen(model) + 1);
devprop_add_value(device, "rom-revision", (uint8_t *)biosVersion, strlen(biosVersion) + 1);
devprop_add_value(device, "@0,display-cfg", (uint8_t *)&default_dcfg_0, DCFG0_LEN);
devprop_add_value(device, "@1,display-cfg", (uint8_t *)&default_dcfg_1, DCFG1_LEN);
/******************** Added Marchrius.**********************/
// For the AppleBacklightDisplay //
branches/ErmaC/Enoch/i386/libsaio/ati.c
6868
6969
7070
71
71
7272
7373
7474
......
835835
836836
837837
838
838
839
839840
840841
841
842
843
842844
843845
844846
845847
846848
847849
848
850
849851
850852
851853
852854
853855
854856
855
857
858
856859
857860
858861
......
865868
866869
867870
868
871
872
869873
870874
871875
......
14201424
14211425
14221426
1427
1428
1429
14231430
14241431
14251432
1426
1427
14281433
14291434
14301435
{"Ipomoea",3},
{"Muskgrass",4},
{"Juncus",4},
{"Osmunda", 4},
{"Osmunda", 4},
{"Pondweed",3},
{"Spikerush", 4},
{"Typha", 5},
{
static uint32_t v = 0;
if (v) {
if (v)
{
return false;
}
if (!card->posted) {
if (!card->posted)
{
return false;
}
v = 1;
val->type = kCst;
val->size = 4;
val->data = (uint8_t *)&v;
return true;
}
bool get_dual_link_val(value_t *val)
{
bool doit = false;
if(getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit) {
if(getBoolForKey(kEnableDualLink, &doit, &bootInfo->chameleonConfig) && doit)
{
uint8_t AAPL00_value[] = {0x01, 0x00, 0x00, 0x00};
val->type = kStr;
val->size = strlen("AAPL00,DualLink") + 1;
bool get_hdmiaudio(value_t * val)
{
bool doit = false;
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit) {
if(getBoolForKey(kEnableHDMIAudio, &doit, &bootInfo->chameleonConfig) && doit)
{
val->type = kStr;
val->size = strlen("onboard-1") + 1;
val->data = (uint8_t *)"onboard-1";
}
#endif
static charname[24];
static charname_parent[24];
static bool init_card(pci_dt_t *pci_dev)
{
booladd_vbios = true;
charname[24];
charname_parent[24];
inti;
intn_ports = 0;
branches/ErmaC/Enoch/i386/libsaio/load.c
5757
5858
5959
60
60
6161
6262
6363
6464
6565
66
66
67
6768
6869
6970
70
71
72
73
7174
7275
7376
......
7881
7982
8083
81
84
85
86
8287
8388
8489
......
258263
259264
260265
261
262
263
264
266
267
268
269
265270
266
271
272
273
267274
268275
269276
......
276283
277284
278285
279
286
280287
281288
282289
......
289296
290297
291298
292
299
300
293301
294302
295303
296
304
305
297306
298307
299308
300309
301
310
311
302312
303313
304314
305315
306
316
317
307318
308319
309320
......
317328
318329
319330
320
331
332
321333
322334
323335
......
355367
356368
357369
358
359
370
371
360372
361373
362374
struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
cpu_type_t fapcputype;
uint32_t fapoffset;
uint32_t fapsize;
uint32_t fapsize;
if (fhp->magic == FAT_MAGIC)/* 0xcafebabe */
{
nfat = fhp->nfat_arch;
swapped = 0;
} else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */
}
else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */
{
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
} else {
}
else
{
return -1;
}
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
} else {
}
else
{
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
segname = segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
} else {
}
else
{
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
}
if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) ||
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) {
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN))))
{
stop("Kernel overflows available space");
}
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) {
if (vmsize && ((strncmp(segname, "__PRELINK_INFO", sizeof("__PRELINK_INFO")) == 0) || (strncmp(segname, "__PRELINK", sizeof("__PRELINK")) == 0)))
{
gHaveKernelCache = true;
}
// Copy from file load area.
if (vmsize>0 && filesize > 0) {
if (vmsize>0 && filesize > 0)
{
bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize);
}
// Zero space at the end of the segment.
if (vmsize > filesize) {
if (vmsize > filesize)
{
bzero((char *)(vmaddr + filesize), vmsize - filesize);
}
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType) {
switch (archCpuType)
{
case CPU_TYPE_I386:
{
i386_thread_state_t *i386ThreadState;
symTab = (struct symtab_command *)cmdBase;
#if DEBUG
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n",
symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
getchar();
#endif
branches/ErmaC/Enoch/i386/libsaio/disk.c
263263
264264
265265
266
266
267267
268268
269269
......
844844
845845
846846
847
847
848848
849849
850850
......
975975
976976
977977
978
978
979
980
981
982
983
984
979985
980986
981987
......
13251331
13261332
13271333
1328
1334
13291335
13301336
13311337
......
14301436
14311437
14321438
1433
1439
14341440
14351441
14361442
......
14931499
14941500
14951501
1502
1503
14961504
14971505
14981506
......
17171725
17181726
17191727
1720
1728
17211729
17221730
17231731
......
17271735
17281736
17291737
1730
1738
17311739
17321740
17331741
......
17361744
17371745
17381746
1739
1747
17401748
17411749
17421750
......
17761784
17771785
17781786
1779
1787
17801788
17811789
17821790
......
17881796
17891797
17901798
1791
1799
17921800
17931801
17941802
......
18281836
18291837
18301838
1831
1832
1839
1840
18331841
18341842
18351843
1836
1844
1845
1846
18371847
18381848
18391849
......
18521862
18531863
18541864
1855
1865
18561866
18571867
18581868
......
21832193
21842194
21852195
2186
2196
21872197
21882198
21892199
......
22182228
22192229
22202230
2221
2231
22222232
22232233
22242234
......
23282338
23292339
23302340
2331
2341
23322342
23332343
23342344
......
23372347
23382348
23392349
2340
2350
23412351
23422352
23432353
return errname;
}
sprintf(errorstr, "Error 0x%02x", errnum);
snprintf(errorstr, sizeof(errorstr), "Error 0x%02x", errnum);
return errorstr; // No string, print error code only
}
// same as Apple ZFS
//EFI_GUID const GPT_ZFS_GUID= { 0x6A898CC3, 0x1DD2, 0x11B2, { 0x99, 0xA6, 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }; // 0xBF01 "Solaris /usr & Apple ZFS
BVRef newGPTBVRef( int biosdev,
static BVRef newGPTBVRef( int biosdev,
int partno,
unsigned int blkoff,
const gpt_ent *part,
{
// Create a new mapping.
map = (struct DiskBVMap *)malloc(sizeof(*map));
map = (struct DiskBVMap *) malloc(sizeof(*map));
if ( !map )
{
return NULL;
}
if ( map )
{
map->biosdev = biosdev;
dpme.dpme_boot_block);
*/
if (strcmp(dpme_p->dpme_type, "Apple_HFS") == 0)
if (strncmp(dpme_p->dpme_type, "Apple_HFS",sizeof("Apple_HFS")) == 0)
{
bvr = newAPMBVRef(biosdev,
i,
// Determine whether the partition header signature is present.
if (memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)))
if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) )
{
goto scanErr;
}
goto scanErr;
}
bzero(buffer,bufferSize);
if (readBytes(biosdev, gptBlock, 0, bufferSize, buffer) != 0)
{
goto scanErr;
if (!valid)
{
// OS X Standard
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/SystemVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/SystemVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no);
if (!loadConfigFile(dirSpec, &systemVersion))
{
else
{
// OS X Server
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/ServerVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/ServerVersion.plist", BIOS_DEV_UNIT(bvr), bvr->part_no);
if (!loadConfigFile(dirSpec, &systemVersion))
{
}
/*else
{
sprintf(dirSpec, "hd(%d,%d)/.IAProductInfo", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.IAProductInfo", BIOS_DEV_UNIT(bvr), bvr->part_no);
if (!loadConfigFile(dirSpec, &systemVersion))
{
if(!valid)
{
int fh = -1;
sprintf(dirSpec, "hd(%d,%d)/.PhysicalMediaInstall", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.PhysicalMediaInstall", BIOS_DEV_UNIT(bvr), bvr->part_no);
fh = open(dirSpec, 0);
if (fh >= 0)
}
else
{
sprintf(dirSpec, "hd(%d,%d)/.IAPhysicalMedia", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/.IAPhysicalMedia", BIOS_DEV_UNIT(bvr), bvr->part_no);
fh = open(dirSpec, 0);
if (fh >= 0)
//
if (bvr->flags & kBVFlagBooter)
{
sprintf(dirSpec, "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strcpy(fileSpec, ".disk_label.contentDetails");
snprintf(dirSpec, sizeof(dirSpec), "hd(%d,%d)/System/Library/CoreServices/", BIOS_DEV_UNIT(bvr), bvr->part_no);
strlcpy(fileSpec, ".disk_label.contentDetails", sizeof(fileSpec));
ret = GetFileInfo(dirSpec, fileSpec, &flags, &time);
if (!ret)
{
fh = open(strcat(dirSpec, fileSpec), 0);
strlcat(dirSpec, fileSpec, sizeof(dirSpec));
fh = open(dirSpec,0);
fileSize = file_size(fh);
if (fileSize > 0 && fileSize < BVSTRLEN)
{
if (!error)
{
label[fileSize] = '\0';
strcpy(bvr->altlabel, label);
strlcpy(bvr->altlabel, label, sizeof(bvr->altlabel));
}
}
}
}
// Try to match hd(x,y) first.
sprintf(testStr, "hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no);
snprintf(testStr, sizeof(testStr),"hd(%d,%d)", BIOS_DEV_UNIT(bvr), bvr->part_no);
if ( matchLen ? !strncmp(match, testStr, matchLen) : !strcmp(match, testStr) )
{
return true;
* hd(x,y)|uuid|"label" "alias";hd(m,n)|uuid|"label" "alias"; etc...
*/
bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen)
static bool getVolumeLabelAlias(BVRef bvr, char* str, long strMaxLen)
{
char *aliasList, *entryStart, *entryNext;
if (name == NULL)
{
sprintf(p, "TYPE %02X", type);
snprintf(p, strMaxLen, "TYPE %02X", type);
}
else
{
}
// Set the devices label
sprintf(bvr->label, p);
snprintf(bvr->label, sizeof(bvr->label), p);
}
branches/ErmaC/Enoch/i386/libsaio/pci_setup.c
44
55
66
7
8
9
10
11
12
13
14
15
16
717
818
919
......
3545
3646
3747
38
48
3949
4050
4151
4252
4353
44
45
46
54
55
56
4757
4858
4959
......
5161
5262
5363
54
64
5565
5666
5767
......
5969
6070
6171
62
72
6373
6474
6575
......
104114
105115
106116
107
117
108118
109119
110120
......
112122
113123
114124
115
125
116126
117
127
118128
119129
120130
121131
122132
123133
124
134
125135
126136
127137
......
131141
132142
133143
134
144
135145
136146
137147
#include "pci.h"
#include "modules.h"
#ifndef DEBUG_PCI_SETUP
#define DEBUG_PCI_SETUP 0
#endif
#if DEBUG_PCI_SETUP
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
extern bool setup_ati_devprop(pci_dt_t *ati_dev);
extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev);
extern bool setup_gma_devprop(pci_dt_t *gma_dev);
switch (current->class_id)
{
case PCI_CLASS_BRIDGE_HOST:
//DBG("Setup BRIDGE_HOST \n");
DBG("Setup BRIDGE_HOST \n");
if (current->dev.addr == PCIADDR(0, 0, 0))
{
dram_controller_dev = current;
}
break; // PCI_CLASS_BRIDGE_HOST
case PCI_CLASS_NETWORK_ETHERNET:
//DBG("Setup ETHERNET %s enabled\n", do_eth_devprop?"":"no");
case PCI_CLASS_NETWORK_ETHERNET:
DBG("Setup ETHERNET %s enabled\n", do_eth_devprop? "is":"is not");
if (do_eth_devprop)
{
setup_eth_builtin(current);
break; // PCI_CLASS_NETWORK_ETHERNET
case PCI_CLASS_NETWORK_OTHER:
//DBG("Setup WIRELESS %s enabled\n", do_wifi_devprop?"":"no");
DBG("Setup WIRELESS %s enabled\n", do_wifi_devprop? "is":"is not");
if (do_wifi_devprop)
{
setup_wifi_airport(current);
break; // PCI_CLASS_NETWORK_OTHER
case PCI_CLASS_DISPLAY_VGA:
//DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop?"":"no");
DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop? "is":"is not");
if (do_gfx_devprop)
{
switch (current->vendor_id)
break; // PCI_CLASS_DISPLAY_VGA
case PCI_CLASS_MULTIMEDIA_AUDIO_DEV:
//DBG("Setup HDEF %s enabled\n", do_hda_devprop?"":"no");
DBG("Setup HDEF %s enabled\n", do_hda_devprop? "is":"is not");
if (do_hda_devprop)
{
setup_hda_devprop(current);
break; // PCI_CLASS_MULTIMEDIA_AUDIO_DEV
case PCI_CLASS_SERIAL_USB:
//DBG("USB fix \n");
DBG("USB\n");
notify_usb_dev(current);
/*if (do_usb_devprop)
/*if (do_usb_devprop)
{
set_usb_devprop(current);
}*/
break; // PCI_CLASS_SERIAL_USB
case PCI_CLASS_BRIDGE_ISA:
//DBG("Force HPET %s enabled\n", do_enable_hpet?"":"no");
DBG("Force HPET %s enabled\n", do_enable_hpet? "is":"is not");
if (do_enable_hpet)
{
force_enable_hpet(current);
}
execute_hook("PCIDevice", current, NULL, NULL, NULL);
//DBG("setup_pci_devs current devID=%08x\n", current->device_id);
DBG("setup_pci_devs current device ID = [%04x:%04x]\n", current->vendor_id, current->device_id);
setup_pci_devs(current->children);
current = current->next;
}
branches/ErmaC/Enoch/i386/libsaio/smbios.h
833833
834834
835835
836
836
837837
838838
839839
typedef struct SMBOemProcessorBusSpeed
{
SMB_STRUCT_HEADER// Type 132
SMBWord ProcessorBusSpeed; // MT/s unit
SMBWord ProcessorBusSpeed;// MT/s unit
} __attribute__((packed)) SMBOemProcessorBusSpeed;
//----------------------------------------------------------------------------------------------------------
branches/ErmaC/Enoch/i386/libsaio/nvidia_helper.c
5252
5353
5454
55
55
5656
57
57
5858
5959
60
60
6161
6262
6363
6464
6565
6666
67
68
69
70
67
68
69
70
7171
7272
7373
74
74
7575
76
76
7777
7878
7979
......
108108
109109
110110
111
112
113
114
111
112
113
114
115
116
117
118
115119
116
120
117121
118122
119123
......
127131
128132
129133
130
134
135
131136
132137
133138
134
139
140
135141
136142
137143
138
144
145
139146
140147
141148
*/
cardList_t* cardList = NULL;
cardList_t *cardList = NULL;
void add_card(char* model, uint32_t id, uint32_t subid, uint64_t videoRam)
void add_card(char *model, uint32_t id, uint32_t subid, uint64_t videoRam)
{
cardList_t* new_card = malloc(sizeof(cardList_t));
cardList_t *new_card = malloc(sizeof(cardList_t));
if (new_card)
{
new_card->next = cardList;
cardList = new_card;
new_card->id = id;
new_card->subid = subid;
new_card->videoRam = videoRam;
new_card->model = model;
new_card->id= id;
new_card->subid= subid;
new_card->videoRam= videoRam;
new_card->model= model;
}
}
cardList_t* FindCardWithIds(uint32_t id, uint32_t subid)
cardList_t *FindCardWithIds(uint32_t id, uint32_t subid)
{
cardList_t* entry = cardList;
cardList_t *entry = cardList;
while(entry)
{
if((entry->id == id) && (entry->subid == subid))
void fill_card_list(void)
{
unsigned inti, count;
TagPtr NVDIATag;
char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL;
uint32_t dev_id = 0, subdev_id = 0;
uint64_t VramSize = 0;
TagPtrNVDIATag;
char*model_name = NULL;
char*match_id = NULL;
char*sub_id = NULL;
char*vram_size = NULL;
uint32_tdev_id = 0;
uint32_tsubdev_id = 0;
uint64_tVramSize = 0;
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA"))))
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char *)"NVIDIA"))))
{
count = XMLTagCount(NVDIATag);
model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));
vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size"));
if (match_id) {
if (match_id)
{
dev_id = strtoul(match_id, NULL, 16);
}
if (sub_id) {
if (sub_id)
{
subdev_id = strtoul(sub_id, NULL, 16);
}
if (vram_size) {
if (vram_size)
{
VramSize = strtoul(vram_size, NULL, 10);
}
branches/ErmaC/Enoch/i386/libsaio/pci.c
1414
1515
1616
17
17
1818
19
19
2020
2121
2222
......
213213
214214
215215
216
216
217217
218218
219219
#endif
#if DEBUG_PCI
#define DBG(x...)printf(x)
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#define DBG(x...)msglog(x)
#endif
pci_dt_t*root_pci_dev;
while (current) {
printf("%02x:%02x.%x [%04x%02x] [%04x:%04x] (subsys [%04x:%04x]):: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, 0 /* FIXME: what should this be? */,
current->class_id, current->progif,
current->vendor_id, current->device_id,
current->subsys_id.subsys.vendor_id, current->subsys_id.subsys.device_id,
get_pci_dev_path(current));
branches/ErmaC/Enoch/i386/libsaio/msdos.c
807807
808808
809809
810
810
811811
812812
813813
}
// Calculate a fake timestamp using modification date and time values.
*time = (dirp->deMDate & 0x7FFF) << (16 + dirp->deMTime);
*time = (dirp->deMDate & 0x7FFF) << (16 + dirp->deMTime);
if (infoValid)
{
branches/ErmaC/Enoch/i386/libsaio/md5c.c
166166
167167
168168
169
169
170
170171
171172
172173
173
174
175
176
174177
175178
176179
partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
for (i = partLen; i + 63 < inputLen; i += 64)
{
MD5Transform (context->state, &((const unsigned char *)input)[i]);
}
index = 0;
} else {
}
else
{
i = 0;
}
branches/ErmaC/Enoch/i386/boot2/graphics.c
11201120
11211121
11221122
1123
1124
1123
1124
11251125
11261126
11271127
unsigned long numbers[],
unsigned long maxArrayCount )
{
char *propStr;
unsigned long count = 0;
char*propStr;
unsigned longcount = 0;
propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig);
branches/ErmaC/Enoch/i386/boot2/drivers.c
740740
741741
742742
743
744
743
745744
746
747
745
746
747
748
748749
749750
750751
......
798799
799800
800801
801
802
802
803803
804804
805805
......
825825
826826
827827
828
829
828
830829
831
832
833
834
835
836
830
831
832
833
834
835
837836
838837
839838
//==========================================================================
// MatchLibraries
static long
MatchLibraries( void )
static long MatchLibraries( void )
{
TagPtr prop, prop2;
ModulePtr module, module2;
TagPtr prop;
TagPtr prop2;
ModulePtr module;
ModulePtr module2;
long done;
do {
// FindModule
#if NOTDEF
static ModulePtr
FindModule( char * name )
static ModulePtr FindModule( char *name )
{
ModulePtr module;
TagPtr prop;
//==========================================================================
// ParseXML
static long
ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
static long ParseXML( char *buffer, ModulePtr *module, TagPtr *personalities )
{
long length, pos;
TagPtr moduleDict, required;
ModulePtr tmpModule;
pos = 0;
longlength;
longpos = 0;
TagPtrmoduleDict;
TagPtrrequired;
ModulePtrtmpModule;
while (1)
{
length = XMLParseNextTag(buffer + pos, &moduleDict);
branches/ErmaC/Enoch/i386/boot2/mboot.c
290290
291291
292292
293
294
293
294
295295
296296
297297
......
404404
405405
406406
407
407
408408
409409
410410
......
415415
416416
417417
418
419
418
419
420420
421421
422422
continue_at_low_address();
// Now fix our return address.
// JrCs: this macro should be rewritten because the code generated by XCode 4.x
// change the value of the argument passed as parameter (multiboot_magic)
// JrCs: this macro should be rewritten because the code generated by XCode 4.x
// change the value of the argument passed as parameter (multiboot_magic)
// FIX_RETURN_ADDRESS_USING_FIRST_ARG(multiboot_magic);
// We can now do just about anything, including return to our caller correctly.
else
doSelectDevice = true;
}
if(getValueForBootKey(mi->mi_cmdline, "timeout", &val, &size))
{
char *endptr;
multiboot_timeout = intVal;
multiboot_timeout_set = 1;
}
}
}
if(getValueForBootKey(mi->mi_cmdline, "partno", &val, &size))
{
char *endptr;
branches/ErmaC/Enoch/i386/boot2/lzvn.c
5757
5858
5959
60
60
6161
62
62
6363
6464
6565
} while (0)
size_t lzvn_decode(void * dst,
size_t lzvn_decode(void *dst,
size_t dst_size,
const void * src,
const void *src,
size_t src_size)
{
size_t rax = 0;
branches/ErmaC/Enoch/i386/boot2/Makefile
4242
4343
4444
45
46
47
45
46
47
48
49
50
51
52
4853
4954
5055
# The ordering is important;
# boot2.o must be first.
OBJS = boot2.o boot.o graphics.o drivers.o prompt.o options.o lzss.o lzvn.o mboot.o \
ramdisk.o picopng.o resume.o bmdecompress.o graphic_utils.o gui.o modules.o \
modules_support.o boot_modules.o
OBJS = boot2.o boot.o graphics.o \
drivers.o prompt.o options.o \
lzss.o lzvn.o mboot.o \
ramdisk.o \
picopng.o resume.o \
bmdecompress.o graphic_utils.o gui.o \
modules.o \
modules_support.o boot_modules.o
# button.o browser.o scrollbar.o == NOTYET
OBJS := $(addprefix $(OBJROOT)/, $(OBJS))
branches/ErmaC/Enoch/i386/boot2/modules.c
2525
2626
2727
28
29
28
29
3030
3131
3232
......
118118
119119
120120
121
121
122122
123123
124124
......
271271
272272
273273
274
274
275275
276276
277277
......
300300
301301
302302
303
303
304304
305305
306306
......
12291229
12301230
12311231
1232
1233
1234
1232
1233
1234
12351235
12361236
12371237
#define DBGPAUSE()
#endif
static inline voidrebase_location(UInt32* location, char* base, int type);
static inline voidbind_location(UInt32* location, char* value, UInt32 addend, int type);
static inline voidrebase_location(UInt32 *location, char *base, int type);
static inline voidbind_location(UInt32 *location, char *value, UInt32 addend, int type);
// NOTE: Global so that modules can link with this
static UInt64 textAddress = 0;
last = mod->mm_string;
}
char* name = strdup(last);
char *name = strdup(last);
name[strlen(last) - sizeof("dylib")] = 0;
DBG("Loading multiboot module %s\n", name);
* adjust it's internal symbol list (sort) to optimize locating new symbols
* NOTE: returns the address if the symbol is "start", else returns 0xFFFFFFFF
*/
long long add_symbol(char* symbol, long long addr, char is64)
long long add_symbol(char *symbol, long long addr, char is64)
{
// This only can handle 32bit symbols
symbolList_t* entry;
*/
void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat)
{
moduleList_t* new_entry = malloc(sizeof(moduleList_t));
moduleList_t *new_entry = malloc(sizeof(moduleList_t));
new_entry->next = loadedModules;
loadedModules = new_entry;
return 0;
}
void start_built_in_module(const char* name,
const char* author,
const char* description,
void start_built_in_module(const char *name,
const char *author,
const char *description,
UInt32 version,
UInt32 compat,
void(*start_function)(void))
branches/ErmaC/Enoch/i386/boot2/modules.h
3434
3535
3636
37
37
3838
3939
4040
4141
42
43
44
42
43
44
4545
4646
4747
......
6868
6969
7070
71
71
7272
7373
7474
......
7676
7777
7878
79
80
79
80
8181
8282
8383
8484
8585
8686
87
87
8888
8989
90
90
9191
9292
93
93
9494
9595
96
96
9797
98
98
9999
100100
101101
102102
103103
104
105
106
107
104
105
106
107
108108
109109
110110
typedef struct callbackList_t
{
void(*callback)(void*, void*, void*, void*);
struct callbackList_t* next;
struct callbackList_t *next;
} callbackList_t;
typedef struct moduleHook_t
{
const char* name;
callbackList_t* callbacks;
struct moduleHook_t* next;
const char *name;
callbackList_t *callbacks;
struct moduleHook_t *next;
} moduleHook_t;
typedef struct modulesList_t
int load_module(char* module);
int is_module_loaded(const char* name);
void module_loaded(const char* name, void* start, const char* author, const char* description, UInt32 version, UInt32 compat);
void module_loaded(const char *name, void *start, const char *author, const char *description, UInt32 version, UInt32 compat);
/********************************************************************************/
/*Symbol Functions*/
/********************************************************************************/
long longadd_symbol(char* symbol, long long addr, char is64);
unsigned intlookup_all_symbols(const char* name);
long longadd_symbol(char *symbol, long long addr, char is64);
unsigned intlookup_all_symbols(const char *name);
/********************************************************************************/
/*Macho Parser*/
/********************************************************************************/
void*parse_mach(void* binary,
void*parse_mach(void *binary,
int(*dylib_loader)(char*),
long long(*symbol_handler)(char*, long long, char),
void (*section_handler)(char* section, char* segment, void* cmd, UInt64 offset, UInt64 address)
void (*section_handler)(char *section, char *segment, void *cmd, UInt64 offset, UInt64 address)
);
unsigned inthandle_symtable(UInt32 base,
struct symtab_command* symtabCommand,
struct symtab_command *symtabCommand,
long long(*symbol_handler)(char*, long long, char),
char is64);
voidrebase_macho(void* base, char* rebase_stream, UInt32 size);
voidrebase_macho(void *base, char *rebase_stream, UInt32 size);
voidbind_macho(void* base, UInt8* bind_stream, UInt32 size);
voidbind_macho(void *base, UInt8 *bind_stream, UInt32 size);
/********************************************************************************/
/*Module Interface*/
/********************************************************************************/
intreplace_function(const char* symbol, void* newAddress);
intexecute_hook(const char* name, void*, void*, void*, void*);
voidregister_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
moduleHook_t*hook_exists(const char* name);
intreplace_function(const char *symbol, void *newAddress);
intexecute_hook(const char *name, void*, void*, void*, void*);
voidregister_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*));
moduleHook_t*hook_exists(const char* name);
#if DEBUG_MODULES
voidprint_hook_list();
branches/ErmaC/Enoch/i386/boot2/gui.c
1313
1414
1515
16
17
18
19
20
21
22
23
24
25
1626
1727
1828
......
483493
484494
485495
496
497
486498
487499
488500
......
551563
552564
553565
554
566
567
568
555569
556570
571
557572
558
573
574
559575
560576
577
561578
562579
563580
......
572589
573590
574591
575
592
593
594
576595
577596
578597
579598
580
599
600
581601
582602
603
583604
584605
585606
......
593614
594615
595616
596
617
618
597619
598620
599621
600622
623
601624
602625
603626
......
647670
648671
649672
650
673
674
651675
652676
653677
654
678
679
655680
656681
657682
658683
659684
660
661
685
686
687
688
662689
663690
664691
......
783810
784811
785812
786
813
787814
788815
789816
......
934961
935962
936963
964
965
966
937967
968
938969
939970
940971
......
958989
959990
960991
961
992
993
962994
963995
964996
965997
966998
967
968
969
970
971
972
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
9731011
9741012
9751013
9761014
1015
9771016
1017
9781018
9791019
9801020
......
9851025
9861026
9871027
988
989
990
991
992
993
994
995
1028
9961029
1030
1031
1032
1033
1034
1035
1036
1037
1038
9971039
9981040
9991041
......
11611203
11621204
11631205
1164
1206
1207
11651208
11661209
11671210
......
12031246
12041247
12051248
1206
1249
1250
12071251
12081252
1209
1253
1254
12101255
12111256
12121257
......
12341279
12351280
12361281
1237
1282
1283
12381284
12391285
12401286
......
12761322
12771323
12781324
1279
1325
1326
12801327
1281
1282
1328
1329
1330
1331
1332
1333
12831334
1284
1285
1335
1336
1337
1338
12861339
12871340
12881341
1289
1342
1343
12901344
12911345
12921346
......
13011355
13021356
13031357
1358
1359
13041360
13051361
13061362
......
13111367
13121368
13131369
1314
1315
1370
1371
1372
1373
13161374
13171375
1318
1376
1377
13191378
13201379
1321
1322
1380
1381
1382
13231383
1324
1384
1385
13251386
13261387
13271388
13281389
13291390
13301391
1331
1392
1393
13321394
13331395
13341396
......
13471409
13481410
13491411
1350
1351
1412
1413
1414
1415
13521416
13531417
13541418
......
13641428
13651429
13661430
1367
1431
13681432
13691433
1370
1434
1435
13711436
13721437
13731438
......
13911456
13921457
13931458
1394
1459
1460
13951461
13961462
13971463
13981464
13991465
1400
1466
1467
14011468
14021469
14031470
1404
1471
1472
14051473
14061474
14071475
14081476
14091477
14101478
1411
1479
1480
14121481
14131482
14141483
14151484
1416
1485
1486
14171487
14181488
14191489
14201490
14211491
14221492
1423
1493
1494
14241495
14251496
14261497
14271498
14281499
1429
1500
1501
14301502
14311503
14321504
......
14481520
14491521
14501522
1451
1523
14521524
14531525
14541526
1455
1456
1527
1528
1529
14571530
14581531
14591532
......
14631536
14641537
14651538
1466
1539
14671540
14681541
1469
1542
14701543
14711544
14721545
......
14771550
14781551
14791552
1480
1553
1554
14811555
14821556
14831557
14841558
14851559
1486
1560
1561
14871562
14881563
14891564
1490
1565
1566
14911567
14921568
14931569
14941570
14951571
14961572
1497
1573
1574
14981575
14991576
15001577
1501
1578
1579
15021580
15031581
15041582
15051583
15061584
1507
1585
1586
15081587
15091588
15101589
15111590
15121591
1513
1592
1593
15141594
15151595
15161596
......
15401620
15411621
15421622
1543
1623
1624
15441625
15451626
15461627
......
15531634
15541635
15551636
1556
1637
1638
15571639
15581640
15591641
15601642
1561
1643
1644
15621645
15631646
1564
1647
1648
15651649
15661650
15671651
......
15711655
15721656
15731657
1574
1658
1659
15751660
15761661
15771662
15781663
15791664
15801665
1581
1666
1667
15821668
15831669
15841670
15851671
15861672
1587
1673
1674
15881675
15891676
15901677
15911678
15921679
1593
1680
1681
15941682
15951683
15961684
......
16051693
16061694
16071695
1608
1696
1697
16091698
1610
1699
1700
16111701
16121702
16131703
......
16161706
16171707
16181708
1619
1709
1710
16201711
1621
1712
1713
16221714
16231715
1624
1716
1717
1718
16251719
16261720
16271721
......
16331727
16341728
16351729
1636
1730
1731
16371732
1638
1733
1734
16391735
16401736
16411737
16421738
16431739
16441740
1645
1741
1742
16461743
16471744
16481745
......
16611758
16621759
16631760
1664
1665
1761
1762
1763
1764
16661765
16671766
1668
1767
1768
1769
16691770
1670
1771
1772
1773
16711774
1672
1775
1776
16731777
16741778
16751779
1676
1780
1781
16771782
16781783
16791784
......
16891794
16901795
16911796
1692
1693
1694
1797
1798
1799
1800
1801
1802
16951803
16961804
16971805
......
17131821
17141822
17151823
1716
1824
1825
17171826
17181827
17191828
1720
1829
1830
17211831
17221832
1723
1833
1834
17241835
17251836
1726
1727
1837
1838
1839
17281840
17291841
1730
1731
1842
1843
1844
1845
17321846
17331847
17341848
1735
1849
17361850
1737
1851
1852
17381853
17391854
17401855
17411856
1742
1857
17431858
17441859
17451860
17461861
17471862
17481863
1749
1864
1865
17501866
17511867
17521868
1753
1869
1870
17541871
17551872
17561873
......
17631880
17641881
17651882
1766
1883
1884
17671885
17681886
17691887
......
17711889
17721890
17731891
1774
1892
1893
17751894
17761895
1777
1778
1896
1897
1898
1899
17791900
1780
1901
1902
17811903
17821904
17831905
......
18121934
18131935
18141936
1815
1816
1937
1938
1939
1940
18171941
1818
1942
1943
18191944
18201945
18211946
......
18762001
18772002
18782003
1879
2004
2005
18802006
1881
1882
2007
2008
2009
2010
18832011
18842012
1885
2013
2014
2015
18862016
18872017
18882018
18892019
18902020
1891
1892
2021
2022
2023
2024
18932025
18942026
1895
2027
2028
2029
18962030
18972031
18982032
......
19162050
19172051
19182052
1919
2053
2054
19202055
19212056
19222057
19232058
1924
2059
2060
19252061
19262062
19272063
......
19332069
19342070
19352071
1936
2072
19372073
19382074
19392075
......
19722108
19732109
19742110
1975
2111
2112
19762113
19772114
19782115
......
19882125
19892126
19902127
1991
19922128
19932129
19942130
......
21652301
21662302
21672303
2304
2305
21682306
21692307
21702308
......
21862324
21872325
21882326
2189
2327
2328
21902329
21912330
21922331
#include "appleboot.h"
#include "vers.h"
#ifndef DEBUG_GUI
#define DEBUG_GUI 0
#endif
#if DEBUG_GUI
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
#define IMG_REQUIRED -1
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
initFont( &font_console, &images[iFontConsole]);
initFont( &font_small, &images[iFontSmall]);
//DBG("Graphic objects successfully loaded !!\n",theme_name);
return 0;
}
int createBackBuffer( window_t *window )
{
gui.backbuffer = malloc(sizeof(pixmap_t));
if(!gui.backbuffer) {
if(!gui.backbuffer)
{
//DBG("Unable to allocate memory for gui.backbuffer");
return 1;
}
gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
if(!gui.backbuffer->pixels) {
if(!gui.backbuffer->pixels)
{
free(gui.backbuffer);
gui.backbuffer = 0;
//DBG("Unable to allocate memory for gui.backbuffer->pixels");
return 1;
}
int createWindowBuffer( window_t *window )
{
window->pixmap = malloc(sizeof(pixmap_t));
if(!window->pixmap) {
if(!window->pixmap)
{
//DBG("Unable to allocate memory for window->pixmap");
return 1;
}
window->pixmap->pixels = malloc( window->width * window->height * 4 );
if(!window->pixmap->pixels) {
if(!window->pixmap->pixels)
{
free(window->pixmap);
window->pixmap = 0;
//DBG("Unable to allocate memory for window->pixmap->pixels");
return 1;
}
int freeWindowBuffer( window_t *window )
{
if (window->pixmap && window->pixmap->pixels) {
if (window->pixmap && window->pixmap->pixels)
{
free(window->pixmap->pixels);
free(window->pixmap);
return 0;
}
return 1;
}
int val, len;
const char *string;
if(getIntForKey("devices_max_visible", &val, theme )) {
if(getIntForKey("devices_max_visible", &val, theme ))
{
gui.maxdevices = MIN( val, gDeviceCount );
}
if(getIntForKey("devices_iconspacing", &val, theme )) {
if(getIntForKey("devices_iconspacing", &val, theme ))
{
gui.devicelist.iconspacing = val;
}
// check layout for horizontal or vertical
gui.layout = HorizontalLayout;
if(getValueForKey( "devices_layout", &string, &len, theme)) {
if (!strcmp (string, "vertical")) {
if(getValueForKey( "devices_layout", &string, &len, theme))
{
if (!strncmp (string, "vertical",sizeof("vertical")))
{
gui.layout = VerticalLayout;
}
}
gui.countdown.pos.y = pixel;
}
/*
/*
* Parse devicelist parameters
*/
setupDeviceList(theme);
return 1;
}
#else
//DBG("Unable to load %s theme plist.\n",theme_name);
return 1;
#endif
}
// parse display size parameters
gui.screen.height = screen_params[1];
// load graphics otherwise fail and return
if (loadGraphics() == 0) {
if (loadGraphics() == 0)
{
loadThemeValues(&bootInfo->themeConfig);
colorFont(&font_small, gui.screen.font_small_color);
colorFont(&font_console, gui.screen.font_console_color);
// create the screen & window buffers
if (createBackBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.devicelist) == 0) {
if (createWindowBuffer(&gui.bootprompt) == 0) {
if (createWindowBuffer(&gui.infobox) == 0) {
if (createWindowBuffer(&gui.menu) == 0) {
if (createBackBuffer(&gui.screen) == 0)
{
if (createWindowBuffer(&gui.screen) == 0)
{
if (createWindowBuffer(&gui.devicelist) == 0)
{
if (createWindowBuffer(&gui.bootprompt) == 0)
{
if (createWindowBuffer(&gui.infobox) == 0)
{
if (createWindowBuffer(&gui.menu) == 0)
{
gui.logo.draw = true;
drawBackground();
// lets copy the screen into the back buffer
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
setVideoMode( GRAPHICS_MODE, 0 );
gui.initialised = true;
return 0;
}
}
}
// not available memory, freeing resources
freeWindowBuffer(&gui.menu);
freeWindowBuffer(&gui.infobox);
freeWindowBuffer(&gui.bootprompt);
freeWindowBuffer(&gui.devicelist);
freeWindowBuffer(&gui.screen);
freeBackBuffer(&gui.screen);
unloadGraphics();
DBG("Loading error occurred, reseting...\n",theme_name);
// Loading error occurred, freeing resources
freeWindowBuffer(&gui.menu);
freeWindowBuffer(&gui.infobox);
freeWindowBuffer(&gui.bootprompt);
freeWindowBuffer(&gui.devicelist);
freeWindowBuffer(&gui.screen);
freeBackBuffer(&gui.screen);
unloadGraphics();
return 1;
}
}
// draw visible device icons
for (i = 0; i < gui.maxdevices; i++) {
for (i = 0; i < gui.maxdevices; i++)
{
BVRef param = menuItems[start + i].param;
bool isSelected = ((start + i) == selection) ? true : false;
drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
if (gui.layout == HorizontalLayout) {
if (gui.layout == HorizontalLayout)
{
p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
}
if (gui.layout == VerticalLayout) {
if (gui.layout == VerticalLayout)
{
p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
}
}
//prompt_pos=0;
if( gui.bootprompt.draw == true ) {
if(gui.bootprompt.draw == true )
{
gui.bootprompt.draw = false;
gui.redraw = true;
// this causes extra frames to be drawn
static inline
void vramwrite (void *data, int width, int height)
{
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
{
memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
} else {
uint32_t r, g, b;
}
else
{
uint32_t r;
uint32_t g;
uint32_t b;
int i, j;
for (i = 0; i < VIDEO (height); i++) {
for (j = 0; j < VIDEO (width); j++) {
for (i = 0; i < VIDEO (height); i++)
{
for (j = 0; j < VIDEO (width); j++)
{
b = ((uint8_t *) data)[4*i*width + 4*j];
g = ((uint8_t *) data)[4*i*width + 4*j + 1];
r = ((uint8_t *) data)[4*i*width + 4*j + 2];
switch (VIDEO (depth)) {
switch (VIDEO (depth))
{
case 32:
*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
break;
case 15:
*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
break;
default:
break;
}
}
}
void updateVRAM()
{
if (gui.redraw) {
if (gui.devicelist.draw) {
if (gui.redraw)
{
if (gui.devicelist.draw)
{
blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
}
if (gui.bootprompt.draw) {
if (gui.bootprompt.draw)
{
blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
}
if (gui.menu.draw) {
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
if (gui.menu.draw)
{
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
}
if (gui.infobox.draw) {
if (gui.infobox.draw)
{
blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
}
}
vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
if (gui.redraw) {
if (gui.redraw)
{
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
gui.redraw = false;
}
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str) {
if (pi->str == pi->last_str) {
if (pi->last_str)
{
if (pi->str == pi->last_str)
{
*(pi->str) = '\0';
return 0;
}
char *formattedtext;
va_list ap;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext); i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], window->pixmap, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
}
char *formattedtext;
va_list ap;
//window = &gui.debug;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
va_end(ap);
position_torigin, cursor, bounds;
int i;
int character;
origin.x = MAX( gui.debug.cursor.x, window->hborder );
origin.y = MAX( gui.debug.cursor.y, window->vborder );
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext); i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], gui.backbuffer, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
}
position_torigin, cursor, bounds;
font_t *font = &font_console;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
pi.str = formattedtext;
pi.last_str = 0;
bounds.y = ( window->height - ( window->vborder * 2 ) );
cursor = origin;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext) ; i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
continue;
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {
if ( cursor.y > ( bounds.y + font->chars[0]->height) )
{
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], gui.backbuffer, cursor);
}
}
// ====================================================================
pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
pixmap_t *charToPixmap(unsigned char ch, font_t *font)
{
unsigned int cha = (unsigned int)ch - 32;
if (cha >= font->count) {
if (cha >= font->count)
{
// return ? if the font for the char doesn't exists
cha = '?' - 32;
}
// ====================================================================
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p)
{
pixmap_t* pm = charToPixmap(ch, font);
if (pm && ((p.x + pm->width) < blendInto->width)) {
if (pm && ((p.x + pm->width) < blendInto->width))
{
blend(pm, blendInto, p);
return pos(p.x + pm->width, p.y);
} else {
}
else
{
return p;
}
}
int i=0;
position_t current_pos = pos(p.x, p.y);
for (i=0; i < strlen(ch); i++) {
for (i=0; i < strlen(ch); i++)
{
// newline ?
if ( ch[i] == '\n' ) {
if ( ch[i] == '\n' )
{
current_pos.x = p.x;
current_pos.y += font->height;
continue;
}
// tab ?
if ( ch[i] == '\t' ) {
if ( ch[i] == '\t' )
{
current_pos.x += TAB_PIXELS_WIDTH;
continue;
}
int height = font->height;
// calculate the width in pixels
for (i=0; i < strlen(text); i++) {
if (text[i] == '\n') {
for (i=0; i < strlen(text); i++)
{
if (text[i] == '\n')
{
width = 0;
height += font->height;
} else if (text[i] == '\t') {
}
else if (text[i] == '\t')
{
width += TAB_PIXELS_WIDTH;
} else {
}
else
{
pixmap_t* pm = charToPixmap(text[i], font);
if (pm){
if (pm)
{
width += pm->width;
}
}
if (width > max_width) {
if (width > max_width)
{
max_width = width;
}
}
int destroyFont(font_t *font)
{
int i;
for (i = 0; i < CHARACTERS_COUNT; i++) {
if (font->chars[i]) {
if (font->chars[i]->pixels) {
for (i = 0; i < CHARACTERS_COUNT; i++)
{
if (font->chars[i])
{
if (font->chars[i]->pixels)
{
free (font->chars[i]->pixels);
}
free (font->chars[i]);
font->height = data->image->height;
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
{
start = end;
// if the pixel is red we've reached the end of the char
if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {
if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
{
end = x + 1;
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
{
font->chars[count]->width = ( end - start) - 1;
font->chars[count]->height = font->height;
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
{
space += ( font->chars[count]->width * data->image->height * 4 );
// we skip the first line because there are just the red pixels for the char width
for( y = 1; y< (font->height); y++) {
for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {
for( y = 1; y< (font->height); y++)
{
for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
{
pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
}
}
// check if font is monospaced
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
{
monospaced = true;
}
font->width = font->chars[count]->width;
count++;
}
}
}
}
for (x = count; x < CHARACTERS_COUNT; x++) {
for (x = count; x < CHARACTERS_COUNT; x++)
{
font->chars[x] = NULL;
}
if(monospaced) {
if(monospaced)
{
font->width = 0;
}
void colorFont(font_t *font, uint32_t color)
{
if( !color ) {
if( !color )
{
return;
}
int count = 0;
pixel_t *buff;
while( font->chars[count++] ) {
while( font->chars[count++] )
{
width = font->chars[count-1]->width;
height = font->chars[count-1]->height;
for( y = 0; y < height; y++ ) {
for( x = 0; x < width; x++ ) {
for( y = 0; y < height; y++ )
{
for( x = 0; x < width; x++ )
{
buff = &(pixel( font->chars[count-1], x, y ));
if( buff->ch.a ) {
if( buff->ch.a )
{
buff->ch.r = (color & 0xFFFF0000) >> 16;
buff->ch.g = (color & 0xFF00FF00) >> 8;
buff->ch.b = (color & 0xFF0000FF);
uint8_t alpha=0;
for( y=0; y<10; y++) {
for( x=0; x<10; x++) {
for( y=0; y<10; y++)
{
for( x=0; x<10; x++)
{
// skip if the pixel should be visible
if(roundedCorner[y][x] != 0xFF){
if(roundedCorner[y][x] != 0xFF)
{
alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
// Upper left corner
pixel(p, x, y).ch.a = alpha;
visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
// lets display the text and allow scroll thru using up down / arrows
while(1) {
while(1)
{
// move to current line in text
for( offset = 0, i = 0; offset < strlen(text); offset++ ) {
if( currentline == i) {
for( offset = 0, i = 0; offset < strlen(text); offset++ )
{
if( currentline == i)
{
break;
}
if( text[offset] =='\n') {
if( text[offset] =='\n')
{
i++;
}
}
// find last visible line in text and place \0
for( i = offset, cnt = 0; i < strlen(text); i++) {
if(text[i]=='\n') {
for( i = offset, cnt = 0; i < strlen(text); i++)
{
if(text[i]=='\n')
{
cnt++;
}
if ( cnt == visiblelines ) {
if ( cnt == visiblelines )
{
text[i]='\0';
break;
}
position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
// draw prev indicator
if(offset) {
if(offset)
{
blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
}
// draw next indicator
if( lines > ( currentline + visiblelines ) ) {
if( lines > ( currentline + visiblelines ) )
{
pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
}
updateVRAM();
key = getchar();
if( key == KEY_UP ) {
if( currentline > 0 ) {
currentline--;
{
int y;
if( time18() > lasttime) {
if( time18() > lasttime)
{
lasttime = time18();
pixmap_t *buffBar = images[iProgressBar].image;
}
}
#endif
// ====================================================================
void drawProgressBar(pixmap_t *blendInto, uint16_t width, position_t p, uint8_t progress)
return buff;
}
break;
default:
break;
}
return DO_NOT_BOOT;
}
char dirspec[256];
if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
if ((strlen(theme_name) + 24) > sizeof(dirspec))
{
usePngImage = false;
return;
}
branches/ErmaC/Enoch/i386/boot2/graphic_utils.c
7878
7979
8080
81
81
82
8283
8384
8485
uint32_t x;
register uint8_t tempB;
for (x = 0; x < (p->height) * (p->width) ; x++) {
for (x = 0; x < (p->height) * (p->width) ; x++)
{
tempB = (p->pixels[x]).ch.b;
(p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
(p->pixels[x]).ch.r = tempB;
branches/ErmaC/Enoch/i386/modules/Resolution/Resolution.c
99
1010
1111
12
13
12
13
1414
15
16
17
15
16
17
1818
1919
void Resolution_start();
void Resolution_start()
{
UInt32 bp = 0;
UInt32 x, y;
UInt32 bp = 0;
UInt32 x, y;
patchVideoBios();
getResolution(&x, &y, &bp);
gui.screen.width = x;
gui.screen.height = y;
getResolution(&x, &y, &bp);
gui.screen.width = x;
gui.screen.height = y;
}
branches/ErmaC/Enoch/i386/modules/Keylayout/Keylayout.c
1313
1414
1515
16
17
18
19
20
21
22
23
24
25
1626
1727
1828
29
1930
2031
2132
......
5061
5162
5263
53
64
65
5466
5567
5668
5769
58
70
71
5972
6073
6174
62
75
76
6377
6478
6579
6680
67
81
82
6883
6984
70
85
7186
72
87
88
7389
7490
7591
7692
77
93
94
7895
79
96
8097
8198
8299
83100
101
84102
85
103
104
86105
87106
107
88108
109
89110
90111
91112
92
113
114
93115
94116
95117
......
97119
98120
99121
100
101
122
123
102124
103
125
126
104127
105128
106129
......
113136
114137
115138
116
117
139
140
141
118142
119
120
143
144
121145
122
123
124
146
147
148
149
125150
126
151
152
153
127154
128155
129156
#include "Keylayout.h"
#include "bootstruct.h"
#ifndef DEBUG_KLAYOUT
#define DEBUG_KLAYOUT 0
#endif
#if DEBUG_KLAYOUT
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
#define kKeyboardLayout "KeyboardLayout"
struct keyboard_layout *current_layout = NULL;
int getchar_replacement();
int getchar_replacement() {
int code = bgetc();
return (code);
}
static uint32_t load_keyboard_layout_file(const char *filename) {
static uint32_t load_keyboard_layout_file(const char *filename)
{
int fd;
char magic[KEYBOARD_LAYOUTS_MAGIC_SIZE];
uint32_t version;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)
{
goto fail; // fail
}
if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
if (read(fd, magic, sizeof(magic)) != sizeof(magic))
{
printf("Can't find magic in keyboard layout file: %s\n", filename);
goto fail;
}
if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) {
if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0)
{
printf("Invalid magic code in keyboard layout file: %s\n", filename);
goto fail;
}
}
if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) {
if (read(fd, (char*) &version, sizeof(version)) != sizeof(version))
{
printf("Can't get version of keyboard layout file: %s\n", filename);
goto fail;
}
if (version != KEYBOARD_LAYOUTS_VERSION) {
if (version != KEYBOARD_LAYOUTS_VERSION)
{
verbose("Bad version for keyboard layout file %s expected v%d found v%d\n",
filename, KEYBOARD_LAYOUTS_VERSION, version);
filename, KEYBOARD_LAYOUTS_VERSION, version);
goto fail;
}
if (current_layout)
{
free(current_layout);
}
current_layout = malloc(sizeof(*current_layout));
if (!current_layout)
{
goto fail;
}
b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0);
if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) {
if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout))
{
printf("Wrong keyboard layout file %s size\n", filename);
goto fail;
}
close(fd);
return 1;
fail:
fail:
if (current_layout) {
if (current_layout)
{
free(current_layout);
current_layout = NULL;
}
const char*val;
intlen;
if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig)) {
sprintf(layoutPath, "/Extra/Keymaps/%s", val);
if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig))
{
snprintf(layoutPath, sizeof(layoutPath),"/Extra/Keymaps/%s", val);
// Add the extension if needed
if (len <= 4 || strcmp(val+len-4,".lyt") != 0)
strncat(layoutPath, ".lyt", sizeof(layoutPath) - strlen(layoutPath) - 1);
if (len <= 4 || strncmp(val+len-4,".lyt", sizeof(".lyt")) != 0)
strlcat(layoutPath, ".lyt", sizeof(layoutPath));
if (!load_keyboard_layout_file(layoutPath)) {
printf("Can't load %s keyboard layout file. Keylayout will not be used !\n",
layoutPath);
if (!load_keyboard_layout_file(layoutPath))
{
DBG("Can't load %s keyboard layout file. Keylayout will not be used !\n",
layoutPath);
sleep(2);
} else if (!replace_function("_getchar", &getchar_replacement)) {
}
else if (!replace_function("_getchar", &getchar_replacement))
{
printf("Can't replace function getchar: Keylayout module can't be used !\n");
sleep(2);
}
branches/ErmaC/Enoch/i386/modules/AcpiCodec/acpi_codec.c
43304330
43314331
43324332
4333
4333
43344334
43354335
43364336
{
DropTables_p = XMLCastDict(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"ACPIDropTables"));
if (DropTables_p) DropTables_tag_count = XMLTagCount(DropTables_p) ;
}
}
U32 new_table = 0ul;
U8 new_table_index = 0, table_added = 0;
branches/ErmaC/Enoch/i386/util/segsize.c
103103
104104
105105
106
106
107107
108108
109109
// boolisDATA;
// unsignedvmsize;
#define lcp((struct load_command *)cp)
#define lcp((struct load_command *)cp)
switch(swap(lcp->cmd)) {
case LC_SEGMENT:
branches/ErmaC/Enoch/package/Scripts.templates/AddOption/postinstall
33
44
55
6
7
8
6
7
8
99
1010
1111
......
3333
3434
3535
36
36
3737
3838
39
39
4040
4141
4242
......
4949
5050
5151
52
52
5353
5454
5555
5656
57
57
5858
5959
6060
set -u
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/plistbuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
key="@optionKey@"
value="@optionValue@"
case "$type" in
bool|text)
/usr/libexec/plistbuddy -c "Add :${key} string ${value}" "$bootPListFile"
/usr/libexec/PlistBuddy -c "Add :${key} string ${value}" "$bootPListFile"
;;
list)
current_values=$( /usr/libexec/plistbuddy -c "Print :${key}" \
current_values=$( /usr/libexec/PlistBuddy -c "Print :${key}" \
"$bootPListFile" 2>/dev/null )
result=$?
current_values="${current_values// /\\ }" # Escape spaces
else
new_values="${current_values}\ ${value}"
fi
/usr/libexec/plistbuddy -c "Set :${key} ${new_values}" \
/usr/libexec/PlistBuddy -c "Set :${key} ${new_values}" \
"$bootPListFile"
else
# Create a new option
new_values="${value}"
/usr/libexec/plistbuddy -c "Add :${key} string ${new_values}" \
/usr/libexec/PlistBuddy -c "Add :${key} string ${new_values}" \
"$bootPListFile"
fi
;;
branches/ErmaC/Enoch/package/Scripts.templates/Post/postinstall
55
66
77
8
89
910
1011
......
1920
2021
2122
22
23
23
24
2425
2526
26
27
27
28
2829
2930
3031
3132
32
33
33
34
3435
3536
36
37
37
38
39
40
41
3842
3943
44
4045
41
46
4247
4348
4449
45
46
47
48
4950
5051
5152
......
5556
5657
5758
58
59
60
59
60
61
62
6163
6264
6365
# $3 = Installation volume (mountpoint) to receive the payload
# $4 = Root directory for the system
logName="@LOG_FILENAME@"
mainLine="=============================================================================="
subLine="------------------------------------------------------------------------------"
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//')
targetDevice=$( /usr/libexec/PlistBuddy -c "Print :targetdev" ${configFile} )
choicedVolume=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
choicedVolume=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
# Check target exists
if [ ! -d "${targetVolume}" ]; then
echo "Target volume does not exist !" >&2
if [ ! -d "${v_mntpt}" ]; then
echo "Ram disk volume does not exist !"
exit 1
fi
if [ ! -d "${v_mntpt}" ]; then
echo "Ram disk volume does not exist !" >&2
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
if [ ! -d "${targetVolume}" ]; then
echo "Target volume does not exist !"
exit 1
fi
if [ ! -d "${choicedVolume}" ]; then
echo "${choicedVolume} volume does not exist !" >&2
echo "${choicedVolume} volume does not exist !"
exit 1
fi
logName="@LOG_FILENAME@"
exec > >(tee -a "${v_mntpt}/${logName}") 2>&1
echo "$mainLine"
echo "Running Post postinstall script"
echo "Target volume = ${choicedVolume}"
echo "Moving Extra folder to ${choicedVolume}"
cp -R "${v_mntpt}/Extra" "${choicedVolume}"/
echo "NOTE: any Themes or modules you have must be there since this now is the boot partition,"
echo " ACPI tables, SMBios.plist and the org.chameleon.Boot.plist (with custom settings"
echo " for the target OSX must be in each partition that contanin it.)"
echo "NOTE: any Themes or modules you have must be there since this now"
echo " is the boot partition. ACPI tables, SMBios.plist and the"
echo " org.chameleon.Boot.plist (with custom settings for the target"
echo " OSX must be in each partition that contain it.)"
echo "$subLine"
echo "Post postinstall script complete"
branches/ErmaC/Enoch/package/Scripts.templates/Pre/preinstall
2929
3030
3131
32
33
32
33
3434
3535
3636
......
4545
4646
4747
48
4849
4950
5051
......
5354
5455
5556
56
57
57
58
5859
5960
6061
}
RAM_DISK() {
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x "${v_mntpt}" ) ]; then
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' | grep -x "${v_mntpt}" ) ]; then
devToUmount=$( LC_ALL=C diskutil info "${v_mntpt}" | grep -i 'Device Node:' | awk '{print $3}' )
UMOUNT_VDISK $devToUmount
fi
exit 1
fi
dev=$( echo "${dev}" | tr -d " \t\n" )
rm -f $configFile
# adding the Ram disk device to InstallConfig.plist to be shared with other packages
/usr/libexec/PlistBuddy -c "Add :ramdisk string ${dev}" $configFile
RAM_DISK
# ensure that ram disk has "/Volumes/BOOTRAMDISK" mount point
v_mntpt=$( LC_ALL=C diskutil info ${dev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
v_mntpt=$( LC_ALL=C diskutil info ${dev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
if [ ! -d "${v_mntpt}" ]; then
echo "Ram Disk not found!"
exit
branches/ErmaC/Enoch/package/Scripts.templates/InstallTheme/postinstall
33
44
55
6
7
8
9
6
7
8
109
1110
1211
set -u
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
themeName="@themeName@"
themeDir="@themeDir@"
logName="@LOG_FILENAME@"
branches/ErmaC/Enoch/package/Scripts.templates/InstallModule/postinstall
33
44
55
6
7
8
6
7
8
99
1010
1111
set -u
configFile='/private/tmp/InstallConfig.plist'
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//' )
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
moduleName="@moduleName@"
moduleFile="@moduleFile@"
branches/ErmaC/Enoch/package/Scripts/Main/ESPpostinstall
11
22
33
4
4
55
66
77
88
99
10
11
12
1013
1114
15
1216
1317
1418
......
2327
2428
2529
26
27
28
30
31
32
2933
3034
3135
3236
3337
34
35
3638
3739
3840
3941
4042
4143
42
4344
4445
4546
4647
4748
49
4850
4951
5052
......
5254
5355
5456
55
57
5658
57
59
5860
5961
6062
......
6971
7072
7173
72
74
7375
74
75
76
7677
7778
7879
......
8384
8485
8586
87
8688
8789
8890
......
9395
9496
9597
96
97
98
99
98100
99101
100102
......
102104
103105
104106
105
107
106108
107109
108110
......
116118
117119
118120
119
120
121
121
122
123
122124
123125
124126
......
128130
129131
130132
131
133
132134
133135
134136
......
144146
145147
146148
147
149
148150
149151
150
152
153
151154
152155
153
156
157
154158
155159
156160
......
159163
160164
161165
162
163
166
167
168
164169
165
170
166171
167172
168173
......
202207
203208
204209
205
206210
207211
208212
......
214218
215219
216220
217
218
219
220
221
222
223
224
225
226
227
228
229
230221
231222
232223
233224
234
235225
236
237
226
227
238228
239
240
241
242
243
244
245
246
247
229
248230
249
250
251
231
232
233
252234
253235
254
255
256
257
258
259
260
261
262
263
264
265
266236
267237
268238
......
275245
276246
277247
278
279
248
249
250
280251
281
282
283
284
285
286
252
253
254
255
256
257
258
259
260
261
262
263
287264
288265
289266
......
298275
299276
300277
301
278
302279
303280
304281
......
332309
333310
334311
335
312
336313
337314
338315
......
355332
356333
357334
358
335
359336
360337
361338
......
364341
365342
366343
344
367345
368346
369347
......
372350
373351
374352
375
376
377
378
379
380353
381354
382355
......
385358
386359
387360
361
388362
389363
390364
391
392
365
366
393367
394368
395369
396
397
370
371
398372
399373
400374
401
402
403
375
376
404377
405378
406379
......
408381
409382
410383
384
385
386
387
388
389
390
391
411392
412393
413394
414395
415
396
416397
417398
418399
#!/bin/bash
# --------------------------------------------------------------------------------------------------------
# Install.sh v1.3, script to install Chameleon
# Install.sh v1.5, script to install Chameleon
# Created by Miky1979 on December 8th, 2014
# --------------------------------------------------------------------------------------------------------
targetVolume="${3}"
InstallToESP="1"
InstallBootloader="0"
espmtp="/Volumes/ESP"
WINDOWS_EXIST="0"
opt="u"
configFile="/private/tmp/InstallConfig.plist"
if [ "${InstallToESP}" == "1" ]; then TYPE="ESP"; else TYPE="Standard"; fi
if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then
# installing stage 0, 1 and 2 only if user want this:
# ie only if have no selected noboot choice
choicedVolume="${targetVolume}"
ESP_MOUNTED="0"
# --------------------------------------------------------------------------------------------------------
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//')
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
logName="Chameleon_Installer_Log.txt"
logFile="${v_mntpt}/${logName}"
# --------------------------------------------------------------------------------------------------------
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage1LoaderExFAT="boot1x"
stage2Loader="boot"
versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' )
# --------------------------------------------------------------------------------------------------------
localdd="/bin/dd"
SS="${usrLocalBin}/sectorsize"
# --------------------------------------------------------------------------------------------------------
# Scanning all Variables. We are switching to the target Volume or its ESP.
# This function is usefull to rescan the new target "at need"
SCAN() {
bootDevice=$( LC_ALL=C diskutil info / | grep -i 'Device Node:' | awk '{print $NF}' )
targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetSlice=${targetDevice#*disk*s}
IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' )
FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
awk '{print $NF}' | awk '{print tolower($0)}' )
disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ $InstallBootloader = "1" ];then
blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' )
# Create a folder inside the Desktop called "DebugChameleon", and the log will be full
DEBUG() {
echo "$mainLine"
echo "DEBUG: display script variables (ESPpostinstall)"
echo "DEBUG: display script variables (${TYPE}postinstall)"
echo "$mainLine"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: bootDevice: Current Volume device is ${bootDevice}"
echo "DEBUG: versionToInstall: version to install is ${versionToInstall}"
echo "DEBUG: IOContent: partition scheme is ${IOContent}"
echo "DEBUG: FS: file System is ${FS}"
# --------------------------------------------------------------------------------------------------------
# Checking for unsupported FAT16 filesystem
CHECK_FAT16() {
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \
| awk '{print $NF}' | awk '{print tolower($0)}' )
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
case $pers in
fat16)
exit 1
;;
*)
echo "First Check Passed!"
echo "First Check Passed (not Fat16)!"
;;
esac
}
CHECK_ESP_MOUNTPOINT() {
# umount the ESP by its Mount Point
# and checking it if is busy by another ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
umount -f /Volumes/ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \
grep -x "${espmtp}" ) ]; then
umount -f ${espmtp}
ESP_MOUNTED="0"
fi
}
if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then
# ESP is already mounted, so now we aquire the Mount Point
espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^[ \t]*//' )
sed -e 's/^ *//' | sed -e 's/ *$//' )
if [ -d "${espmtp}" ];then
echo "ESP Mount Point is:${espmtp}, using that as target Volume!"
choicedVolume="${espmtp}"
fi
if [ $ESP_MOUNTED = "0" ];then
mkdir -p /Volumes/ESP
mkdir -p "${espmtp}"
case $( fstyp $espDisk ) in
hfs)
mount -t hfs $espDisk /Volumes/ESP
echo "Mounting $espDisk on $espmtp as hfs Volume.."
mount -t hfs $espDisk "${espmtp}"
;;
msdos)
mount -t msdos $espDisk /Volumes/ESP
echo "Mounting $espDisk on $espmtp as msdos Volume.."
mount -t msdos $espDisk "${espmtp}"
;;
*)
echo "ESP fileSystem unsupported, Installing to ${targetVolume}!"
esac
sleep 0.3
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \
grep -x "${espmtp}" ) ]; then
echo "EFI System Partition mounted!"
ESP_MOUNTED="1"
choicedVolume="/Volumes/ESP"
choicedVolume="${espmtp}"
SCAN
else
echo "ESP can't be mounted, Installing to ${targetVolume}!"
# --------------------------------------------------------------------------------------------------------
# Writing stage 0
CHECK_WINDOWS() {
WINDOWS_EXIST="0"
if [ "${disksignature}" = "00000000" ]; then
echo "Windows installation not found on ${targetDisk}."
else
WRITE_STAGE0() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 0:"
CHECK_WINDOWS
case "$1" in
hfs)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi
;;
msdos)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi
;;
exfat)
stage0Loader="boot0"
;;
esac
"${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk}
echo "${stage0Loader} writed to ${targetDisk}"
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 1 on different filesystems
WRITE_STAGE1_HFS() {
# Writing stage 1
WRITE_STAGE1() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 HFS:"
$localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw}
echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}."
fi
}
WRITE_STAGE1_EXFAT() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:"
echo -e "${mainLine}\nWRITING STAGE 1 ${2}:"
cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/
cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw}
echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}."
cp -R "${i386Dir}/${1}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y "-${3}" -f "${v_mntpt}/${1}" ${targetDeviceRaw}
echo "${stage1Loader} (${2}) writed to ${targetDeviceRaw}."
fi
}
WRITE_STAGE1_FAT32() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 FAT32:"
$localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs"
cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs"
$localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc
$localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512
echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 2
WRITE_STAGE2() {
}
# --------------------------------------------------------------------------------------------------------
# Waiting for targhet Volume was re-mounted before proceeding..
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..)
WAIT_REMOUNT() {
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..).
# exception is the EFI partition: in Mavericks autoremount...in Yosemite not..
REMOUNT() {
if [ $InstallBootloader = "1" ];then
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
if [ "${InstallToESP}" == "1" ]; then
if [ ! -d "${choicedVolume}" ]; then
MOUNT_ESP
fi
else
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
fi
fi
fi
}
else
echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.."
cp -R "${choicedVolume}/Extra" "${v_mntpt}"/
./clean_bootplist.pl "${v_mntpt}" >/dev/null
./clean_bootplist.pl "${v_mntpt}"
fi
}
# --------------------------------------------------------------------------------------------------------
exec > >(tee -a "${logFile}") 2>&1
echo "$mainLine"
echo "Main ESP Post-Install Script"
echo "Main ${TYPE} Post-Install Script"
echo "Chameleon installer log - $( date )"
if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi
echo ""
echo "GPT partition Scheme detected.."
espDisk="${targetDisk}s1"
if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \
awk '{print $NF}' ) = "EFI" ]; then
awk '{print $NF}' | sed -e 's/^ *//' | sed -e 's/ *$//' ) = "EFI" ]; then
echo "EFI partition found is ${espDisk}, try to mount it.."
MOUNT_ESP
else
fi
;;
*)
InstallToESP = "0"
echo "Can't install on the ESP, because does not exist.."
echo "..continue installing to ${targetVolume}"
;;
SCAN
fi
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then
DEBUG
fi
# adding the chosen Volume dev id to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile
echo "${mainLine}"
CHECK_FAT16
CHECK_WINDOWS
case "$FS" in
hfs)
echo "${targetDevice} is HFS formatted"
WRITE_STAGE0 hfs
WRITE_STAGE1_HFS
if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0hfs"; else stage0Loader="boot0"; fi
stage1Loader="${stage1LoaderHFS}"
;;
msdos)
echo "${targetDevice} is FAT32 formatted"
WRITE_STAGE0 msdos
WRITE_STAGE1_FAT32
if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0md"; else stage0Loader="boot0"; fi
stage1Loader="${stage1LoaderFAT}"
;;
exfat)
echo "${targetDevice} is ExFAT formatted"
WRITE_STAGE0 exfat
WRITE_STAGE1_EXFAT
WAIT_REMOUNT
stage0Loader="boot0"
stage1Loader="${stage1LoaderExFAT}"
;;
*)
echo "FileSystem unsupported, aborting!"
;;
esac
# Debug mode: create a "DebugChameleon" folder on your Desktop to debug this script
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then DEBUG; fi
# if the target device is equal to the boot device keep the Volume mounted using boot1-install
if [ "${bootDevice}" = "${targetDevice}" ]; then opt="M"; fi
WRITE_STAGE0 "${stage0Loader}"
WRITE_STAGE1 "${stage1Loader}" "${FS}" "${opt}"
if [ "${bootDevice}" != "${targetDevice}" ]; then REMOUNT; fi
WRITE_STAGE2
PARTITION_ACTIVE_IF
echo "$mainLine"
echo "END - ESP Post-Install Script"
echo "END - ${TYPE} Post-Install Script"
# --------------------------------------------------------------------------------------------------------
exit 0
branches/ErmaC/Enoch/package/Scripts/Main/Standardpostinstall
11
22
33
4
4
55
66
77
88
99
10
11
12
1013
1114
15
1216
1317
1418
......
2327
2428
2529
26
27
28
30
31
32
2933
3034
3135
3236
3337
34
35
3638
3739
3840
3941
4042
4143
42
4344
4445
4546
4647
4748
49
4850
4951
5052
......
5254
5355
5456
55
57
5658
57
59
5860
5961
6062
......
6971
7072
7173
72
74
7375
74
75
76
7677
7778
7879
......
8384
8485
8586
87
8688
8789
8890
......
9395
9496
9597
96
97
98
99
98100
99101
100102
......
102104
103105
104106
105
107
106108
107109
108110
......
116118
117119
118120
119
120
121
121
122
123
122124
123125
124126
......
128130
129131
130132
131
133
132134
133135
134136
......
144146
145147
146148
147
149
148150
149151
150
152
153
151154
152155
153
156
157
154158
155159
156160
......
159163
160164
161165
162
163
166
167
168
164169
165
170
166171
167172
168173
......
202207
203208
204209
205
206210
207211
208212
......
214218
215219
216220
217
218
219
220
221
222
223
224
225
226
227
228
229
230221
231222
232223
233224
234225
235
236
226
227
237228
238
239
240
241
242
243
244
245
246
229
247230
248
249
250
231
232
233
251234
252235
253
254
255
256
257
258
259
260
261
262
263
264
265236
266237
267238
......
274245
275246
276247
277
278
248
249
250
279251
280
281
282
283
284
285
252
253
254
255
256
257
258
259
260
261
262
263
286264
287265
288266
......
297275
298276
299277
300
278
301279
302280
303281
......
331309
332310
333311
334
312
335313
336314
337315
......
354332
355333
356334
357
335
358336
359337
360338
......
363341
364342
365343
344
366345
367346
368347
......
371350
372351
373352
374
375
376
377
378
379353
380354
381355
......
384358
385359
386360
361
387362
388363
389364
390
391
365
366
392367
393368
394369
395
396
370
371
397372
398373
399374
400
401
402
375
376
403377
404378
405379
......
407381
408382
409383
384
385
386
387
388
389
390
391
410392
411393
412394
413395
414
396
415397
416398
417399
#!/bin/bash
# --------------------------------------------------------------------------------------------------------
# Install.sh v1.3, script to install Chameleon
# Install.sh v1.5, script to install Chameleon
# Created by Miky1979 on December 8th, 2014
# --------------------------------------------------------------------------------------------------------
targetVolume="${3}"
InstallToESP="0"
InstallBootloader="0"
espmtp="/Volumes/ESP"
WINDOWS_EXIST="0"
opt="u"
configFile="/private/tmp/InstallConfig.plist"
if [ "${InstallToESP}" == "1" ]; then TYPE="ESP"; else TYPE="Standard"; fi
if [[ $( /usr/libexec/PlistBuddy -c "Print bootloader" ${configFile} ) == "true" ]];then
# installing stage 0, 1 and 2 only if user want this:
# ie only if have no selected noboot choice
choicedVolume="${targetVolume}"
ESP_MOUNTED="0"
# --------------------------------------------------------------------------------------------------------
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} | sed -e 's/[[:blank:]]*//g' )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' \
| sed -e 's/^[ \t]*//')
v_mntptDev=$( /usr/libexec/PlistBuddy -c "Print :ramdisk" ${configFile} )
v_mntpt=$( LC_ALL=C diskutil info ${v_mntptDev} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^ *//' | sed -e 's/ *$//' )
backupRootDir="${targetVolume}/Chameleon.Backups"
backupDir=$( /usr/libexec/PlistBuddy -c "Print :backupDir" ${configFile} )
logName="Chameleon_Installer_Log.txt"
logFile="${v_mntpt}/${logName}"
# --------------------------------------------------------------------------------------------------------
stage0Loader="boot0"
stage0LoaderDualBoot="boot0md"
stage1LoaderHFS="boot1h"
stage1LoaderFAT="boot1f32"
stage1LoaderExFAT="boot1x"
stage2Loader="boot"
versionToInstall=$(cat "${i386Dir}/Boot" | grep -a 'Darwin/x86 boot v' )
# --------------------------------------------------------------------------------------------------------
localdd="/bin/dd"
SS="${usrLocalBin}/sectorsize"
# --------------------------------------------------------------------------------------------------------
# Scanning all Variables. We are switching to the target Volume or its ESP.
# This function is usefull to rescan the new target "at need"
SCAN() {
bootDevice=$( LC_ALL=C diskutil info / | grep -i 'Device Node:' | awk '{print $NF}' )
targetDevice=$( LC_ALL=C diskutil info "${choicedVolume}" | grep -i 'Device Node:' | awk '{print $NF}' )
targetDeviceRaw=${targetDevice/disk/rdisk}
targetDisk=${targetDevice%s*}
targetSlice=${targetDevice#*disk*s}
IOContent=$( LC_ALL=C diskutil info "${targetDisk}" | grep -i 'Content (IOContent)' | awk '{print $NF}' )
FS=$( LC_ALL=C diskutil info ${targetDevice} | grep -i 'Type (Bundle)' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
awk '{print $NF}' | awk '{print tolower($0)}' )
disksignature=$( dd 2>/dev/null if="${targetDisk}" count=1 | dd 2>/dev/null count=4 bs=1 skip=440 | \
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
perl -ne '@a=split"";for(@a){printf"%02x",ord}' )
if [ $InstallBootloader = "1" ];then
blocksize=$( "${SS}" "${targetDeviceRaw}" | awk '{ print $2 }' )
# Create a folder inside the Desktop called "DebugChameleon", and the log will be full
DEBUG() {
echo "$mainLine"
echo "DEBUG: display script variables (Standardpostinstall)"
echo "DEBUG: display script variables (${TYPE}postinstall)"
echo "$mainLine"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader} (or boot0hfs)"
echo "DEBUG: stage0LoaderDualBoot: Disk loader is ${stage0LoaderDualBoot} (or boot0hfs)"
echo "DEBUG: stage0Loader: Disk loader is ${stage0Loader}"
echo "DEBUG: stage1LoaderHFS: Partition loader is ${stage1LoaderHFS}"
echo "DEBUG: stage1LoaderFat: Partition loader is ${stage1LoaderFAT}"
echo "DEBUG: stage1LoaderExFAT: Partition loader is ${stage1LoaderExFAT}"
echo "DEBUG: targetDisk: Disk device is ${targetDisk}"
echo "DEBUG: targetDiskRaw: Disk raw device is ${targetDiskRaw}"
echo "DEBUG: targetSlice: Volume slice is ${targetSlice}"
echo "DEBUG: bootDevice: Current Volume device is ${bootDevice}"
echo "DEBUG: versionToInstall: version to install is ${versionToInstall}"
echo "DEBUG: IOContent: partition scheme is ${IOContent}"
echo "DEBUG: FS: file System is ${FS}"
# --------------------------------------------------------------------------------------------------------
# Checking for unsupported FAT16 filesystem
CHECK_FAT16() {
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' \
| awk '{print $NF}' | awk '{print tolower($0)}' )
pers=$( LC_ALL=C diskutil info "${targetDeviceRaw}" | grep -i 'File System Personality' | \
awk '{print $NF}' | awk '{print tolower($0)}' )
case $pers in
fat16)
exit 1
;;
*)
echo "First Check Passed!"
echo "First Check Passed (not Fat16)!"
;;
esac
}
CHECK_ESP_MOUNTPOINT() {
# umount the ESP by its Mount Point
# and checking it if is busy by another ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
umount -f /Volumes/ESP
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \
grep -x "${espmtp}" ) ]; then
umount -f ${espmtp}
ESP_MOUNTED="0"
fi
}
if [ $( df | grep "${espDisk}" | awk '{print $1}' | grep -x "${espDisk}" ) ];then
# ESP is already mounted, so now we aquire the Mount Point
espmtp=$( LC_ALL=C diskutil info ${espDisk} | grep -i 'mount point' | awk '{$1=$2=""; print $0}' | \
sed -e 's/^[ \t]*//' )
sed -e 's/^ *//' | sed -e 's/ *$//' )
if [ -d "${espmtp}" ];then
echo "ESP Mount Point is:${espmtp}, using that as target Volume!"
choicedVolume="${espmtp}"
fi
if [ $ESP_MOUNTED = "0" ];then
mkdir -p /Volumes/ESP
mkdir -p "${espmtp}"
case $( fstyp $espDisk ) in
hfs)
mount -t hfs $espDisk /Volumes/ESP
echo "Mounting $espDisk on $espmtp as hfs Volume.."
mount -t hfs $espDisk "${espmtp}"
;;
msdos)
mount -t msdos $espDisk /Volumes/ESP
echo "Mounting $espDisk on $espmtp as msdos Volume.."
mount -t msdos $espDisk "${espmtp}"
;;
*)
echo "ESP fileSystem unsupported, Installing to ${targetVolume}!"
esac
sleep 0.3
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^[ \t]*//' | \
grep -x '/Volumes/ESP' ) ]; then
if [ $( df | awk '{$1=$2=$3=$4=$5=$6=$7=$8=""; print $0}' | sed -e 's/^ *//' | sed -e 's/ *$//' | \
grep -x "${espmtp}" ) ]; then
echo "EFI System Partition mounted!"
ESP_MOUNTED="1"
choicedVolume="/Volumes/ESP"
choicedVolume="${espmtp}"
SCAN
else
echo "ESP can't be mounted, Installing to ${targetVolume}!"
# --------------------------------------------------------------------------------------------------------
# Writing stage 0
CHECK_WINDOWS() {
WINDOWS_EXIST="0"
if [ "${disksignature}" = "00000000" ]; then
echo "Windows installation not found on ${targetDisk}."
else
WRITE_STAGE0() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 0:"
CHECK_WINDOWS
case "$1" in
hfs)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0hfs"; else stage0Loader="boot0"; fi
;;
msdos)
if [ WINDOWS_EXIST = "1" ];then stage0Loader="boo0md"; else stage0Loader="boot0";fi
;;
exfat)
stage0Loader="boot0"
;;
esac
"${usrLocalBin}/fdisk440" -u -f "${i386Dir}/${stage0Loader}" -y ${targetDisk}
echo "${stage0Loader} writed to ${targetDisk}"
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 1 on different filesystems
WRITE_STAGE1_HFS() {
# Writing stage 1
WRITE_STAGE1() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 HFS:"
$localdd if="${i386Dir}/${stage1LoaderHFS}" of=${targetDeviceRaw}
echo "${stage1LoaderHFS} (hfs) writed to ${targetDeviceRaw}."
fi
}
WRITE_STAGE1_EXFAT() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 ExFAT:"
echo -e "${mainLine}\nWRITING STAGE 1 ${2}:"
cp -R "${usrLocalBin}/boot1-install" "${v_mntpt}"/
cp -R "${i386Dir}/${stage1LoaderExFAT}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y -u -f "${v_mntpt}/${stage1LoaderExFAT}" ${targetDeviceRaw}
echo "${stage1LoaderExFAT} (ExFAT) writed to ${targetDeviceRaw}."
cp -R "${i386Dir}/${1}" "${v_mntpt}"/
"${v_mntpt}/boot1-install" -y "-${3}" -f "${v_mntpt}/${1}" ${targetDeviceRaw}
echo "${stage1Loader} (${2}) writed to ${targetDeviceRaw}."
fi
}
WRITE_STAGE1_FAT32() {
if [ $InstallBootloader = "1" ];then
echo -e "${mainLine}\nWRITING STAGE 1 FAT32:"
$localdd if=${targetDeviceRaw} count=1 bs=512 of="${v_mntpt}/origbs"
cp "${i386Dir}/${stage1LoaderFAT}" "${v_mntpt}/newbs"
$localdd if="${v_mntpt}/origbs" of="${v_mntpt}/newbs" skip=3 seek=3 bs=1 count=87 conv=notrunc
$localdd if="${v_mntpt}/newbs" of="${targetDeviceRaw}" count=1 bs=512
echo "${stage1LoaderFAT} (Fat32) writed to ${targetDeviceRaw}."
fi
}
# --------------------------------------------------------------------------------------------------------
# Writing stage 2
WRITE_STAGE2() {
}
# --------------------------------------------------------------------------------------------------------
# Waiting for targhet Volume was re-mounted before proceeding..
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..)
WAIT_REMOUNT() {
# Note: the target Volume is umonted by boot1-install that also take the step to remount it (only waiting..).
# exception is the EFI partition: in Mavericks autoremount...in Yosemite not..
REMOUNT() {
if [ $InstallBootloader = "1" ];then
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
if [ "${InstallToESP}" == "1" ]; then
if [ ! -d "${choicedVolume}" ]; then
MOUNT_ESP
fi
else
if [ ! -d "${choicedVolume}" ]; then
echo -e "${mainLine}\nWAITING TO RE-MOUNT ${choicedVolume}:"
until [ -d "${choicedVolume}" ]; do
sleep 0.3
done
echo "${choicedVolume} is mounted!"
fi
fi
fi
}
else
echo "Extra folder already exist on ${choicedVolume}, copying to the Ram Disk.."
cp -R "${choicedVolume}/Extra" "${v_mntpt}"/
./clean_bootplist.pl "${v_mntpt}" >/dev/null
./clean_bootplist.pl "${v_mntpt}"
fi
}
# --------------------------------------------------------------------------------------------------------
exec > >(tee -a "${logFile}") 2>&1
echo "$mainLine"
echo "Main Standard Post-Install Script"
echo "Main ${TYPE} Post-Install Script"
echo "Chameleon installer log - $( date )"
if [ $InstallBootloader = "1" ];then echo "$versionToInstall"; else echo "no boot session"; fi
echo ""
echo "GPT partition Scheme detected.."
espDisk="${targetDisk}s1"
if [ $( LC_ALL=C diskutil info ${espDisk} | grep -i 'Partition Type:' | \
awk '{print $NF}' ) = "EFI" ]; then
awk '{print $NF}' | sed -e 's/^ *//' | sed -e 's/ *$//' ) = "EFI" ]; then
echo "EFI partition found is ${espDisk}, try to mount it.."
MOUNT_ESP
else
fi
;;
*)
InstallToESP = "0"
echo "Can't install on the ESP, because does not exist.."
echo "..continue installing to ${targetVolume}"
;;
SCAN
fi
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then
DEBUG
fi
# adding the chosen Volume dev id to the InstallConfig.plist
/usr/libexec/PlistBuddy -c "Add :targetdev string ${targetDevice}" $configFile
echo "${mainLine}"
CHECK_FAT16
CHECK_WINDOWS
case "$FS" in
hfs)
echo "${targetDevice} is HFS formatted"
WRITE_STAGE0 hfs
WRITE_STAGE1_HFS
if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0hfs"; else stage0Loader="boot0"; fi
stage1Loader="${stage1LoaderHFS}"
;;
msdos)
echo "${targetDevice} is FAT32 formatted"
WRITE_STAGE0 msdos
WRITE_STAGE1_FAT32
if [ $WINDOWS_EXIST = "1" ];then stage0Loader="boot0md"; else stage0Loader="boot0"; fi
stage1Loader="${stage1LoaderFAT}"
;;
exfat)
echo "${targetDevice} is ExFAT formatted"
WRITE_STAGE0 exfat
WRITE_STAGE1_EXFAT
WAIT_REMOUNT
stage0Loader="boot0"
stage1Loader="${stage1LoaderExFAT}"
;;
*)
echo "FileSystem unsupported, aborting!"
;;
esac
# Debug mode: create a "DebugChameleon" folder on your Desktop to debug this script
if [ -d "${HOME}/Desktop/DebugChameleon" ]; then DEBUG; fi
# if the target device is equal to the boot device keep the Volume mounted using boot1-install
if [ "${bootDevice}" = "${targetDevice}" ]; then opt="M"; fi
WRITE_STAGE0 "${stage0Loader}"
WRITE_STAGE1 "${stage1Loader}" "${FS}" "${opt}"
if [ "${bootDevice}" != "${targetDevice}" ]; then REMOUNT; fi
WRITE_STAGE2
PARTITION_ACTIVE_IF
echo "$mainLine"
echo "END - Standard Post-Install Script"
echo "END - ${TYPE} Post-Install Script"
# --------------------------------------------------------------------------------------------------------
exit 0
branches/ErmaC/Enoch/package/buildpkg.sh
475475
476476
477477
478
478479
479480
480481
ditto --noextattr --noqtn ${SYMROOT}/i386/boot ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0md ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot0hfs ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1f32 ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1h ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386
ditto --noextattr --noqtn ${SYMROOT}/i386/boot1x ${PKG_BUILD_DIR}/${choiceId}/Root/usr/standalone/i386

Archive Download the corresponding diff file

Revision: 2587