blob: 3d2b8502622408b5c7b2ef4f6da59748e24bac03 [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 Kay1559f642024-06-04 00:04:48 +00007include ../../make_helpers/build-rules.mk
Chris Kay1870c722024-05-02 17:52:37 +00008include ../../make_helpers/common.mk
Chris Kayc8a47ba2023-10-20 09:17:33 +00009include ../../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),)
Chris Kay48d20fa2024-05-29 21:57:48 +000022 WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
23 $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i))
24
25 WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
Imre Kis2d137c52019-07-09 18:30:58 +020026endif
27
Chris Kay255a4092024-02-21 12:52:46 +000028LDFLAGS := -Wl,--gc-sections -nostdlib
29
Roberto Vargase92111a2018-05-22 16:05:42 +010030ifeq ($(DEBUG),1)
Chris Kay255a4092024-02-21 12:52:46 +000031 LDFLAGS += -Wl,-Map=$(MAPFILE)
Roberto Vargase92111a2018-05-22 16:05:42 +010032endif
33
John Tsichritzisf6ea99b2019-05-21 15:47:37 +010034ifeq (${ARM_ARCH_MINOR},0)
35 ASFLAGS = -march=armv8-a
36else
37 ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
38endif
Roberto Vargase92111a2018-05-22 16:05:42 +010039
40.PHONY: all clean distclean
41
Jimmy Brisson1dfa2712024-07-22 12:55:43 -050042all: $(BUILD_DIR)/romlib.bin $(BUILD_DIR)/romlib.ldflags $(LIB_DIR)/libwrappers.a
Roberto Vargase92111a2018-05-22 16:05:42 +010043
Chris Kay1559f642024-06-04 00:04:48 +000044%.o: %.s | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000045 $(s)echo " AS $@"
46 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010047
Chris Kay1559f642024-06-04 00:04:48 +000048$(BUILD_DIR)/%.o: %.s | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000049 $(s)echo " AS $@"
50 $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010051
Chris Kay1559f642024-06-04 00:04:48 +000052$(BUILD_DIR)/romlib.ld: romlib.ld.S | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000053 $(s)echo " PP $@"
54 $(q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
Roberto Vargase92111a2018-05-22 16:05:42 +010055
Chris Kay1559f642024-06-04 00:04:48 +000056$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000057 $(s)echo " LD $@"
58 $(q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
Roberto Vargase92111a2018-05-22 16:05:42 +010059
Chris Kay1559f642024-06-04 00:04:48 +000060$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000061 $(s)echo " BIN $@"
62 $(q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
Roberto Vargase92111a2018-05-22 16:05:42 +010063
Chris Kay1559f642024-06-04 00:04:48 +000064$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000065 $(s)echo " VAR $@"
66 $(q)$(ROMLIB_GEN) genvar --output $@ $<
Roberto Vargase92111a2018-05-22 16:05:42 +010067
Chris Kay1559f642024-06-04 00:04:48 +000068$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000069 $(s)echo " AR $@"
70 $(q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
Imre Kis2d137c52019-07-09 18:30:58 +020071
Chris Kay1559f642024-06-04 00:04:48 +000072$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000073 $(s)echo " PRE $@"
74 $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
Roberto Vargase92111a2018-05-22 16:05:42 +010075
Chris Kay1559f642024-06-04 00:04:48 +000076$(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000077 $(s)echo " WRP $<"
78 $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
Imre Kis2d137c52019-07-09 18:30:58 +020079
Chris Kay1559f642024-06-04 00:04:48 +000080$(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s | $$(@D)/
Imre Kis2d137c52019-07-09 18:30:58 +020081
Chris Kay1559f642024-06-04 00:04:48 +000082$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i | $$(@D)/
Chris Kay1870c722024-05-02 17:52:37 +000083 $(s)echo " TBL $@"
84 $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
Roberto Vargase92111a2018-05-22 16:05:42 +010085
Jimmy Brisson1dfa2712024-07-22 12:55:43 -050086$(BUILD_DIR)/romlib.ldflags: ../../$(PLAT_DIR)/jmptbl.i
87 $(s)echo " LDFLAGS $@"
88 $(q)$(ROMLIB_GEN) link-flags $< > $@
89
Roberto Vargase92111a2018-05-22 16:05:42 +010090clean:
Chris Kay1870c722024-05-02 17:52:37 +000091 $(q)rm -f $(BUILD_DIR)/*
Roberto Vargase92111a2018-05-22 16:05:42 +010092
93-include $(BUILD_DIR)/romlib.d
Imre Kis2d137c52019-07-09 18:30:58 +020094-include $(BUILD_DIR)/jmptbl.d