WO2015184732A1 - Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium - Google Patents

Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium Download PDF

Info

Publication number
WO2015184732A1
WO2015184732A1 PCT/CN2014/090696 CN2014090696W WO2015184732A1 WO 2015184732 A1 WO2015184732 A1 WO 2015184732A1 CN 2014090696 W CN2014090696 W CN 2014090696W WO 2015184732 A1 WO2015184732 A1 WO 2015184732A1
Authority
WO
WIPO (PCT)
Prior art keywords
code
stage
backup
partition
unit
Prior art date
Application number
PCT/CN2014/090696
Other languages
French (fr)
Chinese (zh)
Inventor
段瑞楠
Original Assignee
西安中兴新软件有限责任公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 西安中兴新软件有限责任公司 filed Critical 西安中兴新软件有限责任公司
Publication of WO2015184732A1 publication Critical patent/WO2015184732A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Definitions

  • the invention relates to a boot program management technology in the embedded field, in particular to a storage method of a boot program, a fault recovery method and device, and a computer storage medium.
  • UBoot and BootLoader are boot programs for Central Processing Units (CPUs) for a variety of embedded devices.
  • UBoot is an upgraded version of BootLoader.
  • UBoot supports not only Linux but also VxWorks, NetBSD, and LyxOS. operating system.
  • the processors that UBoot can support include: 80 ⁇ 86, ARM, MIPS, XScale, and PowerPC.
  • the main function of UBoot is to initialize the hardware device. After the software and hardware running environment is set, the operating system kernel is loaded into the memory from the storage medium. Finally, jump to the operating system portal and transfer control to the operating system.
  • FOTA Firmware Over The Air
  • the FOTA technology upgrade usually adopts the differential upgrade method.
  • the idea of differential upgrade is to compare two software versions, calculate the difference between the two software versions according to the difference algorithm, and carry, modify, and erase the difference pages in the storage medium flash block.
  • To complete the firmware upgrade complete the file system upgrade by random reading and writing files.
  • the first stage code and the second stage code in the boot program are combined and stored in a storage medium, and here, generally used to complete basic parameter setting and loading the second stage code into the memory.
  • the code is called the first stage code.
  • the code that loads the kernel to the memory and runs is called the second stage code.
  • the boot program fails during the running or upgrading process, the system will be difficult to recover.
  • Need to remove the storage medium use the burner to perform software rewriting or write with the Joint Test Action Group (JTAG) interface, which is not only insecure, but also destroys the problem site and brings the software development process. A lot of inconvenience.
  • JTAG Joint Test Action Group
  • embodiments of the present invention are expected to provide a storage method, a failure recovery method, and a device for booting a program, which can keep the boot program of the embedded system stable, thereby improving the security of the embedded system.
  • the embodiment of the invention provides a storage method of a boot program, the method comprising:
  • the two-stage code is used to load the kernel into memory and run it;
  • the first stage code is stored in a preset first partition in the storage medium
  • the second stage code is stored in a preset second partition in the storage medium.
  • the method further includes:
  • the second stage backup code is stored in a preset third partition in the storage medium.
  • the method further includes:
  • the updated second stage code update is stored in The second stage backup code in the third partition.
  • the embodiment of the present invention provides a method for recovering a fault of a booting program.
  • the first phase code and the second phase code are respectively stored in a first partition and a second partition of the storage medium.
  • the method further includes:
  • the first stage code detects whether the second stage code is faulty
  • the download mode of the boot program is entered.
  • the method further includes:
  • the boot mode of the boot program is entered.
  • the method further includes:
  • the second stage code is inconsistent with the second stage backup code, it is determined that the second piece of code stored in the second partition has been upgraded, and the upgraded second stage code is further used.
  • the second stage backup code newly stored in the third partition.
  • an embodiment of the present invention provides a storage device, where the storage device includes: a configuration unit and a storage unit;
  • the configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
  • the storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium.
  • the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code.
  • the storage unit is further configured to store the second stage backup code in a third partition preset in the storage medium.
  • the storage device further includes:
  • an update unit configured to update the second stage backup code stored in the third partition with the upgraded second stage code after the second stage code upgrade.
  • the embodiment of the present invention further provides an embedded device, where the embedded device includes: a configuration unit, a storage unit, a detecting unit, a determining unit, and a fault recovery unit;
  • the configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
  • the storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
  • the detecting unit is configured to detect, after the completion of the basic parameter setting, the first stage code, whether the second stage code is faulty;
  • the determining unit is configured to determine whether there is a second-stage backup code when the detecting unit detects the second-stage code failure;
  • the fault recovery unit is configured to enter a download mode of the boot program when the determining unit determines that the second stage backup code does not exist.
  • the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code.
  • the storage unit is further configured to backup the second stage.
  • the code is stored in a third partition preset in the storage medium;
  • the detecting unit is further configured to detect whether the second stage backup code is faulty
  • the fault recovery unit is further configured to determine, in the determining unit, that the second phase backup code exists, and when the detecting unit detects that the second phase backup code is faultless, recovering the fault by using the second phase backup code
  • the second stage code stored in the second partition the determining unit determines that the second stage backup code exists, and enters a download mode of the boot program when the detecting unit detects the second stage backup code failure.
  • the detecting unit is further configured to detect whether the second phase code is consistent with the second phase backup code
  • the embedded device further includes:
  • An execution unit configured to detect, in the detecting unit, that the second phase code is faultless, and when the determining unit determines that the second phase backup code does not exist, jump to an entry of the second phase code to complete the remaining Initializing operation; detecting, by the detecting unit, that the second-stage code is fault-free, and when the determining unit determines that the second-stage backup code exists, if the detecting unit detects the second-stage code and the If the two-stage backup code is consistent, then jump to the entry of the second-stage code to complete the remaining initialization operations;
  • An update unit configured to detect, in the detecting unit, that the second stage code is faultless, and When the determining unit determines that the second stage backup code exists, if the detecting unit detects that the second stage code is inconsistent with the second stage backup code, it is determined that the second piece of code has been upgraded, and the upgrade is performed.
  • the second stage of code update updates the second stage backup code stored in the third partition.
  • Embodiments of the present invention also provide a computer storage medium having stored therein computer executable instructions for performing the above method.
  • the storage method, the fault recovery method and device, the computer storage medium, the first stage code and the second stage code of the boot program are provided by the embodiment of the present invention; wherein the first stage code is used to complete the basic parameter Setting, performing fault detection on the second stage code, and performing corresponding operations according to the detection result; the second stage code is used to load the kernel into the memory and run; storing the first stage code in the storage medium preset first Partitioning, and storing the second stage code in a second partition preset in the storage medium; thus, during the running or upgrading of the booting program, the first partition preset in the storage medium is not frequently erased, Only the second partition preset in the storage medium is erased, so that the storage area where the problem occurs in the storage medium can be reduced, thereby prolonging the service life of the storage medium.
  • the download operation mode of the boot program may be entered; if the second stage backup code exists and the second stage backup is detected The code is not faulty, and the second stage backup code stored in the third partition can be used to recover the fault stored in the second partition second stage code; if the second stage backup code exists, the second stage backup code is detected to be faulty , can enter the boot operation mode of the boot program; thus, it can timely recover the faults occurring during the boot program running or upgrading process, thereby improving the security of the embedded system.
  • FIG. 1 is a schematic flowchart of an implementation method of a storage method of a boot program according to an embodiment of the present invention
  • FIG. 2 is a schematic flowchart of a method for implementing a fault recovery method of a boot program according to an embodiment of the present invention
  • FIG. 3 is a schematic structural diagram of a storage device according to an embodiment of the present invention.
  • FIG. 4 is a schematic structural diagram of an embedded device according to an embodiment of the present invention.
  • the first stage code and the second stage code of the boot program are configured; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result.
  • the second stage code is used to load the kernel into the memory and run; store the first stage code in a preset first partition in the storage medium, and store the second stage code in a storage medium preset The second partition.
  • the embodiment of the invention provides a storage method of the boot program. As shown in FIG. 1 , the method includes:
  • Step S100 Configure the first stage stage1 code of the bootstrap program and the second stage stage2 code.
  • the bootloader can be BootLoader, UBoot, or a more advanced version of the bootloader.
  • the boot program usually includes a boot load mode and a download mode, and allows the user to switch between the two work modes; wherein, the boot load mode, also called “autonomous boot mode", that is, the program from the target machine On the storage medium, the operating system is loaded into the memory random access memory (RAM) and booted.
  • the whole process has no user intervention.
  • the boot mode is a commonly used mode in the normal working mode of the boot program. Boot mode, therefore, when the embedded device is released, the program is generally booted to boot the kernel code in the boot mode; in the download mode, the boot program on the target machine in the boot mode will communicate through a serial port connection or a network connection. Download files from the host, such as downloading applications, data files, kernel images, etc. Files downloaded from the host are usually saved to the directory by the boot program.
  • the memory RAM of the standard machine is then written by the boot program to the storage medium on the target machine, and finally the boot operation of the kernel is completed.
  • the bootloader is divided into stage1 and stage2 in the bootloader mode.
  • the stage1 code is usually implemented in assembly language and contains the following basic steps:
  • the Stage2 code is usually implemented in C and consists of the following basic steps:
  • the configured stage1 code is used to complete basic parameter setting, perform fault detection on the stage2 code, and perform corresponding operations according to the detection result; wherein, basic parameters, for example, a central processing unit (CPU) Parameters, memory parameters, and some basic input/output (I/O) control parameters; the stage2 code configured to complete the remaining initialization operations, namely: loading the kernel into memory and running.
  • basic parameters for example, a central processing unit (CPU) Parameters, memory parameters, and some basic input/output (I/O) control parameters
  • the stage2 code configured to complete the remaining initialization operations, namely: loading the kernel into memory and running.
  • Step S101 Store the stage1 code in a preset first partition in the storage medium, and store the stage2 code in a preset second partition in the storage medium.
  • NAND Flash storage media in embedded devices
  • the stage1 code and the stage2 code are partitioned and stored in a storage medium, and when the boot program is upgraded by using FOTA technology, the stage1 code is fixed. None upgrade, only the stage2 code that can be upgraded is upgraded. Therefore, during the boot process upgrade, the first partition preset in the storage medium is not frequently erased, only the storage medium is preset. The second partition is erased, so that the storage area in the storage medium can be reduced, thereby prolonging the service life of the storage medium; and in the process of running or upgrading the boot program, if the first stage code detects the second stage If the code fails, it will directly enter the boot mode of the bootloader, which can save the embedded system and improve the security of the embedded system.
  • the stage2 code may be backed up to obtain a second stage backup stage2backup code, and the stage2backup code is stored in a preset third partition in the storage medium; during the boot program running or upgrading, the stage1 is considered The code is definitely not faulty.
  • the stage2backup code stored in the third partition can be used to recover the faulty stage2 code, so that the boot program can be run or upgraded in time. The failures that occur are restored to improve the security of the embedded system.
  • stage2backup code stored in the third partition is updated with the upgraded stage2 code.
  • the failed stage2 code is stored in a preset fourth partition in the storage medium, so as to subsequently troubleshoot the problem according to the faulty stage2 code, and facilitate the positioning of the problem.
  • the embodiment of the present invention provides a fault recovery method for a boot program, where the first phase code and the second phase code are respectively stored in the first partition and the second partition of the storage medium; as shown in FIG. 2,
  • the method includes:
  • Step S200 After the basic parameter setting is completed, the stage1 code detects whether the stage 2 code of the second stage is faulty. If the stage2 code is detected to be faulty, the process goes to step S201; if the stage2 code is detected to be faultless, then the process proceeds to Step S204.
  • Step S201 determining whether there is a stage2backup code, determining that there is a second-stage backup code, proceeding to step S202; and determining that there is no stage2backup code, entering a download mode of the boot program.
  • Step S202 detecting whether the stage2backup code is faulty, detecting that the stage2backup code is faultless, and proceeding to step S203; and detecting that the stage2backup code is faulty, entering the bootloader download mode.
  • Step S203 recovering the failed stage2 code stored in the second partition by using the stage2backup code, and proceeding to step S200.
  • Step S204 determining whether there is a stage2backup code, determining that there is no stage2backup code, jumping to the entry of the stage2 code, completing the remaining initialization operations; determining that there is a stage2backup code, proceeding to step S205.
  • Step S205 detecting whether the stage2 code is consistent with the stage2backup code. If it is detected that the stage2 code is consistent with the stage2backup code, jump to the entry of the stage2 code to complete the remaining initialization operations; if it is detected that the stage2 code is inconsistent with the stage2backup code, then Proceed to step S206.
  • Step S206 It is determined that the stage2 code has been upgraded, and the stage2backup code stored in the third partition is updated by using the upgraded stage2 code.
  • step S200 after the basic parameter setting is completed, the stage1 code reads the stage2 code from the storage medium into the memory, and generates a check of the stage2 code by using a preset check code generation algorithm.
  • the code compares the generated check code with the pre-stored stage2 check code to detect whether the stage2 code is faulty. If the generated check code is different from the pre-stored stage2 check code, the stage2 code is detected to be faulty. Go to step S201; if the generated check code is the same as the pre-stored stage 2 check code, it is detected that the stage 2 code is not faulty, and the process proceeds to step S204.
  • step S201 it is determined whether there is a stage2backup code, it is determined that there is a second-stage backup code, and the process proceeds to step S202; when it is determined that the stage2backup code does not exist, the download mode of the boot program is entered.
  • step S202 the stage2backup generation is generated by using a preset check code generation algorithm.
  • the check code of the code compares the generated check code with the pre-stored stage2backup check code to detect whether the stage2backup code is faulty. If the generated check code is different from the pre-stored stage2backup check code, the detection center is detected. If the stage 2backup code is faulty, the boot program download mode is entered; if the generated check code is the same as the pre-stored stage 2backup check code, if it is detected that the stage 2backup code is not faulty, the process proceeds to step S203.
  • step S203 the stage2backup code is used to recover the failed stage2 code stored in the second partition, that is, the stage2backup code stored in the third partition is written into the second partition corresponding to the faulty stage2 code, so that it can be timely Perform error correction and recover the faulty stage2 code; preferably, after writing the stage2backup code to the second partition corresponding to the faulty stage2 code, it can be written in the predefined flag bit to indicate that "the bootloader needs to be re-run or When the flag indicating "the boot program needs to be re-run or upgraded" is detected, the process proceeds to step S200, the boot program running or upgrading process is re-initiated, and the flag is cleared.
  • step S204 it is determined whether there is a stage2backup code, it is determined that there is no stage2backup code, jump to the entry of the stage2 code, and the remaining initialization operations are completed; when it is determined that the stage2backup code exists, the process proceeds to step S205.
  • step S205 the check code of the stage2backup code is first generated by using the same check code generation algorithm as the stage2, and when the stage2backup code is determined to be faultless, the check code of the stage2backup is compared with the stage2 Checking the check code, if the check code of the stage2backup is the same as the check code of the stage2, it is detected that the stage2 code is consistent with the stage2backup code, jumps to the entry of the stage2 code, and completes the remaining initialization operations; If the check code of the stage2backup is different from the check code of the stage2, it is detected that the stage2 code is inconsistent with the stage2backup code. At this time, it is determined that the stage2 code has been upgraded, and the process proceeds to step S206.
  • step S206 the upgraded stage2 code is used to update the storage in the third partition.
  • the stage2backup code that is, writes the upgraded stage2 code to the third partition corresponding to the stage2backup code.
  • the failure of the stage2 code may be caused by power failure when upgrading the stage2 code.
  • the stage1 code in the boot program is first run, and the stage2 code is detected to detect that the stage2 code is faulty.
  • the system can be recovered and saved in time, thereby avoiding the system booting problem occurring in the prior art; the failure of the stage2 code may also be caused by frequent erasing of the second partition in the storage medium, resulting in the second The partition is caused by bad blocks.
  • the check code generation algorithm may be an external irreversible push, and an algorithm with a relatively high collision cost, such as a salinated information digest algorithm MD5.
  • the verification operation has a high performance requirement ratio, and an appropriate check code generation algorithm can be designed.
  • a check code generation algorithm with a certain encryption strength can be designed.
  • the check code generation algorithm is not specifically limited.
  • the failed stage2 code is written to the preset fourth partition in the storage medium, so as to subsequently troubleshoot the problem according to the faulty stage2 code.
  • the stage1 code and the stage2 code are partitioned and stored in a storage medium, that is, the stage1 code is stored in a preset first partition in the storage medium, and the stage2 code is stored. a second partition preset in the storage medium; when the boot program is run or upgraded, the stage1 code is fixed, never upgraded, only the stage2 code that can be upgraded is upgraded, therefore, the boot program During the running or upgrading process, the first partition preset in the storage medium is not frequently erased, and only the second partition preset in the storage medium is erased; thus, when the stage2 code fails, You can directly enter the boot mode of the bootloader and save the system in time to improve the security of the embedded system.
  • the stage2 code is backed up to obtain a stage2backup code, and the stage2backup code is stored in a preset third partition in the storage medium.
  • the Stage1 code is definitely not going to fail
  • the stage2 code and the stage2backup code are guaranteed by software logic that one of the points in time is fault-free or complete, and when the stage2 code fails, the fault-free storage in the third partition can be utilized.
  • the stage2backup code restores the stage2 code of the fault stored in the second partition; thus, it can recover the faults occurring during the booting or upgrading process in time, thereby improving the security of the embedded system;
  • stage2 fails, if the stage2backup code also fails, the download mode of the boot program is entered, and the system can be rescued in time.
  • the embodiments of the present invention can be applied not only to the upgrade scenario of the bootstrap program, but also to any scenario that ensures the integrity of the bootloader.
  • the embodiment of the present invention further provides a storage device and an embedded device. Since the principle and method for solving the problem between the storage device and the embedded device are similar, the implementation process and implementation of the storage device and the embedded device are implemented. For the principle, refer to the implementation process of the foregoing method and the description of the implementation principle, and the repeated description will not be repeated.
  • the storage device provided by the embodiment of the present invention includes: a configuration unit 300 and a storage unit 301;
  • the configuration unit 300 is configured to configure a first stage code and a second stage code of the bootstrap program
  • the storage unit 301 is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
  • the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result; the second stage code is used to load the kernel into the memory and run.
  • the configuration unit 300 is further configured to configure a backup code of the second stage code to obtain a second stage backup code.
  • the storage unit 301 is further configured to:
  • the second stage backup code is stored in a preset third partition in the storage medium.
  • the storage device further includes:
  • the updating unit 302 is configured to update the second stage backup code stored in the third partition by using the upgraded second stage code after the second stage code upgrade.
  • the embedded device provided by the embodiment of the present invention includes: a configuration unit 300, a storage unit 301, a detecting unit 400, a determining unit 401, and a fault recovery unit 402;
  • the configuration unit 300 is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and execute according to the detection result. Corresponding operation; the second stage code is used to load the kernel into memory and run;
  • the storage unit 301 is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
  • the detecting unit 400 is configured to detect, after the basic parameter setting is completed in the first stage code, whether the second stage code is faulty;
  • the determining unit 401 is configured to determine whether there is a second-stage backup code when the detecting unit 400 detects the second-stage code failure;
  • the fault recovery unit 402 is configured to enter a download operation mode of the boot program when the determining unit 401 determines that the second stage backup code does not exist.
  • the configuration unit 300 is further configured to configure the preparation of the second phase code. a second stage backup code is obtained; correspondingly, the storage unit 301 is further configured to store the second stage backup code in a third partition preset in the storage medium;
  • the detecting unit 400 is further configured to detect whether the second stage backup code is faulty
  • the fault recovery unit 402 is further configured to determine, in the determining unit 401, that the second phase backup code exists, and use the second phase backup code when the detecting unit 400 detects that the second phase backup code is not faulty. Recovering the second stage code stored in the second partition; determining that the second stage backup code exists in the determining unit 401, and entering the boot program when the detecting unit 400 detects the second stage backup code failure Download the operating mode.
  • the detecting unit 400 is further configured to detect whether the second phase code is consistent with the second phase backup code
  • the embedded device further includes:
  • the executing unit 403 is configured to detect that the second phase code is not faulty at the detecting unit 400, and jump to the entrance of the second phase code when the determining unit 401 determines that the second phase backup code does not exist And completing the remaining initialization operation; detecting, by the detecting unit 400, that the second-stage code is fault-free, and when the determining unit 401 determines that the second-stage backup code exists, if the detecting unit 400 detects the second The phase code is consistent with the second phase backup code, then jumps to the entry of the second phase code to complete the remaining initialization operations;
  • the updating unit 302 is configured to detect, when the detecting unit 400 detects that the second phase code is faultless, and when the determining unit 401 determines that the second phase backup code exists, if the detecting unit 400 detects the second phase The code is inconsistent with the second stage backup code, and it is determined that the second piece of code stored in the second partition has been upgraded, and the second stage backup code stored in the third partition is updated with the upgraded second stage code.
  • Embodiments of the present invention also provide a computer storage medium having stored therein computer executable instructions for performing the above method.
  • the configuration unit 300, the storage unit 301, and the update unit 302 may be a central processing unit (CPU), a microprocessor (MPU), and a digital signal processor (DSP) located in the storage device.
  • a field programmable gate array (FPGA) implementation the configuration unit 300, the storage unit 301, the update unit 302, the detection unit 400, the determination unit 401, the fault recovery unit 402,
  • the execution unit 403 can be implemented by a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA) located in the embedded device.
  • embodiments of the present invention can be provided as a method, system, or computer program product. Accordingly, the present invention can take the form of a hardware embodiment, a software embodiment, or a combination of software and hardware. Moreover, the invention can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) including computer usable program code.
  • the computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device.
  • the apparatus implements the functions specified in one or more blocks of a flow or a flow and/or block diagram of the flowchart.
  • These computer program instructions can also be loaded into a computer or other programmable data processing device Having a series of operational steps performed on a computer or other programmable device to produce computer-implemented processing such that instructions executed on a computer or other programmable device are provided for implementing one or more processes in a flowchart and/or Or block diagram the steps of a function specified in a box or multiple boxes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Stored Programmes (AREA)

Abstract

Disclosed are a bootstrap storage method, which comprises: configuring first-stage codes and second-stage codes of a bootstrap (S100), wherein the first-stage codes are used for completing basic parameter setting, performing fault detection on the second-stage codes and executing corresponding operations according to detection results, and the second-stage codes are used for loading a kernel to memory and running the kernel; and storing the first-stage codes in a first partition preset in a storage medium and storing the second-stage codes in a second partition preset in the storage medium (S101). In addition, also disclosed are a bootstrap fault recovery method, a storage device and an embedded device, and a computer storage medium.

Description

引导程序的存储方法、故障恢复方法及设备、计算机存储介质Bootloader storage method, fault recovery method and device, computer storage medium 技术领域Technical field
本发明涉及嵌入式领域的引导程序管理技术,尤其涉及一种引导程序的存储方法、故障恢复方法及设备、计算机存储介质。The invention relates to a boot program management technology in the embedded field, in particular to a storage method of a boot program, a fault recovery method and device, and a computer storage medium.
背景技术Background technique
UBoot及BootLoader是用于多种嵌入式设备的中央处理器(Central Processing Unit,CPU)的引导程序,UBoot是BootLoader升级后的版本;UBoot不仅支持Linux系统,而且支持VxWorks、NetBSD、LyxOS等嵌入式操作系统。UBoot可以支持的处理器包括:80×86、ARM、MIPS、XScale、PowerPC,UBoot的主要功能是初始化硬件设备,待将软硬件运行环境设置好后,将操作系统内核从存储介质中载入内存,最终跳转到操作系统入口,将控制权移交给操作系统。UBoot and BootLoader are boot programs for Central Processing Units (CPUs) for a variety of embedded devices. UBoot is an upgraded version of BootLoader. UBoot supports not only Linux but also VxWorks, NetBSD, and LyxOS. operating system. The processors that UBoot can support include: 80×86, ARM, MIPS, XScale, and PowerPC. The main function of UBoot is to initialize the hardware device. After the software and hardware running environment is set, the operating system kernel is loaded into the memory from the storage medium. Finally, jump to the operating system portal and transfer control to the operating system.
空中接口固件更新(Firmware Over The Air,FOTA)是终端设备的固件升级空中下载技术,指终端设备通过云端设备管理(Device Management,DM)及下载协议,将固件升级包通过互联网下载到终端设备内部;然后,由终端设备内部的安装程序进行自升级,从而实现软件Bug的修复、新功能的扩展。Firmware Over The Air (FOTA) is a firmware upgrade over-the-air download technology for terminal devices. It refers to the terminal device downloading the firmware upgrade package to the terminal device through the Internet through the Device Management (DM) and download protocol. Then, the self-upgrade is performed by the installer inside the terminal device, thereby realizing the repair of the software bug and the expansion of the new function.
FOTA技术升级通常采用差分升级的方式,差分升级的思想是对比两个软件版本,根据差分算法计算出两个软件版本的差异部分,通过对存储介质Flash块中差异页进行搬运、修改、擦除来完成固件升级,通过对文件进行随机读写完成文件系统的升级。The FOTA technology upgrade usually adopts the differential upgrade method. The idea of differential upgrade is to compare two software versions, calculate the difference between the two software versions according to the difference algorithm, and carry, modify, and erase the difference pages in the storage medium flash block. To complete the firmware upgrade, complete the file system upgrade by random reading and writing files.
但是,现有引导程序升级的技术方案至少存在以下缺陷:However, the existing technical solutions for bootloader upgrades have at least the following drawbacks:
1)现有技术中,若升级引导程序时出现掉电,下次启动系统时会出现 系统自举问题。1) In the prior art, if a power failure occurs when upgrading the boot program, it will appear the next time the system is booted. System bootstrapping problem.
2)现有技术中,引导程序中的第一阶段代码和第二阶段代码是合并在一起存储于存储介质中的,这里,通常将用于完成基本参数设置和加载第二阶段代码到内存的代码称为第一阶段代码,将用于加载内核到内存并运行的代码称为第二阶段代码;若引导程序在运行或升级过程中出现了故障,系统将难以恢复,这种情况下,就需要进行存储介质拆卸,用烧片器进行软件重写或者用联合测试工作组(Joint Test Action Group,JTAG)接口进行写入,这样不但不安全,而且破坏了问题现场,为软件研发过程带来了许多不便。2) In the prior art, the first stage code and the second stage code in the boot program are combined and stored in a storage medium, and here, generally used to complete basic parameter setting and loading the second stage code into the memory. The code is called the first stage code. The code that loads the kernel to the memory and runs is called the second stage code. If the boot program fails during the running or upgrading process, the system will be difficult to recover. In this case, Need to remove the storage medium, use the burner to perform software rewriting or write with the Joint Test Action Group (JTAG) interface, which is not only insecure, but also destroys the problem site and brings the software development process. A lot of inconvenience.
发明内容Summary of the invention
有鉴于此,本发明实施例期望提供一种引导程序的存储方法、故障恢复方法及设备,能够使嵌入式系统的引导程序保持稳定运行,从而提高嵌入式系统的安全性。In view of this, embodiments of the present invention are expected to provide a storage method, a failure recovery method, and a device for booting a program, which can keep the boot program of the embedded system stable, thereby improving the security of the embedded system.
为达到上述目的,本发明的技术方案是这样实现的:In order to achieve the above object, the technical solution of the present invention is achieved as follows:
本发明实施例提供了一种引导程序的存储方法,该方法包括:The embodiment of the invention provides a storage method of a boot program, the method comprising:
配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;Configuring a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result; The two-stage code is used to load the kernel into memory and run it;
将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区。The first stage code is stored in a preset first partition in the storage medium, and the second stage code is stored in a preset second partition in the storage medium.
一具体实施例中,所述方法还包括:In a specific embodiment, the method further includes:
配置所述第二阶段代码的备份代码,得到第二阶段备份代码;Configuring the backup code of the second stage code to obtain the second stage backup code;
将所述第二阶段备份代码存储于存储介质中预设的第三分区。The second stage backup code is stored in a preset third partition in the storage medium.
一具体实施例中,所述方法还包括:In a specific embodiment, the method further includes:
在所述第二阶段代码升级后,利用升级后的第二阶段代码更新存储于 第三分区中的第二阶段备份代码。After the second stage code upgrade, the updated second stage code update is stored in The second stage backup code in the third partition.
本发明实施例提供了一种引导程序的故障恢复方法,将第一阶段代码和第二阶段代码分别存储于存储介质的第一分区和第二分区中;该方法还包括:The embodiment of the present invention provides a method for recovering a fault of a booting program. The first phase code and the second phase code are respectively stored in a first partition and a second partition of the storage medium. The method further includes:
所述第一阶段代码在完成基本参数设置后,检测所述第二阶段代码是否故障;After the basic parameter setting is completed, the first stage code detects whether the second stage code is faulty;
检测到所述第二阶段代码故障时,确定是否存在第二阶段备份代码;When the second stage code failure is detected, determining whether there is a second stage backup code;
确定不存在所述第二阶段备份代码时,进入引导程序的下载模式。When it is determined that the second stage backup code does not exist, the download mode of the boot program is entered.
一具体实施例中,所述方法还包括:In a specific embodiment, the method further includes:
确定存在所述第二阶段备份代码时,检测所述第二阶段备份代码是否故障;Determining whether the second stage backup code is faulty when the second stage backup code exists;
检测到所述第二阶段备份代码无故障时,利用所述第二阶段备份代码恢复故障的存储于第二分区中的第二阶段代码;When detecting that the second stage backup code is faultless, recovering the second phase code stored in the second partition by using the second stage backup code;
检测到所述第二阶段备份代码故障时,进入引导程序的下载模式。When the second stage backup code failure is detected, the boot mode of the boot program is entered.
一具体实施例中,所述方法还包括:In a specific embodiment, the method further includes:
检测到所述第二阶段代码无故障时,确定是否存在所述第二阶段备份代码;When it is detected that the second stage code is faultless, determining whether the second stage backup code exists;
确定不存在所述第二阶段备份代码时,跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;Determining that the second stage backup code does not exist, jumping to the entry of the second stage code to complete the remaining initialization operations;
确定存在所述第二阶段备份代码时,检测所述第二阶段代码与所述第二阶段备份代码是否一致;When it is determined that the second stage backup code exists, detecting whether the second stage code is consistent with the second stage backup code;
若检测到所述第二阶段代码与所述第二阶段备份代码一致,则跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;If it is detected that the second phase code is consistent with the second phase backup code, jump to the entry of the second phase code to complete the remaining initialization operations;
若检测到所述第二阶段代码与所述第二阶段备份代码不一致,则确定存储于第二分区中的第二段代码已被升级,利用升级后的第二阶段代码更 新存储于第三分区中的第二阶段备份代码。If it is detected that the second stage code is inconsistent with the second stage backup code, it is determined that the second piece of code stored in the second partition has been upgraded, and the upgraded second stage code is further used. The second stage backup code newly stored in the third partition.
基于上述方法,本发明实施例提供了一种存储设备,该存储设备包括:配置单元、存储单元;其中,Based on the foregoing method, an embodiment of the present invention provides a storage device, where the storage device includes: a configuration unit and a storage unit;
所述配置单元,配置为配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;The configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
所述存储单元,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区。The storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium.
一具体实施例中,所述配置单元,还配置为配置所述第二阶段代码的备份代码,得到第二阶段备份代码;In a specific embodiment, the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code.
所述存储单元,还配置为将所述第二阶段备份代码存储于存储介质中预设的第三分区。The storage unit is further configured to store the second stage backup code in a third partition preset in the storage medium.
一具体实施例中,所述存储设备还包括:In a specific embodiment, the storage device further includes:
更新单元,配置为在所述第二阶段代码升级后,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。And an update unit configured to update the second stage backup code stored in the third partition with the upgraded second stage code after the second stage code upgrade.
基于上述方法,本发明实施例还提供了一种嵌入式设备,该嵌入式设备包括:配置单元、存储单元、检测单元、确定单元、故障恢复单元;其中,Based on the foregoing method, the embodiment of the present invention further provides an embedded device, where the embedded device includes: a configuration unit, a storage unit, a detecting unit, a determining unit, and a fault recovery unit;
所述配置单元,配置为配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;The configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
所述存储单元,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区; The storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
所述检测单元,配置为所述第一阶段代码在完成基本参数设置后,检测第二阶段代码是否故障;The detecting unit is configured to detect, after the completion of the basic parameter setting, the first stage code, whether the second stage code is faulty;
所述确定单元,配置为在检测单元检测到所述第二阶段代码故障时,确定是否存在第二阶段备份代码;The determining unit is configured to determine whether there is a second-stage backup code when the detecting unit detects the second-stage code failure;
所述故障恢复单元,配置为在确定单元确定不存在所述第二阶段备份代码时,进入引导程序的下载模式。The fault recovery unit is configured to enter a download mode of the boot program when the determining unit determines that the second stage backup code does not exist.
一具体实施例中,所述配置单元,还配置为配置所述第二阶段代码的备份代码,得到第二阶段备份代码;相应的,所述存储单元,还配置为将所述第二阶段备份代码存储于存储介质中预设的第三分区;In a specific embodiment, the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code. Correspondingly, the storage unit is further configured to backup the second stage. The code is stored in a third partition preset in the storage medium;
所述检测单元,还配置为检测所述第二阶段备份代码是否故障;The detecting unit is further configured to detect whether the second stage backup code is faulty;
所述故障恢复单元,还配置为在确定单元确定存在所述第二阶段备份代码,并在检测单元检测到所述第二阶段备份代码无故障时,利用所述第二阶段备份代码恢复故障的存储于第二分区中的第二阶段代码;在确定单元确定存在所述第二阶段备份代码,并在检测单元检测到所述第二阶段备份代码故障时,进入引导程序的下载模式。The fault recovery unit is further configured to determine, in the determining unit, that the second phase backup code exists, and when the detecting unit detects that the second phase backup code is faultless, recovering the fault by using the second phase backup code The second stage code stored in the second partition; the determining unit determines that the second stage backup code exists, and enters a download mode of the boot program when the detecting unit detects the second stage backup code failure.
一具体实施例中,所述检测单元,还配置为检测所述第二阶段代码与所述第二阶段备份代码是否一致;In a specific embodiment, the detecting unit is further configured to detect whether the second phase code is consistent with the second phase backup code;
所述嵌入式设备还包括:The embedded device further includes:
执行单元,配置为在检测单元检测到所述第二阶段代码无故障,并在确定单元确定不存在所述第二阶段备份代码时,跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;在检测单元检测到所述第二阶段代码无故障,并在确定单元确定存在所述第二阶段备份代码时,若所述检测单元检测到所述第二阶段代码与所述第二阶段备份代码一致,则跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;An execution unit configured to detect, in the detecting unit, that the second phase code is faultless, and when the determining unit determines that the second phase backup code does not exist, jump to an entry of the second phase code to complete the remaining Initializing operation; detecting, by the detecting unit, that the second-stage code is fault-free, and when the determining unit determines that the second-stage backup code exists, if the detecting unit detects the second-stage code and the If the two-stage backup code is consistent, then jump to the entry of the second-stage code to complete the remaining initialization operations;
更新单元,配置为在检测单元检测到所述第二阶段代码无故障,并在 确定单元确定存在所述第二阶段备份代码时,若所述检测单元检测到所述第二阶段代码与所述第二阶段备份代码不一致,则确定所述第二段代码已被升级,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。An update unit configured to detect, in the detecting unit, that the second stage code is faultless, and When the determining unit determines that the second stage backup code exists, if the detecting unit detects that the second stage code is inconsistent with the second stage backup code, it is determined that the second piece of code has been upgraded, and the upgrade is performed. The second stage of code update updates the second stage backup code stored in the third partition.
本发明实施例还提供一种计算机存储介质,其中存储有计算机可执行指令,所述计算机可执行指令用于执行上述的方法。Embodiments of the present invention also provide a computer storage medium having stored therein computer executable instructions for performing the above method.
本发明实施例所提供的引导程序的存储方法、故障恢复方法及设备、计算机存储介质,配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区;如此,在引导程序运行或升级过程中,不会对存储介质中预设的第一分区进行频繁擦写,仅是对存储介质中预设的第二分区进行擦写,这样,能够缩小存储介质中出现问题的存储区域,从而延长存储介质的使用寿命。The storage method, the fault recovery method and device, the computer storage medium, the first stage code and the second stage code of the boot program are provided by the embodiment of the present invention; wherein the first stage code is used to complete the basic parameter Setting, performing fault detection on the second stage code, and performing corresponding operations according to the detection result; the second stage code is used to load the kernel into the memory and run; storing the first stage code in the storage medium preset first Partitioning, and storing the second stage code in a second partition preset in the storage medium; thus, during the running or upgrading of the booting program, the first partition preset in the storage medium is not frequently erased, Only the second partition preset in the storage medium is erased, so that the storage area where the problem occurs in the storage medium can be reduced, thereby prolonging the service life of the storage medium.
本发明实施例在第二阶段代码故障恢复时,若不存在所述第二阶段备份代码,可以进入引导程序的下载操作模式;若存在所述第二阶段备份代码且检测所述第二阶段备份代码无故障,可以利用存储于第三分区中的第二阶段备份代码恢复故障的存储于第二分区第二阶段代码;若存在所述第二阶段备份代码但检测所述第二阶段备份代码故障,可以进入引导程序的下载操作模式;如此,能够及时地对引导程序运行或升级过程中出现的故障进行恢复,从而提高嵌入式系统的安全性。In the second stage of the code failure recovery, if the second stage backup code does not exist, the download operation mode of the boot program may be entered; if the second stage backup code exists and the second stage backup is detected The code is not faulty, and the second stage backup code stored in the third partition can be used to recover the fault stored in the second partition second stage code; if the second stage backup code exists, the second stage backup code is detected to be faulty , can enter the boot operation mode of the boot program; thus, it can timely recover the faults occurring during the boot program running or upgrading process, thereby improving the security of the embedded system.
附图说明DRAWINGS
图1为本发明实施例引导程序的存储方法实现流程示意图;1 is a schematic flowchart of an implementation method of a storage method of a boot program according to an embodiment of the present invention;
图2为本发明实施例引导程序的故障恢复方法实现流程示意图; 2 is a schematic flowchart of a method for implementing a fault recovery method of a boot program according to an embodiment of the present invention;
图3为本发明实施例存储设备的组成结构示意图;3 is a schematic structural diagram of a storage device according to an embodiment of the present invention;
图4为本发明实施例嵌入式设备的组成结构示意图。FIG. 4 is a schematic structural diagram of an embedded device according to an embodiment of the present invention.
具体实施方式detailed description
本发明实施例中,配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区。In the embodiment of the present invention, the first stage code and the second stage code of the boot program are configured; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result. The second stage code is used to load the kernel into the memory and run; store the first stage code in a preset first partition in the storage medium, and store the second stage code in a storage medium preset The second partition.
下面结合附图和具体实施方式对本发明所述方法和装置作进一步说明。The method and apparatus of the present invention are further described below in conjunction with the drawings and specific embodiments.
本发明实施例提出了一种引导程序的存储方法,如图1所示,该方法包括:The embodiment of the invention provides a storage method of the boot program. As shown in FIG. 1 , the method includes:
步骤S100:配置引导程序的第一阶段stage1代码及第二阶段stage2代码。Step S100: Configure the first stage stage1 code of the bootstrap program and the second stage stage2 code.
这里,引导程序可以为BootLoader、UBoot,也可以为更高级版本的引导程序。Here, the bootloader can be BootLoader, UBoot, or a more advanced version of the bootloader.
这里,引导程序通常包括启动加载模式和下载模式,而且允许用户在这两种工作模式之间进行切换;其中,启动加载模式,也称为“自主引导方式”,也即引到程序从目标机的存储介质上将操作系统加载到内存随机存取存储器(Random Access Memory,RAM)中并引导运行,整个过程并没有用户的介入,该引导方式是引导程序的正常工作模式下普遍采用的一种引导方式,因此,在嵌入式设备发布的时候,引到程序一般以该引导方式对内核代码进行启动引导;下载模式,该引导方式下目标机上的引导程序将通过串口连接或网络连接等通信手段从主机下载文件,如下载应用程序、数据文件、内核映像等,从主机下载的文件通常首先被引导程序保存到目 标机的内存RAM中,然后再被引导程序写到目标机上的存储介质中,最后完成内核的引导运行。Here, the boot program usually includes a boot load mode and a download mode, and allows the user to switch between the two work modes; wherein, the boot load mode, also called "autonomous boot mode", that is, the program from the target machine On the storage medium, the operating system is loaded into the memory random access memory (RAM) and booted. The whole process has no user intervention. The boot mode is a commonly used mode in the normal working mode of the boot program. Boot mode, therefore, when the embedded device is released, the program is generally booted to boot the kernel code in the boot mode; in the download mode, the boot program on the target machine in the boot mode will communicate through a serial port connection or a network connection. Download files from the host, such as downloading applications, data files, kernel images, etc. Files downloaded from the host are usually saved to the directory by the boot program. The memory RAM of the standard machine is then written by the boot program to the storage medium on the target machine, and finally the boot operation of the kernel is completed.
一般,引导程序在启动加载模式下分为:stage1和stage2,stage1代码通常用汇编语言实现,包含以下几个基本步骤:In general, the bootloader is divided into stage1 and stage2 in the bootloader mode. The stage1 code is usually implemented in assembly language and contains the following basic steps:
1)基本参数设置;1) Basic parameter settings;
2)为stage2准备内存RAM空间;2) Prepare memory RAM space for stage2;
3)将stage2从存储介质中读取到内存RAM空间。3) Read stage2 from the storage medium to the memory RAM space.
4)设置好堆栈;4) Set up the stack;
5)跳转到stage2的入口处。5) Jump to the entrance of stage2.
Stage2代码通常用C语言实现,包含以下几个基本步骤:The Stage2 code is usually implemented in C and consists of the following basic steps:
1)初始化本阶段需要用到的硬件;1) Initialize the hardware required for this phase;
2)检测系统的内存映象;2) detecting the memory image of the system;
3)将内核和根文件系统从存储介质上加载到内存RAM空间;3) loading the kernel and root file system from the storage medium into the memory RAM space;
4)为内核设置启动参数;4) Set the startup parameters for the kernel;
5)调用内核。5) Call the kernel.
本步骤中,配置的所述stage1代码用于完成基本参数设置、对所述stage2代码进行故障检测及根据检测结果执行相应的操作;其中,基本参数,例如,中央处理器(Central Processing Unit,CPU)参数、内存参数以及一些基本的输入/输出(Input/Output,I/O)控制参数;配置的所述stage2代码用于完成剩余的初始化操作,即:加载内核到内存并运行。In this step, the configured stage1 code is used to complete basic parameter setting, perform fault detection on the stage2 code, and perform corresponding operations according to the detection result; wherein, basic parameters, for example, a central processing unit (CPU) Parameters, memory parameters, and some basic input/output (I/O) control parameters; the stage2 code configured to complete the remaining initialization operations, namely: loading the kernel into memory and running.
步骤S101:将所述stage1代码存储于存储介质中预设的第一分区,并将所述stage2代码存储于存储介质中预设的第二分区。Step S101: Store the stage1 code in a preset first partition in the storage medium, and store the stage2 code in a preset second partition in the storage medium.
通常,嵌入式设备中的存储介质采用NAND Flash。Typically, storage media in embedded devices use NAND Flash.
这里,将所述stage1代码及所述stage2代码在存储介质中分区进行存储,在采用FOTA技术对引导程序升级时,所述stage1代码是固定不变的, 永远不被升级,仅升级可被升级的所述stage2代码,因此,在引导程序升级过程中,不会对存储介质中预设的第一分区进行频繁擦写,仅是对存储介质中预设的第二分区进行擦写,这样,能够缩小存储介质中出现问题的存储区域,从而延长存储介质的使用寿命;并且在引导程序运行或升级的过程中,若第一阶段代码检测到第二阶段代码故障,则直接进入引导程序的下载模式,这样,可以挽救嵌入式系统,从而提高嵌入式系统的安全性。Here, the stage1 code and the stage2 code are partitioned and stored in a storage medium, and when the boot program is upgraded by using FOTA technology, the stage1 code is fixed. Never upgrade, only the stage2 code that can be upgraded is upgraded. Therefore, during the boot process upgrade, the first partition preset in the storage medium is not frequently erased, only the storage medium is preset. The second partition is erased, so that the storage area in the storage medium can be reduced, thereby prolonging the service life of the storage medium; and in the process of running or upgrading the boot program, if the first stage code detects the second stage If the code fails, it will directly enter the boot mode of the bootloader, which can save the embedded system and improve the security of the embedded system.
优选的,可以对所述stage2代码进行备份得到第二阶段备份stage2backup代码,并将所述stage2backup代码存储于存储介质中预设的第三分区;在引导程序运行或升级过程中,认为所述stage1代码肯定是不会出现故障的,在所述stage2代码出现故障时,可以利用存储于第三分区中的所述stage2backup代码恢复故障的stage2代码,如此,能够及时地对引导程序运行或升级过程中出现的故障进行恢复,从而提高嵌入式系统的安全性。Preferably, the stage2 code may be backed up to obtain a second stage backup stage2backup code, and the stage2backup code is stored in a preset third partition in the storage medium; during the boot program running or upgrading, the stage1 is considered The code is definitely not faulty. When the stage2 code fails, the stage2backup code stored in the third partition can be used to recover the faulty stage2 code, so that the boot program can be run or upgraded in time. The failures that occur are restored to improve the security of the embedded system.
进一步地,在所述stage2代码升级后,利用升级后的stage2代码更新存储于第三分区中的stage2backup代码。Further, after the stage2 code is upgraded, the stage2backup code stored in the third partition is updated with the upgraded stage2 code.
进一步地,将故障的stage2代码存储于存储介质中预设的第四分区,以便后续根据故障的stage2代码排查问题,且方便问题的定位。Further, the failed stage2 code is stored in a preset fourth partition in the storage medium, so as to subsequently troubleshoot the problem according to the faulty stage2 code, and facilitate the positioning of the problem.
基于上述方法,本发明实施例提出了一种引导程序的故障恢复方法,将第一阶段代码和第二阶段代码分别存储于存储介质的第一分区和第二分区中;如图2所示,该方法包括:Based on the foregoing method, the embodiment of the present invention provides a fault recovery method for a boot program, where the first phase code and the second phase code are respectively stored in the first partition and the second partition of the storage medium; as shown in FIG. 2, The method includes:
步骤S200:第一阶段stage1代码在完成基本参数设置后,检测第二阶段stage2代码是否故障,若检测所述stage2代码故障,则转入步骤S201;若检测所述stage2代码无故障,则转入步骤S204。Step S200: After the basic parameter setting is completed, the stage1 code detects whether the stage 2 code of the second stage is faulty. If the stage2 code is detected to be faulty, the process goes to step S201; if the stage2 code is detected to be faultless, then the process proceeds to Step S204.
步骤S201:确定是否存在stage2backup代码,确定存在第二阶段备份代码时,转入步骤S202;确定不存在stage2backup代码时,进入引导程序的下载模式。 Step S201: determining whether there is a stage2backup code, determining that there is a second-stage backup code, proceeding to step S202; and determining that there is no stage2backup code, entering a download mode of the boot program.
步骤S202:检测所述stage2backup代码是否故障,检测到所述stage2backup代码无故障时,转入步骤S203;检测到所述stage2backup代码故障时,进入引导程序下载模式。Step S202: detecting whether the stage2backup code is faulty, detecting that the stage2backup code is faultless, and proceeding to step S203; and detecting that the stage2backup code is faulty, entering the bootloader download mode.
步骤S203:利用stage2backup代码恢复故障的存储于第二分区中的stage2代码,转入步骤S200。Step S203: recovering the failed stage2 code stored in the second partition by using the stage2backup code, and proceeding to step S200.
步骤S204:确定是否存在stage2backup代码,确定不存在stage2backup代码时,跳转到stage2代码的入口处,完成剩余的初始化操作;确定存在stage2backup代码时,转入步骤S205。Step S204: determining whether there is a stage2backup code, determining that there is no stage2backup code, jumping to the entry of the stage2 code, completing the remaining initialization operations; determining that there is a stage2backup code, proceeding to step S205.
步骤S205:检测stage2代码与stage2backup代码是否一致,若检测到stage2代码与stage2backup代码一致,则跳转到stage2代码的入口处,完成剩余的初始化操作;若检测到stage2代码与stage2backup代码不一致,则转入步骤S206。Step S205: detecting whether the stage2 code is consistent with the stage2backup code. If it is detected that the stage2 code is consistent with the stage2backup code, jump to the entry of the stage2 code to complete the remaining initialization operations; if it is detected that the stage2 code is inconsistent with the stage2backup code, then Proceed to step S206.
步骤S206:确定stage2代码已被升级,利用升级后的stage2代码更新存储于第三分区中的stage2backup代码。Step S206: It is determined that the stage2 code has been upgraded, and the stage2backup code stored in the third partition is updated by using the upgraded stage2 code.
具体的,在步骤S200中,所述stage1代码在完成基本参数设置后,将所述stage2代码从存储介质中读取到内存,采用预设的校验码生成算法生成所述stage2代码的校验码,将生成的校验码与预存的stage2校验码进行对比,从而检测所述stage2代码是否故障,若生成的校验码与预存的stage2校验码不相同,则检测所述stage2代码故障,转入步骤S201;若生成的校验码与预存的stage2校验码相同,则检测所述stage2代码无故障,转入步骤S204。Specifically, in step S200, after the basic parameter setting is completed, the stage1 code reads the stage2 code from the storage medium into the memory, and generates a check of the stage2 code by using a preset check code generation algorithm. The code compares the generated check code with the pre-stored stage2 check code to detect whether the stage2 code is faulty. If the generated check code is different from the pre-stored stage2 check code, the stage2 code is detected to be faulty. Go to step S201; if the generated check code is the same as the pre-stored stage 2 check code, it is detected that the stage 2 code is not faulty, and the process proceeds to step S204.
在步骤S201中,确定是否存在stage2backup代码,确定存在第二阶段备份代码时,转入步骤S202;确定不存在stage2backup代码时,进入引导程序的下载模式。In step S201, it is determined whether there is a stage2backup code, it is determined that there is a second-stage backup code, and the process proceeds to step S202; when it is determined that the stage2backup code does not exist, the download mode of the boot program is entered.
在步骤S202中,采用预设的校验码生成算法生成所述stage2backup代 码的校验码,将生成的校验码与预存的stage2backup校验码进行对比,从而检测所述stage2backup代码是否故障,若生成的校验码与预存的stage2backup校验码不相同,则检测所述stage2backup代码故障,进入引导程序下载模式;若生成的校验码与预存的stage2backup校验码相同,则检测到所述stage2backup代码无故障时,转入步骤S203。In step S202, the stage2backup generation is generated by using a preset check code generation algorithm. The check code of the code compares the generated check code with the pre-stored stage2backup check code to detect whether the stage2backup code is faulty. If the generated check code is different from the pre-stored stage2backup check code, the detection center is detected. If the stage 2backup code is faulty, the boot program download mode is entered; if the generated check code is the same as the pre-stored stage 2backup check code, if it is detected that the stage 2backup code is not faulty, the process proceeds to step S203.
在步骤S203中,利用stage2backup代码恢复故障的存储于第二分区中的stage2代码,即:将存储于第三分区中的stage2backup代码写入故障的stage2代码对应的第二分区中,这样能够及时地进行纠错,并对故障的stage2代码进行恢复;优选的,将stage2backup代码写入故障的stage2代码对应的第二分区中后,可以在预先定义的标志位写入表示“引导程序需要重新运行或升级”的标志,当检测到表示“引导程序需要重新运行或升级”的标志时,转入步骤S200,重新发起引导程序运行或升级流程,并清除该标志。In step S203, the stage2backup code is used to recover the failed stage2 code stored in the second partition, that is, the stage2backup code stored in the third partition is written into the second partition corresponding to the faulty stage2 code, so that it can be timely Perform error correction and recover the faulty stage2 code; preferably, after writing the stage2backup code to the second partition corresponding to the faulty stage2 code, it can be written in the predefined flag bit to indicate that "the bootloader needs to be re-run or When the flag indicating "the boot program needs to be re-run or upgraded" is detected, the process proceeds to step S200, the boot program running or upgrading process is re-initiated, and the flag is cleared.
在步骤S204中,确定是否存在stage2backup代码,确定不存在stage2backup代码时,跳转到stage2代码的入口处,完成剩余的初始化操作;确定存在stage2backup代码时,转入步骤S205。In step S204, it is determined whether there is a stage2backup code, it is determined that there is no stage2backup code, jump to the entry of the stage2 code, and the remaining initialization operations are completed; when it is determined that the stage2backup code exists, the process proceeds to step S205.
在步骤S205中,首先采用与所述stage2相同的校验码生成算法生成所述stage2backup代码的校验码,确定所述stage2backup代码无故障时,将所述stage2backup的校验码与所述stage2的校验码进行对比,若所述stage2backup的校验码与所述stage2的校验码相同,则检测到stage2代码与stage2backup代码一致,跳转到stage2代码的入口处,完成剩余的初始化操作;若所述stage2backup的校验码与所述stage2的校验码不相同,则检测到stage2代码与stage2backup代码不一致,此时确定stage2代码已被升级,转入步骤S206。In step S205, the check code of the stage2backup code is first generated by using the same check code generation algorithm as the stage2, and when the stage2backup code is determined to be faultless, the check code of the stage2backup is compared with the stage2 Checking the check code, if the check code of the stage2backup is the same as the check code of the stage2, it is detected that the stage2 code is consistent with the stage2backup code, jumps to the entry of the stage2 code, and completes the remaining initialization operations; If the check code of the stage2backup is different from the check code of the stage2, it is detected that the stage2 code is inconsistent with the stage2backup code. At this time, it is determined that the stage2 code has been upgraded, and the process proceeds to step S206.
在步骤S206中,利用升级后的stage2代码更新存储于第三分区中的 stage2backup代码,即:将升级后的stage2代码写入stage2backup代码对应的第三分区中。In step S206, the upgraded stage2 code is used to update the storage in the third partition. The stage2backup code, that is, writes the upgraded stage2 code to the third partition corresponding to the stage2backup code.
具体实施中,所述stage2代码的故障可能是由于在升级stage2代码时掉电造成的,在下次启动系统时,首先运行引导程序中的stage1代码,对stage2代码进行检测,检测到stage2代码故障时,能够及时地恢复并挽救所述系统,从而避免了现有技术中出现的系统自举问题;所述stage2代码的故障也可能是由对存储介质中的第二分区频繁擦写,造成第二分区出现坏块引起的。In a specific implementation, the failure of the stage2 code may be caused by power failure when upgrading the stage2 code. When the system is started next time, the stage1 code in the boot program is first run, and the stage2 code is detected to detect that the stage2 code is faulty. The system can be recovered and saved in time, thereby avoiding the system booting problem occurring in the prior art; the failure of the stage2 code may also be caused by frequent erasing of the second partition in the storage medium, resulting in the second The partition is caused by bad blocks.
具体实施中,所述校验码生成算法可以是外部不可逆推,碰撞成本比较高的算法,比如经过盐化处理的信息摘要算法MD5。校验操作对性能要求比很高,可以设计适当的校验码生成算法,优选的,可以设计具有一定加密强度的校验码生成算法,这里对校验码生成算法不作具体限定。In a specific implementation, the check code generation algorithm may be an external irreversible push, and an algorithm with a relatively high collision cost, such as a salinated information digest algorithm MD5. The verification operation has a high performance requirement ratio, and an appropriate check code generation algorithm can be designed. Preferably, a check code generation algorithm with a certain encryption strength can be designed. The check code generation algorithm is not specifically limited.
进一步地,检测到所述stage2代码故障后,将故障的stage2代码写入存储介质中预设的第四分区,以便后续根据故障的stage2代码排查问题。Further, after detecting the failure of the stage2 code, the failed stage2 code is written to the preset fourth partition in the storage medium, so as to subsequently troubleshoot the problem according to the faulty stage2 code.
本发明实施例中,将所述stage1代码及所述stage2代码在存储介质中分区进行存储,即:将所述stage1代码存储于存储介质中预设的第一分区,并将所述stage2代码存储于存储介质中预设的第二分区;在引导程序运行或升级时,所述stage1代码是固定不变的,永远不被升级,仅升级可被升级的所述stage2代码,因此,在引导程序运行或升级过程中,不会对存储介质中预设的第一分区进行频繁擦写,仅是对存储介质中预设的第二分区进行擦写;这样,在所述stage2代码出现故障时,可以直接进入引导程序的下载模式,能够及时地挽救系统,从而提高嵌入式系统的安全性。In the embodiment of the present invention, the stage1 code and the stage2 code are partitioned and stored in a storage medium, that is, the stage1 code is stored in a preset first partition in the storage medium, and the stage2 code is stored. a second partition preset in the storage medium; when the boot program is run or upgraded, the stage1 code is fixed, never upgraded, only the stage2 code that can be upgraded is upgraded, therefore, the boot program During the running or upgrading process, the first partition preset in the storage medium is not frequently erased, and only the second partition preset in the storage medium is erased; thus, when the stage2 code fails, You can directly enter the boot mode of the bootloader and save the system in time to improve the security of the embedded system.
在上述一种优选的实施方式中,对所述stage2代码进行备份得到stage2backup代码,并将所述stage2backup代码存储于存储介质中预设的第三分区,在引导程序运行或升级时,认为所述stage1代码肯定是不会出现故障 的,所述stage2代码和所述stage2backup代码由软件逻辑保证某一个时间点其中一个是无故障的或完整的,在所述stage2代码出现故障时,可以利用存储于第三分区中的无故障的stage2backup代码恢复存储于第二分区中的故障的stage2代码;如此,能够及时地对引导程序运行或升级过程中出现的故障进行恢复,从而提高嵌入式系统的安全性;In a preferred embodiment, the stage2 code is backed up to obtain a stage2backup code, and the stage2backup code is stored in a preset third partition in the storage medium. When the boot program is run or upgraded, the Stage1 code is definitely not going to fail The stage2 code and the stage2backup code are guaranteed by software logic that one of the points in time is fault-free or complete, and when the stage2 code fails, the fault-free storage in the third partition can be utilized. The stage2backup code restores the stage2 code of the fault stored in the second partition; thus, it can recover the faults occurring during the booting or upgrading process in time, thereby improving the security of the embedded system;
进一步地,在所述stage2代码出现故障时,若stage2backup代码也出现故障,则进入引导程序的下载模式,此时也能够及时地挽救系统。Further, when the stage2 code fails, if the stage2backup code also fails, the download mode of the boot program is entered, and the system can be rescued in time.
本发明实施例不仅可以应用于引导程序的升级场景,也可以应用于确保引导程序完整性的任意场景。The embodiments of the present invention can be applied not only to the upgrade scenario of the bootstrap program, but also to any scenario that ensures the integrity of the bootloader.
为实现上述方法,本发明实施例还提供了一种存储设备、嵌入式设备,由于该存储设备、嵌入式设备解决问题的原理与方法相似,因此,存储设备、嵌入式设备的实施过程及实施原理均可以参见前述方法的实施过程及实施原理描述,重复之处不再赘述。In order to implement the foregoing method, the embodiment of the present invention further provides a storage device and an embedded device. Since the principle and method for solving the problem between the storage device and the embedded device are similar, the implementation process and implementation of the storage device and the embedded device are implemented. For the principle, refer to the implementation process of the foregoing method and the description of the implementation principle, and the repeated description will not be repeated.
如图3所示,本发明实施例提供的存储设备,包括:配置单元300、存储单元301;其中,As shown in FIG. 3, the storage device provided by the embodiment of the present invention includes: a configuration unit 300 and a storage unit 301;
所述配置单元300,配置为配置引导程序的第一阶段代码及第二阶段代码;The configuration unit 300 is configured to configure a first stage code and a second stage code of the bootstrap program;
所述存储单元301,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区;The storage unit 301 is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
其中,所述第一阶段代码用于完成基本参数设置、对第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行。The first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result; the second stage code is used to load the kernel into the memory and run.
为了描述的方便,以上所述存储设备的各部分以功能分为各种模块或单元分别描述。以上功能单元或模块的划分方式仅为本发明实施例给出的一种优选实现方式,功能单元或模块的划分方式不构成对本发明的限制。 For convenience of description, the various parts of the storage device described above are separately described by functions into various modules or units. The division of the above functional units or modules is only a preferred implementation manner of the embodiments of the present invention, and the division manner of the functional units or modules does not constitute a limitation of the present invention.
具体实施中,所述配置单元300,还配置为配置所述第二阶段代码的备份代码,得到第二阶段备份代码;In a specific implementation, the configuration unit 300 is further configured to configure a backup code of the second stage code to obtain a second stage backup code.
所述存储单元301还配置为:The storage unit 301 is further configured to:
将所述第二阶段备份代码存储于存储介质中预设的第三分区。The second stage backup code is stored in a preset third partition in the storage medium.
具体实施中,所述存储设备还包括:In a specific implementation, the storage device further includes:
更新单元302,配置为在所述第二阶段代码升级后,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。The updating unit 302 is configured to update the second stage backup code stored in the third partition by using the upgraded second stage code after the second stage code upgrade.
如图4所示,本发明实施例提供的嵌入式设备,包括:配置单元300、存储单元301、检测单元400、确定单元401、故障恢复单元402;其中,As shown in FIG. 4, the embedded device provided by the embodiment of the present invention includes: a configuration unit 300, a storage unit 301, a detecting unit 400, a determining unit 401, and a fault recovery unit 402;
所述配置单元300,配置为配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;The configuration unit 300 is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and execute according to the detection result. Corresponding operation; the second stage code is used to load the kernel into memory and run;
所述存储单元301,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区;The storage unit 301 is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
所述检测单元400,配置为在第一阶段代码在完成基本参数设置后,检测第二阶段代码是否故障;The detecting unit 400 is configured to detect, after the basic parameter setting is completed in the first stage code, whether the second stage code is faulty;
所述确定单元401,配置为在检测单元400检测到所述第二阶段代码故障时,确定是否存在第二阶段备份代码;The determining unit 401 is configured to determine whether there is a second-stage backup code when the detecting unit 400 detects the second-stage code failure;
所述故障恢复单元402,配置为在确定单元401确定不存在所述第二阶段备份代码时,进入引导程序的下载操作模式。The fault recovery unit 402 is configured to enter a download operation mode of the boot program when the determining unit 401 determines that the second stage backup code does not exist.
为了描述的方便,以上所述存储设备的各部分以功能分为各种模块或单元分别描述。以上功能单元或模块的划分方式仅为本发明实施例给出的一种优选实现方式,功能单元或模块的划分方式不构成对本发明的限制。For convenience of description, the various parts of the storage device described above are separately described by functions into various modules or units. The division of the above functional units or modules is only a preferred implementation manner of the embodiments of the present invention, and the division manner of the functional units or modules does not constitute a limitation of the present invention.
具体实施中,所述配置单元300,还配置为配置所述第二阶段代码的备 份代码,得到第二阶段备份代码;相应的,所述存储单元301,还配置为将所述第二阶段备份代码存储于存储介质中预设的第三分区;In a specific implementation, the configuration unit 300 is further configured to configure the preparation of the second phase code. a second stage backup code is obtained; correspondingly, the storage unit 301 is further configured to store the second stage backup code in a third partition preset in the storage medium;
所述检测单元400,还配置为检测所述第二阶段备份代码是否故障;The detecting unit 400 is further configured to detect whether the second stage backup code is faulty;
所述故障恢复单元402,还配置为在确定单元401确定存在所述第二阶段备份代码,并在检测单元400检测到所述第二阶段备份代码无故障时,利用所述第二阶段备份代码恢复故障的存储于第二分区中的第二阶段代码;在确定单元401确定存在所述第二阶段备份代码,并在检测单元400检测到所述第二阶段备份代码故障时,进入引导程序的下载操作模式。The fault recovery unit 402 is further configured to determine, in the determining unit 401, that the second phase backup code exists, and use the second phase backup code when the detecting unit 400 detects that the second phase backup code is not faulty. Recovering the second stage code stored in the second partition; determining that the second stage backup code exists in the determining unit 401, and entering the boot program when the detecting unit 400 detects the second stage backup code failure Download the operating mode.
具体实施中,所述检测单元400,还配置为检测所述第二阶段代码与所述第二阶段备份代码是否一致;In a specific implementation, the detecting unit 400 is further configured to detect whether the second phase code is consistent with the second phase backup code;
所述嵌入式设备还包括:The embedded device further includes:
执行单元403,配置为在检测单元400检测到所述第二阶段代码无故障,并在确定单元401确定不存在所述第二阶段备份代码时,跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;在检测单元400检测到所述第二阶段代码无故障,并在确定单元401确定存在所述第二阶段备份代码时,若所述检测单元400检测到所述第二阶段代码与所述第二阶段备份代码一致,则跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;The executing unit 403 is configured to detect that the second phase code is not faulty at the detecting unit 400, and jump to the entrance of the second phase code when the determining unit 401 determines that the second phase backup code does not exist And completing the remaining initialization operation; detecting, by the detecting unit 400, that the second-stage code is fault-free, and when the determining unit 401 determines that the second-stage backup code exists, if the detecting unit 400 detects the second The phase code is consistent with the second phase backup code, then jumps to the entry of the second phase code to complete the remaining initialization operations;
更新单元302,配置为在检测单元400检测到所述第二阶段代码无故障,并在确定单元401确定存在所述第二阶段备份代码时,若所述检测单元400检测到所述第二阶段代码与所述第二阶段备份代码不一致,则确定存储于第二分区中的第二段代码已被升级,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。The updating unit 302 is configured to detect, when the detecting unit 400 detects that the second phase code is faultless, and when the determining unit 401 determines that the second phase backup code exists, if the detecting unit 400 detects the second phase The code is inconsistent with the second stage backup code, and it is determined that the second piece of code stored in the second partition has been upgraded, and the second stage backup code stored in the third partition is updated with the upgraded second stage code.
本发明实施例还提供一种计算机存储介质,其中存储有计算机可执行指令,所述计算机可执行指令用于执行上述的方法。 Embodiments of the present invention also provide a computer storage medium having stored therein computer executable instructions for performing the above method.
在实际应用中,所述配置单元300、所述存储单元301、所述更新单元302可由位于所述存储设备的中央处理器(CPU)、微处理器(MPU)、数字信号处理器(DSP)、或现场可编程门阵列(FPGA)实现;所述配置单元300、所述存储单元301、所述更新单元302、所述检测单元400、所述确定单元401、所述故障恢复单元402、所述执行单元403可由位于所述嵌入式设备的中央处理器(CPU)、微处理器(MPU)、数字信号处理器(DSP)、或现场可编程门阵列(FPGA)实现。In practical applications, the configuration unit 300, the storage unit 301, and the update unit 302 may be a central processing unit (CPU), a microprocessor (MPU), and a digital signal processor (DSP) located in the storage device. Or a field programmable gate array (FPGA) implementation; the configuration unit 300, the storage unit 301, the update unit 302, the detection unit 400, the determination unit 401, the fault recovery unit 402, The execution unit 403 can be implemented by a central processing unit (CPU), a microprocessor (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA) located in the embedded device.
本领域内的技术人员应明白,本发明的实施例可提供为方法、系统、或计算机程序产品。因此,本发明可采用硬件实施例、软件实施例、或结合软件和硬件方面的实施例的形式。而且,本发明可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器和光学存储器等)上实施的计算机程序产品的形式。Those skilled in the art will appreciate that embodiments of the present invention can be provided as a method, system, or computer program product. Accordingly, the present invention can take the form of a hardware embodiment, a software embodiment, or a combination of software and hardware. Moreover, the invention can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage and optical storage, etc.) including computer usable program code.
本发明是参照根据本发明实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。The present invention has been described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (system), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flowchart illustrations and/or FIG. These computer program instructions can be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing device to produce a machine for the execution of instructions for execution by a processor of a computer or other programmable data processing device. Means for implementing the functions specified in one or more of the flow or in a block or blocks of the flow chart.
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。The computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing device to operate in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture comprising the instruction device. The apparatus implements the functions specified in one or more blocks of a flow or a flow and/or block diagram of the flowchart.
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备 上,使得在计算机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。 These computer program instructions can also be loaded into a computer or other programmable data processing device Having a series of operational steps performed on a computer or other programmable device to produce computer-implemented processing such that instructions executed on a computer or other programmable device are provided for implementing one or more processes in a flowchart and/or Or block diagram the steps of a function specified in a box or multiple boxes.

Claims (13)

  1. 一种引导程序的存储方法,其中,所述方法包括:A storage method of a boot program, wherein the method comprises:
    配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;Configuring a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and perform corresponding operations according to the detection result; The two-stage code is used to load the kernel into memory and run it;
    将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区。The first stage code is stored in a preset first partition in the storage medium, and the second stage code is stored in a preset second partition in the storage medium.
  2. 根据权利要求1所述的方法,其中,所述方法还包括:The method of claim 1 wherein the method further comprises:
    配置所述第二阶段代码的备份代码,得到第二阶段备份代码;Configuring the backup code of the second stage code to obtain the second stage backup code;
    将所述第二阶段备份代码存储于存储介质中预设的第三分区。The second stage backup code is stored in a preset third partition in the storage medium.
  3. 根据权利要求2所述的方法,其中,所述方法还包括:The method of claim 2, wherein the method further comprises:
    在所述第二阶段代码升级后,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。After the second stage code upgrade, the second stage backup code stored in the third partition is updated with the upgraded second stage code.
  4. 一种引导程序的故障恢复方法,其中,将第一阶段代码和第二阶段代码分别存储于存储介质的第一分区和第二分区中;所述方法还包括:A fault recovery method for a boot program, wherein the first stage code and the second stage code are respectively stored in a first partition and a second partition of a storage medium; the method further includes:
    所述第一阶段代码在完成基本参数设置后,检测所述第二阶段代码是否故障;After the basic parameter setting is completed, the first stage code detects whether the second stage code is faulty;
    检测到所述第二阶段代码故障时,确定是否存在第二阶段备份代码;When the second stage code failure is detected, determining whether there is a second stage backup code;
    确定不存在所述第二阶段备份代码时,进入引导程序的下载模式。When it is determined that the second stage backup code does not exist, the download mode of the boot program is entered.
  5. 根据权利要求4所述的方法,其中,所述方法还包括:The method of claim 4 wherein the method further comprises:
    确定存在所述第二阶段备份代码时,检测所述第二阶段备份代码是否故障;Determining whether the second stage backup code is faulty when the second stage backup code exists;
    检测到所述第二阶段备份代码无故障时,利用所述第二阶段备份代码恢复故障的存储于第二分区中的第二阶段代码;When detecting that the second stage backup code is faultless, recovering the second phase code stored in the second partition by using the second stage backup code;
    检测到所述第二阶段备份代码故障时,进入引导程序的下载模式。 When the second stage backup code failure is detected, the boot mode of the boot program is entered.
  6. 根据权利要求4或5所述的方法,其中,所述方法还包括:The method of claim 4 or 5, wherein the method further comprises:
    检测到所述第二阶段代码无故障时,确定是否存在所述第二阶段备份代码;When it is detected that the second stage code is faultless, determining whether the second stage backup code exists;
    确定不存在所述第二阶段备份代码时,跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;Determining that the second stage backup code does not exist, jumping to the entry of the second stage code to complete the remaining initialization operations;
    确定存在所述第二阶段备份代码时,检测所述第二阶段代码与所述第二阶段备份代码是否一致;When it is determined that the second stage backup code exists, detecting whether the second stage code is consistent with the second stage backup code;
    若检测到所述第二阶段代码与所述第二阶段备份代码一致,则跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;If it is detected that the second phase code is consistent with the second phase backup code, jump to the entry of the second phase code to complete the remaining initialization operations;
    若检测到所述第二阶段代码与所述第二阶段备份代码不一致,则确定存储于第二分区中的第二段代码已被升级,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。If it is detected that the second stage code is inconsistent with the second stage backup code, it is determined that the second piece of code stored in the second partition has been upgraded, and is updated in the third partition by using the upgraded second stage code update. The second phase of the backup code.
  7. 一种存储设备,其中,所述存储设备包括:配置单元、存储单元;其中,A storage device, where the storage device includes: a configuration unit, a storage unit;
    所述配置单元,配置为配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;The configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
    所述存储单元,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区。The storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium.
  8. 根据权利要求7所述的存储设备,其中,所述配置单元,还配置为配置所述第二阶段代码的备份代码,得到第二阶段备份代码;The storage device according to claim 7, wherein the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code;
    所述存储单元,还配置为将所述第二阶段备份代码存储于存储介质中预设的第三分区。The storage unit is further configured to store the second stage backup code in a third partition preset in the storage medium.
  9. 根据权利要求8所述的存储设备,其中,所述存储设备还包括: The storage device of claim 8, wherein the storage device further comprises:
    更新单元,配置为在所述第二阶段代码升级后,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。And an update unit configured to update the second stage backup code stored in the third partition with the upgraded second stage code after the second stage code upgrade.
  10. 一种嵌入式设备,其中,所述嵌入式设备包括:配置单元、存储单元、检测单元、确定单元、故障恢复单元;其中,An embedded device, wherein the embedded device includes: a configuration unit, a storage unit, a detecting unit, a determining unit, and a fault recovery unit; wherein
    所述配置单元,配置为配置引导程序的第一阶段代码及第二阶段代码;其中,所述第一阶段代码用于完成基本参数设置、对所述第二阶段代码进行故障检测及根据检测结果执行相应操作;所述第二阶段代码用于加载内核到内存并运行;The configuration unit is configured to configure a first stage code and a second stage code of the boot program; wherein the first stage code is used to complete basic parameter setting, perform fault detection on the second stage code, and according to the detection result Performing the corresponding operation; the second stage code is used to load the kernel into the memory and run;
    所述存储单元,配置为将所述第一阶段代码存储于存储介质中预设的第一分区,并将所述第二阶段代码存储于存储介质中预设的第二分区;The storage unit is configured to store the first stage code in a preset first partition in the storage medium, and store the second stage code in a preset second partition in the storage medium;
    所述检测单元,配置为所述第一阶段代码在完成基本参数设置后,检测第二阶段代码是否故障;The detecting unit is configured to detect, after the completion of the basic parameter setting, the first stage code, whether the second stage code is faulty;
    所述确定单元,配置为在检测单元检测到所述第二阶段代码故障时,确定是否存在第二阶段备份代码;The determining unit is configured to determine whether there is a second-stage backup code when the detecting unit detects the second-stage code failure;
    所述故障恢复单元,配置为在确定单元确定不存在所述第二阶段备份代码时,进入引导程序的下载模式。The fault recovery unit is configured to enter a download mode of the boot program when the determining unit determines that the second stage backup code does not exist.
  11. 根据权利要求10所述的嵌入式设备,其中,所述配置单元,还配置为配置所述第二阶段代码的备份代码,得到第二阶段备份代码;相应的,所述存储单元,还配置为将所述第二阶段备份代码存储于存储介质中预设的第三分区;The embedded device according to claim 10, wherein the configuration unit is further configured to configure a backup code of the second stage code to obtain a second stage backup code; correspondingly, the storage unit is further configured to And storing the second stage backup code in a third partition preset in the storage medium;
    所述检测单元,还配置为检测所述第二阶段备份代码是否故障;The detecting unit is further configured to detect whether the second stage backup code is faulty;
    所述故障恢复单元,还配置为在确定单元确定存在所述第二阶段备份代码,并在检测单元检测到所述第二阶段备份代码无故障时,利用所述第二阶段备份代码恢复故障的存储于第二分区中的第二阶段代码;在确定单元确定存在所述第二阶段备份代码,并在检测单元检测到所述第二阶段备 份代码故障时,进入引导程序的下载模式。The fault recovery unit is further configured to determine, in the determining unit, that the second phase backup code exists, and when the detecting unit detects that the second phase backup code is faultless, recovering the fault by using the second phase backup code a second stage code stored in the second partition; determining, in the determining unit, that the second stage backup code exists, and detecting, in the detecting unit, the second stage When the code fails, enter the boot mode of the bootloader.
  12. 根据权利要求10或11所述的嵌入式设备,其中,所述检测单元,还配置为检测所述第二阶段代码与所述第二阶段备份代码是否一致;The embedded device according to claim 10 or 11, wherein the detecting unit is further configured to detect whether the second phase code is consistent with the second phase backup code;
    所述嵌入式设备还包括:The embedded device further includes:
    执行单元,配置为在检测单元检测到所述第二阶段代码无故障,并在确定单元确定不存在所述第二阶段备份代码时,跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;在检测单元检测到所述第二阶段代码无故障,并在确定单元确定存在所述第二阶段备份代码时,若所述检测单元检测到所述第二阶段代码与所述第二阶段备份代码一致,则跳转到所述第二阶段代码的入口处,完成剩余的初始化操作;An execution unit configured to detect, in the detecting unit, that the second phase code is faultless, and when the determining unit determines that the second phase backup code does not exist, jump to an entry of the second phase code to complete the remaining Initializing operation; detecting, by the detecting unit, that the second-stage code is fault-free, and when the determining unit determines that the second-stage backup code exists, if the detecting unit detects the second-stage code and the If the two-stage backup code is consistent, then jump to the entry of the second-stage code to complete the remaining initialization operations;
    更新单元,配置为在检测单元检测到所述第二阶段代码无故障,并在确定单元确定存在所述第二阶段备份代码时,若所述检测单元检测到所述第二阶段代码与所述第二阶段备份代码不一致,则确定所述第二段代码已被升级,利用升级后的第二阶段代码更新存储于第三分区中的第二阶段备份代码。An update unit configured to detect, when the detecting unit detects that the second stage code is faulty, and when the determining unit determines that the second stage backup code exists, if the detecting unit detects the second stage code and the If the second stage backup code is inconsistent, it is determined that the second piece of code has been upgraded, and the second stage backup code stored in the third partition is updated by using the upgraded second stage code.
  13. 一种计算机存储介质,其中存储有计算机可执行指令,所述计算机可执行指令用于执行所述权利要求1至3、权利要求4至6任一项所述的方法。 A computer storage medium having stored therein computer executable instructions for performing the method of any one of claims 1 to 3 and 4 to 6.
PCT/CN2014/090696 2014-06-06 2014-11-10 Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium WO2015184732A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201410250492.X 2014-06-06
CN201410250492.XA CN105183580A (en) 2014-06-06 2014-06-06 Storage method and fault recovery method for bootstrap program, and devices

Publications (1)

Publication Number Publication Date
WO2015184732A1 true WO2015184732A1 (en) 2015-12-10

Family

ID=54766007

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/090696 WO2015184732A1 (en) 2014-06-06 2014-11-10 Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium

Country Status (2)

Country Link
CN (1) CN105183580A (en)
WO (1) WO2015184732A1 (en)

Families Citing this family (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107122668A (en) * 2017-04-28 2017-09-01 环球智达科技(北京)有限公司 Firmware encrypting method
CN107122212A (en) * 2017-04-28 2017-09-01 环球智达科技(北京)有限公司 Firmware encrypting method
CN108958769A (en) * 2018-06-26 2018-12-07 四川斐讯信息技术有限公司 A kind of embedded device software systems restorative procedure and system
CN110007971A (en) * 2019-03-25 2019-07-12 联想(北京)有限公司 A kind of information processing method and device, equipment, storage medium
CN110134426A (en) * 2019-04-18 2019-08-16 深圳市致宸信息科技有限公司 A kind of embedded system upgrade method, device and terminal device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1808385A (en) * 2006-01-20 2006-07-26 北京朗通环球科技有限公司 Guide system of embedded system
CN101118494A (en) * 2006-08-01 2008-02-06 环达电脑(上海)有限公司 System and method for starting up and operating system from external connected electronic card with built-in equipment
CN102289397A (en) * 2011-09-13 2011-12-21 全星科技(珠海)有限公司 Method and device for automatically restoring embedded system of set top box
CN102945176A (en) * 2012-11-09 2013-02-27 青岛海信移动通信技术股份有限公司 Terminal equipment booting and updating method and equipment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4819521B2 (en) * 2006-02-17 2011-11-24 株式会社日立製作所 Storage system, virtualization method, and storage apparatus

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1808385A (en) * 2006-01-20 2006-07-26 北京朗通环球科技有限公司 Guide system of embedded system
CN101118494A (en) * 2006-08-01 2008-02-06 环达电脑(上海)有限公司 System and method for starting up and operating system from external connected electronic card with built-in equipment
CN102289397A (en) * 2011-09-13 2011-12-21 全星科技(珠海)有限公司 Method and device for automatically restoring embedded system of set top box
CN102945176A (en) * 2012-11-09 2013-02-27 青岛海信移动通信技术股份有限公司 Terminal equipment booting and updating method and equipment

Also Published As

Publication number Publication date
CN105183580A (en) 2015-12-23

Similar Documents

Publication Publication Date Title
US10701084B2 (en) Reliable and secure firmware update with a dynamic validation for internet of things (IoT) devices
US8423991B2 (en) Embedded network device and firmware upgrading method
TWI501253B (en) Handling errors during device bootup from a non-volatile memory
US9471435B2 (en) Information processing device, information processing method, and computer program
KR101856284B1 (en) Backing up firmware during initialization of device
US9027014B2 (en) Updating firmware compatibility data
US20100058314A1 (en) Computer System and Related Method of Logging BIOS Update Operation
US7861119B1 (en) Updating a firmware image using a firmware debugger application
US20100169709A1 (en) System Of Updating Firmware And Method Thereof, And Method Of Creating Firmware
CN106775610B (en) Electronic equipment starting method and electronic equipment
WO2015184732A1 (en) Bootstrap storage method, bootstrap fault recovery method and device, and computer storage medium
US11163886B2 (en) Information handling system firmware bit error detection and correction
US20120239920A1 (en) Approaches for updating bios
CN104572206A (en) Application program self updating and backup recovery method
WO2016206514A1 (en) Startup processing method and device
US11144328B2 (en) System method to update failover process by running basic input/output (BIOS) system boot code from non-volatile memory express device (NVME)
CN101807152B (en) Basic output and input system for self verification of selection read only memory and verification method thereof
TW201520895A (en) System and method for automatically recovering BIOS of a computer
TW202030602A (en) The method and system of bios recovery and update
US8788800B2 (en) OS processing method, system and non-transitory computer readable storage medium thereof
CN109375953B (en) Operating system starting method and device
CN111273928B (en) Bootloader design method for self-upgrading
US20230087221A1 (en) Detection fields of view
WO2021012170A1 (en) Firmware booting method and device, and computer-readable storage medium
JP2005284902A (en) Terminal device, control method and control program thereof, host device, control method and control program thereof, and method, system, and program for remote updating

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 14894136

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 14894136

Country of ref document: EP

Kind code of ref document: A1