blob: 2cc16d7c97a2a0e6dc4053ebd0923b262804465a [file] [log] [blame]
Bryan O'Donoghue32ce6172018-03-13 16:50:27 +00001/*
2 * Copyright (C) 2017 Linaro
3 * Bryan O'Donoghue <bryan.odonoghue@linaro.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <tee/optee.h>
10
11int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start,
12 unsigned long tzdram_len, unsigned long image_len)
13{
14 unsigned long tzdram_end = tzdram_start + tzdram_len;
15 uint32_t tee_file_size;
16
17 tee_file_size = hdr->init_size + hdr->paged_size +
18 sizeof(struct optee_header);
19
20 if (hdr->magic != OPTEE_MAGIC ||
21 hdr->version != OPTEE_VERSION ||
22 hdr->init_load_addr_hi > tzdram_end ||
23 hdr->init_load_addr_lo < tzdram_start ||
24 tee_file_size > tzdram_len ||
25 tee_file_size != image_len ||
26 (hdr->init_load_addr_lo + tee_file_size) > tzdram_end) {
27 return -EINVAL;
28 }
29
30 return 0;
31}