plat_bl_common.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <arch_helpers.h>
  8. #include <common/bl_common.h>
  9. #include <common/debug.h>
  10. #include <lib/xlat_tables/xlat_tables_compat.h>
  11. #include <plat/common/platform.h>
  12. #include <services/arm_arch_svc.h>
  13. #include <smccc_helpers.h>
  14. #include <tools_share/firmware_encrypted.h>
  15. /*
  16. * The following platform functions are weakly defined. The Platforms
  17. * may redefine with strong definition.
  18. */
  19. #pragma weak bl2_el3_plat_prepare_exit
  20. #pragma weak plat_error_handler
  21. #pragma weak bl2_plat_preload_setup
  22. #pragma weak bl2_plat_handle_pre_image_load
  23. #pragma weak bl2_plat_handle_post_image_load
  24. #pragma weak plat_get_enc_key_info
  25. #pragma weak plat_is_smccc_feature_available
  26. #pragma weak plat_get_soc_version
  27. #pragma weak plat_get_soc_revision
  28. int32_t plat_get_soc_version(void)
  29. {
  30. return SMC_ARCH_CALL_NOT_SUPPORTED;
  31. }
  32. int32_t plat_get_soc_revision(void)
  33. {
  34. return SMC_ARCH_CALL_NOT_SUPPORTED;
  35. }
  36. int32_t plat_is_smccc_feature_available(u_register_t fid __unused)
  37. {
  38. return SMC_ARCH_CALL_NOT_SUPPORTED;
  39. }
  40. void bl2_el3_plat_prepare_exit(void)
  41. {
  42. }
  43. void __dead2 plat_error_handler(int err)
  44. {
  45. while (1)
  46. wfi();
  47. }
  48. void bl2_plat_preload_setup(void)
  49. {
  50. }
  51. int bl2_plat_handle_pre_image_load(unsigned int image_id)
  52. {
  53. return 0;
  54. }
  55. int bl2_plat_handle_post_image_load(unsigned int image_id)
  56. {
  57. return 0;
  58. }
  59. /*
  60. * Weak implementation to provide dummy decryption key only for test purposes,
  61. * platforms must override this API for any real world firmware encryption
  62. * use-case.
  63. */
  64. int plat_get_enc_key_info(enum fw_enc_status_t fw_enc_status, uint8_t *key,
  65. size_t *key_len, unsigned int *flags,
  66. const uint8_t *img_id, size_t img_id_len)
  67. {
  68. #define DUMMY_FIP_ENC_KEY { 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
  69. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
  70. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, \
  71. 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef }
  72. const uint8_t dummy_key[] = DUMMY_FIP_ENC_KEY;
  73. assert(*key_len >= sizeof(dummy_key));
  74. *key_len = sizeof(dummy_key);
  75. memcpy(key, dummy_key, *key_len);
  76. *flags = 0;
  77. return 0;
  78. }
  79. /*
  80. * Set up the page tables for the generic and platform-specific memory regions.
  81. * The size of the Trusted SRAM seen by the BL image must be specified as well
  82. * as an array specifying the generic memory regions which can be;
  83. * - Code section;
  84. * - Read-only data section;
  85. * - Init code section, if applicable
  86. * - Coherent memory region, if applicable.
  87. */
  88. void __init setup_page_tables(const mmap_region_t *bl_regions,
  89. const mmap_region_t *plat_regions)
  90. {
  91. #if LOG_LEVEL >= LOG_LEVEL_VERBOSE
  92. const mmap_region_t *regions = bl_regions;
  93. while (regions->size != 0U) {
  94. VERBOSE("Region: 0x%lx - 0x%lx has attributes 0x%x\n",
  95. regions->base_va,
  96. regions->base_va + regions->size,
  97. regions->attr);
  98. regions++;
  99. }
  100. #endif
  101. /*
  102. * Map the Trusted SRAM with appropriate memory attributes.
  103. * Subsequent mappings will adjust the attributes for specific regions.
  104. */
  105. mmap_add(bl_regions);
  106. /* Now (re-)map the platform-specific memory regions */
  107. mmap_add(plat_regions);
  108. /* Create the page tables to reflect the above mappings */
  109. init_xlat_tables();
  110. }