Reprogramming Embedded Systems at Run-Time
Total Page:16
File Type:pdf, Size:1020Kb
Proceedings of the 8th International Conference on Sensing Technology, Sep. 2-4, 2014, Liverpool, UK Reprogramming Embedded Systems at Run-Time Richard Oliver, Adriana Wilde IEEE(S) and Ed Zaluska SMIEEE Electronics and Computer Science University of Southampton, United Kingdom {rjo2g10,agw106,ejz}@ecs.soton.ac.uk Abstract—The dynamic re-programming of embedded systems is load mechanisms. This paper aims to address the problem of a long-standing problem in the field. With the advent of wireless dynamic reprogramming of such systems, and will offer sensor networks and the ‘Internet of Things’ it has now become comparison and a critical appraisal of the methods currently necessary to be able to reprogram at run-time due to the being used in the field. difficulty of gaining access to such systems once deployed. The issues of power consumption, flexibility, and operating system The remainder of this paper is structured as follows. protections are examined for a range of approaches, and a Section II explains code execution on embedded devices, critical comparison is given. A combination of approaches is section III discusses various existing methods, focusing on the recommended for the implementation of real-world systems and issues of power consumption, flexibility of approach, and OS areas where further work is required are highlighted. protection. Section IV follows with conclusions and suggests future work in the area. Keywords-Wireless sensor networks; Programming; Runtime, Energy consumption II. BACKGROUND I. INTRODUCTION This section will cover the execution of code on microcontrollers. This is typically of no concern when flashing Embedded systems are pervasive in the modern world, a static image to a microcontroller but a greater understanding being found in systems as widely ranging as fridges, cars, is required to implement dynamic code loading. traffic lights, and industrial automation. In the past, embedded systems have relied on purpose-built chips or large and A factor of considerable importance is the addressing expensive circuits in order to implement their functionality. modes available for particular architectures. Two common Due to the availability of inexpensive microcontrollers addressing modes are absolute and relative addressing. With designed for use in embedded systems, much of the absolute addressing, jump instructions are provided with the implementation details of such systems has moved from the actual address in memory of the destination. With relative hardware to the software domain. A long standing problem in addressing, jump instructions are provided with an offset that is the field of embedded systems has been the reprogramming of added to the current value of the program counter. This is an such systems once deployed. Reprogramming is often required important distinction to make as, with an embedded system, the during the initial development of these systems, or to add new program may be loaded at any arbitrary position in program functionality and fix bugs once deployed [1], [2]. The memory. If relative addressing is used then this is not a relevance of this problem has been highlighted with the advent problem and the program is able to execute from any location of the ‘Internet of Things’ and wireless sensor networks in memory without any further changes. If absolute addressing (WSNs). Many of these systems will be difficult (or is used then the addresses must be changed to the correct impossible) to gain physical access to once deployed as well as values for the programs placement in memory before execution costly and labour-intensive if nodes are distributed over a wide occurs. Relative addressing can be used as a basis for Position- area, so methods must be devised if we wish to reprogram them independent code (PIC), whilst the use of absolute addressing [3], [4]. would be an example of relocatable code. When we consider this problem in the context of WSNs, it Another important factor is linking. The process of linking is important to realise that the programmers wishing to use the is required if the address of a symbol (variable or function) is network may not be embedded systems experts, so they may not known when the code is compiled (e.g., a call to a function lack an understanding of the underlying operating system (OS). provided by the operating system). If the application is Also, the research areas of the end-users can be as wide- compiled separately from the OS and the location of the ranging as biology and environmental engineering [4], [5], [6]. desired function in memory is unknown, then the device must Though this factor of accessibility for non-experts is arguably correctly insert the address of the function before execution. holding back the wider adoption of WSNs [3], [6], this paper Some embedded operating systems avoid the need for linking focuses more closely on the lower-level problems of embedded by providing a kernel ‘jump table’. The jump table is always at systems reprogramming such as power, speed, down-time, and the same address in memory and it contains the addresses of reliability [7]. There have been many different approaches any kernel-provided functions. In this way, linking becomes proposed that solve this problem including scripting languages unnecessary. An example of the relocating, linking, and [8], [9], virtual machines (VMs), and various run-time link and loading process is shown in Figure 1. 124 Proceedings of the 8th International Conference on Sensing Technology, Sep. 2-4, 2014, Liverpool, UK TABLE 1: FEATURE COMPARISON OF STUDIED METHODS Mechanism VM PIC Reloc. OS Protection Kernel Modification Kernel Replacement Loose Coupling Maté [11] ● ● ●1 TOSBoot [12] ● SOS [13] ● ● ● Contiki [1] ● ● ● RETOS [14] ● ● ● ● Darjeeling [15] ● ● ● SenSpire [10] ● ● ● Enix [16] ●2 1 Only if user-specified instructions are omitted. 2 Kernel-supported PIC intensive activities [7]. Also, when we consider reprogramming at run-time, we must consider if any CPU overhead exists (compared to native code) and whether rebooting the node is required (another power intensive operation). Levis et al. [11] emphasise the importance of power consumption as a “precious resource” in their development of Maté. Maté is an application-specific virtual machine (or bytecode interpreter) with a high-level interface allowing complex applications to be written in a small amount of code. Programs implemented with Maté are made up of one or more Figure 1. Dynamic linking and loading, adapted from [10] capsules. Each capsule can contain 24 instructions and is the size of a single TinyOS packet1. This approach greatly reduces III. ISSUES application upload energy requirements for certain applications with the most extreme example being gdi-comm, a program of To offer a critical comparison of the mechanisms available 7130 bytes, being expressed in a single Maté capsule. Maté, we will examine three issues in detail. These issues are power however, exhibits a significant CPU overhead per instruction consumption, flexibility of approach, and operating system issued because it is a virtual machine. This overhead varies protection. Table I lists the approaches that will be studied and depending on the complexity of the instruction issued with the gives an overview of the features of each approach. The two extremes being 33:1 for a logical and, and 1.03:1 for a mechanism by which code is executed is listed for each packet send. Besides making programs take longer to execute, approach as either virtual machine, position independent code, this also increases power consumption due to the CPU having or relocatable code. The flexibility of each approach is shown to remain powered for longer than it otherwise would before by the kernel modification, kernel replacement, and loose returning to sleep mode. Testing by Levis et al. [11] suggests coupling columns. An indication of whether the OS is that this CPU overhead outweighs the energy savings of the protected in any way from remotely programmed code is given concise capsules after running for six days. This figure will in the OS Protection column. These issues will be discussed in vary for different applications but it suggests that Maté is only detail in what follows. suitable for non-permanent changes to application code. A. Power Consumption Another approach, TOSBoot [12], is a full binary In the area of embedded systems (wireless sensor networks replacement mechanism. The core of the paper concerns the in particular), power consumption is often of critical Deluge data dissemination protocol; however, it is the importance. In the case of WSNs, where many of the devices TOSBoot bootloader that is used to re-image the device. This may be inaccessible, nodes may be expected to run for weeks mechanism, although flexible, is exceptionally power (if not months) entirely unattended. All efforts must therefore intensive. The image transmitted over the network must be made to minimise power consumption when implementing a contain the full operating system (including all libraries, remote reprogramming mechanism. Considerations must be applications, and deluge itself), and is written to external flash, made when making use of the packet radio and when writing to flash, as these are typically considered some of the most energy 1 TinyOS is the operating system that Maté is implemented on top of. 125 Proceedings of the 8th International Conference on Sensing Technology, Sep. 2-4, 2014, Liverpool, UK a power intensive operation. The node is then rebooted (also Brouwers et al. [15] present Darjeeling, a byte code power intensive), and TOSBoot copies the image from external interpretation approach, similar to that of Maté. Whereas Maté flash into program flash before executing the code, also energy has an application-specific instruction set, Darjeeling is intensive. This is certainly the most power intensive solution modelled after the Java VM and is a generic VM. As a result, discussed in this paper. Darjeeling programs will have a larger code size than Maté’s thereby causing more power to be used during program upload Another approach is the SOS operating system by Han et to the nodes.