A firmware detection method and device based on interrupt vector

By building verification units and functional units in the bin firmware of embedded systems, modifying interrupt vectors for firmware self-checking, the problem of difficult firmware verification in embedded systems is solved, and fast, stable and reliable firmware verification is achieved , reducing R&D and maintenance costs.

CN112597503BActive Publication Date: 2024-12-13SUPCON TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202011519057.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-21
Publication Date
2024-12-13
Estimated Expiration
2040-12-21

AI Technical Summary

Technical Problem

In embedded systems, firmware verification is difficult to implement, especially because the boot program relies heavily on hardware, resulting in differences in different processor architectures and board-level device configurations, resulting in frequent modification of boot programs, which increases R&D, testing and maintenance costs. Some CPU design reasons cannot support boot programs.

Method used

Using a firmware detection method based on interrupt vectors, by building verification units and functional units in bin firmware, modifying interrupt vectors, and using interrupt vector addresses to store verification information to be checked, realizing firmware self-test, avoiding the need to run boot programs, directly Firmware verification is performed in embedded systems.

Benefits of technology

It realizes fast, stable and reliable firmware verification, reduces design and maintenance costs, and is suitable for different processor architectures and board-level devices. It does not require external memory devices to obtain firmware length, ensuring reliable code execution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112597503B_ABST
    Figure CN112597503B_ABST
Patent Text Reader

Abstract

The present invention discloses a firmware detection method and device based on interrupt vectors, S1: start the embedded system, and then run the verification unit to verify the optimized bin firmware, obtain the total number of bytes of the optimized bin firmware and record it as N; S2: the N bytes of the optimized bin firmware are composed of an unsigned integer data in every 4 bytes, and a number of unsigned integer data are accumulated to obtain a cumulative verification value and record it as V; S3: determine whether the verification and verification data V is 0, if V is equal to 0, the verification is passed, if V is not equal to 0, it is determined that the ARM chip is abnormal. The present invention adds a verification unit in the firmware to replace the conventional boot program to perform firmware verification, does not change the structure of the firmware code, and does not obtain the length of the firmware through an external storage device. Therefore, the present invention has simple design, stability and reliability, does not need to run the boot program, quickly realizes the verification of the firmware, and ensures reliable execution of the detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of embedded systems, and in particular relates to a firmware detection method and device based on interrupt vectors. Background Art

[0002] In embedded systems, it is very important to ensure the correctness of executable code, which is indispensable to system reliability. Under the existing technology, the boot program is usually executed first, and the length and check code of the firmware are obtained through the boot program. After calculation, the firmware is checked. If the check passes, it jumps to the firmware code for execution; if the check fails, it is not executed.

[0003] Usually, the boot program is heavily dependent on hardware implementation, especially in embedded platforms. Boot is the first code executed by the embedded system after power-on. After it completes the initialization of the CPU and related hardware, it installs the operating system image or the solidified embedded application into the memory and then jumps to the space where the operating system is located to start the operating system. For embedded systems, boot is implemented based on a specific hardware platform. Therefore, it is almost impossible to establish a universal boot for all embedded systems. Different processor architectures have different boots. Boot depends not only on the CPU architecture, but also on the configuration of the embedded system board-level devices. For two different embedded boards, even if they use the same processor, in order to make the boot program running on one board also run on another board, it is generally necessary to modify the boot source program accordingly. Therefore, designing a boot program for an embedded system requires a lot of R&D costs, testing costs, production costs (re-burning is required) and maintenance costs, which is not conducive to the rapid launch of products.

[0004] In addition, in embedded systems, due to some CPU design reasons, the boot program cannot be supported, and firmware verification is difficult to implement. Summary of the invention

[0005] The technical purpose of the present invention is to provide a firmware detection method and device based on interrupt vectors to solve the technical problem of the difficulty in implementing firmware verification.

[0006] To solve the above problems, the technical solution of the present invention is:

[0007] A firmware detection method based on interrupt vectors uses optimized bin firmware burned into an embedded system to perform firmware detection, wherein the optimized bin firmware includes a detection unit for implementing firmware self-checking, including the following steps:

[0008] S1: Start the embedded system, and then run the verification unit to verify the optimized bin firmware, and obtain the total number of bytes of the optimized bin firmware, which is recorded as N;

[0009] S2: The N bytes of the optimized bin firmware are combined into an unsigned integer data with every 4 bytes, and a plurality of unsigned integer data are accumulated to obtain an accumulated and checksum value recorded as V;

[0010] S3: Determine whether the accumulated and verified value V is 0. If V is equal to 0, the verification passes. If V is not equal to 0, it is determined that the ARM chip is abnormal.

[0011] Further preferably, before step S1, it also includes building an optimized bin firmware, which specifically includes the following steps:

[0012] A1: Build the verification unit and function unit of the optimized bin firmware. The verification unit is used to implement firmware detection, and the function unit is used to ensure the normal operation of the embedded system.

[0013] A2: Get bin firmware by cross-compiling the inspection unit and the functional unit;

[0014] A3: Modify the interrupt vector of bin firmware to get optimized bin firmware;

[0015] A4: Burn the optimized bin firmware to the ROM of the ARM chip in the embedded system.

[0016] Among them, in step A3, modifying the interrupt vector of the bin firmware to obtain the optimized bin firmware specifically includes the following steps:

[0017] B1: Get the total number of bytes of the bin firmware and record it as M. If M is divisible by 4, let I = M. If M is not divisible by 4, then get I based on M through the calculation formula, where I is an integer value divisible by 4.

[0018] The calculation formula is I = (M / 4 + 1) × 4, where / is the division and rounding symbol;

[0019] B2: Increase the total number of bytes M to I based on the 0-filling method in the bin firmware;

[0020] B3: Get the interrupt vector addresses m and n of the ARM chip, and write the integer value I into the m byte of the bin firmware;

[0021] B4: Every 4 bytes of bin firmware form an unsigned integer data, and accumulate several unsigned integer data to get the value O, invert the value O bit by bit and add the value 1 to get the value P, write the value P into the n-byte of the bin firmware to get the optimized bin firmware.

[0022] A firmware detection device for firmware detection based on interrupt vectors, comprising:

[0023] A data acquisition module is used to obtain the total number of bytes and data of the optimized bin firmware;

[0024] A data processing module, used for performing data processing on the total number of bytes obtained to obtain a cumulative sum check value;

[0025] The verification judgment module is used to judge whether the accumulated and verified value is 0. If it is 0, the verification passes; if it is not 0, the verification fails.

[0026] A computer device includes a memory and a processor. The memory stores computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor executes the above-mentioned firmware detection method based on interrupt vectors.

[0027] A storage medium storing computer-readable instructions, when the computer-readable instructions are executed by one or more processors, enables the one or more processors to execute the above-mentioned firmware detection method based on interrupt vectors.

[0028] Due to the adoption of the above technical solution, the present invention has the following advantages and positive effects compared with the prior art:

[0029] The present invention adds a verification unit in the firmware, replaces the conventional method of using a boot program to perform firmware verification, uses the unused interrupt vector address in the bin firmware to store the information to be verified, does not change the structure of the firmware code, and does not obtain the length of the firmware through an external storage device. Therefore, the present invention has a simple design, is stable and reliable, does not need to run the boot program, does not change the firmware file structure, quickly implements firmware verification, and ensures the technical effect of reliable execution of the code. BRIEF DESCRIPTION OF THE DRAWINGS

[0030] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the following detailed description of the preferred embodiment.The drawings are only for the purpose of illustrating the preferred embodiments and are not to be construed as limiting the invention.

[0031] Figure 1 It is a flowchart of a firmware detection method based on interrupt vectors in one embodiment of the present invention;

[0032] Figure 2 A schematic diagram of a process for constructing an optimized bin firmware in one embodiment of the present invention;

[0033] Figure 3 A schematic diagram of a process of modifying the interrupt vector of a bin firmware to obtain an optimized bin firmware in one embodiment of the present invention;

[0034] Figure 4 The figure is a schematic diagram of a firmware detection device for firmware detection based on interrupt vectors in one embodiment of the present invention. DETAILED DESCRIPTION

[0035] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings and other implementation methods can be obtained based on these drawings without creative work.

[0036] In order to simplify the drawings, only the parts related to the present invention are schematically shown in each figure, and they do not represent the actual structure of the product. In addition, in order to simplify the drawings and facilitate understanding, in some figures, only one of the parts with the same structure or function is schematically drawn or marked. In this article, "one" not only means "only one", but also means "more than one".

[0037] The following is a further detailed description of a firmware detection method based on interrupt vectors proposed by the present invention in conjunction with the accompanying drawings and specific embodiments. The advantages and features of the present invention will become more apparent from the following description and claims.

[0038] Example 1

[0039] See also Figure 1 , this embodiment provides a firmware detection method based on interrupt vectors that is specifically applicable to STM32F10x series chips.

[0040] First see Figure 2 Before step S1, a bin firmware including a check unit is constructed, and the interrupt vector of the bin firmware is modified to obtain an optimized bin firmware. Specifically, a check unit and a function unit are constructed, the check unit is used to implement the check of the bin firmware, and the function unit is used to provide software support for the embedded system of the STM32F10x series chip. Therefore, in this embodiment, the bin firmware includes a check unit and a function unit, and the check unit and the function unit are cross-compiled to obtain the bin firmware.

[0041] Then modify the interrupt vector reserved in the bin firmware. Figure 3 In this embodiment, the total number of bytes of the bin firmware is obtained and recorded as M. If the total number of bytes M is divisible by 4, let I=M. If M is not divisible by 4, it is calculated, that is, M is divided by 4, the integer is added to 1 and then multiplied by 4. I is used as the total number of bytes required for the bin firmware. The total number of bytes M of the bin firmware is increased to I based on the 0-padding method through the file tool.

[0042] Get the two interrupt vector addresses 28 to 35 of the STM32F10x series chip. The interrupt vector addresses 28 to 35 are reserved interrupt vectors. Write the total byte number I to the 28-31 bytes of the bin firmware through the file tool; form an unsigned integer data with every 4 bytes of the total byte number I of the bin firmware, and accumulate several unsigned integer data to obtain the value O, invert the value O bit by bit and add the value 1 to obtain the value P, write the value P to the 32 to 35 bytes of the bin firmware through the file tool, and finally obtain the optimized bin firmware.

[0043] Next, burn the optimized bin firmware into the ROM of the STM32F10x series chip.

[0044] See also Figure 1 , the STM32F10x series chip is powered on and starts, and the bin firmware is run. At this time, the detection unit is started first, the optimized bin firmware is verified, and the firmware detection process begins. The detection unit obtains the total number of bytes of the optimized bin firmware from the 28th to 31st bytes of the STM32F10x series chip ROM address, recorded as N. The N bytes of the optimized bin firmware are composed of an unsigned integer data of every 4 bytes, and several unsigned integer data are accumulated to obtain the cumulative check value, recorded as V. Determine whether the cumulative check value V is 0. If V is equal to 0, the check passes, and the functional unit continues to perform the corresponding task. If V is not equal to 0, the check fails, and it can be re-burned for judgment. If it still fails, it is determined that the STM32F10x series chip has an abnormality.

[0045] Example 2

[0046] See also Figure 1 This embodiment provides a firmware detection method based on interrupt vectors specifically applicable to LPC178x_7x series chips.

[0047] First see Figure 2 Before step S1, a bin firmware including a verification unit is constructed, and the interrupt vector of the bin firmware is modified to obtain an optimized bin firmware. Specifically, a verification unit and a functional unit are constructed, the verification unit is used to implement verification of the bin firmware, and the functional unit is used to provide software support for the embedded system of the LPC178x_7x series chip. Therefore, in this embodiment, the bin firmware includes a verification unit and a functional unit, and the verification unit and the functional unit are cross-compiled to obtain the bin firmware.

[0048] Then modify the interrupt vector reserved in the bin firmware. Figure 3In this embodiment, the total number of bytes of the bin firmware is obtained and recorded as M. If the total number of bytes M is divisible by 4, let I=M. If M is not divisible by 4, it is calculated, that is, M is divided by 4, the integer is added to 1 and then multiplied by 4. I is used as the total number of bytes required for the bin firmware. The total number of bytes M of the bin firmware is increased to I based on the 0-padding method through the file tool.

[0049] Get the two interrupt vector addresses 28-35 of the LPC178x_7x series chip. The interrupt vector addresses 28-32 are reserved interrupt vectors. Write the total byte number I to the 28-31 bytes of the bin firmware through the file tool; form an unsigned integer data with every 4 bytes of the total byte number I of the bin firmware, and accumulate several unsigned integer data to get the value O, invert the value O bit by bit and add the value 1 to get the value P, write the value P to the 32-35 bytes of the bin firmware through the file tool, and finally get the optimized bin firmware.

[0050] Next, burn the obtained optimized bin firmware into the ROM of the LPC178x_7x series chip.

[0051] See also Figure 1 , the LPC178x_7x series chip is powered on and starts, running the bin firmware. At this time, the detection unit is started first, the optimized bin firmware is verified, and the firmware detection process begins. The detection unit obtains the total number of bytes of the optimized bin firmware from the 28th to 31st bytes of the LPC178x_7x series chip ROM address, recorded as N. The N bytes of the optimized bin firmware are composed of an unsigned integer data of every 4 bytes, and several unsigned integer data are accumulated to obtain the cumulative and check values, recorded as V. Determine whether the cumulative and check value V is 0. If V is equal to 0, the check passes, and the functional unit continues to perform the corresponding task. If V is not equal to 0, the check fails, and it can be re-burned for judgment. If it still fails, it is determined that the LPC178x_7x series chip has an abnormality.

[0052] Example 3

[0053] See also Figure 1 This embodiment provides a firmware detection method based on interrupt vectors that is specifically applicable to LPC111x and LPC11Cxx series chips.

[0054] First see Figure 2In step S1, a bin firmware including a verification unit is constructed, and the interrupt vector of the bin firmware is modified to obtain an optimized bin firmware. Specifically, a verification unit and a functional unit are constructed, the verification unit is used to implement verification of the bin firmware, and the functional unit is used to provide software support for the embedded system of the chip of this embodiment. Therefore, in this embodiment, the bin firmware includes a verification unit and a functional unit, and the verification unit and the functional unit are cross-compiled to obtain the bin firmware.

[0055] Then modify the interrupt vector reserved in the bin firmware. Figure 3 In this embodiment, the total number of bytes of the bin firmware is obtained and recorded as M. If the total number of bytes M is divisible by 4, let I=M. If M is not divisible by 4, it is calculated, that is, M is divided by 4, the integer is added to 1 and then multiplied by 4. I is used as the total number of bytes required for the bin firmware. The total number of bytes M of the bin firmware is increased to I based on the 0-padding method through the file tool.

[0056] The two interrupt vector addresses of the chip of this embodiment are obtained as bytes 88-95. The interrupt vector addresses 88-95 are reserved interrupt vectors. The total byte number I is written into bytes 88-91 of the bin firmware through the file tool; every 4 bytes of the total byte number I of the bin firmware form an unsigned integer data, and several unsigned integer data are accumulated to obtain a value O, the value O is bitwise inverted and the value 1 is added to obtain a value P, and the value P is written into bytes 92-95 of the bin firmware through the file tool to finally obtain the optimized bin firmware.

[0057] Next, the obtained optimized bin firmware is burned into the ROM of the chip of this embodiment.

[0058] Finally, in step S3, the LPC178x_7x series chip is powered on and started, and the bin firmware is run. At this time, the detection unit is started first to verify the optimized bin firmware. The detection unit obtains the total number of bytes of the optimized bin firmware from the 88th-91st bytes of the ROM address of the chip in this embodiment, respectively, and records it as N. The N bytes of the optimized bin firmware are composed of an unsigned integer data of every 4 bytes, and a number of unsigned integer data are accumulated to obtain a cumulative check value, which is recorded as V. It is determined whether the cumulative check value V is 0. If V is equal to 0, the check is passed, and the functional unit continues to perform the corresponding task. If V is not equal to 0, the check fails, and it can be re-burned for judgment. If it still fails, it is determined that the LPC178x_7x series chip has an abnormality.

[0059] Example 4

[0060] See also Figure 4 This embodiment provides a firmware detection device based on interrupt vectors that can implement embodiments 1 to 3, including:

[0061] A data acquisition module is used to obtain the total number of bytes and data of the optimized bin firmware;

[0062] A data processing module, used for performing data processing on the total number of bytes obtained to obtain a cumulative sum check value;

[0063] The verification judgment module is used to determine whether the cumulative and verification values ​​are 0. If they are 0, the verification passes. If they are not 0, the verification fails.

[0064] Example 5

[0065] This embodiment also provides a computer device, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the firmware detection method based on interrupt vectors such as embodiment 1, embodiment 2, or embodiment 3.

[0066] Example 6

[0067] This embodiment also provides a storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors execute the firmware detection method based on interrupt vectors such as Example 1, Example 2, or Example 3.

[0068] The embodiments of the present invention are described in detail above in conjunction with the accompanying drawings, but the present invention is not limited to the above embodiments. Even if various changes are made to the present invention, if these changes fall within the scope of the claims of the present invention and their equivalents, they still fall within the protection scope of the present invention.

Claims

1. A firmware detection method based on interrupt vector, characterized in that: The optimized bin firmware burned into the embedded system is used to perform firmware detection, wherein the optimized bin firmware includes a detection unit for implementing firmware self-detection, including the following steps: S1: Start the embedded system, and then run the detection unit to verify the optimized bin firmware, and obtain the total number of bytes of the optimized bin firmware, which is recorded as N; S2: The N bytes of the optimized bin firmware are grouped into an unsigned integer data with every 4 bytes, and a plurality of unsigned integer data are accumulated to obtain an accumulated and check value, which is recorded as V; S3: Determine whether the cumulative check value V is 0. If V is equal to 0, the check passes. If V is not equal to 0, it is determined that the ARM chip is abnormal. Before step S1, the optimized bin firmware is constructed, which specifically includes the following steps: A1: construct the detection unit and the function unit of the optimized bin firmware, wherein the detection unit is used to implement firmware detection, and the function unit is used to implement normal operation of the embedded system; A2: cross-compile the detection unit and the functional unit to obtain bin firmware; A3: modify the interrupt vector of the bin firmware to obtain the optimized bin firmware; A4: Burn the optimized bin firmware into the ROM of the ARM chip in the embedded system; In step A3, modifying the interrupt vector of the bin firmware to obtain the optimized bin firmware specifically includes the following steps: B1: Get the total number of bytes of the bin firmware and record it as M. If M is divisible by 4, let I=M. If M is not divisible by 4, then get I based on M through a calculation formula, where I is an integer value divisible by 4. The calculation formula is ,in, is the division rounding sign; B2: increasing the total byte number M of the bin firmware to 1 based on the 0-filling method; B3: Obtain the interrupt vector addresses m and n of the ARM chip, and write the integer value I into the m byte of the bin firmware; B4: Every 4 bytes of the bin firmware are organized into an unsigned integer data, and several unsigned integer data are accumulated to obtain a value O, the value O is bitwise inverted and a value 1 is added to obtain a value P, and the value P is written into the n-byte of the bin firmware to obtain the optimized bin firmware.

2. A firmware detection device based on interrupt vector, configured to implement the firmware detection method based on interrupt vector according to claim 1, characterized in that: include: A data acquisition module is used to acquire the total number of bytes and data of the optimized bin firmware, where the total number of bytes is recorded as N; A data processing module is used to perform data processing on the total number of bytes obtained to obtain a cumulative sum check value, specifically, the N bytes of the optimized bin firmware are composed of an unsigned integer data per 4 bytes, and a plurality of unsigned integer data are accumulated to obtain the cumulative sum check value, which is recorded as V; The verification judgment module is used to judge whether the accumulated and verified value is 0. If it is 0, the verification passes; if it is not 0, the verification fails.

3. A computer device, comprising a memory and a processor, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the processor executes the firmware detection method based on interrupt vectors as claimed in claim 1.

4. A storage medium storing computer-readable instructions, wherein when the computer-readable instructions are executed by one or more processors, the one or more processors execute the firmware detection method based on interrupt vectors as claimed in claim 1.