Makefile 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 = $(LIB_DIR)/libfdt.a $(LIB_DIR)/libc.a
  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. PROCESSED_JMPTBL = ../../$(PLAT_DIR)/jmptbl.i
  19. # Determine if mbedtls is needed
  20. ifneq ($(filter $(CRYPTO_SUPPORT),1 2 3),)
  21. PROCESSED_JMPTBL = $(BUILD_DIR)/jmptbl_processed.i
  22. $(shell mkdir -p $(BUILD_DIR) && cat ../../$(PLAT_DIR)/jmptbl.i ../../$(PLAT_DIR)/jmptbl_mbedtls.i > $(BUILD_DIR)/jmptbl_processed.i)
  23. LIBS += $(LIB_DIR)/libmbedtls.a
  24. endif
  25. ifneq ($(PLAT_DIR),)
  26. # Generate wrapper sources and objects
  27. WRAPPER_SOURCES = $(sort $(shell $(ROMLIB_GEN) genwrappers -b $\
  28. $(WRAPPER_DIR) --list $(PROCESSED_JMPTBL)))
  29. WRAPPER_OBJS = $(WRAPPER_SOURCES:.s=.o)
  30. endif
  31. LDFLAGS := -Wl,--gc-sections -nostdlib
  32. ifeq ($(DEBUG),1)
  33. LDFLAGS += -Wl,-Map=$(MAPFILE)
  34. endif
  35. ifeq (${ARM_ARCH_MINOR},0)
  36. ASFLAGS = -march=armv8-a
  37. else
  38. ASFLAGS = -march=armv8.${ARM_ARCH_MINOR}-a
  39. endif
  40. .PHONY: all clean distclean
  41. all: $(BUILD_DIR)/romlib.bin $(BUILD_DIR)/romlib.ldflags $(LIB_DIR)/libwrappers.a
  42. %.o: %.s | $$(@D)/
  43. $(s)echo " AS $@"
  44. $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
  45. $(BUILD_DIR)/%.o: %.s | $$(@D)/
  46. $(s)echo " AS $@"
  47. $(q)$(aarch64-as) -c $(ASFLAGS) -o $@ $<
  48. $(BUILD_DIR)/romlib.ld: romlib.ld.S | $$(@D)/
  49. $(s)echo " PP $@"
  50. $(q)$(aarch64-cpp) -E $(PPFLAGS) -o $@ romlib.ld.S
  51. $(BUILD_DIR)/romlib.elf: $(OBJS) $(BUILD_DIR)/romlib.ld | $$(@D)/
  52. $(s)echo " LD $@"
  53. $(q)$(aarch64-ld) -T $(BUILD_DIR)/romlib.ld -L$(LIB_DIR) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
  54. $(BUILD_DIR)/romlib.bin: $(BUILD_DIR)/romlib.elf | $$(@D)/
  55. $(s)echo " BIN $@"
  56. $(q)$(aarch64-oc) -O binary $(BUILD_DIR)/romlib.elf $@
  57. $(WRAPPER_DIR)/jmpvar.s: $(BUILD_DIR)/romlib.elf | $$(@D)/
  58. $(s)echo " VAR $@"
  59. $(q)$(ROMLIB_GEN) genvar --output $@ $<
  60. $(LIB_DIR)/libwrappers.a: $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS) | $$(@D)/
  61. $(s)echo " AR $@"
  62. $(q)$(aarch64-ar) -rc $@ $(WRAPPER_DIR)/jmpvar.o $(WRAPPER_OBJS)
  63. $(BUILD_DIR)/jmptbl.i: $(PROCESSED_JMPTBL) | $$(@D)/
  64. $(s)echo " PRE $@"
  65. $(q)$(ROMLIB_GEN) pre --output $@ --deps $(BUILD_DIR)/jmptbl.d $<
  66. $(WRAPPER_SOURCES) $&: $(PROCESSED_JMPTBL) | $$(@D)/
  67. $(s)echo " WRP $<"
  68. $(q)$(ROMLIB_GEN) genwrappers --bti=$(ENABLE_BTI) -b $(WRAPPER_DIR) $<
  69. $(WRAPPER_OBJS): $(WRAPPER_DIR)/%.o: $(WRAPPER_DIR)/%.s | $$(@D)/
  70. $(BUILD_DIR)/jmptbl.s: $(PROCESSED_JMPTBL) | $$(@D)/
  71. $(s)echo " TBL $@"
  72. $(q)$(ROMLIB_GEN) gentbl --output $@ --bti=$(ENABLE_BTI) $<
  73. $(BUILD_DIR)/romlib.ldflags: $(PROCESSED_JMPTBL) | $$(@D)/
  74. $(s)echo " LDFLAGS $@"
  75. $(q)$(ROMLIB_GEN) link-flags $< > $@
  76. clean:
  77. $(q)rm -f $(BUILD_DIR)/*
  78. -include $(BUILD_DIR)/romlib.d
  79. -include $(BUILD_DIR)/jmptbl.d