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 email them upstream to
21 # us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 # Thank you for choosing FreeEMS to run your engine!
31 PPCSDIR
= preprocessedc
32 # Set the windows/non debian path first and then overwrite
33 # with the debian one so we can grep the deb line out and
34 # end up with a working windows make file in an automated
35 # way. Additionally, please ensure you do not add any sets
36 # of three .. . in a row or the line will be missing from
37 # the windows version. Likewise sets of ### longer than 6
38 # or so are also at risk :-)
46 COPY
= $(PREFIX
)objcopy
47 DUMP
= $(PREFIX
)objdump
52 #Temporary - need to suss out. for now any H change = full recompile.
53 ASMH
= 9S12XDP512asm.s
55 GLOBALH
= freeEMS.h
9S12XDP512.h memory.h globalConstants.h globalDefines.h errorDefines.h structs.h TunableConfigs.h FixedConfigs.h
56 ISRSH
= commsISRs.h enginePositionISRs.h injectionISRs.h
58 COMMSH
= commsCore.h blockDetailsLookup.h
59 FUELH
= fuelAndIgnitionCalcs.h derivedVarsGenerator.h coreVarsGenerator.h
63 LOOKUPH
= tableLookup.h
64 LINKER
= memory.x regions.x hc9s12xdp512elfb.x
66 WMFILE
= Makefile.windows
69 # let's keep this to a bare minimum! :-)
70 HANDASMS
= flashBurn.s
72 # .c files from inc/ should be included here as deps for the parts they are relied on by!! TODO
74 ALLHEADERS
= $(GLOBALH
) $(COMMSH
) $(ISRSH
) $(UTILH
) $(FUELH
) $(MAINH
) $(INITH
) $(ISRH
) $(FLASHH
) $(LOOKUPH
)
75 ALLH
= $(patsubst %.h
,$(INCDIR
)/%.h
,$(ALLHEADERS
)) $(LINKER
) $(MFILE
) $(patsubst %.c
,$(INCDIR
)/%.c
,$(CINCS
)) $(INCDIR
)/$(ASMH
)
77 # Warning : do not include .c files from inc/ as they are included into the other C files and automatically compiled.
79 FLASHCLASSES
= FixedConfig1.c FixedConfig2.c IATTransferTable.c CHTTransferTable.c MAFTransferTable.c TestTransferTable.c
80 # 8*1k + 8*1k + 8*1k = 24k
81 FUELCLASSES
= FuelTables.c FuelTables2.c
82 TIMECLASSES
= TimingTables.c TimingTables2.c
83 TUNECLASSES
= TunableConfig.c TunableConfig2.c
85 # Code and global constants can be stored anywhere
86 SUBCLASSES
= fuelAndIgnitionCalcs.c commsCore.c blockDetailsLookup.c coreVarsGenerator.c derivedVarsGenerator.c flashWrite.c tableLookup.c interrupts.c init.c utils.c globalConstants.c
87 # ISR code that MUST be in the unpaged flash!
88 ISRCLASSES
= injectionISRs.c ignitionISRs.c enginePositionISRs.c commsISRs.c realtimeISRs.c miscISRs.c
90 CLASSES
= freeEMS.c staticInit.c main.c
$(SUBCLASSES
) $(ISRCLASSES
) $(FLASHCLASSES
) $(FUELCLASSES
) $(TIMECLASSES
) $(TUNECLASSES
)
92 PREPROCESSED
= $(patsubst %.c
,$(PPCSDIR
)/%.pp.c
,$(CLASSES
))
93 ASSEMBLIES
= $(patsubst %.c
,$(ASMDIR
)/%.s
,$(CLASSES
))
94 OBJECTS
= $(patsubst %.c
,$(OBJDIR
)/%.o
,$(CLASSES
)) $(patsubst %.s
,$(OBJDIR
)/%.o
,$(HANDASMS
))
95 DUMPS
= $(patsubst %.c
,$(OBJDIR
)/%.dmp
,$(CLASSES
)) $(patsubst %.s
,$(OBJDIR
)/%.dmp
,$(HANDASMS
))
97 S19FILE
= freeems-
$(VERSION
).s19
99 REOUT
= $(OUTDIR
)/freeems-
$(VERSION
).re
100 ELFOUT
= $(OUTDIR
)/freeems-
$(VERSION
).elf
101 DUMPOUT
= $(OUTDIR
)/freeems-
$(VERSION
).dmp
102 MAPOUT
= $(OUTDIR
)/freeems-
$(VERSION
).map
103 S19OUT
= $(OUTDIR
)/$(S19FILE
)
104 S19SAVED
= ..
/firmware
/$(S19FILE
)
105 S19ZIP
= $(S19SAVED
).zip
107 # M68hc1x GCC Options we may want : -minmax -mlong-calls
109 # http://www.gnu.org/software/m68hc11/m68hc11_gcc.html shows code size with different options used
110 # include debug info, optimise , 16 bit ints, hcs12 platform
111 GCCOPTS
= -g
-Wall
-Werror
-Winline
-O
-m68hcs12
-mshort
-ffunction-sections
-fomit-frame-pointer
-msoft-reg-count
=8 -mauto-incdec
-fsigned-char
112 # -ffunction-sections option splits out the functions such that the garbage collection can get
113 # them on a per section basis. I'm not sure, but this could be harmful to paged code so may
114 # have to review this at a later date perhaps splitting paged functions from nonpaged ones.
116 # pass to linker, link for hc12
117 LINKOPTS
= -Wl
,-defsym
,vectors_addr
=0xF710,-m
,m68hc12elfb
,-T
,hc9s12xdp512elfb.x
118 LINKOPTSGC
= -Wl
,--gc-sections
,--print-gc-sections
,-defsym
,vectors_addr
=0xF710,-m
,m68hc12elfb
,-T
,hc9s12xdp512elfb.x
119 #LINKOPTS = -Wl,--print-map,--gc-sections,--print-gc-sections,-defsym,vectors_addr=0xF710,-m,m68hc12elfb,-T,hc9s12xdp512elfb.x
120 # vectors address in the above line is the VMA address and must be short form 0xF710, not a paged address.
121 # Add this in : "--print-map," with no spaces/quotes to get a map dump when the linker fails in a confusing way.
122 # --gc-sections,--print-gc-sections, add those in to find out what isn't being used and clear up flash space
124 # If using the below option for paged flash, the ADDRESS_TYPE field in the freeEMSloader script should be updated to match.
125 # --change-section-lma .ppagePP=0xPP8000 \ (where PP = the ppage value for that page of flash) OR if using linear address per formula
126 # --only-section=.text2 --change-section-lma .text2=0x380000 \ produced error
127 # .rodata is now inside .text for convenience during load
130 COPYOPTS
= --output-target
=srec \
131 --change-section-lma .fixedconf1
+0xFD4000 \
132 --change-section-lma .fixedconf2
+0xFD4000 \
133 --change-section-lma .text1
+0xFD4000 \
134 --change-section-lma .text
+0xFEC000 \
135 --change-section-lma .data
+0xFEC000 \
136 --change-section-lma .vectors
+0xFEC000 \
137 --change-section-lma .rodata
+0xFEC000 \
138 --only-section
=.fixedconf1 \
139 --only-section
=.fixedconf2 \
140 --only-section
=.text \
141 --only-section
=.text1 \
142 --only-section
=.data \
143 --only-section
=.vectors \
144 --only-section
=.rodata \
145 --change-section-lma .ppageF8
=0xF88000 \
146 --change-section-lma .fpageF9
=0xF98000 \
147 --change-section-lma .dpageF9
=0xF9A000 \
148 --change-section-lma .ppageFE
=0xFE8000 \
149 --only-section
=.ppageF8 \
150 --only-section
=.fpageF9 \
151 --only-section
=.dpageF9 \
152 --only-section
=.ppageFE \
153 --change-section-lma .fpageFA
=0xFA8000 \
154 --change-section-lma .dpageFA
=0xFAA000 \
155 --change-section-lma .fpageFB
=0xFB8000 \
156 --change-section-lma .dpageFB1
=0xFBA000 \
157 --change-section-lma .dpageFB2
=0xFBA400 \
158 --change-section-lma .dpageFB3
=0xFBA800 \
159 --change-section-lma .dpageFB4
=0xFBAC00 \
160 --change-section-lma .dpageFB5
=0xFBB000 \
161 --change-section-lma .dpageFB6
=0xFBB400 \
162 --change-section-lma .dpageFB7
=0xFBB800 \
163 --change-section-lma .dpageFB8
=0xFBBC00 \
164 --change-section-lma .fpageFC
=0xFC8000 \
165 --change-section-lma .dpageFC
=0xFCA000 \
166 --only-section
=.dpageFA \
167 --only-section
=.fpageFA \
168 --only-section
=.dpageFB1 \
169 --only-section
=.dpageFB2 \
170 --only-section
=.dpageFB3 \
171 --only-section
=.dpageFB4 \
172 --only-section
=.dpageFB5 \
173 --only-section
=.dpageFB6 \
174 --only-section
=.dpageFB7 \
175 --only-section
=.dpageFB8 \
176 --only-section
=.fpageFB \
177 --only-section
=.dpageFC \
178 --only-section
=.fpageFC
179 # --change-section-lma .ppageFD=0xFD8000 \
180 # --change-section-lma .ppageFF=0xFF8000 \
181 # --only-section=.ppageFD \ This is left here for clarity only (equivalent to text1 but paged)
182 # --only-section=.ppageFF This is left here for clarity only (equivalent to text but paged)
183 # Changes to the above options should be reflected in memory.x and memory.h also!
184 # --only-section=.ppageE0 \
185 # --only-section=.ppageE1 \
186 # --only-section=.ppageE2 \
187 # --only-section=.ppageE3 \
188 # --only-section=.ppageE4 \
189 # --only-section=.ppageE5 \
190 # --only-section=.ppageE6 \
191 # --only-section=.ppageE7 \
192 # --only-section=.ppageE8 \
193 # --only-section=.ppageE9 \
194 # --only-section=.ppageEA \
195 # --only-section=.ppageEB \
196 # --only-section=.ppageEC \
197 # --only-section=.ppageED \
198 # --only-section=.ppageEE \
199 # --only-section=.ppageEF \
200 # --only-section=.ppageF0 \
201 # --only-section=.ppageF1 \
202 # --only-section=.ppageF2 \
203 # --only-section=.ppageF3 \
204 # --only-section=.ppageF4 \
205 # --only-section=.ppageF5 \
206 # --only-section=.ppageF6 \
207 # --only-section=.ppageF7 \
208 # --change-section-lma .ppageE0=0xE08000 \
209 # --change-section-lma .ppageE1=0xE18000 \
210 # --change-section-lma .ppageE2=0xE28000 \
211 # --change-section-lma .ppageE3=0xE38000 \
212 # --change-section-lma .ppageE4=0xE48000 \
213 # --change-section-lma .ppageE5=0xE58000 \
214 # --change-section-lma .ppageE6=0xE68000 \
215 # --change-section-lma .ppageE7=0xE78000 \
216 # --change-section-lma .ppageE8=0xE88000 \
217 # --change-section-lma .ppageE9=0xE98000 \
218 # --change-section-lma .ppageEA=0xEA8000 \
219 # --change-section-lma .ppageEB=0xEB8000 \
220 # --change-section-lma .ppageEC=0xEC8000 \
221 # --change-section-lma .ppageED=0xED8000 \
222 # --change-section-lma .ppageEE=0xEE8000 \
223 # --change-section-lma .ppageEF=0xEF8000 \
224 # --change-section-lma .ppageF0=0xF08000 \
225 # --change-section-lma .ppageF1=0xF18000 \
226 # --change-section-lma .ppageF2=0xF28000 \
227 # --change-section-lma .ppageF3=0xF38000 \
228 # --change-section-lma .ppageF4=0xF48000 \
229 # --change-section-lma .ppageF5=0xF58000 \
230 # --change-section-lma .ppageF6=0xF68000 \
231 # --change-section-lma .ppageF7=0xF78000 \
234 # do the assemblies first as its faster, then objects, then preprocessed files.
235 # the labels are there to print out the messages, the variables are the dependencies which do the work.
236 all: $(PPCSDIR
) preprocess
$(PREPROCESSED
) compile
$(ASSEMBLIES
) $(OBJDIR
) assemble
$(OBJECTS
) $(OUTDIR
) link
$(ELFOUT
) debug
$(DUMPOUT
) $(MAPOUT
) $(REOUT
) s19
$(S19OUT
)
237 fast
: $(OBJDIR
) fastcomp
$(OBJECTS
) $(OUTDIR
) link
$(ELFOUT
) s19
$(S19OUT
)
238 alldebug
: $(OBJDIR
) dumps
$(DUMPS
) $(OUTDIR
) debug
$(DUMPOUT
) $(MAPOUT
) $(REOUT
)
239 release
: save
$(S19SAVED
) makewinmake
$(WMFILE
) clean commit svnexp zipall
$(ALLZIP
) zips19
$(S19ZIP
) upload
251 ################################################################################
252 # Running the C Pre Processor... #
253 ################################################################################
255 # Generate preprocessed source files to examine
256 $(PREPROCESSED
): $(PPCSDIR
)/%.pp.c
: %.c
$(ALLH
)
257 $(GCC
) $(GCCOPTS
) -E
$< > $@
260 # traditional single stage compile
262 ################################################################################
263 # Compiling FreeEMS... #
264 ################################################################################
266 #$(ASSEMBLIES): $(ASMDIR)/%.s: $(PPCSDIR)/%.pp.c
267 #$(GCC) $(GCCOPTS) -x cpp-output -S -o $@ $<
270 # generate assembly files to examine
272 ################################################################################
273 # Compiling PPC to Assembly... #
274 ################################################################################
276 $(ASSEMBLIES
): $(ASMDIR
)/%.s
: $(PPCSDIR
)/%.pp.c
277 $(GCC
) $(GCCOPTS
) -x cpp-output
-S
-o
$@
$<
280 # generate object files to link
282 ################################################################################
283 # Assembling Object Files... #
284 ################################################################################
286 $(OBJECTS
): $(OBJDIR
)/%.o
: $(ASMDIR
)/%.s
287 $(GCC
) $(GCCOPTS
) -c
-o
$@
$<
290 # link the object files into an elf executable
292 ################################################################################
293 # Linking the Objects into an ELF... #
294 ################################################################################
296 $(ELFOUT
): $(OBJECTS
)
297 $(GCC
) $(GCCOPTS
) $(LINKOPTSGC
) -o
$(ELFOUT
) $(OBJECTS
) # ...
298 $(GCC
) $(GCCOPTS
) $(LINKOPTS
) -o
$(ELFOUT
) $(OBJECTS
)
299 # the above is to ensure no warnings, TODO find out how to stop .tramp from being collected!
301 # dump the full disassembled source with private headers
303 ################################################################################
304 # Creating Individual Dump Files... #
305 ################################################################################
307 $(DUMPS
): $(OBJDIR
)/%.dmp
: $(OBJDIR
)/%.o
308 $(DUMP
) -spSd
$< > $@
311 # dump the full disassembled source with private headers
312 # create a memory map
313 # output the readelf information
315 ################################################################################
316 # Generating Debug Files... #
317 ################################################################################
319 $(DUMPOUT
): $(ELFOUT
)
320 $(DUMP
) -spSd
$(ELFOUT
) > $(DUMPOUT
)
323 $(NM
) $(ELFOUT
) |
sort > $(MAPOUT
)
326 $(RE
) -a
-W
$(ELFOUT
) > $(REOUT
)
329 ################################################################################
330 # Building The S19 File... #
331 ################################################################################
333 # generate a loadable s19
335 $(COPY
) $(COPYOPTS
) $(ELFOUT
) $(S19OUT
)
336 $(SIZE
) -t
$(OBJECTS
)
337 echo
"Flash image size is" `echo \`cat
$(S19OUT
) | wc
-l\
` "* 16" | bc -l` "bytes..."
340 # not yet implemented!
342 ################################################################################
343 # Commiting final changes... #
344 ################################################################################
347 # not yet implemented!
349 ################################################################################
350 # Exporting from SVN... #
351 ################################################################################
354 # not yet implemented!
356 ################################################################################
357 # Uploading to SF.net... #
358 ################################################################################
362 ################################################################################
363 # Saving The Firmware... #
364 ################################################################################
366 # save a copy in firmware directory above
367 $(S19SAVED
): $(S19OUT
)
368 $(CP
) $(S19OUT
) $(S19SAVED
)
372 ################################################################################
373 # Generating Windows Makefile... #
374 ################################################################################
377 ..
/bin
/makeWinMake.bash
380 # zip that copy ready for release
382 ################################################################################
383 # Zipping The Release... #
384 ################################################################################
385 #$(S19ZIP): $(S19SAVED)
387 # $(ZIP) $(S19ZIP) $(S19SAVED)
390 # zip that copy ready for release
392 ################################################################################
393 # Zipping The Firmware... #
394 ################################################################################
395 # move this process to above the normal dirs
396 $(S19ZIP
): $(S19SAVED
)
398 $(ZIP
) $(S19ZIP
) $(S19SAVED
)
403 ################################################################################
404 # Removing generated assembly files.... #
405 ################################################################################
407 ################################################################################
408 # Removing pre-processed C output directory... #
409 ################################################################################
411 ################################################################################
412 # Removing object and dump output directory.... #
413 ################################################################################
415 ################################################################################
416 # Removing final output directory.... #
417 ################################################################################