-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
232 lines (165 loc) · 7.07 KB
/
Makefile
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#=====================================================================
#(C) Unpublished Work of ADMtek Incorporated. All Rights Reserved.
#
# boot loader make file
#=====================================================================
# These values must conform to linuxld.h content
LOADER_OFFSET = 0x80800000
RUNTIME_OFFSET = 0x80801000
#============================ Make ==============================
# Don't define any builtin rules and variables.
MAKEFLAGS := $(MAKEFLAGS)R
# Delete default suffixes
.SUFFIXES:
# Delete default rules
.DEFAULT:
#.DEFAULT:
# $(error no rules for target "$@")
# Set V=something for verbose building messages
#V = 1
v = $(if $(V),,@)
#============================ Compilers ==============================
CROSS_PREFIX ?= $(HOME)/gnutools/mipsisa32-elf/bin/mipsisa32-elf-
AS = $(CROSS_PREFIX)as
CC = $(CROSS_PREFIX)gcc
LD = $(CROSS_PREFIX)ld
AR = $(CROSS_PREFIX)ar
OBJCOPY = $(CROSS_PREFIX)objcopy
OBJDUMP = $(CROSS_PREFIX)objdump
#============================ Tools ==================================
RM = rm $(if $(V),-v) -f
RM_R = rm $(if $(V),-v) -fr
MV = mv $(if $(V),-v)
CP = cp $(if $(V),-v) -a
MKDIR = mkdir $(if $(V),-v)
MKDIR_P = mkdir $(if $(V),-v) -p
#======================= Endian dependance =========================
ENDIAN_FG = -EL
EDIR = el
LIB_PATH = -L./lib/$(EDIR)
#======================= Compiler Flags ============================
CC_FLAG = $(ENDIAN_FG) -Wall -W -Os
CPU_FLAG = -mips32
INCLUDE_DIR = -I./include
ALL_C_FLAGS = $(CC_FLAG) $(INCLUDE_DIR) $(CPU_FLAG) $(EXT_DEF) $(EXTRA_DEFINE)
#======================= Directories ===============================
OBJ_DIR = ./build
BIN_DIR = ./bin
SRC_DIR = ./src
TFTPBOOT = $(HOME)/tftpboot
OBJ_DIR_STAMP = $(OBJ_DIR)/.dir
BIN_DIR_STAMP = $(BIN_DIR)/.dir
TFTPBOOT_STAMP = $(TFTPBOOT)/.dir
#==================== NandFlash Linker Flags ===========================
LD_FLAG = -X -N
LIBS = -lz -lc -lnosys
BOOT_NAME = nand_bootinit
BOOT_NAME_RAM = nand_bootinit_ram
BOOT_OBJS = $(OBJ_DIR)/nand_bootinit.o
BOOT_OBJS_RAM = $(OBJ_DIR)/nand_bootinit_ram.o
EXEC_NAME = nand_bootmain
exec_objs = nand_ldrinit.o bloader.o linuxld.o xmodem.o nand.o nand_ecc.o
exec_objs += cachelib.o irqlib.o timer.o vector.o except.o utils.o
exec_objs += if_5120.o memlib.o uartdrv.o tftp.o eth.o skbuff.o arp.o ip.o
exec_objs += udp.o param.o nf.o
EXEC_OBJS = $(addprefix $(OBJ_DIR)/,$(exec_objs))
EXEC_NAME_RAM = nand_bootmain_ram
exec_objs_ram = nand_ldrinit.o bloader_ram.o linuxld.o xmodem.o nand.o nand_ecc.o
exec_objs_ram += cachelib.o irqlib.o timer.o vector.o except.o utils.o
exec_objs_ram += if_5120.o memlib.o uartdrv.o tftp.o eth.o skbuff.o arp.o ip.o
exec_objs_ram += udp.o param.o nf.o
EXEC_OBJS_RAM = $(addprefix $(OBJ_DIR)/,$(exec_objs_ram))
ROM_NAME = nandloader
RAM_NAME = nandloader_ram
CMM_CREATE = loadercmm
ROM_IMG = $(BIN_DIR)/$(ROM_NAME).img
ROM_CMM = $(BIN_DIR)/$(ROM_NAME).cmm
BOOT_IMG = $(OBJ_DIR)/$(BOOT_NAME).img
MAIN_IMG = $(OBJ_DIR)/$(EXEC_NAME).img
RAM_IMG = $(BIN_DIR)/$(RAM_NAME).img
BOOT_RAM_IMG = $(OBJ_DIR)/$(BOOT_NAME_RAM).img
MAIN_RAM_IMG = $(OBJ_DIR)/$(EXEC_NAME_RAM).img
ALL_OBJS = $(BOOT_OBJS) $(BOOT_OBJS_RAM) $(EXEC_OBJS) $(EXEC_OBJS_RAM)
#====================== NandFlash Rules =============================
.PHONY : all %install
all : $(ROM_IMG) $(RAM_IMG)
install : rom_img_install ram_img_install
rom_img_install : $(BOOT_IMG) $(MAIN_IMG) $(ROM_IMG) $(TFTPBOOT_STAMP)
@echo "> Copying $(ROM_IMG) to $(TFTPBOOT)"
$(v)$(CP) $(ROM_IMG) $(TFTPBOOT)
$(ROM_IMG) : $(BOOT_IMG) $(MAIN_IMG) $(BIN_DIR_STAMP)
@echo "> Constructing $@"
$(v)cat $(BOOT_IMG) $(MAIN_IMG) > $@
#$(BIN_DIR)/$(CMM_CREATE) $(ROM_IMG) $(ROM_CMM)
$(BOOT_IMG) : $(BOOT_OBJS) $(OBJ_DIR_STAMP)
@echo "> Linking $@"
$(v)$(LD) $(ENDIAN_FG) $(LD_FLAG) $(LIB_PATH) -e _nand_reset -Ttext $(LOADER_OFFSET) \
-Map $(OBJ_DIR)/$(BOOT_NAME).map -o $(OBJ_DIR)/$(BOOT_NAME).elf \
$(BOOT_OBJS) $(LIBS)
$(v)$(OBJCOPY) -O binary $(OBJ_DIR)/$(BOOT_NAME).elf $(OBJ_DIR)/$(BOOT_NAME).bin
$(v)$(OBJCOPY) -I binary -O binary --pad-to 0x1000 $(OBJ_DIR)/$(BOOT_NAME).bin $@
$(MAIN_IMG) : $(EXEC_OBJS) $(OBJ_DIR_STAMP)
@echo "> Linking $@"
$(v)$(LD) $(ENDIAN_FG) $(LD_FLAG) $(LIB_PATH) -e _ldrinit -Ttext $(RUNTIME_OFFSET) \
-Map $(OBJ_DIR)/$(EXEC_NAME).map -o $(OBJ_DIR)/$(EXEC_NAME).elf \
$(EXEC_OBJS) $(LIBS)
$(v)$(OBJCOPY) -O binary $(OBJ_DIR)/$(EXEC_NAME).elf $@
ram_img_install : $(BOOT_RAM_IMG) $(MAIN_RAM_IMG) $(RAM_IMG) $(TFTPBOOT_STAMP)
@echo "> Copying $(RAM_IMG) to $(TFTPBOOT)"
$(v)$(CP) $(RAM_IMG) $(TFTPBOOT)
$(RAM_IMG) : $(BOOT_RAM_IMG) $(MAIN_RAM_IMG) $(BIN_DIR_STAMP)
@echo "> Constructing $@"
$(v)cat $(BOOT_RAM_IMG) $(MAIN_RAM_IMG) > $(RAM_IMG)
#$(OBJCOPY) --set-start=$(LOADER_OFFSET) -O srec -I binary $(BIN_DIR)/$(RAM_NAME).img $(BIN_DIR)/$(RAM_NAME).srec
#$(BIN_DIR)/$(CMM_CREATE) $(BIN_DIR)/$(ROM_NAME).img $(BIN_DIR)/$(ROM_NAME).cmm
$(BOOT_RAM_IMG) : $(BOOT_OBJS_RAM) $(OBJ_DIR_STAMP)
@echo "> Linking $@"
$(v)$(LD) $(ENDIAN_FG) $(LD_FLAG) $(LIB_PATH) -e _nand_reset -Ttext $(LOADER_OFFSET) \
-Map $(OBJ_DIR)/$(BOOT_NAME_RAM).map -o $(OBJ_DIR)/$(BOOT_NAME_RAM).elf \
$(BOOT_OBJS_RAM) $(LIBS)
$(v)$(OBJCOPY) -O binary $(OBJ_DIR)/$(BOOT_NAME_RAM).elf $(OBJ_DIR)/$(BOOT_NAME_RAM).bin
$(v)$(OBJCOPY) -I binary -O binary --pad-to 0x1000 $(OBJ_DIR)/$(BOOT_NAME_RAM).bin $@
$(MAIN_RAM_IMG) : $(EXEC_OBJS_RAM) $(OBJ_DIR_STAMP)
@echo "> Linking $@"
$(v)$(LD) $(ENDIAN_FG) $(LD_FLAG) $(LIB_PATH) -e _ldrinit -Ttext $(RUNTIME_OFFSET) \
-Map $(OBJ_DIR)/$(EXEC_NAME_RAM).map -o $(OBJ_DIR)/$(EXEC_NAME_RAM).elf \
$(EXEC_OBJS_RAM) $(LIBS)
$(v)$(OBJCOPY) -O binary $(OBJ_DIR)/$(EXEC_NAME_RAM).elf $@
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.c $(OBJ_DIR_STAMP)
@echo "> Compiling $< to $@"
$(v)$(CC) $(ALL_C_FLAGS) -c $< -o $@
$(OBJ_DIR)/%.o : $(SRC_DIR)/%.S $(OBJ_DIR_STAMP)
@echo "> Compiling $< to $@"
$(v)$(CC) $(ALL_C_FLAGS) -c $< -o $@
#======================== Directory rules ============================
%/.dir :
@echo "> Creating directory $@"
$(v)$(MKDIR_P) $(dir $@)
$(v)touch $@
#========================== Clean rules ==============================
.PHONY : clean
clean:
@echo "> Cleaning $(OBJ_DIR) $(BIN_DIR)"
$(v)$(RM_R) $(OBJ_DIR) $(BIN_DIR)
#===================== Dependencies generation =======================
deps = $(patsubst %.o,%.dep,$(ALL_OBJS))
#$(warning deps: $(deps))
dep_gen_cmd_tail = -M $(ALL_C_FLAGS) -w $< > [email protected] \
&& sed '\''s!$(subst .,\.,$*.o) *:!$(patsubst %.dep,%.o,$@) $(patsubst %.dep,%.lo,$@) $@ $(patsubst %.dep,%.s,$@):!g'\'' \
&& $(MV) [email protected] $@ && $(RM) [email protected]; } \
|| $(RM) $@ [email protected] [email protected]
c_deps_gen_cmd = $(SHELL) -ec '{ $(CC) -D__GENDEPS__ $(dep_gen_cmd_tail)'
$(OBJ_DIR)/%.o: $(OBJ_DIR)/%.dep
$(OBJ_DIR)/%.dep: $(SRC_DIR)/%.c $(OBJ_DIR_STAMP)
@echo "> Generating dependencies for $<"; \
$(c_deps_gen_cmd)
ifeq "$(deps)" ""
DONT_INCLUDE_DEPS = defined
endif
ifneq "$(filter %clean dist% none,$(MAKECMDGOALS))" ""
DONT_INCLUDE_DEPS = defined
endif
ifndef DONT_INCLUDE_DEPS
-include $(deps)
endif