Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

Post compile file copy script

Hello,

I am trying to create a script so that the .sof file is copied to a specific location after the build is done. I went as far as adding this to the .qsf file:

set_global_assignment -name POST_FLOW_SCRIPT_FILE "quartus_sh:post_compile.tcl"

Now, I don't know what to put in the post_compile.tcl file to actually do the file copy. The build fails at the end because there is no post_compile.tcl yet.

Does anyone know how to do this?

Thank you!

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    How about consulting a tcl manual? Unfortunately, I'm not aware of the copy syntax, but I know where to read about.

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I was not sure if Altera was using standard Tcl. I ended up adding this:

    file copy -force src.rbf dest.rbf

    Right now, I am hardcoding the "src.rbf" name. I eventually would like to be able to use the top name for it so that this script can be generic and can be used for other projects. I will add a post when I find out how to do that.

    Thank you
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Tcl has some direct commands for finding file names, stripping the prefix off, etc. (I don't remember the names though.) When writing out a file, I always use the following, which looks to see if the file exists, copies it to a .bak file, and then opens a new one. (The file used here was a .csf)

    set filename src

    if {[file exists $filename.csf]} {

    if {[file exists $filenam.csf.bak]} {

    puts "removing $filenam.csf.bak"

    file delete $filename.csf.bak

    }

    file copy $filename.csf $filename.csf.bak

    puts "moving $filename.csf to $filename.csf.bak"

    file delete $filename.csf

    }

    set file [file open $filename.csf a]

    puts $file "Add some text to the file"

    puts $file "Add some more"

    close $file
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I got this working by doing this:

    set rbf_file_name ".rbf"
    post_message "### Copying output $rbf_file_name"
    file copy -force $rbf_file_name new_dir/$rbf_file_name
    

    This is what the Altera site says about the arguments passed in:

    --- Quote Start ---

    The first argument passed in the quartus(args) variable is the name of the flow or module being executed, depending on the assignment you use. The second argument is the name of the project, and the third argument is the name of the revision

    --- Quote End ---

    I am not sure how the output file name relates to these, but the script above seems to work fine.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You're selecting the second argument, which is the project name. Most output files are named after the revision, so I would change it to that. (In most projects the project name and revision name are the same, in which case it technically doesn't matter, but revision is probably correct.) Remember that:

    a) Project name is the name of your .qpf.

    b) Revision is the name of the .qsf.

    There can be only one .qpf but multiple .qsf files, which are controlled under Project -> Revisions...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thank you Rysc!

    This is the kind of clarification I was looking for. I did notice that argv[1] and [2] are the same, but that is probably because I have a simple project.