Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 1 | /* |
Roberto Vargas | 2ca18d9 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | #include <string.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 10 | |
| 11 | #include <plat/common/platform.h> |
| 12 | #include <tools_share/tbbr_oid.h> |
Masahiro Yamada | d1f9775 | 2017-05-23 19:41:36 +0900 | [diff] [blame] | 13 | |
Antonio Nino Diaz | 9d602fe | 2016-05-20 14:14:16 +0100 | [diff] [blame] | 14 | #include "fvp_def.h" |
| 15 | |
| 16 | /* |
| 17 | * Store a new non-volatile counter value. On some FVP versions, the |
| 18 | * non-volatile counters are RO. On these versions we expect the values in the |
| 19 | * certificates to always match the RO values so that this function is never |
| 20 | * called. |
| 21 | * |
| 22 | * Return: 0 = success, Otherwise = error |
| 23 | */ |
| 24 | int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr) |
| 25 | { |
| 26 | const char *oid; |
| 27 | uint32_t *nv_ctr_addr; |
| 28 | |
| 29 | assert(cookie != NULL); |
| 30 | |
| 31 | oid = (const char *)cookie; |
| 32 | if (strcmp(oid, TRUSTED_FW_NVCOUNTER_OID) == 0) { |
| 33 | nv_ctr_addr = (uint32_t *)TFW_NVCTR_BASE; |
| 34 | } else if (strcmp(oid, NON_TRUSTED_FW_NVCOUNTER_OID) == 0) { |
| 35 | nv_ctr_addr = (uint32_t *)NTFW_CTR_BASE; |
| 36 | } else { |
| 37 | return 1; |
| 38 | } |
| 39 | |
| 40 | *(unsigned int *)nv_ctr_addr = nv_ctr; |
| 41 | |
| 42 | /* Verify that the current value is the one we just wrote. */ |
| 43 | if (nv_ctr != (unsigned int)(*nv_ctr_addr)) |
| 44 | return 1; |
| 45 | |
| 46 | return 0; |
| 47 | } |