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

Subversion Repositories openfire_core

[/] [openfire_core/] [trunk/] [utils/] [openfire_bram.pl] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 cutullus
#!/usr/bin/perl -w
2
############################################################
3
# openfire_bram
4
#
5
# Initializes BRAMs with OpenFire code.
6
#
7
# Stephen Douglas Craven
8
# 1/17/2006
9
# Configurable Computing Lab
10
# Virginia Tech
11
#
12
# History
13
# 1/17/2006 -- Added support for variable MB names
14
############################################################
15
 
16
#
17
# Globals
18
#
19
use vars qw/ %opt /;
20
 
21
#
22
# Command line options processing
23
#
24
sub init()
25
{
26
    use Getopt::Std;
27
    my $opt_string = 'o:n:t:f:b:hx:p:';
28
    getopts( "$opt_string", \%opt ) or usage();
29
    usage() if ($opt{h});
30
}
31
 
32
#
33
# Message about this program and how to use it
34
#
35
sub usage()
36
{
37
    print STDERR << "EOF";
38
 
39
This program creates a BMM file from an NCD and uses this to read and
40
write initial BRAM contents from a bitstream.
41
 
42
NOTE: XDL and DATA2MEM must be installed and in the user's path.
43
 
44
usage: $0 [-h] [-n NCD_FILE -o BMM_FILE] [-r ROM_FILE -b BITSTREAM]
45
 
46
 -h                   : this (help) message
47
 -n NCD_FILE          : NCD_FILE containing placed BRAMs (default = implementation/system.ncd)
48
 -o BMM_FILE          : BMM_FILE to create (default = implementation/openfire.bmm)
49
 -t top-level module  : name of the top-level OpenFire module (default = openfire)
50
 -f ELF_FILE          : ELF file to place in OpenFire memory (optional)
51
 -b BITSTREAM         : bitstream to update with BRAM contents (default = implementation/download.bit)
52
 -x XDL_FILE          : use specified XDL file (w/o flag, generates own from NCD_FILE)
53
 -p #                 : number of processors in design; named top-level_module0, top-level_module1, etc.
54
                           (default = 1)
55
 
56
example: $0 -n system.ncd -o system.bmm -f openfire.elf -b download.bit
57
example: $0 -o system.bmm -p 4 -t vtmb_
58
 
59
EOF
60
exit;
61
}
62
 
63
init();
64
 
65
# Fill in Default Values
66
if($opt{t}) {
67
        $top_level_name = $opt{t};
68
} else {
69
        $top_level_name = "openfire";
70
}
71
if($opt{n}) {
72
        $ncd_file = $opt{n};
73
} else {
74
        $ncd_file = "implementation/system.ncd";
75
}
76
if($opt{o}) {
77
        $output_bmm = $opt{o};
78
} else {
79
        $output_bmm = "implementation/openfire.bmm";
80
}
81
if($opt{b}) {
82
        $bitstream = $opt{b};
83
} else {
84
        $bitstream = "implementation/download.bit";
85
}
86
if($opt{p}) {
87
        $num_processors = $opt{p};
88
} else {
89
        $num_processors = 1;
90
}
91
# An XDL file is a textual representation of an NCD file
92
# An NCD file, after PAR< contains the physical locations of all components
93
# We need to know where PAR placed the OpenFire BRAMs, so we create and parse an XDL file
94
$xdl_file = $ncd_file;
95
$xdl_file =~ s/ncd/xdl/;
96
if($opt{x})
97
{
98
        # If an XDL file is specified, check if its there
99
        if(-r $opt{x})
100
        {
101
                $xdl_file = $opt{x};
102
        } else {
103
                print "ERROR! Specifiec XDL File $opt{x} cannot be read! Exiting \n";
104
                exit(0);
105
        }
106
} elsif (-r $xdl_file) # if no XDL file given, search for default one
107
{
108
} else {        # can't find an XDL file, so create one
109
        system("xdl -ncd2xdl $ncd_file $xdl_file");
110
}
111
 
112
# DATA2MEM needs a BMM File to describe the memory layout and BRAM physical locations
113
# We will make a BMM file using information from the XDL file
114
open(bmm_file, ">$output_bmm");
115
 
116
# Loop for each processor
117
for($count = 0; $count < $num_processors; $count++)
118
{
119
        $processor_name = $top_level_name.$count.'/';
120
        # Get BRAM locations by searching for all BRAMs linked to a specific OpenFire
121
        # These BRAMs then get sorted to (hopefully) insure that the program is loaded correctly
122
#       $brams = `grep inst $xdl_file | grep RAMB16 | grep $processor_name | sort +1 -n -t B`;
123
        $brams = `grep inst $xdl_file | grep RAMB16 | grep $processor_name | grep -v "i.*_ila\/" | sort +1 -n -t B`;
124
 
125
        $i = 0;
126
        # Loop over each BRAM discovered above
127
        foreach $_ (split(/\n/, $brams)){
128
                # We need the name of the BRAM and its location
129
                if(/inst \"($top_level_name[\w\d_\/]+)\".*RAMB16_([\w\d]+)/) {
130
                        $mem[$i] = $1;
131
                        $location[$i] = $2;
132
                        $i++;
133
                }
134
        }
135
        $num_brams = $i;
136
 
137
        # Create BMM File for Data2mem
138
        $size = 2048 * $i -1;   # each BRAM is 2048 Bytes
139
        printf bmm_file ("ADDRESS_SPACE lmb_bram_$count RAMB16 [0x00000000:0x0000%X]\n", $size);
140
        print bmm_file "    BUS_BLOCK\n";
141
 
142
        $msb = 31;
143
        for ($i = $num_brams - 1; $i >= 0; $i--) {
144
                $lsb = $msb - 32 / $num_brams + 1;
145
                print bmm_file "    $mem[$i] [$msb:$lsb] PLACED = $location[$i];\n";
146
                $msb = $lsb - 1;
147
        }
148
        print bmm_file "    END_BUS_BLOCK;\n";
149
        print bmm_file "END_ADDRESS_SPACE;\n";
150
}
151
 
152
close(bmm_file);
153
 
154
# Test BMM File for Correctness
155
$error = `data2mem -bm $output_bmm`;
156
if(!$error and $opt{f}) {
157
    # Populate BRAM with ELF contents
158
    system("data2mem -bm ".$output_bmm." -bd ".$opt{f}." -bt ".$bitstream." -o b tmp666.bit");
159
    system("mv tmp666.bit ".$bitstream);
160
} elsif($error)  {
161
        print "$error";
162
    print "Error in BMM File!  Sorry!\n";
163
}

powered by: WebSVN 2.1.0

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