Method for accessing flash memory and control device

By monitoring the CPU read status signal and distinguishing the acquisition vector entry address and the program read data, the problem of being unable to obtain the interrupt vector entry address under read protection of the main flash array is solved, achieving safe access and reducing capacity pressure in the read protection state. .

CN118626419APending Publication Date: 2024-09-10PUYA SEMICON SHANGHAI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410808802.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-21
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

When the main array of flash memory is in a read-protected state, the existing technology cannot obtain the entry address of the interrupt vector, resulting in failure of interrupt exception handling and exacerbating the capacity pressure on the SRAM and boot array.

Method used

By monitoring the status signal of the CPU reading vector, we distinguish between the two states of obtaining the vector entry address and the program reading the data. Access is allowed in the first state and access is denied in the second state, thereby obtaining the vector entry in the read protection state. address.

Benefits of technology

It realizes obtaining the vector entry address when the main flash memory array is in read-protected state, reducing the capacity pressure of SRAM and boot array, and ensuring the protection of the program to prevent leakage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626419A
    Figure CN118626419A
Patent Text Reader

Abstract

In the method for accessing the flash memory, when a main array of the flash memory is in a read protection state, the step of accessing the main array during abnormal processing of a CPU comprises the following steps: monitoring a state signal of a CPU read vector, the state signal is divided into at least two states, the first state indicates that the read vector is in a state of obtaining a vector entry address, and the second state indicates that the read vector is in a state of obtaining a vector entry address; the second state indicates that the read vector is in a state that the program reads the data. And controlling the access according to the state signal: when the state signal is in the first state, allowing the access. When the state signal is in the second state, access is denied. The invention further discloses a device for accessing the flash memory. According to the invention, the vector entry address can be obtained when the main array of the flash memory is in the read protection state.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of semiconductor integrated circuits, and in particular to a method for accessing a flash memory (FLASH). The present invention also relates to a control device for accessing a flash memory. Background Art

[0002] like Figure 1 As shown in the figure, it is the memory structure of existing embedded flash memory products. In most embedded FLASH product applications, there are Figure 1 As shown in the memory structure, the storage structure of the flash memory includes the main array 105 (main array), the boot array 106 (boot array) and the SRAM 108, namely SRAM+main FLASH+Boot FLASH. The main FLASH is the main array, and the Boot FLASH is the boot array.

[0003] CPU 101 is connected to a flash memory array composed of a system bus 102 (system bus), a bus matrix 103 (busmatrix), a main array 105, and a boot array 106, and an SRAM 108 through a bus, wherein the flash memory array needs to be further connected through a flash memory controller interface 104 (FLASH ctrl interface), and the SRAM 108 needs to be further connected through an SRAM controller interface 107 (SRAM ctrl interface).

[0004] The main FLASH often has a much larger capacity than SRAM and Boot FLASH, and SRAM has to bear the capacity pressure of temporary storage during CPU program execution, so user programs are generally placed in the main FLASH. In order to protect user programs, the main FLASH is often configured as a read-protected state to ensure that user programs can only be executed but not read as data.

[0005] In the case where the main FLASH is configured as read protection, the program located in the SRAM or Boot FLASH cannot read the data in the main FLASH. Figure 2 As shown, it is a flow chart of CPU accessing flash memory under existing read protection; step S101 indicates CPU accessing main FLASH under read protection, step S102 indicates instruction reading, and step S103 indicates data reading. Step S104 indicates permission, that is, access to read instruction is allowed, that is, step S102 is allowed; step S105 indicates disallowance, that is, data reading is not allowed, which is the function after read protection is set, so as to protect user programs and prevent user program leakage.

[0006] However, during the CPU processing, if an interrupt exception needs to be handled, the entry address of the interrupt vector must be obtained first before jumping to the interrupt vector program. The action of obtaining the entry address is to read the constant, which is recognized by the bus as data reading. The configuration of read protection restricts the action of reading data. When handling exceptions, the CPU will fail to obtain the vector entry address, that is, Figure 2 Step S103 in the above method is not allowed to be performed. This is because in the existing method, the action of obtaining the vector entry address is identified as the data reading corresponding to step S103, and therefore is not allowed.

[0007] Therefore, in this application, the vector address cannot be mapped to the protected main FLASH, but can only be mapped to the SRAM or Boot FLASH in the above figure, which will increase the capacity pressure. Summary of the invention

[0008] The technical problem to be solved by the present invention is to provide a method for accessing a flash memory, which can obtain a vector entry address when the main array of the flash memory is in a read protection state. To this end, the present invention also provides a device for accessing the flash memory.

[0009] In order to solve the above technical problems, in the method for accessing a flash memory provided by the present invention, when the main array of the flash memory is in a read protection state, the steps of accessing the main array during CPU exception processing include:

[0010] A state signal of a CPU reading a vector is monitored, wherein the state signal is distinguished into at least two states, a first state indicating that the reading vector is in a state of obtaining a vector entry address, and a second state indicating that the reading vector is in a state of a program reading out data.

[0011] Controlling access according to the status signal includes:

[0012] When the state signal is in the first state, access is allowed.

[0013] When the state signal is in the second state, access is denied.

[0014] A further improvement is that the access of the CPU to the main array includes instruction reading and data reading.

[0015] The access to the main array during the CPU exception processing belongs to the data reading.

[0016] A further improvement is that the storage structure of the flash memory includes the main array, the startup array and the SRAM.

[0017] The entry addresses of user programs and interrupt vectors are stored in the main array.

[0018] A further improvement is that, when the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array.

[0019] A further improvement is that the status signal includes at least 1 bit of data representation.

[0020] When the state signal is 1, it is in the first state, and when the state signal is 0, it is in the second state.

[0021] Alternatively, when the state signal is 0, it is in the first state, and when the state signal is 1, it is in the second state.

[0022] A further improvement is that the status signal is stored in a register inside the CPU.

[0023] A further improvement is that the read protection state of the main array is set via an option byte.

[0024] In order to solve the above technical problems, in the control device for accessing the flash memory provided by the present invention, when the main array of the flash memory is in a read protection state, the control device is used to control access to the main array as follows during CPU abnormal processing:

[0025] A state signal of a CPU reading a vector is monitored, wherein the state signal is distinguished into at least two states, a first state indicating that the reading vector is in a state of obtaining a vector entry address, and a second state indicating that the reading vector is in a state of a program reading out data.

[0026] Controlling access according to the status signal includes:

[0027] When the state signal is in the first state, access is allowed.

[0028] When the state signal is in the second state, access is denied.

[0029] A further improvement is that the access of the CPU to the main array includes instruction reading and data reading.

[0030] The access to the main array during the CPU exception processing belongs to the data reading.

[0031] A further improvement is that the storage structure of the flash memory includes the main array, the startup array and the SRAM.

[0032] The entry addresses of user programs and interrupt vectors are stored in the main array.

[0033] A further improvement is that, when the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array.

[0034] A further improvement is that the status signal includes at least 1 bit of data representation.

[0035] When the state signal is 1, it is in the first state, and when the state signal is 0, it is in the second state.

[0036] Alternatively, when the state signal is 0, it is in the first state, and when the state signal is 1, it is in the second state.

[0037] A further improvement is that the status signal is stored in a register inside the CPU.

[0038] A further improvement is that the read protection state of the main array is set via an option byte.

[0039] A further improvement is that the control device is arranged in a flash memory controller.

[0040] The present invention adds the recognition of CPU behavior on the basis of performing read protection on the main array of the flash memory, that is, monitoring the state signal of the CPU reading the vector, and realizing the recognition of the CPU reading behavior by monitoring the obtained state signal, so that data reading can be divided into two situations, the first situation is to obtain the vector entry address, and the second situation is the program reading out the data. In the existing method, all data reading is not allowed during read protection, so the existing method cannot obtain the vector entry address. The method of the present invention, by monitoring the state signal, can distinguish the above two situations through the two states of the state signal, thereby realizing allowing the acquisition of the vector entry address and not allowing the program to read out the data; in this way, the present invention can not only realize the protection of the program stored in the main array to prevent leakage, but also can obtain the vector entry address, that is, obtain the entry address of the interrupt vector, so the present invention can obtain the vector entry address when the main array of the flash memory is in the read protection state.

[0041] In addition, since the present invention can obtain the vector entry address when the main array of the flash memory is in the read protection state, the entry address of the interrupt vector can also be mapped, i.e., stored in the main array; whereas in the existing method, since it is impossible to obtain the vector entry address when the main array of the flash memory is in the read protection state, the entry address of the interrupt vector cannot be stored in the main array and can only be stored in the boot array and SRAM, which will increase the capacity pressure, and the present invention can obviously reduce the capacity pressure of the boot array and SRAM. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] The present invention is further described in detail below with reference to the accompanying drawings and specific embodiments:

[0043] Figure 1 It is the memory structure of existing embedded flash memory products;

[0044] Figure 2 This is a flow chart of CPU accessing flash memory under existing read protection;

[0045] Figure 3 is a flow chart of a method for accessing a flash memory according to an embodiment of the present invention;

[0046] Figure 4 The present invention is a flowchart of a method for accessing a flash memory in which a CPU accesses a flash memory under read protection. DETAILED DESCRIPTION

[0047] like Figure 3 , which is a flow chart of a method for accessing a flash memory according to an embodiment of the present invention; in the method for accessing a flash memory according to an embodiment of the present invention, the main array 105 of the flash memory is in a read protection state, and the steps of accessing the main array 105 during CPU exception processing include:

[0048] Step S201, monitoring a state signal of a CPU reading a vector, wherein the state signal is distinguished into at least two states, a first state indicating that the read vector is in a state of obtaining a vector entry address, and a second state indicating that the read vector is in a state of a program reading out data.

[0049] Step S202, controlling access according to the status signal, including:

[0050] When the state signal is in the first state, access is allowed.

[0051] When the state signal is in the second state, access is denied.

[0052] The CPU's access to the main array 105 includes instruction reading and data reading. Figure 4 The above is a flowchart of CPU accessing flash memory under read protection using the method for accessing flash memory according to an embodiment of the present invention; step S301 represents CPU accessing main FLASH under read protection, step S302 represents instruction reading, and step S303 represents data reading.

[0053] In the method of the embodiment of the present invention, the access to the main array 105 during the CPU exception processing belongs to the data reading. Figure 3 The corresponding process of the embodiment of the present invention corresponds to the process corresponding to the data reading of step S303. Figure 4In the embodiment, step S303 is further divided into two cases. The first case corresponds to when the state signal is in the first state. At this time, the data reading corresponds to the acquisition vector entry address shown in step S304. Step S307 is allowed, that is, when the data reading is the acquisition vector entry address, the data reading is allowed, that is, the acquisition vector entry address is allowed. The second case corresponds to when the state signal is in the second state. At this time, the data reading corresponds to the program reading data shown in step S305. Step S308 is not allowed, that is, the data reading is not allowed, that is, the program reading data is not allowed, so that the program stored in the main array 105 can be protected to prevent leakage.

[0054] In the embodiments of the present invention, please also refer to Figure 1 As shown, the storage structure of the flash memory includes the main array 105 , the boot array 106 and the SRAM 108 .

[0055] The entry addresses of user programs and interrupt vectors are stored in the main array 105 .

[0056] When the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array 105 .

[0057] In the method of the embodiment of the present invention, the state signal includes at least 1 bit of data representation. The state signal is stored in a register inside the CPU.

[0058] In some embodiments, the state signal is 1 in the first state and the state signal is 0 in the second state. In other embodiments, the state signal is 0 in the first state and the state signal is 1 in the second state.

[0059] The read protection state of the main array 105 is set by option bytes.

[0060] The method of the embodiment of the present invention adds the recognition of CPU behavior on the basis of read protection of the main array 105 of the flash memory, that is, monitoring the state signal of the CPU reading the vector, and realizing the recognition of the CPU reading behavior by monitoring the obtained state signal, so that data reading can be divided into two situations, the first situation is to obtain the vector entry address, and the second situation is the program reading out the data. In the existing method, all data reading is not allowed during read protection, so the existing method cannot obtain the vector entry address. The method of the embodiment of the present invention, by monitoring the state signal, can distinguish the above two situations through the two states of the state signal, thereby realizing allowing the acquisition of the vector entry address and not allowing the program to read out the data; in this way, the method of the embodiment of the present invention can not only realize the protection of the program stored in the main array 105 to prevent leakage, but also can obtain the vector entry address, that is, obtain the entry address of the interrupt vector, so the method of the embodiment of the present invention can obtain the vector entry address when the main array 105 of the flash memory is in the read protection state.

[0061] In addition, since the method of the embodiment of the present invention can obtain the vector entry address when the main array 105 of the flash memory is in the read protection state, the entry address of the interrupt vector can also be mapped, that is, stored in the main array 105; in the existing method, since it is impossible to obtain the vector entry address when the main array 105 of the flash memory is in the read protection state, the entry address of the interrupt vector cannot be stored in the main array 105, and can only be stored in the startup array 106 and SRAM108, which will increase the capacity pressure. The method of the embodiment of the present invention can obviously reduce the capacity pressure of the startup array 106 and SRAM108.

[0062] In the control device for accessing the flash memory according to the embodiment of the present invention, when the main array 105 of the flash memory is in the read protection state, the control device is used to control the access to the main array 105 as follows during the CPU exception processing:

[0063] A state signal of a CPU reading a vector is monitored, wherein the state signal is distinguished into at least two states, a first state indicating that the reading vector is in a state of obtaining a vector entry address, and a second state indicating that the reading vector is in a state of a program reading out data.

[0064] Controlling access according to the status signal includes:

[0065] When the state signal is in the first state, access is allowed.

[0066] When the state signal is in the second state, access is denied.

[0067] The CPU's access to the main array 105 includes instruction reading and data reading.

[0068] In the embodiment of the present invention, the access to the main array 105 during the CPU exception processing belongs to the data reading.

[0069] In the embodiment of the present invention, please also refer to Figure 1 As shown, the storage structure of the flash memory includes the main array 105 , the boot array 106 and the SRAM 108 .

[0070] The entry addresses of user programs and interrupt vectors are stored in the main array 105 .

[0071] When the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array 105 .

[0072] In the embodiment of the present invention, the state signal includes at least 1 bit of data representation. The state signal is stored in a register inside the CPU.

[0073] In some embodiments, the state signal is 1 in the first state and the state signal is 0 in the second state. In other embodiments, the state signal is 0 in the first state and the state signal is 1 in the second state.

[0074] The read protection state of the main array 105 is set by option bytes.

[0075] In the embodiment of the present invention, the CPU internal status signal is used to distinguish between obtaining the vector entry address and the program reading data in the CPU data reading action, allowing the vector entry address to be obtained, but not allowing the program to read data, which is specifically manifested as follows:

[0076] Monitor the status signal of the read vector when the CPU exception processing

[0077] When the status signal is 1, the data read action is to obtain the vector entry address, and the program source is not restricted. When it is 0, the data read action is for the program to read out data, and the program source is restricted.

[0078] The embodiment of the present invention achieves the effect of adding a CPU behavior recognition method to the original FLASH read protection: when the data of the FLASH main array is read by a program, the access is denied;

[0079] When the CPU executes to fetch vector data by fetching instructions, access is allowed.

[0080] The present invention has been described in detail above through specific embodiments, but these do not constitute limitations of the present invention. Without departing from the principle of the present invention, those skilled in the art may also make many variations and improvements, which should also be considered as the protection scope of the present invention.

Claims

1. A method for accessing flash memory, It is characterized in that When the main array of the flash memory is in a read protection state, the steps of accessing the main array during CPU exception processing include: Monitoring a state signal of a CPU reading a vector, wherein the state signal is distinguished into at least two states, a first state indicating that the reading vector is in a state of obtaining a vector entry address, and a second state indicating that the reading vector is in a state of a program reading out data; Controlling access according to the status signal includes: When the state signal is in the first state, allowing access; When the state signal is in the second state, access is denied.

2. The method for accessing a flash memory according to claim 1, Features: The CPU's access to the main array includes instruction reading and data reading; The access to the main array during the CPU exception processing belongs to the data reading.

3. The method for accessing a flash memory according to claim 1, Features: The storage structure of the flash memory includes the main array, the boot array and the SRAM; The entry addresses of user programs and interrupt vectors are stored in the main array.

4. The method for accessing a flash memory as claimed in claim 3, Features: When the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array.

5. The method for accessing a flash memory as claimed in claim 1, Features: The state signal includes at least 1 bit of data representation; When the state signal is 1, it is in the first state; when the state signal is 0, it is in the second state; Alternatively, when the state signal is 0, it is in the first state, and when the state signal is 1, it is in the second state.

6. The method for accessing a flash memory as claimed in claim 5, Features: The status signal is stored in a register inside the CPU.

7. The method for accessing a flash memory according to claim 1, Features: The read protection state of the main array is set via option bytes.

8. A control device for accessing a flash memory, Features: When the main array of the flash memory is in a read protection state, the control device is used to control access to the main array as follows during CPU exception processing: Monitoring a state signal of a CPU reading a vector, wherein the state signal is distinguished into at least two states, a first state indicating that the reading vector is in a state of obtaining a vector entry address, and a second state indicating that the reading vector is in a state of a program reading out data; Controlling access according to the status signal includes: When the state signal is in the first state, allowing access; When the state signal is in the second state, access is denied.

9. The control device for accessing a flash memory according to claim 8, Features: The CPU's access to the main array includes instruction reading and data reading; The access to the main array during the CPU exception processing belongs to the data reading.

10. The control device for accessing a flash memory according to claim 8, Features: The storage structure of the flash memory includes the main array, the boot array and the SRAM; The entry addresses of user programs and interrupt vectors are stored in the main array.

11. The control device for accessing a flash memory according to claim 10, Features: When the state signal is in the first state, the CPU obtains the entry address of the interrupt vector by accessing the main array.

12. The control device for accessing a flash memory according to claim 8, Features: The state signal includes at least 1 bit of data representation; When the state signal is 1, it is in the first state; when the state signal is 0, it is in the second state; Alternatively, when the state signal is 0, it is in the first state, and when the state signal is 1, it is in the second state.

13. The control device for accessing a flash memory according to claim 12, Features: The status signal is stored in a register inside the CPU.

14. The control device for accessing a flash memory according to claim 8, Features: The read protection state of the main array is set via option bytes.

15. The control device for accessing a flash memory according to claim 8, Features: The control device is arranged in a flash memory controller.