Firmware upgrading method, server and terminal equipment
By cutting and compressing the firmware upgrade package, adapting to the limited memory space of terminal devices, it solves the problem that smart home appliances cannot be upgraded when there is insufficient memory, and improves the security of firmware transmission.
Patent Information
- Application Number
- CN202311790268.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-22
- Publication Date
- 2025-07-01
AI Technical Summary
Smart home appliances cannot complete firmware upgrades when there is insufficient memory, and there is a risk of firmware information leakage.
By obtaining the first memory space size of the terminal device, the upgrade package of the target firmware is cut into multiple firmware slices and compressed to form multiple compressed files. The size of each compressed file is not greater than the first memory space size, ensuring that the terminal device can safely upgrade firmware.
It realizes a secure firmware upgrade when the terminal device has small memory, reduces the risk of firmware information leakage and improves the success rate of firmware upgrades.
Smart Images

Figure CN120234019A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of network technologies, and particularly to a firmware upgrade method, a server, and a terminal device. Background Art
[0002] With the development of technology, smart home appliances have become a new choice for many families. During the use of smart home appliances, it is necessary to upgrade the firmware of the smart home appliances. When performing firmware upgrade, terminal devices such as smart home appliances will download the upgrade package of the complete firmware for local upgrade. However, since downloading the complete upgrade package requires a large amount of memory, when the memory of the terminal device is insufficient, the firmware upgrade cannot be completed. Moreover, during the transmission of the firmware, there is a risk of firmware information leakage. Therefore, how to perform secure firmware upgrade when the memory of the terminal device is small has become an urgent problem to be solved. Summary of the Invention
[0003] This application provides a firmware upgrade method, a server, and a terminal device, which can enable the terminal device to implement firmware upgrade when the memory is small. The technical solution is as follows:
[0004] On the one hand, a firmware upgrade method is provided, and the method includes:
[0005] Obtain the size of the first memory space for firmware upgrade in the terminal device, where the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space;
[0006] Based on the size of the first memory space, cut the upgrade package of the target firmware into multiple firmware slices, and respectively compress the multiple firmware slices to obtain multiple compressed files;
[0007] Send the multiple compressed files to the terminal device in sequence, so that the terminal device upgrades the target firmware; where the size of each compressed file is not greater than the size of the first memory space.
[0008] Optionally, the step of based on the size of the first memory space, cutting the upgrade package of the target firmware into multiple firmware slices, and respectively compressing the multiple firmware slices to obtain multiple compressed files includes:
[0009] Based on the size of the first memory space and a reference compression ratio, determine the cutting size, where the reference compression ratio refers to the ratio of the file size before compression to the file size after compression;
[0010] Let i = 1, and cut out a firmware slice starting from the (i - 1)-th cutting position of the upgrade package according to the cutting size to obtain the i-th firmware slice;
[0011] Compress the i-th firmware slice;
[0012] If the size of the compressed i-th firmware slice is greater than the size of the first memory space, reduce the reference compression ratio and return to the step of determining the cutting size based on the size of the first memory space and the reference compression ratio;
[0013] If the size of the compressed i-th firmware slice is less than or equal to the size of the first memory space and the upgrade package has not been completely cut, determine the compressed i-th firmware slice as one of the compressed files, let i = i + 1, and return to the step of cutting out a firmware slice starting from the cutting position of the (i - 1)-th cut of the upgrade package according to the cutting size.
[0014] Optionally, before sequentially sending the multiple compressed files to the terminal device, the method further includes:
[0015] Determine encryption keys corresponding to the multiple firmware slices respectively, and the encryption keys corresponding to the multiple firmware slices are different;
[0016] Encrypt the multiple compressed files respectively according to the encryption keys corresponding to the multiple firmware slices.
[0017] Optionally, determining the encryption keys corresponding to the multiple firmware slices respectively includes:
[0018] For each firmware slice, send a random password to the terminal device;
[0019] Receive the random encryption vector sent by the terminal device;
[0020] Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0021] On the other hand, a firmware upgrade method is provided, and the method includes:
[0022] Receive multiple compressed files sequentially sent by the server, where the multiple compressed files are obtained by respectively compressing multiple firmware slices, the multiple firmware slices are obtained by cutting an upgrade package of a target firmware according to the size of a first memory space for firmware upgrade in the terminal device, the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space, and the size of each compressed file is not greater than the size of the first memory space;
[0023] Whenever a compressed file is received, store the compressed file in the first memory space;
[0024] The compressed file is decompressed in multiple times. Whenever a part of the slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.
[0025] Optionally, the step of decompressing the compressed file in multiple times and writing the currently decompressed slice data into the system partition corresponding to the target firmware whenever a part of the slice data is decompressed includes:
[0026] Read the file list of the compressed file, where the file list is used to store the names of the files compressed in the compressed file;
[0027] If the file list includes the file name of the firmware slice to be currently decompressed, determine the offset position of the currently decompressed firmware slice in the compressed file;
[0028] Starting from the offset position, read the content of the compressed file and decompress it;
[0029] If the size of the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing and call the write callback function to write the currently decompressed content into the system partition;
[0030] If all the currently decompressed content has been written into the system partition and the slice data of the currently decompressed firmware slice has not been completely decompressed, starting from the last stop position, return to the step of reading the content of the compressed file and decompressing it.
[0031] Optionally, the multiple compressed files are encrypted compressed files; before storing the compressed file into the first memory space, it further includes:
[0032] Determine the encryption key corresponding to the firmware slice compressed in the compressed file, and the encryption keys corresponding to the multiple firmware slices are different;
[0033] Decrypt the compressed file according to the encryption key corresponding to the firmware slice compressed in the compressed file.
[0034] Optionally, the step of determining the encryption key corresponding to the firmware slice compressed in the compressed file includes:
[0035] Receive the random password sent by the server;
[0036] Send a random encryption vector to the server;
[0037] Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0038] On the other hand, a server is provided, and the server includes:
[0039] A transceiver, configured to obtain the size of a first memory space for firmware upgrade in a terminal device, where the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space;
[0040] A processor, configured to cut an upgrade package of a target firmware into multiple firmware slices based on the size of the first memory space, and respectively compress the multiple firmware slices to obtain multiple compressed files;
[0041] The transceiver is further configured to sequentially send the multiple compressed files to the terminal device, so that the terminal device upgrades the target firmware; wherein, the size of each compressed file is not greater than the size of the first memory space.
[0042] Optionally, the processor is specifically configured to:
[0043] Determine a cutting size based on the size of the first memory space and a reference compression ratio, where the reference compression ratio refers to the ratio between the size of the file before compression and the size of the file after compression;
[0044] Let i = 1, and cut out a firmware slice starting from the (i - 1)-th cutting position of the upgrade package according to the cutting size to obtain the i-th firmware slice;
[0045] Compress the i-th firmware slice;
[0046] If the size of the compressed i-th firmware slice is greater than the size of the first memory space, reduce the reference compression ratio, and return to the step of determining the cutting size based on the size of the first memory space and the reference compression ratio;
[0047] If the size of the compressed i-th firmware slice is less than or equal to the size of the first memory space, and the upgrade package has not been completely cut, determine the compressed i-th firmware slice as one of the compressed files, let i = i + 1, and return to the step of cutting out a firmware slice starting from the (i - 1)-th cutting position of the upgrade package according to the cutting size.
[0048] Optionally, the processor is further configured to:
[0049] Determine encryption keys corresponding to the multiple firmware slices respectively, where the encryption keys corresponding to the multiple firmware slices are different;
[0050] Encrypt the multiple compressed files respectively according to the encryption keys corresponding to the multiple firmware slices.
[0051] Optionally, the processor is further configured to:
[0052] For each of the firmware slices, send a random password to the terminal device;
[0053] Receive the random encryption vector sent by the terminal device;
[0054] Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0055] On the other hand, a terminal device is provided, and the terminal device includes:
[0056] A transceiver, configured to receive a plurality of compressed files sequentially sent by a server, where the plurality of compressed files are obtained by respectively compressing a plurality of firmware slices, the plurality of firmware slices are obtained by cutting an upgrade package of a target firmware according to the size of a first memory space in the terminal device for firmware upgrade, the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space, and the size of each compressed file is not greater than the size of the first memory space;
[0057] A memory, configured to store the compressed file in the first memory space whenever a compressed file is received;
[0058] A processor, configured to decompress the compressed file in multiple times, and whenever a part of slice data is decompressed, write the currently decompressed slice data into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.
[0059] Optionally, the processor is specifically configured to:
[0060] Read the file list of the compressed file, where the file list is used to store the names of the respective files compressed in the compressed file;
[0061] If the file list includes the file name of the firmware slice to be currently decompressed, determine the offset position of the firmware slice to be currently decompressed in the compressed file;
[0062] Start from the offset position, read the content of the compressed file and decompress it;
[0063] If the size of the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing and call a write callback function to write the currently decompressed content into the system partition;
[0064] If all the currently decompressed content has been written into the system partition and the slice data of the firmware slice to be currently decompressed has not been completely decompressed, start from the last stop position, and return to the step of reading the content of the compressed file and decompressing it.
[0065] Optionally, the multiple compressed files are encrypted compressed files; the processor is further configured to:
[0066] Determine the encryption keys corresponding to the firmware slices compressed in the compressed files, where the encryption keys corresponding to the multiple firmware slices are different;
[0067] Decrypt the compressed files according to the encryption keys corresponding to the firmware slices compressed in the compressed files.
[0068] Optionally, the processor is further configured to:
[0069] Receive the random password sent by the server;
[0070] Send a random encryption vector to the server;
[0071] Determine the random password and the random encryption vector as the encryption keys corresponding to the firmware slices.
[0072] On the other hand, a computer-readable storage medium is provided, in which a computer program is stored, and when the computer program is executed by a processor, the steps of the above-mentioned firmware upgrade method are implemented.
[0073] On the other hand, a computer program product including instructions is provided, and when the instructions run on a computer, the computer is caused to execute the steps of the above-mentioned firmware upgrade method.
[0074] The technical solution provided by this application can at least bring the following beneficial effects:
[0075] Obtain the size of the first memory space for firmware upgrade in the terminal device through the server, and based on the size of the first memory space, cut the upgrade package of the target firmware into multiple firmware slices and compress them to obtain multiple compressed files, ensuring that the terminal device can store the compressed files in the first memory space, effectively guaranteeing the success rate of firmware upgrade. Moreover, the terminal device decompresses the compressed file in multiple times while writing the decompressed content into the corresponding system partition, which can reduce the occupation of memory space. In summary, the method provided by the embodiments of this application enables the terminal device to achieve secure firmware upgrade when the remaining memory space is small. Description of the Drawings
[0076] In order to more clearly illustrate the technical solutions in the embodiments of this application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of this application. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0077] Figure 1 It is a schematic structural diagram of an implementation environment provided by an embodiment of the present application;
[0078] Figure 2 It is a flowchart of a firmware upgrade method provided by an embodiment of the present application;
[0079] Figure 3 It is a schematic structural diagram of a server provided by an embodiment of the present application;
[0080] Figure 4 It is a schematic structural diagram of a terminal device provided by an embodiment of the present application. Detailed implementation manners
[0081] To make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the following will further describe the implementation manners of the present application in detail with reference to the accompanying drawings.
[0082] Before explaining the firmware upgrade method provided by the embodiment of the present application in detail, the application scenarios and implementation environment involved in the embodiment of the present application will be introduced first.
[0083] With the development of technology, smart home appliances have become a new choice for many families, and OTA (Over-the-Air Technology) is a basic function of smart home appliances. During the use of smart home appliances, OTA is required to implement the firmware upgrade of smart home appliances. Traditional OTA generally downloads and stores the upgrade package of the complete firmware in the smart home appliance for local upgrade. However, since downloading the complete firmware requires a large amount of memory, when the memory of the smart home appliance is insufficient, the smart home appliance may not be able to complete the firmware upgrade. Moreover, during the transmission of the firmware, there is a risk of firmware information leakage.
[0084] Based on this, the embodiment of the present application provides a firmware upgrade method, which can reduce the memory occupation of the firmware. Even when the memory of the terminal device is insufficient, the firmware upgrade can be completed. At the same time, the transmission process of the firmware is encrypted, which can reduce the risk of firmware information leakage.
[0085] Please refer to Figure 1 , Figure 1 It is a schematic diagram of an implementation environment shown according to an exemplary embodiment. This implementation environment includes a server 101 and a terminal device 102, and the server 101 can be communicatively connected to the terminal device 102. This communication connection can be a wired or wireless connection, and the embodiment of the present application does not limit this.
[0086] The server 101 is used to obtain the size of the first memory space in the terminal device 102 for firmware upgrade. Based on the size of the first memory space, the upgrade package of the target firmware is cut into multiple firmware slices, and the multiple firmware slices are respectively compressed to obtain multiple compressed files, and the multiple compressed files are sequentially sent to the terminal device 102.
[0087] The terminal device 102 is used to receive the multiple compressed files sequentially sent by the server 101. Whenever a compressed file is received, the compressed file is stored in the first memory space, and the compressed file is decompressed in multiple times. Whenever a part of the slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware.
[0088] Among them, the server 101 can be an independent server, or a server cluster or a distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, or a cloud computing service center.
[0089] The terminal device 102 can be any electronic product that can perform human-computer interaction with the user through one or more ways such as a keyboard, a touchpad, a touch screen, a remote control, voice interaction, or a handwriting device. For example, a PC (Personal Computer), a mobile phone, a smart phone, a PDA (Personal Digital Assistant), a wearable device, a pocket PC (Pocket PC), a tablet computer, a smart vehicle console, etc., or it can also be a smart home appliance such as a smart TV or a smart speaker.
[0090] Those skilled in the art should understand that the above-mentioned server 101 and terminal device 102 are only examples. Other existing or future possible servers or terminal devices that can be applied to the embodiments of the present application should also be included in the protection scope of the embodiments of the present application, and are hereby incorporated by reference.
[0091] It should be noted that the application scenarios and implementation environments described in the embodiments of the present application are for more clearly explaining the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. Those of ordinary skill in the art know that with the emergence of new application scenarios and the evolution of implementation environments, the technical solutions provided by the embodiments of the present application are equally applicable to similar technical problems.
[0092] Next, a detailed explanation of the firmware upgrade method provided by the embodiments of the present application will be given.
[0093] Figure 2 It is a flowchart of a firmware upgrade method provided by the embodiments of the present application. Please refer to Figure 2 and the method includes the following steps.
[0094] Step 201: The server obtains the size of the first memory space for firmware upgrade in the terminal device. The size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space.
[0095] The first memory space is the memory space for firmware upgrade in the terminal device. The size of the first memory space is allocated by the terminal device based on the size of its own current remaining memory space. That is to say, the size of the first memory space can depend on the size of the current remaining memory space in the terminal device. If the current remaining memory space in the terminal device is large, more memory space can be allocated as the first memory space. If the current remaining memory space in the terminal device is small, less memory space can be allocated as the first memory space.
[0096] For example, when the remaining memory space of the terminal device is X, the size of the first memory space can be 30%X, that is, the size of the first memory space can be 30% of the size of the current remaining memory space in the terminal device. Of course, the size of the first memory space can be adjusted according to the actual situation. That is to say, the size of the first memory space can be 30%, 40% or any percentage of the size of the current remaining memory space in the terminal device. The embodiments of the present application do not limit this.
[0097] In some embodiments, in order to obtain the size of the first memory space, the server can send a memory space acquisition request to the terminal device. After the terminal device receives the memory space acquisition request, it allocates the size of the first memory space based on the size of the current remaining memory space and sends the size of the first memory space to the server so that the server can obtain the size of the first memory space.
[0098] In some embodiments, in order to determine whether the terminal device needs to perform firmware upgrade, before obtaining the size of the first memory space for firmware upgrade in the terminal device, the current version numbers of each firmware in the terminal device can also be obtained. That is to say, if the current version numbers of each firmware of the terminal device are all the latest version numbers, it means that the terminal device does not need to perform firmware upgrade and does not need to perform the subsequent steps. If the current version number of a certain firmware in the terminal device is not the latest version number, it means that the terminal device can perform firmware upgrade and continue with the subsequent steps. The firmware that needs to be upgraded currently is called the target firmware.
[0099] Continuing the above description, the server can send a firmware version number acquisition request to the terminal device. After receiving the firmware version number acquisition request, the terminal device sends the current version numbers of each firmware it includes to the server. In this way, the server can obtain the current version numbers of each firmware in the terminal device.
[0100] Step 202: Based on the size of the first memory space, the server cuts the upgrade package of the target firmware into multiple firmware slices, and compresses each of the multiple firmware slices to obtain multiple compressed files.
[0101] Based on the above description, the first memory space is the memory space used by the terminal device for firmware upgrade. Therefore, the server can cut the upgrade package of the target firmware into multiple firmware slices based on the size of the first memory space, so that the terminal device can perform firmware upgrade based on the first memory space, avoiding the situation of firmware upgrade failure due to insufficient memory.
[0102] In some embodiments, the server can cut the upgrade package of the target firmware into multiple firmware slices and compress the multiple firmware slices through the following steps (1)-(5).
[0103] (1) Based on the size of the first memory space and the reference compression ratio, determine the cutting size. The reference compression ratio refers to the ratio between the file size before compression and the file size after compression.
[0104] The reference compression ratio is the ratio between the file size before compression and the file size after compression under normal circumstances. That is to say, the reference compression ratio can be an empirical value obtained by technicians during the process of compressing files. In order to ensure that the size of the compressed file obtained after compressing the firmware slice obtained by cutting is not greater than the size of the first memory space, it is necessary to ensure that the cutting size of the firmware slice is not greater than the product of the size of the first memory space and the reference compression ratio.
[0105] In some embodiments, the product of the size of the first memory space and the reference compression ratio can be determined as the cutting size to make full use of the first memory space.
[0106] For example, the size of the first memory space is 10M, the reference compression ratio is 2.5, and the cutting size is equal to the product of the reference compression ratio and the size of the first memory space. Therefore, the cutting size can be 25M.
[0107] It should be noted that the reference compression ratio can be 2.5 as described above, or other values obtained by technicians during the process. The embodiments of the present application do not limit this.
[0108] (2) Let \(i = 1\). According to the cutting size, cut out a firmware slice starting from the cutting position of the \((i - 1)\)-th time of the upgrade package to obtain the \(i\)-th firmware slice.
[0109] When \(i = 1\), it means that the upgrade package has not been cut yet. That is to say, the upgrade package is a complete upgrade package. According to the cutting size, cut it from the starting position of the upgrade package to obtain the first firmware slice; when \(i = 2\), cut out a firmware slice starting from the cutting position of the first time of the upgrade package. That is to say, cut the upgrade package again at the position where the first firmware slice is cut to obtain the second firmware slice. Similarly, when \(i = 3\), cut starting from the cutting position of the second time of the upgrade package to obtain the third firmware slice. And so on, when \(i\) is equal to any integer, cut the upgrade package in the above manner.
[0110] (3) Compress the \(i\)-th firmware slice.
[0111] Compressing the \(i\)-th firmware slice can obtain the compressed \(i\)-th firmware slice. It should be noted that the zip compression algorithm can be used to compress the \(i\)-th firmware slice, and other compression algorithms can also be used to compress the firmware slice. The embodiments of the present application do not limit this.
[0112] (4) If the size of the compressed \(i\)-th firmware slice is greater than the size of the first memory space, then reduce the reference compression ratio, and return to the step of determining the cutting size based on the size of the first memory space and the reference compression ratio.
[0113] Due to the difference in the data in the firmware slice, it may occur that the size of the compressed firmware slice is greater than the size of the first memory space. That is to say, it may occur that the size of the compressed \(i\)-th firmware slice is greater than the size of the first memory space, resulting in the terminal device being unable to receive the compressed firmware slice. Therefore, in order to avoid the above situation, the size of the compressed \(i\)-th firmware slice can be compared with the size of the first memory space.
[0114] If the size of the compressed \(i\)-th firmware slice is greater than the size of the first memory space, then discard the compressed \(i\)-th firmware slice, reduce the reference compression ratio, and re-cut the \(i\)-th firmware slice. That is to say, it is possible to return to step (1) and re-determine the cutting size of the \(i\)-th firmware slice based on the size of the first memory space and the reduced reference compression ratio, so as to re-cut out the \(i\)-th firmware slice.
[0115] The methods for reducing the reference compression ratio include various ones. By way of example, subtracting a fixed value from the reference compression ratio, or reducing the reference compression ratio by a fixed proportion. The embodiments of the present application do not make any limitations thereto. Among them, the fixed value and the fixed proportion can be set in advance. For example, the fixed value is 0.5 and the fixed proportion is 20%.
[0116] For example, if the reference compression ratio is 2.5 and the size of the i-th firmware slice after compression is greater than the size of the first memory space, the reference compression ratio can be reduced by 0.5, that is, the reduced reference compression ratio is 2. Then, the cutting size of the i-th firmware slice is re-determined according to the reduced reference compression ratio, and the i-th firmware slice is re-cut starting from the cutting position of the (i - 1)-th time.
[0117] Based on the above description, the cutting size is determined based on the reference compression ratio and the size of the first memory space. Therefore, after reducing the reference compression ratio, the cutting size of the i-th firmware slice will also be reduced accordingly. After re-cutting the i-th firmware slice according to the reduced cutting size, the size of the i-th firmware slice after compression will also be reduced. In this way, it can be ensured that the size of each firmware slice after compression is not greater than the size of the first memory space.
[0118] For example, if the reference compression ratio before reduction is 2.5, at this time, the size of the first firmware slice is 25M, and the size of the first memory space is 10M. If the size of the first firmware slice after compression is greater than 10M, the reference compression ratio can be reduced from 2.5 to 2. Then, based on the size of the first memory space and the reduced reference compression ratio, the cutting size of the first firmware slice is re-determined to be 20M. According to this cutting size, the first firmware slice is re-cut to obtain the first firmware slice with a size of 20M. If the size of the first firmware slice with a size of 20M after compression is still greater than 10M, the cutting size of the first firmware slice can be continuously determined based on the size of the first memory space and the further reduced reference compression ratio, and the first firmware slice is re-cut according to this cutting size until the size of the first firmware slice after compression is not greater than 10M.
[0119] It should be noted that the above is to reduce the size of the firmware slice after compression by reducing the reference compression ratio. In practical applications, other methods can be used to reduce the size of the firmware slice after compression. The embodiments of the present application do not make any limitations thereto.
[0120] (5) If the size of the i-th firmware slice after compression is less than or equal to the size of the first memory space and the upgrade package has not been completely cut, the compressed i-th firmware slice is determined as a compressed file, and let i = i + 1, and return to the step of cutting out a firmware slice starting from the (i - 1)-th cutting position of the upgrade package according to the cutting size.
[0121] If the size of the i-th firmware slice after compression is less than or equal to the size of the first memory space, it indicates that the terminal device can receive the i-th compressed firmware slice. At this time, the i-th compressed firmware slice can be determined as a compressed file. If the upgrade package has not been completely sliced, let i = i + 1, and return to step (2).
[0122] As an example, assume that the upgrade package is sliced twice. That is, when i = 2 and the second firmware slice is obtained, the upgrade package has not been completely sliced. Then let i = 2 + 1 = 3, and according to the slicing size, slice out a firmware slice starting from the second slicing position of the upgrade package to obtain the third firmware slice. And so on until the upgrade package is completely sliced.
[0123] Step 203: The server sequentially sends the multiple compressed files to the terminal device so that the terminal device upgrades the target firmware; wherein, the size of each compressed file is not greater than the size of the first memory space.
[0124] In some embodiments, after the server compresses the multiple firmware slices to obtain multiple compressed files, corresponding serial numbers can also be set for the multiple compressed files, and then the multiple compressed files are sequentially sent to the terminal device in order.
[0125] For example, there are a total of 4 compressed files. The serial number of the compressed file corresponding to the first firmware slice is 1, the serial number of the compressed file corresponding to the second firmware slice is 2, the serial number of the compressed file corresponding to the third firmware slice is 3, and the serial number of the compressed file corresponding to the last firmware slice is -1. In this way, the server can first send the compressed file with the serial number 1, then send the compressed file with the serial number 2, then send the compressed file with the serial number 3, and finally send the compressed file with the serial number -1.
[0126] It should be noted that the multiple compressed files can be numbered according to the above method, or the multiple compressed files can be numbered by other methods, as long as the server can sequentially send the multiple compressed files. The embodiments of the present application do not make any limitations in this regard.
[0127] In some embodiments, before sequentially sending the multiple compressed files to the terminal device, the encryption keys corresponding to the multiple firmware slices can also be determined, and the encryption keys corresponding to the multiple firmware slices are different; according to the encryption keys corresponding to the multiple firmware slices, the multiple compressed files are encrypted respectively.
[0128] Among them, the implementation process for the server to determine the encryption keys corresponding to the multiple firmware slices includes: for each firmware slice, sending a random password to the terminal device; receiving the random encryption vector sent by the terminal device; and determining the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0129] The encryption keys corresponding to the multiple firmware slices are all different. That is to say, before the server sends the compressed file to the terminal device each time, it can determine the encryption key corresponding to the firmware slice to be sent by performing the above interaction with the terminal device. Of course, it can also determine the encryption keys corresponding to the multiple firmware slices respectively by performing multiple interactions with the terminal device before sending the first compressed file. The embodiments of the present application do not make any limitations in this regard.
[0130] It should be noted that the encryption key can be a combination of the above random password and random encryption vector, or other encryption keys jointly determined by the server and the terminal device. The embodiments of the present application do not make any limitations in this regard.
[0131] It should be noted that after the upgrade package of the target firmware is cut and compressed, the multiple compressed files can be sent to the terminal device in sequence, or each compressed file can be sent to the terminal device as soon as it is obtained. That is to say, the upgrade package can be cut and compressed while sending the compressed files obtained after the cutting and compression to the terminal device. The embodiments of the present application do not make any limitations in this regard.
[0132] Step 204: The terminal device receives the multiple compressed files sent by the server in sequence.
[0133] Based on the above description, after the server sends the multiple compressed files to the terminal device in sequence, the terminal device can receive the multiple compressed files.
[0134] In some embodiments, before the server sends each compressed file, it can also send information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and MD5 (Message Digest Algorithm 5) of the compressed file corresponding to the firmware slice to the terminal device. In this way, before the terminal device receives the compressed file sent by the server, it can also receive information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and MD5 of the compressed file corresponding to the firmware slice.
[0135] Among them, the size of the firmware slice before compression is used to indicate whether the terminal device decompresses the firmware slice completely in subsequent steps.
[0136] The size of the firmware slice after compression is used to indicate whether the terminal device has received the compressed file completely. That is to say, after the server sends the compressed file to the terminal device, the terminal device can determine the size of the received file during the process of receiving the compressed file, and then judge whether the compressed file has been received completely by comparing the size of the received file with the size of the firmware slice after compression sent in advance. That is, if the size of the received file is less than the size of the firmware slice after compression, it is determined that the compressed file has not been received completely; if the size of the received file is equal to the size of the firmware slice after compression, it is determined that the compressed file has been received completely.
[0137] In addition to indicating the order in which the server sends the multiple compressed files as described above, the serial number of the compressed file can also be used to indicate whether the compressed file received by the terminal device is the last compressed file. For example, there are a total of 4 compressed files. The serial number of the compressed file corresponding to the first firmware slice is 1, the serial number of the compressed file corresponding to the second firmware slice is 2, the serial number of the compressed file corresponding to the third firmware slice is 3, and the serial number of the compressed file corresponding to the last firmware slice is -1. In this way, when the terminal device receives the compressed file with the serial number -1, it means that the compressed file corresponding to the upgrade package of the target firmware has been received completely.
[0138] The MD5 of the compressed file is used for the terminal device to verify the integrity of the received compressed file. That is to say, after the terminal device receives the compressed file, it can calculate the MD5 based on the content of the received compressed file. If the calculated MD5 is consistent with the MD5 sent by the server, it means that the received compressed file is complete and the transmission is correct; if the calculated MD5 is inconsistent with the MD5 sent by the server, it means that there is an error in the received compressed file, and the terminal device will feedback the information that the MD5 of the compressed file is inconsistent to the server so that the server can resend the compressed file. The above is to verify the integrity of the compressed file based on MD5. Of course, in practical applications, the integrity of the compressed file can also be verified by other methods, and the embodiments of the present application do not limit this.
[0139] It should be noted that in the above content, the information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and the MD5 corresponding to each compressed file in the multiple compressed files is sent to the terminal device before the server sends each compressed file. That is to say, the information corresponding to each compressed file is sent separately. In practical applications, before sending the compressed file for the first time, the information corresponding to the multiple compressed files can also be sent together, and the embodiments of the present application do not limit this.
[0140] If the information of the multiple compressed files is sent together, the information of the multiple compressed files can be marked with serial numbers, and the serial numbers of the relevant information of the multiple compressed files are the same as the serial numbers of the multiple compressed files set in the above steps. In this way, after the terminal device receives the multiple compressed files, it can confirm information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and the MD5 of each compressed file according to the serial number.
[0141] In some embodiments, before the server sends information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and the MD5 corresponding to the multiple compressed files, it will encrypt them. Therefore, after the terminal device receives this information, it needs to decrypt it to obtain the relevant content.
[0142] Based on the above description, information such as the size of the firmware slice before compression, the size of the firmware slice after compression, the serial number, and the MD5 corresponding to the multiple compressed files can be sent separately or together. If the relevant information of each compressed file in the multiple compressed files is sent separately, the encryption key corresponding to the firmware slice of the compressed file can be used to encrypt it; if the relevant information of the multiple compressed files is sent together, before sending the relevant information of the multiple compressed files, the server and the terminal device can perform an interaction of determining the encryption key as described above to determine the encryption key corresponding to the relevant information of the multiple compressed files, and the server can encrypt the relevant information of the multiple compressed files based on this encryption key.
[0143] Step 205: Whenever the terminal device receives a compressed file, store the compressed file in the first memory space.
[0144] Based on the above description, the size of each compressed file is not greater than the size of the first memory space. Thus, whenever the terminal device receives a compressed file, it can store the compressed file in the first memory space. And before storing the currently received compressed file, the previously stored compressed file will be deleted. Of course, in practical applications, the currently received compressed file can also overwrite the previously stored compressed file so that only the currently received compressed file is stored in the first memory space.
[0145] In some embodiments, the multiple compressed files are encrypted compressed files; before storing the compressed file in the first memory space, it further includes: determining the encryption key corresponding to the firmware slice compressed in the compressed file, and the encryption keys corresponding to the multiple firmware slices are different; decrypting the compressed file according to the encryption key corresponding to the firmware slice compressed in the compressed file.
[0146] Among them, the implementation process for the terminal device to determine the encryption key corresponding to the firmware slice compressed in the compressed file is as follows: receive the random password sent by the server; send a random encryption vector to the server; determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0147] Based on the above description, since the multiple compressed files are encrypted compressed files, therefore, it is necessary to decrypt the compressed file based on the encryption key corresponding to the firmware slice compressed in the compressed file. Among them, the process for the terminal device and the server to determine the encryption key has been described in detail above, and will not be elaborated here. Please refer to the above content.
[0148] Step 206: The terminal device decompresses the compressed file in multiple times. Whenever a part of the slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.
[0149] In some embodiments, the terminal device can decompress the compressed file in multiple times through the following steps (1)-(5) and write the decompressed slice data into the system partition corresponding to the target firmware.
[0150] (1) Read the file list of the compressed file, and the file list is used to store the names of the various files compressed in the compressed file.
[0151] Since the compressed file may include multiple files, therefore, the names of the various files compressed stored in the file list of the compressed file can be read to determine whether the compressed file includes the firmware slice to be decompressed.
[0152] In some embodiments, the open callback function can be called to open the compressed file, and then, the read callback function can be called to read the file list of the compressed file. Of course, in practical applications, the compressed file can also be opened and the file list can be read through other means, and the embodiments of the present application do not make any limitations in this regard.
[0153] (2) If the file list includes the file name of the currently to-be-decompressed firmware slice, determine the offset position of the currently to-be-decompressed firmware slice in the compressed file.
[0154] The currently to-be-decompressed firmware slice is any one of the compressed firmware slices, that is to say, the currently to-be-decompressed firmware slice can be the i-th firmware slice after compression.
[0155] Since the compressed file may include other files in addition to the firmware slice to be decompressed currently, and the offset positions of each file are different, the offset position of the firmware slice to be decompressed currently in the compressed file can be determined for subsequent steps.
[0156] In some embodiments, to determine whether the compressed file includes the firmware slice to be decompressed, user intervention can be allowed. That is, the user can determine whether the compressed file includes the firmware slice to be decompressed according to the names of the files stored in the file list.
[0157] In other embodiments, before decompressing the compressed file in multiple times, the terminal device can also receive the file name of the firmware slice to be decompressed sent by the server, and compare the received file name with the file names stored in the file list to determine whether the compressed file includes the firmware slice to be decompressed. Of course, in practical applications, the terminal device and the server can also negotiate a naming rule so that the server sets the file name of the firmware slice to be decompressed according to the naming rule. In this way, the terminal device does not need to receive the file name of the firmware slice to be decompressed sent by the server and can directly determine whether the compressed file includes the firmware slice to be decompressed based on the naming rule.
[0158] As an example, the naming rule can be ota_sequence number.part, where the sequence number is the sequence number of the compressed file where the firmware slice to be decompressed is located. For example, ota_01.part is the file name of the firmware slice to be decompressed included in the compressed file with the sequence number 01, and ota_02.part is the file name of the firmware slice to be decompressed included in the compressed file with the sequence number 02. Similarly, the file names of other firmware slices to be decompressed can also be named according to the above naming rule. In this way, when the file list includes a file name that is the same as the above naming rule, the terminal device can determine that the compressed file includes the firmware slice to be decompressed.
[0159] It should be noted that in addition to the above naming rule, other naming rules can also be used, and the embodiments of the present application do not limit this.
[0160] (3) Starting from the offset position, read the content of the compressed file and decompress it.
[0161] Continuing the above description, after determining the offset position of the firmware slice to be decompressed currently in the compressed file, the seek callback function can be called to jump to the offset position, and the read callback function can be called to read the content of the compressed file starting from the offset position. Of course, in practical applications, the content of the compressed file can also be jumped to and read through other methods, and the embodiments of the present application do not limit this.
[0162] In some embodiments, the compressed file carries a file header, which includes information such as a compression algorithm, a compression algorithm version, a check code, etc.
[0163] Among them, the compression algorithm is used to indicate the algorithm used by the server to compress the firmware slice, so that the terminal device can use the corresponding decompression algorithm to decompress the compressed file. For example, if the compression algorithm is the zip compression algorithm, the terminal device can use the unzip decompression algorithm to decompress the compressed file.
[0164] The compression algorithm version is used to indicate the algorithm version used by the server to compress the firmware slice, so that the server can use the corresponding version of the decompression algorithm to decompress the compressed file.
[0165] The check code is used to detect or verify whether an error occurs after the compressed file is transmitted or saved. The check code can be a CRC (Cyclic Redundancy Check) check code, or other check codes, which are not limited in the embodiments of the present application.
[0166] That is to say, the error of the compressed file can be verified by reading the file header, and after reading the content of the compressed file, the corresponding decompression algorithm can be used to decompress the compressed file.
[0167] (4) If the size of the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing and call the write callback function to write the currently decompressed content into the system partition.
[0168] If the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing, store the currently decompressed content in the second memory space, call the write callback function, and write the currently decompressed content from the second memory space into the corresponding system partition to overwrite the original content.
[0169] The size of the content decompressed at one time depends on the size of the second memory space, which is used to store the decompressed content. The second memory space can be a part of the first memory space, or a part or all of the stack memory space. If there is remaining memory space after the first memory space stores the compressed file, part or all of the remaining memory space can be used as the second memory space; if there is no remaining memory space after the first memory space stores the compressed file, part or all of the stack memory space can be allocated as the second memory space.
[0170] The system partition is located on the Flash memory (equivalent to a hard disk), which is the area where each firmware in the terminal device is located. Since the Flash memory has at least one system partition, it is possible to determine the system partition where the target firmware is located, so as to write the currently decompressed content into the corresponding system partition.
[0171] It should be noted that the above is to call the write callback function to write the currently decompressed content into the system partition. In actual applications, other methods that can overwrite the original content can also be used to write the currently decompressed content into the system partition. The embodiments of the present application do not limit this.
[0172] (5) If all the currently decompressed content has been written into the system partition, and the slice data of the currently to-be-decompressed firmware slice has not been completely decompressed, then starting from the last stop position, return to the step of reading the content of the compressed file and decompressing it.
[0173] Continuing the above description, if all the currently decompressed content has been written into the system partition, that is to say, all the currently decompressed content stored in the second memory space has been written into the system partition, the write length and offset position of the currently decompressed content in this system partition can be recorded. If the slice data of the currently to-be-decompressed firmware slice has not been completely decompressed, step (3) can be returned, and starting from the last stop position, read the content of the compressed file and decompress it. Moreover, based on this write length and this offset position, the next decompressed content can be written into the corresponding system partition. The last stop position is used to indicate the position where the decompression of the compressed file stopped last time, so that the terminal device can continue to decompress from this stop position.
[0174] Compare the size of the content written into the system partition with the size of the currently to-be-decompressed firmware slice before compression. If the size of the content written into the system partition is less than the size of the currently to-be-decompressed firmware slice before compression, it means that all the currently decompressed content has not been written into the system partition, and continue to read the content of the compressed file and decompress it. If the size of the content written into the system partition is equal to the size of the currently to-be-decompressed firmware slice before compression, it means that all the slice data of this firmware slice has been written into the system partition, and at the same time, it also indicates that the firmware slice to be decompressed in this compressed file has been completely decompressed, and the close callback function can be called to close this compressed file.
[0175] Continuing with the above description, after the firmware slices to be decompressed in the compressed file have been decompressed, the terminal device can determine whether the compressed file is the last compressed file based on the serial number of the compressed file. If the compressed file is the last compressed file, it means that the slice data of all firmware slices of the target firmware have been written to the system partition. If the compressed file is not the last compressed file, it means that the slice data of some firmware slices of the target firmware have not been written to the system partition, and the terminal device needs to continue receiving the next compressed file until it is determined that the compressed file is the last compressed file.
[0176] When the data of all firmware slices of the upgrade package of the target firmware have been written to the system partition, it means that the target firmware in the terminal device has been upgraded.
[0177] The terminal device can have one or more operating systems. When the terminal device has one operating system, after the data of the multiple firmware slices have been written to the system partition, it means that the terminal device has completed the upgrade of the target firmware, that is, the version number of the target firmware has been updated. When the terminal device has multiple operating systems, if the operating system currently used by the terminal device is not the operating system where the target firmware is located, after the data of the multiple firmware slices have been written to the system partition of the operating system where the target firmware is located, the terminal device can be restarted to update the version number of the target firmware; if the operating system currently used by the terminal device is the operating system where the target firmware is located, there is no need to restart.
[0178] It should be noted that the MD5 mentioned above is the MD5 corresponding to a compressed file. That is to say, each compressed file in the multiple compressed files has a corresponding MD5. In practical applications, the server can also send the MD5 corresponding to the complete upgrade package of the target firmware to the terminal device before sending the multiple compressed files, so that after the terminal device completes the upgrade of the target firmware, it calculates the MD5 of the upgraded target firmware and compares the calculated MD5 with the MD5 corresponding to the complete upgrade package of the target firmware received. If the calculated MD5 is consistent with the received MD5, it means that the upgrade package of the target firmware is complete and the terminal device has completed the upgrade of the target firmware; if the calculated MD5 is inconsistent with the received MD5, it means that an error occurred during the transmission of the upgrade package of the target firmware or an error occurred during the firmware upgrade process, and it is necessary to return to step 203 to perform the firmware upgrade again.
[0179] In some embodiments, if there is sufficient remaining memory in the terminal device, that is, the size of the first memory space obtained by the server is not less than the size of the upgrade package of the target firmware, the server can also cut and compress the upgrade package of the target firmware, and then send all the compressed files to the terminal device. After the terminal device receives all the compressed files, it decrypts and decompresses the compressed files, and combines the data of the decompressed firmware slices into a complete upgrade package of the target firmware, and then upgrades the target firmware based on the upgrade package.
[0180] In the embodiments of the present application, the server obtains the size of the first memory space in the terminal device for firmware upgrade, and based on the size of the first memory space, cuts the upgrade package of the target firmware into multiple firmware slices and compresses them to obtain multiple compressed files, ensuring that the terminal device can store the compressed files in the first memory space, effectively guaranteeing the success rate of firmware upgrade; before the server and the terminal device transmit the compressed files, they determine the encryption keys corresponding to the multiple firmware slices respectively, and the encryption keys corresponding to the multiple firmware slices are all different, which can improve the security of the transmission process of the compressed files. Moreover, the terminal device decompresses the compressed files in multiple times while writing the decompressed content into the corresponding system partition, which can reduce the occupation of memory space. In summary, the method provided by the embodiments of the present application can enable the terminal device to achieve secure firmware upgrade when the remaining memory space is small.
[0181] Figure 3 FIG. is a schematic structural diagram of a server 300 provided by an embodiment of the present application. Please refer to Figure 3 The server 300 includes: a transceiver 301 and a processor 302.
[0182] The transceiver 301 is configured to obtain the size of the first memory space in the terminal device for firmware upgrade, and the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space;
[0183] The processor 302 is configured to cut the upgrade package of the target firmware into multiple firmware slices based on the size of the first memory space, and compress the multiple firmware slices respectively to obtain multiple compressed files;
[0184] The transceiver 301 is further configured to sequentially send the multiple compressed files to the terminal device so that the terminal device upgrades the target firmware; wherein, the size of each compressed file is not greater than the size of the first memory space.
[0185] Optionally, the processor 302 is specifically configured to:
[0186] Determine the cutting size based on the size of the first memory space and the reference compression ratio, where the reference compression ratio refers to the ratio of the file size before compression to the file size after compression;
[0187] Let \(i = 1\). According to the cutting size, cut out a firmware slice starting from the cutting position of the \((i - 1)\)-th time of the upgrade package to obtain the \(i\)-th firmware slice;
[0188] Compress the \(i\)-th firmware slice;
[0189] If the size of the compressed \(i\)-th firmware slice is greater than the size of the first memory space, reduce the reference compression ratio, and return to the step of determining the cutting size based on the size of the first memory space and the reference compression ratio;
[0190] If the size of the compressed \(i\)-th firmware slice is less than or equal to the size of the first memory space and the upgrade package has not been completely cut, determine the compressed \(i\)-th firmware slice as a compressed file, let \(i = i + 1\), and return to the step of cutting out a firmware slice starting from the cutting position of the \((i - 1)\)-th time of the upgrade package according to the cutting size.
[0191] Optionally, the processor 302 is further configured to:
[0192] Determine the encryption keys corresponding to the multiple firmware slices respectively, and the encryption keys corresponding to the multiple firmware slices are different;
[0193] Encrypt the multiple compressed files respectively according to the encryption keys corresponding to the multiple firmware slices.
[0194] Optionally, the processor 302 is further configured to:
[0195] For each firmware slice, send a random password to the terminal device;
[0196] Receive the random encryption vector sent by the terminal device;
[0197] Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0198] In the embodiments of the present application, the server cuts the upgrade package of the target firmware into multiple firmware slices and compresses them to obtain multiple compressed files based on the size of the first memory space used for firmware upgrade in the terminal device, ensuring that the terminal device can store the compressed files in the first memory space, effectively guaranteeing the success rate of firmware upgrade; before sending the compressed files, determine the encryption keys corresponding to the multiple firmware slices respectively, and the encryption keys corresponding to the multiple firmware slices are all different, which can improve the security of the transmission process of the compressed files.
[0199] It should be noted that: when the server 300 provided in the above embodiment performs firmware upgrade, only the division of the above functional devices is used for illustration. In practical applications, the above functions can be allocated to different functional devices according to needs, that is, the internal structure of the server 300 is divided into different functional devices to complete all or part of the functions described above. In addition, the server 300 provided in the above embodiment and the embodiment of the firmware upgrade method belong to the same concept. For the specific implementation process, please refer to the method embodiment, which will not be elaborated here.
[0200] Figure 4 FIG. is a schematic structural diagram of a terminal device 400 provided by an embodiment of the present application. Please refer to Figure 4 The terminal device includes: a transceiver 401, a memory 402, and a processor 403.
[0201] The transceiver 401 is configured to receive a plurality of compressed files sequentially sent by the server. The plurality of compressed files are obtained by respectively compressing a plurality of firmware slices. The plurality of firmware slices are obtained by cutting an upgrade package of a target firmware according to the size of a first memory space used for firmware upgrade in the terminal device. The size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space, and the size of each compressed file is not greater than the size of the first memory space.
[0202] The memory 402 is configured to store the compressed file in the first memory space whenever a compressed file is received.
[0203] The processor 403 is configured to decompress the compressed file in multiple times. Whenever a part of slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.
[0204] Optionally, the processor 403 is specifically configured to:
[0205] Read the file list of the compressed file, where the file list is used to store the names of the respective files compressed in the compressed file.
[0206] If the file list includes the file name of the firmware slice to be currently decompressed, determine the offset position of the firmware slice to be currently decompressed in the compressed file.
[0207] Start from the offset position, read the content of the compressed file and decompress it.
[0208] If the size of the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing and call the write callback function to write the currently decompressed content into the system partition.
[0209] If all the content of the currently decompressed content has been written to the system partition, and the slice data of the firmware slice to be decompressed currently has not been completely decompressed, then starting from the last stop position, return to the step of reading the content of the compressed file and decompressing it.
[0210] Optionally, the multiple compressed files are encrypted compressed files; the processor 403 is further configured to:
[0211] Determine the encryption keys corresponding to the firmware slices compressed in the compressed file, and the encryption keys corresponding to the multiple firmware slices are different;
[0212] Decrypt the compressed file according to the encryption key corresponding to the firmware slice compressed in the compressed file.
[0213] Optionally, the processor 403 is further configured to:
[0214] Receive a random password sent by the server;
[0215] Send a random encryption vector to the server;
[0216] Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
[0217] In the embodiments of the present application, the terminal device decompresses the received compressed file in multiple times. Whenever a part of the slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware, which can reduce the occupation of the memory space. That is to say, even if the remaining memory of the terminal device is small, the upgrade of the target firmware can be realized. Moreover, before receiving the compressed file, determining the encryption keys corresponding to the multiple firmware slices respectively, and the encryption keys corresponding to the multiple firmware slices are all different, which can improve the security of the transmission process of the compressed file.
[0218] It should be noted that: when the terminal device 400 provided in the above embodiment performs firmware upgrade, only the above-mentioned functional devices are divided for illustration. In practical applications, the above functions can be allocated to different functional devices according to needs, that is, the internal structure of the terminal device 400 is divided into different functional devices to complete all or part of the functions described above. In addition, the terminal device 400 provided in the above embodiment and the embodiment of the firmware upgrade method belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0219] In some embodiments, a computer-readable storage medium is further provided. The storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the firmware upgrade method in the above embodiment are implemented. For example, the computer-readable storage medium may be a ROM, a RAM, a CD-ROM, a magnetic tape, a floppy disk, and an optical data storage device, etc.
[0220] It should be noted that the computer-readable storage medium mentioned in the embodiments of the present application can be a non-volatile storage medium, in other words, it can be a non-transitory storage medium.
[0221] It should be understood that all or part of the steps for implementing the above embodiments can be realized by software, hardware, firmware or any combination thereof. When implemented by software, it can be realized in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The computer instructions can be stored in the above computer-readable storage medium.
[0222] That is, in some embodiments, a computer program product containing instructions is also provided. When it runs on a computer, it causes the computer to execute the steps of the firmware upgrade method described above.
[0223] It should be understood that the "at least one" mentioned herein refers to one or more, and the "multiple" refers to two or more. In the description of the embodiments of the present application, unless otherwise specified, " / " means "or". For example, A / B can represent A or B; the "and / or" herein is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, in order to clearly describe the technical solutions of the embodiments of the present application, in the embodiments of the present application, terms such as "first" and "second" are used to distinguish the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the terms "first", "second", etc. do not limit the quantity and execution order, and the terms "first", "second", etc. do not necessarily limit to be different.
[0224] It should be noted that the information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.) and signals involved in the embodiments of the present application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of relevant countries and regions.
[0225] The above are the embodiments provided by the present application, which are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A firmware upgrade method, characterized in that, The method includes: Obtaining the size of a first memory space for firmware upgrade in a terminal device, where the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space; Based on the size of the first memory space, cutting an upgrade package of a target firmware into multiple firmware slices, and respectively compressing the multiple firmware slices to obtain multiple compressed files; Sequentially sending the multiple compressed files to the terminal device to enable the terminal device to upgrade the target firmware; wherein, the size of each compressed file is not greater than the size of the first memory space.
2. The method according to claim 1, characterized in that The step of, based on the size of the first memory space, cutting an upgrade package of a target firmware into multiple firmware slices, and respectively compressing the multiple firmware slices to obtain multiple compressed files, includes: Determining a cutting size based on the size of the first memory space and a reference compression ratio, where the reference compression ratio refers to the ratio between the size of a file before compression and the size of the file after compression; Let i = 1, and starting from the (i - 1)-th cutting position of the upgrade package, cutting out a firmware slice according to the cutting size to obtain the i-th firmware slice; Compressing the i-th firmware slice; If the size of the compressed i-th firmware slice is greater than the size of the first memory space, then reducing the reference compression ratio, and returning to the step of determining the cutting size based on the size of the first memory space and the reference compression ratio; If the size of the compressed i-th firmware slice is less than or equal to the size of the first memory space, and the upgrade package has not been completely cut, then determining the compressed i-th firmware slice as one of the compressed files, letting i = i + 1, and returning to the step of cutting out a firmware slice starting from the (i - 1)-th cutting position of the upgrade package according to the cutting size.
3. The method according to claim 1 or 2, characterized in that, Before sequentially sending the multiple compressed files to the terminal device, the method further includes: Determining encryption keys respectively corresponding to the multiple firmware slices, where the encryption keys corresponding to the multiple firmware slices are different; Respectively encrypting the multiple compressed files according to the encryption keys corresponding to the multiple firmware slices.
4. The method according to claim 3, characterized in that, The step of determining encryption keys respectively corresponding to the multiple firmware slices includes: For each firmware slice, sending a random password to the terminal device; Receiving a random encryption vector sent by the terminal device; Determining the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
5. A firmware upgrade method, characterized in that, The method includes: Receiving multiple compressed files sequentially sent by a server, where the multiple compressed files are obtained by respectively compressing multiple firmware slices, the multiple firmware slices are obtained by cutting an upgrade package of a target firmware according to the size of a first memory space for firmware upgrade in a terminal device, the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space, and the size of each compressed file is not greater than the size of the first memory space; Whenever receiving a compressed file, storing the compressed file into the first memory space; The compressed file is decompressed in multiple times. Whenever a part of the slice data is decompressed, the currently decompressed slice data is written into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.
6. The method according to claim 5, wherein The step of decompressing the compressed file in multiple times and writing the currently decompressed slice data into the system partition corresponding to the target firmware whenever a part of the slice data is decompressed includes: Read the file list of the compressed file, where the file list is used to store the names of the files compressed in the compressed file; If the file list includes the file name of the firmware slice to be currently decompressed, determine the offset position of the firmware slice to be currently decompressed in the compressed file; Starting from the offset position, read the content of the compressed file and decompress it; If the size of the currently decompressed content reaches the size of the content decompressed at one time, stop decompressing and call the write callback function to write the currently decompressed content into the system partition; If all the currently decompressed content has been written into the system partition and the slice data of the firmware slice to be currently decompressed has not been completely decompressed, start from the last stop position and return to the step of reading the content of the compressed file and decompressing it.
7. The method according to claim 5 or 6, characterized in that The multiple compressed files are encrypted compressed files; Before storing the compressed file into the first memory space, it further includes: Determine the encryption key corresponding to the firmware slice compressed in the compressed file, and the encryption keys corresponding to the multiple firmware slices are different; Decrypt the compressed file according to the encryption key corresponding to the firmware slice compressed in the compressed file.
8. The method according to claim 7, wherein The step of determining the encryption key corresponding to the firmware slice compressed in the compressed file includes: Receive the random password sent by the server; Send a random encryption vector to the server; Determine the random password and the random encryption vector as the encryption key corresponding to the firmware slice.
9. A server, characterized in that, The server includes: A transceiver for obtaining the size of the first memory space in the terminal device for firmware upgrade, where the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space; A processor for cutting the upgrade package of the target firmware into multiple firmware slices based on the size of the first memory space and compressing the multiple firmware slices respectively to obtain multiple compressed files; The transceiver is further configured to sequentially send the multiple compressed files to the terminal device so that the terminal device upgrades the target firmware; wherein, the size of each compressed file is not greater than the size of the first memory space.
10. A terminal device, characterized in that, The terminal device includes: A transceiver for receiving multiple compressed files sequentially sent by the server, where the multiple compressed files are obtained by compressing multiple firmware slices respectively, and the multiple firmware slices are obtained by cutting the upgrade package of the target firmware according to the size of the first memory space in the terminal device for firmware upgrade, the size of the first memory space is allocated by the terminal device based on the size of the current remaining memory space, and the size of each compressed file is not greater than the size of the first memory space; A memory for storing the compressed file in the first memory space whenever a said compressed file is received; A processor for decompressing the compressed file in multiple times, and whenever a part of sliced data is decompressed, writing the currently decompressed sliced data into the system partition corresponding to the target firmware to implement the upgrade of the target firmware.