package com.microchip.mplab.ipelib.device; import com.microchip.crownking.Pair; import com.microchip.crownking.edc.Bitfield; import com.microchip.crownking.edc.DCR; import com.microchip.crownking.edc.Field; import com.microchip.crownking.edc.MemoryPartition; import com.microchip.crownking.edc.Programming; import com.microchip.crownking.edc.Region; import com.microchip.crownking.mplabinfo.FamilyDefinitions.Family; import com.microchip.mplab.crownkingx.xMemoryPartition; import com.microchip.mplab.crownkingx.xPIC; import com.microchip.mplab.ipelib.common.SharedData; import com.microchip.mplab.ipelib.tools.IPENotifier; import com.microchip.mplab.mdbcore.assemblies.Assembly; import com.microchip.mplab.mdbcore.memory.MemoryEvent; import com.microchip.mplab.mdbcore.memory.MemoryModel; import com.microchip.mplab.mdbcore.memory.MultiPartition; import com.microchip.mplab.mdbcore.memory.PhysicalMemory; import com.microchip.mplab.mdbcore.memory.MemoryEvent.EVENTS; import com.microchip.mplab.mdbcore.memory.MultiPartition.MODE; import com.microchip.mplab.mdbcore.memory.memorytypes.BootMemory; import com.microchip.mplab.mdbcore.memory.memorytypes.ConfigurationBits; import com.microchip.mplab.mdbcore.memory.memorytypes.DataFlash; import com.microchip.mplab.mdbcore.memory.memorytypes.DeviceID; import com.microchip.mplab.mdbcore.memory.memorytypes.EEData; import com.microchip.mplab.mdbcore.memory.memorytypes.FlashData; import com.microchip.mplab.mdbcore.memory.memorytypes.ProgramMemory; import com.microchip.mplab.mdbcore.memory.memorytypes.UserID; import java.util.List; import java.util.Map.Entry; import org.openide.util.Lookup.Result; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class CDevice { private xPIC picdevicedb = null; private SharedData sharedData; private Programming programming = null; private MemoryModel memModel; public long auxMemBeginAddr = 0L; public long auxMemEndAddr = 0L; private long flashBeginAddress = 0L; private long flashEndAddress = 0L; private long pgmMemBeginAddr = 0L; private long pgmMemEndAddr = 0L; private long memoryBeginAddress = 0L; private long memoryEndAddress = 0L; public long eememoryBeginAddr = 0L; public long eememoryEndAddr = 0L; private long userIDBeginAddr = 0L; private long userIDEndAddr = 0L; private long cfgMemBeginAddress = 0L; private long cfgMemEndAddress = 0L; private long bootMemBeginAddr = 0L; private long bootMemEndAddr = 0L; private PhysicalMemory programMemory = null; private PhysicalMemory DataFlash = null; private PhysicalMemory EEMemory = null; private PhysicalMemory userID = null; private PhysicalMemory configMemory = null; private PhysicalMemory flashData = null; private PhysicalMemory bootMem = null; private PhysicalMemory deviceID = null; private MemoryObserver memoryObserver = null; private Long DataflashEndAddress; private Long DataflashBeginAddress; private boolean Is_Partitioned = false; public CDevice() { this.sharedData = SharedData.getSingletonObject(); this.memoryObserver = new MemoryObserver(); } public boolean getDeviceInfo() { this.picdevicedb = this.sharedData.getDeviceName(); if (this.picdevicedb != null) { this.programming = this.picdevicedb.getProgramming(); return true; } else { return false; } } public int getBytesPerWord() { try { long p = this.picdevicedb.getMemTraits().getCodeWordTraits().getWordSize(); return (int)p; } catch (Exception var3) { return -1; } } public int getAddrInc() { return (int)this.picdevicedb.getMemTraits().getCodeWordTraits().getAddrInc(); } public boolean getProgramMemoryRange(long start, long end) { Pair ePgmMemRange = this.picdevicedb.getInstRange(); if (this.picdevicedb.getMainPartition().hasAuxCode()) { ePgmMemRange = this.picdevicedb.getCodeRange(); } if (!this.picdevicedb.getIDOntoPartition().isEmpty()) { ePgmMemRange = this.picdevicedb.getMainPartition().getFileRange(); } if (this.sharedData.getAssemblySession().GetDeviceName().startsWith("ATSAM")) { this.pgmMemBeginAddr = start; this.pgmMemEndAddr = end; return true; } else if (ePgmMemRange != null && (Long)ePgmMemRange.second != 0L) { this.pgmMemBeginAddr = (Long)ePgmMemRange.first; this.pgmMemEndAddr = (Long)ePgmMemRange.second; if (this.sharedData.getAssemblySession().GetDeviceName().startsWith("PIC32CZ")) { List nodes = this.picdevicedb.getMainPartition().getCodeRegions(); NamedNodeMap p = nodes.get(1).getAttributes(); String be = p.getNamedItem("edc:beginaddr").getNodeValue(); String en = p.getNamedItem("edc:endaddr").getNodeValue(); be = be.substring(2); en = en.substring(2); this.pgmMemBeginAddr = Long.parseLong(be, 16); this.pgmMemEndAddr = Long.parseLong(en, 16); } return true; } else { return false; } } public boolean getProgramMemoryRange(String id) { Pair ePgmMemRange = this.picdevicedb.getInstRange(); if (this.picdevicedb.getMainPartition().hasAuxCode()) { ePgmMemRange = this.picdevicedb.getCodeRange(); } if (this.picdevicedb.getIDOntoPartition().isEmpty()) { ePgmMemRange = this.picdevicedb.getMainPartition().getFileRange(); } else { ePgmMemRange = ((MemoryPartition)this.picdevicedb.getIDOntoPartition().get(id)).getCodeRange(); } if (ePgmMemRange != null && (Long)ePgmMemRange.second != 0L) { this.pgmMemBeginAddr = (Long)ePgmMemRange.first; this.pgmMemEndAddr = (Long)ePgmMemRange.second; return true; } else { return false; } } public Pair getMemoryRange(String memType) { if (memType.compareToIgnoreCase("program") == 0) { return this.picdevicedb.getInstRange(); } else if (memType.compareToIgnoreCase("eeprom") == 0) { return this.picdevicedb.getMagicEEDataRange(); } else if (memType.compareToIgnoreCase("flash") == 0) { return this.picdevicedb.getFlashDataRange(); } else if (memType.compareToIgnoreCase("boot") == 0) { return this.picdevicedb.getBootRAMRange(); } else if (memType.compareToIgnoreCase("user") == 0) { return this.picdevicedb.getUserIDRange(); } else { return memType.compareToIgnoreCase("auxilary") == 0 ? this.picdevicedb.getAuxCodeRange() : null; } } public boolean isValidProgramMemoryRange(long sAddr, long eAddr) { Pair ePgmMemRange = this.picdevicedb.getInstRange(); if (!this.picdevicedb.getIDOntoPartition().isEmpty()) { ePgmMemRange = this.picdevicedb.getMainPartition().getFileRange(); } if (ePgmMemRange == null || (Long)ePgmMemRange.second == 0L) { return false; } else { return sAddr < 0L || eAddr <= 0L || sAddr >= eAddr ? false : sAddr >= (Long)ePgmMemRange.first && sAddr < (Long)ePgmMemRange.second && eAddr > (Long)ePgmMemRange.first && eAddr <= (Long)ePgmMemRange.second; } } public boolean isValidEEMemoryRange(long sAddr, long eAddr) { Pair eEEMemRange = this.picdevicedb.getMainPartition().getMagicEEDataRange(); if (eEEMemRange == null || (Long)eEEMemRange.second == 0L) { return false; } else if (sAddr < 0L || eAddr <= 0L || sAddr >= eAddr) { return false; } else if (sAddr + (Long)eEEMemRange.first >= (Long)eEEMemRange.first && eAddr + (Long)eEEMemRange.first > (Long)eEEMemRange.first && eAddr + (Long)eEEMemRange.first <= (Long)eEEMemRange.second) { return true; } else { this.picdevicedb = this.getXPICDeviceInfo(); return this.picdevicedb == null ? false : this.picdevicedb.getFamily() == Family.ARM32BIT || this.picdevicedb.getFamily() == Family.AVR; } } public boolean isValidFlashMemoryRange(long sAddr, long eAddr) { Pair eEEMemRange = this.picdevicedb.getFlashDataRange(); if (eEEMemRange == null || (Long)eEEMemRange.second == 0L) { return false; } else { return sAddr < 0L || eAddr <= 0L || sAddr >= eAddr ? false : sAddr >= (Long)eEEMemRange.first && sAddr < (Long)eEEMemRange.second && eAddr > (Long)eEEMemRange.first && eAddr <= (Long)eEEMemRange.second; } } public boolean isValidAuxiliaryRange(long sAddr, long eAddr) { Pair eEEMemRange = this.picdevicedb.getAuxCodeRange(); if (eEEMemRange == null || (Long)eEEMemRange.second == 0L) { return false; } else { return sAddr < 0L || eAddr <= 0L || sAddr >= eAddr ? false : sAddr >= (Long)eEEMemRange.first && sAddr < (Long)eEEMemRange.second && eAddr > (Long)eEEMemRange.first && eAddr <= (Long)eEEMemRange.second; } } public long getPgmTotalMemoryInBytes(long startAdd, long endAddr) { long retVal = -1L; if (this.getProgramMemoryRange(startAdd, endAddr)) { retVal = this.pgmMemEndAddr - this.pgmMemBeginAddr + 1L; if (this.isProgramMemory() && this.programMemory.GetMemoryModel().WordIncrement() * 2 == this.programMemory.GetMemoryModel().WordSize()) { retVal = (retVal + this.pgmMemBeginAddr) * 2L; } } return retVal; } public long getPgmTotalMemoryInBytes(String id) { long retVal = -1L; if (this.getProgramMemoryRange(id)) { retVal = this.pgmMemEndAddr - this.pgmMemBeginAddr; if (this.isProgramMemory() && this.programMemory.GetMemoryModel().WordIncrement() * 2 == this.programMemory.GetMemoryModel().WordSize()) { retVal = (retVal + this.pgmMemBeginAddr) * 2L; } } return retVal; } public PhysicalMemory getMemory(Class cMemory) { MemoryModel Mem = null; PhysicalMemory physicalmemory = null; Assembly assembly = this.sharedData.getAssemblySession(); if (assembly != null && (Mem = (MemoryModel)assembly.getLookup().lookup(cMemory)) != null) { this.memModel = Mem; if (Mem == null) { return null; } physicalmemory = Mem.GetPhysicalMemory(); physicalmemory.Attach(this.memoryObserver, null); } return physicalmemory; } public long getPageSize() { long boundary = 128L; for (Region region : this.getXPICDeviceInfo().getMainPartition().getRegionObjects()) { if (region.getType().equals("CodeSector")) { if (region.getPageSize() != null) { boundary = region.getPageSize(); } break; } } return boundary; } public byte[] getProgramMemoryData(long lstart, long lend) { boolean retVal = this.isProgramMemory(); int bufferSize = 0; if (this.programMemory != null) { if (this.getProgramMemoryRange(lstart, lend)) { long memSize = this.pgmMemEndAddr - this.pgmMemBeginAddr + 1L; int offset1 = (int)memSize; if (offset1 > 0) { if (this.programMemory.GetMemoryModel().WordIncrement() * 2 == this.programMemory.GetMemoryModel().WordSize()) { bufferSize = (int)((offset1 + this.pgmMemBeginAddr) * 2L); } else { bufferSize = (int)(offset1 + this.pgmMemBeginAddr); if (this.programMemory.GetMemoryModel().WordIncrement() == 4) { bufferSize = offset1; } } this.programMemory.RefreshFromTarget(this.pgmMemBeginAddr, bufferSize); byte[] bytes = new byte[bufferSize]; if (this.programMemory.GetMemoryModel().WordIncrement() == 4) { this.programMemory.Read(this.pgmMemBeginAddr, bufferSize, bytes); } else { this.programMemory.Read(0L, bufferSize, bytes); } return bytes; } } return null; } else { return null; } } public byte[] getProgramMemoryData(String id) { boolean retVal = this.isProgramMemory(); int bufferSize = 0; if (this.programMemory != null && this.getProgramMemoryRange(id)) { long offset = (Long)((MemoryPartition)this.sharedData.getAssemblySession().GetDevice().getIDOntoPartition().get("only")).getCodeRange().first; long memSize = this.pgmMemEndAddr - (this.pgmMemBeginAddr - offset); bufferSize = (int)(2L * memSize); this.programMemory.RefreshFromTarget(this.pgmMemBeginAddr - offset, bufferSize); byte[] bytes = new byte[bufferSize]; if (this.programMemory.GetMemoryModel().WordIncrement() == 4) { this.programMemory.Read(this.pgmMemBeginAddr - offset, bufferSize, bytes); } else { this.programMemory.Read(this.pgmMemBeginAddr - offset, bufferSize, bytes); } return bytes; } else { return null; } } public int getEEBytesPerWord() { try { long p = this.picdevicedb.getMemTraits().getEEDataWordTraits().getWordSize(); return (int)p; } catch (Exception var3) { return -1; } } public int getEEAddrInc() { return (int)this.picdevicedb.getMemTraits().getEEDataWordTraits().getAddrInc(); } public long getEETotalMemoryInBytes() { long retVal = -1L; if (this.getEPROMMemoryRange()) { retVal = this.memoryEndAddress - this.memoryBeginAddress; } return retVal; } public boolean getEPROMMemoryRange() { Pair eEDataRange = this.picdevicedb.getEEDataRange(); this.memoryBeginAddress = (Long)eEDataRange.first; this.memoryEndAddress = (Long)eEDataRange.second; this.sharedData.setMemRange(eEDataRange); return true; } public boolean getEEmemoryRange() { Pair eMemRange = this.picdevicedb.getMagicEEDataRange(); this.eememoryBeginAddr = (Long)eMemRange.first; this.eememoryEndAddr = (Long)eMemRange.second; return true; } public byte[] getEEMemoryData() { byte[] bytes = null; if (this.EEMemory != null) { long memDiff = this.eememoryEndAddr - this.eememoryBeginAddr; int offset = (int)memDiff; if (offset > 0) { bytes = new byte[offset]; this.EEMemory.RefreshFromTarget(this.eememoryBeginAddr, offset); this.EEMemory.Read(this.eememoryBeginAddr, offset, bytes); } } return bytes; } public boolean isEEMemory() { this.EEMemory = this.getMemory(EEData.class); return this.EEMemory != null; } public boolean isConfigMemory() { try { this.configMemory = this.getMemory(ConfigurationBits.class); } catch (Exception var2) { return false; } return this.configMemory != null; } public boolean isProgramMemory() { this.programMemory = this.getMemory(ProgramMemory.class); return this.programMemory != null; } public boolean isDataFlash() { this.DataFlash = this.getMemory(DataFlash.class); return this.DataFlash != null; } public boolean isDeviceID() { this.deviceID = this.getMemory(DeviceID.class); return this.deviceID != null; } public boolean isAuxMem() { boolean retFlag = false; if (this.picdevicedb != null) { retFlag = this.picdevicedb.hasAuxCode(); } return retFlag; } public boolean isUserID() { xMemoryPartition xmp = this.picdevicedb.getMainPartition(); this.userID = this.getMemory(UserID.class); return xmp.hasUserID(); } public boolean hasOTPMemory() { xMemoryPartition xmp = this.picdevicedb.getMainPartition(); this.userID = this.getMemory(UserID.class); return xmp.hasUserOTP(); } public boolean isFlashData() { this.flashData = this.getMemory(FlashData.class); return this.flashData != null; } public boolean hasDIA_DCI_Memory() { xMemoryPartition xmp = this.picdevicedb.getMainPartition(); return xmp.hasDCI() || xmp.hasDIA(); } public boolean hasDIAMemory() { xMemoryPartition xmp = this.picdevicedb.getMainPartition(); return xmp.hasDIA(); } private boolean getUserIDRange() { xMemoryPartition xmp = this.picdevicedb.getMainPartition(); if (xmp.hasUserID() && this.picdevicedb.getMemTraits().getUserIDWordTraits() != null) { this.userIDBeginAddr = (Long)xmp.getUserIDRange().first; this.userIDEndAddr = (Long)xmp.getUserIDRange().second; return true; } else if (xmp.hasUserOTP()) { this.userIDBeginAddr = (Long)xmp.getUserOTPRange().first; this.userIDEndAddr = (Long)xmp.getUserOTPRange().second; return true; } else { return false; } } public long getuserIDTotalBytes() { long retVal = -1L; if (this.getUserIDRange()) { retVal = this.userIDEndAddr - this.userIDBeginAddr; if ((this.isUserID() || this.hasOTPMemory()) && this.userID.GetMemoryModel().WordIncrement() * 2 == this.userID.GetMemoryModel().WordSize()) { retVal *= 2L; } } else if (this.sharedData.getAssemblySession().GetDevice().getFamily().is32Bit()) { retVal = 2L; } return retVal; } public byte[] getUserIDdata() { long bufferSize = 0L; if ((this.userID != null || this.picdevicedb.getMainPartition().hasUserOTP()) && this.getUserIDRange()) { long userIDSize = this.userIDEndAddr - this.userIDBeginAddr; int offset = (int)userIDSize; if (offset > 0) { if (this.userID.GetMemoryModel().WordIncrement() * 2 == this.userID.GetMemoryModel().WordSize()) { bufferSize = offset * 2; } else { bufferSize = offset; } byte[] bytes = new byte[(int)bufferSize]; this.userID.RefreshFromTarget(this.userIDBeginAddr, bufferSize); this.userID.Read(this.userIDBeginAddr, bufferSize, bytes); return bytes; } } return null; } public byte[] getConfigMemoryData() { boolean retVal = this.isConfigMemory(); if (this.configMemory != null) { if (this.getConfigMemoryRange()) { long memDiff = this.cfgMemEndAddress - this.cfgMemBeginAddress; int offset = (int)((int)memDiff * this.picdevicedb.getMemTraits().getConfigFuseWordTraits().getWordSize()); if (offset > 0) { byte[] bytes = new byte[offset]; int g = this.configMemory.GetMemoryModel().WordSize(); this.configMemory.RefreshFromTarget(this.cfgMemBeginAddress, offset); this.configMemory.Read(this.cfgMemBeginAddress, offset, bytes); return bytes; } } return null; } else { return null; } } public boolean getConfigMemoryRange() { Pair eConfigMemRange = this.picdevicedb.getDCRRange(); if (eConfigMemRange != null) { this.cfgMemBeginAddress = (Long)eConfigMemRange.first; this.cfgMemEndAddress = (Long)eConfigMemRange.second; return true; } else { return false; } } public int getConfigBytesPerWord() { try { long p = this.picdevicedb.getMemTraits().getEEDataWordTraits().getWordSize(); return (int)p; } catch (Exception var3) { return -1; } } public long getUSerIDAdd() { long addrs = 0L; xMemoryPartition xmp = this.picdevicedb.getMainPartition(); if (xmp.hasUserID()) { addrs = (Long)xmp.getUserIDRange().first; } else if (xmp.hasUserOTP()) { addrs = (Long)xmp.getUserOTPRange().first; } return addrs; } public boolean getFlashDataRange() { Pair eFlashData = this.picdevicedb.getFlashDataRange(); this.flashBeginAddress = (Long)eFlashData.first; this.flashEndAddress = (Long)eFlashData.second; return true; } public boolean getDataFlashRange() { Pair eFlashData = this.picdevicedb.getDataSpaceRange(); this.DataflashBeginAddress = (Long)eFlashData.first; this.DataflashEndAddress = (Long)eFlashData.second; return true; } public byte[] getFlashMemoryData() { boolean retVal = this.isFlashData(); if (this.flashData != null) { byte[] bytes = null; if (this.getFlashDataRange()) { long memSize = this.flashEndAddress - this.flashBeginAddress; int offset = (int)memSize; if (offset > 0) { bytes = new byte[offset]; this.flashData.RefreshFromTarget(this.flashBeginAddress, offset); this.flashData.Read(this.flashBeginAddress, offset, bytes); } } return bytes; } else { return null; } } public byte[] getDataFlashMemory() { boolean retVal = this.isDataFlash(); if (this.DataFlash != null) { byte[] bytes = null; if (this.getDataFlashRange()) { long memSize = this.getDataFlashEndAddrs() * this.picdevicedb.getMemTraits().getDeviceIDWordTraits().getWordSize(); int offset = (int)memSize; if (offset > 0) { bytes = new byte[(int)memSize]; this.DataFlash.RefreshFromTarget(0L, memSize); this.DataFlash.Read(0L, memSize, bytes); } } return bytes; } else { return null; } } public boolean getBootMemRange() { Pair eBootMemRange = this.picdevicedb.getBootConfigRange(); if (eBootMemRange != null && (Long)eBootMemRange.second != 0L) { this.bootMemBeginAddr = (Long)eBootMemRange.first; this.bootMemEndAddr = (Long)eBootMemRange.second; return true; } else { return false; } } public long getBootMemInBytes() { long retVal = -1L; if (this.getBootMemRange()) { retVal = this.bootMemEndAddr - this.bootMemBeginAddr; if (this.isBootMem() && this.bootMem.GetMemoryModel().WordIncrement() * 2 == this.bootMem.GetMemoryModel().WordSize()) { retVal = (retVal + this.bootMemBeginAddr) * 2L; } } return retVal; } public boolean isBootMem() { this.bootMem = this.getMemory(BootMemory.class); return this.bootMem != null; } public byte[] getBootMemData() { byte[] bytes = null; if (this.bootMem != null) { this.getBootMemRange(); long memDiff = this.bootMemEndAddr - this.bootMemBeginAddr; int offset = (int)memDiff; if (offset > 0) { bytes = new byte[offset]; this.bootMem.RefreshFromTarget(this.bootMemBeginAddr, offset); this.bootMem.Read(this.bootMemBeginAddr, offset, bytes); } } return bytes; } public boolean getAuxMemRange() { Pair auxMemRange = this.picdevicedb.getAuxCodeRange(); if (auxMemRange != null && (Long)auxMemRange.second != 0L) { this.auxMemBeginAddr = (Long)this.picdevicedb.getAuxCodeRange().first; this.auxMemEndAddr = (Long)this.picdevicedb.getInstRange().second; return true; } else { return false; } } public long getAuxMemTotalMemoryInBytes() { long retVal = -1L; if (this.getAuxMemRange()) { retVal = this.auxMemEndAddr - this.auxMemBeginAddr; } return retVal; } public byte[] getAuxMemData() { byte[] bytes = null; if (this.programMemory != null) { long memDiff = this.auxMemEndAddr - this.auxMemBeginAddr; int offset = (int)memDiff; if (offset > 0) { bytes = new byte[offset * 2]; this.programMemory.RefreshFromTarget(this.auxMemBeginAddr, offset * 2); this.programMemory.Read(this.auxMemBeginAddr, offset * 2, bytes); } } return bytes; } public boolean checkVoltageSlab(float voltage) { float min = this.picdevicedb.getVddMinVoltage(); float max = this.picdevicedb.getVddMaxVoltage(); int TempIntvppmax = (int)(max * 1000.0F); int Tempintvppmin = (int)(min * 1000.0F); float Tempfloat1 = 0.0F; boolean retVal = false; for (int imp1 = Tempintvppmin; imp1 <= TempIntvppmax; imp1 += 125) { Tempfloat1 /= 1000.0F; if (voltage == Tempfloat1) { retVal = true; } } return retVal; } public xPIC getXPICDeviceInfo() { return this.picdevicedb; } public boolean hasVPPFirst() { this.sharedData = SharedData.getSingletonObject(); String Val = this.sharedData.getNodeAttributeText("/PIC/Programming", "edc:hasvppfirst", this.picdevicedb); return Val != null && Val.equals("true"); } public boolean hasLVPinProgramming() { this.sharedData = SharedData.getSingletonObject(); String Val = this.sharedData.getNodeAttributeText("/PIC/Programming", "edc:haslvp", this.picdevicedb); return Val != null && Val.equals("true"); } public long getDataFlashEndAddrs() { this.sharedData = SharedData.getSingletonObject(); String Val = this.sharedData.getNodeAttributeText("/PIC/DataFlashSpace/", "edc:endaddr", this.picdevicedb); if (Val != null) { if (Val.contains("0x")) { Val = Val.substring(2); } return Long.parseLong(Val, 16); } else { return -1L; } } public MemoryModel getMemModel() { return this.memModel; } public long getConfigStart() { return this.cfgMemBeginAddress; } public long getConfigSize() { this.getConfigMemoryRange(); return this.cfgMemEndAddress - this.cfgMemBeginAddress; } public void clearAll() { if (this.isProgramMemory()) { this.programMemory.Clear(); } if (this.isEEMemory()) { this.EEMemory.Clear(); } if (this.isDataFlash()) { this.DataFlash.Clear(); } this.updateMultiPartitionModeFromTargetImage(); if (this.isConfigMemory()) { this.configMemory.Clear(); } if (this.isFlashData()) { this.flashData.Clear(); } if (this.isUserID() || this.hasOTPMemory()) { this.userID.Clear(); } if (this.isBootMem()) { this.bootMem.Clear(); } if (!this.sharedData.getAssemblySession().GetDevice().getIDOntoPartition().isEmpty()) { this.updateFBOOT(); } IPENotifier.getIPENotifierController().setMemoryChangedNotification(); } public void setProgramMemory(PhysicalMemory pm) { this.programMemory = pm; this.programMemory.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setEEMemory(PhysicalMemory eem) { this.EEMemory = eem; this.EEMemory.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setBootMem(PhysicalMemory boot) { this.bootMem = boot; this.bootMem.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setIDMem(PhysicalMemory IDMem) { this.userID = IDMem; this.userID.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setConfigMem(PhysicalMemory configMem) { this.configMemory = configMem; this.configMemory.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setFlashMemory(PhysicalMemory fd) { this.flashData = fd; this.flashData.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public void setDataFlashMemory(PhysicalMemory fd) { this.DataFlash = fd; this.DataFlash.Notify(new MemoryEvent(EVENTS.MEMORY_CHANGED)); } public boolean isPartitioned() { this.updateMultiPartitionModeFromTargetImage(); return this.Is_Partitioned; } private void updateMultiPartitionModeFromTargetImage() { try { long fbootAddr = -1L; long btMode = -1L; xPIC picdevicedb = this.sharedData.getAssemblySession().GetDevice(); MemoryPartition mp = picdevicedb.getMainPartition(); ConfigurationBits config = (ConfigurationBits)this.sharedData.getAssemblySession().lookup(ConfigurationBits.class); if (!picdevicedb.getIDOntoPartition().isEmpty()) { Pair dcrr = this.findDCRNamed(mp, "FBOOT"); if (dcrr != null) { for (Bitfield bitfield : ((DCR)dcrr.second).getBitfields()) { String fname = bitfield.getName(); if (fname.equalsIgnoreCase("BTMODE")) { fbootAddr = (Long)dcrr.first; btMode = bitfield.getMask(); break; } } } if (fbootAddr != -1L && btMode != -1L) { byte[] buff = new byte[4]; long val = config.GetPhysicalMemory().ReadWord(fbootAddr); if (val == 0L) { } if ((val & btMode ^ btMode) != 0L) { this.Is_Partitioned = true; } else { this.Is_Partitioned = false; } } } } catch (Exception var12) { } } private Pair findDCRNamed(MemoryPartition mp, String wordName) { for (Entry dcrEntry : mp.getRegisterMap().getDCRsByAddress().entrySet()) { DCR dcr = dcrEntry.getValue(); if (wordName.equalsIgnoreCase(dcr.getName())) { return new Pair(dcrEntry.getKey(), dcr); } } return null; } private void updateFBOOT() { Assembly current_Session = this.sharedData.getAssemblySession(); Result mems = current_Session.getLookup().lookupResult(MemoryModel.class); for (Class cls : mems.allClasses()) { MemoryModel mem = (MemoryModel)current_Session.getLookup().lookup(cls); if (mem instanceof MultiPartition && this.Is_Partitioned) { long fbootAddr = -1L; long btMode = -1L; for (Entry e : this.picdevicedb.getAddrOntoDCR().entrySet()) { DCR dcr = new DCR(e.getValue()); for (Entry f : dcr.getPlaceOntoField().entrySet()) { Field field = new Field(f.getValue()); String fname = field.getName(); if (fname.equalsIgnoreCase("BTMODE")) { fbootAddr = e.getKey(); btMode = field.getMask() << (int)f.getKey().longValue(); break; } } } btMode &= -2L; PhysicalMemory config_mem = this.getMemory(ConfigurationBits.class); long val = config_mem.ReadWord(fbootAddr); val &= -2L; if (val != 0L) { config_mem.WriteWord(fbootAddr, val); } ((MultiPartition)mem).SetMode(MODE.MULTIPLE); ((MultiPartition)mem).SetActivePartition(1); } } } }