ARMmbed / ARMmbed/mbed-tools

POST_APPLICATION_ADDR macro for bootloader is not defined

Open
#315 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
49
Forks
32
PR merge metrics
No merged PRs in 30d

Description

**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
](https://os.mbed.com/docs/mbed-os/v6.14/porting/porting-custom-boards.html)
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):**
- OS: Ubuntu
- Version: 20.04.2

**Mbed (please complete the following information):**
- Device: custom board based on STM32WB55xG
- Mbed OS Version: 6.14.0
- Mbed CLI 2 Version: 7.34.0

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Start with custom_targets.json, mbed_app.json, the top-level CMakeLists.txt, and the custom target CMakeLists.txt. Run the shown mbed-tools compile command and trace mbed_configure_app_target and mbed_set_post_build to determine why target.restrict_size does not produce POST_APPLICATION_ADDR; done means the bootloader builds with POST_APPLICATION_ADDR defined as 0x8020000.

Written by the indexing model from the issue text.

Assessment

Tech stack
cmake, cpp
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.