Skip to content

Commit

Permalink
Added "quiet" arg for less intrusive autodetection probes
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Jul 31, 2018
1 parent 0310d43 commit 05a75b0
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 85 deletions.
2 changes: 1 addition & 1 deletion ARM7TDMISProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ ARM7TDMISProcessor::~ARM7TDMISProcessor()

}

void ARM7TDMISProcessor::PostInitProbes()
void ARM7TDMISProcessor::PostInitProbes(bool /*quiet*/)
{
//WriteIceRegister(DEBUG_CTRL, 0x3f);
//uint32_t ret = ReadIceRegister(DEBUG_CTRL);
Expand Down
2 changes: 1 addition & 1 deletion ARM7TDMISProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ARM7TDMISProcessor : public DebuggableDevice
BYPASS = 0xf
};

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Internal debug stuff
Expand Down
2 changes: 1 addition & 1 deletion ARMDebugPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ARMDebugPort::ARMDebugPort(
m_defaultRegisterAP = NULL;
}

void ARMDebugPort::PostInitProbes()
void ARMDebugPort::PostInitProbes(bool quiet)
{
//Turn on the debug stuff
EnableDebugging();
Expand Down
2 changes: 1 addition & 1 deletion ARMDebugPort.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ARMDebugPort : public ARMDevice
INST_APACC = 0x0b,
};

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info
Expand Down
2 changes: 1 addition & 1 deletion FreescaleIMXDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ FreescaleIMXDevice::~FreescaleIMXDevice()
{
}

void FreescaleIMXDevice::PostInitProbes()
void FreescaleIMXDevice::PostInitProbes(bool /*quiet*/)
{
//Get a pointer to our ARM DAP. This should always be one scan chain position before us.
m_dap = dynamic_cast<ARMDebugPort*>(m_iface->GetDevice(m_pos-2));
Expand Down
2 changes: 1 addition & 1 deletion FreescaleIMXDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FreescaleIMXDevice : public FreescaleMicrocontroller
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

///5-bit-wide JTAG instructions (from datasheet table 56-3)
enum instructions
Expand Down
2 changes: 1 addition & 1 deletion FreescaleIMXSmartDMA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ FreescaleIMXSmartDMA::FreescaleIMXSmartDMA(
}
}

void FreescaleIMXSmartDMA::PostInitProbes()
void FreescaleIMXSmartDMA::PostInitProbes(bool /*quiet*/)
{

}
Expand Down
2 changes: 1 addition & 1 deletion FreescaleIMXSmartDMA.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class FreescaleIMXSmartDMA
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info
Expand Down
4 changes: 3 additions & 1 deletion JtagDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ class JtagDevice

/**
@brief Does a post-initialization probe of the device to read debug ROMs etc.
@param quiet Do minimal probing to avoid triggering security lockdowns
*/
virtual void PostInitProbes() =0;
virtual void PostInitProbes(bool quiet) =0;

bool LookupConstant(std::string name, uint32_t& value)
{
Expand Down
2 changes: 1 addition & 1 deletion JtagDummy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ JtagDummy::~JtagDummy()

}

void JtagDummy::PostInitProbes()
void JtagDummy::PostInitProbes(bool /*quiet*/)
{

}
Expand Down
2 changes: 1 addition & 1 deletion JtagDummy.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class JtagDummy : public JtagDevice
virtual ~JtagDummy();

virtual std::string GetDescription();
virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);
};

#endif
Expand Down
4 changes: 2 additions & 2 deletions JtagInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void JtagInterface::PrintChainFaultMessage()
@throw JtagException if any of the scan operations fails.
*/
void JtagInterface::InitializeChain()
void JtagInterface::InitializeChain(bool quiet)
{
//Clear out any junk already on the chain. This is necessary if chain state ever changes
m_idcodes.clear();
Expand Down Expand Up @@ -319,7 +319,7 @@ void JtagInterface::InitializeChain()
for(auto p : m_devices)
{
if(p)
p->PostInitProbes();
p->PostInitProbes(quiet);
}
}

Expand Down
2 changes: 1 addition & 1 deletion JtagInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class JtagInterface
virtual void ResetToIdle(); //TODO: Make this protected as well? Not likely to be needed for anything in well-written code

//High-level JTAG interface (register level)
void InitializeChain();
void InitializeChain(bool quiet = false);
size_t GetDeviceCount();
unsigned int GetIDCode(unsigned int device);
JtagDevice* GetDevice(unsigned int device);
Expand Down
2 changes: 1 addition & 1 deletion MicrochipPIC32Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ MicrochipPIC32Device::MicrochipPIC32Device(
}
}

void MicrochipPIC32Device::PostInitProbes()
void MicrochipPIC32Device::PostInitProbes(bool /*quiet*/)
{
//Reset both TAPS
EnterMtapMode();
Expand Down
2 changes: 1 addition & 1 deletion MicrochipPIC32Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ class MicrochipPIC32Device : public MicrochipMicrocontroller
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

///Device families
enum families
Expand Down
152 changes: 88 additions & 64 deletions STM32Device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ STM32Device::STM32Device(
"");
}

//Look up RAM size (TODO can we get this from descriptors somehow?)
switch(m_deviceID)
{
case STM32F411E:
m_ramKB = 128;
break;

default:
m_ramKB = 0;
}

//uint32_t id = m_dap->ReadMemory(0xe0042000);
//LogDebug("id = %08x\n", id);

Expand All @@ -66,7 +77,7 @@ STM32Device::STM32Device(

}

void STM32Device::PostInitProbes()
void STM32Device::PostInitProbes(bool quiet)
{
//Get a pointer to our ARM DAP. This should always be one scan chain position before us.
m_dap = dynamic_cast<ARMDebugPort*>(m_iface->GetDevice(m_pos-1));
Expand All @@ -77,80 +88,89 @@ void STM32Device::PostInitProbes()
"");
}

//Look up size of flash memory
try
{
m_flashKB = m_dap->ReadMemory(0x1fff7a20) >> 16; //F_ID, flash size in kbytes
}
catch(const JtagException& e)
//Leave a lot of stuff blank to avoid probing and tripping alarms
if(quiet)
{
//If we fail, set flash size to zero so we don't try doing anything with it
//unknown protection level
m_protectionLevel = 3;
m_locksProbed = true;
m_flashKB = 0;

if(!IsDeviceReadLocked().GetValue())
LogWarning("STM32Device: Unable to read flash memory size even though read protection doesn't seem to be set\n");

else
LogVerbose("STM32Device: Cannot determine flash size because read protection is set\n");
}

//Look up RAM size (TODO can we get this from descriptors somehow?)
switch(m_deviceID)
{
case STM32F411E:
m_ramKB = 128;
break;

default:
m_ramKB = 0;
m_waferX = 0;
m_waferY = 0;
m_waferNum = 0;
strncpy(m_waferLot, "???????", sizeof(m_waferLot));
for(int i=0; i<12; i++)
m_serialRaw[i] = 0;
return;
}

//Check read lock status
STM32Device::ProbeLocksNondestructive();

//Look up size of flash memory.
//If locked, don't try reading as this will trigger security lockdown
if(IsDeviceReadLocked().GetValue())
LogVerbose("STM32Device: Cannot determine flash size because read protection is set\n");
else
{
try
{
m_flashKB = m_dap->ReadMemory(0x1fff7a20) >> 16; //F_ID, flash size in kbytes
}
catch(const JtagException& e)
{
//If we fail, set flash size to zero so we don't try doing anything with it
m_flashKB = 0;
LogWarning("STM32Device: Unable to read flash memory size even though read protection doesn't seem to be set\n");
}
}

//Extract serial number fields
try
if(IsDeviceReadLocked().GetValue())
{
uint32_t serial[3];
serial[0] = m_dap->ReadMemory(0x1fff7a10);
serial[1] = m_dap->ReadMemory(0x1fff7a14);
serial[2] = m_dap->ReadMemory(0x1fff7a18);
m_waferX = serial[0] >> 16;
m_waferY = serial[0] & 0xffff;
m_waferNum = serial[1] & 0xff;
m_waferLot[0] = (serial[1] >> 24) & 0xff;
m_waferLot[1] = (serial[1] >> 16) & 0xff;
m_waferLot[2] = (serial[1] >> 8) & 0xff;
m_waferLot[3] = (serial[2] >> 24) & 0xff;
m_waferLot[4] = (serial[2] >> 16) & 0xff;
m_waferLot[5] = (serial[2] >> 8) & 0xff;
m_waferLot[6] = (serial[2] >> 0) & 0xff;
m_waferLot[7] = 0;
m_serialRaw[0] = m_waferX >> 8;
m_serialRaw[1] = m_waferX & 0xff;
m_serialRaw[2] = m_waferY >> 8;
m_serialRaw[3] = m_waferY & 0xff;
m_serialRaw[4] = m_waferNum;
for(int i=0; i<7; i++)
m_serialRaw[5+i] = m_waferLot[i];
LogVerbose("STM32Device: Cannot determine serial number because read protection is set\n");
}
catch(const JtagException& e)
else
{
//If we can't read the serial number, that probably means the chip is locked.
//Write zeroes rather than leaving it uninitialized.
m_waferX = 0;
m_waferY = 0;
m_waferNum = 0;
strncpy(m_waferLot, "???????", sizeof(m_waferLot));
for(int i=0; i<12; i++)
m_serialRaw[i] = 0;

//Display a warning if the chip is NOT locked, but we couldn't read the serial number anyway
if(!IsDeviceReadLocked().GetValue())
try
{
uint32_t serial[3];
serial[0] = m_dap->ReadMemory(0x1fff7a10);
serial[1] = m_dap->ReadMemory(0x1fff7a14);
serial[2] = m_dap->ReadMemory(0x1fff7a18);
m_waferX = serial[0] >> 16;
m_waferY = serial[0] & 0xffff;
m_waferNum = serial[1] & 0xff;
m_waferLot[0] = (serial[1] >> 24) & 0xff;
m_waferLot[1] = (serial[1] >> 16) & 0xff;
m_waferLot[2] = (serial[1] >> 8) & 0xff;
m_waferLot[3] = (serial[2] >> 24) & 0xff;
m_waferLot[4] = (serial[2] >> 16) & 0xff;
m_waferLot[5] = (serial[2] >> 8) & 0xff;
m_waferLot[6] = (serial[2] >> 0) & 0xff;
m_waferLot[7] = 0;
m_serialRaw[0] = m_waferX >> 8;
m_serialRaw[1] = m_waferX & 0xff;
m_serialRaw[2] = m_waferY >> 8;
m_serialRaw[3] = m_waferY & 0xff;
m_serialRaw[4] = m_waferNum;
for(int i=0; i<7; i++)
m_serialRaw[5+i] = m_waferLot[i];
}
catch(const JtagException& e)
{
//If we can't read the serial number, that probably means the chip is locked.
//Write zeroes rather than leaving it uninitialized.
m_waferX = 0;
m_waferY = 0;
m_waferNum = 0;
strncpy(m_waferLot, "???????", sizeof(m_waferLot));
for(int i=0; i<12; i++)
m_serialRaw[i] = 0;

//Display a warning if the chip is NOT locked, but we couldn't read the serial number anyway
LogWarning("STM32Device: Unable to read serial number even though read protection doesn't seem to be set\n");

else
LogVerbose("STM32Device: Cannot determine serial number because read protection is set\n");
}
}
}

Expand Down Expand Up @@ -260,7 +280,8 @@ void STM32Device::PrintLockProbeDetails()
{
"completely unlocked",
"boundary scan enabled, memory access and debug disabled",
"JTAG completely disabled"
"JTAG completely disabled",
"quiet probe, lock status not checked"
};
LogNotice("STM32 read protection level appears to be: %d (%s)\nDetails:\n", m_protectionLevel, table[m_protectionLevel]);

Expand Down Expand Up @@ -425,6 +446,9 @@ UncertainBoolean STM32Device::IsDeviceReadLocked()
case 0:
return UncertainBoolean( false, UncertainBoolean::CERTAIN );

case 3:
return UncertainBoolean( true, UncertainBoolean::USELESS );

case 1:
default:
return UncertainBoolean( true, UncertainBoolean::VERY_LIKELY );
Expand Down
2 changes: 1 addition & 1 deletion STM32Device.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class STM32Device
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// General device info
Expand Down
2 changes: 1 addition & 1 deletion XilinxCoolRunnerIIDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ XilinxCoolRunnerIIDevice::XilinxCoolRunnerIIDevice(
m_stepping = stepping;
}

void XilinxCoolRunnerIIDevice::PostInitProbes()
void XilinxCoolRunnerIIDevice::PostInitProbes(bool /*quiet*/)
{
}

Expand Down
2 changes: 1 addition & 1 deletion XilinxCoolRunnerIIDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class XilinxCoolRunnerIIDevice : public XilinxCPLD
JtagInterface* iface,
size_t pos);

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

///JTAG device IDs
enum deviceids
Expand Down
2 changes: 1 addition & 1 deletion XilinxFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ XilinxFPGA::XilinxFPGA(unsigned int idcode, JtagInterface* iface, size_t pos, si
{
}

void XilinxFPGA::PostInitProbes()
void XilinxFPGA::PostInitProbes(bool /*quiet*/)
{

}
Expand Down
2 changes: 1 addition & 1 deletion XilinxFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class XilinxFPGA : public XilinxDevice
XilinxFPGA(unsigned int idcode, JtagInterface* iface, size_t pos, size_t irlength);
virtual ~XilinxFPGA();

virtual void PostInitProbes();
virtual void PostInitProbes(bool quiet);

public:
//Configuration bus access
Expand Down

0 comments on commit 05a75b0

Please sign in to comment.