1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
Use crossdev to build a bare-metal (no kernel headers or full eglibc) for
an ARM Cortex-M4 dev board. The cortex-m4 is the armv7e-m arch for gcc.
The Cortex-M4 has a silicon FPU option (VFPv4-SP) of single-precision (SP),
which is known as a Cortex-M4F. The Cortex-M4 also includes SIMD DSP
instructions.
This commands builds binutils/gcc/newlib/gdb; first emerge crossdev-999999,
then disable any layman/other overlays and enable the output overlay in the
crossdev command (unless you want the cross-foo overlay to be created in
the first existing overlay found by crossdev).
Note for newer portage using repos.conf you should use PORTDIR_OVERLAY for
the output overlay instead of the crossdev argument for ov-output. Also if
portage complains about no LIBC defined, you can add ELIBC="newlib" to
the command line.
USE="hardened multitarget lzma -multilib -openmp -fortran -jit" EXTRA_ECONF="--disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb" crossdev armv7m-hardfloat-eabi --ex-gdb --show-fail-log --ov-output /usr/local/cortex-m4
To use the nano-io and nano-malloc config options, use this one:
USE="hardened multitarget lzma -multilib -openmp -fortran -jit" EXTRA_ECONF="--enable-newlib-nano-formatted-io --enable-newlib-nano-malloc --with-newlib --disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb" crossdev armv7m-hardfloat-eabi --abis "aapcs,atpcs" --ex-gdb --show-fail-log --ov-output /usr/local/cortex-m4
Final command using portage newlib for default stage-1 gcc:
PORTDIR_OVERLAY="/usr/local/cortex-m4 /var/lib/layman/ada" USE="hardened multitarget lzma -multilib -openmp -fortran -jit -vtv" EXTRA_ECONF="--enable-newlib-nano-formatted-io --enable-newlib-nano-malloc --with-newlib --disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb --with-abi=aapcs-linux --enable-libstdcxx-time=no" crossdev --g 5.4.0-r4 -t armv7m-hardfloat-eabi --ex-gdb --show-fail-log -v
Using newlib-nano ebuild in local overlay, note newlib-nano enables the above
two options plus several others:
PORTDIR_OVERLAY="/usr/local/cortex-m4 /var/lib/layman/ada /usr/local/portage" USE="hardened multitarget lzma -multilib -nls -openmp -fortran -jit -vtv" EXTRA_ECONF="--with-newlib --disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb --with-abi=aapcs-linux" crossdev --g 5.4.0-r4 -t armv7m-hardfloat-eabi --lenv 'USE="newlib-nano"' --ex-gdb --show-fail-log -v
2-stage gcc command with crossdev arg for stage 4 with c,c++ and newlib:
PORTDIR_OVERLAY="/usr/local/cortex-m4 /var/lib/layman/ada" USE="-ada hardened multitarget lzma -multilib -nls -openmp -fortran -jit -vtv" EXTRA_ECONF="--with-newlib --disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb --with-abi=aapcs-linux --enable-libstdcxx-time=no" crossdev --g 5.4.0-r4 -s4 -t armv7m-hardfloat-eabi --lenv 'USE="newlib-nano"' --ex-gdb --show-fail-log -v
Same command as above but with ada support (just no libada)
PORTDIR_OVERLAY="/usr/local/cortex-m4 /var/lib/layman/ada" USE="ada hardened multitarget lzma -multilib -nls -openmp -fortran -jit -vtv" EXTRA_ECONF="--with-newlib --disable-libada --disable-multilib --disable-libsanitizer --with-arch=armv7e-m --with-tune=cortex-m4 --with-float-abi=hard --with-fpu=fpv4-sp-d16 --with-mode=thumb --with-abi=aapcs-linux --enable-libstdcxx-time=no" crossdev --g 6.4.0 -s4 -t armv7m-hardfloat-eabi --genv 'EXTRA_ECONF="--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm"' --lenv 'USE="newlib-nano"' --ex-gdb --show-fail-log -v
Extra upstream config hack for transactional memory related code in
crtbegin.o, add INHIBIT_LIBC_CFLAGS to EXTRA_ECONF:
--genv 'EXTRA_ECONF="--with-host-libstdcxx=-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm" INHIBIT_LIBC_CFLAGS="-DUSE_TM_CLONE_REGISTRY=0"'
Basic CFLAGS for target builds:
CFLAGS="-mthumb -march=armv7e-m -mtune=cortex-m4 -mabi=aapcs \
-mfpu=fpv4-sp-d16 -mfloat-abi=hard -mfp16-format=ieee \
-Wa,-mimplicit-it=thumb"
Current vendor toolchain produces:
text data bss dec hex filename
208576 1112 27888 237576 3a008 _build/nrf52832_xxaa_s132.out
Updated toolchain using gcc 5.4.0, newlib 2.4.0, gdb 7.11.1 without libnano*
but with newlib-nano-formatted-io and newlib-nano-malloc enabled and -Os
plus -g debug symbols produces:
text data bss dec hex filename
129268 1820 28500 159588 26f64 _build/nrf52832_xxaa_s132.out
Updated toolchain using slightly more correct (and bloaty) debug flags, where
DEBUG_BLOAT = -Og -g3 produces:
text data bss dec hex filename
145780 1820 28548 176148 2b014 _build/nrf52832_xxaa_s132.out
Roll your own toolchain ftw!
|