energia / Energia

Fork of Arduino for the Texas Instruments LaunchPad's
http://energia.nu
Other
794 stars 672 forks source link

CC3200 Incorrect binary sketch size reported #443

Closed astuder closed 9 years ago

astuder commented 10 years ago

Energia for CC3200 reports an incorrect binary sketch size. E.g. for Blink:

CC3200: Binary sketch size: 102,471 bytes (of a 262,144 byte maximum) Tiva: Binary sketch size: 4,556 bytes (of a 262,144 byte maximum)

Reported upload size is about 100K less, i.e. probably correct.

No functional impact, but might create an issue for a large sketch if Energia verifies against maximum.

astuder commented 10 years ago

I'm not setup to recompile and test the java parts of Energia, but I think the issue is with lines 126ff in Sizer.java

if(arch == "lm4f") {
    size = (new Integer(st.nextToken().trim())).longValue();
    size += (new Integer(st.nextToken().trim())).longValue();
} else {
    st.nextToken();
    st.nextToken();
    st.nextToken();
    size += (new Integer(st.nextToken().trim())).longValue();
}

the if should probably read

if(arch == "lm4f" || arch == "cc3200") {
robertinant commented 10 years ago

That did it!! Thanks for catching that! Committed with: 1b9e24ee24e63751141357409d7de17a297bab15

rei-vilo commented 10 years ago

Does really the blinky sketch take all that RAM?

$ /Applications/Energia.app/Contents/Resources/Java/hardware/tools/lm4f/bin/arm-none-eabi-size /var/folders/5d/dky9xc691m32kztqnhkn8bhw0000gn/T/build4504629373896744113.tmp/Blink.cpp.elf
   text    data     bss     dec     hex filename
   3704       0   98344  102048   18ea0 /var/folders/5d/dky9xc691m32kztqnhkn8bhw0000gn/T/build4504629373896744113.tmp/Blink.cpp.elf

Performing an objdump gives

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000e78  20004000  20004000  00004000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .bss          00008024  20004e78  20004e78  00004e78  2**2
                  ALLOC
  2 .heap         00010004  2000ce9c  2000ce9c  00004e78  2**0
                  ALLOC
  3 .comment      00000070  00000000  00000000  00004e78  2**0
                  CONTENTS, READONLY
  4 .ARM.attributes 00000033  00000000  00000000  00004ee8  2**0
                  CONTENTS, READONLY

The question is about the 0x10004 = 64 KB + 4 Bytes heap.

spirilis commented 10 years ago

what's the rest of the objdump -x say? curious which symbols are using it...

astuder commented 10 years ago

64K is probably the default heap-size. From the cc3200 linker script:

HEAP_SIZE = 0x00010000;
[..]
 .heap :
{
  _heap = .;
  . = . + HEAP_SIZE;
  . = ALIGN(8);
  _eheap = .;
}

The LM4F scripts basically says everything below stack not used by variables is heap

/* end of allocated ram is start of heap, heap grows up towards stack*/
PROVIDE(end = _end);
/* top of stack starts at end of ram, stack grows down towards heap */
PROVIDE (_estack = ORIGIN(ram) + LENGTH(ram));

Edit to add: heap is the area that malloc can use to dynamically allocate memory. As it's not known at compile time how much memory will be dynamically allocated, the compiler has to reserve that area no matter whether its used or not. One of the perils of dynamic memory allocation and why it's usually avoided for small MCUs.

rei-vilo commented 10 years ago

Here's the full * objdump -x* of the Blink example:

$ /Applications/Energia.app/Contents/Resources/Java/hardware/tools/lm4f/bin/arm-none-eabi-objdump -x /var/folders/5d/dky9xc691m32kztqnhkn8bhw0000gn/T/build9026688581127218701.tmp/Blink.cpp.elf
/var/folders/5d/dky9xc691m32kztqnhkn8bhw0000gn/T/build9026688581127218701.tmp/Blink.cpp.elf:     file format elf32-littlearm
/var/folders/5d/dky9xc691m32kztqnhkn8bhw0000gn/T/build9026688581127218701.tmp/Blink.cpp.elf
architecture: arm, flags 0x00000112:
EXEC_P, HAS_SYMS, D_PAGED
start address 0x20004451

Program Header:
    LOAD off    0x00000000 vaddr 0x20000000 paddr 0x20000000 align 2**15
         filesz 0x00004e78 memsz 0x0001cea0 flags rwx
private flags = 5000002: [Version5 EABI] [has entry point]

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000e78  20004000  20004000  00004000  2**2
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  1 .bss          00008024  20004e78  20004e78  00004e78  2**2
                  ALLOC
  2 .heap         00010004  2000ce9c  2000ce9c  00004e78  2**0
                  ALLOC
  3 .comment      00000070  00000000  00000000  00004e78  2**0
                  CONTENTS, READONLY
  4 .ARM.attributes 00000033  00000000  00000000  00004ee8  2**0
                  CONTENTS, READONLY
SYMBOL TABLE:
20004000 l    d  .text  00000000 .text
20004e78 l    d  .bss   00000000 .bss
2000ce9c l    d  .heap  00000000 .heap
00000000 l    d  .comment   00000000 .comment
00000000 l    d  .ARM.attributes    00000000 .ARM.attributes
00000000 l    df *ABS*  00000000 startup_gcc.c
20004e78 l     O .bss   00008000 pui32Stack
2000450c l     F .text  00000006 NmiSR
20004514 l     F .text  00000006 FaultISR
20004524 l     F .text  00000006 IntDefaultHandler
2000451c l     F .text  00000006 BusFaultHandler
20004480 l     F .text  00000000 zero_loop
00000000 l    df *ABS*  00000000 Blink.cpp
00000000 l    df *ABS*  00000000 wiring.c
2000ce78 l     O .bss   00000020 SysTickCbFuncs
2000ce98 l     O .bss   00000004 milliseconds
00000000 l    df *ABS*  00000000 wiring_digital.c
00000000 l    df *ABS*  00000000 main.cpp
00000000 l    df *ABS*  00000000 gpio.c
00000000 l    df *ABS*  00000000 interrupt.c
00000000 l    df *ABS*  00000000 pin.c
20004cd8 l     O .text  00000100 g_ulPinToPadMap
00000000 l    df *ABS*  00000000 prcm.c
20004dd8 l     O .text  000000a0 PRCM_PeriphRegsList
00000000 l    df *ABS*  00000000 systick.c
00000000 l    df *ABS*  00000000 cpu.c
00000000 l    df *ABS*  00000000 
00010000 l       *ABS*  00000000 HEAP_SIZE
2001cea0 l       .heap  00000000 _eheap
2000ce9c l       .heap  00000000 _heap
200047d8 g     F .text  0000001c IntVTableBaseSet
20004438  w    F .text  0000000c UARTIntHandler
20004e78 g       .text  00000000 __init_data
20004e78 g       .text  00000000 __exidx_end
20004e78 g       .text  00000000 _etext
2000494c g     F .text  00000054 PRCMPeripheralClkEnable
20004410 g     F .text  00000026 loop
200047a0 g     F .text  00000028 GPIOPinWrite
200048d8 g     F .text  00000038 PinTypeGPIO
20004e78 g       .text  00000000 __fini_array_end
2000483c g     F .text  0000009c PinConfigSet
20004694 g     F .text  00000060 digitalWrite
200049e4 g     F .text  0000008c PRCMPeripheralReset
200045d4 g     F .text  000000c0 pinMode
20004c18 g     O .text  00000014 port_to_base
20004e78 g       .text  00000000 __exidx_start
20004444  w    F .text  0000000c UARTIntHandler1
2000ce9c g       .bss   00000000 _ebss
00000000  w      *UND*  00000000 _Z14serialEventRunv
20004be8 g     F .text  00000018 SysTickValueGet
20004c2c g     O .text  00000052 digital_pin_to_pin_num
20004e78 g       .bss   00000000 _bss
20004a70 g     F .text  00000120 PRCMCC3200MCUInit
2000458c g     F .text  00000048 SysTickIntHandler
20004bc8 g     F .text  00000020 SysTickPeriodSet
20004910 g     F .text  0000003c PRCMSysResetCauseGet
20004000 g       .text  00000000 _text
20004e78 g       .text  00000000 __fini_array_start
200046f4 g     F .text  00000064 main
20004e78 g       .text  00000000 __init_array_end
20004560 g     F .text  0000002a delay
200047c8 g     F .text  00000010 IntMasterEnable
20004e78 g       .text  00000000 __preinit_array_end
20004e78 g       .text  00000000 _data
20004400 g     F .text  0000000e setup
20004cac g     O .text  00000029 digital_pin_to_bit_mask
20004e78 g       .text  00000000 _edata
20004000 g     O .text  00000400 g_pfnVectors
20004450 g     F .text  000000b4 ResetISR
200047f4 g     F .text  00000048 PinModeSet
20004e78 g       .text  00000000 __init_array_start
20004c80 g     O .text  00000029 digital_pin_to_port
20004c00 g     F .text  00000016 CPUcpsie
20004758 g     F .text  00000048 GPIODirModeSet
20004b90 g     F .text  0000001c SysTickEnable
20004bac g     F .text  0000001c SysTickIntEnable
20004e78 g       .text  00000000 __preinit_array_start
2000452c g     F .text  00000032 delayMicroseconds
200049a0 g     F .text  00000044 PRCMPeripheralClkDisable
robertinant commented 10 years ago

Couple of things:

First, there was a bug in the size calculation. It was including .bss section. In theory that should be included since the both .text and .data are in RAM. Either way, it has been patched with 1b9e24ee24e63751141357409d7de17a297bab15 I will have to thing about how to go about including the .bss.

1: All driverlib code is currently in RAM. I have not gotten around to fixing that. I think it is as simple as defining TARGET_IS_CC3200 somewhere where it gets picked up by rom.h 2: All optimization is switched of. This is for debugging purposes. I can make you a build that switches that off although debugging might become difficult then. 3: The linker file assumes a dead piece of dead RAM. Length of RAM is set to 192k. I think that that is fixed in PG1.32 so can be set to 256k? 4: Heap is HUGE right now with 65k. Reducing that should do at least something. 5: Stack is set to 32k. I think that can be reduced to 16 although should be the last resort.

holla2040 commented 10 years ago

OK. sounds good.

On Wed, Aug 20, 2014 at 3:09 PM, robertinant notifications@github.com wrote:

Couple of things:

First, there was a bug in the size calculation. It was including .bss section. In theory that should be included since the both .text and .data are in RAM. Either way, it has been patched with 1b9e24e https://github.com/energia/Energia/commit/1b9e24ee24e63751141357409d7de17a297bab15 I will have to thing about how to go about including the .bss.

1: All driverlib code is currently in RAM. I have not gotten around to fixing that. I think it is as simple as defining TARGET_IS_CC3200 somewhere where it gets picked up by rom.h 2: All optimization is switched of. This is for debugging purposes. I can make you a build that switches that off although debugging might become difficult then. 3: The linker file assumes a dead piece of dead RAM. Length of RAM is set to 192k. I think that that is fixed in PG1.32 so can be set to 256k? 4: Heap is HUGE right now with 65k. Reducing that should do at least something. 5: Stack is set to 32k. I think that can be reduced to 16 although should be the last resort.

— Reply to this email directly or view it on GitHub https://github.com/energia/Energia/issues/443#issuecomment-52844481.


Dr. Craig Hollabaugh craig@hollabaugh.com 970 690 4911

robertinant commented 9 years ago

This has been fixed.