Android Startup Process
During Android startup, uboot will pass in an init parameter. This init parameter specifies the first program to run during startup. The default value is the INIT program, which is stored in ramdisk. IMG. You can analyze its code to see what initialization tasks have been done in it. Its source file is in system/CORE/init. C.
It will call init. RC initialization file, which is in the out/target/product/generic/root directory. After the file is started, we will find that the root directory is read-only and the sdcard owner is system, in this file, you can modify it to implement the root directory's read/write.
By analyzing these files, we can also find that ramdisk is first loaded when Android is started. the IMG image is mounted to the/directory, and a series of initialization actions are performed, including creating various Required Directories, initializing the console, and enabling services. System. IMG specifies some script commands in init. RC, which are parsed and mounted to the/system directory under the root directory through init. C.
Ramdisk. IMG, system. IMG, userdata. IMG Image Generation Process:
First, run the file ramdisk command on the Linux terminal. IMG, print out the following characters ramdisk. IMG: gzip compressed data, from snapshot), you can see that a new ramdisk is decompressed. IMG, this ramdisk. IMG is compressed using cpio. You can use the cpio command to decompress it.
-I-f ramdisk. IMG. After decompression, some folders and files are generated. When you see these files, you will understand that they are identical to those in the root directory. It shows that ramdisk. IMG is actually packaging and compressing the root directory.
The following describes the source of system. IMG. You can see this text in the 629 lines in build/CORE/makefile.
# The installed image, which may be optimized or unoptimized.
#
Installed_systemimage: = $ (product_out)/system. img
From this we can see that the system should generate system. IMG in the $ (product_out) directory.
Next, there is a copy-file-to-target in row 662, which copies system. IMG from an intermediate directory to the/Generic Directory.
Build_system is defined in row 636.
The system. IMG here is not the system. IMG we see under the/Generic Directory, but under another intermediate directory, but the same file. The first copy is to copy the system. img in the out/target/product/generic/obj/packaging/systemimage_unopt_intermediates directory to the/Generic Directory.
Now that we know the origins of system. IMG, we need to analyze what it is and what it contains ??
Makefile line624
$ (Built_systemimage_unopt): $ (internal_systemimage_files) $ (internal_mkuserfs)
$ (Call build-systemimage-target, $ @)
Here, Build-systemimg-target makefile line605 is called.
Ifeq ($ (target_userimages_use_ext2), true)
# Generate an ext2 Image
# $ (1): output file
Define build-systemimage-Target
@ Echo "Target System FS image: $(1 )"
$ (Call build-userimage-ext2-target, $ (target_out), $ (1), system ,)
Endef
Else # target_userimages_use_ext2! = True
# Generate a yaffs2 Image
# $ (1): output file
Define build-systemimage-Target
@ Echo "Target System FS image: $(1 )"
@ Mkdir-p $ (DIR $(1 ))
* $ (Hide) $ (mkyaffs2)-F $ (target_out) $(1 )*
Endef
Endif # target_userimages_use_ext2
The definition of target_userimages_use_ext2 cannot be found !!! However, from the above analysis, we can infer that it should be the yaffs2 file system.
Among them, mkyaffs2 :( Core/config. mk line161)
Mkyaffs2: = $ (host_out_executables)/mkyaffs2image $ (host_executable_suffix)
Define mkyaffs2 as an executable file mkyaffs2image in the directory/Media/Disk/mydroid/out/host/linux-x86/bin. Run this program to get the following information:
#./Mkyaffs2image
Mkyaffs2image: image building tool for yaffs2 built Nov 13 2009
Usage: mkyaffs2image [-F] dir image_file [convert]
-F fix file Stat (mod, user, group) for Device
Dir the directory tree to be converted
Image_file the output file to hold the image
'Convert' produce a big-Endian image from a little-endian machine
We know that this program can generate a file system image for yaffs2. The above functions of * $ (hide) $ (mkyaffs2)-F $ (target_out) $ (1) * are also clarified, convert the target_out directory to the yaffs2 format and output it to/Media/Disk/mydroid/out/target/product/generic/obj/packaging/systemimage_unopt_intermediates/system. IMG (that is, the system we finally see in the/Generic Directory. IMG ).
Now we know about the generation process of system. IMG. To find out the content in system. IMG, we need to analyze the content in the target_out directory. (I want to mount system. IMG to Linux to see what is in it, but it does not support the yaffs and yaffs2 file systems !!!)
Next: Analyze target_out and find the definition of target_out In the build/CORE/envsetup. Sh file (line205:
Target_out: = $ (product_out)/System
That is, the system directory under the/Media/Disk/mydroid/out/target/product/Generic Directory.
# Tree-L 1
.
| -- App
| -- Bin
| -- Build. Prop
| -- Etc
| -- Fonts
| -- Framework
| -- Lib
| -- USR
'-- Xbin
Now everything is clear, we finally see the system. the imgfile is an image of the system directory under this directory. It is similar to the linux root file system image and contains Android applications, configuration files, fonts, and so on.
Userdata. IMG comes from the data directory. By default, there is no file in it.
Ramdisk. IMG, system. IMG, and userdata. IMG image disassembly process:
1. ramdisk. IMG:
Ramdisk (initrd) is a small partition image that is mounted read-only to the kernel during boot. It only protects/init and some configuration files. It is used to initialize and mount other file system images. Ramdisk is a standard Linux feature.
Ramdisk. IMG is included in Google Android SDK ($ sdk_root/tools/lib/images/ramdisk. IMG), you can also compile and generate ($ sdk_root/out/target/product/$ produt_name/ramdisk. IMG ). This is a gzip compressed cpio file.
Modify the ramdisk image of Android
To modify it, copy it to your Linux machine and run the following command to unbind it:
user@computer:$ mv ramdisk.img ramdisk.cpio.gzgzip -d ramdisk.cpio.gzmkdir ramdiskcd ramdisk cpio -i -F ../ramdisk.cpio
After unzipping, make some modifications and delete useless files, and then run the following command to recreate ramdisk. cpio:
user@computer:$ cpio -i -t -F ../ramdisk.cpio | cpio -o -H newc -O ../ramdisk_new.cpio
You can rename the name and compress it:
User @ COMPUTER: $ CD ..
Gzip ramdisk_new.cpio
MV ramdisk_new.cpio.gz ramdisk. img
2. system and data images
System. IMG is an image mounted to/, which contains all the system executable files.
The image mounted to/data by userdata. IMG contains application and user-related data.
In actual physical devices, they mount the file system through the init. RC Script in ramdisk. They can be in different formats, such as yaffs2, ext4, or ubi-Fs.
They are generated and flushed into physical devices through the android build system. The simulators have different usage for them (see below ):
3. Android simulator Image
System. IMG is copied to a temporary file for the simulator to work. Any changes you make to the root directory of the simulator will be lost after the simulator exits.
Userdata. IMG is only used when the-wipe-data parameter is used. Usually ~ /. Android/userdata-qemu.img (under Linux) mounted as A/Data Partition image, and using-wipe-data will copy the content in userdata. img to the userdata-qemu.img.
When sdcard. IMG is used to use the-sdcard parameter, it is mounted to/sdcard
Cache. IMG uses the-Cache parameter to specify/cache content. If this parameter is not specified, an empty temporary file is created and mounted to/cache when the simulator starts. This temporary file will be automatically cleared upon exit.
The simulator does not modify system. IMG and userdata. IMG. 4. Disassemble Android's
Yaffs2 Image
A yaffs2 file is recognized as a "VMS Alpha executable" file in Linux.
User @ COMPUTER: $ File $ {sdk_root}/out/target/product/imx51_ccwmx51js/system. img
./Out/target/product/imx51_ccwmx51js/system. IMG: VMS Alpha executable
Download unyaffs from the Google Code site.
If the above executable file does not work in your system, you can also download the source code and recompile it.
User @ COMPUTER: $ gcc-O unyaffs. c
Sudo chmod + x/complete/directory/path/to/unyaffs
Then use this command to disassemble the yaff2 image file:
User @ COMPUTER: $ mkdir Image
CD image
Unyaffs ../system. img
5. disassemble the ext4 Image
If the image is ext4, you can directly mount it to read the content:
User @ COMPUTER: $ Mount-o loop-T ext4 system. img/Media
6. disassemble the jffs2 Image
Here, we will discuss how to disassemble the jffs2 image:
User @ COMPUTER: modprobe mtdblock
Modprobe jffs2
Modprobe mtdram total_size = 65536 erase_size = 256
Mknod/tmp/mtdblock0 B 31 0
Dd If =/pathtoimage/rootfs. jffs2 of =/tmp/mtdblock0
Mount-T jffs2/tmp/mtdblock0/mnt
Post reading:Android Startup Process and the relationship between various images-an article for beginners of Android is recommended! Unfortunately, the author does not know who it is. Thank you very much. Nice to see.