mbtest.py 3.08 KB
Newer Older
1
import os
2
import sys,getopt
3 4
import time
import struct
5
import logging
6 7 8 9
sys.path.append("eb")
from eb import *
from xil_multiboot import *

10 11 12 13 14 15 16 17 18 19 20

def usage():
    print 'usage: mbtest.py [commands]'
    print '-t, --target <ip address>'
    print '-h, --help'
    print '-a, --address <address in hex>'
    print '-d, --dump <filename>'
    print '-p, --program <filename>'
    print '-e, --erase <size in hex (min 64kB)>'
    print '-i, --id'
    print '-s, --status'
Qiang Du's avatar
Qiang Du committed
21
    print '-r, --reconfigure <address in hex>'
22 23

def main(argv):
24 25 26 27
    log_level = logging.DEBUG
    log_level = logging.INFO
    logging.basicConfig(level=log_level)

28 29 30 31 32
    if len(argv)==0:
        usage()
        sys.exit()

    try:
Qiang Du's avatar
Qiang Du committed
33
        opts, args = getopt.getopt(argv, 'hisa:d:p:e:t:r:',['help','dump=','target=','address=','program=','erase=','id','status','reconfigure='])
34 35 36 37
    except getopt.GetoptError as err:
        print str(err)
        sys.exit(2)

38
    baseaddr = 0x20800
39
    target_ip = 'rflab2.lbl.gov'
40
    flash_address = 0x0
41
    flash_size = 0xf3
Qiang Du's avatar
Qiang Du committed
42
    prog_file = '../../syn/cute_wr/wr_core_demo/cute_top_wrc.bin'
43
    dump_file = 'dump_foo'
44

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    for opt,arg in opts:
        if opt in ('-h', '--help'):
            usage()
            sys.exit()
        elif opt in ('--dump', '-d'):
            dump_file=arg
            action = 'dump'
        elif opt in ('-t', '--target'):
            target_ip = arg
            print 'target',target_ip
        elif opt in ('-a', '--address'):
            flash_address = int(arg, base=16)
            print 'address: ',flash_address
        elif opt in ('--program', '-p'):
            prog_file = arg
            fileinfo = os.stat(prog_file)
            flash_size = fileinfo.st_size
            action = 'program'
        elif opt in ('--erase', '-e'):
            flash_size = int(arg, base=16)
            action = 'serase'
        elif opt in ('--id', '-i'):
            action = 'id'
        elif opt in ('--status', '-s'):
            action = 'status'
Qiang Du's avatar
Qiang Du committed
70 71 72
        elif opt in ('--reconfigure', '-r'):
            action = 'reconfigure'
            icap_addr = int(arg, base=16)
73

74
    logging.info('action ='+ action)
75

76 77 78
    target = EB(target_ip)
    target.open()
    mb = XilMultiboot(ETHERBONE, target, baseaddr, prog_file)
79

80 81 82 83 84 85 86 87 88 89 90
    if (action is 'program'):
        logging.info('Programming file %s'% prog_file)
        mb.write(flash_address)
    elif (action is 'serase'):
        mb.flash.serase(flash_address)
    elif (action is 'id'):
        flash_id = mb.flash.read_id()
        logging.info('Flash ID:    0x' + flash_id.encode('hex'))
    elif (action is 'dump'):
        logging.info('Dumping to file %s from address 0x%x to 0x%x'%(dump_file, flash_address, flash_address+flash_size))
        mb.read(dump_file, flash_address,flash_address+flash_size)
91
        #mb.dump(dump_file, flash_address,flash_address+flash_size)
92 93
    elif (action is 'status'):
        status = mb.flash.rsr()
94
        logging.info('Status:    0x%x'% status)
Qiang Du's avatar
Qiang Du committed
95 96 97
    elif (action is 'reconfigure'):
        logging.info('reconfiguring to add: 0x%x' % icap_addr)
        mb.iprog(icap_addr)
98 99

    target.close()
100 101

if __name__ == "__main__":
102
    main(sys.argv[1:])