pylink icon indicating copy to clipboard operation
pylink copied to clipboard

Can't connect the device if the device had been secured.

Open ltbkey opened this issue 7 years ago • 11 comments

l used the script below, but if the device had been secured, the script occurs error. # Init the jlink jlink = pylink.JLink()

# Open a connection to your J-Link.
jlink.open(serial_no)

# Set SWD as the interface
jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)

# Connect to the target device.
jlink.connect('stm32f301k8',4000, verbose=True)

the error is shown below.

Traceback (most recent call last): File "jlink_flash.py", line 49, in jlink.connect('stm32f301k8',4000, verbose=True) File "D:\APP\Python27\lib\site-packages\pylink\jlink.py", line 141, in wrapper return func(self, *args, **kwargs) File "D:\APP\Python27\lib\site-packages\pylink\jlink.py", line 910, in connect result = self._dll.JLINKARM_Connect() WindowsError: exception: priviledged instruction

I tried to use "unlock()", but it didn't work. # jlink.unlock() #does not work

Looking forward your help! Thank you!

ltbkey avatar Mar 27 '18 14:03 ltbkey

This doesn't seem to be a secured issue. WindowsError generally indicates a Windows system call error. This could be related to what is being fixed by PR #25, so I'd give that a go. If not, I'd check to see if your system has weird permissions.

hkpeprah avatar Mar 27 '18 17:03 hkpeprah

Thank you for your reply! I have checked PR #25, and tested the new library.py, it did not work because my python version is on win32. My script "jlink_flash.py" should find the "JlinkARM.dll", is that right? Thank you again!

ltbkey avatar Mar 28 '18 02:03 ltbkey

Hi @hkpeprah , I made more tests. JLink_x64.dll does not affect the connection between jlink and device. I deleted "JLink_x64.dll" in JLink_v620, J-Flash and J-Link commander work correctly: connecting, securing, reading, programming. So the issue just is that "jlink.py" can't connect device if the device had been secured. One more test, if a device had been secured, I used J-Link commander to connect the device, connected successfully, and the device was erased too. Then "jlink.py" worked correctly. Thanks!

ltbkey avatar Mar 28 '18 07:03 ltbkey

We currently have not implemented an unlock method for the STM32 in PyLink FWIW.

hkpeprah avatar Mar 28 '18 19:03 hkpeprah

How difficult would it be to implement? This is just a single call into the SDK, right?

On Wed, Mar 28, 2018 at 2:36 PM, Ford [email protected] wrote:

We currently have not implemented an unlock method for the STM32 in PyLink FWIW.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/pylink/issues/27#issuecomment-377009328, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtLiL1gY10SyMK8nsDz-gEK_JUqIOANks5ti-YogaJpZM4S8_cP .

sstallion avatar Mar 28 '18 19:03 sstallion

Nope. The SDK has no unlock method. The one that exists for Kinetis is based on Freescale's specification.

hkpeprah avatar Mar 28 '18 19:03 hkpeprah

Ah, gotcha. So relatively painful - is there something from JLinkExe that could be used for inspiration?

On Wed, Mar 28, 2018 at 2:45 PM, Ford [email protected] wrote:

Nope. The SDK has no unlock method. The one that exists for Kinetis is based on Freescale's specification.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/square/pylink/issues/27#issuecomment-377011981, or mute the thread https://github.com/notifications/unsubscribe-auth/AFtLiPzuu88XOvrywTTtagm7gktegQHtks5ti-g_gaJpZM4S8_cP .

sstallion avatar Mar 28 '18 19:03 sstallion

Maybe. But I imagine that there's a spec out there that we can follow. And OpenOCD probably has something as well that we could look at (I did this for the Kinetis one as well), though the first step would be getting a board.

hkpeprah avatar Mar 28 '18 19:03 hkpeprah

I might take a look at it if I can find the time. I do have an STM32F207 board handy I can test with.

sstallion avatar Mar 28 '18 19:03 sstallion

Thank you both! @hkpeprah, @sstallion Looking forward a good news. It doesn't matter that chip is erased after the connection. Thank you again.

ltbkey avatar Mar 29 '18 01:03 ltbkey

Hi: I just fix this problem, the remove need two steps: 1、modify the pylink source code 2、

def unsecure_device_hook(title, msg, flags):
    return pylink.enums.JLinkFlags.DLG_BUTTON_YES

...
jlink = pylink.JLink(unsecure_hook=unsecure_device_hook)
...

Moral-ecomo avatar Apr 23 '20 12:04 Moral-ecomo