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

A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin XPeppers
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debuggingAshish Agrawal
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh KhetanRajesh Khetan
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverNanik Tolaram
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessNanik Tolaram
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The BasicsMike Desjardins
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesChris Simmonds
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android DevelopmentSpeck&Tech
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Atif AbbAsi
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)fefe7270
 

What's hot (20)

A quick and fast intro to Kotlin
A quick and fast intro to Kotlin A quick and fast intro to Kotlin
A quick and fast intro to Kotlin
 
Android crash debugging
Android crash debuggingAndroid crash debugging
Android crash debugging
 
Android internals By Rajesh Khetan
Android internals By Rajesh KhetanAndroid internals By Rajesh Khetan
Android internals By Rajesh Khetan
 
Learning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device DriverLearning AOSP - Android Linux Device Driver
Learning AOSP - Android Linux Device Driver
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
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
 
Learning AOSP - Android Booting Process
Learning AOSP - Android Booting ProcessLearning AOSP - Android Booting Process
Learning AOSP - Android Booting Process
 
Android Development: The Basics
Android Development: The BasicsAndroid Development: The Basics
Android Development: The Basics
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Binder: Android IPC
Binder: Android IPCBinder: Android IPC
Binder: Android IPC
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 
Kotlin for Android Development
Kotlin for Android DevelopmentKotlin for Android Development
Kotlin for Android Development
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Android Internals
Android InternalsAndroid Internals
Android Internals
 
Flutter
FlutterFlutter
Flutter
 
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)
 
Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I Introduction to Koltin for Android Part I
Introduction to Koltin for Android Part I
 
Introduction to Qt
Introduction to QtIntroduction to Qt
Introduction to Qt
 
Android audio system(audioflinger)
Android audio system(audioflinger)Android audio system(audioflinger)
Android audio system(audioflinger)
 

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.