blob: da3d3d56d55087a6b4a3a2f7685de3c64cabe82a [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 Kay0adde4e2024-05-14 13:08:31 +00007ifeq ($(filter-out clean,$(or $(MAKECMDGOALS),all)),)
8 toolchains :=
9else
10 toolchains := aarch64
11endif
Chris Kayc8a47ba2023-10-20 09:17:33 +000012
13include ../../make_helpers/toolchain.mk
14
Imre Kis2d137c52019-07-09 18:30:58 +020015ROMLIB_GEN = ./romlib_generator.py
Grant Likely388248a2020-07-30 08:50:10 +010016BUILD_DIR = $(BUILD_PLAT)/romlib
17LIB_DIR = $(BUILD_PLAT)/lib
18WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
Roberto Vargase92111a2018-05-22 16:05:42 +010019LIBS = -lmbedtls -lfdt -lc
20INC = $(INCLUDES:-I%=-I../../%)
Julius Werner53456fc2019-07-09 13:49:11 -070021PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
Roberto Vargase92111a2018-05-22 16:05:42 +010022OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
Grant Likely388248a2020-07-30 08:50:10 +010023MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
Roberto Vargase92111a2018-05-22 16:05:42 +010024
Imre Kis2d137c52019-07-09 18:30:58 +020025ifneq ($(PLAT_DIR),)
Chris Kay48d20fa2024-05-29 21:57:48 +000026 WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
27 $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i))
28
29 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
Imre Kis2d137c52019-07-09 18:30:58 +020030endif
31
Roberto Vargase92111a2018-05-22 16:05:42 +010032V ?= 0
33ifeq ($(V),0)
34 Q := @
35else
36 Q :=
37endif
38
Chris Kay255a4092024-02-21 12:52:46 +000039LDFLAGS := -Wl,--gc-sections -nostdlib
40
Roberto Vargase92111a2018-05-22 16:05:42 +010041ifeq ($(DEBUG),1)
Chris Kay255a4092024-02-21 12:52:46 +000042 LDFLAGS += -Wl,-Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010043endif
44
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010045ifeq (${ARM_ARCH_MINOR},0)
46 ASFLAGS = -march=armv8-a
47else
48 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
49endif
Roberto Vargase92111a2018-05-22 16:05:42 +010050
51.PHONY: all clean distclean
52
53all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
54
55%.o: %.s
56 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000057 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010058
59$(BUILD_DIR)/%.o: %.s
60 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000061 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010062
63$(BUILD_DIR)/romlib.ld: romlib.ld.S
64 @echo " PP $@"
Chris Kay523e8642023-12-04 12:03:51 +000065 $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010066
67$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
68 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +000069 $(Q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010070
71$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
72 @echo " BIN $@"
Chris Kay523e8642023-12-04 12:03:51 +000073 $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010074
75$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
76 @echo " VAR $@"
Imre Kis2d137c52019-07-09 18:30:58 +020077 $(Q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010078
Imre Kis2d137c52019-07-09 18:30:58 +020079$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Roberto Vargase92111a2018-05-22 16:05:42 +010080 @echo " AR $@"
Chris Kay523e8642023-12-04 12:03:51 +000081 $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020082
83$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
84 @echo " PRE $@"
85 $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010086
Chris Kay1479b1a2024-05-23 13:09:39 +000087$(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i
Imre Kis2d137c52019-07-09 18:30:58 +020088 @echo " WRP $<"
89 $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
Imre Kis2d137c52019-07-09 18:30:58 +020090
Chris Kay1479b1a2024-05-23 13:09:39 +000091$(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s
Imre Kis2d137c52019-07-09 18:30:58 +020092
93$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
Roberto Vargase92111a2018-05-22 16:05:42 +010094 @echo " TBL $@"
Imre Kis2d137c52019-07-09 18:30:58 +020095 $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010096
97clean:
98 @rm -f $(BUILD_DIR)/*
99
100-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +0200101-include $(BUILD_DIR)/jmptbl.d