A method and device for automatically dividing storage domains of an embedded system
By dividing the storage domain configuration rules of the embedded system into two parts, and using a recursive iterative algorithm to dynamically divide the storage domain when the embedded system starts, the problem of insufficient flexibility caused by the solidification of the storage domain configuration rules in the existing technology is solved, and the implementation Storage domains are automatically divided to adapt to different partition situations, reducing maintenance costs.
Patent Information
- Application Number
- CN202110658644.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-15
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-06-15
AI Technical Summary
Existing embedded systems solidify storage domain configuration rules during the code compilation stage, resulting in a loss of flexibility in storage domain configuration, increased maintenance costs, and inability to adapt to different partitions of non-volatile memory.
An automatic storage domain division method for embedded systems is proposed. By dividing the storage domain configuration rules into two parts, the rules that are not related to the non-volatile memory are solidified in the code compilation stage, and the rules associated with them are set in the code programming stage. Parameters, a recursive iterative algorithm is used to dynamically divide the storage domain when the system is started, and realize the cache attribute configuration of code and data partitions.
It realizes the dynamic and flexible automatic division of storage domains according to different partitions of non-volatile memory, reduces the number of storage domains, and improves the flexibility and efficiency of the system.
Smart Images

Figure CN113485947B
Abstract
Description
Technical Field
[0001] The present application relates to a storage domain partitioning method for an embedded system. Background Art
[0002] When the embedded system is running, the Memory Protection Unit (MPU) provides access restrictions and protection for storage resources. It grants special permissions to monitoring and controlling programs at the hardware level, which can effectively enhance the efficiency and restrictions of program access to storage resources.
[0003] In embedded systems using the ARM (Advanced RISC Machine) architecture, the storage protection unit is implemented by configuring the memory region (also called memory region) on the non-volatile memory by the program. There can be one or more memory regions, and each memory region has a set of configuration rules.
[0004] The configuration rules of the storage domain include the following contents.
[0005] (1) Region base address: It is used to define the starting address of the region and must be aligned to an integer multiple of the region size.
[0006] (2) Storage domain size (region size), can only be 2 n Bytes, n is an integer between 5 and 22, that is, the size of each storage domain can be between 32 bytes, 64 bytes, 128 bytes, ... 1GB, 2GB, 4GB.
[0007] (3) Storage region attributes, which include multiple attributes, including cache attributes. The cache attribute can be set to any of Non-cachable, Write-through Cacheable, and Write-back Cacheable.
[0008] The number of storage domains has an upper limit, for example, 12 or 16. The configuration rules of storage domains have different priorities. For example, if there are 16 storage domains, the configuration rules of storage domain 15 have the highest priority, and the configuration rules of storage domain 0 have the lowest priority. Overlap between storage domains is allowed. When there is overlap between storage domains, the configuration rule with the highest priority of the storage domain to which the overlapping area belongs takes effect in the overlapping area. In actual applications, by setting multiple storage domains and setting configuration rules for each storage domain, the non-volatile memory configuration features can be configured to improve system efficiency and protect storage areas when the program is running.
[0009] Embedded systems usually use flash memory as non-volatile memory. A flash memory contains a code partition that runs in the execution-in-place (XIP) mode and a data partition that stores data. The cache attribute of the code partition needs to be set to write-through cache or write-back cache. When the embedded system is running, the program will update the content in the data partition. The cache attribute of the data partition needs to be set to non-cacheable. The two partitions need different cache attributes so that the CPU can access the two partitions according to their respective cache attributes.
[0010] Existing embedded systems are divided into storage domains manually. During the code compilation stage of the embedded system, the configuration rules of the storage domains are solidified as part of the code and compiled in. The partition information is completely consistent with the subsequent code burning. This loses the flexibility of storage domain configuration and adjustment, and increases maintenance costs. Summary of the invention
[0011] The technical problem to be solved by the present application is to propose a method for automatically partitioning storage domains of an embedded system, which has the flexibility to adapt to non-volatile memories in various partitioning situations.
[0012] To solve the above technical problems, the present application proposes a method for automatically dividing storage domains of embedded systems, comprising the following steps. Step S1: Divide the configuration rules of the storage domain into two parts, the first part is the configuration rules that are not associated with the partition information of the non-volatile memory, and the second part is the configuration rules that are associated with the partition information of the non-volatile memory; in the code compilation stage of the embedded system, compile the configuration rules of the storage domain into an image file, wherein the configuration rules of the first part are solidified into code, and one or more parameters are set in the configuration rules of the second part, and different values of these parameters represent different storage domain division situations. Step S2: In the code burning stage of the embedded system, the non-volatile memory is partitioned, including at least three partitions-partition table, code partition, and data partition; one or more partitions with no requirements for cache attributes are set between the code partition and the data partition; then the partition information is burned into the partition table, and the image file of the configuration rules of the storage domain is burned into the code partition. Step S3: When the embedded system starts running, the storage domains of the non-volatile memory are automatically divided according to the partition information in the partition table using a recursive iterative algorithm to achieve the following three goals: (1) the cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache; (2) the cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable; (3) the entire non-volatile memory has a minimum number of storage domains; then the information of the divided storage domains is used as the values of various parameters of the mirror file of the configuration rule of the storage domain, and the configuration rule of the storage domain is finally determined.
[0013] Furthermore, in step S1, the configuration rules of the second part of the storage domain include: a storage domain base address, a storage domain size, and a cache attribute of the storage domain.
[0014] Furthermore, in step S2, the partition information includes a partition name, a partition address, and a partition size.
[0015] Further, as an embodiment 1 of the present application for application scenario 1, the starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the code partition is lower than the address segment of the data partition, the highest address of the code partition is ab, and the lowest address of the data partition is at. In the step S3, the recursive iterative algorithm includes the following steps. Step S51: Set the entire non-volatile storage domain as a storage domain, and set the cache attribute of the storage domain to be non-cacheable; set variable 1 V1 to represent the address in the non-volatile memory, and its initial value is fb. Step S52: In the size set of the storage domain, select a value that is closest to ab-V1 and ≤ab-V1 and is called S(i), and select a value that is closest to ab-V1 and ≥ab-V1 and is called S(i+1). Step S53: Determine whether S(i) is equal to ab-V1. If so, the area of S(i) size starting from variable 1 V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then enter step S55. If not, go to step S54. Step S54: Determine whether the value of V1+S(i+1) falls between ab and at. If so, the area of size S(i+1) starting from variable V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then go to step S55. If not, the area of size S(i) starting from variable V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; change the value of variable V1 to V1+S(i), and return to step S52. Step S55: All storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0016] Further, as the first embodiment of the present application for application scenario 2, the starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the data partition is lower than the address segment of the code partition, the highest address of the data partition is ab, and the lowest address of the code partition is at. In the step S3, the recursive iterative algorithm includes the following steps. Step S51: Set the entire non-volatile storage domain as a storage domain, and set the cache attribute of the storage domain to a write-through cache or a write-back cache; set variable 1 V1 to represent the address in the non-volatile memory, and its initial value is fb. Step S52: In the size set of the storage domain, select a value that is closest to ab-V1 and ≤ab-V1 and is called S(i), and select a value that is closest to ab-V1 and ≥ab-V1 and is called S(i+1). Step S53: Determine whether S(i) is equal to ab-V1. If so, the area of size S(i) starting from variable 1 V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; then enter step S55. If not, go to step S54. Step S54: Determine whether the value of V1+S(i+1) falls between ab and at. If so, the area of size S(i+1) starting from variable V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; then go to step S55. If not, the area of size S(i) starting from variable V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; change the value of variable V1 to V1+S(i), and return to step S52. Step S55: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0017] Further, as the second embodiment of the present application for application scenario one, the starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the code partition is lower than the address segment of the data partition, the highest address of the code partition is ab, and the lowest address of the data partition is at. In the step S3, the recursive iterative algorithm includes the following steps. Step S61: Set the entire non-volatile storage domain as a storage domain, and the cache attribute of the storage domain is set to be non-cacheable; in the size set of the storage domain, select a value that is closest to at-fb and ≥at-fb called S_init, and the area of S_init size starting from fb toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; set variable two V2 to represent the address in the non-volatile memory, and its initial value is fb+S_init. Step S62: In the size set of the storage domain, select a value that is closest to V2-at and ≤V2-at called S(i), and select a value that is closest to V2-at and ≥V2-at called S(i+1). Step S63: Determine whether S(i) is equal to V2-at. If so, the area of S(i) size starting from variable two V2 toward the low address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then enter step S65. If not, enter step S64. Step S64: Determine whether the value of V2-S(i+1) falls between ab and at. If so, the area of S(i+1) size starting from variable two V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then enter step S65. If not, as used in application scenario one, the area of S(i) size starting from variable two V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; change the value of variable two V2 to V2-S(i), and return to step S62. Step S65: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0018] Further, as the second embodiment of the present application for application scenario 2, the starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the data partition is lower than the address segment of the code partition, the highest address of the data partition is ab, and the lowest address of the code partition is at. In the step S3, the recursive iterative algorithm includes the following steps. Step S61: Set the entire non-volatile storage domain as a storage domain, and the cache attribute of the storage domain is set to write-through cache or write-back cache; in the size set of the storage domain, select a value that is closest to at-fb and ≥at-fb called S_init, and the area of S_init size starting from ft toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; set variable two V2 to represent the address in the non-volatile memory, and its initial value is fb+S_init. Step S62: In the size set of the storage domain, select a value that is closest to V2-at and ≤V2-at called S(i), and select a value that is closest to V2-at and ≥V2-at called S(i+1). Step S63: Determine whether S(i) is equal to V2-at. If so, the area of S(i) size starting from variable V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; then enter step S65. If not, enter step S64. Step S64: Determine whether the value of V2-S(i+1) falls between ab and at. If so, the area of S(i+1) size starting from variable V2 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; then enter step S65. If not, the area of S(i) size starting from variable V2 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; change the value of variable V2 to V2-S(i), and return to step S62. Step S65: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0019] Further, the size set of the storage domain refers to the set of sizes of all legal storage domains, which is {32 bytes, 64 bytes, 128 bytes, ... 1GB, 2GB, 4GB}, and each value in the set is twice the previous value. If the non-volatile memory is a 4K-aligned flash memory, the size set of the storage domain is changed to {4KB, 8KB, 16KB, ... 1GB, 2GB, 4GB}, and each value in the set is twice the previous value.
[0020] Further, as the third embodiment of the present application for application scenario one or application scenario two, in step S3, the recursive iterative algorithm includes the following steps. Step S71: Use steps S51 to S55 to obtain the divided storage domain, which is called the addition mode; also use steps S61 to S65 to obtain the divided storage domain, which is called the subtraction mode. Step S72: Compare the number of storage domains divided by the addition mode and the number of storage domains divided by the subtraction mode, and select the smaller number as the final divided storage domain; if the number of storage domains divided by the two modes is the same, select the storage domain divided by any mode as the final divided storage domain.
[0021] The present application also proposes a storage domain automatic division device for an embedded system, including a compiling processing unit, a burning processing unit and a startup processing unit. The compiling processing unit is used to compile the configuration rules of the storage domain into a mirror file during the code compiling stage of the embedded system; wherein the configuration rules of the first part of the storage domain that is not associated with the partition information of the non-volatile memory are solidified into code, and one or more parameters are set in the configuration rules of the second part of the storage domain that is associated with the partition information of the non-volatile memory, and different values of these parameters represent different storage domain division situations. The burning processing unit is used to partition the non-volatile memory during the code burning stage of the embedded system, including at least three partitions-partition table, code partition, and data partition; one or more partitions with no requirements for cache attributes are set between the code partition and the data partition; then the partition information is burned into the partition table, and the mirror file of the configuration rules of the storage domain is burned into the code partition. The startup processing unit is used to automatically divide the storage domains of the non-volatile memory using a recursive iterative algorithm according to the partition information in the partition table when the embedded system is started, so as to achieve the following three goals: (1) the cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache; (2) the cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable; (3) the entire non-volatile memory has a minimum number of storage domains; then the information of the divided storage domains is used as the values of each parameter of the mirror file of the configuration rule of the storage domain, and the configuration rule of the storage domain is finally determined.
[0022] The technical effect achieved by the present application is that the automatic division of storage domains can be completed dynamically and flexibly according to different partitioning conditions of the non-volatile memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 It is a flow chart of the method for automatically dividing storage domains of an embedded system proposed in this application.
[0024] Figure 2It is a schematic diagram of partitioning the non-volatile memory.
[0025] Figure 3 It is a schematic diagram of application scenario 1 of the present application.
[0026] Figure 4 It is a schematic diagram of application scenario 2 of the present application.
[0027] Figure 5 It is a flowchart of the first embodiment (addition mode) of the recursive iterative algorithm.
[0028] Figure 6 It is a flowchart of the second embodiment (subtraction mode) of the recursive iterative algorithm.
[0029] Figure 7 It is a flowchart of Embodiment 3 (addition mode and subtraction mode) of the recursive iterative algorithm.
[0030] Figure 8 It is a structural schematic diagram of the storage domain automatic partitioning device of the embedded system proposed in this application.
[0031] Explanation of the reference numerals in the figure: compilation processing unit 1, burning processing unit 2, startup processing unit 3. DETAILED DESCRIPTION
[0032] See also Figure 1 The method for automatically dividing storage domains of embedded systems proposed in this application includes the following steps.
[0033] Step S1: Divide the configuration rules of the storage domain into two parts, the first part is the configuration rules that are not associated with the partition information of the non-volatile memory, and the second part is the configuration rules that are associated with the partition information of the non-volatile memory. The configuration rules of the second part of the storage domain include, for example: the base address of the storage domain, the size of the storage domain, and the cache properties of the storage domain. In the code compilation stage of the embedded system, the configuration rules of the storage domain are compiled into an image file (image), in which the configuration rules of the first part are solidified into code, and one or more parameters (variables) are set in the configuration rules of the second part, and different values of these parameters represent different storage domain division situations.
[0034] Step S2: During the code burning phase of the embedded system, the non-volatile memory is partitioned, including at least three partitions: partition table, code partition, and data partition. The partitions and storage domains here are two completely different systems and concepts. Please refer to Figure 2, the cache attribute of the code partition needs to be set to write-through cache or write-back cache, and the cache attribute of the data partition needs to be set to non-cacheable. Set one or more partitions that have no requirements for cache attributes between the code partition and the data partition. Then burn the partition information into the partition table, and burn the image file of the configuration rules of the storage domain into the code partition. The partition information includes the partition name, partition address, partition size, etc.
[0035] Step S3: When the embedded system starts running, the storage domain of the non-volatile memory is automatically divided according to the partition information in the partition table using a recursive iterative algorithm to achieve the following three goals. (1) The cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache. (2) The cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable. (3) The entire non-volatile memory has the least number of storage domains. The information of the divided storage domains is then used as the values of the various parameters of the mirror file of the configuration rules of the storage domains, and the configuration rules of the storage domains are finally determined.
[0036] See also Figure 3 This is the first application scenario of the present application. The starting address (lowest address) of the non-volatile memory is fb, and the ending address (highest address) is ft. The code partition is located in a relatively low address segment, and the highest address of the code partition is ab. The data partition is located in a relatively high address segment, and the lowest address of the data partition is at.
[0037] See also Figure 4 This is the second application scenario of the present application. The starting address (lowest address) of the non-volatile memory is fb, and the ending address (highest address) is ft. The data partition is located in a relatively low address segment, and the highest address of the data partition is ab. The code partition is located in a relatively high address segment, and the lowest address of the code partition is at.
[0038] comprehensive Figure 3 , Figure 4 It can be seen that in any scenario, the highest address of the code partition or the data partition located in the lower address segment is ab, and the lowest address of the code partition or the data partition located in the higher address segment is at.
[0039] See also Figure 5 , the first embodiment (addition mode) of the recursive iterative algorithm in step S3 includes the following steps.
[0040] Step S51: Set the entire non-volatile storage domain as a storage domain. If used in application scenario 1, the cache attribute of the storage domain is set to non-cacheable. If used in application scenario 2, the cache attribute of the storage domain is set to write-through cache or write-back cache. Set variable 1 V1 to represent the address in the non-volatile memory, and its initial value is fb.
[0041] Step S52: In the size set of the storage domain, select a value that is closest to ab-V1 and ≤ab-V1 and is called S(i), and also select a value that is closest to ab-V1 and ≥ab-V1 and is called S(i+1), S(i+1)=2×S(i).
[0042] The storage domain size set refers to the set of sizes of all legal (available) storage domains, for example {32 bytes, 64 bytes, 128 bytes, ... 1GB, 2GB, 4GB}, where each value in the set is twice the previous value.
[0043] If the non-volatile memory is a flash memory, the partitions in the flash memory require 4K alignment, so the minimum partition is 4KB. In order to adapt to this partition situation, the size set of the storage domain is changed to {4KB, 8KB, 16KB, ... 1GB, 2GB, 4GB}, and each value in the set is twice the previous value.
[0044] Step S53: Determine whether S(i) is equal to ab-V1.
[0045] If yes, as used in application scenario 1, the area of size S(i) starting from variable 1 V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i) starting from variable 1 V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Next, enter step S55.
[0046] If not, go to step S54.
[0047] Step S54: Determine whether the value of V1+S(i+1) falls between ab and at.
[0048] If yes, as used in application scenario 1, the area of size S(i+1) starting from variable 1 V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i+1) starting from variable 1 V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Next, proceed to step S55.
[0049] If not, as used in application scenario 1, the area of size S(i) starting from variable 1 V1 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i) starting from variable 1 V1 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Change the value of variable 1 V1 to V1+S(i), and return to step S52.
[0050] Step S55: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0051] See also Figure 6 , the second embodiment (subtraction mode) of the recursive iterative algorithm in step S3 includes the following steps.
[0052] Step S61: Set the entire non-volatile storage domain as a storage domain. If used in application scenario one, the cache attribute of the storage domain is set to non-cacheable. If used in application scenario two, the cache attribute of the storage domain is set to write-through cache or write-back cache. In the size set of the storage domain, select a value that is closest to at-fb and ≥ at-fb and is called S_init. If used in application scenario one, the area of S_init size starting from fb toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. If used in application scenario two, the area of S_init size starting from ft toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Set variable two V2 to represent the address in the non-volatile memory, and its initial value is fb+S_init.
[0053] Step S62: In the size set of the storage domain, select a value that is closest to V2-at and ≤V2-at and is called S(i), and also select a value that is closest to V2-at and ≥V2-at and is called S(i+1), S(i+1)=2×S(i).
[0054] Step S63: Determine whether S(i) is equal to V2-at.
[0055] If yes, as used in application scenario 1, the area of size S(i) starting from variable 2 V2 toward the lower address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i) starting from variable 2 V2 toward the higher address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Next, proceed to step S65.
[0056] If not, go to step S64.
[0057] Step S64: Determine whether the value of V2-S(i+1) falls between ab and at.
[0058] If yes, as used in application scenario 1, the area of size S(i+1) starting from variable 2 V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i+1) starting from variable 2 V2 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Next, proceed to step S65.
[0059] If not, as used in application scenario 1, the area of size S(i) starting from variable 2 V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache. As used in application scenario 2, the area of size S(i) starting from variable 2 V2 toward the low address direction is divided into a storage domain, and its cache attribute is set to non-cacheable. Change the value of variable 2 V2 to V2-S(i), and return to step S62.
[0060] Step S65: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
[0061] See also Figure 7 , the third embodiment (addition mode and subtraction mode) of the recursive iterative algorithm in step S3 includes the following steps.
[0062] Step S71: Adopting the addition mode to obtain the divided storage domain, as shown in step S51 to step S55; also adopting the subtraction mode to obtain the divided storage domain, as shown in step S61 to step S65.
[0063] Step S72: Compare the number of storage domains divided by the addition mode and the number of storage domains divided by the subtraction mode, and select the smaller number as the final divided storage domain. If the number of storage domains divided by the two modes is the same, select the storage domain divided by either mode as the final divided storage domain.
[0064] See also Figure 8 The storage domain automatic partitioning device of the embedded system proposed in the present application includes a compiling processing unit 1, a burning processing unit 2 and a starting processing unit 3. Figure 8 The device shown is Figure 1 The method shown corresponds to .
[0065] The compiling processing unit 1 is used to compile the configuration rules of the storage domain into an image file during the code compiling stage of the embedded system. The configuration rules of the first part of the storage domain that is not associated with the partition information of the non-volatile memory are solidified into code, and one or more parameters are set in the configuration rules of the second part of the storage domain that is associated with the partition information of the non-volatile memory, and different values of these parameters represent different storage domain division situations.
[0066] The burning processing unit 2 is used to partition the non-volatile memory during the code burning stage of the embedded system, including at least three partitions: a partition table, a code partition, and a data partition. One or more partitions with no requirements for cache attributes are set between the code partition and the data partition. Then the partition information is burned into the partition table, and the image file of the configuration rules of the storage domain is burned into the code partition.
[0067] The startup processing unit 3 is used to automatically divide the storage domain of the non-volatile memory according to the partition information in the partition table using a recursive iterative algorithm when the embedded system starts running, so as to achieve the following three goals. (1) The cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache. (2) The cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable. (3) The entire non-volatile memory has the least number of storage domains. Then, the information of the divided storage domains is used as the values of the various parameters of the mirror file of the configuration rules of the storage domains, and the configuration rules of the storage domains are finally determined.
[0068] Compared with the prior art, the method for automatically dividing storage domains of an embedded system proposed in this application has the following beneficial effects.
[0069] First, when the embedded system is running, the automatic division of the storage domain is completed dynamically and flexibly according to the partitioning of the non-volatile memory that can only be determined in the burning stage. Therefore, the present application can be applied to non-volatile memories with various partitioning conditions, rather than non-volatile memories with a specific partitioning condition fixed in the code.
[0070] Second, through the optimal screening of the recursive iterative algorithm, the minimum number of valid and legal storage domain combinations is obtained, and the limited number of storage domains is efficiently utilized.
[0071] The above are only preferred embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should all be included in the protection scope of the present application.
Claims
1. A method for automatically dividing storage domains of an embedded system, characterized in that: The method comprises the following steps: Step S1: Divide the configuration rules of the storage domain into two parts, the first part is the configuration rules that are not associated with the partition information of the non-volatile memory, and the second part is the configuration rules that are associated with the partition information of the non-volatile memory; in the code compilation stage of the embedded system, compile the configuration rules of the storage domain into an image file, wherein the configuration rules of the first part are solidified into code, and one or more parameters are set in the configuration rules of the second part, and different values of these parameters represent different storage domain division situations; Step S2: During the code burning phase of the embedded system, the non-volatile memory is partitioned to include at least three partitions: a partition table, a code partition, and a data partition; one or more partitions having no requirements on cache attributes are set between the code partition and the data partition; Then, the partition information is burned into the partition table, and the image file of the configuration rules of the storage domain is burned into the code partition; Step S3: When the embedded system starts running, the storage domain of the non-volatile memory is automatically divided using a recursive iterative algorithm according to the partition information in the partition table to achieve the following three goals; (1) The cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache; (2) The cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable; (3) The entire non-volatile memory has a minimum number of storage domains; Then, the information of the divided storage domains is used as the values of various parameters of the mirror file of the configuration rule of the storage domain, and the configuration rule of the storage domain is finally determined.
2. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: In the step S1, the configuration rules of the second part of the storage domain include: a storage domain base address, a storage domain size, and a cache attribute of the storage domain.
3. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: In the step S2, the partition information includes a partition name, a partition address, and a partition size.
4. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: The starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the code partition is lower than the address segment of the data partition, the highest address of the code partition is ab, and the lowest address of the data partition is at; In step S3, the recursive iterative algorithm includes the following steps: Step S51: setting the entire non-volatile storage domain as a storage domain, and setting the cache attribute of the storage domain as non-cacheable; Set variable V1 to represent the address in the non-volatile memory, and its initial value is fb; Step S52: In the size set of the storage domain, select a value that is closest to ab-V1 and ≤ ab-V1 and is called S(i), and select a value that is closest to ab-V1 and ≥ ab-V1 and is called S(i+1); Step S53: determine whether S(i) is equal to ab-V1; If yes, the area of size S(i) starting from variable 1 V1 toward the higher address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then proceed to step S55; If not, proceed to step S54; Step S54: determine whether the value of V1+S(i+1) falls between ab and at; If yes, the area of size S(i+1) starting from variable 1 V1 toward the higher address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; then proceed to step S55; If not, the area of size S(i) starting from variable 1 V1 toward the higher address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; Change the value of variable 1 V1 to V1+S(i), and return to step S52; Step S55: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
5. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: The starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the data partition is lower than the address segment of the code partition, the highest address of the data partition is ab, and the lowest address of the code partition is at; In step S3, the recursive iterative algorithm includes the following steps: Step S51: setting the entire non-volatile storage domain as a storage domain, and setting the cache attribute of the storage domain to write-through cache or write-back cache; Set variable V1 to represent the address in the non-volatile memory, and its initial value is fb; Step S52: In the size set of the storage domain, select a value that is closest to ab-V1 and ≤ ab-V1 and is called S(i), and select a value that is closest to ab-V1 and ≥ ab-V1 and is called S(i+1); Step S53: determine whether S(i) is equal to ab-V1; If yes, the area of size S(i) starting from variable 1 V1 toward the lower address is divided into a storage domain, and its cache attribute is set to non-cacheable; Next, proceed to step S55; If not, proceed to step S54; Step S54: determine whether the value of V1+S(i+1) falls between ab and at; If yes, the area of size S(i+1) starting from variable 1 V1 and heading toward the lower address is divided into a storage domain, and its cache attribute is set to non-cacheable; Next, proceed to step S55; If not, the area of size S(i) starting from variable 1 V1 toward the lower address is divided into a storage domain, and its cache attribute is set to non-cacheable; Change the value of variable 1 V1 to V1+S(i), and return to step S52; Step S55: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
6. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: The starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the code partition is lower than the address segment of the data partition, the highest address of the code partition is ab, and the lowest address of the data partition is at; In step S3, the recursive iterative algorithm includes the following steps: Step S61: the entire non-volatile storage domain is set as a storage domain, and the cache attribute of the storage domain is set as non-cacheable; in the size set of the storage domain, a value closest to at-fb and ≥ at-fb is selected as S_init, and the area of S_init size starting from fb toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; Set variable 2 V2 to represent the address in the non-volatile memory, and its initial value is fb+S_init; Step S62: In the size set of the storage domain, select a value that is closest to V2-at and ≤ V2-at and is called S(i), and select a value that is closest to V2-at and ≥ V2-at and is called S(i+1); Step S63: Determine whether S(i) is equal to V2-at; If yes, the area of size S(i) starting from variable 2 V2 and heading toward the lower address is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; Next, proceed to step S65; If not, proceed to step S64; Step S64: determine whether the value of V2-S(i+1) falls between ab and at; If yes, the area of size S(i+1) starting from variable 2 V2 and heading toward the higher address is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; Next, proceed to step S65; If not, as used in application scenario 1, the area of size S(i) starting from variable 2 V2 toward the high address direction is divided into a storage domain, and its cache attribute is set to write-through cache or write-back cache; Change the value of variable 2 V2 to V2-S(i), and return to step S62; Step S65: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
7. The method for automatically dividing storage domains of an embedded system according to claim 1, characterized in that: The starting address of the non-volatile memory is fb, and the ending address is ft; the address segment of the data partition is lower than the address segment of the code partition, the highest address of the data partition is ab, and the lowest address of the code partition is at; In step S3, the recursive iterative algorithm includes the following steps: Step S61: the entire non-volatile storage domain is set as a storage domain, and the cache attribute of the storage domain is set as write-through cache or write-back cache; in the size set of the storage domain, a value closest to at-fb and ≥ at-fb is selected as S_init, and the area of S_init size starting from ft toward the lower address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; Set variable 2 V2 to represent the address in the non-volatile memory, and its initial value is fb+S_init; Step S62: In the size set of the storage domain, select a value that is closest to V2-at and ≤ V2-at and is called S(i), and select a value that is closest to V2-at and ≥ V2-at and is called S(i+1); Step S63: Determine whether S(i) is equal to V2-at; If yes, the area of size S(i) starting from variable 2 V2 and heading toward the higher address is divided into a storage domain, and its cache attribute is set to non-cacheable; Next, proceed to step S65; If not, proceed to step S64; Step S64: determine whether the value of V2-S(i+1) falls between ab and at; If yes, the area of size S(i+1) starting from variable 2 V2 and heading towards the lower address is divided into a storage domain, and its cache attribute is set to non-cacheable; Next, proceed to step S65; If not, the area of size S(i) starting from variable 2 V2 toward the lower address direction is divided into a storage domain, and its cache attribute is set to non-cacheable; Change the value of variable 2 V2 to V2-S(i), and return to step S62; Step S65: All the storage domains obtained are the divided storage domains; the later the storage domain is established, the higher the priority of its configuration rule.
8. The method for automatically dividing storage domains of an embedded system according to any one of claims 4 to 7, characterized in that: The storage domain size set refers to the set of sizes of all legal storage domains, which is {32 bytes, 64 bytes, 128 bytes, ..., 1GB, 2GB, 4GB}, and each value in the set is twice the previous value; If the non-volatile memory is a 4K-aligned flash memory, the size set of the storage domain is changed to {4KB, 8KB, 16KB, ... 1GB, 2GB, 4GB}, and each value in the set is twice the previous value.
9. The method for automatically dividing storage domains of an embedded system according to any one of claims 4 to 7, characterized in that: In step S3, the recursive iterative algorithm includes the following steps: Step S71: using steps S51 to S55 to obtain a divided storage domain, which is called an addition mode; and also using steps S61 to S65 to obtain a divided storage domain, which is called a subtraction mode; Step S72: comparing the number of storage domains divided by the addition mode and the number of storage domains divided by the subtraction mode, and selecting the storage domain with the smaller number as the final divided storage domain; If the number of storage domains divided by the two modes is the same, the storage domain divided by any one mode is selected as the final divided storage domain.
10. A device for automatically dividing storage domains of an embedded system, characterized in that: It includes a compiling processing unit, a burning processing unit and a starting processing unit; The compiling processing unit is used to compile the configuration rules of the storage domain into an image file during the code compiling stage of the embedded system; The configuration rules of the first part of the storage domain that is not associated with the partition information of the non-volatile memory are solidified into codes, and one or more parameters are set in the configuration rules of the second part of the storage domain that is associated with the partition information of the non-volatile memory, and different values of these parameters represent different storage domain division situations; The burning processing unit is used to partition the non-volatile memory during the code burning stage of the embedded system, including at least three partitions: a partition table, a code partition, and a data partition; one or more partitions with no requirements for cache attributes are set between the code partition and the data partition; Then, the partition information is burned into the partition table, and the image file of the configuration rules of the storage domain is burned into the code partition; The startup processing unit is used to automatically divide the storage domain of the non-volatile memory using a recursive iterative algorithm according to the partition information in the partition table when the embedded system is started and run, so as to achieve the following three goals; (1) The cache attribute in the highest priority configuration rule of the storage domain to which the complete code partition belongs is write-through cache or write-back cache; (2) The cache attribute in the highest priority configuration rule of the storage domain to which the complete data partition belongs is non-cacheable; (3) The entire non-volatile memory has a minimum number of storage domains; Then, the information of the divided storage domains is used as the values of various parameters of the mirror file of the configuration rule of the storage domain, and the configuration rule of the storage domain is finally determined.
