xref: /rk3399_ARM-atf/plat/arm/board/tc/rotpk_test.c (revision cb6b7505051ef59a81d50ab2f4c6e56ba2b41275)
100b7e0bfSlaurenw-arm /*
200b7e0bfSlaurenw-arm  * Copyright (c) 2023, Arm Limited. All rights reserved.
300b7e0bfSlaurenw-arm  *
400b7e0bfSlaurenw-arm  * SPDX-License-Identifier: BSD-3-Clause
500b7e0bfSlaurenw-arm  */
600b7e0bfSlaurenw-arm 
700b7e0bfSlaurenw-arm #include <stdint.h>
800b7e0bfSlaurenw-arm #include <stdio.h>
900b7e0bfSlaurenw-arm 
1000b7e0bfSlaurenw-arm #include <drivers/arm/rss_comms.h>
1100b7e0bfSlaurenw-arm #include <plat/common/platform.h>
1200b7e0bfSlaurenw-arm #include <rss_platform_api.h>
1300b7e0bfSlaurenw-arm #include <tc_plat.h>
1400b7e0bfSlaurenw-arm 
1500b7e0bfSlaurenw-arm static void print_hex(const char *key_id_name, size_t key_size, const uint8_t *key_buf)
1600b7e0bfSlaurenw-arm {
1700b7e0bfSlaurenw-arm 	printf("%s = ", key_id_name);
1800b7e0bfSlaurenw-arm 	for (int i = 0; i < key_size; i++) {
1900b7e0bfSlaurenw-arm 		printf("%02x", key_buf[i]);
2000b7e0bfSlaurenw-arm 	}
2100b7e0bfSlaurenw-arm 	printf("\n\n");
2200b7e0bfSlaurenw-arm }
2300b7e0bfSlaurenw-arm 
2400b7e0bfSlaurenw-arm int rotpk_test(void)
2500b7e0bfSlaurenw-arm {
2600b7e0bfSlaurenw-arm 	psa_status_t status;
2700b7e0bfSlaurenw-arm 	uint8_t key_buf[128];
2800b7e0bfSlaurenw-arm 	size_t key_size;
2900b7e0bfSlaurenw-arm 
3000b7e0bfSlaurenw-arm 	struct key_id_info key_ids[3] = {
3100b7e0bfSlaurenw-arm 	       {.key_id = RSS_BUILTIN_KEY_ID_HOST_S_ROTPK,  .key_id_name = "Secure-ROTPK"},
3200b7e0bfSlaurenw-arm 	       {.key_id = RSS_BUILTIN_KEY_ID_HOST_NS_ROTPK,  .key_id_name = "NS-ROTPK"},
3300b7e0bfSlaurenw-arm 	       {.key_id = RSS_BUILTIN_KEY_ID_HOST_CCA_ROTPK,  .key_id_name = "CCA-ROTPK"}
3400b7e0bfSlaurenw-arm 	};
3500b7e0bfSlaurenw-arm 
3600b7e0bfSlaurenw-arm 	status = rss_comms_init(PLAT_RSS_AP_SND_MHU_BASE, PLAT_RSS_AP_RCV_MHU_BASE);
3700b7e0bfSlaurenw-arm 	if (status != PSA_SUCCESS) {
38*cb6b7505Slaurenw-arm 		printf("Failed to initialize RSS communication channel - psa_status = %d\n", status);
3900b7e0bfSlaurenw-arm 		return -1;
4000b7e0bfSlaurenw-arm 	}
4100b7e0bfSlaurenw-arm 
4200b7e0bfSlaurenw-arm 	for (int i = 0; i < ARRAY_SIZE(key_ids); i++) {
4300b7e0bfSlaurenw-arm 		status = rss_platform_key_read(key_ids[i].key_id, key_buf,
4400b7e0bfSlaurenw-arm 			       sizeof(key_buf), &key_size);
4500b7e0bfSlaurenw-arm 		if (status != PSA_SUCCESS) {
46*cb6b7505Slaurenw-arm 			printf("Failed to retrieve %s - psa_status = %d\n", key_ids[i].key_id_name, status);
4700b7e0bfSlaurenw-arm 			return -1;
4800b7e0bfSlaurenw-arm 		}
4900b7e0bfSlaurenw-arm 		print_hex(key_ids[i].key_id_name, key_size, key_buf);
5000b7e0bfSlaurenw-arm 	}
5100b7e0bfSlaurenw-arm 
5200b7e0bfSlaurenw-arm 	printf("Passed rotpk_test\n");
5300b7e0bfSlaurenw-arm 
5400b7e0bfSlaurenw-arm 	return 0;
5500b7e0bfSlaurenw-arm }
56