BIOS-based microcontroller program online updating method and device

By partitioning the flash memory of the microcontroller and using the BIOS command-line interface and Ymodem protocol for online updates, the inconvenience of disassembling the microcontroller and the hardware dependency problem of microcontroller program updates are solved, achieving efficient and reliable program updates.

CN121597248APending Publication Date: 2026-03-03SHANDONG CHAOYUE DATA CONTROL ELECTRONICS CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511744311.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-25
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing microcontroller program update methods suffer from problems such as inconvenience in disassembling the device, reliance on additional hardware, and complexity in the update process. In particular, in standard computer motherboards, traditional update methods require disassembling the entire device or relying on a separate processor, resulting in high costs and low efficiency.

Method used

A serial communication interface is set up between the central processing unit and the microcontroller on the motherboard, and the flash memory of the microcontroller is divided into a boot program area, a first application area, and a second application area. Online updates are performed using the BIOS command line interface and the Ymodem protocol. Program data is transferred through a portable storage device, and the program is migrated after the microcontroller is reset.

Benefits of technology

It enables online updates without disassembling the motherboard or using an external programmer, reducing maintenance costs and operational difficulty, and improving the efficiency and reliability of program updates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121597248A_ABST
    Figure CN121597248A_ABST
Patent Text Reader

Abstract

The invention discloses a BIOS (Basic Input / Output System)-based microcontroller program online updating method and device, which is characterized in that a serial communication interface is arranged between a central processing unit of a mainboard and a microcontroller, and a flash memory of the microcontroller is divided into a bootstrap program area, a first application program area and a second application program area; an update program under the BIOS and a binary program file to be updated are placed in a portable storage device, and the update program is run after a computer is started to enter a BIOS command line interface. The updating program reads the binary file and sends the data to the microcontroller through the serial communication interface according to the Ymodem protocol, and the microcontroller stores the data in the second application program area. And after the microcontroller is reset, the bootstrap program copies the to-be-executed program to the first application program area and skips to execute the to-be-executed program. The on-line updating of the microcontroller program can be completed without dismounting the mainboard and externally connecting a programmer, the maintenance cost is obviously reduced, and the updating efficiency and reliability are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computers, and more particularly to a method and apparatus for online updating of microcontroller programs based on BIOS. Background Technology

[0002] In the field of domestically produced computers and servers, microcontrollers undertake a series of critical tasks, including power-on timing control, hardware status monitoring, and system management. During the product development and debugging phase, developers can directly use the JTAG and SWD debugging interfaces reserved on the motherboard and a dedicated programmer to easily program the microcontroller online. However, once the product is assembled and delivered for use, if an upgrade to the microcontroller program is needed for function optimization or problem fixing, traditional update methods face serious challenges.

[0003] If the microcontroller only supports circuit programming, maintenance personnel must physically disassemble the entire device to reconnect the programmer. This process is not only cumbersome and time-consuming, but also greatly increases the risk of damaging the delicate motherboard hardware during disassembly and reassembly, resulting in high maintenance costs, low efficiency, and is extremely unfriendly to ordinary users.

[0004] Although some microcontrollers support in-system programming and can be updated via serial port using a pre-built bootloader, this method typically requires configuring a specific boot pin, which can interrupt the microcontroller's currently running program and affect device functionality. Furthermore, it often relies on a separate processor that is not powered by the microcontroller to initiate the update operation, a hardware requirement not found in most standard computer motherboards. Summary of the Invention

[0005] This application provides a method and apparatus for online updating of microcontroller programs based on BIOS, in order to solve the problems of inconvenience in disassembling the device, dependence on additional hardware, and complexity of the update process in existing microcontroller program update methods.

[0006] In a first aspect, this application provides a method for online updating of microcontroller programs based on BIOS, comprising: A serial communication interface is set up between the central processing unit and the microcontroller on the motherboard, and the flash memory of the microcontroller is divided into a boot program area, a first application area, and a second application area; the first application area and the second application area are the same size; Place the update program in the BIOS and the binary program file to be updated on a portable storage device; Start the computer and enter the BIOS command line interface; run the update program on the portable storage device. The update program reads the binary program file, uses the binary program file as the program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface according to the Ymodem protocol. The microcontroller stores the received program data as a program to be executed in the second application area; After the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0007] Secondly, this application provides a device for online updating of microcontroller programs based on BIOS, comprising: The partitioning module is configured to set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and to divide the flash memory of the microcontroller into a boot program area, a first application area, and a second application area; the first application area and the second application area are the same size; The updater storage module is configured to store the updater from the BIOS and the binary program file to be updated in a portable storage device. The update program execution module is configured to boot the computer and enter the BIOS command line interface to run the update program in the portable storage device. The program data sending module is configured to read the binary program file, use the binary program file as the program data to be transmitted, and send the program data to the microcontroller through the serial communication interface in accordance with the Ymodem protocol. The program to be executed storage module is configured so that the microcontroller stores the received program data as the program to be executed in the second application area; The execution module is configured such that, after the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0008] Thirdly, this application provides a readable medium including executable instructions, which, when executed by a processor of an electronic device, cause the electronic device to perform any of the methods described in the first aspect.

[0009] Fourthly, this application provides an electronic device including a processor and a memory storing execution instructions, wherein when the processor executes the execution instructions stored in the memory, the processor performs the method as described in any of the first aspects.

[0010] This application provides a method and apparatus for online microcontroller program updates based on BIOS. A serial communication interface is established between the motherboard's central processing unit and the microcontroller. The microcontroller's flash memory is divided into a boot program area, a first application program area, and a second application program area; the first and second application program areas are of the same size. The update program from the BIOS and the binary program file to be updated are placed in a portable storage device. The computer is started and enters the BIOS command-line interface, and the update program in the portable storage device is run. The update program reads the binary program file, uses it as program data to be transmitted, and sends the program data to the microcontroller via the serial communication interface according to the Ymodem protocol. The microcontroller stores the received program data as the program to be executed in the second application program area. After the microcontroller is reset, the boot program in the boot program area copies the program to be executed to the first application program area and jumps to the first application program area to execute the program. This method enables online microcontroller program updates in the BIOS environment without disassembling the motherboard or using an external programmer, significantly reducing maintenance costs and operational difficulty, and improving the efficiency and reliability of program updates.

[0011] The further effects of the aforementioned non-conventional preferred method will be explained below in conjunction with specific embodiments. Attached Figure Description

[0012] To more clearly illustrate the embodiments of this application or the existing technical solutions, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 A flowchart illustrating a method for online updating of a microcontroller program based on BIOS, provided as an embodiment of this application; Figure 2 A flowchart illustrating another method for online updating of a microcontroller program based on BIOS, provided in an embodiment of this application; Figure 3 A flowchart illustrating another method for online updating of a microcontroller program based on BIOS, provided in an embodiment of this application; Figure 4 This is a schematic diagram of a device for online updating microcontroller programs based on BIOS, provided in one embodiment of this application. Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0014] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0015] In the field of domestically produced computers and servers, microcontrollers undertake a series of critical tasks, including power-on timing control, hardware status monitoring, and system management. During the product development and debugging phase, developers can directly use the JTAG and SWD debugging interfaces reserved on the motherboard and a dedicated programmer to easily program the microcontroller online. However, once the product is assembled and delivered for use, if an upgrade to the microcontroller program is needed for function optimization or problem fixing, traditional update methods face serious challenges.

[0016] If the microcontroller only supports circuit programming, maintenance personnel must physically disassemble the entire device to reconnect the programmer. This process is not only cumbersome and time-consuming, but also greatly increases the risk of damaging the delicate motherboard hardware during disassembly and reassembly, resulting in high maintenance costs, low efficiency, and is extremely unfriendly to ordinary users.

[0017] Although some microcontrollers support in-system programming and can be updated via serial port using a pre-built bootloader, this method typically requires configuring a specific boot pin, which can interrupt the microcontroller's currently running program and affect device functionality. Furthermore, it often relies on a separate processor that is not powered by the microcontroller to initiate the update operation, a hardware requirement not found in most standard computer motherboards.

[0018] To address this issue, this application proposes a method for online microcontroller program updates based on BIOS, aiming to solve the problems of inconvenience in disassembling the device, reliance on additional hardware, and complexity of the update process in existing microcontroller program update methods. In this embodiment, a method for online microcontroller program updates based on BIOS includes: Step 101: Set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and divide the flash memory of the microcontroller into a boot program area, a first application program area, and a second application program area; the first application program area and the second application program area are the same size.

[0019] During the motherboard hardware design phase, a serial communication interface needs to be reserved between the central processing unit (CPU) and the microcontroller, typically implemented using a UART serial port. This serial port serves as a dedicated data channel between the CPU and the microcontroller, used for bidirectional communication during subsequent program updates.

[0020] At the same time, the microcontroller's flash memory space needs to be rationally planned, dividing it into three functionally distinct storage areas: a bootloader area, a first application area, and a second application area. The first and second application areas must maintain the same storage capacity to ensure complete storage and backup of the applications.

[0021] The storage areas in the flash memory are arranged in order from low address to high address as the boot program area, the first application program area, and the second application program area. The boot program area stores a fixed boot program and does not participate in program updates. The boot program runs first every time the microcontroller is powered on. The first application program area serves as the program execution area, and the second application program area serves as the program cache area.

[0022] The flash memory's storage layout follows an order from low address to high address. The lowest address segment is allocated to the bootloader area, which stores fixed bootloader code. This part of the program is determined at the microcontroller's factory and is not updated subsequently, ensuring the stability and reliability of the system startup.

[0023] The bootloader is configured as the microcontroller's entry point, and its code is executed first each time the microcontroller powers on or resets. Following the bootloader area is the first application area, which is where the actual functional code runs. All tasks performed by the microcontroller under normal operating conditions are controlled by the program in this area. Finally, there is the second application area, which serves as a program buffer. This area is specifically used to receive and temporarily store new versions of program code transmitted via the serial port. After the program transmission is complete and verified, the bootloader moves it to the first application area for execution.

[0024] Step 102: Place the update program under BIOS and the binary program file to be updated on a portable storage device.

[0025] Before performing the microcontroller program update, a portable storage device, typically a USB flash drive, is required. This device will serve as the carrier for the program and data. Two key files need to be placed in the root directory of this storage device: one is an update program that runs specifically in the BIOS environment. This program is an executable file that conforms to the UEFI application standard and has complete functionality for reading the file system, operating serial communication, and implementing the Ymodem protocol.

[0026] The other is the microcontroller binary file to be updated. This binary file contains all the machine code for the new version of the microcontroller program. Both files must be placed in the root directory of the storage device so that they can be quickly located and accessed later in the BIOS command-line environment.

[0027] Step 103: Start the computer and enter the BIOS command line interface, then run the update program in the portable storage device.

[0028] After starting the computer, instead of entering the operating system, you can enter the BIOS setup interface during the power-on self-test (POST) phase by pressing a specific key. Then, you can select to enter the BIOS Shell command-line environment. The Shell environment provides an interactive interface similar to the operating system's command line, supporting basic file operations and program execution functions.

[0029] In the shell command line, you first need to identify and switch to the file system path corresponding to the portable storage device, usually represented by a device identifier like "fs0:" or "fs1:". After switching to the root directory of the storage device, you will see the previously prepared update program file. You can start the update program by entering its filename in the command line and pressing Enter. Once the update program starts running, it will take over all subsequent update operations.

[0030] Step 104: The update program reads the binary program file, uses the binary program file as the program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface according to the Ymodem protocol.

[0031] After the update program starts, it first accesses the binary program file in the root directory of the portable storage device through the file system interface provided by the BIOS, reads the entire contents of the binary program file, and loads it into memory. After reading is complete, the contents of the binary file become the program data to be transferred.

[0032] To ensure the reliability and integrity of data transmission, the update program uses the Ymodem file transfer protocol to encapsulate and transmit program data. The update program configures and opens the serial communication interface connected to the microcontroller through the serial port driver interface provided by the BIOS, setting appropriate communication parameters such as baud rate, data bits, stop bits, and parity bits.

[0033] Subsequently, the update program, in accordance with the Ymodem protocol specifications, progressively encapsulates the program data and sends it to the microcontroller via serial port. The entire transmission process includes a complete protocol interaction flow such as handshake negotiation, data packetization, verification, and acknowledgment.

[0034] Step 105: The microcontroller stores the received program data as a program to be executed in the second application area.

[0035] After receiving data from the serial port, the microcontroller's communication processing module in the currently running application handles the reception and processing. The application continuously monitors the serial port data via serial interrupts or polling. Once a data frame conforming to the Ymodem protocol format is identified, it begins parsing and verification according to the protocol specifications. For each received data frame, the microcontroller performs a CRC check to confirm that no errors occurred during transmission.

[0036] After successful verification, the microcontroller extracts the valid program code segments carried in the data frame and writes them sequentially to the corresponding address locations in the second application area according to the receiving order. The entire receiving process is sequential, ensuring that the new program code can be stored completely and correctly in the second application area. Once all program data has been received, the second application area will have a complete copy of the new version of the program to be executed. This program is not yet running; it exists only as program code ready for execution.

[0037] Step 106: After the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0038] After receiving and storing the program data, the microcontroller sets a program update flag in the flash memory. When the bootloader detects the program update flag after the microcontroller is reset, it performs the operation of copying the program to be executed from the second application area to the first application area, and clears the program update flag after the copying is completed.

[0039] To ensure the bootloader can accurately determine whether a program migration operation is necessary, a program update flag mechanism needs to be established in the microcontroller's flash memory. After the application receives all the new program data via serial port and successfully stores it in the second application area, it writes a predefined program update flag to a specific address in the flash memory. This update flag can be a specific numerical value or a checksum, used to identify the presence of a valid executable program in the second application area. The flag's storage location is typically chosen in a shared data area accessible by both the bootloader and application areas, or at a fixed offset within the second application area.

[0040] Each time the microcontroller powers on or resets, the bootloader, as the first piece of code to execute, first reads the content of this flag. If the bootloader detects that the program update flag exists and is valid, it determines that a program update operation is needed and then initiates the process of copying the program from the second application area to the first application area. After the entire program copy is completed and confirmed to be error-free, the bootloader will actively clear the program update flag, restoring the flag to its initial state or an invalid value. The purpose of clearing the flag is to prevent the microcontroller from misjudging during subsequent startup processes, avoiding unnecessary repeated execution of program copy operations, and ensuring the efficiency and stability of the system startup process.

[0041] If an update flag is detected, the bootloader determines that a program migration operation is required and initiates a program copying process from the second application area to the first application area. The bootloader reads the complete program code stored in the second application area byte by byte or block by block and writes it to the corresponding location in the first application area to replace the program with the new one.

[0042] The bootloader sets the microcontroller's stack pointer to the starting address of the first application area; the microcontroller fetches instructions from the starting address and executes the program to be run.

[0043] After the program copy is complete, the bootloader needs to transfer the microcontroller's execution flow to the first application area. Specifically, the bootloader modifies the microcontroller's program counter register, setting its value to the starting address of the first application area. Simultaneously, the bootloader needs to reinitialize the stack pointer, pointing it to the beginning of the stack space corresponding to the first application area, ensuring the new program has the correct stack environment during runtime.

[0044] After these registers are set, the bootloader executes a jump instruction, and the microcontroller's program execution flow switches from the bootloader area to the first application area. Thereafter, the microcontroller fetches, decodes, and executes instructions from the starting address of the first application area, and the new version of the application officially begins running, completing the entire program update process.

[0045] As can be seen from the above technical solutions, the beneficial effects of this embodiment are: This application provides a method for online microcontroller program updates based on BIOS. A serial communication interface is established between the motherboard's central processing unit and the microcontroller. The microcontroller's flash memory is divided into a boot program area, a first application program area, and a second application program area; the first and second application program areas are of the same size. The update program from the BIOS and the binary program file to be updated are placed in a portable storage device. The computer is started and enters the BIOS command-line interface, running the update program from the portable storage device. The update program reads the binary program file, uses it as program data to be transmitted, and sends the program data to the microcontroller via the serial communication interface according to the Ymodem protocol. The microcontroller stores the received program data as the program to be executed in the second application program area. After the microcontroller is reset, the boot program in the boot program area copies the program to be executed to the first application program area and jumps to the first application program area to execute the program. This method enables online microcontroller program updates in the BIOS environment without disassembling the motherboard or using an external programmer, significantly reducing maintenance costs and operational difficulty, and improving the efficiency and reliability of program updates.

[0046] Figure 1 The example shown is only a basic embodiment of a method for online updating microcontroller programs based on BIOS according to this application. With certain optimizations and extensions, other preferred embodiments of a method for online updating microcontroller programs based on BIOS can be obtained.

[0047] like Figure 2 The image shows another specific embodiment of a method for online updating of microcontroller programs based on BIOS, as described in this application.

[0048] In this embodiment, a method for online updating of microcontroller programs based on BIOS includes the following steps: Step 201: Set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and divide the flash memory of the microcontroller into a boot program area, a first application program area, and a second application program area; the first application program area and the second application program area are the same size.

[0049] Step 202: Place the update program under BIOS and the binary program file to be updated on a portable storage device.

[0050] Step 203: Start the computer and enter the BIOS command line interface, then run the update program in the portable storage device.

[0051] Step 204: The update program reads the binary program file, uses the binary program file as the program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface according to the Ymodem protocol.

[0052] Step 205: The update program divides the program data to be sent into fixed-size data blocks.

[0053] After obtaining the complete microcontroller binary program data, the update program needs to preprocess the data to meet the requirements of serial port transmission. Since microcontroller program files typically have a large amount of data, directly transmitting the entire file is neither practical nor reliable; therefore, the program data needs to be divided into segments of a fixed size. The Ymodem protocol defines two standard data block sizes: a standard block of 128 bytes and an extended block of 1024 bytes. Considering actual transmission needs and efficiency, the update program usually chooses the 1024-byte extended block size. This allows for increased transmission speed while maintaining reliability and reducing protocol overhead.

[0054] The updater starts at the beginning of the binary program file and reads data sequentially in selected block sizes. Each preceding complete data block contains exactly 1024 bytes of data. When the total size of the program file is not a multiple of 1024, the last data block may be insufficient. In this case, the updater needs to pad the last incomplete data block, typically using specific padding characters such as 0x1A or 0xFF, to bring the data block to 1024 bytes.

[0055] This process ensures that all data blocks have a uniform size, facilitating subsequent protocol encapsulation and transmission. During the segmentation process, the update program maintains the current read position and the number of segments in memory, ensuring that the entire program file can be completely and orderly divided into multiple data blocks.

[0056] Step 206: Encapsulate each data block into a protocol frame conforming to the Ymodem protocol, and send the protocol frame to the microcontroller through the serial communication interface.

[0057] The protocol frame includes: a 1-byte frame header, a 1-byte packet number, a 1-byte packet number inverse code, a 128- or 1024-byte information block, and a 2-byte CRC checksum.

[0058] After data segmentation, the update program needs to encapsulate each data block using the Ymodem protocol to construct a data frame structure conforming to the protocol specifications. Protocol frame construction begins with the frame header. The update program selects the appropriate frame header identifier based on the data block size: if the data block is 128 bytes, SOH is used as the frame header, with a hexadecimal value of 0x01; if the data block is 1024 bytes, STX is used as the frame header, with a hexadecimal value of 0x02. The selection of the frame header allows the receiving end to immediately identify the size of subsequent data blocks, laying the foundation for correctly parsing the protocol frame.

[0059] Following the frame header is the packet number field, where the updater assigns a unique sequence number to each data block. The packet number starts at 1 and increments sequentially with each data block sent, wrapping back to 0 after reaching 255. The packet number field occupies one byte and identifies the data block's position within the entire transmission sequence. To enhance packet number reliability, the protocol design requires a packet number complement field immediately following the packet number. The packet number complement is obtained by inverting each bit of the packet number; for example, a packet number of 0x01 has a complement of 0xFE. The receiver can verify the relationship between the packet number and its complement to detect whether an error occurred during transmission. This redundancy enhances the protocol's fault tolerance.

[0060] After the packet number and its inverse, the update program places the actual program data block as an information block field into the protocol frame. The length of the information block is determined by the type indicated in the frame header, and is either 128 or 1024 bytes. This data is the valid program code that the microcontroller ultimately needs to receive and store. To ensure data integrity during serial transmission, the update program performs a CRC check on the information block. The CRC check uses the CRC-16 algorithm, which performs a polynomial operation on each byte in the information block, ultimately generating a 16-bit checksum. The update program converts this checksum into two bytes and appends them to the information block in high-order byte-first, low-order byte-last order, as the final part of the protocol frame.

[0061] Once the complete protocol frame is constructed, the update program sends all bytes of the entire protocol frame sequentially through the serial communication interface. The transmission process is byte-level sequential transmission, starting from the frame header, sending the packet number, the packet number inverse, the complete information block content in sequence, and finally sending two bytes for CRC checksum.

[0062] Step 207: The microcontroller stores the received program data as a program to be executed in the second application area.

[0063] Step 208: After the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0064] As can be seen from the above technical solution, the beneficial effects of this embodiment are: by dividing program data into fixed-size data blocks and encapsulating them into protocol frames conforming to the Ymodem protocol, standardization and reliability of data transmission are achieved. The data segmentation mechanism allows large-capacity programs to be transmitted in segments, reducing the risk of data loss due to a single transmission failure.

[0065] like Figure 3The image shows another specific embodiment of a method for online updating of a microcontroller program based on BIOS, as described in this application. This embodiment is a further description based on the foregoing embodiments.

[0066] In this embodiment, a method for online updating of microcontroller programs based on BIOS includes the following steps: Step 301: Set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and divide the flash memory of the microcontroller into a boot program area, a first application program area, and a second application program area; the first application program area and the second application program area are the same size.

[0067] Step 302: Place the update program under BIOS and the binary program file to be updated on a portable storage device.

[0068] Step 303: Start the computer and enter the BIOS command line interface, then run the update program in the portable storage device.

[0069] Step 304: The update program reads the binary program file, uses the binary program file as the program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface according to the Ymodem protocol.

[0070] Step 305: The microcontroller stores the received program data as a program to be executed in the second application area.

[0071] Step 306: The microcontroller receives program data frame by frame through the serial communication interface and verifies each received protocol frame.

[0072] The microcontroller is configured to operate the serial communication interface in receive mode, and communication parameters matching the update program are set, including baud rate, data bits, stop bits, and parity. The microcontroller continuously monitors the status of the serial port receive buffer via serial port interrupt mechanism or polling. When data arrival is detected, the microcontroller's serial port processing program is triggered, and it begins receiving data from the update program byte by byte.

[0073] Once a complete protocol frame is received, the microcontroller immediately initiates the verification process. This verification process involves two levels of checks. The first is packet number consistency verification. The microcontroller compares the received packet number byte with its inverse byte bit-by-bit, verifying if they are inverses of each other. If the packet number and its inverse do not match, it indicates an error occurred during transmission, and the frame data is deemed invalid. If the packet number verification passes, the microcontroller proceeds to the second level of verification: CRC integrity verification. The microcontroller uses the same CRC-16 algorithm as the sender to calculate a checksum for the received data block content and compares the calculated checksum with the 2-byte checksum carried at the end of the protocol frame.

[0074] If the two check values ​​match exactly, it means that no errors occurred during the transmission of the information block data, and the data is complete and reliable; if the check values ​​do not match, it means that the data was interfered with or damaged during transmission, and the frame data cannot be used.

[0075] Step 307: When the verification passes, extract the data blocks from the protocol frame and write them sequentially into the second application area, while returning an acknowledgment response to the update program; when the verification fails, return a negative response to the update program to request retransmission of the protocol frame.

[0076] Once the protocol frame verification passes, the microcontroller confirms that the data carried in the frame is complete and correct, and can be safely stored in flash memory. The microcontroller extracts the information block portion from the protocol frame; this portion contains the actual program code that needs to be stored. Based on the packet number information in the protocol frame, the microcontroller can calculate the storage location of this data block in the second application area. Specifically, the calculation involves subtracting 1 from the packet number, multiplying by the data block size, and adding the starting address of the second application area to obtain the target address where the data block should be written.

[0077] The microcontroller invokes the flash memory write operation interface to perform programming operations on the second application area. Due to the write characteristics of flash memory, an erase operation may be required before writing new data. The microcontroller writes the data byte by byte or sector by sector to the calculated target address location according to the byte order of the information block. During the writing process, the microcontroller may perform write verification, reading the newly written data and comparing it with the original data to ensure that the flash memory programming operation is successfully completed. Once all the data in the entire information block has been written to the second application area, the storage operation for that data block is complete.

[0078] After data storage is complete, the microcontroller needs to send a feedback signal to the update program to indicate that the data has been successfully received and stored. The microcontroller sends an ACK acknowledgment character via the serial communication interface, whose hexadecimal value is typically 0x06. Upon receiving the ACK, the update program knows that the current frame of data has been processed correctly and can proceed with the encapsulation and transmission of the next frame of data, thus advancing the entire program transmission process.

[0079] If an error is detected in the protocol frame during the verification phase, whether it's a packet number check failure or a CRC check failure, the microcontroller will not perform any storage operations on the information block of that frame to avoid writing erroneous data to flash memory and causing program corruption. At this time, the microcontroller needs to send a NAK negative acknowledgment character to the update program via the serial communication interface; its hexadecimal value is typically 0x15. The negative acknowledgment explicitly informs the update program that the protocol frame just sent was not correctly received and that there is a problem with the data.

[0080] Upon receiving a NAK acknowledgment, the update program recognizes the current frame transmission failure and immediately reconstructs and resends a protocol frame with the same packet number, achieving automatic data retransmission. This retransmission process is transparent to the user and requires no manual intervention; the system automatically retryes until the frame data is successfully transmitted. Through this acknowledgment mechanism, the Ymodem protocol achieves reliable data transmission. Even in suboptimal serial communication environments with noise interference, multiple retransmissions ensure the final correct data transmission, guaranteeing the success rate of microcontroller program updates.

[0081] Step 308: After the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0082] As can be seen from the above technical solution, the beneficial effects of this embodiment are as follows: by receiving data frame by frame and verifying each protocol frame, combined with acknowledgment and negative acknowledgment mechanisms, automatic error control and retransmission functions for data transmission are achieved. Packet number verification can detect data frame loss or duplication, and CRC verification can detect errors in data content; the combination of the two ensures the order and integrity of received data. The acknowledgment mechanism allows the sender to adjust its transmission strategy in a timely manner based on feedback from the receiver, retransmitting failed data frames without having to restart the entire transmission process. like Figure 4 The image shown is a specific embodiment of an apparatus for online updating a microcontroller program based on BIOS, according to this application. This embodiment provides an apparatus for online updating a microcontroller program based on BIOS, specifically for executing... Figures 1-3A physical apparatus for a method of online updating a microcontroller program based on BIOS is provided. Its technical solution is essentially the same as the embodiments described above, and the corresponding descriptions in the embodiments above also apply to this embodiment. The apparatus for online updating a microcontroller program based on BIOS in this embodiment includes: The partitioning module 401 is configured to set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and to divide the flash memory of the microcontroller into a boot program area, a first application area, and a second application area; the first application area and the second application area are the same size. The updater storage module 402 is configured to store the updater under BIOS and the binary program file to be updated in a portable storage device; Update program execution module 403 is configured to start the computer and enter the BIOS command line interface to run the update program in the portable storage device; The program data sending module 404 is configured to read the binary program file, use the binary program file as the program data to be transmitted, and send the program data to the microcontroller through the serial communication interface in accordance with the Ymodem protocol. The program storage module 405 is configured so that the microcontroller stores the received program data as the program to be executed in the second application area; The execution module 406 is configured such that after the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

[0083] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. The memory may include RAM, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk storage device. Of course, the electronic device may also include other hardware required for other services.

[0084] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. This bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0085] Memory is used to store instructions for execution. Specifically, instructions for execution are computer programs that can be executed. Memory can include main memory and non-volatile memory, and it provides the processor with execution instructions and data.

[0086] In one possible implementation, the processor reads the corresponding execution instructions from non-volatile memory into main memory and then executes them. Alternatively, it may obtain the corresponding execution instructions from other devices to logically form a device for in-circuit microcontroller program updates based on BIOS. The processor executes the execution instructions stored in memory to implement the method for in-circuit microcontroller program updates based on BIOS provided in any embodiment of this application.

[0087] The above is as stated in this application. Figure 4The method for executing a BIOS-based online microcontroller program update device provided in the illustrated embodiment can be applied to a processor or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by software instructions. The processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor.

[0088] The steps of the method disclosed in the embodiments of this application can be directly manifested as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method.

[0089] This application also proposes a readable medium storing executable instructions. When these instructions are executed by the processor of an electronic device, the electronic device can execute a method for online updating a microcontroller program based on BIOS, as provided in any embodiment of this application, and specifically for executing, for example... Figure 1 or Figure 2 or Figure 3 The method shown.

[0090] The electronic devices in the foregoing embodiments may be computers.

[0091] Those skilled in the art will understand that the embodiments of this application can be provided as methods or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or a combination of software and hardware.

[0092] The various embodiments in this application are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the apparatus embodiments are basically similar to the method embodiments, so the description is relatively simple; relevant parts can be referred to the descriptions of the method embodiments.

[0093] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0094] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for online updating of microcontroller programs based on BIOS, characterized in that, include: A serial communication interface is set between the central processing unit and the microcontroller on the motherboard, and the flash memory of the microcontroller is divided into a boot program area, a first application area, and a second application area; the first application area and the second application area are the same size; Place the update program in the BIOS and the binary program file to be updated on a portable storage device; Start the computer and enter the BIOS command line interface, then run the update program on the portable storage device; The update program reads the binary program file, uses the binary program file as program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface in accordance with the Ymodem protocol; The microcontroller stores the received program data as a program to be executed in the second application area; After the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

2. The method according to claim 1, characterized in that, Also includes: After receiving and storing the program data, the microcontroller sets a program update flag in the flash memory; When the microcontroller is reset and the program update flag is detected, the bootloader performs the operation of copying the program to be executed from the second application area to the first application area, and clears the program update flag after the copying is completed.

3. The method according to claim 1, characterized in that, The step of sending the program data to the microcontroller according to the Ymodem protocol includes: The update program divides the program data to be sent into fixed-size data blocks; Each data block is encapsulated into a protocol frame conforming to the Ymodem protocol, and the protocol frame is sent to the microcontroller through the serial communication interface.

4. The method according to claim 3, characterized in that, The protocol frame includes: 1-byte frame header, 1-byte packet number, 1-byte packet number inverse code, 128 or 1024-byte information block, 2-byte CRC checksum.

5. The method according to claim 3, characterized in that, The microcontroller stores the received program data as a program to be executed in the second application area, including: The microcontroller receives the program data frame by frame through the serial communication interface and verifies each received protocol frame. When the verification passes, the data blocks in the protocol frame are extracted and written sequentially into the second application area, and an acknowledgment response is returned to the update program; when the verification fails, a negative response is returned to the update program to request retransmission of the protocol frame.

6. The method according to claim 1, characterized in that, The step of jumping to the first application area to execute the program to be executed includes: The bootloader sets the microcontroller's stack pointer to the starting address of the first application area; The microcontroller fetches instructions from the starting address and executes the program to be executed.

7. The method according to claim 1, characterized in that, Also includes: The storage areas in the flash memory are, in order from low address to high address, the bootloader area, the first application area, and the second application area; The bootloader area stores the fixed bootloader and does not participate in program updates. The bootloader runs first each time the microcontroller is powered on. The first application area serves as the program execution area, and the second application area serves as the program cache area.

8. A device for online updating of microcontroller programs based on BIOS, characterized in that, include: The partitioning module is configured to set up a serial communication interface between the central processing unit and the microcontroller on the motherboard, and to divide the flash memory of the microcontroller into a boot program area, a first application area, and a second application area; the first application area and the second application area are the same size; The updater storage module is configured to store the updater from the BIOS and the binary program file to be updated in a portable storage device. The update program execution module is configured to start the computer and enter the BIOS command line interface to run the update program in the portable storage device. The program data sending module is configured so that the update program reads the binary program file, uses the binary program file as program data to be transmitted, and sends the program data to the microcontroller through the serial communication interface in accordance with the Ymodem protocol. The program to be executed storage module is configured so that the microcontroller stores the received program data as a program to be executed in the second application area; The execution module is configured such that, after the microcontroller is reset, the bootloader in the bootloader area copies the program to be executed to the first application area and jumps to the first application area to execute the program to be executed.

9. A computer-readable storage medium storing a computer program, characterized in that, The computer program is used to execute a method for updating a microcontroller program online based on BIOS, as described in any one of claims 1-7.

10. An electronic device, characterized in that, The electronic device includes: processor; Memory used to store the processor's executable instructions; The processor is configured to read the executable instructions from the memory and execute the instructions to implement the method for online updating a microcontroller program based on BIOS as described in any one of claims 1-7.