-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpru_rules.mak
More file actions
181 lines (162 loc) · 6.88 KB
/
Copy pathpru_rules.mak
File metadata and controls
181 lines (162 loc) · 6.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Shared build settings for all PRU/RTU/TX_PRU core makefiles
#
# Before including this file, define:
# OUTPUT_NAME - base name for .out and .h outputs
# MCU_HEX_NAME - filename for MCU+ hex array (e.g. pru0_load_bin.h)
# HEX_ARRAY_PREFIX - array name prefix for hexpru (e.g. PRU0Firmware)
# MCU_HEX_PATH - full destination path for MCU+ hex array
# FILES_PATH - directories to search for source files
# COMMAND_FILES - linker command file(s)
# PRU_VERSION - silicon version (3: PRUSS, PRU-ICSS; 4: PRU_ICSSG)
# EXPECTED_DEVICE - device this firmware targets (e.g. am261x); validated
# against DEVICE from imports.mak to catch mismatches
#
# Optional: Before including this file, define to override defaults in:
# Compiler flags (CFLAGS):
# OPT_LEVEL - C code optimization: off, 0, 1, 2, 3, 4 (default: 2)
# Linker flags (LFLAGS):
# STACK_SIZE - C code stack size in bytes (default: 0x100)
# HEAP_SIZE - C code heap size in bytes (default: 0x100)
# ENTRY_POINT - Assembly code entry point (default: main)
#
# Optional: After including this file, append values to:
# INCLUDE - additional project-specific include paths
# CFLAGS - additional compiler flags
# LFLAGS - additional linker flags
# DFLAGS - project-specific compiler defines
# LIBS - project-specific libraries
# Validate DEVICE
# DEVICE from imports.mak should match EXPECTED_DEVICE declared in the
# core makefile. Fail fast here so a wrong/missing DEVICE is caught before
# the compiler silently picks the wrong device-specific headers.
VALID_DEVICES := am243x am64x am261x am263x am263px am62x
ifeq (,$(DEVICE))
$(error DEVICE is not set. Set DEVICE in imports.mak (valid values: $(VALID_DEVICES)))
endif
ifeq (,$(filter $(DEVICE),$(VALID_DEVICES)))
$(error DEVICE='$(DEVICE)' is not recognised. Update DEVICE in imports.mak (valid values: $(VALID_DEVICES)))
endif
ifneq ($(DEVICE),$(EXPECTED_DEVICE))
$(error DEVICE='$(DEVICE)' but this firmware targets $(EXPECTED_DEVICE). Update DEVICE in imports.mak)
endif
# Build outputs
GEN_DIR := generated
TARGET := $(GEN_DIR)/$(OUTPUT_NAME).out
TARGET_HEX := $(GEN_DIR)/$(OUTPUT_NAME).h
# Standard include paths for all PRU firmware
INCLUDE := \
--include_path=$(CGT_TI_PRU_PATH)/include \
--include_path=syscfg \
# Search for assembly & C source files
vpath %.asm $(FILES_PATH)
vpath %.c $(FILES_PATH)
vpath %.cmd $(FILES_PATH)
vpath %.obj $(GEN_DIR)
C_FILES := $(notdir $(foreach directory, $(FILES_PATH), $(wildcard $(directory)/*.c)))
ASM_FILES := $(notdir $(foreach directory, $(FILES_PATH), $(wildcard $(directory)/*.asm)))
# Generate an object file for every *.asm and *.c source file in FILES_PATH
OBJECTS := $(patsubst %.asm, $(GEN_DIR)/%.obj, $(notdir \
$(foreach directory, $(FILES_PATH), $(wildcard $(directory)/*.asm))))
OBJECTS += $(patsubst %.c, $(GEN_DIR)/%.obj, $(notdir \
$(foreach directory, $(FILES_PATH), $(wildcard $(directory)/*.c))))
# Compiler flags (see 'PRU Optimizing C/C++ Compiler User's Guide')
# PRU_VERSION must be set in the core's makefile
# silicon version: -v (3: PRUSS, PRU-ICSS; 4: PRU_ICSSG)
# OPT_LEVEL may be overridden in the core's makefile
# C code optimization: -O (off, 0, 1, 2, 3, 4)
OPT_LEVEL ?= 2
CFLAGS := \
-v$(PRU_VERSION) -O$(OPT_LEVEL) \
--display_error_number --diag_wrap=off --diag_warning=225 \
--asm_directory=$(GEN_DIR) --obj_directory=$(GEN_DIR) --pp_directory=$(GEN_DIR) \
-ppd -ppa -g --endian=little
# Linker flags (see 'PRU Optimizing C/C++ Compiler User's Guide')
LFLAGS := \
-m$(GEN_DIR)/$(OUTPUT_NAME).map --xml_link_info=$(GEN_DIR)/$(OUTPUT_NAME)_linkInfo.xml \
--display_error_number --diag_wrap=off --diag_warning=225 --diag_suppress=10063-D \
--warn_sections --reread_libs --ram_model
ifeq ($(C_FILES),)
# PRU firmware is assembly-only
# ENTRY_POINT may be overridden in the core's makefile
ENTRY_POINT ?= main
LFLAGS += \
--entry_point=$(ENTRY_POINT) --disable_auto_rts
else
# PRU firmware has C code
# STACK_SIZE may be overridden in the core's makefile
# HEAP_SIZE may be overridden in the core's makefile
STACK_SIZE ?= 0x100
HEAP_SIZE ?= 0x100
LFLAGS += \
--stack_size=$(STACK_SIZE) --heap_size=$(HEAP_SIZE) \
-i$(CGT_TI_PRU_PATH)/lib -i$(CGT_TI_PRU_PATH)/include --library=libc.a
endif
# Only build if tools are defined
ifeq (,$(CGT_TI_PRU_PATH))
all clean:
@echo 'CGT_TI_PRU_PATH not set. Make sure that:'
@echo ' 1) PRU_NO_CODE_TOOL_PATH points to the pru-no-code-tool repo'
@echo ' 2) imports.mak exists at PRU_NO_CODE_TOOL_PATH'
@echo ' 3) Both the pru-no-code-tool and imports.mak are set up as per'
else
# All Target
ifeq ($(wildcard ../example.syscfg),)
# If Sysconfig file is not present — define a no-op syscfg target so that
# the order-only prerequisite on the .obj rules is always satisfiable
all: $(OBJECTS) $(COMMAND_FILES)
@$(MAKE) --no-print-directory -Onone "$(TARGET)"
syscfg:
else
# If Sysconfig file is present then invoke syscfg target
all: syscfg $(OBJECTS) $(COMMAND_FILES)
@$(MAKE) --no-print-directory -Onone "$(TARGET)"
endif
# Create the output directory once; used as an order-only prerequisite below
$(GEN_DIR):
$(MKDIR) $(GEN_DIR)
# Invoke the compiler on all assembly files in vpath to create the object files
# syscfg is an order-only prerequisite: ensures SysConfig completes before
# any object file is compiled (prevents race condition under parallel make -j)
$(GEN_DIR)/%.obj: %.asm | $(GEN_DIR) syscfg
@echo 'Building file: "$<"'
@echo 'Invoking: PRU Compiler'
"$(CGT_TI_PRU_PATH)/bin/clpru" $(INCLUDE) $(CFLAGS) $(DFLAGS) --output_file=$@ $<
@echo 'Finished building: "$<"'
@echo ' '
# Invoke the compiler on all c files in vpath to create the object files
$(GEN_DIR)/%.obj: %.c | $(GEN_DIR) syscfg
@echo 'Building file: "$<"'
@echo 'Invoking: PRU Compiler'
"$(CGT_TI_PRU_PATH)/bin/clpru" $(INCLUDE) $(CFLAGS) $(DFLAGS) --output_file=$@ $<
@echo 'Finished building: "$<"'
@echo ' '
# Invoke the linker (-z flag) to make the .out file
$(TARGET): $(OBJECTS) $(COMMAND_FILES)
@echo 'Building target: "$@"'
@echo 'Invoking: PRU Linker'
"$(CGT_TI_PRU_PATH)/bin/clpru" $(CFLAGS) -z $^ $(LFLAGS) -o $(TARGET) $(LIBS)
@echo 'Finished building target: "$@"'
@echo ' '
@$(MAKE) --no-print-directory post-build
# To clean generated files
clean:
-$(RMDIR) $(GEN_DIR)
-$(RMDIR) syscfg/
ifeq ($(BUILD_MCUPLUS),y)
-$(RM) $(MCU_HEX_PATH)
endif
@echo 'Finished clean'
@echo ' '
endif
# Generate hex array
post-build:
-$(CGT_TI_PRU_PATH)/bin/hexpru --diag_wrap=off --array --array:name_prefix=$(HEX_ARRAY_PREFIX) -o $(TARGET_HEX) $(TARGET)
-$(CAT) $(PRU_NO_CODE_TOOL_PATH)/.metadata/pru_load_bin_copyright.h $(TARGET_HEX) > $(TARGET_HEX).temp
-$(MOVE) $(TARGET_HEX).temp $(TARGET_HEX)
ifeq ($(BUILD_MCUPLUS),y)
-$(COPY) $(TARGET_HEX) $(MCU_HEX_PATH)
endif
@echo ' '
.PHONY: all clean syscfg
# Include the dependencies that the compiler creates (-ppd and -ppa flags)
-include $(OBJECTS:%.obj=%.pp)