###################################### # building variables ###################################### # debug build? DEBUG ?= 1 # optimization OPT ?= -Og # Set to 0 to suppress dirty submodule warning CHECK_DIRTY_SUBMODULE ?= 1 # Set to 0 to skip tools check CHECK_TOOLS ?= 1 # Set to 1 to enable 16MB external flash support. (deprecated, use EXTFLASH_SIZE_MB instead!) LARGE_FLASH ?= 0 # Configure where data is stored in the external flash by # setting EXTFLASH_OFFSET. Useful if the first 1MB are to be preserved. EXTFLASH_OFFSET ?= 0 # Configure external flash size by setting EXTFLASH_SIZE ifeq ($(LARGE_FLASH),1) # 16MB EXTFLASH_SIZE_MB ?= 16 else # 1MB EXTFLASH_SIZE_MB ?= 1 endif # Configure external flash size in MB (Megabytes) EXTFLASH_SIZE_MB ?= 1 EXTFLASH_SIZE ?= $(shell echo "$$(( $(EXTFLASH_SIZE_MB) * 1024 * 1024 ))") # Compress supported ROMs by default. Set to 0 to disable. COMPRESS ?= lz4 ifdef COMPRESS COMPRESS_PARAM := --compress=$(COMPRESS) endif # Reset the DBGMCU configuration register (DBGMCU_CR) after flashing # Set to 0 to keep the clocks running when suspended (makes debugging easier) RESET_DBGMCU ?= 1 ifeq ($(RESET_DBGMCU),1) RESET_DBGMCU_CMD = $(MAKE) reset_dbgmcu else RESET_DBGMCU_CMD = $(MAKE) reset_mcu endif PYTHON3 ?= /usr/bin/env python3 ####################################### # paths ####################################### # Build path BUILD_DIR ?= build # Common C sources C_SOURCES += \ retro-go-stm32/components/lupng/miniz.c \ retro-go-stm32/retro-go/main/gui.c \ Core/Src/porting/gw_alloc.c \ Core/Src/retro-go/rg_main.c \ Core/Src/retro-go/rg_emulators.c \ Core/Src/retro-go/rom_manager.c \ Core/Src/porting/odroid_settings.c \ Core/Src/retro-go/bitmaps/header_gb.c \ Core/Src/retro-go/bitmaps/header_nes.c \ Core/Src/retro-go/bitmaps/header_sms.c \ Core/Src/retro-go/bitmaps/header_gg.c \ Core/Src/retro-go/bitmaps/header_col.c \ Core/Src/retro-go/bitmaps/header_sg1000.c \ Core/Src/retro-go/bitmaps/header_pce.c \ Core/Src/retro-go/bitmaps/logo_gb.c \ Core/Src/retro-go/bitmaps/logo_nes.c \ Core/Src/retro-go/bitmaps/logo_sms.c \ Core/Src/retro-go/bitmaps/logo_gg.c \ Core/Src/retro-go/bitmaps/logo_col.c \ Core/Src/retro-go/bitmaps/logo_sg1000.c \ Core/Src/retro-go/bitmaps/logo_pce.c # Version and URL for the STM32CubeH7 SDK SDK_VERSION ?= v1.8.0 SDK_URL ?= https://raw.githubusercontent.com/STMicroelectronics/STM32CubeH7 # Local path for the SDK SDK_DIR ?= Drivers # SDK C sources SDK_C_SOURCES = \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_adc_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dac.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_dma.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_exti.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_flash.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_gpio.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_hsem.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_i2c.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ltdc.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_mdma.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_ospi.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_pwr.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rtc.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_sai.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_spi.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim_ex.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_tim.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_wwdg.c \ Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal.c \ # SDK ASM sources SDK_ASM_SOURCES = \ Drivers/CMSIS/Device/ST/STM32H7xx/Source/Templates/gcc/startup_stm32h7b0xx.s \ Core/Src/memcpy-armv7m.s # SDK headers SDK_HEADERS = \ Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7b0xx.h \ Drivers/CMSIS/Device/ST/STM32H7xx/Include/stm32h7xx.h \ Drivers/CMSIS/Device/ST/STM32H7xx/Include/system_stm32h7xx.h \ Drivers/CMSIS/Include/cmsis_compiler.h \ Drivers/CMSIS/Include/cmsis_gcc.h \ Drivers/CMSIS/Include/cmsis_version.h \ Drivers/CMSIS/Include/core_cm7.h \ Drivers/CMSIS/Include/mpu_armv7.h \ Drivers/STM32H7xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_ll_adc.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_adc_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_cortex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dac_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dac.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_def.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dma_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_dma.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_exti.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_flash_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_flash.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_gpio_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_gpio.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_hsem.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_i2c_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_i2c.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ltdc_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ltdc.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_mdma.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_ospi.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_pwr_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_pwr.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rcc_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rcc.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rtc_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_rtc.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_sai.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_spi_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_spi.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_tim.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_tim_ex.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal_wwdg.h \ Drivers/STM32H7xx_HAL_Driver/Inc/stm32h7xx_hal.h \ ####################################### # binaries ####################################### PREFIX = arm-none-eabi- # The gcc compiler bin path can be either defined in make command via GCC_PATH variable (> make GCC_PATH=xxx) # either it can be added to the PATH environment variable. ifdef GCC_PATH CC = $(GCC_PATH)/$(PREFIX)gcc CXX = $(GCC_PATH)/$(PREFIX)g++ AS = $(GCC_PATH)/$(PREFIX)gcc -x assembler-with-cpp CP = $(GCC_PATH)/$(PREFIX)objcopy SZ = $(GCC_PATH)/$(PREFIX)size GDB = $(GCC_PATH)/$(PREFIX)gdb DUMP = $(GCC_PATH)/$(PREFIX)objdump else CC = $(PREFIX)gcc CXX = $(PREFIX)g++ AS = $(PREFIX)gcc -x assembler-with-cpp CP = $(PREFIX)objcopy SZ = $(PREFIX)size GDB = $(PREFIX)gdb DUMP = $(PREFIX)objdump endif HEX = $(CP) -O ihex BIN = $(CP) -O binary -S ECHO = echo TOUCH = touch ####################################### # CFLAGS ####################################### # cpu CPU = -mcpu=cortex-m7 -mtune=cortex-m7 # fpu FPU = -mfpu=fpv5-d16 # float-abi FLOAT-ABI = -mfloat-abi=hard # mcu MCU = $(CPU) -mthumb -mno-unaligned-access $(FPU) $(FLOAT-ABI) # macros for gcc # AS defines AS_DEFS += # C defines C_DEFS += \ -DUSE_HAL_DRIVER \ -DSTM32H7B0xx \ -DVECT_TAB_ITCM \ -DIS_LITTLE_ENDIAN \ -DDEBUG_RG_ALLOC \ -DMINIZ_NO_TIME # AS includes AS_INCLUDES += # C includes C_INCLUDES += \ -ICore/Inc \ -ICore/Inc/porting \ -ICore/Inc/porting/gb \ -ICore/Inc/porting/nes \ -ICore/Inc/porting/smsplusgx \ -ICore/Inc/porting/pce \ -ICore/Inc/porting/snes9x \ -ICore/Inc/retro-go \ -IDrivers/STM32H7xx_HAL_Driver/Inc \ -IDrivers/STM32H7xx_HAL_Driver/Inc/Legacy \ -IDrivers/CMSIS/Device/ST/STM32H7xx/Include \ -IDrivers/CMSIS/Include \ -Iretro-go-stm32/components/miniz \ -Iretro-go-stm32/components/lupng \ CXX_INCLUDES = \ -I3rdparty/snes9x \ -I3rdparty/snes9x/apu \ -I3rdparty/snes9x/apu/bapu/dsp \ -I3rdparty/snes9x/apu/bapu/smp \ # Force include the configuration CFLAGS += $(CFLAGS_EXTRA) -include $(BUILD_DIR)/config.h # compile gcc flags ASFLAGS += $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections CFLAGS += $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections ifeq ($(DEBUG), 1) CFLAGS += -g -gdwarf-2 endif CFLAGS += -fstack-usage -Wstack-usage=20480 # Generate dependency information CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)" CXXFLAGS = $(CFLAGS) $(CXX_INCLUDES) \ -fno-rtti \ -fno-exceptions \ -fno-math-errno \ -fomit-frame-pointer \ -fno-stack-protector \ -DRIGHTSHIFT_IS_SAR \ -DHAVE_STDINT_H \ -DIS_LITTLE_ENDIAN \ -Wno-error=format-truncation LDFLAGS += -Wl,--defsym=__EXTFLASH_OFFSET__=$(EXTFLASH_OFFSET) LDFLAGS += -Wl,--defsym=__EXTFLASH_TOTAL_LENGTH__=$(EXTFLASH_SIZE) ####################################### # LDFLAGS ####################################### # link script LDSCRIPT ?= STM32H7B0VBTx_FLASH.ld # libraries LIBS = -lc -lm -lnosys CXXLIBS = -lstdc++ LIBDIR += LDFLAGS += $(MCU) -specs=nano.specs -T$(LDSCRIPT) $(LIBDIR) $(LIBS) $(CXXLIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections # default action: build all all: $(BUILD_DIR) $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET)_extflash.bin $(BUILD_DIR)/$(TARGET)_intflash.bin ####################################### # build the application ####################################### # list of objects # CC OBJECTS = $(addprefix $(BUILD_DIR)/core/,$(notdir $(C_SOURCES:.c=.o) $(SDK_C_SOURCES:.c=.o))) GNUBOY_OBJECTS = $(addprefix $(BUILD_DIR)/gnuboy/,$(notdir $(GNUBOY_C_SOURCES:.c=.o))) NES_OBJECTS = $(addprefix $(BUILD_DIR)/nes/,$(notdir $(NES_C_SOURCES:.c=.o))) SMSPLUSGX_OBJECTS = $(addprefix $(BUILD_DIR)/smsplusgx/,$(notdir $(SMSPLUSGX_C_SOURCES:.c=.o))) PCE_OBJECTS = $(addprefix $(BUILD_DIR)/pce/,$(notdir $(PCE_C_SOURCES:.c=.o))) vpath %.c $(sort $(dir $(C_SOURCES) $(NES_C_SOURCES) $(GNUBOY_C_SOURCES) $(SMSPLUSGX_C_SOURCES) $(PCE_C_SOURCES) $(SDK_C_SOURCES))) # CXX CXX_OBJECTS = $(addprefix $(BUILD_DIR)/core/,$(notdir $(CXX_SOURCES:.cpp=.o) )) SNES9X_OBJECTS = $(addprefix $(BUILD_DIR)/snes9x/,$(notdir $(SNES9X_CXX_SOURCES:.cpp=.o))) vpath %.cpp $(sort $(dir $(CXX_SOURCES) $(SNES9X_CXX_SOURCES) )) # list of ASM program objects OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(SDK_ASM_SOURCES:.s=.o))) vpath %.s $(sort $(dir $(SDK_ASM_SOURCES))) OBJECTS += $(addprefix $(BUILD_DIR)/,roms.a) # function used to generate prerequisite rules for SDK objects define sdk_obj_prereq_gen $(BUILD_DIR)/$(patsubst %.c,%.o,$(patsubst %.s,%.o,$(notdir $1))): $1 endef # note: the blank line above is intentional # generate all object prerequisite rules $(eval $(foreach obj,$(SDK_C_SOURCES) $(SDK_ASM_SOURCES),$(call sdk_obj_prereq_gen,$(obj)))) FORCE: Core/Inc/githash.h: FORCE | $(BUILD_DIR) $(V)./scripts/update_githash.sh $@ # Run parse_roms.py to generate information about the roms $(BUILD_DIR)/rom_files.txt: FORCE | $(BUILD_DIR) $(V)$(ECHO) [ BASH ] Checking for updated roms $(V)./scripts/update_rom_files.sh build/rom_files.txt roms/* $(BUILD_DIR)/roms.a: $(BUILD_DIR)/rom_files.txt parse_roms.py $(V)$(ECHO) [ PYTHON3 ] $(notdir $<) $(V)$(PYTHON3) parse_roms.py --flash-size $(EXTFLASH_SIZE) $(COMPRESS_PARAM) $(BUILD_DIR)/config.h $(BUILD_DIR)/saveflash.ld &: $(BUILD_DIR)/roms.a $(V)/bin/sh -c true STM32H7B0VBTx_FLASH.ld: $(BUILD_DIR)/saveflash.ld # rom_manager.c depends on the different *_roms.c files but they only change when roms.a changes $(BUILD_DIR)/core/rom_manager.o: Core/Src/retro-go/rom_manager.c $(BUILD_DIR)/roms.a Core/Src/main.c: Core/Inc/githash.h Core/Src/retro-go/rg_main.c: Core/Inc/githash.h ifeq (${CHECK_DIRTY_SUBMODULE},1) CheckDirtySubmodules: $(V)git submodule foreach "git diff --quiet" 2> /dev/null || \ (echo -e "\n\n\nYou have changes in the submodule. This is not normal.\nPlease clean the submodule by running 'git submodule update --init'\n\n(You may set CHECK_DIRTY_SUBMODULE=0 to suppress this warning)\n\n\n" && exit 1) $(V)git submodule status | grep -v '+' 2> /dev/null > /dev/null || \ (echo -e "\n\n\nYou are using a submodule that is not updated.\nPlease sync the submodules by running 'git submodule update --init'\n\n(You may set CHECK_DIRTY_SUBMODULE=0 to suppress this warning)\n\n\n" && exit 1) else CheckDirtySubmodules: endif .PHONY: CheckDirtySubmodules ifeq (${CHECK_TOOLS},1) CheckTools: $(V)$(CC) -v 2>&1 | grep "gcc version 1[01]" > /dev/null || \ ( \ echo -e "\n\n\nPlease use GCC version 10\n\n\nYou are using:" && \ $(CC) -v 2>&1 | grep "gcc version" ; \ echo -e "\n\n\n" && \ exit 1 \ ) $(V)$(CP) --info | grep "elf32-littlearm" > /dev/null || \ ( \ echo -e "\n\n\nobjcopy seems to be missing or not suport elf32-littlearm. Please install binutils.\n\n\n" && \ exit 1 \ ) $(V)$(DUMP) --help | grep "armv7e-m" > /dev/null || \ ( \ echo -e "\n\n\nobjdump seems to be missing or not suport armv7e-m. Please install binutils.\n\n\n" && \ exit 1 \ ) else CheckTools: endif .PHONY: CheckTools $(BUILD_DIR)/%.o: %.s Makefile.common Makefile $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ AS ] $(notdir $<) $(V)$(AS) -c $(CFLAGS) $< -o $@ $(BUILD_DIR)/$(TARGET).elf: CheckTools $(OBJECTS) $(NES_OBJECTS) $(GNUBOY_OBJECTS) $(SMSPLUSGX_OBJECTS) $(PCE_OBJECTS) $(CXX_OBJECTS) $(SNES9X_OBJECTS) Makefile.common Makefile $(LDSCRIPT) $(V)$(ECHO) [ LD ] $(notdir $@) $(V)$(CC) $(OBJECTS) $(NES_OBJECTS) $(GNUBOY_OBJECTS) $(SMSPLUSGX_OBJECTS) $(PCE_OBJECTS) $(CXX_OBJECTS) $(SNES9X_OBJECTS) $(LDFLAGS) -o $@ $(V)$(SZ) $@ $(V)./scripts/size.sh $@ # CC $(BUILD_DIR)/core/%.o: %.c Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CC core ] $(notdir $<) $(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/core/$(notdir $(<:.c=.lst)) $< -o $@ $(BUILD_DIR)/nes/%.o: %.c Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CC nes ] $(notdir $<) $(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/nes/$(notdir $(<:.c=.lst)) $< -o $@ $(BUILD_DIR)/gnuboy/%.o: %.c Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CC gb ] $(notdir $<) $(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/gnuboy/$(notdir $(<:.c=.lst)) $< -o $@ $(BUILD_DIR)/smsplusgx/%.o: %.c Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CC sms ] $(notdir $<) $(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/smsplusgx/$(notdir $(<:.c=.lst)) $< -o $@ $(BUILD_DIR)/pce/%.o: %.c Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CC pce ] $(notdir $<) $(V)$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/pce/$(notdir $(<:.c=.lst)) $< -o $@ # CXX $(BUILD_DIR)/core/%.o: %.cpp Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CXX core ] $(notdir $<) $(V)$(CXX) -c $(CXXFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/core/$(notdir $(<:.cpp=.lst)) $< -o $@ $(BUILD_DIR)/snes9x/%.o: %.cpp Makefile Makefile.common $(SDK_HEADERS) $(BUILD_DIR)/config.h | $(BUILD_DIR) CheckDirtySubmodules $(V)$(ECHO) [ CXX SNES9X ] $(notdir $<) $(V)$(CXX) -c $(CXXFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/snes9x/$(notdir $(<:.cpp=.lst)) $< -o $@ $(BUILD_DIR): $(V)mkdir $@ $(V)mkdir $@/core $(V)mkdir $@/nes $(V)mkdir $@/gnuboy $(V)mkdir $@/smsplusgx $(V)mkdir $@/pce $(V)mkdir $@/snes9x ####################################### # Flashing ####################################### OPENOCD ?= openocd ADAPTER ?= stlink FLASHAPP ?= scripts/flash_multi.sh FLASHTEST ?= scripts/flashapp.sh --test # Starts openocd and attaches to the target. To be used with 'flash_intflash_nc' and 'gdb' openocd: $(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; halt" .PHONY: openocd # Programs the internal flash using a new OpenOCD instance flash_intflash: $(BUILD_DIR)/$(TARGET)_intflash.bin $(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "program $< 0x08000000 verify reset exit" .PHONY: flash_intflash # Flashes using an existing openocd instance flash_intflash_nc: $(BUILD_DIR)/$(TARGET)_intflash.bin echo "program $< 0x08000000 verify reset" | nc -c localhost 4444 .PHONY: flashx flash_extflash: $(BUILD_DIR)/$(TARGET)_extflash.bin $(FLASHAPP) $(BUILD_DIR)/$(TARGET)_extflash.bin $(EXTFLASH_OFFSET) .PHONY: flash_extflash flash_test: flash_intflash $(FLASHTEST) .PHONY: flash_test # Programs both the external and internal flash. flash: $(V)$(MAKE) flash_intflash $(V)$(MAKE) flash_extflash $(V)$(RESET_DBGMCU_CMD) .PHONY: flash # Alias for flash flash_all: flash # Transfers save files from the device to the host machine flash_saves_backup: $(BUILD_DIR)/$(TARGET).elf $(V)./scripts/saves_backup.sh $< .PHONY: flash_saves_backup # Transfers save files from the host machine to the device flash_saves_restore: $(BUILD_DIR)/$(TARGET).elf $(V)./scripts/saves_restore.sh $< .PHONY: flash_saves_restore # Erases the saveflash area on the device flash_saves_erase: $(BUILD_DIR)/$(TARGET).elf $(V)./scripts/saves_erase.sh $< .PHONY: flash_saves_erase reset_dbgmcu: # Reset the DBGMCU configuration register (DBGMCU_CR) $(V)$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; reset halt; mww 0x5C001004 0x00000000; resume; exit;" .PHONY: reset_dbgmcu reset_mcu: $(V)$(OPENOCD) -f scripts/interface_$(ADAPTER).cfg -c "init; reset run; exit;" 2> $(BUILD_DIR)/openocd.log .PHONY: reset_mcu gdb: $(BUILD_DIR)/$(TARGET).elf $(GDB) $< -ex "target extended-remote :3333" .PHONY: gdb # Flashes intflash *only* and launches gdb afterwards gdb_intflash: flash_intflash_nc gdb .PHONY: gdb_intflash dump_logs: $(BUILD_DIR)/$(TARGET).elf $(V)./scripts/dump_logs.sh .PHONY: dump_logs help: @echo "Game and Watch Retro Go" @echo "" @echo "Configuration variables:" @echo " EXTFLASH_SIZE_MB - Sets the external flash size in MB" @echo " EXTFLASH_SIZE - Sets the external flash size in bytes (deprecated)" @echo " LARGE_FLASH - Sets the external flash size to 16MB (deprecated)" @echo " EXTFLASH_OFFSET - Places the data at an offset in the external flash (useful for dual boot)" @echo " RESET_DBGMCU - Configures if DBGMCU should be reset after flashing." @echo " Set to 0 to disable power saving (default=1)" @echo "" @echo "Current configuration:" @echo " EXTFLASH_SIZE_MB=$(EXTFLASH_SIZE_MB)" @echo " EXTFLASH_SIZE=$(EXTFLASH_SIZE)" @echo " LARGE_FLASH=$(LARGE_FLASH)" @echo " EXTFLASH_OFFSET=$(EXTFLASH_OFFSET)" @echo " RESET_DBGMCU=$(RESET_DBGMCU)" @echo " GCC_PATH=$(GCC_PATH)" @echo " PREFIX=$(PREFIX)" @echo "" @echo "Targets:" @echo " flash_extflash - Only programs the external flash" @echo " flash_intflash - Only programs the internal flash" @echo " flash_intflash_nc - Only programs the internal flash and uses an existing openocd server" @echo " flash_test - Runs a flash test. Will overwrite data on the external flash!" @echo " gdb - Starts gdb and attaches to openocd" @echo " gdb_intflash - Runs flash_intflash_nc, then starts gdb and attaches to openocd" @echo " openocd - Starts openocd with appropriate config" @echo " reset_dbgmcu - Resets the unit and turns off DBGMCU (lowers battery drain)" @echo " reset_mcu - Resets the unit" @echo " dump_logs - Dumps the callstack and logbuf. Starts openocd and gdb under the hood." @echo "" .PHONY: help ####################################### # download SDK files ####################################### $(SDK_DIR)/%: $(V)$(ECHO) [ WGET ] $(notdir $@) $(V)wget -q $(SDK_URL)/$(SDK_VERSION)/$@ -P $(dir $@) .PHONY: download_sdk download_sdk: $(SDK_HEADERS) $(SDK_C_SOURCES) $(SDK_ASM_SOURCES) ####################################### # clean up ####################################### clean: $(V)$(ECHO) [ RM ] $(BUILD_DIR) $(V)-rm -fR $(BUILD_DIR) distclean: clean $(V)$(ECHO) [ RM ] $(SDK_DIR) $(V)rm -rf $(SDK_DIR) ####################################### # dependencies ####################################### -include $(wildcard $(BUILD_DIR)/*.d) # *** EOF ***