Forum Discussion
Implementing firmware version
I am trying to make a code that can store firmware versions from a .txt file, I tried doing it with a ROM initialized with a .mif file, but it's not working. I have a Cyclone III that sends that info to a microcontroller and then to a HMI (human machine interface) screen so I can see the FPGA's firmware version. It's all in VHDL, but I posted this issue a few days ago and I got this reply (that seemed more appropriate, but I don't know how to do it):
--- Quote Start --- What you are attempting I have done in the past to store hardware versions and software build numbers but I had Nios II reading out the values. Perhaps you can skip using the ROM and just 'include a value defined in a verilog include file that is generated by your build system. In the include file you could just have something like 'define VERSION_NUMBER <machine generated version number> and in your hardware design refer to that value. --- Quote End --- But I've never done anything in verilog, only VHDL. I searched that out but still can't make much of it. If anyone could possibly post a code on how that's done, it would really help me, been trying to do this for long now.22 Replies
- Altera_Forum
Honored Contributor
Annoyingly - Quartus will not initilise ROMs or RAMs from a text file using textio. You will need a wizard generated ROM with the correct .mif file.
But you can do it by infering a ROM (or register) from a constant that is defined in a package, and have TCL modify the package every time you recompile the project. Im not a TCL person but we have it working here for one of our projects. It means the software can easily probe the version register to make sure it's got the correct firmware. - Altera_Forum
Honored Contributor
I used textio the first time I tried (like more than a month ago) then I discovered that it isn't synthesizable so then I created a ROM with megawizard and used a .mif file. I just can't figure out why that doesn't work... and when I compile it, I don't see the rom instance in the analysis log under compilation.
Also never used TCL, so I don't really know how it works. I can look it up. - Altera_Forum
Honored Contributor
Please raise an Enhancement Request of altera for this Feature. You can do it in Verilog and Xilinx have no problems with it for verilog or VHDL - its very annoying Altera dont support it!
- Altera_Forum
Honored Contributor
I just want a working solution for this, and if it's possible to do it with verilog, then I guess I'll try that, could you possibly tell me how to do it? and post a code or something? I'm using quartus.
- Altera_Forum
Honored Contributor
--- Quote Start --- I just want a working solution for this, and if it's possible to do it with verilog, then I guess I'll try that, could you possibly tell me how to do it? and post a code or something? I'm using quartus. --- Quote End --- You can use generics/parameters at the top-level of your design, and use those to populate registers within your design. You can then use Quartus to populate the generics:
This Tcl code can be part of a script you explicitly call (source), or you can have Quartus run it as part of the build sequence: http://www.altera.com/support/examples/tcl/auto_processing.html If you prefer to have your version number stored in a file, then you can have Tcl read that file and populate the generic. Cheers, Dave# -----------------------------------------------------------------# Generics# ----------------------------------------------------------------- # Build timestamp# - Tcl returns the same as set timestamp puts " - Build timestamp ($timestamp 0x)" # Version (integer format) set version # Generics set_parameter -name VERSION $version set_parameter -name TIMESTAMP $timestamp - Altera_Forum
Honored Contributor
Thanks for the reply Dave, I will do that and give a feedback later.
- Altera_Forum
Honored Contributor
While searching about TCL scripting I ended up finding this:
http://www.altera.com/support/examples/tcl/tcl-version-number.html Which suits my case very well, since we use SVN here. But I am still very new to all this scripting and all, so I still have some doubts. I implemented that script into one project just for testing purposes, and the script is:
I am using the automatic run of that script as well. So when I compile my project I got the following warning: Critical Warning: Couldn't run command to get revision number. couldn't execute "svn": no such file or directory And I'm not sure what is wrong, since I commited the whole folder of the project in SVN, also not sure how the script gets the version number, if it's by the commited folder or by a txt file included in it. And I put in red parts of the code that I don't know if I'm supposed to change them or not. Anyone?# Gets SVN revision number for the specified file proc get_subversion_revision { file_name } { global done # The maximum number of seconds to wait for the svn info # command to complete set timeout_seconds 30 # The svn info command with filename that is run set cmd "svn info ${file_name}" # Attempt to get the version information. # If the command can't be run, return an error. # Otherwise set up a file event to process the command output. if { } { return -code error $input } else { fileevent $input readable # Set up a timeout so that the process can't hang if the # repository is down. set timeout ] # Don't continue until the revision number is found, # or the operation times out. Cancel the timeout anyway. vwait done after cancel $timeout } } # Helper procedure for the above procedure proc get_revision_info { inp } { global done revision_number if { } { catch {close $inp} set done 1 } elseif { $done } { gets $inp line } else { gets $inp line # Use a regular expression to match the line with the # revision number. if { } { set done 1 } } } # Creates a register bank in a vhdl file with the specified hex value proc generate_vhdl { hex_value } { set num_digits set bit_width set high_index set reset_value if { puts $fh "LIBRARY ieee;\nUSE ieee.std_logic_1164.ALL;" puts $fh "ENTITY version_reg IS" puts $fh " PORT (" puts $fh " clock: IN STD_LOGIC;" puts $fh " reset: IN STD_LOGIC;" puts $fh " data_out: OUT STD_LOGIC_VECTOR(${high_index} downto 0)" puts $fh " );" puts $fh "END version_reg;" puts $fh "ARCHITECTURE rtl OF version_reg IS" puts $fh "BEGIN" puts $fh "PROCESS (clock,reset)" puts $fh " BEGIN" puts $fh " IF (reset='0') THEN" puts $fh " data_out <=X\"${reset_value}\";" puts $fh " ELSIF rising_edge (clock) THEN" puts $fh " data_out <= X\"${hex_value}\";" puts $fh " END IF;" puts $fh "END PROCESS;" puts $fh "END rtl;" close $fh } res ] } { return -code error $res } else { return 1 } } # This line accommodates script automation foreach { flow project revision } $quartus(args) { break } set file_name ${project}.qpf set done 0 set revision_number "" # Call procedure to get file revision number and handle any errors if { } { post_message -type critical_warning "Couldn't run command to get revision number. $msg" } else { if { -1 == $done } { post_message -type critical_warning "Timeout getting revision number." } elseif { } { post_message -type critical_warning "Couldn't find revision number in output of svn info $file_name." } else { # Call procedure to store the number if { } { post_message -type critical_warning "Couldn't generate VHDL file. $res" } else { post_message "Successfully updated version number to version 0x${revision_number}" } } } - Altera_Forum
Honored Contributor
I suspect your Tcl shell does not include the path to the command "svn".
Try setting up the path correctly. For a discussion of this with regards to Altera's Quartus Tcl shell see Appendix B of this doc: http://www.ovro.caltech.edu/~dwh/correlator/pdf/altera_pcie_analysis.pdf Cheers, Dave - Altera_Forum
Honored Contributor
Hmm I did that but I get this error:
tcl> cd c:/program files/tortoiseSVN/bin Error:wrong# args: should be "cd ?dirName?" Error: while executing Error:"cd c:/program files/tortoiseSVN/bin" And since I'm such a noob on this matter, I'm not quite sure if that's where the command is, but from what I saw it's the best place for it. And I searched about it and I found this: http://stackoverflow.com/questions/2299593/using-bash-to-get-revision-number-from-subversion Don't know if that command works. - Altera_Forum
Honored Contributor
Well it can't have spaces in the dir path... but how do I access it then?