| 1 |
349 |
julius |
######################################################################
|
| 2 |
|
|
#### ####
|
| 3 |
392 |
julius |
#### Common software makefile for inclusion by others ####
|
| 4 |
349 |
julius |
#### ####
|
| 5 |
|
|
######################################################################
|
| 6 |
|
|
#### ####
|
| 7 |
|
|
#### Copyright (C) 2010 Authors and OPENCORES.ORG ####
|
| 8 |
|
|
#### ####
|
| 9 |
|
|
#### This source file may be used and distributed without ####
|
| 10 |
|
|
#### restriction provided that this copyright statement is not ####
|
| 11 |
|
|
#### removed from the file and that any derivative work contains ####
|
| 12 |
|
|
#### the original copyright notice and the associated disclaimer. ####
|
| 13 |
|
|
#### ####
|
| 14 |
|
|
#### This source file is free software; you can redistribute it ####
|
| 15 |
|
|
#### and/or modify it under the terms of the GNU Lesser General ####
|
| 16 |
|
|
#### Public License as published by the Free Software Foundation; ####
|
| 17 |
|
|
#### either version 2.1 of the License, or (at your option) any ####
|
| 18 |
|
|
#### later version. ####
|
| 19 |
|
|
#### ####
|
| 20 |
|
|
#### This source is distributed in the hope that it will be ####
|
| 21 |
|
|
#### useful, but WITHOUT ANY WARRANTY; without even the implied ####
|
| 22 |
|
|
#### warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ####
|
| 23 |
|
|
#### PURPOSE. See the GNU Lesser General Public License for more ####
|
| 24 |
|
|
#### details. ####
|
| 25 |
|
|
#### ####
|
| 26 |
|
|
#### You should have received a copy of the GNU Lesser General ####
|
| 27 |
|
|
#### Public License along with this source; if not, download it ####
|
| 28 |
|
|
#### from http://www.opencores.org/lgpl.shtml ####
|
| 29 |
|
|
#### ####
|
| 30 |
|
|
######################################################################
|
| 31 |
|
|
|
| 32 |
360 |
julius |
DESIGN_NAME=orpsoc
|
| 33 |
349 |
julius |
|
| 34 |
|
|
OR32_TOOL_PREFIX=or32-elf-
|
| 35 |
|
|
|
| 36 |
|
|
OR32_LD=$(OR32_TOOL_PREFIX)ld
|
| 37 |
|
|
OR32_AS=$(OR32_TOOL_PREFIX)as
|
| 38 |
|
|
OR32_CC=$(OR32_TOOL_PREFIX)gcc
|
| 39 |
|
|
OR32_AR=$(OR32_TOOL_PREFIX)ar
|
| 40 |
|
|
OR32_RANLIB=$(OR32_TOOL_PREFIX)ranlib
|
| 41 |
|
|
OR32_OBJDUMP=$(OR32_TOOL_PREFIX)objdump
|
| 42 |
|
|
OR32_OBJCOPY=$(OR32_TOOL_PREFIX)objcopy
|
| 43 |
|
|
|
| 44 |
392 |
julius |
# SW_ROOT should be set by whatever is running this
|
| 45 |
349 |
julius |
|
| 46 |
392 |
julius |
# Special case for CPU drivers
|
| 47 |
|
|
CPU_DRIVER ?=$(SW_ROOT)/drivers/or1200
|
| 48 |
|
|
|
| 49 |
|
|
# Rest of drivers, check if we have any that we should use board-specific
|
| 50 |
|
|
# versions of.
|
| 51 |
|
|
# Expecting BOARD_SPECIFIC_DRIVERS and BOARD_PATH to be set
|
| 52 |
|
|
COMMON_SW_DRIVERS=$(shell ls $(SW_ROOT)/drivers )
|
| 53 |
|
|
COMMON_SW_DRIVERS_EXCLUDE_BOARD_DRIVERS_CMD=$(shell for driver in $(BOARD_SPECIFIC_DRIVERS); do echo -n "grep -v $$driver"; done)
|
| 54 |
|
|
COMMON_SW_DRIVERS_WITHOUT_BOARD_DRIVERS=$(shell echo $(COMMON_SW_DRIVERS) $(COMMON_SW_DRIVERS_EXCLUDE_BOARD_DRIVERS_CMD))
|
| 55 |
|
|
|
| 56 |
|
|
# Add paths to the common drivers
|
| 57 |
|
|
SW_DRIVER_PATHS=$(shell for driver in $(COMMON_SW_DRIVERS_WITHOUT_BOARD_DRIVERS); do echo $(SW_ROOT)/drivers/$$driver; done)
|
| 58 |
|
|
# If anything in BOARD_SPECIFIC_DRIVERS, add it to SW_DRIVER_PATHS
|
| 59 |
|
|
# It's expected BOARD_PATH points to the board's path and the heirarchy of
|
| 60 |
|
|
# sw/drivers exists
|
| 61 |
|
|
SW_DRIVER_PATHS += $(shell for driver in $(BOARD_SPECIFIC_DRIVERS); do echo $(BOARD_PATH)/sw/drivers/$$driver; done)
|
| 62 |
|
|
|
| 63 |
|
|
# Now assemble all of the include paths for the drivers, prefix with -I for GCC
|
| 64 |
|
|
DRIVER_INCLUDE_PATHS=$(shell for driverpath in $(SW_DRIVER_PATHS); do echo "-I$$driverpath/include"; done)
|
| 65 |
|
|
|
| 66 |
|
|
# If BOARD_PATH isn't set, then we're not compiling for a board, so use the
|
| 67 |
|
|
# generic board.h include path, otherwise, use that board's
|
| 68 |
|
|
ifeq ($(BOARD_PATH),)
|
| 69 |
|
|
DRIVER_INCLUDE_PATHS +=-I$(SW_ROOT)/board/include
|
| 70 |
|
|
else
|
| 71 |
|
|
DRIVER_INCLUDE_PATHS +=-I$(BOARD_PATH)/sw/board/include
|
| 72 |
|
|
endif
|
| 73 |
|
|
|
| 74 |
|
|
VECTORS_OBJ ?=$(CPU_DRIVER)/crt0.o
|
| 75 |
|
|
ORPSOC_LIB ?=$(SW_ROOT)/lib/liborpsoc.a
|
| 76 |
|
|
SUPPORT_LIBS ?=$(ORPSOC_LIB)
|
| 77 |
|
|
|
| 78 |
|
|
# All driver compilations will generate an object file of this name to be
|
| 79 |
|
|
# included into the liborpsoc library
|
| 80 |
|
|
DRIVER_OBJ=compiled.o
|
| 81 |
|
|
|
| 82 |
349 |
julius |
# Machine flags - uncomment one or create custom combination of flags
|
| 83 |
|
|
# All software div, mul and FPU
|
| 84 |
|
|
#MACH_FLAGS ?=-msoft-mul -msoft-div -msoft-float
|
| 85 |
|
|
# FPGA default - only hardware multiply
|
| 86 |
|
|
#MACH_FLAGS ?=-mhard-mul -msoft-div -msoft-float
|
| 87 |
|
|
# All hardware flags
|
| 88 |
|
|
#MARCH_FLAGS ?=-mhard-mul -mhard-div -mhard-float
|
| 89 |
|
|
# Hardware integer arith, soft float
|
| 90 |
|
|
MARCH_FLAGS ?=-mhard-mul -mhard-div -msoft-float
|
| 91 |
|
|
|
| 92 |
392 |
julius |
OR32_CFLAGS ?=-g -nostdlib -O2 $(MARCH_FLAGS) \
|
| 93 |
|
|
$(DRIVER_INCLUDE_PATHS) \
|
| 94 |
|
|
-I$(SW_ROOT)/lib/include
|
| 95 |
349 |
julius |
|
| 96 |
392 |
julius |
OR32_LDFLAGS ?=-lgcc -T$(CPU_DRIVER)/link.ld -e 256
|
| 97 |
|
|
OR32_ARFLAGS ?=-r
|
| 98 |
393 |
julius |
# RTL_VERILOG_INCLUDE_DIR *MUST* be set!
|
| 99 |
392 |
julius |
# Backup one - default, but may be wrong!
|
| 100 |
393 |
julius |
RTL_VERILOG_INCLUDE_DIR ?= $(SW_ROOT)/../rtl/verilog/include
|
| 101 |
349 |
julius |
|
| 102 |
393 |
julius |
DESIGN_VERILOG_DEFINES=$(RTL_VERILOG_INCLUDE_DIR)/$(DESIGN_NAME)-defines.v
|
| 103 |
392 |
julius |
DESIGN_PROCESSED_VERILOG_DEFINES=$(SW_ROOT)/lib/include/$(DESIGN_NAME)-defines.h
|
| 104 |
349 |
julius |
|
| 105 |
393 |
julius |
OR1200_VERILOG_DEFINES=$(RTL_VERILOG_INCLUDE_DIR)/or1200_defines.v
|
| 106 |
392 |
julius |
OR1200_PROCESSED_VERILOG_DEFINES=$(SW_ROOT)/lib/include/or1200-defines.h
|
| 107 |
349 |
julius |
|
| 108 |
361 |
julius |
PROCESSED_DEFINES=$(DESIGN_PROCESSED_VERILOG_DEFINES) $(OR1200_PROCESSED_VERILOG_DEFINES)
|
| 109 |
349 |
julius |
|
| 110 |
393 |
julius |
ELF_DEPENDS+= $(SUPPORT_LIBS)
|
| 111 |
361 |
julius |
|
| 112 |
349 |
julius |
# Set V=1 when calling make to enable verbose output
|
| 113 |
|
|
# mainly for debugging purposes.
|
| 114 |
|
|
ifeq ($(V), 1)
|
| 115 |
|
|
Q=
|
| 116 |
|
|
else
|
| 117 |
|
|
Q ?=@
|
| 118 |
|
|
endif
|
| 119 |
|
|
|
| 120 |
|
|
# Our local utilities
|
| 121 |
392 |
julius |
UTILS_BIN2HEX=$(SW_ROOT)/utils/bin2hex
|
| 122 |
349 |
julius |
$(UTILS_BIN2HEX):
|
| 123 |
392 |
julius |
$(Q)$(MAKE) -C $(SW_ROOT)/utils bin2hex
|
| 124 |
349 |
julius |
|
| 125 |
392 |
julius |
UTILS_BIN2VMEM=$(SW_ROOT)/utils/bin2vmem
|
| 126 |
349 |
julius |
$(UTILS_BIN2VMEM):
|
| 127 |
392 |
julius |
$(Q)$(MAKE) -C $(SW_ROOT)/utils bin2vmem
|
| 128 |
349 |
julius |
|
| 129 |
|
|
# Rule to generate C header file from Verilog file with `defines in it
|
| 130 |
|
|
$(DESIGN_PROCESSED_VERILOG_DEFINES): $(DESIGN_VERILOG_DEFINES)
|
| 131 |
|
|
$(Q)echo; echo "\t### Creating software defines header from verilog defines ###";
|
| 132 |
392 |
julius |
$(Q)echo "//This file is autogenerated from "$<" do not change!" > $@
|
| 133 |
|
|
$(Q)echo "#ifndef _"$(DESIGN_NAME)"_DEFINES_H_" >> $@
|
| 134 |
|
|
$(Q)echo "#define _"$(DESIGN_NAME)"_DEFINES_H_" >> $@
|
| 135 |
|
|
$(Q)cat $< | sed s://.*::g | sed 's/'\`'/'#'/g' >> $@
|
| 136 |
|
|
$(Q)echo "#endif" >> $@
|
| 137 |
|
|
$(Q)echo; echo >> $@
|
| 138 |
349 |
julius |
|
| 139 |
|
|
# This works (doesn't error), but for now we have to remove all of the numbers
|
| 140 |
|
|
# in verilog format, eg. 8'b0010_0000 or 32'h0000_0f00, or 32'd256 etc. as it's
|
| 141 |
|
|
# not so straight forward to convert these
|
| 142 |
|
|
$(OR1200_PROCESSED_VERILOG_DEFINES): $(OR1200_VERILOG_DEFINES)
|
| 143 |
|
|
$(Q)echo; echo "\t### Creating OR1200 software defines header from verilog defines ###";
|
| 144 |
392 |
julius |
$(Q)echo "//This file is autogenerated from "$<" do not change!" > $@
|
| 145 |
|
|
$(Q)echo "#ifndef _OR1200_DEFINES_H_" >> $@
|
| 146 |
|
|
$(Q)echo "#define _OR1200_DEFINES_H_" >> $@
|
| 147 |
|
|
$(Q)cat $< | sed s://.*::g | grep -v \'[dhb] | sed 's/'\`'/'#'/g' >> $@
|
| 148 |
|
|
$(Q)echo "#endif" >> $@
|
| 149 |
|
|
$(Q)echo; echo >> $@
|
| 150 |
349 |
julius |
|
| 151 |
|
|
# Default make
|
| 152 |
|
|
%.flashin: %.bin $(UTILS_BIN2HEX)
|
| 153 |
|
|
$(Q)$(UTILS_BIN2HEX) $< 1 -size_word > $@
|
| 154 |
|
|
|
| 155 |
|
|
%.vmem: %.bin $(UTILS_BIN2VMEM)
|
| 156 |
|
|
$(Q)$(UTILS_BIN2VMEM) $< > $@
|
| 157 |
|
|
|
| 158 |
393 |
julius |
%.elf: %.c $(ELF_DEPENDS) $(VECTORS_OBJ)
|
| 159 |
349 |
julius |
$(Q)$(OR32_CC) $^ $(OR32_CFLAGS) $(OR32_LDFLAGS) -o $@
|
| 160 |
|
|
|
| 161 |
|
|
%.elf: %.S $(ELF_DEPENDS)
|
| 162 |
|
|
$(Q)$(OR32_CC) $^ $(OR32_CFLAGS) $(OR32_LDFLAGS) -o $@
|
| 163 |
|
|
|
| 164 |
|
|
%.o: %.S
|
| 165 |
|
|
$(Q)$(OR32_CC) $(OR32_CFLAGS) -c $< -o $@
|
| 166 |
|
|
|
| 167 |
|
|
%.o: %.c
|
| 168 |
|
|
$(Q)$(OR32_CC) $(OR32_CFLAGS) -c $< -o $@
|
| 169 |
|
|
|
| 170 |
392 |
julius |
COMPILE_SRCS_BASENAMES=$(basename $(COMPILE_SRCS))
|
| 171 |
|
|
COMPILE_OBJS=$(COMPILE_SRCS_BASENAMES:%=%.o)
|
| 172 |
349 |
julius |
|
| 173 |
392 |
julius |
$(DRIVER_OBJ): $(COMPILE_OBJS)
|
| 174 |
|
|
$(Q)$(OR32_LD) $(OR32_ARFLAGS) $^ -o $@
|
| 175 |
|
|
|
| 176 |
|
|
# Rule to make all necessary driver objects
|
| 177 |
|
|
|
| 178 |
|
|
$(ORPSOC_LIB): $(PROCESSED_DEFINES)
|
| 179 |
349 |
julius |
$(Q)echo; echo "\t### Building software support library ###"; echo
|
| 180 |
392 |
julius |
$(Q)$(MAKE) -C $(SW_ROOT)/lib liborpsoc.a
|
| 181 |
349 |
julius |
|
| 182 |
|
|
$(VECTORS_OBJ):
|
| 183 |
392 |
julius |
$(Q)$(MAKE) -C $(CPU_DRIVER) crt0.o
|
| 184 |
349 |
julius |
|
| 185 |
|
|
# This relies on the local clean rule of each makefile
|
| 186 |
|
|
clean-all: distclean
|
| 187 |
|
|
|
| 188 |
|
|
clean-support:
|
| 189 |
|
|
$(Q)$(MAKE) -C ../support clean
|
| 190 |
|
|
|
| 191 |
|
|
# List of software directories, exclude include/
|
| 192 |
|
|
SWDIRS=$(shell ls ../ | grep -v include)
|
| 193 |
|
|
|
| 194 |
|
|
distclean:
|
| 195 |
|
|
$(Q)for dir in $(SWDIRS); do if [ -d ../$$dir ]; then $(MAKE) -C ../$$dir clean; fi; done
|
| 196 |
392 |
julius |
$(Q)for dir in $(SW_DRIVER_PATHS); do $(MAKE) -C $$dir clean; done
|
| 197 |
349 |
julius |
$(Q)rm -f $(PROCESSED_DEFINES)
|