OSDN Git Service

8f9664602dba4b4cf0c0bbaeeeedd56050be118a
[armadillo-ux/hermit-at-ux.git] / src / target / armadillo2x0 / Makefile
1 #
2 # Copyright (c) 2006 Atmark Techno, Inc.  All Rights Reserved.
3 #
4
5 #
6 # Guarantee that the top-level TARGET variable, if set, is armadillo.
7 #
8 ifeq (, $(TARGET))
9         TARGET := armadillo2x0
10 endif
11
12 .PROFILE := $(PROFILE)
13
14 status :=
15 error :=
16
17 #
18 # Configure settings based on the target passed from the top-level
19 # makefile.  The PROFILE := armadillo line is just a default and can
20 # be overridden from the command line.
21 #
22 NCVT = ../../../tools/ncvt
23 current-profile := $(shell $(NCVT) $(TARGET) $(.PROFILE))
24 ifneq (,$(wildcard profile-stamp))
25         previous-profile := $(shell cat profile-stamp)
26         ifneq ($(current-profile), $(previous-profile))
27                 error := profile-error
28         endif
29 endif
30
31 #
32 # Configuration for standalone, optimized ARM920T cross-compile.
33 #
34 BUILD_NAME := $(shell $(NCVT) -c "-" loader $(TARGET) $(.PROFILE) v$(HERMIT_VERSION))
35 BUILD_TARGETS := $(BUILD_NAME).bin
36
37 CROSS := arm-linux-
38 GCC_VER := $(shell $(CROSS)gcc -dumpversion | sed "s/\..*//")
39 INCLUDEDIR := ../../../include
40 CC := $(CROSS)gcc
41 CFLAGS := -Wall -O2 -fomit-frame-pointer -I$(INCLUDEDIR) -nostdlib \
42         -DHERMIT_VERSION='"$(HERMIT_VERSION)"' \
43         -march=armv4 -mtune=arm9tdmi -static
44 CFLAGS += -DTARGET_STRING=\"$(TARGET)\" -DPROFILE_STRING=\"$(.PROFILE)\"
45
46 #
47 # The LDSCRIPT variable can be overridden based on the target-derived
48 # settings.
49 #
50 LDSCRIPT := flash
51 OBJSECTIONS := .boot .text .data .bss
52 OBJCOPYFLAGS := -O binary -S $(addprefix -j ,$(OBJSECTIONS))
53
54 ASMS := boot.S lib1funcs.S
55 SRCS := entry.c loader.c memmap.c linux.c board.c mmu.c medium_io.c
56 SRCS += ../memzero.c ../medium.c ../frob.c ../setenv.c ../gunzip.c
57 SRCS += ../flash/flash_core.c ../flash/flash_amd.c
58 SRCS += ../md5sum.c
59
60 ifeq ($(GCC_VER), 2)
61 SRCS += ../flash/flash_spi_dummy.c ../flash/flash_intel_dummy.c
62 endif
63
64 #
65 # Profile Specific
66 #
67 ifeq (, $(.PROFILE))
68         CFLAGS += -DCONSOLE=0 -DRELOCATE
69         status := profile-detect
70 endif
71
72 ifeq (eth, $(.PROFILE))
73         SRCS += eth_ep93xx.c i2c_armadillo2x0.c tftpdl.c
74         SRCS += ../net/arp.c ../net/eth.c ../net/eth_util.c ../net/ip.c
75         SRCS += ../net/tftp.c ../net/udp.c ../net/mac.c
76         CFLAGS += -DCONSOLE=0 -DRELOCATE -DENABLE_ETH
77 #       CFLAGS += -DDEBUG_ETH
78         status := profile-detect
79 endif
80
81 ifeq (ttyAM1, $(.PROFILE))
82         CFLAGS += -DCONSOLE=1 -DRELOCATE
83         status := profile-detect
84 endif
85
86 ifeq (notty, $(.PROFILE))
87         CFLAGS += -DRELOCATE
88         status := profile-detect
89 endif
90
91 ifeq (boot, $(.PROFILE))
92         ASMS := init.S lib1funcs.S
93         CFLAGS += -DCONSOLE=0 -DBOOTMODE
94         LDSCRIPT := bootmode
95         status := profile-detect
96 endif
97
98 ifeq (boot-eth, $(.PROFILE))
99         ASMS := init.S lib1funcs.S
100         SRCS += eth_ep93xx.c i2c_armadillo2x0.c tftpdl.c
101         SRCS += ../net/arp.c ../net/eth.c ../net/eth_util.c ../net/ip.c
102         SRCS += ../net/tftp.c ../net/udp.c ../net/mac.c
103         CFLAGS += -DCONSOLE=0 -DBOOTMODE -DENABLE_ETH
104 #       CFLAGS += -DDEBUG_ETH
105         LDSCRIPT := bootmode
106         status := profile-detect
107 endif
108
109 ifneq (,$(PLL_HI))
110         .PLL_HI := $(PLL_HI)
111 endif
112 ifneq (,$(PLL_LO))
113         .PLL_LO := $(PLL_LO)
114 endif
115 ifeq (200,$(CLOCK))
116 #       S*21/24*31 = 399.974400MHz
117         .PLL_HI := 0xa300
118         .PLL_LO := 0xd7
119 endif
120 ifeq (184,$(CLOCK))
121 #       S*21/16*19 = 367.718400MHz
122         .PLL_HI := 0xa200
123         .PLL_LO := 0x4f
124 endif
125 ifneq (,$(.PLL_HI))
126         CFLAGS += -DPLL_HI=$(.PLL_HI)
127 endif
128 ifneq (,$(.PLL_LO))
129         CFLAGS += -DPLL_LO=$(.PLL_LO)
130 endif
131
132 ifeq (, $(error))
133 ifeq (, $(status))
134         error := profile-unknown
135 endif
136 endif
137
138 OBJS := $(SRCS:.c=.o)
139 DEPS := $(SRCS:.c=.d)
140 LIBS := -lgcc -ltarget
141
142 all: $(error) profile-stamp $(BUILD_TARGETS)
143
144 profile-error:
145         @echo "profile-stamp mismatch; 'make scrub' to switch profiles"
146         @echo "  previous PROFILE:" $(previous-profile)
147         @echo "   current PROFILE:" $(current-profile)
148         @false
149 profile-unknown:
150         @echo "unknown PROFILE: $(.PROFILE)"
151         @false
152 profile-stamp:
153         @echo "$(current-profile)" > $@
154
155 # Hermit second stage loader (ELF image)
156 $(BUILD_NAME).elf: $(ASMS) $(OBJS) ../common/libtarget.a Makefile $(BUILD_NAME).lds
157         $(CC) $(CFLAGS) -L. -L../common \
158                 -Wl,-Map,$(BUILD_NAME).map \
159                 -Wl,-T$(BUILD_NAME).lds -o $@ \
160                 $(ASMS) $(OBJS) \
161                 -Wl,--start-group $(LIBS) -Wl,--end-group
162
163 $(BUILD_NAME).lds: $(wildcard loader.lds.*)
164         cp loader.lds.$(LDSCRIPT) $@
165
166 %.bin: %.elf
167         $(CROSS)objcopy $(OBJCOPYFLAGS) $< $@
168
169 # automated dependency checking
170 ifeq (,$(filter clean scrub,$(MAKECMDGOALS)))
171 -include $(DEPS)
172
173 DEPENDS := ../../../depend.sh
174 %.d: %.c
175         env CC=$(CC) $(DEPENDS) $< $@ $(CFLAGS)
176 endif
177
178 # installation
179 PHONY: install
180 install:
181         $(INSTALL) -m 644 -o root -g root \
182                 $(BUILD_TARGETS) \
183                 $(INSTALLPREFIX)/lib/hermit/
184
185 # housecleaning
186 .PHONY: clean
187 clean:
188         rm -f $(OBJS) loader-*.lds *.elf *.bin *.map
189 scrub: clean
190         rm -f profile-stamp 
191         rm -f *.d ../*.d ../flash/*.d ../net/*.d
192         rm -f *.o ../*.o ../flash/*.o ../net/*.o
193