Skip to content

Commit

Permalink
scripts/adi_project_lattice_pb.tcl: Fixing project creation.
Browse files Browse the repository at this point in the history
Using the official project creation with template project.
Adding a workaround fix to template project for Linux.

Signed-off-by: Villyam <[email protected]>
  • Loading branch information
Villyam committed Dec 12, 2024
1 parent 9a7a120 commit 8d8f438
Showing 1 changed file with 66 additions and 47 deletions.
113 changes: 66 additions & 47 deletions projects/scripts/adi_project_lattice_pb.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ proc adi_project_pb {project_name args} {
-board "" \
-speed "" \
-language "verilog" \
-psc "" \
-psc "${env(TOOLRTF)}/../../templates/MachXO3D_Template01/MachXO3D_Template01.psc" \
-cmd_list {{source ./system_pb.tcl}} \
{*}$args]

Expand All @@ -58,6 +58,11 @@ proc adi_project_pb {project_name args} {
set cmd_list $opt(-cmd_list)
set psc $opt(-psc)

if {$psc == "${env(TOOLRTF)}/../../templates/MachXO3D_Template01/MachXO3D_Template01.psc"} {
update_template
set psc ./MachXO3D_Template01/MachXO3D_Template01.psc
}

global ad_hdl_dir

if { [string match "auto" $dev_select] } {
Expand Down Expand Up @@ -156,37 +161,15 @@ proc adi_project_create_pb {project_name args} {
set preinst_ip_mod_dir ${env(TOOLRTF)}
set propel_builder_project_dir "$ppath/$project_name/$project_name"

if {$psc == ""} {
file mkdir $propel_builder_project_dir

# Creating the necessary .socproject file for being able to open the Radiant
# and Propel SDK from Propel Builder if needed.
set file [open "$ppath/$project_name/.socproject" w]
puts $file [format {<?xml version="1.0" encoding="UTF-8"?>
<propelProject>
<builder-resource>
<socProject sbxfile="./%s/%s.sbx"/>
</builder-resource>
</propelProject>} $project_name $project_name]
close $file
sbp_create_project -name "$project_name" \
-path $ppath \
-device $device \
-speed $speed \
-language $language \
-psc $psc

sbp_design new -name $project_name \
-path $propel_builder_project_dir/$project_name.sbx \
-device $device \
-speed $speed \
-language $language \
-board $board
} else {
sbp_create_project -name "$project_name" \
-path $ppath \
-device $device \
-speed $speed \
-language $language \
-psc $psc

foreach port [sbp_get_ports *] {
sbp_delete $port -type port
}
foreach port [sbp_get_ports *] {
sbp_delete $port -type port
}

sbp_design save
Expand All @@ -197,25 +180,9 @@ proc adi_project_create_pb {project_name args} {
eval $cmd
}

# Workaround for keeping the configured IP folders in Propel Builder 2023.2
# command line version.
# The 'sbp_design save' doesn't saves the temporary .lib folder to lib folder,
# instead deletes if there is anything in lib folder.
# I am copying the content of .lib (the configured IP cores) to lib after save
# to keep the configured IP cores for the Radiant project.
# Also generating the bsp after copying the configured IP cores to lib folder
# because that's also based on the content of lib folder.
#
# Update: - If the psc default template file exists then the save works fine
# and we do not need to generate the bsp separately also.
sbp_design save
sbp_design generate

if {$psc == ""} {
file copy "$propel_builder_project_dir/.lib/latticesemi.com" \
"$propel_builder_project_dir/lib"
}

# Generating the bsp.
sbp_design pge sge \
-i "$propel_builder_project_dir/$project_name.sbx" \
Expand Down Expand Up @@ -360,3 +327,55 @@ proc adi_ip_update {project_name args} {
sbp_replace -vlnv $vlnv -name $ip_niname -component $project_name/$ip_iname
}
}

proc update_template {args} {
global env
array set opt [list -dpath "./" \
-template "${env(TOOLRTF)}/../../templates/MachXO3D_Template01" \
]

set dpath $opt(-dpath)
set template $opt(-template)

if {[file exist $dpath] != 1} {
file mkdir $dpath
}
if {[file exist $dpath/MachXO3D_Template01] == 1} {
exec rm -r $dpath/MachXO3D_Template01
}
file copy -force "${env(TOOLRTF)}/../../templates/MachXO3D_Template01" $dpath

set regx {\s+file\s+copy\s+}

puts [pwd]
if {[file exist $dpath/MachXO3D_Template01/MachXO3D_Template01.tcl] == 1} {
set file [open $dpath/MachXO3D_Template01/MachXO3D_Template01.tcl r]
set fdata [read $file]
close $file
set file [open $dpath/MachXO3D_Template01/MachXO3D_Template01.tcl w]
foreach line [split $fdata "\n"] {
if {[regexp $regx $line]} {
puts $file { if {[file exist $targetDir] != 1} {file mkdir $targetDir}}
puts { if {[file exist $targetDir] != 1} {file mkdir $targetDir}}
}
puts $file $line
puts $line
}
close $file
}
if {[file exist $dpath/MachXO3D_Template01/verification/MachXO3D_Template01_v.tcl] == 1} {
set file [open $dpath/MachXO3D_Template01/verification/MachXO3D_Template01_v.tcl r]
set fdata [read $file]
close $file
set file [open $dpath/MachXO3D_Template01/verification/MachXO3D_Template01_v.tcl w]
foreach line [split $fdata "\n"] {
if {[regexp $regx $line]} {
puts $file { if {[file exist $targetDir] != 1} {file mkdir $targetDir}}
puts { if {[file exist $targetDir] != 1} {file mkdir $targetDir}}
}
puts $file $line
puts $line
}
close $file
}
}

0 comments on commit 8d8f438

Please sign in to comment.