Flash memory write protection method and device, electronic equipment and storage medium
By establishing a preset table and determining the target write protection mode based on the flash memory identifier, the problem of modification errors in flash write protection driver development is solved, achieving more efficient write protection operation and security.
Patent Information
- Application Number
- CN202211436317.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-16
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-11-16
AI Technical Summary
When developing flash write protection drivers, it is easy to make mistakes in modification, which may result in some or all areas being unwriteable, firmware being unable to be upgraded, and causing a large number of devices to be sent back to the factory for repair.
By establishing a preset table, the flash memory identifier is obtained and the target write protection mode is determined according to the preset table. The triggering conditions are processed using the target protection mode, supporting single block protection and BP bit protection. Single block protection is preferred, reducing the complexity of driver design.
It improves the correctness and security of flash write protection operations, avoids driver modification errors, and ensures that the flash memory effectively protects the preset area during initialization.
Smart Images

Figure CN115712586B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and more specifically, to a write protection method, apparatus, electronic device, and storage medium for flash memory. Background Technology
[0002] Currently, SPI NOR and SPI NAND flash memory are commonly used in embedded devices due to their small size and fewer pins. These flash memory types have built-in write protection mechanisms, such as BP (Block Protect) bit protection and Individual Block Protect. BP bit protection typically has 3-5 bits, and the protection level is configured by setting their combined values, with each protection level corresponding to a write-protected region. Individual Block Protect uses the flash memory's built-in configuration table, implementing write protection for the block containing the specified address through the operation address and specific instructions.
[0003] However, when developing write protection drivers for flash memory, many factors need to be considered. For example, when using BP bit protection, the bits of each register involved need to be modified accordingly. In addition, the flash memory driver may also modify the relevant registers. If these factors are not considered carefully, confusion will occur, which will prevent the designed program from deprotecting the flash memory. This will make it impossible to write to some or all areas of the flash memory, and the firmware itself will not be able to be upgraded. In the end, the devices with this flash memory can only be returned to the factory for repair, which may lead to a batch of accidents. Summary of the Invention
[0004] The purpose of this application is to provide a write protection method, apparatus, electronic device, and storage medium for flash memory, so as to improve the correctness of write protection for flash memory.
[0005] This invention is implemented as follows:
[0006] In a first aspect, embodiments of this application provide a write protection method for flash memory, comprising: when a trigger condition is triggered, obtaining an identifier of the flash memory; if the identifier represents an identifier existing in a preset table, determining a target write protection mode according to the preset table, wherein the preset table further includes relevant information on write protection of the flash memory corresponding to the identifier; and processing the operation corresponding to the trigger condition using the target write protection mode based on the preset table.
[0007] In this embodiment, when a trigger condition is triggered, a flash memory identifier is obtained, and a target protection method is determined based on a preset table and the identifier. Based on the preset table, the operation corresponding to the trigger condition is processed using the target protection method. This enables write protection operations to be performed automatically based on the trigger condition and the preset table when the trigger condition is triggered. This eliminates the need for staff to develop a separate write protection driver for each flash memory, thereby avoiding errors in modification when developing the write protection driver for the flash memory and improving the correctness of write protection operations on the flash memory.
[0008] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, determining the target write protection mode according to the preset table includes: determining whether single-block protection is currently performed according to the preset table; if single-block protection is currently performed, processing the operation corresponding to the trigger condition using the target write protection mode based on the preset table includes: processing the operation corresponding to the trigger condition using the single-block protection based on the preset table.
[0009] In this embodiment, by first determining whether the flash memory can be protected by a single block according to a preset table, if single block protection can be performed, the operation corresponding to the trigger condition is processed by single block protection. When the flash memory supports both single block protection and BP bit protection at the same time, single block protection is preferred, so that a better write protection method can be used to write protect the flash memory.
[0010] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the triggering condition is the initialization of the flash memory driver, and the step of processing the operation corresponding to the triggering condition using the single-block protection based on the preset table includes: setting write protection for a preset protection area using the single-block protection based on the preset table.
[0011] In this embodiment of the application, when the flash memory driver is initialized, and after determining that single-block protection is currently being performed, single-block protection can be used to set write protection for a preset protection area. This allows the preset area to be written protected during flash memory initialization, thereby enabling protection of the preset area after flash memory initialization is completed, and thus improving the security of the flash memory.
[0012] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the triggering condition is the initialization of the flash memory driver, and the method further includes: if the single-block protection is not currently performed, then based on the preset table, write protection is set for the preset protection area using BP bit protection.
[0013] In this embodiment of the application, when the flash memory driver is initialized, and after determining that single-block protection is not currently performed, the BP bit protection can be used to set write protection for the preset protection area. This allows the preset area to be written protected during flash memory initialization, thereby enabling protection of the preset area after flash memory initialization is completed, and thus improving the security of the flash memory.
[0014] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the triggering condition is receiving an operation address, and the step of processing the operation corresponding to the triggering condition using the single-block protection based on the preset table includes: setting the flash memory to single-block protection mode based on the preset table; and issuing a command to perform a write protection operation on the operation address according to the operation address and the preset commands of the single-block protection.
[0015] In this embodiment of the application, when the operation address is received and it is determined that single-block protection can be performed, the flash memory can be set to single-block protection mode based on a preset table. Then, according to the operation address and the preset single-block protection commands, a command to perform write protection operation on the operation address is issued, thereby enabling write protection of the flash memory area corresponding to the operation address through single-block protection.
[0016] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the triggering condition is receiving an operation address, and the method further includes: if the single-block protection is not currently performed, then determining the protection level of the operation address based on the operation address and the preset table, wherein the operation address is the address for setting write protection or deprotection of the area range corresponding to the operation address, and the preset table also includes information on the protection levels corresponding to the flash memory corresponding to the identifier when the BP bit is protected; based on the protection level and the preset table, using BP bit protection to set write protection or deprotection of the area corresponding to the operation address.
[0017] In this embodiment, since the preset table contains information on the protection levels of the corresponding flash memory when the BP bit is protected, after receiving the operation address, the corresponding protection level can be directly found in the preset table based on the operation address, without having to calculate the protection level manually based on the write protection characteristics of each flash memory. This reduces the complexity and difficulty of flash driver design and facilitates subsequent maintenance.
[0018] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the step of using BP bit protection to write-protect or deprotect the region corresponding to the operation address based on the protection level and the preset table includes: determining from the preset table the preset values of each register that needs to be modified and some bits of each register corresponding to the protection level and the identifier; reading the current value of each register; modifying the current value according to the protection level and the preset value so that the BP bit corresponding to the current value is consistent with the protection level, and the corresponding bit of the current value is consistent with the preset value; and writing the modified current value back to each register.
[0019] In this embodiment, since the preset table includes preset values of each register and its partial bits corresponding to the protection level corresponding to each identifier, after reading the current value of each register, the current value of each register can be directly modified according to the preset values of each register and its partial bits corresponding to the protection level and identifier in the preset table, and the modified current value is written back to each register. In this way, the correctness of the value rewritten back to each register can be improved, and the situation where the current value of the register is read incorrectly but the current value of the register is not modified, resulting in an error when writing back the value to the register, can be avoided as much as possible.
[0020] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the operation address is a write-protected address, which is an address for setting write protection for the area range corresponding to the write-protected address. The step of determining the protection level of the operation address based on the operation address and the preset table includes: if the write-protected address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the larger area range corresponding to the protection level is determined as the protection level corresponding to the write-protected address.
[0021] In this embodiment of the application, since important data is usually write-protected, if the write protection address corresponds to an address in the preset table that is between two protection levels, then the protection level with the larger area corresponding to the protection level is determined as the protection level corresponding to the write protection address. This ensures that the area corresponding to the determined protection level includes the entire area corresponding to the write protection address, thereby achieving write protection for the area corresponding to the write protection address.
[0022] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the operation address is a deprotection address, which is an address for setting deprotection of the area range corresponding to the deprotection address. The step of determining the protection level of the operation address according to the operation address and the preset table includes: if the deprotection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the smaller area range corresponding to the protection level is determined as the protection level corresponding to the deprotection address.
[0023] In this embodiment of the application, if the deprotection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the smaller area corresponding to the protection level is determined as the protection level corresponding to the write protection address. This ensures that the area to be deprotected will not contain areas that are not required to be deprotected, that is, the area to be deprotected will not contain write protection areas other than the deprotection address, thereby improving the security of other write protection areas.
[0024] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, before setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the protection level and the preset table, the method further includes: determining that the protection level corresponding to the operation address is less than or equal to the maximum preset protection level, wherein the maximum preset protection level is the protection level corresponding to the preset protection region.
[0025] In this embodiment, before setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the determined protection level and preset table, it is first determined that the protection level corresponding to the operation address is less than or equal to the maximum preset protection level. This ensures that the region to be written protected is included in the preset flash memory region that can be written protected, thereby avoiding write protection operations on regions that do not need to be written protected.
[0026] In conjunction with the technical solution provided in the first aspect above, in some possible implementations, the method further includes: if the protection level corresponding to the operation address is greater than the maximum preset protection level, then based on the maximum preset protection level and the preset table, use BP bit protection to set write protection for the area corresponding to the maximum preset protection level.
[0027] In this embodiment, a protection level greater than the maximum preset protection level at the operation address indicates that write protection is applied to all areas capable of write protection, as well as some or all areas that do not require write protection. Possible scenarios where the protection level at the operation address exceeds the maximum preset protection level include: the protected area corresponding to the maximum preset protection level already encompasses the entire flash memory size, but the operation address exceeds the flash memory range; or the protected area corresponding to the maximum preset protection level does not encompass the entire flash memory size, but the operation address exceeds the protection range. When the protected area corresponding to the maximum preset protection level does not encompass the entire flash memory size, the unprotected area generally has special considerations. For example, the unprotected area may be a writable area that requires frequent erasure and rewriting. If write protection is applied to this area, it needs to be deprotected or rewritten during erasure and rewriting, which requires modifying the flash memory registers. Since some flash memory registers have a limited number of erase / write cycles, frequent modifications will quickly bring them to their lifespan limit. Therefore, in such applications, setting the protection level to not exceed the maximum preset protection level can effectively extend the lifespan of the flash memory.
[0028] Secondly, embodiments of this application provide a write protection device for flash memory, comprising: a processing module, configured to acquire an identifier of the flash memory when a trigger condition is triggered; a write protection module, configured to determine a target write protection mode according to a preset table if the identifier is present in the preset table, wherein the preset table further includes relevant information on write protection of the flash memory corresponding to the identifier; and to process the operation corresponding to the trigger condition using the target write protection mode based on the preset table.
[0029] Thirdly, embodiments of this application provide an electronic device, including: a processor and a memory, the processor and the memory being connected; the memory being used to store a program; the processor being used to invoke the program stored in the memory to execute the method provided by the embodiments of the first aspect described above and / or some possible implementations of the embodiments of the first aspect described above.
[0030] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, the computer program executing, when run by a processor, the methods provided as described in the first aspect embodiments and / or some possible implementations of the first aspect embodiments. Attached Figure Description
[0031] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0032] Figure 1 This is a flowchart illustrating the steps of a write protection method for flash memory provided in an embodiment of this application.
[0033] Figure 2 This is a module block diagram of a flash memory write protection device provided in an embodiment of this application.
[0034] Figure 3 This is a module block diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0035] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0036] Given that inadequate consideration during write protection of flash memory can lead to confusion, rendering self-designed programs unable to deprotect the flash memory, causing partial or complete write failures, and preventing firmware upgrades, ultimately necessitating the return of devices with the affected flash memory to the factory for repair, potentially resulting in mass incidents, the inventors of this application, through research and exploration, propose the following embodiments to solve the aforementioned problems.
[0037] First, before writing-protecting the flash memory, a preset table can be created. This preset table can include mnemonics, information, identifier 1 (flash memory name), ..., identifier n (flash memory name). The mnemonics can include the bits of each register involved in write protection, such as: WPS (Write Protect Selection), TB (Top / Bottom) / INV (Invert), CMP (Complementary), SEC (Sector), WPE (Write Protect Enable), SRP0 (Status Register Protect 0), SRP1 (Status Register Protect 1), QE (Quad Enable), ECC_E (Error Correcting Code_Enable), BP[n-1:0], etc. It can also include a string of characters that are easy to understand and describe, such as IsWr2Srs (register write mode) and IdFunction (special code identification function).
[0038] It should be noted that mnemonics are only for convenience. When describing the bits of the registers involved in write protection, try to make them the same as or similar to the definitions in most flash memory datasheets. However, the focus is on the function. For example, some BP bits are equivalent to TB and SEC, so these BP bits can be configured in TB and SEC.
[0039] The WPS bit can be set to 1 or 0. When set to 1, single-block protection is used. When using single-block protection, the configuration related to BP bit protection, such as BP[n-1:0], CMP, SEC, etc., can be ignored.
[0040] The TB / INV bit indicates whether the write-protected area starts from the bottom or top of the flash memory. If the TB / INV bit is 1, it means it starts from the bottom; if the TB / INV bit is 0, it means it starts from the top.
[0041] The CMP bit is used in conjunction with BP[n-1:0]. When the values of BP[n-1:0] are the same and the CMP bit is 0, a portion of the flash memory is protected. Conversely, when the CMP bit is 1, the rest of the flash memory is protected.
[0042] When the SEC bit is set to 1, it indicates that protection is performed by sector (4KB in size).
[0043] The WPE bit enables the WP pin for write protection. When the WPE bit is 1, it indicates that write protection is enabled; when the WPE bit is 0, it indicates that write protection is disabled.
[0044] QE is used to enable Quad SPI (Quad Serial Peripheral Interface) and QPI (Quad Peripheral Interface) modes.
[0045] The ECC_E bit is used to enable or disable the built-in error correction code algorithm in the flash memory. It should be noted that the ECC_E bit is currently only required for SPI NAND Flash.
[0046] IsWr2Srs refers to whether register 1 and register 2 need to be operated on simultaneously (i.e., written) during write protection operations.
[0047] BP[n-1:0] is present in all flash memory, invariably located in flash memory register 1. The bit offset is fixed for flash memory of the same type, so the register number and bit offset do not need to be listed in the default table; they only need to be defined directly in the flash memory driver. However, the number of valid BP bits is not fixed and can be configured in the default table. The number of bits may vary depending on the flash memory type, typically 3 to 5 bits. n bits of BP[n-1:0] form a binary number, corresponding to a write protection level, with each level corresponding to a protection range. The binary number formed by BP[n-1:0] takes values from 0 to 2. nFor example, if a flash memory has 5 bits (n=5), then the value ranges from 0 to 32, meaning there are a maximum of 33 protection levels. Level 0 indicates that the entire flash memory area is not write-protected. In practice, some binary values composed of BP[n-1:0] may correspond to the same protection range, meaning that the number of available protection levels is less than 2. n Some BP bits have functions equivalent to TB and SEC in the embodiments of this application, so these BP bits can be configured in TB and SEC instead of being used as protection level configuration bits.
[0048] `IdFunction` points to a method (function) that returns a special code, typically used in conjunction with the flash memory ID to uniquely identify different flash memories in a predefined table. When the flash memory ID itself is unique, `IdFunction` can point to a default implementation. This default implementation returns its own defined default special code, such as 0. When `IdFunction` points to an empty implementation, it can be used for special handling, indicating that the identification code is the flash memory ID (i.e., identification is based solely on the flash memory ID). Only when a new flash memory has the same ID as an existing one in the table, but its parameters are different, is it necessary to add a new method and have `IdFunction` point to that method. This method can return a special code that distinguishes the new flash memory from an existing flash memory with the same ID, based on some distinguishing characteristic.
[0049] The information corresponding to WPS, TB, CMP, SEC, WPE, SRP0, SRP1, QE, and ECC_E can be: existence, register number, bit offset, and bit value; the information corresponding to BP[n-1:0] can be: the number of bits of BP, protection level, and protection range list; the information corresponding to IsWr2Srs can be: whether registers 1 and 2 need to be written simultaneously; the information corresponding to IdFunction can be: the flash memory identification function, or it can be empty.
[0050] For example, please refer to Table 1, which is a preset table provided in the embodiments of this application.
[0051] Table 1
[0052]
[0053] It should be noted that in Table 1, the mnemonics "WPS, TB, CMP, SEC, WPE, SRP0, SRP1, QE, ECC_E" are grouped together to indicate that they all require corresponding information, which can be: existence, register number, bit offset, and bit value. In actual implementation, each needs to be registered individually. Some of these bit values need to be directly set when implementing write protection, while others reside in the same register as the bits that need direct setting, and may be tampered with during write-back. Therefore, they need to be recorded in Table 1 for verification when setting the write protection register. The identification code must be unique. It can be the flash memory's built-in ID (flash ID) or a user-defined ID. For example, the identification code can consist of the flash ID and a special code. Since the built-in ID number of flash memory is generally composed of 2 or 3 bytes of hexadecimal numbers, for consistency, the flash ID can be set to 3 bytes; if it is less than 3 bytes, the high byte can be padded with 0. The special code can be 1 byte, which can be used to solve the problem of flash IDs being the same but parameters being different, making them indistinguishable.
[0054] In addition, the number of identification codes can be set according to the actual situation. For example, when there is only one flash memory initially, the preset table can include identification code 1 and the corresponding contents of identification code 1. As the number of flash memory increases, the identification codes and contents corresponding to the newly added flash memory can be added to the preset table in sequence. For another example, if there are 5 flash memory initially, when setting the preset table, the preset table can include identification code 1, identification code 2, identification code 3, identification code 4 and identification code 5, and the corresponding contents of each identification code.
[0055] When adding a flash memory to the preset table, first check if an identification code with the same flash memory ID as the new flash memory already exists in the preset table; if an identification code with the same flash memory ID as the new flash memory exists, check if the information corresponding to the identification code is consistent with the information of the new flash memory; if the information corresponding to the identification code is consistent with the information of the new flash memory, then there is no need to add the flash memory, but you can mark it in the flash memory name to indicate that the identification code supports the flash memory for easy viewing later.
[0056] Correspondingly, if no identifier exists that matches the flash ID of the newly added flash memory, a new column can be added to the preset table. The flash ID of the newly added flash memory can be filled into the corresponding identifier in this column. Then, the relevant information of the newly added flash memory can be filled into the preset table according to the flash memory datasheet, and the IdFunction of the flash memory can be set to null. Alternatively, the identifier can be set to the flash memory ID and a special code. In this case, a new column can be added to the preset table. The 4-byte identifier composed of the flash ID of the newly added flash memory and the special code value can be filled into the corresponding identifier in this column. A function can be registered for the IdFunction of the flash memory to return the newly added special code. Then, the relevant information of the newly added flash memory can be filled into the preset table according to the flash memory datasheet.
[0057] Furthermore, if an identification code exists that is identical to the flash memory ID of the newly added flash memory, but the information corresponding to this identification code is inconsistent with that of the newly added flash memory, a new column can be added to the preset table. The 4-byte identification code, composed of the flash memory ID of the newly added flash memory and a special code value, can be filled into this column. This feature code is unique across all feature code values in the identification code with the same flash memory ID as the newly added flash memory; it can be the value of the largest existing feature code plus 1. A function is then registered for the IdFunction of this flash memory. This function can return the newly added special code based on the differences between the newly added flash memory and other flash memories with the same ID. Finally, the relevant information of the newly added flash memory is filled into the preset table according to the flash memory datasheet.
[0058] It is understandable that flash memory modules with the same ID but different special codes should have their IdFunction in the default table pointing to the same identification function. This function can determine the unique special codes of flash memory modules with the same ID based on their respective characteristics.
[0059] It should be noted that Table 1 is merely a schematic diagram of a preset table for easy understanding of the embodiments of this application. In practice, the preset table can be converted into a corresponding supported format and integrated into the driver according to the driver of the flash memory device and the programming language used. Table 1 only lists the parameters that require special handling when writing to common flash memory. When adding new flash memory in the future, other bits that require special handling may be encountered. In this case, the relevant information of the new flash memory can be filled into the table with reference to the foregoing description. For different flash memory, bits that do not exist can be deleted from the converted preset table. For example, if the WPS bit does not exist in the SPI NAND Flash, the WPS bit can be deleted when setting the SPI NAND Flash in the preset table; for another example, if the ECC_E bit does not exist in the SPI NOR Flash, the ECC_E bit can be deleted when setting the SPI NOR Flash in the preset table. In addition, if the flash memory supports single-block protection and single-block protection can be used for the flash memory, WPS can be set to 1, and items related to BP bit protection can be deleted, such as TB, CMP, SEC, and BP[n-1:0], which do not need to be configured. In this way, when converting Table 1 into the table required for the actual flash driver, only the relevant parameters that exist can be retained. This makes the driver more concise and clear, reduces the size of the driver, and facilitates maintenance.
[0060] After the preset table is set up, it can be converted into the corresponding supported format according to the driver of the flash memory device and the programming language used, and then integrated into the driver.
[0061] The following combination Figure 1The specific process and steps of a write protection method for flash memory are described. This application provides a write protection method for flash memory, applicable to flash memory drivers.
[0062] It should be noted that the flash memory write protection method provided in this application embodiment is not based on... Figure 1 The following order is a restriction.
[0063] Step S101: When the trigger condition is triggered, obtain the flash memory identifier.
[0064] The aforementioned identifier may be a flash memory ID, or it may include a flash memory ID and a special code.
[0065] When the identifier is a flash memory ID, the flash memory driver can read the flash memory ID to obtain the identifier when the trigger condition is met. After obtaining the identifier, it can be compared with the identifiers in the preset table. If an identifier matching the identifier exists in the preset table, then the identifier indicates that it exists in the preset table. Conversely, if no identifier matching the identifier exists in the preset table, it means that the current flash memory driver does not support write protection operations for this flash memory, and any subsequent write protection operations can be disabled in the driver.
[0066] When the identifier includes a flash memory ID and a special code, the method for obtaining the identifier is as follows: first, read the flash memory ID of the flash memory, then call the function of IdFunction registered in the preset table one by one to obtain the special code; after obtaining the flash memory ID and the special code each time, combine the flash memory ID and the special code. If the combination is the same as the identification code corresponding to the currently called IdFunction column in the preset table, the above identifier is obtained, and the identifier indicates that the identifier exists in the preset table.
[0067] In addition, the flash ID of the flash memory can be read first; after obtaining the flash ID, the identification codes in the preset table are traversed to find the identification code that includes the flash ID; after finding the identification code, the function registered to IdFunction for the identification code is called to obtain the special code; after obtaining the special code, the flash ID is combined with the special code. If the combination is the same as the identification code corresponding to the IdFunction column currently called in the preset table, the above-mentioned identifier is obtained, and the identifier indicates that the identifier exists in the preset table.
[0068] It should be noted that if no special code is found using the above method, it means that the current flash memory driver does not support write protection for the flash memory, and any subsequent write protection operations can be disabled in the driver.
[0069] After obtaining the identifier of the flash memory, step S102 can be performed.
[0070] Step S102: If the identifier exists in the preset table, then determine the target write protection method according to the preset table.
[0071] The preset table also includes information about the write protection of the corresponding flash memory. It should be noted that the contents of the preset table can be found in the aforementioned instructions on creating the preset table; to avoid redundancy, they will not be repeated here. Furthermore, the target write protection method can be BP bit write protection or single-block protection.
[0072] Optionally, determining the target write protection mode based on the preset table may specifically include: determining whether to perform single-block protection based on the preset table.
[0073] Specifically, the system searches the preset table for the WPS bit corresponding to the flash memory and determines whether the WPS bit exists. If the WPS bit exists, it is determined that single-block protection is currently in use. Checking whether the WPS bit exists can be done by checking if the WPS bit value is 1. If the WPS bit value is 1, it is determined that single-block protection is currently in use.
[0074] It should be noted that whether single-block protection is currently enabled can be preset in the WPS bit of the preset table according to the usage of the flash memory. For example, if flash memory 1 supports single-block operation and BP bit operation, and single-block operation is preferred when using flash memory 1, then the WPS bit corresponding to flash memory 1 can be set to 1 in the preset table; or if flash memory 2 supports single-block protection and BP bit operation, but BP bit operation is selected when using flash memory 2, then the WPS bit corresponding to flash memory 2 can be set to 0 in the preset table.
[0075] After determining the target write protection mode, this method can continue to step S103.
[0076] Step S103: Based on the preset table, process the operation corresponding to the trigger condition using the target write protection method.
[0077] After determining the target protection method, the operation corresponding to the trigger condition can be processed using the target protection method based on the preset table. For example, if the target write protection method is determined to be BP bit protection, the operation corresponding to the trigger condition can be processed using the BP bit protection method based on the preset table; or if the target write protection method is determined to be single block protection, the operation corresponding to the trigger condition can be processed using single block protection based on the preset table.
[0078] In this embodiment, when a trigger condition is triggered, a flash memory identifier is obtained, and a target protection method is determined based on a preset table and the identifier. The operation corresponding to the trigger condition is then processed using the target protection method. This enables write protection operations to be performed automatically based on the trigger condition and the preset table when the trigger condition is triggered. This eliminates the need for staff to develop a separate write protection driver for each flash memory, thereby avoiding errors in modification when developing the write protection driver for the flash memory and improving the correctness of write protection operations on the flash memory.
[0079] Optionally, if single-block protection is currently in effect, the above-mentioned processing of the operation corresponding to the trigger condition using the target write protection method based on the preset table may specifically include: processing the operation corresponding to the trigger condition using single-block protection based on the preset table.
[0080] The commands involved in single-block protection include: global block lock for writing to the entire flash memory, global block unlock for writing to the entire flash memory, read block lock for reading a specific address, individual block lock for writing to a specific block, and individual block unlock for writing to a specific block. Furthermore, processing the operations corresponding to the trigger conditions using single-block protection can specifically include: applying different single-block protection commands based on the trigger conditions.
[0081] It should be noted that the commands involved in single-block protection and the specific principles of single-block protection operation can be referred to in the existing technology, and will not be elaborated here to avoid redundancy.
[0082] In this embodiment of the application, by first determining whether the flash memory can be protected by a preset table, if it can be protected by a single block, the operation corresponding to the trigger condition is processed by using single block protection based on the preset table. When the flash memory supports both single block protection and BP bit protection at the same time, single block protection is preferred, so that a better write protection method can be used to protect the flash memory from write.
[0083] Furthermore, the write protection method for the aforementioned flash memory may also include: if single-block protection is not currently performed, then based on a preset table, BP bit protection is used to process the operation corresponding to the trigger condition.
[0084] Specifically, after finding the identification code corresponding to the flash memory, if the WPS bit corresponding to the identification code does not exist, that is, the WPS bit is not 1, it can be determined that single-block protection will not be performed at present. At this time, the BP bit protection can be used to process the operation corresponding to the trigger condition based on the preset table.
[0085] It should be noted that when using BP bit protection to process operations corresponding to trigger conditions, the corresponding processing can be performed according to the item in the preset table that corresponds to BP bit protection. Furthermore, the specific principle of BP bit protection can be found in existing technologies, and will not be elaborated upon here to avoid further explanation.
[0086] Optionally, when the trigger condition is the initialization of the flash memory driver, the above-mentioned processing of the operation corresponding to the trigger condition using single-block protection based on the preset table may specifically include: setting write protection for the preset protection area using single-block protection based on the preset table.
[0087] The preset area can be the entire flash memory or a portion of it. Understandably, this preset area can be set according to actual needs; for example, an area storing important data can be set as the preset area; or an area storing data that needs to be protected from arbitrary tampering can be set as the preset area.
[0088] In this embodiment of the application, when the flash memory driver is initialized, and after determining that single-block protection is currently being performed, write protection settings can be applied to the preset protection area based on a preset table. This allows the preset area to be write protected during flash memory initialization, thereby enabling protection of the preset area after flash memory initialization is completed, and thus improving the security of the flash memory.
[0089] Optionally, when the trigger condition is the initialization of the flash memory driver, the above flash memory write protection method may further include: if single-block protection is not currently performed, then write protection settings for the preset protection area are performed based on a preset table using BP bit protection.
[0090] For a description of the preset area, please refer to the description of the preset area in the previous embodiments. To avoid redundancy, it will not be described here.
[0091] It is understandable that when using BP bit protection to process operations corresponding to trigger conditions, the corresponding processing can be performed according to the item in the preset table that corresponds to BP bit protection. Furthermore, the specific principle of BP bit protection can be found in existing technologies, and will not be elaborated upon here to avoid further explanation.
[0092] In this embodiment of the application, when the flash memory driver is initialized, and after determining that no single block protection is currently performed, write protection settings for a preset protection area can be configured based on a preset table using BP bit protection. This allows write protection of the preset area to be achieved through BP bit protection during flash memory initialization, thereby enabling protection of the preset area after flash memory initialization is completed, and thus improving the security of the flash memory.
[0093] Optionally, when the trigger condition is receiving an operation address, the above-mentioned processing of the operation corresponding to the trigger condition using single-block protection based on the preset table may specifically include: setting the flash memory to single-block protection mode based on the preset table; and issuing a command to perform a write protection operation on the operation address according to the operation address and the preset single-block protection commands.
[0094] Specifically, setting the flash memory to single-block protection mode based on the preset table can include: setting the register used to determine whether to perform single-block protection according to the preset table to represent the current state of using single-block protection mode. For example, the WPS bit register and bit offset in the preset table can be referenced to set the WPS bit of the flash memory to 1, so that the flash memory can be set to single-block protection mode.
[0095] The preset single-block protection commands may include: global block lock for writing to the entire flash memory, global block unlock for writing to the entire flash memory, read block lock for reading a specific address, individual block lock for writing to a specific block, and individual block unlock for writing to a specific block. It should be noted that the specific principles behind the preset single-block protection commands, and the commands issued to perform write protection operations on the target address based on the target address and the preset single-block protection commands, can be found in existing technologies and will not be elaborated upon here.
[0096] In this embodiment of the application, upon receiving the operation address and after determining that single-block protection is currently possible, a command to perform a write protection operation on the operation address can be issued according to the operation address and the preset single-block protection commands, thereby enabling write protection of the flash memory area corresponding to the operation address through single-block protection.
[0097] Optionally, when the trigger condition is receiving an operation address, the above flash memory write protection method may further include: if single-block protection is not currently performed, determining the protection level of the operation address based on the operation address and a preset table; and using BP bit protection to set write protection or deprotection for the area corresponding to the operation address based on the protection level and the preset table.
[0098] The operation address is the address for setting write protection or deprotection of the area range corresponding to the operation address.
[0099] The preset table also includes information on the protection levels corresponding to the flash memory when the BP bit is protected. Each protection level includes: the protection level corresponding to each flash memory region, and the registers and their values for each protection level.
[0100] In this embodiment, since the preset table contains information on the protection levels corresponding to the flash memory when the BP bit is protected, after receiving the operation address, the corresponding protection level can be directly found in the preset table based on the operation address, without the flash driver needing to temporarily calculate the protection level based on the write protection characteristics of each flash memory. This reduces the complexity and difficulty of flash driver design and facilitates subsequent maintenance.
[0101] Furthermore, the above-mentioned write protection or deprotection setting of the corresponding area of the operation address using BP bit protection based on the protection level and preset table can specifically include: determining the preset values of each register and part of each register corresponding to the protection level and identifier from the preset table; reading the current value of each register; modifying the current value according to the protection level and preset value so that the BP bit corresponding to the current value is consistent with the protection level, and the corresponding bit of the current value is consistent with the preset value; and writing the modified current value back to each register.
[0102] Specifically, first determine the value corresponding to the mnemonic "IsWr2Srs". If the value is 0, modify register 1 by reading it from the flash register. Then, based on the identified identifier, find the number of valid BP bits in the preset table and configure the value of the number of valid BP bits starting from the predefined BP offset to the value corresponding to the write protection level. Next, find all mnemonic-related bits with a "presence" configuration value of 1 and a "register number" of 1 in the preset table, along with their "bit offset" and "bit value", to modify the corresponding bit value of the read register 1. Finally, write the modified value of register 1 back to the flash register. If the value corresponding to the mnemonic "IsWr2Srs" is 1, then registers 1 and 2 need to be modified. Read registers 1 and 2 and modify them similarly to modify register 1. After modification, write the modified values back to flash registers 1 and 2 together.
[0103] In this embodiment, since the preset table includes preset values of each register and its partial bits corresponding to the protection level corresponding to each identifier, after reading the current value of each register, the current value of each register can be directly modified according to the preset values of each register and its partial bits corresponding to the protection level and identifier in the preset table, and the modified current value is written back to each register. In this way, the correctness of the value rewritten back to each register can be improved, and the situation where the current value of the register is read incorrectly but the current value of the register is not modified, resulting in an error when writing back the value to the register, can be avoided as much as possible.
[0104] Optionally, when the operation address is a write protection address, and the write protection address is an address for setting write protection for the area range corresponding to the write protection address, the above determination of the protection level of the operation address based on the operation address and the preset table may specifically include: if the write protection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the larger area range corresponding to the protection level is determined as the protection level corresponding to the write protection address.
[0105] It is understandable that, regardless of whether the protection area of the flash memory is divided into protection levels from the bottom (setting the bottom as the 0 offset address of the protection area) or the top (setting the top as the 0 offset address of the protection area), it can be designed so that the larger the protection level, the larger the corresponding protected flash memory area. In this case, if the write protection address corresponds to an address in the preset table that is between two protection levels, then the larger of the two protection levels is determined as the protection level corresponding to the write protection address. For example, if the area range corresponding to the write protection address is 0-5M, and this 0-5M area corresponds to the address between protection level 7 and protection level 8, then protection level 8 is determined as the protection level corresponding to this write protection address.
[0106] In this embodiment of the application, since important data is usually write-protected, if the write protection address corresponds to an address in the preset table that is between two protection levels, then the protection level with the larger area corresponding to the protection level is determined as the protection level corresponding to the write protection address. This ensures that the area corresponding to the determined protection level includes the entire area corresponding to the write protection address, thereby achieving write protection for the area corresponding to the write protection address.
[0107] Optionally, when the operation address is a deprotection address, and the deprotection address is an address for setting deprotection of the area range corresponding to the deprotection address, the above determination of the protection level of the operation address based on the operation address and the preset table may specifically include: if the deprotection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the smaller area range corresponding to the protection level is determined as the protection level corresponding to the deprotection address.
[0108] It's understandable that regardless of whether the flash memory's protection area is divided into protection levels from the bottom (setting the bottom as the 0 offset address of the protection area) or the top (setting the top as the 0 offset address of the protection area), it can be designed so that the larger the protection level, the larger the corresponding protected flash memory area. In this case, if the deprotection address corresponds to an address in the preset table that falls between two protection levels, then the smaller of the two protection levels is determined as the protection level corresponding to the deprotection address. For example, if the write protection address corresponds to a region ranging from 0 to 5M, and this 0-5M region corresponds to addresses between protection levels 7 and 8, then protection level 7 is determined as the protection level corresponding to this deprotection address.
[0109] In this embodiment of the application, if the deprotection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the smaller area corresponding to the protection level is determined as the protection level corresponding to the write protection address. This ensures that the area to be deprotected will not contain areas that are not required to be deprotected, that is, the area to be deprotected will not contain write protection areas other than the deprotection address, thereby improving the security of other write protection areas.
[0110] Optionally, before setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the protection level and preset table, the above flash memory write protection method may further include: determining that the protection level corresponding to the operation address is less than or equal to the maximum preset protection level, wherein the maximum preset protection level is the protection level corresponding to the preset protection region.
[0111] The preset protection level can be set according to the actual situation. For example, if it is set that write protection can be performed on all areas of the flash memory, the protection level corresponding to all areas of the flash memory can be set to the preset protection level; or if it is set that write protection can be performed only on the 0-6M area of the flash memory, the protection level corresponding to the 0-6M area of the flash memory can be set to the preset protection level.
[0112] In this embodiment, before setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the determined protection level and preset table, it is first determined that the protection level corresponding to the operation address is less than or equal to the maximum preset protection level. This ensures that the region to be written protected is included in the preset flash memory region that can be written protected, thereby avoiding write protection operations on regions that do not need to be written protected.
[0113] Furthermore, it is understood that when the operating address is less than or equal to the maximum preset protection level, the area range corresponding to the protection level determined based on the operating address and the preset table should include the entire area range corresponding to the operating address.
[0114] Furthermore, the write protection method for the aforementioned flash memory may also include: if the protection level corresponding to the operation address is greater than the maximum preset protection level, then based on the maximum preset protection level and the preset table, the BP bit protection is used to set write protection for the area corresponding to the maximum preset protection level.
[0115] In this embodiment, a protection level greater than the maximum preset protection level at the operation address indicates that write protection is applied to all areas capable of write protection, as well as some or all areas that do not require write protection. Possible scenarios where the protection level at the operation address exceeds the maximum preset protection level include: the protected area corresponding to the maximum preset protection level already encompasses the entire flash memory size, but the operation address exceeds the flash memory range; or the protected area corresponding to the maximum preset protection level does not encompass the entire flash memory size, but the operation address exceeds the protection range. When the protected area corresponding to the maximum preset protection level does not encompass the entire flash memory size, the unprotected area generally has special considerations. For example, the unprotected area may be a writable area that requires frequent erasure and rewriting. If write protection is applied to this area, it needs to be deprotected or rewritten during erasure and rewriting, which requires modifying the flash memory registers. Since some flash memory registers have a limited number of erase / write cycles, frequent modifications will quickly bring them to their lifespan limit. Therefore, in such applications, setting the protection level to not exceed the maximum preset protection level can effectively extend the lifespan of the flash memory.
[0116] It should be noted that specific protection interfaces can be used for write protection operations in critical areas. Without invoking these interfaces, deprotection operations are impossible. In other words, without invoking or correctly invoking these protection interfaces, the critical areas cannot be tampered with, effectively preventing unauthorized damage. Furthermore, authorization code verification can be added to these protection interfaces to further enhance the security of write protection and deprotection operations.
[0117] Please see Figure 2 Based on the same inventive concept, this application also provides a flash memory write protection device 100, which includes a processing module 101 and a write protection module 102.
[0118] The processing module 101 is used to obtain the identifier of the flash memory when the trigger condition is triggered.
[0119] The write protection module 102 is used to determine the target write protection mode according to the preset table if the identifier exists in the identifier representation preset table. The preset table also includes relevant information on the write protection of the flash memory corresponding to the identifier. Based on the preset table, the operation corresponding to the trigger condition is processed using the target write protection mode.
[0120] Optionally, the write protection module 102 is specifically used to determine whether single-block protection is currently performed based on a preset table; if single-block protection is currently performed, the single-block protection is used to process the operation corresponding to the trigger condition based on the preset table.
[0121] Optionally, the trigger condition is the initialization of the flash memory driver. Accordingly, the write protection module 102 is specifically used to set write protection for a preset protection area based on a preset table and using single-block protection.
[0122] Optionally, the trigger condition is the initialization of the flash memory driver. The write protection module 102 is also used to set write protection for the preset protection area based on the preset table and using BP bit protection if single-block protection is not currently performed.
[0123] Optionally, the trigger condition is receiving an operation address. Specifically, the write protection module 102 is used to set the flash memory to single-block protection mode based on a preset table; and to issue a command to perform a write protection operation on the operation address according to the operation address and the preset single-block protection commands.
[0124] Optionally, the trigger condition is receiving an operation address. The write protection module 102 is also used to determine the protection level of the operation address based on the operation address and the preset table if single-block protection is not currently performed. The operation address is the address for setting write protection or deprotection of the area corresponding to the operation address. The preset table also includes information on the protection levels corresponding to the flash memory when the BP bit is protected. Based on the protection level and the preset table, the BP bit protection is used to set write protection or deprotection of the area corresponding to the operation address.
[0125] Optionally, the write protection module 102 is specifically used to determine the preset values of each register and part of each register corresponding to the protection level and the identifier from the preset table; read the current value of each register; modify the current value according to the protection level and the preset value so that the BP bit corresponding to the current value is consistent with the protection level, and the corresponding bit of the current value is consistent with the preset value; and write the modified current value back to each register.
[0126] Optionally, the operation address is a write protection address, which is the address for setting write protection for the area range corresponding to the write protection address. Accordingly, the write protection module 102 is specifically used to determine the protection level with the larger area range corresponding to the write protection address if the write protection address corresponds to an address in the preset table that is between two protection levels.
[0127] Optionally, the operation address is the deprotection address, which is the address for setting the deprotection of the area range corresponding to the deprotection address. Correspondingly, the write protection module 102 is specifically used to determine the protection level with the smaller area range corresponding to the protection level as the protection level corresponding to the write protection address if the deprotection address corresponds to an address in the preset table that is between two protection levels.
[0128] Optionally, before setting write protection or deprotection for the area corresponding to the operation address using BP bit protection based on the protection level and preset table, the write protection module 102 is also used to determine that the protection level corresponding to the operation address is less than or equal to the maximum preset protection level, where the maximum preset protection level is the protection level corresponding to the preset protection area.
[0129] Optionally, the write protection module 102 is also used to set write protection for the area corresponding to the maximum preset protection level based on the maximum preset protection level and the preset table, using BP bit protection, if the protection level corresponding to the operation address is greater than the maximum preset protection level.
[0130] Please see Figure 3 Based on the same inventive concept, this application provides a schematic structural block diagram of an electronic device 200, which can be used to implement the above-described flash memory write protection method. In this application embodiment, the electronic device 200 can be, but is not limited to, a personal computer (PC), smartphone, tablet computer, personal digital assistant (PDA), mobile internet device (MID), security equipment, monitoring equipment, set-top box, Internet of Things (IoT) device, etc. Structurally, the electronic device 200 may include a processor 210 and a memory 220.
[0131] Processor 210 and memory 220 are electrically connected directly or indirectly to achieve data transmission or interaction. For example, these components can be electrically connected to each other through one or more communication buses or signal lines. Processor 210 can be an integrated circuit chip with signal processing capabilities. Processor 210 can also be a general-purpose processor, such as a Central Processing Unit (CPU), Digital Signal Processor (DSP), Application Specific Integrated Circuit (ASIC), discrete gate or transistor logic device, or discrete hardware component, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application. Furthermore, the general-purpose processor can be a microprocessor or any conventional processor.
[0132] The memory 220 may be, but is not limited to, Random Access Memory (RAM), Read Only Memory (ROM), Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), NOR Flash, NAND Flash, or eMMC (Embedded Multi Media Card). The memory 220 stores programs, which the processor 210 executes upon receiving execution instructions.
[0133] It should be understood that Figure 3 The structure shown is for illustrative purposes only. The electronic device 200 provided in this application embodiment may also have a more advanced design. Figure 3 Fewer or more components, or having the same Figure 3 The different configurations shown. Furthermore... Figure 3 The components shown can be implemented through software, hardware, or a combination thereof.
[0134] It should be noted that, as those skilled in the art will clearly understand, for the sake of convenience and brevity, the specific working processes of the systems, devices and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0135] Based on the same inventive concept, embodiments of this application also provide a computer-readable storage medium storing a computer program thereon, which executes the methods provided in the above embodiments when the computer program is run.
[0136] The storage medium can be any available medium that a computer can access, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
[0137] In addition, the storage medium can also be random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), NOR flash, NAND flash, or eMMC (Embedded Multi Media Card).
[0138] In the embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the displayed or discussed mutual couplings, direct couplings, or communication connections may be through some communication interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms.
[0139] Furthermore, the units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0140] Furthermore, the functional modules in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0141] The above description is merely an embodiment of this application and is not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.
Claims
1. A write protection method for flash memory, characterized in that, include: When the trigger condition is met, obtain the flash memory identifier; If the identifier exists in the preset table, then the target write protection method is determined according to the preset table. The preset table also includes relevant information about the write protection of the flash memory corresponding to the identifier. Based on the preset table, the operation corresponding to the trigger condition is processed using the target write protection method; If the identifier does not exist in the preset table, then any subsequent write-protection operations are prohibited in the driver. The step of determining the target write protection mode according to the preset table includes: Based on the preset table, determine whether to perform single-block protection; If the single-block protection is currently in effect, the process of handling the operation corresponding to the trigger condition using the target write protection method based on the preset table includes: Based on the preset table, the single-block protection is used to process the operation corresponding to the trigger condition.
2. The method according to claim 1, characterized in that, The trigger condition is the initialization of the flash memory driver. The step of processing the operation corresponding to the trigger condition using the single-block protection based on the preset table includes: Based on the preset table, write protection is set for the preset protection area using the single-block protection.
3. The method according to claim 1, characterized in that, The triggering condition is the initialization of the flash memory driver, and the method further includes: If the single-block protection is not performed at present, then write protection is set for the preset protection area using BP bit protection based on the preset table.
4. The method according to claim 1, characterized in that, The triggering condition is receiving an operation address. The process of handling the operation corresponding to the triggering condition using the single-block protection based on the preset table includes: Based on the preset table, the flash memory is set to single-block protection mode; Based on the operation address and the preset commands for the single-block protection, a command is issued to perform a write protection operation on the operation address.
5. The method according to claim 1, characterized in that, The triggering condition is receiving an operation address, and the method further includes: If the single-block protection is not performed at present, the protection level of the operation address is determined according to the operation address and the preset table. The operation address is the address for setting write protection or deprotection of the area range corresponding to the operation address. The preset table also includes the protection level information of each flash memory corresponding to the identifier when the BP bit is protected. Based on the protection level and the preset table, BP bit protection is used to set write protection or deprotection for the area corresponding to the operation address.
6. The method according to claim 5, characterized in that, The step of setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the protection level and the preset table includes: The preset table is used to determine the registers that need to be modified and the preset values of some bits of each register corresponding to the protection level and the identifier. Read the current value of each register; The current value is modified according to the protection level and the preset value so that the BP bit corresponding to the current value is consistent with the protection level, and the corresponding bit of the current value is consistent with the preset value; Write the modified current value back to each of the registers.
7. The method according to claim 5, characterized in that, The operation address is a write-protected address, which is an address for setting write protection for the area range corresponding to the write-protected address. Determining the protection level of the operation address based on the operation address and the preset table includes: If the write protection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the larger area corresponding to the protection level is determined as the protection level corresponding to the write protection address.
8. The method according to claim 5, characterized in that, The operation address is a deprotection address, which is the address for setting deprotection of the area range corresponding to the deprotection address. Determining the protection level of the operation address based on the operation address and the preset table includes: If the deprotection address corresponds to an address in the preset table that is between two protection levels, then among the two protection levels, the protection level with the smaller area corresponding to the protection level is determined as the protection level corresponding to the deprotection address.
9. The method according to claim 5, characterized in that, Before setting write protection or deprotection for the region corresponding to the operation address using BP bit protection based on the protection level and the preset table, the method further includes: The protection level corresponding to the operation address is determined to be less than or equal to the maximum preset protection level, where the maximum preset protection level is the protection level corresponding to the preset protection area.
10. The method according to claim 9, characterized in that, The method further includes: If the protection level corresponding to the operation address is greater than the maximum preset protection level, then based on the maximum preset protection level and the preset table, write protection is set for the area corresponding to the maximum preset protection level using BP bit protection.
11. A write protection device for flash memory, characterized in that, include: The processing module is used to obtain the flash memory identifier when the trigger condition is triggered; The write protection module is used to determine the target write protection mode according to the preset table if the identifier exists in the preset table. The preset table also includes relevant information on the write protection of the flash memory corresponding to the identifier. Based on the preset table, the operation corresponding to the trigger condition is processed using the target write protection method; if the identifier does not exist in the preset table, any subsequent write protection operation is prohibited in the driver. The write protection module is specifically used to determine whether to perform single-block protection based on the preset table; If the single-block protection is currently in effect, the operation corresponding to the trigger condition is processed using the single-block protection based on the preset table.
12. An electronic device, characterized in that, include: A processor and a memory, wherein the processor and the memory are connected; The memory is used to store programs; The processor is used to run a program stored in the memory and perform the method as described in any one of claims 1-10.
13. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a computer, performs the method as described in any one of claims 1-10.
Citation Information
Patent Citations
Partition protection method and device for nonvolatile memory
CN110968254A
