Switch to a new cortex-m4 compiler

This one is newer, so it supports a newer C++ standard. It's also
hermetic.

Also add a variant for building for some Kinetis-K chips with less RAM
that are used on fet12v2.

Change-Id: I9e50b6aae498e0c35acfedb846b3ada619a0e630
diff --git a/tools/BUILD b/tools/BUILD
index 3f3d4b2..3a75af3 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -29,6 +29,11 @@
 )
 
 config_setting(
+    name = "cpu_cortex_m4f_k22",
+    values = {"cpu": "cortex-m4f-k22"},
+)
+
+config_setting(
     name = "cpu_armhf",
     values = {"cpu": "armhf-debian"},
 )
@@ -56,6 +61,8 @@
 
 environment(name = "cortex-m4f")
 
+environment(name = "cortex-m4f-k22")
+
 environment_group(
     name = "cpus",
     defaults = [
@@ -67,5 +74,6 @@
         ":roborio",
         ":armhf-debian",
         ":cortex-m4f",
+        ":cortex-m4f-k22",
     ],
 )
diff --git a/tools/cpp/BUILD b/tools/cpp/BUILD
index 183d830..d541a8a 100644
--- a/tools/cpp/BUILD
+++ b/tools/cpp/BUILD
@@ -11,6 +11,7 @@
         "//tools:has_asan": [],
         "//tools:has_tsan": [],
         "//tools:cpu_cortex_m4f": [],
+        "//tools:cpu_cortex_m4f_k22": [],
         "//conditions:default": ["//third_party/gperftools:tcmalloc"],
     }),
 )
@@ -32,6 +33,7 @@
         "roborio|gcc": ":cc-compiler-roborio",
         "armhf-debian|clang": "cc-compiler-armhf-debian",
         "cortex-m4f|gcc": "cc-compiler-cortex-m4f",
+        "cortex-m4f-k22|gcc": "cc-compiler-cortex-m4f-k22",
     },
 )
 
@@ -214,18 +216,60 @@
     supports_param_files = 1,
 )
 
+filegroup(
+    name = "gcc_arm_none_eabi_none_files",
+    srcs = [
+        "//tools/cpp/gcc_arm_none_eabi:tool-wrappers",
+        "@gcc_arm_none_eabi//:compiler_pieces",
+    ],
+)
+
+filegroup(
+    name = "gcc_arm_none_eabi_compiler_files",
+    srcs = [
+        "//tools/cpp/gcc_arm_none_eabi:as",
+        "//tools/cpp/gcc_arm_none_eabi:gcc",
+        "//tools/cpp/gcc_arm_none_eabi:ld",
+    ],
+)
+
+filegroup(
+    name = "gcc_arm_none_eabi_linker_files",
+    srcs = [
+        "//motors/core:linkerscripts",
+        "//tools/cpp/gcc_arm_none_eabi:ar",
+        "//tools/cpp/gcc_arm_none_eabi:gcc",
+        "//tools/cpp/gcc_arm_none_eabi:ld",
+        "@gcc_arm_none_eabi//:compiler_pieces",
+    ],
+)
+
 cc_toolchain(
     name = "cc-compiler-cortex-m4f",
-    all_files = ":empty",
-    compiler_files = ":empty",
+    all_files = ":gcc_arm_none_eabi_none_files",
+    compiler_files = ":gcc_arm_none_eabi_compiler_files",
     cpu = "cortex-m4f",
     dwp_files = ":empty",
     dynamic_runtime_libs = [":empty"],
-    linker_files = "//motors/core:linkerscript",
+    linker_files = ":gcc_arm_none_eabi_linker_files",
+    objcopy_files = "//tools/cpp/gcc_arm_none_eabi:objcopy",
+    static_runtime_libs = [":empty"],
+    strip_files = "//tools/cpp/gcc_arm_none_eabi:strip",
+    supports_param_files = 1,
+)
+
+cc_toolchain(
+    name = "cc-compiler-cortex-m4f-k22",
+    all_files = ":gcc_arm_none_eabi_none_files",
+    compiler_files = ":gcc_arm_none_eabi_compiler_files",
+    cpu = "cortex-m4f-k22",
+    dwp_files = ":empty",
+    dynamic_runtime_libs = [":empty"],
+    linker_files = ":gcc_arm_none_eabi_linker_files",
     objcopy_files = ":empty",
     static_runtime_libs = [":empty"],
     strip_files = ":empty",
-    supports_param_files = 0,
+    supports_param_files = 1,
 )
 
 py_binary(
diff --git a/tools/cpp/CROSSTOOL b/tools/cpp/CROSSTOOL
index 9306652..0b1223e 100644
--- a/tools/cpp/CROSSTOOL
+++ b/tools/cpp/CROSSTOOL
@@ -23,6 +23,10 @@
   cpu: "cortex-m4f"
   toolchain_identifier: "cortex-m4f"
 }
+default_toolchain {
+  cpu: "cortex-m4f-k22"
+  toolchain_identifier: "cortex-m4f-k22"
+}
 toolchain {
   toolchain_identifier: "stub_armeabi-v7a"
   host_system_name: "armeabi-v7a"
@@ -817,47 +821,47 @@
   abi_libc_version: "cortex-m4f"
   tool_path {
     name: "ar"
-    path: "/usr/bin/arm-none-eabi-ar"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ar"
   }
   tool_path {
     name: "compat-ld"
-    path: "/usr/bin/arm-none-eabi-ld"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ld"
   }
   tool_path {
     name: "cpp"
-    path: "/usr/bin/arm-none-eabi-cpp"
+    path: "gcc_arm_none_eabi/arm-none-eabi-cpp"
   }
   tool_path {
     name: "dwp"
-    path: "/usr/bin/arm-none-eabi-dwp"
+    path: "gcc_arm_none_eabi/arm-none-eabi-dwp"
   }
   tool_path {
     name: "gcc"
-    path: "/usr/bin/arm-none-eabi-gcc"
+    path: "gcc_arm_none_eabi/arm-none-eabi-gcc"
   }
   tool_path {
     name: "gcov"
-    path: "/usr/bin/arm-none-eabi-gcov"
+    path: "gcc_arm_none_eabi/arm-none-eabi-gcov"
   }
   tool_path {
     name: "ld"
-    path: "/usr/bin/arm-none-eabi-ld"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ld"
   }
   tool_path {
     name: "nm"
-    path: "/usr/bin/arm-none-eabi-nm"
+    path: "gcc_arm_none_eabi/arm-none-eabi-nm"
   }
   tool_path {
     name: "objcopy"
-    path: "/usr/bin/arm-none-eabi-objcopy"
+    path: "gcc_arm_none_eabi/arm-none-eabi-objcopy"
   }
   tool_path {
     name: "objdump"
-    path: "/usr/bin/arm-none-eabi-objdump"
+    path: "gcc_arm_none_eabi/arm-none-eabi-objdump"
   }
   tool_path {
     name: "strip"
-    path: "/usr/bin/arm-none-eabi-strip"
+    path: "gcc_arm_none_eabi/arm-none-eabi-strip"
   }
   supports_gold_linker: false
   supports_thin_archives: false
@@ -887,6 +891,8 @@
   compiler_flag: "-Wformat=2"
   compiler_flag: "-Werror"
   compiler_flag: "-Wstrict-aliasing=2"
+  compiler_flag: "-Wno-misleading-indentation"
+  compiler_flag: "-Wno-int-in-bool-context"
   compiler_flag: "-Wdouble-promotion"
   compiler_flag: "-pipe"
   compiler_flag: "-g"
@@ -901,10 +907,10 @@
   linker_flag: "-fno-strict-aliasing"
   linker_flag: "--specs=nano.specs"
   linker_flag: "-lgcc"
-  linker_flag: "-lstdc++"
+  linker_flag: "-lstdc++_nano"
   linker_flag: "-lm"
-  linker_flag: "-lc"
-  linker_flag: "-Tmotors/core/mk64fx512.ld"
+  linker_flag: "-lc_nano"
+  linker_flag: "-Tmotors/core/kinetis_192k.ld"
   objcopy_embed_flag: "-I"
   objcopy_embed_flag: "binary"
   compilation_mode_flags {
@@ -974,7 +980,209 @@
       action: "c++-header-preprocessing"
       action: "c++-module-compile"
       flag_group {
-        flag: "--std=gnu++11"
+        flag: "--std=gnu++1y"
+        flag: "-fno-exceptions"
+        flag: "-fno-rtti"
+      }
+    }
+  }
+  feature {
+    name: "include_paths"
+    flag_set {
+      action: "preprocess-assemble"
+      action: "c-compile"
+      action: "c++-compile"
+      action: "c++-header-parsing"
+      action: "c++-header-preprocessing"
+      action: "c++-module-compile"
+      flag_group {
+        flag: "-iquote"
+        flag: "%{quote_include_paths}"
+        iterate_over: "quote_include_paths"
+      }
+      flag_group {
+        flag: "-I%{include_paths}"
+        iterate_over: "include_paths"
+      }
+      flag_group {
+        flag: "-I"
+        flag: "%{system_include_paths}"
+        iterate_over: "system_include_paths"
+      }
+    }
+  }
+}
+toolchain {
+  toolchain_identifier: "cortex-m4f-k22"
+  host_system_name: "local"
+  target_system_name: "cortex-m4f-k22"
+  target_cpu: "cortex-m4f-k22"
+  target_libc: "cortex-m4f-k22"
+  compiler: "gcc"
+  abi_version: "cortex-m4f-k22"
+  abi_libc_version: "cortex-m4f-k22"
+  tool_path {
+    name: "ar"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ar"
+  }
+  tool_path {
+    name: "compat-ld"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ld"
+  }
+  tool_path {
+    name: "cpp"
+    path: "gcc_arm_none_eabi/arm-none-eabi-cpp"
+  }
+  tool_path {
+    name: "dwp"
+    path: "gcc_arm_none_eabi/arm-none-eabi-dwp"
+  }
+  tool_path {
+    name: "gcc"
+    path: "gcc_arm_none_eabi/arm-none-eabi-gcc"
+  }
+  tool_path {
+    name: "gcov"
+    path: "gcc_arm_none_eabi/arm-none-eabi-gcov"
+  }
+  tool_path {
+    name: "ld"
+    path: "gcc_arm_none_eabi/arm-none-eabi-ld"
+  }
+  tool_path {
+    name: "nm"
+    path: "gcc_arm_none_eabi/arm-none-eabi-nm"
+  }
+  tool_path {
+    name: "objcopy"
+    path: "gcc_arm_none_eabi/arm-none-eabi-objcopy"
+  }
+  tool_path {
+    name: "objdump"
+    path: "gcc_arm_none_eabi/arm-none-eabi-objdump"
+  }
+  tool_path {
+    name: "strip"
+    path: "gcc_arm_none_eabi/arm-none-eabi-strip"
+  }
+  supports_gold_linker: false
+  supports_thin_archives: false
+  needsPic: false
+  compiler_flag: "-D__STDC_FORMAT_MACROS"
+  compiler_flag: "-D__STDC_CONSTANT_MACROS"
+  compiler_flag: "-D__STDC_LIMIT_MACROS"
+  compiler_flag: "-D__MK22FX512__"
+  compiler_flag: "-DF_CPU=120000000"
+  compiler_flag: "-Wl,--gc-sections"
+  compiler_flag: "-D__have_long32"
+  compiler_flag: "-fstack-protector"
+  compiler_flag: "-mcpu=cortex-m4"
+  compiler_flag: "-mfpu=fpv4-sp-d16"
+  compiler_flag: "-mthumb"
+  compiler_flag: "-mfloat-abi=hard"
+  compiler_flag: "-fno-strict-aliasing"
+  compiler_flag: "-fmessage-length=80"
+  compiler_flag: "-fmax-errors=20"
+  compiler_flag: "-Wall"
+  compiler_flag: "-Wextra"
+  compiler_flag: "-Wpointer-arith"
+  compiler_flag: "-Wcast-qual"
+  compiler_flag: "-Wwrite-strings"
+  compiler_flag: "-Wtype-limits"
+  compiler_flag: "-Wsign-compare"
+  compiler_flag: "-Wformat=2"
+  compiler_flag: "-Werror"
+  compiler_flag: "-Wstrict-aliasing=2"
+  compiler_flag: "-Wno-misleading-indentation"
+  compiler_flag: "-Wno-int-in-bool-context"
+  compiler_flag: "-Wdouble-promotion"
+  compiler_flag: "-pipe"
+  compiler_flag: "-g"
+  compiler_flag: "-fno-common"
+  compiler_flag: "-ffreestanding"
+  compiler_flag: "-fbuiltin"
+  linker_flag: "-no-canonical-prefixes"
+  linker_flag: "-mcpu=cortex-m4"
+  linker_flag: "-mfpu=fpv4-sp-d16"
+  linker_flag: "-mthumb"
+  linker_flag: "-mfloat-abi=hard"
+  linker_flag: "-fno-strict-aliasing"
+  linker_flag: "--specs=nano.specs"
+  linker_flag: "-lgcc"
+  linker_flag: "-lstdc++_nano"
+  linker_flag: "-lm"
+  linker_flag: "-lc_nano"
+  linker_flag: "-Tmotors/core/kinetis_128k.ld"
+  objcopy_embed_flag: "-I"
+  objcopy_embed_flag: "binary"
+  compilation_mode_flags {
+    mode: OPT
+    compiler_flag: "-O2"
+    compiler_flag: "-finline-functions"
+    compiler_flag: "-ffast-math"
+    compiler_flag: "-funroll-loops"
+    compiler_flag: "-DNDEBUG"
+    compiler_flag: "-ffunction-sections"
+    linker_flag: "-Wl,--gc-sections"
+  }
+  linking_mode_flags {
+    mode: FULLY_STATIC
+  }
+  cxx_builtin_include_directory: "/usr/lib/gcc/arm-none-eabi/4.8/include"
+  cxx_builtin_include_directory: "/usr/lib/gcc/arm-none-eabi/4.8/include-fixed"
+  cxx_builtin_include_directory: "/usr/lib/arm-none-eabi/include"
+  cxx_builtin_include_directory: "/usr/include/newlib"
+  builtin_sysroot: ""
+  unfiltered_cxx_flag: "-no-canonical-prefixes"
+  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
+  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
+  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
+  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""
+  supports_normalizing_ar: false
+  supports_start_end_lib: false
+  supports_interface_shared_objects: false
+  supports_incremental_linker: false
+  supports_fission: false
+  feature {
+    name: "dbg"
+    flag_set {
+      action: "preprocess-assemble"
+      action: "c-compile"
+      action: "c++-compile"
+      action: "c++-header-parsing"
+      action: "c++-header-preprocessing"
+      action: "c++-module-compile"
+      flag_group {
+        flag: "-fno-omit-frame-pointer"
+      }
+    }
+    implies: "all_modes"
+  }
+  feature {
+    name: "opt"
+    implies: "all_modes"
+  }
+  feature {
+    name: "fastbuild"
+    implies: "all_modes"
+  }
+  feature {
+    name: "all_modes"
+    flag_set {
+      action: "preprocess-assemble"
+      action: "assemble"
+      action: "c-compile"
+      flag_group {
+        flag: "--std=gnu99"
+      }
+    }
+    flag_set {
+      action: "c++-compile"
+      action: "c++-header-parsing"
+      action: "c++-header-preprocessing"
+      action: "c++-module-compile"
+      flag_group {
+        flag: "--std=gnu++1y"
         flag: "-fno-exceptions"
         flag: "-fno-rtti"
       }
diff --git a/tools/cpp/cortex_m4f_crosstool.pb b/tools/cpp/cortex_m4f_crosstool.pb
index ec02440..cd854fd 100644
--- a/tools/cpp/cortex_m4f_crosstool.pb
+++ b/tools/cpp/cortex_m4f_crosstool.pb
@@ -17,21 +17,21 @@
   target_system_name: "%NAME%"
   toolchain_identifier: "%NAME%"
 
-  tool_path { name: "ar" path: "/usr/bin/arm-none-eabi-ar" }
-  tool_path { name: "compat-ld" path: "/usr/bin/arm-none-eabi-ld" }
-  tool_path { name: "cpp" path: "/usr/bin/arm-none-eabi-cpp" }
-  tool_path { name: "dwp" path: "/usr/bin/arm-none-eabi-dwp" }
-  tool_path { name: "gcc" path: "/usr/bin/arm-none-eabi-gcc" }
-  tool_path { name: "gcov" path: "/usr/bin/arm-none-eabi-gcov" }
+  tool_path { name: "ar" path: "gcc_arm_none_eabi/arm-none-eabi-ar" }
+  tool_path { name: "compat-ld" path: "gcc_arm_none_eabi/arm-none-eabi-ld" }
+  tool_path { name: "cpp" path: "gcc_arm_none_eabi/arm-none-eabi-cpp" }
+  tool_path { name: "dwp" path: "gcc_arm_none_eabi/arm-none-eabi-dwp" }
+  tool_path { name: "gcc" path: "gcc_arm_none_eabi/arm-none-eabi-gcc" }
+  tool_path { name: "gcov" path: "gcc_arm_none_eabi/arm-none-eabi-gcov" }
   # C(++) compiles invoke the compiler (as that is the one knowing where
   # to find libraries), but we provide LD so other rules can invoke the linker.
-  tool_path { name: "ld" path: "/usr/bin/arm-none-eabi-ld" }
-  tool_path { name: "nm" path: "/usr/bin/arm-none-eabi-nm" }
-  tool_path { name: "objcopy" path: "/usr/bin/arm-none-eabi-objcopy" }
+  tool_path { name: "ld" path: "gcc_arm_none_eabi/arm-none-eabi-ld" }
+  tool_path { name: "nm" path: "gcc_arm_none_eabi/arm-none-eabi-nm" }
+  tool_path { name: "objcopy" path: "gcc_arm_none_eabi/arm-none-eabi-objcopy" }
   objcopy_embed_flag: "-I"
   objcopy_embed_flag: "binary"
-  tool_path { name: "objdump" path: "/usr/bin/arm-none-eabi-objdump" }
-  tool_path { name: "strip" path: "/usr/bin/arm-none-eabi-strip" }
+  tool_path { name: "objdump" path: "gcc_arm_none_eabi/arm-none-eabi-objdump" }
+  tool_path { name: "strip" path: "gcc_arm_none_eabi/arm-none-eabi-strip" }
   linking_mode_flags { mode: FULLY_STATIC }
 
   # TODO(bazel-team): In theory, the path here ought to exactly match the path
@@ -84,7 +84,7 @@
       action: "c++-header-preprocessing"
       action: "c++-module-compile"
       flag_group {
-        flag: "--std=gnu++11"
+        flag: "--std=gnu++1y"
         flag: "-fno-exceptions"
         flag: "-fno-rtti"
       }
@@ -137,10 +137,10 @@
 
   # Pretty much everything needs this, including parts of the glibc STL...
   linker_flag: "-lgcc"
-  linker_flag: "-lstdc++"
+  linker_flag: "-lstdc++_nano"
   linker_flag: "-lm"
-  linker_flag: "-lc"
-  linker_flag: "-Tmotors/core/mk64fx512.ld"
+  linker_flag: "-lc_nano"
+  linker_flag: "-T%LINKER_SCRIPT%"
 
   compiler_flag: "-fmessage-length=80"
   compiler_flag: "-fmax-errors=20"
@@ -156,6 +156,10 @@
   compiler_flag: "-Werror"
   compiler_flag: "-Wstrict-aliasing=2"
 
+  # TODO(Brian): Drop these once we upgrade Eigen.
+  compiler_flag: "-Wno-misleading-indentation"
+  compiler_flag: "-Wno-int-in-bool-context"
+
   # Be annoying about using doubles places we probably didn't mean to, because
   # the FPU only does single-precision.
   compiler_flag: "-Wdouble-promotion"
diff --git a/tools/cpp/gcc_arm_none_eabi/BUILD b/tools/cpp/gcc_arm_none_eabi/BUILD
new file mode 100644
index 0000000..485263f
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/BUILD
@@ -0,0 +1,79 @@
+package(default_visibility = ["//tools/cpp:__pkg__"])
+
+filegroup(
+    name = "gcc",
+    srcs = [
+        "arm-none-eabi-gcc",
+        "@gcc_arm_none_eabi//:gcc",
+    ],
+)
+
+filegroup(
+    name = "ar",
+    srcs = [
+        "arm-none-eabi-ar",
+        "@gcc_arm_none_eabi//:ar",
+    ],
+)
+
+filegroup(
+    name = "ld",
+    srcs = [
+        "arm-none-eabi-ld",
+        "@gcc_arm_none_eabi//:ld",
+    ],
+)
+
+filegroup(
+    name = "nm",
+    srcs = [
+        "arm-none-eabi-nm",
+        "@gcc_arm_none_eabi//:nm",
+    ],
+)
+
+filegroup(
+    name = "objcopy",
+    srcs = [
+        "arm-none-eabi-objcopy",
+        "@gcc_arm_none_eabi//:objcopy",
+    ],
+)
+
+filegroup(
+    name = "objdump",
+    srcs = [
+        "arm-none-eabi-objdump",
+        "@gcc_arm_none_eabi//:objdump",
+    ],
+)
+
+filegroup(
+    name = "strip",
+    srcs = [
+        "arm-none-eabi-strip",
+        "@gcc_arm_none_eabi//:strip",
+    ],
+)
+
+filegroup(
+    name = "as",
+    srcs = [
+        "arm-none-eabi-as",
+        "@gcc_arm_none_eabi//:as",
+    ],
+)
+
+filegroup(
+    name = "tool-wrappers",
+    srcs = [
+        ":ar",
+        ":as",
+        ":gcc",
+        ":ld",
+        ":nm",
+        ":objcopy",
+        ":objdump",
+        ":strip",
+    ],
+)
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ar b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ar
new file mode 100755
index 0000000..377d32e
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ar
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-ar \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-ar \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-as b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-as
new file mode 100755
index 0000000..09c589c
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-as
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-as \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-as \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-cpp b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-cpp
new file mode 100755
index 0000000..a3ff222
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-cpp
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-cpp \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-cpp \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcc b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcc
new file mode 100755
index 0000000..6ff0448
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcc
@@ -0,0 +1,6 @@
+#!/bin/bash --norc
+
+PATH="${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/lib/gcc/arm-none-eabi/7.3.1:$PATH" \
+	exec \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-gcc \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcov b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcov
new file mode 100755
index 0000000..c6ae49e
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-gcov
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-gcov \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-gcov \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ld b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ld
new file mode 100755
index 0000000..7115b82
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-ld
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-ld \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-ld \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-nm b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-nm
new file mode 100755
index 0000000..7b1f4cd
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-nm
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-nm \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-nm \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objcopy b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objcopy
new file mode 100755
index 0000000..6f27cc4
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objcopy
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-objcopy \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-objcopy \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objdump b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objdump
new file mode 100755
index 0000000..a677573
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-objdump
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-objdump \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-objdump \
+	"$@"
diff --git a/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-strip b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-strip
new file mode 100755
index 0000000..f11bd20
--- /dev/null
+++ b/tools/cpp/gcc_arm_none_eabi/arm-none-eabi-strip
@@ -0,0 +1,5 @@
+#!/bin/bash --norc
+
+exec -a arm-none-eabi-strip \
+	${BAZEL_OUTPUT_ROOT}external/gcc_arm_none_eabi/bin/arm-none-eabi-strip \
+	"$@"
diff --git a/tools/cpp/gen_crosstool.py b/tools/cpp/gen_crosstool.py
index af28c56..547faf0 100644
--- a/tools/cpp/gen_crosstool.py
+++ b/tools/cpp/gen_crosstool.py
@@ -47,6 +47,13 @@
       '%NAME%': 'cortex-m4f',
       '%CPU%': '__MK64FX512__',
       '%F_CPU%': '120000000',
+      '%LINKER_SCRIPT%': 'motors/core/kinetis_192k.ld',
+      })
+  add_m4f_toolchain(crosstool_proto.toolchain.add(), m4f_proto, {
+      '%NAME%': 'cortex-m4f-k22',
+      '%CPU%': '__MK22FX512__',
+      '%F_CPU%': '120000000',
+      '%LINKER_SCRIPT%': 'motors/core/kinetis_128k.ld',
       })
 
   with open(args[2], 'w') as f:
diff --git a/tools/cpp/static_crosstool.pb b/tools/cpp/static_crosstool.pb
index 99a36f9..5cfe31c 100644
--- a/tools/cpp/static_crosstool.pb
+++ b/tools/cpp/static_crosstool.pb
@@ -27,6 +27,11 @@
   toolchain_identifier: "cortex-m4f"
 }
 
+default_toolchain {
+  cpu: "cortex-m4f-k22"
+  toolchain_identifier: "cortex-m4f-k22"
+}
+
 toolchain {
   abi_version: "armeabi-v7a"
   abi_libc_version: "armeabi-v7a"