Log management method and system, embedded equipment, device, vehicle and medium
By using logical erasing technology in embedded devices, actual erasing is performed only when new logs are written, which solves the problems of large loss and slow speed when clearing Flash storage logs, and achieves efficient log management.
Patent Information
- Application Number
- CN202411606717.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-04-11
AI Technical Summary
In embedded devices, when clearing the logs stored in Flash, all sectors need to be erased, resulting in large losses and slow clearance.
By using the start address pointer and the write address pointer in the log storage area for logical erasing, only actual erasing is performed when writing a new log, reducing the number of erasings to Flash.
It has realized the speed up the log clearing process, reduces the number of erases and losses of Flash, and improves the efficiency of log management.
Smart Images

Figure CN119806386A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of log management, and more specifically, to a log management method, a log management system, an embedded device, an electronic apparatus, a vehicle, and a computer-readable storage medium. Background Art
[0002] In embedded devices, the most widely used persistent storage device is Flash, which has the advantages of low cost, small size for the same capacity, fast reading speed, and power-off data retention. However, when writing data to Flash, it is necessary to ensure that the level of the target area to be written is all "1". When the target write area is not all "1", it is necessary to erase the sector where the target write address is located. Since the essence of sector erasing is the process of charging the storage unit through high voltage, the Flash sector can only be erased a limited number of times.
[0003] In the related art, when clearing the logs stored in the Flash, all sectors need to be erased, which causes great loss to the Flash and slows the clearing speed. Summary of the invention
[0004] Embodiments of the present application provide a log management method, a log management system, an embedded device, an electronic apparatus, a vehicle, and a computer-readable storage medium.
[0005] The present application provides a log management method, which includes:
[0006] Determine a starting address pointer and a write address pointer according to the starting address of the log storage area in the flash memory, wherein the starting address pointer is used to indicate the starting address of the stored logs in the log storage area, and the write address pointer is used to indicate the write address of the current log in the log storage area;
[0007] Erasing the record storage area corresponding to the log storage area;
[0008] The log management is completed according to the start address pointer, the write address pointer and the erase processing result of the record storage area.
[0009] Thus, in the log management method, log management system, embedded device, electronic device, vehicle and computer-readable storage medium of the implementation mode of the present application, by pointing both the start address pointer and the write address pointer to the start address of the log storage area, and erasing the record storage area corresponding to the log storage area, so that the log storage area is in a state where there is no stored log, the log storage area is "logically erased". The log storage area is erased again when a new log is subsequently written, so there is no need to actually erase the log storage area when clearing the log storage area. Only the record storage area needs to be erased, which speeds up the log clearing process, reduces the number of erasures of the Flash, and thus reduces the loss.
[0010] In some implementations, determining the start address pointer and the write address pointer according to the start address of the log storage area in the flash memory includes:
[0011] The starting address pointer and the writing address pointer are pointed to the starting address of the log storage area.
[0012] In this way, by pointing the start address pointer and the write address pointer to the start address of the log storage area, the log storage area can be made logically empty.
[0013] In some implementations, the log management method further includes:
[0014] Performing an erasing process on the current log storage area and a writing process on the current log according to the write address pointer;
[0015] After the writing of the current log is completed, the write address pointer is pointed to the next position after the end of the current log.
[0016] In this way, the erasing process of the current log storage area and the writing process of the current log can be completed according to the write address pointer, and after the log writing is completed, the write address pointer is moved backward by the length of a log so that the subsequently written log is after the current log, realizing the sequential storage of the logs.
[0017] In some implementations, the erasing process of the current log storage area according to the write address pointer and the writing process of the current log include:
[0018] When the write address pointer points to the starting address of the current sector, erasing the current sector;
[0019] According to the write address pointer, write the current log into the current sector after erasure; or,
[0020] In the case that the write address pointer points to a non-starting address of the current sector, the current log is written into the current sector according to the write address pointer.
[0021] In this way, the current sector is erased only when the write address pointer points to the starting address of the current sector. There is no need to erase the current sector when writing each log, which can reduce the number of times the current sector is erased, thereby reducing the loss of Flash.
[0022] In some implementations, the starting address of the stored log is the starting address of the current sector, and when the write address pointer points to the starting address of the current sector, erasing the current sector includes:
[0023] When the address pointed to by the acquisition start address pointer is the same as the address pointed to by the write address pointer, erasing the current sector;
[0024] The start address pointer points to the start address of the next sector.
[0025] In this case, when the address pointed by the start address pointer is the same as the address pointed by the write address pointer, the current log storage area is full and needs to be erased before a new log can be written. Since the previously written historical log is erased at this time, after erasing the current sector, the start address pointer is pointed to the next sector of the current sector to update the start address of the stored log. By eliminating the oldest historical log, valuable logs are retained to the greatest extent.
[0026] In some implementations, the step of pointing the start address pointer to the start address of the next sector includes:
[0027] In the case that the current sector is the last sector of the current log storage area, the start address pointer is pointed to the initial address of the initial sector of the current log storage area.
[0028] In this way, when the current sector is the last sector of the current log storage area, the start address pointer is executed as the start address of the current log storage area, so that circular storage can be further realized.
[0029] In some implementations, the step of pointing the write address pointer to a position after the end of the current log includes:
[0030] When there is no free storage space in the current log storage area, the write address pointer is pointed to the start address of the current log storage area.
[0031] In this way, when the current log storage area is full, the write address pointer is pointed to the start address of the current log storage area to achieve circular storage in the current log storage area.
[0032] In some implementations, after the current log is written, the log management method further includes:
[0033] Obtaining a write record address pointer, wherein the write record address pointer is used to indicate a write address of a current log record when it is written into a record storage area of the flash memory;
[0034] Writing the current log record of the current log into the record storage area according to the address pointed to by the record address pointer, wherein the current log record includes the starting address of the stored log and the ending address of the current log;
[0035] The write record address pointer is pointed to the position after the end of the current log record.
[0036] In this way, the log record is synchronously written into the record storage area according to the write record address, so that the storage status in the corresponding log storage area can be obtained by reading the log record in the record storage area.
[0037] In some implementations, the step of pointing the write record address pointer to a position after the end of the current log record includes:
[0038] When the end of the current log record is the end storage space of the record storage area, erasing the record storage area;
[0039] The write record address pointer points to the starting address of the record storage area.
[0040] In this way, when the record storage area is full, the record storage area is erased, and the write record address pointer is pointed to the start address of the record storage area to provide storage space for subsequent log records to be written.
[0041] In some implementations, the log management method further includes:
[0042] In the case where the log record exists, determining the end address of the log record, the start address and the end address of the stored log according to the last log record;
[0043] Assigning a value to the write record address pointer according to the end address of the log record;
[0044] According to the starting address of the stored log, assign a value to the starting address pointer;
[0045] The write address pointer is assigned a value according to the end address of the stored log.
[0046] In this way, the start address pointer, the write address pointer, and the write record address pointer can be reinitialized according to the last log record.
[0047] In some implementations, the log management method further includes:
[0048] Writing current log status information into the information storage area of the flash memory, wherein the current log status information includes initialization time and log metadata;
[0049] Point the write address pointer and the start address pointer to the start address of the initial sector of the current log storage area;
[0050] The write record address pointer points to the initial address of the record storage area.
[0051] In this way, by writing the current log status information into the information storage area of the flash memory and assigning values to the write address pointer, the start address pointer and the write record address pointer, the initialization of the flash memory can be completed.
[0052] In some implementations, writing the current log status information into the information storage area of the flash memory includes:
[0053] When the log status information stored in the information storage area is different from the current log status information, erasing the information storage area;
[0054] The current log status information is written into the information storage area of the flash memory.
[0055] In this way, by erasing the information storage area when the log status information is different from the current log status information, and writing the current log status information into the information storage area of the flash memory, the flash memory can be re-initialized.
[0056] In some implementations, all logs in the same log storage area have the same log length, and the log management method further includes:
[0057] The read address of the target log is determined according to the start address pointer, the target log offset value, and the log length corresponding to the target log storage area where the target log is located.
[0058] In this way, the read address of the target log can be obtained according to the starting address pointer, the target log offset value and the log length, without traversing the log storage area, which greatly reduces the time for reading the log.
[0059] In some implementations, all logs in the same log storage area have the same log length, and the log management method further includes:
[0060] The number of logs stored in the target log storage area is determined according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area.
[0061] In this way, according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area, the number of logs stored in the target log storage area can be quickly determined without traversing all the logs, thus reducing the time for calculating the total number of logs.
[0062] The embodiment of the present application provides a log management system, the log management system includes a flash memory, a RAM and a controller; the flash memory includes at least one log storage area and a corresponding record storage area, the log storage area includes a plurality of sectors; the RAM is configured to store a start address pointer and a write address pointer, the start address pointer is used to indicate the start address of the stored log in the log storage area, the write address pointer is used to indicate the write address of the current log written in the log storage area; the controller is configured to:
[0063] Determine the starting address pointer and the writing address pointer according to the starting address of the log storage area in the flash memory;
[0064] Erasing the record storage area corresponding to the log storage area;
[0065] The log management is completed according to the start address pointer, the write address pointer and the erase processing result of the record storage area.
[0066] In some implementations, the RAM further includes a write record address pointer, which is used to indicate a write address of a current log record when it is written into a record storage area of the flash memory.
[0067] In some embodiments, the flash memory also includes an information storage area, which is used to store log status information, and the log status information includes initialization time, a starting address and an ending address of the record storage area, and a starting address and an ending address of the log storage area.
[0068] An embodiment of the present application provides an embedded device, wherein the embedded device includes a log management system as described in any of the above embodiments.
[0069] An embodiment of the present application provides an electronic device, which includes one or more processors and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the method in any of the above embodiments are implemented.
[0070] An embodiment of the present application provides a vehicle, which includes a log management system as described in any of the above embodiments, or an embedded device as described in the above embodiments, or an electronic device as described in the above embodiments.
[0071] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the steps of the method in any of the above embodiments are implemented.
[0072] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] The above and / or additional aspects and advantages of the present application will become apparent and easily understood from the description of the embodiments in conjunction with the following drawings, in which:
[0074] Figure 1 It is a flowchart of a log management method of certain implementation modes of the present application;
[0075] Figure 2 is a schematic diagram of a flash memory of a log management system according to certain embodiments of the present application;
[0076] Figure 3 It is a schematic diagram of clearing logs in certain implementation modes of the present application;
[0077] Figure 4 is a schematic diagram of a log management system of certain implementation modes of the present application;
[0078] Figure 5 It is a flowchart of a log management method of certain implementation modes of the present application;
[0079] Figure 6 It is a flowchart of a log management method of certain implementation modes of the present application;
[0080] Figure 7 is a schematic diagram of an erase process and a write log in certain embodiments of the present application;
[0081] Figure 8 It is a flowchart of a log management method of certain implementation modes of the present application;
[0082] Fig. 9 is a schematic diagram of writing a log in certain embodiments of the present application;
[0083] Fig.10 It is a flowchart of a log management method of certain implementation modes of the present application;
[0084] Fig.11 It is a flowchart of a log management method of certain implementation modes of the present application;
[0085] Fig.12 It is a flowchart of a log management method of certain implementation modes of the present application;
[0086] Fig.13 It is a flowchart of a log management method of certain implementation modes of the present application;
[0087] Fig.14 It is a flowchart of a log management method of certain implementation modes of the present application;
[0088] Fig.15 It is a flowchart of a log management method of certain implementation modes of the present application;
[0089] Fig.16 is a schematic diagram of erasing a record storage area and writing a log record in certain embodiments of the present application;
[0090] Fig.17 It is a flowchart of a log management method of certain implementation modes of the present application;
[0091] Fig.18 It is a flowchart of a log management method of certain implementation modes of the present application;
[0092] Fig.19 is a schematic diagram of a flash memory after initial initialization in certain embodiments of the present application;
[0093] Fig. 20 It is a flowchart of a log management method of certain implementation modes of the present application;
[0094] Fig.21 It is a flowchart of a log management method of certain implementation modes of the present application;
[0095] Fig. 22 is a schematic diagram of a log storage area in certain embodiments of the present application;
[0096] Fig.23 is a schematic diagram of a log storage area in certain embodiments of the present application;
[0097] Fig.24 It is a flowchart of a log storage method of certain implementation modes of the present application;
[0098] Fig.25It is a schematic diagram of a log management method of certain implementation modes of the present application. DETAILED DESCRIPTION
[0099] The embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements with the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be understood as limiting the present application.
[0100] In embedded devices, the most widely used persistent storage device is Flash, which has the advantages of low cost, small size for the same capacity, fast reading speed, and power-off data retention. However, when writing data to Flash, it is necessary to ensure that the level of the target area to be written is all "1". When the target write area is not all "1", it is necessary to erase the sector where the target write address is located. Since the essence of sector erasing is the process of charging the storage unit through high voltage, the Flash sector can only be erased a limited number of times.
[0101] In the related art, when clearing the logs stored in the Flash, all sectors need to be erased, which causes great loss to the Flash and slows the clearing speed.
[0102] Based on the above unresolved issues, please refer to Figures 1 to 3 The present application embodiment provides a log management method, the log management method comprising:
[0103] 01: According to the starting address of the log storage area 10 in the flash memory 100, a starting address pointer and a write address pointer are determined. The starting address pointer is used to indicate the starting address of the stored log in the log storage area 10, and the write address pointer is used to indicate the write address of the current log in the log storage area 10;
[0104] 02: Erase the record storage area 30 corresponding to the log storage area 10;
[0105] 03: Complete log management based on the start address pointer, the write address pointer and the erase processing result of the record storage area 30.
[0106] The embodiment of the present application provides an electronic device, which includes one or more processors and a memory, wherein the memory stores a computer program, and the computer program can be executed by the processor. The processor can be used to determine a starting address pointer and a write address pointer according to the starting address of the log storage area 10 in the flash memory 100; perform an erase process on the record storage area 30 corresponding to the log storage area 10; and complete log management according to the erase process results of the starting address pointer, the write address pointer and the record storage area 30.
[0107] The embodiment of the present application provides a log management device, which includes a first determination module, a first processing module and a management module. The first determination module can be used to determine the starting address pointer and the write address pointer according to the starting address of the log storage area 10 in the flash memory 100; the first processing module can be used to erase the record storage area 30 corresponding to the log storage area 10; the management module can be used to complete the log management according to the starting address pointer, the write address pointer and the erase processing result of the record storage area 30.
[0108] See also Figure 4 The embodiment of the present application provides a log management system 1000, which includes a flash memory 100, a RAM and a controller 300; the flash memory 100 includes at least one log storage area 10 and a corresponding record storage area 30; the RAM is configured to store a start address pointer and a write address pointer, the start address pointer is used to indicate the start address of the stored log in the log storage area 10, and the write address pointer is used to indicate the write address of the current log written in the log storage area 10; the controller 300 is configured to: determine the start address pointer and the write address pointer according to the start address of the log storage area 10 in the flash memory 100; erase the record storage area 30 corresponding to the log storage area 10; and complete the log management according to the erase processing results of the start address pointer, the write address pointer and the record storage area 30.
[0109] Specifically, the flash memory 100 (Flash) is a non-volatile memory that is erased in sectors, and is programmable and can save data when the power is off. The random access memory (Random Access Memory, RAM) is a volatile memory with fast read and write speeds, can be randomly read and written, and can directly exchange data with the CPU. In the implementation of the present application, a limited number of variables are maintained in the RAM, so that when performing log management, the address recorded in the RAM can be directly operated, without the need to cyclically read the data in the Flash and then judge the validity of the data in the traditional way. The log reading and writing speed is significantly improved, and the implementation method is simple. Among them, the starting address pointer, write address pointer and write record address pointer are stored in the RAM space, and these pointers usually only need to occupy tens of bytes, and the additional resources are less.
[0110] Among them, see Figure 4 , the controller 300 includes an erase controller, a loop write controller, a read controller and a Flash difference controller. The erase controller is used to erase the Flash. The loop write controller is used to write the Flash. The read controller is used to read the Flash. The Flash difference controller is used to adapt different Flashes to perform log management. In addition, the log management system also includes a read-write address verifier, which is used to verify the read address or write address of the log.
[0111] The flash memory 100 is divided into a plurality of storage areas, including a log storage area 10, a record storage area 30, and an information storage area 50. The information storage area 50 is used to store log status information, such as log write time, the first and last addresses of the log storage area 10, the first and last addresses of the record storage area 30, etc. The log storage area 10 is used to store logs, and the log storage area 10 includes a plurality of sectors 11. The record storage area 30 is used to store the write records of the log, for example, the last address after the log is written.
[0112] Furthermore, the record storage area 30 and the log storage area 10 correspond one to one, and the log records stored in the record storage area 30 are log records corresponding to the logs stored in the log storage area 10 .
[0113] The start address pointer and the write address pointer are stored in the RAM so that the start address pointer and the write address pointer can be read and written at any time. The start address pointer is used to store the start address of the stored log in the log storage area 10 in the Flash, and the write address pointer is used to indicate the write address of the current log that needs to be written into the log storage area 10 at the time of writing.
[0114] In the related art, when clearing the log stored in the Flash, it is necessary to erase the sector 11 in the Flash where the log is stored. When writing next time, to ensure that there are no other stored logs in the area to be written in the sector 11, it is necessary to erase the sector 11 again. Therefore, it is necessary to erase the Flash twice to complete the process of clearing the logs until the next writing.
[0115] In the implementation mode of the present application, since the start address pointer indicates the start address of the stored log, and the write address pointer is the write address of the log to be written, when the address pointed to by the start address pointer is the same as the address pointed to by the write address pointer, it means that there is no stored log in the current log storage area, and after the current log to be written is written, the current log is the first stored log. In other words, when the address pointed to by the start address pointer is the same as the address pointed to by the write address pointer, the current log storage area is logically empty.
[0116] In addition, the record storage area 30 stores the write records of the stored logs in the log storage area 10. When the record storage area 30 is empty, it can be regarded as that there are no stored logs in the log storage area 10. Then, by erasing the storage in the record storage area 30, the current log storage area can be made logically empty.
[0117] Therefore, according to the starting address of the current storage area, the starting address pointer and the write address pointer are determined, and the record storage area 30 corresponding to the log storage area 10 is erased, so that the current log storage area can be logically empty, that is, the "logical erasure" of the log storage area 10 is realized. After the "logical erasure", the logs originally stored in the log storage area 10 become dirty logs, waiting to be erased when a new log is written later.
[0118] It should be noted that the implementation of the present application only logically makes the log storage area 10 empty, rather than actually erasing the log storage area 10. The actual erasure is performed when a new log is subsequently written, so the log management method of the implementation of the present application only needs to erase the record storage area 30 when clearing the log storage area 10, reducing the number of erasures of the Flash.
[0119] Furthermore, the storage space occupied by the record storage area 30 is smaller than the storage space occupied by the log storage area 10. Only the record storage area 30 is erased instead of the log storage area 10, which can reduce the time used for the erasing process. In other words, when clearing, only the pointer needs to be moved and the content of the record storage area 30 needs to be erased, which speeds up the log clearing process. Since no additional space is required to store the process variables in the operation during the clearing operation or erasing process, the space complexity of the clearing operation or erasing process is O(1) and the time complexity is O(1).
[0120] Thus, in the log management method of the embodiment of the present application, by pointing both the start address pointer and the write address pointer to the start address of the log storage area 10, and erasing the record storage area 30 corresponding to the log storage area 10, so that the log storage area 10 is in a state where there is no stored log, the log storage area 10 is "logically erased". When a new log is subsequently written, the log storage area 10 is erased again, so that there is no need to actually erase the log storage area 10 when clearing the log storage area 10, and only the record storage area 30 needs to be erased, which speeds up the log clearing process, reduces the number of erasures to the Flash, and thus reduces the loss.
[0121] See also Figure 3 and Figure 5 In some implementations, step 01, according to the starting address of the log storage area 10 in the flash memory 100, determines the starting address pointer and the writing address pointer, including:
[0122] 0101: Set the start address pointer and write address pointer to point to the start address of log storage area 10.
[0123] In some implementations, the processor may be configured to point the start address pointer and the write address pointer to the start address of the log storage area 10 .
[0124] In some embodiments, the first determination module includes a first movement submodule, and the first movement submodule can be used to point the start address pointer and the write address pointer to the start address of the log storage area 10.
[0125] Specifically, the start address pointer and the write address pointer are both pointed to the start address of the log storage area 10, so that the addresses pointed to by the start address pointer and the write address pointer are the same, so that the log storage area 10 is logically empty.
[0126] Furthermore, since the write address pointer points to the starting address of the log storage area 10, when writing the current log, it is written to the starting address of the log storage area 10, and the current log is the first log in the log storage area 10. In addition, before writing the current log, the first sector 11 of the log storage area 10 is erased to ensure that there is no other storage content in the first sector 11.
[0127] By pointing the start address pointer and the write address pointer to the start address of the log storage area 10, the "existence state" of the log is erased, and there is no need to erase the sector 11 where the log is located, thereby avoiding concentrated erasing operations on a large number of sectors 11. A single sector 11 is only erased when the log is actually written and when necessary, reducing the loss of Flash.
[0128] In this way, by pointing the start address pointer and the write address pointer to the start address of the log storage area 10, the log storage area 10 can be made logically empty.
[0129] See also Figure 6 and Figure 7 In some implementations, the log management method further includes:
[0130] 04: According to the write address pointer, the current log storage area is erased and the current log is written;
[0131] 05: After completing the writing of the current log, the write address pointer points to the position after the end of the current log.
[0132] In some embodiments, the processor may be used to erase the current log storage area and write the current log according to the write address pointer; and to point the write address pointer to the next position after the end of the current log after completing the writing of the current log.
[0133] In some embodiments, the log management device further includes a second processing module and a first moving module. The second processing module can be used to erase the current log storage area and write the current log according to the write address pointer; the first moving module can be used to point the write address pointer to the next position after the end of the current log after completing the writing of the current log.
[0134] Specifically, when storing the current log, the current log storage area is erased according to the write address pointer to ensure that no other content is stored in the corresponding storage space when the current log is written. The current log is written to the corresponding write address to complete the writing of the current log.
[0135] After the current log is written, the write address pointer is pointed to the position after the end of the current log as the write address for the next log, thereby realizing sequential writing to the current log storage area.
[0136] It should be noted that before each current log is written, erasure processing can be performed according to the write address pointer, or it can be determined whether erasure processing is required according to the address pointed to by the write address pointer, and then erasure processing is performed when it is determined that erasure processing is required.
[0137] In this way, the erasing process of the current log storage area and the writing process of the current log can be completed according to the write address pointer, and after the log writing is completed, the write address pointer is moved backward by the length of a log so that the subsequently written log is after the current log, realizing the sequential storage of the logs.
[0138] See also Figure 8 and Fig. 9 In some implementations, step 05, pointing the write address pointer to a position after the end of the current log, includes:
[0139] 051: When there is no free storage space in the current log storage area, the write address pointer points to the starting address of the current log storage area.
[0140] In some implementations, the processor may be configured to point the write address pointer to the start address of the current log storage area when there is no free storage space in the current log storage area.
[0141] In some embodiments, the first moving module includes a second moving submodule, which can be used to point the write address pointer to the starting address of the current log storage area when there is no free storage space in the current log storage area.
[0142] Specifically, the free storage space refers to the storage space in the current log storage area that is still allowed to write logs. When there is no free storage space in the current log storage area, the current log storage area is full. At this time, the write address points to the starting address of the current log area, that is, when the next log is written, it is written to the starting address of the current log storage area to achieve circular writing.
[0143] In this way, when the current log storage area is full, the write address pointer is pointed to the start address of the current log storage area to achieve circular storage in the current log storage area.
[0144] See also Figure 7 , Figures 9 to 11In some implementations, step 04, erasing the current log storage area according to the write address pointer, and writing the current log, includes:
[0145] 041: When the write address pointer points to the start address of the current sector 111, the current sector 111 is erased;
[0146] 042: Write the current log to the erased current sector 111 according to the write address pointer; or,
[0147] 043: When the write address pointer points to a non-starting address of the current sector 111, the current log is written to the current sector 111 according to the write address pointer.
[0148] In some embodiments, the processor can be used to erase the current sector 111 when the write address pointer points to the starting address of the current sector 111; and to write the current log to the erased current sector 111 according to the write address pointer; and can also be used to write the current log to the current sector 111 according to the write address pointer when the write address pointer points to a non-starting address of the current sector 111.
[0149] In some embodiments, the second processing module further includes a first processing submodule, a first writing submodule, and a second writing submodule. The first processing submodule may be used to erase the current sector 111 when the write address pointer points to the starting address of the current sector 111; the first writing submodule may be used to write the current log to the erased current sector 111 according to the write address pointer; and the second writing submodule may be used to write the current log to the current sector 111 according to the write address pointer when the write address pointer points to a non-starting address of the current sector 111.
[0150] Specifically, the log storage area 10 includes a plurality of sectors 11 arranged in series, wherein the current sector 111 is the sector 11 pointed to by the write address pointer.
[0151] When deleting a single log, the entire sector actually needs to be erased. In addition, the default behavior of deleting a single log is to restore other logs in the sector, so it is necessary to read the log, erase the sector, and write the log, which consumes a lot of time.
[0152] In the implementation manner of the present application, the current sector 111 is erased only when the write address pointer points to the start address of the current sector 111. When the write address pointer points to other addresses of the current sector 111, the current sector 111 is not erased.
[0153] That is to say, when the current log is the first log of the current sector 111 after writing, the entire current sector 111 needs to be erased before writing to ensure that the current sector 111 can write the log, and then write the current log after erasing. When the current log is not the first log of the current sector 111 after writing, there is no need to erase it, and the current log can be written directly.
[0154] Since the entire current sector 111 has been erased in the first log, and the log writing is written in chronological order, when the subsequent log is written to the current sector 111, there is no other storage content at the address pointed to by the write address pointer, and no further erasure is required. Therefore, when the current sector 111 is not the first log written, there is no need to erase the current sector 111, and the current log can be written directly. The implementation method of the present application realizes "lazy erasure", that is, in each cycle of the cyclic writing, each sector only needs to be erased once when it is first written, so that multiple sequential write operations in the same sector later do not need to be checked for writability, avoiding the time delay caused by the pre-write check.
[0155] In addition, since the log storage area 10 is stored cyclically, each sector 11 is erased once in each cycle, ensuring that the number of erasures of each sector 11 in the log storage area 10 of each Flash is substantially the same during the life cycle of the log management system, thereby achieving wear leveling of the Flash and avoiding erasing only a single sector 11 once, resulting in damage after multiple erasures that affects the use of the entire Flash.
[0156] Furthermore, since no additional space is required to store the process variables in the operation during the write operation, the space complexity of the write log operation is O(1). The time complexity of the write operation is O(1).
[0157] In this way, the current sector 111 is erased only when the write address pointer points to the start address of the current sector 111. The current sector 111 does not need to be erased when each log is written, which can reduce the number of erasures of the current sector 111 and thus reduce the loss of the Flash.
[0158] See also Fig. 9 and Fig.12 In some implementations, the starting address of the stored log is the starting address of the current sector 111. Step 041, when the write address pointer points to the starting address of the current sector 111, the current sector 111 is erased, including:
[0159] 0411: When the address pointed by the start address pointer is the same as the address pointed by the write address pointer, the current sector 111 is erased;
[0160] 0412: Set the start address pointer to the start address of the next sector.
[0161] In some embodiments, the processor may be configured to erase the current sector 111 when the address pointed to by the start address pointer is the same as the address pointed to by the write address pointer; and to point the start address pointer to the start address of the next sector.
[0162] In some embodiments, the first processing submodule includes an erasing unit and a moving unit. The erasing unit can be used to erase the current sector 111 when the address pointed by the start address pointer is the same as the address pointed by the write address pointer; the moving unit can be used to point the start address pointer to the start address of the next sector.
[0163] Specifically, the starting address of the stored log is the starting address of the current sector 111 , that is, the stored log is written sequentially starting from the starting address of the current sector 111 , and the address pointed to by the starting address pointer is the starting address of the current sector 111 .
[0164] Since the log writing mode of the log storage area 10 is cyclic writing, when the current log storage area is full, the write address pointer will point to the starting address of the current log storage area, and the address pointed to by the starting address pointer will overlap.
[0165] Therefore, when the address pointed by the start address pointer is the same as the address pointed by the write address pointer, it means that the current log storage area is full and there is no storage space for subsequent logs to be written, so erasing is required to provide storage space for other logs.
[0166] When the current log storage area is full, the log stored in the current sector 111 pointed to by the start address pointer is the earliest written log and has a lower value. Therefore, the entire current sector 111 can be erased to clear the log in the current sector 111, eliminate historical logs, and provide storage space for subsequent logs to be written.
[0167] Further, after erasing the current sector 111, the starting address of the stored log becomes the starting address of the next sector, so the starting address pointer now points to the starting address of the next sector.
[0168] In one embodiment, the start address pointer firstLogAddr and the write address pointer nextLogWriteAddr both point to the start address of the first sector 11, and the first sector 11 is erased. After erasing, the start address pointer firstLogAddr is pointed to the start address of the second sector 11, and the current log is written to the start address of the first sector 11. After the writing of the current log is completed, the write address pointer nextLogWriteAddr is moved backward by the length of a log, that is, the write address pointer nextLogWriteAddr is pointed to the position after the end of the current log.
[0169] In this way, when the address pointed by the start address pointer is the same as the address pointed by the write address pointer, the current log storage area is full and needs to be erased before a new log can be written. Since the previously written historical log is erased at this time, after erasing the current sector 111, the start address pointer is pointed to the next sector of the current sector 111 to update the start address of the stored log. By eliminating the oldest historical log, valuable logs are retained to the greatest extent.
[0170] See also Fig. 9 and Fig.13 In some implementations, step 0412, pointing the start address pointer to the start address of the next sector, includes:
[0171] 04121: When the current sector 111 is the last sector 11 of the current log storage area, the start address pointer is pointed to the initial address of the initial sector 11 of the current log storage area.
[0172] In some implementations, the processor may be configured to point the start address pointer to the initial address of the initial sector 11 of the current log storage area when the current sector 111 is the last sector 11 of the current log storage area.
[0173] In some embodiments, the moving unit includes a moving subunit. The moving subunit can be used to point the start address pointer to the initial address of the initial sector 11 of the current log storage area when the current sector 111 is the last sector 11 of the current log storage area.
[0174] Specifically, when current sector 111 is the end sector 11 of current log storage area, because log is cyclic storage in current log storage area, then after current sector 111 is erased, the starting address of stored log is the starting address of current log storage area. Therefore, the starting address pointer is pointed to the starting address of current log storage area, to further realize the cyclic storage of log. It should be noted that the end sector 11 herein refers to the last sector 11 of current log storage area.
[0175] In this way, when the current sector 111 is the last sector 11 of the current log storage area, the start address pointer is executed as the start address of the current log storage area, so that circular storage can be further realized.
[0176] See also Figure 7 , Fig. 9 and Fig.14 In some implementations, the log management method further includes:
[0177] 06: Get a write record address pointer, which is used to indicate the write address of the current log record when it is written into the record storage area 30 of the flash memory 100;
[0178] 07: write the current log record of the current log into the record storage area 30 according to the address pointed to by the record address pointer, where the current log record includes the starting address of the stored log and the end address of the current log;
[0179] 08: Set the write record address pointer to the position after the end of the current log record.
[0180] In some embodiments, the processor can be used to obtain a write record address pointer; and to write the current log record of the current log into the record storage area 30 according to the address pointed to by the record address pointer; and to point the write record address pointer to the next position after the end of the current log record.
[0181] In some embodiments, the log management device further includes an acquisition module, a first writing module, and a second moving module. The acquisition module can be used to acquire a write record address pointer; the first writing module can be used to write the current log record of the current log into the record storage area 30 according to the address pointed to by the record address pointer; and the second moving module can be used to point the write record address pointer to the next position after the end of the current log record.
[0182] In some embodiments, the RAM further includes a write record address pointer, which is used to indicate a write address of the current log record when it is written into the record storage area 30 of the flash memory 100 .
[0183] Specifically, the log storage area 30 stores the log records when the logs of the corresponding log storage area 10 are written, and the log records include the starting address of the stored logs after the current log is written, and the end address of the current log. The distribution of the stored logs can be determined according to the log records, so that the historical logs can be quickly restored after startup or abnormal restart.
[0184] The write record address pointer is used to indicate the write address of the current log record when writing into the record storage area 30. When writing the log record, writing is performed according to the address pointed to by the write record address pointer.
[0185] The current log record corresponding to the current log is written into the record storage area 30 according to the address pointed to by the write record address pointer, so as to store the current log record in the record storage area 30. By reading the log record in the record storage area 30, the log storage status of the corresponding log storage area 10 can be obtained.
[0186] After the log record is written, the write record address pointer is pointed to the position after the end of the current log record, so that the next log record written is after the current log record, thereby realizing the sequential writing of log records.
[0187] In this way, the log record is synchronously written into the log storage area 30 according to the write record address, so that the storage status in the corresponding log storage area 10 can be obtained by reading the log record in the log storage area 30 .
[0188] See also Fig.15 and Fig.16 In some implementations, step 08, pointing the write record address pointer to a position after the end of the current log record, includes:
[0189] 081: When the end of the current log record is the last storage space of the record storage area 30, the record storage area 30 is erased;
[0190] 082: Point the write record address pointer to the starting address of the record storage area 30.
[0191] In some embodiments, the processor may be configured to erase the record storage area 30 when the end of the current log record is the end storage space of the record storage area 30 ; and to point the write record address pointer to the starting address of the record storage area 30 .
[0192] In some embodiments, the second moving module includes a first erasing submodule and a third moving submodule. The first erasing submodule can be used to erase the record storage area 30 when the end of the current log record is the end storage space of the record storage area 30; the third moving submodule can be used to point the write record address pointer to the starting address of the record storage area 30.
[0193] Specifically, the end storage space is the last storage space of the storage area. When the end of the current log record is the end storage space of the record storage area 30, the record storage area 30 is full.
[0194] Since each log record stored in the record storage area 30 includes the starting address of the stored log and the ending address of the corresponding log, only the last log record is needed to determine the beginning and ending addresses of all logs. Therefore, when the record storage area 30 is full, the previously stored log record is eliminated, and the beginning and ending addresses of the stored log can be obtained after writing a new log record.
[0195] When the record storage area 30 is full, in order to allow the log record of the next log to be written into the record storage space, the record storage area 30 is erased to clear the record storage area 30. The write record address pointer points to the starting address of the record storage area 30, so that the log record of the next log can be written into the starting address of the record storage area 30 as the first log record stored.
[0196] In one embodiment, the end of the current log record is the end storage space of the current record storage area, and the current record storage area is erased to restore the current record storage area. The write record address pointer nextRecWriteAddr points to the start address of the record storage area 30, and when writing the next log record, it is written to the start address of the record storage area 30. After completing the writing of the new log record, the write record address pointer nextRecWriteAddr points to the next position after the end of the log record.
[0197] In this way, when the record storage area 30 is full, the record storage area 30 is erased, and the write record address pointer is pointed to the start address of the record storage area 30 to provide storage space for subsequent log records to be written.
[0198] See also Fig.17 In some implementations, the log management method further includes:
[0199] 09: If there are log records, determine the end address of the log record, the start address and the end address of the stored logs according to the last log record;
[0200] 010: Assign a value to the write record address pointer according to the end address of the log record;
[0201] 011: Assign a value to the starting address pointer according to the starting address of the stored log;
[0202] 012: Assign a value to the write address pointer according to the end address of the stored log.
[0203] In some embodiments, the processor may be used to determine the end address of the log record, the start address and the end address of the stored log based on the last log record when a log record exists; and to assign a value to a write record address pointer based on the end address of the log record; and to assign a value to a start address pointer based on the start address of the stored log; and to assign a value to a write address pointer based on the end address of the stored log.
[0204] In some embodiments, the log management device further includes a second determination module, a first assignment module, a second assignment module, and a third assignment module. The second determination module can be used to determine the end address of the log record, the start address and the end address of the stored log according to the last log record when there is a log record; the first assignment module can be used to assign a value to the write record address pointer according to the end address of the log record; the second assignment module can be used to assign a value to the start address pointer according to the start address of the stored log; and the third assignment module can be used to assign a value to the write address pointer according to the end address of the stored log.
[0205] Specifically, when the log system has completed the initial initialization and the Flash layout has not changed, it needs to be re-initialized each time the Flash is powered on or the software is reset to restore the historical data. During initialization, the start address pointer, write address pointer, and write record address pointer are assigned values so that the write position can be determined when the log is written and the log record is written.
[0206] During re-initialization, if there are log records in the log storage area 30 , the last log record is retrieved to obtain the head and tail addresses of the logs stored in the log storage area 10 and the end address of the last log record.
[0207] The next position of the end address of the log record is assigned to the write record address pointer, the start address of the stored log is assigned to the start address pointer, and then the next position of the end address of the stored log is assigned to the write address pointer to complete the reinitialization of the Flash.
[0208] In addition, when reinitializing, if there is no log record in the record storage area 30, the starting address of the log record area is assigned to the write address pointer and the starting address pointer, and then the starting address of the record storage area 30 is assigned to the write address pointer, just like the initial initialization.
[0209] In this way, the start address pointer, the write address pointer, and the write record address pointer can be reinitialized according to the last log record.
[0210] See also Fig.18 and Fig.19 In some implementations, the log management method further includes:
[0211] 013: Write the current log status information into the information storage area 50 of the flash memory 100, where the current log status information includes the initialization time and log metadata;
[0212] 014: point both the write address pointer and the start address pointer to the start address of the initial sector 11 of the current log storage area;
[0213] 015: Point the write record address pointer to the initial address of the record storage area 30.
[0214] In some embodiments, the processor can be used to write current log status information into the information storage area 50 of the flash memory 100, the current log status information including the initialization time and log metadata; and to point both the write address pointer and the start address pointer to the start address of the initial sector 11 of the current log storage area; and to point the write record address pointer to the initial address of the record storage area 30.
[0215] In some embodiments, the log management device includes a second writing module, a third moving module, and a fourth moving module. Among them, the second writing module can be used to write the current log status information into the information storage area 50 of the flash memory 100, and the current log status information includes the initialization time and log metadata; the third moving module can be used to point both the write address pointer and the start address pointer to the start address of the initial sector 11 of the current log storage area; the fourth moving module can be used to point the write record address pointer to the initial address of the record storage area 30.
[0216] In some embodiments, the flash memory 100 also includes an information storage area 50, which is used to store log status information, including initialization time, the starting address and ending address of the record storage area 30, and the starting address and ending address of the log storage area 10.
[0217] Specifically, when Flash is initialized for the first time, the current log status information needs to be written into the information storage area 50 of Flash. The log status information includes the initialization time (inifTime), log metadata (logMateData), and information checksum (checkSum). Among them, the log metadata includes the first address (logDataAddrStart) of each log storage area 10, the tail address (logDataAddrEnd) of each log storage area 10, the first address (writeRecAddrStart) and the tail address (writeRecAddreEnd) of the corresponding record storage area 30, and the log length (logSize) stored therein.
[0218] Since it can be regarded that no log is stored in the Flash during the initialization, the write address pointer and the start address pointer are both pointed to the start address of the initial sector 11 of the current log storage area, and the write record address pointer is pointed to the initial address of the record storage area 30, to indicate that the current log storage area is empty. After the current log is written, the current log is the first log in the current log storage area, and the log record corresponding to the current log is the first log record in the current record storage area.
[0219] By increasing or decreasing the log metadata and the first and last storage address arrays recorded in the information storage area, the number of log types managed by the log management system can be controlled, which brings strong scalability to the system and improves the system's compatibility with different Flash storage chips.
[0220] In addition, the space complexity of initializing Flash is O(1) and the time complexity is O(logm), where m is the number of log records.
[0221] In this way, by writing the current log status information into the information storage area 50 of the flash memory 100 and assigning values to the write address pointer, the start address pointer and the write record address pointer, the initialization of the flash memory 100 can be completed.
[0222] See also Fig. 20 In some implementations, step 013, writing the current log status information into the information storage area 50 of the flash memory 100, includes:
[0223] 0131: when the log status information stored in the information storage area 50 is different from the current log status information, the information storage area 50 is erased;
[0224] 0132: Write the current log status information into the information storage area 50 of the flash memory 100.
[0225] In some embodiments, the processor may be configured to erase the information storage area 50 when the log status information stored in the information storage area 50 is different from the current log status information; and to write the current log status information into the information storage area 50 of the flash memory 100 .
[0226] In some embodiments, the second writing module includes a second erasing submodule and a writing submodule. The second erasing submodule can be used to erase the information storage area 50 when the log status information stored in the information storage area 50 is different from the current log status information; the writing submodule can be used to write the current log status information into the information storage area 50 of the flash memory 100.
[0227] Specifically, when the initialization is completed, if the current log status information specified is different from the log status information stored in the information storage area 50 during the re-initialization call, and the status information previously stored in the information storage area 50 needs to be cleared, the information storage area 50 is erased to clear the information storage area 50. After erasing, the current log status information is written into the information storage area 50 to complete the re-initialization of the log status information in the information storage area 50.
[0228] After rewriting the log status information, the write address pointer and the start address pointer are both pointed to the start address of the initial sector 11 of the current log storage area, and the write record address pointer is pointed to the initial address of the record storage area 30 to complete this initialization. It can be considered that this initialization process is essentially "the initial initialization that did not occur in the first time".
[0229] In this way, by erasing the information storage area 50 when the log status information is different from the current log status information and writing the current log status information into the information storage area 50 of the flash memory 100 , the flash memory 100 can be re-initialized.
[0230] See also Figure 21 to Figure 23 In some implementations, all logs in the same log storage area 10 have the same log length, and the log management method further includes:
[0231] 016: Determine the read address of the target log according to the start address pointer, the target log offset value and the log length corresponding to the target log storage area 10 where the target log is located.
[0232] In some embodiments, the processor may be configured to determine the read address of the target log based on the start address pointer, the target log offset value, the log length corresponding to the target log storage area 10 where the target log is located, and the start address and end address of the target log storage area 10.
[0233] In some embodiments, the log management device further includes a third determination module. The third determination module can be used to determine the read address of the target log according to the start address pointer, the target log offset value, the log length corresponding to the target log storage area 10 where the target log is located, and the start address and end address of the target log storage area 10.
[0234] Specifically, in the related art, when the business scenario is more complex, the types and number of logs to be recorded are large, and the capacity of a single Flash storage chip may not be enough to save all logs. At this time, logs of different lengths need to be stored on multiple Flash chips (MCU and DSP's own Flash, external expansion Flash, etc.). If different types of logs are written to the same storage area, it will become difficult to read the target log. There must be a mechanism to distinguish the boundaries of each log. This process is inevitably accompanied by a waste of storage capacity and a large number of judgments when distinguishing log boundaries and content, which greatly slows down the indexing speed of logs.
[0235] In the implementation manner of the present application, logs of the same length are stored in each log storage area 10, so that the logs are arranged compactly, easy to index, and no space is wasted.
[0236] When reading the target log, the starting address pointer in the RAM can be obtained, and the log status information can be retrieved from the information storage area 50 to obtain the log length corresponding to the target log storage area 10 where the target log is located, the starting address and the end address of the target log storage area 10. According to the starting address pointer firstLogAddr, the target log offset value i, the log length logSize corresponding to the target log storage area 10 where the target log is located, the starting address logDataAddrStart and the end address logDataAddrEnd of the target log storage area 10, the reading address of the target log can be determined.
[0237] The target log offset value is the storage order of the target log in the log storage area 10 . For example, when the target log is the third log stored in the log storage area 10 , the target log offset value is 3.
[0238] See also Fig. 22 , when the address pointed to by the starting address pointer firstLogAddr is the starting address of the log storage area 10, the method for determining the read address readAddr of the target log is:
[0239] readAddr=firstLogAddr+i*logSize
[0240] See also Fig.23, when the address pointed to by the starting address pointer firstLogAddr is the starting address of the log storage area 10, the method for determining the read address readAddr of the target log is:
[0241] readAddr=firstLogAddr+i*logSize-logDataAddrEnd+logDataAddrStart
[0242] In addition, since there is no need to store additional process variables during reading, the space complexity of reading the log is O(1). The time complexity of reading the log is O(1).
[0243] In this way, the read address of the target log can be obtained according to the start address pointer, the target log offset value and the log length, without traversing the log storage area 10, which greatly reduces the time for reading the log.
[0244] See also Figure 22 to Figure 24 In some implementations, all logs in the same log storage area 10 have the same log length, and the log management method further includes:
[0245] 017: Determine the number of logs stored in the target log storage area 10 according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area 10 .
[0246] In some implementations, the processor may be configured to determine the number of logs stored in the target log storage area 10 according to the start address pointer, the write address pointer, and the log length corresponding to the target log storage area 10 .
[0247] In some embodiments, the log management device further includes a fourth determination module. The fourth determination module can be used to determine the number of logs stored in the target log storage area 10 according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area 10.
[0248] Specifically, the log lengths in each log storage area 10 are the same, and the log lengths are stored in the information storage area 50 . By retrieving the log metadata, the log length corresponding to the log storage area 10 can be obtained.
[0249] According to the start address pointer firstLogAddr, the write address pointer nextLogWriteAddr and the log length logSize corresponding to the target log storage area 10, the number of logs stored in the target log storage area 10 can also be determined.
[0250] See also Fig. 22, when the address pointed to by the starting address pointer firstLogAddr is the starting address of the log storage area 10, the number of logs logNum is determined as follows:
[0251]
[0252] See also Fig.23 In the case where the address pointed to by the start address pointer firstLogAddr is not the start address of the log storage area 10, the first address logDataAddrStart and the end address logDataAddrEnd of the log storage area 10 can also be retrieved in the information storage area 50 to determine the number of logs logNum. The number of logs logNum is determined as follows:
[0253]
[0254] In this way, according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area 10, the number of logs stored in the target log storage area 10 can be quickly determined without traversing all the logs, thereby reducing the time for calculating the total number of logs.
[0255] See also Fig.25 In some embodiments, when receiving an instruction, the controller of the log management system first determines whether the read address or the write address is valid. After determining that it is valid, it determines the type of the target flash memory and performs a read operation or a write operation on the target flash memory.
[0256] Specifically, when performing a read operation, a read address is calculated according to the log offset value and the log storage form (length and storage address), and the log is read back according to the read address.
[0257] When performing a write operation, determine the length type of the Flash to determine which log storage area needs to be written. And determine whether the address pointed to by the write address pointer is a sector boundary. If it is a sector boundary, determine whether the address pointed to by the write address pointer is the end position of the log storage area. If it is the end position, point the write address pointer to the start address of the log storage area, erase the start sector, and write the log; if it is not the end position, erase the current sector and write the log.
[0258] If the address pointed to by the write address pointer is not a sector boundary, the log is written directly to the current sector.
[0259] In this way, the log reading operation or log writing operation is completed.
[0260] An embodiment of the present application provides an embedded device, and the embedded device includes a log management system 1000 as described in any of the above embodiments.
[0261] An embodiment of the present application provides a vehicle, the vehicle including a log management system 1000 as in any of the above embodiments, or an embedded device as in the above embodiments, or an electronic device as in the above embodiments.
[0262] An embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the steps of the method in any of the above embodiments are implemented.
[0263] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "illustrative embodiments", "examples", "specific examples" or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiments or examples are included in at least one embodiment or example of the present application. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. In addition, those skilled in the art may combine and combine different embodiments or examples described in this specification and the features of different embodiments or examples without contradiction.
[0264] In addition, the term "connection" should be understood in a broad sense, for example, it can include fixed connection, detachable connection, or integral connection; it can include direct connection, indirect connection through an intermediate medium, and internal communication between two elements. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.
[0265] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0266] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, fragment or portion of code that includes one or more executable instructions for implementing the steps of a specific logical function or process, and the scope of the preferred embodiments of the present application includes alternative implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present application belong.
[0267] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.
Claims
1. A log management method, characterized in that: The log management method comprises: Determine a starting address pointer and a write address pointer according to the starting address of the log storage area in the flash memory, wherein the starting address pointer is used to indicate the starting address of the stored logs in the log storage area, and the write address pointer is used to indicate the write address of the current log in the log storage area; Erasing the record storage area corresponding to the log storage area; The log management is completed according to the start address pointer, the write address pointer and the erase processing result of the record storage area.
2. The log management method according to claim 1, characterized in that: The step of determining a starting address pointer and a writing address pointer according to a starting address of a log storage area in the flash memory comprises: The starting address pointer and the writing address pointer are pointed to the starting address of the log storage area.
3. The log management method according to claim 1, characterized in that: The log management method further includes: According to the write address pointer, the current log storage area is erased and the current log is written; After the writing of the current log is completed, the write address pointer is pointed to the next position after the end of the current log.
4. The log management method according to claim 3, characterized in that: The erasing process of the current log storage area according to the write address pointer and the writing process of the current log include: When the write address pointer points to the starting address of the current sector, erasing the current sector; According to the write address pointer, write the current log into the current sector after erasure; or, In the case that the write address pointer points to a non-starting address of the current sector, the current log is written into the current sector according to the write address pointer.
5. The log management method according to claim 4, characterized in that: The starting address of the stored log is the starting address of the current sector, and when the write address pointer points to the starting address of the current sector, erasing the current sector includes: When the address pointed to by the start address pointer is the same as the address pointed to by the write address pointer, erasing the current sector; The start address pointer points to the start address of the next sector.
6. The log management method according to claim 5, characterized in that: The step of pointing the start address pointer to the start address of the next sector comprises: In the case that the current sector is the last sector of the current log storage area, the start address pointer is pointed to the initial address of the initial sector of the current log storage area.
7. The log management method according to claim 3, characterized in that: The step of pointing the write address pointer to a position after the end of the current log comprises: When there is no free storage space in the current log storage area, the write address pointer is pointed to the start address of the current log storage area.
8. The log management method according to claim 1, characterized in that: After the current log is written, the log management method further includes: Obtaining a write record address pointer, wherein the write record address pointer is used to indicate a write address of a current log record when it is written into a record storage area of the flash memory; Writing the current log record of the current log into the record storage area according to the address pointed to by the record address pointer, wherein the current log record includes the starting address of the stored log and the ending address of the current log; The write record address pointer is pointed to the position after the end of the current log record.
9. The log management method according to claim 8, characterized in that: Pointing the write record address pointer to a position after the end of the current log record includes: When the end of the current log record is the end storage space of the record storage area, erasing the record storage area; The write record address pointer points to the starting address of the record storage area.
10. The log management method according to claim 8, characterized in that: The log management method further includes: In the case where the log record exists, determining the end address of the log record, the start address and the end address of the stored log according to the last log record; Assigning a value to the write record address pointer according to the end address of the log record; According to the starting address of the stored log, assign a value to the starting address pointer; The write address pointer is assigned a value according to the end address of the stored log.
11. The log management method according to claim 1, characterized in that: The log management method further includes: Writing current log status information into the information storage area of the flash memory, wherein the current log status information includes initialization time and log metadata; Point the write address pointer and the start address pointer to the start address of the initial sector of the current log storage area; The write record address pointer points to the initial address of the record storage area.
12. The log management method according to claim 11, characterized in that: The step of writing the current log status information into the information storage area of the flash memory comprises: When the log status information stored in the information storage area is different from the current log status information, erasing the information storage area; The current log status information is written into the information storage area of the flash memory.
13. The log management method according to claim 1, characterized in that: The log lengths of all logs in the same log storage area are the same, and the log management method further includes: The read address of the target log is determined according to the start address pointer, the target log offset value and the log length corresponding to the target log storage area where the target log is located.
14. The log management method according to claim 1, characterized in that: The log lengths of all logs in the same log storage area are the same, and the log management method further includes: The number of logs stored in the target log storage area is determined according to the start address pointer, the write address pointer and the log length corresponding to the target log storage area.
15. A log management system, characterized in that: The log management system includes a flash memory, a RAM and a controller; the flash memory includes at least one log storage area and a corresponding record storage area; the RAM is configured to store a start address pointer and a write address pointer, the start address pointer is used to indicate the start address of the stored log in the log storage area, and the write address pointer is used to indicate the write address of the current log written in the log storage area; the controller is configured to: Determine the starting address pointer and the writing address pointer according to the starting address of the log storage area in the flash memory; Erasing the record storage area corresponding to the log storage area; The log management is completed according to the start address pointer, the write address pointer and the erase processing result of the record storage area.
16. The log management system according to claim 15, characterized in that: The RAM further includes a write record address pointer, which is used to indicate a write address of a current log record when it is written into the record storage area of the flash memory.
17. The log management system according to claim 15, characterized in that: The flash memory also includes an information storage area, and the information storage area is used to store log status information, and the log status information includes initialization time, a start address and an end address of the record storage area, and a start address and an end address of the log storage area.
18. An embedded device, characterized in that: The embedded device includes a log management system as described in any one of claims 15 to 17.
19. An electronic device, characterized in that: The electronic device includes one or more processors and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the steps of the method according to any one of claims 1 to 14 are implemented.
20. A vehicle, characterized in that: The vehicle comprises the log management system according to any one of claims 15 to 17, or the embedded device according to claim 18, or the electronic apparatus according to claim 19.
21. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method according to any one of claims 1 to 14 are implemented.
Citation Information
Cited By
Log processing system, log writing method and log reading method and device
CN120949994A