ARMmbed / mbed-tools

⚠️ Beta Status: New command line tooling for Mbed OS
Apache License 2.0
45 stars 30 forks source link

POST_APPLICATION_ADDR macro for bootloader is not defined #315

Open reiniercoetzer opened 3 years ago

reiniercoetzer commented 3 years ago

Describe the bug Hi Mbed team, @ladislas @Patater ,

We are using Mbed-OS 6.14 with Mbed-CLI2 and CMake to port a bootloader for our custom target.

In “target_overrides” we are simply using “target.restrict_size”: “0x20000” to basically use the managed bootloader. However, when we are compiling the bootloader application, it seems as though the POST_APPLICATION_ADDR macro is not being defined.

I followed this guide to port a custom target using Mbed-CLI2: Porting custom boards - Porting | Mbed OS 6 Documentation Could you maybe give some pointers as to why this is happening?

To Reproduce Our custom_targets.json:

{
    "TS_PHOENIX": {
        "inherits": [
            "MCU_STM32WB55xG"
        ],
        "components_add": [
            "SPIF", "FLASH", "FLASHIAP"
        ],
        "detect_code": [
            "0839"
        ],
        "device_name": "STM32WB55RGVx",
        "config": {
            "update_file_name": {
                "help": "Value: Defines the update filename which is expected by the bootloader.",
                "value": "\"ts.bin\"",
                "macro_name": "TS_UPDATE_FILE_NAME"
            }
        }
    }

}

Our mbed_app.json:

{
    "target_overrides": {
        "*": {
            "target.restrict_size": "0x20000",
            "target.macros_add": ["NDEBUG=1"],
            "platform.stdio-flush-at-exit": false
        },
        "TS_PHOENIX": {
            "target.macros_add": ["TS_UPDATE_FILE_NAME=\"ts.bin\""],
            "spif-driver.SPI_CLK": "SPI_FLASH_SCK",
            "spif-driver.SPI_CS": "SPI_FLASH_CS",
            "spif-driver.SPI_MOSI": "SPI_FLASH_MOSI",
            "spif-driver.SPI_MISO": "SPI_FLASH_MISO"
        }
    }
}

Top-level CMakeLists.txt

cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)

set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "")
set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "")
set(APP_TARGET VOYAGER-PHOENIX-BL)

include(${MBED_PATH}/tools/cmake/app.cmake)

add_subdirectory(${MBED_PATH})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/TARGET_TS_PHOENIX)

add_executable(${APP_TARGET})

mbed_configure_app_target(${APP_TARGET})

project(${APP_TARGET})

target_sources(${APP_TARGET}
    PRIVATE
        main.cpp
)

target_include_directories(${APP_TARGET}
    PUBLIC
        .
)

target_link_libraries(${APP_TARGET}
    PRIVATE
        mbed-os
        mbed-core
        mbed-stm
        mbed-stm32wb
        mbed-ts-phoenix
        mbed-storage
)

mbed_set_post_build(${APP_TARGET})

option(VERBOSE_BUILD "Have a verbose build process")
if(VERBOSE_BUILD)
    set(CMAKE_VERBOSE_MAKEFILE ON)
endif()

Custom target CMakeListst.txt (based on the mbed-stm32wb55xg):

add_library(mbed-toolsense-phoenix INTERFACE)

target_sources(mbed-toolsense-phoenix
    INTERFACE
        PeripheralPins.c
        system_clock.c
)

target_include_directories(mbed-toolsense-phoenix
    INTERFACE
        .
)

target_link_libraries(mbed-toolsense-phoenix INTERFACE mbed-stm32wb55xg)

Compiling command line:

mbed-tools compile -m TS_PHOENIX -t GCC_ARM

And the last output from the build:

...
X-BL.dir/main.cpp.obj.d -o CMakeFiles/VOYAGER-PHOENIX-BL.dir/main.cpp.obj -c ../../../../main.cpp
../../../../main.cpp: In function 'int main()':
../../../../main.cpp:28:28: error: 'POST_APPLICATION_ADDR' was not declared in this scope
   28 |     mbed_start_application(POST_APPLICATION_ADDR);
      |                            ^~~~~~~~~~~~~~~~~~~~~
../../../../main.cpp: In function 'bool update(const char*)':
../../../../main.cpp:37:28: error: 'POST_APPLICATION_ADDR' was not declared in this scope
   37 |         apply_update(file, POST_APPLICATION_ADDR);
      |                            ^~~~~~~~~~~~~~~~~~~~~

Why is the macro not being defined?

Expected behavior The simple bootloader application builds and POST_APPLICATION_ADDR=0x8020000

Desktop (please complete the following information):

Mbed (please complete the following information):

Additional context Add any other context about the problem here.

LDong-Arm commented 3 years ago

Hi @reiniercoetzer, thanks for raising this issue. Macros for bootloader support are not currently generated, and the main issue is tracked in #156.