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