Skip to content
Snippets Groups Projects
Commit 647a8ec2 authored by Qiang Du's avatar Qiang Du
Browse files

Command line arguments in mbtest.py

parent e8e6d9c0
Branches
Tags
No related merge requests found
......@@ -59,6 +59,6 @@ class EB:
dlist = []
with eb.Cycle(self.device, 0, 0) as cycle:
for i in nrregs:
dlist.append(cycle.read(addr, v))
dlist.append(cycle.read(addr))
logging.debug('mread: 0x%08x'% dlist[i])
return dlist
import os
import sys
import sys,getopt
import time
import struct
import logging
......@@ -7,37 +7,86 @@ sys.path.append("eb")
from eb import *
from xil_multiboot import *
def main():
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'
def main(argv):
log_level = logging.DEBUG
log_level = logging.INFO
logging.basicConfig(level=log_level)
ip = 'rflab2.lbl.gov'
target = EB(ip)
target.open()
if len(argv)==0:
usage()
sys.exit()
try:
opts, args = getopt.getopt(argv, 'hisa:d:p:e:t:',['help','dump=','target=','address=','program=','erase=','id','status'])
except getopt.GetoptError as err:
print str(err)
sys.exit(2)
baseaddr = 0x20800
target_ip = 'rflab2.lbl.gov'
flash_address = 0x0
flash_length = 0x0ff
file_name = 'foo_bit'
mb = XilMultiboot(ETHERBONE, target, baseaddr, file_name)
# read id
# id = mb.flash.read_id()
# logging.info('Flash ID: 0x' + id.encode('hex'))
flash_size = 0xff
prog_file = '../../syn/cute_wr/wr_core_demo/cute_top_wrc.bit'
dump_file = 'dump_foo'
# mb.flash.serase(flash_address)
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'
logging.info('Programming file %s'% file_name)
mb.write(flash_address)
mb.read(0,0xff)
print 'action =', action
mb.flash.write(flash_address,range(0x0, 0x0 + flash_length))
status = mb.flash.rsr()
logging.info('Status: 0x%x', status)
target = EB(target_ip)
target.open()
mb = XilMultiboot(ETHERBONE, target, baseaddr, prog_file)
dat = mb.flash.read(flash_address, flash_length)
dat_pack = struct.pack('B'*len(dat), *dat)
print 'Flash: 0x' + dat_pack.encode('hex')
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)
elif (action is 'status'):
status = mb.flash.rsr()
logging.info('Status: 0x%x', status)
if __name__ == "__main__":
main()
main(sys.argv[1:])
......@@ -70,9 +70,9 @@ class XilMultiboot:
#
# Read from flash
#
def read(self, sa, ea):
def read(self, fname, sa, ea):
# Ask for and open bitstream file
fname = raw_input("Output file name for flash readout: ")
#fname = raw_input("Output file name for flash readout: ")
f = open(fname,'wb')
# Read the data and dump to file
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment