]> git.ipfire.org Git - thirdparty/u-boot.git/blame - lib/optee/optee.c
optee: Add lib entries for sharing OPTEE code across ports
[thirdparty/u-boot.git] / lib / optee / optee.c
CommitLineData
32ce6179
BD
1/*
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}