This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 over the air bootloader with gcc

For my current project, I need to compile the »over the air bootloader« with gcc (because our buildserver runs on linux, developers using Mac … no Windows and no Keil so far).

But unfortunaly, the bootloader example from the sdk (5.1) examples won't compile with gcc. It's missing gcc makefile and even there are at least 2 Keil specific files in the project (arm_startup_nrf51.s and bootloader_util_arm.c).

Could you provide support to help me on this topic?

I'd also checked:- devzone.nordicsemi.com/index.php/nrf51822-bootloader-with-gcc

Parents
  • Hi, thanks for sharing both your codes. I'm working on both OSX and Linux, and I've made some modifications (more or less like the ones made by Nikita) to make the bootloader code compile with gcc. I build the code with the standard gcc configuration (not hlnd/pure-gcc).

    The problem is that using 0x3C000 as BOOTLOADER_REGION_START, with FLASH (rx) : ORIGIN = 0x0003C000, LENGTH = 0x4000 ends with:

    
    _build/dfu_single_bank_ble_s110.out section `.text' will not fit in region `FLASH'
    ...
    ld: region `FLASH' overflowed by 10600 bytes
    
    

    My current Makefile is this:

    
    TARGET_CHIP := NRF51822_QFAA_CA
    BOARD := BOARD_NRF6310
    CFLAGS += -DBLE_STACK_SUPPORT_REQD -DBOOTLOADER_BANKED
    
    SDK_PATH = /opt/nrf51/nrf51_sdk_v5_2_0_39364/nrf51822/
    
    C_SOURCE_FILES = main.c
    C_SOURCE_FILES += bootloader_util_arm.c
    C_SOURCE_FILES += bootloader.c
    C_SOURCE_FILES += dfu_single_bank.c
    C_SOURCE_FILES += dfu_transport_ble.c
    
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/app_timer.c
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/app_scheduler.c
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/app_gpiote.c
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/crc16.c
    C_SOURCE_FILES += $(SDK_PATH)Source/sd_common/softdevice_handler.c
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/pstorage.c
    C_SOURCE_FILES += $(SDK_PATH)Source/app_common/hci_mem_pool.c
    
    C_SOURCE_FILES += $(SDK_PATH)Source/ble/ble_conn_params.c
    C_SOURCE_FILES += $(SDK_PATH)Source/ble/ble_advdata.c
    C_SOURCE_FILES += $(SDK_PATH)Source/ble/ble_services/ble_srv_common.c
    C_SOURCE_FILES += $(SDK_PATH)Source/ble/ble_services/ble_dfu.c
    
    INCLUDEPATHS += -I"../include"
    INCLUDEPATHS += -I"../include/ble_transport"
    INCLUDEPATHS += -I"$(SDK_PATH)Include/ble"
    INCLUDEPATHS += -I"$(SDK_PATH)Include/s110"
    INCLUDEPATHS += -I"$(SDK_PATH)Include/app_common"
    INCLUDEPATHS += -I"$(SDK_PATH)Include/ble/ble_services"
    INCLUDEPATHS += -I"$(SDK_PATH)Include/sd_common"
    
    OUTPUT_FILENAME := dfu_single_bank_ble_s110
    
    # Use custom linker script
    LINKER_SCRIPT := gcc_nrf51_s110_xxaa_bl.ld
    
    CFLAGS += -Os -flto -ffunction-sections -fdata-sections -fno-builtin
    LDFLAGS += --specs=nano.specs -lc -lnosys -Wl,--gc-sections
    
    include $(SDK_PATH)Source/templates/gcc/Makefile.common
    
    

    Have you experienced these problems with executable size when dealing with bootloader code at 0x3C000? Are there any compiler settings to set to reduce code size to fit at 0x3C000?

    Thanks for any help.

    Samuele.

  • About codesize:

    • Your CFLAGS+=-Os is ignored because the Sdk Makefile.common sets CFLAGS+=-O0 for debug target and CFLAGS+=-O3 for release target. You could either patch that away from the Sdk Makefile.common or hack it using INCLUDEPATHS+=-Os (see the gcc/Makefile in my attached BleblGcc-V2.zip above).
    • Your -ffunction-sections etc. is counterproductive if you have no unused functions. In this case -ffunction-sections will blow your binary size a bit up.
    • Which gcc version are you using? I tried gcc 4.7.4 and 4.8.3 and investigeted a slightly smaller codesize when using 4.8.3.
    • I worked the above solution (accepted answer) by using Sdk 5.1.0 and the bootloader matches to 15k (+1k flash for persistent data).

    About linkerscript: Your "FLASH (rx) : ORIGIN = 0x0003C000, LENGTH = 0x4000" is wrong. You have to reserve the last page (1k) for the bootloader's persistent data. So you have to configure e.g. "FLASH (rx) : ORIGIN = 0x0003C000, LENGTH = 0x3C00" instead, what gives you 15k for your bin file (code & const data).

    About bin versus hex: Unfortunately, the JLinkExe won't accept hex files and nrfjprog is not available for Linux (and maybe also not for Mac, isn't it?). That's why I have to use bin files for Jtag flashing.

Reply
  • About codesize:

    • Your CFLAGS+=-Os is ignored because the Sdk Makefile.common sets CFLAGS+=-O0 for debug target and CFLAGS+=-O3 for release target. You could either patch that away from the Sdk Makefile.common or hack it using INCLUDEPATHS+=-Os (see the gcc/Makefile in my attached BleblGcc-V2.zip above).
    • Your -ffunction-sections etc. is counterproductive if you have no unused functions. In this case -ffunction-sections will blow your binary size a bit up.
    • Which gcc version are you using? I tried gcc 4.7.4 and 4.8.3 and investigeted a slightly smaller codesize when using 4.8.3.
    • I worked the above solution (accepted answer) by using Sdk 5.1.0 and the bootloader matches to 15k (+1k flash for persistent data).

    About linkerscript: Your "FLASH (rx) : ORIGIN = 0x0003C000, LENGTH = 0x4000" is wrong. You have to reserve the last page (1k) for the bootloader's persistent data. So you have to configure e.g. "FLASH (rx) : ORIGIN = 0x0003C000, LENGTH = 0x3C00" instead, what gives you 15k for your bin file (code & const data).

    About bin versus hex: Unfortunately, the JLinkExe won't accept hex files and nrfjprog is not available for Linux (and maybe also not for Mac, isn't it?). That's why I have to use bin files for Jtag flashing.

Children
No Data
Related