Pages: [1]   Go Down
Author Topic: Image too big for flash or avrdude problem?  (Read 434 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I am currently working on improving the OpenBSD arduino toolchain described here:
http://playground.arduino.cc/OpenBSD/CLI

I have managed to fix a few things that will make the makefile more user-friendly, however, I have noticed an issue with the SD library.

If I build a simple program with just SD.begin() in setup() I get a hex file like so:
Code:
$ make
test -d applet || mkdir applet
echo '#include "Arduino.h"' > applet/test.cpp
echo '#ifdef __cplusplus' >> applet/test.cpp
echo 'extern "C" void __cxa_pure_virtual(void) { while(1); }'  >> applet/test.cpp
echo '#endif\n' >> applet/test.cpp
cat test.ino >> applet/test.cpp
cat /usr/local/share/arduino//cores/arduino/main.cpp >> applet/test.cpp
mkdir -p utility
/usr/local/bin/avr-gcc -c -mmcu=atmega328p -I. -gstabs -DF_CPU=16000000 -I/usr/local/share/arduino//cores/arduino -I/usr/local/share/arduino//libraries/SD -I/usr/local/share/arduino//libraries/File -I/usr/local/share/arduino//libraries/utility/SdFile -I/usr/local/share/arduino//libraries/utility/SdVolume -I/usr/local/share/arduino//libraries/utility/Sd2Card -I/usr/local/share/arduino//libraries/SD/utility/ -I/usr/local/share/arduino//libraries/File/utility/ -I/usr/local/share/arduino//libraries/utility/SdFile/utility/ -I/usr/local/share/arduino//libraries/utility/SdVolume/utility/ -I/usr/local/share/arduino//libraries/utility/Sd2Card/utility/ -I/usr/local/share/arduino//variants/standard -I/usr/local/share/arduino//variants/standard -Os -Wall -Wstrict-prototypes  -std=gnu99  -ffunction-sections -fdata-sections /usr/local/share/arduino//cores/arduino/wiring.c -o wiring.o
...

   text    data     bss     dec     hex filename
      0   30670       0   30670    77ce applet/test.hex
$ du -h applet/test.hex                                                                             
86.0K   applet/test.hex

Notice that the reported size (dec) is close to 32K, the size of a standard arduino flash.

If I now try to upload this with avrdude-5.11 (or avrdude-5.10), this happens:

Code:
> sudo make upload
/usr/local/bin/avrdude -V -F -C /etc/avrdude.conf -p atmega328p -P /dev/cuaU0  -c arduino -b 115200 -U flash:w:applet/test.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
avrdude: NOTE: FLASH memory has been specified, an erase cycle will be performed
         To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "applet/test.hex"
avrdude: input file applet/test.hex auto detected as Intel Hex
avrdude: writing flash (30670 bytes):

Writing | ###############################################    | 93% 5.48savrdude: stk500_recv(): programmer is not responding
*** Error 1 in /home/edd/source/test (BSDmakefile:198 'upload')

Uploading gets to 93% every time before stalling. This does not happen with an arduino mega.

My question is, does the program not fit in the 32K flash, or is this an avrdude issue?

I speculate that the image is too big for the flash, if that is the case then why? The SD library should fit on 32K flash.

The makefile I am using (with my changes) is here:
https://github.com/jasperla/openbsd-wip/blob/master/devel/arduino/files/BSDmakefile

This problem was not introduced by my changes.

Any ideas? Removing -gstabs does not help. I have experimented with stripping the intermediate core.a; this makes the .a much smaller but presumably in a section which is not present in the resulting hex file. The hex file remains the same size.
Logged

Offline Offline
Edison Member
*
Karma: 57
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems as if the linker includes everything from the SD library. Perhaps it is a compiler or linker flag.
Do you use Arduino 1.0.4 as source ?
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It turns out I'm using 1.0.2, but I don't think this is the problem.

I recently added -ffunction-sections -fdata-sections to CFLAGS and linked with -Wl,--gc-sections. This should strip anything unused. It makes the binary a little smaller, but not small enough. Oddly, if i remove the SD.begin() so that the sources contain no reference to the SD library, the binary is much much smaller.

Maybe, like you say, sd.begin() erroneously pulls in the whole library. Perhaps I am missing a linker/objcopy flag? Any ideas anyone?
Logged

texas
Offline Offline
God Member
*****
Karma: 27
Posts: 862
old, but not dead
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dump the fuse bits with avrdude and see if some FLASH is reserved for a bootloader.  I suspect that might explain why it doesn't fit.
Logged

Experience, it's what you get when you were expecting something else.

Pages: [1]   Go Up
Jump to: