blob: 9ade331d0127b6b4f4aa15ec6e90e3c03fb35ea0 [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 Kay1870c722024-05-02 17:52:37 +000013include ../../make_helpers/common.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +000014include ../../make_helpers/toolchain.mk
15
Imre Kis2d137c52019-07-09 18:30:58 +020016ROMLIB_GEN = ./romlib_generator.py
Grant Likely388248a2020-07-30 08:50:10 +010017BUILD_DIR = $(BUILD_PLAT)/romlib
18LIB_DIR = $(BUILD_PLAT)/lib
19WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
Roberto Vargase92111a2018-05-22 16:05:42 +010020LIBS = -lmbedtls -lfdt -lc
21INC = $(INCLUDES:-I%=-I../../%)
Julius Werner53456fc2019-07-09 13:49:11 -070022PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
Roberto Vargase92111a2018-05-22 16:05:42 +010023OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
Grant Likely388248a2020-07-30 08:50:10 +010024MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
Roberto Vargase92111a2018-05-22 16:05:42 +010025
Imre Kis2d137c52019-07-09 18:30:58 +020026ifneq ($(PLAT_DIR),)
Chris Kay48d20fa2024-05-29 21:57:48 +000027 WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
28 $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i))
29
30 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
Imre Kis2d137c52019-07-09 18:30:58 +020031endif
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
Chris Kay1870c722024-05-02 17:52:37 +000050 $(s)echo " AS $@"
51 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010052
53$(BUILD_DIR)/%.o: %.s
Chris Kay1870c722024-05-02 17:52:37 +000054 $(s)echo " AS $@"
55 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010056
57$(BUILD_DIR)/romlib.ld: romlib.ld.S
Chris Kay1870c722024-05-02 17:52:37 +000058 $(s)echo " PP $@"
59 $(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
Chris Kay1870c722024-05-02 17:52:37 +000062 $(s)echo " LD $@"
63 $(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
Chris Kay1870c722024-05-02 17:52:37 +000066 $(s)echo " BIN $@"
67 $(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
Chris Kay1870c722024-05-02 17:52:37 +000070 $(s)echo " VAR $@"
71 $(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)
Chris Kay1870c722024-05-02 17:52:37 +000074 $(s)echo " AR $@"
75 $(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
Chris Kay1870c722024-05-02 17:52:37 +000078 $(s)echo " PRE $@"
79 $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010080
Chris Kay1479b1a2024-05-23 13:09:39 +000081$(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i
Chris Kay1870c722024-05-02 17:52:37 +000082 $(s)echo " WRP $<"
83 $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
Imre Kis2d137c52019-07-09 18:30:58 +020084
Chris Kay1479b1a2024-05-23 13:09:39 +000085$(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s
Imre Kis2d137c52019-07-09 18:30:58 +020086
87$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
Chris Kay1870c722024-05-02 17:52:37 +000088 $(s)echo " TBL $@"
89 $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010090
91clean:
Chris Kay1870c722024-05-02 17:52:37 +000092 $(q)rm -f $(BUILD_DIR)/*
Roberto Vargase92111a2018-05-22 16:05:42 +010093
94-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +020095-include $(BUILD_DIR)/jmptbl.d