Makefile 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #
  2. # Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
  3. #
  4. # SPDX-License-Identifier: BSD-3-Clause
  5. #
  6. include ../../../../../make_helpers/common.mk
  7. include ../../../../../make_helpers/build_macros.mk
  8. include ../../../../../make_helpers/toolchain.mk
  9. # Build architecture
  10. ARCH := rk3399-m0
  11. # Build platform
  12. PLAT_M0 ?= rk3399m0
  13. PLAT_M0_PMU ?= rk3399m0pmu
  14. INCLUDES += -Iinclude/ \
  15. -I../../include/shared/
  16. # NOTE: Add C source files here
  17. C_SOURCES_COMMON := src/startup.c
  18. C_SOURCES := src/dram.c \
  19. src/stopwatch.c
  20. C_SOURCES_PMU := src/suspend.c
  21. # Flags definition
  22. COMMON_FLAGS := -g -mcpu=cortex-m0 -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft
  23. CFLAGS := -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common
  24. # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523
  25. CFLAGS += $(call cc_option, --param=min-pagesize=0)
  26. ASFLAGS := -Wa,--gdwarf-2 -Wa,--fatal-warnings
  27. LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none -Wl,--fatal-warnings -z noexecstack
  28. LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments)
  29. # NOTE: The line continuation '\' is required in the next define otherwise we
  30. # end up with a line-feed characer at the end of the last c filename.
  31. # Also bare this issue in mind if extending the list of supported filetypes.
  32. define SOURCES_TO_OBJS
  33. $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
  34. $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
  35. endef
  36. SOURCES_COMMON := $(C_SOURCES_COMMON)
  37. SOURCES := $(C_SOURCES)
  38. SOURCES_PMU := $(C_SOURCES_PMU)
  39. OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON)))
  40. OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES)))
  41. OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU)))
  42. LINKERFILE := $(BUILD)/$(PLAT_M0).ld
  43. MAPFILE := $(BUILD)/$(PLAT_M0).map
  44. MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map
  45. ELF := $(BUILD)/$(PLAT_M0).elf
  46. ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf
  47. BIN := $(BUILD)/$(PLAT_M0).bin
  48. BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin
  49. LINKERFILE_SRC := src/$(PLAT_M0).ld.S
  50. # Function definition related compilation
  51. define MAKE_C
  52. $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
  53. -include $(patsubst %.o,%.d,$(OBJ))
  54. $(OBJ) : $(2)
  55. $(s)echo " CC $$<"
  56. $$(q)$($(ARCH)-cc) $$(COMMON_FLAGS) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@
  57. endef
  58. define MAKE_S
  59. $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
  60. $(OBJ) : $(2)
  61. $(s)echo " AS $$<"
  62. $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(COMMON_FLAGS) $$(ASFLAGS) -c $$< -o $$@
  63. endef
  64. define MAKE_OBJS
  65. $(eval C_OBJS := $(filter %.c,$(2)))
  66. $(eval REMAIN := $(filter-out %.c,$(2)))
  67. $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
  68. $(eval S_OBJS := $(filter %.S,$(REMAIN)))
  69. $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
  70. $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
  71. $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
  72. endef
  73. .PHONY: all
  74. all: $(BIN) $(BIN_PMU)
  75. .DEFAULT_GOAL := all
  76. $(LINKERFILE): $(LINKERFILE_SRC)
  77. $(q)$($(ARCH)-cc) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $<
  78. -include $(LINKERFILE).d
  79. $(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE)
  80. $(s)echo " LD $@"
  81. $(q)$($(ARCH)-ld) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON)
  82. %.bin : %.elf
  83. $(s)echo " BIN $@"
  84. $(q)$($(ARCH)-oc) -O binary $< $@
  85. $(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE)
  86. $(s)echo " LD $@"
  87. $(q)$($(ARCH)-ld) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON)
  88. $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1)))
  89. $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1)))
  90. $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1)))