Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 1 | # |
Chris Kay | c7ea347 | 2024-01-15 18:45:07 +0000 | [diff] [blame] | 2 | # Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved. |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 7 | include ../../make_helpers/build-rules.mk |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 8 | include ../../make_helpers/common.mk |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 9 | include ../../make_helpers/toolchain.mk |
| 10 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 11 | ROMLIB_GEN = ./romlib_generator.py |
Grant Likely | 388248a | 2020-07-30 08:50:10 +0100 | [diff] [blame] | 12 | BUILD_DIR = $(BUILD_PLAT)/romlib |
| 13 | LIB_DIR = $(BUILD_PLAT)/lib |
| 14 | WRAPPER_DIR = $(BUILD_PLAT)/libwrapper |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 15 | LIBS = -lmbedtls -lfdt -lc |
| 16 | INC = $(INCLUDES:-I%=-I../../%) |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 17 | PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 18 | OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o |
Grant Likely | 388248a | 2020-07-30 08:50:10 +0100 | [diff] [blame] | 19 | MAPFILE = $(BUILD_PLAT)/romlib/romlib.map |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 20 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 21 | ifneq ($(PLAT_DIR),) |
Chris Kay | 48d20fa | 2024-05-29 21:57:48 +0000 | [diff] [blame] | 22 | 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 Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 26 | endif |
| 27 | |
Chris Kay | 255a409 | 2024-02-21 12:52:46 +0000 | [diff] [blame] | 28 | LDFLAGS := -Wl,--gc-sections -nostdlib |
| 29 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 30 | ifeq ($(DEBUG),1) |
Chris Kay | 255a409 | 2024-02-21 12:52:46 +0000 | [diff] [blame] | 31 | LDFLAGS += -Wl,-Map=$(MAPFILE) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 32 | endif |
| 33 | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 34 | ifeq (${ARM_ARCH_MINOR},0) |
| 35 | ASFLAGS = -march=armv8-a |
| 36 | else |
| 37 | ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a |
| 38 | endif |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 39 | |
| 40 | .PHONY: all clean distclean |
| 41 | |
Jimmy Brisson | 1dfa271 | 2024-07-22 12:55:43 -0500 | [diff] [blame] | 42 | all: $(BUILD_DIR)/romlib.bin $(BUILD_DIR)/romlib.ldflags $(LIB_DIR)/libwrappers.a |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 43 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 44 | %.o: %.s | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 45 | $(s)echo " AS $@" |
| 46 | $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 47 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 48 | $(BUILD_DIR)/%.o: %.s | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 49 | $(s)echo " AS $@" |
| 50 | $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 51 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 52 | $(BUILD_DIR)/romlib.ld: romlib.ld.S | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 53 | $(s)echo " PP $@" |
| 54 | $(q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 55 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 56 | $(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 57 | $(s)echo " LD $@" |
| 58 | $(q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 59 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 60 | $(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 61 | $(s)echo " BIN $@" |
| 62 | $(q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@ |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 63 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 64 | $(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 65 | $(s)echo " VAR $@" |
| 66 | $(q)$(ROMLIB_GEN) genvar --output $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 67 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 68 | $(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 69 | $(s)echo " AR $@" |
| 70 | $(q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 71 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 72 | $(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 73 | $(s)echo " PRE $@" |
| 74 | $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 75 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 76 | $(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 77 | $(s)echo " WRP $<" |
| 78 | $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $< |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 79 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 80 | $(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s | $$(@D)/ |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 81 | |
Chris Kay | 1559f64 | 2024-06-04 00:04:48 +0000 | [diff] [blame] | 82 | $(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i | $$(@D)/ |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 83 | $(s)echo " TBL $@" |
| 84 | $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 85 | |
Jimmy Brisson | 1dfa271 | 2024-07-22 12:55:43 -0500 | [diff] [blame] | 86 | $(BUILD_DIR)/romlib.ldflags: ../../$(PLAT_DIR)/jmptbl.i |
| 87 | $(s)echo " LDFLAGS $@" |
| 88 | $(q)$(ROMLIB_GEN) link-flags $< > $@ |
| 89 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 90 | clean: |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 91 | $(q)rm -f $(BUILD_DIR)/* |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 92 | |
| 93 | -include $(BUILD_DIR)/romlib.d |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 94 | -include $(BUILD_DIR)/jmptbl.d |