Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By samprice
#3466 Ok Got it to compile for Mac.
i was using a sshfs mount, and switched to the instructions provided earlier
Still failed at very end, but all of my binary gcc programs appeared to be made.
It failed at
Code: Select all[EXTRA]  Preparing working directories
[ERROR]
[ERROR]  >>
[ERROR]  >>  Build failed in step '(top-level)'
[ERROR]  >>
[ERROR]  >>  Error happened in: CT_DoForceRmdir[scripts/functions@460]
[ERROR]  >>        called from: main[scripts/crosstool-NG.sh@238]


Now when I compile my program on mac I get an error saying that -lpp or libpp cannot be found
Code: Select all./../../lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':
(.irom0.text+0x7c): undefined reference to `wDev_ProcessFiq'
./../../lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':
(.irom0.text+0x84): undefined reference to `lmacInit'
./../../lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':
(.irom0.text+0x88): undefined reference to `wDev_Initialize'
./../../lib/libmain.a(app_main.o): In function `read_macaddr_from_otp':


The linux version doesnt have a libpp, so I think my gcc compiling is missing a step...

This is the list of steps I did
Code: Select allhdiutil create -size 10g -fs "Case-sensitive HFS+" -volname ESPTools ESPTools.sparsebundle
hdiutil attach ESPTools.sparsebundle
 ln -s /Volumes/ESPTools/ esptools
cd esptools
git clone -b lx106-g++ git://github.com/jcmvbkbc/crosstool-NG.git
./bootstrap
grep=/opt/local/bin/grep ./configure --prefix=`pwd`

now Chang ldflags in zconfig/Makefile
LDFLAGS = -L/opt/local/lib -lintl
Added following line to top of kconfig/zconf.hash.c
#define offsetof(type,field) __builtin_offsetof(type, field)
make
make install
./ct-ng xtensa-lx106-elf
./ct-ng build
User avatar
By joostn
#3468
jcmvbkbc wrote:
igrr wrote:I'm looking for a way to put all functions defined in an object file into irom0.text section. Is there a way other than adding ICACHE_FLASH_ATTR (i.e. __attribute__((section(".irom0.text")))) to every function definition?
man ld did not reveal anything for me, unfortunately.

You can add rules to .irom0.text output section that would match .text from your specific source file and exclude it from all other rules that match .text, e.g:
Code: Select all  .text : ALIGN(4)
  {
    _stext = .;
    _text_start = ABSOLUTE(.);
    *(.entry.text)
    *(.init.literal)
    *(.init)
    *(EXCLUDE_FILE(some_file.o) .literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
    *(.fini.literal)
    *(.fini)
    *(.gnu.version)
    _text_end = ABSOLUTE(.);
    _etext = .;
  } >iram1_0_seg :iram1_0_phdr

  .irom0.text : ALIGN(4)
  {
    _irom0_text_start = ABSOLUTE(.);
    *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
    some_file.o(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
    _irom0_text_end = ABSOLUTE(.);
  } >irom0_0_seg :irom0_0_phdr


Is there any way to just place all code in irom0 by default?
I've tried removing the entire line
(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
from iram1_0_seg and move this to irom0_0_seg but this results in
Code: Select all../../esp8266/esp_iot_sdk_V0.9.2/esptool/esptool -eo build/test1.out1 -bo build/0x00000.bin -bs .text -bs .data -bs .rodata -bc -ec
make: *** [build/0x00000.bin] Error 1
User avatar
By jcmvbkbc
#3471
joostn wrote:Is there any way to just place all code in irom0 by default?
I've tried removing the entire line
(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
from iram1_0_seg and move this to irom0_0_seg but this results in
Code: Select all../../esp8266/esp_iot_sdk_V0.9.2/esptool/esptool -eo build/test1.out1 -bo build/0x00000.bin -bs .text -bs .data -bs .rodata -bc -ec
make: *** [build/0x00000.bin] Error 1

But that's esptool issue, the compiler and linker appear to have done their part.
User avatar
By joostn
#3527
But that's esptool issue, the compiler and linker appear to have done their part.

Both are equally black boxes to me :D

Anyway I did a make clean; make and now I get linker errors as well:
Code: Select all"/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/bin/xtensa-lx106-elf-g++" -L../../esp8266/esp_iot_sdk_V0.9.2/lib -L ../../esp8266/esp_iot_sdk_V0.9.2/ld/ -Teagle.app.v6.cpp.ld -Wl,--no-check-sections  -u call_user_start  -Wl,-static -nostdlib  -Xlinker -Map=build/test1.map -Wl,--gc-sections build/obj/uart.o build/obj/main.o build/obj/jnuclib.o build/obj/jnucgpio.o build/obj/jnucasync.o build/obj/jnuckeyboarddebouncer.o build/obj/jnuceventdispatcher.o build/obj/jnucinterruptonchange.o build/obj/jnucinterrupthandlers.o build/obj/jnucinternaltempsensor.o build/obj/jnucble.o build/obj/jnucblecommon.o build/obj/jnucblecentral.o build/obj/jnucdisplaybase.o build/obj/jnucbuffereddisplay.o build/obj/jnuccontrols.o build/obj/jnucpcd8544.o build/obj/jnucili9320.o build/obj/jnucst7735.o build/obj/jnucseps225.o build/obj/jnucsystick.o build/obj/jnucboards.o build/obj/jnucbitmap.o build/obj/jnucfonts.o build/obj/jnucWindowManager.o build/obj/jnucdialogs.o build/obj/someFonts.o build/obj/jnucrotary.o build/obj/jnuctimer.o build/obj/jnucservo.o build/obj/jnucuart.o build/obj/jnucstream.o build/obj/jnucnetcommon.o build/obj/jnuctcpserver.o build/obj/staticfunctionstub.o  -o build/test1.out
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.2/../../../../xtensa-lx106-elf/bin/ld: warning: cannot find entry symbol call_user_start; defaulting to 0000000040100000
build/obj/jnucasync.o:(.text._ZN4jnuc9function0IvE14invokeEmbeddedIZNS_10TimerQueueC1EvEUlvE0_EEvPKS1_+0x18): undefined reference to `system_os_post'
build/obj/jnucasync.o: In function `void jnuc::function0<void>::invokeEmbedded<jnuc::TimerQueue::TimerQueue()::{lambda()#2}>(jnuc::function0<void> const*)':
jnucasync.cpp:(.text._ZN4jnuc9function0IvE14invokeEmbeddedIZNS_10TimerQueueC1EvEUlvE0_EEvPKS1_+0xc6): undefined reference to `system_os_post'
build/obj/jnucasync.o:(.text._ZN4jnuc10TimerQueue19RescheduleInterruptEv+0xc): undefined reference to `system_get_time'
...

This is my linker script:
Code: Select all/* This linker script generated from xt-genldscripts.tpp for LSP . */
/* Linker Script for ld -N */
MEMORY
{
  dport0_0_seg :                         org = 0x3FF00000, len = 0x10
  dram0_0_seg :                          org = 0x3FFE8000, len = 0x14000
  iram1_0_seg :                          org = 0x40100000, len = 0x8000
  irom0_0_seg :                          org = 0x40240000, len = 0x32000
}

PHDRS
{
  dport0_0_phdr PT_LOAD;
  dram0_0_phdr PT_LOAD;
  dram0_0_bss_phdr PT_LOAD;
  iram1_0_phdr PT_LOAD;
  irom0_0_phdr PT_LOAD;
}


/*  Default entry point:  */
ENTRY(call_user_start)
PROVIDE(_memmap_vecbase_reset = 0x40000000);
/* Various memory-map dependent cache attribute settings: */
_memmap_cacheattr_wb_base = 0x00000110;
_memmap_cacheattr_wt_base = 0x00000110;
_memmap_cacheattr_bp_base = 0x00000220;
_memmap_cacheattr_unused_mask = 0xFFFFF00F;
_memmap_cacheattr_wb_trapnull = 0x2222211F;
_memmap_cacheattr_wba_trapnull = 0x2222211F;
_memmap_cacheattr_wbna_trapnull = 0x2222211F;
_memmap_cacheattr_wt_trapnull = 0x2222211F;
_memmap_cacheattr_bp_trapnull = 0x2222222F;
_memmap_cacheattr_wb_strict = 0xFFFFF11F;
_memmap_cacheattr_wt_strict = 0xFFFFF11F;
_memmap_cacheattr_bp_strict = 0xFFFFF22F;
_memmap_cacheattr_wb_allvalid = 0x22222112;
_memmap_cacheattr_wt_allvalid = 0x22222112;
_memmap_cacheattr_bp_allvalid = 0x22222222;
PROVIDE(_memmap_cacheattr_reset = _memmap_cacheattr_wb_trapnull);

SECTIONS
{

  .dport0.rodata : ALIGN(4)
  {
    _dport0_rodata_start = ABSOLUTE(.);
    *(.dport0.rodata)
    *(.dport.rodata)
    _dport0_rodata_end = ABSOLUTE(.);
  } >dport0_0_seg :dport0_0_phdr

  .dport0.literal : ALIGN(4)
  {
    _dport0_literal_start = ABSOLUTE(.);
    *(.dport0.literal)
    *(.dport.literal)
    _dport0_literal_end = ABSOLUTE(.);
  } >dport0_0_seg :dport0_0_phdr

  .dport0.data : ALIGN(4)
  {
    _dport0_data_start = ABSOLUTE(.);
    *(.dport0.data)
    *(.dport.data)
    _dport0_data_end = ABSOLUTE(.);
  } >dport0_0_seg :dport0_0_phdr

  .data : ALIGN(4)
  {
    _data_start = ABSOLUTE(.);
    *(.data)
    *(.data.*)
    *(.gnu.linkonce.d.*)
    *(.data1)
    *(.sdata)
    *(.sdata.*)
    *(.gnu.linkonce.s.*)
    *(.sdata2)
    *(.sdata2.*)
    *(.gnu.linkonce.s2.*)
    *(.jcr)
    _data_end = ABSOLUTE(.);
  } >dram0_0_seg :dram0_0_phdr

  .rodata : ALIGN(4)
  {
    _rodata_start = ABSOLUTE(.);
    *(.rodata)
    *(.rodata.*)
    *(.gnu.linkonce.r.*)
    *(.rodata1)
    __XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
    *(.xt_except_table)
    *(.gcc_except_table)
    *(.gnu.linkonce.e.*)
    *(.gnu.version_r)
    *(.eh_frame)
    . = (. + 3) & ~ 3;
    /*  C++ constructor and destructor tables, properly ordered:  */
    __init_array_start = ABSOLUTE(.);
    KEEP (*crtbegin.o(.ctors))
    KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
    KEEP (*(SORT(.ctors.*)))
    KEEP (*(.ctors))
    __init_array_end = ABSOLUTE(.);
    KEEP (*crtbegin.o(.dtors))
    KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
    KEEP (*(SORT(.dtors.*)))
    KEEP (*(.dtors))
    /*  C++ exception handlers table:  */
    __XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
    *(.xt_except_desc)
    *(.gnu.linkonce.h.*)
    __XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
    *(.xt_except_desc_end)
    *(.dynamic)
    *(.gnu.version_d)
    . = ALIGN(4);      /* this table MUST be 4-byte aligned */
    _bss_table_start = ABSOLUTE(.);
    LONG(_bss_start)
    LONG(_bss_end)
    _bss_table_end = ABSOLUTE(.);
    _rodata_end = ABSOLUTE(.);
  } >dram0_0_seg :dram0_0_phdr

  .bss ALIGN(8) (NOLOAD) : ALIGN(4)
  {
    . = ALIGN (8);
    _bss_start = ABSOLUTE(.);
    *(.dynsbss)
    *(.sbss)
    *(.sbss.*)
    *(.gnu.linkonce.sb.*)
    *(.scommon)
    *(.sbss2)
    *(.sbss2.*)
    *(.gnu.linkonce.sb2.*)
    *(.dynbss)
    *(.bss)
    *(.bss.*)
    *(.gnu.linkonce.b.*)
    *(COMMON)
    . = ALIGN (8);
    _bss_end = ABSOLUTE(.);
    _heap_start = ABSOLUTE(.);
/*    _stack_sentry = ALIGN(0x8); */
  } >dram0_0_seg :dram0_0_bss_phdr
/* __stack = 0x3ffc8000; */

  .text : ALIGN(4)
  {
    _stext = .;
    _text_start = ABSOLUTE(.);
    *(.entry.text)
    *(.init.literal)
    *(.init)
/*    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*) */
    *(.fini.literal)
    *(.fini)
    *(.gnu.version)
    _text_end = ABSOLUTE(.);
    _etext = .;
  } >iram1_0_seg :iram1_0_phdr

  .lit4 : ALIGN(4)
  {
    _lit4_start = ABSOLUTE(.);
    *(*.lit4)
    *(.lit4.*)
    *(.gnu.linkonce.lit4.*)
    _lit4_end = ABSOLUTE(.);
  } >iram1_0_seg :iram1_0_phdr

  .irom0.text : ALIGN(4)
  {
    _irom0_text_start = ABSOLUTE(.);
    *(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
    *(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
    _irom0_text_end = ABSOLUTE(.);
  } >irom0_0_seg :irom0_0_phdr
}

/* get ROM code address */
INCLUDE "../ld/eagle.rom.addr.v6.ld"

(I just edited the .text and .irom0.text sections)

It's not a big deal, I can move individual functions to ROM if needed. It just would be handy if it would be the other way round (everything in ROM by default, move to RAM on request).

BTW thanks for all your work and help, it's working like a charm!