Log Processing Method, Device, and Readable Storage Medium for Embedded Systems
By writing the first log record of the firmware version number at the initial location of each flash erase unit of the embedded system and writing the second log record of the log data at other locations, the problem of garbled code and time-consuming during log parsing of embedded devices is solved, and fast and accurate log parsing is achieved.
Patent Information
- Application Number
- CN202111281511.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-29
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2041-10-29
AI Technical Summary
In the prior art, when embedded devices store log information, they are prone to garbled code during analysis and take a long time.
Write a first log record containing the current firmware version number at the initial position of each flash erase unit, write a second log record containing the current log data at other positions, find the corresponding version of the target bin file through the firmware version number in the first log record, and parse the target string in the target bin file according to the string address in the second log record.
It realizes the accurate finding of the corresponding bin file in the embedded system for parsing. The parsing is successful in one parsing, avoiding the garbled code and multiple parsing caused by the inconsistent bin file version and the log record version, significantly shortening the analysis time.
Smart Images

Figure CN114077594B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of embedded technologies, and in particular, to a method, a device, and a computer-readable storage medium for processing logs of an embedded system. Background Art
[0002] With the development of embedded technologies, embedded systems have become an important part of the computer field. Embedded devices also have more and more functions, and the relationships between functions are becoming closer and closer, resulting in more and more problems with the products. Even after some products are launched on the market, a large number of problems need to be solved. Therefore, for an embedded system, the log information recorded during operation plays a very important role for developers to locate faults.
[0003] In the prior art, an embedded device will allocate an area in the flash to store log information, and the log information is generally stored in the form of a string. To save the flash space occupied by a single log message, the ASCII code values of the string are generally not directly stored, but the address of the string in the bin file is recorded. After the log file is exported, a host computer tool and the bin file corresponding to the log file are used for parsing. The starting address of the recorded string is parsed from the log file, and the string is parsed by looking up the corresponding address in the bin file.
[0004] By storing the addresses of log strings, the flash space can be greatly saved. However, during parsing, since the corresponding addresses in the bin file need to be searched through the recorded addresses for string parsing, garbled characters are likely to appear during the parsing process, or multiple bin files need to be parsed multiple times to completely parse the strings in the log file, resulting in a long parsing time. Summary of the Invention
[0005] The main purpose of the present invention is to provide a method, a device, and a computer-readable storage medium for processing logs of an embedded system, aiming to solve the technical problems in the prior art that the method of storing logs easily causes garbled characters during parsing and takes a long time.
[0006] To achieve the above object, an embodiment of the present invention provides a method for processing logs of an embedded system. The embedded system uses a flash erase unit as a log storage unit, and multiple flash erase units constitute a log storage space. The method for processing logs of the embedded system includes:
[0007] Determine whether the current write pointer position of the embedded system is the initial position of a flash erase unit;
[0008] If it is the initial position of a flash erase unit, obtain the current firmware version number of the embedded system;
[0009] Write a first log record containing the current firmware version number at the current write pointer position;
[0010] If it is not the initial position of the flash erase unit, obtain the current log data;
[0011] Write a second log record containing the current log data at the current write pointer position.
[0012] Optionally, before the step of writing the second log record containing the current log data at the current write pointer position, it includes:
[0013] Judge whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record;
[0014] If it is sufficient to store the current log record, execute the step of writing the second log record containing the current log data at the current write pointer position.
[0015] Optionally, after the step of judging whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record, it includes:
[0016] If it is not sufficient to store the current log record, move the current write pointer to the initial position of the next flash erase unit to point to a new flash erase unit, and execute the step of judging whether the current write pointer position of the embedded system is the initial position of the flash erase unit.
[0017] Optionally, the step of writing the first log record containing the current firmware version number at the current write pointer position includes:
[0018] Write the log type flag field and the firmware version number field in sequence at the current write pointer position to write the first log record at the initial position of the current flash erase unit.
[0019] Optionally, the step of writing the second log record containing the current log data at the current write pointer position includes:
[0020] Write the log type flag field, the string address field, the parameter count field, and the real-time parameter value field at the current write pointer position to write the second log record containing the current log data at the current write pointer position.
[0021] Optionally, before the step of obtaining the current firmware version number of the embedded system if it is the initial position of the flash erase unit, it further includes:
[0022] If it is the initial position of the flash erase unit, judge whether there is a written log record in the current flash erase unit;
[0023] If there is a written log record in the current flash erase unit, erase the written log record of the current flash erase unit and perform the step of obtaining the current firmware version number of the embedded system.
[0024] Optionally, the log processing method of the embedded system further includes:
[0025] When receiving a log output instruction sent by the host computer, send the log record file stored in the log storage space to the host computer, where the log record file includes the first log record and the second log record in each of the flash erase units;
[0026] For the host computer to find the target bin file corresponding to the firmware version number according to the firmware version number in the first log record, and the host computer parses out the target string in the target bin file based on the string address in the second log record.
[0027] Optionally, the present invention further provides a log processing method for an embedded system, and the log processing method of the embedded system is applied to a host computer. The log processing method of the embedded system includes:
[0028] Obtain the log record file stored in the log storage space in the embedded system; where the log record file includes the first log record and the second log record in each of the flash erase units;
[0029] According to the firmware version number in the first log record, find the target bin file corresponding to the firmware version number in the preset bin folder;
[0030] According to the string address in the second log record, parse out the target string in the target bin file.
[0031] In addition, the present invention further provides a device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the above-mentioned log processing method of the embedded system are implemented.
[0032] In addition, the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned log processing method of the embedded system are implemented.
[0033] The present invention provides a log processing method, device, and readable storage medium for an embedded system. By writing a first log record containing the current firmware version number at the initial position of each flash erase unit, and writing a second log record containing the current log data at other positions of each flash erase unit, when parsing, the firmware version number corresponding to the log record of the currently parsed flash erase unit can be obtained from the first log record at the initial position of each flash erase unit. Then, the target bin file corresponding to the obtained firmware version number can be found, and the target string can be parsed from the target bin file according to the string address in the second log record. This realizes the ability to accurately find the corresponding bin file for parsing, achieving successful parsing at one time, and avoiding problems such as parsing garbled codes caused by the mismatch between the version of the bin file and the version of the log record and the need for multiple parses, which takes a long time. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 It is a schematic diagram of the device structure of the hardware operating environment involved in the solution of the embodiment of the present invention;
[0035] Figure 2 It is a schematic diagram of the data structure of a flash erase unit in the present invention;
[0036] Figure 3 It is a schematic flowchart of the first embodiment of the log processing method for the embedded system of the present invention.
[0037] The implementation, functional features, and advantages of the object of the present invention will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0038] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0039] In the subsequent description, suffixes such as "module", "component", or "unit" used to represent elements are only for the convenience of describing the present invention, and they have no specific meaning themselves. Therefore, "module", "component", or "unit" can be used interchangeably.
[0040] Refer to Figure 1, the present invention provides a device, which may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, and a communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard). Optionally, the user interface 1003 may further include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory or a flash memory. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0041] Those skilled in the art can understand that Figure 1 the device shown in
[0042] is not a limitation on the device, and may include more or fewer components than shown in the figure, or combine some components, or have a different component layout. Figure 1 As shown in
[0043] In Figure 1 the device shown, the network interface 1004 is mainly used to connect to a server and communicate with the server for data; the user interface 1003 is mainly used to connect to a client and communicate with the client for data; and the processor 1001 may be used to call the computer program stored in the memory 1005 and perform the following operations:
[0044] Judge whether the current write pointer position of the embedded system is the initial position of the flash erase unit;
[0045] If it is the initial position of the flash erase unit, obtain the current firmware version number of the embedded system;
[0046] Write a first log record containing the current firmware version number at the current write pointer position;
[0047] If it is not the initial position of the flash erase unit, obtain the current log data;
[0048] Write a second log record containing the current log data at the current write pointer position.
[0049] Further, before the step of writing the second log record including the current log data at the current write pointer position, the processor 1001 may call the computer program stored in the memory 1005 and further perform the following operations:
[0050] Determine whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record;
[0051] If it is sufficient to store the current log record, then perform the step of writing the second log record including the current log data at the current write pointer position.
[0052] Further, after the step of determining whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record, the processor 1001 may call the computer program stored in the memory 1005 and further perform the following operations:
[0053] If it is not sufficient to store the current log record, then move the current write pointer to the initial position of the next flash erase unit to point to the new flash erase unit, and perform the step of determining whether the current write pointer position of the embedded system is the initial position of the flash erase unit.
[0054] Further, the step of writing the first log record including the current firmware version number at the current write pointer position includes:
[0055] Write the log type flag field and the firmware version number field in sequence at the current write pointer position to write the first log record at the initial position of the current flash erase unit.
[0056] Further, the step of writing the second log record including the current log data at the current write pointer position includes:
[0057] Write the log type flag field, the string address field, the parameter count field, and the real-time parameter value field at the current write pointer position to write the second log record including the current log data at the current write pointer position.
[0058] Further, before the step of obtaining the current firmware version number of the embedded system if it is the initial position of the flash erase unit, the processor 1001 may call the computer program stored in the memory 1005 and further perform the following operations:
[0059] If it is the initial position of the flash erase unit, then determine whether there is a written log record in the current flash erase unit;
[0060] If there is a written log record in the current flash erase unit, erase the written log record of the current flash erase unit, and perform the step of obtaining the current firmware version number of the embedded system.
[0061] Further, the processor 1001 can call the computer program stored in the memory 1005 and further perform the following operations:
[0062] When receiving the log output instruction sent by the host computer, send the log record file stored in the log storage space to the host computer, where the log record file includes the first log record and the second log record in each of the flash erase units;
[0063] For the host computer to find the target bin file corresponding to the firmware version number according to the firmware version number in the first log record, and the host computer parses out the target string in the target bin file based on the string address in the second log record.
[0064] Further, the present invention also provides a log processing method for an embedded system. The log processing method for the embedded system is applied to the host computer, and the log processing method for the embedded system includes:
[0065] Obtain the log record file stored in the log storage space in the embedded system; where the log record file includes the first log record and the second log record in each of the flash erase units;
[0066] According to the firmware version number in the first log record, find the target bin file corresponding to the firmware version number in the preset bin folder;
[0067] According to the string address in the second log record, parse out the target string in the target bin file.
[0068] The present invention also provides a log processing method for an embedded system. In the first embodiment of the log processing method for the embedded system, refer to Figure 3 , the log processing method for the embedded system of the present invention includes:
[0069] Step A10, determine whether the current write pointer position of the embedded system is the initial position of the flash erase unit;
[0070] To assist in understanding the present application, the following explains the related technical points involved in the present application:
[0071] Logs can be used to record information about the interaction between the system and system users, operation content or time, and system running status, etc. They are an important part of a system and play an important role in processing historical data, diagnosing problem tracking, and understanding system activities. Through logs, the last valid records can be retained when the system freezes or crashes, facilitating developers or maintenance personnel to quickly analyze and locate the location and cause of the freeze or crash based on relevant information, thus greatly reducing the development and maintenance time and saving human resource costs.
[0072] Flash memory is a kind of non-volatile memory that can permanently store data without current supply. It has the performance of electronic erasable and programmable, and can be erased and written multiple times. Flash memory consists of different numbers of blocks, and different models of flash memory contain different numbers of blocks. Each block includes 16 sectors, each sector includes 16 pages, and each page contains 256 bytes. Since flash memory is an erasable and writable memory, the storage space erased each time is called a flash erasure unit, also called a log storage unit. Flash memory is composed of individual flash erasure units that can be erased independently.
[0073] In flash memory, a certain storage space (i.e., log storage space) is generally allocated to store log information so that log information can be permanently saved. For example, if 32KB of space is allocated in flash memory to store log information, then the log storage space in this flash memory is 32KB. The storage space erased each time by flash memory is called a flash erasure unit, also called a log storage unit. For example, if flash erases 4KB of stored data each time, then the erasure unit of this flash is 4KB. Assuming the log storage space is 32KB and the flash erasure unit is 4KB, then this log storage space consists of 4 flash erasure units.
[0074] It should be noted that the flash memory stores log records one by one at consecutive addresses. The initial position of the flash erase unit, that is, the starting address of the flash erase unit, can be determined according to the preset starting address of the first flash erase unit and the size of the flash erase unit. For example, if the starting address of the first flash erase unit is 0 and the size of the flash erase unit is 1KB, then the starting address of the second flash erase unit is 1024, the starting address of the third flash erase unit is 1024 * 2, and the starting address of the fourth flash erase unit is 1024 * 3. Before writing a log record, it is necessary to determine whether the current write pointer position is the initial position of the current flash erase unit, that is, to determine whether the current write pointer position is the starting address of the current flash erase unit.
[0075] Step A20, if it is the initial position of the flash erase unit, then obtain the current firmware version number of the embedded system and write the first log record containing the current firmware version number at the current write pointer position;
[0076] It should be noted that the firmware refers to the driver programs stored inside the device. The firmware version number refers to the version number of the officially released firmware. The main purpose of launching a new official firmware is to fix the BUGs existing in the previous firmware and optimize related performances. The firmware version number is usually represented in the form of a combination of numbers and letters, and sometimes it is also named according to the version release time. The naming rule is defined by the production developer itself. For example, the firmware version number is 1.0.0.116.
[0077] It can be understood that if the current write pointer position is the initial position of the current flash erase unit, that is, the starting address of the current flash erase unit, then obtain the current firmware version number of the embedded system and write the first log record containing the current firmware version number at the current write pointer position, that is, write a log record containing the current firmware version number. Refer to Figure 2 , Figure 2 is a schematic diagram of the data structure of a single flash erase unit, Figure 2 The address where the first log record, that is, the first log record, is written in
[0078] Optionally, the step of writing the first log record containing the current firmware version number at the current write pointer position includes:
[0079] Write the log type flag field and the firmware version number field in sequence at the current write pointer position to write the first log record at the initial position of the current flash erase unit.
[0080] It should be noted that the log type flag is used to distinguish different stored data. For example, 0 indicates that the firmware version number is stored in this log, and 1 indicates that the log data is stored in this log. Then, the first field of all the first log records is 0, and the first field of all the second log records is 1. Refer to Figure 2 , Figure 2 In Figure 2 , the first log record is the first log record, including a log type flag field and a firmware version number field. Optionally, the first log record may further include a time information field.
[0081] Step A30: If it is not the initial position of the flash erase unit, obtain the current log data, and write a second log record containing the current log data at the current write pointer position.
[0082] It should be noted that the log data includes a string address, real-time parameter values, and may further include time information. If the current write pointer position is not the initial position of the current flash erase unit, that is, not the first address of the current flash erase unit, then obtain the current log data, and write a second log record containing the current log data at the current write pointer position. For example, refer to Figure 2 , Figure 2 In Figure 2 , the second log record, that is, the second log record, is written to an address other than the first address of the flash erase unit. The log records written to a single flash erase unit only contain one first log record, and the other log records are all second log records.
[0083] Optionally, the step of writing a second log record containing the current log data at the current write pointer position includes:
[0084] Write a log type flag field, a string address field, a parameter number field, and a real-time parameter value field at the current write pointer position to write a second log record containing the current log data at the current write pointer position.
[0085] It should be noted that the log type flag is used to distinguish different stored data. For example, 0 indicates that the firmware version number is stored, and 1 indicates that the log data is stored. Then, the first field of all the second log records is 1.
[0086] The string address, that is, the address of the string in the bin file. A complete log includes the number of parameters, the string, the real-time parameter values, and may also include the running time information. To save the log storage space in the flash memory, we generally only record the address of the string in the bin file in the log record, rather than directly recording the string, so that more log records can be recorded in the log storage space.
[0087] The number of parameters, that is, the number of parameters involved in the current runtime, and the real-time parameter value, that is, the real-time value of the parameter when the embedded system runs to the current position.
[0088] Refer to Figure 2 , Figure 2 The second log record in is the second log record, including a log type flag field, a string address field, a parameter number field, and a real-time parameter value field, but does not include the current firmware version number field. A flash erase unit records logs of the same firmware version number and does not involve log records of two or more firmware version numbers. Since a first log record containing the current firmware version number has been written at the initial position of the current flash erase unit, the second log records written at other positions of the current flash erase unit may not include the current firmware version number.
[0089] In this embodiment, by writing a first log record containing the current firmware version number at the initial position of each flash erase unit and writing a second log record containing the current log data at other positions of each flash erase unit, when parsing, the firmware version number corresponding to the log record of the current flash erase unit being parsed can be obtained from the first log record at the initial position of each flash erase unit. Then, the target bin file of the corresponding version can be found according to the obtained firmware version number, and the target string can be parsed from the target bin file according to the string address in the second log record. This realizes that the corresponding bin file can be accurately found for parsing, and the parsing is successful at one time, avoiding the problems of parsing garbled codes and the need for multiple parses due to the mismatch between the version of the bin file and the version of the log record, which takes a long time.
[0090] Furthermore, in another embodiment of the log processing method of the embedded system of the present invention, before the step of obtaining the current firmware version number of the embedded system if it is the initial position of the flash erase unit, the following steps are also included:
[0091] Step B1, if it is the initial position of the flash erase unit, determine whether there is a written log record in the current flash erase unit;
[0092] Step B2, if there is a written log record in the current flash erase unit, erase the written log record in the current flash erase unit and execute the step of obtaining the current firmware version number of the embedded system.
[0093] It should be noted that the log storage space in the flash memory consists of at least one flash erase unit. When the last flash erase unit is full, it means that the entire log storage space is full. Then the write pointer moves to the initial position of the first flash erase unit. For example, if the current log storage space consists of 4 flash erase units, when the 4th erase unit is full, the write pointer moves to the initial position of the 1st flash erase unit. Since the log records have been written in the 1st flash erase unit before, it is necessary to first erase the written log records in the 1st flash erase unit, then obtain the current firmware version number of the embedded system, and rewrite the log records to maintain the continuity and orderliness of the log storage space stored in the flash memory.
[0094] Optionally, before the step of writing the second log record containing the current log data at the current write pointer position, the following steps are included:
[0095] Step C1: Determine whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record;
[0096] It can be understood that at least one log record can be stored in a flash erase unit. A log record containing the firmware version number is written at the initial position of the flash erase unit, and log records containing log data are written at other positions of the flash erase unit. Before writing the second log record, it is necessary to determine whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position can store the current log record. To determine whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position can store the current log record, the length of the current log record can be calculated. Whether the sum of the length of the current log record and the address of the current write pointer position is greater than the end address of the current flash erase unit. If it is greater, it means that the current flash erase unit cannot store the current log record. If it is less, it means that the current flash erase unit can store the current log record.
[0097] Step C2: If it is sufficient to store the current log record, execute the step of writing the second log record containing the current log data at the current write pointer position;
[0098] Step C3: If it is not sufficient to store the current log record, move the current write pointer to the initial position of the next flash erase unit to point to a new flash erase unit, and execute the step of determining whether the current write pointer position of the embedded system is the initial position of the flash erase unit.
[0099] It is understandable that if the remaining storage space of the current flash erase unit can store the current log record, a second log record containing the current log data is written at the current write pointer position. If the remaining storage space of the current flash erase unit cannot store the current log record, the write pointer is moved to the initial position of the next flash erase unit, that is, the write pointer is moved to the start address of the next flash erase unit, and the step of determining whether the current write pointer position of the embedded system is the initial position of the flash erase unit is executed.
[0100] It should be noted that each time the device is powered on or restarted, even if the flash erase unit pointed to by the write pointer position saved at the last shutdown is not full, the write pointer will still be moved to the initial position of the next flash erase unit of the flash erase unit pointed to by the write pointer position saved at the last shutdown. For example, if the write pointer position saved at the last shutdown points to the second flash erase unit, even if the second flash erase unit is not full, the write pointer will be moved to the initial position of the third flash erase unit after restart or power-on.
[0101] Furthermore, in another embodiment of the log processing method of the embedded system of the present invention, the log processing method of the embedded system further includes:
[0102] Step D, when a log output instruction sent by the host computer is received, the log record file stored in the log storage space is sent to the host computer, where the log record file includes the first log record and the second log record in each of the flash erase units;
[0103] for the host computer to find the target bin file corresponding to the firmware version number according to the firmware version number in the first log record, and the host computer parses the target string in the target bin file based on the string address in the second log record.
[0104] It should be noted that the host computer refers to a computer that can directly issue control commands. The log record file contains the first log record and the second log record recorded in each flash erase unit. The host computer is connected to the processor of the embedded system through the debug serial port module. When receiving the log output instruction sent by the host computer, the log record file stored in the log storage space is sent to the host computer through the debug serial port. After receiving the log record file, the host computer parses the log records in each flash erase unit one by one. For a single flash erase unit, first, the first log record is found according to the preset log type tag, and the firmware version number is obtained from the first log record. Then, the target bin file corresponding to the firmware version number is searched. When parsing the second log record, the target string is parsed from the target bin file according to the string address in the second log record. Thus, the bin file corresponding to the firmware version number can be accurately found for parsing, and successful parsing is achieved at one time, avoiding the problems of parsing garbled codes caused by the mismatch between the version of the bin file and the log record version and the need for multiple parses, which takes a long time.
[0105] Furthermore, the present invention also proposes a log processing method for an embedded system. The log processing method for the embedded system is applied to a host computer, and the log processing method for the embedded system includes:
[0106] Step S10, obtaining the log record file stored in the log storage space of the embedded system; wherein, the log record file includes the first log record and the second log record in each flash erase unit;
[0107] It can be understood that the log record file records the first log record and the second log record recorded in multiple flash erase units. The first log record includes a log type tag field and a firmware version number field, and the second log record includes a log type tag field, a string address field, a parameter number field, and a real-time parameter value field.
[0108] Step S20, searching for the target bin file corresponding to the firmware version number in the preset bin folder according to the firmware version number in the first log record;
[0109] Step S30, parsing the target string from the target bin file according to the string address in the second log record.
[0110] It is understandable that when using the host computer tool for string parsing, first select the log record file to be parsed, and then select the preset bin folder. There are multiple bin files named after the firmware version number stored in the preset bin folder. When the host computer tool receives the start parsing instruction, it parses the log records in each flash erase unit from top to bottom. For the log records in a single flash erase unit, each log is also parsed one by one. That is, first, according to the preset type tag, find the first first log record, obtain the firmware version number from the first log record, and according to the firmware version number in the first log record, search for the target bin file corresponding to the firmware version number in the preset bin folder. Then, according to the string address in the second log record of the first item, parse out the first target string in the target bin file, and then parse the second second log record. According to the string address in the second log record of the second item, parse out the second target string in the target bin file, and continue parsing until all the second log records of the current flash erase unit are parsed, and then continue to parse the log records of the next flash erase unit.
[0111] In this embodiment, by first obtaining the firmware version number in the first log record recorded in the log record file, the target bin file can be quickly found according to the firmware version number. Then, according to the string address in the second log record recorded in the log record file, the target string is parsed out in the target bin file, so that all the strings recorded in the log record file can be parsed out at one time, avoiding the problems of parsing garbled codes caused by the mismatch between the version of the bin file and the log record version and the need for multiple parses, which takes a long time.
[0112] Furthermore, an embodiment of the present invention also proposes a device, where the device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of each embodiment of the above-mentioned log processing method for the embedded system. Among them, the device can be the carrier device of the above-mentioned log processing method for the embedded system, and the device can also be the host computer of the above-mentioned application of the log processing method for the embedded system.
[0113] In addition, an embodiment of the present invention also proposes a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, it implements the steps of each embodiment of the above-mentioned log processing method for the embedded system.
[0114] The extended content of the specific implementation manners of the device and the computer-readable storage medium of the present invention is basically the same as that of each embodiment of the above-mentioned log processing method for the embedded system, and will not be repeated here.
[0115] It should be noted that, in this text, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements not only includes those elements but also includes other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising such element.
[0116] The serial numbers of the embodiments of the present invention described above are for description only and do not represent the superiority or inferiority of the embodiments.
[0117] From the description of the above embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0118] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit of the present invention and the scope protected by the claims. All of these fall within the protection scope of the present invention.
Claims
1. A method for processing logs of an embedded system, characterized in that, the embedded system uses a flash erase unit as a log storage unit, and multiple flash erase units constitute a log storage space. The method for processing logs of the embedded system includes: judging whether the current write pointer position of the embedded system is the initial position of a flash erase unit; if it is the initial position of a flash erase unit, obtaining the current firmware version number of the embedded system; writing a first log record containing the current firmware version number at the current write pointer position; if it is not the initial position of a flash erase unit, obtaining the current log data; writing a second log record containing the current log data at the current write pointer position, where the second log record contains a string address.
2. The method for processing logs of an embedded system according to claim 1, characterized in that, before the step of writing a second log record containing the current log data at the current write pointer position includes: judging whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record; if it is sufficient to store the current log record, then execute the step of writing a second log record containing the current log data at the current write pointer position.
3. The method for processing logs of an embedded system according to claim 2, characterized in that, after the step of judging whether the remaining storage space of the current flash erase unit pointed to by the current write pointer position is sufficient to store the current log record includes: if it is not sufficient to store the current log record, then move the current write pointer to the initial position of the next flash erase unit to point to a new flash erase unit, and execute the step of judging whether the current write pointer position of the embedded system is the initial position of a flash erase unit.
4. The method for processing logs of an embedded system according to claim 1, characterized in that, the step of writing a first log record containing the current firmware version number at the current write pointer position includes: writing a log type marker field and a firmware version number field in sequence at the current write pointer position to write a first log record at the initial position of the current flash erase unit.
5. The method for processing logs of an embedded system according to claim 1, characterized in that, the step of writing a second log record containing the current log data at the current write pointer position includes: writing a log type marker field, a string address field, a parameter count field, and a real-time parameter value field at the current write pointer position to write a second log record containing the current log data at the current write pointer position.
6. The method for processing logs of an embedded system according to claim 1, characterized in that, before the step of if it is the initial position of a flash erase unit, obtaining the current firmware version number of the embedded system further includes: if it is the initial position of a flash erase unit, judging whether there is a written log record in the current flash erase unit; If there is a written log record in the current flash erasure unit, erase the written log record of the current flash erasure unit and perform the step of obtaining the current firmware version number of the embedded system.
7. The log processing method of the embedded system according to any one of claims 1 to 6, characterized in that, the log processing method of the embedded system further includes: when receiving a log output instruction sent by the host computer, send the log record file stored in the log storage space to the host computer, wherein the log record file includes the first log record and the second log record in each of the flash erasure units; for the host computer to find the target bin file corresponding to the firmware version number according to the firmware version number in the first log record, and the host computer parses out the target string in the target bin file based on the string address in the second log record.
8. A log processing method of an embedded system, characterized in that, the log processing method of the embedded system is applied to the host computer, and the log processing method of the embedded system includes: obtain the log record file stored in the log storage space in the embedded system; wherein the log record file includes the first log record and the second log record in each flash erasure unit, the first log record is written at the initial position of the flash erasure unit, and the second log record is written at other positions of the flash erasure unit; find the target bin file corresponding to the firmware version number in the preset bin folder according to the firmware version number in the first log record; parse out the target string in the target bin file according to the string address in the second log record.
9. A device, characterized in that, the device includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, and when the computer program is executed by the processor, the steps of the log processing method of the embedded system according to any one of claims 1 to 8 are implemented.
10. A computer-readable storage medium, characterized in that, a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the log processing method of the embedded system according to any one of claims 1 to 8 are implemented.
Citation Information
Patent Citations
Firmware upgrade method, firmware upgrade device and firmware upgrade system
CN108694052A
Applying custom software image updates to non-volatile storage in a failsafe manner
US20050132179A1