diff --git a/CMakeLists.txt b/CMakeLists.txt index fd79ac10e..95e27d215 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ cmake_policy(SET CMP0042 NEW) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) ### @@ -25,10 +26,10 @@ option(STLINK_INSTALL_UDEV_RULES "Install udev rules files" ON) option(STLINK_INSTALL_MODPROBE_CONF "Install modprobe conf files" ON) option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF) -# Determine project version +## Determine project version include(${CMAKE_MODULE_PATH}/get_version.cmake) -# Set C build flags +## Set C build flags if (NOT MSVC) include(${CMAKE_MODULE_PATH}/c_flags.cmake) else () @@ -39,11 +40,7 @@ else () set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT "/MT /Zi /O2 /Ob1 /D NDEBUG") endif () - -# ==== - -#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) - +## Set installation directories for libraries if (IS_DIRECTORY ${LIB_INSTALL_DIR}) set(LIB_INSTALL_DIR ${LIB_INSTALL_DIR} CACHE PATH "Main library directory") set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}") @@ -52,6 +49,7 @@ else () set(STLINK_LIBRARY_PATH "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}") endif () +## Set installation directories for header files if (IS_DIRECTORY ${INCLUDE_INSTALL_DIR}) set(INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR} CACHE PATH "Main include directory") set(STLINK_INCLUDE_PATH "${INCLUDE_INSTALL_DIR}") @@ -67,11 +65,14 @@ endif () find_package(libusb REQUIRED) +## Package configuration (pkg-config) on unix-based systems if (NOT WIN32 AND NOT CMAKE_CROSSCOMPILING) + add_subdirectory(cmake/pkgconfig) find_package(PkgConfig) pkg_check_modules(GTK3 gtk+-3.0) endif () +## Check for system-specific additional header files and libraries include(CheckIncludeFile) CHECK_INCLUDE_FILE(sys/mman.h STLINK_HAVE_SYS_MMAN_H) @@ -93,44 +94,52 @@ else () set(SSP_LIB "") endif () -if (CMAKE_BUILD_TYPE STREQUAL "") - set(CMAKE_BUILD_TYPE "Debug") -endif () -if (${CMAKE_BUILD_TYPE} MATCHES "Debug") - include(CTest) -endif () +### +# Main build process +### + +## Define include directories to avoid absolute paths for header defines +include_directories(${LIBUSB_INCLUDE_DIR}) + +# ==== +include_directories(include) ### TODO: Clean this up... +include_directories(${PROJECT_BINARY_DIR}/include/stlink) +include_directories(include/stlink) +include_directories(include/stlink/tools) +# ==== + +include_directories(src) set(STLINK_HEADERS - include/stlink.h - include/stlink/usb.h - include/stlink/sg.h - include/stlink/logging.h - include/stlink/mmap.h - include/stlink/chipid.h - include/stlink/flash_loader.h - ) + include/stlink.h + include/stlink/backend.h + include/stlink/chipid.h + include/stlink/commands.h + include/stlink/flash_loader.h + include/stlink/reg.h + src/logging.h + src/md5.h + src/sg.h + src/usb.h + ) set(STLINK_SOURCE - src/chipid.c - src/common.c - src/usb.c - src/sg.c - src/logging.c - src/flash_loader.c - src/md5.c - ) + src/common.c + src/chipid.c + src/flash_loader.c + src/logging.c + src/md5.c + src/sg.c + src/usb.c + ) if (WIN32 OR MINGW OR MSYS) + include_directories(src/mingw) set(STLINK_SOURCE "${STLINK_SOURCE};src/mmap.c;src/mingw/mingw.c") - set(STLINK_HEADERS "${STLINK_HEADERS};src/mingw/mingw.h") + set(STLINK_HEADERS "${STLINK_HEADERS};src/mmap.h;src/mingw/mingw.h") endif () -include_directories(${LIBUSB_INCLUDE_DIR}) -include_directories(include) -include_directories(${PROJECT_BINARY_DIR}/include) -include_directories(src/mingw) - if (MSVC) include_directories(src/win32) include_directories(src/getopt) @@ -138,6 +147,11 @@ if (MSVC) add_definitions(-DHAVE_STRING_H -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS /wd4710) endif () +## Include test execution for test-targets for target Debug +if (${CMAKE_BUILD_TYPE} MATCHES "Debug") + include(CTest) +endif () + ### # Shared library @@ -150,14 +164,15 @@ else (WIN32) endif () add_library( - ${STLINK_LIB_SHARED} SHARED - ${STLINK_HEADERS} # header files for ide projects generated by cmake - ${STLINK_SOURCE} - ) + ${STLINK_LIB_SHARED} SHARED + ${STLINK_HEADERS} # header files for ide projects generated by cmake + ${STLINK_SOURCE} + ) + target_link_libraries( - ${STLINK_LIB_SHARED} - ${LIBUSB_LIBRARY} - ) + ${STLINK_LIB_SHARED} + ${LIBUSB_LIBRARY} + ) set(STLINK_SHARED_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) @@ -165,7 +180,8 @@ message(STATUS "STLINK_LIB_SHARED: ${STLINK_LIB_SHARED}") message(STATUS "PROJECT_VERSION_MAJOR: ${PROJECT_VERSION_MAJOR}") message(STATUS "VERSION: ${STLINK_SHARED_VERSION}") -set_target_properties(${STLINK_LIB_SHARED} PROPERTIES +set_target_properties( + ${STLINK_LIB_SHARED} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} VERSION ${STLINK_SHARED_VERSION} ) @@ -184,7 +200,7 @@ else () target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY} ${SSP_LIB}) endif () -install(TARGETS ${STLINK_LIB_SHARED} DESTINATION ${STLINK_LIBRARY_PATH}) ### TODO: Check path +install(TARGETS ${STLINK_LIB_SHARED} DESTINATION ${STLINK_LIBRARY_PATH}) ### @@ -199,6 +215,11 @@ add_library( ${STLINK_SOURCE} ) +set_target_properties( + ${STLINK_LIB_STATIC} PROPERTIES + OUTPUT_NAME ${PROJECT_NAME} + ) + # Link static library with Apple macOS libraries if (APPLE) find_library(ObjC objc) @@ -207,36 +228,42 @@ if (APPLE) target_link_libraries(${STLINK_LIB_STATIC} ${CoreFoundation} ${IOKit} ${ObjC} ${SSP_LIB}) endif () -if (WIN32 OR MINGW OR MSYS) ### TODO: MinGW OR MSYS on Linux +if (WIN32 OR MINGW OR MSYS) target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} wsock32 ws2_32 ${SSP_LIB}) else () target_link_libraries(${STLINK_LIB_STATIC} ${LIBUSB_LIBRARY} ${SSP_LIB}) endif () -set_target_properties(${STLINK_LIB_STATIC} PROPERTIES OUTPUT_NAME ${PROJECT_NAME}) - if (STLINK_STATIC_LIB) - install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}) ### TODO: Check path + install(TARGETS ${STLINK_LIB_STATIC} ARCHIVE DESTINATION ${STLINK_LIBRARY_PATH}) endif () ### -# Tools +# Build toolset executables ### +set(ST-UTIL_SOURCES src/st-util/gdb-remote.c src/st-util/gdb-server.c src/st-util/semihosting.c) + +if (MSVC) + # Add getopt to sources + set(ST-UTIL_SOURCES "${ST-UTIL_SOURCES};src/getopt/getopt.c") +endif () + add_executable(st-flash src/tools/flash.c src/tools/flash_opts.c) add_executable(st-info src/tools/info.c) +add_executable(st-util ${ST-UTIL_SOURCES}) if (WIN32 OR APPLE) target_link_libraries(st-flash ${STLINK_LIB_STATIC} ${SSP_LIB}) target_link_libraries(st-info ${STLINK_LIB_STATIC} ${SSP_LIB}) + target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB}) else () target_link_libraries(st-flash ${STLINK_LIB_SHARED} ${SSP_LIB}) target_link_libraries(st-info ${STLINK_LIB_SHARED} ${SSP_LIB}) + target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB}) endif () -install(TARGETS st-flash st-info RUNTIME DESTINATION bin) ### TODO: Check path - if (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (STLINK_INSTALL_MODPROBE_CONF) install(FILES etc/modprobe.d/stlink_v1.conf DESTINATION ${STLINK_MODPROBED_DIR}/) @@ -247,27 +274,23 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux") endif () endif () -add_subdirectory(src/gdbserver) -add_subdirectory(src/stlink-gui) - +install(TARGETS st-flash DESTINATION bin) +install(TARGETS st-info DESTINATION bin) +install(TARGETS st-util DESTINATION bin) ### -# Others +# Additional build tasks ### -add_subdirectory(include) ### TODO: Check path -add_subdirectory(doc/man) -add_subdirectory(tests) - +# ==== +add_subdirectory(include) # contains subordinate CMakeLists for version config and old header includes + ### TODO: Clean this up ... # ==== - -### -# Package build -### - -add_subdirectory(cmake/packaging) -include(cmake/packaging/cpack_config.cmake) +add_subdirectory(src/stlink-gui) # contains subordinate CMakeLists to build GUI +add_subdirectory(tests) # contains subordinate CMakeLists to build test executables +add_subdirectory(doc/man) # contains subordinate CMakeLists to generate manpages +add_subdirectory(cmake/packaging) # contains subordinate CMakeLists to build packages ### diff --git a/LICENSE.md b/LICENSE.md index 9c3b59f0f..4cb795b18 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2020, The stlink project (github.com/stlink-org/stlink) & "Capt'ns Missing Link" authors. +Copyright (c) 2020, stlink-org All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/Makefile b/Makefile index 444f1920b..74a4fece5 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ help: @echo " debug: Run a debug build" @echo " release: Run a release build" @echo " install: Install release build" + @echo " uninstall: Uninstall release build" @echo " package: Package release build" @echo " lint: Lint check all source-code" @echo " test: Build and run tests" @@ -35,11 +36,16 @@ install: build/Release @echo "[INSTALL] Release" @$(MAKE) -C build/Release install +uninstall: build/Release + @echo "[UNINSTALL] Release" + @$(MAKE) -C build/Release uninstall + package: build/Release @echo "[PACKAGE] Release" @$(MAKE) -C build/Release package test: debug + @echo "[TEST]" @$(MAKE) -C build/Debug test build/Debug: diff --git a/cmake/modules/Find7zip.cmake b/cmake/modules/Find7zip.cmake deleted file mode 100644 index 83eb912d4..000000000 --- a/cmake/modules/Find7zip.cmake +++ /dev/null @@ -1,7 +0,0 @@ -# Find7zip.cmake -# Detect 7zip file archiver on Windows systems to extract (zip-)archives - -find_program( - ZIP_EXECUTABLE NAMES 7z.exe p7zip - HINTS "C:\\Program Files\\7-Zip\\" "C:\\Program Files (x86)\\7-Zip\\" -) diff --git a/cmake/modules/Findlibusb.cmake b/cmake/modules/Findlibusb.cmake index 13f70d7b7..898820033 100644 --- a/cmake/modules/Findlibusb.cmake +++ b/cmake/modules/Findlibusb.cmake @@ -73,7 +73,6 @@ elseif (WIN32) # Windows if (NOT LIBUSB_FOUND OR EXISTS "/etc/debian_version") # Preparations for installing libusb library - find_package(7zip REQUIRED) set(LIBUSB_WIN_VERSION 1.0.23) # set libusb version set(LIBUSB_WIN_ARCHIVE libusb-${LIBUSB_WIN_VERSION}.7z) set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_BINARY_DIR}/${LIBUSB_WIN_ARCHIVE}) @@ -92,17 +91,11 @@ elseif (WIN32) # Windows file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}) - # Extract libusb package - if (${ZIP_EXECUTABLE} MATCHES "p7zip") - execute_process( - COMMAND ${ZIP_EXECUTABLE} -d ${LIBUSB_WIN_ARCHIVE_PATH} - WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER} - ) - else () - execute_process( - COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER} - ) # <-- Note the absence of a space character following the -o option! - endif () + # Extract libusb package with cmake + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar xv ${LIBUSB_WIN_ARCHIVE_PATH} + WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER} + ) # Find path to libusb library FIND_PATH( diff --git a/cmake/packaging/CMakeLists.txt b/cmake/packaging/CMakeLists.txt index e831f611f..431c85d2d 100644 --- a/cmake/packaging/CMakeLists.txt +++ b/cmake/packaging/CMakeLists.txt @@ -2,3 +2,5 @@ add_subdirectory(debian) add_subdirectory(fedora) add_subdirectory(opensuse) add_subdirectory(windows) + +include(cpack_config.cmake) diff --git a/cmake/packaging/debian/copyright b/cmake/packaging/debian/copyright index 7a6d585c5..4a7b110ae 100644 --- a/cmake/packaging/debian/copyright +++ b/cmake/packaging/debian/copyright @@ -2,173 +2,156 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: stlink Upstream-Contact: Luca Bocassi Source: https://github.com/stlink-org/stlink - -Files: * -Copyright: 2011-2018 agpanarin - 2011-2018 Alexey Cherevatenko - 2011-2018 Anatoli - 2011-2018 Andrea Mucignat - 2011-2018 Andrew 'Necromant' Andrianov - 2011-2018 Andrey Yurovsky - 2011-2018 Andy Isaacson - 2011-2018 Áron RADICS - 2011-2018 A Sheaff - 2011-2018 Björn Hauffe - 2011-2018 bob - 2011-2018 Breton M. Saunders - 2011-2018 Bruno Dal Bo - 2011-2018 Burns - 2011-2018 Chris Dew - 2011-2018 Chris Hiszpanski - 2011-2018 Chris Li - 2011-2018 Chris Samuelson - 2011-2018 Christophe Levantis - 2011-2018 Craig Lilley - 2011-2018 dandev37 - 2011-2018 Dan Hepler - 2011-2018 Daniel Campoverde [alx741] - 2011-2018 Daniel O'Connor - 2011-2018 Dave Flogeras - 2011-2018 Dave Murphy - 2011-2018 Dave Vandervies - 2011-2018 Denis Fokin - 2011-2018 Denis Osterland - 2011-2018 Dmitry Bravikov - 2011-2018 Efe Can İçöz - 2011-2018 Ethan Zonca - 2011-2018 Fabien Chouteau - 2011-2018 Fabien Le Mentec - 2011-2018 fhars - 2011-2018 Friedrich Beckmann - 2011-2018 Geoffrey Brown - 2011-2018 George Talusan - 2011-2018 Georg von Zengen - 2011-2018 giuseppe barba - 2011-2018 Greg Alexander - 2011-2018 Greg Meiste - 2011-2018 Hakkavélin - 2011-2018 htk - 2011-2018 Ian Griffiths <6thimage@gmail.com> - 2011-2018 Jack Peel - 2011-2018 Jakub Tyszkowski - 2011-2018 Jan Sarenik - 2011-2018 Jean-Luc Béchennec - 2011-2018 Jean-Marie Lemetayer - 2011-2018 Jeff Kent - 2011-2018 Jeffrey Nelson - 2011-2018 Jens Hoffmann - 2011-2018 Jerome Lambourg - 2011-2018 Jerry Jacobs - 2011-2018 Jim Paris - 2011-2018 Jiří Netolický - 2011-2018 jnosky - 2011-2018 jnosky - 2011-2018 JohannesTaelman - 2011-2018 Jonas Danielsson - 2011-2018 Jonas Norling - 2011-2018 Josh Bialkowski - 2011-2018 Karl Palsson - 2011-2018 kevin - 2011-2018 Kyle Manna - 2011-2018 Lari Lehtomäki - 2011-2018 le mentec fabien - 2011-2018 Martin Nowak - 2011-2018 Matteo Collina - 2011-2018 Max Chen - 2011-2018 Maxime Coquelin - 2011-2018 Maxime Vincent - 2011-2018 Michael Pratt - 2011-2018 Michael Sparmann - 2011-2018 Mike Szczys - 2011-2018 mlundinse - 2011-2018 mux - 2011-2018 Ned Konz - 2011-2018 Nic McDonald - 2011-2018 Nicolas Schodet - 2011-2018 Nikolay - 2011-2018 nullsub - 2011-2018 Olivier Croquette - 2011-2018 Olivier Gay - 2011-2018 Onno Kortmann - 2011-2018 orangeudav - 2011-2018 Pavel Kirienko - 2011-2018 Pekka Nikander - 2011-2018 Pete - 2011-2018 Peter Zotov - 2011-2018 Petteri Aimonen - 2011-2018 Piotr Haber - 2011-2018 Rene Hopf - 2011-2018 Robin Kreis - 2011-2018 Rob Spanton - 2011-2018 Rytis Karpuska - 2011-2018 Sean Simmons - 2011-2018 Sergey Alirzaev - 2011-2018 Simon Wright - 2011-2018 Stany MARCEL - 2011-2018 Stefan Misik - 2011-2018 Sven Wegener - 2011-2018 Tectu - 2011-2018 tekaikko - 2011-2018 texane - 2011-2018 Theodore A. Roth - 2011-2018 Thomas Gärtner - 2011-2018 Tobias Badertscher - 2011-2018 Tom de Boer - 2011-2018 Tristan Gingold - 2011-2018 Uli Köhler - 2011-2018 Uwe Bonnes - 2011-2018 Vadim Kaushan - 2011-2018 Vegard Storheil Eriksen - 2011-2018 Viacheslav Dobromyslov - 2011-2018 Victor Mayoral Vilches - 2011-2018 Wojciech A. Koszek - 2011-2018 Woodrow Douglass - 2011-2018 The "Capt'ns Missing Link" Authors. +Disclaimer: +Comment: License: BSD-3-clause - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - . - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of Intel Corporation nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - . - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Files: flashloaders/stm32l0x.s - flashloaders/stm32lx.s -Copyright: 2010 Spencer Oliver - 2011 Øyvind Harboe - 2011 Clement Burin des Roziers -License: GPL-2+ - This package is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - . - This package is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - . - You should have received a copy of the GNU General Public License - along with this program. If not, see - . - On Debian systems, the complete text of the GNU General - Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + . + 1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + 3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + . + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +Files: * +Copyright: 2011-2020 stlink-org + Martin Capitanio [capnm] + Fabien Le Mentec [texane] + Jerry Jacobs [xor-gate] + [Nightwalker-87] + . + Alexey Cherevatenko + Alexey Panarin + Anatoli Klassen [dev26th] + Andrea Mucignat + Andrew Andrianov [necromant] + Andrey Yurovsky + Andy Isaacson + Áron Radics + A. Sheaff + Björn Hauffe + Ihor Bobalo + Breton M. Saunders + Bruno Dal Bo + Burns Fisher + Chris Dew + Chris Hiszpanski + Chris Li + Chris Samuelson + Christian Deussen [nullsub] + Christophe Levantis + Craig Lilley + Dan Dev + Dan Hepler + Daniel Campoverde [alx741] + Daniel O'Connor + Dave Flogeras + Dave Murphy [WinterMute] + Dave Vandervies [dj3vande] + Denis Fokin + Denis Osterland + Dmitry Bravikov [bravikov] + Efe Can İçöz + Ethan Zonca + Fabien Chouteau + Florian Hars + Friedrich Beckmann + Geoffrey Brown + George Talusan [gtalusan] + Georg von Zengen + Giuseppe Barba + Greg Alexander [galexander1] + Greg Meiste [meisteg] + Guillaume Revaillot [grevaillot] + Hakkavélin + Halt Hammerzeit + htk + Ian Griffiths + Jack Peel + Jakub Tyszkowski + Jan Sarenik + Jean-Luc Béchennec + Jean-Marie Lemetayer + Jeff Kent + Jeffrey Nelson + Jens Hoffmann + Jerome Lambourg + Jim Paris + Jiří Netolický + Jerry Nosky [jnosky] + Johannes Taelman + Jonas Danielsson + Jonas Norling + Josh Bialkowski + Karl Palsson [karlp] + Kevlar Harness + Kyle Manna + Lari Lehtomäki + Martin Nowak + Matteo Collina + Max Chen + Maxime Coquelin [mcoquelin-stm32] + Maxime Vincent + Michael Pratt [prattmic] + Michael Sparmann + Mike Szczys + Magnus Lundin [mlu] + mux + Ned Konz + Nic McDonald + Nicolas Schodet + Oleksiy Slyshyk [slyshykO] + Olivier Croquette + Olivier Gay + Onno Kortmann + orangeudav + Pavel Kirienko + Pekka Nikander + Pete Nelson + Peter Zotov + Petteri Aimonen + Piotr Haber + Rene Hopf [rene-dev] + Robin Kreis + Roger Wolff [rewolff] + Rob Spanton + Rytis Karpuska + Sean Simmons + Sergey Alirzaev + Simon Wright + Stany Marcel + Stefan Misik + Sven Wegener + Joel Bodenmann [Tectu] + Tuomo Kaikkonen + Theodore A. Roth + Thomas Gärtner + Tobias Badertscher + Tom de Boer + Tristan Gingold + Uli Köhler + Uwe Bonnes [UweBonnes] + Vadim Kaushan + Vasiliy Glazov [Vascom] + Vegard Storheil Eriksen + Viacheslav Dobromyslov + Victor Mayoral Vilches + William Ransohoff [WRansohoff] + Wojciech A. Koszek + Woodrow Douglass + Xim [chenguokai] + ... and others diff --git a/cmake/pkgconfig/CMakeLists.txt b/cmake/pkgconfig/CMakeLists.txt new file mode 100644 index 000000000..53870fee4 --- /dev/null +++ b/cmake/pkgconfig/CMakeLists.txt @@ -0,0 +1,15 @@ +set(PKG_CONFIG_LIBDIR "\${prefix}/lib/\${deb_host_multiarch}") +set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/\${deb_host_multiarch}/${PROJECT_NAME}") +set(PKG_CONFIG_LIBS "-L\${libdir} -l:libstlink.so.${PROJECT_VERSION_MAJOR}") +set(PKG_CONFIG_CFLAGS "-I\${includedir}") +set(PKG_CONFIG_REQUIRES "libusb-1.0") + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.pc.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + ) + +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + DESTINATION ${STLINK_LIBRARY_PATH}/pkgconfig + ) diff --git a/debian/pkg-config/pkg-config.pc.cmake b/cmake/pkgconfig/pkgconfig.pc.cmake similarity index 99% rename from debian/pkg-config/pkg-config.pc.cmake rename to cmake/pkgconfig/pkgconfig.pc.cmake index c00eb070e..4f881daec 100644 --- a/debian/pkg-config/pkg-config.pc.cmake +++ b/cmake/pkgconfig/pkgconfig.pc.cmake @@ -1,10 +1,11 @@ +prefix=${CMAKE_INSTALL_PREFIX} deb_host_multiarch=${CMAKE_LIBRARY_PATH} +libdir=${PKG_CONFIG_LIBDIR} +includedir=${PKG_CONFIG_INCLUDEDIR} + Name: ${PROJECT_NAME} Description: ${PROJECT_DESCRIPTION} Version: ${PROJECT_VERSION} -Requires: ${PKG_CONFIG_REQUIRES} -prefix=${CMAKE_INSTALL_PREFIX} -includedir=${PKG_CONFIG_INCLUDEDIR} -libdir=${PKG_CONFIG_LIBDIR} Libs: ${PKG_CONFIG_LIBS} Cflags: ${PKG_CONFIG_CFLAGS} +Requires: ${PKG_CONFIG_REQUIRES} diff --git a/debian/pkg-config/CMakeLists.txt b/debian/pkg-config/CMakeLists.txt deleted file mode 100644 index fa3a326a8..000000000 --- a/debian/pkg-config/CMakeLists.txt +++ /dev/null @@ -1,15 +0,0 @@ -#set(PKG_CONFIG_LIBDIR "\${prefix}/lib/\${deb_host_multiarch}") -#set(PKG_CONFIG_INCLUDEDIR "\${prefix}/include/\${deb_host_multiarch}/${PROJECT_NAME}") -#set(PKG_CONFIG_LIBS "-L\${libdir} -l:libstlink.so.${PROJECT_VERSION_MAJOR}") -#set(PKG_CONFIG_CFLAGS "-I\${includedir}") -#set(PKG_CONFIG_REQUIRES "libusb-1.0") - -#configure_file( -# "${CMAKE_CURRENT_SOURCE_DIR}/pkg-config.pc.cmake" -# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" -# ) - -#install( -# FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" -# DESTINATION ${STLINK_LIBRARY_PATH}/debian/ -# ) diff --git a/doc/compiling.md b/doc/compiling.md index 7296af650..65d2510d0 100644 --- a/doc/compiling.md +++ b/doc/compiling.md @@ -5,24 +5,22 @@ On Windows users should ensure that the following software is installed: -* `7zip` -* `git` +* `git` (_optional, but recommended_) * `cmake` (3.17.0 or later) * `MinGW-w64` (7.0.0 or later) with GCC toolchain 8.1.0 ### Installation -1. Install `7zip` from -2. Install `git` from -3. Install `cmake` from
+1. Install `git` from +2. Install `cmake` from
Ensure that you add cmake to the $PATH system variable when following the instructions by the setup assistant. -4. Install +3. Install - _EITHER_: **MinGW-w64** from (mingw-w64-install.exe)
- _OR_: **MSVC toolchain** from Visual Studio Build Tools 2019 -5. Create a new destination folder at a place of your choice -6. Open the command-line (cmd.exe) and execute `cd C:\$Path-to-your-destination-folder$\` -7. Fetch the project sourcefiles by running `git clone https://github.com/stlink-org/stlink.git`from the command-line (cmd.exe)
+4. Create a new destination folder at a place of your choice +5. Open the command-line (cmd.exe) and execute `cd C:\$Path-to-your-destination-folder$\` +6. Fetch the project sourcefiles by running `git clone https://github.com/stlink-org/stlink.git`from the command-line (cmd.exe)
or download the stlink zip-sourcefolder from the Release page on GitHub #### MSVC toolchain - minimal installation @@ -73,7 +71,7 @@ Directory `\build\Release` contains final executables. **NOTE 1:** -Executables link against libusb.dll library. It has to be placed in the same directory as binaries or in PATH. +Executables link against libusb.dll library. It has to be placed in the same directory as binaries or in PATH. It can be copied from: `\build\3rdparty\libusb-{version}\MS{arch}\dll\libusb-1.0.dll`. **NOTE 2:** @@ -228,10 +226,22 @@ To do this with only one simple command, type: The debug target is only necessary in order to modify the sources and to run under a debugger. -## Build using a different directory for shared libs +## Build options +### Build using a different directory for shared libs To put the compiled shared libs into a different directory during installation, you can use the cmake option `cmake -DLIB_INSTALL_DIR:PATH="/usr/lib64" ..`. +### Standard installation directories + +The cmake build system of this toolset includes `GNUInstallDirs` to define GNU standard installation directories. +This module provides install directory variables as defined by the GNU Coding Standards. + +Below are the preset default cmake options, which apply if none of these options are redefined: + +* `-DCMAKE_INSTALL_SYSCONFDIR=/etc` +* `-DCMAKE_INSTALL_PREFIX=/usr/local` + + Author: nightwalker-87 diff --git a/doc/man/CMakeLists.txt b/doc/man/CMakeLists.txt index 090a2237e..221c84d7b 100644 --- a/doc/man/CMakeLists.txt +++ b/doc/man/CMakeLists.txt @@ -1,3 +1,7 @@ +### +# Generate manpages +### + set(MANPAGES st-util st-flash st-info) # Only generate manpages with pandoc in Debug builds diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 6e5e3c279..6cf397659 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -2,6 +2,7 @@ configure_file( "${PROJECT_SOURCE_DIR}/include/stlink/version.h.in" "${CMAKE_BINARY_DIR}/include/stlink/version.h" ) + file(GLOB STLINK_HEADERS "stlink/*.h" "${CMAKE_BINARY_DIR}/include/stlink/*.h") install(FILES ${CMAKE_SOURCE_DIR}/include/stlink.h DESTINATION ${STLINK_INCLUDE_PATH}) install(FILES ${CMAKE_SOURCE_DIR}/include/stm32.h DESTINATION ${STLINK_INCLUDE_PATH}) diff --git a/include/stlink.h b/include/stlink.h index 87d708ef3..74c366d1c 100644 --- a/include/stlink.h +++ b/include/stlink.h @@ -137,7 +137,7 @@ typedef struct flash_loader { typedef struct _stlink stlink_t; -#include "stlink/backend.h" +#include struct _stlink { struct _stlink_backend *backend; @@ -245,14 +245,14 @@ typedef struct flash_loader { int stlink_write_option_bytes(stlink_t *sl, stm32_addr_t addr, uint8_t* base, uint32_t len); int stlink_fwrite_option_bytes(stlink_t *sl, const char* path, stm32_addr_t addr); -#include "stlink/sg.h" -#include "stlink/usb.h" -#include "stlink/reg.h" -#include "stlink/commands.h" -#include "stlink/chipid.h" -#include "stlink/flash_loader.h" -#include "stlink/version.h" -#include "stlink/logging.h" +#include +#include +#include +#include +#include +#include +#include +#include #ifdef __cplusplus } diff --git a/include/stlink/flash_loader.h b/include/stlink/flash_loader.h index 95042f7b6..5f4526114 100644 --- a/include/stlink/flash_loader.h +++ b/include/stlink/flash_loader.h @@ -10,7 +10,7 @@ #include #include -#include "stlink.h" +#include #ifdef __cplusplus extern "C" { diff --git a/include/stlink/tools/flash.h b/include/stlink/tools/flash.h index 15e020b35..8c3f7d766 100644 --- a/include/stlink/tools/flash.h +++ b/include/stlink/tools/flash.h @@ -2,6 +2,7 @@ #define STLINK_TOOLS_FLASH_H_ #include + #include #define DEBUG_LOG_LEVEL 100 diff --git a/src/chipid.c b/src/chipid.c index 17cb4d546..fcc1c55eb 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -1,5 +1,5 @@ -#include "stlink.h" -#include "stlink/chipid.h" +#include +#include static const struct stlink_chipid_params devices[] = { { @@ -580,7 +580,6 @@ static const struct stlink_chipid_params devices[] = { .bootrom_size = 0x7000, // 28K (table 2) .option_base = STM32_G4_OPTION_BYTES_BASE, .option_size = 4, - }, { // STM32G471/473/474/483/484 (from RM0440) @@ -621,8 +620,6 @@ static const struct stlink_chipid_params devices[] = { .bootrom_base = 0x0, .bootrom_size = 0x0 }, - - }; const struct stlink_chipid_params *stlink_chipid_get_params(uint32_t chipid) diff --git a/src/common.c b/src/common.c index df51733e2..9d21624f8 100644 --- a/src/common.c +++ b/src/common.c @@ -11,9 +11,9 @@ #include #include -#include "stlink.h" -#include "stlink/mmap.h" -#include "stlink/logging.h" +#include +#include "mmap.h" +#include "logging.h" #include "md5.h" #ifndef O_BINARY @@ -2904,12 +2904,12 @@ int stlink_mwrite_flash(stlink_t *sl, uint8_t* data, uint32_t length, stm32_addr } else { num_empty = 0; } - /* + /* * TODO: investigate: - * a kind of weird behaviour here: + * a kind of weird behaviour here: * if the file is identified to be all-empty and four-bytes aligned, - * still flash the whole file even if ignoring message is printed - */ + * still flash the whole file even if ignoring message is printed + */ err = stlink_write_flash(sl, addr, data, (num_empty == length) ? (uint32_t) length : (uint32_t) length - num_empty, num_empty == length); stlink_fwrite_finalize(sl, addr); return err; @@ -2953,12 +2953,12 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) { } else { num_empty = 0; } - /* + /* * TODO: investigate: - * a kind of weird behaviour here: + * a kind of weird behaviour here: * if the file is identified to be all-empty and four-bytes aligned, - * still flash the whole file even if ignoring message is printed - */ + * still flash the whole file even if ignoring message is printed + */ err = stlink_write_flash(sl, addr, mf.base, (num_empty == mf.len) ? (uint32_t) mf.len : (uint32_t) mf.len - num_empty, num_empty == mf.len); stlink_fwrite_finalize(sl, addr); unmap_file(&mf); @@ -3179,9 +3179,9 @@ int stlink_read_option_bytes32(stlink_t *sl, uint32_t* option_byte) } /** - * Write option bytes + * Write option bytes * @param sl - * @param option_byte value to write + * @param option_byte value to write * @return 0 on success, -ve on failure. */ int stlink_write_option_bytes32(stlink_t *sl, uint32_t option_byte) diff --git a/src/flash_loader.c b/src/flash_loader.c index a1c9c3757..ed253f92b 100644 --- a/src/flash_loader.c +++ b/src/flash_loader.c @@ -1,9 +1,9 @@ -#include "stlink.h" - #include #include #include +#include + #define FLASH_REGS_BANK2_OFS 0x40 #define FLASH_BANK2_START_ADDR 0x08080000 @@ -384,16 +384,16 @@ int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t targe /* run loader */ stlink_run(sl); -// This piece of code used to try to spin for .1 second by waiting +// This piece of code used to try to spin for .1 second by waiting // doing 10000 rounds of 10 microseconds. But because this usually runs -// on Unix-like OSes, the 10 microseconds get rounded up to the "tick" +// on Unix-like OSes, the 10 microseconds get rounded up to the "tick" // (actually almost two ticks) of the system. 1 milisecond. Thus, the -// ten thousand attempts, when "something goes wrong" that requires -// the error message "flash loader run error" would wait for something -// like 20 seconds before coming up with the error. -// by increasing the sleep-per-round to the same order-of-magnitude as +// ten thousand attempts, when "something goes wrong" that requires +// the error message "flash loader run error" would wait for something +// like 20 seconds before coming up with the error. +// by increasing the sleep-per-round to the same order-of-magnitude as // the tick-rounding that the OS uses, the wait until the error message is -// reduced to the same order of magnitude as what was intended. -- REW. +// reduced to the same order of magnitude as what was intended. -- REW. #define WAIT_ROUNDS 100 /* wait until done (reaches breakpoint) */ for (i = 0; i < WAIT_ROUNDS; i++) { diff --git a/src/gdbserver/CMakeLists.txt b/src/gdbserver/CMakeLists.txt deleted file mode 100644 index ff9bde165..000000000 --- a/src/gdbserver/CMakeLists.txt +++ /dev/null @@ -1,23 +0,0 @@ -set(STUTIL_SOURCE - gdb-remote.c - gdb-remote.h - gdb-server.c - gdb-server.h - semihosting.c - semihosting.h - ) - -if (MSVC) - # We need a getopt from somewhere... - set(STUTIL_SOURCE "${STUTIL_SOURCE};../getopt/getopt.c") -endif () - -add_executable(st-util ${STUTIL_SOURCE}) - -if (WIN32 OR APPLE) - target_link_libraries(st-util ${STLINK_LIB_STATIC} ${SSP_LIB}) -else () - target_link_libraries(st-util ${STLINK_LIB_SHARED} ${SSP_LIB}) -endif () - -install(TARGETS st-util RUNTIME DESTINATION bin) diff --git a/src/getopt/LICENSE.txt b/src/getopt/LICENSE.txt index 340303a96..4e4ed8bd5 100644 --- a/src/getopt/LICENSE.txt +++ b/src/getopt/LICENSE.txt @@ -1,3 +1,5 @@ +BSD 3-Clause License + Copyright (c) 2012, Kim Gräsman All rights reserved. diff --git a/src/getopt/getopt.c b/src/getopt/getopt.c index 72dce14d6..5dd45bff7 100644 --- a/src/getopt/getopt.c +++ b/src/getopt/getopt.c @@ -1,8 +1,8 @@ -#include "getopt.h" - #include #include +#include "getopt.h" + #if !defined(_MSC_VER) const int no_argument = 0; const int required_argument = 1; @@ -19,8 +19,8 @@ static char* optcursor = NULL; /* Implemented based on [1] and [2] for optional arguments. optopt is handled FreeBSD-style, per [3]. - Other GNU and FreeBSD extensions are purely accidental. - + Other GNU and FreeBSD extensions are purely accidental. + [1] http://pubs.opengroup.org/onlinepubs/000095399/functions/getopt.html [2] http://www.kernel.org/doc/man-pages/online/pages/man3/getopt.3.html [3] http://www.freebsd.org/cgi/man.cgi?query=getopt&sektion=3&manpath=FreeBSD+9.0-RELEASE @@ -37,22 +37,22 @@ int getopt(int argc, char* const argv[], const char* optstring) { if (optind >= argc) goto no_more_optchars; - /* If, when getopt() is called argv[optind] is a null pointer, getopt() + /* If, when getopt() is called argv[optind] is a null pointer, getopt() shall return -1 without changing optind. */ if (argv[optind] == NULL) goto no_more_optchars; - /* If, when getopt() is called *argv[optind] is not the character '-', + /* If, when getopt() is called *argv[optind] is not the character '-', getopt() shall return -1 without changing optind. */ if (*argv[optind] != '-') goto no_more_optchars; - /* If, when getopt() is called argv[optind] points to the string "-", + /* If, when getopt() is called argv[optind] points to the string "-", getopt() shall return -1 without changing optind. */ if (strcmp(argv[optind], "-") == 0) goto no_more_optchars; - /* If, when getopt() is called argv[optind] points to the string "--", + /* If, when getopt() is called argv[optind] points to the string "--", getopt() shall return -1 after incrementing optind. */ if (strcmp(argv[optind], "--") == 0) { ++optind; @@ -64,12 +64,12 @@ int getopt(int argc, char* const argv[], const char* optstring) { optchar = *optcursor; - /* FreeBSD: The variable optopt saves the last known option character + /* FreeBSD: The variable optopt saves the last known option character returned by getopt(). */ optopt = optchar; - /* The getopt() function shall return the next option character (if one is - found) from argv that matches a character in optstring, if there is + /* The getopt() function shall return the next option character (if one is + found) from argv that matches a character in optstring, if there is one that matches. */ optdecl = strchr(optstring, optchar); if (optdecl) { @@ -79,15 +79,15 @@ int getopt(int argc, char* const argv[], const char* optstring) { optarg = ++optcursor; if (*optarg == '\0') { /* GNU extension: Two colons mean an option takes an - optional arg; if there is text in the current argv-element - (i.e., in the same word as the option name itself, for example, + optional arg; if there is text in the current argv-element + (i.e., in the same word as the option name itself, for example, "-oarg"), then it is returned in optarg, otherwise optarg is set to zero. */ if (optdecl[2] != ':') { /* If the option was the last character in the string pointed to by an element of argv, then optarg shall contain the next element of argv, and optind shall be incremented by 2. If the resulting - value of optind is greater than argc, this indicates a missing + value of optind is greater than argc, this indicates a missing option-argument, and getopt() shall return an error indication. Otherwise, optarg shall point to the string following the @@ -97,7 +97,7 @@ int getopt(int argc, char* const argv[], const char* optstring) { if (++optind < argc) { optarg = argv[optind]; } else { - /* If it detects a missing option-argument, it shall return the + /* If it detects a missing option-argument, it shall return the colon character ( ':' ) if the first character of optstring was a colon, or a question-mark character ( '?' ) otherwise. */ @@ -112,7 +112,7 @@ int getopt(int argc, char* const argv[], const char* optstring) { optcursor = NULL; } } else { - /* If getopt() encounters an option character that is not contained in + /* If getopt() encounters an option character that is not contained in optstring, it shall return the question-mark ( '?' ) character. */ optchar = '?'; } @@ -131,7 +131,7 @@ int getopt(int argc, char* const argv[], const char* optstring) { [1] http://www.kernel.org/doc/man-pages/online/pages/man3/getopt.3.html */ -int getopt_long(int argc, char* const argv[], const char* optstring, +int getopt_long(int argc, char* const argv[], const char* optstring, const struct option* longopts, int* longindex) { const struct option* o = longopts; const struct option* match = NULL; @@ -165,7 +165,7 @@ int getopt_long(int argc, char* const argv[], const char* optstring, if (longindex) *longindex = (match - longopts); - /* If flag is NULL, then getopt_long() shall return val. + /* If flag is NULL, then getopt_long() shall return val. Otherwise, getopt_long() returns 0, and flag shall point to a variable which shall be set to val if the option is found, but left unchanged if the option is not found. */ @@ -190,7 +190,7 @@ int getopt_long(int argc, char* const argv[], const char* optstring, retval = ':'; } } else if (strchr(argv[optind], '=')) { - /* An argument was provided to a non-argument option. + /* An argument was provided to a non-argument option. I haven't seen this specified explicitly, but both GNU and BSD-based implementations show this behavior. */ diff --git a/include/stlink/stlinkusb.h b/src/libusb_settings.h similarity index 91% rename from include/stlink/stlinkusb.h rename to src/libusb_settings.h index 633d82bd0..c2e2df923 100644 --- a/include/stlink/stlinkusb.h +++ b/src/libusb_settings.h @@ -1,5 +1,5 @@ -#ifndef STLINKUSB_H -#define STLINKUSB_H +#ifndef LIBUSB_SETTINGS_H +#define LIBUSB_SETTINGS_H #include diff --git a/src/logging.c b/src/logging.c index 59c2ea298..4ad89a5ed 100644 --- a/src/logging.c +++ b/src/logging.c @@ -9,7 +9,7 @@ #include #include -#include "stlink/logging.h" +#include "logging.h" static int max_level = UINFO; diff --git a/include/stlink/logging.h b/src/logging.h similarity index 100% rename from include/stlink/logging.h rename to src/logging.h diff --git a/src/md5.c b/src/md5.c index e2b526c7d..521c52969 100755 --- a/src/md5.c +++ b/src/md5.c @@ -15,9 +15,10 @@ // IMPORTS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -#include "md5.h" #include +#include "md5.h" + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // INTERNAL FUNCTIONS //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/mmap.c b/src/mmap.c index 90ae5fc17..b76e4ad64 100644 --- a/src/mmap.c +++ b/src/mmap.c @@ -3,7 +3,7 @@ #include #include -#include "stlink/mmap.h" +#include "mmap.h" void *mmap (void *addr, size_t len, int prot, int flags, int fd, long long offset) { diff --git a/include/stlink/mmap.h b/src/mmap.h similarity index 100% rename from include/stlink/mmap.h rename to src/mmap.h diff --git a/src/sg.c b/src/sg.c index 031cc64e5..a0790f3c7 100644 --- a/src/sg.c +++ b/src/sg.c @@ -82,8 +82,8 @@ #include #include -#include "stlink.h" -#include "stlink/logging.h" +#include +#include "logging.h" #define STLINK_OK 0x80 #define STLINK_FALSE 0x81 diff --git a/include/stlink/sg.h b/src/sg.h similarity index 95% rename from include/stlink/sg.h rename to src/sg.h index 98efd4e58..3a8a7a239 100644 --- a/include/stlink/sg.h +++ b/src/sg.h @@ -1,5 +1,5 @@ /* - * File: stlink/sg.h + * File: sg.h * Author: karl * * Created on October 1, 2011, 11:29 PM @@ -8,8 +8,8 @@ #ifndef STLINK_SG_H #define STLINK_SG_H -#include "stlinkusb.h" -#include "stlink.h" +#include "libusb_settings.h" +#include #ifdef __cplusplus extern "C" { @@ -70,4 +70,3 @@ stlink_t* stlink_v1_open(const int verbose, int reset); #endif #endif /* STLINK_SG_H */ - diff --git a/src/gdbserver/gdb-remote.c b/src/st-util/gdb-remote.c similarity index 99% rename from src/gdbserver/gdb-remote.c rename to src/st-util/gdb-remote.c index 3b1794f3e..24636e8c9 100644 --- a/src/gdbserver/gdb-remote.c +++ b/src/st-util/gdb-remote.c @@ -8,6 +8,7 @@ #include #include #include + #if defined(__MINGW32__) || defined(_MSC_VER) #include #else @@ -15,6 +16,8 @@ #include #endif +#include "gdb-remote.h" + static const char hex[] = "0123456789abcdef"; int gdb_send_packet(int fd, char* data) { @@ -169,4 +172,3 @@ int gdb_check_for_interrupt(int fd) { return 0; } - diff --git a/src/gdbserver/gdb-remote.h b/src/st-util/gdb-remote.h similarity index 100% rename from src/gdbserver/gdb-remote.h rename to src/st-util/gdb-remote.h diff --git a/src/gdbserver/gdb-server.c b/src/st-util/gdb-server.c similarity index 99% rename from src/gdbserver/gdb-server.c rename to src/st-util/gdb-server.c index 9081c8084..a3839cfc8 100644 --- a/src/gdbserver/gdb-server.c +++ b/src/st-util/gdb-server.c @@ -14,6 +14,7 @@ #include #define __attribute__(x) #endif + #if defined(_WIN32) #include #else @@ -24,8 +25,7 @@ #endif #include -#include - +#include #include "gdb-remote.h" #include "gdb-server.h" #include "semihosting.h" diff --git a/src/gdbserver/gdb-server.h b/src/st-util/gdb-server.h similarity index 100% rename from src/gdbserver/gdb-server.h rename to src/st-util/gdb-server.h diff --git a/src/gdbserver/semihosting.c b/src/st-util/semihosting.c similarity index 99% rename from src/gdbserver/semihosting.c rename to src/st-util/semihosting.c index 40758b61d..fed66ab60 100644 --- a/src/gdbserver/semihosting.c +++ b/src/st-util/semihosting.c @@ -5,10 +5,9 @@ #include #include -#include "semihosting.h" - #include -#include +#include +#include "semihosting.h" static int mem_read_u8(stlink_t *sl, uint32_t addr, uint8_t *data) { @@ -100,7 +99,7 @@ static int mem_write(stlink_t *sl, uint32_t addr, void *data, uint16_t len) // the requested bytes. (perhaps reading the whole area is faster??). // // If 16 and 8 bit writes are available, then they could be used instead. - + // Just return when the length is zero avoiding unneeded work. if (len == 0) return 0; diff --git a/src/gdbserver/semihosting.h b/src/st-util/semihosting.h similarity index 100% rename from src/gdbserver/semihosting.h rename to src/st-util/semihosting.h diff --git a/src/stlink-gui/CMakeLists.txt b/src/stlink-gui/CMakeLists.txt index 74b71cecd..b5ef99df9 100644 --- a/src/stlink-gui/CMakeLists.txt +++ b/src/stlink-gui/CMakeLists.txt @@ -1,35 +1,41 @@ +### +# Build GUI +### + +## GUI-Building requires the presence of a GTK3 toolset if (NOT GTK3_FOUND) message(STATUS "GTK3 not found!") - return() # no GTK3 present => no GUI build + return() # no GTK3 present => no GUI build else (GTK3_FOUND) message(STATUS "Found GTK3: -I${GTK3_INCLUDE_DIRS}, ${GTK3_LIBRARIES}") endif () -set(GUI_SOURCES gui.c gui.h) -set(INSTALLED_UI_DIR share/stlink) ### TODO: Check Path - include_directories(SYSTEM ${GTK3_INCLUDE_DIRS}) -# stlink-gui-local +set(GUI_SOURCES gui.c gui.h) + +## stlink-gui-local add_executable(stlink-gui-local ${GUI_SOURCES}) set_target_properties( stlink-gui-local PROPERTIES - COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_CURRENT_SOURCE_DIR}" ### TODO: Check Path + COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_CURRENT_SOURCE_DIR}" + # Note: ${CMAKE_CURRENT_SOURCE_DIR} is src/stlink-gui ) target_link_libraries(stlink-gui-local ${STLINK_LIB_STATIC} ${GTK3_LDFLAGS} ${SSP_LIB}) -# stlink-gui +## stlink-gui add_executable(stlink-gui ${GUI_SOURCES}) set_target_properties( stlink-gui PROPERTIES - COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_PREFIX}/${INSTALLED_UI_DIR}" ### TODO: Check Path + COMPILE_DEFINITIONS STLINK_UI_DIR="${CMAKE_INSTALL_PREFIX}/bin" + # Note: ${CMAKE_INSTALL_PREFIX} defaults to /usr/local ) target_link_libraries(stlink-gui ${STLINK_LIB_STATIC} ${GTK3_LDFLAGS} ${SSP_LIB}) -install(TARGETS stlink-gui RUNTIME DESTINATION bin) ### TODO: Check Path -install(FILES gui.ui DESTINATION ${INSTALLED_UI_DIR}) ### TODO: Check Path +install(TARGETS stlink-gui DESTINATION bin) +install(FILES stlink-gui.ui DESTINATION bin) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") - install(FILES stlink-gui.desktop DESTINATION share/applications) # Install desktop entry + install(FILES stlink-gui.desktop DESTINATION share/applications) # Install desktop application entry install(FILES icons/stlink-gui.svg DESTINATION share/icons/hicolor/scalable/apps) # Install icon endif () diff --git a/src/stlink-gui/gui.c b/src/stlink-gui/gui.c index f90196c06..5d5a422d5 100644 --- a/src/stlink-gui/gui.c +++ b/src/stlink-gui/gui.c @@ -779,10 +779,10 @@ static void stlink_gui_build_ui (STlinkGUI *gui) { GtkBuilder *builder; GtkListStore *devmem_store; GtkListStore *filemem_store; - gchar *ui_file = STLINK_UI_DIR "/gui.ui"; + gchar *ui_file = STLINK_UI_DIR "/stlink-gui.ui"; if (!g_file_test (ui_file, G_FILE_TEST_EXISTS)) - ui_file = "gui.ui"; + ui_file = "stlink-gui.ui"; builder = gtk_builder_new (); if (!gtk_builder_add_from_file (builder, ui_file, NULL)) { g_printerr ("Failed to load UI file: %s\n", ui_file); diff --git a/src/stlink-gui/gui.ui b/src/stlink-gui/stlink-gui.ui similarity index 100% rename from src/stlink-gui/gui.ui rename to src/stlink-gui/stlink-gui.ui diff --git a/src/tools/flash.c b/src/tools/flash.c index 3a9cc3674..841b93c3c 100644 --- a/src/tools/flash.c +++ b/src/tools/flash.c @@ -2,7 +2,6 @@ // TODO - this should be done as just a simple flag to the st-util command line... - #include #include #include @@ -10,7 +9,7 @@ #include #include -#include +#include static stlink_t *connected_stlink = NULL; diff --git a/src/tools/flash_opts.c b/src/tools/flash_opts.c index 085d278db..544d4ad90 100644 --- a/src/tools/flash_opts.c +++ b/src/tools/flash_opts.c @@ -1,9 +1,9 @@ -#include - #include #include #include +#include + static bool starts_with(const char * str, const char * prefix) { size_t n = strlen(prefix); if (strlen(str) < n) return false; diff --git a/src/usb.c b/src/usb.c index c9ea7039a..4e7a2983f 100644 --- a/src/usb.c +++ b/src/usb.c @@ -7,11 +7,13 @@ #include #endif #include -#include #include #include -#include "stlink.h" +#if defined(__MINGW32__) || defined(_MSC_VER) +#include +#endif +#include enum SCSI_Generic_Direction {SG_DXFER_TO_DEV=0, SG_DXFER_FROM_DEV=0x80}; diff --git a/include/stlink/usb.h b/src/usb.h similarity index 96% rename from include/stlink/usb.h rename to src/usb.h index 1448481be..968f38ba4 100644 --- a/include/stlink/usb.h +++ b/src/usb.h @@ -1,5 +1,5 @@ /* - * File: stlink/usb.h + * File: usb.h * Author: karl * * Created on October 1, 2011, 11:29 PM @@ -10,9 +10,9 @@ #include -#include "stlink.h" -#include "stlinkusb.h" -#include "stlink/logging.h" +#include +#include "libusb_settings.h" +#include "logging.h" #ifdef __cplusplus extern "C" { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c6b04ddb3..40d2203db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,16 @@ -set(TESTS usb sg) +### +# Build test executables +### -foreach (test ${TESTS}) - add_executable(${test} ${test}.c) - add_dependencies(${test} ${STLINK_LIB_STATIC}) - target_link_libraries(${test} ${STLINK_LIB_STATIC} ${SSP_LIB}) - add_test(${test} ${CMAKE_CURRENT_BINARY_DIR}/${test}) +set(TESTEXEC usb sg) + +foreach (test ${TESTEXEC}) + add_executable(test-${test} ${test}.c) + add_dependencies(test-${test} ${STLINK_LIB_STATIC}) + target_link_libraries(test-${test} ${STLINK_LIB_STATIC} ${SSP_LIB}) + add_test(test-${test} ${CMAKE_BINARY_DIR}/bin/test-${test}) endforeach () -add_executable(flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c") -target_link_libraries(flash ${STLINK_LIB_STATIC} ${SSP_LIB}) -add_test(flash ${CMAKE_CURRENT_BINARY_DIR}/flash) +add_executable(test-flash flash.c "${CMAKE_SOURCE_DIR}/src/tools/flash_opts.c") +target_link_libraries(test-flash ${STLINK_LIB_STATIC} ${SSP_LIB}) +add_test(test-flash ${CMAKE_BINARY_DIR}/bin/test-flash) diff --git a/tests/flash.c b/tests/flash.c index 53032474a..903370cc3 100644 --- a/tests/flash.c +++ b/tests/flash.c @@ -3,7 +3,7 @@ #include #include -#include +#include #if defined(_MSC_VER) #include diff --git a/tests/sg.c b/tests/sg.c index 32ef55b69..1af177174 100644 --- a/tests/sg.c +++ b/tests/sg.c @@ -7,6 +7,7 @@ #include #include #include + #include #if defined(_MSC_VER) diff --git a/tests/usb.c b/tests/usb.c index a2c3ef8cd..d4098834d 100644 --- a/tests/usb.c +++ b/tests/usb.c @@ -1,4 +1,5 @@ #include + #include int main(int ac, char** av) { @@ -35,7 +36,6 @@ int main(int ac, char** av) { printf("cpuid:impl_id = %0#x, variant = %#x\n", cpuid.implementer_id, cpuid.variant); printf("cpuid:part = %#x, rev = %#x\n", cpuid.part, cpuid.revision); } - printf("-- read_sram\n"); static const uint32_t sram_base = STM32_SRAM_BASE;