Method for updating firmware and electronic equipment
By switching and restoring different systems within the Android system, the system resolves boot issues caused by firmware aging or corruption, as well as reliability issues during non-AB system upgrades, ensuring stable system operation during the upgrade process.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- FUZHOU ROCKCHIP SEMICON
- Filing Date
- 2025-12-10
- Publication Date
- 2026-04-21
AI Technical Summary
After a successful upgrade, existing Android AB systems may fail to boot if the firmware storage medium is physically aged or damaged. Furthermore, non-AB system upgrades may result in system bricking, affecting system reliability and stability.
By running the primary bootloader firmware and the Android bootloader firmware, and switching to different systems based on the number of system boots and the mode, the system reads the system recovery instructions and switches or restores them, ensuring that the system switches to another system when it cannot boot normally. In recovery mode, different system recovery instructions are used to solve the reliability problem in the non-AB system upgrade process.
It improves the reliability of firmware upgrades, ensures that the system can still start normally after physical aging or damage, solves the problem of system bricking during non-AB system upgrades, and guarantees the stability and reliability of system operation.
Smart Images

Figure CN121900792A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of embedded technology, and more particularly to methods for updating firmware and electronic devices. Background Technology
[0002] Android firmware can be broadly categorized into three types: primary bootloader firmware, Android bootloader firmware, and Android system firmware. The primary bootloader firmware is the first bootloader firmware that boots after power-on. It is not represented in the firmware partition table and boots the Android bootloader firmware. The Android bootloader firmware boots the Android system firmware. The Android system firmware has two boot modes: recovery mode and normal mode. Recovery mode boots the device into the recovery subsystem, while normal mode boots the device into the normal Android system. The Android system firmware comprises all other Android firmware besides the primary bootloader firmware and the Android bootloader firmware. The boot communication partition is a read-write partition that serves as a communication bridge between the primary bootloader firmware, the Android bootloader firmware, and the Android system firmware.
[0003] The Android system is divided into AB system and non-AB system. The AB system was introduced to address the potential system bricking issue during non-AB upgrades (i.e., recovery upgrades) and to solve reliability problems during the upgrade process. Although the AB system can solve reliability issues during the upgrade process, if the firmware of the slot marked as bootable is corrupted during use or physically aged, causing the firmware of the corresponding slot to be damaged, the Android AB system will fail to boot normally. Summary of the Invention
[0004] This invention provides a method and electronic device for updating firmware, which can improve the reliability of firmware upgrades and ensure the stability of system operation.
[0005] In one aspect of the present invention, a method for updating firmware is provided. The method includes: running a primary bootloader firmware; if the system failed to boot normally last time and the number of system boot attempts exceeds a preset maximum number of boot attempts, then switching the system to another system different from it, and then restarting the device; running an Android bootloader firmware; if the system enters recovery mode, then reading a system recovery command from a boot communication partition; and if the system recovery command is a preset system recovery command, then using the current system to restore another system different from it, and then restarting the device.
[0006] In another aspect of the invention, an electronic device is provided. The electronic device includes: a memory configured to store an executable program; and a processor configured to execute the program to perform the described method of updating firmware.
[0007] According to the present invention, if the system failed to boot normally last time and the number of system boot attempts exceeds the preset maximum number of boot attempts, the system is switched to another system different from it, and then the device is restarted. The Android boot firmware is then run again. If the system enters recovery mode, a system recovery command is read from the boot communication partition. If this system recovery command is a preset system recovery command, the current system is used to restore another system different from it, and then the device is restarted. In this way, when the system fails to boot normally, it is switched to another system different from it. After switching, the problem of the current firmware being damaged and unable to boot normally due to physical aging or damage to the firmware storage medium during device use is solved, ensuring that the system can always boot normally. Furthermore, when the system enters recovery mode and needs to execute a system recovery command, using another system different from it to restore the system can solve the problem of system bricking that may occur during non-AB system upgrades, ensuring the reliability of the upgrade process, thereby improving the reliability of firmware upgrades and guaranteeing the stability of system operation. Attached Figure Description
[0008] Figure 1 This is a flowchart illustrating the steps of a firmware update method according to an embodiment of the present invention. Figure 2 This is a flowchart illustrating a method for updating firmware according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0009] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.
[0010] Before detailing the embodiments of this application, some related concepts will first be explained: AB system (A / B partition): is a dual-system partitioning mechanism in Android devices that enables seamless upgrades through two independent system slots (A slot and B slot); Non-AB system (traditional partition): A system with only one system partition; Other firmware image files: Image files of other firmware, which mainly include primary bootloader firmware, Android bootloader firmware, boot firmware, recovery firmware, dynamic partition firmware super, system firmware (system partition firmware), vendor firmware (vendor partition firmware), ODM firmware (original design manufacturer partition firmware), etc. Dual-system partition table description structure: A data structure consisting of a dual-system description structure magic number, a digital digest algorithm type, a dual-system partition description item list digital digest value, a first system partition description item list, and a second system partition description item list; Primary partition table: The partition table used during device startup. Before using this partition table, it is checked for corruption. If the primary partition table is not corrupted, it is used. If the primary partition table is found to be corrupted, the backup partition table is used. Backup partition table: This refers to a backup of the primary partition table, which is used when the primary partition table is damaged. User data partition: refers to the partition where terminal user data is stored, such as the userdata partition or data partition in the Android system.
[0011] In existing technologies, the AB system was introduced to address the potential system bricking issue during non-AB upgrades, aiming to solve reliability problems in the upgrade process. While the AB system can resolve reliability issues during upgrades, if the firmware of the slot marked as successfully booted is corrupted during use or physically aged, causing firmware damage to the corresponding slot, the Android AB system will fail to boot properly.
[0012] To address at least the aforementioned technical problems, this disclosure provides a method for updating firmware. According to embodiments of this disclosure, a first-level bootloader firmware is run. If the system failed to boot normally last time and the number of system boot attempts exceeds a preset maximum number of boot attempts, the system is switched to another system different from it. Then, the device is restarted, and the Android bootloader firmware is run again. If the system enters recovery mode, a system recovery command is read from the boot communication partition. If this system recovery command is a preset system recovery command, the current system is used to restore the other system different from it, and then the device is restarted. In this way, when the system fails to boot normally, it is switched to another system different from it. After the switch, the problem of the current firmware being corrupted and unable to boot normally due to physical aging or damage to the firmware storage medium during device use is solved. The system can always boot normally. In addition, when the system enters recovery mode and needs to execute a system recovery command, using the other system different from it to restore can solve the system bricking problem that may occur during non-AB system upgrades, ensuring the reliability of the upgrade process, thereby improving the reliability of firmware upgrades and ensuring the stability of system operation.
[0013] In some embodiments, the first system and the second system are independent non-AB systems. The non-AB system of Android refers to a non-AB system composed of the first-level bootloader firmware, the Android bootloader firmware, and the Android system firmware that do not support Android AB functionality. The first system and the second system are such non-AB systems.
[0014] In the following, the technical solutions according to this disclosure will be described with reference to specific embodiments and in conjunction with the accompanying drawings.
[0015] Figure 1 This is a flowchart illustrating a method 100 for updating firmware according to an embodiment of the present disclosure. (Refer to...) Figure 1 The method 100 includes the following steps 102 to 106.
[0016] In step 102, the first-level bootloader firmware is run. If the system failed to boot normally last time and the number of system boots exceeds the preset maximum number of boots, the system is switched to another system that is different from it, and then the device is restarted.
[0017] In some embodiments, prior to step 102, the method 100 may further include: constructing a boot communication partition image file; writing a preset second system construction instruction at a first preset position in the boot communication partition image file; during the flashing and burning process of the device firmware, writing a main partition table in a preset main partition table area at the beginning of the main storage medium and a backup partition table in a preset backup partition table area at the end of the main storage medium; and writing the boot communication partition image file into the boot communication partition in the main storage medium, while simultaneously writing other firmware image files into the corresponding firmware partitions.
[0018] In this way, the initial writing of each data item is completed, so that subsequent firmware updates can be implemented.
[0019] In some embodiments, if the number of system boots exceeds the maximum number of boots, the switching between the first system and the second system is performed based on the current boot partition table and the dual-system partition table description structure. In some embodiments, the address spaces of all preset read-only firmware partitions in the current boot partition table and the backup partition table are updated to the address spaces of the firmware partitions corresponding to the other system partition description entries in the dual-system partition table description structure.
[0020] In some embodiments, the following steps are performed: First, read the Android startup completion flag. If the Android startup completion flag is not a preset system normal startup magic number, it is determined that the system did not start normally last time. Second, read the system startup count. If the system startup count is greater than a preset maximum startup count, the main partition table is read from the preset main partition table area as the current startup partition table. Third, determine whether the system is currently a first system or a second system based on the current startup partition table and the dual-system partition table description structure. If the system is currently the first system, switch the first system to the second system. If the system is currently the second system, switch the second system to the first system. Fourth, clear the recovery completion flag at the first preset position, the system recovery command at the second preset position, and the Android startup completion flag at the third preset position in the boot communication partition. Fifth, update the system startup count at the fourth preset position in the boot communication partition to the initial value. Finally, restart the device.
[0021] In this way, if the system failed to start normally last time and the number of system startups exceeds the preset maximum number of startups, it is very likely that the current firmware is damaged due to physical aging or damage to the firmware storage medium during device use, thus preventing normal startup. At this time, if the system is currently the first system, it will switch to the second system, and if the system is currently the second system, it will switch to the first system. This achieves switching between the first and second systems to ensure that the system can start normally.
[0022] In some implementations, a partition description item is randomly selected from the list of first system partition description items in the dual-system partition table description structure; based on the partition name of the selected partition description item, a partition with the same partition name is searched in the current boot partition table, and it is determined whether the partition start address and partition size of the selected partition description item and the partition with the same partition name are the same; if they are the same, the system is determined to be the first system; and if they are not the same, the system is determined to be the second system.
[0023] In this way, by comparing the dual-system partition table description structure with the currently booted partition table, it is more accurate and faster to identify whether the system is currently the first system or the second system.
[0024] In some embodiments, the address spaces of all preset read-only firmware partitions in the current boot partition table are updated to the address spaces of the corresponding firmware partitions in the second system partition description item list of the dual-system partition table description structure to obtain an updated current boot partition table; the updated current boot partition table is written to a preset main partition table area at the beginning of the main storage medium to complete the update of the main partition table; the backup partition table is read from the preset backup partition table area; the address spaces of all preset read-only firmware partitions in the backup partition table are updated to the address spaces of the corresponding firmware partitions in the second system partition description item list of the dual-system partition table description structure to obtain an updated backup partition table; and the updated backup partition table is written to a preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
[0025] In some embodiments, the address spaces of all preset read-only firmware partitions in the current boot partition table are updated to the address spaces of the firmware partitions corresponding to the firmware partitions in the first system partition description item list of the dual-system partition table description structure, resulting in an updated current boot partition table; the updated current boot partition table is written to a preset main partition table area at the beginning of the main storage medium to complete the update of the main partition table; the backup partition table is read from the preset backup partition table area; the address spaces of all preset read-only firmware partitions in the backup partition table are updated to the address spaces of the firmware partitions corresponding to the firmware partitions in the first system partition description item list of the dual-system partition table description structure, resulting in an updated backup partition table; and the updated backup partition table is written to a preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
[0026] In this way, when switching from the first system to the second system, and vice versa, both the primary partition table and the backup partition table are updated, achieving effective system switching and ensuring that the system can start normally after the switch.
[0027] In some embodiments, the method 100 may further include: if the Android startup completion marker is a preset system normal startup magic number, then determining the last normal startup of the system; clearing the Android startup completion marker at a third preset position in the boot communication partition, and updating the system startup count at a fourth preset position in the boot communication partition to the initial value; and normal startup, booting the Android startup bootloader firmware.
[0028] In this way, when Android completes startup and is marked with the preset system normal startup magic number, it means that the system is normal, and it can start up according to the normal process.
[0029] In some embodiments, the method 100 may further include: if the number of system startups is not greater than a preset maximum number of startups, then incrementing the number of system startups by one and writing the incremented number of system startups into a fourth preset position in the boot communication partition; and then starting normally to boot the Android bootloader firmware.
[0030] In this way, if the number of system startups has not exceeded the preset maximum number of startups, it means that the inability to start normally is probably not due to firmware corruption. In this case, you can try to start the system again.
[0031] In step 104, the Android bootloader firmware is run. If the system enters recovery mode, the system recovery command is read from the boot communication partition.
[0032] In step 106, if the system recovery command is a preset system recovery command, then the current system is used to restore another system that is different from it, and then the device is restarted.
[0033] In some embodiments, based on the current system partition description item list of the dual-system partition table description structure, the firmware data in the firmware partition corresponding to all partition description items in the current system partition description item list is copied to the address space corresponding to the corresponding partition description item in the other system partition description item list, thereby completing the recovery of the other system.
[0034] In some embodiments, the system boot count at the fourth preset position in the boot communication partition is updated to an initial value; the dual-system partition table description structure is read from the seventh preset position in the boot communication partition; if the magic number of the dual-system partition table description structure is not a preset magic number, an error is prompted and the system recovery command is exited; if the magic number of the dual-system partition table description structure is a preset magic number, the digital digest values of the first system partition description item list and the second system partition description item list of the dual-system partition table description structure are calculated according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual-system partition table description structure; the calculated digital digest value is checked to see if it is the same as the digital digest value of the dual-system partition description item list of the dual-system partition table description structure; if they are different, an error is prompted and the system recovery command is exited; if they are the same, the primary partition is read from the preset primary partition table area. The system is defined as either the first system or the second system based on the current boot partition table and the dual-system partition table description structure. If the system is currently the first system, the firmware data in the firmware partitions corresponding to all partition description entries in the first system partition description list of the dual-system partition table description structure is copied to the address space corresponding to the corresponding partition description entry in the second system partition description list, thus completing the second system recovery. If the system is currently the second system, the firmware data in the firmware partitions corresponding to all partition description entries in the second system partition description list of the dual-system partition table description structure is copied to the address space corresponding to the corresponding partition description entry in the first system partition description list, thus completing the first system recovery. A preset recovery completion magic number is written to the first preset position in the boot communication partition. The system recovery command in the second preset position in the boot communication partition is cleared. Finally, the device is restarted.
[0035] In this way, before restoring the system, the validity of the dual-system partition table description structure is checked. After the validity is checked, the system restoration continues, ensuring the security of the restoration process. Then, the system is identified. If the current system is the first system, the first system is used to restore the second system, and if the current system is the second system, the second system is used to restore the first system. Even if the system becomes bricked during the upgrade process, the bricked system can be restored smoothly, thus ensuring the reliability of the upgrade process.
[0036] In some embodiments, the Android bootloader firmware is run, and a second system build instruction is read from a fifth preset location in the boot communication partition; if the second system build instruction is a preset second system build instruction, the system is booted into recovery mode, and a system recovery instruction is read from a second preset location in the boot communication partition; if the second system build instruction is not a preset second system build instruction, a factory erase instruction is read from a sixth preset location in the boot communication partition; if the factory erase instruction is a preset factory erase instruction, the system is booted into recovery mode, and a system recovery instruction is read from a second preset location in the boot communication partition; if the factory erase instruction is not a preset factory erase instruction, a system recovery instruction is read from a second preset location in the boot communication partition; if the system recovery instruction is a preset system recovery instruction, the system is booted into recovery mode, and a system recovery instruction is read from a second preset location in the boot communication partition; and if the system recovery instruction is not a preset system recovery instruction, the system is booted according to a preset process.
[0037] In this way, when running the Android bootloader firmware, if there are preset second system build instructions, preset factory erase instructions, or preset system recovery instructions in the boot communication partition, the system will be booted into recovery mode, which improves the robustness and security of the system.
[0038] In some embodiments, it is determined whether the preset process is a preset recovery mode; if yes, the system is guided into recovery mode; and if no, the system is guided into a normal Android system. In some embodiments, if the Android system boots up completely, a preset system normal boot magic number is written to the third preset position in the boot communication partition; a recovery completion marker is read from the first preset position in the boot communication partition; it is checked whether the recovery completion marker is a preset recovery completion magic number; if no, recovery selection information is output, which is to remind the user that the backup system is abnormal and whether to choose to restore on the next boot; if the user chooses to restore on the next boot, a preset system recovery command is written to the second preset position in the boot communication partition; and if the system performs its own OTA upgrade and the upgrade is successful, the upgrade client obtains a complete firmware upgrade package corresponding to the current firmware version from the upgrade server and saves the complete firmware upgrade package to a preset path in the preset unencrypted data partition as a reserved upgrade package.
[0039] In this way, if the system performs its own OTA upgrade and the upgrade is successful, the upgrade client obtains a complete firmware upgrade package corresponding to the current firmware version from the upgrade server. The complete firmware upgrade package is saved to a preset path in the preset unencrypted data partition as a reserved upgrade package. This is to ensure the compatibility of the user data partition to the greatest extent possible in case of compatibility issues with the user data partition. In addition, when the system performs its own OTA upgrade, it always upgrades the firmware of the current system itself (i.e., not an A / B upgrade). When upgrading the first system firmware, it always upgrades the corresponding first system firmware, and when upgrading the second system firmware, it always upgrades the corresponding second system firmware. This ensures that the firmware of another system will not be damaged when the current system performs its own OTA upgrade. Therefore, after the switch between the first system and the second system is completed, the system can always start normally.
[0040] In some embodiments, before reading the system recovery instruction from the boot communication partition, the method further includes: reading a second system build instruction from a fifth preset location in the boot communication partition; if the second system build instruction is a preset second system build instruction, then building a second system according to the second system build instruction; if the second system build instruction is not a preset second system build instruction, then reading a factory erase instruction from a sixth preset location in the boot communication partition; if the factory erase instruction is a preset factory erase instruction, then performing a factory erase operation according to the factory erase instruction; and if the factory erase instruction is not a preset factory erase instruction, then performing the step of reading the system recovery instruction from the boot communication partition.
[0041] In some embodiments, the system boot count in the fourth preset location of the boot communication partition is updated to the initial value; all preset readable and writable partitions other than the boot communication partition are erased and reformatted; the factory erase command in the sixth preset location of the boot communication partition is cleared; and the device is restarted.
[0042] In this way, the system boot count in the fourth preset position of the boot communication partition is updated to the initial value, all preset readable and writable partitions except the boot communication partition are erased and reformatted, and the factory erase command in the sixth preset position of the boot communication partition is cleared, thereby achieving a reliable factory erase operation.
[0043] In some embodiments, the method 100 may further include: if the system recovery instruction is not a preset system recovery instruction, checking whether the Android recovery instruction area in the boot communication partition contains a prompt to erase data instruction; if not, performing the corresponding recovery operation according to a preset process; if it contains, updating the system boot count at the fourth preset position in the boot communication partition to the initial value; reading the recovery completion marker from the first preset position in the boot communication partition; if the recovery completion marker is not a preset recovery completion magic number, restoring the damaged system according to the system; checking whether a reserved upgrade package exists in the preset path of the preset unencrypted data partition; if it exists, using the reserved upgrade package to perform a firmware upgrade on the system; after the upgrade is completed, deleting the reserved upgrade package and clearing... If the Android recovery command area in the boot communication partition is not found, the system is reset. If the recovery is not found, the user data partition is erased and formatted, the Android recovery command area in the boot communication partition is cleared, and the device is reset. If the recovery completion is marked with a preset recovery completion magic number, a reserved upgrade package is checked for existence in a preset path of a preset unencrypted data partition. If it exists, the system is upgraded using the reserved upgrade package. After the upgrade is completed, the reserved upgrade package is deleted, the Android recovery command area in the boot communication partition is cleared, and the device is reset. If the Android recovery command area in the boot communication partition is not found, the user data partition is erased and formatted, the Android recovery command area in the boot communication partition is cleared, and the device is reset.
[0044] In this way, when the first system and the second system switch between each other, if there is a compatibility issue with the user data partition, the Android system will write a prompt to erase data in the Android recovery command area of the boot communication partition and boot the system into recovery mode. Therefore, when checking if the Android recovery command area in the boot communication partition contains a prompt to erase data, it will check if there is a reserved upgrade package in the preset path of the preset unencrypted data partition. If there is, the reserved upgrade package will be used to upgrade the firmware of the current system. By upgrading the current system to the most recent firmware update, the potential compatibility issues of the user data partition can be resolved, thereby maximizing the compatibility of the user data partition.
[0045] The following will describe, through examples, the application scenarios of the firmware update method and device according to embodiments of the present invention.
[0046] Figure 2 This is a flowchart illustrating a method for updating firmware according to an embodiment of the present invention. Figure 2 As shown, the method includes steps 201 to 218.
[0047] In step 201, a boot communication partition image file is constructed; a preset second system construction instruction is written to the first preset position in the boot communication partition image file; during the device firmware flashing process, a main partition table is written to the preset main partition table area at the beginning of the main storage medium, and a backup partition table is written to the preset backup partition table area at the end of the main storage medium; the boot communication partition image file is written to the boot communication partition in the main storage medium, and other firmware image files are written to the corresponding firmware partitions.
[0048] In some embodiments, a binary image file with a size equal to the boot communication partition and completely empty content is constructed as the boot communication partition image file. The user data partition (e.g., data) is the last partition in the partition table (including the primary partition table and the backup partition table).
[0049] In step 202, the first-level bootloader firmware is run, and the Android boot completion marker is read from the third preset location in the boot communication partition.
[0050] In step 203, if the Android startup completion marker is the preset system normal startup magic number, then the last normal startup of the system is determined; the Android startup completion marker in the third preset position of the boot communication partition is cleared, and the system startup count in the fourth preset position of the boot communication partition is updated to the initial value; normal startup, booting the Android startup boot program firmware.
[0051] In some embodiments, the initial value is 0.
[0052] In step 204, if the Android startup completion marker is not the preset system normal startup magic number, it is determined that the system did not start normally last time; the system startup count is read from the fourth preset position in the boot communication partition.
[0053] In step 205, if the number of system boots is greater than the preset maximum number of boots, the main partition table is read from the preset main partition table area as the current boot partition table; the current system is determined to be the first system or the second system according to the description structure of the current boot partition table and the dual system partition table; if the current system is the first system, the first system is switched to the second system; if the current system is the second system, the second system is switched to the first system; the recovery completion mark in the first preset position, the system recovery command in the second preset position, and the Android boot completion mark in the third preset position in the boot communication partition are cleared; the number of system boots in the fourth preset position in the boot communication partition is updated to the initial value; the device is restarted, specifically including the following (1) to (8).
[0054] (1) Read the dual-system partition table description structure from the seventh preset position in the boot communication partition, check whether the magic number of the dual-system partition table description structure is the preset magic number of the dual-system partition table description structure. If it is, execute (2); otherwise, the dual-system partition table description structure is invalid, start normally, and boot the Android boot boot program firmware.
[0055] (2) Calculate the digital digest values of the first system partition description item list and the second system partition description item list of the dual system partition table description structure according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual system partition table description structure. Check whether the calculated digital digest value is the same as the digital digest value of the dual system partition description item list of the dual system partition table description structure. If they are the same, execute the following step (3). Otherwise, start normally and boot the Android bootloader firmware.
[0056] (3) Read the primary partition table from the preset primary partition table area as the current boot partition table.
[0057] (4) Randomly select a partition description item from the list of the first system partition description items in the dual system partition table description structure; search for a partition with the same partition name in the current boot partition table according to the partition name of the selected partition description item, and determine whether the partition start address and partition size of the selected partition description item and the partition with the same partition name are the same. If they are the same, the system is currently the first system. If they are not the same, the system is currently the second system.
[0058] (5) If the system is currently the first system, then switch the first system to the second system, specifically including (5-1) to (5-5).
[0059] (5-1) Update the address space of all preset read-only firmware partitions in the current boot partition table to the address space of the firmware partition corresponding to the second system partition description item list of the dual system partition table description structure, and obtain the updated current boot partition table.
[0060] (5-2) Write the updated current boot partition table to the preset main partition table area in the header of the main storage medium to complete the update of the main partition table.
[0061] (5-3) Read the backup partition table from the preset backup partition table area.
[0062] (5-4) Update the address space of all preset read-only firmware partitions in the backup partition table to the address space of the firmware partition corresponding to the second system partition description item list of the dual system partition table description structure to obtain the updated backup partition table.
[0063] (5-5) Write the updated backup partition table to the preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
[0064] (6) If the system is currently the second system, then switch the second system to the first system, specifically including (6-1) to (6-5) below.
[0065] (6-1) Update the address space of all preset read-only firmware partitions in the current boot partition table to the address space of the firmware partition corresponding to the first system partition description item in the dual system partition table description structure, and obtain the updated current boot partition table.
[0066] (6-2) Write the updated current boot partition table to the preset main partition table area in the header of the main storage medium to complete the update of the main partition table.
[0067] (6-3) Read the backup partition table from the preset backup partition table area.
[0068] (6-4) Update the address space of all preset read-only firmware partitions in the backup partition table to the address space of the firmware partition corresponding to the first system partition description item in the dual system partition table description structure to obtain the updated backup partition table.
[0069] (6-5) Write the updated backup partition table to the preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
[0070] (7) Clear the recovery completion mark in the first preset position, the system recovery command in the second preset position, and the Android startup completion mark in the third preset position in the boot communication partition; update the system startup count in the fourth preset position in the boot communication partition to the initial value.
[0071] (8) Restart the device.
[0072] In step 206, if the number of system startups is not greater than the preset maximum number of startups, the number of system startups is incremented by one, and the incremented number of system startups is written to the fourth preset position in the boot communication partition; then, the system starts normally and boots the Android bootloader firmware.
[0073] In step 207, the Android bootloader firmware is run. If there are preset second system build instructions, preset factory erase instructions, or preset system restore instructions in the boot communication partition, then step 208 is executed; otherwise, the system is booted according to the preset process.
[0074] In some embodiments, the Android bootloader firmware is run, and a second system build instruction is read from the fifth preset location in the boot communication partition; if the second system build instruction is a preset second system build instruction, then step 208 is executed; if the second system build instruction is not a preset second system build instruction, then a factory erase instruction is read from the sixth preset location in the boot communication partition; if the factory erase instruction is a preset factory erase instruction, then step 208 is executed; if the factory erase instruction is not a preset factory erase instruction, then a system recovery instruction is read from the second preset location in the boot communication partition; if the system recovery instruction is a preset system recovery instruction, then step 208 is executed; if the system recovery instruction is not a preset system recovery instruction, then the system is booted according to a preset process.
[0075] In some embodiments, booting the system according to a preset process includes: determining whether the preset process is a preset recovery mode; if so, booting the system into recovery mode; if not, booting the system into the normal Android system.
[0076] In some embodiments, the system boots into a normal Android system, specifically as follows: if the Android system boots up successfully, a preset system normal boot magic number is written to the third preset location in the boot communication partition; a recovery completion marker is read from the first preset location in the boot communication partition; it is checked whether the recovery completion marker is the preset recovery completion magic number; if not, recovery selection information is output, which reminds the user that the backup system is abnormal and asks whether to choose to restore on the next boot; if the user chooses to restore on the next boot, a preset system recovery command is written to the second preset location in the boot communication partition; if the system (first system or second system) performs its own OTA upgrade and the upgrade is successful, the upgrade client obtains a complete firmware upgrade package corresponding to the current firmware version from the upgrade server and saves the complete firmware upgrade package to a preset path in the preset unencrypted data partition (such as cache) as a reserved upgrade package.
[0077] In step 208, the system is booted into recovery mode. In recovery mode, the second system build instructions are read from the fifth preset location in the boot communication partition.
[0078] In step 209, if the second system construction instruction is a preset second system construction instruction, then the second system is constructed according to the second system construction instruction, specifically including the following (1) to (12).
[0079] (1) Update the number of system startups in the fourth preset position of the boot communication partition to the initial value.
[0080] (2) Clear the dual-system partition table description structure in the seventh preset position of the boot communication partition.
[0081] (3) Construct a dual-system partition table description structure consisting of a dual-system description structure magic number, a digital digest algorithm type, a dual-system partition description item list digital digest value, a first system partition description item list, and a second system partition description item list. Set the dual-system description structure magic number of the dual-system partition table description structure to a preset dual-system description structure magic number, and set the digital digest algorithm type of the dual-system partition table description structure to a preset digital digest algorithm.
[0082] In some embodiments, the first system partition description item list and the second system partition description item list are both lists composed of partition description items, each of which consists of a partition name, a partition start address, and a partition size.
[0083] (4) Read the main partition table from the preset main partition table area as the current boot partition table, construct the first system partition description item list based on all read-only firmware partitions in the current boot partition table, and save it to the first system partition description item list of the dual system partition table description structure, specifically including (4-1) to (4-2) below.
[0084] (4-1) Read the primary partition table from the preset primary partition table area in the header of the primary storage medium as the current boot partition table.
[0085] (4-2) Traverse the current boot partition table. For each partition, check if the partition name is a preset read-only firmware partition. If it is, store the partition name, partition start address and partition size of the read-only firmware partition in the corresponding partition description item in the first system partition description item list of the dual system partition table description structure in order. Otherwise, continue to traverse the next partition until the current boot partition table is traversed.
[0086] (5) Before the last partition of the current boot partition table (i.e., the user data partition), construct the second system partition description item list for all read-only firmware partitions based on the first system partition description item list, and save it to the second system partition description item list of the dual system partition table description structure; the first system and the second system share the boot communication partition and all readable and writable partitions (such as the metadata partition, cache partition, user data partition, etc.), specifically including the following (5-1) to (5-3).
[0087] (5-1) Obtain the last partition of the current boot partition table, and obtain the starting address and size of the partition as the initial starting address and initial size of the user data partition.
[0088] (5-2) Traverse the first system partition description item list of the dual system partition table description structure. For each partition description item traversed, store the partition name and partition size of the description item in order into the corresponding partition description item in the second system partition description item list of the dual system partition table description structure.
[0089] (5-3) Traverse the list of second system partition description entries in the dual system partition table description structure. If the current one is the first partition description entry, set the partition start address of the partition description entry to the initial start address of the user data partition. Otherwise, set the partition start address of the partition description entry to the sum of the partition start address and partition size of the previous partition description entry.
[0090] (6) Copy the firmware data in the firmware partition corresponding to all partition description items in the first system partition description item list to the address space corresponding to the partition description item in the second system partition description item list according to the first system partition description item list, and complete the second system construction.
[0091] In some embodiments, the first system partition description item list of the dual system partition table description structure is traversed. For each partition description item traversed, the firmware data in the address space formed by the partition start address and partition size of the partition description item is copied to the address space corresponding to the partition start address and partition size of the partition description item in the second system partition description item list of the dual system partition table description structure whose partition name is the same as the corresponding partition name.
[0092] (7) Calculate the final starting address and final partition size of the user data partition according to the second system partition description item list, then update the current boot partition table, and write the updated current boot partition table to the preset main partition table area in the header of the main storage medium, thereby completing the update of the main partition table, specifically including (7-1) to (7-4) below.
[0093] (7-1) Take the sum of the partition start address and partition size of the partition description item corresponding to the last firmware partition in the second system partition description item list as the final start address of the user data partition.
[0094] (7-2) Take “the initial starting address of the user data partition + the initial partition size of the user data partition - the final starting address of the user data partition” as the final partition size of the user data partition.
[0095] (7-3) Update the starting address and size of the last partition (i.e., the user data partition) in the current boot partition table to be the final starting address and final size of the user data partition, respectively.
[0096] (7-4) Write the updated current boot partition table to the preset primary partition table area in the header of the primary storage medium. (8) Read the backup partition table from the preset backup partition table area, update the backup partition table according to the final starting address and final partition size of the user data partition, and write the updated backup partition table to the preset backup partition table area at the end of the main storage medium, thereby completing the update of the backup partition table. Specifically, (8-1) is as follows (8-3).
[0097] (8-1) Read the backup partition table from the preset backup partition table area at the end of the main storage medium.
[0098] (8-2) Update the last partition (i.e., the user data partition) in the backup partition table to set the partition start address and partition size to the final start address and final size of the user data partition, respectively.
[0099] (8-3) Write the updated backup partition table to the preset backup partition table area at the end of the main storage medium.
[0100] (9) Calculate the digital digest values of the first system partition description item list and the second system partition description item list of the dual system partition table description structure according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual system partition table description structure, and save the calculated digital digest values to the digital digest values of the dual system partition description item list of the dual system partition table description structure.
[0101] (10) Write the dual-system partition table description structure in the seventh preset position of the boot communication partition.
[0102] (11) Write the preset recovery completion magic number in the first preset position of the boot communication partition, and clear the system recovery command in the second preset position of the boot communication partition.
[0103] (12) Write the preset factory erase command in the sixth preset position of the boot communication partition, clear the second system build command in the fifth preset position of the boot communication partition, and then restart the device.
[0104] In step 210, if the second system build instruction is not the preset second system build instruction, then the factory erase instruction is read from the sixth preset position in the boot communication partition.
[0105] In step 211, if the factory erase command is a preset factory erase command, then the factory erase operation is performed according to the factory erase command.
[0106] In some embodiments, the system boot count in the fourth preset location of the boot communication partition is updated to the initial value; all preset readable and writable partitions (including user data partitions) except the boot communication partition are erased and reformatted; the factory erase command in the sixth preset location of the boot communication partition is cleared; and the device is restarted.
[0107] In step 212, if the factory erase command is not the preset factory erase command, the system recovery command is read from the second preset location in the boot communication partition.
[0108] In step 213, if the system recovery command is a preset system recovery command, then after using the system recovery command to restore another system that is different from it, the device is restarted, specifically including the following (1) to (11).
[0109] (1) Update the number of system startups in the fourth preset position of the boot communication partition to the initial value.
[0110] (2) Read the dual-system partition table description structure from the seventh preset position in the boot communication partition.
[0111] (3) If the magic number of the dual system description structure of the dual system partition table description structure is not the preset magic number of the dual system description structure, an error message will be displayed and the system recovery command will be exited.
[0112] (4) If the magic number of the dual system partition table description structure is the preset magic number of the dual system partition table description structure, then calculate the digital digest value of the first system partition description item list and the second system partition description item list of the dual system partition table description structure according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual system partition table description structure.
[0113] (5) Check whether the calculated digital digest value is the same as the digital digest value of the dual system partition description item list of the dual system partition table description structure. If they are different, an error message will be displayed and the system recovery command will be exited. If they are the same, the primary partition table will be read from the preset primary partition table area as the current boot partition table.
[0114] (6) Determine whether the system is currently the first system or the second system based on the description structure of the current boot partition table and the dual system partition table.
[0115] In some embodiments, a partition description item is randomly selected from the list of first system partition description items in the dual-system partition table description structure. Based on the partition name of the selected partition description item, a partition with the same partition name is found in the current boot partition table. It is determined whether the starting address and partition size of the selected partition description item and the partition with the same partition name are the same. If they are the same, the system is determined to be the first system; otherwise, the system is determined to be the second system.
[0116] (7) If the system is currently the first system, then copy the firmware data in the firmware partition corresponding to all partition description entries in the first system partition description entry list of the dual system partition table description structure to the address space corresponding to the partition description entry in the second system partition description entry list, and complete the second system recovery.
[0117] (8) If the system is currently the second system, then copy the firmware data in the firmware partition corresponding to all partition description entries in the second system partition description entry list of the dual system partition table description structure to the address space corresponding to the partition description entry in the first system partition description entry list, and complete the first system recovery.
[0118] (9) Write the preset recovery completion magic number in the first preset position in the boot communication partition.
[0119] (10) Clear the system recovery command in the second preset location in the boot communication partition.
[0120] (11) Restart the device.
[0121] In step 214, if the system recovery command is not the preset system recovery command, check whether the Android recovery command area in the boot communication partition contains a prompt to wipe data command (such as --prompt_and_wipe_data); if it does not contain it, perform the corresponding recovery operation according to the preset process; if it does contain it, proceed to step 215.
[0122] In step 215, the number of system boots in the fourth preset location of the boot communication partition is updated to the initial value.
[0123] In step 216, the recovery completion marker is read from the first preset location in the boot communication partition.
[0124] In step 217, if the recovery completion marker is not the preset recovery completion magic number, then the damaged system is restored according to the system; check if there is a reserved upgrade package in the preset path of the preset unencrypted data partition; if there is, use the reserved upgrade package to upgrade the system firmware. After the upgrade is completed, delete the reserved upgrade package and clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device; if there is no such package, erase and format the user data partition, clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device.
[0125] In some embodiments, system recovery of a damaged system includes the following (1) to (5).
[0126] (1) Check the validity of the dual-system partition table description structure. If it is valid, execute (2). Otherwise, prompt an error and exit the system recovery command, specifically including (1-1) to (1-2).
[0127] (1-1) Read the dual-system partition table description structure from the seventh preset position in the boot communication partition, check whether the magic number of the dual-system partition table description structure is the preset magic number of the dual-system description structure. If it is, execute the following steps (1-2). Otherwise, prompt an error and exit the system recovery command.
[0128] (1-2) Calculate the digital digest values of the first system partition description item list and the second system partition description item list of the dual system partition table description structure according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual system partition table description structure. Check whether the calculated digital digest value is the same as the digital digest value of the dual system partition description item list of the dual system partition table description structure. If it is, execute (2). Otherwise, prompt an error and exit the system recovery command.
[0129] (2) Read the primary partition table from the preset primary partition table area as the current boot partition table.
[0130] (3) Determine whether the system is currently the first system or the second system based on the description structure of the current boot partition table and the dual system partition table.
[0131] In some embodiments, a partition description item is randomly selected from the list of first system partition description items in the dual-system partition table description structure. Based on the partition name of the selected partition description item, a partition with the same partition name is found in the current boot partition table. It is determined whether the starting address and partition size of the selected partition description item and the partition with the same partition name are the same. If they are the same, it is determined that the current system is the first system; otherwise, it is determined that the current system is the second system.
[0132] (4) If the system is currently the first system, the second system is restored through the first system. According to the first system partition description item list of the dual system partition table description structure, the firmware data in the firmware partition corresponding to all partition description items in the first system partition description item list is copied to the address space corresponding to the partition description item in the second system partition description item list, and the second system is restored. If the system is currently the second system, the first system is restored through the second system. According to the second system partition description item list of the dual system partition table description structure, the firmware data in the firmware partition corresponding to all partition description items in the second system partition description item list is copied to the address space corresponding to the corresponding partition description item in the first system partition description item list, thus completing the first system restoration.
[0133] (5) Write the preset recovery completion magic number in the first preset position of the boot communication partition, and clear the system recovery command in the second preset position of the boot communication partition.
[0134] In step 218, if the recovery completion marker is a preset recovery completion magic number, then check if a reserved upgrade package exists in the preset path of the preset unencrypted data partition (such as cache). If it exists, use the reserved upgrade package to upgrade the system firmware. After the upgrade is completed, delete the reserved upgrade package and clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device. If it does not exist, erase and format the user data partition, clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device.
[0135] According to another aspect of the invention, Figure 3 This is a schematic diagram illustrating an electronic device 300 according to an embodiment of the present invention. (Refer to...) Figure 3 The electronic device 300 includes a memory 302 and a processor 304. The memory 302 is configured to store a computer program that can run on the processor 304. When the processor 304 executes the computer program, it implements the various steps of the firmware update method as described above.
[0136] In summary, the firmware upgrade method and electronic device provided by this invention, when running a primary bootloader firmware, if the system failed to boot normally last time and the number of system boot attempts exceeds the preset maximum number of boot attempts, switches the system to another system different from it, then restarts the device, runs the Android bootloader firmware, and if the system enters recovery mode, reads the system recovery command from the boot communication partition. If the system recovery command is a preset system recovery command, the current system is used to restore the other system different from it, and then the device is restarted. In this way, when the system fails to boot normally, it switches to another system different from it. After switching, the problem of the current firmware being damaged and unable to boot normally due to physical aging or damage to the firmware storage medium during device use is solved, ensuring that the system can always boot normally. Furthermore, when the system enters recovery mode and needs to execute the system recovery command, using the other system different from it to restore it can solve the system bricking problem that may occur during non-AB system upgrades, ensuring the reliability of the upgrade process, thereby improving the reliability of firmware upgrades and ensuring the stability of system operation. Additionally, when switching between the first and second systems, if there are compatibility issues with the user data partition, the Android system will write a prompt to erase data in the Android recovery command area of the boot communication partition and boot the system into recovery mode. Therefore, when checking if the Android recovery command area in the boot communication partition contains a prompt to erase data, it will check if there is a reserved upgrade package in the preset path of the preset unencrypted data partition. If so, the reserved upgrade package will be used to upgrade the firmware of the current system. By upgrading the current system to the most recent firmware update, the potential compatibility issues of the user data partition can be resolved, thereby maximizing the compatibility of the user data partition.
[0137] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.
Claims
1. A method for updating firmware, characterized in that, include: If the system failed to boot normally last time and the number of system boot attempts exceeds the preset maximum number of boot attempts, the system will be switched to another system that is different from it, and then the device will be restarted. Running the Android bootloader firmware, if the system enters recovery mode, it reads system recovery instructions from the boot communication partition; and If the system recovery command is a preset system recovery command, then the current system is used to restore another system that is different from it, and then the device is restarted.
2. The method according to claim 1, characterized in that, Switching the system to another system that is different from it includes: If the number of system startups exceeds the maximum number of startups, the switching between the first system and the second system is performed based on the current startup partition table and the dual-system partition table description structure.
3. The method according to claim 1, characterized in that, Switching the system to another system that is different from it includes: Update the address space of all preset read-only firmware partitions in the current boot partition table and backup partition table to the address space of the firmware partition corresponding to the system partition description entry in the other system partition description structure of the dual-system partition table description structure.
4. The method according to claim 1, characterized in that, Using the current system to restore another system that is different from it includes: Based on the current system partition description item list of the dual-system partition table description structure, the firmware data in the firmware partition corresponding to all partition description items in the current system partition description item list is copied to the address space corresponding to the corresponding partition description item in the other system partition description item list, thus completing the recovery of the other system.
5. The method according to claim 1, characterized in that, Before running the Level 1 bootloader firmware, it also includes: Build a boot communication partition image file; A preset second system build instruction is written at a first preset location in the boot communication partition image file; During the firmware flashing process, the primary partition table is written to the preset primary partition table area at the beginning of the primary storage medium, and the backup partition table is written to the preset backup partition table area at the end of the primary storage medium; and The boot communication partition image file is written to the boot communication partition in the main storage medium, and other firmware image files are written to the corresponding firmware partitions.
6. The method according to claim 5, characterized in that, Running the primary bootloader firmware, if the system failed to boot normally last time and the number of system boot attempts exceeds the preset maximum number of boot attempts, then switching the system to another different system and then restarting the device includes: Read the Android startup completion flag; If the Android startup completion flag is not the preset system normal startup magic number, then it is determined that the system did not start normally last time; Read the system startup count; If the number of system startups exceeds the preset maximum number of startups, then the primary partition table is read from the preset primary partition table area as the current startup partition table; Based on the description structure of the current boot partition table and the dual-system partition table, it is determined whether the system is currently the first system or the second system. If the system is currently the first system, then the first system will be switched to the second system; If the system is currently the second system, then the second system will be switched to the first system; Clear the recovery completion marker in the first preset location, the system recovery command in the second preset location, and the Android boot completion marker in the third preset location in the boot communication partition; Update the system boot count in the fourth preset position of the boot communication partition to the initial value; and Restart the device.
7. The method according to claim 6, characterized in that, Determining whether the system is currently the first system or the second system based on the current boot partition table and dual-system partition table description structure includes: Randomly select a partition description item from the list of first system partition description items in the dual-system partition table description structure; Based on the partition name of the selected partition description entry, search for a partition with the same partition name in the current boot partition table, and determine whether the selected partition description entry and the partition with the same partition name have the same partition start address and partition size; If all are the same, then the system is determined to be the first system; and If they are not all the same, then the system is determined to be the second system.
8. The method according to claim 6, characterized in that, Switching the first system to the second system includes: The address spaces of all preset read-only firmware partitions in the current boot partition table are updated to the address spaces of the firmware partitions corresponding to the second system partition description entries in the dual system partition table description structure, thus obtaining the updated current boot partition table. The updated current boot partition table is written into the preset main partition table area in the header of the main storage medium to complete the update of the main partition table; Read the backup partition table from the preset backup partition table area; The address spaces of all preset read-only firmware partitions in the backup partition table are updated to the address spaces of the firmware partitions corresponding to the firmware partitions in the second system partition description item list of the dual-system partition table description structure, resulting in an updated backup partition table; and The updated backup partition table is written to the preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
9. The method according to claim 6, characterized in that, Switching the second system to the first system includes: The address spaces of all preset read-only firmware partitions in the current boot partition table are updated to the address spaces of the firmware partitions corresponding to the first system partition description entries in the dual system partition table description structure, thus obtaining the updated current boot partition table. The updated current boot partition table is written into the preset main partition table area in the header of the main storage medium to complete the update of the main partition table; Read the backup partition table from the preset backup partition table area; The address spaces of all preset read-only firmware partitions in the backup partition table are updated to the address spaces of the firmware partitions corresponding to the first system partition description entries in the dual-system partition table description structure, resulting in an updated backup partition table; and The updated backup partition table is written to the preset backup partition table area at the end of the main storage medium to complete the update of the backup partition table.
10. The method according to claim 6, characterized in that, Also includes: If the Android startup completion marker is a preset system normal startup magic number, then the last normal startup of the system is determined; Clear the Android boot completion marker in the third preset position of the boot communication partition, and update the system boot count in the fourth preset position of the boot communication partition to the initial value; as well as Normal startup, guiding the Android bootloader firmware.
11. The method according to claim 6, characterized in that, Also includes: If the number of system startups is not greater than the preset maximum number of startups, then the number of system startups is incremented by one, and the incremented number of system startups is written to the fourth preset position in the boot communication partition; as well as Normal startup, guiding the Android bootloader firmware.
12. The method according to claim 5, characterized in that, To restore a different system using the current system, and then restart the device, includes: Update the system startup count in the fourth preset position of the boot communication partition to the initial value; Read the dual-system partition table description structure from the seventh preset position in the boot communication partition; If the magic number of the dual-system partition table description structure is not the preset magic number of the dual-system description structure, an error message will be displayed and the system recovery command will be exited. If the magic number of the dual-system partition table description structure is a preset magic number, then the digital digest value of the first system partition description item list and the second system partition description item list of the dual-system partition table description structure is calculated according to the digital digest algorithm corresponding to the digital digest algorithm type of the dual-system partition table description structure. Check whether the calculated digital digest value is the same as the digital digest value of the dual-system partition description item list of the dual-system partition table description structure; If they are not the same, an error message will be displayed, and the system recovery command will be exited. If they are the same, then the primary partition table is read from the preset primary partition table area as the current boot partition table; Based on the current boot partition table and the dual-system partition table description structure, it is determined whether the system is currently the first system or the second system; If the system is currently the first system, then the firmware data in the firmware partitions corresponding to all partition description entries in the first system partition description item list of the dual system partition table description structure is copied to the address space corresponding to the partition description item in the second system partition description item list, thereby completing the recovery of the second system. If the system is currently the second system, then the firmware data in the firmware partitions corresponding to all partition description entries in the second system partition description item list of the dual system partition table description structure is copied to the address space corresponding to the corresponding partition description item in the first system partition description item list, thus completing the recovery of the first system. A preset recovery completion magic number is written to the first preset position in the boot communication partition; Clear the system recovery command from the second preset location in the boot communication partition; and Restart the device.
13. The method according to claim 1, characterized in that, Running the Android bootloader firmware, if the system enters recovery mode, the system recovery instructions read from the boot communication partition include: Run the Android bootloader firmware and read the second system build instructions from the fifth preset location in the boot communication partition; If the second system build instruction is a preset second system build instruction, then the system is guided into recovery mode, and the system recovery instruction is read from the second preset location in the boot communication partition; If the second system build instruction is not a preset second system build instruction, then the factory erase instruction is read from the sixth preset position in the boot communication partition; If the factory erase command is a preset factory erase command, then the system is guided into recovery mode, and the system recovery command is read from the second preset location in the boot communication partition; If the factory erase command is not the preset factory erase command, then the system recovery command is read from the second preset location in the boot communication partition; If the system recovery command is a preset system recovery command, then the system is guided into recovery mode, and the system recovery command is read from the second preset location in the boot communication partition; and If the system recovery command is not a preset system recovery command, the system will be guided according to the preset process.
14. The method according to claim 13, characterized in that, The system is guided according to a preset procedure, including: Determine whether the preset process is a preset recovery mode; If so, then guide the system into recovery mode; and If not, then the system will be guided into the normal Android system.
15. The method according to claim 14, characterized in that, Booting the system into the normal Android system includes: If the Android system boots up successfully, a preset system normal startup magic number is written to the third preset position in the boot communication partition. Read the recovery completion marker from the first preset position in the boot communication partition; Check if the recovery completion marker is a preset recovery completion magic number; If not, the recovery selection information will be output, which will remind the user that the backup system is abnormal and ask whether to choose to restore on the next boot. If the user chooses to restore on the next boot, a preset system restore command is written to the second preset location in the boot communication partition; and If the system performs its own OTA upgrade and the upgrade is successful, the upgrade client obtains a complete firmware upgrade package corresponding to the current firmware version from the upgrade server and saves the complete firmware upgrade package to a preset path in the preset unencrypted data partition as a reserved upgrade package.
16. The method according to claim 1, characterized in that, Before reading system recovery instructions from the boot communication partition, the process also includes: Read the second system build instructions from the fifth preset location in the boot communication partition; If the second system construction instruction is a preset second system construction instruction, then the second system is constructed according to the second system construction instruction; If the second system build instruction is not a preset second system build instruction, then the factory erase instruction is read from the sixth preset position in the boot communication partition; If the factory erase command is a preset factory erase command, then the factory erase operation is performed according to the factory erase command; and If the factory erase command is not the preset factory erase command, then the step of reading the system recovery command from the boot communication partition is executed.
17. The method according to claim 16, characterized in that, Performing the factory erase operation according to the factory erase command includes: Update the system startup count in the fourth preset position of the boot communication partition to the initial value; Erase and reformat all preset readable and writable partitions except for the boot communication partition; Clear the factory erase command in the sixth preset position of the boot communication partition; and Restart the device.
18. The method according to claim 1, characterized in that, Also includes: If the system recovery command is not a preset system recovery command, then check whether the Android recovery command area in the boot communication partition contains a prompt to erase data; If not, the corresponding recovery operation will be performed according to the preset procedure; If it is present, the system startup count in the fourth preset position of the boot communication partition will be updated to the initial value; Read the recovery completion marker from the first preset position in the boot communication partition; If the recovery completion marker is not a preset recovery completion magic number, then the damaged system is recovered according to the system. Check if a reserved upgrade package exists in the preset path of the preset unencrypted data partition; If it exists, the reserved upgrade package is used to upgrade the firmware of the system. After the upgrade is completed, the reserved upgrade package is deleted, and the instructions in the Android recovery instruction area of the boot communication partition are cleared. Then the device is restarted. If it does not exist, erase and format the user data partition, clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device; If the recovery completion marker is a preset recovery completion magic number, then check if there is a reserved upgrade package under the preset path of the preset unencrypted data partition; If it exists, the reserved upgrade package is used to upgrade the firmware of the system. After the upgrade is completed, the reserved upgrade package is deleted, and the instructions in the Android recovery instruction area of the boot communication partition are cleared. Then the device is restarted. as well as If it does not exist, erase and format the user data partition, clear the instructions in the Android recovery instruction area of the boot communication partition, and then restart the device.
19. An electronic device, characterized in that, include: The memory is configured to store executable programs; as well as A processor is configured to execute the program to perform the method according to any one of claims 1 to 18.