2 * Copyright (C) 2017 Linaro
3 * Bryan O'Donoghue <bryan.odonoghue@linaro.org>
5 * SPDX-License-Identifier: GPL-2.0+
11 int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start,
12 unsigned long tzdram_len, unsigned long image_len)
14 unsigned long tzdram_end = tzdram_start + tzdram_len;
15 uint32_t tee_file_size;
17 tee_file_size = hdr->init_size + hdr->paged_size +
18 sizeof(struct optee_header);
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) {