blob: 1ae90959d25a91b6eecaac689b2caa90951ebe45 [file] [log] [blame]
Roberto Vargase92111a2018-05-22 16:05:42 +01001#
Chris Kayc7ea3472024-01-15 18:45:07 +00002# Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
Roberto Vargase92111a2018-05-22 16:05:42 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
Chris Kayc8a47ba2023-10-20 09:17:33 +00007toolchains := aarch64
8
9include ../../make_helpers/toolchain.mk
10
Chris Kayc66b9f32024-01-15 18:45:07 +000011AS = $(CROSS_COMPILE)gcc
Chris Kayfdb6f422024-01-15 19:55:11 +000012AR = $(CROSS_COMPILE)gcc-ar
Roberto Vargase92111a2018-05-22 16:05:42 +010013LD = $(CROSS_COMPILE)ld
14OC = $(CROSS_COMPILE)objcopy
Chris Kayc7ea3472024-01-15 18:45:07 +000015CPP = $(CROSS_COMPILE)gcc -E
Imre Kis2d137c52019-07-09 18:30:58 +020016ROMLIB_GEN = ./romlib_generator.py
Grant Likely388248a2020-07-30 08:50:10 +010017BUILD_DIR = $(BUILD_PLAT)/romlib
18LIB_DIR = $(BUILD_PLAT)/lib
19WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
Roberto Vargase92111a2018-05-22 16:05:42 +010020LIBS = -lmbedtls -lfdt -lc
21INC = $(INCLUDES:-I%=-I../../%)
Julius Werner53456fc2019-07-09 13:49:11 -070022PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
Roberto Vargase92111a2018-05-22 16:05:42 +010023OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
Grant Likely388248a2020-07-30 08:50:10 +010024MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
Roberto Vargase92111a2018-05-22 16:05:42 +010025
Imre Kis2d137c52019-07-09 18:30:58 +020026ifneq ($(PLAT_DIR),)
27 WRAPPER_SOURCES = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)
28 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
29endif
30
Roberto Vargase92111a2018-05-22 16:05:42 +010031V ?= 0
32ifeq ($(V),0)
33 Q := @
34else
35 Q :=
36endif
37
Louis Mayencourt70d4c9c2019-04-29 16:35:30 +010038LDFLAGS := --gc-sections -O1
Roberto Vargase92111a2018-05-22 16:05:42 +010039ifeq ($(DEBUG),1)
Louis Mayencourt70d4c9c2019-04-29 16:35:30 +010040 LDFLAGS += -Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010041endif
42
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010043ifeq (${ARM_ARCH_MINOR},0)
44 ASFLAGS = -march=armv8-a
45else
46 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
47endif
Roberto Vargase92111a2018-05-22 16:05:42 +010048
49.PHONY: all clean distclean
50
51all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
52
53%.o: %.s
54 @echo " AS $@"
Chris Kayc66b9f32024-01-15 18:45:07 +000055 $(Q)$(AS) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010056
57$(BUILD_DIR)/%.o: %.s
58 @echo " AS $@"
Chris Kayc66b9f32024-01-15 18:45:07 +000059 $(Q)$(AS) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010060
61$(BUILD_DIR)/romlib.ld: romlib.ld.S
62 @echo " PP $@"
63 $(Q)$(CPP) $(PPFLAGS) -o $@ romlib.ld.S
64
65$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
66 @echo " LD $@"
67 $(Q)$(LD) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
68
69$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
70 @echo " BIN $@"
71 $(Q)$(OC) -O binary $(BUILD_DIR)/romlib.elf $@
72
73$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
74 @echo " VAR $@"
Imre Kis2d137c52019-07-09 18:30:58 +020075 $(Q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010076
Imre Kis2d137c52019-07-09 18:30:58 +020077$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Roberto Vargase92111a2018-05-22 16:05:42 +010078 @echo " AR $@"
Imre Kis2d137c52019-07-09 18:30:58 +020079 $(Q)$(AR) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
80
81$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
82 @echo " PRE $@"
83 $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010084
Imre Kis2d137c52019-07-09 18:30:58 +020085$(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i
86 @echo " WRP $<"
87 $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
88 @touch $@
John Tsichritzisaec19d32019-03-08 16:54:13 +000089
Imre Kis2d137c52019-07-09 18:30:58 +020090$(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp
91
92$(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp
93
94$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
Roberto Vargase92111a2018-05-22 16:05:42 +010095 @echo " TBL $@"
Imre Kis2d137c52019-07-09 18:30:58 +020096 $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010097
98clean:
99 @rm -f $(BUILD_DIR)/*
100
101-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +0200102-include $(BUILD_DIR)/jmptbl.d