I’m using Eclipse based IDE’s to develop and debug my embedded applications. This works great, as Eclipse has all the necessary tools to edit, build and debug it. But when it comes just to download/flash a binary to the board, then things are pretty much specific to the tools used. With the advent of the new MCUXpresso IDE, here is how that Eclipse IDE can be used for this.
Outline
The normal way in Eclipse to download a binary to the target is to use the debugger with a so called launch (or debug) configuration. That launch configuration needs a ‘project’, so programming a board without a project is not the usual thing. But there are ways how to download and program an application without a project. I show this here with using the NXP MCUXpresso IDE (V10.0.0), but some ways are applicable say using the Kinetis Design Studio (V3.2.0) or if using the GNU ARM Eclipse plugins.
Binaries
There are different file formats which can be used to program a microcontroller:
- ELF/Dwarf: This is the normal output format of the linker. Typical extensions are .elf, .abs or .axf (ARM eXecutable File). This file format has the code and data, plus the debug information (which is *not* downloaded to the target and only used for debugging).
That ELF/Dwarf file usually gets converted into different binary formats more suitable for programmers or boot loaders, and they do not include the debug information:
- S19/S-Record: textual file format (type, address, size, code, checksum). Typical extensions are .s19, .srec or .sx
- Intel Hex: textual file format (similar representation as S19). Typical extension is .hex
- Binary: In this format, the data is written in binary form, without address information. It is basically a ‘memory dump’.
Each format has its own pros and cons, see “S-Record, Intel Hex and Binary Files” for a more detailed overview.
To generate the different formats:
- MCUXpresso IDE: see “MCUXpresso IDE: S-Record, Intel Hex and Binary Files“
- Kinetis Design Studio or using GNU ARM Eclipse: see “Binary (and S19) Files for the mbed Bootloader with Eclipse and GNU ARM Eclipse Plugins“
- Converting, merging and manipulating binary files: I use the SRecord tool (for all kind of other formats too!), see “CRC Checksum Generation with ‘SRecord’ Tools for GNU and Eclipse” and “Merging S19 Files“
MCUXpresso IDE and GUI Flash Programmer
With MCUXpresso IDE V11, the GUI Flash Programmer supports LinkServer, P&E and Segger connections. The file formats supported depend on the connection type:
- P&E: .axf (ELF/Dwarf)
- LinkServer: .axf (ELF/Dwarf), .bin (Binary)
- SEGGER: .axf (ELF/Dwarf), .bin (Binary)
Using LinkServer GUI Flash Programmer
With using the MCUXpresso IDE, there is a LinkServer GUI Flash Programmer (see “Using the LPCXpresso V2/V3 Boards to Debug an external Board“):
In that dialog I simply can specify the binary I want to download. But there are the following restrictions:
- Only ELF/Dwarf and binary files supported (e.g. no S19 or Intel Hex files)
- Only works with the NXP LinkServer debug connection (LPC-Link, LPC-Link2, CMSIS-DAP) (e.g. no support for Segger J-Link or P&E Multilink)
Using Launch Configuration
The other approach is to use a launch configuration. This actually would be the same as using a normal debug session.
💡 In Kinetis Design Studio V3.2.0 there is a ‘Flash from file’ toolbar button. It is basically the same as using a special launch configuration. As it might interfere with the normal Eclipse launch configuration, I’m not using that way any more.
To create a new launch/debug configuration, I can duplicate an existing one (matching my device):
P&E
The P&E connection is not able to load a raw binary file directly, it only recognizes a file with a header file.
I can make a elf file out of a bin (raw binary) file with the GNU ‘objcopy command (see “Converting a Raw Binary File into an ELF/Dwarf File for Loading and Debugging“):
arm-none-eabi-objcopy.exe --input-target=binary --output-target=elf32-little myApp.bin myApp.bin.elf
This adds a ELF header to the file which I can inspect/verify with the ‘readelf’ GNU programm:
arm-none-eabi-readelf.exe -a myApp.bin.elf
which gives for examle:
ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) Machine: None Version: 0x1 Entry point address: 0x0 Start of program headers: 0 (bytes into file) Start of section headers: 26956 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 0 (bytes) Number of program headers: 0 Size of section headers: 40 (bytes) Number of section headers: 5 Section header string table index: 2 Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .data PROGBITS 00000000 000034 0068f4 00 WA 0 0 1 [ 2] .shstrtab STRTAB 00000000 006928 000021 00 0 0 1 [ 3] .symtab SYMTAB 00000000 006a14 000050 10 4 2 4 [ 4] .strtab STRTAB 00000000 006a64 000058 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific)
For the P&E debug connection (MCUXpresso IDE or e.g. Kinetis Design Studio), use a dummy project use that file for the debug session:
Then I can use the normal ‘debug’ which will use that binary file specified to be programmed. If I want only to download and skip the ‘debug’ step, then I can use the approach described in “Emulating Eclipse ‘Run’ with ‘Debug’ Configuration“.
Segger (GNU ARM Eclipse)
The same approach is used for the Segger J-Link debug connection (Kinetis Design Studio, or with the GNU ARM Eclipse plugins installed in MCUXpresso IDE, see “MCUXpresso IDE: Importing Kinetis Design Studio Projects“).
Specify the binary file in the Main tab:
The following files are supported: ELF/Dwarf, S19 and Intel Hex.
In the ‘Startup’ settings disable loading the symbols:
Using the same approach for Binary files will produce an error. Alex from Segger (thanks!) provided me a way how to load binary files:
Specify a dummy (valid) ELF/Dwarf file:
In the Startup tab, disable ‘Load Symbols’ and ‘Load Executable’. Use the
monitor loadbin <file name>
to load the file.
💡 I tried using Eclipse variables as ${project_loc} instead of using an absolute path to the binary, but this somehow can lock the debug session (not sure why). Using an absolute path worked for me.
Have ‘Set Program counter’, ‘Set Breakpoint’ and ‘Continue’ disabled:
Summary
Currently users of the GNU ARM Eclipse plugins (e.g. Kinetis Design Studio, or if you install them into MCUXpresso IDE) have the most flexible options to download binaries to the target. For the GNU ARM Eclipse plugins and the P&E plugin all what I need is to specify the binary file.
If using the standard MCUXpresso IDE V10.0.0, then there is the LinkServer dialog which supports the LPC-Link2/Link connections. For P&E the support is the same as with the GNU ARM Eclipse Plugins. For Segger I can install the GNU ARM Eclipse plugins or to use the Segger external tools to download binaries.
Because ‘programming binary files’ is not a standard feature of Eclipse, every vendor comes up with its own ways. If such an option or extension is not present, you still can try using a normal launch configuration, but the debug plugin has to accept a binary without debug information. Or use an external tool outside Eclipse.
Happy Binaring 🙂
Links
- MCUXpresso IDE: http://www.nxp.com/mcuxpresso/ide
- Kinetis Design Studio IDE: http://www.nxp.com/kds
- GNU ARM Eclipse plugins: http://gnuarmeclipse.github.io/
Thanks. A good pointer. I sometimes want to program a newly built test image. The scenario is that as part of my workflow when submitting a Git PullRequest, I build a new project/directory instance from the baseline Git. And then merge the changes I want to a PR branch and build test. At the end I have an image which I need to do some integration testing with – but its difficult to program through KDS/JTAG without a new project.
BTW there is a new BlackMagicProbe/JTAG (BMP) completed from KickStarter – I received one this week, but haven’t tried it yet
https://gitter.im/1bitsy/Lobby?source=orgpage
https://1bitsy-and-black-magic-probe.backerkit.com/
LikeLike
Yes, I had looked at that Black Magic probe, and my thinking was ‘oh, yet another debug probe without the required software/debugger’. Maybe it will be different for that one, but my experience with that kind of things was not good. Doing a SWD/JTAG probe is not hard. Supporting all the different microcontrollers is the hard thing: flash programming, memory map, exception handling, hardware breakpoints, security and flash protection settings, etc.
Let us know how it works!
LikeLike
I am trying to recover FRDM-K22F OpenSDA firmware using Kinetis studio and Multilink FX, however J12 on board is set for JTAG programmer. Can I program chip without using SDA_JTAG_TDO and SDA_JTAG_TDI pins. Before I dropped to Bootloader in Windows 10: from ARMmbed: 0221_k20dx128_k22f_0x8000.bin
from Pemicro: MSD-DEBUG-FRDM-K22F_Pemicro_v114.SDA
from NXP: mbedWinSerial_16466.exe
Which one to use?
LikeLike
Hi Marceli,
See https://mcuoneclipse.com/2014/11/10/recovering-the-frdm-k64f-bootloader-or-cloning-the-program-of-a-microcontroller/, same thing applies to the FRDM-K22F.
You need to program the K20 with the SWD header nearby with a SWD/JTAG programmer. As for the bootloader and application see https://mcuoneclipse.com/2016/08/01/bricking_and_recovering_opensda_boards_in_windows_8_and_10/
I hope this helps,
Erich
LikeLike
Thanks for a great summary! It is nice to have this information all in one place.
LikeLike
Hi, Erich
I’m trying to load a bin file into a k64F using the procedure explained on this post with a multilink universal probe. But it’s working only with .elf files (or others with link information). This post is from may, which is relatively recent, however i also found that PnE does not support bin file load (info date: November/17).
Are you aware of some update between that looses this funcionality? Can you still load bin files?
Thank you, again.
and again 🙂
LikeLike
Hi Diogo,
What kind of error message do you get? Do not forget to disable ‘Load Symbols’ in the ‘Startup’ tab of the launch configuration.
But I might be able to see your problem: it seems that the target memory is not programmed/flashed. I’m looking into what happens…..
LikeLike
I have found a way to get it loaded, have a read at https://mcuoneclipse.com/2018/01/27/converting-a-raw-binary-file-into-an-elf-dwarf-file-for-loading-and-debugging/
I hope this helps,
Erich
LikeLike
Pingback: Converting a Raw Binary File into an ELF/Dwarf File for Loading and Debugging | MCU on Eclipse
Hi Erich,
thanks for this helpful article. It aims exactly at the problem which I currently have. I want to debug u-boot with attached DTB in Eclipse on a ARM-target using the J-Link GDB-server. It seems only possible to download a binary file via GDB-server as an ELF-file. Therefore I wanted to follow the suggested P&E approach using objcopy to create an ELF file from my binary file using:
arm-eabi-objcopy –input-target=binary –output-target=elf32-little u-boot-dtb.img u-boot.dtb.elf
Eclipse or is it GNU MCU(?), however, denies to download the resulting file, bailing out with an indecisive error reading:
load /home/Projects/Linux/u-boot-2020.04/u-boot.dtb.elf
Error message from debugger back end:
Load failed
I compared the outputs of a normal u-boot.elf file and my created one and found several differences. Many of the difference are visible in your example as well, therefore, I guess, they are don’t care. What stunned me, however, was this entry from the normal u-boot.elf and this could make the difference:
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
LOAD 0x010000 0x8a000000 0x8a000000 0x6da33 0x6da33 RW 0x10000
Is it possible to create this program header with objcopy or do you have anything in mind, which could cause or even cure my problem? I use Eclipse 2020-03, CDT 9.11, GNU MCU 20200127.
Thanks
Joachim
LikeLike
A binary file is just a BLOB (Binary Large OBject) and a dump of files and no address information.
Your u-boot.elf has loader information (offset, where to load the binary, at offset 0x010000).
So if you load a binary to something different, you have to specify the offset.
It should be possible to add an offset, e.g.
monitor loadbin ,
so for your case try
monitor loadbin u-boot.bin,0x010000
I hope this helps,
Erich
LikeLike
Thanks for your reply. I am not sure, however, how your answer fits my question, but anyway, I meanwhile found out how to create a valid ELF-file for use in Eclipse. You can combine an bin file and a BLOB to a valid elf file like this (from the u-boot compile log):
# concatenate bin-files (here u-boot-nodtb.bin and dtb file)
cat u-boot-nodtb.bin dts/dt.dtb > u-boot-dtb.bin
cp u-boot-dtb.bin u-boot.bin
# create ELF file like suggested in this article
arm-eabi-objcopy -I binary -B arm -O elf32-littlearm u-boot.bin u-boot-elf.o
# link it
arm-eabi-ld.bfd u-boot-elf.o -o u-boot.elf -T u-boot-elf.lds –defsym=”_start”=0x8A000000 -Ttext=0x8A000000
For completeness I add an excerpt from the man page of arm-eabi-ld.bfd:
This version of ld uses the general purpose BFD libraries to operate on object files. This allows ld to read, combine, and write object files in many different formats—for example, COFF or “a.out”. Different formats may be linked together to produce any available kind of object file.
LikeLike
And for even more completeness, this is the content of the linker script (here u-boot-elf.lds):
ENTRY(“_start”)
SECTIONS
{
. = “_start”;
.data : {
*(.data*)
}
}
LikeLike
Pingback: Standalone and Command Line Programmer with MCUXpresso | MCU on Eclipse