blob: 0d160cb1ddad33c1aca33cfec406db98d1db2ba9 [file] [log] [blame]
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +01001/*
Roberto Vargas2ca18d92018-02-12 12:36:17 +00002 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +01005 */
6
7#include <assert.h>
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +01008#include <stdint.h>
9#include <string.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <plat/common/platform.h>
Antonio Nino Diaza320ecd2019-01-15 14:19:50 +000012#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000013#include <tools_share/tbbr_oid.h>
Masahiro Yamadad1f97752017-05-23 19:41:36 +090014
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +010015/*
16 * Store a new non-volatile counter value. On some FVP versions, the
17 * non-volatile counters are RO. On these versions we expect the values in the
18 * certificates to always match the RO values so that this function is never
19 * called.
20 *
21 * Return: 0 = success, Otherwise = error
22 */
23int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr)
24{
25 const char *oid;
26 uint32_t *nv_ctr_addr;
27
28 assert(cookie != NULL);
29
30 oid = (const char *)cookie;
31 if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) {
32 nv_ctr_addr = (uint32_t *)TFW_NVCTR_BASE;
33 } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) {
34 nv_ctr_addr = (uint32_t *)NTFW_CTR_BASE;
35 } else {
36 return 1;
37 }
38
39 *(unsigned int *)nv_ctr_addr = nv_ctr;
40
41 /* Verify that the current value is the one we just wrote. */
42 if (nv_ctr != (unsigned int)(*nv_ctr_addr))
43 return 1;
44
45 return 0;
46}