selfload: check target memory type in selfload_check

Currently, selflock_check() verifies that the binary is loaded in an
usable RAM area.

Extend its functionality so we can also check that BL31 is loaded in
a manually reserved area, and fail early if the range is not protected.

Change-Id: Iecdeedd9e8da67f73ac47d2a82e85b306469a626
Signed-off-by: Ting Shen <phoenixshen@google.com>
Reviewed-on: https://review.coreboot.org/c/31122
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Ting Shen
2019-01-28 17:22:22 +08:00
committed by Patrick Georgi
parent ab92f26a13
commit 05532260ae
6 changed files with 27 additions and 27 deletions

View File

@@ -201,33 +201,25 @@ bool bootmem_walk(range_action_t action, void *arg)
return false;
}
static int bootmem_region_targets_ram(uint64_t start, uint64_t end,
struct memranges *bm)
int bootmem_region_targets_type(uint64_t start, uint64_t size,
enum bootmem_type dest_type)
{
const struct range_entry *r;
uint64_t end = start + size;
memranges_each_entry(r, bm) {
memranges_each_entry(r, &bootmem) {
/* All further bootmem entries are beyond this range. */
if (end <= range_entry_base(r))
break;
if (start >= range_entry_base(r) && end <= range_entry_end(r)) {
if (range_entry_tag(r) == BM_MEM_RAM)
if (range_entry_tag(r) == dest_type)
return 1;
}
}
return 0;
}
/* Common testcase for loading any segments to bootmem.
* Returns 1 if the requested memory range is all tagged as type BM_MEM_RAM.
* Otherwise returns 0.
*/
int bootmem_region_targets_usable_ram(uint64_t start, uint64_t size)
{
return bootmem_region_targets_ram(start, start + size, &bootmem);
}
void *bootmem_allocate_buffer(size_t size)
{
const struct range_entry *r;