Binary Files for the mbed Bootloader with Eclipse and GNU ARM Eclipse Plugins
Join the DZone community and get the full member experience.Join For Free
the existing opensdav1 (see “ opensda on the freedom kl25z board “) bootloader is using the industry standard motorola s-record ( s19 ) files. however, new frdm-k64f board (see “ ftf: frdm-k64f, kinetis design studio and kinetis sdk “) has opensdav2 on it, which is an mbed bootloader . so how to create files with an ide other than mbed for that bootloader which is present on the frdm-k64f board by default? well, creating binary files is one thing, but to have it working with the mbed bootloader is another challenge.
mbed bootloader and binary files
the mbed firmware running on the kinetis k20 of the frdm-k64f board has three functions:
- debug interface as usb hid device implementing cmsis-dap
- serial-to-usb bridge (unfortunately it is *not* a usb cdc device class, so it requires a proprietary mbed usb driver for this).
- msd (mass storage device) usb bootloader .
it is interesting to see that the debug interface is using a usb hid (human interface device class). so for the host this looks like a keyboard or a mouse (which are hid devices too). the advantage of this approach is that no drivers are needed on the host. however, the hid interface is very slow compared to other device classes (well, a keyboard or a mouse does not have to be really fast), so this probably explains why the mbed debug interface speed is somewhat ok, but not as fast as e.g. a p&e multilink or segger j-link?
the 3rd function is of interest here: the mbed opensdav2 firmware looks like a usb memory (stick) device where i can copy files to it, and it will program the target processor. this functionality exists in the opensdav1 firmware for other boards too (e.g. frdm-kl25z).
while the opensdav1 firmware accepts motorola s19 files, for strange reasons the mbed msd bootloader only accepts binary (*.bin) files.
i very much prefer the standard s19 files, as they are easily generated by any tools, and there are many tools to convert/deal/change s19 files. it is not clear to me why the mbed bootloader only accepts bin files: the s19 files are industry standard, easy to generate and handle. yes, s19 files use two bytes for every code byte because it is an ascii format. that would make a difference if the connection speed to the bootloader would be limited, but this is not the case with opensdav2: i mean usb is not a ‘few bytes per second’ communication protocol where a binary protocol would make sense?
creating binary files with gnu arm eclipse plugins
both my eclipse kepler (see “ gnu additional tools: create flash image, print size and extended listing options “) and as well kds include the gnu arm eclipse plugins. codewarrior has a somewhat older/similar plugin too, see “ s-record generation with gcc for arm/kinetis ” how to create s19/binary files with codewarrior.
to generate a binary file for the mbed msd bootloader, go to the project settings (menu project > properties ), and to the toolchains tab under c/c++ build > settings :
enable ‘create flash image’ and press the ‘apply’ button.
then switch to the ‘tool settings’ tab, go to the general settings of ‘cross arm gnu create flash image’ and choose ‘raw binary’:
press ‘ok’ and build your project. the binary file will be created in the project output folder:
bugs in mbed bootloader?
so far so good, if there would not be a bug in the mbed msd bootloader.
there are two issues associated with the mbed msd bootloader i’m aware
of (and i have lost a lot of time finding out the problem. it is especially bad as it might brick your board, and it might be hard to recover the board, see “
recovering frdm-k64f mbed board
- the board get bricked if the binary file has all the flash security bits set to 0xff, or if the flash configuration fields are missing/not set in the application. see “ how (not) to secure my microcontroller ” on this issue.
- even if the nv_fsec backdoor key security field of the flash configuration is configured propery, the mbed bootloader will screw up the board.
note that the two above issues are *not* present if using opensdav1, p&e multilink or segger j-link (for me yet another good reason to spend little money a good piece of debug probe compared to waste a lot of time …).
keyen fsec settings: backdoor key security enable
the issue is with the keyen (2 bits) in the fsec (flash security) settings. the k64f reference manual documents it like this:
0b00, 0b01 and 0b11 settings disable the backdoor keys, and 01 is the preferred way. however, somehow the mbed bootloader only seems to accept 0b11. somehow the mbed library uses 0b11, but if you are using other libraries/tool chains or processor expert, then very likely the default value 0b01 is used, which then bricks my frdm-k64f board.
this can be easily reproduced with a small example. in the example startup code below used with the kinetis sdk, the flash configuration settings are configured after the vector table:
if the last word is 0xffffff7e, this will brick your board, while 0xfffffffe works fine. both values shall work the same according to the freescale reference manual.
same problem if i’m using processor expert and want to load that generated binary file with the mbed msd bootloader:
that (correct) 0x7eu value bricks the board. the workaround is to use 0xfeu instead (see “ disable my code generation ” how to change the code manually).
i have submitted that problem, so hopefully it will be addressed by an update of the mbed bootloader. until then, at least to know one reason which bricks the board is better than not knowing.
the mbed msd bootloader requires binary (.bin) files. generating binary files is very well possible with gnu tools and easy with the gnu arm eclipse build plugins (see http://gnuarmeclipse.livius.net/blog/ ). the current mbed bootloader has an issue with the fsec security bits: if they are not set the way the bootloader expects them, it will brick the board. ways how to recover the board are discussed in “ recovering frdm-k64f mbed board “. i admit that this problem does not occur if you are inside the ‘mbed system’: but i hope that mbed will get to a point that it will be easier to be used with ‘offline’ tools too. i looking forward to that.happy bootloading!
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.