forked from OP-TEE/optee_os
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: nvmem: add nvmem-huk driver
This driver is meant to read the otp unique hardware key from a nvmem controller. It uses the nvmem framework to read the nvmem cells from the device-tree. Signed-off-by: Thomas Perrot <[email protected]>
- Loading branch information
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2023, Microchip | ||
*/ | ||
|
||
#include <drivers/nvmem.h> | ||
#include <io.h> | ||
#include <kernel/dt.h> | ||
#include <kernel/huk_subkey.h> | ||
#include <kernel/tee_common_otp.h> | ||
#include <malloc.h> | ||
#include <matrix.h> | ||
#include <sama5d2.h> | ||
#include <tee_api_defines.h> | ||
#include <tee_api_types.h> | ||
#include <types_ext.h> | ||
#include <trace.h> | ||
|
||
static uint8_t *huk; | ||
|
||
TEE_Result tee_otp_get_hw_unique_key(struct tee_hw_unique_key *hwkey) | ||
{ | ||
if (!huk) | ||
return TEE_ERROR_NO_DATA; | ||
|
||
memcpy(hwkey->data, huk, HW_UNIQUE_KEY_LENGTH); | ||
|
||
return TEE_SUCCESS; | ||
} | ||
|
||
static TEE_Result nvmem_huk_read(const void *fdt, int node) | ||
{ | ||
TEE_Result res = TEE_ERROR_GENERIC; | ||
struct nvmem_cell *cell = NULL; | ||
uint8_t *data = NULL; | ||
size_t len = 0; | ||
|
||
res = nvmem_get_cell_by_name(fdt, node, "hw_unique_key", &cell); | ||
if (res) | ||
return res; | ||
|
||
res = nvmem_cell_malloc_and_read(cell, &data); | ||
if (res) | ||
goto out_free_cell; | ||
|
||
if (len != HW_UNIQUE_KEY_LENGTH) { | ||
res = TEE_ERROR_GENERIC; | ||
goto out_free_cell; | ||
} | ||
huk = data; | ||
|
||
out_free_cell: | ||
nvmem_put_cell(cell); | ||
|
||
return res; | ||
} | ||
|
||
static TEE_Result nvmem_huk_probe(const void *fdt, int node, | ||
const void *compat_data __unused) | ||
{ | ||
return nvmem_huk_read(fdt, node); | ||
} | ||
|
||
static const struct dt_device_match nvmem_huk_match_table[] = { | ||
{ .compatible = "optee,nvmem-huk" }, | ||
{ } | ||
}; | ||
|
||
DEFINE_DT_DRIVER(nvmem_huk_dt_driver) = { | ||
.name = "nvmem_huk", | ||
.type = DT_DRIVER_NVMEM, | ||
.match_table = nvmem_huk_match_table, | ||
.probe = nvmem_huk_probe, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
srcs-y += nvmem.c | ||
srcs-$(CFG_ATMEL_SFC) += atmel_sfc.c | ||
srcs-$(CFG_NVMEM_DIE_ID) += nvmem_die_id.c | ||
srcs-$(CFG_NVMEM_HUK) += nvmem_huk.c |