blob: 2d8f61f9dbc4a13e20ed1923e996fcf8ed663375 [file] [log] [blame]
Lokesh Vutla82f29fd2018-08-27 15:57:15 +05301# SPDX-License-Identifier: GPL-2.0+
2#
3# Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
4# Lokesh Vutla <lokeshvutla@ti.com>
5
6ifdef CONFIG_SPL_BUILD
7
Lokesh Vutla890b2e72018-11-02 19:51:04 +05308# Openssl is required to generate x509 certificate.
9# Error out if openssl is not available.
10ifeq ($(shell which openssl),)
11$(error "No openssl in $(PATH), consider installing openssl")
12endif
13
14SHA_VALUE= $(shell openssl dgst -sha512 -hex $(obj)/u-boot-spl.bin | sed -e "s/^.*= //g")
15IMAGE_SIZE= $(shell cat $(obj)/u-boot-spl.bin | wc -c)
16LOADADDR= $(shell echo $(CONFIG_SPL_TEXT_BASE) | sed -e "s/^0x//g")
17MAX_SIZE= $(shell printf "%d" $(CONFIG_SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE))
18
19# Parameters to get populated into the x509 template
20SED_OPTS= -e s/TEST_IMAGE_LENGTH/$(IMAGE_SIZE)/
21SED_OPTS+= -e s/TEST_IMAGE_SHA_VAL/$(SHA_VALUE)/
22SED_OPTS+= -e s/TEST_CERT_TYPE/1/ # CERT_TYPE_PRIMARY_IMAGE_BIN
23SED_OPTS+= -e s/TEST_BOOT_CORE/$(CONFIG_SYS_K3_BOOT_CORE_ID)/
24SED_OPTS+= -e s/TEST_BOOT_ARCH_WIDTH/32/
25SED_OPTS+= -e s/TEST_BOOT_ADDR/$(LOADADDR)/
26
27# Command to generate ecparam key
28quiet_cmd_genkey = OPENSSL $@
29cmd_genkey = openssl ecparam -out $@ -name prime256v1 -genkey
30
31# Command to generate x509 certificate
32quiet_cmd_gencert = OPENSSL $@
33cmd_gencert = cat $(srctree)/tools/k3_x509template.txt | sed $(SED_OPTS) > u-boot-spl-x509.txt; \
34 openssl req -new -x509 -key $(KEY) -nodes -outform DER -out $@ -config u-boot-spl-x509.txt -sha512
35
36# If external key is not provided, generate key using openssl.
37ifeq ($(CONFIG_SYS_K3_KEY), "")
38KEY=u-boot-spl-eckey.pem
Andrew F. Davis50836962019-04-12 12:54:46 -040039# On HS use real key or warn if not available
40ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
41ifneq ($(wildcard $(TI_SECURE_DEV_PKG)/keys/custMpk.pem),)
42KEY=$(TI_SECURE_DEV_PKG)/keys/custMpk.pem
43else
44$(warning "WARNING: signing key not found. Random key will NOT work on HS hardware!")
45endif
46endif
Lokesh Vutla890b2e72018-11-02 19:51:04 +053047else
Lokesh Vutlaadc702e2018-12-19 12:53:31 +053048KEY=$(patsubst "%",$(srctree)/%,$(CONFIG_SYS_K3_KEY))
Lokesh Vutla890b2e72018-11-02 19:51:04 +053049endif
50
51u-boot-spl-eckey.pem: FORCE
52 $(call if_changed,genkey)
53
54# tiboot3.bin is mandated by ROM and ROM only supports R5 boot.
55# So restrict tiboot3.bin creation for CPU_V7R.
56ifdef CONFIG_CPU_V7R
57u-boot-spl-cert.bin: $(KEY) $(obj)/u-boot-spl.bin image_check FORCE
58 $(call if_changed,gencert)
59
60image_check: $(obj)/u-boot-spl.bin FORCE
61 @if [ $(IMAGE_SIZE) -gt $(MAX_SIZE) ]; then \
62 echo "===============================================" >&2; \
63 echo "ERROR: Final Image too big. " >&2; \
64 echo "$< size = $(IMAGE_SIZE), max size = $(MAX_SIZE)" >&2; \
65 echo "===============================================" >&2; \
66 exit 1; \
67 fi
68
69tiboot3.bin: u-boot-spl-cert.bin $(obj)/u-boot-spl.bin FORCE
70 $(call if_changed,cat)
71
72ALL-y += tiboot3.bin
73endif
74
Lokesh Vutla82f29fd2018-08-27 15:57:15 +053075ifdef CONFIG_ARM64
Andrew F. Davis50836962019-04-12 12:54:46 -040076ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
77SPL_ITS := u-boot-spl-k3_HS.its
78$(SPL_ITS): FORCE
79 IS_HS=1 \
80 $(srctree)/tools/k3_fit_atf.sh \
81 $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST))) > $@
82
83ALL-y += tispl.bin_HS
84else
Lokesh Vutla82f29fd2018-08-27 15:57:15 +053085SPL_ITS := u-boot-spl-k3.its
86$(SPL_ITS): FORCE
87 $(srctree)/tools/k3_fit_atf.sh \
88 $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST))) > $@
89
90ALL-y += tispl.bin
91endif
Andrew F. Davis50836962019-04-12 12:54:46 -040092endif
Lokesh Vutla82f29fd2018-08-27 15:57:15 +053093
94else
Andrew F. Davis50836962019-04-12 12:54:46 -040095
96ifeq ($(CONFIG_TI_SECURE_DEVICE),y)
97ALL-y += u-boot.img_HS
98else
Lokesh Vutla82f29fd2018-08-27 15:57:15 +053099ALL-y += u-boot.img
100endif
Andrew F. Davis50836962019-04-12 12:54:46 -0400101endif
102
103include $(srctree)/arch/arm/mach-k3/config_secure.mk