A Firmware Upgrade Method and System for a Bootloader Architecture
The integrated Bootloader architecture enables efficient firmware updates and debugging, addressing inflexibility in existing systems by allowing direct flash memory updates and utilizing DDR memory, enhancing development efficiency.
Patent Information
- Application Number
- CN202210035756.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-10
- Publication Date
- 2025-05-27
- Estimated Expiration
- 2042-01-10
AI Technical Summary
Existing embedded systems lack flexibility in software updates and information interaction, with existing Bootloader architectures being inflexible and lacking efficient firmware upgrade mechanisms.
A Bootloader architecture that integrates firmware upgrade and debugging functionalities, allowing for direct updates to internal flash memory through SPI communication and additional support from DDR memory, with modes for normal operation, debugging, and firmware upgrade.
Enhances the flexibility and efficiency of firmware updates by integrating firmware upgrade and debugging into a unified process, improving development efficiency and reducing the need for repeated recompilation and external tools.
Smart Images

Figure CN114356383B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of system architecture design, and particularly to a firmware upgrade method and system for a Bootloader architecture. Background Art
[0002] An embedded system is an application-centered, software and hardware customizable special computer system suitable for strict comprehensive requirements such as functions, reliability, cost, volume, power consumption, etc. It has the characteristics of small software code, high automation, fast response speed, etc., and is particularly suitable for systems requiring real-time and multitasking. An embedded system mainly consists of an embedded processor, related support hardware, an embedded operating system, and an application software system, etc., and can work independently. BootLoader is a program used to complete the startup of the embedded system and the loading of system software, and is a key step in system development. On the one hand, BootLoader provides powerful program download and debugging functions, and on the other hand, it is easy to expand, update, and upgrade software, providing users with a friendly software architecture that is easy to modify and transplant on all microprocessors. An embedded operating system without BootLoader has poor flexibility, lacks the information interaction process with users, and cannot achieve convenient and effective parameter transfer. Summary of the Invention
[0003] The present invention provides a firmware upgrade method and system for a Bootloader architecture, aiming to solve the problems of poor flexibility and lack of information interaction in existing embedded operating systems.
[0004] The present invention provides a firmware upgrade method for a Bootloader architecture, including the following steps:
[0005] S1. Start the embedded system, initialize the serial port, run boot, read and print the status of bootsel. If bootsel = 2 is recognized, enter the firmware upgrade mode and execute step S2; if bootsel = 0 is recognized, enter the default startup mode and execute step S3;
[0006] S2. Initialize functions such as spi and uart, establish a connection with the on-chip flash through the spi communication protocol, perform erase, read, and write operations on the flash, write the firmware into the flash from the serial port through the serial port interrupt function, and complete the firmware update by restarting and switching to the main mode;
[0007] S3. Add ddr initialization to the original firmware program, write the firmware upgrade program into ddr through jlink, run the program in ddr, and update the original firmware in the flash through the serial port interrupt to complete the firmware upgrade of the bootloader.
[0008] As a further improvement of the present invention, after the embedded system enters the firmware upgrade mode, the following operations are performed:
[0009] a1. The program prints prompt information, loads the firmware upgrade program, sends the new firmware program to the flash through the serial port to complete the firmware upgrade, switches back to the default startup mode with bootloader = 0. When the system is powered on and reset again, the new firmware runs to complete the operation of the upper-layer device.
[0010] As a further improvement of the present invention, when the developer has made a new firmware program and needs to upgrade the firmware, the embedded system switches to the default startup mode and performs the following operations:
[0011] a2. The program reads the data stored at a fixed position in the flash. The data stores the size information and verification information of the firmware. According to the size information of the firmware, the firmware data in the flash is copied to the sram. It is judged whether the copy is accurate through the verification information of the firmware. If it is correct, the firmware information is executed, and various initialization operations required by the upper-layer device are loaded. If the data copy is incorrect, an error is reported and the above process is repeated.
[0012] As a further improvement of the present invention, when an error occurs during the copy of the firmware data to the sram or a new program needs to be written into the sram for debugging, the program is directly written into the sram for running and debugging by switching to the debug mode. The following operations are performed:
[0013] a3. After the program prints the prompt information, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debugged firmware program into the sram and directly run the firmware content. The debugger modifies the firmware by viewing the log information printed on the serial port.
[0014] The present invention also provides a firmware upgrade system with a Bootloader architecture, including:
[0015] Initialization module: Executes to start the embedded system, initializes the serial port, runs boot, reads and prints the status of bootsel, and enters the default startup module, or the debug module, or the firmware upgrade module according to the status of bootsel;
[0016] Default startup module: Executes the default startup mode of the bootloader program;
[0017] Debug module: Executes the debug mode of the bootloader program;
[0018] Firmware upgrade module: Executes the firmware upgrade mode of the bootloader program.
[0019] As a further improvement of the present invention, the default startup module specifically executes:
[0020] The program reads the data stored at a fixed position in the flash. The data stores the size information and verification information of the firmware. According to the size information of the firmware, the firmware data in the flash is copied to the sram. Whether the copy is accurate is judged through the verification information of the firmware. If it is correct, the firmware information is executed, and various initialization operations required by the upper-layer device are loaded. If the data copy is incorrect, an error is reported and the above process is repeated.
[0021] As a further improvement of the present invention, the debugging module specifically executes:
[0022] After the program prints the prompt information, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debugged firmware program into the sram and directly run the firmware content. The debugger modifies the firmware by viewing the log information printed by the serial port.
[0023] As a further improvement of the present invention, the firmware upgrade module specifically executes:
[0024] The program prints prompt information, loads the firmware upgrade program, sends the new firmware program to the flash from the serial port to complete the firmware upgrade, and switches back to the default startup mode of the main mode. When the system is powered on and reset again, the new firmware is run to complete the operation of the upper-layer device.
[0025] The beneficial effects of the present invention are: on the basis of the original embedded system architecture, a firmware upgrade mode is added, making the original independent program loading and debugging modules into a whole, which can directly update the on-chip flash. At the same time, another way to update the firmware is also provided: updating the on-chip flash from the ddr memory, which greatly improves the development efficiency of the Bootloader. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 is a flowchart of a method for upgrading the firmware of a Bootloader architecture of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0027] In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0028] The present invention relates to a method for designing a BootLoader architecture, in particular to a BootLoader architecture design method with a clear architecture structure, more powerful functions, convenient for maintenance and modification, strong scalability, and obvious advantages in software update and function expansion.
[0029] Such asFigure 1 As shown in the figure, a firmware upgrade method for a Bootloader architecture of the present invention includes the following steps:
[0030] S1. Start the embedded system, initialize the serial port, run the boot and print the message "Bootloader is running", read and print the status of bootsel. If bootsel = 2 is recognized, enter the firmware upgrade mode and execute step S2; if bootsel = 0 is recognized, enter the default startup mode and execute step S3;
[0031] S2. Initialize functions such as spi and uart, establish a connection with the on-chip flash through the spi communication protocol, perform operations such as erasing, reading, and writing on the flash, write the firmware to the flash from the serial port through the serial port interrupt function, and complete the firmware update by restarting and switching to the main mode.
[0032] S3. Add ddr initialization to the original firmware program, write the firmware upgrade program into the ddr through jlink, run the program in the ddr, and update the original firmware in the flash through the serial port interrupt to complete the firmware upgrade of the bootloader.
[0033] Steps S2 and S3 are two independent firmware upgrade methods. First, the method of step S2 means that during the firmware upgrade process, break away from the original default mode and switch to the Bootsel = 2 mode, that is, the firmware upgrade mode, and update the firmware through this mode; second, the method of step S3 means that during the firmware upgrade process, still stay in the current default mode, load the updated firmware program into the ddr through jlink / st-link to run, and complete the firmware update of the on-chip flash.
[0034] After the system initialization, according to the different statuses of bootsel read and printed, it can be divided into the following three situations.
[0035] When the embedded system enters the firmware upgrade mode, execute: a1. The program prints a prompt message, loads the firmware upgrade program, sends the new firmware program to the flash from the serial port to complete the firmware upgrade, switches back to the default startup mode of bootloader = 0 in the main mode. When the system is powered on and reset again, run the new firmware to complete the operation of the upper device.
[0036] When the developer finishes making a new firmware program and needs to upgrade the firmware, the embedded system switches to the default startup mode and executes: a2. The program reads the data stored at a fixed position in the flash. The data stores the size information and check information of the firmware. According to the size information of the firmware, the firmware data in the flash is copied to the SRAM, and it is judged whether the copy is accurate through the check information of the firmware. If it is correct, the firmware information is executed, and various initialization operations required by the upper-layer devices are loaded. If the data copy is incorrect, an error is reported and the above process is repeated.
[0037] When an error occurs during the copy of the firmware data to the SRAM or when a new program needs to be written into the SRAM for debugging, the program is directly written into the SRAM for running and debugging by switching to the debug mode. Execute: a3. After the program prints the prompt information, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debug firmware program into the SRAM and directly run the firmware content. The debugger modifies the firmware by viewing the log information printed by the serial port.
[0038] Combined with Figure 1 As shown in
[0039] Initialization module: Execute to start the embedded system, initialize the serial port, run the boot and print the information "Bootloader is running", read and print the status of the bootsel, and enter the default startup module, or debug module, or firmware upgrade module according to the status of the bootsel;
[0040] Default startup module: Execute the default startup mode of the bootloader program;
[0041] Debug module: Execute the debug mode of the bootloader program;
[0042] Firmware upgrade module: Execute the firmware upgrade mode of the bootloader program.
[0043] This system architecture includes three modes:
[0044] BOOT_MODE_SPI_NOR mode: the execution mode corresponding to the default startup module; this mode is the default startup method of the bootloader program of the present invention. During the startup process of the embedded system, the serial port will be initialized first and the message "Bootloader is running" will be printed to indicate that the boot is running. Immediately afterwards, the status of bootsel will be read and printed. If bootsel = 0 is recognized, the default mode will be entered. First, the program will read the data stored at a fixed position in the flash. The firmware size information and check information are stored here. Then, according to the size information, the firmware data in the flash will be copied to the sram. Then, it will be judged whether the copy is accurate through the check information. If it is correct, the firmware information will be executed, and various initialization operations required by the upper-layer devices will be loaded. If the data copy is incorrect, an error will be reported and the above process will be repeated.
[0045] In the default startup method, when the bootloader starts to load, it will print the current boot status through the serial port. For example: boot stat: 0x0 / 0x1 / 0x2 to inform the boot mode; the size of the data and the accuracy of the data are determined by adding the firmware data size information and the sum information of all binary data to the head of the firmware bin file. During the process of writing data into the on-chip flash, this data size information will be read. According to this size information, it is determined how much information the on-chip flash will receive. Finally, the sum of the binary data received by the flash will be compared with the previous sum information. If the comparison is incorrect, an error will be reported and it will be prompted to update the firmware again.
[0046] BOOT_MODE_SERIAL mode: the execution mode corresponding to the debug module; this mode is the debug mode of the bootloader. When an error occurs when copying data to the sram or when some new programs need to be written into the sram for debugging, this mode can be switched to directly write the program into the sram for running and debugging. After entering the debug mode, after the program prints some prompt messages, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debug firmware program into the sram and directly run the firmware content. The debugger can modify the firmware by viewing the log information printed by the serial port.
[0047] BOOT_UPGRATE_FLASH mode: The execution mode corresponding to the firmware upgrade module; this mode is the firmware upgrade mode of the bootloader. When developers have created a new firmware program and need to upgrade the firmware, they can switch to this mode. After entering, the program first prints a prompt message to indicate that the program has entered this mode, and then loads the firmware upgrade program. At this time, developers send the pre-prepared new firmware program to the flash through the serial port to complete the firmware upgrade. Finally, it switches back to the main mode bootloader = 0. Once the system is powered on and reset again, the new firmware can be run to complete a series of support operations for the upper-layer device.
[0048] The current mainstream architecture design method of the bootloader still mainly focuses on the program loading and debugging modes. The method of updating the firmware still uses the internal flash library function of the stm32 to separately complete the update of the on-chip flash. Each time the firmware needs to be updated, the program needs to be recompiled and the system upgrade and maintenance are completed through the external j-flash, lacking flexibility. In view of the above problems, the present invention adds a firmware upgrade mode on the basis of the former, making the originally independent two modules into a whole, which can directly update the on-chip flash. At the same time, it also provides another way to update the firmware: update the on-chip flash from the ddr memory, greatly improving the development efficiency of the Bootloader.
[0049] The above content is a further detailed description of the present invention in combination with specific preferred embodiments. It cannot be determined that the specific implementation of the present invention is only limited to these descriptions. For those of ordinary skill in the technical field to which the present invention belongs, without departing from the concept of the present invention, several simple deductions or substitutions can still be made, which should all be regarded as belonging to the protection scope of the present invention.
Claims
1. A firmware upgrade method for a Bootloader architecture, characterized in that, it includes the following steps: S1. Start the embedded system, initialize the serial port, run boot, read and print the status of bootsel. If bootsel = 2 is recognized, enter the firmware upgrade mode and execute step S2; if bootsel = 0 is recognized, enter the default boot mode and execute step S3; S2. Initialize functions such as spi and uart, establish a connection with the on-chip flash through the spi communication protocol, perform erase, read and write operations on the flash, write the firmware to the flash from the serial port through the serial port interrupt function, and complete the firmware update by restarting and switching to the main mode; S3. Add ddr initialization to the original firmware program, write the firmware upgrade program into ddr through jlink, run the program in ddr, and update the original firmware in the flash through the serial port interrupt to complete the firmware upgrade of the bootloader; When the embedded system enters the firmware upgrade mode, execute: a1. The program prints a prompt message, loads the firmware upgrade program, sends the new firmware program to the flash from the serial port to complete the firmware upgrade, switches back to the default boot mode with bootloader = 0. When the system is powered on and reset again, run the new firmware to complete the operation of the upper-layer device; When the developer makes a new firmware program and needs to upgrade the firmware, the embedded system switches to the default boot mode and executes: a2. The program reads the data stored at a fixed position in the flash. The data stores the size information and check information of the firmware. Copy the firmware data in the flash to the sram according to the size information of the firmware, and judge whether the copy is accurate through the check information of the firmware. If it is correct, execute the firmware information and load various initialization operations required by the upper-layer device. If the data copy is incorrect, report an error and repeat the above process.
2. The firmware upgrade method for a Bootloader architecture according to claim 1, characterized in that, when an error occurs during the copy of the firmware data to the sram or a new program needs to be written into the sram for debugging, directly write the program into the sram to run and debug by switching to the debug mode, and execute: a3. After the program prints the prompt message, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debug firmware program into the sram and directly run the firmware content. The debugger modifies the firmware by viewing the log information printed on the serial port.
3. A firmware upgrade system for a Bootloader architecture, characterized in that, it includes: Initialization module: Execute to start the embedded system, initialize the serial port, run boot, read and print the status of bootsel, and enter the default boot module, or debug module, or firmware upgrade module according to the status of bootsel; Default boot module: Execute the default boot mode of the bootloader program; Debug module: Execute the debug mode of the bootloader program; Firmware upgrade module: Execute the firmware upgrade mode of the bootloader program; The default startup module specifically executes: The program reads the data stored in the fixed position of the flash. The data stores the size information and verification information of the firmware. According to the size information of the firmware, the firmware data in the flash is copied to the sram. Whether the copy is accurate is judged by the verification information of the firmware. If it is correct, the firmware information is executed, and various initialization operations required by the upper-layer device are loaded. If the data copy is incorrect, an error is reported and the above process is repeated; The debug module specifically executes: After the program prints the prompt information, it will be in a state of waiting for an interrupt, waiting for the debugger to send the debug firmware program into the sram and directly run the firmware content. The debugger modifies the firmware by viewing the log information printed by the serial port; The firmware upgrade module specifically executes: The program prints the prompt information, loads the firmware upgrade program, sends the new firmware program to the flash from the serial port to complete the firmware upgrade, and switches back to the default startup mode of the main mode. When the system is powered on and reset again, the new firmware is run to complete the operation of the upper-layer device.
Citation Information
Patent Citations
Embedded type partition image security certification and kernel trusted boot method and equipment thereof
CN104794393A
Safe and easily-used firmware upgrade method and system
CN108108193A