xref: /rk3399_ARM-atf/plat/common/plat_bl_common.c (revision 2be57b8658b1206a8fb8a2cfbbd9b15cae4b354d)
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*2be57b86SSumit Garg #include <tools_share/firmware_encrypted.h>
15566034fcSSoby Mathew 
16566034fcSSoby Mathew /*
17566034fcSSoby Mathew  * The following platform functions are weakly defined. The Platforms
18566034fcSSoby Mathew  * may redefine with strong definition.
19566034fcSSoby Mathew  */
20566034fcSSoby Mathew #pragma weak bl2_el3_plat_prepare_exit
21566034fcSSoby Mathew #pragma weak plat_error_handler
22566034fcSSoby Mathew #pragma weak bl2_plat_preload_setup
23566034fcSSoby Mathew #pragma weak bl2_plat_handle_pre_image_load
24566034fcSSoby Mathew #pragma weak bl2_plat_handle_post_image_load
25566034fcSSoby Mathew #pragma weak plat_try_next_boot_source
26*2be57b86SSumit Garg #pragma weak plat_get_enc_key_info
27566034fcSSoby Mathew 
28566034fcSSoby Mathew void bl2_el3_plat_prepare_exit(void)
29566034fcSSoby Mathew {
30566034fcSSoby Mathew }
31566034fcSSoby Mathew 
32566034fcSSoby Mathew void __dead2 plat_error_handler(int err)
33566034fcSSoby Mathew {
34566034fcSSoby Mathew 	while (1)
35566034fcSSoby Mathew 		wfi();
36566034fcSSoby Mathew }
37566034fcSSoby Mathew 
38566034fcSSoby Mathew void bl2_plat_preload_setup(void)
39566034fcSSoby Mathew {
40566034fcSSoby Mathew }
41566034fcSSoby Mathew 
42566034fcSSoby Mathew int bl2_plat_handle_pre_image_load(unsigned int image_id)
43566034fcSSoby Mathew {
44566034fcSSoby Mathew 	return 0;
45566034fcSSoby Mathew }
46566034fcSSoby Mathew 
47566034fcSSoby Mathew int bl2_plat_handle_post_image_load(unsigned int image_id)
48566034fcSSoby Mathew {
49566034fcSSoby Mathew 	return 0;
50566034fcSSoby Mathew }
51566034fcSSoby Mathew 
52566034fcSSoby Mathew int plat_try_next_boot_source(void)
53566034fcSSoby Mathew {
54566034fcSSoby Mathew 	return 0;
55566034fcSSoby Mathew }
56a6f340feSSoby Mathew 
570916c38dSRoberto Vargas /*
58*2be57b86SSumit Garg  * Weak implementation to provide dummy decryption key only for test purposes,
59*2be57b86SSumit Garg  * platforms must override this API for any real world firmware encryption
60*2be57b86SSumit Garg  * use-case.
61*2be57b86SSumit Garg  */
62*2be57b86SSumit Garg int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
63*2be57b86SSumit Garg 			  size_t *key_len, unsigned int *flags,
64*2be57b86SSumit Garg 			  const uint8_t *img_id, size_t img_id_len)
65*2be57b86SSumit Garg {
66*2be57b86SSumit Garg #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
67*2be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
68*2be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
69*2be57b86SSumit Garg 			    0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }
70*2be57b86SSumit Garg 
71*2be57b86SSumit Garg 	const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
72*2be57b86SSumit Garg 
73*2be57b86SSumit Garg 	assert(*key_len >= sizeof(dummy_key));
74*2be57b86SSumit Garg 
75*2be57b86SSumit Garg 	*key_len = sizeof(dummy_key);
76*2be57b86SSumit Garg 	memcpy(key, dummy_key, *key_len);
77*2be57b86SSumit Garg 	*flags = 0;
78*2be57b86SSumit Garg 
79*2be57b86SSumit Garg 	return 0;
80*2be57b86SSumit Garg }
81*2be57b86SSumit Garg 
82*2be57b86SSumit Garg /*
830916c38dSRoberto Vargas  * Set up the page tables for the generic and platform-specific memory regions.
840916c38dSRoberto Vargas  * The size of the Trusted SRAM seen by the BL image must be specified as well
850916c38dSRoberto Vargas  * as an array specifying the generic memory regions which can be;
860916c38dSRoberto Vargas  * - Code section;
870916c38dSRoberto Vargas  * - Read-only data section;
880916c38dSRoberto Vargas  * - Init code section, if applicable
890916c38dSRoberto Vargas  * - Coherent memory region, if applicable.
900916c38dSRoberto Vargas  */
910916c38dSRoberto Vargas 
920916c38dSRoberto Vargas void __init setup_page_tables(const mmap_region_t *bl_regions,
930916c38dSRoberto Vargas 			      const mmap_region_t *plat_regions)
940916c38dSRoberto Vargas {
950916c38dSRoberto Vargas #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
960916c38dSRoberto Vargas 	const mmap_region_t *regions = bl_regions;
970916c38dSRoberto Vargas 
980916c38dSRoberto Vargas 	while (regions->size != 0U) {
990916c38dSRoberto Vargas 		VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
1000916c38dSRoberto Vargas 				regions->base_va,
1010916c38dSRoberto Vargas 				regions->base_va + regions->size,
1020916c38dSRoberto Vargas 				regions->attr);
1030916c38dSRoberto Vargas 		regions++;
1040916c38dSRoberto Vargas 	}
1050916c38dSRoberto Vargas #endif
1060916c38dSRoberto Vargas 	/*
1070916c38dSRoberto Vargas 	 * Map the Trusted SRAM with appropriate memory attributes.
1080916c38dSRoberto Vargas 	 * Subsequent mappings will adjust the attributes for specific regions.
1090916c38dSRoberto Vargas 	 */
1100916c38dSRoberto Vargas 	mmap_add(bl_regions);
1110916c38dSRoberto Vargas 
1120916c38dSRoberto Vargas 	/* Now (re-)map the platform-specific memory regions */
1130916c38dSRoberto Vargas 	mmap_add(plat_regions);
1140916c38dSRoberto Vargas 
1150916c38dSRoberto Vargas 	/* Create the page tables to reflect the above mappings */
1160916c38dSRoberto Vargas 	init_xlat_tables();
1170916c38dSRoberto Vargas }
118