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.
Join the DZone community and get the full member experience.Join For Free
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.
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:
- It happened 6 times during last semester.
- In all cases, a Windows 10 machine was involved.
- 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:
- Go to http://www.nxp.com/opensda and select your board.
- Check if your bootloader is a V2, V2.1 or V2.x. If yes, you are potentially affected.
If your firmware might be affected, you can
- Do nothing. The problem seems to be rather rare from my experience.
- Be prepared to reprogram it with the original firmware.
- 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:
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:
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!
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.
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:
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.
- Launch the commander (jlink executable)
- Set the device: device MK20DX128xxx5
- Load the binary: loadbin k20dx128_bootloader_0x5000.bin, 0
- Reset the device: r
- Quit the commander: exit
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:
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.
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.
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.