Makefile 3.5 KB

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