forked from haxxxen/ps3mfw-builder-0.2.1-mod
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathps3mfw_base.tcl
2165 lines (1999 loc) · 72.5 KB
/
ps3mfw_base.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/tclsh
#
# ps3mfw -- PS3 MFW creator
#
# Copyright (C) Anonymous Developers (Code Monkeys)
#
# This software is distributed under the terms of the GNU General Public
# License ("GPL") version 3, as published by the Free Software Foundation.
#
#
# logging functions
proc get_log_fd {} {
global log_fd LOG_FILE
if {![info exists log_fd]} {
set log_fd [open $LOG_FILE w]
fconfigure $log_fd -buffering none
}
return $log_fd
}
proc log {msg {force 0}} {
global options
if {!$options(--silent) || $force} {
set fd [get_log_fd]
puts $fd $msg
if {$force} {
puts stderr $msg
} else {
puts $msg
}
}
}
proc debug {msg} {
if {$::options(--debug-log)} {
log $msg 1
}
}
proc grep {re args} {
set result [list]
set files [eval glob -types f $args]
foreach file $files {
set fp [open $file]
set l 0
while {[gets $fp line] >= 0} {
if [regexp -- $re $line] {
lappend result [list $file $line $l]
}
incr l
}
close $fp
}
set result
}
proc _get_comment_from_file {filename re} {
set results [grep $re $filename]
set comment ""
foreach match $results {
foreach {file match line} $match break
append comment "[string trim [regsub $re $match {}]]\n"
}
string trim $comment
}
proc get_task_description {filename} {
return [_get_comment_from_file $filename {^# Description:}]
}
proc get_option_description {filename option} {
return [_get_comment_from_file $filename "^# Option ${option}:"]
}
proc get_sorted_options {filename options} {
return [lsort -command [list sort_options $filename] $options]
}
proc sort_options {file opt1 opt2 } {
set re1 "^# Option ${opt1}:"
set re2 "^# Option ${opt2}:"
set results1 [grep $re1 $file]
set results2 [grep $re2 $file]
if {$results1 == {} && $results2 == {}} {
return [string compare $opt1 $opt2]
} elseif {$results1 == {}} {
return 1
} elseif {$results2 == {}} {
return -1
} else {
foreach {file match line1} [lindex $results1 0] break
foreach {file match line2} [lindex $results2 0] break
return [expr {$line1 - $line2}]
}
}
proc get_option_type {filename option} {
return [_get_comment_from_file $filename "^# Type ${option}:"]
}
# task functions
proc task_to_file {task} {
return [file join ${::TASKS_DIR} ${task}.tcl]
}
proc file_to_task {file} {
return [file rootname [file tail $file]]
}
proc compare_tasks {task1 task2} {
return [compare_task_files [task_to_file $task1] [task_to_file $task2]]
}
proc compare_task_files {file1 file2} {
set prio1 [_get_comment_from_file $file1 {^# Priority:}]
set prio2 [_get_comment_from_file $file2 {^# Priority:}]
if {$prio1 == {} && $prio2 == {}} {
return [string compare $file1 $file2]
} elseif {$prio1 == {}} {
return 1
} elseif {$prio2 == {}} {
return -1
} else {
return [expr {$prio1 - $prio2}]
}
}
proc sort_tasks {tasks} {
return [lsort -command compare_tasks $tasks]
}
proc sort_task_files {files} {
return [lsort -command compare_task_files $files]
}
proc get_sorted_tasks { {tasks {}} } {
set files [glob -nocomplain [file join ${::TASKS_DIR} *.tcl]]
set tasks [list]
foreach file $files {
lappend tasks [file_to_task $file]
}
return [sort_tasks $tasks]
}
proc get_sorted_task_files { } {
set files [glob -nocomplain [file join ${::TASKS_DIR} *.tcl]]
return [sort_task_files $files]
}
proc get_selected_tasks { } {
return ${::selected_tasks}
}
# failure functions
proc die {message} {
global LOG_FILE
log "FATAL ERROR: $message" 1
puts stderr "See ${LOG_FILE} for more info"
puts stderr "Last lines of log : "
puts stderr "*****************"
catch {puts stderr "[tail $LOG_FILE]"}
puts stderr "*****************"
exit -2
}
proc catch_die {command message} {
set catch {
if {[catch {@command@} res] } {
die "@message@ : $res"
}
return $res
}
debug "Executing command $command"
set catch [string map [list "@command@" "$command" "@message@" "$message"] $catch]
uplevel 1 $catch
}
# shell functions
proc shell {args} {
set fd [get_log_fd]
debug "Executing shell $args\n"
eval exec $args >&@ $fd
}
proc shellex {args} {
set outbuffer ""
debug "Executing shellex $args\n"
set outbuffer [eval exec $args]
return $outbuffer
}
# file functions
proc hexify { str } {
set out ""
for {set i 0} { $i < [string length $str] } { incr i} {
set c [string range $str $i $i]
binary scan $c H* h
append out "\[$h\]"
}
return $out
}
proc tail {filename {n 10}} {
set fd [open $filename r]
set lines [list]
while {![eof $fd]} {
lappend lines [gets $fd]
if {[llength $lines] > $n} {
set lines [lrange $lines end-$n end]
}
}
close $fd
return [join $lines "\n"]
}
proc create_mfw_dir {args} {
catch_die {file mkdir $args} "Could not create dir $args"
}
proc copy_file {args} {
catch_die {file copy {*}$args} "Unable to copy $args"
}
proc copy_dir {src dst } {
debug "Copying source dir:$src to target directory:$dst"
copy_file -force $src $dst
}
proc delete_file {args} {
catch_die {file delete {*}$args} "Unable to delete $args"
}
proc rename_file {src dst} {
catch_die {file rename {*}$src $dst} "Unable to rename and/or move $src $dst"
}
proc delete_promo { } {
delete_file -force ${::CUSTOM_PROMO_FLAGS_TXT}
}
proc copy_mfw_imgs { } {
create_mfw_dir ${::CUSTOM_MFW_DIR}
copy_file -force ${::CUSTOM_IMG_DIR} ${::CUSTOM_MFW_DIR}
}
# ROGERO app_home/ modification
proc copy_ps3_game {arg} {
variable option
set arg0 0
set arg1 0
set arg2 0
set arg3 0
set arg4 1
if {[info exists ::patch_xmb::options(--add-install-pkg)]} {
set arg0 $::patch_xmb::options(--add-install-pkg) }
if {[info exists ::patch_xmb::options(--add-pkg-mgr)]} {
set arg1 $::patch_xmb::options(--add-pkg-mgr) }
if {[info exists ::patch_xmb::options(--add-hb-seg)]} {
set arg2 $::patch_xmb::options(--add-hb-seg) }
if {[info exists ::patch_xmb::options(--add-emu-seg)]} {
set arg3 $::patch_xmb::options(--add-emu-seg) }
if {[info exists ::customize_firmware::options(--customize-embedded-app)]} {
set arg4 [file exists $::customize_firmware::options(--customize-embedded-app) == 0] }
if { $arg0 || $arg1 || $arg2 || $arg3 && !$arg4 } {
rename_file -force $arg ${::CUSTOM_EMBEDDED_APP}
} elseif { $arg0 || $arg1 || $arg2 || $arg3 && $arg4 } {
copy_file -force $arg ${::CUSTOM_MFW_DIR}
} elseif { !$arg0 && !$arg1 && !$arg2 && !$arg3 && !$arg4 } {
create_mfw_dir ${::CUSTOM_MFW_DIR}
rename_file -force $arg ${::CUSTOM_EMBEDDED_APP}
} elseif { !$arg0 && !$arg1 && !$arg2 && !$arg3 && $arg4 } {
create_mfw_dir ${::CUSTOM_MFW_DIR}
copy_file -force $arg ${::CUSTOM_MFW_DIR}
}
unset arg0, arg1, arg2, arg3, arg4
}
proc copy_ps3_game_standart { } {
set ttf "SCE-PS3-RD-R-LATIN.TTF"
debug "using font file .ttf as argument to search for"
debug "cause we need a tar with a bit space in it"
modify_devflash_file [file join dev_flash data font $ttf] callback_ps3_game_standart
}
proc callback_ps3_game_standart { file } {
log "Creating custom directory in dev_flash"
create_mfw_dir ${::CUSTOM_MFW_DIR}
if {${::CFW} == "AC1D"} {
log "Installing standalone 'Custom FirmWare' app"
copy_file -force ${::CUSTOM_PS3_GAME2} ${::CUSTOM_MFW_DIR}
log "Copy custom imgs into dev_flash"
copy_file -force ${::CUSTOM_IMG_DIR} ${::CUSTOM_MFW_DIR}
} else {
log "Installing standalone '*Install Package Files' app"
copy_file -force ${::CUSTOM_PS3_GAME} ${::CUSTOM_MFW_DIR}
}
}
# PUP functions
proc pup_extract {pup dest} {
set debugmode no
if { $::options(--tool-debug) } {
set debugmode yes
}
# now extract out the PUP file
shell ${::PKGTOOL} -debug $debugmode -action unpack -type pup -in [file nativename $pup] -out [file nativename $dest]
}
proc pup_create {dir pup build} {
# shell ${::PUP} c $dir $pup $build
shell ${::PUPPACK} $pup [file nativename $dir] [file nativename $build]
}
proc pup_get_build {pup} {
set fd [open $pup r]
fconfigure $fd -translation binary
seek $fd 16
set build [read $fd 8]
close $fd
if {[binary scan $build W build_ver] != 1} {
error "Cannot read 64 bit big endian from [hexify $build]"
}
return $build_ver
}
proc get_pup_build {} {
debug "Getting PUP build from: [file tail ${::IN_FILE}]"
catch_die {pup_get_build ${::IN_FILE}} "Could not get the PUP build information"
return [pup_get_build ${::IN_FILE}]
}
proc set_pup_build {build} {
debug "PUP build: $build"
set ::PUP_BUILD $build
}
proc get_pup_version {dir} {
debug "Getting PUP version from: [file tail $dir]"
set fd [open [file join $dir] r]
set version [string trim [read $fd]]
close $fd
return $version
}
proc set_pup_version {version} {
debug "Setting PUP version in: [file tail ${::CUSTOM_VERSION_TXT}]"
set fd [open [file join ${::CUSTOM_VERSION_TXT}] w]
puts $fd "${version}"
close $fd
}
proc modify_pup_version_file {prefix suffix {clear 0}} {
if {$clear} {
set version ""
} else {
set version [::get_pup_version ${::ORIGINAL_VERSION_TXT}]
}
debug "PUP version: ${prefix}${version}${suffix}"
set_pup_version "${prefix}${version}${suffix}"
}
# tar extract functions
proc extract_tar {tar dest} {
debug "Extracting tar file: [file tail $tar] into: [file tail $dest]"
# now go untar the file
file mkdir $dest
catch_die {::tar::untar $tar -dir $dest} "Could not untar file: $tar"
}
#new fixed tarball rebuild functions
proc create_cex_tar341_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.41 dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex341_000 $tar $files} "Could not create CEX 3.41 dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar341_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.41 dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex341_content $tar $files} "Could not create CEX 3.41 dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar341_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.41 update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex341_update $tar $files} "Could not create CEX 3.41 update tar file $tar"
cd $pwd
}
proc create_cex_tar341_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.41 dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex341_dev3 $tar $files} "Could not create CEX 3.41 dev_flash3 tar file $tar"
cd $pwd
}
proc create_cex_tar355_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.55 dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex355_000 $tar $files} "Could not create CEX 3.55 dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar355_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.55 dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex355_content $tar $files} "Could not create CEX 3.55 dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar355_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.55 update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex355_update $tar $files} "Could not create CEX 3.55 update tar file $tar"
cd $pwd
}
proc create_cex_tar355_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 3.55 dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex355_dev3 $tar $files} "Could not create CEX 3.55 dev_flash3 tar file $tar"
cd $pwd
}
proc create_dex_tar3_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 3.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex3_000 $tar $files} "Could not create DEX 3.xx dev_flash tar file $tar"
cd $pwd
}
proc create_dex_tar3_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 3.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex3_content $tar $files} "Could not create DEX 3.xx dev_flash tar file $tar"
cd $pwd
}
proc create_dex_tar3_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 3.xx update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex3_update $tar $files} "Could not create DEX 3.xx update tar file $tar"
cd $pwd
}
proc create_dex_tar3_spkg {tar directory files} {
set debug [file tail $tar]
if {$debug == "spkg_hdr" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 3.xx spkg tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex3_spkg $tar $files} "Could not create DEX 3.xx spkg tar file $tar"
cd $pwd
}
proc create_dex_tar3_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 3.xx dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex3_dev3 $tar $files} "Could not create DEX 3.xx dev_flash3 tar file $tar"
cd $pwd
}
proc create_cex_tar4_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex4_000 $tar $files} "Could not create CEX 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar4_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex4_content $tar $files} "Could not create CEX 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_cex_tar4_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 4.xx update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex4_update $tar $files} "Could not create CEX 4.xx update tar file $tar"
cd $pwd
}
proc create_cex_tar4_spkg {tar directory files} {
set debug [file tail $tar]
if {$debug == "spkg_hdr" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 4.xx spkg tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex4_spkg $tar $files} "Could not create CEX 4.xx spkg tar file $tar"
cd $pwd
}
proc create_cex_tar4_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating CEX 4.xx dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_cex4_dev3 $tar $files} "Could not create CEX 4.xx dev_flash3 tar file $tar"
cd $pwd
}
proc create_dex_tar4_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex4_000 $tar $files} "Could not create DEX 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_dex_tar4_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex4_content $tar $files} "Could not create DEX 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_dex_tar4_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 4.xx update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex4_update $tar $files} "Could not create DEX 4.xx update tar file $tar"
cd $pwd
}
proc create_dex_tar4_spkg {tar directory files} {
set debug [file tail $tar]
if {$debug == "spkg_hdr" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 4.xx spkg tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex4_spkg $tar $files} "Could not create DEX 4.xx spkg tar file $tar"
cd $pwd
}
proc create_dex_tar4_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DEX 4.xx dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_dex4_dev3 $tar $files} "Could not create DEX 4.xx dev_flash3 tar file $tar"
cd $pwd
}
proc create_deh_tar3_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 3.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh3_000 $tar $files} "Could not create DECR 3.xx dev_flash tar file $tar"
cd $pwd
}
proc create_deh_tar3_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 3.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh3_content $tar $files} "Could not create DECR 3.xx dev_flash tar file $tar"
cd $pwd
}
proc create_deh_tar3_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 3.xx update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh3_update $tar $files} "Could not create DECR 3.xx update tar file $tar"
cd $pwd
}
proc create_deh_tar3_spkg {tar directory files} {
set debug [file tail $tar]
if {$debug == "spkg_hdr" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 3.xx spkg tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh3_spkg $tar $files} "Could not create DECR 3.xx spkg tar file $tar"
cd $pwd
}
proc create_deh_tar3_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 3.xx dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh3_dev3 $tar $files} "Could not create DECR 3.xx dev_flash3 tar file $tar"
cd $pwd
}
proc create_deh_tar4_000 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh4_000 $tar $files} "Could not create DECR 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_deh_tar4_content {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 4.xx dev_flash tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh4_content $tar $files} "Could not create DECR 4.xx dev_flash tar file $tar"
cd $pwd
}
proc create_deh_tar4_update {tar directory files} {
set debug [file tail $tar]
if {$debug == "update_files" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 4.xx update tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh4_update $tar $files} "Could not create DECR 4.xx update tar file $tar"
cd $pwd
}
proc create_deh_tar4_spkg {tar directory files} {
set debug [file tail $tar]
if {$debug == "spkg_hdr" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 4.xx spkg tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh4_spkg $tar $files} "Could not create DECR 4.xx spkg tar file $tar"
cd $pwd
}
proc create_deh_tar4_dev3 {tar directory files} {
set debug [file tail $tar]
if {$debug == "content" } {
set debug [file tail [file dirname $tar]]
}
debug "Creating DECR 4.xx dev_flash3 tar file $debug"
set pwd [pwd]
cd $directory
catch_die {::tar::create_deh4_dev3 $tar $files} "Could not create DECR 4.xx dev_flash3 tar file $tar"
cd $pwd
}
# PKG functions
proc unpkg_devflash_all {updatedir outdir} {
file mkdir $outdir
foreach file [lsort [glob -nocomplain [file join $updatedir dev_flash_*]]] {
unpkg_archive $file [file join $outdir [file tail $file]]
}
}
proc find_devflash_archive {dir find} {
foreach file [glob -nocomplain [file join $dir * content]] {
if {[catch {::tar::stat $file $find}] == 0} {
return $file
}
}
return ""
}
proc unpkg_archive {pkg dest} {
debug "unpkg-ing file: [file tail $pkg]"
catch_die {unpkg $pkg $dest} "Could not unpkg file: [file tail $pkg]"
}
proc unpkg {pkg dest} {
set debugmode no
if { $::options(--tool-debug) } {
set debugmode yes
}
# now decrypt the 'pkg' file
shell ${::PKGTOOL} -debug $debugmode -action decrypt -type pkg -in [file nativename $pkg] -out [file nativename $dest]
}
proc pkg_archive {dir pkg} {
debug "pkg-ing file: [file tail $pkg]"
catch_die {pkg $dir $pkg} "Could not pkg file: [file tail $pkg]"
}
proc pkg {pkg dest} {
log "Building \"OLD PKG\" retail package" 1
shell ${::PKG} retail [file nativename $pkg] [file nativename $dest]
}
# SPKG functions
proc copy_spkg { } {
debug "searching for spkg"
set spkg [glob -directory ${::CUSTOM_UPDATE_DIR} *.1]
debug "spkg found in $spkg"
debug "copy new spkg into spkg dir"
copy_file -force $spkg ${::CUSTOM_SPKG_DIR}
if {[file exists [file join $spkg]]} {
debug "removing spkg from working dir"
delete_file -force $spkg
}
}
proc spkg_archive {pkg} {
# die "This function is NO LONGER SUPPORTED!!!"
debug "spkg-ing file: [file tail $pkg]"
catch_die {spkg $pkg} "Could not spkg file: [file tail $pkg]"
}
proc spkg {pkg} {
# die "This function is NO LONGER SUPPORTED!!!"
shell ${::SPKG} [file nativename $pkg]
}
proc pkg_spkg_archive {dir pkg} {
debug "pkg-ing / spkg-ing file: [file tail $pkg]"
catch_die {pkg_spkg $dir $pkg} "Could not pkg / spkg file: [file tail $pkg]"
}
proc pkg_spkg {pkg dest} {
log "Building \"NEW PKG & SPKG\" retail package(s)....." 1
shell ${::NEWPKG} retail [file nativename $pkg] [file nativename $dest]
}
# CORE_OS functions
proc cosunpkg_package { pkg dest } {
debug "cosunpkg-ing file: [file tail $pkg]"
catch_die { cosunpkg $pkg $dest } "Could not cosunpkg file: [file tail $pkg]"
}
proc cosunpkg { pkg dest } {
shell ${::COSUNPKG} [file nativename $pkg] [file nativename $dest]
}
proc cospkg_package { dir pkg } {
debug "cospkg-ing file: [file tail $dir]"
catch_die { cospkg $dir $pkg } "Could not cospkg file: [file tail $pkg]"
}
proc cospkg { dir pkg } {
shell ${::COSPKG} [file nativename $pkg] [file nativename $dir]
}
proc modify_coreos_file { file callback args } {
log "Modifying CORE_OS file: [file tail $file]"
set unpkgdir [file join ${::CUSTOM_UPDATE_DIR} CORE_OS_PACKAGE.unpkg]
set cosunpkgdir [file join ${::CUSTOM_UPDATE_DIR} CORE_OS_PACKAGE]
::unpack_coreos_files ${::CUSTOM_PUP_DIR} LV0_SCE_HDRS
if {[file writable [file join $cosunpkgdir $file]]} {
set ::SELF $file
eval $callback [file join $cosunpkgdir $file] $args
} elseif { ![file exists [file join $cosunpkgdir $file]] } {
die "Could not find $file in CORE_OS_PACKAGE"
} else {
die "File $file is not writable in CORE_OS_PACKAGE"
}
# debug "CORE_OS file: [file tail $file] successfully modified"
log "CORE_OS file: [file tail $file] successfully modified" 1
::repack_coreos_files LV0_SCE_HDRS
}
proc modify_coreos_files { files callback args } {
log "Modifying CORE_OS file: [file tail $files]"
set pkg [file join ${::CUSTOM_UPDATE_DIR} CORE_OS_PACKAGE.pkg]
set unpkgdir [file join ${::CUSTOM_UPDATE_DIR} CORE_OS_PACKAGE.unpkg]
set cosunpkgdir [file join ${::CUSTOM_UPDATE_DIR} CORE_OS_PACKAGE]
::unpack_coreos_files ${::CUSTOM_PUP_DIR} LV0_SCE_HDRS
foreach file $files {
if {[file writable [file join $cosunpkgdir $file]]} {
log "Using file $file now"
set ::SELF $file
eval $callback [file join $cosunpkgdir $file] $args
} elseif { ![file exists [file join $cosunpkgdir $file]] } {
die "Could not find $file in CORE_OS_PACKAGE"
} else {
die "File $file is not writable in CORE_OS_PACKAGE"
}
}
log "CORE_OS file(s): [file tail $file] successfully modified" 1
::repack_coreos_files LV0_SCE_HDRS
}
proc unpack_coreos_files { pupdir array } {
log "Unpacking CORE_OS files....."
upvar $array MyLV0Hdrs
set updatedir [file join $pupdir update_files]
set pkgfile [file join $updatedir CORE_OS_PACKAGE.pkg]
set unpkgdir [file join $updatedir CORE_OS_PACKAGE.unpkg]
set cosunpkgdir [file join $updatedir CORE_OS_PACKAGE]
# unpkg and cosunpkg the "COREOS.pkg"
::unpkg_archive $pkgfile $unpkgdir
::cosunpkg_package [file join $unpkgdir content] $cosunpkgdir
# if firmware is >= 3.60, we need to extract LV0 contents
if {${::NEWMFW_VER} >= "3.60"} {
if {$::options(--auto-cos)} {
catch_die {extract_lv0 $cosunpkgdir "lv0" MyLV0Hdrs} "ERROR: Could not extract LV0"
}
}
# set the global flag that "CORE_OS" is unpacked
set ::FLAG_COREOS_UNPACKED 1
log "CORE_OS unpacked"
}
proc repack_coreos_files { array } {
log "Repacking CORE_OS files....."
upvar $array MyLV0Hdrs
# if firmware is >= 3.60, we need to import LV0 contents
set lv0 [file join ${::CUSTOM_COSUNPKG_DIR} ${::LV0NEW}]
if {${::NEWMFW_VER} >= "3.60"} {
if {$::options(--auto-cos)} {
catch_die {import_lv0 $::CUSTOM_COSUNPKG_DIR "lv0" MyLV0Hdrs} "ERROR: Could not import LV0"
}
}
# re-package the files, and then cleanup/delete the COSUNPKG dir
::cospkg_package $::CUSTOM_COSUNPKG_DIR [file join $::CUSTOM_UNPKG_DIR content]
# catch_die {file delete -force $::CUSTOM_COSUNPKG_DIR} "Could not delete directory:$::CUSTOM_COSUNPKG_DIR for cleanup"
# if we are >= 3.56 FW, we need to build the new "spkg" headers, otherwise use normal pkg build
set pkg $::CUSTOM_PKG_DIR
set unpkgdir $::CUSTOM_UNPKG_DIR
if {[file exists [file join ${::ORIGINAL_SPKG_TAR}]]} {
::pkg_spkg_archive $unpkgdir $pkg
::copy_spkg
} else {
::pkg_archive $unpkgdir $pkg
}
# cleanup/remove the old .unpkg dir
catch_die {file delete -force ${unpkgdir}} "Could not delete directory:$unpkgdir for cleanup"
# set the global flag that "CORE_OS" is packed
set ::FLAG_COREOS_UNPACKED 0
log "CORE_OS repacked"
}
# LV0 functions
proc extract_lv0 {path file array} {
log "Extracting 3.60+ LV0 and loaders...."
upvar $array MyLV0Hdrs
set fullpath [file join $path $file]
# read in the SELF hdr info for LV0
import_self_info $fullpath MyLV0Hdrs
# decrypt LV0 to "LV0.elf", and delete the original "lv0"
decrypt_self $fullpath ${fullpath}.elf
if {!$::options(--sign-iso)} {
file delete ${fullpath}
}
# export LV0 contents.....
append fullpath ".elf"
shell ${::LV0TOOL} -option export -filename ${file}.elf -filepath $path
# debug "3.60+ LOADERS EXTRACTED SUCCESSFULLY!"
log "3.60+ LOADERS EXTRACTED SUCCESSFULLY!"
}
proc import_lv0 {path file array} {
log "Importing 3.60+ loaders into LV0...."
upvar $array MySelfHdrs
set fullpath [file join $path $file]
set lv1ldr_crypt no
# if firmware is >= 3.65, LV1LDR is crypted, otherwise it's
# not crypted. Also, check if we "override" this setting
# by the flag in the "patch_coreos" task
if {${::NEWMFW_VER} >= "3.65"} {
set lv1ldr_crypt yes
if {$::FLAG_NO_LV1LDR_CRYPT != 0} {
set lv1ldr_crypt no
}
}
# execute the "lv0tool" to re-import the loaders
shell ${::LV0TOOL} -option import -lv1crypt $lv1ldr_crypt -cleanup yes -filename ${file}.elf -filepath $path
# resign "lv0.elf" "lv0.self"
if {$::options(--sign-iso)} {
sign_iso_elf ${fullpath}.elf ${fullpath}.self $fullpath
file delete $fullpath
} else {
sign_elf ${fullpath}.elf ${fullpath}.self MySelfHdrs
}
file delete ${fullpath}.elf
file rename -force ${fullpath}.self $fullpath
# debug "lv0 successfully rebuilt"
log "LV0 successfully rebuilt"
}
# .self functions
proc decrypt_self {in out} {
debug "Decrypting self file: [file tail $in]"
catch_die {unself $in $out} "Could not decrypt file: [file tail $in]"
}
proc unself {in out} {
set FIN [file nativename $in]
set FOUT [file nativename $out]
shell ${::SCETOOL} -d $FIN $FOUT
}
proc import_self_info {in array} {
log "Importing SELF-HDR info from file: [file tail $in]"
upvar $array MySelfHdrs
set MyArraySize 0
# clear the incoming array
foreach key [array names MySelfHdrs] {
set MySelfHdrs($key) ""
}
# execute the "SCETOOL -w" cmd to dump the needed SCE-HDR info
catch_die {set buffer [shellex ${::SCETOOL} -w $in]} "failed to dump SCE header for file: [file tail $in]"
# parse out the return buffer, and
# save off the fields into the global array
set data [split $buffer "\n"]
foreach line $data {
if { [regexp -- {(^Key-Revision:)(.*)} $line match] } {
set MySelfHdrs(--KEYREV) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^Auth-ID:)(.*)} $line match] } {
set MySelfHdrs(--AUTHID) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^Vendor-ID:)(.*)} $line match] } {
set MySelfHdrs(--VENDORID) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^SELF-Type:)(.*)} $line match] } {
set MySelfHdrs(--SELFTYPE) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^AppVersion:)(.*)} $line match] } {
set MySelfHdrs(--APPVERSION) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^FWVersion:)(.*)} $line match] } {
set MySelfHdrs(--FWVERSION) [lindex [split $match ":"] 1]
incr MyArraySize 1
} elseif { [regexp -- {(^CtrlFlags:)(.*)} $line match] } {