Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 1 | # |
Chris Kay | c7ea347 | 2024-01-15 18:45:07 +0000 | [diff] [blame] | 2 | # Copyright (c) 2016-2024, Arm Limited and Contributors. All rights reserved. |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 3 | # |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | # SPDX-License-Identifier: BSD-3-Clause |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 5 | # |
| 6 | |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 7 | include ../../../../../make_helpers/common.mk |
Quentin Schulz | 2b69e80 | 2024-10-31 16:38:25 +0100 | [diff] [blame] | 8 | include ../../../../../make_helpers/build_macros.mk |
Chris Kay | c8a47ba | 2023-10-20 09:17:33 +0000 | [diff] [blame] | 9 | include ../../../../../make_helpers/toolchain.mk |
| 10 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 11 | # Build architecture |
Quentin Schulz | 7f8f27d | 2024-10-31 16:32:23 +0100 | [diff] [blame] | 12 | ARCH := rk3399-m0 |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 13 | |
| 14 | # Build platform |
| 15 | PLAT_M0 ?= rk3399m0 |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 16 | PLAT_M0_PMU ?= rk3399m0pmu |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 17 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 18 | .SUFFIXES: |
| 19 | |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 20 | INCLUDES += -Iinclude/ \ |
| 21 | -I../../include/shared/ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 22 | |
| 23 | # NOTE: Add C source files here |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 24 | C_SOURCES_COMMON := src/startup.c |
| 25 | C_SOURCES := src/dram.c \ |
Lin Huang | e7c2422 | 2016-11-30 16:57:08 +0800 | [diff] [blame] | 26 | src/stopwatch.c |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 27 | C_SOURCES_PMU := src/suspend.c |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 28 | |
| 29 | # Flags definition |
Quentin Schulz | 7f8f27d | 2024-10-31 16:32:23 +0100 | [diff] [blame] | 30 | COMMON_FLAGS := -g -mcpu=cortex-m0 -mthumb -Wall -O3 -nostdlib -mfloat-abi=soft |
Julius Werner | f585246 | 2017-01-30 16:13:21 -0800 | [diff] [blame] | 31 | CFLAGS := -ffunction-sections -fdata-sections -fomit-frame-pointer -fno-common |
Quentin Schulz | 2b69e80 | 2024-10-31 16:38:25 +0100 | [diff] [blame] | 32 | # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105523 |
| 33 | CFLAGS += $(call cc_option, --param=min-pagesize=0) |
Quentin Schulz | 4e5c9a1 | 2024-10-31 16:55:25 +0100 | [diff] [blame^] | 34 | ASFLAGS := -Wa,--gdwarf-2 -Wa,--fatal-warnings |
| 35 | LDFLAGS := -Wl,--gc-sections -Wl,--build-id=none -Wl,--fatal-warnings -z noexecstack |
Quentin Schulz | c77f83f | 2024-10-31 16:43:16 +0100 | [diff] [blame] | 36 | LDFLAGS += $(call ld_option,-Xlinker --no-warn-rwx-segments) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 37 | |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 38 | # NOTE: The line continuation '\' is required in the next define otherwise we |
| 39 | # end up with a line-feed characer at the end of the last c filename. |
| 40 | # Also bare this issue in mind if extending the list of supported filetypes. |
| 41 | define SOURCES_TO_OBJS |
| 42 | $(notdir $(patsubst %.c,%.o,$(filter %.c,$(1)))) \ |
| 43 | $(notdir $(patsubst %.S,%.o,$(filter %.S,$(1)))) |
| 44 | endef |
| 45 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 46 | SOURCES_COMMON := $(C_SOURCES_COMMON) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 47 | SOURCES := $(C_SOURCES) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 48 | SOURCES_PMU := $(C_SOURCES_PMU) |
| 49 | OBJS_COMMON := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_COMMON))) |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 50 | OBJS := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES))) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 51 | OBJS_PMU := $(addprefix $(BUILD)/,$(call SOURCES_TO_OBJS,$(SOURCES_PMU))) |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 52 | LINKERFILE := $(BUILD)/$(PLAT_M0).ld |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 53 | MAPFILE := $(BUILD)/$(PLAT_M0).map |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 54 | MAPFILE_PMU := $(BUILD)/$(PLAT_M0_PMU).map |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 55 | ELF := $(BUILD)/$(PLAT_M0).elf |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 56 | ELF_PMU := $(BUILD)/$(PLAT_M0_PMU).elf |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 57 | BIN := $(BUILD)/$(PLAT_M0).bin |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 58 | BIN_PMU := $(BUILD)/$(PLAT_M0_PMU).bin |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 59 | LINKERFILE_SRC := src/$(PLAT_M0).ld.S |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 60 | |
| 61 | # Function definition related compilation |
| 62 | define MAKE_C |
| 63 | $(eval OBJ := $(1)/$(patsubst %.c,%.o,$(notdir $(2)))) |
Julius Werner | 844782d | 2016-11-03 12:25:48 -0700 | [diff] [blame] | 64 | -include $(patsubst %.o,%.d,$(OBJ)) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 65 | |
| 66 | $(OBJ) : $(2) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 67 | $(s)echo " CC $$<" |
Quentin Schulz | 7f8f27d | 2024-10-31 16:32:23 +0100 | [diff] [blame] | 68 | $$(q)$($(ARCH)-cc) $$(COMMON_FLAGS) $$(CFLAGS) $$(INCLUDES) -MMD -MT $$@ -c $$< -o $$@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 69 | endef |
| 70 | |
| 71 | define MAKE_S |
| 72 | $(eval OBJ := $(1)/$(patsubst %.S,%.o,$(notdir $(2)))) |
| 73 | |
| 74 | $(OBJ) : $(2) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 75 | $(s)echo " AS $$<" |
Quentin Schulz | e235d8d | 2024-10-31 16:35:00 +0100 | [diff] [blame] | 76 | $$(q)$($(ARCH)-as) -x assembler-with-cpp $$(COMMON_FLAGS) $$(ASFLAGS) -c $$< -o $$@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 77 | endef |
| 78 | |
| 79 | define MAKE_OBJS |
| 80 | $(eval C_OBJS := $(filter %.c,$(2))) |
| 81 | $(eval REMAIN := $(filter-out %.c,$(2))) |
| 82 | $(eval $(foreach obj,$(C_OBJS),$(call MAKE_C,$(1),$(obj),$(3)))) |
| 83 | |
| 84 | $(eval S_OBJS := $(filter %.S,$(REMAIN))) |
| 85 | $(eval REMAIN := $(filter-out %.S,$(REMAIN))) |
| 86 | $(eval $(foreach obj,$(S_OBJS),$(call MAKE_S,$(1),$(obj),$(3)))) |
| 87 | |
| 88 | $(and $(REMAIN),$(error Unexpected source files present: $(REMAIN))) |
| 89 | endef |
| 90 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 91 | .PHONY: all |
| 92 | all: $(BIN) $(BIN_PMU) |
| 93 | |
| 94 | .DEFAULT_GOAL := all |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 95 | |
| 96 | $(LINKERFILE): $(LINKERFILE_SRC) |
Quentin Schulz | 7f8f27d | 2024-10-31 16:32:23 +0100 | [diff] [blame] | 97 | $($(ARCH)-cc) $(COMMON_FLAGS) $(INCLUDES) -P -E -D__LINKER__ -MMD -MF $@.d -MT $@ -o $@ $< |
Xing Zheng | 93280b7 | 2016-10-26 21:25:26 +0800 | [diff] [blame] | 98 | -include $(LINKERFILE).d |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 99 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 100 | $(ELF) : $(OBJS) $(OBJS_COMMON) $(LINKERFILE) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 101 | $(s)echo " LD $@" |
Quentin Schulz | e235d8d | 2024-10-31 16:35:00 +0100 | [diff] [blame] | 102 | $(q)$($(ARCH)-ld) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE) -Wl,-T$(LINKERFILE) $(OBJS) $(OBJS_COMMON) |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 103 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 104 | %.bin : %.elf |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 105 | $(s)echo " BIN $@" |
Quentin Schulz | 7f8f27d | 2024-10-31 16:32:23 +0100 | [diff] [blame] | 106 | $(q)$($(ARCH)-oc) -O binary $< $@ |
Caesar Wang | b400374 | 2016-10-12 08:10:12 +0800 | [diff] [blame] | 107 | |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 108 | $(ELF_PMU) : $(OBJS_COMMON) $(OBJS_PMU) $(LINKERFILE) |
Chris Kay | 1870c72 | 2024-05-02 17:52:37 +0000 | [diff] [blame] | 109 | $(s)echo " LD $@" |
Quentin Schulz | e235d8d | 2024-10-31 16:35:00 +0100 | [diff] [blame] | 110 | $(q)$($(ARCH)-ld) -o $@ $(COMMON_FLAGS) $(LDFLAGS) -Wl,-Map=$(MAPFILE_PMU) -Wl,-T$(LINKERFILE) $(OBJS_PMU) $(OBJS_COMMON) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 111 | |
| 112 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_COMMON),$(1))) |
Julius Werner | 705aeeb | 2016-10-31 19:18:47 -0700 | [diff] [blame] | 113 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES),$(1))) |
Lin Huang | 00960ba | 2018-04-20 15:55:21 +0800 | [diff] [blame] | 114 | $(eval $(call MAKE_OBJS,$(BUILD),$(SOURCES_PMU),$(1))) |