xref: /aosp_15_r20/external/arm-trusted-firmware/plat/common/tbbr/plat_tbbr.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2016-2017, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include <assert.h>
8*54fd6939SJiyong Park #include <string.h>
9*54fd6939SJiyong Park 
10*54fd6939SJiyong Park #include <drivers/auth/auth_mod.h>
11*54fd6939SJiyong Park #include <plat/common/platform.h>
12*54fd6939SJiyong Park #if USE_TBBR_DEFS
13*54fd6939SJiyong Park #include <tools_share/tbbr_oid.h>
14*54fd6939SJiyong Park #else
15*54fd6939SJiyong Park #include <platform_oid.h>
16*54fd6939SJiyong Park #endif
17*54fd6939SJiyong Park 
18*54fd6939SJiyong Park /*
19*54fd6939SJiyong Park  * Store a new non-volatile counter value. This implementation
20*54fd6939SJiyong Park  * only allows updating of the platform's Trusted NV counter when a
21*54fd6939SJiyong Park  * certificate protected by the Trusted NV counter is signed with
22*54fd6939SJiyong Park  * the ROT key. This avoids a compromised secondary certificate from
23*54fd6939SJiyong Park  * updating the platform's Trusted NV counter, which could lead to the
24*54fd6939SJiyong Park  * platform becoming unusable. The function is suitable for all TBBR
25*54fd6939SJiyong Park  * compliant platforms.
26*54fd6939SJiyong Park  *
27*54fd6939SJiyong Park  * Return: 0 = success, Otherwise = error
28*54fd6939SJiyong Park  */
plat_set_nv_ctr2(void * cookie,const auth_img_desc_t * img_desc,unsigned int nv_ctr)29*54fd6939SJiyong Park int plat_set_nv_ctr2(void *cookie, const auth_img_desc_t *img_desc,
30*54fd6939SJiyong Park 		unsigned int nv_ctr)
31*54fd6939SJiyong Park {
32*54fd6939SJiyong Park 	int trusted_nv_ctr;
33*54fd6939SJiyong Park 
34*54fd6939SJiyong Park 	assert(cookie != NULL);
35*54fd6939SJiyong Park 	assert(img_desc != NULL);
36*54fd6939SJiyong Park 
37*54fd6939SJiyong Park 	trusted_nv_ctr = strcmp(cookie, TRUSTED_FW_NVCOUNTER_OID) == 0;
38*54fd6939SJiyong Park 
39*54fd6939SJiyong Park 	/*
40*54fd6939SJiyong Park 	 * Only update the Trusted NV Counter if the certificate
41*54fd6939SJiyong Park 	 * has been signed with the ROT key. Non Trusted NV counter
42*54fd6939SJiyong Park 	 * updates are unconditional.
43*54fd6939SJiyong Park 	 */
44*54fd6939SJiyong Park 	if (!trusted_nv_ctr || img_desc->parent == NULL)
45*54fd6939SJiyong Park 		return plat_set_nv_ctr(cookie, nv_ctr);
46*54fd6939SJiyong Park 
47*54fd6939SJiyong Park 	/*
48*54fd6939SJiyong Park 	 * Trusted certificates not signed with the ROT key are not
49*54fd6939SJiyong Park 	 * allowed to update the Trusted NV Counter.
50*54fd6939SJiyong Park 	 */
51*54fd6939SJiyong Park 	return 1;
52*54fd6939SJiyong Park }
53