diff --git a/build.sh b/build.sh index d5c8053..cc036aa 100755 --- a/build.sh +++ b/build.sh @@ -3,10 +3,10 @@ PACKAGE_FILE_NAME="SummerCart64" FILES=( - "./fw/output_files/SummerCart64.pof" - "./hw/v1/ftdi-template.xml" + "./fw/output_files/SC64_update.bin" + "./fw/output_files/SC64_update.pof" + "./hw/ftdi-template.xml" "./sw/cic/UltraCIC-III.hex" - "./sw/riscv/build/controller.rom" "./LICENSE" ) @@ -35,6 +35,10 @@ popd pushd fw echo "Building FPGA firmware" quartus_sh --flow compile ./SummerCart64.qpf +quartus_cpf -c ./SummerCart64.cof +cp output_files/SC64_firmware.pof output_files/SC64_update.pof +cat output_files/sc64_firmware_ufm_auto.rpd output_files/sc64_firmware_cfm0_auto.rpd > output_files/SC64_update_LE.bin +riscv32-unknown-elf-objcopy -I binary -O binary --reverse-bytes=4 output_files/SC64_update_LE.bin output_files/SC64_update.bin popd diff --git a/build_in_docker.sh b/build_in_docker.sh index 7405b54..dded6f2 100755 --- a/build_in_docker.sh +++ b/build_in_docker.sh @@ -1,3 +1,6 @@ #!/bin/bash -docker run --mount type=bind,src="$(pwd)",target="/workdir" ghcr.io/polprzewodnikowy/sc64env:v1.0 /bin/bash ./build.sh +docker run \ + --mount type=bind,src="$(pwd)",target="/workdir" \ + ghcr.io/polprzewodnikowy/sc64env:v1.0 \ + /bin/bash -c "./build.sh" diff --git a/fw/SummerCart64.cof b/fw/SummerCart64.cof new file mode 100644 index 0000000..bf1be85 --- /dev/null +++ b/fw/SummerCart64.cof @@ -0,0 +1,42 @@ + + + output_files/SC64_firmware.pof + 1 + 1 + 14 + + Page_0 + 1 + + output_files/SummerCart64.sof1 + + + 10 + 0 + 0 + 1 + 0 + + 1 + + + 0 + 1 + 0 + 0 + 0 + 0 + 2 + ../sw/n64/build/SummerLoader64.hex + ../sw/riscv/build/controller.hex + 305152 + + + 1 + 2 + 0 + -1 + -1 + 1 + + \ No newline at end of file diff --git a/fw/SummerCart64.qsf b/fw/SummerCart64.qsf index 1987b3c..f35482f 100644 --- a/fw/SummerCart64.qsf +++ b/fw/SummerCart64.qsf @@ -19,7 +19,7 @@ # # Quartus Prime # Version 20.1.1 Build 720 11/11/2020 SJ Lite Edition -# Date created = 21:23:28 September 18, 2021 +# Date created = 23:19:06 October 24, 2021 # # -------------------------------------------------------------------------- # # @@ -86,7 +86,6 @@ set_global_assignment -name SYSTEMVERILOG_FILE rtl/system/sc64.sv set_global_assignment -name SYSTEMVERILOG_FILE rtl/system/system.sv set_global_assignment -name SYSTEMVERILOG_FILE rtl/usb/usb_ft1248.sv set_global_assignment -name SIGNALTAP_FILE output_files/signaltap.stp -set_global_assignment -name SLD_FILE db/signaltap_auto_stripped.stp # Pin & Location Assignments # ========================== diff --git a/fw/build.sh b/fw/build.sh index 4c1b7c8..c30bed2 100755 --- a/fw/build.sh +++ b/fw/build.sh @@ -1,3 +1,13 @@ #!/bin/bash -docker run --mount type=bind,src="$(pwd)/..",target="/workdir" ghcr.io/polprzewodnikowy/sc64env:v1.0 /bin/bash -c "cd fw && quartus_sh --flow compile ./SummerCart64.qpf" +docker run \ + --mount type=bind,src="$(pwd)/..",target="/workdir" \ + ghcr.io/polprzewodnikowy/sc64env:v1.0 \ + /bin/bash -c " \ + cd fw && \ + quartus_sh --flow compile ./SummerCart64.qpf && \ + quartus_cpf -c ./SummerCart64.cof && \ + cp output_files/SC64_firmware.pof output_files/SC64_update.pof && \ + cat output_files/sc64_firmware_ufm_auto.rpd output_files/sc64_firmware_cfm0_auto.rpd > output_files/SC64_update_LE.bin && \ + riscv32-unknown-elf-objcopy -I binary -O binary --reverse-bytes=4 output_files/SC64_update_LE.bin output_files/SC64_update.bin + " diff --git a/fw/rtl/cpu/cpu_cfg.sv b/fw/rtl/cpu/cpu_cfg.sv index 426b1b9..275ab66 100644 --- a/fw/rtl/cpu/cpu_cfg.sv +++ b/fw/rtl/cpu/cpu_cfg.sv @@ -30,7 +30,7 @@ module cpu_cfg ( R_SCR: bus.rdata = { cfg.cpu_ready, cfg.cpu_busy, - cfg.usb_waiting, + 1'b0, cfg.cmd_error, 21'd0, skip_bootloader, @@ -65,7 +65,6 @@ module cpu_cfg ( if (sys.reset) begin cfg.cpu_ready <= 1'b0; cfg.cpu_busy <= 1'b0; - cfg.usb_waiting <= 1'b0; cfg.cmd_error <= 1'b0; cfg.sdram_switch <= 1'b0; cfg.sdram_writable <= 1'b0; @@ -91,9 +90,8 @@ module cpu_cfg ( { cfg.cpu_ready, cfg.cpu_busy, - cfg.usb_waiting, cfg.cmd_error - } <= bus.wdata[31:28]; + } <= {bus.wdata[31:30], bus.wdata[28]}; end if (bus.wmask[0]) begin { diff --git a/fw/rtl/n64/n64_cfg.sv b/fw/rtl/n64/n64_cfg.sv index 49d6023..486d343 100644 --- a/fw/rtl/n64/n64_cfg.sv +++ b/fw/rtl/n64/n64_cfg.sv @@ -29,7 +29,7 @@ module n64_cfg ( R_SR: bus.rdata = { cfg.cpu_ready, cfg.cpu_busy, - cfg.usb_waiting, + 1'b0, cfg.cmd_error, 12'd0 }; diff --git a/fw/rtl/system/config.sv b/fw/rtl/system/config.sv index fa4b8e3..42e4820 100644 --- a/fw/rtl/system/config.sv +++ b/fw/rtl/system/config.sv @@ -2,7 +2,6 @@ interface if_config (); logic cpu_ready; logic cpu_busy; - logic usb_waiting; logic cmd_error; logic cmd_request; logic [7:0] cmd; @@ -38,7 +37,6 @@ interface if_config (); modport n64 ( input cpu_ready, input cpu_busy, - input usb_waiting, input cmd_error, output cmd_request, output cmd, @@ -50,7 +48,6 @@ interface if_config (); modport cpu ( output cpu_ready, output cpu_busy, - output usb_waiting, output cmd_error, input cmd_request, input cmd, diff --git a/sw/n64/.gitignore b/sw/n64/.gitignore index e53d106..23dcf96 100644 --- a/sw/n64/.gitignore +++ b/sw/n64/.gitignore @@ -1,2 +1,2 @@ /build -/what \ No newline at end of file +*.z64 diff --git a/sw/n64/Makefile b/sw/n64/Makefile index f835a6f..e46c4df 100644 --- a/sw/n64/Makefile +++ b/sw/n64/Makefile @@ -1,69 +1,28 @@ -ROOTDIR = $(N64_INST) - -GCCN64PREFIX = $(ROOTDIR)/bin/mips64-elf- -CC = $(GCCN64PREFIX)gcc -AS = $(GCCN64PREFIX)as -LD = $(GCCN64PREFIX)ld -OBJCOPY = $(GCCN64PREFIX)objcopy -OBJDUMP = $(GCCN64PREFIX)objdump - -CHKSUM64 = $(ROOTDIR)/bin/chksum64 -MKSPRITE = $(ROOTDIR)/bin/mksprite -N64TOOL = $(ROOTDIR)/bin/n64tool - -HEADER_PATH = $(ROOTDIR)/mips64-elf/lib -HEADER_NAME = header - -PROG_NAME = SummerLoader64 - -ROM_SIZE = 1028k - -SOURCE_DIR = src BUILD_DIR = build +SOURCE_DIR = src +PROGRAM_NAME = SummerLoader64 -SRC_DIRS = $(SOURCE_DIR) $(sort $(dir $(wildcard $(SOURCE_DIR)/*/.))) -INC_DIRS = $(addprefix -I, . $(SRC_DIRS)) -I./libsc64/inc -SRC_FILES = $(wildcard $(patsubst %, %/*.c, . $(SRC_DIRS))) -# IMG_FILES = $(wildcard $(patsubst %, %/*.png, . $(SRC_DIRS))) -OBJ_FILES = $(addprefix $(BUILD_DIR)/, $(notdir $(IMG_FILES:.png=.o) $(SRC_FILES:.c=.o))) +include $(N64_INST)/include/n64.mk -VPATH = $(SRC_DIRS) +src = main.c sc64.c boot.c crc32.c -COMMONFLAGS = -march=vr4300 -mtune=vr4300 -ASFLAGS = $(COMMONFLAGS) -CFLAGS = $(COMMONFLAGS) -std=gnu11 -Os -Wall -I$(ROOTDIR)/mips64-elf/include $(INC_DIRS) -ffunction-sections -fdata-sections -Wl,--gc-sections -LINK_FLAGS = -L$(ROOTDIR)/mips64-elf/lib -ldragon -lc -lm -ldragonsys -Tn64.ld -#-L./libsc64/lib -lsc64_libdragon -N64_FLAGS = -l $(ROM_SIZE) -h $(HEADER_PATH)/$(HEADER_NAME) -o $(BUILD_DIR)/$(PROG_NAME).z64 +all: $(BUILD_DIR)/$(PROGRAM_NAME).hex -all: make_output_dir $(BUILD_DIR)/$(PROG_NAME).z64 +$(BUILD_DIR)/$(PROGRAM_NAME).elf: $(src:%.c=$(BUILD_DIR)/%.o) -$(OBJ_FILES): Makefile +$(PROGRAM_NAME).z64: N64_ROM_TITLE="$(PROGRAM_NAME)" -$(BUILD_DIR)/$(PROG_NAME).z64: $(BUILD_DIR)/$(PROG_NAME).elf - $(OBJCOPY) $(BUILD_DIR)/$(PROG_NAME).elf $(BUILD_DIR)/$(PROG_NAME).bin -O binary - $(OBJDUMP) -S $(BUILD_DIR)/$(PROG_NAME).elf > $(BUILD_DIR)/$(PROG_NAME).lst - $(N64TOOL) $(N64_FLAGS) -t $(PROG_NAME) $(BUILD_DIR)/$(PROG_NAME).bin - $(CHKSUM64) $(BUILD_DIR)/$(PROG_NAME).z64 - truncate --size=90k $(BUILD_DIR)/$(PROG_NAME).z64 - $(OBJCOPY) $(BUILD_DIR)/$(PROG_NAME).z64 $(BUILD_DIR)/$(PROG_NAME).hex -I binary -O ihex - -$(BUILD_DIR)/$(PROG_NAME).elf: $(OBJ_FILES) - $(LD) -o $(BUILD_DIR)/$(PROG_NAME).elf $(OBJ_FILES) $(LINK_FLAGS) - -$(BUILD_DIR)/%.o: %.c - $(COMPILE.c) $(OUTPUT_OPTION) $< - -# $(BUILD_DIR)/%.sprite: $(IMG_FILES) -# $(MKSPRITE) 32 $< $@ - -# $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.sprite -# $(OBJCOPY) -I binary -O elf32-bigmips -B mips:4000 --rename-section .data=.rodata $< $@ - -make_output_dir: - $(shell mkdir ./$(BUILD_DIR) 2> /dev/null) +$(BUILD_DIR)/$(PROGRAM_NAME).hex: $(PROGRAM_NAME).z64 + sed 's/\x00*$$//' $(PROGRAM_NAME).z64 > $(BUILD_DIR)/$(PROGRAM_NAME)_stripped.z64 + @if [ $$(stat -L -c %s $(BUILD_DIR)/$(PROGRAM_NAME)_stripped.z64) -gt 92160 ]; then\ + echo "\n Error: stripped file size is larger than 90kB thus cannot fit inside FPGA flash.\n"; exit 1;\ + fi + truncate --size=90k $(BUILD_DIR)/$(PROGRAM_NAME)_stripped.z64 + $(N64_OBJCOPY) -I binary -O ihex $(BUILD_DIR)/$(PROGRAM_NAME)_stripped.z64 $(BUILD_DIR)/$(PROGRAM_NAME).hex clean: - $(shell rm -rf ./$(BUILD_DIR) 2> /dev/null) + rm -rf ./$(BUILD_DIR) ./$(PROGRAM_NAME).z64 -.PHONY: all clean make_output_dir +-include $(wildcard $(BUILD_DIR)/*.d) + +.PHONY: all clean diff --git a/sw/n64/build.sh b/sw/n64/build.sh index faeb3d6..a048919 100755 --- a/sw/n64/build.sh +++ b/sw/n64/build.sh @@ -1,3 +1,6 @@ #!/bin/bash -docker run --mount type=bind,src="$(pwd)",target="/workdir" ghcr.io/polprzewodnikowy/sc64env:v1.0 /bin/bash -c "make clean all" +docker run \ + --mount type=bind,src="$(pwd)",target="/workdir" \ + ghcr.io/polprzewodnikowy/sc64env:v1.0 \ + /bin/bash -c "make clean all" diff --git a/sw/n64/src/boot/boot.c b/sw/n64/src/boot.c similarity index 100% rename from sw/n64/src/boot/boot.c rename to sw/n64/src/boot.c diff --git a/sw/n64/src/boot/boot.h b/sw/n64/src/boot.h similarity index 100% rename from sw/n64/src/boot/boot.h rename to sw/n64/src/boot.h diff --git a/sw/n64/src/boot/crc32.c b/sw/n64/src/crc32.c similarity index 100% rename from sw/n64/src/boot/crc32.c rename to sw/n64/src/crc32.c diff --git a/sw/n64/src/boot/crc32.h b/sw/n64/src/crc32.h similarity index 100% rename from sw/n64/src/boot/crc32.h rename to sw/n64/src/crc32.h diff --git a/sw/n64/src/main.c b/sw/n64/src/main.c index 1e0aac6..3535426 100644 --- a/sw/n64/src/main.c +++ b/sw/n64/src/main.c @@ -1,5 +1,5 @@ #include "sc64.h" -#include "boot/boot.h" +#include "boot.h" int main(void) { diff --git a/sw/n64/src/boot/n64_regs.h b/sw/n64/src/n64_regs.h similarity index 100% rename from sw/n64/src/boot/n64_regs.h rename to sw/n64/src/n64_regs.h diff --git a/sw/riscv/Makefile b/sw/riscv/Makefile index d4db2a9..897e6c5 100644 --- a/sw/riscv/Makefile +++ b/sw/riscv/Makefile @@ -29,6 +29,7 @@ $(BUILD_DIR)/uc.elf: $(OBJS) SC64.ld $(BUILD_DIR)/controller.rom: $(BUILD_DIR)/uc.elf $(OBJCOPY) -R .bootloader $(BUILD_DIR)/uc.elf $(BUILD_DIR)/controller.elf $(OBJCOPY) -O binary --set-section-flags .bss=alloc,contents $(BUILD_DIR)/controller.elf $(BUILD_DIR)/controller.bin + $(OBJCOPY) -I binary -O ihex $(BUILD_DIR)/controller.bin $(BUILD_DIR)/controller.hex python3 tools/bin2rom.py $@ < $(BUILD_DIR)/controller.bin @echo 'Size of controller modules:' @$(SIZE) -B -t --common $(OBJS) diff --git a/sw/riscv/build.sh b/sw/riscv/build.sh index 1c0ceb8..024bdf7 100755 --- a/sw/riscv/build.sh +++ b/sw/riscv/build.sh @@ -1,3 +1,6 @@ #!/bin/bash -docker run --mount type=bind,src="$(pwd)",target="/workdir" ghcr.io/polprzewodnikowy/sc64env:v1.0 /bin/bash -c "USER_FLAGS=\"-DDEBUG\" make clean all" +docker run \ + --mount type=bind,src="$(pwd)",target="/workdir" \ + ghcr.io/polprzewodnikowy/sc64env:v1.0 \ + /bin/bash -c "USER_FLAGS=\"-DDEBUG\" make clean all"