mirror of https://github.com/ARMmbed/mbed-os.git
Don't use whole-archive linking (#71)
* First attempt at converting to OBJECT libraries. Not working due to more object library limitations * Only compile the main libraries as OBJECT, because that's all that CMake can be made to do right now. * Fix availability of target-specific flags * Missed some usages * Fix some STM32 ethernet stuff that was not linking correctly * More fixes for STM32 ethernet and weak symbols * Fix prebuilt object file linking for MUSCA_S1 * Fix STM32 eth init license headerspull/15339/head
parent
b90b13bd10
commit
ce093f1785
|
@ -264,23 +264,20 @@ add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
|
|||
# Create top-level targets ----------------------------------------------------------------------------------
|
||||
|
||||
if(NOT MBED_IS_NATIVE_BUILD)
|
||||
|
||||
# Create a distro for the microcontroller cmake target, ensuring its sources are only compiled once
|
||||
mbed_create_distro(${MBED_TARGET_CMAKE_NAME}-lib ${MBED_TARGET_CMAKE_NAME} mbed-core-flags)
|
||||
|
||||
# Set up the linker script and hook it up to the MCU cmake target
|
||||
mbed_setup_linker_script(${MBED_TARGET_CMAKE_NAME}-lib)
|
||||
|
||||
# Now make the Mbed OS code depend on the target, ensuring everything has access to the uC's flags and objects.
|
||||
target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-lib)
|
||||
|
||||
# Core Mbed OS libraries
|
||||
# mbed-baremetal contains baremetal sources + target sources + target compile flags.
|
||||
# mbed-os will be a superset of mbed-baremetal, also containing the RTOS sources and RTOS flags.
|
||||
# Note that many different source files will compile differently depending on if the RTOS is in use.
|
||||
# So, it's needed to compile the core sources twice, once for RTOS and once for non-RTOS.
|
||||
mbed_create_distro(mbed-baremetal mbed-core-flags mbed-core-sources)
|
||||
mbed_create_distro(mbed-os mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
|
||||
mbed_create_distro(mbed-baremetal ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources)
|
||||
mbed_create_distro(mbed-os ${MBED_TARGET_CMAKE_NAME} mbed-core-flags mbed-core-sources mbed-rtos-flags mbed-rtos-sources)
|
||||
|
||||
# Set up the linker script and hook it up to the top-level OS targets
|
||||
mbed_setup_linker_script(mbed-baremetal mbed-os)
|
||||
|
||||
# Make sure that things linking mbed-core-flags can also get the target-specific include dirs and flags.
|
||||
mbed_extract_flags(${MBED_TARGET_CMAKE_NAME}-flags ${MBED_TARGET_CMAKE_NAME})
|
||||
target_link_libraries(mbed-core-flags INTERFACE ${MBED_TARGET_CMAKE_NAME}-flags)
|
||||
endif()
|
||||
|
||||
# Ninja requires to be forced for response files
|
||||
|
|
|
@ -19,5 +19,4 @@ target_include_directories(mbed-emac
|
|||
target_sources(mbed-emac
|
||||
PRIVATE
|
||||
stm32xx_emac.cpp
|
||||
stm32xx_eth_irq_callback.cpp
|
||||
)
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,3 +1,33 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "stm32f4xx_hal.h"
|
||||
|
||||
/**
|
||||
|
@ -79,3 +109,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
NVIC_DisableIRQ(ETH_IRQn);
|
||||
}
|
||||
}
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -117,3 +119,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -116,3 +118,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -122,3 +124,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -25,7 +27,6 @@
|
|||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef USE_USER_DEFINED_HAL_ETH_MSPINIT
|
||||
|
||||
#include "stm32f7xx_hal.h"
|
||||
|
@ -122,3 +123,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -150,3 +152,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -161,3 +163,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -161,3 +163,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -1,10 +1,9 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2018, STMicroelectronics
|
||||
* Copyright (c) 2020, Arduino SA
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
* Copyright (c) 2022, STMicroelectronics
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
|
@ -176,3 +175,7 @@ void HAL_ETH_MspDeInit(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_MSPINIT */
|
||||
|
||||
// Blank, non-weak-override function to make sure the linker pulls in this file
|
||||
void stm32_eth_init_weak_symbol_helper()
|
||||
{}
|
|
@ -145,7 +145,16 @@ extern "C" {
|
|||
|
||||
void _eth_config_mac(ETH_HandleTypeDef *heth);
|
||||
void ETH_IRQHandler(void);
|
||||
MBED_WEAK void STM_HAL_ETH_Handler(ETH_HandleTypeDef *heth);
|
||||
|
||||
// We need to give the linker a reason to pull in the stmxx_eth_init.c files, since they only contain
|
||||
// weak symbol overrides and would otherwise be ignored.
|
||||
void stm32_eth_init_weak_symbol_helper();
|
||||
|
||||
#ifdef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK
|
||||
MBED_WEAK void STM_HAL_ETH_Handler();
|
||||
#else
|
||||
void STM_HAL_ETH_Handler();
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -242,16 +251,6 @@ static void MPU_Config(void)
|
|||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* IRQ Handler
|
||||
*
|
||||
* @param heth: ETH handle
|
||||
* @retval None
|
||||
*/
|
||||
MBED_WEAK void STM_HAL_ETH_Handler()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Ethernet IRQ Handler
|
||||
*
|
||||
|
@ -289,6 +288,9 @@ static osThreadId_t create_new_thread(const char *threadName, void (*thread)(voi
|
|||
bool STM32_EMAC::low_level_init_successful()
|
||||
#ifndef ETH_IP_VERSION_V2
|
||||
{
|
||||
// Generate a reference to this empty function so the linker pulls it in.
|
||||
stm32_eth_init_weak_symbol_helper();
|
||||
|
||||
uint32_t PHY_ID;
|
||||
|
||||
/* Init ETH */
|
||||
|
@ -360,6 +362,9 @@ bool STM32_EMAC::low_level_init_successful()
|
|||
{
|
||||
uint32_t idx;
|
||||
|
||||
// Generate a reference to this empty function so the linker pulls it in.
|
||||
stm32_eth_init_weak_symbol_helper();
|
||||
|
||||
MPU_Config();
|
||||
|
||||
/* Init ETH */
|
||||
|
@ -1085,4 +1090,46 @@ void HAL_ETH_MACErrorCallback(ETH_HandleTypeDef *heth)
|
|||
}
|
||||
#endif // ETH_IP_VERSION_V2
|
||||
|
||||
#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK
|
||||
|
||||
#define FLAG_RX 1
|
||||
|
||||
/**
|
||||
* Override Ethernet Rx Transfer completed callback
|
||||
* @param heth: ETH handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
STM32_EMAC &emac = STM32_EMAC::get_instance();
|
||||
if (emac.thread) {
|
||||
osThreadFlagsSet(emac.thread, FLAG_RX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the IRQ Handler
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void STM_HAL_ETH_Handler()
|
||||
{
|
||||
STM32_EMAC &emac = STM32_EMAC::get_instance();
|
||||
HAL_ETH_IRQHandler(&emac.EthHandle);
|
||||
}
|
||||
|
||||
#else /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */
|
||||
|
||||
/**
|
||||
* IRQ Handler
|
||||
*
|
||||
* @param heth: ETH handle
|
||||
* @retval None
|
||||
*/
|
||||
MBED_WEAK void STM_HAL_ETH_Handler()
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */
|
||||
|
||||
#endif /* DEVICE_EMAC */
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/* Copyright (c) 2017-2019 ARM Limited
|
||||
* Copyright (c) 2017-2019 STMicroelectronics
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK
|
||||
|
||||
#if DEVICE_EMAC
|
||||
|
||||
#include "stm32xx_emac.h"
|
||||
#define FLAG_RX 1
|
||||
|
||||
/**
|
||||
* Override Ethernet Rx Transfer completed callback
|
||||
* @param heth: ETH handle
|
||||
* @retval None
|
||||
*/
|
||||
void HAL_ETH_RxCpltCallback(ETH_HandleTypeDef *heth)
|
||||
{
|
||||
STM32_EMAC &emac = STM32_EMAC::get_instance();
|
||||
if (emac.thread) {
|
||||
osThreadFlagsSet(emac.thread, FLAG_RX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the IRQ Handler
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void STM_HAL_ETH_Handler()
|
||||
{
|
||||
STM32_EMAC &emac = STM32_EMAC::get_instance();
|
||||
HAL_ETH_IRQHandler(&emac.EthHandle);
|
||||
}
|
||||
|
||||
#endif /* DEVICE_EMAC */
|
||||
|
||||
#endif /* USE_USER_DEFINED_HAL_ETH_IRQ_CALLBACK */
|
|
@ -102,3 +102,4 @@ target_link_libraries(mbed-lwipstack
|
|||
PRIVATE
|
||||
mbed-rtos-flags
|
||||
)
|
||||
|
||||
|
|
|
@ -55,21 +55,28 @@ target_link_libraries(mbed-netsocket-api
|
|||
mbed-mbedtls
|
||||
)
|
||||
|
||||
# Currently, netsocket-api needs to link to whichever library is providing an implementation
|
||||
# of OnboardNetworkStack::get_default_instance(). Otherwise, the link order is not correct.
|
||||
if("MBED_CONF_NSAPI_DEFAULT_STACK=LWIP" IN_LIST MBED_CONFIG_DEFINITIONS)
|
||||
target_link_libraries(mbed-netsocket-api PUBLIC mbed-lwipstack)
|
||||
elseif("MBED_CONF_NSAPI_DEFAULT_STACK=NANOSTACK" IN_LIST MBED_CONFIG_DEFINITIONS)
|
||||
target_link_libraries(mbed-netsocket-api PUBLIC mbed-nanostack)
|
||||
endif()
|
||||
|
||||
if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
target_link_libraries(mbed-netsocket-api
|
||||
INTERFACE
|
||||
mbed-emac
|
||||
)
|
||||
endif()
|
||||
|
||||
add_library(mbed-netsocket INTERFACE)
|
||||
|
||||
target_link_libraries(mbed-netsocket
|
||||
INTERFACE
|
||||
mbed-mbedtls
|
||||
mbed-lwipstack
|
||||
)
|
||||
|
||||
if("DEVICE_EMAC=1" IN_LIST MBED_TARGET_DEFINITIONS)
|
||||
target_link_libraries(mbed-netsocket
|
||||
INTERFACE
|
||||
mbed-emac
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(mbed-netsocket
|
||||
INTERFACE
|
||||
mbed-wifi
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_target_functions)
|
||||
|
||||
#
|
||||
# Sign TF-M secure and non-secure images and combine them with the bootloader
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_target_functions)
|
||||
|
||||
#
|
||||
# Merge Cortex-M4 HEX and a Cortex-M0 HEX.
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_target_functions)
|
||||
|
||||
#
|
||||
# Sign TF-M secure and non-secure images and combine them with the bootloader
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_target_functions)
|
||||
|
||||
#
|
||||
# Patch an LPC target vector table in the binary file.
|
||||
|
|
|
@ -35,7 +35,7 @@ else()
|
|||
endif()
|
||||
|
||||
include(mbed_generate_config_header)
|
||||
include(mbed_set_post_build)
|
||||
include(mbed_target_functions)
|
||||
include(mbed_create_distro)
|
||||
|
||||
# Load toolchain and mbed configuration, generating it if needed
|
||||
|
|
|
@ -1,24 +1,8 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# This script provides mbed_create_distro(), a function that lets you compile multiple
|
||||
# apps that use Mbed OS without waiting for Mbed OS to build multiple times.
|
||||
|
||||
# You can use it like this:
|
||||
# mbed_create_distro(mbed_for_my_app mbed-os mbed-storage-kvstore mbed-storage-filesystem)
|
||||
#
|
||||
# add_executable(myapp1 MyApp1.cpp)
|
||||
# target_link_libraries(myapp1 PRIVATE mbed_for_my_app)
|
||||
# mbed_set_post_build(myapp1)
|
||||
#
|
||||
# add_executable(myapp2 MyApp2.cpp)
|
||||
# target_link_libraries(myapp2 PRIVATE mbed_for_my_app)
|
||||
# mbed_set_post_build(myapp2)
|
||||
#
|
||||
# Both myapp1 and myapp2 will act like they were linked to mbed-os, mbed-storage-kvstore,
|
||||
# and mbed-storage-filesystem. Note that if you actually did target_link_libraries(myapp1 PRIVATE mbed-os
|
||||
# mbed-storage-kvstore mbed-storage-filesystem), it would compile a new version of the Mbed OS source
|
||||
# files for each target. However, using mbed_create_distro(), Mbed OS will only be compiled once.
|
||||
# This script provides mbed_create_distro(), a function that combines a tree of INTERFACE targets
|
||||
# into a single library target, copying properties appropriately.
|
||||
|
||||
# Append the value of PROPERTY from SOURCE to the value of PROPERTY on DESTINATION
|
||||
function(copy_append_property PROPERTY SOURCE DESTINATION)
|
||||
|
@ -32,7 +16,13 @@ endfunction(copy_append_property)
|
|||
# Create a "distribution" of Mbed OS containing the base Mbed and certain modules.
|
||||
# This distribution only needs to be compiled once and can be referenced in an arbitrary amount of targets.
|
||||
function(mbed_create_distro NAME) # ARGN: modules...
|
||||
add_library(${NAME} STATIC EXCLUDE_FROM_ALL)
|
||||
|
||||
# Use an OBJECT library so that weak symbol resolution works properly
|
||||
add_library(${NAME} OBJECT EXCLUDE_FROM_ALL)
|
||||
|
||||
# Workaround to ensure that everything that links to this library receives its objects, including other object libraries
|
||||
# from here: https://gitlab.kitware.com/cmake/cmake/-/issues/18090#note_1041608
|
||||
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${NAME}>)
|
||||
|
||||
# Now copy include dirs, compile defs, and compile options (but NOT interface source files) over
|
||||
# to the distribution target so they will be passed into things that link to it.
|
||||
|
@ -46,41 +36,105 @@ function(mbed_create_distro NAME) # ARGN: modules...
|
|||
list(GET REMAINING_MODULES 0 CURR_MODULE)
|
||||
list(REMOVE_AT REMAINING_MODULES 0)
|
||||
|
||||
get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE)
|
||||
if(TARGET "${CURR_MODULE}")
|
||||
|
||||
# Pass up mbed linker script property, which is used by the top level code to select the linker script
|
||||
copy_append_property(INTERFACE_MBED_LINKER_SCRIPT ${CURR_MODULE} ${NAME})
|
||||
get_property(CURR_MODULE_TYPE TARGET ${CURR_MODULE} PROPERTY TYPE)
|
||||
|
||||
if("${CURR_MODULE_TYPE}" STREQUAL "STATIC_LIBRARY")
|
||||
# Don't need to do anything other than linking it
|
||||
target_link_libraries(${NAME} PUBLIC ${CURR_MODULE})
|
||||
# Pass up mbed linker script property, which is used by the top level code to select the linker script
|
||||
copy_append_property(INTERFACE_MBED_LINKER_SCRIPT ${CURR_MODULE} ${NAME})
|
||||
|
||||
if("${CURR_MODULE_TYPE}" STREQUAL "STATIC_LIBRARY")
|
||||
# Don't need to do anything other than linking it
|
||||
target_link_libraries(${NAME} PUBLIC ${CURR_MODULE})
|
||||
else()
|
||||
# Make sure that linking to the distro pulls in the compiled code from CURR_MODULE
|
||||
target_link_libraries(${NAME} PRIVATE ${CURR_MODULE})
|
||||
|
||||
copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME})
|
||||
|
||||
# Additionally, interface libraries can export precompiled .o files as sources.
|
||||
# We need to copy these to the interface sources of the distro, because adding a .o
|
||||
# to the sources of an object library does nothing.
|
||||
get_property(CURR_MODULE_INTERFACE_SOURCES TARGET ${CURR_MODULE} PROPERTY INTERFACE_SOURCES)
|
||||
foreach(INTERFACE_SOURCE ${CURR_MODULE_INTERFACE_SOURCES})
|
||||
if("${INTERFACE_SOURCE}" MATCHES ".o$" OR "${INTERFACE_SOURCE}" MATCHES ".obj$")
|
||||
# Object file found
|
||||
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
# CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries
|
||||
# via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/.
|
||||
# see: https://cmake.org/pipermail/cmake/2019-May/069453.html
|
||||
# also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090
|
||||
|
||||
if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY")
|
||||
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${CURR_MODULE}>)
|
||||
|
||||
# Check if this object library has any other libraries exported through its INTERFACE_SOURCES.
|
||||
# If it does, we need to propagate those too.
|
||||
foreach(INTERFACE_SOURCE ${CURR_MODULE_INTERFACE_SOURCES})
|
||||
if(INTERFACE_SOURCE MATCHES "\\$<TARGET_OBJECTS:.*>")
|
||||
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
|
||||
list(APPEND COMPLETED_MODULES ${CURR_MODULE})
|
||||
|
||||
# find sub-modules of this module
|
||||
get_property(SUBMODULES TARGET ${CURR_MODULE} PROPERTY INTERFACE_LINK_LIBRARIES)
|
||||
foreach(SUBMODULE ${SUBMODULES})
|
||||
if(NOT "${SUBMODULE}" MATCHES "::@") # remove CMake internal CMAKE_DIRECTORY_ID_SEP markers
|
||||
# Remove LINK_ONLY genexes from target_link_libraries(... PRIVATE). We can ignore things wrapped in these
|
||||
# because they will already have been handled by the target_link_libraries earlier on.
|
||||
if(NOT "${SUBMODULE}" MATCHES "\\$<LINK_ONLY:.*>")
|
||||
if(NOT ${SUBMODULE} IN_LIST COMPLETED_MODULES)
|
||||
list(APPEND REMAINING_MODULES ${SUBMODULE})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
else()
|
||||
# Make sure that linking to the distro pulls in the compiled code from CURR_MODULE
|
||||
target_link_libraries(${NAME} PRIVATE ${CURR_MODULE})
|
||||
# Module is not a target, it's something else like a linker flag or a generator expression
|
||||
# So, just link it to the output.
|
||||
target_link_libraries(${NAME} INTERFACE ${CURR_MODULE})
|
||||
endif()
|
||||
|
||||
endwhile()
|
||||
|
||||
endfunction(mbed_create_distro)
|
||||
|
||||
# Traverse a tree of targets and create an interface target containing all of the flags (includes/compile options/
|
||||
# etc) but none of the source files extracted from those targets.
|
||||
# This is mainly used as a shim so that we don't need to edit 100s of target CMake files and separate out the targets
|
||||
# containing flags from the targets containing source files.
|
||||
function(mbed_extract_flags NAME) # ARGN: modules...
|
||||
add_library(${NAME} INTERFACE)
|
||||
|
||||
# Now copy include dirs, compile defs, and compile options (but NOT interface source files) over
|
||||
# to the distribution target so they will be passed into things that link to it.
|
||||
# To do this, we need to recursively traverse the tree of dependencies.
|
||||
set(REMAINING_MODULES ${ARGN})
|
||||
set(COMPLETED_MODULES ${ARGN})
|
||||
while(NOT "${REMAINING_MODULES}" STREQUAL "")
|
||||
|
||||
#message("Flags: ${NAME}. REMAINING_MODULES: ${REMAINING_MODULES}")
|
||||
|
||||
list(GET REMAINING_MODULES 0 CURR_MODULE)
|
||||
list(REMOVE_AT REMAINING_MODULES 0)
|
||||
|
||||
if(TARGET "${CURR_MODULE}")
|
||||
copy_append_property(INTERFACE_COMPILE_DEFINITIONS ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_COMPILE_OPTIONS ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_INCLUDE_DIRECTORIES ${CURR_MODULE} ${NAME})
|
||||
copy_append_property(INTERFACE_LINK_OPTIONS ${CURR_MODULE} ${NAME})
|
||||
|
||||
# CMake currently has a limitation that OBJECT libraries cannot link to other OBJECT libraries
|
||||
# via the LINK_LIBRARIES property -- CMake will not link the objects in properly :/.
|
||||
# see: https://cmake.org/pipermail/cmake/2019-May/069453.html
|
||||
# also: https://gitlab.kitware.com/cmake/cmake/-/issues/18090
|
||||
|
||||
if("${CURR_MODULE_TYPE}" STREQUAL "OBJECT_LIBRARY")
|
||||
target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:${CURR_MODULE}>)
|
||||
|
||||
# Check if this object library has any other libraries exported through its INTERFACE_SOURCES.
|
||||
# If it does, we need to propagate those too.
|
||||
get_property(OBJ_INTERFACE_SOURCES TARGET ${NAME} PROPERTY INTERFACE_SOURCES)
|
||||
foreach(INTERFACE_SOURCE ${OBJ_INTERFACE_SOURCES})
|
||||
if(INTERFACE_SOURCE MATCHES "\\$<TARGET_OBJECTS:.*>")
|
||||
target_sources(${NAME} INTERFACE ${INTERFACE_SOURCE})
|
||||
endif()
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
list(APPEND COMPLETED_MODULES ${CURR_MODULE})
|
||||
|
||||
# find sub-modules of this module
|
||||
|
@ -96,8 +150,12 @@ function(mbed_create_distro NAME) # ARGN: modules...
|
|||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
else()
|
||||
# Module is not a target, it's something else like a linker flag or a generator expression
|
||||
# So, just link it to the output.
|
||||
target_link_libraries(${NAME} INTERFACE ${CURR_MODULE})
|
||||
endif()
|
||||
|
||||
endwhile()
|
||||
|
||||
endfunction(mbed_create_distro)
|
||||
endfunction(mbed_extract_flags)
|
|
@ -18,13 +18,14 @@ endfunction(mbed_set_linker_script)
|
|||
|
||||
|
||||
#
|
||||
# Set up the linker script for the top-level Mbed MCU target.
|
||||
# Set up the linker script for the top-level Mbed OS targets.
|
||||
# If needed, this also creates another target to preprocess the linker script.
|
||||
#
|
||||
function(mbed_setup_linker_script mbed_mcu_target)
|
||||
function(mbed_setup_linker_script mbed_os_target mbed_baremetal_target)
|
||||
|
||||
# Find the path to the desired linker script
|
||||
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_mcu_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
|
||||
# (the property should be set on both the OS and baremetal targets in a sane world)
|
||||
get_property(RAW_LINKER_SCRIPT_PATHS TARGET ${mbed_baremetal_target} PROPERTY INTERFACE_MBED_LINKER_SCRIPT)
|
||||
|
||||
# Check if two (or more) different linker scripts got used
|
||||
list(REMOVE_DUPLICATES RAW_LINKER_SCRIPT_PATHS)
|
||||
|
@ -71,19 +72,26 @@ function(mbed_setup_linker_script mbed_mcu_target)
|
|||
# which is then added as a dependency of the MCU target. This ensures the linker script will exist
|
||||
# by the time we need it.
|
||||
add_custom_target(mbed-linker-script DEPENDS ${LINKER_SCRIPT_PATH} VERBATIM)
|
||||
add_dependencies(${mbed_mcu_target} mbed-linker-script)
|
||||
|
||||
# Add linker flags to the MCU target to pick up the preprocessed linker script
|
||||
target_link_options(${mbed_mcu_target}
|
||||
INTERFACE
|
||||
"-T" "${LINKER_SCRIPT_PATH}"
|
||||
)
|
||||
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
|
||||
|
||||
|
||||
add_dependencies(${TARGET} mbed-linker-script)
|
||||
|
||||
# Add linker flags to the MCU target to pick up the preprocessed linker script
|
||||
target_link_options(${TARGET}
|
||||
INTERFACE
|
||||
"-T" "${LINKER_SCRIPT_PATH}"
|
||||
)
|
||||
endforeach()
|
||||
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
|
||||
target_link_options(${mbed_mcu_target}
|
||||
INTERFACE
|
||||
"--scatter=${raw_linker_script_path}"
|
||||
"--predefine=${_linker_preprocess_definitions}"
|
||||
"--map"
|
||||
)
|
||||
foreach(TARGET ${mbed_baremetal_target} ${mbed_os_target})
|
||||
target_link_options(${TARGET}
|
||||
INTERFACE
|
||||
"--scatter=${raw_linker_script_path}"
|
||||
"--predefine=${_linker_preprocess_definitions}"
|
||||
"--map"
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
endfunction(mbed_setup_linker_script)
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright (c) 2021 ARM Limited. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
# File containing various functions for operating on library and executable targets.
|
||||
|
||||
#
|
||||
# Converts output file of `target` to binary file and to Intel HEX file.
|
||||
#
|
|
@ -20,14 +20,8 @@ list(APPEND link_options
|
|||
"-Wl,--end-group"
|
||||
"-specs=nosys.specs"
|
||||
"-Wl,--cref"
|
||||
"-Wl,--allow-multiple-definition"
|
||||
)
|
||||
|
||||
# Add the -Wl,--whole-archive flag as a hack to fix resolution of weak symbols between .a libraries.
|
||||
# This basically causes the linker to process each object in each .a library as if it was its own file.
|
||||
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> -Wl,--whole-archive <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,--no-whole-archive")
|
||||
set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> -Wl,--whole-archive <OBJECTS> -o <TARGET> <LINK_LIBRARIES> -Wl,--no-whole-archive")
|
||||
|
||||
# Add linking time preprocessor macro for TFM targets
|
||||
if("TFM" IN_LIST MBED_TARGET_LABELS)
|
||||
list(APPEND link_options
|
||||
|
|
|
@ -4,4 +4,8 @@ future>=0.18.0,<1.0
|
|||
jinja2>=2.11.3
|
||||
intelhex>=2.3.0,<3.0.0
|
||||
mbed-tools
|
||||
mbed-os-tools
|
||||
mbed-os-tools
|
||||
|
||||
# needed for signing secure images
|
||||
cryptography
|
||||
cbor
|
Loading…
Reference in New Issue