Design of Universal Bootloader Based on ARM
【Summary】
Among the embedded systems, the system architecture can generally be divided into three parts: boot loader, kernel, application. The bootloader works in the best of the system, serving the kernel start, and the application system development. Therefore, it is very important to design a reliable bootloader. This article mainly focuses on the design ideas and implementation techniques of common guidance loading procedures. In addition, based on the in-depth understanding of the working principle of the bootloader and the system startup process, the author has developed a hardware test technology that is different from traditional, efficient, dependent bootloaded software.
Key word Linux ARM boot loader U-boot
1 Introduction
With the advancement of the informationization process, the embedded system is widely used in the field of information terminal, industrial control and information home appliances in the field of information terminal, industrial control and information appliances such as software and hardware. A variety of microprocessors using ARM technology IP cores throughout the various product markets. ARM technology is widely used in embedded systems, and almost all major semiconductor vendors in the world produce universal chips based on ARM architectures. It can be said that ARM technology is everywhere. In addition, running GNU / Linux on the embedded development board has become more and more popular, ARM Linux's widespread application makes some implementation, application and support around it a popular research direction. A standard embedded system model can be divided into three parts: bootloader, kernel, application; briefly, bootloader is a small program running before operating the operating system kernel. Through this small program, initialize the necessary hardware devices, create some information required to create the kernel, thereby bringing the software hardware environment of the system to a suitable state, eventually calling the operating system kernel, playing the role of booting and loading the kernel [1] . In addition, bootloader is also a choice for consideration in terms of hardware test tools of embedded systems. Traditional hardware tests are based on JTAG emulation equipment, and the debugging process is complex, there is limitations. The author believes that as long as the partial peripheral driver is appropriately developed in BootLoader, the author can fully meet the maintenance requirements of external equipment, this hardware test method is independent of JTAG test, practical, simple, almost Without external hardware restrictions, a new hardware test method can be formed.
2 Feasibility analysis of universal bootloader
The bootloader is the first code that is running after the system is powered. The boot procedures in our familiar PC are composed of BIOS and OS Bootloader (Lilo or GRUB) located in MBR. However, in the embedded system, there is usually no firmware program like the BIOS, so the load start task of the entire system is done by bootloader. BootLoader is severely implemented in hardware, especially in an embedded system. BootLoader, which needs to be different architectures, is different; in addition to the architecture, BootLoader also depends on the configuration of a specific embedded plate-based device. That is to say, for two different embedded panels, even if they are constructed based on the same CPU, the bootloader running on one of the plates is not necessarily running on another. However, we can still summarize some universal concepts for bootloader, especially for a particular architecture.
After the system is powered or reset, all CPUs typically take instructions from a certain address pre-arranged by the CPU manufacturer. For example, the CPU based on ARM7TDMI CORE is typically taken from the address 0x00000000 from the address 0x00000000 when reset [2]. CPU-based embedded systems typically have some type of solid state storage device (such as ROM, EEPROM or FLASH, etc.) being mapped to this pre-arranged address. Therefore, after the system is powered up, the CPU can first execute the bootloader program. The software programming interface between the different architectural CPUs is very different, and it is difficult to achieve a certain difficulty, but the CPU of the same architecture is made to achieve a general purpose operation. Bootloader is possible, with the CPU of the ARM structure as an example, all the ARM7 and ARM9 system follow the same startup process, start executing from 0x00000000 after the system is reset, the CPU works in the system state, you need to close all external interrupts, turn off the watchdog timing Merger, set the clock source, initialize the dynamic memory, set the PLL parameter, self-loaded into the dynamic memory run, to initialize external devices such as serial port, network card, provide a user interface or directly load the kernel. Moreover, for the design of General BootLoader, the hardware range processed by BootLoader is minimized, using the method of isolating the difference between the hardware structure, modular and staged starting source code, put more functions At the same time as much as possible. This series of design technologies implements a BootLoader that is substantially generally used in the ARM structure CPU. 3 Isolation Technology of Hardware Differences in BootLoader
The most complex and maximum change in bootloader is to handle hardware details, and any two types of CPUs always have a certain difference. Especially in the embedded field, the diversified application demand determines that any processor is impossible to compete for all applications. At the same time, the market has also derived a lot of different models of CPUs in order to meet the needs of different levels of users. As the design goal of the General BootLoader, more hardware should be supported as much as possible, then the differences on these hardware details must face. For the CPU of the ARM structure, these differences are mainly reflected in the program access interface. For example, the address of the SDRAM controller register group and its respective function definitions, parameters supported by PLL. For embedded systems, more important differences are present in a diverse peripheral device, such as SDRAM operating parameters, LCD controller register group, Flash chipset, serial port controller, etc. However, they have many important common situations, such as machine instructions, startup steps, CPU internal register groups (R1-R15), MMU, etc. It is based on these common points, coupled with special technical means, shielding the differences in hardware details, and implements a general BootLoader in accordance with the minimization design principles.
Currently, hardware differential isolation techniques that are often used in accordance with the needs, basically can be divided into compile time isolation technology and runtime isolation technology. The compile time isolation technology is simple, but the lack of flexibility, the difference in hardware is essentially integrated with the program body, and the source code needs to be obtained in the case where the hardware changes, and recompiles to match hardware differences. The core of compile time isolation technology is to use a unified CPU description system, abstract the description system from the code, forming a module that does not depend on any other part, the program body has restricted access to the module, through which The access interface is provided to obtain specific descriptions for the CPU. The implementation scale of the module can be large according to different occasions, which can be simply only one CPU definition header, or can be complex to several C files and several header files. In the actual combination of minimization design principles, a CPU description header file can meet most of the needs. The key to implementation is that a unified, inclusive, moderate CPU description system must be defined. Another runtime isolation technology has considerable flexibility, and you can support several CPUs without any changes to the program entity. Of course, it is relatively complex in the application, and more implementation technology is relatively more. In the implementation, more common three design methods include parameter blocks, function pointers, inheritance in object-oriented design, and integrated use of these three methods. The parameter block is similar to the environment variable of the process in the operating system, records the CPU-related information in a structured manner, and can even be a general array, pass the starting address of the parameter block to the program main body, and the program body is followed by protocol pair Parameter blocks are accessed. The function pointer is not much different from the parameter block. The main difference is that the parameter block passes the data, and the function pointer passes the code. The function implementation is divided into combined language functions and C language functions. The combined language function is not special. The C language function must be required to set the stack area first. The concept of inheritance is used to bootloader is a further extension of object-oriented design ideas. Generally speaking, most of the projects can benefit from object-oriented ideas. BootLoader uses the optimal occasion of inheritance and object-oriented design ideas that the equipment driver and protocol stack, you can use the design model of the Linux device driver access interface, define a set of standards that are similar to the system call, and the device driver is responsible for processing physics The device and the logic device to the program body, and the program body is accessed by a unified function interface, and the access object to the physical device is implemented in a logical device. The hierarchical design of the network protocol stack is an excellent case for object-oriented ideas, and there are many logical entities in the agreement to be represented by an object. For example, the TFTP protocols commonly used in Bootloader, the existing protocol logic entities have TFTP, UDP, IP, Frame. Combined with hierarchical design, each entity is responsible for encapsulating the corresponding protocol head and protocol content corresponding to the package, providing the corresponding access interface, an internal implementation of the upper hidden entity, providing a program access interface so that the upper entity can utilize the service of the lower entity. Finally, combine these three technologies to play a collaborative advantage, overcome their respective defects to get better design implementation. 4 BootLoader modular design technology
Modular design technology has been widely used in the development of various large application systems, and modular design is the benefits of project implementation. The system is structural, the development process is clear, and the code is easy to maintain. Applying modular design technology in system software or underlying software such as Bootloader is one of the important means of developing universal BootLoader software. This technology generally divides the bootloader as a separate, granularity, and the modules are designed with loosely, hierarchical combination. During the development process, according to the module, it can be completed in the order, the base module is implemented and commissioned in the development, and then completes other modules. A universal bootloader can be divided into several modules: CPU reset module, SDRAM configuration module, kernel boot module, hardware drive module, hardware debug module, network protocol module, user interaction interface. For the CPU reset module, any other module must work after it is complete, so it is necessary to implement and debug it first, it is necessary to complete the CPU reset, including the identification of the CPU model, turn off the external interrupt, set Clock source, GPIO, PLL and related register groups, and then the SDRAM configuration module takes over the following work to end the life of this module. For the SDRAM configuration module, it only needs to understand the CPU has been working in a certain state. It is currently based on the SDRAM chip specification to set the SDRAM controller operating parameters, such as memory width, new frequency, new frequency, and access timing cycles. Signal, then move the bootloader to SDRAM, set the PLL parameter to increase the CPU frequency, bus frequency, and peripheral frequency, so that the software runs in SDRAM. With the normal work of these two modules, a minimized startup program has been completed, and its work is implemented on demand. It can be seen that modular design technology has a key role in simplifying software design, reducing difficulty, and accelerating development progress. 5 bootloader stage design technology
Staged Design is a special technique for Bootloader, and other engineering projects have not raised the design idea to a height of design patterns, almost all boot loaders are using this technology, including the first phase of the PC system is completed by BIOS. The second phase is completed by the MBR. There are usually two phases start, and there are three stages of startup. The central idea of staged design is to divide a differentiality between the time and different stages into two or more stages, and each stage is solved relatively independent, concentrated issues, while doing it for the next stage. Preparation. The latter stage works on the previous stage, but does not show any services provided, which is different from the modular design and hierarchical design. Any work can be divided into several phases, but not booting loading software is so obvious. The BootLoader in the embedded system is even more commonly used, and the code is divided into two phases according to what stored media. In the first stage, it runs on the Flash or ROM, handover some of the necessary initialization transactions, hand over control, in order to achieve short and delicate purposes, this stage adopts assembly language, and bootloader is necessary to use hardware difference isolation technology Get better versatility. The second stage is running on the SDRAM, in addition to using the CPU and SDRAM provided by the first phase of the determined state, there is no meguchi in the first stage, and the work made in the first phase can be repeated here, this stage is mainly processed. Peripheral devices such as serial ports, guide kernel, flash programming, network transmission and user interaction interface, etc., can combine the code structure of modular design technology and object-oriented design ideas, using C language development code to get good Readability and portability [3]. Staged design techniques should be used in conjunction with the two techniques mentioned above, and the benefits of using these three technologies separately are limited. In addition, the use of these three technologies has not been unchanged, and it is necessary to use the best effect in the design. 6 BootLoader hardware test application technology
6.1 Analysis of the principle of Bootloader hardware test
Recently, the development of hardware test technology is very fast. As a chip-level testing technology, JTAG standard has been widely used in embedded system development. The JTAG standard specifies that each pin of the digital integrated circuit corresponds to one or more mobile register units, called the boundary scanning unit BSC. It connects the JTAG circuit to the kernel logic circuit while isolating the kernel circuit and chip pin. All boundary scanners of the integrated circuit constitute the boundary scan register BSR, which is only valid when performing the JTAG test, is invalid when the integrated circuit is working properly, does not affect the operation of the integrated circuit [4]. JTAG technology is currently the most effective test method that tests logic and chip logic in the chip, but unfortunately, this technology requires other auxiliary facilities, complex test technology, not suitable for simple occasions. After understanding the BootLoader working principle, the author thinks that bootloader can test hardware devices, especially chip logic testing.
The ARM architecture regulates the unified address of the system memory area and I / O regions. From the perspective of software, any hardware access to memory is consistent, and the hardware's control / status register group is equivalent to a memory unit. Take up one or more memory addresses. With this feature, combined with hardware drive implementation, the appropriate user control interface can be completed to complete the hardware.
6.2 Test the Ethernet card with Bootloader
Ethernet cards play an important role in the research and development of embedded systems, allowing Ethernet cards to work and must be guided by the bootloader. Ethernet card usually integrates MAC sub-layers and physical layers, from software programming requires a network card's working mode, physical layer parameters, and packets. In order to test the network card, the author implements a series of console commands, including: (1) xor implementation of a certain bit or calculation of the register
(2) AND implementation of a bit of work and operations of the register
(3) OR implementation of a bit or operation of the register
(4) NO achieves a certain bit of register
(5) send a message to the internal FIFO of the MAC sublayer
(6) Receive Removes a message from the internal FIFO from the MAC sublayer
(7) Malloc and Free implementation global stack storage management
With these console commands, the combination of the NIC driver, refer to the Ethernet card chip manual, you can configure an Ethernet card, access the card, and view the device interrupt status, and control the message.
In addition to the Ethernet card, bootloader can also support other peripheral tests. This test method does not require other facilities such as simulators, the integrated debugging environment, low test cost, high test efficiency, meets the problem of chip logic test requirements, and it has the advantages of closer to real running parameters, which is different from JTAG test A test technology.
7 Conclusion
Faced with more and more different hardware in the market, even a very common bootloader is hard to do. GM does not mean universal. Under existing technical conditions and market selection, a unified embedded CPU architecture is almost impossible. Different embedded CPUs are different, it is impossible to design a way to all applications. All the Surge CPUs. To this end, it is extremely important to design a general BootLoader to the development of embedded systems. While it is impossible to support all embedded CPUs, it brings excellent code structure, concise extension interface, fast development cycle, and supports a wide range of embedded CPUs. These advantages make it easier to transplant to other embedded CPUs, thereby enters a benign cycle. Hardware detail difference isolation technology, modular and stage design technology is currently widely used in design techniques, but the use of these three technologies is not a constant, only technical constant innovations and cross-integrated use of technology can be solved Various problems. Using bootloader to hardware testing is a very effective way to have a technically developed and innovative application, which is a very effective means on peripheral hardware testing, accurate test results, no emulator support, and does not damage hardware equipment.
The design of the general bootloader based on ARM
Abstract
In any embedded system application, the system architecture can be divided into three parts:.. Bootloader, Kernel, and Application Bootloader works at the bottom of the architecture stack, and facilitates kernel booting, also application development It is very important to implement a reliable bootloader. This paper will mainly focus on the general bootloader design and implement. Otherwise, based on the deeply understanding of the principle and the process of booting, the author discovers a new efficient technology for testing peripheral, which is different with the classic peripheral hardware Testing method.key Words Linux ARM Bootloader U-boot