Compare commits

..
16 Commits
Author SHA1 Message Date
Gatsby d13f6cb8b3 refactor(platform/xilinx): replace symbolic links with hard links for better compatibility
- Replaced symbolic links with hard links in the Vitis project source management.
- Symbolic links often cause reference issues during debugging in Xilinx Vitis.
- This change improves source visibility and debugger integration.
2025-06-13 12:24:45 +08:00
Gatsby 0eb4535dc8 bug(platform/xilinx): fix variable typo 2025-05-09 22:43:58 +08:00
Gatsby 94c8d59201 chore(platform/xilinx): add variable checks and clean up Makefile 2025-05-09 22:30:16 +08:00
Gatsby 5fd695266f refactor(make): reorganize targets and improve locking mechanism
1.	Introduce a “project lock” mechanism alongside the existing “build lock”; the lock file is now generated within the platform-specific Makefile.
2.	Set `project` as the default Makefile goal for consistency.
3.	Remove the `standalone` target to improve compatibility, especially when invoked via `make -f`.
4.	Simplify target dependencies for better maintainability and clarity.
2025-05-09 22:27:52 +08:00
Gatsby 698e123a26 chore: refine common commands 2025-05-09 22:22:40 +08:00
Gatsby Van 751071d670 refactor(platform/xilinx): use tcl command to create links eliminating the need for administrator privileges on Windows 2025-02-24 01:40:14 +08:00
Gatsby Van af260c1610 docs(platform/xilinx): update path descriptions in documentation 2024-11-06 00:33:15 +08:00
Gatsby Van caa636018b refactor: make paths relative to current working directory
- Allows configuration files to be placed in separate folders, with paths in config files now relative to the config file's location.
- Added `cd /d "%~dp0"` at the beginning of the `.bat` template to ensure paths are based on the script's location, enhancing portability and consistency.
2024-11-06 00:32:04 +08:00
Gatsby Van 94aea3524e chore: fix typo 2024-11-05 23:49:32 +08:00
Gatsby Van 906df8b40a fix(platform/xilinx): correct option from -template to -app in Xilinx SDK setup
Replaces the incorrect `-template` option with `-app` for proper Xilinx SDK project configuration, resolving an issue introduced in the last commit.
2024-11-04 20:36:33 +08:00
Gatsby Van 38d3fd5667 chore(makefile): add @ to silence specific print commands 2024-11-04 20:36:33 +08:00
Gatsby Van eb3ca273b4 refactor(platform/xilinx): strengthen parameter validation 2024-11-04 20:36:33 +08:00
Gatsby Van af92cd0a53 feat(platform/xilinx): add support for specifying application template 2024-11-04 20:36:33 +08:00
Gatsby Van 61da61b28e refactor(platform/xilinx): modify default BSP/Domain names to reduce conflicts 2024-11-04 20:36:33 +08:00
Gatsby Van c042d2c391 fix(platform/xilinx): fix(platform/xilinx): ensure domain is generated post-creation 2024-11-04 20:36:33 +08:00
Gatsby 1ccae2ebed docs: add common issue regarding symbolic links on Windows 2024-11-04 20:36:22 +08:00
5 changed files with 143 additions and 132 deletions
+39 -65
View File
@@ -5,53 +5,48 @@ HIDE = > /dev/zero
endif
TIMESTAMP = $(shell date +"%T")
copy_files = cp $(1) $(2)
copy_dir = cp -r $(1) $(2)
remove_file = rm -rf $(1)
remove_dir = rm -rf $(1)
mk_dir = mkdir -p $(1)
read_file = cat $(1) 2>/dev/null
print_lines = echo $(1) | tr ' ' '\n'
green = \\e[32m$(1)\\e[39m
print = printf "$(call green,[$(TIMESTAMP)]) $(1)\n"
make_dir_link = ln -sfr $(1) $(2)
make_link = ln -sfr $(1) $(2)
cmd_copy = cp -a $(1) $(2)
cmd_link = ln -sfr $(1) $(2)
cmd_remove = rm -rf $(1)
cmd_mkdir = mkdir -p $(1)
cmd_cat = cat $(1) 2>/dev/null
cmd_print_lines = echo $(1) | tr ' ' '\n'
color_green = \033[32m$(1)\033[0m
log = @printf "$(call color_green,[$(TIMESTAMP)]) %s\n" "$(1)"
show_build_type = $(call log,Building for $(call green,$(1)))
check-var = $(if $(strip $($(1))),,$(error [ERROR] Missing required variable: $(1)))
check_command = $(shell which $(1) > /dev/null 2>&1 && echo y || echo n)
print_build_type = $(call print,Building for $(call green,$(1)))
ifeq ('y', '$(strip $(LINK_SRCS))')
update_files = $(call make_link,$(1),$(2))
update_dir = $(call make_dir_link,$(1),$(2))
ACTION = Linking
else
update_files = $(call copy_files,$(1),$(dir $(2)))
update_dir = $(call copy_dir,$(1),$(2))
ACTION = Copying
endif
$(call check-var,PROJECT)
$(call check-var,PLATFORM)
$(call check-var,BUILD_DIR)
$(call check-var,CONFIG_FILE)
$(call check-var,LINK_SRCS)
ifndef PROJECT
@$(error "PROJECT variable needs to be set")
endif
ifndef PLATFORM
@$(error "PLATFORM variable needs to be set")
endif
ifndef BUILD_DIR
@$(error "BUILD_DIR variable needs to be set")
endif
ifndef CONFIG_FILE
@$(error "CONFIG_FILE variable needs to be set")
endif
ifndef SCRIPT_DIR
CURRENT_FILE := $(lastword $(MAKEFILE_LIST))
CURRENT_DIR := $(patsubst %/,%,$(dir $(CURRENT_FILE)))
SCRIPT_DIR := $(CURRENT_DIR)
endif
ifeq ($(strip $(LINK_SRCS)),y)
update_files = $(call cmd_link,$(1),$(2))
update_dir = $(call cmd_link,$(1),$(2))
ACTION = Linking
else
update_files = $(call cmd_copy,$(1),$(dir $(2)))
update_dir = $(call cmd_copy,$(1),$(2))
ACTION = Copying
endif
#------------------------------------------------------------------------------
# COMMON INITIALIZATION
#------------------------------------------------------------------------------
PLATFORM_TOOLS = $(SCRIPT_DIR)/platform/$(PLATFORM)
BUILD_LOCK = $(BUILD_DIR)/.project.lock
BUILD_LOCK = $(BUILD_DIR)/.build.lock
PROJECT_LOCK = $(BUILD_DIR)/.project.lock
ifeq ('xilinx', '$(PLATFORM)')
include $(PLATFORM_TOOLS)/xilinx.mk
@@ -62,49 +57,28 @@ endif
# Generic Goals
#------------------------------------------------------------------------------
.DEFAULT_GOAL := all
PHONY += all
ifneq ($(wildcard $(BUILD_LOCK)),)
all:
@$(call print_build_type,$(PLATFORM))
$(MAKE) --no-print-directory build
@$(call print,Done ($(notdir $(BUILD_DIR))))
else
all:
@$(call print_build_type,$(PLATFORM))
$(MAKE) --no-print-directory project
$(MAKE) --no-print-directory build
@$(call print,Done ($(notdir $(BUILD_DIR))))
endif
PHONY := clean reset project build sdkopen
.DEFAULT_GOAL := project
# Create project using corresponding SDK
project: $(PLATFORM)_project
@echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK)
standalone:
$(MAKE) --no-print-directory project LINK_SRCS=n
# Build project using generic compiler
build: $(PLATFORM)_sdkbuild
# Build project using corresponding compiler
build: project $(PLATFORM)_sdkbuild
# Open the project using the corresponding SDK
sdkopen: $(PLATFORM)_sdkopen
sdkopen: project $(PLATFORM)_sdkopen
# Remove build artefacts
PHONY += clean
ifneq ($(wildcard $(BUILD_LOCK)),)
clean:
@$(call print,Cleaning sdk build uploaded to board)
$(MAKE) --no-print-directory $(PLATFORM)_sdkclean
clean: $(PLATFORM)_sdkclean
else
clean:
@$(call print,No project found, cleaning dummy files)
$(MAKE) --no-print-directory reset
clean: reset
endif
# Remove the whole build directory
PHONY += reset
reset: $(PLATFORM)_reset
@$(call print,[Delete] $(BUILD_DIR))
@$(call remove_dir,$(BUILD_DIR))
@$(call log,[Delete] $(BUILD_DIR))
@$(call cmd_remove,$(BUILD_DIR))
.PHONY: $(PHONY)
+3 -3
View File
@@ -44,7 +44,7 @@
- **project_name**: 项目名称,例如 `"demo"`。
- **version**: 项目版本,例如 `"0.0.0"`。
- **hw_design**: 硬件设计文件(`.hdf` 或 `.xsa` 文件)路径(相对当前工作路径),例如 `"demo_v0.0.0.hdf"`。
- **hw_design**: 硬件设计文件(`.hdf` 或 `.xsa` 文件)路径(相对档案工作路径),例如 `"demo_v0.0.0.hdf"`。
### *fsbl_patch* (TODO)
@@ -172,7 +172,7 @@
}
```
- **sources**: 源文件列表,可使用通配符。例如,`"src/*"` 会将当前工作目录下的 `src` 文件夹中的所有文件复制或链接到相应工程目录下的 `src` 文件夹中。
- **sources**: 源文件列表,可使用通配符。例如,`"src/*"` 会将当前工作路径下的 `src` 文件夹中的所有文件复制或链接到相应工程目录下的 `src` 文件夹中。
- **target_cpu**: 目标 CPU ID[^2];
- **os**: 操作系统类型[^1],必须与 BSP/Domain 匹配;
- **language**: 编程语言,"C" 或 "C++";
@@ -240,4 +240,4 @@
[^2]: 具体可选 CPU ID 取决于硬件型号;
[^3]: 均为“workspace path”,即工程内部相对路径;
[^3]: 相对对应工程的文件夹的路径;
+60 -31
View File
@@ -90,6 +90,46 @@ proc _configure_bsp {bsp_name bsp_config platform_name is_vitis} {
return $bsp_name
}
# Helper procedure to recursively create hard links for files in a directory
proc _link_or_copy_dir {source_dir target_dir link_mode} {
# Create target directory if it doesn't exist
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Process each file and subdirectory in the source directory
foreach item [glob -nocomplain -directory $source_dir *] {
set item_name [file tail $item]
set target_item [file join $target_dir $item_name]
# Remove existing file or directory
if {[file exists $target_item]} {
file delete -force $target_item
_warn "Deleted existing item: $target_item"
}
if {[file isfile $item]} {
# Handle file - create hard link or copy
if {$link_mode eq "y"} {
if {[catch {
file link -hard $target_item $item
} err]} {
error "Failed to create hard link: $err"
} else {
_info "Created hard link: $target_item -> $item"
}
} else {
file copy $item $target_item
_info "Copied file: $item to $target_item"
}
} elseif {[file isdirectory $item]} {
# Handle subdirectory recursively
_link_or_copy_dir $item $target_item $link_mode
}
}
}
# Helper procedure to handle source files: link or copy based on LINK_SRCS
proc _handle_sources {app_name sources} {
# Check environment variable LINK_SRCS
@@ -104,53 +144,41 @@ proc _handle_sources {app_name sources} {
if {[llength $expanded_sources] == 0} {
_error "Source file not found" "No file or directory matches $source_file"
}
# Hanle each expanded source
# Handle each expanded source
foreach eval_source $expanded_sources {
set relative_source [string range $eval_source [expr [string length $::root] + 1] end]
set target_path [file join $::ws $app_name $relative_source]
# Ensure the target directory exists
if {[file isfile $eval_source]} {
# For files, ensure the parent directory exists
set target_dir [file dirname $target_path]
if {![file exists $target_dir]} {
file mkdir $target_dir
_info "Created directory: $target_dir"
}
# Delete existing symbolic link or file if it exists
# Delete existing file if it exists
if {[file exists $target_path]} {
file delete -force $target_path
_warn "Deleted existing link or file: $target_path"
_warn "Deleted existing file: $target_path"
}
# Handle source based on the value of LINK_SRCS
switch $link_srcs {
"y" {
# Create symbolic link
# -- TCL cannont create symbolic link for files on Windows
# -- Fallback to use mklink command
if {$::tcl_platform(platform) eq "windows" && ![file isdirectory $eval_source]} {
# Handle file based on LINK_SRCS
if {$link_srcs eq "y"} {
if {[catch {
exec cmd /c mklink [file nativename $target_path] [file nativename $eval_source]
file link -hard $target_path $eval_source
} err]} {
error "Failed to create file symbolic link using mklink: $err"
error "Failed to create hard link: $err"
}
_info "Created hard link: $target_path -> $eval_source"
} else {
file copy $eval_source $target_path
_info "Copied file: $eval_source to $target_path"
}
} else {
if {[catch {
file link -symbolic $target_path $eval_source
} err]} {
error "Failed to create symbolic link: $err"
}
}
_info "Created symbolic link: $target_path -> $eval_source"
}
"n" {
# Copy the source file
file copy $eval_source $target_path
_info "Copied source file: $eval_source to $target_path"
}
default {
_error "Unknown value for LINK_SRCS: ${link_srcs}."
}
# For directories, use the helper function
_link_or_copy_dir $eval_source $target_path $link_srcs
}
}
}
@@ -233,7 +261,8 @@ proc _update_app_build_config {app_name build_type build_config is_vitis} {
"linker-misc" -
"linker-script" {
if {$value ne ""} {
eval $cmd $app_name -set $param $value
set value_list [list $value]
eval $cmd $app_name -set $param $value_list
_info "Set $param: $value for $app_name."
}
}
@@ -440,7 +469,7 @@ close $config_file_id
set root [pwd]
set config [json::json2dict $config_data]
set project_name [dict get $config project_name]
set hw_file [file normalize [file join $::root [dict get $config hw_design]]]
set hw_file [file normalize [file join $root [dict get $config hw_design]]]
_info "Starting process: $function"
_info "Project name: $project_name"
+21 -12
View File
@@ -1,14 +1,21 @@
#------------------------------------------------------------------------------
# ENVIRONMENT VARIABLES
#------------------------------------------------------------------------------
$(call check-var,XILINX_VITIS_CLASSIC)
$(call check-var,PLATFORM_TOOLS)
$(call check-var,CONFIG_FILE)
$(call check-var,BUILD_DIR)
$(call check-var,PROJECT_LOCK)
$(call check-var,BUILD_LOCK)
$(call check-var,LINK_SRCS)
define tcl_util
xsct -nodisp $(PLATFORM_TOOLS)/util.tcl \
$(1) \
$(CONFIG_FILE) $(BUILD_DIR)
endef
PHONY += xilinx_reset xilinx_project xilinx_sdkclean xilinx_sdkbuild
xilinx_sdkopen:
@$(call print,Launching IDE...)
@$(call log,Launching IDE...)
@if [ "$(call check_command,vitis)" = "y" ]; then \
if [ "$(XILINX_VITIS_CLASSIC)" = "y" ]; then \
vitis -classic -workspace=$(BUILD_DIR); \
@@ -21,20 +28,22 @@ xilinx_sdkopen:
echo "No IDE found!" && exit 1; \
fi
PHONY += xilinx_sdkbuild
xilinx_sdkbuild:
@$(call print,[Build] SDK projects in $(BUILD_DIR))
@$(call log,[Build] SDK projects in $(BUILD_DIR))
$(call tcl_util, build) $(HIDE)
@echo "$(TIMESTAMP): Build lock." > $(BUILD_LOCK)
PHONY += xilinx_sdkclean
xilinx_sdkclean:
@$(call print,[Delete] SDK artefacts from $(BUILD_DIR))
@$(call log,[Delete] SDK artefacts from $(BUILD_DIR))
$(call tcl_util, clean_project) $(HIDE)
xilinx_project:
@$(call print,Creating and configuring the IDE project)
$(call mk_dir,$(BUILD_DIR))
$(PROJECT_LOCK):
@$(call log,Creating and configuring the IDE project)
@$(call cmd_mkdir,$(BUILD_DIR))
$(call tcl_util, create_project) $(HIDE)
@echo "$(TIMESTAMP): Project lock." > $@
xilinx_project: $(PROJECT_LOCK)
xilinx_reset:
$(call remove_dir,.Xil) $(HIDE)
$(call cmd_remove,.Xil) $(HIDE)
+8 -9
View File
@@ -1,17 +1,16 @@
@echo off
cd /d "%~dp0"
set "platform=xilinx"
set "pltform_ver=2019.1"
set "platform_ver=2019.1"
set "work_dir=%~dp0build"
set "config=%~dp0config.json"
set "tools_dir=%~dp0scripts\platform\%platform%"
REM Change working dir to the dir where this script is located
cd /d "%~dp0"
REM Set up enviroment
call "%tools_dir%\setenv.bat" "%pltform_ver%"
REM Set up environment
call "%tools_dir%\setenv.bat" "%platform_ver%"
if "%ERRORLEVEL%" neq "0" (
echo Error: Failed to installize enviroment.
echo Error: Failed to initialize environment.
pause >nul
exit /b 1
)
@@ -24,8 +23,8 @@ if "%ERRORLEVEL%" neq "0" (
exit /b 1
)
REM Lauch SDK
call "%tools_dir%\launch.bat" "%pltform_ver%" "%work_dir%"
REM Launch SDK
call "%tools_dir%\launch.bat" "%platform_ver%" "%work_dir%"
if "%ERRORLEVEL%" neq "0" (
echo Error: Failed to launch SDK.
pause >nul