blob: 9859ce1c87ae88f231e9dc9edd669bb2a613c790 [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
Chris Kay1559f642024-06-04 00:04:48 +000013include ../../make_helpers/build-rules.mk
Chris Kay1870c722024-05-02 17:52:37 +000014include ../../make_helpers/common.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +000015include ../../make_helpers/toolchain.mk
16
Imre Kis2d137c52019-07-09 18:30:58 +020017ROMLIB_GEN = ./romlib_generator.py
Grant Likely388248a2020-07-30 08:50:10 +010018BUILD_DIR = $(BUILD_PLAT)/romlib
19LIB_DIR = $(BUILD_PLAT)/lib
20WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
Roberto Vargase92111a2018-05-22 16:05:42 +010021LIBS = -lmbedtls -lfdt -lc
22INC = $(INCLUDES:-I%=-I../../%)
Julius Werner53456fc2019-07-09 13:49:11 -070023PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
Roberto Vargase92111a2018-05-22 16:05:42 +010024OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
Grant Likely388248a2020-07-30 08:50:10 +010025MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
Roberto Vargase92111a2018-05-22 16:05:42 +010026
Imre Kis2d137c52019-07-09 18:30:58 +020027ifneq ($(PLAT_DIR),)
Chris Kay48d20fa2024-05-29 21:57:48 +000028 WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
29 $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i))
30
31 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
Imre Kis2d137c52019-07-09 18:30:58 +020032endif
33
Chris Kay255a4092024-02-21 12:52:46 +000034LDFLAGS := -Wl,--gc-sections -nostdlib
35
Roberto Vargase92111a2018-05-22 16:05:42 +010036ifeq ($(DEBUG),1)
Chris Kay255a4092024-02-21 12:52:46 +000037 LDFLAGS += -Wl,-Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010038endif
39
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010040ifeq (${ARM_ARCH_MINOR},0)
41 ASFLAGS = -march=armv8-a
42else
43 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
44endif
Roberto Vargase92111a2018-05-22 16:05:42 +010045
46.PHONY: all clean distclean
47
48all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
49
Chris Kay1559f642024-06-04 00:04:48 +000050%.o: %.s | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000051 $(s)echo " AS $@"
52 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010053
Chris Kay1559f642024-06-04 00:04:48 +000054$(BUILD_DIR)/%.o: %.s | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000055 $(s)echo " AS $@"
56 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010057
Chris Kay1559f642024-06-04 00:04:48 +000058$(BUILD_DIR)/romlib.ld: romlib.ld.S | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000059 $(s)echo " PP $@"
60 $(q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010061
Chris Kay1559f642024-06-04 00:04:48 +000062$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000063 $(s)echo " LD $@"
64 $(q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010065
Chris Kay1559f642024-06-04 00:04:48 +000066$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000067 $(s)echo " BIN $@"
68 $(q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010069
Chris Kay1559f642024-06-04 00:04:48 +000070$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000071 $(s)echo " VAR $@"
72 $(q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010073
Chris Kay1559f642024-06-04 00:04:48 +000074$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000075 $(s)echo " AR $@"
76 $(q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020077
Chris Kay1559f642024-06-04 00:04:48 +000078$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000079 $(s)echo " PRE $@"
80 $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010081
Chris Kay1559f642024-06-04 00:04:48 +000082$(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000083 $(s)echo " WRP $<"
84 $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
Imre Kis2d137c52019-07-09 18:30:58 +020085
Chris Kay1559f642024-06-04 00:04:48 +000086$(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s | $$(@D)/
Imre Kis2d137c52019-07-09 18:30:58 +020087
Chris Kay1559f642024-06-04 00:04:48 +000088$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000089 $(s)echo " TBL $@"
90 $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010091
92clean:
Chris Kay1870c722024-05-02 17:52:37 +000093 $(q)rm -f $(BUILD_DIR)/*
Roberto Vargase92111a2018-05-22 16:05:42 +010094
95-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +020096-include $(BUILD_DIR)/jmptbl.d