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