]> rtime.felk.cvut.cz Git - fpga/lx-cpu1/lx-rocon.git/blobdiff - hw/Makefile
RoCoN: USB CDC ACM use maximal packet length - 64 bytes.
[fpga/lx-cpu1/lx-rocon.git] / hw / Makefile
index a8005260ef8fc3531609b1e0535b92ddbc110eaf..882628de2c9d915ded9309acd30e3938e6763666 100644 (file)
 #                 places all components and makes routes between them (depending
 #                 on the chosen optimization mode) and produces NCD file.
 #  - clean      : Clean build directory, dependency (*.d) files and call
-#  - all        : Transfer placed and routed NCD file into the bit file, which can
-#                 be then used to configure particular FPGA
+#  - gen        : Transfer placed and routed NCD file into the bin file, which can
+#                 be then used to configure particular FPGA (this is further packaged
+#                 for SelectMap interface via the ARM CPU)
+#  - firmware   : Builds the firmware for Tumbl core
 
 # Dependicies are handled, so in most cases only 'download' target is called.
 
@@ -43,16 +45,81 @@ NGD            := $(OUTB).ngd
 PCF            := $(OUTB).pcf
 NCD_MAP        := $(OUTB)_map.ncd
 NCD            := $(OUTB).ncd
-BIT            := $(OUTB).bit
+BIN            := $(OUTB).bin
+PKG            := $(OUTB).pkg
+TWR            := $(OUTB).twr
+TSI            := $(OUTB).tsi
 
 REQ_NGC            := $(REQB).ngc
 REQ_NGD            := $(REQB).ngd
 REQ_PCF            := $(REQB).pcf
 REQ_NCD_MAP        := $(REQB)_map.ncd
 REQ_NCD            := $(REQB).ncd
-REQ_BIT            := $(REQB).bit
+REQ_BIN            := $(REQB).bin
+REQ_PKG            := $(REQB).pkg
 REQ_SRC            := .
 
+REQ_FIRMWARE       := $(OUT)/imem.bin $(OUT)/imem.asm $(OUT)/dmem.bin $(OUT)/firmware.lst
+
+#===============================================================================
+# Sythesis settings (SmartXplorer)
+
+XST_GLOB_OPT := AllClockNets
+XST_OPT_LEVEL := 2
+XST_OPT_MODE := Speed
+XST_IOB_PACKING := False
+XST_POWER := NO
+XST_KEEP_HIEARCHY := No
+XST_NETLIST_HIEARCHY := As_Optimized
+XST_READ_CORES := YES
+XST_WRITE_TIMING_CONSTRAINTS := NO
+XST_CROSS_CLOCK_ANALYSIS := NO
+XST_CASE := Maintain
+XST_REDUCE_CONTROL_SETS := Auto
+XST_REGISTER_DUPLICATION := YES
+XST_REGISTER_BALANCING := Yes
+XST_MOVE_FIRST_STAGE := YES
+XST_MOVE_LAST_STAGE := YES
+XST_OPTIMIZE_PRIMITIVES := NO
+XST_USE_CLOCK_ENABLE := AUTO
+XST_EQUIVALENT_REGISTER_REMOVAL := YES
+XST_IOBUF := YES
+XST_MAX_FANOUT := 100000
+XST_RESOURCE_SHARING := YES
+XST_SLICE_UTILIZATION_RATIO_MARGIN := 5
+XST_SLICE_UTILIZATION_RATIO := 100
+XST_BRAM_UTILIZATION_RATIO := 100
+XST_DSP_UTILIZATION_RATIO := 100
+XST_USE_DSP48 := Auto
+XST_USE_SYNC_SET := Auto
+XST_USE_SYNC_RESET := Auto
+XST_SAFE_IMPLEMENTATION := No
+
+MAP_PLACER_COST_TABLE := 2
+MAP_LOGIC_OPT := on
+MAP_GLOBAL_OPT := off
+MAP_EQUIVALENT_REGISTER_REMOVAL := off
+MAP_LUT_COMBINING := off
+
+#===============================================================================
+# Firmware
+
+MB_CROSS_COMPILE ?= mbtumbl-elf-
+TARGET_CC := $(MB_CROSS_COMPILE)gcc
+TARGET_LD := $(MB_CROSS_COMPILE)ld
+TARGET_OBJCOPY := $(MB_CROSS_COMPILE)objcopy
+TARGET_OBJDUMP := $(MB_CROSS_COMPILE)objdump
+
+C_OBJS := $(OUT)/firmware.o
+A_OBJS :=
+CFLAGS := -mxl-soft-div -msoft-float -Wno-main -Wl,-no-check-sections -ffunction-sections -fno-zero-initialized-in-bss -g -O2 -Wall
+AFLAGS := -D__ASSEMBLY__ $(CFLAGS)
+LDFLAGS := -static -nostdlib -relax -defsym _STACK_SIZE=0x0200 --gc-sections
+
+OBJS := $(OUT)/start.o $(C_OBJS) $(A_OBJS)
+
+FIRMWARE_DIR := ./lx-rocon_firmware
+
 #===============================================================================
 
 # Attempt to create a output directory.
@@ -65,7 +132,7 @@ $(if $(OUTPUT_DIR),,$(error output directory "$(OUT)" does not exist))
 #===============================================================================
 
 .PHONY: all
-all: gen
+all: pkg firmware
 
 .PHONY: re-synthesize
 re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
@@ -78,14 +145,36 @@ re-synthesize $(REQ_NGC): $(addprefix $(REQ_SRC)/,$(PRJ))
          -ofmt NGC \
          -top $(TOP) \
          -p $(DEVICE) \
-         -opt_mode Speed \
-         -keep_hierarchy soft \
-         -opt_level 1" | xst | tee xst.log
+         -keep_hierarchy $(XST_KEEP_HIEARCHY) \
+         -glob_opt $(XST_GLOB_OPT) \
+         -opt_mode $(XST_OPT_MODE) \
+         -opt_level $(XST_OPT_LEVEL) \
+         -power $(XST_POWER) \
+         -iob $(XST_IOB_PACKING) \
+         -read_cores $(XST_READ_CORES) \
+         -write_timing_constraints $(XST_WRITE_TIMING_CONSTRAINTS) \
+         -cross_clock_analysis $(XST_CROSS_CLOCK_ANALYSIS) \
+         -case $(XST_CASE) \
+         -reduce_control_sets $(XST_REDUCE_CONTROL_SETS) \
+         -resource_sharing $(XST_RESOURCE_SHARING) \
+         -iobuf $(XST_IOBUF) \
+         -max_fanout $(XST_MAX_FANOUT) \
+         -register_duplication $(XST_REGISTER_DUPLICATION) \
+         -register_balancing $(XST_REGISTER_BALANCING) \
+         -move_first_stage $(XST_MOVE_FIRST_STAGE) \
+         -move_last_stage $(XST_MOVE_LAST_STAGE) \
+         -optimize_primitives $(XST_OPTIMIZE_PRIMITIVES) \
+         -use_clock_enable $(XST_USE_CLOCK_ENABLE) \
+         -equivalent_register_removal $(XST_EQUIVALENT_REGISTER_REMOVAL) \
+         -slice_utilization_ratio_maxmargin $(XST_SLICE_UTILIZATION_RATIO_MARGIN) \
+         -slice_utilization_ratio $(XST_SLICE_UTILIZATION_RATIO) \
+         -bram_utilization_ratio $(XST_BRAM_UTILIZATION_RATIO) \
+         -dsp_utilization_ratio $(XST_DSP_UTILIZATION_RATIO)" | xst | tee xst.log
 
 .PHONY: re-translate
 re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
        cd $(OUT); \
-       ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -uc $(SRC)/$(UCF) \
+       ngdbuild -intstyle $(INTSTYLE) -p $(DEVICE) -nt timestamp -uc $(SRC)/$(UCF) \
          $(addprefix -sd $(SRC)/,$(SEARCH_DIRS)) \
          $(NGC) \
          $(NGD)
@@ -93,17 +182,58 @@ re-translate $(REQ_NGD): $(REQ_NGC) $(REQ_UCF)
 .PHONY: re-map
 re-map $(REQ_NCD_MAP) $(REQ_PCF): $(REQ_NGD)
        cd $(OUT); \
-       map -intstyle $(INTSTYLE) -o $(NCD_MAP) $(NGD) $(PCF)
+       map -w -intstyle $(INTSTYLE) -p $(DEVICE) -logic_opt $(MAP_LOGIC_OPT) -ol high -t $(MAP_PLACER_COST_TABLE) -xt 0 \
+         -r 4 -global_opt $(MAP_GLOBAL_OPT) -mt off -ir off -pr off -lc $(MAP_LUT_COMBINING) \
+         -power off -equivalent_register_removal $(MAP_EQUIVALENT_REGISTER_REMOVAL) \
+         -o $(NCD_MAP) $(NGD) $(PCF) | tee map.log
 
 .PHONY: re-par
 re-par $(REQ_NCD): $(REQ_NCD_MAP) $(REQ_PCF)
        cd $(OUT); \
-       par -intstyle $(INTSTYLE) $(NCD_MAP) -w $(NCD) $(PCF)
+       par -w -intstyle $(INTSTYLE) -ol high -xe n -mt off $(NCD_MAP) $(NCD) $(PCF) | tee par.log
+       cd $(OUT); \
+       trce -e 20 -tsi $(TSI) -o $(TWR) $(NCD) $(PCF)
 
 .PHONY: re-gen
-re-gen $(REQ_BIT): $(REQ_NCD)
+re-gen $(REQ_BIN): $(REQ_NCD)
        cd $(OUT); \
-       bitgen -w $(NCD) $(OUTB) $(PCF)
+       bitgen -w -g Binary:yes -g INIT_9K:Yes -g StartUpClk:Cclk $(NCD) $(OUTB) $(PCF) | tee bitgen.log
+
+.PHONY: packager
+packager $(OUT)/packager:
+       gcc packager.c -o $(OUT)/packager
+
+.PHONY: re-pkg
+re-pkg $(REQ_PKG): $(OUT)/packager $(REQ_BIN)
+       cd $(OUT); \
+       ./packager le $(BIN) $(PKG)
+
+$(OUT)/%.o: $(FIRMWARE_DIR)/%.c
+       $(TARGET_CC) $(CFLAGS) -c $< -o $@
+
+$(OUT)/%.o: $(FIRMWARE_DIR)/%.S
+       $(TARGET_CC) $(AFLAGS) -c $< -o $@
+
+$(OUT)/firmware.elf: $(OBJS)
+       $(TARGET_LD) $(LDFLAGS) -T $(FIRMWARE_DIR)/utils/tumbl.ld-script -o $@ $(OBJS)
+
+$(OUT)/bin2mem: $(FIRMWARE_DIR)/utils/bin2mem.c
+       gcc $< -o $@
+
+.PHONY: re-firmware
+re-firmware $(REQ_FIRMWARE): $(REQ_PKG) $(OUT)/bin2mem $(OUT)/firmware.elf
+       $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .text -S $(OUT)/imem.bin
+       $(TARGET_OBJCOPY) -O binary $(OUT)/firmware.elf -j .data -S $(OUT)/dmem.bin
+       $(TARGET_OBJDUMP) -DSCz $(OUT)/firmware.elf >$(OUT)/firmware.lst
+       cd $(OUT); \
+       $(TARGET_OBJDUMP) -b binary -mmbtumbl -EB -D imem.bin | sed -e 's/.data/.text/' > imem.asm
+
+# imem
+# watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80000000 -l 0x200 -f dump -u -
+# dmem
+# watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80001000 -l 0x200 -f dump -u -
+# PC
+# watch -d ./usb_sendhex -d 0x1669:0x1023 -t 4 -s 0x80003008 -l 0x4 -f dump -u -
 
 #===============================================================================
 
@@ -124,4 +254,10 @@ map: $(REQ_NCD_MAP) $(REQ_PCF)
 par: $(REQ_NCD)
 
 .PHONY: gen
-gen: $(REQ_BIT)
+gen: $(REQ_BIN)
+
+.PHONY: pkg
+pkg: $(OUT)/packager $(REQ_PKG)
+
+.PHONY: firmware
+firmware: $(REQ_FIRMWARE)