A user on IRC mentioned the availability of FLM files for flash programming, provided by chip vendors. He asked if OpenOCD can support them. I've never heard of them so ... quick check ... https://arm-software.github.io/CMSIS_5/Pack/html/flashAlgorithm.html https://github.com/ARM-software/CMSIS_5/tree/develop/Device/_Template_Flash https://github.com/pyocd/FlashAlgo
I have found a few FLM files inside Segger JLink applications. https://www.segger.com/downloads/jlink/JLink_Linux_x86_64.tgz ARM defined the struct and the function prototypes API to be exported by a position independent ELF, renamed as .FLM. The debugger loads the ELF in target memory, exchanges data through target memory, calls the API. It could be interesting to add FLM support to OpenOCD because we could easily reuse what chip vendors distribute. The problem is the Apache-2.0 license of the include file https://github.com/ARM-software/CMSIS_5/blob/develop/Device/_Template_Flash/FlashOS.h or the same split in two files https://github.com/pyocd/FlashAlgo/blob/main/source/FlashOS.h https://github.com/pyocd/FlashAlgo/blob/main/source/FlashPrg.h Apache-2.0 is not compatible with GPLv2 (only with GPLv3) https://www.apache.org/licenses/GPL-compatibility.html We had some talk about switching OpenOCD to GPLv3, but this will prevent us from including code fragments from Linux and U-Boot. No way. Plus we have to drop what we have already included! Linux only accepts Apache-2.0 code that has been dual licensed https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/LICENSES/dual/Apache-2.0 like this one, that by the way is still in "staging" and could even be dropped atter a while https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/staging/wfx/hif_api_mib.h If you have different info, please let me know. Having some firmware .FLM in Apache-2.0 or other incompatible license is not a problem as long as the firmware is not linked inside OpenOCD binary but distributed as an independent file. The issue is that we need the include file to describe, inside OpenOCD, how to read the struct and how to format the arguments of the API. Or probably not !!! For the API we need to set the target registers accordingly to the ABI then call the function by setting the target's program counter PC. The function prototype is implicit in the way we set the registers, but we don't need to include the Apache-2.0 file .h in OpenOCD! For the struct, we need to load it from the ELF/FLM. But to handle host and target endianess we cannot simply read() the struct from target ELF in a host struct defined in the Apache-2.0 file .h. We should read from ELF an array, parse it to extract the struct fields, adapt the endianess and put them in a completely different struct or in a set of local variables. Maybe this could be the way to go! Feedback? Antonio