For those who are interested in the Android underlying layer, the specific startup process should attract us. However, many startup files have to be pushed to the host by adb, which is inconvenient. It is strange that the Toolbox provided by Android is too simple. So before getting to know the Android startup process, we will install Busybox on Android. In this way, there are a lot of tools for us to use.
First, go to the busybox homepage to download the source code of the latest version, and then use the arm cross compiler to compile the executable program of busybox. during compilation, pay attention to some setting options, such
Build Options->
Build BusyBox as a static binary (no shared libs) should be selected, because the compiled busyBox can be run independently.
│ Do you want to build BusyBox with a Cross Compiler? │
│ (/HOME/toolchains/gcc-4.0.2-glibc-2.3.5/arm-9tdmi-linux-gnu/bin/arm-9tdmi-linux-gnu │ this is the path of the cross compiler, according to the specific circumstances to set.
Installation Options->
Don't use/usr
In this way, the compiled busybox will not be installed in the/usr directory of your host. Be sure to select.
The function options of busybox can be selected as needed, but do not be greedy.
OK. Here we will not be entangled in compiling busybox. There are countless materials on the Internet. Next, we will install busybox on the simulator. Create a folder for busybox on the simulator, and enter the executable file directory of busybox.
Adb push busybox. asc/data/busybox
Then enter adb shell, chmod 777./busybox, and you can use it directly. But it is still inconvenient. I can't lose busybox every time I use a command? Therefore, we can first install the program in the current directory with./busybox -- install, and then add the current directory to the PATH variable. Temporarily use export to add it. If you want to add it permanently, go to the next step.
Now, the preparation is complete and the study is started. Since we are studying the startup process, we should first look at the init. rc file. Open it in the etc directory and analyze the content. The first is the definition of env, that is, the definition of global environment variables. What is the meaning of the content in the subsequent establishment and initialization, this is followed by the initial process information that runs when the system is started. This is interesting, including usbd-config and qemu, which are not required by qemu, while usbd-config is used as the initial process, it should be the same as in the previous article, used for debugging or usb communication. Next, it is the service process started after the initial startup process is completed. If these processes exit for some reason, they will be automatically restarted. This includes the console, adbd monitoring process, usbd monitoring process, debugadh monitoring process, and so on. Aside from these daemon processes, we can pay attention to runtime and zygote. These two processes seem to be in charge of the startup of other processes and applications.
Now, let's make an experiment and change the automatic call START process to manual to see what the START process is. To achieve this goal, you must first modify init. the rc file, of course, is not changed in the console of the simulator. First, it cannot be changed. Second, it is useless if you change the file. It will be overwritten next time you load the file. Therefore, we need to start with the original image ramdisk. img. Starting from the 2.6 standard Linux kernel, initrd. img adopts cpio compression. It is assumed that ramdisk. img is the same. You need to decompress it using gunzip and then decompress it using cpio. OK. Go to the tools/lib/images directory and run the file command to check the ramdisk. img type.
Ramdisk. img: gzip compressed data, from Unix
Next, copy ramdisk.imgto another directory, change its name to ramdisk.img.gz, and run the command
Gunzip ramdisk.img.gz
Create a folder named ramdisk.
Cpio-I-F ../ramdisk. img
Now you can see and operate the content in ramdisk. Of course, you can also perform operations directly outside, but we recommend that you concentrate all the content extracted from cpio in a folder, because we will compress it into a new ramdisk. img later.
OK. Now let's start the modification process. Open init. rc in any editor. First add your Busybox installation PATH in PATH, and then annotate the content. We need to start them manually.
# Zygote {# exec/system/bin/app_process # args {#0-Xzygote #1/system/bin #2-zygote #}# autostart 1 #}# runtime {# exec /system/bin/runtime # autostart 1 #}
Note that you should not comment out both of them at the same time, comment out one of them, and then try to start it manually. If the two comment at the same time I have a problem here, it cannot be started.
OK. Then, use the following command to repackage the image.
Cpio-I-t-F ../ramdisk. img> list
Cpio-o-H newc-O lk. img <list
The lk. img generated in the current directory is our new image. Use your own image to start emulator;
Emulator-console-ramdisk lk. img
If we comment on zygote, enter
App_process-Xzygote/system/bin-zygote
Manual start. The output information in the command line is
Prepping:/system/app/AlarmProvider.apk:/system/app/Browser.apk:/system/app/
Calendar.apk:/system/app/Camera.apk:/system/app/Contacts.apk:
/System/app/Development.apk:/system/app/GDataFeedsProvider.apk:/system/app/
Gmail.apk:/system/app/GmailProvider.apk:/system/app/GoogleApps.apk:
/System/app/GoogleAppsProvider.apk:/system/app/Home.apk:/system/app/ImProvider.apk:
/System/app/Maps.apk:/system/app/MediaPickerActivity.apk:
/System/app/MediaProvider.apk:/system/app/Phone.apk:/system/app/PimProvider.apk:/system/
App/ApiDemos.apk:/system/app/SettingsProvider.apk:
/System/app/Sms.apk:/system/app/SyncProvider.apk:/system/app/TelephonyProvider.apk:
/System/app/XmppService.apk:/system/app/YouTube.apk
File not found:/system/app/AlarmProvider.apk
File not found:/system/app/Calendar.apk
File not found:/system/app/Camera.apk
File not found:/system/app/GDataFeedsProvider.apk
File not found:/system/app/Gmail.apk
File not found:/system/app/GmailProvider.apk
File not found:/system/app/MediaPickerActivity.apk
File not found:/system/app/PimProvider.apk
File not found:/system/app/ApiDemos.apk
File not found:/system/app/Sms.apk
File not found:/system/app/SyncProvider.apk
File not found:/system/app/YouTube.apk
Prep complete
Hey, you can see some apps that Google may launch soon, such as Gmail, from the File not found information. Of course, these are the startup information of the Java framework. We will use other tools for further exploration in the future.
If we annotate runtime, the output information is:
++ Post-zygote
From the column of andy_android