Method for updating bottom-layer firmware program, storage medium and electronic device

By introducing interface switching and mutual exclusion semaphores into the underlying firmware program update method, the problems of cumbersome operations and system crashes are solved, flexible and reliable online updates are achieved, professional skill requirements are reduced and update efficiency is improved.

CN113918199BActive Publication Date: 2024-10-29CRRC ZHUZHOU ELECTRIC LOCOMOTIVE RESEARCH INSTITUTE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010664704.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-07-10
Publication Date
2024-10-29
Estimated Expiration
2040-07-10

AI Technical Summary

Technical Problem

The update method of the underlying firmware program in the prior art is cumbersome, requires high professional skills, has low update efficiency, and may cause system crash due to interface access conflicts.

Method used

Provides a method for updating the underlying firmware program, including receiving update requests, obtaining target code, caching the program to be updated, determining the system boot mode and switching interfaces, calling the corresponding interface function to update the program, and introducing a mutually exclusive semaphore during the update process To avoid illegal access to the interface.

Benefits of technology

It realizes flexible updates that are compatible with different boot methods, avoids system crashes, reduces operational complexity and professional skill requirements, improves update efficiency, and can restore the original program when the update fails.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113918199B_ABST
    Figure CN113918199B_ABST
Patent Text Reader

Abstract

The present application relates to the field of computer embedded software technology, and specifically to an update method, storage medium and electronic device for a bottom-level firmware program, which solves the problems in the related art that the update method for the bottom-level firmware program is cumbersome to operate, requires high professional skills of the operator, has low update efficiency and is unreliable. The method includes: receiving an update request, obtaining the target code of the bottom-level firmware program to be updated; caching the bottom-level firmware program to be updated; judging the system boot startup mode, and judging whether it is necessary to switch the interface based on the system boot startup mode; if necessary, switching the system interface to the first interface; calling the first interface function to update the bottom-level firmware program to be updated, and verifying the updated bottom-level firmware program; switching the first interface back to the system interface; if not necessary, calling the interface function corresponding to the system interface to update the stored bottom-level firmware program, and verifying the updated bottom-level firmware program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of computer embedded software, and in particular to an updating method, a storage medium and an electronic device for an underlying firmware program. Background Art

[0002] In the field of industrial control embedded systems, it is usually necessary to update the underlying firmware programs (such as operating systems and even boot programs) during on-site maintenance. Traditional software updates involve using an emulator to burn the program into the memory through the JTAG (Joint Test Action Group) interface. However, this method is cumbersome to operate and requires high professional skills from operators. In addition, on-site operations usually require plugging and unplugging single boards to connect to the JTAG interface, which is extremely inconvenient and affects the efficiency of program updates.

[0003] It also includes disassembling the chip and using a burner to burn it, but this method that requires disassembling the hardware is also very unreliable. Therefore, using software to implement online updates of the underlying firmware program (boot program, operating system) has become a technical point that developers and maintenance personnel are increasingly paying attention to.

[0004] When the underlying firmware program is updated online through software, the traditional software update method will cause the system to crash when the interface of the system boot startup mode and the interface of normal access to peripherals after the system starts are different, and the two interfaces cannot be accessed at the same time.

[0005] Therefore, the updating method of the underlying firmware program in the related art is cumbersome to operate, requires high professional skills of the operator, has low updating efficiency, is unreliable, and may cause system crashes due to interface access conflicts. Summary of the invention

[0006] In response to the above problems, the present application provides a method for updating the underlying firmware program, a storage medium and an electronic device, which solves the technical problems in the related technology that the method for updating the underlying firmware program is cumbersome to operate, requires high professional skills of the operator, has low update efficiency, is unreliable in the update method, and has the problem of system crashes due to interface access conflicts.

[0007] In a first aspect, the present application provides a method for updating an underlying firmware program, the method comprising:

[0008] Receive an update request and obtain the target code of the underlying firmware program to be updated;

[0009] caching the underlying firmware program to be updated;

[0010] Determining a system boot mode, and determining whether an interface needs to be switched based on the system boot mode;

[0011] If interface switching is required, the system interface is switched to the first interface;

[0012] Calling the first interface function to update the underlying firmware program to be updated, and verifying the updated underlying firmware program;

[0013] Switching the first interface back to the system interface;

[0014] If interface switching is not required, the interface function corresponding to the system interface is called to update the stored underlying firmware program, and the updated underlying firmware program is verified.

[0015] According to an embodiment of the present application, optionally, the above-mentioned method for updating the underlying firmware program further includes:

[0016] Get the mutex semaphore before switching interfaces;

[0017] The bottom firmware program is updated, and the mutex semaphore is released after verification is completed.

[0018] According to an embodiment of the present application, optionally, in the above-mentioned underlying firmware program update method, the system interface is a local bus control interface, the first interface is a serial peripheral interface, and the underlying firmware program includes at least one of a boot program and an operating system.

[0019] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the step of determining whether to switch the interface based on the system boot mode includes:

[0020] When the system is booted from the serial peripheral interface, the underlying firmware program is stored in a memory connected to the serial peripheral interface, and an interface switch needs to be performed;

[0021] When the system is booted from the local bus control interface, the bottom-level firmware program is stored in a memory connected to the local bus control interface, and there is no need to switch interfaces.

[0022] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the step of switching the system interface to the first interface includes:

[0023] Convert the preset IO pin from high level to low level;

[0024] When a falling edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a low level, so as to switch the system interface to the first interface.

[0025] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the step of switching the first interface back to the system interface includes:

[0026] Convert the preset IO pin from low level to high level;

[0027] When a rising edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a high level, so as to switch the first interface to the system interface.

[0028] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the updating of the underlying firmware program to be updated and the verification of the updated underlying firmware program include:

[0029] Step 1: Determine the program burning offset address and maximum capacity according to the type of the underlying firmware program to be updated, and back up the original underlying firmware program of the system;

[0030] Step 2: Calculate the total number of erase blocks and the total number of pages to be written to update the underlying firmware program, and determine whether the total capacity of the underlying firmware program is less than or equal to the preset maximum capacity. If so, execute step 3; if not, exit the update;

[0031] Step 3: erase a block to be erased, and make the first counter count once, wherein the initial value of the first counter is set to zero; determine whether the value recorded by the first counter is less than the total number of blocks to be erased, if so, execute step 3 again, if not, execute step 4;

[0032] Step 4: writing one page of data of the bottom firmware program into the flash memory from the offset address in sequence, and causing the second counter to count once, with the initial value of the second counter being set to zero;

[0033] Verify the written underlying firmware program. If the verification succeeds, determine whether the number recorded by the second counter is less than the total number of pages of the underlying firmware program to be written. If so, continue to execute step 4 until the number recorded by the second counter is greater than or equal to the total number of pages of the underlying firmware program.

[0034] If the verification fails, the underlying firmware program to be updated is restored through the backed-up underlying firmware program.

[0035] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the step of determining the program burning offset address and the maximum capacity according to the type of the underlying firmware program to be updated includes:

[0036] Determine the type of underlying firmware program to be updated according to preset type parameters;

[0037] When the preset type parameter is 0, the bottom firmware program is a boot program, and the offset address of the boot program is determined to be a first offset address, and the maximum capacity is a first preset capacity;

[0038] When the preset type parameter is 1, the underlying firmware program is an operating system, the offset address of the operating system is determined to be a second offset address, and the maximum capacity is a second preset capacity.

[0039] According to an embodiment of the present application, optionally, in the above-mentioned underlying firmware program update method, the total number of blocks to be erased includes the minimum number of blocks required to constitute a capacity not less than the total capacity of the underlying firmware program, and the total number of pages to be written includes the minimum number of pages required to constitute a capacity not less than the total capacity of the underlying firmware program.

[0040] According to an embodiment of the present application, optionally, in the above-mentioned method for updating the underlying firmware program, the step of verifying the updated underlying firmware program includes:

[0041] It is determined whether the underlying firmware program in the flash memory is completely consistent with the underlying firmware program in the system cache. If so, the verification is successful; if not, the verification fails.

[0042] In a second aspect, the present application provides a storage medium, which stores a computer program that can be executed by one or more processors and can be used to implement the above-mentioned underlying firmware program update method.

[0043] In a third aspect, the present application provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, the memory and the processor are communicatively connected to each other, and when the computer program is executed by the processor, the above-mentioned underlying firmware program update method is executed.

[0044] The present application provides a method for updating a bottom-level firmware program, a storage medium, and an electronic device. Compared with the prior art, the method has the following beneficial effects:

[0045] 1. Compatible with two different boot modes, LBC and SPI. You can choose to update the boot program or operating system according to user needs, and restore to the original program when the update fails;

[0046] 2. Introduce mutually exclusive semaphores to ensure that the interface mode remains unchanged during program updates and avoid illegal access to the interface that may cause system crashes;

[0047] 3. Update the underlying firmware online without disassembling the hardware;

[0048] 4. The operation is simple, the professional skills of the operators are not high, and the update efficiency is high. BRIEF DESCRIPTION OF THE DRAWINGS

[0049] The present application will be described in more detail below based on embodiments and with reference to the accompanying drawings:

[0050] Figure 1 A flowchart of a method for updating a bottom-level firmware program provided in an embodiment of the present application;

[0051] Figure 2 A schematic diagram of interface switching of a method for updating a bottom-level firmware program provided in an embodiment of the present application;

[0052] Figure 3 A schematic diagram of the update process of the underlying firmware program update method provided in an embodiment of the present application.

[0053] In the drawings, the same reference numerals are used for the same components, and the drawings are not drawn to scale. DETAILED DESCRIPTION

[0054] The following will describe the implementation methods of the present application in detail with reference to the accompanying drawings and embodiments, so that the implementation process of how the present application applies technical means to solve technical problems and achieve corresponding technical effects can be fully understood and implemented accordingly. The embodiments of the present application and the various features in the embodiments can be combined with each other without conflict, and the technical solutions formed are all within the scope of protection of the present application.

[0055] The present invention discloses a method for updating a bottom-level firmware program, a storage medium, and an electronic device, which solve the technical problems in the related art that the method for updating a bottom-level firmware program is cumbersome to operate, requires high professional skills of operators, has low updating efficiency, and is unreliable.

[0056] Embodiment 1

[0057] Figure 1 A flowchart of a method for updating a bottom-level firmware program provided in an embodiment of the present application is shown as follows: Figure 1 As shown, the method includes:

[0058] Step S110: receiving an update request and obtaining the target code of the underlying firmware program to be updated;

[0059] Step S120: caching the underlying firmware program to be updated;

[0060] Step S130: determining a system boot mode, and determining whether an interface needs to be switched based on the system boot mode;

[0061] Step S140: If interface switching is required, the system interface is switched to the first interface;

[0062] Step S150: calling the first interface function to update the underlying firmware program to be updated, and verifying the updated underlying firmware program;

[0063] Step S160: Switching the first interface back to the system interface;

[0064] Step S170: If interface switching is not required, the interface function corresponding to the system interface is called to update the stored underlying firmware program, and the updated underlying firmware program is verified.

[0065] Furthermore, the method further includes: obtaining a mutex semaphore before performing interface switching;

[0066] The bottom firmware program is updated, and the mutex semaphore is released after verification is completed.

[0067] Furthermore, the system interface is a local bus control interface, the first interface is a serial peripheral interface, and the underlying firmware program includes at least one of a boot program and an operating system.

[0068] This application performs software updates on the underlying firmware programs (such as operating systems and even boot programs) based on the Feiteng chip, and can support two different boot startup modes: local bus control interface LBC and serial peripheral interface SPI. It achieves compatibility with two boot startup modes, selectable update types, and flexible, convenient and reliable online updates of the underlying firmware programs.

[0069] The boot program is a program that needs to be started when the system is powered on to complete the deployment of the minimum system and guide the loading of the operating system. Common boot programs include UBOOT and bootrom in vxWorks.

[0070] The LBC interface and SPI interface of the Feiteng chip share a 1GB address space. The two interfaces cannot be used at the same time and need to be configured and switched through hardware pins. For example, for a board booted from SPI, the peripheral device is connected to the processor through the LBC interface. After the system is successfully booted, the interface mode needs to be switched from SPI to LBC to work properly. The boot mode of the system determines the storage location of the underlying firmware program in the memory connected to which interface.

[0071] The booting mode of the system may be determined according to a preset pin, or according to a preset storage address of a program, or may be determined by other existing technologies.

[0072] Based on the characteristics of the Feiteng chip, if you want to perform an online update of the underlying firmware program, you first need to determine whether to switch between the LBC interface and the SPI interface, and it is required that the interface mode is not allowed to be switched again during the program update process, otherwise illegal access to the interface may cause the system to crash.

[0073] Feiteng FT-2000A / 2 is a domestically produced processor for equipment and industrial control embedded systems provided by Feiteng platform. It integrates a self-developed kernel and has the characteristics of low power consumption, strong real-time, high reliability, high security, etc. In this embodiment, Feiteng FT-2000A / 2 is used as an example for explanation.

[0074] Specifically, the user uploads the underlying firmware program target code that needs to be updated to the peripheral FLASH memory through the remote client, and then sends an update request. Among them, the FLASH memory is connected to Feiteng FT-2000A / 2 through the LBC interface, and the FLASH memory is mounted with a file system to facilitate user file management.

[0075] Among them, LBC adopts the form of address line / data line multiplexing; SPI is used for synchronous serial data transmission between processor and peripheral low-speed devices; FLASH is flash memory, which is a non-volatile memory. It can save data for a long time even in the absence of current, and its storage characteristics are equivalent to those of a hard disk.

[0076] Specifically, after receiving the update request, the system copies the underlying firmware program to be updated to the system cache through the I / O interface, determines whether the system boot mode is SPI boot or LBC boot, and switches the LBC interface and the SPI interface according to the boot mode.

[0077] Further, judging whether it is necessary to switch the interface based on the system boot mode includes:

[0078] When the system is booted from the serial peripheral interface, the underlying firmware program is stored in a memory connected to the serial peripheral interface, and an interface switch needs to be performed;

[0079] When the system is booted from the local bus control interface, the bottom-level firmware program is stored in a memory connected to the local bus control interface, and there is no need to switch interfaces.

[0080] For example, the LBC interface can connect multiple peripheral devices through chip selection. After the system is successfully started, the chip works in LBC mode to communicate with these peripheral devices.

[0081] Specifically, when updating the underlying firmware program, there are two boot modes: In case 1, the system is booted via SPI, that is, the underlying program is stored in the FLASH connected to the SPI interface, then you first need to switch the interface mode from the original LBC interface to the SPI interface; In case 2, the system is booted via LBC, that is, the underlying program is stored in the FLASH connected to the LBC interface, then the interface does not need to be switched.

[0082] Regardless of whether switching is needed, it is necessary to ensure that the interface mode remains unchanged during the program update, otherwise it will cause illegal access. Therefore, a mutex semaphore is introduced when switching the interface. The mutex semaphore is a blocking mode. The switch between the LBC interface and the SPI interface is performed only after the mutex semaphore is successfully obtained.

[0083] Among them, introducing a mutex semaphore during switching can prevent other programs from switching the LBC interface and the SPI interface, ensuring that the interface mode remains unchanged during program updates.

[0084] Further, switching the system interface to the first interface includes:

[0085] Convert the preset IO pin from high level to low level;

[0086] When a falling edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a low level, so as to switch the system interface to the first interface.

[0087] Specifically, the preset IO pin is converted from a high level to a low level; when the first control chip detects the falling edge of the preset IO pin, it controls the level value of the second chip interface switching pin to a low level to switch the system interface to an SPI interface.

[0088] Further, switching the first interface back to the system interface includes:

[0089] Convert the preset IO pin from low level to high level;

[0090] When a rising edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a high level, so as to switch the first interface to the system interface.

[0091] Specifically, the preset IO pin is converted from a low level to a high level; when the first control chip detects a rising edge of the preset IO pin, the level value of the second chip interface switching pin is controlled to be a high level to switch the SPI interface to the system interface.

[0092] Among them, the preset IO pin can be a GPIO pin, the first control chip can be an FPGA, the second chip can be a Feiteng FT-2000A / 2, and the second chip interface switching pin is the spi_lpc_select pin; FPGA is a field programmable gate array, GPIO is a general input / output port, and its pin function can be controlled by the designer through registers, and can be used for input, output or other special functions.

[0093] Figure 2 The interface switching diagram of an underlying firmware program update method provided by an embodiment of the present application is as follows: Figure 2 As shown in the figure, the steps of interface switching are as follows:

[0094] The underlying firmware program corresponding to the target code is cached according to the update request, and the system's mutual exclusion semaphore is obtained.

[0095] Determine whether to switch interfaces based on the system boot mode.

[0096] When the interface needs to be switched, the specific GPIO pin is controlled to be pulled down from high level to low level. After capturing the falling edge of the specific GPIO pin, the FPGA controls the spi_lpc_select pin level value of Feiteng FT-2000A / 2 to be low level. Feiteng FT-2000A / 2 controls the use of the SPI interface mode, thereby realizing the switching between the LBC interface and the SPI interface. After the switching is completed, the SPI interface is called to update the stored underlying firmware program, and the underlying firmware program is verified.

[0097] Then control the specific GPIO pin from low level to high level. After capturing the rising edge of the specific GPIO pin, FPGA controls the spi_lpc_select pin level value of Feiteng FT-2000A / 2 to a high level. Feiteng FT-2000A / 2 controls the use of the LBC interface mode, thereby switching to the original interface and releasing the mutually exclusive semaphore.

[0098] Specifically, the LBC and SPI interfaces of Feiteng FT-2000A / 2 share the address space of 0 to 1GB. The LBC interface and the SPI interface are switched by the spi_lpc_select pin of the chip hardware. When spi_lpc_select is high, LBC uses this 1GB address space. When spi_lpc_select is low, SPI uses this 1GB address space.

[0099] When the interface switching is not needed, the LBC interface is called to update the stored bottom firmware program, and the bottom firmware program is verified; and the mutex semaphore is released.

[0100] Further, the updating of the underlying firmware program to be updated and verifying the updated underlying firmware program includes:

[0101] Step S210: determining the program burning offset address and the maximum capacity according to the type of the underlying firmware program to be updated, and backing up the original underlying firmware program of the system;

[0102] Step S220: Calculate the total number of erase blocks and the total number of pages to be written to update the underlying firmware program, and determine whether the total capacity of the underlying firmware program is less than or equal to the preset maximum capacity. If so, execute step S230; if not, exit the update.

[0103] Step S230: Erasing a block to be erased, and making the first counter count once, wherein the initial value of the first counter is set to zero; determining whether the value recorded by the first counter is less than the total number of blocks to be erased, if so, executing step S230 again, if not, executing step S240;

[0104] Step S240: writing a page of data in the bottom firmware program into the flash memory in sequence from the offset address, and causing the second counter to count once, with the initial value of the second counter being set to zero;

[0105] Verify the written underlying firmware program. If the verification succeeds, determine whether the number recorded by the second counter is less than the total number of pages of the underlying firmware program to be written. If so, continue to execute step S240 until the number recorded by the second counter is greater than or equal to the total number of pages of the underlying firmware program.

[0106] If the verification fails, the underlying firmware program to be updated is restored through the backed-up underlying firmware program.

[0107] Further, the step of determining the program burning offset address and the maximum capacity according to the type of the underlying firmware program to be updated includes:

[0108] Determine the type of underlying firmware program to be updated according to preset type parameters;

[0109] When the preset type parameter is 0, the bottom firmware program is a boot program, and the offset address of the boot program is determined to be a first offset address, and the maximum capacity is a first preset capacity;

[0110] When the preset type parameter is 1, the underlying firmware program is an operating system, the offset address of the operating system is determined to be a second offset address, and the maximum capacity is a second preset capacity.

[0111] Furthermore, the total number of blocks to be erased includes the minimum number of blocks required to constitute a capacity not less than the total capacity of the underlying firmware program, and the total number of pages to be written includes the minimum number of pages required to constitute a capacity not less than the total capacity of the underlying firmware program.

[0112] Furthermore, the checking of the updated underlying firmware program includes:

[0113] It is determined whether the underlying firmware program in the flash memory is completely consistent with the underlying firmware program in the system cache. If so, the verification is successful; if not, the verification fails.

[0114] Figure 3 The following is a schematic diagram of the update process of the underlying firmware program update method provided in the embodiment of the present application, such as Figure 3 As shown, the bottom firmware program is referred to as the bottom program here, and the steps of updating and reading back the bottom program include:

[0115] Step S310: Determine the underlying program type to be updated, whether it is a boot program or an operating system, based on the user parameter TYPE value. TYPE=0 indicates updating the boot program, TYPE=1 indicates updating the operating system, and the remaining parameter values ​​are invalid to exit the update. Determine the offset address and maximum capacity of the underlying program to be burned.

[0116] The offset address of the boot program is 0, and the maximum capacity maxSize is 3MB, or 0x300000 bytes (the prefix 0x indicates hexadecimal). The offset address of the operating system is 0x300000, and the maximum capacity maxSize is 5MB, or 0x500000 bytes.

[0117] Step S320: Back up the original FLASH bottom-level program. Starting from the offset address offset, read the original data in the FLASH into the system cache for backup, and the read size is maxSize.

[0118] Step S330: Determine the blocks to be erased and the number of pages to be read / written according to the actual size of the underlying program. If the actual size of the underlying program exceeds the maximum capacity maxSize, exit the update; if the actual size of the underlying program does not exceed the maximum capacity maxSiz, execute step S340.

[0119] Among them, FLASH erasure is based on blocks as the basic unit, and read / write is based on pages as the basic unit. Therefore, the number of blocks to be erased includes the minimum number of blocks required for the capacity to be no less than the total capacity of the underlying firmware, and the number of pages to be read / written includes the minimum number of pages required for the capacity to be no less than the total capacity of the underlying firmware.

[0120] For example, if the size of each block of FLASH is 0x8000 bytes, the size of each page is 0x100 bytes, and the size of the program to be updated is 3000000 bytes, it is necessary to determine the offset address of the underlying program burning from step S310, and then start erasing 92 blocks (BlkNum = 92) and reading / writing 11719 pages (PageNum = 11719).

[0121] Step S340: Erase one block to be erased in sequence from the offset address, and increment ErsCnt by one; compare ErsCnt and BlkNum, and when ErsCnt < BlkNum, execute step S340 again to perform the block erasing operation.

[0122] Among them, set the initial value of ErsCnt to 0, loop to call the erasing function of the LBC or SPI interface, erase one block each time, and increment ErsCnt by one each time the interface is called. When ErsCnt >= BlkNum, execute step S350.

[0123] Step S350: Write the data of one page of the underlying firmware program in sequence from the offset address to the flash memory, and increment WtCnt by one. Compare WtCnt and PageNum, and when WtCnt < PageNum, perform the burning of the underlying program.

[0124] Among them, set the initial value of WtCnt to 0, call the writing interface function of SPI or LBC, and write the data of the underlying program backed up in step S320 to the FLASH in sequence from the offset address, burn one page each time, and increment WtCnt by one each time it is called, and then execute step S360.

[0125] Step S360: After burning each page, perform the read-back verification of the underlying program. Call the read interface function of SPI or LBC to read back the data written to the flash memory, and compare the read data with the system cache data. If they are exactly the same, the verification passes and step S380 is executed; otherwise, the verification fails and step S370 is executed.

[0126] Step S370: When the verification fails, since the FLASH erasing and writing operations have been performed at this time and the original underlying program in the FLASH has been damaged, it is necessary to restore the backed-up original underlying program, and then execute step S390.

[0127] Step S380: When the verification is successful, return to execute step S350. When WtCnt >= PageNum, the burning is completed and step S390 is executed.

[0128] Step S390: Feedback the update success or failure information according to the execution situation and end.

[0129] This embodiment provides a flowchart of an update method for a bottom-level firmware program, including: receiving an update request, obtaining the target code of the bottom-level firmware program to be updated; caching the bottom-level firmware program to be updated; judging the system boot startup mode, and judging whether it is necessary to switch the interface based on the system boot startup mode; if the interface switching is required, switching the system interface to the first interface; calling the first interface function to update the bottom-level firmware program to be updated, and verifying the updated bottom-level firmware program; switching the first interface back to the system interface; if the interface switching is not required, calling the interface function corresponding to the system interface to update the stored bottom-level firmware program, and verifying the updated bottom-level firmware program. Combined with the characteristics that the LBC interface and the SPI interface of the Feiteng chip cannot be used at the same time, it is compatible with two different boot startup modes of SPI and LBC. It can choose to update the boot program or the operating system according to user needs, and can be restored to the original program when the update fails, introducing a mutex semaphore to ensure that the interface mode remains unchanged during the program update process, and avoid illegal interface access causing system crashes.

[0130] Embodiment 2

[0131] This embodiment also provides a computer-readable storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, a server, an App application store, etc., on which a computer program is stored. When the computer program is executed by a processor, the method steps of the first embodiment can be implemented, and this embodiment will not be repeated here.

[0132] Embodiment 3

[0133] This embodiment provides an electronic device, which includes a memory and a processor, wherein the memory stores a computer program, and the memory and the processor are communicatively connected to each other. When the computer program is executed by the processor, the updating method of the underlying firmware program described in Embodiment 1 is executed.

[0134] Among them, the processor can be an application specific integrated circuit (Application Specific Integrated Circuit, referred to as ASIC), a digital signal processor (Digital Signal Processor, referred to as DSP), a digital signal processing device (Digital Signal Processing Device, referred to as DSPD), a programmable logic device (Programmable Logic Device, referred to as PLD), a field programmable gate array (Field·Programmable Gate Array, referred to as FPGA), a controller, a microcontroller, a microprocessor or other electronic components, and is used to execute the updating method of the underlying firmware program in the above-mentioned embodiment 1.

[0135] The memory can be implemented by any type of volatile or non-volatile storage device or a combination of them, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk.

[0136] In summary, the present application provides a method for updating the underlying firmware program, a storage medium and an electronic device, the method comprising: receiving an update request, obtaining the target code of the underlying firmware program to be updated; caching the underlying firmware program to be updated; judging the system boot startup mode, and judging whether it is necessary to switch the interface based on the system boot startup mode; if the interface switching is required, switching the system interface to the first interface; calling the first interface function to update the underlying firmware program to be updated, and verifying the updated underlying firmware program; switching the first interface back to the system interface; if the interface switching is not required, calling the interface function corresponding to the system interface to update the stored underlying firmware program, and verifying the updated underlying firmware program.

[0137] Combined with the characteristics of Feiteng chip LBC interface and SPI interface cannot be used at the same time, it is compatible with two different boot startup methods, SPI and LBC. It can choose to update the boot program or the operating system according to user needs, and can be restored to the original program when the update fails. The introduction of mutual exclusion semaphore ensures that the interface mode remains unchanged during the program update process, avoiding illegal access to the interface and causing system crashes. The underlying firmware program is updated online without disassembling the hardware. The operation is simple, the professional skills of the operator are not high, and the update efficiency is high. The technical problems of the underlying firmware program update method in the related technology that the operation is cumbersome, the professional skills of the operator are high, the update efficiency is low, and the update method is unreliable are solved.

[0138] In the several embodiments provided in the present application, it should be understood that the disclosed method can also be implemented in other ways. The method embodiments described above are merely illustrative.

[0139] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0140] Although the implementation methods disclosed in this application are as above, the above contents are only the implementation methods adopted for facilitating the understanding of this application, and are not intended to limit this application. Any technician in the technical field to which this application belongs can make any modifications and changes in the form and details of the implementation without departing from the spirit and scope disclosed in this application, but the scope of patent protection of this application shall still be based on the scope defined in the attached claims.

Claims

1. A method for updating a bottom-level firmware program, It is characterized in that The method comprises: Receive an update request and obtain the target code of the underlying firmware program to be updated; caching the underlying firmware program to be updated; Determining a system boot mode, and determining whether an interface needs to be switched based on the system boot mode; If interface switching is required, the system interface is switched to a first interface, wherein the system interface is a local bus control interface and the first interface is a serial peripheral interface; Calling a function corresponding to the first interface to update the underlying firmware program to be updated, and verifying the updated underlying firmware program; Switching the first interface back to the system interface; If interface switching is not required, the interface function corresponding to the system interface is called to update the stored underlying firmware program, and the updated underlying firmware program is verified.

2. The method according to claim 1, It is characterized in that Also includes: Get the mutex semaphore before switching interfaces; The bottom firmware program is updated, and the mutex semaphore is released after verification is completed.

3. The method according to claim 1, It is characterized in that The bottom firmware program includes at least one of a boot program and an operating system.

4. The method according to claim 3, It is characterized in that The determining whether to switch the interface based on the system boot mode includes: When the system is booted from the serial peripheral interface, the underlying firmware program is stored in a memory connected to the serial peripheral interface, and an interface switch needs to be performed; When the system is booted from the local bus control interface, the bottom-level firmware program is stored in a memory connected to the local bus control interface, and there is no need to switch interfaces.

5. The method according to claim 1, It is characterized in that The step of switching the system interface to the first interface includes: Convert the preset IO pin from high level to low level; When a falling edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a low level, so as to switch the system interface to the first interface.

6. The method according to claim 1, It is characterized in that The switching the first interface back to the system interface includes: Convert the preset IO pin from low level to high level; When a rising edge of a preset IO pin is detected, the level value of the interface switching pin is controlled to be a high level, so as to switch the first interface to the system interface.

7. The method according to claim 1, It is characterized in that The updating of the underlying firmware program to be updated and verifying the updated underlying firmware program includes: Step 1: Determine the program burning offset address and maximum capacity according to the type of the underlying firmware program to be updated, and back up the original underlying firmware program of the system; Step 2: Calculate the total number of erased blocks and the total number of written pages required to update the underlying firmware program, and determine whether the total capacity of the underlying firmware program is less than or equal to the preset maximum capacity. If so, execute step 3; if not, exit the update; Step 3: Erase a block to be erased, and make the first counter count once, wherein the initial value of the first counter is set to zero; determine whether the value recorded by the first counter is less than the total number of blocks to be erased, if so, execute step 3 again, if not, execute step 4; Step 4: writing one page of data of the bottom firmware program into the flash memory from the offset address in sequence, and causing the second counter to count once, with the initial value of the second counter being set to zero; Verify the written underlying firmware program. If the verification succeeds, determine whether the number recorded by the second counter is less than the total number of pages of the underlying firmware program to be written. If so, continue to execute step 4 until the number recorded by the second counter is greater than or equal to the total number of pages of the underlying firmware program. If the verification fails, the underlying firmware program to be updated is restored through the backed-up underlying firmware program.

8. The method according to claim 7, It is characterized in that The step of determining the program writing offset address and the maximum capacity according to the type of the underlying firmware program to be updated includes: Determine the type of underlying firmware program to be updated according to preset type parameters; When the preset type parameter is 0, the bottom firmware program is a boot program, and the offset address of the boot program is determined to be a first offset address, and the maximum capacity is a first preset capacity; When the preset type parameter is 1, the underlying firmware program is an operating system, the offset address of the operating system is determined to be a second offset address, and the maximum capacity is a second preset capacity.

9. The method according to claim 7, It is characterized in that The total number of blocks to be erased includes the minimum number of blocks required to constitute a capacity not less than the total capacity of the underlying firmware program, and the total number of pages to be written includes the minimum number of pages required to constitute a capacity not less than the total capacity of the underlying firmware program.

10. The method according to claim 7, It is characterized in that The verifying the updated underlying firmware program includes: It is determined whether the underlying firmware program in the flash memory is completely consistent with the underlying firmware program in the system cache. If so, the verification is successful; if not, the verification fails.

11. A storage medium, It is characterized in that The computer program stored in the storage medium can be executed by one or more processors and can be used to implement the underlying firmware program update method as described in any one of claims 1 to 10.

12. An electronic device, It is characterized in that It comprises a memory and a processor, the memory stores a computer program, the memory and the processor are communicatively connected with each other, and when the computer program is executed by the processor, the updating method of the underlying firmware program as described in any one of claims 1 to 10 is executed.