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 | 0adde4e | 2024-05-14 13:08:31 +0000 | [diff] [blame] | 7 | ifeq ($(filter-out clean,$(or $(MAKECMDGOALS),all)),) |
| 8 | toolchains := |
| 9 | else |
| 10 | toolchains := aarch64 |
| 11 | endif |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 12 | |
| 13 | include ../../make_helpers/toolchain.mk |
| 14 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 15 | ROMLIB_GEN = ./romlib_generator.py |
Grant Likely | 388248a | 2020-07-30 08:50:10 +0100 | [diff] [blame] | 16 | BUILD_DIR = $(BUILD_PLAT)/romlib |
| 17 | LIB_DIR = $(BUILD_PLAT)/lib |
| 18 | WRAPPER_DIR = $(BUILD_PLAT)/libwrapper |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 19 | LIBS = -lmbedtls -lfdt -lc |
| 20 | INC = $(INCLUDES:-I%=-I../../%) |
Julius Werner | 53456fc | 2019-07-09 13:49:11 -0700 | [diff] [blame] | 21 | 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] | 22 | OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o |
Grant Likely | 388248a | 2020-07-30 08:50:10 +0100 | [diff] [blame] | 23 | MAPFILE = $(BUILD_PLAT)/romlib/romlib.map |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 24 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 25 | ifneq ($(PLAT_DIR),) |
Chris Kay | 48d20fa | 2024-05-29 21:57:48 +0000 | [diff] [blame] | 26 | WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\ |
| 27 | $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)) |
| 28 | |
| 29 | WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o) |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 30 | endif |
| 31 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 32 | V ?= 0 |
| 33 | ifeq ($(V),0) |
| 34 | Q := @ |
| 35 | else |
| 36 | Q := |
| 37 | endif |
| 38 | |
Chris Kay | 255a409 | 2024-02-21 12:52:46 +0000 | [diff] [blame] | 39 | LDFLAGS := -Wl,--gc-sections -nostdlib |
| 40 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 41 | ifeq ($(DEBUG),1) |
Chris Kay | 255a409 | 2024-02-21 12:52:46 +0000 | [diff] [blame] | 42 | LDFLAGS += -Wl,-Map=$(MAPFILE) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 43 | endif |
| 44 | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 45 | ifeq (${ARM_ARCH_MINOR},0) |
| 46 | ASFLAGS = -march=armv8-a |
| 47 | else |
| 48 | ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a |
| 49 | endif |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 50 | |
| 51 | .PHONY: all clean distclean |
| 52 | |
| 53 | all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a |
| 54 | |
| 55 | %.o: %.s |
| 56 | @echo " AS $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 57 | $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 58 | |
| 59 | $(BUILD_DIR)/%.o: %.s |
| 60 | @echo " AS $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 61 | $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 62 | |
| 63 | $(BUILD_DIR)/romlib.ld: romlib.ld.S |
| 64 | @echo " PP $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 65 | $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 66 | |
| 67 | $(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld |
| 68 | @echo " LD $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 69 | $(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] | 70 | |
| 71 | $(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf |
| 72 | @echo " BIN $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 73 | $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@ |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 74 | |
| 75 | $(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf |
| 76 | @echo " VAR $@" |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 77 | $(Q)$(ROMLIB_GEN) genvar --output $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 78 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 79 | $(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 80 | @echo " AR $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 81 | $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 82 | |
| 83 | $(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i |
| 84 | @echo " PRE $@" |
| 85 | $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 86 | |
Chris Kay | 1479b1a | 2024-05-23 13:09:39 +0000 | [diff] [blame] | 87 | $(WRAPPER_SOURCES) &: $(BUILD_DIR)/jmptbl.i |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 88 | @echo " WRP $<" |
| 89 | $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $< |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 90 | |
Chris Kay | 1479b1a | 2024-05-23 13:09:39 +0000 | [diff] [blame] | 91 | $(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 92 | |
| 93 | $(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 94 | @echo " TBL $@" |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 95 | $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 96 | |
| 97 | clean: |
| 98 | @rm -f $(BUILD_DIR)/* |
| 99 | |
| 100 | -include $(BUILD_DIR)/romlib.d |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 101 | -include $(BUILD_DIR)/jmptbl.d |