Electronic devices often need software updates to correct bugs or to change or add device functionality. However, such devices are often distributed throughout a geographic region, which makes direct updating virtually impossible given time and resource constraints. For example, large numbers of electricity or other utility meters are distributed throughout many geographic regions and updating these devices directly (e.g., physically visiting each device and directly loading new software into the device) would be expensive and time-consuming. As other examples, other devices, such as cellular phones, personal computers, etc., can also be widely distributed, which makes direct updates impractical.
To overcome the issues associated with direct updates, if an electronic device is connected to a network (e.g., a local area network (“LAN”), a wide area network (“WAN”), a priority network, the Internet, and the like), an update can be transmitted to the electronic device over the network. However, there are numerous problems with using network-based updates. First, the device receiving the update must have a reliable connection to the network. If a device loses its connection to the network before receiving an entire update and tries to install an incomplete update, the device may not be properly updated and may malfunction. Similarly, if an update is large, it may take a long time for the device to receive the entire update, which can increase bandwidth requirements. In addition, if the device is battery-powered, the device may be required to be “turned on” during the entire updating process, which reduces the device's battery life. Also, until the entire update is received by the device, the device generally must continue to perform using current software. Therefore, devices generally must have sufficient memory to store current software and at least temporarily store any received updates. If the update is large, the memory requirements for the device may be increased, which increases the cost of the device.
Binary patching has been used to provide updates to electronic devices. In the binary patching process, a delta file is typically generated, and includes the differences between an original binary file and an updated binary file. The delta file can then be compressed into what is known as a patch, and the patch can be transmitted to a device. The device applies the patch to the original binary file stored in the device to generate the updated binary file. The device can then switch from executing the original binary file to the updated binary file. In some embodiments, the patch is smaller than both the original binary file and the updated binary file, which reduces update times and bandwidth requirements. However, binary patching generally requires that a device receive and store an entire patch before applying the patch. Therefore, the device must include adequate memory for storing an entire patch, which may vary in size depending on the degree of the update (i.e., the amount of difference between the original software and the updated software).
Based at least in part upon these and other limitations of existing software patching systems and methods, new software patching systems and methods are welcome additions to the art.
Some embodiments of the present invention provide methods, systems, and non-transitory computer-readable medium containing instructions for updating an electronic device using streaming packetized binary patching. Packetized streaming binary patching does not require the storage of the entire binary patch on the target device. Therefore, the device does not require additional memory allocations for storing an entire binary patch. In addition, by using packetized streaming binary patching, device updates can be performed using fewer resources, such as time, network bandwidth, and the device's battery life. Therefore, updates can be performed quickly and efficiently
In some embodiments, a computer-implemented method for updating an electronic device is provided, and comprises obtaining a binary patch for a binary image currently being executed by the electronic device; generating a plurality of packets based on the binary patch, wherein each packet is independent such that each packet can be applied by the electronic device to the binary image independent of applying the other packets to generate a portion of a patched binary image; and streaming each of the plurality of packets to the electronic device over at least one network.
Some embodiments of the present invention provide a system for updating an electronic device, wherein the system comprises a server configured to obtain a binary patch for a binary image currently being executed by the electronic device, to generate a plurality of packets based on the binary patch, wherein each packet is independent such that each packet can be applied by the electronic device to generate a portion of a patched binary image independent of applying the other packets, and to stream each of the plurality of packets to the electronic device over at least one network.
In some embodiments of the present invention, an electronic device configured to execute a binary image is provided, and comprises a processor and an input/output interface. The input/output interface is configured to receive a stream of a plurality of binary patch packets from at least one server, each of the plurality of binary patch packets being generated by the server based on a binary patch and being independent such that each packet can be applied by the electronic device to the binary image independent of the other packets. The processor is configured to apply each of the plurality of binary patch packets to the binary image to generate a portion of a patched binary image and, when the processor has applied each of the plurality of binary patch packets, replace the binary image with the patched binary image.
Some embodiments of the present invention provide a non-transitory computer-readable medium including executable instructions for updating an electronic device, wherein the medium comprising instructions for: obtaining a binary patch for a binary image currently being executed by the electronic device; generating a plurality of packets based on the binary patch, wherein each packet is independent such that each packet can be applied by the electronic device to the binary image independent of applying the other packets to generate a portion of a patched binary image; and streaming each of the plurality of packets to the electronic device over at least one network.
Other aspects of the invention will become apparent by consideration of the detailed description and accompanying drawings.
Before any embodiments of the invention are explained in detail, it is to be understood that the invention is not limited in its application to the details of construction and the arrangement of components set forth in the following description or illustrated in the following drawings. The invention is capable of other embodiments and of being practiced or of being carried out in various ways. Also, it is to be understood that the phraseology and terminology used herein are for the purpose of description and should not be regarded as limiting. The use of “including,” “comprising,” or “having” and variations thereof herein are meant to encompass the items listed thereafter and equivalents thereof as well as additional items. Unless specified or limited otherwise, the terms “mounted,” “connected,” “supported,” and “coupled” and variations thereof are used broadly and encompass both direct and indirect mountings, connections, supports, and couplings.
In addition, it should be understood that embodiments of the invention may include hardware, software (including firmware) and electronic components or modules that, for purposes of discussion, may be illustrated and described as if some, a majority, or all of the components were implemented solely in hardware. However, one of ordinary skill in the art, and based on a reading of this detailed description, would recognize that, in at least one embodiment, electronic based aspects of the invention may be implemented in software (e.g., stored on non-transitory computer-readable medium). As such, it should be noted that a plurality of hardware and software based devices, as well as a plurality of different structural components, may be utilized to implement the invention. Also, although reference is made herein to software being executed or adapted for execution, it will be appreciated that the present invention applies equally to firmware and firmware updates.
The network 16 can include a local area network (“LAN”), a wide area network (“WAN”), the Internet, other geographic or proprietary networks, or any combination thereof. Also, the network 16 can be constructed from wired connections (e.g., telephone connections, cable connections, fiber optic connections, etc.), wireless connections, or any combination thereof.
The processor 20 retrieves and executes instructions stored in the computer-readable medium 22. The processor 20 can also store and retrieve data to and from the computer-readable medium 22. The computer-readable medium 22 can include non-transitory computer readable medium and can include volatile memory, non-volatile memory, or a combination thereof. In some embodiments, the computer-readable medium 22 includes a disk drive or other types of large capacity storage mechanism. The computer-readable medium 24 can also include a database structure that stores data processed or otherwise obtained by the server 14.
The input/output interface 24 receives information from outside the server 14 and outputs information outside the server 14. For example, the input/output interface 28 can include a network card or adapter, such as an Ethernet card or a wireless network card that allows the server 14 to send and receive information over the network 16.
The processor 32 retrieves and executes instructions stored in the computer-readable medium 34. As described below with respect to
The input/output interface 36 receives information from outside the device 12 and outputs information outside the device 12. In some embodiments, the input/output interface 36 includes a network interface controller (“NIC”) that includes a network card or adapter, such as an Ethernet card or a wireless network card, that allows the device 12 to send and receive information over the network 16. The input/output interface 36 can be plugged into the system bus 38 or can be built into the device's motherboard. The input/output interface 36 can implement the electronic circuitry required for the device 12 to communicate with the network 16 using a specific physical layer (OSI layer) and data link layer standard, such as Ethernet, Wi-Fi, or Token Ring. In some embodiments, the input/output interface 36 includes a processor and computer-readable medium and is configured to perform streaming packetized binary patching. Throughout the present application, functionality may be described as being performed by the electronic device 12 through the processor 32, but it should be understood that the functionality can be performed by input/output interface 36, the processor 32, or both. Also, in some embodiments, the processor 32 is included in the input/output interface 36.
The electronic device 12 executes a compiled binary image that is stored in the computer readable medium 34. Each binary image can contain the operating system for the device 12, networking stacks, and administrative applications for performing functionality, such as binary image management and diagnostic statistics. If the device 12 includes a metering device, the binary image can also include metering applications for handling metrology data.
In some embodiments, the electronic device 12 stores two or more distinct binary images in the computer-readable medium 34 (e.g., flash memory), one of which is the image currently being executed. The other image can include an old binary image or a new binary image that the device 12 is not currently executing.
In existing systems, to upgrade (or downgrade) a device's binary image (e.g., from version A to version B), the server 14 would issue a series of commands over the network 16 to the electronic device 12 to remove all binary images except the binary image currently being executed (i.e., version A). After removing all images except for the image being executed, the device 12 would continue to execute the image already being executed, which would be the only image stored in memory. The server 14 would then issue an additional series of commands to the device 12 and would transmit a new binary image (i.e., image version B) in its entirety to the device 12 over the network 16. After this process, the device's memory would include both the image currently being executed and the new image (i.e., both version A and version B of the image). The device 12 would then be instructed (e.g., by the server 14 via rebooting) to execute the new binary image (i.e., image version B), which completes the upgrade.
Alternatively, binary patching can be used to update the device 12. As shown in
As identified above, there are various pitfalls and costs associated with the updating processes described above. First, sending an entire new image to a device 12 can require relatively large bandwidth resources, time, and memory allocations. Using binary patching can relieve some of these issues, as a binary patch is typically smaller than a complete new image. However, sending a complete binary patch can still impose large memory requirements on a device, as the entire binary patch must be stored until it can be applied. Furthermore, although binary images are atomic (e.g., there are logical divisions in the code for different functionality), one portion of a binary image cannot typically be updated to change one aspect of the image, such as metering functionality. Rather, the entire image must be updated when performing an update. However, from version to version, the entire binary image does not change, even though an update is applied to the entire image.
To address these issues, embodiments of the present invention use streaming packetized binary patching to perform device updates. Using this updating process, individual binary patch packets are generated and transmitted to the device 12 (i.e., the input/output interface 36), rather than transmitting a complete binary patch. The packets are generally smaller than the corresponding complete binary patch, which reduces the device resources required to perform updates.
As compared to
After the patcher generates the packets, the patcher streams each packet to the patchee. Upon receiving each packet, the patchee applies the packet to the original or currently executed image to create a partially patched binary (i.e., a portion of an updated or patched binary). The patchee can then disregard the applied packet (e.g., can overwrite the applied packet with the next received packet) without storing the applied packet for any future use. The patchee continues to receive packets in this manner until all of the packets have been received and applied. After all of the packets have been applied, the patchee will have a complete patched binary image that includes the individual portions generated by each packet. The patchee can then switch to the patched binary image to complete the update.
The patch generated by the bsdiff application generally has three disjoint logical sections that are concurrently accessed during the patching process. Each logical section is compressed using BZ2 compression. As provided, however, bsdiff and bspatch require that the entire patch be present and stored on the target device before the patch application process occurs. In particular, after a device receives an entire patch generated by the bsdiff application, the bspatch application (or other code preprogrammed in the device 12) decompresses the patch and reads and applies each logical section found in disparate locations in the patch. Therefore, using bspatch requires that the entire patch be stored on the target device, which constrains the target device's memory. Furthermore, once the patch is uncompressed, it is even larger (e.g., sometimes even larger than the image to which it is to be applied), which creates even further memory constraints. Also, because bspatch uses BZ2 compression, the target device must include hardware, software, and/or firmware for performing BZ2 decompression. If the target device does not include this functionality, this functionality must be downloaded to the device (e.g., with the patch or separately), which creates additional download costs and memory constraints.
Therefore, returning to
Uncompressed, the control block contains a series of 3-tuples (i, j, k) that are interpreted by the bspatch patching process in the follow manner:
i—read the next i bytes from the diff block and arithmetically add them to the next i bytes of the old image (an offset into the old image is kept throughout the bspatch patching mechanism). These summed i bytes are the next i bytes of the new image.
j—read the next j bytes from the extra block. These j bytes are the next j bytes of the new image.
k—move the offset into the old image by k bytes. No new bytes are contributed to the new image.
During the patch application process performed by bspatch, a simple state machine loops over all 3-tuples until the entire control block is consumed, at which time the patch is fully applied. The conversion utility (referred to as “Patch_gen” below) implements a similar state machine, but instead of applying the patch to the original image, it rewrites the patch in a different format. For example, for each 3-tuple encountered, the streamed patch file looks as described below.
For the i parameter of the 3-tuple, the following is inserted into the new patch:
Here, the ipo_op field is set to be IMG_MGMT_PATCH_OP_ADD. The ipo_len field, same as i, is the number of bytes after the ipo_off field. The ipo_off field is the offset into the old image file that is used. At that offset, ipo_len bytes are read from the old image, and are added to the ipo_len bytes at the ipo_data field. The resultant summation becomes the next ipo_len bytes of the new image.
For the j parameter of the 3-tuple, the following is inserted into the new patch:
Here, the ipo_op field is set to be IMG_MGMT_PATCH_OP_EXTRA. The field ipo_len, same as j, is the number of bytes in the ipo_data location. The ipo_len bytes of data at ipo_len are the next bytes of the new image.
For the z parameter of the 3-tuple, nothing is introduced into the new patch. An internal state tracks where the old image file pointer is, and uses the current value when needed in the img_mgmt_patch_op_add structure.
In addition, since the patch is packetized and streamed, packet size (compressed and uncompressed alike) is taken into account as the struct img_mgmt_patch_op blocks are written to the new file. One value of i or j could be so large that it would exceed a maximum packet length constraint. In such cases, a series of struct img_mgmt_patch_op structures are written to the new patch such that the overall patch can be packetized into acceptable lengths. Therefore, the complete file format of the streamable patch is as follows:
After this process, the packet is ready to be sent with the exception of a packet header and any compression applied to the payload. Because the computation of the compressed packet boundaries can continue for a few minutes, the packet boundaries of the patch can be computed and serialized in advance.
As shown in
In some embodiments, the server 14 also compresses the patch packets to decrease patch packet size (at 78 in
Returning to
Returning to
After the packet has been applied (and the resulting portion of the patched binary image has been stored to memory), the packet can be discarded, and does not need to be stored in the device's memory for any future use. Accordingly, the packet can be erased from the buffer, or the input/output interface 36 may simply overwrite the packet with the next packet received from the server 14.
As shown in
As described above, using streaming packetized binary patching can reduce resources needed for performing a device update. For example, the device 12 only needs to store a packet as it is being applied, and then can disregard the packet. Therefore, the memory requirements on the device 12 are lessened. Furthermore, using streaming packetized binary patching can decrease the time required to perform a device upgrade (or downgrade). For example, when a complete binary patch is download or transmitted to the target device, network loss or unavailability may require the entire patch download or transmission to be restarted. However, if individual patch packets are streamed to the device, network loss or unavailability may only require individual packets to be retransmitted, rather than retransmitting the entire patch.
It should be understood that the computer code included in this application is provided as an example of what the code and data structures may look like for performing streaming packetized binary patching. Other code formats, structures, and languages and other variable names and data structures may be used to perform packetized binary patching as described in the present application.
Various features and advantages of the invention are set forth in the following claims.