crypto: atmel-sha204a - add reading from otp zone
Provide a read function reading the otp zone. The otp zone can be used for storing serial numbers. The otp zone, as also data zone, are only accessible if the chip was locked before. Locking the chip is a post production customization and has to be done manually i.e. not by this driver. Without this step the chip is pretty much not usable, where putting or not putting data into the otp zone is optional. Signed-off-by: Lothar Rubusch <l.rubusch@gmail.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
parent
3f5f746165
commit
e05ce444e9
@ -70,6 +70,30 @@ void atmel_i2c_init_read_config_cmd(struct atmel_i2c_cmd *cmd)
|
||||
}
|
||||
EXPORT_SYMBOL(atmel_i2c_init_read_config_cmd);
|
||||
|
||||
int atmel_i2c_init_read_otp_cmd(struct atmel_i2c_cmd *cmd, u16 addr)
|
||||
{
|
||||
if (addr < 0 || addr > OTP_ZONE_SIZE)
|
||||
return -1;
|
||||
|
||||
cmd->word_addr = COMMAND;
|
||||
cmd->opcode = OPCODE_READ;
|
||||
/*
|
||||
* Read the word from OTP zone that may contain e.g. serial
|
||||
* numbers or similar if persistently pre-initialized and locked
|
||||
*/
|
||||
cmd->param1 = OTP_ZONE;
|
||||
cmd->param2 = cpu_to_le16(addr);
|
||||
cmd->count = READ_COUNT;
|
||||
|
||||
atmel_i2c_checksum(cmd);
|
||||
|
||||
cmd->msecs = MAX_EXEC_TIME_READ;
|
||||
cmd->rxsize = READ_RSP_SIZE;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(atmel_i2c_init_read_otp_cmd);
|
||||
|
||||
void atmel_i2c_init_random_cmd(struct atmel_i2c_cmd *cmd)
|
||||
{
|
||||
cmd->word_addr = COMMAND;
|
||||
|
@ -64,6 +64,10 @@ struct atmel_i2c_cmd {
|
||||
|
||||
/* Definitions for eeprom organization */
|
||||
#define CONFIGURATION_ZONE 0
|
||||
#define OTP_ZONE 1
|
||||
|
||||
/* Definitions for eeprom zone sizes */
|
||||
#define OTP_ZONE_SIZE 64
|
||||
|
||||
/* Definitions for Indexes common to all commands */
|
||||
#define RSP_DATA_IDX 1 /* buffer index of data in response */
|
||||
@ -179,6 +183,7 @@ void atmel_i2c_flush_queue(void);
|
||||
int atmel_i2c_send_receive(struct i2c_client *client, struct atmel_i2c_cmd *cmd);
|
||||
|
||||
void atmel_i2c_init_read_config_cmd(struct atmel_i2c_cmd *cmd);
|
||||
int atmel_i2c_init_read_otp_cmd(struct atmel_i2c_cmd *cmd, u16 addr);
|
||||
void atmel_i2c_init_random_cmd(struct atmel_i2c_cmd *cmd);
|
||||
void atmel_i2c_init_genkey_cmd(struct atmel_i2c_cmd *cmd, u16 keyid);
|
||||
int atmel_i2c_init_ecdh_cmd(struct atmel_i2c_cmd *cmd,
|
||||
|
@ -91,6 +91,29 @@ static int atmel_sha204a_rng_read(struct hwrng *rng, void *data, size_t max,
|
||||
return max;
|
||||
}
|
||||
|
||||
static int atmel_sha204a_otp_read(struct i2c_client *client, u16 addr, u8 *otp)
|
||||
{
|
||||
struct atmel_i2c_cmd cmd;
|
||||
int ret = -1;
|
||||
|
||||
if (atmel_i2c_init_read_otp_cmd(&cmd, addr) < 0) {
|
||||
dev_err(&client->dev, "failed, invalid otp address %04X\n",
|
||||
addr);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = atmel_i2c_send_receive(client, &cmd);
|
||||
|
||||
if (cmd.data[0] == 0xff) {
|
||||
dev_err(&client->dev, "failed, device not ready\n");
|
||||
return -ret;
|
||||
}
|
||||
|
||||
memcpy(otp, cmd.data+1, 4);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int atmel_sha204a_probe(struct i2c_client *client)
|
||||
{
|
||||
struct atmel_i2c_client_priv *i2c_priv;
|
||||
|
Loading…
Reference in New Issue
Block a user