pine64 / bl_iot_sdk

BL602 SDK (Pine64 fork)
https://pine64.github.io/bl602-docs/
Apache License 2.0
134 stars 58 forks source link

Compiling issue in linux #81

Open bat52 opened 3 years ago

bat52 commented 3 years ago

Compiling on my ubuntu 20.04 fails. It seems the components are compiled correctly, but the main is not compiled, nor found by the linker. See the error below.

marco@Latitude-E6440:/media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi$ make use existing version.txt file LD build_out/bl602_demo_wifi.elf /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o: in function.L0 ': (.text+0x2e): undefined reference to main' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1

robertlipe commented 3 years ago

Missing main is a symptom, not the problem. The linker is being invoked to build an rv64 executable when this is an rv32 system. (It's confusing because the entire chain is called "riscv64" but the flags should be setting flags to build and link in 32-bit mode. The hint is the "...lib/rv64imacfd" part of the pathname.

run make V=1 and show us the lines leading up to that linker invocation. It will be called by collect2 which is called by the gcc front-end.

Do you have any environmental variables like CFLAGs or LDFLAGS that are polluting the build environment?

Do other directories build successfully for you?

Actually, I'm seeing that directory fail to build for a different reason, but the failure is ignored (!) and is covered up in the avalanche of jibber jabber of unnecessary recompilation (!!). But the invocation that matches what I think is failing for you starts:

riscv64-unknown-elf-gcc -march=rv32imfc -mabi=ilp32f -Wl,--cref -nostartfiles -Wl,--gc-sections -Wl,-static -Wl,--start-gr [ ... ]

Your failure is about what I'd expect if the -march -mabi flags were missing.

gamelaster commented 3 years ago

Also, it's known that some examples are not possible to compile, although this one if I remember correctly should work fine.

bat52 commented 3 years ago

Thank you for the quick reply. I found that indeed I had the LDFLAGS set, therefore after doing unset LDFLAGS the bl602_boot2 compiled flawlessly.

However, when going to the bl602_demo_wifi it still does not compile, with following errors

'make V=1 ... /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_api.o): in function cfg_api_element_set': /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to_ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:164: undefined reference to_ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:167: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_task.o): in functiondump_cfg_entries': /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:28: undefined reference to_ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:27: undefined reference to_ld_bl_static_cfg_entry_end' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1 '

robertlipe commented 3 years ago

Awesome. Glad we got that fixed without a lot of pain.

That failure is due to missing pieces within the blob of the wifi trying to use symbols that aren't provided by flash.ld. I get the exact failures on my system. I took the problem to the developer chat room last night about 3am and haven't heard back yet. My guess is that it falls into what Marek is describing: a code block that just doesn't work.

We've thus solved the original problem. The ability to build bl602_demo_wifi is a different problem and it's not solved. I don't know if people will scroll back in the IRC thing to read my description when they awaken, but that's where I took the conversation.

On Wed, Nov 25, 2020 at 2:20 AM Marco Merlin notifications@github.com wrote:

Thank you for the quick reply. I found that indeed I had the LDFLAGS set, therefore after doing unset LDFLAGS the bl602_boot2 compiled flawlessly.

However, when going to the bl602_demo_wifi it still does not compile, with following errors

'make V=1 ... /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_api.o): in function cfg_api_element_set': /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:91: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:164: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_api.c:167: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/components/bl602/bl602_wifi/lib/libbl602_wifi.a(cfg_task.o): in function dump_cfg_entries': /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:28: undefined reference to _ld_bl_static_cfg_entry_end' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:24: undefined reference to _ld_bl_static_cfg_entry_start' /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /home/rjwang/work/bl_iot_sdk.release/components/bl602/bl602_wifi/ip/cfg/cfg_task.c:27: undefined reference to _ld_bl_static_cfg_entry_end' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/ project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1 '

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pine64/bl_iot_sdk/issues/81#issuecomment-733544988, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCSD3ZB23UO3AT43LU6VC3SRS45LANCNFSM4UBPSFVA .

bat52 commented 3 years ago

Thank you Robert for your help and comment. Do you mean that this example does not work even in the original SDK ?

robertlipe commented 3 years ago

Correct. See my (lonely) conversation on matrix.io from maybe six or seven hours ago.

I didn't loop backward to see how long this failure has existed. libbl602_wifi.a(cfg_task.o) inside the binary blob is linking against those symbols and they don't exist. Similar symbols are provided by the flash.ld script, but this app doesn't link because nothing provides those symbols. It looks to be configuration data (something like a compiled foo.ini tree) that the WiFi module is wanting, but isn't finding it. Those symbols don't appear in the source tree that I can find.

On Wed, Nov 25, 2020 at 9:15 AM Marco Merlin notifications@github.com wrote:

Thank you Robert for your help and comment. Do you mean that this example does not work even in the original SDK ?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pine64/bl_iot_sdk/issues/81#issuecomment-733767680, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCSD37Z2NKVVGVQPO5ICQDSRUNPRANCNFSM4UBPSFVA .

robertlipe commented 3 years ago

I just pulled the Boufallou tree and tried to build demo_wifi. It fails in almost the same way[1].

I then did a git checkout ee4a10b1a1e3609243bd5e7b3a45f02d768f6c14 to revert to their first public release and it failed in the identical way.

I have no reason to think this is a Mac-only thing (wait, @bat52 is on Linux) but it's my suspicion this directory has never built in a publicly released version.

As an aside, @bat52, do I know you with a slightly different name?

[1] Why "almost"? Because Bouffalo accepted a commit today that broke the tree in a slightly overlapping way. :-/ See https://github.com/bouffalolab/bl_iot_sdk/issues/18. It's awesome debugging two trees that are broken in three different ways.

bat52 commented 3 years ago

Thank you for your comments @robertlipe !

> As an aside, @bat52, do I know you with a slightly different name? I do not think I have ever known you before this discussion... but nice to meet you! :-)

gamelaster commented 3 years ago

"_ld_bl_static_cfg_entry_start" happens when you compile without CONFIG_LINK_ROM=1

bat52 commented 3 years ago

Thank you for the comment @gamelaster. I have tried compiling again after calling

export CONFIG_LINK_ROM=1

but I still get the linker error below. What am I doing wrong?

marco@Latitude-E6440:/media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi$ make CONFIG_LINK_ROM=1 use existing version.txt file LD build_out/bl602_demo_wifi.elf /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/bin/ld: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/toolchain/riscv/Linux/bin/../lib/gcc/riscv64-unknown-elf/8.3.0/../../../../riscv64-unknown-elf/lib/rv64imafdc/lp64d/crt0.o: in function.L0 ': (.text+0x2e): undefined reference to main' collect2: error: ld returned 1 exit status make: *** [/media/marco/DATA/programming/riscv/bl_iot_sdk-master/make_scripts_riscv/project.mk:420: /media/marco/DATA/programming/riscv/bl_iot_sdk-master/customer_app/bl602_demo_wifi/build_out/bl602_demo_wifi.elf] Errore 1

gamelaster commented 3 years ago

Hi @bat52 Did you cleaned the project before compiling?

bat52 commented 3 years ago

yes i did!

Il sab 28 nov 2020, 20:25 Marek Kraus notifications@github.com ha scritto:

Hi @bat52 https://github.com/bat52 Did you cleaned the project before compiling?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/pine64/bl_iot_sdk/issues/81#issuecomment-735279873, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALPNWJOMIDKMUYX54QYCC3SSFFDJANCNFSM4UBPSFVA .

suculent commented 3 years ago

I've stumbled upon the same issue on MacOS as well, @bat52. Make sure to make clean after changing the CONFIG_LINK_ROM variable.

  1. My build returned same error, verified that CPPFLAGS and LDFLAGS are clean.
  2. I've set the export CONFIG_LINK_ROM=1 but forgot to clean!
  3. Build returned same error. 4.make clean && export CONFIG_LINK_ROM=1 && ./genromap and voilá it works.
bat52 commented 3 years ago

thank you @suculent , it ended up working as you said. It was not clear to me I should have used genromap, and indeed I had LDFLAGS still defined in my environment. cheers!