1#
2# Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6
7AS          = $(CROSS_COMPILE)as
8AR          = $(CROSS_COMPILE)ar
9LD          = $(CROSS_COMPILE)ld
10OC          = $(CROSS_COMPILE)objcopy
11CPP         = $(CROSS_COMPILE)cpp
12ROMLIB_GEN  = ./romlib_generator.py
13BUILD_DIR   = $(BUILD_PLAT)/romlib
14LIB_DIR     = $(BUILD_PLAT)/lib
15WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
16LIBS        = -lmbedtls -lfdt -lc
17INC         = $(INCLUDES:-I%=-I../../%)
18PPFLAGS     = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
19OBJS        = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
20MAPFILE     = $(BUILD_PLAT)/romlib/romlib.map
21
22ifneq ($(PLAT_DIR),)
23  WRAPPER_SOURCES   = $(shell $(ROMLIB_GEN) genwrappers -b $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i)
24  WRAPPER_OBJS      = $(WRAPPER_SOURCES:.s=.o)
25endif
26
27V ?= 0
28ifeq ($(V),0)
29  Q := @
30else
31  Q :=
32endif
33
34LDFLAGS := --gc-sections -O1
35ifeq ($(DEBUG),1)
36   LDFLAGS += -Map=$(MAPFILE)
37endif
38
39ifeq (${ARM_ARCH_MINOR},0)
40	ASFLAGS = -march=armv8-a
41else
42	ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
43endif
44
45.PHONY: all clean distclean
46
47all: $(BUILD_DIR)/romlib.bin $(LIB_DIR)/libwrappers.a
48
49%.o: %.s
50	@echo "  AS      $@"
51	$(Q)$(AS) $(ASFLAGS) -o $@ $<
52
53$(BUILD_DIR)/%.o: %.s
54	@echo "  AS      $@"
55	$(Q)$(AS) $(ASFLAGS) -o $@ $<
56
57$(BUILD_DIR)/romlib.ld: romlib.ld.S
58	@echo "  PP      $@"
59	$(Q)$(CPP) $(PPFLAGS) -o $@ romlib.ld.S
60
61$(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld
62	@echo "  LD      $@"
63	$(Q)$(LD) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
64
65$(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf
66	@echo "  BIN     $@"
67	$(Q)$(OC) -O binary $(BUILD_DIR)/romlib.elf $@
68
69$(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf
70	@echo "  VAR     $@"
71	$(Q)$(ROMLIB_GEN) genvar --output $@ $<
72
73$(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
74	@echo "  AR      $@"
75	$(Q)$(AR) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
76
77$(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i
78	@echo "  PRE     $@"
79	$(Q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
80
81$(BUILD_DIR)/wrappers.stamp: $(BUILD_DIR)/jmptbl.i
82	@echo "  WRP     $<"
83	$(Q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
84	@touch $@
85
86$(WRAPPER_SOURCES): $(BUILD_DIR)/wrappers.stamp
87
88$(WRAPPER_OBJS): $(WRAPPER_SOURCES) $(BUILD_DIR)/wrappers.stamp
89
90$(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i
91	@echo "  TBL     $@"
92	$(Q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
93
94clean:
95	@rm -f $(BUILD_DIR)/*
96
97-include $(BUILD_DIR)/romlib.d
98-include $(BUILD_DIR)/jmptbl.d
99