SlideShare a Scribd company logo
1 of 24
Android Init ENM System 권홍재
Kernel에서 Android init 시작 ,[object Object]
안드로이드init은 루트에 위치하기때문에 반드시 커널 부팅옵션에서 “init=/init”옵션이 주어져야 한다.< kernel/init/main.c > static intnoinlineinit_post(void) { ...     if (execute_command) { run_init_process(execute_command); printk(KERN_WARNING "Failed to execute %s.  Attempting "                                                "defaults...", execute_command);     }                                                                                                                                                                                                 run_init_process("/sbin/init"); run_init_process("/etc/init"); run_init_process("/bin/init"); run_init_process("/bin/sh");     panic("No init found.  Try passing init= option to kernel."); }
Init 프로세스의 시작과 Signal 처리 ,[object Object],< android/system/core/init/init.c > static void sigchld_handler(int s) {     write(signal_fd, &s, 1); } ... int main(intargc, char **argv) { ... structsigaction act; act.sa_handler = sigchld_handler; act.sa_flags = SA_NOCLDSTOP; act.sa_mask = 0; act.sa_restorer = NULL; sigaction(SIGCHLD, &act, 0); ... }
디렉토리 생성과  mount ,[object Object],< android/system/core/init/init.c > mkdir("/dev", 0755); mkdir("/proc", 0755); mkdir("/sys", 0755);     mount("tmpfs", "/dev", "tmpfs", 0, "mode=0755"); mkdir("/dev/pts", 0755); mkdir("/dev/socket", 0755);     mount("devpts", "/dev/pts", "devpts", 0, NULL);     mount("proc", "/proc", "proc", 0, NULL);     mount("sysfs", "/sys", "sysfs", 0, NULL);
Standard I/O 설정 ,[object Object],< android/system/core/init/init.c > int main(intargc, char **argv) { ... open_devnull_stdio(); ... } void open_devnull_stdio(void) { intfd;     static const char *name = "/dev/__null__";     if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) { fd = open(name, O_RDWR);         unlink(name);         if (fd >= 0) {             dup2(fd, 0);            dup2(fd, 1);            dup2(fd, 2);             if (fd > 2) {                 close(fd);             }             return;         }     }     exit(1); } fd[0] stdin fd[0] stdin fd[1] stdout fd[1] stdout fd[2] stderr fd[2] stderr fd[3] _null_ fd[3] _null_ fd[…] fd[…]
Init 프로세스의 로그메시지 설정 ,[object Object],(dmesg유틸을 사용하여 확인가능) < android/system/core/init/init.c > int main(intargc, char **argv) { ... log_init(); … } < android/system/core/init/util.c > #define ERROR(x...)   log_write(3, "<3>init: " x) #define NOTICE(x...)  log_write(5, "<5>init: " x) #define INFO(x...)    log_write(6, "<6>init: " x) void log_init(void) {     static const char *name = "/dev/__kmsg__";     if (mknod(name, S_IFCHR | 0600, (1 << 8) | 11) == 0) { log_fd = open(name, O_WRONLY); …     } } void log_write(int level, const char *fmt, ...) { …     write(log_fd, buf, strlen(buf)); }
init.rc파싱 ,[object Object],< android/system/core/init/init.c > int main(intargc, char **argv) { ... parse_config_file(“init.rc”); …. } ,[object Object],< android/system/core/rootdir/init.rc > on init … on boot … on property:ro.kernel.qemu=1 … serviceservicemanager /system/bin/servicemanager servicevold /system/bin/vold servicenetd /system/bin/netd … action_list service_list
Emulator초기화 ,[object Object],< android/system/core/init/init.c > int main(intargc, char **argv) { ... qemu_init(); …. } ,[object Object]
QEMU기반의 어플리케이션이다.
커널cmdline에 qumu=1의 값이 있다면 안드로이드 에뮬레이터라고 인식한다.
qemu mode에서는 property영역에 ro.kernel.<name>에 해당하는 값을 설정하고 이를 시스템에서 참조한다.
QEMU
PC를 위한 오픈 소스 에뮬레이터
프로세서를 에뮬레이션하는 이외에 네트워크, 비디오 하드웨어와 같은 필요한 모든 하위 시스템을 흉내낸다.
또한 (255개 CPU까지 지원하는) SMP와 같은 최신 개념, ARM이나 PowerPC와 같은 다른 프로세서 아키텍처도 에뮬레이션한다.,[object Object]
init.[H/W이름].rc파싱 ,[object Object],< android/system/core/init/init.c > int main(intargc, char **argv) { ... get_hardware_name(); snprintf(tmp, sizeof(tmp), "/init.%s.rc", hardware); parse_config_file(tmp); …. } ,[object Object],(Hardware명을소문자로 치환하여 rc파일을 찾는다.) # cat /proc/cpuinfo … Hardware        : ENMC100 …
.rc파일의 early-init섹션 수행 ,[object Object],< android/system/core/init/init.c > int main(intargc, char **argv) { ... action_for_each_trigger("early-init", action_add_queue_tail); drain_action_queue();  …. } ,[object Object]
init.rc와 init.[H/W 이름].rc파일에서 early-early-init섹션에 해당하는 부분을 실행큐에 담는다.
Drain_action_queue();
실행큐(action_queue)에 저장된 명령어를 하나씩 수행한다.,[object Object]
정적 디바이스 파일 생성 flow< init.c > device_fd = device_init(); main() < devices.c > device_init() coldboot() do_coldboot() devperms구조체를 참조하여  uevent강제발생 Hot Plug handle_device_fd() handle_device_event() make_device()
property 공간 초기화 ,[object Object],(anonymous shared memory) < android/system/core/init/init.c > int main(intargc, char **argv) { ... property_init(); …. } < android/system/core/init/init.c > void property_init(void){ init_property_area(); load_properties_from_file(PROP_PATH_RAMDISK_DEFAULT);  /default.prop }
keychord open 및 serial 동작확인  ,[object Object]

More Related Content

What's hot

Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGLSuhan Lee
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera ArchitecturePicker Weng
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsLinaro
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementationChethan Pchethan
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializableSourabh Sahu
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - VoldWilliam Lee
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depthChris Simmonds
 

What's hot (20)

Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
 
Android - ADB
Android - ADBAndroid - ADB
Android - ADB
 
Understaing Android EGL
Understaing Android EGLUnderstaing Android EGL
Understaing Android EGL
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera Architecture
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Design and Concepts of Android Graphics
Design and Concepts of Android GraphicsDesign and Concepts of Android Graphics
Design and Concepts of Android Graphics
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Q4.11: Porting Android to new Platforms
Q4.11: Porting Android to new PlatformsQ4.11: Porting Android to new Platforms
Q4.11: Porting Android to new Platforms
 
Overview of Android binder IPC implementation
Overview of Android binder IPC implementationOverview of Android binder IPC implementation
Overview of Android binder IPC implementation
 
Parceable serializable
Parceable serializableParceable serializable
Parceable serializable
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
The Android graphics path, in depth
The Android graphics path, in depthThe Android graphics path, in depth
The Android graphics path, in depth
 

Similar to Android+init+process

Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016perillamint
 
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoLinux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoMario Cho
 
망고210 android fastboot nand write 방법
망고210 android fastboot nand write 방법망고210 android fastboot nand write 방법
망고210 android fastboot nand write 방법종인 전
 
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.chcbaram
 
망고100 보드로 놀아보자 14
망고100 보드로 놀아보자 14망고100 보드로 놀아보자 14
망고100 보드로 놀아보자 14종인 전
 
안드로이드 플랫폼 설명
안드로이드 플랫폼 설명안드로이드 플랫폼 설명
안드로이드 플랫폼 설명Peter YoungSik Yun
 
도커없이컨테이너 만들기 8편 - pid namespace
도커없이컨테이너 만들기 8편 - pid namespace도커없이컨테이너 만들기 8편 - pid namespace
도커없이컨테이너 만들기 8편 - pid namespaceSam Kim
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010MinGeun Park
 
13. Application - Tensorflow Autoencoder
13. Application - Tensorflow Autoencoder 13. Application - Tensorflow Autoencoder
13. Application - Tensorflow Autoencoder merry7
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기Chris Ohk
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)Sang Don Kim
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010Ryan Park
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10Ryan Park
 
Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국hanbeom Park
 
7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성HyeonSeok Choi
 
[D2 오픈세미나]5.robolectric 안드로이드 테스팅
[D2 오픈세미나]5.robolectric 안드로이드 테스팅[D2 오픈세미나]5.robolectric 안드로이드 테스팅
[D2 오픈세미나]5.robolectric 안드로이드 테스팅NAVER D2
 
NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기TaeYoung Kim
 

Similar to Android+init+process (20)

Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016Hideroot - Inc0gnito 2016
Hideroot - Inc0gnito 2016
 
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario ChoLinux Kernel Boot Process , SOSCON 2015, By Mario Cho
Linux Kernel Boot Process , SOSCON 2015, By Mario Cho
 
망고210 android fastboot nand write 방법
망고210 android fastboot nand write 방법망고210 android fastboot nand write 방법
망고210 android fastboot nand write 방법
 
Device driver
Device driverDevice driver
Device driver
 
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
컵드론 멀티콥터 펌웨어 분석 2015. 3.28.
 
망고100 보드로 놀아보자 14
망고100 보드로 놀아보자 14망고100 보드로 놀아보자 14
망고100 보드로 놀아보자 14
 
안드로이드 플랫폼 설명
안드로이드 플랫폼 설명안드로이드 플랫폼 설명
안드로이드 플랫폼 설명
 
도커없이컨테이너 만들기 8편 - pid namespace
도커없이컨테이너 만들기 8편 - pid namespace도커없이컨테이너 만들기 8편 - pid namespace
도커없이컨테이너 만들기 8편 - pid namespace
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 
Init to systemd
Init to systemdInit to systemd
Init to systemd
 
13. Application - Tensorflow Autoencoder
13. Application - Tensorflow Autoencoder 13. Application - Tensorflow Autoencoder
13. Application - Tensorflow Autoencoder
 
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
[TechDays Korea 2015] 녹슨 C++ 코드에 모던 C++로 기름칠하기
 
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
[Td 2015]녹슨 c++ 코드에 모던 c++로 기름칠하기(옥찬호)
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
온라인 게임에서 사례로 살펴보는 디버깅 in NDC2010
 
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
온라인 게임에서 사례로 살펴보는 디버깅 in NDC10
 
Deview 2019 눈발자국
Deview 2019 눈발자국Deview 2019 눈발자국
Deview 2019 눈발자국
 
7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성7가지 동시성 모델 - 데이터 병렬성
7가지 동시성 모델 - 데이터 병렬성
 
[D2 오픈세미나]5.robolectric 안드로이드 테스팅
[D2 오픈세미나]5.robolectric 안드로이드 테스팅[D2 오픈세미나]5.robolectric 안드로이드 테스팅
[D2 오픈세미나]5.robolectric 안드로이드 테스팅
 
NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기NodeJs로 디바이스 통신하기
NodeJs로 디바이스 통신하기
 
HI-ARC PS 101
HI-ARC PS 101HI-ARC PS 101
HI-ARC PS 101
 

Android+init+process

  • 1. Android Init ENM System 권홍재
  • 2.
  • 3. 안드로이드init은 루트에 위치하기때문에 반드시 커널 부팅옵션에서 “init=/init”옵션이 주어져야 한다.< kernel/init/main.c > static intnoinlineinit_post(void) { ... if (execute_command) { run_init_process(execute_command); printk(KERN_WARNING "Failed to execute %s. Attempting " "defaults...", execute_command); } run_init_process("/sbin/init"); run_init_process("/etc/init"); run_init_process("/bin/init"); run_init_process("/bin/sh"); panic("No init found. Try passing init= option to kernel."); }
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 11. 커널cmdline에 qumu=1의 값이 있다면 안드로이드 에뮬레이터라고 인식한다.
  • 12. qemu mode에서는 property영역에 ro.kernel.<name>에 해당하는 값을 설정하고 이를 시스템에서 참조한다.
  • 13. QEMU
  • 14. PC를 위한 오픈 소스 에뮬레이터
  • 15. 프로세서를 에뮬레이션하는 이외에 네트워크, 비디오 하드웨어와 같은 필요한 모든 하위 시스템을 흉내낸다.
  • 16.
  • 17.
  • 18.
  • 19. init.rc와 init.[H/W 이름].rc파일에서 early-early-init섹션에 해당하는 부분을 실행큐에 담는다.
  • 21.
  • 22. 정적 디바이스 파일 생성 flow< init.c > device_fd = device_init(); main() < devices.c > device_init() coldboot() do_coldboot() devperms구조체를 참조하여 uevent강제발생 Hot Plug handle_device_fd() handle_device_event() make_device()
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. import_kernel_cmdline에서 읽어온값 설정< android/system/core/init/init.c > int main(intargc, char **argv) { … if (qemu[0]) import_kernel_cmdline(1); if (!strcmp(bootmode,"factory")) property_set("ro.factorytest", "1"); else if (!strcmp(bootmode,"factory2")) property_set("ro.factorytest", "2"); else property_set("ro.factorytest", "0"); property_set("ro.serialno", serialno[0] ? serialno : ""); property_set("ro.bootmode", bootmode[0] ? bootmode : "unknown"); property_set("ro.baseband", baseband[0] ? baseband : "unknown"); property_set("ro.carrier", carrier[0] ? carrier : "unknown"); property_set("ro.bootloader", bootloader[0] ? bootloader : "unknown"); property_set("ro.hardware", hardware); snprintf(tmp, PROP_VALUE_MAX, "%d", revision); property_set("ro.revision", tmp); … }
  • 28.
  • 29.
  • 30.
  • 31. early-boot, boot섹션을 실행큐에 담고 수행한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … /* make sure we actually have all the pieces we need */ if ((device_fd < 0) || (property_set_fd < 0) || (signal_recv_fd < 0)) { ERROR("init startup failure"); return 1; } /* execute all the boot actions to get us started */ action_for_each_trigger("early-boot", action_add_queue_tail); action_for_each_trigger("boot", action_add_queue_tail); drain_action_queue(); … }
  • 32.
  • 33.
  • 34.
  • 35. early-boot, boot섹션을 실행큐에 담고 수행한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … structpollfdufds[4]; … ufds[0].fd = device_fd; ufds[0].events = POLLIN; ufds[1].fd = property_set_fd; ufds[1].events = POLLIN; ufds[2].fd = signal_recv_fd; ufds[2].events = POLLIN; fd_count = 3; if (keychord_fd > 0) { ufds[3].fd = keychord_fd; ufds[3].events = POLLIN; fd_count++; } else { ufds[3].events = 0; ufds[3].revents = 0; } … }
  • 36.
  • 37. 안드로이드boot process 분석을위해 관련 데이터들을 수집한다.< android/system/core/init/init.c > int main(intargc, char **argv) { … i#f BOOTCHART bootchart_count = bootchart_init(); if (bootchart_count < 0) { ERROR("bootcharting init failure"); } else if (bootchart_count > 0) { NOTICE("bootcharting started (period=%d ms)", bootchart_count*BOOTCHART_POLLING_MS); } else { NOTICE("bootcharting ignored"); } #endif … for(;;) { #if BOOTCHART if (bootchart_count > 0) { if (timeout < 0 || timeout > BOOTCHART_POLLING_MS) timeout = BOOTCHART_POLLING_MS; if (bootchart_step() < 0 || --bootchart_count == 0) { bootchart_finish(); bootchart_count = 0; } } #endif … } … }
  • 38.