platformio / platform-atmelsam

Atmel SAM: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelsam
Apache License 2.0
78 stars 105 forks source link

Flashing binary with FPGA bitstream fails in upload: "file operation exceeds flash size" #142

Open maxgerhardt opened 3 years ago

maxgerhardt commented 3 years ago

See https://community.platformio.org/t/mkr-vidor-4000-with-vidorperipherals-upload-fails/18922/.

When the platformio.ini

[env:mkrvidor4000]
board = mkrvidor4000
platform = atmelsam
framework = arduino
lib_deps =
  khoih-prog/WiFiWebServer @ ^1.1.1
  khoih-prog/Functional-Vlpp@^1.0.1
  vidor-libraries/VidorPeripherals @ ^1.1.0

is used with the code

#include <WiFiWebServer.h>
#include <Arduino.h>
void setup()
{
} 
void loop()
{
}

the resulting ELF binary has the sections

.pio\build\mkrvidor4000\firmware.elf  :
section                     size        addr
.text                      13168        8192
.fpga_bitstream_section   429892      262144
.data                        192   536870912
.bss                        2480   536871104
.ARM.attributes               40           0
.comment                     126           0
.debug_frame                 896           0
.stabstr                     441           0
Total                     447235

And the .bin does not only contain the Flash contents but also what's supposed to go into the FPAG bitstream memory, which is apparently right behind flash.

Uploading in PlatformIO fails with a bossac error: "file operation exceeds flash size".

By comparing the working Arduino-IDE bossac invocation of

bossac -i -d --port=cu.usbmodem14101 -I -U true -i -e -w /var/folders/sx/g5n3hgks0z356wtyn16__m6r0000gp/T/arduino_build_507571/FlashErrorA.ino.bin -R

with the non-working PlatformIO invocation

bossac --info --debug --port "cu.usbmodem14101" --write --verify --reset --erase -U true .pio/build/mkrvidor4000/firmware.bin

We can see that a difference is a missing -I flag in PlatformIO, to which bossac says

  -I, --ignoreOverflow  ignore if binary is bigger than internal flash
                        may be used to program external flash with contiguous address space)

So it may be that for that chip the FPGA mem sits right behind flash and thus the Arduino IDE builds a .bin file that has Flash + fill for aligment (?)+ FPGA bitstream and then uses -I for this board (or all boards on Atmel SAM?) to make bossac flash the binary image to the chip into memory that actually exists after all.

Currently, this can be worked around in the platformio.ini with upload_flags = -I but a bugfix or investigation here would be good.