I have an LPC1549, that can be started in USB MSC mode by pulling the right pins up&down during reset. This all works, I see my device as an USB flash disk containing a 256K firmware.bin file. Now I want to be able to generate a firmware.bin file with platformio that can be used to program my LPC. I know platformio already generates a firmware.bin file, but that file is 32MB large, and cannot be uploaded to the flash disk. So I tried to generate my own firmware.bin file using this command: ‘objcopy.exe firmware.elf -O binary -R.heap -R.bss -R.stack_dummy firmware.bin’. Works fine, and strips the RAM parts of the firmware at adress 0x2000000 and higher, so smaller file; nice. Still it does not work when I upload the file to the USB flashdisk. When comparing a ‘working file’ (created by programming LPC via SWD) and a ‘non-working file’, it seems that at offset 0x1C to 0x1F the working file contains ‘4A 14 FF FD’, the non-working file contains only zeros there. How can I make my compiler and/or linker command to get those bytes in the right value?
Wow, that’s quick! Thanks for the reply! For the LPC15xx series it seems also the bin file is containing sections from the ELF that should not be there because they increase the size of the bin to 32MB. Using the flags “-R.heap -R.bss -R.stack_dummy” on objcopy fixes this, should this also be added to the issue on github? For now I have created an extra_script that uses your checksum function to create a firmware_FLASH.bin;
(only last part of extra_script):
# Custom BIN from ELF
env.AddPostAction(
"$BUILD_DIR/${PROGNAME}.elf",
env.VerboseAction(" ".join([
"$OBJCOPY",
"-O",
"binary",
"-R.heap",
"-R.bss",
"-R.stack_dummy",
"$TARGET",
"$BUILD_DIR/${PROGNAME}_FLASH.bin"
]), "Building USB-flash ready bin file from $TARGET"))
# fix checksum
env.AddPostAction("$BUILD_DIR/${PROGNAME}.elf", post_elf_file)
Yes please, but that must be a separate issue in that platform. There’s the code
Does it work that way with the checksum added? I see you’re creating a fixed firmware_FLASH.bin there (which will not be what’s used during the “Upload” procedure, there it will use firmware.bin – you might want to try and modify / fix the existing .bin file)
I created firmware_FLASH.bin because I didn’t know if it would break something if I would use the default firmware.bin. Will change to firmware.bin now.