blob: 1293f061d1439cc95a7015707096a1b04c5486c1 [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),)
26 WRAPPER_SOURCES = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)
27 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
28endif
29
Roberto Vargase92111a2018-05-22 16:05:42 +010030V ?= 0
31ifeq ($(V),0)
32 Q := @
33else
34 Q :=
35endif
36
Chris Kay255a4092024-02-21 12:52:46 +000037LDFLAGS := -Wl,--gc-sections -nostdlib
38
Roberto Vargase92111a2018-05-22 16:05:42 +010039ifeq ($(DEBUG),1)
Chris Kay255a4092024-02-21 12:52:46 +000040 LDFLAGS += -Wl,-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 Kay523e8642023-12-04 12:03:51 +000055 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010056
57$(BUILD_DIR)/%.o: %.s
58 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000059 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010060
61$(BUILD_DIR)/romlib.ld: romlib.ld.S
62 @echo " PP $@"
Chris Kay523e8642023-12-04 12:03:51 +000063 $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010064
65$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
66 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +000067 $(Q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010068
69$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
70 @echo " BIN $@"
Chris Kay523e8642023-12-04 12:03:51 +000071 $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010072
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 $@"
Chris Kay523e8642023-12-04 12:03:51 +000079 $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020080
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