A method and system for flexible storage and upgrading of boot and application programs
By specifying the storage area and modifying parameters in the info section, flexible application upgrades are achieved, solving the problems of application failure to be repaired on-site and unsuccessful upgrades in existing technologies, thus improving upgrade efficiency and system stability.
Patent Information
- Application Number
- CN202210353450.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-06
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-04-06
AI Technical Summary
In existing technologies, applications cannot be repaired on-site and the upgrade process is complex, which cannot effectively solve the problem of bad blocks in NAND flash, resulting in unsuccessful upgrades.
By employing flexible storage and upgrade methods for bootloaders and applications, and utilizing the info area to specify storage regions, parameters can be modified to support flexible upgrades of the BootLoader and applications. This allows for upgrades of non-running segments under abnormal circumstances, and different programs and information can be stored through multiple block areas.
It enables the application to run and upgrade normally under abnormal conditions, improves upgrade efficiency, avoids upgrade failure due to bad blocks, supports flexible switching and testing of multiple program versions, and ensures system stability.
Smart Images

Figure CN114860291B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of Internet of Things application program upgrades, and in particular relates to a method and system for guiding and flexibly storing and upgrading application programs. Background Art
[0002] The current upgrade method uses a primary bootloader, which makes on-site repair impossible if an application fails. Another approach involves using a backup program, verifying the program before running it. If the main program is incorrect, the backup program is copied to the main program area. However, in practice, there's a high probability of bad blocks in the NAND flash memory in the main program area, preventing the backup program from being copied to the main program area. This approach isn't guaranteed to be completely successful in practice. The program storage area is fixed, and without changing the boot program storage area, the bad block issue can't be resolved. This backup method also requires upgrading both the main program and the backup program during the upgrade process, making it cumbersome. Summary of the Invention
[0003] In view of the deficiencies of the prior art, the present invention provides a method and system for flexible storage and upgrading of boot and application programs. This solves the problem that in actual applications, applications cannot be used. Instead of requiring the non-running segment application to have an upgrade function, the BootLoader also needs to have an upgrade function, and the boot area can be specified. When the application needs to be upgraded normally, the non-running segment application upgrade function can meet the need, and when the above-mentioned abnormal situation occurs, the BootLoader upgrade function can be applied. In addition, the boot storage space is specified, and the BootLoader and application storage information are required to be stored in a specified storage area, which is the origin of the info information area. By modifying the parameters of the info information area, the program segment that needs to be booted can be specified. When different programs are needed, it supports the upgrade of new programs into different storage areas.
[0004] The technical solution adopted by the present invention to achieve the above-mentioned purpose is:
[0005] A method for flexibly storing and updating boot and application programs, comprising the following steps:
[0006] The CPU calls the boot program on Block 0 into memory and runs the boot program;
[0007] The boot program searches the BootLoader boot program running area and the specified startup address in the info information area, and guides the BootLoader boot program to run;
[0008] After the BootLoader boot program runs, it waits for an upgrade instruction. If no upgrade instruction is received, it searches the app application running area and the specified startup address in the info information area to guide the app application to run; if an upgrade instruction is received, it parses the upgrade instruction and upgrades according to the parsing result.
[0009] The parsing of the upgrade instruction is specifically as follows: the upgrade object in the parsing upgrade instruction is to upgrade the BootLoader boot program or the app application, and the position of the Block area where the content to be upgraded is located.
[0010] The upgrade process includes: BootLoader upgrades non-running app applications, BootLoader upgrades other non-running BootLoader boot programs, app application upgrades non-running BootLoader boot programs, and app application upgrades other non-running app applications.
[0011] The app application upgrades the BootLoader and other app applications separately as follows:
[0012] When the app application is running and receives an upgrade instruction, it first parses the upgrade instruction to determine whether the object to be upgraded is the BootLoader or the app application, then parses the area to be upgraded to determine whether the area is a non-running segment. If so, it records the version number to be upgraded, then responds, waits to receive the upgrade package, and performs the upgrade; otherwise, it exits the upgrade and executes the app application normally.
[0013] The upgrade package includes:
[0014] The first data packet is the upgrade instruction, including: upgrade object identification code, upgrade segment code, upgrade version number, and time;
[0015] The middle package data includes: upgrade object identifier, program version number, startup address, and program content;
[0016] The tail packet data is the test data, which verifies the correctness and integrity of all program packages.
[0017] A system for flexibly storing and updating boot and application programs, comprising:
[0018] The first boot module, namely boot, is used to search for info information and call the second boot module containing the upgrade module, that is, to search for the BootLoader boot program running area and the specified startup address block x; the BootLoader boot program is on Block x, and is copied to the memory and run the BootLoader boot program;
[0019] The second boot module, BootLoader, is used to search for info information and call the app application containing the upgrade module, that is, to search for the app application running area and Block y of the specified startup address; the app application is loaded on Block y and copied to the memory to run the app application;
[0020] The upgrade module is used to wait for the upgrade instruction after the BootLoader boot program runs. If no upgrade instruction is received, it searches the app application running area and the specified startup address in the info information area to guide the app application to run; if an upgrade instruction is received, it parses the upgrade instruction and upgrades according to the parsing result.
[0021] The upgrade module is used to wait for the upgrade instruction after the app application is running. If no upgrade instruction is received, other applications will continue to run. If an upgrade instruction is received, the upgrade instruction will be parsed and upgraded according to the parsing result.
[0022] A system for flexibly storing and updating boot and application programs includes multiple block areas for storing different programs and information, including:
[0023] Block 0 is used to store the boot program so that the CPU can boot and run the boot program.
[0024] Block 1, used to store info information area;
[0025] Block x is used to store the BootLoader boot program, so as to store multiple BootLoader boot programs;
[0026] Block y is used to store app applications to utilize the storage of multiple app applications.
[0027] The info information area stores the running area, startup address, code verification code area, code length, upgrade time, and upgrade version number of the BootLoader and app application programs respectively.
[0028] The Block x includes multiple Block areas, each of which stores a BootLoader boot program, and the Block y includes multiple Block areas, each of which stores an app application.
[0029] A computer-readable storage medium stores a computer program. When the computer program is executed by a processor, a method for flexible storage and upgrading of boot and application programs is implemented.
[0030] The present invention has the following beneficial effects and advantages:
[0031] 1. In practical applications, the present invention solves the abnormal problem of application program failure. After starting from the BootLoader, a new application program can be upgraded, and the info information area can be modified to correspond to the parameters of the new application program, such as the running area, startup address, code verification code area, code length, upgrade time, and upgrade version number.
[0032] 2. When updating the BootLoader program, you can upgrade the BootLoader through the application, which does not require a restart and disrupts business operations, thereby improving efficiency.
[0033] 3. The program storage area can have multiple segments, such as segment A, segment B, and segment C. For example, when segment A is running, before upgrading to the new official version, you can upgrade a test program to segment B for testing. After the test, you can upgrade the official version to segment C. If there is a problem again, you can switch back to segment B to continue testing, so there is no need to upgrade back and forth. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a 3-segment storage area division diagram;
[0035] Figure 2 It is the info information area map;
[0036] Figure 3 It is the startup flow chart;
[0037] Figure 4 It is the BootLoader operation flow chart;
[0038] Figure 5 It is the BootLoader upgrade object indication diagram;
[0039] Figure 6 This is an indication diagram of the app upgrade object. DETAILED DESCRIPTION
[0040] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0041] This embodiment provides a method and system for flexibly storing and upgrading boot and application programs; the system is divided into (eg Figure 1): boot program, info information area, BootLoader boot program, app application; the boot program is called by CPU from nandflash to DDR for execution, and the boot program is on block0; the info information area (such as Figure 2 ), which stores BootLoader, application app boot program running area, startup address, code verification code area, code length, upgrade time, and upgrade version number; the BootLoader boot program includes multiple areas with different versions of BootLoader programs, which can be 2 areas, 3 areas, or N areas: such as area a, area b, and area c programs. This embodiment has only 3 areas; the app application includes multiple areas with different versions of app application programs, which can be 2 areas, 3 areas, or N areas. This embodiment has only 3 areas.
[0042] When the boot program is running, the boot program searches for the BootLoader running area in the info information area and boots the BootLoader with the specified startup address; (such as Figure 4 After the Bootloader runs, it waits 3-6 seconds (depending on actual requirements) for an upgrade command. If no upgrade command is received, it searches the info area for the app's running area and the specified startup address to boot the app. If an upgrade command is received, it determines whether the upgrade target is the Bootloader or the app, and which storage area is being upgraded. The data in the info area can be modified later during an upgrade.
[0043] In the present invention, BootLoader upgrades the non-running segment app, and BootLoader upgrades the non-running BootLoader segment (such as Figure 5 ), and the app can also upgrade the non-running segment BootLoader and non-running segment app (such as Figure 6 During the process of the app running the non-operating BootLoader and non-operating app, the application is not interrupted and does not need to exit the business.
[0044] When the App upgrades the BootLoader and the App (such as Figure 6), which is part of the business logic and does not require exiting the program or restarting the device to receive upgrade instructions. When the app is running and receives an upgrade instruction, it parses the first packet data to determine whether the upgrade target is the BootLoader program or the app program. It then parses the upgrade area to determine whether it is a non-operating segment. It records the version number and then responds. The middle packet data is the program package and the verification segment, which verify the correctness of the program package. If correct, it is stored in the corresponding startup address location. The last packet data is the verification packet, which verifies the correctness and integrity of all program packages. If incomplete, the package replenishment process begins until the program is complete.
[0045] exist Figure 2 The info information area is divided into the bootloader information area and the app information area. They both have a running area, startup address, code verification code area, code length, upgrade time, and upgrade version number; the running area refers to the selection of the running program as segment A, segment B, or segment C. The startup address is the starting address of the running program in nandflash. The code verification code area is the CRC check bit generated by each upgrade package when the program is upgraded. The code length refers to the number of pages of nandflash occupied by each segment of the program. The upgrade time refers to the time when the first upgrade package is successfully verified, that is, the time when the upgrade starts. The upgrade version number refers to the version number of each upgrade program.
[0046] The first data packet is the upgrade instruction, including: upgrade object identification code, upgrade segment code, upgrade version number, time. The upgrade object identification code is used to determine whether to upgrade the app application or the BootLoader program; the upgrade segment code is the segment code to be upgraded. If the segment code is 2 and the value of the info access area running area is not 2, the next step can be carried out.
[0047] The intermediate package data includes: upgrade object identifier, program version number, startup address and program content package. Verify whether the program package is consistent with the first package. If consistent, store it in the corresponding startup address location;
[0048] The last packet is a check packet, which verifies the correctness and integrity of all program packages. If it is incomplete, the package replenishment process will be started until the program is complete. If it is complete and correct, when switching programs, first modify the corresponding program running area value in the info area, and then restart to complete the program switching operation.
[0049] This flexible switching between different programs is specified by the run area in the info area. After reading the corresponding startup address, the program in the storage area starting from the startup address and with a length equal to the code length is copied to the DDR and started to run.
[0050] This flexible storage means that by modifying the boot address in the info area, the upgraded code can be stored in the area after this boot address. This can avoid bad blocks and is also simple to handle.
[0051] For example, the app program is divided into three versions, namely V1.0, V2.0, and V3.0; they are stored in the A segment storage area, the B segment storage area, and the C segment storage area respectively; the startup address position corresponding to the A segment storage area is 0x80010000, the startup address position corresponding to the B segment storage area is 0x80110000, and the startup address position corresponding to the C segment storage area is 0x80210000. When there is a bad block in the B segment storage area at the startup address 0x80110000 where the app program V2.0 is located, causing V2.0 to be unable to run, it will not be possible to write to the B area through upgrading, which will cause the program to be patched infinitely, resulting in errors. Therefore, by modifying the startup address 0x80310000 corresponding to the B segment storage area to avoid bad blocks, flexible storage is achieved. The described embodiments are only part of the embodiments of the present invention, not all of them.
[0052] The present invention divides the system into: a boot program, an info information area, a BootLoader boot program, and an application (hereinafter also referred to as app). The boot program is called by the CPU from nand flash to DDR for execution, and the boot program is on block 0; the info information area stores the BootLoader, the application app boot program running area, the startup address, the code verification code area, the code length, the upgrade time, and the upgrade version number; the BootLoader boot program includes multiple areas with different versions of BootLoader programs, which can be 2 areas, 3 areas, or N areas: such as area a, area b, and area c programs; the app application includes multiple areas with different versions of app application programs, which can be 2 areas, 3 areas, or N areas.
[0053] Figure 3After the boot program is running, [step 1] searches the info information area for the BootLoader running area, and [step 2] uses the specified startup address to boot the BootLoader. After the BootLoader runs, [step 3] searches the info information area for the app running area, and [step 4] uses the specified startup address to boot the app. The data in the info area can be modified later through upgrades. The present invention can enable the BootLoader to upgrade the non-running app segment and the non-running BootLoader segment, and the app can also upgrade the non-running BootLoader segment and the non-running app segment. This ensures system stability and is particularly suitable for use in the petroleum WIAPA Internet of Things system, with good practical value.
[0054] Boot can flexibly select BootLoader programs in different areas based on the information read in the info area.
[0055] BootLoader can flexibly select APP programs in different areas based on the information read in the info area.
[0056] The BootLoader can upgrade the non-running BootLoader segment and the non-running app segment.
[0057] App applications can be upgraded in the non-running BootLoader segment and the non-running app segment.
[0058] When the app application is upgraded and the non-running BootLoader segment is upgraded or the non-running app segment is upgraded, the business in the app application is not interrupted.
Claims
1. A method for flexibly storing and updating boot and application programs, characterized in that: The following steps are involved: Call the boot program on Block 0 into memory and run the boot program; The boot program searches the BootLoader boot program running area and the specified startup address in the info information area, and guides the BootLoader boot program to run; After the BootLoader boot program runs, it waits for the upgrade instruction. If it does not receive the upgrade instruction, it searches the app application running area and the specified startup address in the info information area to boot the app application to run; If an upgrade instruction is received, the upgrade instruction is parsed and the upgrade is performed according to the parsing result; The upgrade process includes: BootLoader upgrades non-running app applications, BootLoader upgrades other non-running BootLoader boot programs, app application upgrades non-running BootLoader boot programs, and app application upgrades other non-running app applications; The app application upgrades the BootLoader and other app applications separately as follows: When an app receives an upgrade command during its operation, it first parses the upgrade command to determine whether the object to be upgraded is the Bootloader or the app. It then parses the area to be upgraded to determine whether it is a non-running segment. If so, it records the version number to be upgraded and responds, waiting to receive the upgrade package and perform the upgrade. Otherwise, exit the upgrade and execute the app normally.
2. The method for flexible storage and upgrade of boot and application programs according to claim 1, characterized in that: The parsing of the upgrade instruction is specifically as follows: the upgrade object in the parsing upgrade instruction is to upgrade the BootLoader boot program or the app application, and the position of the Block area where the content to be upgraded is located.
3. The method for flexible storage and upgrade of boot and application programs according to claim 1, characterized in that: The upgrade package includes: The first data packet is the upgrade instruction, including: upgrade object identification code, upgrade segment code, upgrade version number, and time; The middle package data includes: upgrade object identifier, program version number, startup address, and program content; The tail packet data is the test data, which verifies the correctness and integrity of all program packages.
4. A system for flexible storage and upgrade of boot and application programs, characterized in that: include: The first boot module is used to search for info information, call the second boot module containing the upgrade module, copy it to the memory and run the BootLoader boot program; The second boot module is used to search for info information, call the app application containing the upgrade module, and copy it to the memory to run the app application; The upgrade module is used to wait for an upgrade instruction after the BootLoader boot program runs. If no upgrade instruction is received, it searches the app application running area and the specified startup address in the info information area to boot the app application to run; if an upgrade instruction is received, it parses the upgrade instruction and upgrades according to the parsing result; or it is used to wait for an upgrade instruction after the app application runs. If no upgrade instruction is received, it continues to run other applications. If an upgrade instruction is received, it parses the upgrade instruction and upgrades according to the parsing result; The system includes multiple Block areas for storing different programs and information, including: Block 0 is used to store the boot program to guide and run the boot program; Block 1, used to store info information area; Block x, used to store the BootLoader program; Block y, used to store app applications; The Block x includes multiple Block areas, each of which stores a BootLoader boot program, and the Block y includes multiple Block areas, each of which stores an app application.
5. The system for flexible storage and update of boot and application programs according to claim 4, characterized in that: The info information area stores the running area, startup address, code verification code area, code length, upgrade time, and upgrade version number of the BootLoader and app application programs respectively.
6. A computer-readable storage medium, characterized in that The storage medium stores a computer program, and when the computer program is executed by the processor, the method for flexible storage and upgrading of boot and application programs as described in any one of claims 1 to 3 is implemented.
Citation Information
Patent Citations
Frequency converter control system program upgrading method
CN106227572A
Chip program upgrading method and device and storage medium
CN111309364A