所以可以用 init.rc 先啟動 static sh。
先在 static sh 中操作所有動作 (fdisk, dd, mkfs, cp,, etc) 都 OK 後。
寫成 script。
要在 init.rc 中 run script,但是又要在 system partition 還沒 mount 起來的時候作。
所以不能用 service,要在一般的 on boot 中用 exec 命令
因為要 run 的 script 是在外部 sd card
所以寫一個程式來啟動..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/mount.h> | |
#include <sys/stat.h> | |
#include <unistd.h> | |
#include <stdio.h> | |
int main(int argc,char **argv) | |
{ | |
int fd; | |
struct stat s; | |
if(mount("/dev/block/mmcblk1p1","/extsd","vfat",0,NULL)){ | |
printf("mount fail!\n"); | |
return 0; | |
} | |
if(stat("/extsd/ss.sh",&s)==0) | |
{ | |
char *a[]={"/extsd/sh","/extsd/ss.sh",NULL}; | |
execv("/extsd/sh",a); | |
} | |
umountexit: | |
//===umount and exit | |
umount("/extsd"); | |
return 0; | |
} |
因為這時候system 還沒 mount 起來,所以要準備 static build 的 sh 和所有 script 中會 run 到的 program。
並且都放到 外部 sdcard 中。
這裡, ss.sh 要作的就是把 data partition format 掉,所以是:
/extsd/mke2fs -t ext4 /dev/block/mmcblk0p5
/extsd/busybox sleep 1
和一般 shell script 不一樣,這個 ssh 不需要在前面寫 shell 的 run path,直接寫command 就可以。
另外,sleep 不是 android shell 的 buildin command,所以要用 busybox 來作。
有關 debug.. 因為 init.rc 這個階段,尤其是 on boot phase ,run 的 program 沒有取得console,所以 debug 起來很麻煩。
基本上把 init.rc 的 loglevel 改為 6 ,只能確認有叫起 init 中的 program,和 取得 exit code,
program run 的狀態就不得而知了。
所以修改 /system/core/init...
diff --git a/init/init.c b/init/init.c
index 21ded0e..380ec54 100755
--- a/init/init.c
+++ b/init/init.c
@@ -170,7 +170,9 @@ int wait_for_service(char *filename) {
sprintf(tmp, "%d,%d", dup(fd), sz);
add_environment("ANDROID_PROPERTY_WORKSPACE", tmp);
/* redirect stdio to null */
- zap_stdio();
+ //zap_stdio();
+ setsid();
+ open_console();
setpgid(0, getpid());
/* execute */
這樣就可以把 stdio 傳給 exec 的 program。在 console 上看到結果了。
沒有留言:
張貼留言