Lokesh Vutla | bc5bd3a | 2018-08-27 15:57:15 +0530 | [diff] [blame] | 1 | # 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 | |
| 6 | ifdef CONFIG_SPL_BUILD |
| 7 | |
Lokesh Vutla | 6b6a394 | 2018-11-02 19:51:04 +0530 | [diff] [blame] | 8 | # Openssl is required to generate x509 certificate. |
| 9 | # Error out if openssl is not available. |
| 10 | ifeq ($(shell which openssl),) |
| 11 | $(error "No openssl in $(PATH), consider installing openssl") |
| 12 | endif |
| 13 | |
| 14 | SHA_VALUE= $(shell openssl dgst -sha512 -hex $(obj)/u-boot-spl.bin | sed -e "s/^.*= //g") |
| 15 | IMAGE_SIZE= $(shell cat $(obj)/u-boot-spl.bin | wc -c) |
| 16 | LOADADDR= $(shell echo $(CONFIG_SPL_TEXT_BASE) | sed -e "s/^0x//g") |
| 17 | MAX_SIZE= $(shell printf "%d" $(CONFIG_SYS_K3_MAX_DOWNLODABLE_IMAGE_SIZE)) |
| 18 | |
| 19 | # Parameters to get populated into the x509 template |
| 20 | SED_OPTS= -e s/TEST_IMAGE_LENGTH/$(IMAGE_SIZE)/ |
| 21 | SED_OPTS+= -e s/TEST_IMAGE_SHA_VAL/$(SHA_VALUE)/ |
| 22 | SED_OPTS+= -e s/TEST_CERT_TYPE/1/ # CERT_TYPE_PRIMARY_IMAGE_BIN |
| 23 | SED_OPTS+= -e s/TEST_BOOT_CORE/$(CONFIG_SYS_K3_BOOT_CORE_ID)/ |
| 24 | SED_OPTS+= -e s/TEST_BOOT_ARCH_WIDTH/32/ |
| 25 | SED_OPTS+= -e s/TEST_BOOT_ADDR/$(LOADADDR)/ |
| 26 | |
| 27 | # Command to generate ecparam key |
| 28 | quiet_cmd_genkey = OPENSSL $@ |
| 29 | cmd_genkey = openssl ecparam -out $@ -name prime256v1 -genkey |
| 30 | |
| 31 | # Command to generate x509 certificate |
| 32 | quiet_cmd_gencert = OPENSSL $@ |
| 33 | cmd_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. |
| 37 | ifeq ($(CONFIG_SYS_K3_KEY), "") |
| 38 | KEY=u-boot-spl-eckey.pem |
| 39 | else |
Lokesh Vutla | c39337c | 2018-12-19 12:53:31 +0530 | [diff] [blame] | 40 | KEY=$(patsubst "%",$(srctree)/%,$(CONFIG_SYS_K3_KEY)) |
Lokesh Vutla | 6b6a394 | 2018-11-02 19:51:04 +0530 | [diff] [blame] | 41 | endif |
| 42 | |
| 43 | u-boot-spl-eckey.pem: FORCE |
| 44 | $(call if_changed,genkey) |
| 45 | |
| 46 | # tiboot3.bin is mandated by ROM and ROM only supports R5 boot. |
| 47 | # So restrict tiboot3.bin creation for CPU_V7R. |
| 48 | ifdef CONFIG_CPU_V7R |
| 49 | u-boot-spl-cert.bin: $(KEY) $(obj)/u-boot-spl.bin image_check FORCE |
| 50 | $(call if_changed,gencert) |
| 51 | |
| 52 | image_check: $(obj)/u-boot-spl.bin FORCE |
| 53 | @if [ $(IMAGE_SIZE) -gt $(MAX_SIZE) ]; then \ |
| 54 | echo "===============================================" >&2; \ |
| 55 | echo "ERROR: Final Image too big. " >&2; \ |
| 56 | echo "$< size = $(IMAGE_SIZE), max size = $(MAX_SIZE)" >&2; \ |
| 57 | echo "===============================================" >&2; \ |
| 58 | exit 1; \ |
| 59 | fi |
| 60 | |
| 61 | tiboot3.bin: u-boot-spl-cert.bin $(obj)/u-boot-spl.bin FORCE |
| 62 | $(call if_changed,cat) |
| 63 | |
| 64 | ALL-y += tiboot3.bin |
| 65 | endif |
| 66 | |
Lokesh Vutla | bc5bd3a | 2018-08-27 15:57:15 +0530 | [diff] [blame] | 67 | ifdef CONFIG_ARM64 |
| 68 | SPL_ITS := u-boot-spl-k3.its |
| 69 | $(SPL_ITS): FORCE |
| 70 | $(srctree)/tools/k3_fit_atf.sh \ |
| 71 | $(patsubst %,$(obj)/dts/%.dtb,$(subst ",,$(CONFIG_SPL_OF_LIST))) > $@ |
| 72 | |
| 73 | ALL-y += tispl.bin |
| 74 | endif |
| 75 | |
| 76 | else |
| 77 | ALL-y += u-boot.img |
| 78 | endif |