1 /* 2 * Copyright (c) 2018-2020, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #include "ps_nv_counters.h" 9 #include "tfm_platform_api.h" 10 ps_read_nv_counter(enum tfm_nv_counter_t counter_id,uint32_t * val)11psa_status_t ps_read_nv_counter(enum tfm_nv_counter_t counter_id, 12 uint32_t *val) 13 { 14 enum tfm_platform_err_t err; 15 16 err = tfm_platform_nv_counter_read(counter_id, PS_NV_COUNTER_SIZE, 17 (uint8_t *)val); 18 if (err != TFM_PLATFORM_ERR_SUCCESS) { 19 return PSA_ERROR_GENERIC_ERROR; 20 } 21 22 return PSA_SUCCESS; 23 } 24 ps_increment_nv_counter(enum tfm_nv_counter_t counter_id)25psa_status_t ps_increment_nv_counter(enum tfm_nv_counter_t counter_id) 26 { 27 enum tfm_platform_err_t err; 28 29 /* NOTE: tfm_plat_increment_nv_counter returns TFM_PLAT_ERR_MAX_VALUE when 30 * the counter reaches its maximum value. The current PS 31 * implementation treats this condition as an error as, from that 32 * moment onwards, the rollback protection can not be achieved based 33 * on the NV counters. 34 */ 35 err = tfm_platform_nv_counter_increment(counter_id); 36 if (err != TFM_PLATFORM_ERR_SUCCESS) { 37 return PSA_ERROR_GENERIC_ERROR; 38 } 39 40 return PSA_SUCCESS; 41 } 42