Method for upgrading a terminal and terminal
By storing the upgrade package in the user data partition block device in an unmounted state and mapping it to memory using mmap, the problem of upgrade packages being corrupted when the data partition changes is solved, thus achieving efficient upgrades of the terminal system.
Patent Information
- Application Number
- CN202011219326.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-11-04
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2040-11-04
AI Technical Summary
During terminal system upgrades, upgrade packages stored in the data partition are easily corrupted, leading to upgrade failures. This is especially true when the data partition space changes, and existing technologies cannot effectively solve this problem.
The upgrade package is stored in the user data partition block device in an unmounted state, and the upgrade data is mapped to the terminal memory using the memory mapping function mmap to achieve system upgrade and avoid the upgrade package being corrupted when the data partition changes.
It improves the success rate of system version upgrades, ensures that the upgrade package is not corrupted during the upgrade process, and enhances the reliability and efficiency of OTA upgrades.
Smart Images

Figure CN114443081B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of system upgrade, in particular to a terminal upgrade method and terminal. BACKGROUND
[0002] In order to obtain the latest use experience, a user needs to upgrade the system of a terminal. Generally, the system upgrade is performed by downloading an upgrade package through over the air (OTA) technology, storing the downloaded upgrade package in a data partition, and then using the upgrade package to upgrade the terminal system from a low version to a high version. However, during the upgrade process, other partitions may occupy the space of the data partition, so that the data partition is modified, and thus the upgrade package in the data partition in the file system is destroyed, resulting in upgrade failure. SUMMARY
[0003] The present application provides a terminal upgrade method and terminal, which stores the upgrade package in a block device, and solves the problem that the upgrade package is destroyed during the upgrade process, resulting in upgrade failure.
[0004] In a first aspect, a terminal upgrade method is provided, which includes: receiving an upgrade package of a target version, the upgrade package including upgrade data of the target version; storing the upgrade package in a user data partition block device, wherein the block device is in an unmounted state during the upgrade process, and the offset of the starting position of the upgrade package relative to the tail of the block device is less than the available space of the block device after the upgrade; mapping the upgrade data to the memory of the terminal through a memory mapping function mmap; and upgrading the terminal from a current version to the target version based on the upgrade data in the memory.
[0005] In the following, the user data partition block device can also be referred to as a data partition block device, or the block device in the following is also the data partition block device.
[0006] According to the terminal upgrade method provided by the embodiments of the present application, the upgrade package is stored in the unmounted user data block device, and the upgrade data is mapped to the memory by using the mmap method, so that the terminal updates each partition by using the upgrade data in the memory, realizes system upgrade, and can ensure that the upgrade package is not destroyed during the upgrade process, thereby improving the success rate of OTA upgrade.
[0007] In combination with the first aspect, in some implementations of the first aspect, the method further includes: unmounting the access path of the block device in the file system.
[0008] With reference to the first aspect, in some implementations of the first aspect, the method further includes: receiving first information sent by the OTA server, the first information including partition information in the target version; determining, according to the first information and the partition information in the current version, that the user data partition size in the target version is changed relative to the user data partition size in the current version.
[0009] With reference to the first aspect, in some implementations of the first aspect, the method further includes: determining, according to the starting position of the upgrade package in the block device and the size of the user data partition block device, a first offset of the starting position relative to a reference position in the block device, the reference position including a position where a tail of the block device is located.
[0010] With reference to the first aspect, in some implementations of the first aspect, the method further includes: generating an upgrade command, the upgrade command including a path of the user data partition block device, the first offset, and the size of the upgrade package; and storing the upgrade command in at least one standby partition, the standby partition being a partition that is not updated during the upgrade process.
[0011] With reference to the first aspect, in some implementations of the first aspect, the first offset includes a byte alignment size, the byte alignment size being used to align the starting position with an integer multiple of byte position of the mmap reading mode.
[0012] With reference to the first aspect, in some implementations of the first aspect, the first information specifically includes indication information of a user data partition size in the target version, and the partition information in the current version includes a user data partition size in the current version; and the determining, according to the first information and the partition information in the current version, that the user data partition size in the target version is changed relative to the user data partition size in the current version includes: when the user data partition size in the target version is different from the user data partition size in the current version, determining that the user data partition size in the target version is changed relative to the user data partition size in the current version.
[0013] In some implementations of the first aspect, the first information includes indication information of sizes of partitions other than a user data partition in the target version, and the partition information in the current version includes indication information of sizes of the partitions other than the user data partition in the current version; and the determining, according to the first information and the partition information in the current version, that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version includes: determining that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version when a sum of the sizes of the partitions other than the user data partition in the target version is different from a sum of the sizes of the partitions other than the user data partition in the current version.
[0014] In the second aspect, a terminal is provided, including: a downloading module configured to receive an upgrade package of a target version, the upgrade package including upgrade data of the target version; and store the upgrade package in a user data partition block device, wherein the block device is in an unmounted state during an upgrade process, and an offset of a start position of the upgrade package relative to a tail of the block device is less than available space of the block device after the upgrade; and an upgrading module configured to map the upgrade data to a memory of the terminal by using a memory mapping function mmap, and upgrade the terminal from a current version to the target version based on the upgrade data in the memory.
[0015] In some implementations of the second aspect, the terminal further includes an uninstalling module configured to uninstall an access path of the block device in a file system.
[0016] In some implementations of the second aspect, the terminal further includes a pre-downloading module and a judging module, wherein the pre-downloading module is configured to receive first information sent by the OTA server, the first information including partition information in the target version; and the judging module is configured to determine, according to the first information and the partition information in the current version, that a size of a user data partition in the target version is changed relative to a size of a user data partition in the current version.
[0017] In some implementations of the second aspect, the terminal further includes an upgrade preprocessing module configured to determine, according to a start position of the upgrade package in the block device and a size of the user data partition block device, a first offset of the start position relative to a tail of the block device.
[0018] With reference to the second aspect, in some implementations of the second aspect, the upgrade pre-processing module is further configured to generate an upgrade command, the upgrade command including a path of the user data partition block device, the first offset, and the upgrade package size; and the storage module is further configured to store the upgrade command in at least one standby partition, the standby partition being a partition that is not updated during the upgrade.
[0019] With reference to the second aspect, in some implementations of the second aspect, the first offset includes a byte alignment size, the byte alignment size being used to align the start position with an integer multiple of byte position of the mmap reading mode.
[0020] With reference to the second aspect, in some implementations of the second aspect, the first information specifically includes indication information of a user data partition size in the target version, and the partition information in the current version includes a user data partition size in the current version; and the processing module is further configured to determine that the user data partition size in the target version has changed relative to the user data partition size in the current version when the user data partition size in the target version is different from the user data partition size in the current version.
[0021] With reference to the second aspect, in some implementations of the second aspect, the first information includes indication information of sizes of other partitions in the target version other than a user data partition, and the partition information in the current version includes indication information of sizes of other partitions in the current version other than the user data partition; and the processing module is further configured to determine that the user partition size in the target version has changed relative to the user partition size in the current version when a sum of the sizes of the other partitions in the target version other than the user data partition is different from a sum of the sizes of the other partitions in the current version other than the user data partition.
[0022] A third aspect provides a terminal, including: a processor; a memory configured to store executable instructions of the processor; and wherein when the processor executes the executable instructions, the terminal is caused to implement the following steps: receiving an upgrade package of a target version, the upgrade package including upgrade data of the target version; storing the upgrade package in a user data partition block device, wherein the block device is in an unmounted state during the upgrade, and a start position of the upgrade package is offset from a tail of the block device by an amount that is less than available space of the block device after the upgrade; mapping the upgrade data to a memory of the terminal by using a memory mapping function mmap; and upgrading the terminal from a current version to the target version based on the upgrade data in the memory.
[0023] With reference to the third aspect, in some implementations of the third aspect, when the processor executes the executable instructions, the terminal is caused to perform the following step: unloading the access path of the block device in the file system.
[0024] With reference to the third aspect, in some implementations of the third aspect, when the processor executes the executable instructions, the terminal is caused to perform the following step: receiving the first information sent by the OTA server, the first information comprising partition information in the target version; determining that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version according to the first information and the partition information in the current version.
[0025] With reference to the third aspect, in some implementations of the third aspect, when the processor executes the executable instructions, the terminal is caused to perform the following step: determining a first offset of the starting position relative to a reference position in the block device according to the starting position of the upgrade package in the block device and the size of the user data partition block device, the reference position comprising a position where the tail of the block device is located.
[0026] With reference to the third aspect, in some implementations of the third aspect, when the processor executes the executable instructions, the terminal is caused to perform the following step: generating an upgrade command, the upgrade command comprising the path of the user data partition block device, the first offset, and the size of the upgrade package; storing the upgrade command in at least one spare partition, the spare partition being a partition that is not updated in the upgrade process.
[0027] With reference to the third aspect, in some implementations of the third aspect, the first offset comprises a byte alignment size, the byte alignment size being used to align the starting position with an integer multiple of byte position of the mmap reading mode.
[0028] With reference to the third aspect, in some implementations of the third aspect, the first information specifically comprises indication information of the size of the user data partition in the target version, and the partition information in the current version comprises the size of the user data partition in the current version; when the processor executes the executable instructions, the terminal is caused to perform the following step: determining that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version when the size of the user data partition in the target version is different from the size of the user data partition in the current version.
[0029] In a third aspect, in some embodiments of the third aspect, the first information comprises indication information of sizes of partitions other than a user data partition in the target version, and the partition information in the current version comprises indication information of sizes of the partitions other than the user data partition in the current version; and when the processor executes the executable instructions, the terminal is caused to implement the following step: determining that the size of the user partition in the target version is changed relative to the size of the user partition in the current version when the sum of the sizes of the other partitions in the target version other than the user data partition is different from the sum of the sizes of the other partitions in the current version other than the user data partition.
[0030] In a fourth aspect, a communication system is provided, and the communication system comprises an OTA server and a terminal, wherein the terminal is configured to implement the method for terminal upgrading according to any one of the implementation manners of the first aspect.
[0031] In a fifth aspect, a computer readable storage medium is provided, and the computer program storage medium has program instructions, which, when executed directly or indirectly, cause the method for terminal upgrading according to any one of the implementation manners of the first aspect to be implemented.
[0032] In a sixth aspect, a computer program is provided, and when the computer program is executed in at least one processor, the method for terminal upgrading according to any one of the implementation manners of the first aspect is implemented.
[0033] In a seventh aspect, a computer program product is provided, and when the computer program is executed in at least one processor, the method for terminal upgrading according to any one of the implementation manners of the first aspect is implemented. BRIEF DESCRIPTION OF DRAWINGS
[0034] Figure 1 FIG. 1 is a schematic diagram of a terminal structure provided by an embodiment of the present application.
[0035] Figure 2 FIG. 2 is a schematic flowchart of a method for terminal upgrading provided by an embodiment of the present application.
[0036] Figure 3 FIG. 3 is a schematic diagram of a storage location of an upgrade package in a block device provided by an embodiment of the present application.
[0037] Figure 4 FIG. 4 is another schematic flowchart of a method for terminal upgrading provided by an embodiment of the present application.
[0038] Figure 5 FIG. 5 is a schematic diagram of a graphical user interface provided by an embodiment of the present application.
[0039] Figure 6A and Figure 6B is a schematic diagram of partition changes before and after upgrading provided by an embodiment of the present application.
[0040] Figure 7 is a schematic diagram of a terminal structure provided by an embodiment of the present application. DETAILED DESCRIPTION
[0041] The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0042] It should be noted that the terms used in the implementation part of the embodiments of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B; "and / or" herein only describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist together, and B exists alone. In addition, in the description of the embodiments of the present application, unless otherwise specified, "multiple" means two or more than two, "at least one" and "one or more" means one, two or more than two.
[0043] Hereinafter, the terms "first", "second" are only used for description purposes, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the "first", "second" features defined can explicitly or implicitly include one or more features.
[0044] In this specification, the reference "one embodiment" or "some embodiments" and the like means that the specific features, structures or characteristics described in connection with the embodiment are included in one or more embodiments of the present application. Therefore, the statements "in one embodiment", "in some embodiments", "in other some embodiments", "in other some embodiments" and the like appearing in different places in the specification are not necessarily all referring to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized. The terms "include", "contain", "have" and their variants mean "include but not limited to", unless otherwise specifically emphasized.
[0045] With the evolution of the terminal system version, when the terminal is upgraded from a low version to a high version, the problem of insufficient system space occurs, at this time, it is necessary to increase the system partition and reduce the data partition. However, as introduced in the background, the current upgrade process usually stores the upgrade package in the data partition of the file system through the file system, if the data partition is reduced, the data partition will be damaged, and the upgrade package will also be damaged, resulting in failure to perform OTA upgrade.
[0046] To solve the above problems, a current solution is to backup the upgrade package to the memory, such as random access memory (RAM), when the upgrade package in the data partition is damaged, the upgrade process can still continue by using the upgrade package data in the memory. However, the solution has the following problems: first, the storage space of the memory is generally small, and with the development of the terminal system, the upgrade package is getting larger and larger, and the memory space is not enough to accommodate the upgrade package; in addition, since the memory is a temporary storage medium, if the terminal power is turned off or the like, the data in the memory will be lost, resulting in upgrade failure.
[0047] In view of the above problems, the embodiment of the present application provides a terminal upgrade method, which stores the upgrade package in the data partition block device (the block device will be in an unmounted state during the upgrade process), and maps the upgrade data in the block device to the memory by using the memory mapping function mmap mode, and then the terminal reads the upgrade data in the memory to complete the upgrade. The method in the embodiment of the present application can solve the problem that the upgrade package is damaged and cannot be upgraded when the data partition changes, and in the method, the upgrade package does not need to be written into the memory, and the upgrade process will not be limited by the memory space capacity, thereby improving the probability of successful upgrade.
[0048] The terminal upgrade method provided by the embodiment of the present application can be applied to the scene of batch wireless upgrade of terminals on the terminal production line; or, it can also be applied to the scene of repairing and upgrading the terminal by users or repair points.
[0049] The terminal upgrade method provided in this application can be applied to electronic devices such as mobile phones, tablets, televisions, wearable devices (such as smartwatches, smart bracelets, smart glasses, smart jewelry, etc.), in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). This application does not limit the specific type of terminal. Exemplary embodiments of the terminal include those equipped with… Terminals for operating systems, etc.
[0050] For example, such as Figure 1 The diagram shown is a structural schematic of a terminal provided in an embodiment of this application. The terminal 100 includes a pre-download module 101, a judgment module 102, a download module 103, an upgrade preprocessing module 104, and an upgrade module 105. Each module can be communicatively connected via a bus 106.
[0051] In some embodiments, the pre-download module 101 can be used to obtain relevant information about the target version through channels including but not limited to wireless fidelity (Wi-Fi) download or universal serial bus (USB) transmission; such relevant information includes but is not limited to: upgrade package size, data partition information, etc.; the data partition information may include partition size, starting position, etc., or may include but is not limited to information in the form of a partition table or other form that can calculate the starting position of the target version's data partition.
[0052] In some embodiments, the judgment module 102 can be used to determine whether the data partition in the current version and the target version has changed based on the relevant information of the target version obtained by the pre-download module. The judgment method includes, but is not limited to, the following two: (1) determining whether the size of the data partition has changed; (2) determining whether the total size of other partitions besides the data partition has changed.
[0053] In some embodiments, the download module 103 can be used to download the upgrade package. Furthermore, the download module 103 can also be used to calculate information such as the starting position of the upgrade package in the data partition block device.
[0054] In some embodiments, the upgrade preprocessing module 104 can be configured to calculate the storage location information of the upgrade package, such as the offset of the starting position of the upgrade package storage relative to the tail of the data partition block device; in addition, the upgrade preprocessing module can also be configured to generate an upgrade command including the storage location information of the upgrade package, so that the upgrade module can obtain the upgrade data according to the upgrade command.
[0055] In some embodiments, the upgrade module 105 can be configured to map the upgrade data in the data partition block device to the memory of the terminal by mmap, and then read the upgrade data in the memory to update each partition and implement terminal upgrade.
[0056] It should be understood that, for the convenience and brevity of description, only the above division of functional modules is exemplified in the embodiments of the present application, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the terminal is divided into different functional modules to complete all or part of the above described functions. For the division of modules or units, only a logical function division is made, and the terminal can actually include more or fewer modules than those shown, such as the terminal can also include an uninstall module for uninstalling the access path of the block device in the file system, which is not limited in the present application. Figure 1
[0057] The method for terminal upgrade provided by the embodiments of the present application will be specifically introduced below in combination with the drawings.
[0058] Exemplarily, as shown in the figure, a flowchart of a method for terminal upgrade provided by the embodiments of the present application is shown. The method can be executed by a terminal and mainly includes the following steps: Figure 2
[0059] S201, receiving an upgrade package of a target version, the upgrade package including upgrade data of the target version.
[0060] In some embodiments, the OTA server can make an upgrade package of the target version, which includes the upgrade data of the target version, such as a partition table of the target version, which can include the actual position of each partition in the target version (such as the starting position of each partition), the size of each partition and other information.
[0061] In some embodiments, after the OTA server generates the target version, it can notify the terminal that there is an available target version. For example, the OTA server sends a notification message to the terminal to indicate that the terminal has an available target version or the upgrade package of the target version is available for download. In response to the notification message, the terminal can download the target version upgrade package from the OTA.
[0062] In some embodiments, the upgrade package can be one or more. Optionally, when there are multiple upgrade packages, the terminal can download each upgrade package in segments.
[0063] S202, store the upgrade package in the user data partition block device, which is in an unmounted state during the upgrade process, and the starting position of the upgrade package relative to the first offset of the tail of the block device is less than the available space of the block device after the upgrade.
[0064] In some embodiments, the block device is in an unmounted state during the upgrade process, which means that the access path of the data partition block device is not included in the file system during the upgrade process. In other words, before the upgrade, the terminal can delete the mapping relationship between the data partition block device and the file system by calling a system command.
[0065] In some embodiments, the starting position of the upgrade package in the data partition block device relative to the offset of the tail of the block device is less than or equal to the available space of the user data partition block device after the upgrade. Specifically, the storage location of the upgrade package in the data partition block device can be close to the tail of the block device (as shown in Figure 3 ), so as to avoid being overwritten by the data of other partitions (such as the bootloader, boot, recovery, system, data partitions, etc.). Figure 3
[0066] It should be understood that generally, the size of the data partition block device of the terminal is greater than the size of the upgrade package of the corresponding version (such as the target version), so if the upgrade package is stored at the tail of the user data partition block device, it can be ensured that during the upgrade process, even if the user data partition becomes smaller (such as being occupied by other partitions), the upgrade package data will not be overwritten, ensuring the successful completion of the upgrade.
[0067] In some embodiments, when there are multiple upgrade packages, the multiple upgrade packages can be stored in sequence at the tail of the data partition block device.
[0068] S203, map the upgrade data to the memory of the terminal by the memory mapping function mmap.
[0069] In some embodiments, the upgrade module of the terminal can map the upgrade package data to the memory according to the storage location of the upgrade package.
[0070] Specifically, the upgrade module of the terminal can map the upgrade data in the data partition block device to the memory of the terminal by mmap according to the starting position of the upgrade package and the size of the upgrade package.
[0071] It should be understood that the above method maps the upgrade data in the block device to the terminal memory through the memory function mapping mmap, so that the terminal is no longer limited by the size of the memory during the upgrade process. This method does not need to read / write actions on the upgrade data, and can achieve efficient access to data.
[0072] In S204, the current version is upgraded to the target version based on the upgrade data in the memory.
[0073] In some embodiments, the upgrade module of the terminal can read the upgrade data from the terminal memory. Then, the upgrade module updates each partition according to the actual position (such as the starting position) of each partition indicated by the upgrade data and the size of each partition, so that the terminal system is upgraded from the current version to the target version.
[0074] It should be understood that the terminal upgrade method provided by the embodiments of the present application can store the upgrade package in the data partition block device in an unmounted state, that is, store the upgrade package at the block device layer. When the upgrade package is stored in the data partition block device, the original data of the block device will be destroyed (such as being cleared), and the upgrade package can be continuously stored in a segment of available space in the block device. During the upgrade process, the upgrade module can map the upgrade data to the terminal memory according to the storage position of the upgrade package in the block device, and then realize system upgrade by reading the upgrade data in the memory. In other words, the terminal upgrade method provided by the embodiments of the present application can ensure that the upgrade package is available as long as the upgrade package is not covered by the upgrade data, and the upgrade process can continue to be executed, even if the data partition changes during the upgrade process. However, the current method of storing the upgrade package in the file system data partition cannot make the upgrade package continuously distributed on the data partition block device. Moreover, if the size of the file system data partition changes or other data is written during the upgrade process, the data partition may be destroyed (such as data disorder in the data partition), and the upgrade package in the data partition will inevitably be destroyed, resulting in upgrade failure.
[0075] According to the terminal upgrade method provided by the embodiments of the present application, the upgrade package is stored in the unmounted user data block device, and the upgrade data is mapped to the memory by using the mmap method. The terminal updates each partition by using the upgrade data in the memory to realize system upgrade, which can ensure that the upgrade package is not destroyed during the upgrade process and improve the efficiency of system version upgrade.
[0076] In order to better understand the terminal upgrade method provided by the embodiments of the present application, the specific process of the method will be described in more detail below with reference to the accompanying drawings.
[0077] Exemplarily, Figure 4A schematic flowchart of a method for terminal upgrading is shown. The method can be performed by a terminal and specifically includes the following steps:
[0078] In S401, the terminal acquires first information of the upgrade package.
[0079] The first information is used to indicate the size of the upgrade package and the partition information of the target version.
[0080] In some embodiments, after the OTA server generates the available target version, it can send a notification message to the terminal to indicate that the terminal has available target version or the upgrade package of the target version is available for download. After detecting the notification message sent by the OTA server, the terminal can prompt the user whether to perform version upgrade.
[0081] For example, the terminal can pop up a prompt information on the display interface to confirm with the user whether to perform version upgrade. For example, as shown in Figure 5 As shown in the figure, the interface provided by the embodiments of the present application is a graphical user interface (GUI) schematic diagram, which can be the main interface of the unlocked mobile phone. The main interface includes multiple application programs (APPs) such as clock, calendar, gallery, memo, smart life, etc. When the mobile phone receives the notification message sent by the OTA server, in response to the notification message, the mobile phone can pop up a prompt information on the main interface: "A new system version is detected and can be applied to your mobile phone. Do you want to perform version update?" Then, if the mobile phone detects that the user clicks the "confirm" icon, it performs the upgrade operation; if the mobile phone detects that the user clicks the "cancel" icon, it does not perform the version upgrade. Optionally, when the user chooses not to perform version upgrade, the mobile phone can again confirm with the user whether to perform version upgrade after a preset period of time, which is not limited in the present application.
[0082] In some embodiments, when the terminal detects that the user selects the operation of performing version upgrade, it can request the OTA server to query the related information of the target version, such as the size of the target version upgrade package, the data partition information in the target version, etc. In response to the query request of the terminal, the OTA server can send first information to the terminal. The first information can be the indication information of the upgrade package, which can be used to indicate the size of the upgrade package, the partition information of the target version, etc. The partition information of the target version includes, for example, the actual starting position of each partition in the target version, the size of each partition, etc. Optionally, the first information can be the partition table of the target version.
[0083] In some possible implementations, the first information may include the size and starting position of the data partition in the target version; or, the first information may also include information capable of calculating the size of the data partition and the starting position of the upgrade package in the target version. In other words, the first information can indicate the size and starting position of the data partition directly or indirectly, and this application does not limit this.
[0084] S402, determine if the size of the data partition has changed.
[0085] In some embodiments, the terminal can determine whether the size of the data partition has changed between the two versions based on the first information obtained and the partition information in the current version.
[0086] like Figure 6A and Figure 6B The figures shown are schematic diagrams illustrating the changes in the data partition in the target version compared to the data partition in the current version. Figure 6A and Figure 6B The bootloader partition, boot partition, recovery partition, system partition, and data partition are shown respectively. Specifically, in Figure 6A In the target version, the space of the data partition is smaller compared to the space of the data partition in the current version; Figure 6B In the target version, the space of the data partition is larger than that of the data partition in the current version.
[0087] If the data partition size changes, the upgrade package is stored at the block device level; if the data partition size does not change, the upgrade package can be stored by writing to the file system. The following mainly describes the terminal upgrade method provided in this application embodiment for the scenario where the data partition size changes after the upgrade.
[0088] It should be understood that when the data partition in the target version remains unchanged, it means that the data partition does not need to be destroyed during the upgrade process. The upgrade package can be stored in the data partition through the file system, or it can be stored in the data partition block device in an unmounted state. However, when the data partition in the target version changes (such as the space becoming smaller or larger), the corresponding data partition under the file system will be destroyed during the upgrade process. At this time, if the upgrade package continues to be stored in the data partition through the file system, the upgrade package will also be destroyed, and the upgrade cannot be achieved.
[0089] Generally, the data partition size of the terminal is larger than the upgrade package size. However, to further determine whether the available space of the data partition is sufficient to accommodate the upgrade package during the upgrade, the method for terminal upgrade provided by the embodiment of the present application further includes the following steps.
[0090] Optionally, the terminal can determine whether the upgrade package can be stored in the data partition block device based on the size of the upgrade package and the data partition size in the target version. For example, when the terminal determines that the data partition size in the target version is larger than the upgrade package size, it indicates that the available space of the data partition is sufficient to accommodate the upgrade package during the upgrade. At this time, it is determined that the upgrade package can be stored in the user data partition block device, that is, the upgrade package is stored in the block device dimension.
[0091] S403, write the upgrade package into the data partition block device.
[0092] In some embodiments, when it is determined in step S402 that the data partition size in the target version changes, the path of the data partition block device in the file system can be unmounted, so that the data partition block device is in an unmounted state. Specifically, the manner of making the block device in the unmounted state is, for example, calling a system command to unmount the access path of the block device in the file system, or calling a system command to delete the mapping relationship between the data partition block device and the file system.
[0093] It should be understood that generally, if the block device is in a mounted state, the computer files and directories on the block device can be accessed by the user through the file system, and the user or the system can also write data into the block device through the file system. However, when the block device stores the upgrade package, if the block device is still in the mounted state, other data written into the block device during the upgrade will destroy the upgrade package, resulting in a failed upgrade. Therefore, in the embodiment of the present application, the block device can be unmounted to make the block device in an unmounted state, so as to avoid the writing of other data and ensure the integrity and availability of the upgrade package.
[0094] Optionally, the block device can be in the unmounted state after the storage of the upgrade package is completed; or the block device can also be in the unmounted state before the storage of the upgrade package. The embodiment of the present application only needs to satisfy that the data partition block device is in the unmounted state during the upgrade, and does not limit the specific time when the block device is in the unmounted state.
[0095] It should be understood that when the upgrade package is stored in the data partition block device, the previous data of the block device will be destroyed, such as being cleared, and the upgrade package can be stored in the block device according to the storage position (such as the starting position) calculated according to the preset criteria.
[0096] When the terminal stores the upgrade package in the data partition block device, the first offset of the starting position of the upgrade package in the data partition block device relative to the tail of the block device is less than or equal to the available space of the upgraded user data partition block device. Specifically, the storage location of the upgrade package in the data partition block device can be close to the tail of the block device (see reference). Figure 3 This is to avoid data being overwritten by other partitions.
[0097] Specifically, the starting position (starAddr) of the upgrade package can be calculated based on the size of the target version upgrade package (packageSize) and the size of the data partition block device (dataSize). The calculation method is: starAddr = dataSize - packageSize - align, where align is the size required for byte alignment.
[0098] It should be understood that the reason for considering the size required for byte alignment here is that when the upgrade package data is subsequently read from the data partition block device using mmap, it needs to start from an integer multiple of the read size (e.g., 4K) to ensure successful data reading. In other words, `align` is used to ensure that the starting position of the upgrade package is aligned to an integer multiple of the read size (e.g., 4K) to guarantee that the upgrade package data is successfully mapped into memory using mmap.
[0099] For example, when mmap reads data in 4KB units, if the starting position of the upgrade package is 1GB, the data can be read successfully. However, if the starting position of the upgrade package is 1GB plus 1 byte, which is not an integer multiple of 4KB, the data cannot be read successfully. In this case, the size of the alignment bytes can be used to increase the offset of the starting position of the upgrade package relative to the end of the data partition block device, so that the starting position is aligned with the position of integer multiples of 4KB, thereby ensuring that the upgrade module maps the upgrade data through mmap.
[0100] S404, writes the upgrade command to at least one spare partition.
[0101] It should be understood that during actual upgrades, the upgrade process often unexpectedly stops due to factors such as terminal power outages. When the terminal restarts, the data partition may have changed due to the previous upgrade, potentially leading to errors in the upgrade data mapped from the previous upgrade package storage location. Therefore, to facilitate the retrieval of upgrade packages and ensure the accuracy of their location, this embodiment uses a first offset of the upgrade package's starting position relative to the tail end of the data partition block device to indicate the upgrade package's storage location.
[0102] Specifically, the terminal can calculate a first offset of a starting position of the upgrade package relative to a tail end of the data partition block device according to the storage position information of the upgrade package in the block device, and the first offset can be used to indicate the storage position of the upgrade package in the upgrade process. The first offset can be calculated according to the size (dataSize) of the data partition block device and the starting position (starAddr) of the upgrade package, and the calculation method is: offset = dataSize - starAddr.
[0103] In some embodiments, when the upgrade package is stored, an upgrade command indicating the storage position of the upgrade package can be generated according to the storage position of the upgrade package, and the upgrade command can be stored in the backup partition, so that when the upgrade data needs to be reacquired (for example, in the scenario of restarting after power-off of the terminal), the position of the upgrade package can be accurately found, and the upgrade process can be continued.
[0104] For example, the upgrade command can include the data partition block device path information, the first offset, and the upgrade package size, or the upgrade command can also include other information that can be used to calculate the first offset, which is not limited in the present application. For example, the format of the upgrade command can be:
[0105] --updata_package = / dev / block / by-name / userdata:offset:packageSize.
[0106] In some embodiments, the backup partition can be a pre-divided fixed partition, and the backup partition is not updated during the upgrade process, in other words, the position, size, and the like of the backup partition do not change during the version iteration process. The backup partition can be used to store a start parameter indicating the mode type of the restart, such as the start upgrade mode. The backup partition can also be used to store the upgrade command. For example, the backup partition is the misc partition.
[0107] In some embodiments, after the upgrade command is stored in the backup partition, the upgrade pre-processing module of the terminal can send a notification message to the upgrade module, notifying the upgrade module that the upgrade command can be read from the backup partition, and the upgrade package data can be acquired according to the storage position of the upgrade package indicated by the upgrade command.
[0108] For example, assuming that the partition table has been updated when the terminal is powered off, causing the data partition to have changed, since the first offset of the upgrade package relative to the tail end of the data partition block device and the updated data partition block device size (newDataSize) are stored in the upgrade command of the standby partition at this time, after the terminal is restarted, the upgrade module can calculate the actual position of the upgrade package in the new data partition block device through the offset and the newDataSize, where the new starting position of the upgrade package is: newstarAddr = newDataSize-offset. Then, the upgrade module maps the upgrade data in the data partition block device into the terminal memory through the mmap method according to the new starting position, and continues the upgrade process.
[0109] The above method can avoid the problem of upgrade package loss and upgrade module unable to read upgrade data, resulting in upgrade failure, in the case of unexpected stop of the upgrade process caused by terminal power failure and the like, by storing the upgrade command in at least one standby partition.
[0110] S405, mapping the upgrade data in the data partition block device into the terminal memory through the mmap method.
[0111] The terminal upgrade module obtains the storage location information of the upgrade package in the data partition block device according to the upgrade command. Specifically, the upgrade module can obtain the path of the data partition block device, the first offset, the data partition block device size, the upgrade package size and the like of the upgrade package in the data partition block device through the upgrade command; and then calculate the starting position of the upgrade package in the data partition block device according to the information.
[0112] In some embodiments, the upgrade module maps the upgrade data into the terminal memory through the mmap method according to the storage location of the upgrade package.
[0113] In some embodiments, after the upgrade package is mapped into the terminal memory through the mmap method, the terminal upgrade module can verify the upgrade package, such as verifying the signature and integrity of the upgrade package, to check whether the source of the upgrade package is legal and whether the upgrade package is complete.
[0114] The above method can avoid the limitation of the size of the memory on the upgrade process by mapping the upgrade data into the terminal memory through the mmap method, in other words, the problem of upgrade failure caused by the size of the upgrade package being greater than the capacity of the memory during the upgrade process can be solved.
[0115] S406, upgrading the terminal system based on the upgrade data in the terminal memory.
[0116] In some embodiments, the upgrading module of the terminal can read the upgrading data from the memory of the terminal; then, the upgrading module updates each partition according to the actual position (e.g., the starting position) of each partition indicated by the upgrading data and the size of each partition, so as to upgrade the terminal system from the current version to the target version.
[0117] In some embodiments, since the data partition block device is destroyed after storing the upgrading package, the upgrading module can format or write mirror data to brush the data partition block device data after the update of each partition is completed.
[0118] According to the terminal upgrading method provided by the embodiments of the present application, the upgrading package is stored in the user data block device in the unmounted state, and the mmap method is used to map the upgrading data to the memory, so that the terminal updates each partition by using the upgrading data in the memory, and realizes system upgrading, which can ensure that the upgrading package is not destroyed in the upgrading process, and improves the success probability of OTA upgrading.
[0119] For example, as shown in Figure 7 The terminal 700 includes a processor 701, a memory 702, a communication interface 703, and a bus 704 connecting these devices. The memory 702 includes computer instructions, and when the computer instructions are executed in the processor 701, the terminal 700 implements the terminal upgrading method provided by the embodiments of the present application.
[0120] In addition, the embodiments of the present application also provide a communication system including an OTA server and a terminal, wherein the OTA server and the terminal are used to execute the terminal upgrading method provided by the embodiments of the present application.
[0121] The embodiments of the present application also provide a computer readable storage medium, which has program instructions, and when the program instructions are executed directly or indirectly, the computer implements the terminal upgrading method provided by the embodiments of the present application.
[0122] The embodiments of the present application also provide a computer program, and when the computer program is executed in at least one processor, the computer implements the terminal upgrading method provided by the embodiments of the present application.
[0123] The embodiments of the present application also provide a computer program product, and when the computer program is executed in at least one processor, the computer implements the terminal upgrading method provided by the embodiments of the present application.
[0124] In the above embodiments, all or part of the methods can be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the methods can be implemented in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in or transmitted by a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through a wired (such as coaxial cable, optical fiber, digital subscriber line) or wireless (such as infrared, wireless, microwave, etc.) manner. The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that includes one or more available media sets. The available media can be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium (for example, a solid state disk (SSD)), etc.
[0125] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiments can be instructed by a computer program to complete the relevant hardware, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiments. The storage medium includes ROM or random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0126] The above is only a specific implementation of the embodiments of the present application, but the protection scope of the embodiments of the present application is not limited to this. Any changes or replacements within the technical scope disclosed in the embodiments of the present application should be covered in the protection scope of the embodiments of the present application. Therefore, the protection scope of the embodiments of the present application should be subject to the protection scope of the claims.
Claims
1. A method for upgrading a terminal, characterized by, Applied to terminals, including: Receive an upgrade package for the target version, the upgrade package including upgrade data for the target version; Receive first information sent by the OTA server, the first information including partition information in the target version; Based on the first information and the partition information in the current version, it is determined that the size of the user data partition in the target version has changed relative to the size of the user data partition in the current version; Unmount the block device from the file system or delete the mapping between the block device and the file system so that the block device is in an unmounted state; The upgrade package is stored in a user data partition block device, wherein the block device is in an unmounted state during the upgrade process, and the offset of the starting position of the upgrade package relative to the tail of the block device is less than the available space of the block device after the upgrade; wherein, the block device is in an unmounted state during the upgrade process means that the access path of the user data partition block device is not included in the file system during the upgrade process. Based on the storage location of the upgrade package, the upgrade package data is mapped into the memory of the terminal using the memory mapping function mmap; Based on the upgrade data in the memory, the terminal is upgraded from the current version to the target version.
2. The method of claim 1, wherein, The method further includes: Based on the starting position of the upgrade package in the block device and the size of the user data partition block device, a first offset of the starting position relative to the tail of the block device is determined.
3. The method of claim 2, wherein, The method further includes: Generate an upgrade command, the upgrade command including the path of the user data partition block device, the first offset, and the size of the upgrade package; The upgrade command is stored in at least one spare partition, which is a partition that is not updated during the upgrade process.
4. The method of claim 2, wherein, The first offset includes a byte alignment size, which is used to align the starting position with an integer multiple of the byte position of the mmap reading method.
5. The method according to any one of claims 1-4, characterized in that, The first information specifically includes indication information of the size of the user data partition in the target version, and the partition information in the current version includes the size of the user data partition in the current version; The step of determining, based on the first information and the partition information in the current version, that the size of the user data partition in the target version has changed relative to the size of the user data partition in the current version includes: When the size of the user data partition in the target version is different from the size of the user data partition in the current version, it is determined that the size of the user data partition in the target version has changed relative to the size of the user data partition in the current version.
6. The method according to any one of claims 1-4, characterized in that, The first information includes indication information of the size of other partitions in the target version besides the user data partition, and the partition information in the current version includes indication information of the size of other partitions in the current version besides the user data partition; The step of determining, based on the first information and the partition information in the current version, that the size of the user data partition in the target version has changed relative to the size of the user data partition in the current version includes: When the sum of sizes of other partitions except the user data partition in the target version is different from the sum of sizes of other partitions except the user data partition in the current version, it is determined that the size of the user partition in the target version is changed relative to the size of the user partition in the current version.
7. A terminal, characterized by comprising: Comprise: The unloading module is further configured to unload the access path of the block device in the file system so that the block device is in an unmounted state. The pre-download module is configured to receive first information sent by an OTA server, wherein the first information comprises partition information in a target version. The judging module is configured to determine, according to the first information and the partition information in a current version, that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version. The downloading module is configured to receive an upgrade package of the target version, wherein the upgrade package comprises upgrade data of the target version. The downloading module is further configured to store the upgrade package in the user data partition block device, wherein the block device is in an unmounted state during the upgrade process, and an offset of a start position of the upgrade package relative to a tail of the block device is less than available space of the block device after the upgrade. The upgrading module is configured to map the upgrade data to memory of the terminal by using a memory mapping function mmap according to a storage position of the upgrade package, and upgrade the terminal from the current version to the target version based on the upgrade data in the memory. The terminal is further configured to delete a mapping relationship between the block device and the file system so that the block device is in an unmounted state.
8. The terminal according to claim 7, characterized by The terminal further comprises an upgrade preprocessing module configured to determine a first offset of the start position relative to the tail of the block device according to a start position of the upgrade package in the block device and a size of the user data partition block device.
9. The terminal according to claim 8, characterized by The upgrade preprocessing module is further configured to generate an upgrade command, wherein the upgrade command comprises a path of the user data partition block device, the first offset, and a size of the upgrade package, and store the upgrade command in at least one standby partition that is not updated during the upgrade process.
10. The terminal according to claim 8, characterized by The first offset comprises a byte alignment size, and the byte alignment size is used to align the start position with an integer multiple byte position of the mmap reading mode.
11. The terminal according to any one of claims 7-10, characterized by, The first information specifically comprises indication information of the size of the user data partition in the target version, and the partition information in the current version comprises the size of the user data partition in the current version. The judging module is further configured to determine that the size of the user data partition in the target version is changed relative to the size of the user data partition in the current version when the size of the user data partition in the target version is different from the size of the user data partition in the current version.
12. The terminal according to any one of claims 7-10, characterized by The first information includes indication information of sizes of other partitions except a user data partition in the target version, and the partition information in the current version includes indication information of sizes of other partitions except the user data partition in the current version; The judging module is further configured to determine that a size of a user partition in the target version is changed relative to a size of a user partition in the current version when a sum of sizes of other partitions except the user data partition in the target version is different from a sum of sizes of other partitions except the user data partition in the current version.
13. A terminal, characterized by The method comprises: a processor; a memory for storing executable instructions of the processor; when the processor executes the executable instructions, the terminal implements the method in any one of claims 1 to 6.
14. A communication system, characterized by The communication system comprises an OTA server and a terminal, wherein the terminal is configured to execute the method in any one of claims 1 to 6.
15. A computer readable storage medium, characterized in that, The computer program storage medium has program instructions which, when executed directly or indirectly, cause the computer to implement the method in any one of claims 1 to 6.
16. A computer program, characterized in that, The computer program, when executed in at least one processor, causes the computer to implement the method in any one of claims 1 to 6.
Citation Information
Patent Citations
Firmware updating method and device
CN107194242A
OTA upgrading-package upgrading method and device
CN107526608A
Ota upgrading method and device, apparatus, and storage medium
CN109032649A
Android system upgrade method, device, server and mobile terminal
CN109086078A