CN112698785B - Data updating method of storage device - Google Patents

Data updating method of storage device Download PDF

Info

Publication number
CN112698785B
CN112698785B CN202011454618.7A CN202011454618A CN112698785B CN 112698785 B CN112698785 B CN 112698785B CN 202011454618 A CN202011454618 A CN 202011454618A CN 112698785 B CN112698785 B CN 112698785B
Authority
CN
China
Prior art keywords
data
session
backup
length
nvm
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.)
Active
Application number
CN202011454618.7A
Other languages
Chinese (zh)
Other versions
CN112698785A (en
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.)
Beijing WatchSmart Technologies Co Ltd
Original Assignee
Beijing WatchSmart Technologies 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 Beijing WatchSmart Technologies Co Ltd filed Critical Beijing WatchSmart Technologies Co Ltd
Priority to CN202011454618.7A priority Critical patent/CN112698785B/en
Publication of CN112698785A publication Critical patent/CN112698785A/en
Application granted granted Critical
Publication of CN112698785B publication Critical patent/CN112698785B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0602Interfaces specially adapted for storage systems specifically adapted to achieve a particular effect
    • G06F3/0614Improving the reliability of storage systems
    • G06F3/0619Improving the reliability of storage systems in relation to data integrity, e.g. data losses, bit errors
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/0644Management of space entities, e.g. partitions, extents, pools
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0655Vertical data movement, i.e. input-output transfer; data movement between one or more hosts and one or more storage devices
    • G06F3/0656Data buffering arrangements
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0668Interfaces specially adapted for storage systems adopting a particular infrastructure
    • G06F3/0671In-line storage system
    • G06F3/0673Single storage device
    • G06F3/0679Non-volatile semiconductor memory device, e.g. flash memory, one time programmable memory [OTP]

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Human Computer Interaction (AREA)
  • Computer Security & Cryptography (AREA)
  • Quality & Reliability (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a data updating method of storage equipment, which is characterized by comprising the following steps: the method comprises the steps that a RAM of a storage device is provided with a RAM buffer area for storing first data, an NVM backup area and a user area, wherein the NVM backup area is used for storing second data, the user area is used for storing update data, and the RAM buffer area and the NVM backup area form a backup space. For transactions made up of multiple APDU instructions, the storage device handles according to Session (Session) states. In the state of starting the session, the data corresponding to each APDU is stored in the RAM buffer as first data. And in a closed session state, the first data is written into the NVM backup area as second data, and the data of the user area is updated by the second data.

Description

Data updating method of storage device
Technical Field
The present invention relates to a data updating method for a storage device, and more particularly, to an updating method when a plurality of instructions are subjected to session processing.
Background
As the storage device, for example, a smart card embedded device operates based on an on-chip operating system (COS, chip Operating System). The application processes the data by executing application protocol data unit (APDU, application Protocol Data Unit) instructions and stores the data on random access Memory (RAM, random Access Memory), non-Volatile Memory (NVM). Data storage management of NVM is one of the most core and complex functions. The main reason is that: firstly, the application scene of the smart card is complex and various, the environment is bad, and the problems that the voltage of equipment is unstable at any time or the power supply voltage is lost often occur. Secondly, because the application program executes the instruction for a certain time interval, for example, the data is lost or incomplete due to the half-way card pulling or off-site operation in the card swiping process.
Because of the NVM fabrication process, NVM requires erasing and then writing NVM pages while preserving data, and thus NVM hardware cannot guarantee the atomicity of page write operations. In order to guarantee the integrity of the data, COS systems need to achieve the atomicity of page operations through NVM drivers. That is, the transaction protection processing for page operations is implemented through NVM driver. The transaction protection processing refers to that when an APDU instruction operates on a single NVM page or multiple NVM pages, if power is off in the execution process of the APDU instruction, the transaction protection of COS needs to ensure that all page data of the NVM keep old data before APDU execution or new data after APDU execution.
The prior transaction management technical method solves the problems, and comprises the following steps:
for power-off protection, byte protection and page protection are performed on the NVM old data. The method comprises the steps of firstly backing up byte data of an NVM page to be rewritten, along with a start address and length information, to a specific byte backup area, secondly copying the whole page data to be rewritten to a page backup area, and concatenating a mapping relation between a source address and a destination address of the page backup and a mapping effective mark.
The transaction protection is generally defined within the scope of a single APDU instruction that corresponds to the protection of a single page NVM or a multi-page NVM.
The disadvantages of the existing scheme are:
1. the existing scheme aims at a single APDU instruction, and can process data protection during power failure, but cannot do transaction protection for the whole transaction flow.
2. The page erasing of NVM is the most time-consuming operation in instruction execution, and frequent byte protection and page protection slow down instruction execution.
3. During a transaction, the updated length of certain instructions does not coincide with the expected length, for example: the update record file instruction, APDU is only passed into the first few bytes of the record, with the following bytes clear 0. If all the backups are to be recorded, space wastage and uncontrollable space would be the result. If only APDU data is backed up, the original data of the record is lost after power failure when the transaction is submitted.
Disclosure of Invention
Accordingly, the present invention is directed to the above-mentioned problems occurring in the prior art, and a first objective of the present invention is to provide a data updating method capable of performing transaction protection on the whole transaction flow.
A second object is to improve data processing efficiency when executing a plurality of instructions.
A third object is that during a transaction, the original data is lost due to the fact that the updated length of the instruction is not consistent with the expected length.
The first technical scheme of the invention is a data updating method of a storage device, which is characterized in that:
setting a RAM buffer area in a RAM of a storage device for storing first data, setting an NVM backup area in an NVM for storing second data and a user area for storing updated data, the RAM buffer area and the NVM backup area constituting a backup space,
for transactions consisting of a plurality of APDU instructions, the storage device handles according to the session state,
in the state of starting the session, the data corresponding to each APDU is stored as first data in the RAM buffer,
and in a closed session state, the first data is written into the NVM backup area as second data, and the data of the user area is updated by the second data.
Preferably, when the update length and the record length are inconsistent, the APDU command operation requires that the current file is a circular record file, the ItemDataLen is the update length, and the value ext is the total length of the current record.
Preferably, backup checklen=length of session backup entry header+length of APDU command operation requires update, datalen=length of session backup entry header+length of APDU command operation requires update+length of record pointer.
When the session state is preferably started, checking whether the check length and the backup length overflow, if not, organizing session backup items in the RAM buffer in a TLV format, and increasing related item values in a session backup area head in the RAM buffer, wherein the method comprises the following steps: the number of backup items, the length value of the RAM buffer area and the check length value of the RAM buffer area are used for processing each APDU instruction one by one in a circulating way until the session is in a closed session state,
refreshing the TLV format data stored in the RAM buffer area to the NVM backup area,
and writing the TLV format data in the NVM backup area into the user area according to the destination address.
The required first data, i.e., the backup data, preferably stored in the RAM buffer is TLV-formatted data, which is TLV data generated by appending a plurality of APDU command data in a session in TLV format one by one to the RAM buffer.
Preferably, the TLV format data is generated by a plurality of APDU command data, and the backup area space margin is estimated by limiting the updated single APDU data length to the fixed length of the session backup entry header+the APDU data length.
Preferably, the TLV format data is stored in the RAM buffer by preferentially backing up a plurality of APDU commands to the RAM buffer and maintaining the data in the RAM during the whole session until the session is finished, and then the data is submitted to the NVM backup area, so as to avoid organizing the NVM backup area data multiple times.
Preferably, when the first data in TLV format stored in the RAM buffer, i.e. the backup data is refreshed to the NVM backup area as the second data, the integrity of the session operation is judged by the session backup area check code CRC 16.
And preferably, the integrity of the session operation is optimized, and when the session outage occurs before the writing of the NVM backup area is completed, the data of the NVM backup area is emptied and rollback processing is performed when the chip is powered on again.
And preferably, the integrity of the session operation is optimized, and when the chip is powered up again after the writing of the NVM backup area is completed, the writing operation from the NVM backup area to the destination address of the user area is continuously executed, and the submitting process is performed.
Drawings
In order to more clearly illustrate the embodiments of the invention or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, it being obvious that the drawings in the description below are only some embodiments of the invention, and that other drawings can be obtained according to these drawings without inventive faculty for a person skilled in the art.
FIG. 1 is a schematic view of an overall framework of COS in an embodiment of the invention;
FIG. 2 is a functional illustration of a backup space and a user space;
FIG. 3 is a diagram illustrating the structure of transaction data;
FIG. 4 is a transaction flow diagram of an embodiment of the present invention;
FIG. 5 is a commit and rollback illustrative diagram of transaction data;
fig. 6 is a diagram illustrating processing when a plurality of instructions are inconsistent with generated transaction data.
Detailed Description
Various exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be noted that: the relative arrangement of the components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present invention unless it is specifically stated otherwise.
Meanwhile, it should be understood that the sizes of the respective parts shown in the drawings are not drawn in actual scale for convenience of description.
The following description of at least one exemplary embodiment is merely exemplary in nature and is in no way intended to limit the invention, its application, or uses.
Techniques, methods, and apparatus known to one of ordinary skill in the relevant art may not be discussed in detail, but are intended to be part of the specification where appropriate.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further discussion thereof is necessary in subsequent figures.
The method of updating transaction data will be described below using a smart card as an example. The chip as a smart card includes at least two memory areas, a RAM and an NVM. Transaction data is updated by a plurality of APDU instructions sent by the upper computer. The chip is run by an on-Chip Operating System (COS).
The transactional commit and rollback method of session operations in the present invention is described below.
FIG. 1 is a schematic view of the overall framework of COS in an embodiment of the invention, as shown in FIG. 1:
the overall framework 100 of the COS program includes four layers, namely, a communication layer 110, an application layer 120, a functional module 130, and a COS bottom layer interface 140.
The communication layer 110 includes 7816 protocols and 14443 protocols 111. The application layer 120 includes an electronic wallet application 121, an intelligent cryptographic advantage application 122, and a tax control application 123. The functional modules 130 include a lifecycle management 131, a rights identification module 132, an algorithm module 133, and a file management module 134. The COS bottom layer interface 140 includes a transaction layer 141, an NVM read/write interface 142, and an algorithm interface 143, where the NVM read/write interface 142 and the algorithm interface 143 are connected to the chip hardware 201 (hardware layer), and the transaction layer 141 performs data read/write operations through the NVM read/write interface 142.
Fig. 2 is a functional explanatory diagram of the backup space and the user space, as shown in fig. 2:
a RAM buffer is established in a RAM area of the chip, and an NVM backup area and an NVM user area are established in an NVM area. The RAM buffer and the NVM backup area constitute a backup space.
The RAM buffer and NVM backup areas are sized to accommodate all APDU transaction data as expected, in this embodiment set to 4096 bytes.
The transaction comprises a plurality of APDU instructions, firstly, the upper computer sends out a thing start instruction, data needing to be backed up is stored in a RAM buffer area in a TLV format, each APDU instruction is sequentially executed, new data is circularly added in the RAM buffer area in the TLV format, and data (first data) corresponding to the plurality of APDU instructions are generated until the upper computer sends out a thing end instruction. The TLV formatted data stored in the RAM buffer is flushed to the NVM backup area. Thereafter, the data (second data) in the NVM backup zone is written to the corresponding location in the NVM user zone according to the target address, and third data is generated at the corresponding location in the NVM user zone. Thus, the commit of the entire transaction is completed.
Fig. 3 is a diagram illustrating the structure of transaction data, as shown in fig. 3:
session backup area B100 is composed of backup area header B110 and Data B120. The backup area header is composed of DataLen, checkLen, checkCode, itemNum. The Data B120 is formed by serially connecting a plurality of session backup items B200, and each session backup item B200 corresponds to an APDU command, and in addition, the session backup item B200 further includes a record pointer B230 of 1 byte.
The session backup area B100 data definition is as shown in table 1 below:
TABLE 1 Session backup area
The session backup item B200 is composed of a session backup item header and APDU data. The session backup item is composed of ItemType, startPage, offset, itemDataLen, valueExt, itemData, wherein ItemType, startPage, offset, itemDataLen, valueExt is session backup item header B210, which is 6 bytes in length. ItemData B220 is session data backed up in a single instruction, which is of a non-fixed length.
The data definitions for the session backup items are shown in table 2 below:
TABLE 2 Session backup items
In addition, the session backup item B200 further includes a 1-byte recording pointer B230 for specifying the data address actually required to be updated in the NVM user area.
FIG. 4 is a transaction flow diagram according to an embodiment of the present invention, as shown in FIG. 4:
the intelligent card is connected with the upper computer, and the upper computer updates the data in the intelligent card through the APDU instruction. For the session processing formed by a plurality of APDU instructions, when the upper computer downloads the APDU instructions, the smart card is set to be in a session starting state, the APDU instructions are processed one by one until the last APDU instruction of the session processing is sent, and then the smart card is set to be in a session closing state.
Step S01, after the smart card (chip) is reset (connected with the upper computer), the session backup area head is initialized.
The session backup area header is initialized, i.e., set to 0 for DataLen, checkLen, checkCode, itemNum.
In step S02, the smart card receives an APDU command that requires modification of the NVM.
After the session starts, the smart card receives the 1 st APDU command, which is used to modify the data stored on the NVM.
In step S03, the smart card determines whether it is in an open session state.
After receiving the 1 st APDU command for modifying the NVM data, the smart card checks whether the current state is a state for opening the session. If the session processing state is the open session state, then the transaction has been initiated, in which state all data modifications are made as an inseparable single process until the transaction is completed.
Step S04, calling the operation of adding the session backup item.
In the open session state, the data of APDUs are ready to be backed up into the RAM cache session backup area.
Step S05, checking whether the check length overflows, and Len is the length value of 6+APDU data (CheckLen+Len > 608).
Checklen=checklen+len, the initial value of CheckLen is 0, len=6+the length value of apdu data. CheckLen is a cyclic cumulative value, and the cumulative number is the number of APDU instructions. The calculation formula len=6+6 in apdu is the byte length of the session backup entry header, and is a fixed length value, that is, the sum of the length values of the occupied bytes of ItemType, startPage, offset, itemDataLen, valueExt in the session backup entry header is 6.
Further, 608 in the calculation formula checklen+len >608 is a limit value, and when the length value of the loop-accumulated checklen+len is larger than the limit value, it is determined that the accumulated APDU command data length overflows.
Step S06, checking whether the backup length overflows, itemDataLen is the actual length (DataLen+ItemDataLen > 4096).
Datalen=datalen+ ItemDataLen, dataLen has an initial value of 0, and itemdatalen is the actual length value of the session backup item ItemData data. DataLen is the loop cumulative value, and the cumulative number is the number of APDU instructions.
In addition, 4096 in the calculation formula datalen+itemdatalen >4096 is a limit value, and when the length value of the cyclically accumulated datalen+itemdatalen is greater than the limit value, it is determined that the sum of the accumulated respective ItemData data lengths overflows.
In step S07, the session backup item (6 byte header data+apdu data) is organized in the RAM buffer.
And organizing session backup items in a TLV format in a RAM buffer area, wherein each session backup item is composed of 6 bytes of session backup item header data and APDU data.
Step S08, the number field value of the backup items of the RAM buffer is +1.
The initial value of ItemNum field of the session backup area is 0, and after increasing the number of backup items, accumulation processing is performed.
Step S09, the RAM buffer length value is incremented (datalen=datalen+itemdatalen).
The data to be updated in the circular accumulation RAM buffer session actually occupies a space length.
Step S10, the RAM buffer check length value is incremented (checklen=checklen+len).
And circularly accumulating the space length occupied by the check data of the RAM buffer area.
Step S11, whether to close the session.
Judging whether to close the session, if so, submitting the transaction.
Step S12, the RAM buffer is refreshed to the NVM backup area.
And refreshing the TLV-format data stored in the RAM buffer area to the NVM backup area.
Step S13, writing the NVM backup area data into the user destination address.
And writing the TLV format data in the NVM backup area into the user area according to the destination address.
And S14, clearing the RAM and the buffer memory of the NVM backup area, and directly calling a write file interface.
If step S03 is a non-open session state, then the RAM and the buffer data of the NVM backup area are emptied, the write file interface is directly called, and the file is written in the NVM user area.
And S15, overflowing the backup area and reporting errors.
If the steps S05 and S06 are overflows, the error is directly reported.
FIG. 5 is a commit and rollback illustration of transaction data, as shown in FIG. 5:
the integrity of the session operation is judged by the session backup area check code CRC 16.
100A. Session outage occurs before the completion of the writing of the NVM back-up region, and when the chip is powered up again, the NVM back-up region data is emptied (RAM buffer is automatically emptied).
100B. session power down occurs after the completion of the writing of the NVM back-up region, and when the chip is powered up again, the writing operation of the NVM back-up region to the user region destination address is continued.
FIG. 6 is a diagram illustrating processing when a plurality of instructions are inconsistent with generated transaction data, as shown in FIG. 6:
the record file in COS system is a special file, and is composed of record number and record length of each record, and some APDU instruction operation requires that the updated length is inconsistent with the record file length.
The following is an example of session processing.
Preconditions for processing and requirements:
1. the file id= "0A" is a cyclic record file, the number of records is 10, and each record length is 250 bytes.
2. The APDU instruction requires 2 records to be added to the "0A" file cycle, wherein the first 3 bytes of the 1 st record are 112233, the other bytes are clear of 0; the first 3 bytes of record 2 are 44556, the other bytes are clear 0. The cyclical recording file is characterized in that the newly added record overlaps the original oldest record.
3. The data of the original oldest record of the 0A file is 01020304050607 … EDEEEFF0 of 16 scale; the data of the second-old record is "0405060708090A … EDEEEFF0" with 16 scale "
4. After the update is completed, the current record pointer needs to be synchronously updated to point to the newly added record.
Send 2 APDU instructions:
instruction 1: apdu= 00D60002 03 112233
Instruction 2: apdu= 00D60002 03 445566
Where D6 is an instruction, 02 represents the second record, 03 represents the update length, and 112233 and 445566 represent the update data.
The existing problems are:
problem 1: since the update length 03 is not equal to the record length 250, buffer overflow is easily caused if 250 bytes are all saved to the RAM cache and it is considered that this instruction may occur multiple times during the entire session.
Problem 2: the design specifies that the length value into the session must be 6+3, but since the record pointer takes 1 byte, the length and the expected collision occur.
The invention solves the problem 1 by marking the ItemType of the backup item to indicate that the current file is a circular record file, itemDataLen is update length=4 (data length 3 bytes+record pointer 1 byte), and ValueExt is current record total length=250.
Problem 2 is solved by satisfying the length value of the design contract session by checklen=6+3, datalen=6+3+1 into the backup area to be 6+apdu data length.
The solution flow of the specific 2 APDU instructions is as follows:
step C10, issue 1 st instruction apdu= 00D60002 03 112233
Step C11, the DataLen of the session backup area is 6+3+1 bytes long, the CheckLen is 6+3 bytes long, and the CheckCode is the check code calculated by CRC 16; the value of ItemNum increases from 0 to 1; data place 1 st APDU Data.
Step C12, the 1 st APDU Data of the Data placement includes the session backup item 1.
Step C13, the data of the session backup item 1 comprises that ItemType is set as a circulation flag; startPage is the starting page position j calculated according to the recording parameters of the APDU instruction; offset is the Offset position from the start position, this example being 3; the value of ItemDataLen is 3+1, where 3 is the ItemData data length and 1 is the pointer length of one byte; valueExt is 250; itemData is 112233; a pointer 1 is recorded.
Step C20, issue 2 nd instruction apdu= 00D60002 03 445566
Step C21, the DataLen of the session backup area is (6+3+1) + (6+3+1), i.e. 20 bytes long, and the CheckLen is (6+3) + (6+3), i.e. 18 bytes long, and the CheckCode is the check code calculated by CRC 16; the value of ItemNum increases from 1 to 2; data place 1 st APDU data+2 nd APDU Data.
In step C22, the 1 st APDU data+2 nd APDU Data of the Data placement comprises a session backup item 1+a session backup item 2.
Step C23, the 1 st APDU data+the data of the session backup item 2 comprises adding new data based on the data of the step C13, and setting ItemType as a circulation flag; startPage is the start page position k calculated from the recording parameters of the APDU instruction; offset is the Offset position from the start position, this example being 3; the value of ItemDataLen is 3+1, where 3 is the ItemData data length and 1 is the pointer length of one byte; valueExt is 250; itemData is 445566, and record pointer 2.
From the above, the present invention is a transaction-based smart card multi-instruction caching method. In the original COS system, in order to ensure the integrity of data, the COS system needs to conduct transaction protection processing on page operations through an NVM driver, so that the atomicity of the page operations is ensured. However, the transaction protection is generally limited to a single APDU instruction that corresponds to the protection of a single page NVM or a multi-page NVM. The disadvantages are: the transaction protection cannot be performed on the transaction flow of a plurality of APDU instructions; because the page erasing of the NVM is time-consuming, page protection is performed for each APDU instruction, so that instruction execution is slowed down; in addition, the updated length of some instructions is inconsistent with the expected original data length, which tends to result in wasted space and uncontrollable space.
The transaction submitting or rollback problem of the session operation is solved by backing up a plurality of APDU instruction data in the session to the RAM buffer area and the NVM backup area in the form of TLV data; in addition, by preferentially backing up a plurality of APDU instructions to the RAM buffer area and maintaining data in the RAM during the whole session, the method that session data are organized to the NVM backup area data only 1 time is realized, and the overall performance of transaction is improved; the problem that the upper computer needs to have a definite estimated value for the space allowance of the backup area is solved by limiting the updated single APDU data length to the calculated length method of the fixed-length session backup item head plus the APDU data length; the problem of inconsistent data updating length during the session is solved by separating and judging the data length of a plurality of APDU instructions issued by the upper computer from the data length added into the session buffer zone.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
Thus far, the present disclosure has been described in detail. In order to avoid obscuring the concepts of the invention, some details known in the art have not been described. How to implement the solutions disclosed herein will be fully apparent to those skilled in the art from the above description.
The description of the present invention has been presented for purposes of illustration and description, and is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art. The embodiments were chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.

Claims (10)

1. The data updating method of the storage device is characterized by comprising the following steps of:
setting a RAM buffer area in a RAM of a storage device for storing first data, setting an NVM backup area in an NVM for storing second data and a user area for storing updated data, the RAM buffer area and the NVM backup area constituting a backup space,
for transactions consisting of a plurality of APDU instructions, the storage device handles according to Session (Session) states,
in the state of opening the session, the data corresponding to each APDU is stored in the RAM buffer as first data in TLV format,
and under the state of closing the session, refreshing the first data stored in the RAM buffer area to the NVM backup area as second data in a TLV format, and then writing the second data in the NVM backup area into the data of the user area according to a destination address.
2. The data updating method of a storage device according to claim 1, wherein:
when the update length and the record length are inconsistent, the APDU instruction operation requires that the ItemType of the backup item is marked, the current file is a circulating record file, itemDataLen is marked as the update length, and ValueExt is marked as the total length of the current record.
3. The data updating method of a storage device according to claim 2, wherein:
backup checklen=length of session backup entry header+length of APDU command operation requiring update, datalen=length of session backup entry header+length of APDU command operation requiring update+length of record pointer.
4. A data updating method of a storage device according to any one of claims 1 to 3, characterized in that:
when the session state is started, checking whether the check length and the backup length overflow, if not, organizing session backup items in the RAM buffer in a TLV format, and increasing related item values in a head of the session backup area in the RAM buffer, wherein the method comprises the following steps: and the number of the backup items, the length value of the RAM buffer area and the check length value of the RAM buffer area are used for processing each APDU instruction one by one in a circulating way until the session is in a closed session state.
5. The data updating method of a storage device according to claim 4, wherein: the required first data stored in the RAM buffer, i.e., the backup data, is TLV-formatted data, which is TLV data generated by appending a plurality of APDU command data in a session in TLV format one by one to the RAM buffer.
6. The data updating method of a storage device according to claim 5, wherein:
the TLV format data is generated by a plurality of APDU instruction data, and the updated single APDU data length is limited to the fixed length of the session backup item head and the length of the APDU data so as to estimate the space allowance of the backup area.
7. The data updating method of a storage device according to claim 6, wherein:
the TLV format data is in a mode of backing up a plurality of APDU instructions to a RAM buffer area preferentially and maintaining the data in the RAM during the whole session until the session is finished, and the data is submitted to an NVM backup area, so that the data in the NVM backup area is prevented from being organized for a plurality of times.
8. The data updating method of a storage device according to claim 7, wherein:
and refreshing the first data in the TLV format stored in the RAM buffer area, namely the backup data, to an NVM backup area, and judging the integrity of the session operation through a session backup area check code CRC 16.
9. The data updating method of a storage device according to claim 8, wherein:
and when the session is powered off before the writing of the NVM backup area is completed, the data of the NVM backup area is emptied and rollback processing is carried out.
10. The method for updating data of a memory device according to claim 8, wherein the integrity of the session operation is that the session power-off occurs after the writing of the NVM backup area is completed, and when the chip is powered up again, the writing operation from the NVM backup area to the destination address of the user area is continued for commit processing.
CN202011454618.7A 2020-12-10 2020-12-10 Data updating method of storage device Active CN112698785B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011454618.7A CN112698785B (en) 2020-12-10 2020-12-10 Data updating method of storage device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011454618.7A CN112698785B (en) 2020-12-10 2020-12-10 Data updating method of storage device

Publications (2)

Publication Number Publication Date
CN112698785A CN112698785A (en) 2021-04-23
CN112698785B true CN112698785B (en) 2024-03-29

Family

ID=75508719

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011454618.7A Active CN112698785B (en) 2020-12-10 2020-12-10 Data updating method of storage device

Country Status (1)

Country Link
CN (1) CN112698785B (en)

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012088867A (en) * 2010-10-18 2012-05-10 Dainippon Printing Co Ltd Ic card and ic card system capable of dynamically changing session buffer
CN111008159A (en) * 2019-11-28 2020-04-14 北京握奇智能科技有限公司 Data protection method, device, equipment and storage medium for storage equipment

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7509487B2 (en) * 2003-09-29 2009-03-24 Gemalto Inc. Secure networking using a resource-constrained device
JP5976458B2 (en) * 2012-08-23 2016-08-23 株式会社東芝 IC card and portable electronic device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2012088867A (en) * 2010-10-18 2012-05-10 Dainippon Printing Co Ltd Ic card and ic card system capable of dynamically changing session buffer
CN111008159A (en) * 2019-11-28 2020-04-14 北京握奇智能科技有限公司 Data protection method, device, equipment and storage medium for storage equipment

Also Published As

Publication number Publication date
CN112698785A (en) 2021-04-23

Similar Documents

Publication Publication Date Title
CN106471478B (en) Device controller and method for performing multiple write transactions atomically within a non-volatile data storage device
US9495286B2 (en) Method and arrangement for completion or recovery of data transactions in a flash type memory device using a commit process
US20090013122A1 (en) Transaction Method for Managing the Storing of Persistent Data in a Transaction Stack
JP2003216902A (en) Proximity communication system and method, data management device and method, storage medium, and computer program
US20060200500A1 (en) Method of efficiently recovering database
JP2003513357A (en) Method and apparatus for performing atomic updates using a logical flash memory device
US20070011416A1 (en) Data storage device and medium and related method of storing backup data
CN101561950B (en) Method and device for processing data of intelligent card
US20030126163A1 (en) Method for file deletion and recovery against system failures in database management system
CN107704603A (en) A kind of method and device for realizing read and write abruption
JP5057887B2 (en) Data update device, data update method, and data update program
CN112698785B (en) Data updating method of storage device
CN111159156B (en) Backup method and device for SQLite database
JP4931711B2 (en) Kernel update method, information processing apparatus, program, and storage medium
CN111694806A (en) Transaction log caching method, device, equipment and storage medium
EP2102748B1 (en) System and method for recovery of memory transactions
CN115469911A (en) Parameter configuration method, system and computer readable storage medium
JP4060639B2 (en) Data management device
JP3313576B2 (en) Memory access control method and device
JP2004295272A (en) Transaction control method
JP4140750B2 (en) IC card memory access control method and apparatus, and program storage medium
TWI805449B (en) Method for performing access control of memory device with aid of multi-stage garbage collection management, memory controller of memory device, and memory device
JP5708228B2 (en) IC card and IC card refresh method
CN101464817B (en) Data recovery method
JP6252341B2 (en) Electronic information storage medium, information processing method, and information processing 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
GR01 Patent grant
GR01 Patent grant