3 # Copyright 2008 Fred Cooke
5 # This file is part of the FreeEMS project.
7 # FreeEMS software is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # FreeEMS software is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with any FreeEMS software. If not, see <http://www.gnu.org/licenses/>.
20 # We ask that if you make any changes to this file you send them upstream to us at admin@diyefi.org
22 # Thank you for choosing FreeEMS to run your engine!
30 PPCSDIR
= zpreprocessedc
31 # Set the windows/non debian path first and then overwrite
32 # with the debian one so we can grep the deb line out and
33 # end up with a working windows make file in an automated
34 # way. Additionally, please ensure you do not add any sets
35 # of three .. . in a row or the line will be missing from
36 # the windows version. Likewise sets of ### longer than 6
37 # or so are also at risk :-)
45 COPY
= $(PREFIX
)objcopy
46 DUMP
= $(PREFIX
)objdump
51 #Temporary - need to suss out. for now any H change = full recompile.
52 ASMH
= 9S12XDP512asm.s
54 GLOBALH
= freeEMS.h
9S12XDP512.h globalConstants.h globalDefines.h errorDefines.h structs.h tunables.h memory.h
55 ISRSH
= commsISRs.h enginePositionISRs.h ignitionISRs.h injectionISRs.h miscISRs.h realtimeISRs.h
57 COMMSH
= commsCore.h blockDetailsLookup.h
58 FUELH
= fuelAndIgnitionCalcs.h derivedVarsGenerator.h coreVarsGenerator.h
62 LOOKUPH
= tableLookup.h
63 LINKER
= memory.x regions.x hc9s12xdp512elfb.x
65 WMFILE
= Makefile.windows
68 # let's keep this to a bare minimum! :-)
69 HANDASMS
= flashBurn.s
71 # .c files from inc/ should be included here as deps for the parts they are relied on by!! TODO
73 ALLHEADERS
= $(GLOBALH
) $(COMMSH
) $(ISRSH
) $(UTILH
) $(FUELH
) $(MAINH
) $(INITH
) $(ISRH
) $(FLASHH
) $(LOOKUPH
)
74 ALLH
= $(patsubst %.h
,$(INCDIR
)/%.h
,$(ALLHEADERS
)) $(LINKER
) $(MFILE
) $(patsubst %.c
,$(INCDIR
)/%.c
,$(CINCS
)) $(INCDIR
)/$(ASMH
)
76 # Warning : do not include .c files from inc/ as they are included into the other C files and automatically compiled.
78 FLASHCLASSES
= FixedConfig1.c FixedConfig2.c IATTransferTable.c CHTTransferTable.c MAFTransferTable.c TestTransferTable.c
79 # 8*1k + 8*1k + 8*1k = 24k
80 FUELCLASSES
= FuelTables.c FuelTables2.c
81 TIMECLASSES
= TimingTables.c TimingTables2.c
82 TUNECLASSES
= TunableConfig.c TunableConfig2.c
84 # Code and global constants can be stored anywhere
85 SUBCLASSES
= fuelAndIgnitionCalcs.c commsCore.c blockDetailsLookup.c coreVarsGenerator.c derivedVarsGenerator.c flashWrite.c tableLookup.c interrupts.c init.c utils.c globalConstants.c
86 # ISR code that MUST be in the unpaged flash!
87 ISRCLASSES
= injectionISRs.c ignitionISRs.c enginePositionISRs.c commsISRs.c realtimeISRs.c miscISRs.c
89 CLASSES
= freeEMS.c staticInit.c main.c
$(SUBCLASSES
) $(ISRCLASSES
) $(FLASHCLASSES
) $(FUELCLASSES
) $(TIMECLASSES
) $(TUNECLASSES
)
91 PREPROCESSED
= $(patsubst %.c
,$(PPCSDIR
)/%.pp.c
,$(CLASSES
))
92 ASSEMBLIES
= $(patsubst %.c
,$(ASMDIR
)/%.s
,$(CLASSES
))
93 OBJECTS
= $(patsubst %.c
,$(OBJDIR
)/%.o
,$(CLASSES
)) $(patsubst %.s
,$(OBJDIR
)/%.o
,$(HANDASMS
))
94 DUMPS
= $(patsubst %.c
,$(OBJDIR
)/%.dmp
,$(CLASSES
)) $(patsubst %.s
,$(OBJDIR
)/%.dmp
,$(HANDASMS
))
96 S19FILE
= freeems-
$(VERSION
).s19
98 REOUT
= $(OUTDIR
)/freeems-
$(VERSION
).re
99 ELFOUT
= $(OUTDIR
)/freeems-
$(VERSION
).elf
100 DUMPOUT
= $(OUTDIR
)/freeems-
$(VERSION
).dmp
101 MAPOUT
= $(OUTDIR
)/freeems-
$(VERSION
).map
102 S19OUT
= $(OUTDIR
)/$(S19FILE
)
103 S19SAVED
= ..
/firmware
/$(S19FILE
)
104 S19ZIP
= $(S19SAVED
).zip
106 # M68hc1x GCC Options we may want : -minmax -mlong-calls
108 # http://www.gnu.org/software/m68hc11/m68hc11_gcc.html shows code size with different options used
109 # include debug info, optimise , 16 bit ints, hcs12 platform
110 GCCOPTS
= -g
-Wall
-Werror
-Winline
-O
-m68hcs12
-mshort
-ffunction-sections
-fomit-frame-pointer
-msoft-reg-count
=8 -mauto-incdec
-fsigned-char
111 # -ffunction-sections option splits out the functions such that the garbage collection can get
112 # them on a per section basis. I'm not sure, but this could be harmful to paged code so may
113 # have to review this at a later date perhaps splitting paged functions from nonpaged ones.
115 # pass to linker, link for hc12
116 LINKOPTS
= -Wl
,-defsym
,vectors_addr
=0xF710,-m
,m68hc12elfb
,-T
,hc9s12xdp512elfb.x
117 LINKOPTSGC
= -Wl
,--gc-sections
,--print-gc-sections
,-defsym
,vectors_addr
=0xF710,-m
,m68hc12elfb
,-T
,hc9s12xdp512elfb.x
118 #LINKOPTS = -Wl,--print-map,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
119 # vectors address in the above line is the VMA address and must be short form 0xF710, not a paged address.
120 # Add this in : "--print-map," with no spaces/quotes to get a map dump when the linker fails in a confusing way.
121 # --gc-sections,--print-gc-sections, add those in to find out what isn't being used and clear up flash space
123 # If using the below option for paged flash, the ADDRESS_TYPE field in the freeEMSloader script should be updated to match.
124 # --change-section-lma .ppagePP=0xPP8000 \ (where PP = the ppage value for that page of flash) OR if using linear address per formula
125 # --only-section=.text2 --change-section-lma .text2=0x380000 \ produced error
126 # .rodata is now inside .text for convenience during load
129 COPYOPTS
= --output-target
=srec \
130 --change-section-lma .fixedconf1
+0xFD4000 \
131 --change-section-lma .fixedconf2
+0xFD4000 \
132 --change-section-lma .text1
+0xFD4000 \
133 --change-section-lma .text
+0xFEC000 \
134 --change-section-lma .data
+0xFEC000 \
135 --change-section-lma .vectors
+0xFEC000 \
136 --change-section-lma .rodata
+0xFEC000 \
137 --only-section
=.fixedconf1 \
138 --only-section
=.fixedconf2 \
139 --only-section
=.text \
140 --only-section
=.text1 \
141 --only-section
=.data \
142 --only-section
=.vectors \
143 --only-section
=.rodata \
144 --change-section-lma .ppageF8
=0xF88000 \
145 --change-section-lma .fpageF9
=0xF98000 \
146 --change-section-lma .dpageF9
=0xF9A000 \
147 --change-section-lma .ppageFE
=0xFE8000 \
148 --only-section
=.ppageF8 \
149 --only-section
=.fpageF9 \
150 --only-section
=.dpageF9 \
151 --only-section
=.ppageFE \
152 --change-section-lma .fpageFA
=0xFA8000 \
153 --change-section-lma .dpageFA
=0xFAA000 \
154 --change-section-lma .fpageFB
=0xFB8000 \
155 --change-section-lma .dpageFB1
=0xFBA000 \
156 --change-section-lma .dpageFB2
=0xFBA400 \
157 --change-section-lma .dpageFB3
=0xFBA800 \
158 --change-section-lma .dpageFB4
=0xFBAC00 \
159 --change-section-lma .dpageFB5
=0xFBB000 \
160 --change-section-lma .dpageFB6
=0xFBB400 \
161 --change-section-lma .dpageFB7
=0xFBB800 \
162 --change-section-lma .dpageFB8
=0xFBBC00 \
163 --change-section-lma .fpageFC
=0xFC8000 \
164 --change-section-lma .dpageFC
=0xFCA000 \
165 --only-section
=.dpageFA \
166 --only-section
=.fpageFA \
167 --only-section
=.dpageFB1 \
168 --only-section
=.dpageFB2 \
169 --only-section
=.dpageFB3 \
170 --only-section
=.dpageFB4 \
171 --only-section
=.dpageFB5 \
172 --only-section
=.dpageFB6 \
173 --only-section
=.dpageFB7 \
174 --only-section
=.dpageFB8 \
175 --only-section
=.fpageFB \
176 --only-section
=.dpageFC \
177 --only-section
=.fpageFC
178 # --change-section-lma .ppageFD=0xFD8000 \
179 # --change-section-lma .ppageFF=0xFF8000 \
180 # --only-section=.ppageFD \ This is left here for clarity only (equivalent to text1 but paged)
181 # --only-section=.ppageFF This is left here for clarity only (equivalent to text but paged)
182 # Changes to the above options should be reflected in memory.x and memory.h also!
183 # --only-section=.ppageE0 \
184 # --only-section=.ppageE1 \
185 # --only-section=.ppageE2 \
186 # --only-section=.ppageE3 \
187 # --only-section=.ppageE4 \
188 # --only-section=.ppageE5 \
189 # --only-section=.ppageE6 \
190 # --only-section=.ppageE7 \
191 # --only-section=.ppageE8 \
192 # --only-section=.ppageE9 \
193 # --only-section=.ppageEA \
194 # --only-section=.ppageEB \
195 # --only-section=.ppageEC \
196 # --only-section=.ppageED \
197 # --only-section=.ppageEE \
198 # --only-section=.ppageEF \
199 # --only-section=.ppageF0 \
200 # --only-section=.ppageF1 \
201 # --only-section=.ppageF2 \
202 # --only-section=.ppageF3 \
203 # --only-section=.ppageF4 \
204 # --only-section=.ppageF5 \
205 # --only-section=.ppageF6 \
206 # --only-section=.ppageF7 \
207 # --change-section-lma .ppageE0=0xE08000 \
208 # --change-section-lma .ppageE1=0xE18000 \
209 # --change-section-lma .ppageE2=0xE28000 \
210 # --change-section-lma .ppageE3=0xE38000 \
211 # --change-section-lma .ppageE4=0xE48000 \
212 # --change-section-lma .ppageE5=0xE58000 \
213 # --change-section-lma .ppageE6=0xE68000 \
214 # --change-section-lma .ppageE7=0xE78000 \
215 # --change-section-lma .ppageE8=0xE88000 \
216 # --change-section-lma .ppageE9=0xE98000 \
217 # --change-section-lma .ppageEA=0xEA8000 \
218 # --change-section-lma .ppageEB=0xEB8000 \
219 # --change-section-lma .ppageEC=0xEC8000 \
220 # --change-section-lma .ppageED=0xED8000 \
221 # --change-section-lma .ppageEE=0xEE8000 \
222 # --change-section-lma .ppageEF=0xEF8000 \
223 # --change-section-lma .ppageF0=0xF08000 \
224 # --change-section-lma .ppageF1=0xF18000 \
225 # --change-section-lma .ppageF2=0xF28000 \
226 # --change-section-lma .ppageF3=0xF38000 \
227 # --change-section-lma .ppageF4=0xF48000 \
228 # --change-section-lma .ppageF5=0xF58000 \
229 # --change-section-lma .ppageF6=0xF68000 \
230 # --change-section-lma .ppageF7=0xF78000 \
233 # do the assemblies first as its faster, then objects, then preprocessed files.
234 # the labels are there to print out the messages, the variables are the dependencies which do the work.
235 all: $(PPCSDIR
) preprocess
$(PREPROCESSED
) compile
$(ASSEMBLIES
) $(OBJDIR
) assemble
$(OBJECTS
) $(OUTDIR
) link
$(ELFOUT
) debug
$(DUMPOUT
) $(MAPOUT
) $(REOUT
) s19
$(S19OUT
)
236 fast
: $(OBJDIR
) fastcomp
$(OBJECTS
) $(OUTDIR
) link
$(ELFOUT
) s19
$(S19OUT
)
237 alldebug
: $(OBJDIR
) dumps
$(DUMPS
) $(OUTDIR
) debug
$(DUMPOUT
) $(MAPOUT
) $(REOUT
)
238 release
: save
$(S19SAVED
) makewinmake
$(WMFILE
) clean commit svnexp zipall
$(ALLZIP
) zips19
$(S19ZIP
) upload
250 ################################################################################
251 # Running the C Pre Processor... #
252 ################################################################################
254 # Generate preprocessed source files to examine
255 $(PREPROCESSED
): $(PPCSDIR
)/%.pp.c
: %.c
$(ALLH
)
256 $(GCC
) $(GCCOPTS
) -E
$< > $@
259 # traditional single stage compile
261 ################################################################################
262 # Compiling FreeEMS... #
263 ################################################################################
265 #$(ASSEMBLIES): $(ASMDIR)/%.s: $(PPCSDIR)/%.pp.c
266 #$(GCC) $(GCCOPTS) -x cpp-output -S -o $@ $<
269 # generate assembly files to examine
271 ################################################################################
272 # Compiling PPC to Assembly... #
273 ################################################################################
275 $(ASSEMBLIES
): $(ASMDIR
)/%.s
: $(PPCSDIR
)/%.pp.c
276 $(GCC
) $(GCCOPTS
) -x cpp-output
-S
-o
$@
$<
279 # generate object files to link
281 ################################################################################
282 # Assembling Object Files... #
283 ################################################################################
285 $(OBJECTS
): $(OBJDIR
)/%.o
: $(ASMDIR
)/%.s
286 $(GCC
) $(GCCOPTS
) -c
-o
$@
$<
289 # link the object files into an elf executable
291 ################################################################################
292 # Linking the Objects into an ELF... #
293 ################################################################################
295 $(ELFOUT
): $(OBJECTS
)
296 $(GCC
) $(GCCOPTS
) $(LINKOPTSGC
) -o
$(ELFOUT
) $(OBJECTS
) # ...
297 $(GCC
) $(GCCOPTS
) $(LINKOPTS
) -o
$(ELFOUT
) $(OBJECTS
)
298 # the above is to ensure no warnings, TODO find out how to stop .tramp from being collected!
300 # dump the full disassembled source with private headers
302 ################################################################################
303 # Creating Individual Dump Files... #
304 ################################################################################
306 $(DUMPS
): $(OBJDIR
)/%.dmp
: $(OBJDIR
)/%.o
307 $(DUMP
) -spSd
$< > $@
310 # dump the full disassembled source with private headers
311 # create a memory map
312 # output the readelf information
314 ################################################################################
315 # Generating Debug Files... #
316 ################################################################################
318 $(DUMPOUT
): $(ELFOUT
)
319 $(DUMP
) -spSd
$(ELFOUT
) > $(DUMPOUT
)
322 $(NM
) $(ELFOUT
) |
sort > $(MAPOUT
)
325 $(RE
) -a
-W
$(ELFOUT
) > $(REOUT
)
328 ################################################################################
329 # Building The S19 File... #
330 ################################################################################
332 # generate a loadable s19
334 $(COPY
) $(COPYOPTS
) $(ELFOUT
) $(S19OUT
)
335 $(SIZE
) -t
$(OBJECTS
)
336 echo
"Flash image size is" `echo \`cat
$(S19OUT
) | wc
-l\
` "* 16" | bc -l` "bytes..."
339 # not yet implemented!
341 ################################################################################
342 # Commiting final changes... #
343 ################################################################################
346 # not yet implemented!
348 ################################################################################
349 # Exporting from SVN... #
350 ################################################################################
353 # not yet implemented!
355 ################################################################################
356 # Uploading to SF.net... #
357 ################################################################################
361 ################################################################################
362 # Saving The Firmware... #
363 ################################################################################
365 # save a copy in firmware directory above
366 $(S19SAVED
): $(S19OUT
)
367 $(CP
) $(S19OUT
) $(S19SAVED
)
371 ################################################################################
372 # Generating Windows Makefile... #
373 ################################################################################
376 ..
/bin
/makeWinMake.bash
379 # zip that copy ready for release
381 ################################################################################
382 # Zipping The Release... #
383 ################################################################################
384 #$(S19ZIP): $(S19SAVED)
386 # $(ZIP) $(S19ZIP) $(S19SAVED)
389 # zip that copy ready for release
391 ################################################################################
392 # Zipping The Firmware... #
393 ################################################################################
394 # move this process to above the normal dirs
395 $(S19ZIP
): $(S19SAVED
)
397 $(ZIP
) $(S19ZIP
) $(S19SAVED
)
402 ################################################################################
403 # Removing generated pre-processed C files.... #
404 ################################################################################
405 $(RM
) $(PREPROCESSED
)
407 ################################################################################
408 # Removing generated assembly files.... #
409 ################################################################################
411 ################################################################################
412 # Removing object files.... #
413 ################################################################################
415 ################################################################################
416 # Removing individual object dump files.... #
417 ################################################################################
420 ################################################################################
421 # Removing final output files.... #
422 ################################################################################