forked from getitnowmarketing/htc-emmc-ra-recovery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extracommands.c
1516 lines (1303 loc) · 39.9 KB
/
extracommands.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
/* Getitnowmarketing
This was taken and modified from Koush's extendedcommands.c
http://github.com/koush/android_bootable_recovery
To handle formatting non yaffs2 partitions like the ext3 /data & /cache on Incredible
*/
/* Smelkus
Updated source credits and added autoreboot - credits to gnm
Added wipe_temp_files per Calkulin's Clear Temp zip
*/
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "amend/commands.h"
#include "commands.h"
#include "common.h"
#include "cutils/misc.h"
#include "cutils/properties.h"
#include "firmware.h"
#include "minzip/DirUtil.h"
#include "minzip/Zip.h"
#include "roots.h"
#include "extracommands.h"
#include <signal.h>
#include <ctype.h>
#include <getopt.h>
#include <linux/input.h>
#include <dirent.h>
#include <sys/reboot.h>
#include <time.h>
#include <termios.h>
#include "bootloader.h"
#include "install.h"
#include "minui/minui.h"
#include <sys/limits.h>
#include "recovery_ui_keys.h"
#include "mmcutils/mmcutils.h"
//disable this, its optional
int signature_check_enabled = 0;
void toggle_signature_check()
{
signature_check_enabled = !signature_check_enabled;
ui_print("Signature Check: %s\n", signature_check_enabled ? "Enabled" : "Disabled");
if (signature_check_enabled == 0) ui_print("Flashing unsigned zips may corrupt your system!\n");
}
int full_ext_format_enabled = 0;
void toggle_full_ext_format()
{
full_ext_format_enabled = !full_ext_format_enabled;
ui_print("Full Format Ext3/4: %s\n", full_ext_format_enabled ? "Enabled" : "Disabled");
if (full_ext_format_enabled == 1) ui_print("Full mke2fs format of ext3-ext4 enabled!\n");
}
void key_logger_test()
{
//finish_recovery(NULL);
//ui_reset_progress();
ui_print("Outputting key codes.\n");
ui_print("Go back to end debugging.\n");
for (;;) {
int key = ui_wait_key();
int action_key = device_handle_key(key, 1);
if (action_key == GO_BACK) {
break;
} else {
ui_print("Key: %d\n", key);
}
}
}
void run_script(char *str1,char *str2,char *str3,char *str4,char *str5,char *str6,char *str7)
{
ui_print(str1);
ui_clear_key_queue();
ui_print("\nPress %s to confirm,", CONFIRM);
ui_print("\nany other key to abort.\n");
int confirm = ui_wait_key();
int action_confirm_rs = device_handle_key(confirm, 1);
if (action_confirm_rs == SELECT_ITEM) {
ui_print(str2);
pid_t pid = fork();
if (pid == 0) {
char *args[] = { "/sbin/sh", "-c", str3, "1>&2", NULL };
execv("/sbin/sh", args);
fprintf(stderr, str4, strerror(errno));
_exit(-1);
}
int status;
while (waitpid(pid, &status, WNOHANG) == 0) {
ui_print(".");
sleep(1);
}
ui_print("\n");
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
ui_print(str5);
} else {
ui_print(str6);
}
} else {
ui_print(str7);
}
if (!ui_text_visible()) return;
}
// This was pulled from bionic: The default system command always looks
// for shell in /system/bin/sh. This is bad.
#define _PATH_BSHELL "/sbin/sh"
extern char **environ;
int
__system(const char *command)
{
pid_t pid;
sig_t intsave, quitsave;
sigset_t mask, omask;
int pstat;
char *argp[] = {"sh", "-c", NULL, NULL};
if (!command) /* just checking... */
return(1);
argp[2] = (char *)command;
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &omask);
switch (pid = vfork()) {
case -1: /* error */
sigprocmask(SIG_SETMASK, &omask, NULL);
return(-1);
case 0: /* child */
sigprocmask(SIG_SETMASK, &omask, NULL);
execve(_PATH_BSHELL, argp, environ);
_exit(127);
}
intsave = (sig_t) bsd_signal(SIGINT, SIG_IGN);
quitsave = (sig_t) bsd_signal(SIGQUIT, SIG_IGN);
pid = waitpid(pid, (int *)&pstat, 0);
sigprocmask(SIG_SETMASK, &omask, NULL);
(void)bsd_signal(SIGINT, intsave);
(void)bsd_signal(SIGQUIT, quitsave);
return (pid == -1 ? -1 : pstat);
}
int format_non_mtd_device(const char* root)
{
// if this is SDEXT:, don't worry about it.
if (0 == strcmp(root, "SDEXT:"))
{
char device_sdext[PATH_MAX];
get_device_index("SDEXT:", device_sdext);
struct stat st;
if (0 != stat(device_sdext, &st))
{
ui_print("No app2sd partition found. Skipping format of /sd-ext.\n");
return 0;
}
}
char path[PATH_MAX];
translate_root_path(root, path, PATH_MAX);
if (0 != ensure_root_path_mounted(root))
{
ui_print("Error mounting %s!\n", path);
ui_print("Skipping format...\n");
return 0;
}
static char tmp[PATH_MAX];
#ifdef HAS_DATA_MEDIA_SDCARD
if (strcmp(root, "DATA:") == 0) {
sprintf(tmp, "cd /data ; for f in $(ls -a | grep -v ^media$); do rm -rf $f; done");
__system(tmp);
}
else {
sprintf(tmp, "rm -rf %s/*", path);
__system(tmp);
sprintf(tmp, "rm -rf %s/.*", path);
__system(tmp);
}
#else
sprintf(tmp, "rm -rf %s/*", path);
__system(tmp);
sprintf(tmp, "rm -rf %s/.*", path);
__system(tmp);
#endif
ensure_root_path_unmounted(root);
return 0;
}
void usb_toggle_sdcard()
{
ui_print("\nEnabling USB-MS : ");
pid_t pid = fork();
if (pid == 0) {
char *args[] = { "/sbin/sh", "-c", "/sbin/ums_toggle on", "1>&2", NULL };
execv("/sbin/sh", args);
fprintf(stderr, "\nUnable to enable USB-MS!\n(%s)\n", strerror(errno));
_exit(-1);
}
int status;
while (waitpid(pid, &status, WNOHANG) == 0) {
ui_print(".");
sleep(1);
}
ui_print("\n");
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
ui_print("\nError : Run 'ums_toggle' via adb!\n\n");
} else {
ui_clear_key_queue();
ui_print("\nUSB-MS enabled!");
ui_print("\nPress %s to disable,", CONFIRM);
ui_print("\nand return to menu\n");
for (;;) {
int key = ui_wait_key();
int action_key = device_handle_key(key, 1);
if (action_key == SELECT_ITEM) {
ui_print("\nDisabling USB-MS : ");
pid_t pid = fork();
if (pid == 0) {
char *args[] = { "/sbin/sh", "-c", "/sbin/ums_toggle off", "1>&2", NULL };
execv("/sbin/sh", args);
fprintf(stderr, "\nUnable to disable USB-MS!\n(%s)\n", strerror(errno));
_exit(-1);
}
int status;
while (waitpid(pid, &status, WNOHANG) == 0) {
ui_print(".");
sleep(1);
}
ui_print("\n");
if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
ui_print("\nError : Run 'ums_toggle' via adb!\n\n");
} else {
ui_print("\nUSB-MS disabled!\n\n");
}
break;
}
}
}
}
#ifdef HAS_INTERNAL_SD
void usb_toggle_internal()
{
ui_print("\nEnabling USB-MS : ");
pid_t pid1 = fork();
if (pid1 == 0) {
char *args[] = { "/sbin/sh", "-c", "/sbin/ums_toggle internal", "1>&2", NULL };
execv("/sbin/sh", args);
fprintf(stderr, "\nUnable to enable USB-MS!\n(%s)\n", strerror(errno));
_exit(-1);
}
int status1;
while (waitpid(pid1, &status1, WNOHANG) == 0) {
ui_print(".");
sleep(1);
}
ui_print("\n");
if (!WIFEXITED(status1) || (WEXITSTATUS(status1) != 0)) {
ui_print("\nError : Run 'ums_toggle' via adb!\n\n");
} else {
ui_clear_key_queue();
ui_print("\nUSB-MS enabled!");
ui_print("\nPress %s to disable,", CONFIRM);
ui_print("\nand return to menu\n");
for (;;) {
int key = ui_wait_key();
int action_key = device_handle_key(key, 1);
if (action_key == SELECT_ITEM) {
ui_print("\nDisabling USB-MS : ");
pid_t pid1 = fork();
if (pid1 == 0) {
char *args[] = { "/sbin/sh", "-c", "/sbin/ums_toggle off", "1>&2", NULL };
execv("/sbin/sh", args);
fprintf(stderr, "\nUnable to disable USB-MS!\n(%s)\n", strerror(errno));
_exit(-1);
}
int status1;
while (waitpid(pid1, &status1, WNOHANG) == 0) {
ui_print(".");
sleep(1);
}
ui_print("\n");
if (!WIFEXITED(status1) || (WEXITSTATUS(status1) != 0)) {
ui_print("\nError : Run 'ums_toggle' via adb!\n\n");
} else {
ui_print("\nUSB-MS disabled!\n\n");
}
break;
}
}
}
}
#endif
void wipe_battery_stats()
{
ensure_root_path_mounted("DATA:");
remove("/data/system/batterystats.bin");
ensure_root_path_unmounted("DATA:");
}
void wipe_rotate_settings()
{
ensure_root_path_mounted("DATA:");
__system("rm -r /data/misc/akmd*");
__system("rm -r /data/misc/rild*");
ensure_root_path_unmounted("DATA:");
}
void make_clockwork_path()
{
ensure_root_path_mounted("SDCARD:");
__system("mkdir -p /sdcard/clockworkmod/backup");
// ensure_root_path_unmounted("SDCARD:");
}
void check_my_battery_level()
{
char cap_s[4];
FILE * cap = fopen("/sys/class/power_supply/battery/capacity","r");
fgets(cap_s, 4, cap);
fclose(cap);
ui_print("\nBattery Level: %s\n", cap_s);
}
#ifndef USES_NAND_MTD
void check_fs() {
ensure_root_path_mounted("SYSTEM:");
ensure_root_path_mounted("DATA:");
ensure_root_path_mounted("CACHE:");
#ifdef IS_ICONIA
ensure_root_path_mounted("FLEXROM:");
#endif
static char discard[1024];
char device[64], name[64], type[64];
FILE *mounts = fopen("/proc/mounts", "r");
while (fscanf(mounts, "%64s %64s %64s %1024[^\n]", device, name, type, discard) != EOF) {
/* Enjoy the whitespace! */
if (
!strcmp(name, "/data") ||
!strcmp(name, "/system") ||
#ifdef IS_ICONIA
!strcmp(name, "/flexrom") ||
!strcmp(name, "/cache")
#else
!strcmp(name, "/cache")
#endif
// !strcmp(name, "/proc")
)
/* Only prints if filter matches */
ui_print("name: %s; type: %s\n", name, type);
}
ensure_root_path_unmounted("SYSTEM:");
ensure_root_path_unmounted("DATA:");
ensure_root_path_unmounted("CACHE:");
#ifdef IS_ICONIA
ensure_root_path_unmounted("FLEXROM:");
#endif
fclose(mounts);
}
#endif
int dump_device(const char *root)
{
const RootInfo* info = get_device_info(root);
if (info == NULL || info->device == NULL) {
return -1;
}
if(!strcmp (info->type, "emmc")) {
mmc_scan_partitions();
const MmcPartition *partition;
partition = mmc_find_partition_by_name(info->partition_name);
if (partition != NULL) {
static char dump[PATH_MAX];
sprintf(dump, "dd if=%s of=/tmp/mkboot/%s.img bs=4096", partition->device_index, info->partition_name);
__system(dump);
LOGW("dump cmd is %s\n", dump);
return 0;
} else {
static char dump[PATH_MAX];
sprintf(dump, "dd if=%s of=/tmp/mkboot/%s.img bs=4096", info->device, info->partition_name);
__system(dump);
LOGW("dump cmd is %s\n", dump);
return 0;
}
}
if(!strcmp (info->type, "mtd")) {
static char dump[PATH_MAX];
sprintf(dump, "dump_image %s /tmp/mkboot/%s.img", info->partition_name, info->partition_name);
__system(dump);
LOGW("dump cmd is %s\n", dump);
return 0;
}
return -1;
}
void unpack_boot()
{
__system("unpackbootimg -i /tmp/mkboot/boot.img -o /tmp/mkboot");
__system("mkbootimg.sh");
#ifdef USES_NAND_MTD
__system("flash_image boot /tmp/mkboot/newboot.img");
#else
char boot_device[PATH_MAX];
char fb_cmd[PATH_MAX];
property_get("ro.boot.block", boot_device, "");
if(!strcmp(boot_device, ""))
{
LOGE("Error getting boot device\n");
return;
}
sprintf(fb_cmd, "dd if=/tmp/mkboot/newboot.img of=%s bs=4096", boot_device);
__system(fb_cmd);
#endif
sync();
}
#ifdef HBOOT_SON_KERNEL
void unpack_boot_hbootzip()
{
__system("unpackbootimg -i /tmp/mkboot/boot.img -o /tmp/mkboot");
__system("mkbootimg.sh");
}
#endif
void setup_mkboot()
{
ensure_root_path_mounted("SDCARD:");
__system("mkdir -p /sdcard/mkboot");
__system("mkdir -p /sdcard/mkboot/zImage");
__system("mkdir -p /sdcard/mkboot/modules");
__system("rm -rf /tmp/mkboot");
__system("mkdir -p /tmp/mkboot");
__system("chmod 0755 /tmp/mkboot/");
}
#ifdef HBOOT_SON_KERNEL
void setup_hbootzip()
{
ensure_root_path_mounted("SDCARD:");
__system("mkdir -p /sdcard/mkboot");
__system("mkdir -p /sdcard/mkboot/zImage");
__system("mkdir -p /sdcard/mkboot/modules");
__system("rm -rf /tmp/mkboot");
__system("mkdir -p /tmp/mkboot");
__system("chmod 0755 /tmp/mkboot/");
__system("mkdir -p /sdcard/mkboot/androidinfo");
}
#endif
int check_file_exists(const char* file_path)
{
struct stat st;
if (0 != stat(file_path, &st)) {
LOGW("Error %s doesn't exist\n", file_path);
return -1;
} else {
return 0;
}
}
int is_dir(const char* file_path)
/* dir ret 0, file ret 1, err ret -1 */
{
if (0 == (check_file_exists(file_path))) {
struct stat s;
stat(file_path, &s);
if (!(S_ISDIR(s.st_mode))) {
return 0;
} else if (!(S_ISREG(s.st_mode))) {
return 1;
} else {
return -1;
}
}
return -1;
}
int copy_file(const char* source, const char* dest)
{
/* need to add a check to see if dest dir exists and volume is mounted */
if (0 == (is_dir(source))) {
char copy[PATH_MAX];
sprintf(copy, "cp -r %s %s", source, dest);
__system(copy);
return 0;
}
if (1 == (is_dir(source))) {
char copy[PATH_MAX];
sprintf(copy, "cp %s %s", source, dest);
__system(copy);
return 0;
}
return 1;
}
void do_module()
{
ensure_root_path_mounted("SYSTEM:");
ensure_root_path_mounted("SDCARD:");
__system("rm -rf /system/lib/modules");
__system("cp -r /sdcard/mkboot/modules /system/lib/modules");
__system("chmod 0644 /system/lib/modules/*");
ensure_root_path_unmounted("SYSTEM:");
//ensure_root_path_unmounted("SDCARD:");
}
#ifdef HBOOT_SON_KERNEL
void make_hboot_zip()
{
ensure_root_path_mounted("SDCARD:");
char htcmodelid[20];
char zipid[5];
property_get("ro.htcmodelid", htcmodelid, "");
//LOGE("htcmodelid is %s\n", htcmodelid);
strncpy (zipid, htcmodelid, 4);
zipid[4]='\0';
puts (zipid);
//LOGE("zipid is: %s\n", zipid);
char zippkg[PATH_MAX];
sprintf(zippkg, "/sbin/zip -j /tmp/mkboot/%sIMG /tmp/mkboot/android-info.txt /tmp/mkboot/boot.img", zipid);
//LOGE("zip command is : %s\n", zippkg);
__system(zippkg);
char zipcopy[PATH_MAX];
sprintf(zipcopy, "cp /tmp/mkboot/%sIMG.zip /sdcard/%sIMG.zip", zipid, zipid);
__system(zipcopy);
//LOGE("zipcopy command is: %s\n", zipcopy);
}
void delete_hboot_zip()
{
ensure_root_path_mounted("SDCARD:");
char htcmodelid[20];
char zipid[5];
property_get("ro.htcmodelid", htcmodelid, "");
strncpy (zipid, htcmodelid, 4);
zipid[4]='\0';
puts (zipid);
char zippkg_del[PATH_MAX];
sprintf(zippkg_del, "rm /sdcard/%sIMG.zip", zipid);
__system(zippkg_del);
}
#endif
void do_make_new_boot()
{
setup_mkboot();
ui_print("\nConnect phone to pc");
ui_print("\nand copy new zImage and");
ui_print("\nmodules to /sdcard/mkboot");
ui_print("\nzImage & modules folder\n\n");
usb_toggle_sdcard();
ensure_root_path_mounted("SDCARD:");
dump_device("BOOT:");
if (0 == (copy_file("/sdcard/mkboot/zImage/zImage", "/tmp/mkboot/zImage"))) {
unpack_boot();
do_module();
ui_print("New boot created and flashed!!\n\n");
} else {
ui_print("Error missing /sdcard/mkboot/zImage/zImage\n\n");
}
__system("rm -rf /tmp/mkboot");
__system("rm /sdcard/mkboot/zImage/*");
__system("rm /sdcard/mkboot/modules/*");
ensure_root_path_unmounted("SDCARD:");
}
#ifdef HBOOT_SON_KERNEL
int do_make_new_hbootbootzip()
{
setup_hbootzip();
ui_print("\nConnect phone to pc");
ui_print("\nand copy new zImage and");
ui_print("\nmodules to /sdcard/mkboot");
ui_print("\nzImage & modules folder\n");
ui_print("\nCopy android-info.txt to");
ui_print("\n/sdcard/mkboot/androidinfo folder\n\n");
usb_toggle_sdcard();
ensure_root_path_mounted("SDCARD:");
dump_device("BOOT:");
if (0 == (copy_file("/sdcard/mkboot/zImage/zImage", "/tmp/mkboot/zImage"))) {
unpack_boot_hbootzip();
do_module();
ui_print("New boot created & Kernel modules installed!\n");
} else {
ui_print("Error missing /sdcard/mkboot/zImage/zImage\n\n");
return -1;
}
if (0 == (copy_file("/sdcard/mkboot/androidinfo/android-info.txt", "/tmp/mkboot/android-info.txt"))) {
__system("rm /tmp/mkboot/boot.img");
__system("mv /tmp/mkboot/newboot.img /tmp/mkboot/boot.img");
make_hboot_zip();
ui_print("Hboot kernel zip created and copied to root of sdcard.\n");
ui_print("Rebooting to bootloader for install!!!!\n\n");
} else {
ui_print("Error missing /sdcard/mkboot/androidinfo/android-info.txt\n\n");
return -1;
}
__system("rm -rf /tmp/mkboot");
__system("rm /sdcard/mkboot/zImage/*");
__system("rm /sdcard/mkboot/modules/*");
sync();
rb_bootloader();
return 0;
}
int do_make_new_hbootbootzip_auto()
{
char manufacturer[64];
property_get("ro.product.manufacturer", manufacturer, "");
if(strcmp(manufacturer, "HTC"))
{
ui_print("Error Non HTC phone detected!!!\n\n");
return -1;
}
setup_hbootzip();
ensure_root_path_mounted("SDCARD:");
dump_device("BOOT:");
if (0 == (copy_file("/sdcard/mkboot/zImage/zImage", "/tmp/mkboot/zImage"))) {
unpack_boot_hbootzip();
do_module();
ui_print("New boot created & kernel modules installed!\n");
} else {
ui_print("Error missing /sdcard/mkboot/zImage/zImage\n\n");
return -1;
}
if (0 == (copy_file("/sdcard/mkboot/androidinfo/android-info.txt", "/tmp/mkboot/android-info.txt"))) {
__system("rm /tmp/mkboot/boot.img");
__system("mv /tmp/mkboot/newboot.img /tmp/mkboot/boot.img");
make_hboot_zip();
ui_print("Hboot kernel zip created and copied to root of sdcard.\n");
ui_print("Rebooting to bootloader for install!!!!\n\n");
} else {
ui_print("Error missing /sdcard/mkboot/androidinfo/android-info.txt\n\n");
return -1;
}
__system("rm -rf /tmp/mkboot");
__system("rm /sdcard/mkboot/zImage/*");
__system("rm /sdcard/mkboot/modules/*");
sync();
rb_bootloader();
return 0;
}
#endif
void install_su(int eng_su)
{
ui_print("Working ......\n");
ensure_root_path_mounted("SYSTEM:");
ensure_root_path_mounted("DATA:");
ensure_root_path_mounted("CACHE:");
char device_sdext[PATH_MAX];
get_device_index("SDEXT:", device_sdext);
struct stat sd;
if (0 == stat(device_sdext, &sd)) {
ensure_root_path_mounted("SDEXT:");
__system("rm /sd-ext/dalvik-cache/*com.noshufou.android.su*classes.dex");
__system("rm -rf /sd-ext/data/com.noshufou.android.su");
__system("rm /sd-ext/app/com.noshufou.android.su*.apk");
__system("rm /sd-ext/dalvik-cache/*uperuser*classes.dex");
ensure_root_path_unmounted("SDEXT:");
}
__system("rm -rf /data/data/com.noshufou.android.su");
__system("rm /data/app/com.noshufou.android.su*.apk");
__system("rm /data/dalvik-cache/*com.noshufou.android.su*classes.dex");
__system("rm /data/dalvik-cache/*uperuser*classes.dex");
__system("rm /cache/dalvik-cache/*com.noshufou.android.su*classes.dex");
__system("rm /cache/dalvik-cache/*uperuser*classes.dex");
__system("rm /system/app/*uperuser.apk");
if ((0 == (check_file_exists("/system/bin/su"))) || (0 == (check_file_exists("/system/xbin/su"))) ){
ui_print("Removing old su\n");
}
delete_file("/system/bin/su");
__system("rm /system/xbin/su");
if (!eng_su) {
copy_file("/extra/su", "/system/bin/su");
copy_file("/extra/Superuser.apk", "/system/app/Superuser.apk");
__system("chmod 0644 /system/app/Superuser.apk");
} else {
copy_file("/extra/suhack", "/system/bin/su");
}
__system("mkdir -p /system/xbin");
__system("chmod 06755 /system/bin/su");
__system("ln -s /system/bin/su /system/xbin/su");
ensure_root_path_unmounted("DATA:");
ensure_root_path_unmounted("SYSTEM:");
ensure_root_path_unmounted("CACHE:");
ui_print("su install complete\n\n");
}
int delete_file(const char* file)
{
/* need to add a check to see if volume is mounted */
if (0 == (is_dir(file))) {
char del[PATH_MAX];
sprintf(del, "rm -rf %s ", file);
__system(del);
return 0;
}
if (1 == (is_dir(file))) {
char del[PATH_MAX];
sprintf(del, "rm %s ", file);
__system(del);
return 0;
}
return 1;
}
void rb_bootloader()
{
sync();
ensure_root_path_unmounted("DATA:");
ensure_root_path_unmounted("SYSTEM:");
ensure_root_path_unmounted("CACHE:");
ensure_root_path_unmounted("SDCARD:");
ensure_root_path_unmounted("SDEXT:");
#ifdef HAS_INTERNAL_SD
ensure_root_path_unmounted("INTERNALSD:");
#endif
#ifdef IS_ICONIA
ensure_root_path_unmounted("FLEXROM:");
#endif
__system("/sbin/reboot bootloader");
}
void rb_recovery()
{
sync();
ensure_root_path_unmounted("DATA:");
ensure_root_path_unmounted("SYSTEM:");
ensure_root_path_unmounted("CACHE:");
ensure_root_path_unmounted("SDCARD:");
ensure_root_path_unmounted("SDEXT:");
#ifdef HAS_INTERNAL_SD
ensure_root_path_unmounted("INTERNALSD:");
#endif
#ifdef IS_ICONIA
ensure_root_path_unmounted("FLEXROM:");
#endif
__system("/sbin/reboot recovery");
}
#ifdef MMC_PART_DEBUG
/* Porting Test */
void display_roots(const char *root)
{
const RootInfo* info = get_device_info(root);
mmc_scan_partitions();
const MmcPartition *partition;
partition = mmc_find_partition_by_name(info->partition_name);
if (partition == NULL) {
LOGW("can't find mmc partition \"%s\"\n",
info->partition_name);
} else {
LOGW("Begin info print!!\n");
LOGW(" filesystem : %s device_index : %s name : %s dstatus : %d dtype : %d dfirstsec : %d dsize : %d \n\n", partition->filesystem, partition->device_index, partition->name, partition->dstatus, partition->dtype, partition->dfirstsec, partition->dsize);
}
}
#endif
#ifndef USES_NAND_MTD
const char* check_extfs_format(const char* root_path)
{
const char *fstype;
if (!strcmp(root_path, "SDEXT:")) {
return NULL;
}
if (!strcmp(root_path, "SYSTEM:") || !strcmp(root_path, "DATA:") || !strcmp(root_path, "CACHE:") || !strcmp(root_path, "FLEXROM:")) {
const RootInfo* info = get_device_info(root_path);
if (info == NULL) {
return NULL;
}
ensure_root_path_mounted(root_path);
if (0 != ensure_root_path_mounted(root_path)) {
ui_print("Error mounting %s!\n", info->mount_point);
return NULL;
}
static char discard1[1024];
char device1[64], name1[64], type1[64];
FILE *mountsf = fopen("/proc/mounts", "r");
while (fscanf(mountsf, "%64s %64s %64s %1024[^\n]", device1, name1, type1, discard1) != EOF) {
/* Enjoy the whitespace! */
if (
!strcmp(name1, info->mount_point)
)
LOGW("name: %s; device: %s; type: %s\n", name1, device1, type1);
}
fclose(mountsf);
if (!strcmp(type1, "ext3") || !strcmp(type1, "ext4")) {
fstype = type1;
return fstype;
} else {
return NULL;
}
}
return NULL;
}
int call_format_ext(const char* root)
{
const MmcPartition *partition = get_root_mmc_partition(root);
if (partition == NULL) {
return -1;
}
const char *fstype = check_extfs_format(root);
if (fstype == NULL) {
return -1;
}
ensure_root_path_unmounted(root);
if (!strcmp(fstype, "ext3")) {
return mmc_format_ext3(partition);
} else if (!strcmp(fstype, "ext4")) {
return mmc_format_ext4(partition);
} else {
LOGW("Error formatting %s as %s \n" , partition->name, fstype);
return -1;
}
}
int force_format_ext3(const char* root)
{
const char *fstype = check_extfs_format(root);
if (fstype == NULL) {
return -1;
}
ensure_root_path_unmounted(root);
const MmcPartition *partition = get_root_mmc_partition(root);
if (partition != NULL) {
return mmc_format_ext3(partition);
}
const RootInfo* info = get_device_info(root);
if (info == NULL) {
return -1;
} else {
return format_ext3_device(info->device);
}
}
int force_format_ext4(const char* root)
{
const char *fstype = check_extfs_format(root);
if (fstype == NULL) {
return -1;
}
ensure_root_path_unmounted(root);
const MmcPartition *partition = get_root_mmc_partition(root);
if (partition != NULL) {
return mmc_format_ext4(partition);
}
const RootInfo* info = get_device_info(root);
if (info == NULL) {
return -1;
} else {
return format_ext4_device(info->device);
}
}
int upgrade_ext3_to_ext4(const char* root)
{
const char *fstype = check_extfs_format(root);
if (fstype == NULL) {
return -1;
}
ensure_root_path_unmounted(root);
const MmcPartition *partition = get_root_mmc_partition(root);
if (partition != NULL) {
if (!strcmp(fstype, "ext3")) {
return mmc_upgrade_ext3(partition);
} else {
ui_print("%s is already ext4\n", partition->name);
return -1;
}
}
const RootInfo* info = get_device_info(root);
if (info == NULL) {
return -1;
}
if (!strcmp(fstype, "ext3")) {
return device_upgrade_ext3(info->device);
} else {