可以脱离vivado sdk gui编译和烧录的Makefile(GPT5.4帮忙写的) - minichao9901/TangNano-20k-Zynq-7020 GitHub Wiki

使用路径

Makefile

.PHONY: help build clean program program-rtt program-daplink2 hw-server

SHELL := powershell.exe
.SHELLFLAGS := -NoProfile -Command
.ONESHELL:

XILINX_SDK ?= E:\Xilinx\SDK\2018.3
XILINX_GCC_BIN ?= $(XILINX_SDK)\gnu\aarch32\nt\gcc-arm-none-eabi\bin
XSDB := $(XILINX_SDK)\bin\xsdb.bat
HW_SERVER := $(XILINX_SDK)\bin\hw_server.bat
HW_URL ?= tcp:127.0.0.1:3121
DRYRUN ?= 0
NOCON ?= 0

HWP_DIR := system_wrapper_hw_platform_0
BIT_FILE ?= $(HWP_DIR)\system_wrapper.bit
HDF_FILE ?= $(HWP_DIR)\system.hdf
PS7_INIT ?= $(HWP_DIR)\ps7_init.tcl

APP ?= usb_bsp_xusbps_daplink_2
CFG ?= Debug
APP_ELF ?= $(APP)\$(CFG)\$(APP).elf

help:
	@Write-Output "Targets:"
	@Write-Output "  make build                APP=$(APP) CFG=$(CFG)"
	@Write-Output "  make clean                APP=$(APP) CFG=$(CFG)"
	@Write-Output "  make program              BIT_FILE=... HDF_FILE=... PS7_INIT=... APP_ELF=..."
	@Write-Output "                           (set DRYRUN=1 to only generate tcl)"
	@Write-Output "                           (set NOCON=1 to skip 'con' in tcl)"
	@Write-Output ""
	@Write-Output "Shortcuts:"
	@Write-Output "  make program-rtt          (program usb_bsp_xusbps_daplink_rtt)"
	@Write-Output "  make program-daplink2     (program usb_bsp_xusbps_daplink_2)"

build:
	@$$env:PATH = "$(XILINX_GCC_BIN);$$env:PATH"; & make -C "$(APP)\$(CFG)" -f makefile "$(APP).elf"

clean:
	@$$env:PATH = "$(XILINX_GCC_BIN);$$env:PATH"; & make -C "$(APP)\$(CFG)" -f makefile clean

hw-server:
	@if (-not (Test-Path "$(HW_SERVER)")) { throw "hw_server.bat not found: $(HW_SERVER)" }
	@if (-not (Get-Process hw_server -ErrorAction SilentlyContinue)) { Start-Process "$(HW_SERVER)" -WindowStyle Hidden | Out-Null }

program: hw-server
	@if (-not (Test-Path "$(XSDB)")) { throw "xsdb.bat not found: $(XSDB). Set XILINX_SDK=.../SDK/2018.3" }
	@$$bit=(Resolve-Path "$(BIT_FILE)").Path.Replace('\','/'); $$hdf=(Resolve-Path "$(HDF_FILE)").Path.Replace('\','/'); $$ps7=(Resolve-Path "$(PS7_INIT)").Path.Replace('\','/'); $$elf=(Resolve-Path "$(APP_ELF)").Path.Replace('\','/'); $$outDir=Join-Path (Resolve-Path ".").Path ".build_sdk"; New-Item -ItemType Directory -Force $$outDir | Out-Null; $$tcl=Join-Path $$outDir "program.tcl"; $$lines=@('connect -url $(HW_URL)',('source ' + $$ps7),'targets -set -nocase -filter {name =~"APU*"} -index 0','rst -system','after 3000','targets -set -filter {level==0} -index 1',('fpga -file ' + $$bit),'targets -set -nocase -filter {name =~"APU*"} -index 0',('loadhw -hw ' + $$hdf + ' -mem-ranges [list {0x40000000 0xbfffffff}]'),'configparams force-mem-access 1','targets -set -nocase -filter {name =~"APU*"} -index 0','ps7_init','ps7_post_config','targets -set -nocase -filter {name =~ "ARM*#0"} -index 0',('dow ' + $$elf),'configparams force-mem-access 0','targets -set -nocase -filter {name =~ "ARM*#0"} -index 0'); if ("$(NOCON)" -eq "0") { $$lines += 'con' }; Set-Content -Path $$tcl -Value $$lines -Encoding ASCII; if ("$(DRYRUN)" -ne "0") { Write-Output ("Generated: " + $$tcl) } else { & "$(XSDB)" $$tcl }

program-rtt:
	@& make program APP=usb_bsp_xusbps_daplink_rtt APP_ELF=usb_bsp_xusbps_daplink_rtt\Debug\usb_bsp_xusbps_daplink_rtt.elf

program-daplink2:
	@& make program APP=usb_bsp_xusbps_daplink_2 APP_ELF=usb_bsp_xusbps_daplink_2\Debug\usb_bsp_xusbps_daplink_2.elf