CN116484327A - Memory operating system program write protection method and device and electronic equipment - Google Patents

Memory operating system program write protection method and device and electronic equipment Download PDF

Info

Publication number
CN116484327A
CN116484327A CN202310002881.XA CN202310002881A CN116484327A CN 116484327 A CN116484327 A CN 116484327A CN 202310002881 A CN202310002881 A CN 202310002881A CN 116484327 A CN116484327 A CN 116484327A
Authority
CN
China
Prior art keywords
partition
write protection
write
sector offset
calculating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310002881.XA
Other languages
Chinese (zh)
Inventor
孙小伍
马云林
王晓伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chongqing Changan Automobile Co Ltd
Original Assignee
Chongqing Changan Automobile Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chongqing Changan Automobile Co Ltd filed Critical Chongqing Changan Automobile Co Ltd
Priority to CN202310002881.XA priority Critical patent/CN116484327A/en
Publication of CN116484327A publication Critical patent/CN116484327A/en
Pending legal-status Critical Current

Links

Classifications

    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The application relates to a memory operating system program write protection method, a memory operating system program write protection device and electronic equipment, wherein the method comprises the following steps: when the first partition and/or the second partition in the write-protection group are detected to have the upgrading requirement, the upgrading authority and the upgrading file of the first partition and/or the second partition are obtained; based on the upgrading authority, removing write protection of the first partition and/or the second partition, re-mounting the first partition and/or the second partition into a read-write partition, and upgrading the first partition and/or the second partition; and after the first partition and/or the second partition are upgraded, re-mounting the first partition and/or the second partition into a read-only partition, and setting write protection for the first partition and/or the second partition. Therefore, the problems of certain constraint, probability of data loss and the like of the method for preventing the read-only program of the operating system from being lost in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.

Description

Memory operating system program write protection method and device and electronic equipment
Technical Field
The present invention relates to the field of storage technologies of operating system programs and data, and in particular, to a method and an apparatus for protecting write of an operating system program of a memory, and an electronic device.
Background
Most of the eMMCs in the market use an eMMC controller and a nand flash memory, and the nand flash has the problems of leaving a factory bad block and generating a bad block in use, and the bad block is mostly generated in writing operation. The eMMC controller needs a bad block management program and an ECC check program to manage bad blocks, and when it is found that a bad block is about to be generated in use, it is necessary to transfer the block data to a new normal block and mark the block as a bad block. In addition, the present eMMC has a BOOT area of pSLC (equivalent to SLC ((Single Level Cell, single layer memory unit)), and the USER area is mostly MLC (Multi-Level Cell), TLC (triple-Level Cell), QLC (Quad-Level Cell), and the like.
In the related art, as in scheme 1 of fig. 1, a read-only program is backed up by means of an a/B partition, if an operating system program corruption is detected, software is automatically switched to a backup program and the corrupted partition is restored by a restoration mechanism, however, the operating system program corruption occurs again when switching to the backup program operation or during restoration by the restoration mechanism; the SOC (System-on-a-Chip) Chip is limited to only support the loading of USER area data from one address, and the bootloader partition data is damaged, so that normal starting cannot be performed, and the size of the BOOT area is limited, so that the BOOT area is not applicable to a high-capacity operating System program.
In another related art, as in scheme 2 of fig. 1, a bootloader stored in a BOOT area is write-protected, and a large-capacity operating system program uses a/B partitioning. However, in the random power-down or interference experiment, there is still probability of data loss, and different manufacturers, models and batches, there are differences in version and algorithm of control programs, such as bad block management program, disc-drop program, etc., in the eMMC chip switching process, and probability of data loss may be introduced.
Disclosure of Invention
The application provides a method, a device and electronic equipment for protecting the program writing of an operating system of a memory, which solve the problems of certain constraint, probability of data loss and the like in the method for preventing the read-only program loss of the operating system in the related technology, and furthest prevent the rewriting and damage of hackers, power failure and the like to the read-only program.
An embodiment of a first aspect of the present application provides a method for protecting writing of an operating system program of a memory, including the following steps: when the first partition and/or the second partition in the write-protection group are detected to have the upgrading requirement, the upgrading authority and the upgrading file of the first partition and/or the second partition are obtained; based on the upgrading authority, removing write protection of the first partition and/or the second partition, re-mounting the first partition and/or the second partition into a read-write partition, and upgrading the first partition and/or the second partition; and after the first partition and/or the second partition are upgraded, re-mounting the first partition and/or the second partition into a read-only partition, and setting write protection for the first partition and/or the second partition.
According to the technical means, the problems that a method for preventing the read-only program of the operating system from being lost has certain constraint, probability of data loss and the like in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.
Further, the clearing write protection of the first partition and/or the second partition includes: calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset; after judging the write protection of the first partition and/or the write protection of the second partition according to the first write protection group state and/or the second write protection group state, calculating the number of first write protection groups according to the first partition capacity, and calculating the number of second write protection groups according to the second partition capacity; and based on the first write protection group number and/or the second write protection group number, circularly utilizing a preset CMD29 to clear the write protection of the first partition and/or the write protection of the second partition, and clearing the write protection marks of the first partition and the second partition after the clearing is completed.
According to the technical means, under the condition that write protection is not cleared, even if upgrade permission is acquired, the read-only program of the operating system cannot be modified, so that the read-only program is prevented from being rewritten and damaged by hackers, power failure and the like to the greatest extent.
Further, the setting write protection for the first partition and/or the second partition includes: calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset; after the first partition is not write-protected and/or the second partition is not write-protected according to the third write-protected group state and/or the fourth write-protected group state, calculating the number of third write-protected groups according to the first partition capacity, and calculating the number of fourth write-protected groups according to the second partition capacity; and based on the third write protection group number and/or the fourth write protection group number, circularly utilizing the preset CMD28 to set write protection for the first partition and/or the second partition respectively, and setting write protection marks of the first partition and the second partition after the write protection is finished.
According to the technical means, the write protection of the protection group is set by circularly using the preset CMD28, so that the data loss of the system in the using process is prevented.
Further, before calculating the third sector offset corresponding to the first partition and/or the fourth sector offset corresponding to the second partition according to the partition offset of the first partition and/or the second partition, the method includes: judging whether the first partition and/or the second partition has a write protection mark or forced write protection; and if the write protection mark or the forced write protection exists in the first partition and/or the second partition, ending setting the write protection on the first partition and/or the second partition.
According to the technical means, if the first partition and/or the second partition are detected to have the write protection mark or forced write protection, setting the write protection is ended, and data is prevented from being modified or lost.
An embodiment of a second aspect of the present application provides an operating system program write protection device for a memory, including: the system comprises an acquisition module, a storage module and a storage module, wherein the acquisition module is used for acquiring upgrading authority and upgrading files of a first partition and/or a second partition in a write-protection group when detecting that the first partition and/or the second partition has upgrading requirements; the clearing module is used for clearing write protection of the first partition and/or the second partition based on the upgrading authority, re-mounting the first partition and/or the second partition into a read-write partition, and upgrading the first partition and/or the second partition; and the write protection module is used for re-mounting the first partition and/or the second partition into a read-only partition after the first partition and/or the second partition are upgraded, and setting write protection for the first partition and/or the second partition.
Further, the clearing module is further configured to: calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset; after judging the write protection of the first partition and/or the write protection of the second partition according to the first write protection group state and/or the second write protection group state, calculating the number of first write protection groups according to the first partition capacity, and calculating the number of second write protection groups according to the second partition capacity; and based on the first write protection group number and/or the second write protection group number, circularly utilizing a preset CMD29 to clear the write protection of the first partition and/or the write protection of the second partition, and clearing the write protection marks of the first partition and the second partition after the clearing is completed.
Further, the write protection module is further configured to: calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset; after the first partition is not write-protected and/or the second partition is not write-protected according to the third write-protected group state and/or the fourth write-protected group state, calculating the number of third write-protected groups according to the first partition capacity, and calculating the number of fourth write-protected groups according to the second partition capacity; and based on the third write protection group number and/or the fourth write protection group number, circularly utilizing the preset CMD28 to set write protection for the first partition and/or the second partition respectively, and setting write protection marks of the first partition and the second partition after the write protection is finished.
Further, before calculating the third sector offset corresponding to the first partition and/or the fourth sector offset corresponding to the second partition according to the partition offset of the first partition and/or the second partition, the write protection module is further configured to: judging whether the first partition and/or the second partition has a write protection mark or forced write protection; and if the write protection mark or the forced write protection exists in the first partition and/or the second partition, ending setting the write protection on the first partition and/or the second partition.
An embodiment of a third aspect of the present application provides an electronic device, including: the memory, the processor and the computer program stored in the memory and capable of running on the processor, the processor executes the program to implement the operating system program write protection method of the memory according to the above embodiment.
An embodiment of a fourth aspect of the present application provides a computer-readable storage medium having stored thereon a computer program that is executed by a processor for implementing an operating system program write protection method for a memory as described in the above embodiment.
Therefore, when the first partition and/or the second partition in the write-protection group have the upgrading requirement, the write-protection is cleared, the first partition and/or the second partition are re-mounted as the read-write partition, the first partition and/or the second partition are upgraded, and after the upgrading is finished, the first partition and/or the second partition are re-mounted as the read-only partition, and the write-protection is set. Therefore, the problems of certain constraint, probability of data loss and the like of the method for preventing the read-only program of the operating system from being lost in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.
Additional aspects and advantages of the application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the application.
Drawings
The foregoing and/or additional aspects and advantages of the present application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings, in which:
FIG. 1 is a diagram illustrating a comparison of partitioning and programming of the present application with other schemes according to one embodiment of the present application;
FIG. 2 is a flowchart of a method for operating system program write protection of a memory according to an embodiment of the present application;
FIG. 3 is a flow chart of a write protected group upgrade of an eMMC register-based operating system write protection method in accordance with one embodiment of the present application;
FIG. 4 is a flow chart of the purging and setting of write protect groups controlled by the eMMC register according to one embodiment of the present application;
FIG. 5 is a block diagram of an operating system program write protect device of a memory according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Reference numerals illustrate: 10-memory operating system program write protection device, 100-acquisition module, 200-purge module, 300-write protection module, 601-memory, 602-processor, 603-communication interface.
Detailed Description
Embodiments of the present application are described in detail below, examples of which are illustrated in the accompanying drawings, wherein the same or similar reference numerals refer to the same or similar elements or elements having the same or similar functions throughout. The embodiments described below by referring to the drawings are exemplary and intended for the purpose of explaining the present application and are not to be construed as limiting the present application.
An operating system program write protection method and apparatus for a memory and an electronic device according to embodiments of the present application are described below with reference to the accompanying drawings. In order to solve the problem that the method for preventing the loss of the read-only program of the operating system in the related art mentioned in the background art has certain constraint and probability of data loss, the application provides a write protection method for the operating system program of a memory, in the method, when the first partition and/or the second partition in the write protection group have upgrading requirements, write protection is cleared, the first partition and/or the second partition is re-mounted as a read-write partition, the first partition and/or the second partition is upgraded, and after the upgrading is finished, the first partition and/or the second partition is re-mounted as a read-only partition, and write protection is set. Therefore, the problems of certain constraint, probability of data loss and the like of the method for preventing the read-only program of the operating system from being lost in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.
Before describing a method for protecting the program writing of the operating system of the memory according to the embodiment of the present application, a BOOT area and a USER area in the related art will be briefly described.
The BOOT area is designed primarily to support booting the system from eMMC. The data of the partition can be read by a simple protocol after eMMC is powered up. Meanwhile, most of the SOCs can be configured through GPIO or FUSE, so that the ROM code is loaded into the SRAM inside the SOCs to be executed after the ROM code is powered on. The SIZE of the BOOT area is typically 4MB by default, i.e. the SIZE of the BOOT SIZE MULT is 32, and the maximum SIZE of the BOOT SIZE MULT may be 255, i.e. the maximum SIZE of the BOOT area may be 255x128 kb=32640 kb=31.875 MB. The method can store bootloader programs, and meanwhile, a simplified memory file system ramdisk is newly added to be used as the final guarantee of system starting. BOOT up of the BOOT area to meet the minimum operating system may be performed concurrently with the upgrade of A, B. The BOOT area supports write protection. By setting the Extended CSD register, a write protect function can be configured for the BOOT area to prevent data from being accidentally overwritten or erased. Two write protection modes of Boot Area are defined in eMMC: power-on write protection, after being enabled, if eMMC is powered down, the write protection function fails, and configuration is required after each Power on. Permanent write protection is enabled, and even if power is lost, the power-off cannot be disabled.
The USER area also supports a similar function as the BOOT areaStoring operating System and->Data, the most +.>Is->The partitions are also the most dominant storage areas. Read-only programs such as operating systems, apps, etc. are stored in this area, and data such as user data is also stored in this area, so write protection is read-only programs such as operating systems for this area. eMMC write protection groups require an integer multiple of 8192 sectors (sectors). In system partitioning, it is necessary to ensure that the starting address and size of the a/B area must be an integer multiple of 8192. In order to facilitate the setting of the A/B zone write protection group, the partition sequence is different from that of the Android partition. Write protection is supported for zone a, zone B, and zones a and B. When the area A is operated to upgrade the area B, the write protection group is the area A, and the write protection of the area B is cleared. If zone A and zone B are damaged, BOO is operatedAnd the write protection of the A and B areas is canceled at the same time of starting the minimum operating system of the T area, and under the normal operation condition, the A and B areas are both write protection areas.
Specifically, fig. 2 is a flowchart of a method for protecting write of an operating system program of a memory according to an embodiment of the present application.
As shown in fig. 2, the operating system program write protection method of the memory includes the following steps:
in step S201, when it is detected that an upgrade requirement exists in the first partition and/or the second partition in the write-protected group, upgrade permission and upgrade file of the first partition and/or the second partition are obtained.
Specifically, as shown in fig. 3, the present application assumes that the first partition is a region a and the second partition is a region B. When the A area or the B area or the A area and the B area are detected to have the upgrading requirement, correspondingly acquiring the upgrading authority and the upgrading file of the A area or the B area or the A area and the B area.
When the read-only partitions such as the system and the app are required to be modified for the operating system with the upgrading authority, the write-protection group can be controlled according to the upgrading strategy of the area A and the area B when the upgrading authority is acquired.
In step S202, write protection of the first partition and/or the second partition is cleared based on the upgrade authority, the first partition and/or the second partition is re-mounted as a read-write partition, and upgrade operation is performed on the first partition and/or the second partition.
Under the normal starting condition, the bootloader stage can set write protection for the A area and the B area through the write protection group. Even if the root upgrading authority is obtained under the condition that the write protection is not cleared, the read-only program of the operating system cannot be modified.
Wherein in some embodiments, clearing write protection of the first partition and/or the second partition comprises: calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset; after judging the write protection of the first partition and/or the write protection of the second partition according to the state of the first write protection group and/or the state of the second write protection group, calculating the number of the first write protection group according to the capacity of the first partition, and calculating the number of the second write protection group according to the capacity of the second partition; based on the number of the first write protection groups and/or the number of the second write protection groups, a preset CMD29 is recycled to clear the write protection of the first partition and/or the write protection of the second partition, and after the clearing is completed, the write protection marks of the first partition and the second partition are cleared.
Specifically, as shown in fig. 4, when a write operation needs to be performed on a certain partition, the write protection clearing flow generally occurs, according to partition offsets of the a area and the B area or the a area or the B area, a first sector offset corresponding to the a area and a second sector offset corresponding to the B area are calculated, or a first sector offset corresponding to the a area or a second sector offset corresponding to the B area is calculated, and a preset CMD29 is used to clear write protection of the a area and write protection of the B area, or clear write protection of the a area or write protection of the B area is obtained through an eMMC command CMD31, or the first write protection group state corresponding to the first sector offset or the second write protection group state corresponding to the second sector offset is obtained, if the a area and the B area or the a area or the B area are written protected by an eMMC register, the first write protection clearing flag is cleared for the first partition and the second partition.
And further, re-mounting the A area or the B area or the A area and the B area as read-write partitions, and upgrading the A area or the B area or the A area and the B area.
In step S203, after the first partition and/or the second partition are upgraded, the first partition and/or the second partition is re-mounted as a read-only partition, and write protection is set for the first partition and/or the second partition.
It should be understood that when the area a and the area B, or the area a or the area B is upgraded, the area a and the area B, or the area a or the area B, release the upgrade authority, and reload the area a and the area B, or the area a or the area B, into a read-only partition.
Further, in some embodiments, setting write protection for the first partition and/or the second partition includes: calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset; after the first partition is judged to be not write-protected and/or the second partition is judged to be not write-protected according to the third write-protected group state and/or the fourth write-protected group state, the number of the third write-protected groups is calculated according to the capacity of the first partition, and the number of the fourth write-protected groups is calculated according to the capacity of the second partition; based on the third write-protection group number and/or the fourth write-protection group number, the preset CMD28 is recycled to set write-protection for the first partition and/or the second partition, and after the write-protection is completed, write-protection marks of the first partition and the second partition are set.
When the partition of the operating system is modified or the partition is mounted in a read-only mode, a write protection flow is required to be set. According to the partition offset of the A area and the B area, or the partition offset of the A area or the B area, calculating a third sector offset corresponding to the A area and a fourth sector offset corresponding to the B area, or the third sector offset corresponding to the A area or the fourth sector offset corresponding to the B area, and acquiring a third write protection group state corresponding to the third sector offset and a fourth write protection group state corresponding to the fourth sector offset, or acquiring a third write protection group state corresponding to the third sector offset or a fourth write protection group state corresponding to the fourth sector offset through an eMMC command CMD 31.
If the A area and the B area or the A area or the B area are not write-protected by the eMMC register, calculating the number of the third write-protection group according to the size of the A area, calculating the number of the fourth write-protection group according to the size of the B area, circularly using a preset CMD28 to set write-protection group write-protection for the A area and the B area or the A area or the B area, and setting write-protection marks of the A area and the B area after the write-protection is completed.
Optionally, in some embodiments, before calculating the third sector offset corresponding to the first partition and/or the fourth sector offset corresponding to the second partition according to the partition offset of the first partition and/or the second partition, the method includes: judging whether the first partition and/or the second partition has a write protection mark or forced write protection; if the first partition and/or the second partition has write protection marks or forced write protection, setting the write protection on the first partition and/or the second partition is ended.
It should be understood that if there is a write protection flag or forced write protection for the a and B areas or the a or B areas, indicating that the a and B areas or the a or B areas are write protected by the eMMC register, the setting of write protection for the a and B areas or the a or B areas is ended.
It should be noted that, in addition to being applicable to the eMMC memory, the write protection method is also applicable to other memories such as nand flash and nor flash. The embodiment of the application is applicable to read-only programs of non-operating systems besides operating system programs.
According to the operating system program write protection method of the memory, when the first partition and/or the second partition in the write protection group have the upgrading requirement, write protection is cleared, the first partition and/or the second partition are re-mounted as read-write partitions, the first partition and/or the second partition are upgraded, and after the upgrading is finished, the first partition and/or the second partition are re-mounted as read-only partitions, and write protection is set. Therefore, the problems of certain constraint, probability of data loss and the like of the method for preventing the read-only program of the operating system from being lost in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.
An operating system program write-protection apparatus for a memory according to an embodiment of the present application will be described next with reference to the accompanying drawings.
FIG. 5 is a block diagram of an operating system program write protect device for a memory according to an embodiment of the present application.
As shown in fig. 5, the operating system program write protection device 10 of the memory includes: an acquisition module 100, a purge module 200, and a write protection module 300.
The acquiring module 100 is configured to acquire an upgrade right and an upgrade file of the first partition and/or the second partition when it is detected that the upgrade requirement exists on the first partition and/or the second partition in the write-protection group; the clearing module 200 is configured to clear write protection of the first partition and/or the second partition based on the upgrade right, reload the first partition and/or the second partition as a read-write partition, and perform upgrade operation on the first partition and/or the second partition; the write protection module 300 is configured to re-mount the first partition and/or the second partition into a read-only partition after the first partition and/or the second partition are upgraded, and set write protection for the first partition and/or the second partition.
Further, the cleaning module 200 is further configured to: calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset; after judging the write protection of the first partition and/or the write protection of the second partition according to the state of the first write protection group and/or the state of the second write protection group, calculating the number of the first write protection group according to the capacity of the first partition, and calculating the number of the second write protection group according to the capacity of the second partition; based on the number of the first write protection groups and/or the number of the second write protection groups, a preset CMD29 is recycled to clear the write protection of the first partition and/or the write protection of the second partition, and after the clearing is completed, the write protection marks of the first partition and the second partition are cleared.
Further, the write protection module 300 is further configured to: calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition; acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset; after the first partition is judged to be not write-protected and/or the second partition is judged to be not write-protected according to the third write-protected group state and/or the fourth write-protected group state, the number of the third write-protected groups is calculated according to the capacity of the first partition, and the number of the fourth write-protected groups is calculated according to the capacity of the second partition; based on the third write-protection group number and/or the fourth write-protection group number, the preset CMD28 is recycled to set write-protection for the first partition and/or the second partition, and after the write-protection is completed, write-protection marks of the first partition and the second partition are set.
Further, before calculating the third sector offset corresponding to the first partition and/or the fourth sector offset corresponding to the second partition according to the partition offset of the first partition and/or the second partition, the write protection module 300 is further configured to: judging whether the first partition and/or the second partition has a write protection mark or forced write protection; if the first partition and/or the second partition has write protection marks or forced write protection, setting the write protection on the first partition and/or the second partition is ended.
It should be noted that the foregoing explanation of the embodiment of the method for protecting the operating system program of the memory is also applicable to the device for protecting the operating system program of the memory of this embodiment, and will not be repeated here.
According to the operating system program write protection device of the memory, when the first partition and/or the second partition in the write protection group have the upgrading requirement, the write protection is cleared, the first partition and/or the second partition are re-mounted as the read-write partition, the first partition and/or the second partition are upgraded, and after the upgrading is finished, the first partition and/or the second partition are re-mounted as the read-only partition, and the write protection is set. Therefore, the problems of certain constraint, probability of data loss and the like of the method for preventing the read-only program of the operating system from being lost in the related technology are solved, and the rewriting and damage of hackers, power failure and the like to the read-only program are prevented to the greatest extent.
Fig. 6 is a schematic structural diagram of an electronic device according to an embodiment of the present application. The electronic device may include:
a memory 601, a processor 602, and a computer program stored on the memory 601 and executable on the processor 602.
The processor 602 implements the operating system program write protection method for the memory provided in the above-described embodiments when executing the program.
Further, the electronic device further includes:
a communication interface 603 for communication between the memory 601 and the processor 602.
A memory 601 for storing a computer program executable on the processor 602.
The memory 601 may include a high-speed RAM (Random Access Memory ) memory, and may also include a nonvolatile memory, such as at least one disk memory.
If the memory 601, the processor 602, and the communication interface 603 are implemented independently, the communication interface 603, the memory 601, and the processor 602 may be connected to each other through a bus and perform communication with each other. The bus may be an ISA (Industry Standard Architecture ) bus, a PCI (Peripheral Component, external device interconnect) bus, or EISA (Extended Industry Standard Architecture ) bus, among others. The buses may be divided into address buses, data buses, control buses, etc. For ease of illustration, only one thick line is shown in fig. 6, but not only one bus or one type of bus.
Alternatively, in a specific implementation, if the memory 601, the processor 602, and the communication interface 603 are integrated on a chip, the memory 601, the processor 602, and the communication interface 603 may perform communication with each other through internal interfaces.
The processor 602 may be a CPU (Central Processing Unit ) or ASIC (Application Specific Integrated Circuit, application specific integrated circuit) or one or more integrated circuits configured to implement embodiments of the present application.
The embodiments of the present application also provide a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements an operating system program write protection method for a memory as above.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. In this specification, schematic representations of the above terms are not necessarily directed to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or N embodiments or examples. Furthermore, the different embodiments or examples described in this specification and the features of the different embodiments or examples may be combined and combined by those skilled in the art without contradiction.
Furthermore, the terms "first," "second," and the like, are used for descriptive purposes only and are not to be construed as indicating or implying a relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defining "a first" or "a second" may explicitly or implicitly include at least one such feature. In the description of the present application, the meaning of "N" is at least two, such as two, three, etc., unless explicitly defined otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more N executable instructions for implementing specific logical functions or steps of the process, and further implementations are included within the scope of the preferred embodiment of the present application in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the embodiments of the present application.
It is to be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the N steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. As with the other embodiments, if implemented in hardware, may be implemented using any one or combination of the following techniques, as is well known in the art: discrete logic circuits having logic gates for implementing logic functions on data signals, application specific integrated circuits having suitable combinational logic gates, programmable gate arrays, field programmable gate arrays, and the like.
Those of ordinary skill in the art will appreciate that all or a portion of the steps carried out in the method of the above-described embodiments may be implemented by a program to instruct related hardware, where the program may be stored in a computer readable storage medium, and where the program, when executed, includes one or a combination of the steps of the method embodiments.
Although embodiments of the present application have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the application, and that variations, modifications, alternatives, and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the application.

Claims (10)

1. A method for protecting a memory from writing an operating system program, comprising the steps of:
when the first partition and/or the second partition in the write-protection group are detected to have the upgrading requirement, the upgrading authority and the upgrading file of the first partition and/or the second partition are obtained;
based on the upgrading authority, removing write protection of the first partition and/or the second partition, re-mounting the first partition and/or the second partition into a read-write partition, and upgrading the first partition and/or the second partition; and
and after the first partition and/or the second partition are upgraded, re-mounting the first partition and/or the second partition into a read-only partition, and setting write protection for the first partition and/or the second partition.
2. The method of claim 1, wherein the clearing write protection of the first partition and/or the second partition comprises:
calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition;
acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset;
after judging the write protection of the first partition and/or the write protection of the second partition according to the first write protection group state and/or the second write protection group state, calculating the number of first write protection groups according to the first partition capacity, and calculating the number of second write protection groups according to the second partition capacity;
and based on the first write protection group number and/or the second write protection group number, circularly utilizing a preset CMD29 to clear the write protection of the first partition and/or the write protection of the second partition, and clearing the write protection marks of the first partition and the second partition after the clearing is completed.
3. The method of claim 2, wherein the setting write protection for the first partition and/or the second partition comprises:
calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition;
acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset;
after the first partition is not write-protected and/or the second partition is not write-protected according to the third write-protected group state and/or the fourth write-protected group state, calculating the number of third write-protected groups according to the first partition capacity, and calculating the number of fourth write-protected groups according to the second partition capacity;
and based on the third write protection group number and/or the fourth write protection group number, circularly utilizing the preset CMD28 to set write protection for the first partition and/or the second partition respectively, and setting write protection marks of the first partition and the second partition after the write protection is finished.
4. The method according to claim 2, comprising, before calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition from partition offsets of the first partition and/or the second partition:
judging whether the first partition and/or the second partition has a write protection mark or forced write protection; and if the write protection mark or the forced write protection exists in the first partition and/or the second partition, ending setting the write protection on the first partition and/or the second partition.
5. An operating system program write protection device for a memory, comprising:
the system comprises an acquisition module, a storage module and a storage module, wherein the acquisition module is used for acquiring upgrading authority and upgrading files of a first partition and/or a second partition in a write-protection group when detecting that the first partition and/or the second partition has upgrading requirements;
the clearing module is used for clearing write protection of the first partition and/or the second partition based on the upgrading authority, re-mounting the first partition and/or the second partition into a read-write partition, and upgrading the first partition and/or the second partition; and
and the write protection module is used for re-mounting the first partition and/or the second partition into a read-only partition after the first partition and/or the second partition are upgraded, and setting write protection for the first partition and/or the second partition.
6. The apparatus of claim 5, wherein the purge module is further configured to:
calculating a first sector offset corresponding to the first partition and/or a second sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition;
acquiring a first write protection group state corresponding to the first sector offset and/or a second write protection group state corresponding to the second sector offset;
after judging the write protection of the first partition and/or the write protection of the second partition according to the first write protection group state and/or the second write protection group state, calculating the number of first write protection groups according to the first partition capacity, and calculating the number of second write protection groups according to the second partition capacity;
and based on the first write protection group number and/or the second write protection group number, circularly utilizing a preset CMD29 to clear the write protection of the first partition and/or the write protection of the second partition, and clearing the write protection marks of the first partition and the second partition after the clearing is completed.
7. The apparatus of claim 6, wherein the write protection module is further to:
calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition according to the partition offsets of the first partition and/or the second partition;
acquiring a third write protection group state corresponding to the third sector offset and/or a fourth write protection group state corresponding to the fourth sector offset;
after the first partition is not write-protected and/or the second partition is not write-protected according to the third write-protected group state and/or the fourth write-protected group state, calculating the number of third write-protected groups according to the first partition capacity, and calculating the number of fourth write-protected groups according to the second partition capacity;
and based on the third write protection group number and/or the fourth write protection group number, circularly utilizing the preset CMD28 to set write protection for the first partition and/or the second partition respectively, and setting write protection marks of the first partition and the second partition after the write protection is finished.
8. The apparatus of claim 6, wherein the write protection module, prior to calculating a third sector offset corresponding to the first partition and/or a fourth sector offset corresponding to the second partition from partition offsets of the first partition and/or the second partition, is further to:
judging whether the first partition and/or the second partition has a write protection mark or forced write protection; and if the write protection mark or the forced write protection exists in the first partition and/or the second partition, ending setting the write protection on the first partition and/or the second partition.
9. An electronic device, comprising: a memory, a processor and a computer program stored on the memory and executable on the processor, the processor executing the program to implement the operating system program write protection method of a memory as claimed in any one of claims 1 to 4.
10. A computer readable storage medium having stored thereon a computer program, characterized in that the program is executed by a processor for implementing an operating system program write protection method of a memory according to any of claims 1-4.
CN202310002881.XA 2023-01-03 2023-01-03 Memory operating system program write protection method and device and electronic equipment Pending CN116484327A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310002881.XA CN116484327A (en) 2023-01-03 2023-01-03 Memory operating system program write protection method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310002881.XA CN116484327A (en) 2023-01-03 2023-01-03 Memory operating system program write protection method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN116484327A true CN116484327A (en) 2023-07-25

Family

ID=87225603

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310002881.XA Pending CN116484327A (en) 2023-01-03 2023-01-03 Memory operating system program write protection method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN116484327A (en)

Similar Documents

Publication Publication Date Title
US8527730B2 (en) Data updating method, memory system and memory device
US8055957B2 (en) Semiconductor integrated circuit device having fail-safe mode and memory control method
US7197613B2 (en) Nonvolatile memory
TWI514408B (en) Handling errors during device bootup from a non-volatile memory
JP4668416B2 (en) Protecting boot block code when enabling write access to the boot block
JP4129381B2 (en) Nonvolatile semiconductor memory device
US10860247B2 (en) Data writing method and storage controller
US8341337B1 (en) Data storage device booting from system data loaded by host
US7836244B2 (en) Method of providing block state information in semiconductor memory device including flash memory
US7675776B2 (en) Bit map control of erase block defect list in a memory
US8341386B2 (en) Method for updating basic input/output system and method for repairing thereof
US7313682B2 (en) Method and system for updating boot memory that stores a fail-safe reset code and is configured to store boot code and boot updater code
CN102298545B (en) System startup boot processing method and device
JP4373943B2 (en) Memory controller, flash memory system, and flash memory control method
US8402204B2 (en) Methods for measuring usable lifespan and replacing an in-system programming code of a memory device, and data storage system using the same
CN111352580B (en) Memory device and method of operating the same
CN103678030A (en) Multi-system equipment start system and method thereof
JP2002351685A (en) Data updating method and controller for nonvolatile memory
US20110231621A1 (en) System recovery method, and storage medium controller and storage system using the same
JP2004220068A (en) Memory card and method for writing data in memory
JP2008251154A (en) Nonvolatile semiconductor memory device
CN116484327A (en) Memory operating system program write protection method and device and electronic equipment
KR100575927B1 (en) Method for booting the nand flash memory using multi boot loader in mobile station
US20220365696A1 (en) Re-partitioning of a flash memory device
JP2008197933A (en) Microcomputer and rewriting method for boot program

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination