Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[scons] Simplify Scons tooling, misc. fixes and improvements #558

Merged
merged 10 commits into from
Feb 26, 2021
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
[submodule "ext/modm-devices"]
path = ext/modm-devices
url = https://github.com/modm-io/modm-devices.git
[submodule "ext/dlr/scons-build-tools"]
path = ext/dlr/scons-build-tools
url = https://github.com/modm-io/scons-build-tools.git
[submodule "ext/ros/ros-lib"]
path = ext/ros/ros-lib
url = https://github.com/modm-io/ros-lib
Expand Down
1 change: 0 additions & 1 deletion ext/dlr/scons-build-tools
Submodule scons-build-tools deleted from 6c35aa
11 changes: 10 additions & 1 deletion src/modm/platform/core/cortex/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,14 @@ def prepare(module, options):
maximum=2 ** 16,
default="3*1024"))

if "f" in options[":target"].get_driver("core")["type"]:
module.add_option(
EnumerationOption(
name="float-abi",
description="Floating point ABI",
enumeration=["soft", "softfp", "hard"],
default="hard"))

salkinium marked this conversation as resolved.
Show resolved Hide resolved
memories = listify(options[":target"].get_driver("core")["memory"])

# Cortex-M0 does not have remappable vector table, so it will remain in Flash
Expand Down Expand Up @@ -258,6 +266,7 @@ def build(env):
"with_fault_storage": env.has_module(":platform:fault"),
"with_memory_traits": env.has_module(":architecture:memory"),
"with_assert": env.has_module(":architecture:assert"),
"with_fpu": env.get("float-abi", "soft") != "soft",
})
env.outbasepath = "modm/src/modm/platform/core"

Expand Down Expand Up @@ -345,7 +354,7 @@ def build(env):
"7f": "-mfpu=fpv5-sp-d16",
"7fd": "-mfpu=fpv5-d16",
}[fpu]
env.collect(":build:archflags", "-mfloat-abi=hard", fpu_spec)
env.collect(":build:archflags", "-mfloat-abi={}".format(env["float-abi"]), fpu_spec)
single_precision = ("-sp-" in fpu_spec)
if single_precision:
env.collect(":build:ccflags", "-fsingle-precision-constant",
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/core/cortex/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ This module adds these architecture specific [compiler options][options]:

- `-mcpu=cortex-m{type}`: the target to compile for.
- `-mthumb`: only Thumb2 instruction set is supported.
- `-mfloat-abi=hard`: if FPU available use the fastest ABI available.
- `-mfloat-abi={soft, softfp, hard}`: the FPU ABI: `hard` is fastest.
- `-mfpu=fpv{4, 5}-{sp}-d16`: single or double precision FPU.
- `-fsingle-precision-constant`: if SP-FPU, treat all FP constants as SP.
- `-Wdouble-promotion`: if SP-FPU, warn if FPs are promoted to doubles.
Expand Down
2 changes: 1 addition & 1 deletion src/modm/platform/core/cortex/startup.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void __modm_startup(void)
SCB_EnableICache();
%% endif

%% if "f" in core
%% if with_fpu
// Enable FPU in privileged and user mode
SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2));
%% endif
Expand Down
7 changes: 6 additions & 1 deletion tools/build_script_generator/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,14 @@ def prepare(module, options):
module.add_collector(
PathCollector(name="path.library",
description="Search path for static libraries"))
def validate_library(library):
if library.startswith("lib") or library.endswith(".a"):
raise ValueError("Libraries must only contain `name` not `libname.a`!")
return library
module.add_collector(
StringCollector(name="library",
description="Libraries to link against"))
description="Libraries to link against",
validate=validate_library))
module.add_collector(
StringCollector(name="pkg-config",
description="Packages to configure against"))
Expand Down
39 changes: 16 additions & 23 deletions tools/build_script_generator/scons/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,16 @@ def build(env):
# SCons tools and toolpaths
toolpaths = {
"scons/site_tools",
"ext/dlr/scons/site_tools"
}
tools = {
"build_target",
"comstr",
"find_files",
"gcc_retarget",
"qtcreator",
"settings_buildpath",
"template",
"utils_buildformat",
"utils",
"utils_buildpath",
}
if env.has_module(":communication:xpcc:generator"):
tools.add("xpcc_generator")
Expand All @@ -101,30 +102,16 @@ def build(env):

device = env.query("::device")
if device["core"].startswith("cortex-m"):
tools.update({"compiler_arm_none_eabi_gcc", "size", "log_itm", "artifact",
"openocd", "openocd_remote", "bmp", "crashdebug", "dfu"})
tools.update({"size", "log_itm", "artifact", "openocd",
"openocd_remote", "bmp", "crashdebug", "dfu"})
if device["platform"] in ["sam"]:
tools.update({"bossac"})
elif device["core"].startswith("avr"):
tools.update({"compiler_avr_gcc", "size", "avrdude"})
else: # hosted
tools.update({"compiler_hosted_gcc"})
tools.update({"size", "avrdude"})

env.collect("path.tools", *toolpaths)
env.collect("tools", *tools)

# Add common DLR SCons build tools
tools.update({
"settings_gcc_default_internal",
"utils_common",
"utils_gcc_version",
})
env.outbasepath = "modm/ext/dlr/scons/site_tools"
for tool in tools:
path = repopath("ext/dlr/scons-build-tools/site_tools/{}.py".format(tool))
if exists(path):
env.copy(path, "{}.py".format(tool))

# Copy only these modm SCons build tools
env.outbasepath = "modm/scons/"
for tool in tools:
Expand All @@ -137,10 +124,16 @@ def build(env):
env.copy("site_tools/info.c.in")

# Generate the env.BuildTarget tool
linkerscript = env.get(":platform:cortex-m:linkerscript.override")
linkerscript = env.relative_outpath(linkerscript) if linkerscript \
else "$BASEPATH/modm/link/linkerscript.ld"
env.substitutions = env.query("::device")
env.substitutions["upload_with_artifact"] = env.has_module(":crashcatcher")
env.substitutions["with_compilation_db"] = env.has_module(":build:compilation_db")
env.substitutions["program_extension"] = ".exe" if env[":target"].identifier.family == "windows" else ".elf"
env.substitutions.update({
"upload_with_artifact": env.has_module(":crashcatcher"),
"with_compilation_db": env.has_module(":build:compilation_db"),
"program_extension": ".exe" if env[":target"].identifier.family == "windows" else ".elf",
"linkerscript": linkerscript,
})
env.outbasepath = "modm/scons/site_tools"
env.template("resources/build_target.py.in", "build_target.py")

Expand Down
77 changes: 41 additions & 36 deletions tools/build_script_generator/scons/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,13 @@ Example for a STM32 target:

```
$ scons build
Compiling C++·· build/release/main.o
Compiling C···· build/release/modm/ext/tlsf/tlsf.o
Compiling C++·· {debug|release}/main.o
Compiling C···· {debug|release}/modm/ext/gcc/cabi.o
...
Compiling C++·· build/release/modm/src/modm/ui/display/virtual_graphic_display.o
Compiling C++·· build/release/modm/src/modm/utils/dummy.o
Create Library· build/release/modm/libmodm.a
Indexing······· build/release/modm/libmodm.a
Linking········ build/release/game_of_life.elf
Compiling C++·· {debug|release}/modm/src/modm/utils/dummy.o
Archiving······ {debug|release}/modm/libmodm.a
Indexing······· {debug|release}/modm/libmodm.a
Linking········ /build/{debug|release}/blink.elf
```


Expand All @@ -88,8 +87,7 @@ Example for a STM32 target with 16MB external heap:

```
$ scons size
Memory usage:.. build/release/game_of_life.elf

Memory usage··· /build/{debug|release}/blink.elf
Program: 12.8 KiB (0.6% used)
(.data + .fastcode + .fastdata + .hardware_init + .reset + .rodata +
.table.copy.extern + .table.copy.intern + .table.section_heap +
Expand Down Expand Up @@ -118,8 +116,8 @@ Example for a STM32 target:

```
$ scons program
.----OpenOCD--- build/release/game_of_life.elf
'-------------> stm32f469nih
╭────────────── /build/{debug|release}/blink.elf
╰───OpenOCD───> stm32f469nih
Open On-Chip Debugger 0.10.0
...
Info : using stlink api v2
Expand All @@ -132,7 +130,7 @@ Info : device id = 0x10006434
Info : flash size = 2048kbytes
Info : Dual Bank 2048 kiB STM32F42x/43x/469/479 found
...
wrote 16384 bytes from file build/release/game_of_life.elf in 0.589736s (27.131 KiB/s)
wrote 16384 bytes from file {debug|release}/blink.elf in 0.589736s (27.131 KiB/s)
** Programming Finished **
** Verify Started **
verified 13064 bytes in 0.296308s (43.056 KiB/s)
Expand All @@ -154,7 +152,10 @@ and can be accessed by pressing the BOOT0-Button during startup.

```
$ scons program-dfu
dfu_stm32_programmer: program [...]/blink/release/blink.bin
Binary File···· /build/{debug|release}/blink.bin
╭────────────── /build/{debug|release}/blink.bin
╰─────DFU─────> stm32f469nih
dfu_stm32_programmer: program /build/{debug|release}/blink.bin
dfu-util 0.9

Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc.
Expand Down Expand Up @@ -221,7 +222,8 @@ You can let the tool guess the port or explicitly specify it:

```
$ scons program-bmp port=/dev/cu.usbmodemDEADBEEF
[...]
╭─Black─Magic── /build/{debug|release}/blink.elf
╰────Probe────> stm32f103rbt6
Remote debugging using /dev/cu.usbmodemDEADBEEF
Target voltage: unknown
Available Targets:
Expand Down Expand Up @@ -254,7 +256,7 @@ running on your own computer (host=`localhost`) or somewhere else.

#### scons run

Executes your project on your computer.
Compiles and executes your program on your computer.
(\* *only Hosted targets*)


Expand Down Expand Up @@ -297,16 +299,18 @@ Launches GDB to debug via Black Magic Probe.

```
scons debug-coredump profile={debug|release} ui={tui|web} \
firmware={GNU Build ID} coredump={path/to/coredump.txt}
coredump={path/to/coredump.txt} \
[firmware={GNU Build ID or path/to/firmware.elf}]
```

Launches GDB for post-mortem debugging with the firmware identified by the
`firmware={hash}` argument using the data from the `coredump={filepath}`
argument.
(optional) `firmware={hash or filepath}` argument using the data from the
`coredump={filepath}` argument.
(\* *only ARM Cortex-M targets*)

See the `:platform:fault` module for details how to receive the coredump data.


#### scons program-remote

```
Expand Down Expand Up @@ -361,8 +365,8 @@ displays the serial output stream.

```
$ scons log-itm fcpu=64000000
.----OpenOCD--> Single Wire Viewer
'------SWO----- stm32f103rbt6
╭───OpenOCD───> Single Wire Viewer
╰─────SWO────── stm32f103rbt6
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
Info : The selected transport took over low-level target control.
Expand Down Expand Up @@ -391,7 +395,7 @@ application.
Compiling C++·· {debug|release}/modm/ext/gcc/assert.o
...
Compiling C++·· {debug|release}/modm/src/modm/utils/dummy.o
Create Library· {debug|release}/modm/libmodm.a
Archiving······ {debug|release}/modm/libmodm.a
Indexing······· {debug|release}/modm/libmodm.a
```

Expand All @@ -406,7 +410,7 @@ Dumps the symbol table for your executable.

```
$ scons symbols
Show symbols for 'build/release/game_of_life.elf':
Show symbols for '{debug|release}/blink.elf':
536871656 00000001 b (anonymous namespace)::nextOperation
536871657 00000001 b (anonymous namespace)::checkNextOperation
536871658 00000001 b (anonymous namespace)::error
Expand All @@ -431,8 +435,8 @@ into assembly instructions:

```
$ scons listing
Ext. Listing··· build/release/game_of_life.lss
$ less build/release/game_of_life.lss
Listing········ {debug|release}/blink.lss
$ less {debug|release}/blink.lss
...
Disassembly of section .text:
...
Expand All @@ -450,8 +454,8 @@ main()
8000d7a: f000 fd91 bl 80018a0 <_ZN5Board17initializeDisplayEv>
Board::initializeTouchscreen();
8000d7e: f7ff fc55 bl 800062c <_ZN5Board21initializeTouchscreenEv>
game_of_life();
8000d82: f7ff feff bl 8000b84 <_Z12game_of_lifev>
blink();
8000d82: f7ff feff bl 8000b84 <_Z12blinkv>
...
```

Expand All @@ -466,7 +470,7 @@ Creates a binary file of your executable.

```
$ scons bin
Binary File···· build/release/game_of_life.bin
Binary File···· {debug|release}/blink.bin
```


Expand All @@ -481,7 +485,8 @@ the hash of the binary file in `{build_path}/artifacts/{hash}.elf`.

```
$ scons artifact
Cache Artifact· build/release/game_of_life.elf
╭───Artifact─── /build/release/blink.elf
╰────Cache────> artifacts/0214523ab713bc7bdfb37d902e65dae8305f4754.elf
```


Expand All @@ -495,14 +500,14 @@ Cleans the build artifacts.

```
$ scons -c
Removed build/release/main.o
Removed build/release/modm/ext/tlsf/tlsf.o

Removed build/release/modm/src/modm/ui/display/virtual_graphic_display.o
Removed build/release/modm/src/modm/utils/dummy.o
Removed build/release/modm/libmodm.a
Removed build/release/game_of_life.elf
Removed build/release/game_of_life.lss
Removed {debug|release}/main.o
Removed {debug|release}/modm/ext/tlsf/tlsf.o
...
Removed {debug|release}/modm/src/modm/ui/display/virtual_graphic_display.o
Removed {debug|release}/modm/src/modm/utils/dummy.o
Removed {debug|release}/modm/libmodm.a
Removed {debug|release}/blink.elf
Removed {debug|release}/blink.lss
```


Expand Down
22 changes: 14 additions & 8 deletions tools/build_script_generator/scons/resources/SConscript.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@
from os.path import join, abspath
Import("env")

profile = env["CONFIG_PROFILE"]
profile = ARGUMENTS.get("profile", "release")
%% if is_modm
env["CONFIG_PROFILE"] = profile
env["BUILDPATH"] = join(env["CONFIG_BUILD_BASE"], profile)
env["BASEPATH"] = abspath(".")
env["BASEPATH"] = abspath("..")
%% if core.startswith("avr")
env["COMPILERPREFIX"] = "avr-"
%% elif core.startswith("cortex-m")
env["COMPILERPREFIX"] = "arm-none-eabi-"
%% endif
Comment on lines +20 to +24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't scale well for e.g. RISC-V and/or non-GCC compilers, but is ok for now...

%% if family == "darwin"
# Using homebrew gcc on macOS instead of clang
env["COMPILERSUFFIX"] = env.Detect(["gcc-11", "gcc-10"])[3:]
Expand Down Expand Up @@ -112,21 +118,21 @@ env["CONFIG_AVRDUDE_OPTIONS"] = "{{ avrdude_options }}"
env["CONFIG_AVRDUDE_BAUDRATE"] = "{{ avrdude_baudrate }}"
%% endif
%% elif core.startswith("cortex-m")
env.Append(MODM_OPENOCD_CONFIGFILES="$BASEPATH/openocd.cfg")
env.Append(MODM_OPENOCD_GDBINIT="$BASEPATH/openocd_gdbinit")
env.Append(MODM_GDBINIT="$BASEPATH/gdbinit")
env.Append(MODM_OPENOCD_CONFIGFILES = "$BASEPATH/modm/openocd.cfg")
env.Append(MODM_OPENOCD_GDBINIT = "$BASEPATH/modm/openocd_gdbinit")
env.Append(MODM_GDBINIT = "$BASEPATH/modm/gdbinit")
%% if platform == "sam"
%% if bossac_offset
env.Append(MODM_BOSSAC_OFFSET={{ bossac_offset }})
env.Append(MODM_BOSSAC_OFFSET = {{ bossac_offset }})
%% endif
%% if bossac_options
env.Append(MODM_BOSSAC_OPTIONS="{{ bossac_options }}")
env.Append(MODM_BOSSAC_OPTIONS = "{{ bossac_options }}")
%% endif
%% endif
%% endif

# XPCC generator tool path
env["XPCC_SYSTEM_DESIGN"] = join(abspath("."), "tools", "xpcc_generator")
env["XPCC_SYSTEM_DESIGN"] = "$BASEPATH/modm/tools/xpcc_generator"
%% endif


Expand Down
Loading