blob: f11e5779e7c10e82c16f634ac481bdf63e68b988 [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
Imre Kis2d137c52019-07-09 18:30:58 +020011ROMLIB_GEN = ./romlib_generator.py
Grant Likely388248a2020-07-30 08:50:10 +010012BUILD_DIR = $(BUILD_PLAT)/romlib
13LIB_DIR = $(BUILD_PLAT)/lib
14WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
Roberto Vargase92111a2018-05-22 16:05:42 +010015LIBS = -lmbedtls -lfdt -lc
16INC = $(INCLUDES:-I%=-I../../%)
Julius Werner53456fc2019-07-09 13:49:11 -070017PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
Roberto Vargase92111a2018-05-22 16:05:42 +010018OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
Grant Likely388248a2020-07-30 08:50:10 +010019MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
Roberto Vargase92111a2018-05-22 16:05:42 +010020
Imre Kis2d137c52019-07-09 18:30:58 +020021ifneq ($(PLAT_DIR),)
22 WRAPPER_SOURCES = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)
23 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
24endif
25
Roberto Vargase92111a2018-05-22 16:05:42 +010026V ?= 0
27ifeq ($(V),0)
28 Q := @
29else
30 Q :=
31endif
32
Louis Mayencourt70d4c9c2019-04-29 16:35:30 +010033LDFLAGS := --gc-sections -O1
Roberto Vargase92111a2018-05-22 16:05:42 +010034ifeq ($(DEBUG),1)
Louis Mayencourt70d4c9c2019-04-29 16:35:30 +010035 LDFLAGS += -Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010036endif
37
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010038ifeq (${ARM_ARCH_MINOR},0)
39 ASFLAGS = -march=armv8-a
40else
41 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
42endif
Roberto Vargase92111a2018-05-22 16:05:42 +010043
44.PHONY: all clean distclean
45
46all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
47
48%.o: %.s
49 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000050 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010051
52$(BUILD_DIR)/%.o: %.s
53 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000054 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010055
56$(BUILD_DIR)/romlib.ld: romlib.ld.S
57 @echo " PP $@"
Chris Kay523e8642023-12-04 12:03:51 +000058 $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010059
60$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
61 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +000062 $(Q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010063
64$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
65 @echo " BIN $@"
Chris Kay523e8642023-12-04 12:03:51 +000066 $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010067
68$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
69 @echo " VAR $@"
Imre Kis2d137c52019-07-09 18:30:58 +020070 $(Q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010071
Imre Kis2d137c52019-07-09 18:30:58 +020072$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Roberto Vargase92111a2018-05-22 16:05:42 +010073 @echo " AR $@"
Chris Kay523e8642023-12-04 12:03:51 +000074 $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020075
76$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
77 @echo " PRE $@"
78 $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010079
Imre Kis2d137c52019-07-09 18:30:58 +020080$(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i
81 @echo " WRP $<"
82 $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
83 @touch $@
John Tsichritzisaec19d32019-03-08 16:54:13 +000084
Imre Kis2d137c52019-07-09 18:30:58 +020085$(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp
86
87$(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp
88
89$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
Roberto Vargase92111a2018-05-22 16:05:42 +010090 @echo " TBL $@"
Imre Kis2d137c52019-07-09 18:30:58 +020091 $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010092
93clean:
94 @rm -f $(BUILD_DIR)/*
95
96-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +020097-include $(BUILD_DIR)/jmptbl.d