A novel Bootloader design

Publisher:好的哎Latest update time:2011-09-19 Keywords:Bootloader Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

This paper designs a novel Bootloader based on Microchip's MPLAB software development environment , and compiles a PC-side host computer interface program. Its features are flexible control, convenient use, and safe and reliable system upgrades.

1 Bootloader Implementation

1.1 Bootloader Operation Mode

The bootloader runs after the microcontroller is powered on/reset and before the user program is run. After running, it determines whether it needs to enter the upgrade state. If it does not need to be upgraded, it will directly run the original program; if it needs to be upgraded, it will first erase the old program, then receive the user program from the serial port and write it to the Flash. The bootloader has two operating modes:

① Boot loading mode, also known as "kernel boot" mode. That is, the Bootloader loads the operating system from a solid-state storage device on the target machine into RAM for execution, and the entire process does not involve user intervention.

② Download mode. In this mode, the Bootloader on the target machine will download the operating system file from the host computer through the serial port, network connection or USB, and then save it to the Flash solid-state storage device on the target machine. This mode of Bootloader is usually used when the kernel and root file system are installed for the first time. In addition, future system updates will also use this working mode of Bootl-oader.

The Bootloader designed in this paper supports both working modes. It is in normal boot loading mode at the beginning, but does not immediately boot into the kernel. Instead, it prompts a delay of 3 seconds. If the host computer user sends some information to the target machine, it switches to download mode, otherwise it continues to boot the kernel.

1.2 Intel HEX File

Intel HEX files are ASCII text files consisting of lines of text that conform to the Intel HEX file format. In an Intel HEX file, each line contains a HEX record. These records consist of hexadecimal coded numbers corresponding to machine language codes and/or constant data. Each record contains 5 fields: the data length field, which represents the number of data bytes in the record; the address field, which represents the starting address of the data in the record; the field representing the HEX record type; the data field, which represents a byte of data. A record can have many data bytes. The number of data bytes in the record must match the number specified in the data length field; the checksum field, which represents the checksum of the record. The checksum is calculated by adding the values ​​corresponding to all the hexadecimal coded numbers in the record and dividing them modulo 256. The two's complement of the remainder is the checksum.

1.3 Bootloader Design

The compiler used in the Bootloader program designed in this paper is the mcc18 compiler of the MPLAB software development environment, and the upgrade file format is Intel HEX format. According to the format of the Intel HEX file, each line of the file content is encapsulated into a frame, and a frame header and a frame footer are added to ensure the reliability of data transmission, and a half-duplex communication mode is used to retransmit the error frame.

The main program code is as follows:

[page]

The main program flow is shown in Figure 1. The program flow for downloading the system image file and writing it into the program memory is shown in Figure 2.

1.4 Design of PC operation interface

The PC operation interface is mainly used to realize the following functions:

①Serial port parameter settings: Set the serial port channel number, data bit number, baud rate and other parameters.

② User login. Enter the user name and password to verify with the lower computer.

③Select the system image file. Select the system image HEX file, read it line by line and send it to the lower computer through the serial port. If there is an error, reselect it.

④Prompt the user that the system update is complete (or failed). Display the system update progress and prompt the user the system update result.

2 Several key technologies and considerations in design

① If all the data in the HEX file is sent to the target chip through the serial port at one time, if a byte is transmitted incorrectly during the communication process, all the data will need to be resent; and the relationship between the chip's Flash write processing speed and the serial port rate must also be considered, otherwise the received data will be lost. In order to enhance the reliability of communication and the variability of the serial port rate, the Bootloader designed in this article uses a half-duplex communication mode to communicate with the host computer: one line of the HEX file is used as a frame of data, and reply data is sent to the host computer after each frame of data verification is completed. The host computer determines the correctness of the sent data frame based on the reply data and chooses to resend or continue to send the next frame; and before upgrading, communicate with the host computer to verify the username and password to ensure that the current upgrade operation is not an erroneous operation.

②When writing to the program memory of the PIC18 series, each time an 8-byte block is written, the unit of program Flash writing can only be changed from 1 to 0. However, the content of the HEX file is not generated as needed. The data length of each frame can be different, and the content of the address field of adjacent frames can also be different. For this reason, when writing to the program memory, the data field content needs to be merged into data blocks in units of 8 bytes according to the content of the address field, and those less than 8 bytes need to be filled with 0xFF. The Bootloader program designed in this article uses a circular Buffer structure to implement this operation:

③The default interrupt vector of the chip starts at 0x08 and 0x18, which cannot be changed. To change the interrupt vector entry address, you need to add jump instructions at these two address locations to jump to the interrupt vector entry address of the user program. Some address areas of the program memory of the PIC18 series are write-protected. To prevent the Bootloader program outside this area from being erased or rewritten, it is necessary to judge the content of the address field of the received data. If it is less than the starting address of the user program, it is necessary to reply to the host computer with "write address error" and discard the current data frame.

Conclusion

Experiments have shown that the Bootloader designed in this paper is stable and easy to control, and can be flexibly changed according to user needs. For example, adding a system reset mechanism to the user program can realize online upgrades, and adding a network download module to the PC operation interface can realize remote control system upgrades, which is extremely important for the release and software upgrade of embedded products.

Keywords:Bootloader Reference address:A novel Bootloader design

Previous article:Design of non-magnetic water meter based on MSP430FW427
Next article:Application of Freescale MCU in battery management system

Recommended ReadingLatest update time:2024-11-16 19:35

The STM32 BootLoader jumps to the APP and runs away, probably because some interrupt function entries cannot be found
When working on embedded products, sometimes in order to facilitate the update of device programs (such as remote updates or only updating module programs, etc.), it is necessary to use a bootloader to perform necessary initialization on the device and guide the download of APP, etc. The bootloader program downloaded
[Microcontroller]
Analysis of the bootloader execution flow after the system is powered on and the startup process of ARM Linux
    1 Introduction     Linux was originally developed by Linus Torvalds, a student at the University of Helsinki in Sweden, in 1991. Later, with the support of GNU, Linux has achieved tremendous development. Although Linux is not as popular as Microsoft's  Windows  operating system on desktop PCs, its rapid developmen
[Microcontroller]
A FLASH Bootloader for PIC16 and PIC18 Devices
Purpose of hard translation: I want to see how to write a bootloader. Note: To implement BootLoader in a microcontroller, the microcontroller must first have an IAP function, or the ability to erase and write its own FLASH. Secondly, the size of the FLASH must be considered. Identification:   1. When the chip leaves
[Microcontroller]
A FLASH Bootloader for PIC16 and PIC18 Devices
Analysis of a Boot Loader used on a microcontroller
Concept and function of Boot Loader In embedded systems represented by ARM, hardware initialization and kernel image creation before the operating system kernel runs are all completed by Boot Loader. On a PC, the first thing to start is the BIOS on the motherboard. BIOS is responsible for hardware initializati
[Microcontroller]
Analysis of a Boot Loader used on a microcontroller
【dsPIC33E】Bootloader (II) Introduction to Microchip's Hex file structure
Most of the Hex files of microcontrollers on the market are based on Intel Hex, and dsPIC33E is no exception. The format supported by dsPIC33E is Intel HEX32 (INHX32). The hex file records data in ascii format by line Each line starts with :, and every at least 2 characters represent a group of hexadecimal data in
[Microcontroller]
【dsPIC33E】Bootloader (II) Introduction to Microchip's Hex file structure
Design of Remote Upgrade of Single Chip Microcomputer Program
1. Introduction Single-chip microcomputers are widely used. In some cases, it is inevitable to upgrade the internal program of single-chip microcomputers, but it is often necessary to recall the single-chip microcomputer products to achieve this. This is very inconvenient for the program upgrade of some remote
[Microcontroller]
Design of Remote Upgrade of Single Chip Microcomputer Program
27. Operation of lighting up LED
Led can be used as a tool for debugging programs: In the early stages of development of embedded system software, such as Bootloader and kernel, since hardware such as serial ports have not yet been initialized, the debugging methods are quite limited. At this time, Led can be used as a debugging method. OK6410
[Microcontroller]
27. Operation of lighting up LED
STM32 A method to call the Bootloader in the system memory from the user code
Preface As we all know, any STM32 contains a system memory, which stores the internal boot code Bootloader. Different STM32 models support different communication ports for upgrading code, and you need to refer to the application note AN2606. However, there is a problem that cannot be avoided, that is, how to enter th
[Microcontroller]
STM32 A method to call the Bootloader in the system memory from the user code
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号