blob: 62cbf3e0ce0e40935b00d77c87f56f0ebb09852d [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
Chris Kay255a4092024-02-21 12:52:46 +000033LDFLAGS := -Wl,--gc-sections -nostdlib
34
Roberto Vargase92111a2018-05-22 16:05:42 +010035ifeq ($(DEBUG),1)
Chris Kay255a4092024-02-21 12:52:46 +000036 LDFLAGS += -Wl,-Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010037endif
38
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010039ifeq (${ARM_ARCH_MINOR},0)
40 ASFLAGS = -march=armv8-a
41else
42 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
43endif
Roberto Vargase92111a2018-05-22 16:05:42 +010044
45.PHONY: all clean distclean
46
47all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
48
49%.o: %.s
50 @echo " AS $@"
Chris Kay523e8642023-12-04 12:03:51 +000051 $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010052
53$(BUILD_DIR)/%.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)/romlib.ld: romlib.ld.S
58 @echo " PP $@"
Chris Kay523e8642023-12-04 12:03:51 +000059 $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010060
61$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
62 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +000063 $(Q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010064
65$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
66 @echo " BIN $@"
Chris Kay523e8642023-12-04 12:03:51 +000067 $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010068
69$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
70 @echo " VAR $@"
Imre Kis2d137c52019-07-09 18:30:58 +020071 $(Q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010072
Imre Kis2d137c52019-07-09 18:30:58 +020073$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Roberto Vargase92111a2018-05-22 16:05:42 +010074 @echo " AR $@"
Chris Kay523e8642023-12-04 12:03:51 +000075 $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020076
77$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
78 @echo " PRE $@"
79 $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010080
Imre Kis2d137c52019-07-09 18:30:58 +020081$(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i
82 @echo " WRP $<"
83 $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
84 @touch $@
John Tsichritzisaec19d32019-03-08 16:54:13 +000085
Imre Kis2d137c52019-07-09 18:30:58 +020086$(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp
87
88$(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp
89
90$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
Roberto Vargase92111a2018-05-22 16:05:42 +010091 @echo " TBL $@"
Imre Kis2d137c52019-07-09 18:30:58 +020092 $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010093
94clean:
95 @rm -f $(BUILD_DIR)/*
96
97-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +020098-include $(BUILD_DIR)/jmptbl.d