## 2 BsDiff Theory  
The main purpose of OTA software upgrades is to effectively distribute the software files that need to be updated and to update and deploy the files that need to be upgraded to hardware devices. The BsDiff and Bspatch algorithms can realize the above process and can be used for the difference and restoration between old and new files. BsDiff generates the required upgrade patch, and the OTA update is completed through the Bspatch algorithm. The BsDiff and Bspatch algorithms are used to determine the difference and regression between the old and new files. The BsDiff algorithm searches for an identical data segment using the suffix array generation algorithm and attempts to expand the approximate but not identical data segment forward and backward. The BsDiff algorithm comprises two parts: a similarity part, which calculates the increment by subtracting the data, and a differential part, which is inserted into a new data segment using an insert command. The Bspatch algorithm generates new binaries by directly editing old binaries and opening new memories to record the results. Because the Bspatch restoration algorithm performs simple calculation operations, an improvement in its restoration performance has little impact on the overall upgrade efficiency. Therefore, this study conducted in-depth research on the BsDiff algorithm for the differential process. Figure 2 illustrates the principle of the BsDiff algorithm. The algorithm compares the old[scan + offset... scan + offset + len - 1] and new[scan... scan + len - 1], which have a maximum matching length of more than 8 bytes, such as \"hello\" for input and \"world\" for output. BsDiff divides the previous \"perfect match region\" and at least 8-byte \"imperfect mismatch regions\" in linear time, with at least 50% mismatch between their forward and backward expansion fields. The \"perfect matching region\" and \"imperfect matching region\" together constitute the \"approximate matching region.\" The interval between the two \"approximate match regions\" forms the \"completely mismatched area,\" which is called the extract string. Figure 2: BsDiff theory. The BsDiff algorithm finds the longest common string between the old and new files by constructing a suffix array of old binary files to extract the difference between the old and new files [20]. BsDiff then represents the difference between the old and new binary files through a series of editing operations; the recorded editing operations are called differential files. When the old and new files differ, the \"imperfect match zone\" contains a large number of identical values, and value subtraction results in diffi, a string containing a large number of zero values. Based on the compression properties, diffi can be compressed to a very small size using the BZIP tool. Similarly, extractj is the \"completely mismatched region\" data that can be copied directly to the new address. The difference file of the BsDiff algorithm is combined with diffi and extractj for replication and insertion, respectively. The data format of the difference file is composed of four parts: the data header, control data, diff data, and extracted data, as shown in Figure 3. Control data <x; y; zk> record diffi bytes, extractj bytes, and offsets relative to the old file, respectively. When restoring the differential file, Bspatch reads the copy and inserts the information according to the control instructions to complete the modification. The BsDiff algorithm determines the maximum approximate matching data segment length by generating suffix arrays of the old and new version files. The length of the matching string is increased by extending the forward and backward areas. The longer the block length of the string, the fewer the replication and insertion operations during packet processing; thus, the number of bytes in the control area can be effectively reduced. This approach enables the BsDiff algorithm to obtain the desired subpackage size; however, the response time is long.