• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 #include <bl_common.h>
9 #include <debug.h>
10 #include <errno.h>
11 #include <plat_arm.h>
12 #include <platform_def.h>
13 #include <tbbr_img_desc.h>
14 #include <utils.h>
15 
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 
22 bl1_mem_info_t fwu_addr_map_secure[] = {
23 	{
24 		.mem_base = ARM_SHARED_RAM_BASE,
25 		.mem_size = ARM_SHARED_RAM_SIZE
26 	},
27 	{
28 		.mem_size = 0
29 	}
30 };
31 
32 bl1_mem_info_t fwu_addr_map_non_secure[] = {
33 	{
34 		.mem_base = ARM_NS_DRAM1_BASE,
35 		.mem_size = ARM_NS_DRAM1_SIZE
36 	},
37 	{
38 		.mem_base = PLAT_ARM_NVM_BASE,
39 		.mem_size = PLAT_ARM_NVM_SIZE
40 	},
41 	{
42 		.mem_size = 0
43 	}
44 };
45 
bl1_plat_mem_check(uintptr_t mem_base,unsigned int mem_size,unsigned int flags)46 int bl1_plat_mem_check(uintptr_t mem_base,
47 		unsigned int mem_size,
48 		unsigned int flags)
49 {
50 	unsigned int index = 0;
51 	bl1_mem_info_t *mmap;
52 
53 	assert(mem_base);
54 	assert(mem_size);
55 	/*
56 	 * The caller of this function is responsible for checking upfront that
57 	 * the end address doesn't overflow. We double-check this in debug
58 	 * builds.
59 	 */
60 	assert(!check_uptr_overflow(mem_base, mem_size - 1));
61 
62 	/*
63 	 * Check the given image source and size.
64 	 */
65 	if (GET_SECURITY_STATE(flags) == SECURE)
66 		mmap = fwu_addr_map_secure;
67 	else
68 		mmap = fwu_addr_map_non_secure;
69 
70 	while (mmap[index].mem_size) {
71 		if ((mem_base >= mmap[index].mem_base) &&
72 			((mem_base + mem_size)
73 			<= (mmap[index].mem_base +
74 			mmap[index].mem_size)))
75 			return 0;
76 
77 		index++;
78 	}
79 
80 	return -ENOMEM;
81 }
82 
83 /*******************************************************************************
84  * This function does linear search for image_id and returns image_desc.
85  ******************************************************************************/
bl1_plat_get_image_desc(unsigned int image_id)86 image_desc_t *bl1_plat_get_image_desc(unsigned int image_id)
87 {
88 	unsigned int index = 0;
89 
90 	while (bl1_tbbr_image_descs[index].image_id != INVALID_IMAGE_ID) {
91 		if (bl1_tbbr_image_descs[index].image_id == image_id)
92 			return &bl1_tbbr_image_descs[index];
93 		index++;
94 	}
95 
96 	return NULL;
97 }
98