]>
Commit | Line | Data |
---|---|---|
3608c106 UH |
1 | # common make targets for compiling fx2 firmware |
2 | # | |
3 | # In your Makefile, define: | |
4 | # SOURCES: list of c files to compile | |
5 | # A51_SOURCES: list of any a51 files. | |
6 | # DEPS: list of any depedancies (like auto-generated header files) that need | |
7 | # generated prior to compiling. You must provide the target definition | |
8 | # for any DEPS you define. | |
9 | # BASENAME: name of your firmware file, i.e., myfirmware, but not myfirmware.c | |
10 | # | |
11 | # Leave these alone or redefine as necessary to customize firmware. | |
12 | # (Redefine after including this makefile) | |
13 | # VID vendor id | |
14 | # PID product id | |
15 | # LIBS optional additional libraries to link with the firmware. | |
16 | # SDCC build/link options | |
17 | # CODE_SIZE: Default --code-size 0x3c00 | |
18 | # XRAM_SIZE: Default --xram-size 0x0200 | |
19 | # XRAM_LOC: Default --xram-loc 0x3c00 | |
20 | # BUILDDIR: build directory (default build) | |
21 | # These two can be changed to be blank if no device descriptor is being used. | |
22 | # DSCR_AREA: Default -Wl"-b DSCR_AREA=0x3e00" | |
23 | # INT2JT: Default -Wl"-b INT2JT=0x3f00" | |
24 | # | |
25 | # Provided targets: | |
26 | # | |
27 | # default target: creates $(BASENAME).ihx | |
28 | # bix: creates $(BASENAME).bix | |
29 | # iic: creates $(BASENAME).iic | |
30 | # load: uses fx2load to load firmware.bix onto the development board | |
31 | # (You can customize VID/PID if you need to load the firmware onto a device that has different vendor and product id | |
32 | # The default is 0x04b4, 0x8613 | |
33 | # clean: delete all the temp files. | |
34 | # | |
35 | # | |
36 | # | |
37 | ||
d1bee53d | 38 | # The sdcc 8051 assembler binary has/had different names. |
cd13b02d | 39 | ifneq ($(shell which sdas8051 2>/dev/null),) |
d1bee53d UH |
40 | # Newer sdcc, Debian / Ubuntu |
41 | SDAS8051 = sdas8051 | |
42 | endif | |
cd13b02d | 43 | ifneq ($(shell which sdcc-sdas8051 2>/dev/null),) |
d1bee53d UH |
44 | # Newer sdcc, Fedora |
45 | SDAS8051 = sdcc-sdas8051 | |
46 | endif | |
cd13b02d | 47 | ifneq ($(shell which asx8051 2>/dev/null),) |
d1bee53d UH |
48 | # Older sdcc |
49 | SDAS8051 = asx8051 | |
50 | endif | |
51 | ||
3608c106 UH |
52 | VID?=0x04b4 |
53 | PID?=0x8613 | |
54 | ||
55 | DSCR_AREA?=-Wl"-b DSCR_AREA=0x3e00" | |
56 | INT2JT?=-Wl"-b INT2JT=0x3f00" | |
57 | CODE_SIZE?=--code-size 0x3c00 | |
58 | XRAM_SIZE?=--xram-size 0x0200 | |
59 | XRAM_LOC?=--xram-loc 0x3c00 | |
60 | BUILDDIR?=build | |
61 | ||
62 | FX2LIBDIR?=$(dir $(lastword $(MAKEFILE_LIST)))../ | |
63 | ||
64 | RELS=$(addprefix $(BUILDDIR)/, $(addsuffix .rel, $(notdir $(basename $(SOURCES) $(A51_SOURCES))))) | |
65 | # these are pretty good settings for most firmwares. | |
66 | # Have to be careful with memory locations for | |
67 | # firmwares that require more xram etc. | |
68 | CC = sdcc -mmcs51 \ | |
69 | $(SDCCFLAGS) \ | |
70 | $(CODE_SIZE) \ | |
71 | $(XRAM_SIZE) \ | |
72 | $(XRAM_LOC) \ | |
73 | $(DSCR_AREA) \ | |
74 | $(INT2JT) | |
75 | ||
76 | ||
77 | .PHONY: ihx iic bix load clean clean-all | |
78 | ||
79 | ||
80 | ihx: $(BUILDDIR)/$(BASENAME).ihx | |
81 | bix: $(BUILDDIR)/$(BASENAME).bix | |
82 | iic: $(BUILDDIR)/$(BASENAME).iic | |
83 | ||
84 | $(FX2LIBDIR)/lib/fx2.lib: $(FX2LIBDIR)/lib/*.c $(FX2LIBDIR)/lib/*.a51 | |
4836f792 | 85 | $(MAKE) -C $(FX2LIBDIR)/lib |
3608c106 UH |
86 | |
87 | $(BUILDDIR): | |
88 | mkdir -p $(BUILDDIR) | |
89 | ||
90 | $(BUILDDIR)/$(BASENAME).ihx: $(BUILDDIR) $(SOURCES) $(A51_SOURCES) $(FX2LIBDIR)/lib/fx2.lib $(DEPS) | |
91 | # can't use default target %.rel because there is no way | |
92 | # to differentiate the dependency. (Is it %.rel: %.c or %.a51) | |
93 | for a in $(A51_SOURCES); do \ | |
94 | cp $$a $(BUILDDIR)/; \ | |
d1bee53d | 95 | cd $(BUILDDIR) && $(SDAS8051) -logs `basename $$a` && cd ..; done |
3608c106 UH |
96 | for s in $(SOURCES); do \ |
97 | THISREL=$$(basename `echo "$$s" | sed -e 's/\.c$$/\.rel/'`); \ | |
98 | $(CC) -c -I $(FX2LIBDIR)/include $$s -o $(BUILDDIR)/$$THISREL ; done | |
99 | $(CC) -o $@ $(RELS) fx2.lib -L $(FX2LIBDIR)/lib $(LIBS) | |
100 | ||
101 | ||
102 | $(BUILDDIR)/$(BASENAME).bix: $(BUILDDIR)/$(BASENAME).ihx | |
103 | objcopy -I ihex -O binary $< $@ | |
104 | $(BUILDDIR)/$(BASENAME).iic: $(BUILDDIR)/$(BASENAME).ihx | |
105 | $(FX2LIBDIR)/utils/ihx2iic.py -v $(VID) -p $(PID) $< $@ | |
106 | ||
107 | load: $(BUILDDIR)/$(BASENAME).bix | |
108 | fx2load -v $(VID) -p $(PID) $(BUILDDIR)/$(BASENAME).bix | |
109 | ||
110 | clean: | |
111 | rm -f $(BUILDDIR)/*.{asm,ihx,lnk,lst,map,mem,rel,rst,sym,adb,cdb,bix} | |
112 | ||
113 | clean-all: clean | |
4836f792 | 114 | $(MAKE) -C $(FX2LIBDIR)/lib clean |
3608c106 | 115 |