Method for providing initialization environment for APP program in bootloader

By defining Flagjump, which will not be reset in Bootloader, the anti -initialization operation of the peripherals will be controlled, and the tedious peripheral cleanup and interrupt shutdown work in the traditional method will be solved.

CN119376824AInactive Publication Date: 2025-01-28TIANJIN JINHANG COMP TECH RES INST
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411470944.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-21
Publication Date
2025-01-28
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

After software upgrade in bootloader, traditional methods require tedious peripheral cleaning and interrupt shutdown work, which are easy to miss and lead to abnormal errors.

Method used

In SRAM memory, defines the variable that is not flagjump, which is not cleared by zero, and controls the anti -initialization operation of the peripherals through the software after the software is reset to simplify the operation required before the jump.

Benefits of technology

By simplifying the operation of the peripheral anti -initialization operation, the tedious steps in the traditional methods are avoided, the stability of jumping after software upgrades is improved, and abnormal errors have been reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119376824A_ABST
    Figure CN119376824A_ABST
Patent Text Reader

Abstract

The invention discloses a method for providing an initialization environment for an APP (Application) program in a bootloader, which comprises the following steps of: defining a variable FlagJump in an SRAM (Static Random Access Memory), and defining the variable FlagJump to a. Noint region of a. Bss section; after the MCU receives the upgrade command, starting to verify the name and version information of the upgrade package, receiving the upgrade package after the verification is passed, performing file MD5 verification after the receiving is completed, and verifying the integrity of the upgrade package; a variable FlagJump value is assigned to be 0 * 55AA55AA, and a system function NVIC System Reset () is called to carry out software reset on the system; after resetting of the system software is completed, the value of FlagJump is judged in a bootloader entry function; a function pointer jumpappptr is defined, whether the address of the FLASHAPP is equal to 0x20000000 or not is judged by bitwise using the address of the FLASHAPP and the upper 0x2FFE0000, if the judgment is successful, jump2app assignment and function pointer operation jump APP are carried out, and if the judgment is not successful, the stack top pointer is judged to be illegal, and an error instruction is sent out. According to the method, the variables are defined in the. Noint area of the. Bss segment, the characteristic that the variable values are not changed after software resetting is utilized, the anti-initialization operation of the peripheral is controlled, and tedious operation is avoided before jumping.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of computer control and relates to a method for providing an initialization environment for an APP program in a bootloader. Background Art

[0002] The bootloader is a program that runs after the CPU starts up and before the operating system kernel runs. The bootloader program initializes the system hardware and loads the operating system or application into the memory for execution. It mainly includes hardware initialization, selection of boot devices such as flash memory and external memory, loading of the operating system or application, execution of the loaded program, error handling and rollback, upgrade support and other functions.

[0003] For some MCUs with small memory and simple functions (such as GD32), the firmware upgrade can also be completed through the bootloader. In order to realize the online upgrade (IAP) function of STM32, the FLASH of STM32 is usually divided into two parts: bootloader and application. The bootloader is the boot program of the application. When we need to upgrade online, we can do it through BOOT. Summary of the invention

[0004] 1. Technical issues to be resolved

[0005] Perform software upgrades in the bootloader. After the upgrade is completed, use the jump instruction to jump to the application storage area for loading and execution. Before the program jumps, it is necessary to perform related peripheral cleanup and interrupt shutdown. The traditional approach is to reset all enabled peripherals and shut down all interrupts. This processing method is very cumbersome. If you forget to reset a used peripheral or interrupt, it may cause an abnormal error after jumping to the application.

[0006] (II) Technical solution

[0007] In order to solve the above technical problems, the present invention provides a method for providing an initialization environment for an APP program in a bootloader, comprising the following steps:

[0008] S1: Define a variable FlagJump in the SRAM memory that will not be cleared by reset, and define this variable in the .noint area of ​​the .bss segment.

[0009] Among them, the __attribute__((section(".noinit"))) instruction is used to define the variable FlagJump, and the type of the variable FlagJump is volatile unsigned int.

[0010] S2: When the MCU receives the upgrade command, it starts to verify the name and version information of the upgrade package. After the verification is passed, the upgrade package is received. After receiving the package, the file MD5 check is performed to verify the integrity of the upgrade package.

[0011] The operating system uses the domestically produced single-chip microcomputer GD32.

[0012] (1) The bootloader's FLASH address is set to FLASH_LOADER value 0x8000000 and the space size is 0x10000.

[0013] (2) The FLASH address of the application is set to FLASH_APP value 0x8010000, and the space behind it is used by the application.

[0014] After the upgrade package is received, use the GD32 write FLASH function to write the upgrade package to the space with FLASH_APP as the starting address.

[0015] S3: Assign the variable FlagJump value to 0x55AA55AA, and call the system function NVIC_SystemReset() to perform a software reset on the system.

[0016] S4: After the system software is reset, the value of FlagJump is determined in the bootloader entry function.

[0017] (1) If this value is 0x55AA55AA, it means that this entry into the program is a startup after an upgrade. There is no need to wait for the upgrade instruction from the interface, and the program can be directly jumped to S5.

[0018] (2) If this value is 0, it means that the program is started after power failure. It needs to wait for external instructions to update. After the timeout, it jumps to S5 application program. S5: First, define the function pointer jump_app_ptr, the parameters and return values ​​are void,

[0019] Define this function pointer type variable jump2app, use the FLASH_APP application address bitwise AND 0x2FFE0000 to determine whether it is equal to 0x20000000. If the judgment is successful, go to S5_1 to S5_3 to assign jump2app and run the function pointer to jump to APP. Otherwise, the stack top pointer is determined to be illegal and an error instruction is issued.

[0020] If S5_1 is equal, it means the stack top pointer is legal, the second word in the user code area is the program start address, and the value of FLASH_APP+4 is assigned to jump2app;

[0021] S5_2 uses MSR_MSP to initialize the APP stack pointer;

[0022] S5_3 runs the function pointer to jump to APP.

[0023] (III) Beneficial effects

[0024] The above technical solution provides a method for providing an initialization environment for an APP program in a bootloader, by defining variables in the .noint area of ​​the .bss segment and utilizing the characteristic that the variable value remains unchanged after a software reset, thereby controlling the deinitialization operation of the peripherals and avoiding cumbersome operations before jumping. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] Figure 1 The present invention is a flow chart of a method for providing an initialization environment for an APP program in a bootloader. DETAILED DESCRIPTION

[0026] In order to make the purpose, content and advantages of the present invention more clear, the specific implementation methods of the present invention are further described in detail below in conjunction with the drawings and examples.

[0027] Reference Figure 1 As shown, the method for providing an initialization environment for an APP program in a bootloader in this embodiment includes the following steps:

[0028] S1: Define a variable FlagJump in the SRAM memory that will not be cleared by reset, and define this variable in the .noint area of ​​the .bss segment.

[0029] Among them, the __attribute__((section(".noinit"))) instruction is used to define the variable FlagJump, and the type of the variable FlagJump is volatile unsigned int.

[0030] S2: When the MCU receives the upgrade command, it starts to verify the name and version information of the upgrade package. After the verification is passed, the upgrade package is received. After receiving the package, the file MD5 check is performed to verify the integrity of the upgrade package.

[0031] Taking the domestically produced single-chip microcomputer GD32 as an example,

[0032] (1) The bootloader's FLASH address is set to FLASH_LOADER value 0x8000000 and the space size is 0x10000.

[0033] (2) The FLASH address of the application is set to FLASH_APP value 0x8010000, and the space behind it is used by the application.

[0034] After the upgrade package is received, use the GD32 write FLASH function to write the upgrade package to the space with FLASH_APP as the starting address.

[0035] S3: Assign the variable FlagJump value to 0x55AA55AA, and call the system function NVIC_SystemReset() to perform a software reset on the system.

[0036] S4: After the system software is reset, the value of FlagJump is determined in the bootloader entry function.

[0037] (1) If this value is 0x55AA55AA, it means that this entry into the program is a startup after an upgrade. There is no need to wait for the upgrade instruction from the interface, and the program can be directly jumped to S5.

[0038] (2) If this value is 0, it means that the program is started after power failure. It needs to wait for external instructions to update. After the timeout, it jumps to S5 application program. S5: First, define the function pointer jump_app_ptr, the parameters and return values ​​are void,

[0039] Define this function pointer type variable jump2app, use the FLASH_APP application address bitwise AND 0x2FFE0000 to determine whether it is equal to 0x20000000. If the judgment is successful, go to S5_1 to S5_3 to assign jump2app and run the function pointer to jump to APP. Otherwise, the stack top pointer is determined to be illegal and an error instruction is issued.

[0040] If S5_1 is equal, it means the stack top pointer is legal, the second word in the user code area is the program start address, and the value of FLASH_APP+4 is assigned to jump2app;

[0041] S5_2 uses MSR_MSP to initialize the APP stack pointer;

[0042] S5_3 runs the function pointer to jump to APP.

[0043] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for providing an initialization environment for an APP program in a bootloader, characterized in that: The following steps are involved: S1: Define a variable FlagJump in the SRAM memory that will not be cleared by reset, and define this variable in the .noint area of ​​the .bss segment; S2: When the MCU receives the upgrade command, it starts to verify the name and version information of the upgrade package. After the verification is passed, it receives the upgrade package. After receiving the package, it performs MD5 verification on the file to verify the integrity of the upgrade package. S3: Assign the variable FlagJump value to 0x55AA55AA, and call the system function NVIC_SystemReset() to perform a software reset on the system; S4: After the system software is reset, the value of FlagJump is determined in the bootloader entry function; S5: Define the function pointer jump_app_ptr, define the function pointer type variable jump2app, use the FLASH_APP application address bitwise AND 0x2FFE0000 to determine whether it is equal to 0x20000000. If the judgment is successful, assign jump2app and run the function pointer to jump to APP. Otherwise, the stack top pointer is determined to be illegal and an error instruction is issued.

2. The method for providing an initialization environment for an APP program in a bootloader according to claim 1, characterized in that: In step S1, the variable FlagJump is defined using the __attribute__((section(".noinit"))) directive.

3. The method for providing an initialization environment for an APP program in a bootloader according to claim 2, characterized in that: In step S1, the type of the variable FlagJump is volatile unsigned int.

4. The method for providing an initialization environment for an APP program in a bootloader as claimed in claim 3, characterized in that: The operating system uses the domestically produced single-chip microcomputer GD32.

5. The method for providing an initialization environment for an APP program in a bootloader according to claim 4, characterized in that: In step S2, the FLASH address of the bootloader is set to FLASH_LOADER, the value is 0x8000000, and the space size is 0x10000.

6. The method for providing an initialization environment for an APP program in a bootloader according to claim 5, characterized in that: In step S2, the FLASH address of the application is set to FLASH_APP, with a value of 0x8010000, and the space behind is used by the application.

7. The method for providing an initialization environment for an APP program in a bootloader according to claim 6, characterized in that: In step S2, after the upgrade package is received, the GD32 write FLASH function is used to write the upgrade package to the space with FLASH_APP as the starting address.

8. The method for providing an initialization environment for an APP program in a bootloader according to claim 7, characterized in that: In step S4, if the value of FlagJump is 0x55AA55AA, it means that this entry into the program is a startup after an upgrade, and there is no need to wait for the upgrade instruction of the interface, and the process directly goes to S5 to jump to the application program.

9. The method for providing an initialization environment for an APP program in a bootloader according to claim 8, characterized in that: In step S4, if the value of FlagJump is 0, it means that the program is started after power failure, and it is necessary to wait for a delay to see whether the external instruction needs to be updated. After the timeout, it jumps to S5 application program jump.

10. The method for providing an initialization environment for an APP program in a bootloader according to claim 9, characterized in that: In step S5, the process of jump2app assignment and function pointer operation jump APP is as follows: If S5_1 is equal, it means the stack top pointer is legal, the second word in the user code area is the program start address, and the value of FLASH_APP+4 is assigned to jump2app; S5_2 uses MSR_MSP to initialize the APP stack pointer; S5_3 runs the function pointer to jump to APP.

Citation Information

Patent Citations

  • Embedded system firmware on-line upgrading system

    CN101477471A

  • Internet of Things MCU air firmware upgrading method

    CN110647337A

  • BootLoader method without influencing application program debugging

    CN112988206A

  • Anti-failure method for remote upgrading of MCU (Microprogrammed Control Unit) program

    CN116450170A

  • MCU firmware upgrading method and system for BMC cluster management single board

    CN117130639A