Makefile 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #
  2. # Copyright (c) 2018-2024, Arm Limited and Contributors. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. include ../../make_helpers/build-rules.mk
  7. include ../../make_helpers/common.mk
  8. include ../../make_helpers/toolchain.mk
  9. ROMLIB_GEN = ./romlib_generator.py
  10. BUILD_DIR = $(BUILD_PLAT)/romlib
  11. LIB_DIR = $(BUILD_PLAT)/lib
  12. WRAPPER_DIR = $(BUILD_PLAT)/libwrapper
  13. LIBS = -lmbedtls -lfdt -lc
  14. INC = $(INCLUDES:-I%=-I../../%)
  15. PPFLAGS = $(INC) $(DEFINES) -P -x assembler-with-cpp -D__LINKER__ -MD -MP -MT $(BUILD_DIR)/romlib.ld
  16. OBJS = $(BUILD_DIR)/jmptbl.o $(BUILD_DIR)/init.o
  17. MAPFILE = $(BUILD_PLAT)/romlib/romlib.map
  18. ifneq ($(PLAT_DIR),)
  19. WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
  20. $(WRAPPER_DIR) --list ../../$(PLAT_DIR)/jmptbl.i))
  21. WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
  22. endif
  23. LDFLAGS := -Wl,--gc-sections -nostdlib
  24. ifeq ($(DEBUG),1)
  25. LDFLAGS += -Wl,-Map=$(MAPFILE)
  26. endif
  27. ifeq (${ARM_ARCH_MINOR},0)
  28. ASFLAGS = -march=armv8-a
  29. else
  30. ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
  31. endif
  32. .PHONY: all clean distclean
  33. all: $(BUILD_DIR)/romlib.bin $(BUILD_DIR)/romlib.ldflags $(LIB_DIR)/libwrappers.a
  34. %.o: %.s | $$(@D)/
  35. $(s)echo " AS $@"
  36. $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
  37. $(BUILD_DIR)/%.o: %.s | $$(@D)/
  38. $(s)echo " AS $@"
  39. $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
  40. $(BUILD_DIR)/romlib.ld: romlib.ld.S | $$(@D)/
  41. $(s)echo " PP $@"
  42. $(q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
  43. $(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld | $$(@D)/
  44. $(s)echo " LD $@"
  45. $(q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  46. $(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf | $$(@D)/
  47. $(s)echo " BIN $@"
  48. $(q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
  49. $(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf | $$(@D)/
  50. $(s)echo " VAR $@"
  51. $(q)$(ROMLIB_GEN) genvar --output $@ $<
  52. $(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) | $$(@D)/
  53. $(s)echo " AR $@"
  54. $(q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
  55. $(BUILD_DIR)/jmptbl.i: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/
  56. $(s)echo " PRE $@"
  57. $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
  58. $(WRAPPER_SOURCES) $&: $(BUILD_DIR)/jmptbl.i | $$(@D)/
  59. $(s)echo " WRP $<"
  60. $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
  61. $(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s | $$(@D)/
  62. $(BUILD_DIR)/jmptbl.s: $(BUILD_DIR)/jmptbl.i | $$(@D)/
  63. $(s)echo " TBL $@"
  64. $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
  65. $(BUILD_DIR)/romlib.ldflags: ../../$(PLAT_DIR)/jmptbl.i | $$(@D)/
  66. $(s)echo " LDFLAGS $@"
  67. $(q)$(ROMLIB_GEN) link-flags $< > $@
  68. clean:
  69. $(q)rm -f $(BUILD_DIR)/*
  70. -include $(BUILD_DIR)/romlib.d
  71. -include $(BUILD_DIR)/jmptbl.d