Recovery of a bootloader

Introduction

Welcome to my little Odyssey.

To start with, I had the MSP430 Launchpad lying around for a long time. Only now I decided to play with it.

The development board itself is called MSP-EXP430G2ET and the MCU that is included is the MSP430G2553.

It seems like there are multiple revisions (the MSP-EXP430G2 has been replaced with the MSP-EXP430G2ET Launchpad), but they should be pin compatible.

The Problem

Full of fresh energy I decided to create a project for this device in Code Composer Studio, the official IDE from TI.

My version is:

Code Composer Studio 
Version: 10.1.1.00004

new_ccs_project

Clicking on identify leaves me with this:

needs_recovery

But upon recovery I always get the same error:

recovery_failed

Great. So I manually chose the target, but even then from within the project I was not able to upload code to the device.


Note: There are exceptions on which devices are supported on the CCS download website.

For v10 this is:

Not Supported

    - MSP430: MSP-FET430PIF (Parallel port), Launchpads and Experimenters kits that use eZ430 technology such as Chronos, MSP-EXP430G2 and MSP-EXP430FR4133 LaunchPads.
        Note: the MSP-EXP430G2ET is supported.
        For a complete list, check the document SLAU647
    - Stellaris ICDI based on FTDI
    - Blackhawk: USB2.0, XDS560 PCI, XDS560T, XDS510
    - Spectrum Digital: XDS510, XDS560R, Parallel Port emulators
    - Texas Instruments: XDS560 PCI, XDS510 ISA
    - In general vendors are not supporting PCI, ISA or parallel port emulators on Linux

So it seems like the MSP-EXP430G2ET should be supported. But maybe not updating firmware.


The device seems to be bricked, at least from the Linux perspective. One solution would be to boot up a Windows-VM and recover the bootloader from there.

But we wont do that. That's too easy.

Attempting a solution

By surfing through the web I found this issue on the mspdebug github repo, which is an open source debugging tool for MSP430 MCUs.

It's also about allowing firmware updates with mspdebug and they succeeded with it.

After compiling mspdebug I get this error:

$ ./mspdebug tilib --allow-fw-update
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.15.0.1 Copyright (C) 2013 TI, Inc.

tilib_api: can't find libmsp430.so: libmsp430.so: cannot open shared object file: No such file or directory

tilib uses msp430.so a shared library from TI. Closed Source?

From a comment of the issue:

There's no proprietary blob -- the source for libmsp430.so is available
under a BSD-like licence. TI name the source packages following the
pattern slac460*.zip. The last release I looked at was slac460y.zip:

    https://dlbeer.co.nz/articles/slac460y/index.html

That sounds great, so let's build it.

I followed the steps written here but the compilation didn't work due to boost errors.

Reading here fixing this seems to be tedious. Also it doesn't seem to be up to date.

So let's get the latest source from TI iself.

https://www.ti.com/tool/MSPDS

Download the files under:

MSPDS-OPEN-SOURCE:
MSP Debug Stack Open Source Package

By reading the README-BUILD.txt I found out that hidapi is needed.

* hidapi
    -Download and build (https://github.com/signal11/hidapi/releases)
    -Version used in official build is 0.8.0-rc1
    -The MSPDebugStack project assumes hidapi being built against libusb-1.0
     (the default used in the Makefile coming with hidapi 0.8.0-rc1)
    -hidapi.h must be copied to ThirdParty\include
    -hid-libusb.o must be copied to ThirdParty\lib

So let's compile that: hidapi I had do install some additional packages:

sudo apt install libudev-dev libusb-1.0-0-dev libfox-1.6-dev

But other than that it compiled without errors. Now let's get to the copying.

The header file is located in hidapi/hidapi/hidapi.h and should be moved to ThirdParty\include.

But there is no hid-libusb.o like the README had said. What now? Under hidapi/libusb/ I find the file hid.o.

A quick check to make sure it's a library:

$ file hid.o
hid.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped

Then I move it to ThirdParty/lib64/.

And ... everything compiled and linked succesfully:

$ file libmsp430.so 
libmsp430.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=251ee7d094b41d3a631e9b6101ed4af1d16cba84, with debug_info, not stripped

Updating the firmware?

Now let's try a firmware update:

LD_PRELOAD=./libmsp430.so ./mspdebug tilib --allow-fw-update

$ LD_PRELOAD=./libmsp430.so ./mspdebug tilib --allow-fw-update
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.15.0.1 Copyright (C) 2013 TI, Inc.

Using new (SLAC460L+) API
MSP430_GetNumberOfUsbIfs
MSP430_GetNameOfUsbIf
Found FET: HID_FET
MSP430_Initialize: HID_FET
FET firmware update is required.
Starting firmware update (this may take some time)...
tilib: MSP430_FET_FwUpdate: MSP-FET / eZ-FET recovery failed (error = 73)
tilib: device initialization failed

It seems like there is no hope.

More googling.

This sounds like the same issue.

Then I found this one.

So is the MSP-EXP430G2ET actually unsupported?


Let's go with UniFlash, maybe it will work...

Let's start it:

./node-webkit/nw

Looks like your typicall webapp, but doesn't work.

This story ends with me starting windows in my boxes (qemu/libvirt frontend) to recover the bootloader on my MSP430 Launchpad. It seems like there is no happy ending this time.

Or not?

The End

I realized that I had Code Composer running in the background. Okay, maybe I should close it and try it once more:

$ LD_PRELOAD=./libmsp430.so ./mspdebug tilib --allow-fw-update
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.15.0.1 Copyright (C) 2013 TI, Inc.

Using new (SLAC460L+) API
MSP430_GetNumberOfUsbIfs
MSP430_GetNameOfUsbIf
Found FET: HID_FET
MSP430_Initialize: HID_FET
FET firmware update is required.
Starting firmware update (this may take some time)...
Initializing bootloader...
Programming new firmware...
     0 percent done
    34 percent done
    67 percent done
   100 percent done
Update complete
Done, finishing...
MSP430_VCC: 3000 mV
tilib: MSP430_VCC: Internal error (error = 68)
tilib: device initialization failed

Oh come on! That was so close... Let's try it a second time.

$ LD_PRELOAD=./libmsp430.so ./mspdebug tilib --allow-fw-update
MSPDebug version 0.25 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2017 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Chip info database from MSP430.dll v3.15.0.1 Copyright (C) 2013 TI, Inc.

Using new (SLAC460L+) API
MSP430_GetNumberOfUsbIfs
MSP430_GetNameOfUsbIf
Found FET: ttyACM0
MSP430_Initialize: ttyACM0
FET firmware update is required.
Starting firmware update (this may take some time)...
Initializing bootloader...
Programming new firmware...
    22 percent done
    25 percent done
    28 percent done
    31 percent done
    34 percent done
    37 percent done
    40 percent done
    40 percent done
    43 percent done
    46 percent done
    49 percent done
    52 percent done
    52 percent done
    55 percent done
    58 percent done
    61 percent done
    64 percent done
    67 percent done
    67 percent done
    67 percent done
    70 percent done
    73 percent done
    76 percent done
    79 percent done
    82 percent done
    85 percent done
    85 percent done
    88 percent done
    91 percent done
    94 percent done
    97 percent done
   100 percent done
Update complete
Done, finishing...
MSP430_VCC: 3000 mV
MSP430_OpenDevice
MSP430_GetFoundDevice
Device: MSP430G2xx3 (id = 0x0067)
2 breakpoints available
MSP430_EEM_Init
Chip ID data:
  ver_id:         5325
  ver_sub_id:     0000
  revision:       20
  fab:            a0
  self:           0000
  config:         00
  fuses:          00
Device: MSP430G2xx3

Available commands:
    !               fill            power           setwatch_r      
    =               gdb             prog            setwatch_w      
    alias           help            read            simio           
    blow_jtag_fuse  hexout          regs            step            
    break           isearch         reset           sym             
    cgraph          load            run             verify          
    delbreak        load_raw        save_raw        verify_raw      
    dis             md              set             
    erase           mw              setbreak        
    exit            opt             setwatch        

Available options:
    color                       gdb_loop                    
    enable_bsl_access           gdbc_xfer_size              
    enable_fuse_blow            iradix                      
    enable_locked_flash_access  lowercase_dis               
    fet_block_size              quiet                       
    gdb_default_port            

Type "help <topic>" for more information.
Use the "opt" command ("help opt") to set options.
Press Ctrl+D to quit.

(mspdebug) 

Finally. I can rest in peace.


$ sudo dmesg | grep tty
[    0.058875] printk: console [tty0] enabled
[    6.283014] systemd[1]: Created slice system-getty.slice.
[ 6836.211105] cdc_acm 2-2:1.0: ttyACM0: USB ACM device
[ 6836.211368] cdc_acm 2-2:1.2: ttyACM1: USB ACM device

Up and running. Next time I'll try and use mspdebug for programming the Launchpad.