"""
This script demonstrates all the functions from CStorageDeviceController
and CStorageDeviceFactory classes. The functions from these classes are
used to manipulate the various memory devices.
This script uses eMMC storage device as an example and assumes that there
is "Standard eMMC eMMC" device configured in winIDEA workspace and that debug
debug session is already initialized.
This script also creates a dummy binary file (dummyEmmc1.bin), in workspace
directory, that is later programmed to eMMC.
Be aware as this script also changes contents of eMMC device.
"""
import isystem.connect as ic
winidea_id = ''
def createDummyBinaryFile(filePath: str, content: bytes):
fileHandle = None
try:
fileHandle = open(filePath, "wb")
fileHandle.write(content)
except Exception as ex:
print(f"Cannot create file: {filePath}")
finally:
if fileHandle is not None:
fileHandle.close()
def getStorageDeviceIndex(connMgr: ic.ConnectionMgr, storageDeviceName: str) -> int:
configuredStorageDevices = ic.StrVector()
ic.CStorageDeviceFactory.getDeviceNames(connMgr, configuredStorageDevices)
storageDeviceIndex = 0
for storageDevice in configuredStorageDevices:
if storageDevice == storageDeviceName:
return storageDeviceIndex
storageDeviceIndex += 1
return -1
def printDeviceInfo(connMgr: ic.ConnectionMgr, storageDeviceName: str):
deviceInfoMap = ic.StrStrMap()
ic.CStorageDeviceFactory.getDeviceInfo(connMgr, storageDeviceName, deviceInfoMap)
print("Device info:")
for key in deviceInfoMap:
print(f"\t{key}: {deviceInfoMap[key]}")
def printPartitionInfo(emmcPartitionCtrl: ic.CStorageDeviceController):
partitionCfg = emmcPartitionCtrl.getPartitionConfigurationModule()
partitionInfo = partitionCfg.getPartitionInfo()
print("Partition info:")
print(f"\tName: {partitionInfo.getName()}")
print(f"\tType: {partitionInfo.getType()}")
print(f"\tBootable: {partitionInfo.isBootable()}")
print(f"\tExtended: {partitionInfo.getExtended()}")
print(f"\tSize [B]: {partitionInfo.getSize()}")
print(f"\tOffset: {partitionInfo.getOffset()}")
print(f"\tEnhanced size [B]: {partitionInfo.getEnhancedSize()}")
print(f"\tEnhanced offset: {partitionInfo.getEnhancedOffset()}")
print(f"\tCan boot status be changed: {partitionInfo.canModifyBoot()}")
print(f"\tCan be removed: {partitionInfo.canRemove()}")
print(f"\tCan size be modified: {partitionInfo.canModifySize()}")
print(f"\tCan offset be modified: {partitionInfo.canModifyOffset()}")
print(f"\tCan name be modified: {partitionInfo.canModifyName()}")
def main():
connMgr = ic.ConnectionMgr()
connMgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
emmcDeviceIndex = getStorageDeviceIndex(connMgr, "Standard eMMC eMMC")
if emmcDeviceIndex < 0:
print("No device named \"Standard eMMC eMMC\" is configured")
return
else:
print(f"eMMC storage device index: {emmcDeviceIndex}")
printDeviceInfo(connMgr, "Standard eMMC eMMC")
try:
emmcPartitionCtrl = ic.CStorageDeviceFactory.makeDevice(connMgr,
ic.EStorageDevice_EMMCDevice,
"Standard eMMC eMMC",
"UserData")
baseAddress = 0
size_B = 4
writeBuffer = ic.VectorBYTE([0xDE, 0xAD, 0xBE, 0xEF])
emmcPartitionCtrl.write(ic.IConnectUMI.wProgDevice, baseAddress, size_B, writeBuffer)
readBuffer = ic.VectorBYTE()
emmcPartitionCtrl.read(baseAddress, size_B, readBuffer)
print(f"Read {size_B} bytes of data from address {baseAddress} in UserData partition:")
for byte in readBuffer:
print(f"\t{hex(byte)}")
emmcPartitionCtrl.erase(ic.IConnectUMI.wProgDevice, baseAddress, size_B)
isEmpty = emmcPartitionCtrl.isDeviceEmpty(baseAddress, size_B)
endAddress = baseAddress + size_B
if isEmpty:
print(f"eMMC UserData partition is empty in range {hex(baseAddress)}-{hex(endAddress)}")
else:
print(f"eMMC UserData partition is not empty in range {hex(baseAddress)}-{hex(endAddress)}")
except Exception as ex:
print(f"Exception occurred in Python eMMC example: {str(ex)}")
finally:
ic.CStorageDeviceFactory.terminateDevice(connMgr,
ic.EStorageDevice_EMMCDevice,
"Standard eMMC eMMC")
try:
emmcPartitionCtrl = ic.CStorageDeviceFactory.makeDevice(connMgr,
ic.EStorageDevice_EMMCDevice,
emmcDeviceIndex,
"Boot2")
emmcPartitionCtrl.erase(ic.IConnectUMI.wProgDevice)
isEmpty = emmcPartitionCtrl.isDeviceEmpty()
if isEmpty:
print(f"Whole eMMC Boot2 partition is empty")
else:
print(f"Whole eMMC Boot2 partition is not empty")
ideCtrl = ic.CIDEController(connMgr)
workspacePath = ideCtrl.getPath(ic.CIDEController.WORKSPACE_DIR)
filePath = f"{workspacePath}\\dummyBin1.bin"
content = b'\xAA\xBB\xCC\xDD'
fileOffset = 0x0
createDummyBinaryFile(filePath, content)
emmcPartitionCtrl.write(ic.IConnectUMI.wProgDevice, ic.IConnectUMI.wFileFormatBin, fileOffset, filePath)
lastError = emmcPartitionCtrl.getLastError()
if len(lastError) != 0:
print(f"Last detected error: {lastError}")
else:
print(f"Last detected error: no error occurred")
except Exception as ex:
print(f"Exception occurred in Python eMMC example: {str(ex)}")
finally:
ic.CStorageDeviceFactory.terminateDevice(connMgr,
ic.EStorageDevice_EMMCDevice,
emmcDeviceIndex)
if __name__ == "__main__":
main()