Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Recover the OpenSDA v2.x Bootloader

DZone's Guide to

How to Recover the OpenSDA v2.x Bootloader

Windows 10 can corrupt an OpenSDA V2.x bootloader. Fortunately it's not a terminal problem, but it might require a terminal solution.

· IoT Zone
Free Resource

More and more of my students are using Microsoft Windows 10 machines, and my computer has been upgraded to Windows 10 a couple of weeks ago too. From my work and experience, a new operating system causes always some challenges, and Windows 10 is no different. And no, this is not about Microsoft vs. Apple vs. Linux. This post is about addressing a potential and painful problem which I have observed with Windows 10 machines, and to my understanding could happen with any other operating system too. The problem is that somehow on several student machines the bootloader and OpenSDA application on their FRDM boards did not work anymore.

FRDM-K64F (top) programming the OpenSDA Bootloader (bottom)

FRDM-K64F (top) programming the OpenSDA Bootloader (bottom)

Windows 10 and OpenSDA Bootloader

I’m not really clear what it is causing this, but the non-working boards somehow had an affected OpenSDA V2.x bootloader:

  1. It happened 6 times during last semester.
  2. In all cases, a Windows 10 machine was involved.
  3. It is not clear under which circumstances it happened. It seems to happen rather randomly, and if the board has been put into BOOTLOADER mode.

The OpenSDA application and bootloader appears as virtual MSD (Mass Storage Device) to the host. My speculation is that somehow the host machines reads and writes to that device in a way that confuses the bootloader application on the board. As a result, it seems to me that this leads to some programming sequences which then invalidates and corrupts the bootloader and application on it.

Affected OpenSDA Firmware

Only OpenSDA V2.0 (NXP FRDM-K64F) and OpenSDA V2.1 (NXP FRDM-K22F) boards were affected. These board have an ‘unsecured’ (mbed) bootloader on it which can be overwritten as it is open. The OpenSDA V1.0 bootloader (produced by P&E), on the other hand, seems not to be affected, as the bootloader firmware is secured and protected, so it cannot be erased. So the problem seems to be related to the OpenSDA V2.x bootloader.

To find out if your firmware could be affected:

  1. Go to http://www.nxp.com/opensda  and select your board.
  2. Check if your bootloader is a V2, V2.1 or V2.x. If yes, you are potentially affected.
    OpenSDA Bootloader Version

    OpenSDA Bootloader Version

If your firmware might be affected, you can

  1. Do nothing. The problem seems to be rather rare from my experience.
  2. Be prepared to reprogram it with the original firmware.
  3. Try the new beta OpenSDA V2.2 firmware (see this link), which seems to be able to deal with the issue.

Either way, with option 2 or 3, you need an external SWD/JTAG debug device/probe to reprogram the firmware on the Kinetis K20 OpenSDA microcontroller:

OpenSDA K20 Device on FRDM-K64F

OpenSDA K20 Device on FRDM-K64F

Bootloader Files

To reprogram the OpenSDA K20, you first need the bootloader firmware file. You might consider cloning it from a working second board (see "Recovering the FRDM-K64F Bootloader, or: Cloning the Program of a Microcontroller").

The other way is to find and download the firmware from http://www.nxp.com/opensda:

Bootloader Firmware File

Bootloader Firmware File

Be careful to select the correct bootloader file. The FRDM-K64F V2.0 bootloader uses a different base address for the application from the V2.1 one.

You might give the V2.2 firmware on new OpenSDA v2.2 Bootloader binary for FRDM-K22F a try. If flashing this to the FRDM-K64F, then you need to load V2.1 debug applications to it!

Programmer Hardware

In any case, you need a separate/external device to re-program the bootloader. The recommended solution is to use either a Segger J-Link or a P&E Multilink. Alternatively, another FRDM board like the FRDM-K64F can be used.

J-Link, Multilink and FRDM board as programmer

J-Link, Multilink and FRDM board as programmer

The easiest and simplest way is to use either the P&E Multilink or Segger J-Link. Locate the K20 on the Tower/Freedom board. Usually, it is close to the K20 device:

SWD Header for the K20 on the FRDM-K22F

SWD Header for the K20 on the FRDM-K22F

SWD for K20 on FRDM-K64F

SWD for K20 on FRDM-K64F

Otherwise, the OpenSDA on an FRDM or Tower board can be used.

Flashing the Bootloader

If you don’t want to use an IDE, you can use the Segger J-Link Commander which is part of the Segger J-Link software package. It is part of Kinetis Design Studio too. Otherwise, it is available from here.

  1. Launch the commander (jlink executable)
  2. Set the device: device MK20DX128xxx5
  3. Load the binary: loadbin k20dx128_bootloader_0x5000.bin, 0
  4. Reset the device: r
  5. Quit the commander: exit
Example Segger Session

Example Segger Session

I can program the bootloader from Eclipse (e.g. Kinetis Design Studio too). Simply create a dummy project for the MK20DX128xxx5 device. In the debugger launch configuration, specify the binary you want to use:

Bootloader Binary

Bootloader Binary

Using FRDM Board to Program Another Board

It is possible to use another FRDM board to program another board. Depending on the board, an SWD header needs to be soldered on the board and jumpers set or traces cut. Below are a few articles outlining the various ways for different boards:

Note: Keep in mind that the Segger license agreement only allows programming of an evaluation board (FRDM, TWR, etc), not custom hardware. The P&E OpenSDA V1 debug firmware does *not* allow programming of any off-board devices.

FRDM-K64F (top) programming the OpenSDA Bootloader (bottom)

FRDM-K64F (top) programming the OpenSDA Bootloader (bottom)

Summary

Windows 10 can corrupt an OpenSDA V2.x bootloader. To recover the bootloader, I need a programming device and the firmware file, then I can restore the bootloader. While I could use another FRDM board to recover it, it is much easier using a P&E Multilink or a Segger J-Link. Anyway, I think for serious development I don’t want to depend on the OpenSDA interface only: to have a ‘real’ debug probe like in this case can save many hours of work.

Happy Recovering!

Topics:
opensda ,bootloader

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

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}