A memory card detection method and system based on ranking entropy
By dividing the memory card into test areas and calculating sorting entropy and jump entropy, the problem of disordered memory card write order was solved, enabling efficient detection and reliability assessment of memory card write order.
Patent Information
- Application Number
- CN202511527283.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-24
- Publication Date
- 2026-02-10
- Estimated Expiration
- 2045-10-24
AI Technical Summary
Existing memory card testing methods fail to effectively identify and quantify consistency issues in memory card write order. In particular, under conditions of controller malfunction or sudden power failure, data write order disorder and read order misalignment may occur, affecting data integrity and reliability.
By dividing the logical address space of the memory card into multiple test areas, writing information-encoded data blocks containing sequence identifiers to each address, and calculating sorting entropy and jump entropy during the readback process, the offset and difference between the actual read order and the original write order are compared to determine whether the write order is out of control.
It can accurately identify and quantify the degree of disorder in the memory card's write order and address jump behavior, improving the sensitivity and reliability of data write consistency detection and timely detecting write errors caused by controller anomalies.
Smart Images

Figure CN120998287B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of memory card detection, and more particularly, to a memory card detection method and system based on sorting entropy. BACKGROUND
[0002] With the wide application of memory cards (such as SD cards, TF cards and other flash storage media) in mobile devices, industrial control, surveillance video and Internet of Things devices, the reliability, timing consistency and controller stability of data writing are becoming key evaluation indicators. In the above application scenarios, data is usually written to the storage device in a continuous and real-time manner, such as video frames, log sequences, data acquisition samples, etc. For these systems, if the writing order of the storage device is disordered or jumps, it may cause serious consequences such as data content disorder, time axis loss, and logic backtracking failure.
[0003] Existing memory card detection methods mostly focus on data integrity, read-write speed or bad block detection, and pay less attention to the writing order consistency problem of data in the logical address space. Some inferior controllers or memory cards with defective firmware design may cause problems such as buffer overflow, write pointer abnormal rollback, address mapping table disorder or not timely flushing due to control logic abnormality, improper cache management or mapping table error during writing. Such problems not only cause logical address jumping during data writing, but also may cause "order misplacement" phenomenon during data readback, that is, although the data is successfully written, the order obtained during readback is inconsistent with the original writing order. For example, the data blocks originally written in order appear to be interlaced, reversed or partially lost during readback. This writing-reading order inconsistency problem is more common when the controller uses a log-type writing strategy but does not correctly update the file system index, especially in edge scenarios such as sudden power failure, hot plug or high-load continuous writing.
[0004] To solve the above problems, there is still a lack of a method and system that can comprehensively identify, quantify and judge the writing order loss behavior of memory cards. SUMMARY
[0005] The technical problem solved by the present application is to provide a memory card detection method and system based on sorting entropy to solve the problems mentioned in the background.
[0006] In order to achieve the above purpose, the present application adopts the following technical scheme:
[0007] The advantages of the present application over the prior art are:
[0008] A memory card detection method based on sorting entropy, comprising the following steps:
[0009] dividing the logical address space of the memory card into a plurality of continuous or equally spaced test regions;
[0010] writing, to each address in the test regions, an information encoding data block containing a sequential identifier;
[0011] after completing all the writing, performing one or more read-back operations on the memory card to obtain the actual reading order of the written data blocks;
[0012] extracting the sequence of sequential identifiers from the reading results to construct a reading order sequence;
[0013] comparing the reading order sequence with the original writing order sequence, and calculating an order entropy for reflecting the degree of disorder;
[0014] comparing the order entropy with a set threshold value, and if the order entropy exceeds the threshold value, determining that the memory card has a risk of out-of-control writing order.
[0015] In some embodiments, the order entropy is calculated as follows:
[0016] comparing each sequential identifier in the reading order sequence with its ideal position in the original writing order, calculating the offset between the actual reading position and the ideal position, and constructing an offset distribution sequence from all the offsets of the sequential identifiers, and calculating the information entropy value based on the offset distribution sequence As the order entropy, the order entropy is defined by the following formula:
[0017] ;
[0018] wherein, Pi represents the probability of the offset falling into the ith offset interval.
[0019] In some embodiments, the method for calculating Pi includes:
[0020] dividing all the offsets into a group of predefined offset intervals, the offset intervals including a plurality of non-overlapping integer intervals;
[0021] counting the number of offset samples contained in the ith offset interval , and normalizing the total number of samples , and calculating the probability value in the ith offset interval based on the following formula :
[0022] .
[0023] In some embodiments, the information encoding data block includes a unique sequential identifier, an optional timestamp field, and payload data.
[0024] In some embodiments, the payload data in the information-encoding data block comprises a predefined fixed pattern or a random byte sequence.
[0025] In some embodiments, the method further comprises:
[0026] After the reading of the data blocks and the extraction of the sequential identifier sequence are completed, the logical address information of each read data block in the storage device is obtained, and a logical address sequence of the read data blocks is constructed;
[0027] Based on the logical address sequence, the difference in logical address between any two data blocks adjacent in the write sequence is calculated according to the write sequence, and a logical address difference sequence is formed;
[0028] Based on the difference sequence, a jump entropy is calculated to reflect the degree of address jump behavior;
[0029] When the jump entropy exceeds a preset threshold, a jump entropy alarm information is output.
[0030] In some embodiments, the method for calculating the jump entropy comprises the following steps:
[0031] The absolute value of each jump difference in the logical address difference sequence is classified according to a plurality of non-overlapping jump amplitude intervals, and the frequency statistics value of each jump amplitude interval is obtained;
[0032] Let the total number of jump samples be , and the number of samples in the i-th jump amplitude interval be , then the probability corresponding to the jump amplitude interval is :
[0033] ;
[0034] The jump entropy value is further calculated as , and the formula is:
[0035] .
[0036] The present application also includes a memory card detection system based on ordering entropy, comprising:
[0037] An address division module is configured to divide the logical address space of the memory card into a plurality of continuous or equally spaced test regions;
[0038] An encoding write module is configured to write an information-encoding data block containing a sequential identifier to each address in the test region;
[0039] A read-back acquisition module is configured to perform one or more read-back operations on the memory card after all the writing is completed, and to obtain the actual reading sequence of the written data blocks;
[0040] The sequence extraction module is used to extract the sequence identifier sequence from the read results and construct the read sequence sequence;
[0041] The entropy calculation module is used to compare the read sequence with the original write sequence and calculate the sorting entropy, which reflects the degree of disorder.
[0042] The anomaly detection module is used to compare the sorting entropy with a set threshold. If the entropy exceeds the threshold, it is determined that the memory card has a risk of write order loss.
[0043] In some embodiments, the sorting entropy is calculated as follows:
[0044] Each sequence identifier in the read sequence is compared with its ideal position in the original write sequence, and the offset between the actual read position and the ideal position is calculated; the offsets of all sequence identifiers are used to construct an offset distribution sequence; and the information entropy value is calculated based on the offset distribution sequence. The sorting entropy is defined by the following formula:
[0045] ;
[0046] in, This represents the probability that the offset falls into the i-th offset interval.
[0047] In some embodiments, calculation The methods include:
[0048] All offsets are divided into a set of predefined offset intervals, which include multiple non-overlapping integer intervals;
[0049] Count the number of offset samples contained in the i-th offset interval. and the total number of samples Normalization is performed, and the probability value within the i-th offset interval is calculated based on the following formula. :
[0050] .
[0051] By adding a sequence identifier to each written data block and reconstructing the actual read sequence during the readback process, it is possible to intuitively identify whether the data is stored in the expected order, thereby promptly detecting write errors caused by controller malfunctions, cache errors, or power failure recovery failures.
[0052] This invention is the first to apply the concept of information entropy to storage order detection. By calculating sorting entropy, it reflects the "degree of disorder" of the actual reading order. Compared with the traditional simple counting method of reverse pairing, it can more accurately measure the distribution breadth and complexity of disorder, and has higher sensitivity and engineering applicability.
[0053] During the detection process, this invention can further extract the difference sequence of adjacent data blocks in the logical address space to identify whether the controller exhibits abnormal jump or bounce behavior during writing. By calculating the jump entropy, this invention can determine the randomness and degree of loss of control of the jump behavior, which helps to reveal the stability and reliability of the controller's address mapping mechanism. Attached Figure Description
[0054] Figure 1 This is an overall flowchart of the present invention;
[0055] Figure 2 This is a diagram illustrating the data block writing process of this invention;
[0056] Figure 3 This is a flowchart of the sorting entropy calculation process of the present invention;
[0057] Figure 4 This is a flowchart of the jump entropy calculation process of this invention. Detailed Implementation
[0058] The specific embodiments of the present invention will now be described with reference to the accompanying drawings.
[0059] This invention discloses a memory card detection method and system based on sorting entropy, which analyzes potential problems in the data writing and reading process of memory cards through a series of systematic operation steps.
[0060] like Figure 1 As shown, the method of the present invention includes the following steps:
[0061] Divide the logical address space of the memory card into multiple consecutive or equally spaced test regions;
[0062] Write a block of information-encoded data containing a sequence identifier to each address in the test area;
[0063] After all writing is completed, perform one or more read-back operations on the memory card to obtain the actual reading order of the written data blocks;
[0064] Extract the sequence of sequence identifiers from the read results and construct the read sequence.
[0065] The read order sequence is compared with the original write order sequence, and the sorting entropy, which reflects the degree of disorder, is calculated.
[0066] The sorting entropy is compared with a set threshold. If the entropy exceeds the threshold, it is determined that the memory card has a risk of losing control of the write order.
[0067] In a specific embodiment, the first step of the detection is to divide the logical address space of the memory card into multiple test regions. These regions can be contiguous or equally spaced. The purpose of this division is to ensure that the detection covers different parts of the memory card, thereby evaluating its overall performance and consistency. For example, for a 1GB memory card, it is assumed to be divided into 10 contiguous test regions, each covering approximately 100MB of address space, i.e., from 0 to 104857599, 104857600 to 209715199, and so on. Another approach is to divide it at equal intervals, such as selecting a test region every 10MB, which can simulate random access scenarios.
[0068] When dividing the memory card into regions, the number and size of regions can be adjusted according to the actual capacity of the memory card and usage requirements. For small-capacity memory cards (such as 512MB), the number of regions can be reduced; for large-capacity memory cards (such as 32GB), the number of regions can be increased to improve detection accuracy. After division, each test region will serve as the target for subsequent data writing.
[0069] like Figure 2 As shown, within each test area, carefully designed information-encoded data blocks need to be written to each address. These data blocks contain the following key components:
[0070] A sequence identifier is a unique number or code used to mark the writing order of data blocks. For example, a 32-bit unsigned integer can be used, incrementing from 1, such as 1, 2, 3,... until the writing is complete. The sequence identifier can be generated using a counter, ensuring that the identifier for each data block is unique.
[0071] A timestamp (optional) records the precise time a data block was written, typically represented as a 64-bit integer in milliseconds. It helps analyze the timing characteristics of write operations, and is particularly useful in detecting intermittent issues. For example, a timestamp could be a UNIX timestamp based on the system clock.
[0072] Payload data, which is the main content of the data block, can be a predefined fixed pattern (such as all 0s, all 1s, or alternating 0x55AA patterns) or a random byte sequence. Fixed patterns are suitable for detecting specific hardware errors, such as bit flips; while random sequences are closer to real-world usage scenarios and can test the memory card's performance under complex data.
[0073] A typical data block structure might be: a 4-byte sequence identifier, an 8-byte timestamp (if used), and the remaining bytes for payload data. The total length can be flexibly adjusted according to the memory card block size (e.g., 512 bytes). During writing, data blocks are sequentially filled into each address of the test area, ensuring that all target addresses are covered.
[0074] After writing is complete, a readback operation is performed on the memory card to obtain the actual read order. Reads can be performed once or multiple times, depending on the testing requirements. Multiple reads can capture intermittent errors, such as occasional data corruption due to hardware instability. During reading, the sequence identifier and corresponding logical address of each data block must be recorded. In practice, the readback operation follows the default logical address order, i.e., reading sequentially from the starting logical address of the test area to the ending address. This order may differ from the write order at the physical level, especially in storage devices with caching, remapping, or wear leveling mechanisms. For testing scenarios with high reliability requirements, multiple rounds of readback can be performed, and different access orders (such as random order) can be used for comparative analysis to enhance the robustness of the testing.
[0075] Extract the sequence identifiers from the read results to construct a read order sequence. For example, suppose the write order is 1, 2, 3, 4, 5, but the actual read order is 1, 3, 2, 4, 5. This indicates that the positions of sequence identifiers 2 and 3 have been swapped. The extraction process requires parsing the first few bytes (e.g., the first 4 bytes) of the data block to correctly identify the sequence identifiers.
[0076] like Figure 3 As shown, to quantify the difference between the read and write orders, sorting entropy is used to measure the degree of disorder. The calculation process consists of the following steps:
[0077] First, offset calculation is performed. Each sequence identifier in the read sequence is compared to its ideal position in the original write sequence (i.e., its order in the write sequence), and the offset is calculated. The offset is defined as the actual position minus the ideal position. For example, if the write sequence is 1,2,3,4,5, the read sequence is 1,3,2,4,5.
[0078] Sequence identifier 1: Ideal position 1, actual position 1, offset 0;
[0079] Sequence identifier 2: Ideal position 2, Actual position 3, Offset 1;
[0080] Sequence identifier 3: Ideal position 3, actual position 2, offset -1;
[0081] Sequence identifier 4: Ideal position 4, actual position 4, offset 0;
[0082] Sequence identifier 5: Ideal position 5, actual position 5, offset 0.
[0083] The resulting offset sequence is [0,1,-1,0,0].
[0084] Next is the offset interval partitioning. Specifically, the offset is divided into a set of predefined discrete intervals. For example, a very simple implementation could be: [-∞, -2], [-1], [0], [1], [2, +∞]. These intervals can be fixed or dynamically adjusted according to the distribution of the offsets. Fixed intervals are suitable for simple implementations, while dynamic intervals can improve adaptability to large datasets.
[0085] Next is the probability calculation. Specifically, the number of offset samples in each interval is counted and normalized using the total number of samples. For example, in the above sequence, the interval [-1] has 1 sample, [0] has 3 samples, [1] has 1 sample, and the total number of samples T=5, then:
[0086] p -1 =1 / 5=0.2;
[0087] p0 = 3 / 5 = 0.6;
[0088] p1 = 1 / 5 = 0.2.
[0089] Next, we calculate the entropy value, specifically using the information entropy formula to calculate the sorting entropy:
[0090] ;
[0091] Substitute the data:
[0092] H = - (0.2 × log2 0.2 + 0.6 × log2 0.6 + 0.2 × log2 0.2)
[0093] ≈ - (0.2 × (-2.322) + 0.6 × (-0.737) + 0.2 × (-2.322))
[0094] ≈ 1.37 bits.
[0095] Information entropy, derived from information theory, is used to measure the uncertainty of random variables. Here, the entropy value reflects the uniformity of the distribution of offsets. If all offsets are concentrated in a certain interval (e.g., all zero), the entropy value is close to 0, indicating that the order is basically maintained; if the offsets are uniformly distributed, the entropy value is high, indicating severe disorder. This quantification method is intuitive and scientific, and can effectively detect problems of out-of-order control.
[0096] The sorting entropy H is compared with a preset threshold. If H exceeds the threshold, the memory card is considered to have a risk of write order loss. The threshold can be selected based on empirical data, such as by testing a large number of normal and abnormal memory cards to determine that the entropy value is usually below 1.0 under normal circumstances, but may exceed 1.5 under abnormal circumstances, so the threshold can be set to 1.2. It can also be adjusted according to the application scenario; for example, the threshold can be reduced for scenarios with high reliability requirements.
[0097] like Figure 4 As shown, besides detecting out-of-order behavior, address jumping behavior can also be analyzed using jump entropy. Specifically:
[0098] After completing the reading of the data block and extracting the sequence identifier sequence, the logical address information of each read data block in the storage device is obtained, and the logical address sequence of the read data block is constructed.
[0099] Based on the logical address sequence, the difference in logical address between any two data blocks with adjacent write ordinal numbers is calculated according to the write order to form a logical address difference sequence.
[0100] Based on the difference sequence, the jump entropy is calculated to reflect the degree of address jump behavior;
[0101] When the jump entropy exceeds a preset threshold, a jump entropy alarm message is output.
[0102] The method for calculating jump entropy is similar to the sorting entropy method described above, and includes the following steps:
[0103] The absolute value of each jump difference in the logical address difference sequence is classified according to multiple preset non-overlapping jump amplitude intervals to obtain the frequency statistics of each jump amplitude interval.
[0104] Let the total number of skip samples be The number of samples in the i-th jump range interval is Then the probability corresponding to the jump range is... for:
[0105] ;
[0106] Further calculate the jump entropy value Its formula is:
[0107] .
[0108] The jump entropy formula is similar to the sorting entropy formula, used to measure the randomness of address differences. An entropy value of 0 indicates that the address jumps are highly consistent, which may reflect normal sequential allocation; a higher entropy value may indicate abnormal address allocation, such as jumps caused by wear leveling.
[0109] The jump entropy is compared with a threshold, for example, set to 0.5. If it exceeds the threshold, an alarm is output, indicating a possible address jump problem.
[0110] The present invention also discloses a system for implementing the above method, comprising:
[0111] The address partitioning module is used to divide the logical address space of the memory card into multiple consecutive or equally spaced test regions.
[0112] The encoding writing module is used to write an information-encoded data block containing a sequence identifier to each address in the test area;
[0113] The readback acquisition module is used to perform one or more readback operations on the memory card after all writing is completed to obtain the actual reading order of the written data blocks;
[0114] The sequence extraction module is used to extract the sequence identifier sequence from the read results and construct the read sequence sequence;
[0115] The entropy calculation module is used to compare the read sequence with the original write sequence and calculate the sorting entropy, which reflects the degree of disorder.
[0116] The anomaly detection module is used to compare the sorting entropy with a set threshold. If the entropy exceeds the threshold, it is determined that the memory card has a risk of write order loss.
[0117] This invention is applicable to various memory cards such as SD cards and CF cards. The value range of parameters such as offset interval and jump range can be adjusted according to the memory card capacity; for example, the interval can be refined for large-capacity cards. It has low computational complexity and is suitable for real-time applications.
[0118] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A memory card detection method based on sorting entropy, characterized in that, Includes the following steps: Divide the logical address space of the memory card into multiple consecutive or equally spaced test regions; Write a block of information-encoded data containing a sequence identifier to each address in the test area; After all writing is completed, perform one or more read-back operations on the memory card to obtain the actual reading order of the written data blocks; Extract the sequence of sequence identifiers from the read results and construct the read sequence. The read order sequence is compared with the original write order sequence, and the sorting entropy, which reflects the degree of disorder, is calculated. The sorting entropy is compared with a set threshold. If the threshold is exceeded, it is determined that the memory card has a risk of losing control of the write order. The sorting entropy is calculated as follows: Each sequence identifier in the read sequence is compared with its ideal position in the original write sequence, and the offset between the actual read position and the ideal position is calculated; the offsets of all sequence identifiers are used to construct an offset distribution sequence; and the information entropy value is calculated based on the offset distribution sequence. The sorting entropy is defined by the following formula: ; in, This indicates that the offset falls within the first... i The probability of each offset interval.
2. The memory card detection method based on sorting entropy according to claim 1, characterized in that, calculate The methods include: All offsets are divided into a set of predefined offset intervals, which include multiple non-overlapping integer intervals; Statistics i Number of offset samples contained in each offset interval and the total number of samples Normalization is performed, and the first equation is calculated based on the following formula. i Probability value within each offset interval : 。 3. The memory card detection method based on sorting entropy according to claim 1, characterized in that, The information-encoded data block includes a unique sequence identifier, an optional timestamp field, and payload data.
4. The memory card detection method based on sorting entropy according to claim 3, characterized in that, The payload data in the information encoded data block includes a predefined fixed pattern or a random byte sequence.
5. The memory card detection method based on sorting entropy according to claim 1, characterized in that, The method further includes: After completing the reading of the information encoded data block and extracting the sequence identifier sequence, the logical address information of each read data block in the storage device is obtained, and the logical address sequence of the read data block is constructed. Based on the logical address sequence, the difference in logical address between any two data blocks with adjacent write ordinal numbers is calculated according to the write order to form a logical address difference sequence. Based on the difference sequence, the jump entropy is calculated to reflect the degree of address jump behavior; When the jump entropy exceeds a preset threshold, a jump entropy alarm message is output.
6. The memory card detection method based on sorting entropy according to claim 5, characterized in that, The method for calculating jump entropy includes the following steps: The absolute value of each jump difference in the logical address difference sequence is classified according to multiple preset non-overlapping jump amplitude intervals to obtain the frequency statistics of each jump amplitude interval. Let the total number of skip samples be , No. i The number of samples in each jump range is Then the probability corresponding to the jump range is... for: ; Further calculate the jump entropy value Its formula is: 。 7. A memory card detection system based on sorting entropy, characterized in that, include: The address partitioning module is used to divide the logical address space of the memory card into multiple consecutive or equally spaced test regions. The encoding writing module is used to write an information-encoded data block containing a sequence identifier to each address in the test area; The readback acquisition module is used to perform one or more readback operations on the memory card after all writing is completed to obtain the actual reading order of the written data blocks; The sequence extraction module is used to extract the sequence identifier sequence from the read results and construct the read sequence sequence; The entropy calculation module is used to compare the read sequence with the original write sequence and calculate the sorting entropy, which reflects the degree of disorder. An anomaly detection module is used to compare the sorting entropy with a set threshold. If the threshold is exceeded, it is determined that the memory card has a risk of write order loss. The sorting entropy is calculated as follows: Each sequence identifier in the read sequence is compared with its ideal position in the original write sequence, and the offset between the actual read position and the ideal position is calculated; the offsets of all sequence identifiers are used to construct an offset distribution sequence; and the information entropy value is calculated based on the offset distribution sequence. The sorting entropy is defined by the following formula: ; in, This indicates that the offset falls within the first... i The probability of each offset interval.
8. The memory card detection system based on sorting entropy according to claim 7, characterized in that, calculate The methods include: All offsets are divided into a set of predefined offset intervals, which include multiple non-overlapping integer intervals; Statistics i Number of offset samples contained in each offset interval and the total number of samples Normalization is performed, and the first equation is calculated based on the following formula. i Probability value within each offset interval : 。
Citation Information
Patent Citations
Read-write test method of memory, electronic equipment and storage medium
CN119559991A