Пример #1
0
def _to_ecmdDataBuffer(buf, defwidth=64):
    if isinstance(buf, _int_types):
        # negative numbers in Python start with infinite one bits, so strip off infinity minus 64 ;)
        buf = buf & ((1 << defwidth) - 1)

        ecmd_buf = ecmd.ecmdDataBuffer(defwidth)
        if defwidth == 64:
            ecmd_buf.setDoubleWord(0, buf)
        elif defwidth == 32:
            ecmd_buf.setWord(0, buf)
        else:
            raise NotImplementedError()

        return ecmd_buf
    if isinstance(buf, bitstring.Bits):
        ecmd_buf = ecmd.ecmdDataBuffer(len(buf))
        overhang = len(buf) % 64
        bits = buf + bitstring.Bits(64 - (
            len(buf) % 64)) if overhang else buf  # pad to multiples of 64 bits
        for i in range(len(bits) // 64):
            ecmd_buf.setDoubleWord(i, bits[i * 64:(i + 1) * 64].uint)
        return ecmd_buf
    if isinstance(buf, (str, unicode)):
        bits = bitstring.Bits(buf)
        return _to_ecmdDataBuffer(bits)
    return buf
Пример #2
0
def _to_ecmdDataBuffer(buf, defwidth=64):
    if isinstance(buf, _int_types):
        # negative numbers in Python start with infinite one bits, so strip off infinity minus 64 ;)
        buf = buf & ((1 << defwidth) - 1)

        ecmd_buf = ecmd.ecmdDataBuffer(defwidth)
        if defwidth == 64:
            ecmd_buf.setDoubleWord(0, buf)
        elif defwidth == 32:
            ecmd_buf.setWord(0, buf)
        else:
            raise NotImplementedError()

        return ecmd_buf

    if isinstance(buf, bitstring.Bits):
        ecmd_buf = ecmd.ecmdDataBuffer(len(buf))
        if len(buf):
            buf_bytes = bytearray(buf.tobytes())
            ecmd_buf.memCopyIn(buf_bytes, len(buf_bytes))

        return ecmd_buf

    if isinstance(buf, _str_types):
        bits = bitstring.Bits(buf)
        return _to_ecmdDataBuffer(bits)

    return buf
Пример #3
0
def _to_ecmdDataBuffer(buf, defwidth=64):
    if isinstance(buf, _int_types):
        # negative numbers in Python start with infinite one bits, so strip off infinity minus 64 ;)
        buf = buf & ((1 << defwidth) - 1)

        ecmd_buf = ecmd.ecmdDataBuffer(defwidth)
        if defwidth == 64:
            ecmd_buf.setDoubleWord(0, buf)
        elif defwidth == 32:
            ecmd_buf.setWord(0, buf)
        else:
            raise NotImplementedError()

        return ecmd_buf
    if isinstance(buf, bitstring.Bits):
        ecmd_buf = ecmd.ecmdDataBuffer(len(buf))
        overhang = len(buf) % 64
        bits = buf + bitstring.Bits(64 - (len(buf) % 64)) if overhang else buf # pad to multiples of 64 bits
        for i in range(len(bits) // 64):
            ecmd_buf.setDoubleWord(i, bits[i*64:(i+1)*64].uint)
        return ecmd_buf
    if isinstance(buf, (str, unicode)):
        bits = bitstring.Bits(buf)
        return _to_ecmdDataBuffer(bits)
    return buf
Пример #4
0
def loadDataBuffer(filename, save_format=ecmd.ECMD_SAVE_FORMAT_BINARY):
    """
    Load a file saved by ecmdDataBuffer and return an EcmdBitArray containing the data
    @rtype: EcmdBitArray
    """
    buf = ecmd.ecmdDataBuffer()
    _bufwrap(buf.readFile(filename, save_format))
    return _from_ecmdDataBuffer(buf)
Пример #5
0
def loadDataBuffer(filename, save_format = ecmd.ECMD_SAVE_FORMAT_BINARY):
    """
    Load a file saved by ecmdDataBuffer and return an EcmdBitArray containing the data
    @rtype: EcmdBitArray
    """
    buf = ecmd.ecmdDataBuffer()
    _bufwrap(buf.readFile(filename, save_format))
    return _from_ecmdDataBuffer(buf)
Пример #6
0
    def putscom(self, addr, val, start=0, numBits=64):
        spyData = ecmd.ecmdDataBuffer(64)
        scomData = ecmd.ecmdDataBuffer(64)
        scomMask = ecmd.ecmdDataBuffer(64)

        if self.debug:
            print("putscom(0x%016x, 0x%016x)" % (addr, val))

        addr = self.__mangle(addr)
        scomMask.flushTo0()  #reset mask to default 0 value
        for x in range(start, start + numBits):
            scomMask.setBit(
                x)  #generates mask based on start and numBits values
        scomData.insertFromHexLeft(data, start, numBits)
        ecmd.ecmdConfigLooperNext(self.tgt, self.looper)
        rc = ecmd.putScomUnderMask(self.tgt, addr, scomData, scomMask)
        if (rc):
            print("ERROR: problem calling putScom")
Пример #7
0
    def getscom(self, addr):
        scomData = ecmd.ecmdDataBuffer(64)

        if self.debug:
            print("getscom(0x%016x, 0x%016x)" % (addr, val))

        #addr = self.__mangle(addr)
        scomData.flushTo0()  #reset mask to default 0 value
        #ecmd.ecmdConfigLooperNext(self.tgt, self.looper)
        rc = ecmd.getScom(self.tgt, addr, scomData)
        if (rc):
            print("ERROR: problem calling putScom")
        return scomData.getDoubleWord(0)
Пример #8
0
# Load the eCMD python module
import ecmd
import os
import sys

# Create our test number variable
# It will be incremented after each test that executes
testNum = 0

# Do some data buffer tests
testNum+=1; print("edb %02d) Create a buffer" % testNum)
edb = ecmd.ecmdDataBuffer(64)

testNum+=1; print("edb %02d) Set a bit" % testNum)
edb.setBit(4)

testNum+=1; print("edb %02d) Get a bit, and print it" % testNum)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum+=1; print("edb %02d) Clear a bit, get it and print it" % testNum)
edb.clearBit(4)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum+=1; print("edb %02d) Set work 1 to 0x01234567, get it and print it" % testNum)
edb.setWord(1, 0x01234567)
print("The value of word 1 is 0x%08x" % edb.getWord(1))

testNum+=1; print("edb %02d) Get byte 5, it should be 0x23" % testNum)
print("The value of byte 5 is 0x%02x" % edb.getByte(5))

testNum+=1; print("edb %02d) Or two databuffers together, result should be 0x89ABCDEF" % testNum)
Пример #9
0
    # Pull them to prevent compile issues
    #core_id, thread_id = t.targetToSequenceId()
    #unit_id_string = unitIdToString(2)
    #clock_state = t.queryClockState("SOMECLOCK")
    t.relatedTargets("pu.c")
    retval = t.queryFileLocationHidden2(ECMD_FILE_SCANDEF, "")
    for loc in retval.fileLocations:
        testval = loc.textFile + loc.hashFile + retval.version

    if "fapi2" in extensions:
        try:
            t.fapi2GetAttr("ATTR_DOES_NOT_EXIST")
            assert ("" == "That was supposed to throw!")
        except KeyError:
            pass

        t.fapi2SetAttr("ATTR_CHIP_ID", 42)
        assert (42 == t.fapi2GetAttr("ATTR_CHIP_ID"))

    # Some buffer tests
    b = ecmdDataBuffer(64)
    b.setDoubleWord(0, 0x1234567812345678)
    assert (convertFromDataBuffer(b).uint == 0x1234567812345678)

    b = EcmdBitArray("0x1234567812345678")
    assert (convertToDataBuffer(b).getDoubleWord(0) == 0x1234567812345678)
    assert (convertToDataBuffer("0x1234567812345678").getDoubleWord(0) ==
            0x1234567812345678)
    assert (convertToDataBuffer(0x1234567812345678).getDoubleWord(0) ==
            0x1234567812345678)
Пример #10
0
# Load the eCMD python module
import ecmd
import os
import sys

# Create our test number variable
# It will be incremented after each test that executes
testNum = 0

# Do some data buffer tests
testNum += 1
print("edb %02d) Create a buffer" % testNum)
edb = ecmd.ecmdDataBuffer(64)

testNum += 1
print("edb %02d) Set a bit" % testNum)
edb.setBit(4)

testNum += 1
print("edb %02d) Get a bit, and print it" % testNum)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum += 1
print("edb %02d) Clear a bit, get it and print it" % testNum)
edb.clearBit(4)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum += 1
print("edb %02d) Set work 1 to 0x01234567, get it and print it" % testNum)
edb.setWord(1, 0x01234567)
print("The value of word 1 is 0x%08x" % edb.getWord(1))
Пример #11
0
# Load the eCMD python module
import ecmd
import os
import sys

# Create our test number variable
# It will be incremented after each test that executes
testNum = 0

# Do some data buffer tests
testNum += 1
print("edb %02d) Create a buffer" % testNum)
edb = ecmd.ecmdDataBuffer(64)

testNum += 1
print("edb %02d) Set a bit" % testNum)
edb.setBit(4)

testNum += 1
print("edb %02d) Get a bit, and print it" % testNum)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum += 1
print("edb %02d) Clear a bit, get it and print it" % testNum)
edb.clearBit(4)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum += 1
print("edb %02d) Set work 1 to 0x01234567, get it and print it" % testNum)
edb.setWord(1, 0x01234567)
print("The value of word 1 is 0x%08x" % edb.getWord(1))
Пример #12
0
# Load the eCMD python module
import ecmd
import os
import sys

# Create our test number variable
# It will be incremented after each test that executes
testNum = 0

# Do some data buffer tests
testNum+=1; print("edb %02d) Create a buffer" % testNum)
edb = ecmd.ecmdDataBuffer(64)

testNum+=1; print("edb %02d) Set a bit" % testNum)
edb.setBit(4)

testNum+=1; print("edb %02d) Get a bit, and print it" % testNum)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum+=1; print("edb %02d) Clear a bit, get it and print it" % testNum)
edb.clearBit(4)
print("The value of bit 4 is %s" % edb.getBit(4))

testNum+=1; print("edb %02d) Set work 1 to 0x01234567, get it and print it" % testNum)
edb.setWord(1, 0x01234567)
print("The value of word 1 is 0x%08x" % edb.getWord(1))

testNum+=1; print("edb %02d) Get byte 5, it should be 0x23" % testNum)
print("The value of byte 5 is 0x%02x" % edb.getByte(5))

testNum+=1; print("edb %02d) Or two databuffers together, result should be 0x89ABCDEF" % testNum)