1## SPDX-License-Identifier: GPL-2.0-only 2 3xcompile ?= ../../../../../build/xcompile 4-include $(xcompile) 5 6GCC_PREFIX?=$(CROSS_COMPILE_arm) 7 8CC = $(GCC_PREFIX)gcc 9NM = $(GCC_PREFIX)nm 10OBJCOPY = $(GCC_PREFIX)objcopy 11 12OPENSSL = openssl 13DD = dd 14CP = cp 15MV = mv 16RM = rm 17 18SIGKEY = 00000000000000000000000000000000 19 20.PHONY: all 21all: tegra_lp0_resume.fw 22 23tegra_lp0_resume.elf: tegra_lp0_resume.ld tegra_lp0_resume.c 24 $(CC) -marm -march=armv4t -mno-unaligned-access -nostdlib -static \ 25 -Os -fpie -Wl,--build-id=none -ggdb3 -T tegra_lp0_resume.ld \ 26 -include ../../../../include/stdint.h \ 27 -include ../../../../commonlib/bsd/include/commonlib/bsd/compiler.h \ 28 -o $@ $(filter %.c,$+) 29 30tegra_lp0_resume.fw: tegra_lp0_resume.elf 31 @# Get rid of any files we're about to create. 32 $(RM) -f $@.nosig $@.sig $@.tosig 33 @# Convert the ELF image into a binary image. 34 $(OBJCOPY) -O binary $< $@.nosig 35 @# Extract the part of the binary which needs to be signed. 36 $(DD) bs=1 skip=544 if=$@.nosig of=$@.tosig 37 @# Calculate a signature for that part. 38 $(OPENSSL) dgst -mac cmac -macopt cipher:aes-128-cbc \ 39 -macopt hexkey:$(SIGKEY) -md5 -binary \ 40 $@.tosig > $@.sig 41 @# Inject the signature into the binary image's header. 42 $(DD) conv=notrunc bs=1 seek=272 count=16 if=$@.sig of=$@.nosig 43 @# Copy the signed binary to the target file name. 44 $(MV) $@.nosig $@ 45 46distclean clean: 47 $(RM) -f tegra_lp0_resume.fw tegra_lp0_resume.fw.sig 48 $(RM) -f tegra_lp0_resume.fw.tosig tegra_lp0_resume.elf 49