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

Subversion Repositories s80186

[/] [s80186/] [trunk/] [scripts/] [make-bios-mif] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jamieiles
#!/usr/bin/env python3
2
 
3
# Copyright Jamie Iles, 2017
4
#
5
# This file is part of s80x86.
6
#
7
# s80x86 is free software: you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation, either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# s80x86 is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with s80x86.  If not, see .
19
 
20
import argparse
21
import os
22
import pystache
23
import struct
24
 
25
pystache.defaults.DELIMITERS = (u'<%', u'%>')
26
 
27
HERE = os.path.dirname(__file__)
28
MIF_TEMPLATE = os.path.join(HERE, 'bios.mif.templ')
29
 
30
def write_mif(binary, output):
31
    with open(binary, 'rb') as b:
32
        data = bytearray(b.read())
33
    vals = []
34
    for i in range(len(data) // 2):
35
        vals.append(struct.unpack('
36
 
37
    data = {
38
        'depth': len(data) // 2,
39
        'width': '16',
40
        'values': [
41
            {'address': '{0:04x}'.format(a),
42
             'value': '{0:04x}'.format(v)} for a, v in enumerate(vals)
43
        ]
44
    }
45
    with open(MIF_TEMPLATE) as f:
46
        template = f.read()
47
    with open(output, 'w') as output:
48
        output.write(pystache.render(template, data))
49
 
50
parser = argparse.ArgumentParser()
51
parser.add_argument('binary')
52
parser.add_argument('output')
53
args = parser.parse_args()
54
 
55
write_mif(args.binary, args.output)

powered by: WebSVN 2.1.0

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