📄 makefile
字号:
# If ENDIAN is not defined, this makefile was called from the command prompt
# (i.e. "make").
# We will first make the startup code that determines endianness, then
# make the little- and big-endian images, then concatenate them.
# Setup the definitions required to make the startup code that
# determines endianness (from bin directory).
# Root directory of YAMON source code.
ROOT = ./..
# Directory where make is supposed to be invoked.
MAKEDIR = .
# Directory where linker scripts reside.
LINKDIR = $(MAKEDIR)/link
# The startup code is intentionally compiled for little endian.
# See Au1x00 Bus Operation app note for more info.
ENDIAN = EL
# Override startup code endian as necessary (for legacy reasons we
# keep the Pb1x00 boards as big-endian, though they really too can
# be changed to be little-endian)...no longer legacy, do EL also
ifeq ($(BUILDTYPE),PB1000xxx)
ENDIAN = EB
endif
ifeq ($(BUILDTYPE),PB1500xxx)
ENDIAN = EB
endif
ifeq ($(BUILDTYPE),PB1100xxx)
ENDIAN = EB
endif
# Default options to SMUNGE for manipulating the "other" endian image
# so that it can be programmed while running the opposite endian.
# NOTE: The width of the Flash affects swizzling and swapping.
# NOTE: Flash widths of 32-bits must use -sw
# NOTE: Flash widths of 16-bits must use -sh
SMUNGE_OPTS = -sw
ifeq ($(BUILDTYPE),PB1200)
SMUNGE_OPTS = -sh
endif
ifeq ($(BUILDTYPE),DB1200)
SMUNGE_OPTS = -sh
endif
# Only one directory holds the source files for the startup code.
SRCDIR = $(ROOT)/init/reset
# Linker script.
ifdef SIMULATE
LD_SCRIPT = $(LINKDIR)/link_sim.xn
else
LD_SCRIPT = $(LINKDIR)/link.xn
endif
# The reset code.
IMAGE_ELF = ./$(RESET).elf
IMAGE_SREC = ./$(RESET).rec
IMAGE_MAP = ./$(RESET).map
IMAGE_DIS = ./$(RESET).dis
# The concatenated srecord file
IMAGE_SREC_CONCAT = ./$(IMAGENAME).rec
# The final flash image.
IMAGE_FLASH = ./$(IMAGENAME).fl
# Paths to and targets used for making the little- and big-endian images.
EL_PATH = ./EL
EB_PATH = ./EB
SREC_EL = $(IMAGENAME)_el.rec
SREC_EB = $(IMAGENAME)_eb.rec
endif # ifdef ENDIAN
# **********************************************
# Definitions common to start, little- and
# big-endian images.
# **********************************************
TOOLDIR = $(MAKEDIR)/tools
# Converter tool.
# Converts from srecord file to flash and binary files.
# The srecord file used is actually the concatenation of 3 files :
# 1) The srecord file holding the reset code.
# 2) The srecord file holding the little endian code.
# 3) The srecord file holding the big endian code.
SRECCONV = $(PERL) $(TOOLDIR)/srecconv.pl
# Options for srecconv tool
# -ES B is overwritten by "!B" or "!E" inserted in file to be converted.
# -EB B is required by the SEAD and SEAD-2 platforms.
SRECCONV_OPTS = -ES B -EB B -A 29
# Path to include directory.
INCLUDE = -I$(ROOT)/include -I$(ROOT)/arch/include
# Options to compiler.
#
# Define DEBUG if you wish debug output on debug serial port.
# DEBUG = -D_DEBUG_
#
# Define SIMULATE if building image for simulation.
# SIMULATE = -D_SIMULATE_
#
BUILDOPTS = -D$(BUILDTYPE)_CONFIG=1
W_OPTS = -Wimplicit -Wformat
REV_OPTS = '-D_REVMAJ_="$(REVMAJ)"' '-D_REVMIN_="$(REVMIN)"'
ifeq ($(TOOLCHAIN),macosx)
CC_OPTS = -G 0 -mips2 -Wa,-mips32 -fno-builtin -mno-abicalls -fno-pic -D_32_ -c -g -O2 $(W_OPTS) $(REV_OPTS) $(INCLUDE) $(DEBUG) $(SIMULATE) $(BUILDOPTS)
else
CC_OPTS = -G 0 -mips32 -mno-abicalls -fno-pic -D_32_ -c -g -O2 $(W_OPTS) $(REV_OPTS) $(INCLUDE) $(DEBUG) $(SIMULATE) $(BUILDOPTS)
endif
# SDE toolchain does not allow a construct like ".bss", it requires
# .section bss instead.
ifeq ($(TOOLCHAIN),sde)
CC_OPTS_A = $(CC_OPTS) -D_ASSEMBLER_ -D_SDE_
else
CC_OPTS_A = $(CC_OPTS) -D_ASSEMBLER_
endif
# This makefile.
MAKEFILE = $(MAKEDIR)/makefile
# Options to linker
LD_OPTS = -G 0
# Linker output format.
ifeq ($(ENDIAN),EB)
OFORMAT = elf32-bigmips
else
OFORMAT = elf32-littlemips
endif
# Search path for source files.
VPATH = $(SRCDIR)
# Source files (C and Assembler).
SRC_C = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.c))
SRC_S = $(foreach dir, $(SRCDIR), $(wildcard $(dir)/*.S))
SRC = $(SRC_C) $(SRC_S)
# Object files.
OBJ_C = $(notdir $(patsubst %.c, %.o, $(SRC_C)))
OBJ_S = $(notdir $(patsubst %.S, %.o, $(SRC_S)))
OBJ = $(OBJ_C) $(OBJ_S)
# **********************************************
# Targets
# **********************************************
.PHONY : all install test_install srec_el srec_eb release set_time clean depend dep
all : test_install set_time $(IMAGE_FLASH)
install :
-$(MKDIR) EL
-$(MKDIR) EB
test_install :
@$(PERL) $(TOOLDIR)/test_install.pl
release :
$(MAKE) clean
$(MAKE) all
$(OBJDUMP) -S $(IMAGE_ELF) > $(IMAGE_DIS)
$(CD) $(EL_PATH); $(OBJDUMP) -S $(IMAGENAME)_el.elf > $(IMAGENAME)_el.dis
$(CD) $(EB_PATH); $(OBJDUMP) -S $(IMAGENAME)_eb.elf > $(IMAGENAME)_eb.dis
set_time :
$(RM) -f $(EL_PATH)/comptime.o $(EB_PATH)/comptime.o
# Build the final flash and binary images :
# 1) Concatenate srecord files for the reset code, big- and little-endian code.
# 2) Apply SRECCONV tool.
$(IMAGE_FLASH) : $(IMAGE_SREC) srec_el srec_eb
$(ECHO) "!L" > ./tmp_little
$(ECHO) "!B" > ./tmp_big
gcc -O2 smunge.c -o ./smunge
ifeq ($(ENDIAN),EL)
# Swizzle EB part into EL ordering for flash programming
$ ./smunge $(SMUNGE_OPTS) $(EB_PATH)/$(SREC_EB)
$ mv $(EB_PATH)/$(SREC_EB).m $(EB_PATH)/$(SREC_EB)
endif
ifeq ($(ENDIAN),EB)
# Swizzle EL part into EB ordering for flash programming
$ ./smunge $(SMUNGE_OPTS) $(EL_PATH)/$(SREC_EL)
$ mv $(EL_PATH)/$(SREC_EL).m $(EL_PATH)/$(SREC_EL)
endif
ifeq ($(ENDIAN),EB)
$(CAT) ./tmp_big $(IMAGE_SREC)\
./tmp_little $(EL_PATH)/$(SREC_EL)\
./tmp_big $(EB_PATH)/$(SREC_EB)\
> $(IMAGE_SREC_CONCAT)
else
$(CAT) ./tmp_little $(IMAGE_SREC)\
./tmp_little $(EL_PATH)/$(SREC_EL)\
./tmp_big $(EB_PATH)/$(SREC_EB)\
> $(IMAGE_SREC_CONCAT)
endif
$(RM) ./tmp_little
$(RM) ./tmp_big
./postproc.pl <$(IMAGE_SREC_CONCAT) >$(IMAGE_SREC_CONCAT).tmp
mv $(IMAGE_SREC_CONCAT).tmp $(IMAGE_SREC_CONCAT)
# Change SREC addresses so that it can be downloaded into RAM first
./smunge -o9fc00000=a0100000 $(IMAGE_SREC_CONCAT)
$(IMAGE_SREC) : $(IMAGE_ELF)
$(OBJCOPY) -O srec $(IMAGE_ELF) $(IMAGE_SREC)
$(IMAGE_ELF) : $(OBJ) $(LD_SCRIPT)
ifeq ($(TOOLCHAIN),macosx)
$(LD) $(LD_OPTS) -T $(LD_SCRIPT) -o $(IMAGE_ELF) -Map $(IMAGE_MAP) -$(ENDIAN) $(OBJ)
else
$(LD) $(LD_OPTS) -T $(LD_SCRIPT) -o $(IMAGE_ELF) -Map $(IMAGE_MAP) --oformat $(OFORMAT) $(OBJ)
endif
$(OBJ_C) : %.o : %.c
$(CC) $(CC_OPTS) -$(ENDIAN) -D$(ENDIAN) -o $@ $<
$(OBJ_S) : %.o : %.S
$(CC) $(CC_OPTS_A) -$(ENDIAN) -D$(ENDIAN) -o $@ $<
$(OBJ) : $(MAKEFILE)
srec_el :
$(CD) $(EL_PATH); $(MAKE) -f ./../$(MAKEFILE) ENDIAN=EL $(SREC_EL)
srec_eb :
$(CD) $(EB_PATH); $(MAKE) -f ./../$(MAKEFILE) ENDIAN=EB $(SREC_EB)
CLEAN_FILES = ./*.m ./*.o ./*.bin ./*.elf ./*.rec ./*.map ./*.dis ./bcfg.fl ./$(RESET).fl ./$(IMAGE_BASENAME)*.fl ./depend.mk
clean :
-$(RM) -f $(CLEAN_FILES)
-$(CD) $(EL_PATH); $(RM) -f $(CLEAN_FILES)
-$(CD) $(EB_PATH); $(RM) -f $(CLEAN_FILES)
depend: test_install dep
$(CD) $(EL_PATH); $(MAKE) -f ./../$(MAKEFILE) ENDIAN=EL dep
$(CD) $(EB_PATH); $(MAKE) -f ./../$(MAKEFILE) ENDIAN=EB dep
dep:
$(CC) $(INCLUDE) -M $(SRC) > ./depend.mk
-include ./depend.mk
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -