Merge pull request #1 from openpowerwtf/master

add scripts
This commit is contained in:
openpowerwtf 2020-10-01 09:55:05 -05:00 committed by GitHub
commit 75b4e45d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 392 additions and 0 deletions

7
bin/asm Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/bash
arch="-ma2"
opts="-mregnames -mrelocatable -be"
as $arch $opts -alhnd $1.s -o $1.out > $1.lst

133
bin/dmp2tcl Executable file
View File

@ -0,0 +1,133 @@
#!/usr/bin/python
# coding: utf-8
# © IBM Corp. 2020
# Licensed under and subject to the terms of the CC-BY 4.0
# license (https://creativecommons.org/licenses/by/4.0/legalcode).
# Additional rights, including the right to physically implement a softcore
# that is compliant with the required sections of the Power ISA
# Specification, will be available at no cost via the OpenPOWER Foundation.
# This README will be updated with additional information when OpenPOWER's
# license is available.
#
# convert dump file (addr8 data4 format) to tcl script for jtag memory load
#
import argparse
inFile = 'image-test.dmp'
outFile = 'image.tcl'
reverse = True # byte-reverse words
blockSize = 128 # maximum block size for writes
parser = argparse.ArgumentParser(description='Convert addr/data format to tcl.')
parser.add_argument('-f', action='store', dest='inFile')
parser.add_argument('-o', action='store', dest='outFile')
parser.add_argument('-b', action='store', dest='blockSize')
parser.add_argument('-r', action='store', dest='reverse')
args = parser.parse_args()
if args.inFile is not None:
inFile = args.inFile
if args.outFile is not None:
outFile = args.outFile
if args.blockSize is not None:
blockSize = int(args.blockSize)
if args.reverse is not None:
reverse = args.reverse != '0'
def d2x(x, w=None):
if w is None:
return '{0:X}'.format(x)
else:
return '{0:0{l}X}'.format(x, l=w)
def x2d(i):
return int(i, 16)
# unsparse data into full block
def addCmd(block):
if len(block) == 0:
return
start = int(block[0][0]/blockSize) * blockSize
end = start + blockSize
data = ''
addr = start
for i in range(len(block)):
waddr = block[i][0]
wdata = block[i][1]
for j in range(addr, waddr, 4):
data += ' ' + '00000000'
data += ' ' + wdata
addr = waddr + 4
for j in range(waddr+4, end, 4):
data += ' ' + '00000000'
cmd = 'waxi ' + d2x(start, 8) + ' {' + data + '} ' + str(blockSize/4)
outLines.append('# ' + d2x(start, 8) + ':' + d2x(end-1, 8))
outLines.append(cmd)
dumpData = []
outLines = []
start = 0
with open(inFile, "rb") as f:
while True:
line = f.readline()
if not line:
break
tokens = line.split()
addr = tokens[0]
data = tokens[1]
dumpData.append([addr,data])
print('Read ' + str(len(dumpData)) + ' words from ' + inFile + '.')
# find sparse blocks
blockStart = 0
blockEnd = blockSize - 4
blockData = []
blocks = 0
for i in range(len(dumpData)):
addr = x2d(dumpData[i][0])
data = dumpData[i][1]
if reverse:
data = data[6] + data[7] + data[4] + data[5] + data[2] + data[3] + data[0] + data[1]
if addr == blockEnd: # reached end of current block -> complete it
blockData.append([addr, data])
addCmd(blockData)
blockStart += blockSize
blockEnd = blockStart + blockSize - 4
blockData = []
blocks += 1
elif addr > blockEnd: # past end of current block -> complete last and start new
addCmd(blockData)
blockStart = int(addr/blockSize) * blockSize
blockEnd = blockStart + blockSize - 4
blockData = [[addr, data]]
blocks += 1
else: # add data
blockData.append([addr, data])
# last one partial
if len(blockData) > 0:
addCmd(blockData)
blocks += 1
print('Created ' + str(blocks) + ' commands for len=' + str(blockSize) + 'B')
f = open(outFile, 'w')
f.write('# created by dmp2tcl from ' + inFile + '\n')
f.write('#'+ '\n')
f.write('# read: ' + str(len(dumpData)) + ' words created: ' + str(blocks) + ' blocks (' + str(blockSize) + 'B)'+ '\n')
f.write('#'+ '\n')
for i in range(len(outLines)):
f.write(outLines[i]+ '\n')
f.close()
print('Created ' + outFile + '.')

10
bin/dump Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/bash
if [ -z "$1" ]; then
f=a
else
f=$1
fi
# this removes the addresses; objdump does show all 0's when align skips addresses
objdump -s -j .hwinit $f.out | tail -n +5 | cut -c 7-41 > $f.hwinit.dmp

128
bin/imagedmp Executable file
View File

@ -0,0 +1,128 @@
#!/usr/bin/python
# coding: utf-8
# © IBM Corp. 2020
# Licensed under and subject to the terms of the CC-BY 4.0
# license (https://creativecommons.org/licenses/by/4.0/legalcode).
# Additional rights, including the right to physically implement a softcore
# that is compliant with the required sections of the Power ISA
# Specification, will be available at no cost via the OpenPOWER Foundation.
# This README will be updated with additional information when OpenPOWER's
# license is available.
# convert objdump to single-line format (addr data)
# objdump -s abc > obj.dmp
# data can be less than 4B/group
# addr NOT guaranteed to be 4B-aligned, so need to handle 1B,2B addresses; assuming each line is at least 4B apart for now
inFile = 'obj.dmp'
outFile = 'image-test.dmp'
keepZeroes = False
le = True
import argparse
parser = argparse.ArgumentParser(description='Convert objdump to addr/data format.')
parser.add_argument('-f', action='store', dest='inFile')
parser.add_argument('-o', action='store', dest='outFile')
parser.add_argument('-z', action='store', dest='keepZeros')
parser.add_argument('-l', action='store', dest='le')
args = parser.parse_args()
if args.inFile is not None:
inFile = args.inFile
if args.outFile is not None:
outFile = args.outFile
if args.keepZeros is not None:
keepZeros = args.keepZeros != '0'
if args.le is not None:
le = args.le != '0'
def b2x(b, w=None):
if w is None:
rem = len(b) % 4
w = len(b)/4
if rem != 0:
w = w + 1
return '{0:0{l}X}'.format(int(b,2), l=w)
def x2b(x, w=None):
i = int(str(x),16)
if w is None:
return bin(i)[2:]
else:
return '{0:0>{l}s}'.format(bin(i)[2:], l=w)
def d2x(x, w=None):
#return hex(int(x)).split('x')[-1].upper()
if w is None:
return '{0:X}'.format(x)
else:
return '{0:0{l}X}'.format(x, l=w)
def x2d(i):
return int(i, 16)
dumpData = []
start = 0
with open(inFile, "rb") as f:
while True:
#data = f.read().replace('\n', ' ').split()
line = f.readline()
if not line:
break
line = line[0:45]
if line.startswith(' '):
tokens = line.split()
addr = tokens[0].upper()
addrAlign = int(addr, 16) % 4
if addrAlign == 1:
print 'Found 1B-aligned addr! - skipping'
print line
print '**********************'
continue
elif addrAlign == 2:
print 'Found 2B-aligned addr! - skipping'
print line
print '**********************'
continue
if len(addr) != 8: # SHOULD be .comment
print 'Skipping: ' + line
break
if start == 0:
start = addr
for i in range(1,5):
if len(tokens) == i:
break
data = tokens[i].upper()
if len(data) < 8:
if le:
data = ('00000000' + data)[-8:]
else:
data = (data + '00000000' + data)[0:8]
dumpData.append([addr,data])
addr = d2x(x2d(addr) + 4)
print('Read ' + str(len(dumpData)) + ' words from ' + inFile + '.')
nz = 0
mem = {}
for i in range(len(dumpData)):
addr = dumpData[i][0]
data = dumpData[i][1]
if data != '00000000' or keepZeroes:
mem[addr] = data
nz += 1
print('Loaded ' + str(nz) + ' nonzero words.')
f = open(outFile, 'w')
for a in sorted(mem) :
f.write(a + ' ' + mem[a] + '\n')
f.close()
print('Wrote ' + outFile + '.')

114
bin/prune Executable file
View File

@ -0,0 +1,114 @@
#!/usr/bin/python
# coding: utf-8
# © IBM Corp. 2020
# Licensed under and subject to the terms of the CC-BY 4.0
# license (https://creativecommons.org/licenses/by/4.0/legalcode).
# Additional rights, including the right to physically implement a softcore
# that is compliant with the required sections of the Power ISA
# Specification, will be available at no cost via the OpenPOWER Foundation.
# This README will be updated with additional information when OpenPOWER's
# license is available.
#
# convert dump file (data4 data4 data4 data4 format) to sparse dump (addr data4)
#
# these are DW! assuming 00000000 high-order for now
config = {
'boot_config': '00000100',
'sections': {
'hwinit': {'addr': '00000000'},
}
}
inFile = 'boot'
outFile = 'boot_prune.dmp'
keepZeros = False
import argparse
parser = argparse.ArgumentParser(description='Convert datax4 format to addr/data format.')
parser.add_argument('-f', action='store', dest='inFile')
parser.add_argument('-o', action='store', dest='outFile')
parser.add_argument('-z', action='store', dest='keepZeros')
args = parser.parse_args()
if args.inFile is not None:
inFile = args.inFile
outFile = inFile + '_prune.dmp'
if args.outFile is not None:
outFile = args.outFile
if args.keepZeros is not None:
keepZeros = args.keepZeros != '0'
def b2x(b, w=None):
if w is None:
rem = len(b) % 4
w = len(b)/4
if rem != 0:
w = w + 1
return '{0:0{l}X}'.format(int(b,2), l=w)
def x2b(x, w=None):
i = int(str(x),16)
if w is None:
return bin(i)[2:]
else:
return '{0:0>{l}s}'.format(bin(i)[2:], l=w)
def d2x(x, w=None):
if w is None:
return '{0:X}'.format(x)
else:
return '{0:0{l}X}'.format(x, l=w)
def x2d(i):
return int(i, 16)
def loadSect(s, start):
if type(start) == int:
addr = start
start = str(start)
else:
addr = x2d(start)
sFile = inFile + '.' + s + '.dmp'
print('Reading section: ' + s + ', address=' + start + '(' + sFile + ')...')
with open(sFile, "rb") as f:
data = f.read().replace('\n', ' ').split()
print('Read ' + str(len(data)) + ' words.')
nz = 0
addrHex = start.zfill(8)
print('Start address is ' + addrHex + '.')
for i in range(len(data)):
if data[i] != '00000000':
mem[addrHex] = data[i].upper()
nz += 1
addr += 4
addrHex = d2x(addr, 8)
print('Loaded ' + str(nz) + ' nonzero words.')
mem = {}
for s in config['sections']:
sectDef = config['sections'][s]
if type(sectDef) is not list:
start = sectDef['addr']
loadSect(s, start)
else:
for i in range(len(sectDef)):
start = sectDef[i]['addr']
loadSect(s, start)
f = open(outFile, 'w')
for a in sorted(mem) :
f.write(a + ' ' + mem[a] + '\n')
f.close()
print('Wrote ' + outFile + '.')