]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding dfu-suffix signing support to build system
authorJacob Alexander <haata@kiibohd.com>
Mon, 2 Mar 2015 09:58:53 +0000 (01:58 -0800)
committerJacob Alexander <haata@kiibohd.com>
Mon, 2 Mar 2015 09:58:53 +0000 (01:58 -0800)
- If dfu-suffix is not found, a warning is given and the binary is not signed
- Unsigned binaries are still ok with the latest version of dfu-util

Lib/CMake/FindDFUSuffix.cmake [new file with mode: 0644]
Lib/CMake/build.cmake

diff --git a/Lib/CMake/FindDFUSuffix.cmake b/Lib/CMake/FindDFUSuffix.cmake
new file mode 100644 (file)
index 0000000..9aaa8f2
--- /dev/null
@@ -0,0 +1,40 @@
+# The module defines the following variables:
+#   DFU_SUFFIX_EXECUTABLE - path to ctags command line client
+#   DFU_SUFFIX_FOUND - true if the command line client was found
+#   DFU_SUFFIX_VERSION_STRING - the version of dfu-suffix found (since CMake 2.8.8)
+# Example usage:
+#   find_package( DFUSuffix )
+#   if( DFU_SUFFIX_FOUND )
+#     message("ctags found: ${DFU_SUFFIX_EXECUTABLE}")
+#   endif()
+
+find_program ( DFU_SUFFIX_EXECUTABLE
+       NAMES dfu-suffix
+       DOC "dfu-suffix executable"
+)
+mark_as_advanced ( DFU_SUFFIX_EXECUTABLE )
+
+if ( DFU_SUFFIX_EXECUTABLE )
+       execute_process ( COMMAND ${DFU_SUFFIX_EXECUTABLE} --version
+               OUTPUT_VARIABLE dfu_suffix_version
+               ERROR_QUIET
+               OUTPUT_STRIP_TRAILING_WHITESPACE
+       )
+
+       if ( dfu_suffix_version MATCHES "^dfu-suffix \\(dfu-util\\)" )
+               string ( REPLACE "\n" "" DFU_SUFFIX_VERSION_STRING ${dfu_suffix_version} )
+               string ( REPLACE "dfu-suffix (dfu-util) " "" DFU_SUFFIX_VERSION_STRING ${DFU_SUFFIX_VERSION_STRING} )
+               string ( REGEX REPLACE "Copyright .*$" "" DFU_SUFFIX_VERSION_STRING ${DFU_SUFFIX_VERSION_STRING} )
+       endif ()
+       unset ( dfu_suffix_version )
+endif ()
+
+# Handle the QUIETLY and REQUIRED arguments and set DFU_SUFFIX_FOUND to TRUE if
+# all listed variables are TRUE
+
+include ( FindPackageHandleStandardArgs )
+find_package_handle_standard_args ( DFU_SUFFIX
+       REQUIRED_VARS DFU_SUFFIX_EXECUTABLE
+       VERSION_VAR DFU_SUFFIX_VERSION_STRING
+)
+
index 676e55766951de56ef1c2f1dac3a7b4011012f2d..b3209bfa68ffc08434ebc3d46867483e95bd82b7 100644 (file)
@@ -1,6 +1,6 @@
 ###| CMAKE Kiibohd Controller Source Configurator |###
 #
-# Written by Jacob Alexander in 2011-2014 for the Kiibohd Controller
+# Written by Jacob Alexander in 2011-2015 for the Kiibohd Controller
 #
 # Released into the Public Domain
 #
@@ -46,12 +46,25 @@ endif ()
 
 
 #| Convert the .ELF into a .bin to load onto the McHCK
+#| Then sign using dfu-suffix (requries dfu-util)
 if ( DEFINED DFU )
+       # dfu-suffix is required to sign the dfu binary
+       find_package ( DFUSuffix )
+
        set( TARGET_BIN ${TARGET}.dfu.bin )
-       add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
-               COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
-               COMMENT "Creating dfu binary file:      ${TARGET_BIN}"
-       )
+       if ( DFU_SUFFIX_FOUND )
+               add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
+                       COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
+                       COMMAND ${DFU_SUFFIX_EXECUTABLE} --add ${TARGET_BIN} --vid ${BOOT_VENDOR_ID} --pid ${BOOT_PRODUCT_ID} 1> /dev/null
+                       COMMENT "Create and sign dfu bin file:  ${TARGET_BIN}"
+               )
+       else ()
+               message ( WARNING "DFU Binary has not been signed, requires dfu-suffix..." )
+               add_custom_command( TARGET ${TARGET_ELF} POST_BUILD
+                       COMMAND ${OBJ_COPY} ${BIN_FLAGS} ${TARGET_ELF} ${TARGET_BIN}
+                       COMMENT "Creating dfu binary file:      ${TARGET_BIN}"
+               )
+       endif ()
 endif ()