DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • Troubleshooting Memory Leaks With Heap Profilers
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Test-Driven Development With The oclif Testing Library: Part One
  • Mule Standalone Runtime Setup and Deployment

Trending

  • Replacing Legacy Systems With Data Streaming: The Strangler Fig Approach
  • Modernize Your IAM Into Identity Fabric Powered by Connectors
  • Building V1 Gen-AI Products at Scale: Technical Product Patterns That Work
  • Jakarta EE 11 and the Road Ahead With Jakarta EE 12
  1. DZone
  2. Data Engineering
  3. Data
  4. Unlocking and Erasing FLASH with Segger J-Link

Unlocking and Erasing FLASH with Segger J-Link

By 
Erich Styger user avatar
Erich Styger
·
Oct. 17, 14 · Interview
Likes (0)
Comment
Save
Tweet
Share
18.7K Views

Join the DZone community and get the full member experience.

Join For Free

when using a bootloader (see “ serial bootloader for the freedom board with processor expert “), then i usually protect the bootloader flash areas, so it does not get accidentally erased by the application ;-). when programming my boards with the p&e multilink, then the p&e firmware will automatically unlock and erase the chip. that’s not the same if working with the segger j-link, as it requires extra steps.

protected flash pages with processor expert

protected flash pages with processor expert

failed programming with protected flash

if i try to re-program the protected bootloader with segger j-link (both in codewarrior and eclipse/kds with gdb), then the download silently fails. the effect is that somehow the application on the board does not match what it should be. looking at the console view, it shows that erase has failed (but no real error reported) :-(:

jlink: failed to erase sectors 0 @ address 0x00000000 (algo135: flash protection violation. flash is write-protected.)
j-link failed to erase in codewarrior

j-link failed to erase in codewarrior

the gnu arm eclipse segger integration with gdb (e.g. kinetis design studio) is not better: no error sign, the only thing is a hidden error in the console log of the jlinkgdbservercl:

error: failed to erase sectors 0 @ address 0x00000000 (algo135: flash protection violation. flash is write-protected.)
error algo135 flash protection violation about failed flash programming

error algo135 flash protection violation about failed flash programming

what i need is to unprotect the memory and then erase it.

erasing

the segger j-link features a very fast programming. part of that speed is that the segger firmware checks each flash page if it really needs to be programmed, and only then it erases and reprogrammed that page. so downloading twice the same application actually will not touch the flash memory at all. additionally, it does not do a complete erase of the device: it only programs the pages i’m using in my application. the advantage of that is first speed. and it does not erase the application data i’m using in non-volatile memory (see “ configuration data: using the internal flash instead of an external eeprom “). however, sometimes i really need to clear all my data in flash too, and then i need to erase all my flash pages on the device.

segger has product named ‘j-flash’ which is used to flash and erase devices outside of an ide. there is a free-of-charge ‘lite’ version available for download from segger. this utility is not intended to be used for production. with this utility i have a gui to erase and program my device.

j-flash lite

j-flash lite

but j-flash lite cannot unlock my locked flash pages :-(.

if my device is not locked, i can use the codewarrior ‘flash file to target’ (see “ flashing with a button (and a magic wand) “) to erase the device:

erasing device with flash file to target

erasing device with flash file to target

again, this does not work if the device is locked. codewarrior has another feature called ‘target task’ which can be used to erase/unsecure (if your device is supported), see “ device is secure? “.

so i need to use a different tool to unlock and unprotect my device: the j-link commander .

unlocking and erasing with j-link commander

to unlock the device, segger has a utility named ‘j-link commander’, available from http://www.segger.com/jlink-software.html . the binary is ‘jlink.exe’ on windows and is a command line utility. to unlock the device use


unlock kinetis
unlocking device

unlocking device

but it seems that i need to do an unlock, followed by an erase to make it permanent. to erase the device, i can use the same command line utility. but i need to specify the device name first, and then i can erase it (example for the kl25z):


device mkl25z128xxx4
unlock kinetis
erase

:!: i need to do the erase operation right after the unlock. a) set device b) unlock and c) erase, otherwise it will fail?

unlocking and erasing with j-link commander

unlocking and erasing with j-link commander

summary

in order to re-program the protected flash sectors with segger j-link, i need first to unlock and mass erase the device. for this, there is the j-link commander utility which has a command line interface to unprotect and erase the device. for erasing only, the j-flash (and lite) is a very useful tool, especially to get a ‘clean’ device memory.

to me, the segger way and tools are very powerful. in this case, things are very flexible, but not that obvious. so i hope this post can help others to get his device unlocked and erased.

happy erasing :-)


application Non-volatile memory Command-line interface Memory (storage engine) CodeWarrior Flash memory Data (computing) Command (computing) Firmware

Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Troubleshooting Memory Leaks With Heap Profilers
  • Java, Spring Boot, and MongoDB: Performance Analysis and Improvements
  • Test-Driven Development With The oclif Testing Library: Part One
  • Mule Standalone Runtime Setup and Deployment

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: