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 | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 7 | toolchains := aarch64 |
| 8 | |
| 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),) |
| 22 | WRAPPER_SOURCES = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i) |
| 23 | WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o) |
| 24 | endif |
| 25 | |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 26 | V ?= 0 |
| 27 | ifeq ($(V),0) |
| 28 | Q := @ |
| 29 | else |
| 30 | Q := |
| 31 | endif |
| 32 | |
Louis Mayencourt | 70d4c9c | 2019-04-29 16:35:30 +0100 | [diff] [blame] | 33 | LDFLAGS := --gc-sections -O1 |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 34 | ifeq ($(DEBUG),1) |
Louis Mayencourt | 70d4c9c | 2019-04-29 16:35:30 +0100 | [diff] [blame] | 35 | LDFLAGS += -Map=$(MAPFILE) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 36 | endif |
| 37 | |
John Tsichritzis | f6ea99b | 2019-05-21 15:47:37 +0100 | [diff] [blame] | 38 | ifeq (${ARM_ARCH_MINOR},0) |
| 39 | ASFLAGS = -march=armv8-a |
| 40 | else |
| 41 | ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a |
| 42 | endif |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 43 | |
| 44 | .PHONY: all clean distclean |
| 45 | |
| 46 | all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a |
| 47 | |
| 48 | %.o: %.s |
| 49 | @echo " AS $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 50 | $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 51 | |
| 52 | $(BUILD_DIR)/%.o: %.s |
| 53 | @echo " AS $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 54 | $(Q)$(aarch64-as) -c $(ASFLAGS) -o $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 55 | |
| 56 | $(BUILD_DIR)/romlib.ld: romlib.ld.S |
| 57 | @echo " PP $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 58 | $(Q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 59 | |
| 60 | $(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld |
| 61 | @echo " LD $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 62 | $(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] | 63 | |
| 64 | $(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf |
| 65 | @echo " BIN $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 66 | $(Q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@ |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 67 | |
| 68 | $(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf |
| 69 | @echo " VAR $@" |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 70 | $(Q)$(ROMLIB_GEN) genvar --output $@ $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 71 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 72 | $(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 73 | @echo " AR $@" |
Chris Kay | 523e864 | 2023-12-04 12:03:51 +0000 | [diff] [blame] | 74 | $(Q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 75 | |
| 76 | $(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i |
| 77 | @echo " PRE $@" |
| 78 | $(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 79 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 80 | $(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i |
| 81 | @echo " WRP $<" |
| 82 | $(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $< |
| 83 | @touch $@ |
John Tsichritzis | aec19d3 | 2019-03-08 16:54:13 +0000 | [diff] [blame] | 84 | |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 85 | $(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp |
| 86 | |
| 87 | $(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp |
| 88 | |
| 89 | $(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 90 | @echo " TBL $@" |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 91 | $(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $< |
Roberto Vargas | e92111a | 2018-05-22 16:05:42 +0100 | [diff] [blame] | 92 | |
| 93 | clean: |
| 94 | @rm -f $(BUILD_DIR)/* |
| 95 | |
| 96 | -include $(BUILD_DIR)/romlib.d |
Imre Kis | 2d137c5 | 2019-07-09 18:30:58 +0200 | [diff] [blame] | 97 | -include $(BUILD_DIR)/jmptbl.d |