SD card encryption security card and the release of the lock, write protection and password features

Previous describes the process of debugging tools and timing of the underlying SD card driver, suitable for beginners to learn, but in the safety-related automotive-grade large-scale projects will need some data security. Now tell us about the knowledge and protection aspects of the lifting of the SD card.

        SD card information in the official English (can be downloaded from the link https://download.csdn.net/download/code_dzhangteng/10278568) describes three ways:

1, hardware write protection;

2, SD card inside the software write protection;,

3, SD card latch / password. The first is simple, but difficult to achieve security and confidentiality; the second is too complicated, you need to write the address block protection settings one by one, give themselves a great burden; third is locked card, the user needs password, the password and the password can be placed in an embedded microcontroller, does not add any burden. In the automotive-grade embedded, this method is very practical, very safe.

        1, SD card side and a LOCK switch identification. Switch to the LOCK position, the SD card is in the hardware write protection, the internal data of the SD card can not be written; LOCK switch to the other side, the SD card is released hardware write protection.

        2, SD card write-protection block 6 as in Command Card Command Class, CMD28 block address is write protected; CMD29 erase block address write-protected; CMD30 query command to query the status of the write protect bit.

        eg: send commands CMD28: 0x5C, 0x ##, 0x ##, 0x ##, 0x ##, 0xFF; 0x ## to four write-protected block address. If you do not understand, you can refer to the introduction of a.

        3, SD card has a security encryption. In an encrypted state, the user must provide a password before they can access the data in the card. At power-card, if the card contains a password, the card automatically enter the locked state, both read and write commands return an error to protect the contents of the card being read and modify.

Password setting function is realized by CMD42, which data includes all information in the command packet.

eg:

① latch set state (the LOCK)
using Block length is set CMD16 PWD_LEN + 2;
send commands CMD42: 0x6A, 0x00,0x00,0x00,0x00,0x95;
send command data: 0x04, LEN, password [LEN] ......, 0xFF, 0xFF;
using CMD16 Block restore the original length.
② latch released state (the UNLOCK)
using CMD16 Block length is set 1;
send commands CMD42: 0x6A, 0x00,0x00,0x00,0x00,0x95;
send command data: 0x08,0xFF, 0xFF;
using CMD16 Block restore the original length.

 eg:

① Set the PWD (password)
using the Block length is set CMD16 password length PWD_LEN + 2;
send commands CMD42: 0x6A, 0x00,0x00,0x00,0x00,0x95;
send command data: 0x01, LEN, CMD_DATA0, CMD_DATA1 ......, 0xFF , 0xFF;
using CMD16 Block restore the original length.
② Clear the PWD (password)
using the Block length is set CMD16 PWD_LEN + 2;
send commands CMD42: 0x6A, 0x00,0x00,0x00,0x00,0x95;
send command data: 0x02, LEN, CMD_DATA0, CMD_DATA1 ......, 0xFF, 0xFF;
Block length using CMD16 to restore the original.
③ modify the PWD (password)
using the Block length is set CMD16 OLD_PWD_LEN + NEW_PWD_LEN + 2;
send commands CMD42: 0x6A, 0x00,0x00,0x00,0x00,0x95;
send command data: 0x05, LEN, the old password [n], the new password [m] ......, 0xFF, 0xFF ;
using CMD16 Block restore the original length.

    You may well be set to lock the card by the above methods, to protect the contents of the SD card. Usually get the card is locked, when they can not use, it can be erased by the above method to force latch state, resume use.

    Note: The above link is CSDN download link, which ①SD card physical layer protocol Ver2.0 (in 2006); ②SD card physical layer protocol Ver3.01 (2010 years); ③SD card physical layer protocol Ver4.10 (2013 years ); ④SD card physical layer protocol Ver6.00 (2017 years).

Which version to use the SD card, SD physical layer protocol can interpret in accordance with the SD card corresponds to FIG selected version. (Recommended study Ver6.00 latest version).


-

Guess you like

Origin blog.csdn.net/u010783226/article/details/92002156