mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 03:40:35 +09:00
unifykey: fix bug for read/write efuse key
PD#168551: need to use unifykey to read/write efuse key 1.fix efuse config name to CONFIG_AMLOGIC_EFUSE 2.add correct efuse key read funciton Change-Id: I415f1b68d5de090220b1bd96db299452af176626 Signed-off-by: Zhongfu Luo <zhongfu.luo@amlogic.com>
This commit is contained in:
@@ -309,6 +309,11 @@ ssize_t efuse_user_attr_store(char *name, const char *buf, size_t count)
|
||||
}
|
||||
|
||||
local_buf = kzalloc(sizeof(char)*(count), GFP_KERNEL);
|
||||
if (!local_buf) {
|
||||
ret = -ENOMEM;
|
||||
pr_err("efuse: failed to allocate memory!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
memcpy(local_buf, buf, count);
|
||||
|
||||
@@ -367,6 +372,12 @@ ssize_t efuse_user_attr_show(char *name, char *buf)
|
||||
}
|
||||
|
||||
local_buf = kzalloc(sizeof(char)*(info.size), GFP_KERNEL);
|
||||
if (!local_buf) {
|
||||
ret = -ENOMEM;
|
||||
pr_err("efuse: failed to allocate memory!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(local_buf, 0, info.size);
|
||||
|
||||
pos = ((loff_t)(info.offset)) & 0xffffffff;
|
||||
@@ -394,6 +405,44 @@ error_exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
ssize_t efuse_user_attr_read(char *name, char *buf)
|
||||
{
|
||||
char *local_buf;
|
||||
ssize_t ret;
|
||||
struct efusekey_info info;
|
||||
loff_t pos;
|
||||
|
||||
if (efuse_getinfo(name, &info) < 0) {
|
||||
pr_err("%s is not found\n", name);
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
local_buf = kzalloc(sizeof(char)*(info.size), GFP_KERNEL);
|
||||
if (!local_buf) {
|
||||
ret = -ENOMEM;
|
||||
pr_err("efuse: failed to allocate memory!\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
memset(local_buf, 0, info.size);
|
||||
|
||||
pos = ((loff_t)(info.offset)) & 0xffffffff;
|
||||
ret = efuse_read_usr(local_buf, info.size, &pos);
|
||||
if (ret == -1) {
|
||||
pr_err("ERROR: efuse read user data fail!\n");
|
||||
goto error_exit;
|
||||
}
|
||||
if (ret != info.size)
|
||||
pr_err("ERROR: read %zd byte(s) not %d byte(s) data\n",
|
||||
ret, info.size);
|
||||
|
||||
memcpy(buf, local_buf, info.size);
|
||||
|
||||
error_exit:
|
||||
kfree(local_buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t userdata_show(struct class *cla,
|
||||
struct class_attribute *attr, char *buf)
|
||||
{
|
||||
|
||||
@@ -283,7 +283,7 @@ static int key_efuse_init(struct key_info_t *uk_info,
|
||||
static int key_efuse_write(char *keyname, unsigned char *keydata,
|
||||
unsigned int datalen)
|
||||
{
|
||||
#ifdef CONFIG_EFUSE
|
||||
#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE)
|
||||
char *title = keyname;
|
||||
struct efusekey_info info;
|
||||
|
||||
@@ -306,7 +306,7 @@ static int key_efuse_write(char *keyname, unsigned char *keydata,
|
||||
static int key_efuse_read(char *keyname, unsigned char *keydata,
|
||||
unsigned int datalen, unsigned int *reallen)
|
||||
{
|
||||
#ifdef CONFIG_EFUSE
|
||||
#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE)
|
||||
char *title = keyname;
|
||||
struct efusekey_info info;
|
||||
int err = 0;
|
||||
@@ -320,7 +320,7 @@ static int key_efuse_read(char *keyname, unsigned char *keydata,
|
||||
return -ENOMEM;
|
||||
memset(buf, 0, info.size);
|
||||
|
||||
err = efuse_user_attr_show(title, buf);
|
||||
err = efuse_user_attr_read(title, buf);
|
||||
if (err >= 0) {
|
||||
*reallen = info.size;
|
||||
if (datalen > info.size)
|
||||
@@ -337,7 +337,7 @@ static int key_efuse_read(char *keyname, unsigned char *keydata,
|
||||
static int key_efuse_query(char *keyname, unsigned int *keystate)
|
||||
{
|
||||
int err = -EINVAL;
|
||||
#ifdef CONFIG_EFUSE
|
||||
#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE)
|
||||
int i;
|
||||
char *title = keyname;
|
||||
struct efusekey_info info;
|
||||
@@ -351,7 +351,7 @@ static int key_efuse_query(char *keyname, unsigned int *keystate)
|
||||
return -ENOMEM;
|
||||
}
|
||||
memset(buf, 0, info.size);
|
||||
err = efuse_user_attr_show(title, buf);
|
||||
err = efuse_user_attr_read(title, buf);
|
||||
*keystate = KEY_NO_EXIST;
|
||||
if (err > 0) {
|
||||
for (i = 0; i < info.size; i++) {
|
||||
@@ -543,7 +543,7 @@ int key_unify_size(struct aml_unifykey_dev *ukdev,
|
||||
|
||||
if (unifykey->permit & KEY_M_PERMIT_READ) {
|
||||
switch (unifykey->dev) {
|
||||
#ifdef CONFIG_EFUSE
|
||||
#if defined(CONFIG_ARM64) && defined(CONFIG_AMLOGIC_EFUSE)
|
||||
case KEY_M_EFUSE:
|
||||
{
|
||||
struct efusekey_info info;
|
||||
|
||||
@@ -30,6 +30,7 @@ extern int efusekeynum;
|
||||
int efuse_getinfo(char *item, struct efusekey_info *info);
|
||||
ssize_t efuse_user_attr_show(char *name, char *buf);
|
||||
ssize_t efuse_user_attr_store(char *name, const char *buf, size_t count);
|
||||
ssize_t efuse_user_attr_read(char *name, char *buf);
|
||||
#else
|
||||
int efuse_read_intlItem(char *intl_item, char *buf, int size);
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user