platformio / platform-siliconlabsefm32

Silicon Labs EFM32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/siliconlabsefm32
Apache License 2.0
5 stars 6 forks source link

Blinky mbed-os firmware does not link for tb_sense_12 board because of ARM library #4

Open maxgerhardt opened 3 years ago

maxgerhardt commented 3 years ago

See https://community.platformio.org/t/silicon-labs-efm32-linker-fail-on-thunderboard-sense-2/18831.

When the example https://github.com/platformio/platform-siliconlabsefm32/tree/develop/examples/mbed-rtos-blink-baremetal

with the platformio.ini

[env:tb_sense_12]
platform = siliconlabsefm32
board = tb_sense_12
framework = mbed

is compiled, one gets

arm-none-eabi-g++ -o .pio\build\tb_sense_12\firmware.elf -T C:\Users\Trevor\Documents\PlatformIO\Projects\Thund_02\.pio\build\tb_sense_12\efr32mg12p.ld.link_script.ld -DMBED_BOOT_STACK_SIZE=1024 -DMBED_RAM_SIZE=0x40000 -DMBED_RAM_START=0x20000000 -DMBED_ROM_SIZE=0x100000 -DMBED_ROM_START=0x0 -DXIP_ENABLE=0 -Wl,--gc-sections -Wl,--wrap,_calloc_r -Wl,--wrap,_free_r -Wl,--wrap,_malloc_r -Wl,--wrap,_memalign_r -Wl,--wrap,_realloc_r -Wl,--wrap,atexit -Wl,--wrap,exit -Wl,--wrap,fprintf -Wl,--wrap,main -Wl,--wrap,printf -Wl,--wrap,snprintf -Wl,--wrap,sprintf -Wl,--wrap,vfprintf -Wl,--wrap,vprintf -Wl,--wrap,vsnprintf -Wl,--wrap,vsprintf -Wl,-n -mcpu=cortex-m4 -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -mthumb @"C:\Users\Trevor\Documents\PlatformIO\Projects\Thund_02\.pio\build\tb_sense_12\longcmd-8c9bf32d6ff45c837f164ee574d2018c" -L.pio\build\tb_sense_12 -LC:\Users\Trevor\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail -LC:\Users\Trevor\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail\TARGET_EFR32_12 -Wl,--start-group -lrail_efr32xg12_release -lrail_efr32xg12_release.ar -lstdc++ -lsupc++ -lm -lc -lgcc -lnosys -lc -lgcc -Wl,--end-group
c:/users/trevor/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld.exe: cannot find -lrail_efr32xg12_release.ar
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\tb_sense_12\firmware.elf] Error 1

The problem is that the buld system tries wants to link two libraries

-lrail_efr32xg12_release -lrail_efr32xg12_release.ar

And it blindly wants to link all *.ar and *.a files in C:\Users\<user>\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\efr32-rf-driver\rail\TARGET_EFR32_12.

But the .ar file is only for ARM compiler toolchain and not GCC-ARM, so the .ar file shouldn't be included in the first place.

The CMakeLists.txt logic doesn't seem to be executed at all to prevent this in C:\Users\<user>\.platformio\packages\framework-mbed\targets\TARGET_Silicon_Labs\TARGET_SL_RAIL\CMakeLists.txt.

# Copyright (c) 2020 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

if("EFR32_12" IN_LIST MBED_TARGET_LABELS)
    if(${MBED_TOOLCHAIN} STREQUAL "ARM")
        set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.ar)
    elseif(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
        set(LIB_RAIL efr32-rf-driver/rail/TARGET_EFR32_12/librail_efr32xg12_release.a)
    endif()
endif()

target_link_libraries(mbed-core INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/${LIB_RAIL})

target_include_directories(mbed-core
    INTERFACE
        efr32-rf-driver/rail
        efr32-rf-driver/rail/ble
        efr32-rf-driver/rail/ieee802154
)

it makes no difference if I also comment out the target_link_libraries line.

A temporary solution is to rename the librail_efr32xg12_release.ar file to something not ending in .ar or .a, e.g. librail_efr32xg12_release.ar.backup, then linking works.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/96354281-blinky-mbed-os-firmware-does-not-link-for-tb_sense_12-board-because-of-arm-library?utm_campaign=plugin&utm_content=tracker%2F38219020&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F38219020&utm_medium=issues&utm_source=github).
giedrius-stanevicius commented 3 years ago

I am not familiar with platformio/mbed build system, but it seems that files:

.platformio
  packages
    framework-mbed
      targets
        TARGET_Silicon_Labs
          TARGET_SL_RAIL
            efr32-rf-driver
              rail
                TARGET_EFR32_12
                  librail_efr32xg12_release.ar
                  librail_efr32xg12_release.a

should be rearranged as:

.platformio
  packages
    framework-mbed
      targets
        TARGET_Silicon_Labs
          TARGET_SL_RAIL
            efr32-rf-driver
              rail
                TARGET_EFR32_12
                  TOOLCHAIN_ARM
                    librail_efr32xg12_release.ar
                  TOOLCHAIN_GCC_ARM
                    librail_efr32xg12_release.a

And this might be mbed, not platformio issue.

giedrius-stanevicius commented 3 years ago

Reported at mbed-os repository: https://github.com/ARMmbed/mbed-os/issues/14958