xref: /rk3399_ARM-atf/plat/common/plat_bl_common.c (revision 0e753437e75b68476b524d32c7e9db7f28d2ad85)
1566034fcSSoby Mathew /*
2e6937287SZelalem  * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
3566034fcSSoby Mathew  *
4566034fcSSoby Mathew  * SPDX-License-Identifier: BSD-3-Clause
5566034fcSSoby Mathew  */
6566034fcSSoby Mathew 
7566034fcSSoby Mathew #include <assert.h>
809d40e0eSAntonio Nino Diaz 
909d40e0eSAntonio Nino Diaz #include <arch_helpers.h>
1009d40e0eSAntonio Nino Diaz #include <common/bl_common.h>
1109d40e0eSAntonio Nino Diaz #include <common/debug.h>
1209d40e0eSAntonio Nino Diaz #include <lib/xlat_tables/xlat_tables_compat.h>
1309d40e0eSAntonio Nino Diaz #include <plat/common/platform.h>
14*0e753437SManish V Badarkhe #include <smccc_helpers.h>
152be57b86SSumit Garg #include <tools_share/firmware_encrypted.h>
16566034fcSSoby Mathew 
17566034fcSSoby Mathew /*
18566034fcSSoby Mathew  * The following platform functions are weakly defined. The Platforms
19566034fcSSoby Mathew  * may redefine with strong definition.
20566034fcSSoby Mathew  */
21566034fcSSoby Mathew #pragma weak bl2_el3_plat_prepare_exit
22566034fcSSoby Mathew #pragma weak plat_error_handler
23566034fcSSoby Mathew #pragma weak bl2_plat_preload_setup
24566034fcSSoby Mathew #pragma weak bl2_plat_handle_pre_image_load
25566034fcSSoby Mathew #pragma weak bl2_plat_handle_post_image_load
26566034fcSSoby Mathew #pragma weak plat_try_next_boot_source
272be57b86SSumit Garg #pragma weak plat_get_enc_key_info
28*0e753437SManish V Badarkhe #pragma weak plat_get_soc_version
29*0e753437SManish V Badarkhe #pragma weak plat_get_soc_revision
30*0e753437SManish V Badarkhe 
31*0e753437SManish V Badarkhe int32_t plat_get_soc_version(void)
32*0e753437SManish V Badarkhe {
33*0e753437SManish V Badarkhe 	return SMC_ARCH_CALL_NOT_SUPPORTED;
34*0e753437SManish V Badarkhe }
35*0e753437SManish V Badarkhe 
36*0e753437SManish V Badarkhe int32_t plat_get_soc_revision(void)
37*0e753437SManish V Badarkhe {
38*0e753437SManish V Badarkhe 	return SMC_ARCH_CALL_NOT_SUPPORTED;
39*0e753437SManish V Badarkhe }
40566034fcSSoby Mathew 
41566034fcSSoby Mathew void bl2_el3_plat_prepare_exit(void)
42566034fcSSoby Mathew {
43566034fcSSoby Mathew }
44566034fcSSoby Mathew 
45566034fcSSoby Mathew void __dead2 plat_error_handler(int err)
46566034fcSSoby Mathew {
47566034fcSSoby Mathew 	while (1)
48566034fcSSoby Mathew 		wfi();
49566034fcSSoby Mathew }
50566034fcSSoby Mathew 
51566034fcSSoby Mathew void bl2_plat_preload_setup(void)
52566034fcSSoby Mathew {
53566034fcSSoby Mathew }
54566034fcSSoby Mathew 
55566034fcSSoby Mathew int bl2_plat_handle_pre_image_load(unsigned int image_id)
56566034fcSSoby Mathew {
57566034fcSSoby Mathew 	return 0;
58566034fcSSoby Mathew }
59566034fcSSoby Mathew 
60566034fcSSoby Mathew int bl2_plat_handle_post_image_load(unsigned int image_id)
61566034fcSSoby Mathew {
62566034fcSSoby Mathew 	return 0;
63566034fcSSoby Mathew }
64566034fcSSoby Mathew 
65566034fcSSoby Mathew int plat_try_next_boot_source(void)
66566034fcSSoby Mathew {
67566034fcSSoby Mathew 	return 0;
68566034fcSSoby Mathew }
69a6f340feSSoby Mathew 
700916c38dSRoberto Vargas /*
712be57b86SSumit Garg  * Weak implementation to provide dummy decryption key only for test purposes,
722be57b86SSumit Garg  * platforms must override this API for any real world firmware encryption
732be57b86SSumit Garg  * use-case.
742be57b86SSumit Garg  */
752be57b86SSumit Garg int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
762be57b86SSumit Garg 			  size_t *key_len, unsigned int *flags,
772be57b86SSumit Garg 			  const uint8_t *img_id, size_t img_id_len)
782be57b86SSumit Garg {
792be57b86SSumit Garg #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
802be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
812be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
822be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }
832be57b86SSumit Garg 
842be57b86SSumit Garg 	const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
852be57b86SSumit Garg 
862be57b86SSumit Garg 	assert(*key_len >= sizeof(dummy_key));
872be57b86SSumit Garg 
882be57b86SSumit Garg 	*key_len = sizeof(dummy_key);
892be57b86SSumit Garg 	memcpy(key, dummy_key, *key_len);
902be57b86SSumit Garg 	*flags = 0;
912be57b86SSumit Garg 
922be57b86SSumit Garg 	return 0;
932be57b86SSumit Garg }
942be57b86SSumit Garg 
952be57b86SSumit Garg /*
960916c38dSRoberto Vargas  * Set up the page tables for the generic and platform-specific memory regions.
970916c38dSRoberto Vargas  * The size of the Trusted SRAM seen by the BL image must be specified as well
980916c38dSRoberto Vargas  * as an array specifying the generic memory regions which can be;
990916c38dSRoberto Vargas  * - Code section;
1000916c38dSRoberto Vargas  * - Read-only data section;
1010916c38dSRoberto Vargas  * - Init code section, if applicable
1020916c38dSRoberto Vargas  * - Coherent memory region, if applicable.
1030916c38dSRoberto Vargas  */
1040916c38dSRoberto Vargas 
1050916c38dSRoberto Vargas void __init setup_page_tables(const mmap_region_t *bl_regions,
1060916c38dSRoberto Vargas 			      const mmap_region_t *plat_regions)
1070916c38dSRoberto Vargas {
1080916c38dSRoberto Vargas #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
1090916c38dSRoberto Vargas 	const mmap_region_t *regions = bl_regions;
1100916c38dSRoberto Vargas 
1110916c38dSRoberto Vargas 	while (regions->size != 0U) {
1120916c38dSRoberto Vargas 		VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
1130916c38dSRoberto Vargas 				regions->base_va,
1140916c38dSRoberto Vargas 				regions->base_va + regions->size,
1150916c38dSRoberto Vargas 				regions->attr);
1160916c38dSRoberto Vargas 		regions++;
1170916c38dSRoberto Vargas 	}
1180916c38dSRoberto Vargas #endif
1190916c38dSRoberto Vargas 	/*
1200916c38dSRoberto Vargas 	 * Map the Trusted SRAM with appropriate memory attributes.
1210916c38dSRoberto Vargas 	 * Subsequent mappings will adjust the attributes for specific regions.
1220916c38dSRoberto Vargas 	 */
1230916c38dSRoberto Vargas 	mmap_add(bl_regions);
1240916c38dSRoberto Vargas 
1250916c38dSRoberto Vargas 	/* Now (re-)map the platform-specific memory regions */
1260916c38dSRoberto Vargas 	mmap_add(plat_regions);
1270916c38dSRoberto Vargas 
1280916c38dSRoberto Vargas 	/* Create the page tables to reflect the above mappings */
1290916c38dSRoberto Vargas 	init_xlat_tables();
1300916c38dSRoberto Vargas }
131