Linker error when trying to build P1 system modules on 0.7.0 [Solved]

I’m trying to build the system modules with JTAG support to be able to debug WiFi connectivity issues. I would like to connect the debugger and step debug with eclipse. I’ll leave the P1 running until it disconnects from WiFi, which I can see on the display, which tells me that WiFi.ready() returns false and IP is 0.0.0.0. At this point I’d like to break and see why the connection is not restored.

To be able to do this, I need to re-compile the system modules with JTAG support, instead of using the system binaries provided by Particle. I get a linker error for SRAM overlow though.

I’m using:

  • arm-none-eabi-gcc version 2016-q3 (5.4.1) on Ubuntu 17.
  • Build command in modules dir: make clean all program-dfu PLATFORM=P1 PARTICLE_DEVELOP=y USE_SWD_JTAG=y DEBUG_BUILD=y
  • make 3.81 or 4.1 with same result

See error below. Building without JTAG support results in the same error.
Obviously, you can build the system modules at Particle just fine, so the difference must be in the build system. What should I change?

Invoking: ARM GCC C++ Linker
mkdir -p ../../../build/target/system-part1/platform-8-m/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=8 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD008 -DUSBD_PID_CDC=0xC008 -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DPRODUCT_ID=8 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -fno-builtin -DSYSTEM_VERSION_STRING=0.7.0-rc.3 -DRELEASE_BUILD -Werror -I../../../modules/photon/system-part1/inc -I../../../modules/shared/stm32f2xx/inc -I../../../communication/src -I../../../services/inc -I../../../platform/shared/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../../../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../../../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../../../platform/MCU/shared/STM32/inc -I../../../platform/MCU/STM32F2xx/CMSIS/Include -I../../../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../../../hal/inc -I../../../hal/shared -I../../../hal/src/photon -I../../../hal/src/stm32f2xx -I../../../hal/src/stm32 -I../../../hal/src/photon/api -I../../../hal/src/photon/include -I../../../hal/src/photon/wiced/security/BESL/host/WICED/ -I../../../hal/src/photon/wiced/security/BESL/include -I../../../hal/src/photon/wiced/security/BESL -I../../../hal/src/photon/wiced/security/BESL/crypto -I../../../hal/src/photon/wiced/WWD/include/ -I../../../hal/src/photon/wiced/platform/include/ -I../../../hal/src/photon/wiced/platform/GCC/ -I../../../hal/src/photon/wiced/security/BESL/supplicant/ -I../../../hal/src/photon/libraries/crypto -I../../../crypto/mbedtls/include -I../../../crypto/inc -I../../../dynalib/inc -I../../../rt-dynalib/inc -I. -MD -MP -MF ../../../build/target/system-part1/platform-8-m/system-part1.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0x80A0000 -DMODULAR_FIRMWARE=1 -DCRYPTO_PART1_SIZE_OPTIMIZATIONS -DMODULE_VERSION=202 -DMODULE_FUNCTION=4 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/module_system_part1.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/wiced_stubs.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/init_dynalib.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/crypto_dynalib.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/module_info.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/import_rt.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/wifi_dynalib.o ../../../build/target/system-part1/platform-8-m/../../../modules/photon/system-part1/src/newlib.o  --output ../../../build/target/system-part1/platform-8-m/system-part1.elf -nostartfiles -Xlinker --gc-sections -L../../../build/arm/linker/stm32f2xx  -L../../../build/target/communication/platform-8-m-prod-8/ -L../../../build/target/hal-dynalib/platform-8-m/ -L../../../build/target/services/platform-8-m/ -L../../../build/target/platform/platform-8-m/ -L../../../build/target/crypto/platform-8-m/ -L../../../build/arm/linker -Wl,--whole-archive -lcommunication -lhal-dynalib -lservices -lplatform -lcrypto -Wl,--no-whole-archive --specs=nano.specs -lnosys ../../../hal/src/photon/lib/resources.a ../../../build/target/hal/platform-8-m/src/photon/resources.o -T../../../modules/photon/system-part1/linker.ld -L../../../modules/photon/system-part2 -Wl,--defsym,PLATFORM_DFU=0x8020000 -Wl,-Map,../../../build/target/system-part1/platform-8-m/system-part1.map
/home/elco/source/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: ../../../build/target/system-part1/platform-8-m/system-part1.elf section `.bss' will not fit in region `SRAM'
../../../build/module.mk:222: recipe for target '../../../build/target/system-part1/platform-8-m/system-part1.elf' failed
/home/elco/source/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: static RAM use exceeds allocated space
make[1]: Leaving directory '/home/elco/repos/firmware/platform/spark/firmware/modules/photon/system-part1'
/home/elco/source/gcc-arm-none-eabi-5_4-2016q3/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld: region `SRAM' overflowed by 16 bytes
makefile:85: recipe for target '/home/elco/repos/firmware/platform/spark/firmware/modules/photon/system-part1/makefile' failed
collect2: error: ld returned 1 exit status
make[1]: *** [../../../build/target/system-part1/platform-8-m/system-part1.elf] Error 1
make: *** [/home/elco/repos/firmware/platform/spark/firmware/modules/photon/system-part1/makefile] Error 2

Monolitic build
In an alternative approach, I try to build a monolitic app so I do not need the system modules:

make PLATFORM=P1 USE_SWD_JTAG=y PARTICLE_DEVELOP=y DEBUG_BUILD=y MODULAR=n

But that results in the following linker error:

Building target: /home/elco/repos/firmware/platform/spark/target/controller-P1/firmware.elf
Invoking: ARM GCC C++ Linker
mkdir -p /home/elco/repos/firmware/platform/spark/target/controller-P1/
arm-none-eabi-g++ -DSTM32_DEVICE -DSTM32F2XX -DPLATFORM_THREADING=1 -DPLATFORM_ID=8 -DPLATFORM_NAME=photon -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD008 -DUSBD_PID_CDC=0xC008 -g3 -gdwarf-2 -Os -mcpu=cortex-m3 -mthumb -DINCLUDE_PLATFORM=1 -DPRODUCT_ID=8 -DPRODUCT_FIRMWARE_VERSION=65535 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DUSE_SWD_JTAG -DMBEDTLS_CONFIG_FILE="<mbedtls_config.h>" -DSYSTEM_VERSION_STRING=0.7.0-rc.3 -DDEBUG_BUILD -DSPARK_NO_CLOUD -I../user/inc -I../wiring/inc -I../hal/inc -I../hal/shared -I../hal/src/photon -I../hal/src/stm32f2xx -I../hal/src/stm32 -I../hal/src/photon/api -I../hal/src/photon/include -I../hal/src/photon/wiced/security/BESL/host/WICED/ -I../hal/src/photon/wiced/security/BESL/include -I../hal/src/photon/wiced/security/BESL -I../hal/src/photon/wiced/security/BESL/crypto -I../hal/src/photon/wiced/WWD/include/ -I../hal/src/photon/wiced/platform/include/ -I../hal/src/photon/wiced/platform/GCC/ -I../hal/src/photon/wiced/security/BESL/supplicant/ -I../hal/src/photon/libraries/crypto -I../system/inc -I../services/inc -I../communication/src -I../platform/shared/inc -I../platform/MCU/STM32F2xx/CMSIS/Include -I../platform/MCU/STM32F2xx/CMSIS/Device/ST/Include -I../platform/MCU/STM32F2xx/SPARK_Firmware_Driver/inc -I../platform/MCU/shared/STM32/inc -I../platform/MCU/STM32F2xx/STM32_StdPeriph_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Device_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_Host_Driver/inc -I../platform/MCU/STM32F2xx/STM32_USB_OTG_Driver/inc -I../crypto/inc -I../crypto/mbedtls/include -I../dynalib/inc -I. -MD -MP -MF /home/elco/repos/firmware/platform/spark/target/controller-P1/firmware.elf.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DBOOTLOADER_SDK_3_3_0_PARTICLE -DPARTICLE_DCT_COMPATIBILITY -DMODULE_VERSION=202 -DMODULE_FUNCTION=3 -DMODULE_DEPENDENCY=0,0,0 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE /home/elco/repos/firmware/platform/spark/target/controller-P1/obj/./src/module_info.o   --output /home/elco/repos/firmware/platform/spark/target/controller-P1/firmware.elf -nostartfiles -Xlinker --gc-sections --specs=nano.specs --specs=../newlib_nano/src/custom-nano.specs -Wl,--whole-archive ../hal/src/photon/lib/Lib_SPI_Flash_Library_BCM9WCDUSI14.a ../hal/src/photon/lib/Lib_HTTP_Server.a ../hal/src/photon/lib/Lib_Wiced_RO_FS.a ../hal/src/photon/lib/Lib_base64.a ../hal/src/photon/lib/Lib_Ring_Buffer.a ../hal/src/photon/lib/Lib_TLV.a ../hal/src/photon/lib/STM32F2xx_Peripheral_Libraries.a ../hal/src/photon/lib/common_GCC.a ../hal/src/photon/lib/Lib_Linked_List.a ../hal/src/photon/lib/FreeRTOS/WICED.a ../hal/src/photon/lib/FreeRTOS/Platform_BCM9WCDUSI14.a ../hal/src/photon/lib/FreeRTOS/Lib_DHCP_Server.a ../hal/src/photon/lib/FreeRTOS/Lib_DNS.a ../hal/src/photon/lib/FreeRTOS/Lib_DNS_Redirect_Daemon.a ../hal/src/photon/lib/FreeRTOS/STM32F2xx.a ../hal/src/photon/lib/FreeRTOS/STM32F2xx_Peripheral_Drivers.a ../hal/src/photon/lib/FreeRTOS/FreeRTOS.a ../hal/src/photon/lib/FreeRTOS/LwIP.a ../hal/src/photon/lib/FreeRTOS/WWD_FreeRTOS_Interface_BCM9WCDUSI14.a ../hal/src/photon/lib/FreeRTOS/WICED_FreeRTOS_Interface.a ../hal/src/photon/lib/FreeRTOS/WWD_LwIP_Interface_FreeRTOS.a ../hal/src/photon/lib/FreeRTOS/WICED_LwIP_Interface.a ../hal/src/photon/lib/FreeRTOS/WWD_for_SDIO_FreeRTOS.a ../hal/src/photon/lib/FreeRTOS/Wiced_Network_LwIP_FreeRTOS.a ../hal/src/photon/lib/Supplicant_BESL.a ../hal/src/photon/lib/BESL.ARM_CM3.release.a -Wl,--no-whole-archive -T../hal/src/photon/wiced/platform/MCU/STM32F2xx/GCC/app_no_bootloader.ld -L../build/arm/linker/stm32f2xx -L../hal/src/photon/wiced/platform/MCU/STM32F2xx/GCC/STM32F2x5 -Wl,--defsym,__STACKSIZE__=1400 -Wl,-Map,/home/elco/repos/firmware/platform/spark/target/controller-P1/firmware.map -u uxTopUsedPriority  -L/home/elco/repos/firmware/platform/spark/target/user/platform-8/firmware/ -L/home/elco/repos/firmware/platform/spark/target/wiring/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/system/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/services/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/communication/platform-8-prod-8/ -L/home/elco/repos/firmware/platform/spark/target/hal/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/platform/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/wiring_globals/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/crypto/platform-8/ -L/home/elco/repos/firmware/platform/spark/target/newlib_nano/platform-8 -L../build/arm/linker -Wl,--whole-archive -lnewlib_nano -luser -lwiring -lhal -lsystem -lservices -lcommunication -lplatform -lwiring_globals -lcrypto -Wl,--no-whole-archive
../hal/src/photon/lib/FreeRTOS/WICED_LwIP_Interface.a(wiced_network_common.o): In function `str_to_ip':
/Users/sergey/dev/particle/photon-wiced/WICED/network/LwIP/WICED/../../wiced_network_common.c:429: undefined reference to `__ctype_ptr__'
make[1]: Leaving directory `/home/elco/repos/firmware/platform/spark/firmware/main'
/home/elco/repos/firmware/platform/spark/target/hal/platform-8//libhal.a(heap_4_lock.o):(.data.ucHeapEnd+0x0): undefined reference to `link_heap_location_end'
/home/elco/repos/firmware/platform/spark/target/hal/platform-8//libhal.a(heap_4_lock.o):(.data.ucHeap+0x0): undefined reference to `link_heap_location'
collect2: error: ld returned 1 exit status
make[1]: *** [/home/elco/repos/firmware/platform/spark/target/controller-P1/firmware.elf] Error 1
make: *** [run_make] Error 2

Changed compiler to 0.5.3 (2016q1) and the system modules build succeeds!

I am getting the same error for the monolitic build.

I can now successfully connect to the debug target, so I can proceed to debug. I marked the thread as solved. Hopefully it will help others.

If there is anything you want me to test regarding the WiFi connective issues, let me know.

1 Like

SWD debugging is now working well and reported a WiFi bug here:

I have not found the root cause yet, but I hope it helps you to narrow down the WiFi issue. Maybe this is related to the WiFi instability when compiling with newer versions of gcc.