blob: 2abcc18ba7c4adbecacb53bbeda7472d1921ae30 [file] [log] [blame]
Caesar Wangb4003742016-10-12 08:10:12 +08001#
Chris Kayc7ea3472024-01-15 18:45:07 +00002# Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved.
Caesar Wangb4003742016-10-12 08:10:12 +08003#
dp-armfa3cf0b2017-05-03 09:38:09 +01004# SPDX-License-Identifier: BSD-3-Clause
Caesar Wangb4003742016-10-12 08:10:12 +08005#
6
Chris Kayc8a47ba2023-10-20 09:17:33 +00007toolchains := rk3399-m0
8
9include ../../../../../make_helpers/toolchain.mk
10
Caesar Wangb4003742016-10-12 08:10:12 +080011# Cross Compile
12M0_CROSS_COMPILE ?= arm-none-eabi-
13
14# Build architecture
15ARCH := cortex-m0
16
17# Build platform
18PLAT_M0 ?= rk3399m0
Lin Huang00960ba2018-04-20 15:55:21 +080019PLAT_M0_PMU ?= rk3399m0pmu
Caesar Wangb4003742016-10-12 08:10:12 +080020
21ifeq (${V},0)
22 Q=@
Caesar Wangb4003742016-10-12 08:10:12 +080023else
24 Q=
25endif
26export Q
27
Caesar Wangb4003742016-10-12 08:10:12 +080028.SUFFIXES:
29
Xing Zheng93280b72016-10-26 21:25:26 +080030INCLUDES += -Iinclude/ \
31 -I../../include/shared/
Caesar Wangb4003742016-10-12 08:10:12 +080032
33# NOTE: Add C source files here
Lin Huang00960ba2018-04-20 15:55:21 +080034C_SOURCES_COMMON := src/startup.c
35C_SOURCES := src/dram.c \
Lin Huange7c24222016-11-30 16:57:08 +080036 src/stopwatch.c
Lin Huang00960ba2018-04-20 15:55:21 +080037C_SOURCES_PMU := src/suspend.c
Caesar Wangb4003742016-10-12 08:10:12 +080038
39# Flags definition
Julius Wernerf5852462017-01-30 16:13:21 -080040COMMON_FLAGS := -g -mcpu=$(ARCH) -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft
41CFLAGS := -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common
42ASFLAGS := -Wa,--gdwarf-2
43LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none
Caesar Wangb4003742016-10-12 08:10:12 +080044
Caesar Wangb4003742016-10-12 08:10:12 +080045# NOTE: The line continuation '\' is required in the next define otherwise we
46# end up with a line-feed characer at the end of the last c filename.
47# Also bare this issue in mind if extending the list of supported filetypes.
48define SOURCES_TO_OBJS
49 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
50 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
51endef
52
Lin Huang00960ba2018-04-20 15:55:21 +080053SOURCES_COMMON := $(C_SOURCES_COMMON)
Caesar Wangb4003742016-10-12 08:10:12 +080054SOURCES := $(C_SOURCES)
Lin Huang00960ba2018-04-20 15:55:21 +080055SOURCES_PMU := $(C_SOURCES_PMU)
56OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON)))
Julius Werner705aeeb2016-10-31 19:18:47 -070057OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES)))
Lin Huang00960ba2018-04-20 15:55:21 +080058OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU)))
Xing Zheng93280b72016-10-26 21:25:26 +080059LINKERFILE := $(BUILD)/$(PLAT_M0).ld
Julius Werner705aeeb2016-10-31 19:18:47 -070060MAPFILE := $(BUILD)/$(PLAT_M0).map
Lin Huang00960ba2018-04-20 15:55:21 +080061MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map
Julius Werner705aeeb2016-10-31 19:18:47 -070062ELF := $(BUILD)/$(PLAT_M0).elf
Lin Huang00960ba2018-04-20 15:55:21 +080063ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf
Julius Werner705aeeb2016-10-31 19:18:47 -070064BIN := $(BUILD)/$(PLAT_M0).bin
Lin Huang00960ba2018-04-20 15:55:21 +080065BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin
Xing Zheng93280b72016-10-26 21:25:26 +080066LINKERFILE_SRC := src/$(PLAT_M0).ld.S
Caesar Wangb4003742016-10-12 08:10:12 +080067
68# Function definition related compilation
69define MAKE_C
70$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Julius Werner844782d2016-11-03 12:25:48 -070071-include $(patsubst %.o,%.d,$(OBJ))
Caesar Wangb4003742016-10-12 08:10:12 +080072
73$(OBJ) : $(2)
74 @echo " CC $$<"
Chris Kay523e8642023-12-04 12:03:51 +000075 $$(Q)$(rk3399-m0-cc) $$(COMMON_FLAGS) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@
Caesar Wangb4003742016-10-12 08:10:12 +080076endef
77
78define MAKE_S
79$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
80
81$(OBJ) : $(2)
82 @echo " AS $$<"
Chris Kay523e8642023-12-04 12:03:51 +000083 $$(Q)$(rk3399-m0-cc) -x assembler-with-cpp $$(COMMON_FLAGS) $$(ASFLAGS) -c $$< -o $$@
Caesar Wangb4003742016-10-12 08:10:12 +080084endef
85
86define MAKE_OBJS
87 $(eval C_OBJS := $(filter %.c,$(2)))
88 $(eval REMAIN := $(filter-out %.c,$(2)))
89 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
90
91 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
92 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
93 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
94
95 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
96endef
97
Lin Huang00960ba2018-04-20 15:55:21 +080098.PHONY: all
99all: $(BIN) $(BIN_PMU)
100
101.DEFAULT_GOAL := all
Xing Zheng93280b72016-10-26 21:25:26 +0800102
103$(LINKERFILE): $(LINKERFILE_SRC)
Chris Kay523e8642023-12-04 12:03:51 +0000104 $(rk3399-m0-cc) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $<
Xing Zheng93280b72016-10-26 21:25:26 +0800105-include $(LINKERFILE).d
Caesar Wangb4003742016-10-12 08:10:12 +0800106
Lin Huang00960ba2018-04-20 15:55:21 +0800107$(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE)
Caesar Wangb4003742016-10-12 08:10:12 +0800108 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +0000109 $(Q)$(rk3399-m0-cc) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON)
Caesar Wangb4003742016-10-12 08:10:12 +0800110
Lin Huang00960ba2018-04-20 15:55:21 +0800111%.bin : %.elf
Caesar Wangb4003742016-10-12 08:10:12 +0800112 @echo " BIN $@"
Chris Kay523e8642023-12-04 12:03:51 +0000113 $(Q)$(rk3399-m0-oc) -O binary $< $@
Caesar Wangb4003742016-10-12 08:10:12 +0800114
Lin Huang00960ba2018-04-20 15:55:21 +0800115$(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE)
116 @echo " LD $@"
Chris Kay523e8642023-12-04 12:03:51 +0000117 $(Q)$(rk3399-m0-cc) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON)
Lin Huang00960ba2018-04-20 15:55:21 +0800118
119$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1)))
Julius Werner705aeeb2016-10-31 19:18:47 -0700120$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1)))
Lin Huang00960ba2018-04-20 15:55:21 +0800121$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1)))