OpenCores
URL https://opencores.org/ocsvn/zap/zap/trunk

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [scripts/] [bin2vlog.pl] - Blame information for rev 41

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 Revanth
#!/usr/bin/perl -w
2
 
3 41 Revanth
#// -----------------------------------------------------------------------------
4
#// --                                                                         --
5
#// --                   (C) 2016-2018 Revanth Kamaraj.                        --
6
#// --                                                                         -- 
7
#// -- --------------------------------------------------------------------------
8
#// --                                                                         --
9
#// -- This program is free software; you can redistribute it and/or           --
10
#// -- modify it under the terms of the GNU General Public License             --
11
#// -- as published by the Free Software Foundation; either version 2          --
12
#// -- of the License, or (at your option) any later version.                  --
13
#// --                                                                         --
14
#// -- This program is distributed in the hope that it will be useful,         --
15
#// -- but WITHOUT ANY WARRANTY; without even the implied warranty of          --
16
#// -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           --
17
#// -- GNU General Public License for more details.                            --
18
#// --                                                                         --
19
#// -- You should have received a copy of the GNU General Public License       --
20
#// -- along with this program; if not, write to the Free Software             --
21
#// -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA           --
22
#// -- 02110-1301, USA.                                                        --
23
#// --                                                                         --
24
#// -----------------------------------------------------------------------------
25
 
26 26 Revanth
###############################################################################
27
# Perl script to translate GCC generated binary files into Verilog memory
28
# files.
29
#
30
# Usage: perl bin2vlog.pl <Binary File> <Target Verilog File>
31
###############################################################################
32
 
33
use strict;
34
use warnings;
35
 
36
# Read command line arguments.
37
my $bin_file = $ARGV[0];
38
my $target_verilog_file = $ARGV[1];
39
 
40
# Generate Verilog file.
41
die "*E: Verilog file creation error...\n" if
42
        system("rm -f $target_verilog_file ; touch $target_verilog_file");
43
 
44
# Open the binary and Verilog file using different file handles.
45
open(my $fh, "<$bin_file") or die
46
        "Bin file $ARGV[0] could not be opened for reading...!\n";
47
 
48
open(GH, ">$target_verilog_file") or die
49
        "Target verilog file could not be opened for writing...\n";
50
 
51
# Read file in binary mode.
52
binmode $fh;
53
 
54
# Memory pointer.
55
my $counter = 0;
56
 
57
#
58
# As long as there are bytes to read from the binary file, we will write out
59
# those bytes. The ord function returns to numeric value of the byte from 0
60
# to 255 corresponding to bytes 8'b0000_0000 to 8'b1111_1111.
61
#
62
while (read($fh, my $buf, 1) == 1) { # Get a byte from the file.
63
 
64
        # Print the numeric value of the byte.
65
        my $line = sprintf("mem[$counter] = 8'h%x;\n", ord $buf);
66
 
67
        # Print to the Verilog file.
68
        print GH $line;
69
 
70
        # Increment memory pointer by 1 since we are dealing with bytes.
71
        $counter++;
72
}
73
 
74
# Close both the files.
75
close($fh);
76
close(GH);
77
 
78
print "Done...\n";
79
exit 0;

powered by: WebSVN 2.1.0

© copyright 1999-2022 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.