Skip to content

Commit

Permalink
minimal-printf: Enable using a target configuration parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hugueskamba committed Nov 19, 2019
1 parent 609612c commit 6826848
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
1 change: 1 addition & 0 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"default_lib": "std",
"bootloader_supported": false,
"static_memory_defines": true,
"printf_lib": "std",
"config": {
"console-uart": {
"help": "Target has UART console on pins STDIO_UART_TX, STDIO_UART_RX. Value is only significant if target has SERIAL device.",
Expand Down
87 changes: 87 additions & 0 deletions tools/test/toolchains/test_toolchains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python3
# Copyright (c) 2019 Arm Limited and Contributors. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0

"""Test the arm toolchain."""

import os
import sys

import mock


ROOT = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..")
)
sys.path.insert(0, ROOT)

from tools.toolchains.arm import ARM_STD, ARM_MICRO, ARMC6
from tools.toolchains.gcc import GCC_ARM
from tools.toolchains.iar import IAR


class TestArmToolchain:
"""Test Arm classes."""

def test_arm_minimal_printf(self):
"""Test that linker flags are correctly added to an instance of ARM."""
mock_target = mock.MagicMock()
mock_target.core = "Cortex-M4"
mock_target.printf_lib = "minimal-printf"
mock_target.supported_toolchains = ["ARM", "uARM", "ARMC5"]

arm_std_obj = ARM_STD(mock_target)
arm_micro_obj = ARM_MICRO(mock_target)
arm_c6_obj = ARMC6(mock_target)

assert "-DMBED_MINIMAL_PRINTF" in arm_std_obj.flags["common"]
assert "-DMBED_MINIMAL_PRINTF" in arm_micro_obj.flags["common"]
assert "-DMBED_MINIMAL_PRINTF" in arm_c6_obj.flags["common"]


class TestGccToolchain:
"""Test the GCC class."""

def test_gcc_minimal_printf(self):
"""Test that linker flags are correctly added to an instance of GCC_ARM."""
mock_target = mock.MagicMock()
mock_target.core = "Cortex-M4"
mock_target.printf_lib = "minimal-printf"
mock_target.supported_toolchains = ["GCC_ARM"]
mock_target.is_TrustZone_secure_target = False

gcc_obj = GCC_ARM(mock_target)

assert "-DMBED_MINIMAL_PRINTF" in gcc_obj.flags["common"]

minimal_printf_wraps = [
"-Wl,--wrap,printf",
"-Wl,--wrap,sprintf",
"-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf",
"-Wl,--wrap,vsprintf",
"-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf",
"-Wl,--wrap,vfprintf",
]

assert all(
elem in gcc_obj.flags["ld"] for elem in minimal_printf_wraps
)


class TestIarToolchain:
"""Test the IAR class."""

def test_iar_minimal_printf(self):
"""Test that linker flags are correctly added to an instance of GCC_ARM."""
mock_target = mock.MagicMock()
mock_target.core = "Cortex-M4"
mock_target.printf_lib = "minimal-printf"
mock_target.supported_toolchains = ["IAR"]
mock_target.is_TrustZone_secure_target = False

iar_obj = IAR(mock_target)

assert "-DMBED_MINIMAL_PRINTF" in iar_obj.flags["common"]
12 changes: 12 additions & 0 deletions tools/toolchains/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ def __init__(self, target, notify=None, macros=None,
if "--library_type=microlib" not in self.flags['common']:
self.flags['common'].append("--library_type=microlib")

if (
target.printf_lib == "minimal-printf"
and "-DMBED_MINIMAL_PRINTF" not in self.flags['common']
):
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")

cpu = {
"Cortex-M0+": "Cortex-M0plus",
"Cortex-M4F": "Cortex-M4.fp.sp",
Expand Down Expand Up @@ -568,6 +574,12 @@ def __init__(self, target, *args, **kwargs):
if "--library_type=microlib" not in self.flags['asm']:
self.flags['asm'].append("--library_type=microlib")

if (
target.printf_lib == "minimal-printf"
and "-DMBED_MINIMAL_PRINTF" not in self.flags["common"]
):
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")

if target.is_TrustZone_secure_target:
if kwargs.get('build_dir', False):
# Output secure import library
Expand Down
19 changes: 19 additions & 0 deletions tools/toolchains/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
self.flags["common"].append("-DMBED_RTOS_SINGLE_THREAD")
self.flags["ld"].append("--specs=nano.specs")

if target.printf_lib == "minimal-printf":
if "-DMBED_MINIMAL_PRINTF" not in self.flags['common']:
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")

minimal_printf_wraps = [
"-Wl,--wrap,printf",
"-Wl,--wrap,sprintf",
"-Wl,--wrap,snprintf",
"-Wl,--wrap,vprintf",
"-Wl,--wrap,vsprintf",
"-Wl,--wrap,vsnprintf",
"-Wl,--wrap,fprintf",
"-Wl,--wrap,vfprintf",
]

for minimal_printf_wrap in minimal_printf_wraps:
if minimal_printf_wrap not in self.flags["ld"]:
self.flags["ld"].append(minimal_printf_wrap)

self.cpu = []
if target.is_TrustZone_secure_target:
# Enable compiler security extensions
Expand Down
6 changes: 6 additions & 0 deletions tools/toolchains/iar.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def __init__(self, target, notify=None, macros=None, build_profile=None,
define_string = self.make_ld_define("DOMAIN_NS", "0x1")
self.flags["ld"].append(define_string)

if (
target.printf_lib == "minimal-printf"
and "-DMBED_MINIMAL_PRINTF" not in self.flags["common"]
):
self.flags["common"].append("-DMBED_MINIMAL_PRINTF")

core = target.core_without_NS
cpu = {
"Cortex-M7F": "Cortex-M7.fp.sp",
Expand Down

0 comments on commit 6826848

Please sign in to comment.