blob: 51d30830c47538999b8ba71df1773695f191f1be [file] [log] [blame]
Antonio Nino Diaz9d602fe2016-05-20 14:14:16 +01001/*
2 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3 *
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>
8#include <platform_oid.h>
9#include <stdint.h>
10#include <string.h>
11#include "fvp_def.h"
12
13/*
14 * Store a new non-volatile counter value. On some FVP versions, the
15 * non-volatile counters are RO. On these versions we expect the values in the
16 * certificates to always match the RO values so that this function is never
17 * called.
18 *
19 * Return: 0 = success, Otherwise = error
20 */
21int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr)
22{
23 const char *oid;
24 uint32_t *nv_ctr_addr;
25
26 assert(cookie != NULL);
27
28 oid = (const char *)cookie;
29 if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) {
30 nv_ctr_addr = (uint32_t *)TFW_NVCTR_BASE;
31 } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) {
32 nv_ctr_addr = (uint32_t *)NTFW_CTR_BASE;
33 } else {
34 return 1;
35 }
36
37 *(unsigned int *)nv_ctr_addr = nv_ctr;
38
39 /* Verify that the current value is the one we just wrote. */
40 if (nv_ctr != (unsigned int)(*nv_ctr_addr))
41 return 1;
42
43 return 0;
44}