Commit 647a8ec2 authored by Qiang Du's avatar Qiang Du

Command line arguments in

parent e8e6d9c0
......@@ -59,6 +59,6 @@ class EB:
dlist = []
with eb.Cycle(self.device, 0, 0) as cycle:
for i in nrregs:
dlist.append(, v))
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: [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
ip = ''
target = EB(ip)
if len(argv)==0:
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)
baseaddr = 0x20800
target_ip = ''
flash_address = 0x0
flash_length = 0x0ff
file_name = 'foo_bit'
mb = XilMultiboot(ETHERBONE, target, baseaddr, file_name)
# read id
# id = mb.flash.read_id()
#'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'):
elif opt in ('--dump', '-d'):
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''Programming file %s'% file_name)
print 'action =', action
mb.flash.write(flash_address,range(0x0, 0x0 + flash_length))
status = mb.flash.rsr()'Status: 0x%x', status)
target = EB(target_ip)
mb = XilMultiboot(ETHERBONE, target, baseaddr, prog_file)
dat =, flash_length)
dat_pack = struct.pack('B'*len(dat), *dat)
print 'Flash: 0x' + dat_pack.encode('hex')
if (action is 'program'):'Programming file %s'% prog_file)
elif (action is 'serase'):
elif (action is 'id'):
flash_id = mb.flash.read_id()'Flash ID: 0x' + flash_id.encode('hex'))
elif (action is 'dump'):'Dumping to file %s from address 0x%x to 0x%x'%(dump_file, flash_address, flash_address+flash_size)), flash_address,flash_address+flash_size)
elif (action is 'status'):
status = mb.flash.rsr()'Status: 0x%x', status)
if __name__ == "__main__":
......@@ -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
Markdown is supported
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