arm_bl1_fwu.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2015-2021, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <assert.h>
  7. #include <errno.h>
  8. #include <platform_def.h>
  9. #include <bl1/tbbr/tbbr_img_desc.h>
  10. #include <common/bl_common.h>
  11. #include <common/debug.h>
  12. #include <lib/utils.h>
  13. #include <plat/arm/common/plat_arm.h>
  14. #include <plat/common/platform.h>
  15. #pragma weak bl1_plat_get_image_desc
  16. /* Struct to keep track of usable memory */
  17. typedef struct bl1_mem_info {
  18. uintptr_t mem_base;
  19. unsigned int mem_size;
  20. } bl1_mem_info_t;
  21. static bl1_mem_info_t fwu_addr_map_secure[] = {
  22. {
  23. .mem_base = ARM_SHARED_RAM_BASE,
  24. .mem_size = ARM_SHARED_RAM_SIZE
  25. },
  26. {
  27. .mem_size = 0
  28. }
  29. };
  30. static bl1_mem_info_t fwu_addr_map_non_secure[] = {
  31. {
  32. .mem_base = ARM_NS_DRAM1_BASE,
  33. .mem_size = ARM_NS_DRAM1_SIZE
  34. },
  35. {
  36. .mem_base = PLAT_ARM_NVM_BASE,
  37. .mem_size = PLAT_ARM_NVM_SIZE
  38. },
  39. {
  40. .mem_size = 0
  41. }
  42. };
  43. int bl1_plat_mem_check(uintptr_t mem_base,
  44. unsigned int mem_size,
  45. unsigned int flags)
  46. {
  47. unsigned int index = 0;
  48. bl1_mem_info_t *mmap;
  49. assert(mem_base);
  50. assert(mem_size);
  51. /*
  52. * The caller of this function is responsible for checking upfront that
  53. * the end address doesn't overflow. We double-check this in debug
  54. * builds.
  55. */
  56. assert(!check_uptr_overflow(mem_base, mem_size - 1));
  57. /*
  58. * Check the given image source and size.
  59. */
  60. if (GET_SECURITY_STATE(flags) == SECURE)
  61. mmap = fwu_addr_map_secure;
  62. else
  63. mmap = fwu_addr_map_non_secure;
  64. while (mmap[index].mem_size) {
  65. if ((mem_base >= mmap[index].mem_base) &&
  66. ((mem_base + mem_size)
  67. <= (mmap[index].mem_base +
  68. mmap[index].mem_size)))
  69. return 0;
  70. index++;
  71. }
  72. return -ENOMEM;
  73. }
  74. /*******************************************************************************
  75. * This function does linear search for image_id and returns image_desc.
  76. ******************************************************************************/
  77. image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
  78. {
  79. unsigned int index = 0;
  80. while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
  81. if (bl1_tbbr_image_descs[index].image_id == image_id)
  82. return &bl1_tbbr_image_descs[index];
  83. index++;
  84. }
  85. return NULL;
  86. }