Before porting a recovery, we need to know why we need to port a recovery?
1. Restore factory settings
2. You need to implement the recovery upgrade function (mainly to help you customize the ROM)
When we transplanted this recovery, we encountered more than N problems, no guidance, no books for reference, and we were accompanied by Du Niang and Google. Some typical problems will be mentioned below.
How to enter recovery?
1. Press the combination button when starting the instance.
2. restart the system to the recovery mode (root permission or related software is required)
3. Reset factory settings in the system (after this function is selected, the system will restart to the recovery mode)
From the above several methods, we can find several problems:
1. How do I enable the combination of buttons to enter the recovery mode?
2. How does one enable system restart to enter the recovery mode?
3. What is the process for entering the recovery mode?
Let's take a look at these questions:
1. How do I enable the combination of buttons to enter the recovery mode?
A: To enable the combination of buttons to enter the recovery mode, we should implement the key detection function in uboot.
But where should we implement this button detection function?
Think about it. We should initialize the hardware in uboot, and add the key detection function to the position of the command line after the detection key is entered. I don't need to talk about where to initialize button operations.
After detecting the combination button, how can I jump to the recovery mode?
The mode from uboot to recovery is the same as that from uboot to kernel. You can configure parameters through bootcmd, load the corresponding recovery. IMG or kernel. IMG, and enter.
2. How does one enable system restart to enter the recovery mode?
A: Before answering this question, we need to know that system restart refers to soft restart, rather than hardware reset or power-down restart. If the software is restarted, most of the internal registers of the CPU will be reset, and the ram data will be lost.
In this case, you need to pass the parameter or flag from the system to uboot to let uboot know which mode you want to enter. You need to set some parameters, it can be saved in this case. For example, save the parameter to NAND,
Or write the parameters to some unchanged registers of the CPU (registers not reset during soft restart ). As long as the soft restart is implemented and the parameter is passed to uboot in the system, it is almost the same. Then enter
It will be OK after recovery. If you use the CPU registers for transfer, please refer to the registers in the reset part of your CPU to see which are not reset by soft restart.
3. What is the process for entering the recovery mode?
A: The overall process is: uboot --> detect the conditions for entering recovery --> pass kernel parameters, load kernel --> load the file system of recovery.
Here it is necessary to talk about this recovery. there are two types of IMG: one is an image that contains the boot information, the kernel, and the recovery micro File System compressed, and the other is an image that only contains the recovery file system uncompressed. If the former is used, you must be able to identify the kernel entry address and the recovery entry address.
Next we will look at a very important situation:
What is the difference between uboot entry into the system and uboot entry into recovery?
First, let's take a look at how uboot is guided into the system:
After completing the uboot initialization, you must specify the kernel entry address and the ramdisk file system entry address. Use bootm to load the kernel and ramdisk to the specified location in Ram, and then load it to the starting address of the specified kernel in Ram, so that the system will enter the kernel. At the same time as entering the kernel, The ramdisk address is also passed in, so that after the kernel completes some operations, it will enter the ramdisk file system, and finally enter the system.
However, the uboot boot into recovery is a bit different:
After uboot initializes some operations, it detects the conditions for entering the recovery (it can be a combination of buttons, or a parameter passed by soft boot to recovery ), then, you need to determine the kernel entry address and the recovery file system entry address. Here, if your rediscovery. IMG is a pure file system, you can access the system in the same way, but the address is slightly different. If recovery. IMG contains information about kernel and boot. Then bootm only needs to load the information of the recovery partition to ram, and then specify the starting address. When preparing to load the kernel, You need to parse the boot information and extract the start address of the kernel and the actual address of the recovery file system. Decompress the corresponding kernel and recovery ramdisk and load it to the specified location of RAM. To boot to the kernel and then to the recovery.
As long as the system soft start enters the recovery mode, restoring the factory settings is almost complete. In the end, the soft start enters recovery and the kernel needs to be modified. In the kernel, configure the passed parameter and obtain this parameter in uboot to determine whether to enter recovery.
To put it bluntly, to implement recovery and factory settings, you only need to modify uboot and kernel.
For more information, see the following articles:
Android restart process
Process Analysis of Android recovery
Dm37xx android2.3.4 adds the recovery upgrade function (1)
Dm37xx android2.3.4 adds the recovery upgrade function (2)
Android recovery-coding guy written at the beginning of 09
[Advanced development tutorial] compile recovery. IMG tutorial