Monday, September 9, 2013

Most frequently used UNIX commands : tar command

This article provides practical examples for most frequently used commands in UNIX.

tar command : 

In Unix, the name of the tar command is short for tape archiving, the storing of entire file systems onto magnetic tape, However, a more common use for tar is to simply combine a few files into a single file, for easy storage and distribution.                                                                 

Creating an archive using tar command
                 
Create a new tar archive :                  
 $ tar cvf archive_name.tar dirname/
Extract from an existing tar archive:
$ tar xvf archive_name.tar
View an existing tar archive:
$ tar tvf archive_name.tar
In the above command:
  • c – create a new archive.
  • v – verbosely list files which are processed.
  • f – following is the archive file name.
  • x – extract files from archive.

Creating a tar gzipped archive using option cvzf

The above tar cvf option, does not provide any compression. To use a gzip compression on the tar archive, use the z option as shown below.
$ tar cvzf archive_name.tar.gz dirname/
  • z – filter the archive through gzip.

Creating a bzipped tar archive using option cvjf

Create a bzip2 tar archive as shown below:
 $ tar cvfj archive_name.tar.bz2 dirname/
  • j – filter the archive through bzip2
gzip vs bzip2: bzip2 takes more time to compress and decompress than gzip. bzip2 archival size is less than gzip.

Extracting (untar) an archive using tar command

Extract a gzipped tar archive ( *.tar.gz ) using option xvzf

Use the option z for uncompressing a gzip tar archive.
$ tar xvfz archive_name.tar.gz

Extracting a bzipped tar archive ( *.tar.bz2 ) using option xvjf

Use the option j for uncompressing a bzip2 tar archive.
$ tar xvfj archive_name.tar.bz2

Listing an archive using tar command

View the tar archive file content without extracting using option tvf                                              

$ tar tvf archive_name.tar

View the *.tar.gz file content without extracting using option tvzf                                                      

$ tar tvfz archive_name.tar.gz

View the *.tar.bz2 file content without extracting using option tvjf                                                   

$ tar tvfj archive_name.tar.bz2

Extract a single file from tar, tar.gz, tar.bz2 file

To extract a specific file from a tar archive, specify the file name at the end of the tar xvf command as shown below. 
$ tar xvf archive_file.tar /path/to/file
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.
$ tar xvfz archive_file.tar.gz /path/to/file 
 $ tar xvfj archive_file.tar.bz2 /path/to/file

Extract a single directory from tar, tar.gz, tar.bz2 file

To extract a single directory (along with it’s subdirectory and files) from a tar archive, specify the directory name at the end of the tar xvf command as shown below.
 $ tar xvf archive_file.tar /path/to/dir/
To extract multiple directories from a tar archive, specify those individual directory names at the end of the tar xvf command as shown below.
 $ tar xvf archive_file.tar /path/to/dir1/ /path/to/dir2/
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.$ 
$ tar xvfz archive_file.tar.gz /path/to/dir/ 
$ tar xvfj archive_file.tar.bz2 /path/to/dir/

Extract group of files from tar, tar.gz, tar.bz2 archives using regular expression

To extract files matching a specified pattern. For example, following tar command extracts all the files with pl extension.
$ tar xvf archive_file.tar --wildcards '*.pl'
  • –wildcards *.pl – files with pl extension

Adding a file or directory to an existing archive using option -r

You can add additional files to an existing tar archive as shown below. 
$ tar rvf archive_name.tar newfile
This newfile will be added to the existing archive_name.tar. Adding a directory to the tar is also similar.
$ tar rvf archive_name.tar newdir/
Note: You cannot add file or directory to a compressed archive. If you try to do so, you will get “tar: Cannot update compressed archives” error as shown below.
$ tar rvfz archive_name.tgz newfile
tar: Cannot update compressed archives
Try `tar --help' or `tar --usage' for more information.

Estimate the tar archive size

The following command, estimates the tar file size ( in KB ) before you create the tar file.
$ tar -cf - /directory/to/archive/ | wc -c
20480
The following command, estimates the compressed tar file size ( in KB ) before you create the tar.gz, tar.bz2 files.
$ tar -czf - /directory/to/archive/ | wc -c
508
$ tar -cjf - /directory/to/archive/ | wc -c
428

Saturday, August 10, 2013

5 steps to compile and simulate "Hello world" with questasim10.0b

Use Questasim transcript window to run all below mentioned commands.

Step-1 : Download uvm-1.1a.tar.gz from http://www.accellera.org/downloads/standards/uvm


Step-2 : Extract that folder on to desktop and copy that whole folder into c:/questasim_10.0b


Step-3 : Now you have to set UVM_HOME environment variable path to locate uvm library which you have added. Go to C:/questasim_10.0b/ using cd command.


then give this command : setenv UVM_HOME uvm-1.1a. so that it will set your UVM_HOME environment variable.


Step-4 : Go to C:/questasim_10.0b/uvm-1.1a/examples/simple/hello_world using cd command.


Step-5 : Give this command : qverilog hello_world.sv
so it will compile,elaborate and simulate the design at one shot.


 You have successfully compiled and simulated "Hello world" of UVM.

Saturday, July 27, 2013

Specifications : quad_odd_1s_finder

Write a Verilog Code for a module "odd_1s_finder" to find out odd number of 1s in a 8 bit signal "data" it gets every clock "clk". 


Whenever data has odd 1s, an event called "odd event", two outputs change: odd_1s_found is true, and a 32 bit counter odd_1s_counter is incremented by 1. 

Example:
If in a given clock cycle, data[7:0]=8'b0100001, you notice it has 2 1s. Since 2 is even number, therefore there are even number of 1s, so your odd_1s_found signal should be False or 0.
Now if data[7:0]=8'b0100011, odd_1s_found signal should be True or 1, given there are 3 1s in the data.

Write a top level module "quad_odd_1s_finder" it create 4 instances of "odd_1s_finder", it comprise of 1 another 34 bit counter to count total number "odd events" from all 4 instance at each clock edge. 
    
For example in a given clock if 2 out of 4 instances had odd events, increment the top-level counter by 2, and if 3 odd events, increment it by 3 and so on. 

Thursday, July 25, 2013

tb_top.sv to verify quad_odd_1s_finder DUT

//tb_top.sv to verify quad_odd_1s_finder

module tb_top;

wire [33:0] total_odd_count;
reg [7:0] data1,data2,data3,data4;
reg clk,rst;

quad_odd_1s_finder uut(.total_odd_count(total_odd_count),.data1(data1),.data2(data2),.data3(data3),.data4(data4),.clk(clk),.rst(rst));


initial clk=1;
always #10 clk =~clk;

initial
 begin

   data1= 8'b0000_0000; data2= 8'b0000_0000; data3= 8'b0000_0000; data4= 8'b0000_0000; rst =1;

   @(posedge clk) rst=1;
 
   @(posedge clk) begin rst = 0;data1 = 8'b0000_0000; data2 = 8'b0000_0000; data3 = 8'b0000_0000; data4 = 8'b0000_0000;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1011; data2 = 8'b1010_1010; data3 = 8'b1010_1010; data4 = 8'b1010_1010;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1011; data2 = 8'b1010_1010; data3 = 8'b1010_1010; data4 = 8'b1010_1010;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1011; data2 = 8'b1010_1010; data3 = 8'b1010_1010; data4 = 8'b1010_1010;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1010; data2 = 8'b1010_1010; data3 = 8'b1010_1011; data4 = 8'b1010_1011;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1011; data2 = 8'b1010_1011; data3 = 8'b1010_1011; data4 = 8'b1010_1010;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1011; data2 = 8'b1010_1011; data3 = 8'b1010_1011; data4 = 8'b1010_1011;  end

   @(posedge clk) begin rst = 0;data1 = 8'b1010_1010; data2 = 8'b1010_1010; data3 = 8'b1010_1010; data4 = 8'b1010_1010;  end

  #100 $stop;

 end

endmodule

Quad_odd_1s_finder DUT

DUT .v files

//Quad_odd_1s_finder
module quad_odd_1s_finder(output reg [33:0] total_odd_count,input [7:0] data1,data2,data3,data4, input clk,rst);

wire [31:0] odd_count1,odd_count2,odd_count3,odd_count4;
wire [2:0] temp_total_odd_count;
wire od_f1,od_f2,od_f3,od_f4;

odd_1s_finder u1(.odd_count(odd_count1),.data(data1),.clk(clk),.rst(rst),.od_f(od_f1));
odd_1s_finder u2(.odd_count(odd_count2),.data(data2),.clk(clk),.rst(rst),.od_f(od_f2));
odd_1s_finder u3(.odd_count(odd_count3),.data(data3),.clk(clk),.rst(rst),.od_f(od_f3));
odd_1s_finder u4(.odd_count(odd_count4),.data(data4),.clk(clk),.rst(rst),.od_f(od_f4));

assign temp_total_odd_count = (odd_count1 || odd_count2 || odd_count3 || odd_count4)? (od_f1+od_f2+od_f3+od_f4):0;

always@(odd_count1 or odd_count2 or odd_count3 or odd_count4 or rst)
 if(rst)
  total_odd_count = 0;
 else
  total_odd_count = total_odd_count+temp_total_odd_count;

endmodule



//odd_1s_finder dut file
module odd_1s_finder(output reg od_f,output reg [31:0] odd_count,input [7:0 ]data,input clk,rst);
parameter TRUE=1'b1,FALSE=1'b0;
reg r;

always@(posedge clk)
  begin
   if(rst)
    begin
     r=0;
     odd_count=0;
    end
   else
     r=^data;
  end

always@(posedge clk)
  begin
   if(r==1)
    begin
     od_f=TRUE;
     odd_count=odd_count+1;
    end
   else
    begin
     od_f=FALSE;
     odd_count=odd_count;
    end
end

endmodule