Recent

Author Topic: Problem linking for Xtensa (ESP32)  (Read 5827 times)

MiR

  • Full Member
  • ***
  • Posts: 206
Re: Problem linking for Xtensa (ESP32)
« Reply #15 on: May 09, 2020, 01:44:26 pm »
Can you please replace your ppcrossxtensa with the file from here:

http://temp.michael-ring.org/ppcrossxtensa.exe

I have added logging for two important commands.

For me the command ldgen fails which as a consequence lets the linker fail.

Please try on your system and report back the output.

One more thing, I saw that you did not follow instructions because you are using latest esp-idf sdk (binutils from 4.0 have a path with 2019 in it), should not matter too much but it might create crazy issues later in the process when you jumped this first hurdle.


Code: [Select]
C:\Users\ring\devel\hello>ppcrossxtensa -Fuxtensa-freertos\rtl -Tfreertos -XPxtensa-esp32-elf- -O3 -Wpesp32 hello
C:\Users\ring\Desktop\esp-idf/tools/ldgen/ldgen.py
--config sdkconfig --fragments C:\Users\ring\Desktop\esp-idf/components/xtensa/linker.lf C:\Users\ring\Desktop\esp-idf/components/soc/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_event/linker.lf C:\Users\ring\Desktop\esp-idf/components/spi_flash/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_wifi/linker.lf C:\Users\ring\Desktop\esp-idf/components/lwip/linker.lf C:\Users\ring\Desktop\esp-idf/components/heap/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_ringbuf/linker.lf C:\Users\ring\Desktop\esp-idf/components/espcoredump/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32_fragments.lf C:\Users\ring\Desktop\esp-idf/components/freertos/linker.lf C:\Users\ring\Desktop\esp-idf/components/newlib/newlib.lf C:\Users\ring\Desktop\esp-idf/components/esp_gdbstub/linker.lf --input C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\ring\Desktop\esp-idf/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
hello.pp(3,18) Error: Can't call the linker, switching to external linking
hello.pp(3,18) Error: Error while linking
C:\Users\ring\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
-g     --gc-sections   -L. -o hello.elf -T link9716.res -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority -L C:\Users\ring\Desktop\esp-idf/components/esp_rom/esp32/ld -T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-funcs.ld -L . -T esp32_out.ld -T esp32.project.ld -L C:\Users\ring\Desktop\esp-idf/components/esp32/ld -T esp32.peripherals.ld
FALSE
hello.pp(3,18) Fatal: There were 2 errors compiling module, stopping
Fatal: Compilation aborted

C:\Users\ring\devel\hello>C:\Users\ring\Desktop\esp-idf/tools/ldgen/ldgen.py --config sdkconfig --fragments C:\Users\ring\Desktop\esp-idf/components/xtensa/linker.lf C:\Users\ring\Desktop\esp-idf/components/soc/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_event/linker.lf C:\Users\ring\Desktop\esp-idf/components/spi_flash/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_wifi/linker.lf C:\Users\ring\Desktop\esp-idf/components/lwip/linker.lf C:\Users\ring\Desktop\esp-idf/components/heap/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp_ringbuf/linker.lf C:\Users\ring\Desktop\esp-idf/components/espcoredump/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/linker.lf C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32_fragments.lf C:\Users\ring\Desktop\esp-idf/components/freertos/linker.lf C:\Users\ring\Desktop\esp-idf/components/newlib/newlib.lf C:\Users\ring\Desktop\esp-idf/components/esp_gdbstub/linker.lf --input C:\Users\ring\Desktop\esp-idf/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\ring\Desktop\esp-idf/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
Traceback (most recent call last):
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 150, in <module>
    main()
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 112, in main
    _update_environment(args)  # assign args.env and args.env_file to os.environ
  File "C:\Users\ring\Desktop\esp-idf\tools\ldgen\ldgen.py", line 41, in _update_environment
    env = json.load(args.env_file)
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\ring\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Invalid \escape: line 6 column 20 (char 164)




MiR

  • Full Member
  • ***
  • Posts: 206
Re: Problem linking for Xtensa (ESP32)
« Reply #16 on: May 09, 2020, 01:59:53 pm »
Problem is likely in the env file generated from freepascal on windows

This:

    "IDF_PATH": "C:\Users\ring\Desktop\esp-idf",

is not working, this:

    "IDF_PATH": "C:/Users/ring/Desktop/esp-idf",

makes ldgen.py happy but it seems there is more hacking needed....

Here's what I changed for the logging, based on this and adding perhaps a little more logging here and there you should be able to fix the compiler or to at least write a good bugreport:

Code: Pascal  [Select][+][-]
  1. diff --git a/compiler/systems/t_freertos.pas b/compiler/systems/t_freertos.pas
  2. index 4efe4deb79..66a599e003 100644
  3. --- a/compiler/systems/t_freertos.pas
  4. +++ b/compiler/systems/t_freertos.pas
  5. @@ -1144,6 +1144,8 @@ begin
  6.          '--libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump';
  7.        Replace(binstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  8.        Replace(cmdstr,'$IDF_PATH',maybequoted(GetEnvironmentVariable('IDF_PATH')));
  9. +      writeln(binstr);
  10. +      writeln(cmdstr);
  11.        if success and not(cs_link_nolink in current_settings.globalswitches) then
  12.          success:=DoExec(binstr,cmdstr,true,false);
  13.      end;
  14. @@ -1186,6 +1188,10 @@ begin
  15.      Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
  16.      Replace(cmdstr,'$DYNLINK',DynLinkStr);
  17.     end;
  18. +
  19. +  writeln(FindUtil(utilsprefix+BinStr));
  20. +  writeln(cmdstr);
  21. +  writeln(success);
  22.    if success and not(cs_link_nolink in current_settings.globalswitches) then
  23.      success:=DoExec(FindUtil(utilsprefix+BinStr),cmdstr,true,false);


« Last Edit: May 09, 2020, 02:03:04 pm by MiR »

TRon

  • Hero Member
  • *****
  • Posts: 525
Re: Problem linking for Xtensa (ESP32)
« Reply #17 on: May 09, 2020, 02:08:34 pm »
Ah, yes indeed marcov.

Unless resorting to WSL or similar solutions then we are still depending on file association (which is not independent from OS, afaik).

In that regards my statement is most certainly too bold. Good catch  :)

On certain platforms it is not always possible to target everything (or even anything due to hardware restrictions ). It is a continues process, adding and improving things etc. For instance i don't  particularly like the version scheme that FPC front-end uses to invoke the correct compiler version, therefor i wrote a front-end for the compiler front-end  %)

As last resort i'm working on bailing out, and invoke a remote compiler (again if possible). But that feature is in early stage and is still being researched. But i already saw another feature i wish to add, and that is that Lazarus seems to support compiler options to be provided from the (main program's) source-code. That could be a nice addition.

electronickiwi

  • New member
  • *
  • Posts: 8
Re: Problem linking for Xtensa (ESP32)
« Reply #18 on: May 10, 2020, 05:15:16 am »
I've tried a few things with mixed results.

First I tried MiR's ppcrossxtensa.exe, and apart from some additional log output got a similar result, including after I changed the IDF_PATH to linux-style.

Yes, I was using esp-idfv4.2, this came after trying v4.0 without success.  (I note the wiki says to use v4.0.1 which isn't one of the labels used for esp-idf releases, but 4.0 is?).

I now changed back to esp-idfv4.0. I deleted everything and built fpc from source again.

Now using MiR compiler the results indicate that the compiler cannot find ".\rtl\xtensa-freertos" which isn't present but ".\rtl\xtensa" and ".\rtl\units\xtensa-freertos" are present, with the latter specified using -Fu

Code: Text  [Select][+][-]
  1. C:\source\fpc>compiler\ppcrossxtensa -vt -Furtl\units\xtensa-freertos\ -Tfreertos -FDC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin -XPxtensa-esp32-elf- -Wpesp32 -FlC:\Users\Wes\esp\xtensa-esp32-elf-libs\ -FlC:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\ hello
  2. Configfile search: fpc.cfg
  3. Configfile search: C:\Users\Wes\fpc.cfg
  4. Configfile search: C:\ProgramData\fpc.cfg
  5. Configfile search: C:\source\fpc\compiler\fpc.cfg
  6. Path ".\::=::\" not found
  7. Path ".\rtl\xtensa-freertos\" not found
  8. Compiler: C:\source\fpc\compiler\ppcrossxtensa.exe
  9. Using executable path: C:\source\fpc\compiler\
  10. Using unit path: .\rtl\units\xtensa-freertos\
  11. Using unit path: .\compiler\
  12. Using library path: C:\Users\Wes\esp\xtensa-esp32-elf-libs\
  13. Using library path: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\
  14. Using library path: .\rtl\units\xtensa-freertos\
  15. Using library path: .\compiler\
  16. Using object path: .\rtl\units\xtensa-freertos\
  17. Using object path: .\compiler\
  18. Searching file hello.pp... found
  19. Unitsearch: system.ppu
  20. Unitsearch: system.pp
  21. Unitsearch: system.pas
  22. Unitsearch: .\rtl\units\xtensa-freertos\system.ppu
  23. PPU Loading .\rtl\units\xtensa-freertos\system.ppu
  24. Searching file hello.pp... found
  25. Searching file hello.pp... found
  26. Unitsearch: ESP32.ppu
  27. Unitsearch: ESP32.pp
  28. Unitsearch: ESP32.pas
  29. Unitsearch: .\rtl\units\xtensa-freertos\ESP32.ppu
  30. PPU Loading .\rtl\units\xtensa-freertos\esp32.ppu
  31. Unitsearch: consoleio.ppu
  32. Unitsearch: consoleio.pp
  33. Unitsearch: consoleio.pas
  34. Unitsearch: .\rtl\units\xtensa-freertos\consoleio.ppu
  35. PPU Loading .\rtl\units\xtensa-freertos\consoleio.ppu
  36. Unitsearch: heapmgr.ppu
  37. Unitsearch: heapmgr.pp
  38. Unitsearch: heapmgr.pas
  39. Unitsearch: .\rtl\units\xtensa-freertos\heapmgr.ppu
  40. PPU Loading .\rtl\units\xtensa-freertos\heapmgr.ppu
  41. Searching file hello.pp... found
  42. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe... found
  43. Using assembler: C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe
  44. Searching file hello.o... found
  45. Searching file .\rtl\units\xtensa-freertos\system.o... found
  46. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  47. Searching file libesp32.a... not found
  48. Searching file libesp32.a... not found
  49. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  50. Searching file libsoc.a... not found
  51. Searching file libsoc.a... not found
  52. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  53. Searching file libdriver.a... not found
  54. Searching file libdriver.a... not found
  55. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  56. Searching file libfreertos.a... not found
  57. Searching file libfreertos.a... not found
  58. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  59. Searching file liblog.a... not found
  60. Searching file liblog.a... not found
  61. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  62. Searching file libesp_common.a... not found
  63. Searching file libesp_common.a... not found
  64. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  65. Searching file libheap.a... not found
  66. Searching file libheap.a... not found
  67. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  68. Searching file libnewlib.a... not found
  69. Searching file libnewlib.a... not found
  70. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  71. Searching file libvfs.a... not found
  72. Searching file libvfs.a... not found
  73. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  74. Searching file libesp_ringbuf.a... not found
  75. Searching file libesp_ringbuf.a... not found
  76. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  77. Searching file libspi_flash.a... not found
  78. Searching file libspi_flash.a... not found
  79. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  80. Searching file libapp_update.a... not found
  81. Searching file libapp_update.a... not found
  82. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  83. Searching file libxtensa.a... not found
  84. Searching file libxtensa.a... not found
  85. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  86. Searching file libbootloader_support.a... not found
  87. Searching file libbootloader_support.a... not found
  88. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... not found
  89. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\libbootloader_support.a... not found
  90. Searching file .\rtl\units\xtensa-freertos\libbootloader_support.a... not found
  91. Searching file .\compiler\libbootloader_support.a... not found
  92. Searching file C:\source\fpc\compiler\libbootloader_support.a... not found
  93. Searching file libpthread.a... not found
  94. Searching file libpthread.a... not found
  95. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  96. Searching file libhal.a... not found
  97. Searching file libhal.a... not found
  98. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  99. Searching file libm.a... not found
  100. Searching file libm.a... not found
  101. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  102. Searching file libg.a... not found
  103. Searching file libg.a... not found
  104. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  105. Searching file libc.a... not found
  106. Searching file libc.a... not found
  107. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  108. Searching file libesp_event.a... not found
  109. Searching file libesp_event.a... not found
  110. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  111. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  112. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  113. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp32.a... found
  114. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libsoc.a... found
  115. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libdriver.a... found
  116. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libfreertos.a... found
  117. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\liblog.a... found
  118. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_common.a... found
  119. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libheap.a... found
  120. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libnewlib.a... found
  121. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libvfs.a... found
  122. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_ringbuf.a... found
  123. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libspi_flash.a... found
  124. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libapp_update.a... found
  125. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libxtensa.a... found
  126. Searching file libbootloader_support.a... not found
  127. Searching file libbootloader_support.a... not found
  128. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libbootloader_support.a... not found
  129. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\xtensa-esp32-elf\lib\libbootloader_support.a... not found
  130. Searching file .\rtl\units\xtensa-freertos\libbootloader_support.a... not found
  131. Searching file .\compiler\libbootloader_support.a... not found
  132. Searching file C:\source\fpc\compiler\libbootloader_support.a... not found
  133. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libpthread.a... found
  134. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libhal.a... found
  135. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libm.a... found
  136. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libg.a... found
  137. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libc.a... found
  138. Searching file C:\Users\Wes\esp\xtensa-esp32-elf-libs\libesp_event.a... found
  139. C:\Users\Wes\esp\esp-idf-4.0/tools/ldgen/ldgen.py
  140. --config sdkconfig --fragments C:\Users\Wes\esp\esp-idf-4.0/components/xtensa/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/soc/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_event/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/spi_flash/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_wifi/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/lwip/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/heap/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_ringbuf/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/espcoredump/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp32/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32_fragments.lf C:\Users\Wes\esp\esp-idf-4.0/components/freertos/linker.lf C:\Users\Wes\esp\esp-idf-4.0/components/newlib/newlib.lf C:\Users\Wes\esp\esp-idf-4.0/components/esp_gdbstub/linker.lf --input C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32.project.ld.in --output ./esp32.project.ld --kconfig C:\Users\Wes\esp\esp-idf-4.0/Kconfig --env-file config.env --libraries-file ldgen_libraries --objdump xtensa-esp32-elf-objdump
  141. hello.pp(19,27) Error: Can't call the linker, switching to external linking
  142. hello.pp(19,27) Error: Error while linking
  143. Searching file hello.o... found
  144. Searching file hello.o... found
  145. Searching file .\rtl\units\xtensa-freertos\system.o... found
  146. Searching file .\rtl\units\xtensa-freertos\system.o... found
  147. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  148. Searching file .\rtl\units\xtensa-freertos\esp32.o... found
  149. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  150. Searching file .\rtl\units\xtensa-freertos\consoleio.o... found
  151. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  152. Searching file .\rtl\units\xtensa-freertos\heapmgr.o... found
  153. Searching file C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe... found
  154. Using util C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
  155. C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-ld.exe
  156. -g     --gc-sections   -L. -o hello.elf -T link12040.res -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -u esp_app_desc -u vfs_include_syscalls_impl -u pthread_include_pthread_impl -u pthread_include_pthread_cond_impl -u pthread_include_pthread_local_storage_impl -u newlib_include_locks_impl -u newlib_include_heap_impl -u newlib_include_syscalls_impl -u newlib_include_pthread_impl -u app_main -u uxTopUsedPriority -L C:\Users\Wes\esp\esp-idf-4.0/components/esp_rom/esp32/ld -T esp32.rom.ld -T esp32.rom.libgcc.ld -T esp32.rom.newlib-data.ld -T esp32.rom.syscalls.ld -T esp32.rom.newlib-funcs.ld -L . -T esp32_out.ld -T esp32.project.ld -L C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld -T esp32.peripherals.ld
  157. FALSE
  158. hello.pp(19,27) Fatal: There were 2 errors compiling module, stopping
  159. Fatal: Compilation aborted

Running with the -sh options produces the following ppas.bat (and the cmd window output is similar to above, but ends with TRUE):
Code: Text  [Select][+][-]
  1. @echo off
  2. SET THEFILE=hello
  3. echo Assembling %THEFILE%
  4. C:\Users\Wes\.espressif\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-as.exe -o hello.o  hello.s --longcalls
  5. if errorlevel 1 goto asmend
  6. Del hello.s
  7. SET THEFILE=hello
  8. echo Linking %THEFILE%
  9. xtensa-esp32-elf-gcc -C -P -x c -E -o esp32_out.ld -I . C:\Users\Wes\esp\esp-idf-4.0/components/esp32/ld/esp32.ld
  10. if errorlevel 1 goto linkend
  11. SET THEFILE=hello
  12. echo Linking %THEFILE%
  13. C:\Users\Wes\esp\esp-idf-4.0/components/esptool_py/esptool/esptool.py --chip esp32 elf2image --flash_mode dio --flash_freq 40m --flash_size 2MB --elf-sha256-offset 0xb0 -o hello.bin hello.elf
  14. if errorlevel 1 goto linkend
  15. goto end
  16. :asmend
  17. echo An error occurred while assembling %THEFILE%
  18. goto end
  19. :linkend
  20. echo An error occurred while linking %THEFILE%
  21. :end
  22.  

Running ppas.bat results in
Code: Text  [Select][+][-]
  1. FileNotFoundError: [Errno 2] No such file or directory: 'hello.elf'
(because it is not being made)

Noting that the wiki advises "So far Linux and Mac hosts only" I then decided to try it via WSL (Ubuntu 18.04) and started from scratch.  I've now been able to get helloworld to run on an ESP32 board (after reducing the flash baud rate) by running from Linux :D.

By the way, a couple of recommended changes for the wiki:
- find ~/esp/esp-idf/components -name "*.a" -exec cp {} ~/esp/xtensa-esp32-elf-libs \;
- for the ESP32:
     make FPC=fpc CPU_TARGET=xtensa OS_TARGET=freertos SUBARCH=lx6 "CROSSOPT=-Cplx6 -XPxtensa-esp32-elf- -Cfhard" all -j

MiR

  • Full Member
  • ***
  • Posts: 206
Re: Problem linking for Xtensa (ESP32)
« Reply #19 on: May 10, 2020, 08:23:30 am »
Seems you are ready for level two  8) , have a look here:

https://github.com/ccrause/fpc-esp-freertos

Michael

electronickiwi

  • New member
  • *
  • Posts: 8
Re: Problem linking for Xtensa (ESP32)
« Reply #20 on: May 10, 2020, 08:41:48 am »
Already there!  ;)  Have successfully run your blink example.  Have updated esp-idf to release v4.1-beta to hopefully be on the same basis as you.

Looking at some of your other examples to get my pascal knowledge refreshed.  I ran into an issue with the compiler not recognising "result", but fixed that with {$mode objfpc}{$H+} added to the program.

Have currently got a problem compiling wifiscan and the other more involved examples that call the esp-idf functions - I think I just need to get all the right paths added to the includes in the command line.  Will let you know how I get on.

MiR

  • Full Member
  • ***
  • Posts: 206
Re: Problem linking for Xtensa (ESP32)
« Reply #21 on: May 10, 2020, 08:46:54 am »
fpc-esp-freertos is not my work, it is work of ccrause, I am mostly working on freertos for arm processors but I also have esp32 in mind when doing this.

This is my project:

https://github.com/michael-ring/mbf-freertos

Michael

electronickiwi

  • New member
  • *
  • Posts: 8
Re: Problem linking for Xtensa (ESP32)
« Reply #22 on: May 10, 2020, 09:38:20 am »
Hi Michael

Sorry for the mix-up, and thanks for the link, and the earlier help.

Wes

PascalDragon

  • Hero Member
  • *****
  • Posts: 3492
  • Compiler Developer
Re: Problem linking for Xtensa (ESP32)
« Reply #23 on: May 10, 2020, 04:38:42 pm »
Quote
only that it can't call the (internal?) linker, and switches to the external linker, which has an error.
That it tries the internal linker first should afaik not happen.

That is in fact a misleading error message by the compiler, cause it prints this if any linker failed, no matter if it was the internal one or not :-[

.py's don't execute on Windows without being prefixed by the interpreter ?

Well, the link script posted by electronickiwi contained a direct call to esptool.py as well and executing it resulted in a call trace inside the Python call, so apparently that does worked correctly.

peter@jazenga.com

  • Newbie
  • Posts: 4
Re: Problem linking for Xtensa (ESP32)
« Reply #24 on: October 04, 2020, 01:36:02 pm »
It would be very helpful if someone could share a working fpc.cfg file for xtensa (ESP32)
I have both Linux and Windows 10 but so far no success due to missing xtensa tools however they are on the system
I am unfamiliar with cross compilation for embedded & RTOS so I don't really know how to create the config or where to place the executable files

ccrause

  • Sr. Member
  • ****
  • Posts: 480
Re: Problem linking for Xtensa (ESP32)
« Reply #25 on: October 04, 2020, 02:49:44 pm »
It would be very helpful if someone could share a working fpc.cfg file for xtensa (ESP32)
I have both Linux and Windows 10 but so far no success due to missing xtensa tools however they are on the system
I am unfamiliar with cross compilation for embedded & RTOS so I don't really know how to create the config or where to place the executable files

Are you trying to compile for embedded or freertos target?  Embedded should be easier to set up, but then you have to write quite a bit of code to configure the cores, set up interrupt handlers, memory manager etc.  FreeRTOS target perform all the configuration of the processors, but linking to the SDK is a little bit more tricky (but the required steps are documented in the wiki).

Post the specific compiler errors you encountered.
How are you creating the cross compiler? Using make, or install with fpcupdeluxe? If using make, please show the full command line you used.
Are the cross tools (e.g. xtensa-esp32-elf-ld on Linux) in the path or not? If not pass the location to these utilities to the compiler using the -FD option.

 

TinyPortal © 2005-2018