Commit c4f821f6 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

sw: Removed read flash script, this will be part of multiboot script

parent b6c633a6
#!/usr/bin/python
#===============================================================================
# CERN (BE-CO-HT)
# Read the converter board flash via MultiBoot logic
#===============================================================================
# author: Theodor Stana (t.stana@cern.ch)
#
# date of creation:
#
# version: 1.0
#
# description:
# This script uses the wb_xil_multiboot module implemented inside a converter
# board FPGA to read the contents of the on-board flash between two addresses
# choosed by the user.
#
#===============================================================================
# GNU LESSER GENERAL PUBLIC LICENSE
#===============================================================================
# This source file is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License, or (at your
# option) any later version. This source is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# source; if not, download it from http://www.gnu.org/licenses/lgpl-2.1.html
#===============================================================================
# last changes:
#===============================================================================
# TODO: -
#===============================================================================
import sys
sys.path.append("../ei2c")
from ei2c import *
import ei2cdefine
MB_BASE = 0x100
MB_CR_OFS = 0x00
MB_SR_OFS = 0x04
MB_GBBAR_OFS = 0x08
MB_MBBAR_OFS = 0x0C
MB_FAR_OFS = 0x10
def spi_transfer(nbytes, cs, dat):
retval = 0
wval = []
# control byte, to be shifted left by 24
ctrl = ((cs << 3) | 0x4) | (nbytes-1)
# Use appropriate command by type
#
# write - we send up to three data bytes in one FAR register write
# writemregs - we send up to 24 data bytes in eight FAR register writes
if isinstance(dat,int):
testelma.write(slot, MB_BASE+MB_FAR_OFS, (ctrl << 24) | dat)
else:
for i in xrange(len(dat)):
wval.append((ctrl << 24) | dat[i])
testelma.writemregs(slot, MB_BASE+MB_FAR_OFS, wval)
# Read the data and prepare the return value
while (retval & (1 << 28) == 0):
retval = testelma.read(slot, MB_BASE+MB_FAR_OFS)
return retval & 0xFFFFFF
def flash_read(addr, nrbytes):
ret = []
spi_transfer(1,1,0x0b)
# send address in reverse order
addr = ((addr & 0xff0000) >> 16) | (((addr & 0xff00) >> 8) << 8) | ((addr & 0xff) << 16)
spi_transfer(3,1,addr)
spi_transfer(1,1,0)
# Read bytes in groups of three
for i in range(nrbytes):
ret.append(spi_transfer(1,1,0))
spi_transfer(1,0,0)
return ret
if __name__ == "__main__":
# Get the IP, user and password for the ELMA crate from ei2cdefine.py
ip = ei2cdefine.HNAME
user = ei2cdefine.USER
pwd = ei2cdefine.PWD
testelma = EI2C(ip, user, pwd)
testelma.open()
# Ask for slot number
while 1:
try:
slot = raw_input("Slot no.: ")
slot = int(slot)
break
except TypeError as e:
print("Please input a decimal slot number.")
except SlotError as e:
print(e.strerror)
except KeyboardInterrupt:
sys.exit();
except:
print("Unexpected error: ", sys.exc_info()[0])
# Get start address
while 1:
try:
sa = int(raw_input("Start address : 0x"), 16)
break
except ValueError as e:
print("Please input a hexadecimal address!")
except KeyboardInterrupt:
print("KeyboardInterrupt")
sys.exit()
except:
print("Unexpected error: ", sys.exc_info()[0])
# Get end address
while 1:
try:
ea = int(raw_input("End address : 0x"), 16)
break
except ValueError as e:
print("Please input a hexadecimal address!")
except KeyboardInterrupt:
print("KeyboardInterrupt")
sys.exit()
except:
print("Unexpected error: ", sys.exc_info()[0])
# Start reading
dat = []
for i in range(sa, ea, 256):
dat += flash_read(i, 256)
print("0x%06x" % i)
dat = ''.join(map(chr,dat))
f = open("flash.bin", "wb")
f.write(dat)
f.close()
testelma.close()
print("DONE!")
print("Output stored to flash.bin")
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