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

Subversion Repositories layer2

[/] [layer2/] [trunk/] [sw/] [common/] [vhd.py] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 idiolatrie
#!/usr/bin/env python
2
#------------------------------------------------------------------------------#
3
# BIN to VHD converter                                                         #
4
#------------------------------------------------------------------------------#
5
# Copyright (C) 2011 Mathias Hoertnagl, mathias.hoertnagl@gmail.com            #
6
#                                                                              #
7
# This program is free software; you can redistribute it and/or modify it      #
8
# under the terms of the GNU General Public License as published by the Free   #
9
# Software Foundation; either version 3 of the License, or (at your option)    #
10
# any later version.                                                           #
11
# This program is distributed in the hope that it will be useful, but WITHOUT  #
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        #
13
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for     #
14
# more details.                                                                #
15
# You should have received a copy of the GNU General Public License along with #
16
# this program; if not, see <http://www.gnu.org/licenses/>.                    #
17
#------------------------------------------------------------------------------#
18
import sys
19
 
20
header = "\
21
library ieee;\n\
22
use ieee.std_logic_1164.all;\n\
23
use ieee.numeric_std.all;\n\
24
\n\
25
library work;\n\
26
use work.imem.all;\n\
27
\n\
28
package data is\n\
29
\n\
30
   constant data : mem_block_t := (\n"
31
 
32
 
33
if len(sys.argv) != 3:
34
   print "Usage: python", sys.argv[0], "<*.bin file>", "<destination folder>"
35
   sys.exit()
36
 
37
outp = {}
38
data = {}
39
 
40
data[0] = "      0 => (\n         "
41
data[1] = "      1 => (\n         "
42
data[2] = "      2 => (\n         "
43
data[3] = "      3 => (\n         "
44
 
45
print ""
46
print "************************************************************************"
47
print "* Memory File Generation                                               *"
48
print "************************************************************************"
49
 
50
print "Loading:", sys.argv[1]
51
 
52
inp = open(sys.argv[1], 'rb')
53
bin = inp.read()
54
inp.close()
55
 
56
# Outout name is fixed to make it automatically loadable.
57
outp = open(sys.argv[2] + 'data.vhd', 'w')
58
outp.write(header)
59
 
60
print "Writing memory file ..."
61
 
62
i = 3
63
j = 39
64
for c in bin:
65
   data[i] = data[i] + ('x"%02X", ' % ord(c))
66
 
67
   if j == 0:
68
      j = 39
69
      for k in range(4):
70
         data[k] = data[k] + "\n         "
71
   else:
72
      j = j - 1
73
 
74
   if i == 0:
75
      i = 3
76
   else:
77
      i = i-1
78
 
79
for i in range(3):
80
   data[i] = data[i] + 'others => x"00"\n      ),\n'
81
 
82
data[3] = data[3] + 'others => x"00"\n      )\n   );\n\nend data;'
83
 
84
for i in range(4):
85
   outp.write(data[i])
86
 
87
outp.close()
88
 
89
print "Done!"

powered by: WebSVN 2.1.0

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