blob: 55f0a829a3749b4d5d954263625242bea1c1e55b [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
45# Cross tool
46CC := ${M0_CROSS_COMPILE}gcc
Chris Kayc7ea3472024-01-15 18:45:07 +000047CPP := ${M0_CROSS_COMPILE}gcc -E
Chris Kayfdb6f422024-01-15 19:55:11 +000048AR := ${M0_CROSS_COMPILE}gcc-ar
Caesar Wangb4003742016-10-12 08:10:12 +080049OC := ${M0_CROSS_COMPILE}objcopy
50OD := ${M0_CROSS_COMPILE}objdump
Caesar Wangb4003742016-10-12 08:10:12 +080051
52# NOTE: The line continuation '\' is required in the next define otherwise we
53# end up with a line-feed characer at the end of the last c filename.
54# Also bare this issue in mind if extending the list of supported filetypes.
55define SOURCES_TO_OBJS
56 $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \
57 $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1))))
58endef
59
Lin Huang00960ba2018-04-20 15:55:21 +080060SOURCES_COMMON := $(C_SOURCES_COMMON)
Caesar Wangb4003742016-10-12 08:10:12 +080061SOURCES := $(C_SOURCES)
Lin Huang00960ba2018-04-20 15:55:21 +080062SOURCES_PMU := $(C_SOURCES_PMU)
63OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON)))
Julius Werner705aeeb2016-10-31 19:18:47 -070064OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES)))
Lin Huang00960ba2018-04-20 15:55:21 +080065OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU)))
Xing Zheng93280b72016-10-26 21:25:26 +080066LINKERFILE := $(BUILD)/$(PLAT_M0).ld
Julius Werner705aeeb2016-10-31 19:18:47 -070067MAPFILE := $(BUILD)/$(PLAT_M0).map
Lin Huang00960ba2018-04-20 15:55:21 +080068MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map
Julius Werner705aeeb2016-10-31 19:18:47 -070069ELF := $(BUILD)/$(PLAT_M0).elf
Lin Huang00960ba2018-04-20 15:55:21 +080070ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf
Julius Werner705aeeb2016-10-31 19:18:47 -070071BIN := $(BUILD)/$(PLAT_M0).bin
Lin Huang00960ba2018-04-20 15:55:21 +080072BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin
Xing Zheng93280b72016-10-26 21:25:26 +080073LINKERFILE_SRC := src/$(PLAT_M0).ld.S
Caesar Wangb4003742016-10-12 08:10:12 +080074
75# Function definition related compilation
76define MAKE_C
77$(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2))))
Julius Werner844782d2016-11-03 12:25:48 -070078-include $(patsubst %.o,%.d,$(OBJ))
Caesar Wangb4003742016-10-12 08:10:12 +080079
80$(OBJ) : $(2)
81 @echo " CC $$<"
Julius Wernerf5852462017-01-30 16:13:21 -080082 $$(Q)$$(CC) $$(COMMON_FLAGS) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@
Caesar Wangb4003742016-10-12 08:10:12 +080083endef
84
85define MAKE_S
86$(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2))))
87
88$(OBJ) : $(2)
89 @echo " AS $$<"
Julius Wernerf5852462017-01-30 16:13:21 -080090 $$(Q)$$(CC) -x assembler-with-cpp $$(COMMON_FLAGS) $$(ASFLAGS) -c $$< -o $$@
Caesar Wangb4003742016-10-12 08:10:12 +080091endef
92
93define MAKE_OBJS
94 $(eval C_OBJS := $(filter %.c,$(2)))
95 $(eval REMAIN := $(filter-out %.c,$(2)))
96 $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3))))
97
98 $(eval S_OBJS := $(filter %.S,$(REMAIN)))
99 $(eval REMAIN := $(filter-out %.S,$(REMAIN)))
100 $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3))))
101
102 $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN)))
103endef
104
Lin Huang00960ba2018-04-20 15:55:21 +0800105.PHONY: all
106all: $(BIN) $(BIN_PMU)
107
108.DEFAULT_GOAL := all
Xing Zheng93280b72016-10-26 21:25:26 +0800109
110$(LINKERFILE): $(LINKERFILE_SRC)
Julius Wernerf5852462017-01-30 16:13:21 -0800111 $(CC) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $<
Xing Zheng93280b72016-10-26 21:25:26 +0800112-include $(LINKERFILE).d
Caesar Wangb4003742016-10-12 08:10:12 +0800113
Lin Huang00960ba2018-04-20 15:55:21 +0800114$(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE)
Caesar Wangb4003742016-10-12 08:10:12 +0800115 @echo " LD $@"
Lin Huang00960ba2018-04-20 15:55:21 +0800116 $(Q)$(CC) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON)
Caesar Wangb4003742016-10-12 08:10:12 +0800117
Lin Huang00960ba2018-04-20 15:55:21 +0800118%.bin : %.elf
Caesar Wangb4003742016-10-12 08:10:12 +0800119 @echo " BIN $@"
120 $(Q)$(OC) -O binary $< $@
121
Lin Huang00960ba2018-04-20 15:55:21 +0800122$(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE)
123 @echo " LD $@"
124 $(Q)$(CC) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON)
125
126$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1)))
Julius Werner705aeeb2016-10-31 19:18:47 -0700127$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1)))
Lin Huang00960ba2018-04-20 15:55:21 +0800128$(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1)))