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