1. Call the main function
In gingerbread/bootable/recovery. C has a main () at the bottom. This is the main port of the recovery application. When recovery is compiled, an executable file named recovery is generated, I put it in the/sbin directory of the recovery/File System in the out/directory. parameters will be input when calling the recovery executable file. These parameters are the parameters of the main function, as shown below:
02 |
main( int
argc, char **argv)
|
05 |
time_t
start = time (NULL); |
10 |
INFO( ">>>>> Enter recovery <<<<<\n" ); |
Argc indicates the number of parameters, and argv indicates each parameter pointer.
Starting recovery...
2. Get commond
2 |
get_args( int
*argc, char ***argv) {
|
3 |
// INFO("Enter get_args\n"); |
4 |
struct
bootloader_message boot; |
5 |
memset (&boot, 0,
sizeof (boot)); |
If the command line has a recovery command, the recovery command of the command line is preferentially executed; otherwise, the command in the MISC partition and the command in the/Cache/recovery/command file are searched down.
3. Obtain the default firmware update path and name.
Int property_get (const char * Key, char * value, const char * default_value );
Including USB flash drive, SD card, and Flash upgrade
4. parsing commands
Int getopt_long (INT, char * const *, const char *, const struct option *, int *);
For example, case's: send_intent = optarg; break;
Optarg is a string after the moderate number of the command.
Register some commands. The register_update_commands function is an upgrade command registered in update-script and recovery-script.
Initialize a variable, int status = install_success; this variable is used to identify whether the upgrade is successful. It serves as a basis for judging when the MISC partition command is cleared.
5. Upgrade, format, and restore
Next, there are three requirements: factorytest; Update and recover; and wipe data.
01 |
if (update_image != NULL) {
|
02 |
status = install_update(update_image); |
04 |
ui_set_background(BACKGROUND_ICON_ERROR); |
05 |
if (status==-1) g_enable_item_move =
false ; |
07 |
} else
if (recover_image != NULL){ |
08 |
status = recover_backup(recover_image); |
10 |
ui_set_background(BACKGROUND_ICON_ERROR); |
11 |
if (status==-1) g_enable_item_move =
false ; |
This part of the code is required for update \ recover. Update follows the install_update branch, and recovery uses recover_backup branch. g_enable_item_move is a variable that indicates whether the items on the recovery upgrade interface can be moved. False indicates that the items cannot be moved.
02 |
if ( wipe_data(wipe_flags) != 0 ) |
04 |
status = INSTALL_ERROR; |
05 |
ui_print( "Data wipe failed.\n" ); |
06 |
// Do not erase the commands in MISC and format them again after restart |
08 |
g_enable_item_move =
false ; |
This part is used to erase the data, that is, the formatting requirement. Based on the erased flags records, the partitions or disks to be formatted are erased separately. If the erasure fails, the g_reset_blmsg variable serves as the discriminant basis during the erasure of boot, false indicates that the file is not wiped out. In this way, the content of the MISC partition is recovey. After the next restart, boot leads to the prompt_and_wait () function in recovery mode. The key part is
This function is used to keep waiting for user input. It is a constant loop. You can select five entries, including restoring factory settings and restarting. maybe_install_firmware_update (send_intent) is an opportunity for the user, write your intent and do something that Google has not done. This is the last function to complete the upgrade,
1 |
// Reset the bootloader message to revert to a normal main system boot. |
4 |
INFO( "ready to clear cmd in misc \n" ); |
5 |
struct
bootloader_message boot; |
6 |
memset (&boot, 0,
sizeof (boot)); |
7 |
set_bootloader_message(&boot); |
Previously, this was a processing of intent. Here g_reset_blmsg is a criterion for clearing boot according to the above mentioned. If you need to clear boot, it indicates that boot will start normally after the next restart and will not enter the recovery mode.
6. After reboot completes the boot and MISC partitions, restart