Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17249 Diskussionen

Implementing firmware version

Altera_Forum
Geehrter Beitragender II
4.874Aufrufe

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.
0 Kudos
22 Antworten
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

 

--- 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: 

 

# -----------------------------------------------------------------# 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  

 

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
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

Thanks for the reply Dave, I will do that and give a feedback later.

Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

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: 

 

# 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}" } } }  

 

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?
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

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
Geehrter Beitragender II
3.397Aufrufe

Well it can't have spaces in the dir path... but how do I access it then?

Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

I did that but I get this error ... 

--- Quote End ---  

 

 

That is not adding the command to your path. That was an attempt to change directory. 

 

In Tcl all things are strings. Because your command had a space in it, Tcl interprets it as two strings. You just needed to use quotes, or parentheses, i.e., 

 

cd "c:/program files/tortoiseSVN/bin" 

cd {c:/program files/tortoiseSVN/bin} 

 

But this is not the solution I was recommending. You need to add this path to you PATH environment variable. 

 

Once you have done that, at the Quartus Tcl console you can type: 

 

puts $env(PATH) 

 

and you should see the new variable. Note that you will need to re-start Quartus once you change the PATH variable since the application only reads it when it starts. 

 

Cheers, 

Dave
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

But this is not the solution I was recommending. You need to add this path to you PATH environment variable. 

--- Quote End ---  

 

 

How do I do that? I am trying this: 

setenv PATH ${"C:/program files/TortoiseSVN/bin"} 

but it gives an error: 

Error:can't read ""C:/program files/TortoiseSVN/bin"": no such variable 

 

I may need administrator acess on this machine to change any enviroment variable, since I'm having so many errors.
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

What operating system are you using? 

 

Under Windows, you would set the path via the control panel. Under Linux you can use scripts that get executed at login. 

 

In either case, you can set the variable before you start Quartus if you use a command-line shell, eg., start a NIOS II IDE shell, and type 

 

export PATH=$PATH:"C:/program files/TortoiseSVN/bin" quartus  

 

and then Quartus will start, with the PATH extended to include the path to SVN. 

 

Of course, you now have non-portable HDL build system. Personally, I'd look into a solution where when you check into/out of SVN, a file is created with the SVN version info. You can then use Quartus to parse that file, and there is no need to worry about SVN being in the path for Quartus. 

 

Cheers, 

Dave
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

Of course, you now have non-portable HDL build system. Personally, I'd look into a solution where when you check into/out of SVN, a file is created with the SVN version info. You can then use Quartus to parse that file, and there is no need to worry about SVN being in the path for Quartus. 

--- Quote End ---  

 

 

I'm using windows XP. I did go to control panel, but I couldn't add anything to PATH because I need adm access, which is going to take some time since IT services are slow. 

Adding the PATH from control panel won't have the problem you mentioned?
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

I'm using windows XP. I did go to control panel, but I couldn't add anything to PATH because I need adm access, which is going to take some time since IT services are slow. 

 

--- Quote End ---  

 

 

You should be able to edit the path as a user; 

 

Control Panel, System, Advanced Tab, Environment Variables, Edit the user Path variable. 

 

 

--- Quote Start ---  

 

Adding the PATH from control panel won't have the problem you mentioned? 

--- Quote End ---  

 

 

Because you are having your HDL project manipulate additional tools (SVN), you will always have a portability issue. If someone gets give a zip file of your code, then they cannot build it if they do not have SVN installed, and your repo checked out. 

 

Cheers, 

Dave
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

I see... well I guess I'll stick to the other idea, which is reading from a file containing the version number. 

 

Btw, is there a way to read one line at a time and store the value of each line into their own variable?
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

I see... well I guess I'll stick to the other idea, which is reading from a file containing the version number. 

 

Btw, is there a way to read one line at a time and store the value of each line into their own variable? 

--- Quote End ---  

 

 

Yes, you can do things like that with Tcl. However, if you are writing the file with the version number in it, simply create the file using Tcl syntax, and then just have your build script source the file. 

 

Eg., something like the following (which is probably more complicated than you need, but you get the point) 

 

# version.tcl# # Automatically generated version file. Do not manually edit.# set version_major 1 set version_minor 2 set version  

 

Cheers, 

Dave
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

I don't think that helps me because I have to send the version number (inside the .txt file which is always going to be inside the project's file) to a 16 bit output in my VHDL code: 

data_rev: out std_logic_vector(15 downto 0) 

 

And each 8 bits of it is 1 number, so say I have a version = 14.10, after converting to binary my output will be: 

data_rev(15 downto 8) <= 0000 1110 -- 14 

data_rev(7 downto 0) <= 0000 1010 -- 10 

 

And that's why I need to get each number into their own variable. The format of my .txt file can be: 

1410 

or 

14 10 

 

Or even some other way that makes it easy to get each 2-digit number into 2 variables (maybe separate the 2 numbers with space). 

I looked for ways of reading line by line, but I don't know how to separate each number into variable a and b. 

Here's some examples I found, but they use 1 variable: 

 

1) set in set lineNumber 0 while { >= 0} { puts ": $line" } close $in ---------------------------------------- 2) set fp set file_data close $fp set data foreach line $data { #do something here to set the a and b values maybe? } ------Could it set index 0 to variable a and index 1 to variable b?-------- 3) set fid ;# Open file for read-only access set fields ;# Split the string into a list while { != -1 } { # Just print out the first field puts ;# Extract item at index 0 }  

 

I would set those 2 variables from the .txt into 2 generics: 

GENERIC( version: integer := 1; -- a revision: integer := 0; -- b ); 

 

For that I'd then use in the script: 

set_parameter -name VERSION $a set_parameter -name REVISION $b  

 

Question: can I put set_parameter directly in my version.tcl or it's only in the .qsf? 

 

So now my question remains, how do I treat those 2 numbers separately... 

Note: The .txt file is manually editted so I'm not treating it at all only reading it with TCL.
Altera_Forum
Geehrter Beitragender II
3.397Aufrufe

 

--- Quote Start ---  

 

can I put set_parameter directly in my version.tcl or it's only in the .qsf? 

 

--- Quote End ---  

 

 

Your version file can be Tcl, and can include any Quartus Tcl commands. You source that file via the Quartus Tcl console. So create a version file with the following syntax: 

 

# version.tcl set_parameter -name VERSION 14 set_parameter -name REVISION 10  

 

 

--- Quote Start ---  

 

The .txt file is manually edited so I'm not treating it at all only reading it with TCL. 

 

--- Quote End ---  

 

 

Since the file is manually edited, I see no problem with the file simply being created in Tcl format. No need to complicate things :) 

 

Cheers, 

Dave
Altera_Forum
Geehrter Beitragender II
3.335Aufrufe

Thanks for everything Dave. Now I just have to test it on the FPGA.

Antworten