GithubHelp home page GithubHelp logo

Comments (3)

hkpeprah avatar hkpeprah commented on September 27, 2024

It sounds like you're possibly programming an image that protects the flash? You will need to erase unless you're writing to a region of flash that is already erased. Some sample code would help.

from pylink.

Agarmonz avatar Agarmonz commented on September 27, 2024

Hello again!
I am not using images with security enabled. In fact, the idea is to program a very basic image and then put the necessary data in memory. And, in case this process is completed correctly, then write into memory the necessary data to activate the flash protection.

Example K64/KE15:
import pylink
Import time
Import sys

try:
jlink = pylink.JLink()
jlink.open()
print(jlink.product_name)
print(jlink.oem)
print('Open connection? %s' % jlink.opened())
print('JLink connected? %s' % jlink.connected())
print('Jlink found -> %s' %
jlink.connected_emulators())
print('Connected device: %s' % jlink.target_connected())
except Exception as e:
print('ERROR: error when opening connection...', str(e)) jlink.close()
sys.exit()

Target connection

try:
print('Specifying target interface...') jlink.set_tif(pylink.enums.JLinkInterfaces.SWD)
except Exception as e:
print('ERROR: debugg...', str(e))
jlink.close()
sys.exit()

try:
print('Establishing the connection...') jlink.connect(microJLink, 'auto', True)
print(' -> Target connected')
except Exception as e:
print('ERROR: error when connecting, first attempt...', str(e))
jlink.close()
sys.exit()

try:
print('Unlocking...')
pylink.unlockers.unlock(jlink, 'Kinetis')
print(' -> Unlocked')
except Exception as e:
print('ERROR: error when unlocking...', str(e)) jlink.close()
sys.exit()

Target erase

jlink.halt()
print('CPU halted')
time.sleep(1)

try:
print('Erasing memory content...')
jlink.erase()
print(' -> Memory Erased')
except Exception as e:
print('ERROR: error when erasing...', str(e))
jlink.close()
sys.exit()

Target connection

try:
print('Establishing the connection...') jlink.connect(microJLink, 'auto', True)
print(' -> Connection established')
except Exception as e:
print('ERROR: error when connecting after erasing...', str(e))
jlink.close()
sys.exit()

try:
print('Unlocking...')
pylink.unlockers.unlock(jlink, 'Kinetis')
print(' -> Unlocked')
except Exception as e: print('ERROR: error when unlocking...', str(e))
jlink.close()
sys.exit()

Flashing .s19

time.sleep(1)
try:
print ('Programming module...')
jlink.flash_file(file_path, 0)
print(' -> Module programmed')
except Exception as e:
print('ERROR: error when programming...', str(e)) jlink.close()
sys.exit()

time.sleep(2)

Memory Write

try:
print('Memory write data1: %s (bytes)' % jlink.memory_write8(dirdata1, data1))

print('Memory write data2: %s (bytes)' % jlink.memory_write8(dirdata2, data2))

except Exception as e:
print('ERROR: error when modifying data...', str(e)) jlink.close()
sys.exit()

Read Modified Memory

try:
print('Reading memory...')
resultMemoryModifiedData1 = jlink.memory_read8(dirdata1, bytesdata1)

resultMemoryModifiedData2 = jlink.memory_read8(dirdata2, bytesdata2)

except Exception as e:
print('ERROR: error when reading memory...', str(e)) jlink.close()
sys.exit()

check mem

print('Checking memory...')

if data1 != resultMemoryModifiedData1: print('ERROR: data1 FAILURE'); jlink.close(); sys.exit()

if data2 != resultMemoryModifiedData2: print('ERROR: data2 FAILURE'); jlink.close(); sys.exit()

print(' -> Memory checked')

Security

try:
print('Memory write SEC: %s (bytes)' % jlink.memory_write8(dirSEC, SEC))
except Exception as e:
print('ERROR: error when modifying SEC...', str(e)) jlink.close()
sys.exit()

Close connection

jlink.close()
print('OK: boot done')

As I said, this same or similar code works in LPC and iMX.
In the Kinetis family, the error I was talking about occurs.
The steps I am trying seem simple:
Connect, unlock in case you have security enabled, clear memory, reconnect, program the image, program data on the image... and if everything is ok then arm the security.

It si true that normally using JLink Lite or JFlash with Kinetis family, it appears a popup talking about flash protection when programming or erasing, in case you want a mass erase you should press 'Yes'.
That pop-up does not appear in LPC or iMX.
An extra info in case that has something yo do with the problem!

Hope your answer soon :)
Thank you very much un advance

from pylink.

hkpeprah avatar hkpeprah commented on September 27, 2024

Hm. I'm having a hard time following. There is OTP that permanently locks flash on the Kinetis chips, so even if your image doesn't enable flash security, if you flashed one at one point that did, then flash access would be permanently locked. In terms of the code, I'm having a hard time following. Could you paste a block like:

jlink = pylink.Jlink()
jlink.connect(...)
<...>

Then point out the specific line in that block that is causing the issue and whether it is on the first time you run it or subsequent runs.

from pylink.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.