1# Licensed to the Apache Software Foundation (ASF) under one
2# or more contributor license agreements.  See the NOTICE file
3# distributed with this work for additional information
4# regarding copyright ownership.  The ASF licenses this file
5# to you under the Apache License, Version 2.0 (the
6# "License"); you may not use this file except in compliance
7# with the License.  You may obtain a copy of the License at
8#
9#   http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing,
12# software distributed under the License is distributed on an
13# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14# KIND, either express or implied.  See the License for the
15# specific language governing permissions and limitations
16# under the License.
17
18OPTEE_DIR ?= ../../../optee
19OPTEE_OS_DIR ?= $(OPTEE_DIR)/optee_os
20UUID ?= $(shell cat "../uuid.txt")
21
22ARCH ?= aarch64
23
24ifeq ($(ARCH), arm)
25	TA_SIGN_KEY ?= $(OPTEE_OS_DIR)/out/arm/export-ta_arm32/keys/default_ta.pem
26	SIGN := $(OPTEE_OS_DIR)/out/arm/export-ta_arm32/scripts/sign_encrypt.py
27	OPTEE_BIN := $(OPTEE_DIR)/toolchains/aarch32/bin
28	OBJCOPY := $(OPTEE_BIN)/arm-linux-gnueabihf-objcopy
29	TARGET := arm-unknown-optee-trustzone
30else
31	TA_SIGN_KEY ?= $(OPTEE_OS_DIR)/out/arm/export-ta_arm64/keys/default_ta.pem
32	SIGN := $(OPTEE_OS_DIR)/out/arm/export-ta_arm64/scripts/sign_encrypt.py
33	OPTEE_BIN := $(OPTEE_DIR)/toolchains/$(ARCH)/bin
34	OBJCOPY := $(OPTEE_BIN)/aarch64-linux-gnu-objcopy
35	TARGET := aarch64-unknown-optee-trustzone
36endif
37
38OUT_DIR := $(CURDIR)/target/$(TARGET)/release
39
40all: ta strip sign
41
42ta:
43	@xargo build --target $(TARGET) --release --verbose
44
45strip:
46	@$(OBJCOPY) --strip-unneeded $(OUT_DIR)/ta $(OUT_DIR)/stripped_ta
47
48sign:
49	@$(SIGN) --uuid $(UUID) --key $(TA_SIGN_KEY) --in $(OUT_DIR)/stripped_ta --out $(OUT_DIR)/$(UUID).ta
50	@echo "SIGN =>  ${UUID}"
51
52clean:
53	@xargo clean
54