From 2c82d9ea7dfdb0fd90e7ac5f303d2189508cd939 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 23 Dec 2020 20:49:56 +0300 Subject: [PATCH 001/120] configure: do not make Capstone dependency automagic This adds regular ./configure options to control dependency on the Capstone disassembly engine. See [0] for the rationale. [0] https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Automagic_dependencies Change-Id: I3e16dc5255d650aa1949ccf896b26dc96e522a75 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/5985 Tested-by: jenkins Reviewed-by: Antonio Borneo --- configure.ac | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index 236d6bc28..baa198730 100644 --- a/configure.ac +++ b/configure.ac @@ -150,6 +150,8 @@ m4_define([LIBJAYLINK_ADAPTERS], m4_define([PCIE_ADAPTERS], [[[xlnx_pcie_xvc], [Xilinx XVC/PCIe], [XLNX_PCIE_XVC]]]) +m4_define([OPTIONAL_LIBRARIES], + [[[capstone], [Use Capstone disassembly framework], []]]) AC_ARG_ENABLE([doxygen-html], AS_HELP_STRING([--disable-doxygen-html], @@ -653,13 +655,24 @@ PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [ PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [use_libusb0=no]) -PKG_CHECK_MODULES([CAPSTONE], [capstone], [have_capstone=yes], - [have_capstone=no]) +AC_ARG_WITH([capstone], + AS_HELP_STRING([--with-capstone], [Use Capstone disassembly library (default=auto)]) + , [ + enable_capstone=$withval + ], [ + enable_capstone=auto +]) -AS_IF([test "x$have_capstone" = "xyes"], [ - AC_DEFINE([HAVE_CAPSTONE], [1], [1 if you have captone disassembly framework.]) -], [ - AC_DEFINE([HAVE_CAPSTONE], [0], [0 if you don't have captone disassembly framework.]) +AS_IF([test "x$enable_capstone" != xno], [ + PKG_CHECK_MODULES([CAPSTONE], [capstone], [ + AC_DEFINE([HAVE_CAPSTONE], [1], [1 if you have Capstone disassembly framework.]) + ], [ + AC_DEFINE([HAVE_CAPSTONE], [0], [0 if you don't have Capstone disassembly framework.]) + if test "x$enable_capstone" != xauto; then + AC_MSG_ERROR([--with-capstone was given, but test for Capstone failed]) + fi + enable_capstone=no + ]) ]) for hidapi_lib in hidapi hidapi-hidraw hidapi-libusb; do @@ -785,7 +798,7 @@ AM_CONDITIONAL([USE_LIBGPIOD], [test "x$use_libgpiod" = "xyes"]) AM_CONDITIONAL([USE_HIDAPI], [test "x$use_hidapi" = "xyes"]) AM_CONDITIONAL([USE_LIBJAYLINK], [test "x$use_libjaylink" = "xyes"]) AM_CONDITIONAL([RSHIM], [test "x$build_rshim" = "xyes"]) -AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$have_capstone" = "xyes"]) +AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$enable_capstone" != "xno"]) AM_CONDITIONAL([MINIDRIVER], [test "x$build_minidriver" = "xyes"]) AM_CONDITIONAL([MINIDRIVER_DUMMY], [test "x$build_minidriver_dummy" = "xyes"]) @@ -856,7 +869,8 @@ echo -------------------------------------------------- m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, LIBGPIOD_ADAPTERS, - LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS], + LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS, + OPTIONAL_LIBRARIES], [s=m4_format(["%-40s"], ADAPTER_DESC([adapter])) AS_CASE([$ADAPTER_VAR([adapter])], [auto], [ From cc79bcd5871669af7070f71c77369492f07cf614 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 29 Dec 2020 02:04:25 +0100 Subject: [PATCH 002/120] configure.ac: fix build with libusb0 and without libusb1 Driver 'openjtag' requires both libftdi and libusb1. The current check is incorrect and the driver is built when libftdi is present with libusb0 and without libusb1, which causes the linker to fail resolving the required libusb1 symbols. Remove the check for libusb0 on driver 'openjtag'. Create a new adapters group LIBFTDI_USB1_ADAPTERS to hold the driver 'openjtag'. Change-Id: I1f5e554b519e51c829d116ede894639cb55a26aa Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5989 Tested-by: jenkins --- configure.ac | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index baa198730..012486666 100644 --- a/configure.ac +++ b/configure.ac @@ -138,8 +138,10 @@ m4_define([HIDAPI_USB1_ADAPTERS], m4_define([LIBFTDI_ADAPTERS], [[[usb_blaster], [Altera USB-Blaster Compatible], [USB_BLASTER]], - [[presto], [ASIX Presto Adapter], [PRESTO]], - [[openjtag], [OpenJTAG Adapter], [OPENJTAG]]]) + [[presto], [ASIX Presto Adapter], [PRESTO]]]) + +m4_define([LIBFTDI_USB1_ADAPTERS], + [[[openjtag], [OpenJTAG Adapter], [OPENJTAG]]]) m4_define([LIBGPIOD_ADAPTERS], [[[linuxgpiod], [Linux GPIO bitbang through libgpiod], [LINUXGPIOD]]]) @@ -250,6 +252,7 @@ AC_ARG_ADAPTERS([ HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, + LIBFTDI_USB1_ADAPTERS LIBGPIOD_ADAPTERS, LIBJAYLINK_ADAPTERS ],[auto]) @@ -723,16 +726,10 @@ PROCESS_ADAPTERS([USB0_ADAPTERS], ["x$use_libusb0" = "xyes"], [libusb-0.1]) PROCESS_ADAPTERS([HIDAPI_ADAPTERS], ["x$use_hidapi" = "xyes"], [hidapi]) PROCESS_ADAPTERS([HIDAPI_USB1_ADAPTERS], ["x$use_hidapi" = "xyes" -a "x$use_libusb1" = "xyes"], [hidapi and libusb-1.x]) PROCESS_ADAPTERS([LIBFTDI_ADAPTERS], ["x$use_libftdi" = "xyes"], [libftdi]) +PROCESS_ADAPTERS([LIBFTDI_USB1_ADAPTERS], ["x$use_libftdi" = "xyes" -a "x$use_libusb1" = "xyes"], [libftdi and libusb-1.x]) PROCESS_ADAPTERS([LIBGPIOD_ADAPTERS], ["x$use_libgpiod" = "xyes"], [libgpiod]) PROCESS_ADAPTERS([LIBJAYLINK_ADAPTERS], ["x$use_internal_libjaylink" = "xyes" -o "x$use_libjaylink" = "xyes"], [libjaylink-0.2]) -AS_IF([test "x$build_openjtag" = "xyes"], [ - AS_IF([test "x$use_libusb1" != "xyes" -a "x$use_libusb0" != "xyes"], [ - AC_MSG_ERROR([libusb-1.x or libusb-0.1 is required for the OpenJTAG Programmer]) - build_openjtag=no - ]) -]) - AS_IF([test "x$enable_linuxgpiod" != "xno"], [ build_bitbang=yes ]) @@ -868,6 +865,7 @@ echo OpenOCD configuration summary echo -------------------------------------------------- m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, + LIBFTDI_USB1_ADAPTERS, LIBGPIOD_ADAPTERS, LIBJAYLINK_ADAPTERS, PCIE_ADAPTERS, OPTIONAL_LIBRARIES], From b5098754cfaa7e58e36816f89e6d219a1d5db54c Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Fri, 1 Jan 2021 14:37:56 +0300 Subject: [PATCH 003/120] doc: fix over/underfull hboxes in PDF This adds some cosmetic changes to make the PDF User Manual look proper. Building it now requires Texinfo 5.0 which shouldn't be problematic according to [0]. Commit 79fdeb37f486f74658f1eaf658abac8efb3eba6a is effectively reverted. [0] https://repology.org/project/texinfo/versions Change-Id: I990bc23bdb53d24c302b26d74fd770ea738e4096 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/5995 Reviewed-by: Jonathan McDowell Tested-by: jenkins Reviewed-by: Antonio Borneo --- README | 2 +- doc/openocd.texi | 98 +++++++++++++++++++++++++++++------------------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/README b/README index 900324ab1..ed0a85856 100644 --- a/README +++ b/README @@ -216,7 +216,7 @@ Additionally, for building from git: - autoconf >= 2.64 - automake >= 1.14 -- texinfo +- texinfo >= 5.0 USB-based adapters depend on libusb-1.0 and some older drivers require libusb-0.1 or libusb-compat-0.1. A compatible implementation, such as diff --git a/doc/openocd.texi b/doc/openocd.texi index 9e060b383..2658c75ea 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4547,8 +4547,10 @@ The current implementation supports three JTAG TAP cores: @end itemize And two debug interfaces cores: @itemize @minus -@item @code{Advanced debug interface} (See: @url{http://opencores.org/project@comma{}adv_debug_sys}) -@item @code{SoC Debug Interface} (See: @url{http://opencores.org/project@comma{}dbg_interface}) +@item @code{Advanced debug interface} +@*(See: @url{http://opencores.org/project@comma{}adv_debug_sys}) +@item @code{SoC Debug Interface} +@*(See: @url{http://opencores.org/project@comma{}dbg_interface}) @end itemize @item @code{quark_d20xx} -- an Intel Quark D20xx core. @item @code{quark_x10xx} -- an Intel Quark X10xx core. @@ -5616,8 +5618,10 @@ is attempted. If this fails or gives inappropriate results, manual setting is required (see 'set' command). @example -flash bank $_FLASHNAME stmqspi 0x90000000 0 0 0 $_TARGETNAME 0xA0001000 -flash bank $_FLASHNAME stmqspi 0x70000000 0 0 0 $_TARGETNAME 0xA0001400 +flash bank $_FLASHNAME stmqspi 0x90000000 0 0 0 \ + $_TARGETNAME 0xA0001000 +flash bank $_FLASHNAME stmqspi 0x70000000 0 0 0 \ + $_TARGETNAME 0xA0001400 @end example There are three specific commands @@ -5655,11 +5659,13 @@ Note the hardware dictated subtle difference of those two cases in dual-flash mo To check basic communication settings, issue @example -stmqspi cmd bank_id 0 0x04; stmqspi cmd bank_id 1 0x05; stmqspi cmd bank_id 0 0x06; stmqspi cmd bank_id 1 0x05 +stmqspi cmd bank_id 0 0x04; stmqspi cmd bank_id 1 0x05 +stmqspi cmd bank_id 0 0x06; stmqspi cmd bank_id 1 0x05 @end example for single flash mode or @example -stmqspi cmd bank_id 0 0x04; stmqspi cmd bank_id 2 0x05; stmqspi cmd bank_id 0 0x06; stmqspi cmd bank_id 2 0x05 +stmqspi cmd bank_id 0 0x04; stmqspi cmd bank_id 2 0x05 +stmqspi cmd bank_id 0 0x06; stmqspi cmd bank_id 2 0x05 @end example for dual flash mode. This should return the status register contents. @@ -5717,9 +5723,9 @@ CS1/CS2 is routed to on the given SoC. @example flash bank $_FLASHNAME ath79 0xbf000000 0 0 0 $_TARGETNAME -# When using multiple chipselects the base should be different for each, -# otherwise the write_image command is not able to distinguish the -# banks. +# When using multiple chipselects the base should be different +# for each, otherwise the write_image command is not able to +# distinguish the banks. flash bank flash0 ath79 0xbf000000 0 0 0 $_TARGETNAME cs0 flash bank flash1 ath79 0x10000000 0 0 0 $_TARGETNAME cs1 flash bank flash2 ath79 0x20000000 0 0 0 $_TARGETNAME cs2 @@ -5880,7 +5886,8 @@ reserved-bits are masked out and cannot be changed. NVMUSERROW: 0xFFFFFC5DD8E0C788 # Write 0xFFFFFC5DD8E0C788 to user row >at91samd nvmuserrow 0xFFFFFC5DD8E0C788 -# Write 0x12300 to user row but leave other bits and low byte unchanged +# Write 0x12300 to user row but leave other bits and low +# byte unchanged >at91samd nvmuserrow 0x12345 0xFFF00 @end example @end deffn @@ -6028,8 +6035,9 @@ The reserved fields are always masked out and cannot be changed. USER PAGE: 0xAEECFF80FE9A9239 # Write >atsame5 userpage 0xAEECFF80FE9A9239 -# Write 2 to SEESBLK and 4 to SEEPSZ fields but leave other bits unchanged -# (setup SmartEEPROM of virtual size 8192 bytes) +# Write 2 to SEESBLK and 4 to SEEPSZ fields but leave other +# bits unchanged (setup SmartEEPROM of virtual size 8192 +# bytes) >atsame5 userpage 0x4200000000 0x7f00000000 @end example @end deffn @@ -6788,7 +6796,8 @@ The driver probes for a number of these chips and autoconfigures itself, apart from the base address. @example -flash bank $_CHIPNAME.eeprom psoc5lp_eeprom 0x40008000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.eeprom psoc5lp_eeprom 0x40008000 0 0 0 \ + $_TARGETNAME @end example @end deffn @@ -6842,19 +6851,31 @@ automatically by parsing data in SPCIF_GEOMETRY register. PSoC6 is equipped with NOR Flash so erased Flash reads as 0x00. @example -flash bank main_flash_cm0 psoc6 0x10000000 0 0 0 $@{TARGET@}.cm0 -flash bank work_flash_cm0 psoc6 0x14000000 0 0 0 $@{TARGET@}.cm0 -flash bank super_flash_user_cm0 psoc6 0x16000800 0 0 0 $@{TARGET@}.cm0 -flash bank super_flash_nar_cm0 psoc6 0x16001A00 0 0 0 $@{TARGET@}.cm0 -flash bank super_flash_key_cm0 psoc6 0x16005A00 0 0 0 $@{TARGET@}.cm0 -flash bank super_flash_toc2_cm0 psoc6 0x16007C00 0 0 0 $@{TARGET@}.cm0 +flash bank main_flash_cm0 psoc6 0x10000000 0 0 0 \ + $@{TARGET@}.cm0 +flash bank work_flash_cm0 psoc6 0x14000000 0 0 0 \ + $@{TARGET@}.cm0 +flash bank super_flash_user_cm0 psoc6 0x16000800 0 0 0 \ + $@{TARGET@}.cm0 +flash bank super_flash_nar_cm0 psoc6 0x16001A00 0 0 0 \ + $@{TARGET@}.cm0 +flash bank super_flash_key_cm0 psoc6 0x16005A00 0 0 0 \ + $@{TARGET@}.cm0 +flash bank super_flash_toc2_cm0 psoc6 0x16007C00 0 0 0 \ + $@{TARGET@}.cm0 -flash bank main_flash_cm4 psoc6 0x10000000 0 0 0 $@{TARGET@}.cm4 -flash bank work_flash_cm4 psoc6 0x14000000 0 0 0 $@{TARGET@}.cm4 -flash bank super_flash_user_cm4 psoc6 0x16000800 0 0 0 $@{TARGET@}.cm4 -flash bank super_flash_nar_cm4 psoc6 0x16001A00 0 0 0 $@{TARGET@}.cm4 -flash bank super_flash_key_cm4 psoc6 0x16005A00 0 0 0 $@{TARGET@}.cm4 -flash bank super_flash_toc2_cm4 psoc6 0x16007C00 0 0 0 $@{TARGET@}.cm4 +flash bank main_flash_cm4 psoc6 0x10000000 0 0 0 \ + $@{TARGET@}.cm4 +flash bank work_flash_cm4 psoc6 0x14000000 0 0 0 \ + $@{TARGET@}.cm4 +flash bank super_flash_user_cm4 psoc6 0x16000800 0 0 0 \ + $@{TARGET@}.cm4 +flash bank super_flash_nar_cm4 psoc6 0x16001A00 0 0 0 \ + $@{TARGET@}.cm4 +flash bank super_flash_key_cm4 psoc6 0x16005A00 0 0 0 \ + $@{TARGET@}.cm4 +flash bank super_flash_toc2_cm4 psoc6 0x16007C00 0 0 0 \ + $@{TARGET@}.cm4 @end example psoc6-specific commands @@ -7110,7 +7131,8 @@ will be touched). Example usage: @example -# swap bank 1 and bank 2 in dual bank devices, by setting SWAP_BANK_OPT bit in OPTSR_PRG +# swap bank 1 and bank 2 in dual bank devices +# by setting SWAP_BANK_OPT bit in OPTSR_PRG stm32h7x option_write 0 0x20 0x8000000 0x8000000 @end example @end deffn @@ -10069,7 +10091,7 @@ Perform a 32-bit DMI write of value at address. Synopsys DesignWare ARC Processors are a family of 32-bit CPUs that SoC designers can optimize for a wide range of uses, from deeply embedded to high-performance host applications in a variety of market segments. See more -at: http://www.synopsys.com/IP/ProcessorIP/ARCProcessors/Pages/default.aspx. +at: @url{http://www.synopsys.com/IP/ProcessorIP/ARCProcessors/Pages/default.aspx}. OpenOCD currently supports ARC EM processors. There is a set ARC-specific OpenOCD commands that allow low-level access to the core and provide necessary support for ARC extensibility and @@ -10681,7 +10703,8 @@ target remote localhost:3333 @item A pipe connection is typically started as follows: @example -target extended-remote | openocd -c "gdb_port pipe; log_output openocd.log" +target extended-remote | \ + openocd -c "gdb_port pipe; log_output openocd.log" @end example This would cause GDB to run OpenOCD and communicate using pipes (stdin/stdout). Using this method has the advantage of GDB starting/stopping OpenOCD for the debug @@ -10895,17 +10918,11 @@ Cyg_Thread::thread_list, Cyg_Scheduler_Base::current_thread. @item ThreadX symbols _tx_thread_current_ptr, _tx_thread_created_ptr, _tx_thread_created_count. @item FreeRTOS symbols -@c The following is taken from recent texinfo to provide compatibility -@c with ancient versions that do not support @raggedright -@tex -\begingroup -\rightskip0pt plus2em \spaceskip.3333em \xspaceskip.5em\relax +@raggedright pxCurrentTCB, pxReadyTasksLists, xDelayedTaskList1, xDelayedTaskList2, pxDelayedTaskList, pxOverflowDelayedTaskList, xPendingReadyList, uxCurrentNumberOfTasks, uxTopUsedPriority. -\par -\endgroup -@end tex +@end raggedright @item linux symbols init_task. @item ChibiOS symbols @@ -10916,11 +10933,14 @@ Rtos::sListSuspended, Rtos::sMaxPriorities, Rtos::sCurrentTaskCount. @item mqx symbols _mqx_kernel_data, MQX_init_struct. @item uC/OS-III symbols -OSRunning, OSTCBCurPtr, OSTaskDbgListPtr, OSTaskQty +OSRunning, OSTCBCurPtr, OSTaskDbgListPtr, OSTaskQty. @item nuttx symbols -g_readytorun, g_tasklisttable +g_readytorun, g_tasklisttable. @item RIOT symbols -sched_threads, sched_num_threads, sched_active_pid, max_threads, _tcb_name_offset +@raggedright +sched_threads, sched_num_threads, sched_active_pid, max_threads, +_tcb_name_offset. +@end raggedright @end table For most RTOS supported the above symbols will be exported by default. However for From f67d7a3c48fcb21c735c7d28c060c875adb9b836 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Wed, 23 Dec 2020 23:28:52 +0300 Subject: [PATCH 004/120] contrib: rpc_examples: haskell: fix ftbs with current libraries And get rid of some warnings along the way. Change-Id: I8fdbe1fa304276be6b0f25249b902b3576aa3793 Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/5987 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/rpc_examples/ocdrpc.hs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/contrib/rpc_examples/ocdrpc.hs b/contrib/rpc_examples/ocdrpc.hs index 9a80cdd84..859864131 100644 --- a/contrib/rpc_examples/ocdrpc.hs +++ b/contrib/rpc_examples/ocdrpc.hs @@ -16,13 +16,11 @@ module Main where import Prelude -import Control.Applicative import Network.Socket import System.IO.Streams.Core hiding (connect) import System.IO.Streams.Network import System.IO.Streams.Attoparsec import Data.Attoparsec.ByteString.Char8 -import Data.Attoparsec.Combinator import Data.ByteString.Char8 hiding (putStrLn, concat, map) import Text.Printf @@ -38,15 +36,14 @@ mdwParser = (manyTill anyChar (string ": ") *> `sepBy` string " \n" ocdMdw :: (InputStream ByteString, OutputStream ByteString) -> Integer -> Integer -> IO [Integer] -ocdMdw s start count = do - s <- ocdExec s $ "mdw " ++ show start ++ " " ++ show count - case parseOnly mdwParser (pack s) of +ocdMdw s start qnt = do + res <- ocdExec s $ "mdw " ++ show start ++ " " ++ show qnt + case parseOnly mdwParser (pack res) of Right r -> return $ concat r main = do osock <- socket AF_INET Stream defaultProtocol - haddr <- inet_addr "127.0.0.1" - connect osock (SockAddrInet 6666 haddr) + connect osock (SockAddrInet 6666 $ tupleToHostAddress (127,0,0,1)) ostreams <- socketToStreams osock putStrLn "Halting the target, full log output captured:" ocdExec ostreams "capture \"halt\"" >>= putStrLn From d4bf20756647c0b74f99ad888bbd65176819248f Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 23 Dec 2020 19:15:02 +0100 Subject: [PATCH 005/120] Makefile.am: fix override of target 'check-recursive' To prevent executing the Jim Tcl tests, the makefile's target 'check-recursive' has been overridden in commit 56d163ce7951 ("jimtcl: update to 0.77, the current version, enable only specific modules"). This causes a runtime warning during build: Makefile:6332: warning: overriding recipe for target 'check-recursive' Makefile:5098: warning: ignoring old recipe for target 'check-recursive' Instead of override the makefile's target 'check-recursive', prevent the recursion by re-assigning as empty the variable SUBDIRS for this specific target only. Change-Id: I03d1c467eba42316a59aeed4612d6bdbe6211282 Signed-off-by: Antonio Borneo Fixes: 56d163ce7951 ("jimtcl: update to 0.77, the current version, enable only specific modules") Reviewed-on: http://openocd.zylin.com/5986 Tested-by: jenkins --- Makefile.am | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Makefile.am b/Makefile.am index 7a718d769..c1de02da0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,8 +6,7 @@ AUTOMAKE_OPTIONS = gnu 1.6 DISTCHECK_CONFIGURE_FLAGS = --disable-install-jim # do not run Jim Tcl tests (esp. during distcheck) -check-recursive: - @true +check-recursive: SUBDIRS := nobase_dist_pkgdata_DATA = \ contrib/libdcc/dcc_stdio.c \ From e22198c1521fdf98c0fc1a524df2af0ef947ec21 Mon Sep 17 00:00:00 2001 From: Jiri Kastner Date: Sun, 3 Jan 2021 10:10:11 +0100 Subject: [PATCH 006/120] contrib: udev file for Cypress SuperSpeed Explorer kit lsusb output: Bus 003 Device 011: ID 04b4:0007 Cypress Semiconductor Corp. Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 8 idVendor 0x04b4 Cypress Semiconductor Corp. idProduct 0x0007 bcdDevice 0.00 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 114 bNumInterfaces 4 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xa0 (Bus Powered) Remote Wakeup MaxPower 100mA Interface Association: bLength 8 bDescriptorType 11 bFirstInterface 0 bInterfaceCount 2 bFunctionClass 2 Communications bFunctionSubClass 2 Abstract (modem) bFunctionProtocol 1 AT-commands (v.25ter) iFunction 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 1 bInterfaceClass 2 Communications bInterfaceSubClass 2 Abstract (modem) bInterfaceProtocol 1 AT-commands (v.25ter) iInterface 0 CDC Header: bcdCDC 1.10 CDC ACM: bmCapabilities 0x02 line coding and serial state CDC Union: bMasterInterface 0 bSlaveInterface 1 CDC Call Management: bmCapabilities 0x00 bDataInterface 1 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x83 EP 3 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 10 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 1 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 10 CDC Data bInterfaceSubClass 0 Unused bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x01 EP 1 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x82 EP 2 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 0 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 2 bAlternateSetting 0 bNumEndpoints 3 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 4 bInterfaceProtocol 0 iInterface 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x04 EP 4 OUT bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x85 EP 5 IN bmAttributes 2 Transfer Type Bulk Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 0 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x86 EP 6 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0040 1x 64 bytes bInterval 10 Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 3 bAlternateSetting 0 bNumEndpoints 0 bInterfaceClass 255 Vendor Specific Class bInterfaceSubClass 5 bInterfaceProtocol 0 iInterface 0 Change-Id: I62f0300199da3551c8774a4a5a4cd106a3ab2904 Signed-off-by: Ricardo Ribalda Delgado Signed-off-by: Jiri Kastner Reviewed-on: http://openocd.zylin.com/3611 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/60-openocd.rules | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index fe57364d7..b886df50b 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -81,6 +81,9 @@ ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374e", MODE="660", GROUP="plugdev", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374f", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0483", ATTRS{idProduct}=="3753", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Cypress SuperSpeed Explorer Kit +ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="0007", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Cypress KitProg in KitProg mode ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f139", MODE="660", GROUP="plugdev", TAG+="uaccess" From c1270bcb38477a0c8a8be32921fccda61f9c06c7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 4 Jan 2021 19:24:21 +0100 Subject: [PATCH 007/120] target: fix memory leak on multiple '-gdb-port' flag In the odd case of multiple flags '-gdb-port' during 'target create' or following 'configure', the new strdup()'ed value will replace the old one without freeing it. Free the old value (if it exists) before replacing it. Change-Id: I1673346613ce7023880046e3a9ba473e75f18b8a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6005 Tested-by: jenkins --- src/target/target.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/target/target.c b/src/target/target.c index 3c1a6338e..c752844b0 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5123,6 +5123,7 @@ no_params: e = Jim_GetOpt_String(goi, &s, NULL); if (e != JIM_OK) return e; + free(target->gdb_port_override); target->gdb_port_override = strdup(s); } else { if (goi->argc != 0) From 3fbcb26f988c10286d00d08e488f87cddd4ebe38 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 3 Jan 2021 12:02:49 +0100 Subject: [PATCH 008/120] udev: fix permission for Ambiq Micro EVK's Commit 68e204f1e91a ("udev: Add rules for Ambiq Micro EVK's.") was initially proposed as http://openocd.zylin.com/3429/ then replaced by http://openocd.zylin.com/3980/ The initial proposal was for file '99-openocd.rules', in which MODE="664" was the norm. After merge of http://openocd.zylin.com/2804/ the new udev rules in '60-openocd.rules' switched to MODE="660", but the evolution of the above patch missed this change. Switch udev rules of Ambiq Micro EVK's to MODE="660" and uniform them to the rest of the file. Change-Id: I4b4eea535184ee8569da3264bff4f1fafb5bce4d Signed-off-by: Antonio Borneo Fixes: 68e204f1e91a ("udev: Add rules for Ambiq Micro EVK's.") Reviewed-on: http://openocd.zylin.com/6004 Tested-by: jenkins --- contrib/60-openocd.rules | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index b886df50b..e0864b827 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -161,9 +161,9 @@ ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="02a5", MODE="660", GROUP="plugdev", ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00ff", MODE="660", GROUP="plugdev", TAG+="uaccess" # Ambiq Micro EVK and Debug boards. -ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6010", MODE="664", GROUP="plugdev", TAG+="uaccess" -ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6011", MODE="664", GROUP="plugdev", TAG+="uaccess" -ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="1106", MODE="664", GROUP="plugdev", TAG+="uaccess" +ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6010", MODE="660", GROUP="plugdev", TAG+="uaccess" +ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6011", MODE="660", GROUP="plugdev", TAG+="uaccess" +ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="1106", MODE="660", GROUP="plugdev", TAG+="uaccess" # Marvell Sheevaplug ATTRS{idVendor}=="9e88", ATTRS{idProduct}=="9e8f", MODE="660", GROUP="plugdev", TAG+="uaccess" From f83c2b0c7c53770df9771d46a32c045175d02284 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 16:49:11 +0100 Subject: [PATCH 009/120] doc/style: fix doxygen error Doxygen complains about non-closed nested comments: doc/manual/style.txt:423: warning: Reached end of file while still inside a (nested) comment. Nesting level 1 (probable line reference: 149) This is caused by the string '/**' that is interpreted as the beginning of a comment. Escape the string to not let doxygen consider it as a comment While there, replace @code/@endcode with @verbatim/@endverbatim to properly render the line. Change-Id: If2a27c4cf659326e317cc4ac8c0b313e97e40432 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5996 Tested-by: jenkins --- doc/manual/style.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual/style.txt b/doc/manual/style.txt index 7191a4b0e..dad3bb440 100644 --- a/doc/manual/style.txt +++ b/doc/manual/style.txt @@ -186,9 +186,9 @@ comments. "empty" lines should be removed from the block. -# Only single spaces should be used; do @b not add mid-line indentation. -# If the total line length will be less than 72-80 columns, then - - The @c /**< form can be used on the same line. + - The @c /\**< form can be used on the same line. - This style should be used sparingly; the best use is for fields: - @code int field; /**< field description */ @endcode + @verbatim int field; /**< field description */ @endverbatim @section styledoxyall Doxygen Style Guide From a16e8ba455c901c9656eebf9f7c06d3dc5844e6b Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 17:00:59 +0100 Subject: [PATCH 010/120] flash/nor/max32xxx: fix path of include file The relative path should have three times '..'. Issue identified by doxygen: src/flash/nor/max32xxx.c:85: warning: include file ../../contrib/loaders/flash/max32xxx/max32xxx.inc not found, perhaps you forgot to add its directory to INCLUDE_PATH? Change-Id: Ie7b4948c6770b8acb9eff26e08eea32945ebb219 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5997 Tested-by: jenkins --- src/flash/nor/max32xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index 9a5e83fa0..586a73b1d 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -82,7 +82,7 @@ struct max32xxx_flash_bank { /* see contrib/loaders/flash/max32xxx/max32xxx.s for src */ static const uint8_t write_code[] = { -#include "../../contrib/loaders/flash/max32xxx/max32xxx.inc" +#include "../../../contrib/loaders/flash/max32xxx/max32xxx.inc" }; /* Config Command: flash bank name driver base size chip_width bus_width target [driver_option] From f94495154d7b8c15c8e207f76afecbe7d0aac53e Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 17:13:12 +0100 Subject: [PATCH 011/120] Doxyfile.in: fix build out-of-tree When doxygen is built out-of-tree, it fails to find the generated file startup_tcl.inc: src/openocd.c:59: warning: include file startup_tcl.inc not found, perhaps you forgot to add its directory to INCLUDE_PATH? Add '@builddir@/src' to INCLUDE_PATH. Change-Id: I51f2f6fe7224bba0f8b3db7219f9831de4e67139 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5998 Tested-by: jenkins --- Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile.in b/Doxyfile.in index 6e68b4e37..55ed7f0f1 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -1234,7 +1234,7 @@ SEARCH_INCLUDES = YES # contain include files that are not input files but should be processed by # the preprocessor. -INCLUDE_PATH = +INCLUDE_PATH = @builddir@/src # You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard # patterns (like *.h and *.hpp) to filter out the header-files in the From fa476daa60b51881938577d102893e6443ea8bf8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 17:32:26 +0100 Subject: [PATCH 012/120] doc/manual/primer/jtag.txt: remove duplicated section name The section name 'primerjtag' is used twice, causing doxygen to complain: warning: multiple use of section label 'primerjtag', (first occurrence: doc/manual/primer/jtag.txt, line 107) Rename one of them. Change-Id: Id307915dbc51a7f647fab4fb28ab431e65344d61 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5999 Tested-by: jenkins --- doc/manual/primer/jtag.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/primer/jtag.txt b/doc/manual/primer/jtag.txt index 41eef723d..097e20d10 100644 --- a/doc/manual/primer/jtag.txt +++ b/doc/manual/primer/jtag.txt @@ -104,7 +104,7 @@ target chips and work out what the various instruction registers/data registers do, so you can actually do something useful. That's where it gets interesting. But in and of itself, JTAG is actually very simple. -@section primerjtag More Reading +@section primerjtagmore More Reading A separate primer contains information about @subpage primerjtagbs for developers that want to extend OpenOCD for such purposes. From 02bd67db3f85b9764b6c4a3556d070a3345e4103 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 17:39:57 +0100 Subject: [PATCH 013/120] Doxyfile.in: exclude libjaylink from doxygen When build using libjaylink as git submodule, doxygen includes the libjaylink files and complains for multiple 'mainpage' comment block, one in OpenOCD and the other in libjaylink: src/jtag/drivers/libjaylink/libjaylink/core.c:37: warning: found more than one \mainpage comment block! (first occurrence: doc/manual/main.txt, line 1), Skipping current block! Exclude libjaylink submodule from doxygen. Change-Id: I5e856817344c9f21f8c26f077a23c00b83cfbcb5 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6000 Tested-by: jenkins --- Doxyfile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doxyfile.in b/Doxyfile.in index 55ed7f0f1..9be53d0fc 100644 --- a/Doxyfile.in +++ b/Doxyfile.in @@ -600,7 +600,7 @@ RECURSIVE = YES # excluded from the INPUT source files. This way you can easily exclude a # subdirectory from a directory tree whose root is specified with the INPUT tag. -EXCLUDE = +EXCLUDE = @srcdir@/src/jtag/drivers/libjaylink # The EXCLUDE_SYMLINKS tag can be used select whether or not files or # directories that are symbolic links (a Unix filesystem feature) are excluded From 4cf5ab614bd830355065bb9400acf5484dc3f2c3 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 18:17:20 +0100 Subject: [PATCH 014/120] openocd: fix incorrect doxygen comments Use '@param' in front of function's parameters and '@a' when the parameter is recalled in the description. This fixes doxygen complains: warning: Found unknown command '@buff16' While there, fix a minor typo s/occured/occurred/ in a comment and the typo s/@apram/@param/ in a doxygen comment. Change-Id: I5cd86a80adef552331310a21c55ec5d11354be21 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6001 Tested-by: jenkins --- src/flash/nor/dsp5680xx_flash.c | 4 +- src/helper/bits.h | 16 +- src/helper/list.h | 212 ++++++++++----------- src/jtag/drivers/jtag_dpi.c | 8 +- src/jtag/drivers/jtag_vpi.c | 20 +- src/jtag/drivers/usb_blaster/usb_blaster.c | 54 +++--- src/target/dsp5680xx.c | 24 +-- 7 files changed, 169 insertions(+), 169 deletions(-) diff --git a/src/flash/nor/dsp5680xx_flash.c b/src/flash/nor/dsp5680xx_flash.c index 6f1eccfeb..49022825e 100644 --- a/src/flash/nor/dsp5680xx_flash.c +++ b/src/flash/nor/dsp5680xx_flash.c @@ -193,8 +193,8 @@ static int dsp5680xx_probe(struct flash_bank *bank) /** * The flash module (FM) on the dsp5680xx supports both individual sector * and mass erase of the flash memory. - * If this function is called with @first == @last == 0 or if @first is the - * first sector (#0) and @last is the last sector then the mass erase command + * If this function is called with @a first == @a last == 0 or if @a first is the + * first sector (#0) and @a last is the last sector then the mass erase command * is executed (much faster than erasing each sector individually). * * @param bank diff --git a/src/helper/bits.h b/src/helper/bits.h index 464584db8..cdcac9eaf 100644 --- a/src/helper/bits.h +++ b/src/helper/bits.h @@ -36,8 +36,8 @@ /** * bitmap_zero - Clears all the bits in memory - * @dst: the address of the bitmap - * @nbits: the number of bits to clear + * @param dst the address of the bitmap + * @param nbits the number of bits to clear */ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) { @@ -47,8 +47,8 @@ static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) /** * clear_bit - Clear a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from + * @param nr the bit to set + * @param addr the address to start counting from */ static inline void clear_bit(unsigned int nr, volatile unsigned long *addr) { @@ -60,8 +60,8 @@ static inline void clear_bit(unsigned int nr, volatile unsigned long *addr) /** * set_bit - Set a bit in memory - * @nr: the bit to set - * @addr: the address to start counting from + * @param nr the bit to set + * @param addr the address to start counting from */ static inline void set_bit(unsigned int nr, volatile unsigned long *addr) { @@ -73,8 +73,8 @@ static inline void set_bit(unsigned int nr, volatile unsigned long *addr) /** * test_bit - Determine whether a bit is set - * @nr: bit number to test - * @addr: Address to start counting from + * @param nr bit number to test + * @param addr Address to start counting from */ static inline int test_bit(unsigned int nr, const volatile unsigned long *addr) { diff --git a/src/helper/list.h b/src/helper/list.h index 6fd0e7ca7..7f6046441 100644 --- a/src/helper/list.h +++ b/src/helper/list.h @@ -64,8 +64,8 @@ extern void __list_add(struct list_head *new, /** * list_add - add a new entry - * @new: new entry to be added - * @head: list head to add it after + * @param new new entry to be added + * @param head list head to add it after * * Insert a new entry after the specified head. * This is good for implementing stacks. @@ -78,8 +78,8 @@ static inline void list_add(struct list_head *new, struct list_head *head) /** * list_add_tail - add a new entry - * @new: new entry to be added - * @head: list head to add it before + * @param new new entry to be added + * @param head list head to add it before * * Insert a new entry before the specified head. * This is useful for implementing queues. @@ -104,7 +104,7 @@ static inline void __list_del(struct list_head *prev, struct list_head *next) /** * list_del - deletes entry from list. - * @entry: the element to delete from the list. + * @param entry the element to delete from the list. * Note: list_empty() on entry does not return true after this, the entry is * in an undefined state. */ @@ -127,10 +127,10 @@ extern void list_del(struct list_head *entry); /** * list_replace - replace old entry by new one - * @old : the element to be replaced - * @new : the new element to insert + * @param old the element to be replaced + * @param new the new element to insert * - * If @old was empty, it will be overwritten. + * If @a old was empty, it will be overwritten. */ static inline void list_replace(struct list_head *old, struct list_head *new) @@ -150,7 +150,7 @@ static inline void list_replace_init(struct list_head *old, /** * list_del_init - deletes entry from list and reinitialize it. - * @entry: the element to delete from the list. + * @param entry the element to delete from the list. */ static inline void list_del_init(struct list_head *entry) { @@ -160,8 +160,8 @@ static inline void list_del_init(struct list_head *entry) /** * list_move - delete from one list and add as another's head - * @list: the entry to move - * @head: the head that will precede our entry + * @param list the entry to move + * @param head the head that will precede our entry */ static inline void list_move(struct list_head *list, struct list_head *head) { @@ -171,8 +171,8 @@ static inline void list_move(struct list_head *list, struct list_head *head) /** * list_move_tail - delete from one list and add as another's tail - * @list: the entry to move - * @head: the head that will follow our entry + * @param list the entry to move + * @param head the head that will follow our entry */ static inline void list_move_tail(struct list_head *list, struct list_head *head) @@ -182,9 +182,9 @@ static inline void list_move_tail(struct list_head *list, } /** - * list_is_last - tests whether @list is the last entry in list @head - * @list: the entry to test - * @head: the head of the list + * list_is_last - tests whether @a list is the last entry in list @a head + * @param list the entry to test + * @param head the head of the list */ static inline int list_is_last(const struct list_head *list, const struct list_head *head) @@ -194,7 +194,7 @@ static inline int list_is_last(const struct list_head *list, /** * list_empty - tests whether a list is empty - * @head: the list to test. + * @param head the list to test. */ static inline int list_empty(const struct list_head *head) { @@ -203,7 +203,7 @@ static inline int list_empty(const struct list_head *head) /** * list_empty_careful - tests whether a list is empty and not being modified - * @head: the list to test + * @param head the list to test * * Description: * tests whether a list is empty _and_ checks that no other CPU might be @@ -222,7 +222,7 @@ static inline int list_empty_careful(const struct list_head *head) /** * list_rotate_left - rotate the list to the left - * @head: the head of the list + * @param head the head of the list */ static inline void list_rotate_left(struct list_head *head) { @@ -236,7 +236,7 @@ static inline void list_rotate_left(struct list_head *head) /** * list_is_singular - tests whether a list has just one entry. - * @head: the list to test. + * @param head the list to test. */ static inline int list_is_singular(const struct list_head *head) { @@ -257,14 +257,14 @@ static inline void __list_cut_position(struct list_head *list, /** * list_cut_position - cut a list into two - * @list: a new list to add all removed entries - * @head: a list with entries - * @entry: an entry within head, could be the head itself + * @param list a new list to add all removed entries + * @param head a list with entries + * @param entry an entry within head, could be the head itself * and if so we won't cut the list * - * This helper moves the initial part of @head, up to and - * including @entry, from @head to @list. You should - * pass on @entry an element you know is on @head. @list + * This helper moves the initial part of @a head, up to and + * including @a entry, from @a head to @a list. You should + * pass on @a entry an element you know is on @a head. @a list * should be an empty list or a list you do not care about * losing its data. * @@ -299,8 +299,8 @@ static inline void __list_splice(const struct list_head *list, /** * list_splice - join two lists, this is designed for stacks - * @list: the new list to add. - * @head: the place to add it in the first list. + * @param list the new list to add. + * @param head the place to add it in the first list. */ static inline void list_splice(const struct list_head *list, struct list_head *head) @@ -311,8 +311,8 @@ static inline void list_splice(const struct list_head *list, /** * list_splice_tail - join two lists, each list being a queue - * @list: the new list to add. - * @head: the place to add it in the first list. + * @param list the new list to add. + * @param head the place to add it in the first list. */ static inline void list_splice_tail(struct list_head *list, struct list_head *head) @@ -323,10 +323,10 @@ static inline void list_splice_tail(struct list_head *list, /** * list_splice_init - join two lists and reinitialise the emptied list. - * @list: the new list to add. - * @head: the place to add it in the first list. + * @param list the new list to add. + * @param head the place to add it in the first list. * - * The list at @list is reinitialised + * The list at @a list is reinitialised */ static inline void list_splice_init(struct list_head *list, struct list_head *head) @@ -339,11 +339,11 @@ static inline void list_splice_init(struct list_head *list, /** * list_splice_tail_init - join two lists and reinitialise the emptied list - * @list: the new list to add. - * @head: the place to add it in the first list. + * @param list the new list to add. + * @param head the place to add it in the first list. * * Each of the lists is a queue. - * The list at @list is reinitialised + * The list at @a list is reinitialised */ static inline void list_splice_tail_init(struct list_head *list, struct list_head *head) @@ -356,18 +356,18 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. + * @param ptr the &struct list_head pointer. + * @param type the type of the struct this is embedded in. + * @param member the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ container_of(ptr, type, member) /** * list_first_entry - get the first element from a list - * @ptr: the list head to take the element from. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. + * @param ptr the list head to take the element from. + * @param type the type of the struct this is embedded in. + * @param member the name of the list_struct within the struct. * * Note, that list is expected to be not empty. */ @@ -376,8 +376,8 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop cursor. - * @head: the head for your list. + * @param pos the &struct list_head to use as a loop cursor. + * @param head the head for your list. */ #define list_for_each(pos, head) \ for (pos = (head)->next; prefetch(pos->next), pos != (head); \ @@ -385,8 +385,8 @@ static inline void list_splice_tail_init(struct list_head *list, /** * __list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop cursor. - * @head: the head for your list. + * @param pos the &struct list_head to use as a loop cursor. + * @param head the head for your list. * * This variant differs from list_for_each() in that it's the * simplest possible list iteration code, no prefetching is done. @@ -398,8 +398,8 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_prev - iterate over a list backwards - * @pos: the &struct list_head to use as a loop cursor. - * @head: the head for your list. + * @param pos the &struct list_head to use as a loop cursor. + * @param head the head for your list. */ #define list_for_each_prev(pos, head) \ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \ @@ -407,9 +407,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_safe - iterate over a list safe against removal of list entry - * @pos: the &struct list_head to use as a loop cursor. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. + * @param pos the &struct list_head to use as a loop cursor. + * @param n another &struct list_head to use as temporary storage + * @param head the head for your list. */ #define list_for_each_safe(pos, n, head) \ for (pos = (head)->next, n = pos->next; pos != (head); \ @@ -417,9 +417,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_prev_safe - iterate over a list backwards safe against removal of list entry - * @pos: the &struct list_head to use as a loop cursor. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. + * @param pos the &struct list_head to use as a loop cursor. + * @param n another &struct list_head to use as temporary storage + * @param head the head for your list. */ #define list_for_each_prev_safe(pos, n, head) \ for (pos = (head)->prev, n = pos->prev; \ @@ -428,9 +428,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the list_struct within the struct. */ #define list_for_each_entry(pos, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member); \ @@ -439,9 +439,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_reverse - iterate backwards over list of given type. - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the list_struct within the struct. */ #define list_for_each_entry_reverse(pos, head, member) \ for (pos = list_entry((head)->prev, typeof(*pos), member); \ @@ -450,9 +450,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_prepare_entry - prepare a pos entry for use in list_for_each_entry_continue() - * @pos: the type * to use as a start point - * @head: the head of the list - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a start point + * @param head the head of the list + * @param member the name of the list_struct within the struct. * * Prepares a pos entry for use as a start point in list_for_each_entry_continue(). */ @@ -461,9 +461,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_continue - continue iteration over list of given type - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Continue to iterate over list of given type, continuing after * the current position. @@ -475,9 +475,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_continue_reverse - iterate backwards from the given point - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Start to iterate over list of given type backwards, continuing after * the current position. @@ -489,9 +489,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_from - iterate over list of given type from the current point - * @pos: the type * to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Iterate over list of given type, continuing from current position. */ @@ -501,10 +501,10 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param n another type * to use as temporary storage + * @param head the head for your list. + * @param member the name of the list_struct within the struct. */ #define list_for_each_entry_safe(pos, n, head, member) \ for (pos = list_entry((head)->next, typeof(*pos), member), \ @@ -514,10 +514,10 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_safe_continue - continue list iteration safe against removal - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param n another type * to use as temporary storage + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Iterate over list of given type, continuing after current point, * safe against removal of list entry. @@ -530,10 +530,10 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_safe_from - iterate over list from current point safe against removal - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param n another type * to use as temporary storage + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Iterate over list of given type from current point, safe against * removal of list entry. @@ -545,10 +545,10 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_for_each_entry_safe_reverse - iterate backwards over list safe against removal - * @pos: the type * to use as a loop cursor. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_struct within the struct. + * @param pos the type * to use as a loop cursor. + * @param n another type * to use as temporary storage + * @param head the head for your list. + * @param member the name of the list_struct within the struct. * * Iterate backwards over list of given type, safe against removal * of list entry. @@ -561,9 +561,9 @@ static inline void list_splice_tail_init(struct list_head *list, /** * list_safe_reset_next - reset a stale list_for_each_entry_safe loop - * @pos: the loop cursor used in the list_for_each_entry_safe loop - * @n: temporary storage used in list_for_each_entry_safe - * @member: the name of the list_struct within the struct. + * @param pos the loop cursor used in the list_for_each_entry_safe loop + * @param n temporary storage used in list_for_each_entry_safe + * @param member the name of the list_struct within the struct. * * list_safe_reset_next is not safe to use in general if the list may be * modified concurrently (eg. the lock is dropped in the loop body). An @@ -686,10 +686,10 @@ static inline void hlist_move_list(struct hlist_head *old, /** * hlist_for_each_entry - iterate over list of given type - * @tpos: the type * to use as a loop cursor. - * @pos: the &struct hlist_node to use as a loop cursor. - * @head: the head for your list. - * @member: the name of the hlist_node within the struct. + * @param tpos the type * to use as a loop cursor. + * @param pos the &struct hlist_node to use as a loop cursor. + * @param head the head for your list. + * @param member the name of the hlist_node within the struct. */ #define hlist_for_each_entry(tpos, pos, head, member) \ for (pos = (head)->first; \ @@ -699,9 +699,9 @@ static inline void hlist_move_list(struct hlist_head *old, /** * hlist_for_each_entry_continue - iterate over a hlist continuing after current point - * @tpos: the type * to use as a loop cursor. - * @pos: the &struct hlist_node to use as a loop cursor. - * @member: the name of the hlist_node within the struct. + * @param tpos the type * to use as a loop cursor. + * @param pos the &struct hlist_node to use as a loop cursor. + * @param member the name of the hlist_node within the struct. */ #define hlist_for_each_entry_continue(tpos, pos, member) \ for (pos = (pos)->next; \ @@ -711,9 +711,9 @@ static inline void hlist_move_list(struct hlist_head *old, /** * hlist_for_each_entry_from - iterate over a hlist continuing from current point - * @tpos: the type * to use as a loop cursor. - * @pos: the &struct hlist_node to use as a loop cursor. - * @member: the name of the hlist_node within the struct. + * @param tpos the type * to use as a loop cursor. + * @param pos the &struct hlist_node to use as a loop cursor. + * @param member the name of the hlist_node within the struct. */ #define hlist_for_each_entry_from(tpos, pos, member) \ for (; pos && ({ prefetch(pos->next); 1; }) && \ @@ -722,11 +722,11 @@ static inline void hlist_move_list(struct hlist_head *old, /** * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry - * @tpos: the type * to use as a loop cursor. - * @pos: the &struct hlist_node to use as a loop cursor. - * @n: another &struct hlist_node to use as temporary storage - * @head: the head for your list. - * @member: the name of the hlist_node within the struct. + * @param tpos the type * to use as a loop cursor. + * @param pos the &struct hlist_node to use as a loop cursor. + * @param n another &struct hlist_node to use as temporary storage + * @param head the head for your list. + * @param member the name of the hlist_node within the struct. */ #define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ for (pos = (head)->first; \ diff --git a/src/jtag/drivers/jtag_dpi.c b/src/jtag/drivers/jtag_dpi.c index 575c6bce2..7cac20051 100644 --- a/src/jtag/drivers/jtag_dpi.c +++ b/src/jtag/drivers/jtag_dpi.c @@ -79,8 +79,8 @@ static int read_sock(char *buf, size_t len) /** * jtag_dpi_reset - ask to reset the JTAG device - * @trst: 1 if TRST is to be asserted - * @srst: 1 if SRST is to be asserted + * @param trst 1 if TRST is to be asserted + * @param srst 1 if SRST is to be asserted */ static int jtag_dpi_reset(int trst, int srst) { @@ -109,11 +109,11 @@ static int jtag_dpi_reset(int trst, int srst) /** * jtag_dpi_scan - launches a DR-scan or IR-scan - * @cmd: the command to launch + * @param cmd the command to launch * * Launch a JTAG IR-scan or DR-scan * - * Returns ERROR_OK if OK, ERROR_xxx if a read/write error occured. + * Returns ERROR_OK if OK, ERROR_xxx if a read/write error occurred. */ static int jtag_dpi_scan(struct scan_command *cmd) { diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index 32a43f8bf..a6609d21e 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -208,8 +208,8 @@ static int jtag_vpi_receive_cmd(struct vpi_cmd *vpi) /** * jtag_vpi_reset - ask to reset the JTAG device - * @trst: 1 if TRST is to be asserted - * @srst: 1 if SRST is to be asserted + * @param trst 1 if TRST is to be asserted + * @param srst 1 if SRST is to be asserted */ static int jtag_vpi_reset(int trst, int srst) { @@ -223,8 +223,8 @@ static int jtag_vpi_reset(int trst, int srst) /** * jtag_vpi_tms_seq - ask a TMS sequence transition to JTAG - * @bits: TMS bits to be written (bit0, bit1 .. bitN) - * @nb_bits: number of TMS bits (between 1 and 8) + * @param bits TMS bits to be written (bit0, bit1 .. bitN) + * @param nb_bits number of TMS bits (between 1 and 8) * * Write a series of TMS transitions, where each transition consists in : * - writing out TCK=0, TMS=, TDI= @@ -250,7 +250,7 @@ static int jtag_vpi_tms_seq(const uint8_t *bits, int nb_bits) /** * jtag_vpi_path_move - ask a TMS sequence transition to JTAG - * @cmd: path transition + * @param cmd path transition * * Write a series of TMS transitions, where each transition consists in : * - writing out TCK=0, TMS=, TDI= @@ -276,7 +276,7 @@ static int jtag_vpi_path_move(struct pathmove_command *cmd) /** * jtag_vpi_tms - ask a tms command - * @cmd: tms command + * @param cmd tms command */ static int jtag_vpi_tms(struct tms_command *cmd) { @@ -342,8 +342,8 @@ static int jtag_vpi_queue_tdi_xfer(uint8_t *bits, int nb_bits, int tap_shift) /** * jtag_vpi_queue_tdi - short description - * @bits: bits to be queued on TDI (or NULL if 0 are to be queued) - * @nb_bits: number of bits + * @param bits bits to be queued on TDI (or NULL if 0 are to be queued) + * @param nb_bits number of bits */ static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift) { @@ -372,7 +372,7 @@ static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift) /** * jtag_vpi_clock_tms - clock a TMS transition - * @tms: the TMS to be sent + * @param tms the TMS to be sent * * Triggers a TMS transition (ie. one JTAG TAP state move). */ @@ -386,7 +386,7 @@ static int jtag_vpi_clock_tms(int tms) /** * jtag_vpi_scan - launches a DR-scan or IR-scan - * @cmd: the command to launch + * @param cmd the command to launch * * Launch a JTAG IR-scan or DR-scan * diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index de3b5d58b..5559bcedb 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -253,7 +253,7 @@ static void ublast_flush_buffer(void) /** * ublast_queue_byte - queue one 'bitbang mode' byte for USB Blaster - * @abyte: the byte to queue + * @param abyte the byte to queue * * Queues one byte in 'bitbang mode' to the USB Blaster. The byte is not * actually sent, but stored in a buffer. The write is performed once @@ -271,7 +271,7 @@ static void ublast_queue_byte(uint8_t abyte) /** * ublast_compute_pin - compute if gpio should be asserted - * @steer: control (ie. TRST driven, SRST driven, of fixed) + * @param steer control (ie. TRST driven, SRST driven, of fixed) * * Returns pin value (1 means driven high, 0 mean driven low) */ @@ -293,7 +293,7 @@ static bool ublast_compute_pin(enum gpio_steer steer) /** * ublast_build_out - build bitbang mode output byte - * @type: says if reading back TDO is required + * @param type says if reading back TDO is required * * Returns the compute bitbang mode byte */ @@ -313,8 +313,8 @@ static uint8_t ublast_build_out(enum scan_type type) /** * ublast_reset - reset the JTAG device is possible - * @trst: 1 if TRST is to be asserted - * @srst: 1 if SRST is to be asserted + * @param trst 1 if TRST is to be asserted + * @param srst 1 if SRST is to be asserted */ static void ublast_reset(int trst, int srst) { @@ -329,7 +329,7 @@ static void ublast_reset(int trst, int srst) /** * ublast_clock_tms - clock a TMS transition - * @tms: the TMS to be sent + * @param tms the TMS to be sent * * Triggers a TMS transition (ie. one JTAG TAP state move). */ @@ -360,8 +360,8 @@ static void ublast_idle_clock(void) /** * ublast_clock_tdi - Output a TDI with bitbang mode - * @tdi: the TDI bit to be shifted out - * @type: scan type (ie. does a readback of TDO is required) + * @param tdi the TDI bit to be shifted out + * @param type scan type (ie. does a readback of TDO is required) * * Output a TDI bit and assert clock to push it into the JTAG device : * - writing out TCK=0, TMS==0, TDI= @@ -387,8 +387,8 @@ static void ublast_clock_tdi(int tdi, enum scan_type type) /** * ublast_clock_tdi_flip_tms - Output a TDI with bitbang mode, change JTAG state - * @tdi: the TDI bit to be shifted out - * @type: scan type (ie. does a readback of TDO is required) + * @param tdi the TDI bit to be shifted out + * @param type scan type (ie. does a readback of TDO is required) * * This function is the same as ublast_clock_tdi(), but it changes also the TMS * while output the TDI. This should be the last TDI output of a TDI @@ -416,8 +416,8 @@ static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type) /** * ublast_queue_bytes - queue bytes for the USB Blaster - * @bytes: byte array - * @nb_bytes: number of bytes + * @param bytes byte array + * @param nb_bytes number of bytes * * Queues bytes to be sent to the USB Blaster. The bytes are not * actually sent, but stored in a buffer. The write is performed once @@ -443,9 +443,9 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes) /** * ublast_tms_seq - write a TMS sequence transition to JTAG - * @bits: TMS bits to be written (bit0, bit1 .. bitN) - * @nb_bits: number of TMS bits (between 1 and 8) - * @skip: number of TMS bits to skip at the beginning of the series + * @param bits TMS bits to be written (bit0, bit1 .. bitN) + * @param nb_bits number of TMS bits (between 1 and 8) + * @param skip number of TMS bits to skip at the beginning of the series * * Write a series of TMS transitions, where each transition consists in : * - writing out TCK=0, TMS=, TDI= @@ -465,7 +465,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip) /** * ublast_tms - write a tms command - * @cmd: tms command + * @param cmd tms command */ static void ublast_tms(struct tms_command *cmd) { @@ -475,7 +475,7 @@ static void ublast_tms(struct tms_command *cmd) /** * ublast_path_move - write a TMS sequence transition to JTAG - * @cmd: path transition + * @param cmd path transition * * Write a series of TMS transitions, where each transition consists in : * - writing out TCK=0, TMS=, TDI= @@ -501,8 +501,8 @@ static void ublast_path_move(struct pathmove_command *cmd) /** * ublast_state_move - move JTAG state to the target state - * @state: the target state - * @skip: number of bits to skip at the beginning of the path + * @param state the target state + * @param skip number of bits to skip at the beginning of the path * * Input the correct TMS sequence to the JTAG TAP so that we end up in the * target state. This assumes the current state (tap_get_state()) is correct. @@ -524,8 +524,8 @@ static void ublast_state_move(tap_state_t state, int skip) /** * ublast_read_byteshifted_tdos - read TDO of byteshift writes - * @buf: the buffer to store the bits - * @nb_bits: the number of bits + * @param buf the buffer to store the bits + * @param nb_bits the number of bits * * Reads back from USB Blaster TDO bits, triggered by a 'byteshift write', ie. eight * bits per received byte from USB interface, and store them in buffer. @@ -552,8 +552,8 @@ static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes) /** * ublast_read_bitbang_tdos - read TDO of bitbang writes - * @buf: the buffer to store the bits - * @nb_bits: the number of bits + * @param buf the buffer to store the bits + * @param nb_bits the number of bits * * Reads back from USB Blaster TDO bits, triggered by a 'bitbang write', ie. one * bit per received byte from USB interface, and store them in buffer, where : @@ -592,9 +592,9 @@ static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits) /** * ublast_queue_tdi - short description - * @bits: bits to be queued on TDI (or NULL if 0 are to be queued) - * @nb_bits: number of bits - * @scan: scan type (ie. if TDO read back is required or not) + * @param bits bits to be queued on TDI (or NULL if 0 are to be queued) + * @param nb_bits number of bits + * @param scan scan type (ie. if TDO read back is required or not) * * Outputs a series of TDI bits on TDI. * As a side effect, the last TDI bit is sent along a TMS=1, and triggers a JTAG @@ -703,7 +703,7 @@ static void ublast_stableclocks(int cycles) /** * ublast_scan - launches a DR-scan or IR-scan - * @cmd: the command to launch + * @param cmd the command to launch * * Launch a JTAG IR-scan or DR-scan * diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c index ee26d24ac..ec07c2519 100644 --- a/src/target/dsp5680xx.c +++ b/src/target/dsp5680xx.c @@ -117,7 +117,7 @@ static int dsp5680xx_drscan(struct target *target, uint8_t *d_in, * @param target * @param d_in This is the data that will be shifted into the JTAG IR reg. * @param d_out The data that will be shifted out of the JTAG IR reg will be stored here. - * @apram ir_len Length of the data to be shifted to JTAG IR. + * @param ir_len Length of the data to be shifted to JTAG IR. * */ static int dsp5680xx_irscan(struct target *target, uint32_t *d_in, @@ -1070,8 +1070,8 @@ static int dsp5680xx_resume(struct target *target, int current, } /** - * The value of @address determines if it corresponds to P: (program) or X: (dat) memory. - * If the address is over 0x200000 then it is considered X: memory, and @pmem = 0. + * The value of @a address determines if it corresponds to P: (program) or X: (dat) memory. + * If the address is over 0x200000 then it is considered X: memory, and @a pmem = 0. * The special case of 0xFFXXXX is not modified, since it allows to read out the * memory mapped EOnCE registers. * @@ -1405,8 +1405,8 @@ static int dsp5680xx_write_32(struct target *t, uint32_t a, uint32_t c, } /** - * Writes @buffer to memory. - * The parameter @address determines whether @buffer should be written to + * Writes @a buffer to memory. + * The parameter @a address determines whether @a buffer should be written to * P: (program) memory or X: (dat) memory. * * @param target @@ -1506,8 +1506,8 @@ static int dsp5680xx_checksum_memory(struct target *t, target_addr_t a, uint32_t } /** - * Calculates a signature over @word_count words in the data from @buff16. - * The algorithm used is the same the FM uses, so the @return may be used to compare + * Calculates a signature over @a word_count words in the data from @a buff16. + * The algorithm used is the same the FM uses, so the @a return may be used to compare * with the one generated by the FM module, and check if flashing was successful. * This algorithm is based on the perl script available from the Freescale website at FAQ 25630. * @@ -1606,14 +1606,14 @@ int dsp5680xx_f_protect_check(struct target *target, uint16_t *protected) /** * Executes a command on the FM module. - * Some commands use the parameters @address and @data, others ignore them. + * Some commands use the parameters @a address and @a data, others ignore them. * * @param target * @param command Command to execute. * @param address Command parameter. * @param data Command parameter. * @param hfm_ustat FM status register. - * @param pmem Address is P: (program) memory (@pmem == 1) or X: (dat) memory (@pmem == 0) + * @param pmem Address is P: (program) memory (@a pmem == 1) or X: (dat) memory (@a pmem == 0) * * @return */ @@ -1787,9 +1787,9 @@ static int set_fm_ck_div(struct target *target) /** * Executes the FM calculate signature command. The FM will calculate over the - * data from @address to @address + @words -1. The result is written to a - * register, then read out by this function and returned in @signature. The - * value @signature may be compared to the one returned by perl_crc to + * data from @a address to @a address + @a words -1. The result is written to a + * register, then read out by this function and returned in @a signature. The + * value @a signature may be compared to the one returned by perl_crc to * verify the flash was written correctly. * * @param target From 7e64e5a895ecd9bf25c5d2b39ff3119dafa30489 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 20:35:09 +0100 Subject: [PATCH 015/120] openocd: fix doxygen parameters of functions Add to doxygen comment the missing parameters. Remove from doxygen comment any non-existing parameter. Fix the parameter names in doxygen comment to match the one in the function prototype. Where the parameter name in the doxygen description seems better than the one in the code, change the code. Escape the character '<' to prevent doxygen to interpret it as an xml tag. Change-Id: I22da723339ac7d7a7a64ac4c1cc4336e2416c2cc Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6002 Tested-by: jenkins --- src/flash/nand/at91sam9.c | 4 +- src/flash/nor/at91sam4.c | 3 ++ src/flash/nor/core.h | 3 +- src/flash/nor/lpc2900.c | 4 +- src/flash/nor/psoc6.c | 1 - src/jtag/drivers/OpenULINK/src/jtag.c | 4 ++ src/jtag/drivers/ftdi.c | 1 - src/jtag/drivers/jtag_vpi.c | 9 ++-- src/jtag/drivers/ulink.c | 2 + src/jtag/drivers/usb_blaster/usb_blaster.c | 14 +++---- src/rtt/rtt.h | 2 +- src/target/arc.c | 1 + src/target/arc_jtag.c | 12 +++--- src/target/arm_adi_v5.c | 2 +- src/target/dsp5680xx.c | 49 +++++++--------------- src/target/riscv/riscv-013.c | 4 +- src/target/semihosting_common.c | 2 + src/target/target.c | 20 +++++++++ 18 files changed, 75 insertions(+), 62 deletions(-) diff --git a/src/flash/nand/at91sam9.c b/src/flash/nand/at91sam9.c index 47c050563..234dd70c1 100644 --- a/src/flash/nand/at91sam9.c +++ b/src/flash/nand/at91sam9.c @@ -105,7 +105,7 @@ static int at91sam9_init(struct nand_device *nand) /** * Enable NAND device attached to a controller. * - * @param info NAND controller information for controlling NAND device. + * @param nand NAND controller information for controlling NAND device. * @return Success or failure of the enabling. */ static int at91sam9_enable(struct nand_device *nand) @@ -119,7 +119,7 @@ static int at91sam9_enable(struct nand_device *nand) /** * Disable NAND device attached to a controller. * - * @param info NAND controller information for controlling NAND device. + * @param nand NAND controller information for controlling NAND device. * @return Success or failure of the disabling. */ static int at91sam9_disable(struct nand_device *nand) diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 86abf7005..d4326e43a 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -1709,6 +1709,9 @@ static int FLASHD_EraseEntireBank(struct sam4_bank_private *pPrivate) /** * Erases the entire flash. * @param pPrivate - the info about the bank. + * @param firstPage + * @param numPages + * @param status */ static int FLASHD_ErasePages(struct sam4_bank_private *pPrivate, int firstPage, diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index 107a1c56e..97a368e8e 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -276,7 +276,8 @@ struct flash_bank *get_flash_bank_by_num_noprobe(unsigned int num); * @param target The target, presumed to contain one or more banks. * @param addr An address that is within the range of the bank. * @param check return ERROR_OK and result_bank NULL if the bank does not exist - * @returns The struct flash_bank located at @a addr, or NULL. + * @param result_bank The struct flash_bank located at @a addr, or NULL. + * @returns ERROR_OK on success, or an error indicating the problem. */ int get_flash_bank_by_addr(struct target *target, target_addr_t addr, bool check, struct flash_bank **result_bank); diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c index 6596cde94..4d3d7f758 100644 --- a/src/flash/nor/lpc2900.c +++ b/src/flash/nor/lpc2900.c @@ -453,8 +453,8 @@ static int lpc2900_write_index_page(struct flash_bank *bank, /** * Calculate FPTR.TR register value for desired program/erase time. * - * @param clock System clock in Hz - * @param time Program/erase time in µs + * @param clock_var System clock in Hz + * @param time_var Program/erase time in µs */ static uint32_t lpc2900_calc_tr(uint32_t clock_var, uint32_t time_var) { diff --git a/src/flash/nor/psoc6.c b/src/flash/nor/psoc6.c index 931404e3e..9c834fde6 100644 --- a/src/flash/nor/psoc6.c +++ b/src/flash/nor/psoc6.c @@ -873,7 +873,6 @@ exit: /** *********************************************************************************************** * @brief Performs Mass Erase operation - * @param bank flash bank index to erase * @return ERROR_OK in case of success, ERROR_XXX code otherwise *************************************************************************************************/ COMMAND_HANDLER(psoc6_handle_mass_erase_command) diff --git a/src/jtag/drivers/OpenULINK/src/jtag.c b/src/jtag/drivers/OpenULINK/src/jtag.c index ecf98a08c..c76f034e8 100644 --- a/src/jtag/drivers/OpenULINK/src/jtag.c +++ b/src/jtag/drivers/OpenULINK/src/jtag.c @@ -48,6 +48,7 @@ uint8_t delay_tms; * Maximum achievable TCK frequency is 182 kHz for ULINK clocked at 24 MHz. * * @param out_offset offset in OUT2BUF where payload data starts + * @param in_offset */ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset) { @@ -125,6 +126,7 @@ void jtag_scan_in(uint8_t out_offset, uint8_t in_offset) * Maximum achievable TCK frequency is 113 kHz for ULINK clocked at 24 MHz. * * @param out_offset offset in OUT2BUF where payload data starts + * @param in_offset */ void jtag_slow_scan_in(uint8_t out_offset, uint8_t in_offset) { @@ -373,6 +375,7 @@ void jtag_slow_scan_out(uint8_t out_offset) * Maximum achievable TCK frequency is 100 kHz for ULINK clocked at 24 MHz. * * @param out_offset offset in OUT2BUF where payload data starts + * @param in_offset */ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset) { @@ -465,6 +468,7 @@ void jtag_scan_io(uint8_t out_offset, uint8_t in_offset) * Maximum achievable TCK frequency is 78 kHz for ULINK clocked at 24 MHz. * * @param out_offset offset in OUT2BUF where payload data starts + * @param in_offset */ void jtag_slow_scan_io(uint8_t out_offset, uint8_t in_offset) { diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index 4fa83ae56..9d1c85cbd 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -1062,7 +1062,6 @@ static void ftdi_swd_swdio_en(bool enable) /** * Flush the MPSSE queue and process the SWD transaction queue - * @param dap * @return */ static int ftdi_swd_run_queue(void) diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index a6609d21e..c5ffe83ba 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -227,8 +227,8 @@ static int jtag_vpi_reset(int trst, int srst) * @param nb_bits number of TMS bits (between 1 and 8) * * Write a series of TMS transitions, where each transition consists in : - * - writing out TCK=0, TMS=, TDI= - * - writing out TCK=1, TMS=, TDI= which triggers the transition + * - writing out TCK=0, TMS=\, TDI=\ + * - writing out TCK=1, TMS=\, TDI=\ which triggers the transition * The function ensures that at the end of the sequence, the clock (TCK) is put * low. */ @@ -253,8 +253,8 @@ static int jtag_vpi_tms_seq(const uint8_t *bits, int nb_bits) * @param cmd path transition * * Write a series of TMS transitions, where each transition consists in : - * - writing out TCK=0, TMS=, TDI= - * - writing out TCK=1, TMS=, TDI= which triggers the transition + * - writing out TCK=0, TMS=\, TDI=\ + * - writing out TCK=1, TMS=\, TDI=\ which triggers the transition * The function ensures that at the end of the sequence, the clock (TCK) is put * low. */ @@ -344,6 +344,7 @@ static int jtag_vpi_queue_tdi_xfer(uint8_t *bits, int nb_bits, int tap_shift) * jtag_vpi_queue_tdi - short description * @param bits bits to be queued on TDI (or NULL if 0 are to be queued) * @param nb_bits number of bits + * @param tap_shift */ static int jtag_vpi_queue_tdi(uint8_t *bits, int nb_bits, int tap_shift) { diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index f473ce39a..ccc023fb8 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -696,6 +696,7 @@ static int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd) * Sends all queued OpenULINK commands to the ULINK for execution. * * @param device pointer to struct ulink identifying ULINK driver instance. + * @param timeout * @return on success: ERROR_OK * @return on failure: ERROR_FAIL */ @@ -1682,6 +1683,7 @@ static int ulink_queue_runtest(struct ulink *device, struct jtag_command *cmd) /** * Execute a JTAG_RESET command * + * @param device * @param cmd pointer to the command that shall be executed. * @return on success: ERROR_OK * @return on failure: ERROR_FAIL diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 5559bcedb..5002a5f53 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -364,8 +364,8 @@ static void ublast_idle_clock(void) * @param type scan type (ie. does a readback of TDO is required) * * Output a TDI bit and assert clock to push it into the JTAG device : - * - writing out TCK=0, TMS==0, TDI= - * - writing out TCK=1, TMS=, TDI= which triggers the JTAG + * - writing out TCK=0, TMS=\=0, TDI=\ + * - writing out TCK=1, TMS=\, TDI=\ which triggers the JTAG * device acquiring the data. * * If a TDO is to be read back, the required read is requested (bitbang mode), @@ -448,8 +448,8 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes) * @param skip number of TMS bits to skip at the beginning of the series * * Write a series of TMS transitions, where each transition consists in : - * - writing out TCK=0, TMS=, TDI= - * - writing out TCK=1, TMS=, TDI= which triggers the transition + * - writing out TCK=0, TMS=\, TDI=\ + * - writing out TCK=1, TMS=\, TDI=\ which triggers the transition * The function ensures that at the end of the sequence, the clock (TCK) is put * low. */ @@ -478,8 +478,8 @@ static void ublast_tms(struct tms_command *cmd) * @param cmd path transition * * Write a series of TMS transitions, where each transition consists in : - * - writing out TCK=0, TMS=, TDI= - * - writing out TCK=1, TMS=, TDI= which triggers the transition + * - writing out TCK=0, TMS=\, TDI=\ + * - writing out TCK=1, TMS=\, TDI=\ which triggers the transition * The function ensures that at the end of the sequence, the clock (TCK) is put * low. */ @@ -525,7 +525,7 @@ static void ublast_state_move(tap_state_t state, int skip) /** * ublast_read_byteshifted_tdos - read TDO of byteshift writes * @param buf the buffer to store the bits - * @param nb_bits the number of bits + * @param nb_bytes the number of bytes * * Reads back from USB Blaster TDO bits, triggered by a 'byteshift write', ie. eight * bits per received byte from USB interface, and store them in buffer. diff --git a/src/rtt/rtt.h b/src/rtt/rtt.h index 597c83829..bc21bd012 100644 --- a/src/rtt/rtt.h +++ b/src/rtt/rtt.h @@ -237,7 +237,7 @@ const struct rtt_control *rtt_get_control(void); * Read channel information. * * @param[in] channel_index Channel index. - * @param[in] channel_type Channel type. + * @param[in] type Channel type. * @param[out] info Channel information. * * @returns ERROR_OK on success, an error code on failure. diff --git a/src/target/arc.c b/src/target/arc.c index ffe974532..8e568455e 100644 --- a/src/target/arc.c +++ b/src/target/arc.c @@ -924,6 +924,7 @@ exit: * Finds an actionpoint that triggered last actionpoint event, as specified by * DEBUG.ASR. * + * @param target * @param actionpoint Pointer to be set to last active actionpoint. Pointer * will be set to NULL if DEBUG.AH is 0. */ diff --git a/src/target/arc_jtag.c b/src/target/arc_jtag.c index fd77b37f2..ca1a09649 100644 --- a/src/target/arc_jtag.c +++ b/src/target/arc_jtag.c @@ -237,7 +237,7 @@ static void arc_jtag_enque_register_rw(struct arc_jtag *jtag_info, uint32_t *add * @param type Type of registers to write: core or aux. * @param addr Array of registers numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ static int arc_jtag_write_registers(struct arc_jtag *jtag_info, uint32_t type, uint32_t *addr, uint32_t count, const uint32_t *buffer) @@ -272,7 +272,7 @@ static int arc_jtag_write_registers(struct arc_jtag *jtag_info, uint32_t type, * @param type Type of registers to read: core or aux. * @param addr Array of registers numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ static int arc_jtag_read_registers(struct arc_jtag *jtag_info, uint32_t type, uint32_t *addr, uint32_t count, uint32_t *buffer) @@ -337,7 +337,7 @@ int arc_jtag_write_core_reg_one(struct arc_jtag *jtag_info, uint32_t addr, * @param jtag_info * @param addr Array of registers numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ int arc_jtag_write_core_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, const uint32_t *buffer) @@ -361,7 +361,7 @@ int arc_jtag_read_core_reg_one(struct arc_jtag *jtag_info, uint32_t addr, * @param jtag_info * @param addr Array of core register numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ int arc_jtag_read_core_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, uint32_t *buffer) @@ -385,7 +385,7 @@ int arc_jtag_write_aux_reg_one(struct arc_jtag *jtag_info, uint32_t addr, * @param jtag_info * @param addr Array of registers numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ int arc_jtag_write_aux_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, const uint32_t *buffer) @@ -409,7 +409,7 @@ int arc_jtag_read_aux_reg_one(struct arc_jtag *jtag_info, uint32_t addr, * @param jtag_info * @param addr Array of AUX register numbers. * @param count Amount of registers in arrays. - * @param values Array of register values. + * @param buffer Array of register values. */ int arc_jtag_read_aux_reg(struct arc_jtag *jtag_info, uint32_t *addr, uint32_t count, uint32_t *buffer) diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 59bb186c6..8f5ad59c3 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -450,7 +450,7 @@ static int mem_ap_write(struct adiv5_ap *ap, const uint8_t *buffer, uint32_t siz * @param buffer The data buffer to receive the data. No particular alignment is assumed. * @param size Which access size to use, in bytes. 1, 2 or 4. * @param count The number of reads to do (in size units, not bytes). - * @param address Address to be read; it must be readable by the currently selected MEM-AP. + * @param adr Address to be read; it must be readable by the currently selected MEM-AP. * @param addrinc Whether the target address should be increased after each read or not. This * should normally be true, except when reading from e.g. a FIFO. * @return ERROR_OK on success, otherwise an error code. diff --git a/src/target/dsp5680xx.c b/src/target/dsp5680xx.c index ec07c2519..62844ea3b 100644 --- a/src/target/dsp5680xx.c +++ b/src/target/dsp5680xx.c @@ -1410,27 +1410,21 @@ static int dsp5680xx_write_32(struct target *t, uint32_t a, uint32_t c, * P: (program) memory or X: (dat) memory. * * @param target - * @param address + * @param a address * @param size Bytes (1), Half words (2), Words (4). * @param count In bytes. - * @param buffer + * @param b buffer * * @return */ -static int dsp5680xx_write(struct target *t, target_addr_t a, uint32_t s, uint32_t c, +static int dsp5680xx_write(struct target *target, target_addr_t a, uint32_t size, uint32_t count, const uint8_t *b) { /* TODO Cannot write 32bit to odd address, will write 0x12345678 as 0x5678 0x0012 */ - struct target *target = t; - uint32_t address = a; - uint32_t count = c; - uint8_t const *buffer = b; - uint32_t size = s; - check_halt_and_debug(target); int retval = 0; @@ -1479,12 +1473,12 @@ static int dsp5680xx_write_buffer(struct target *t, target_addr_t a, uint32_t si * * @return */ -static int dsp5680xx_read_buffer(struct target *t, target_addr_t a, uint32_t size, - uint8_t *buf) +static int dsp5680xx_read_buffer(struct target *target, target_addr_t address, uint32_t size, + uint8_t *buffer) { - check_halt_and_debug(t); + check_halt_and_debug(target); /* The "/2" solves the byte/word addressing issue.*/ - return dsp5680xx_read(t, a, 2, size / 2, buf); + return dsp5680xx_read(target, address, 2, size / 2, buffer); } /** @@ -1499,19 +1493,19 @@ static int dsp5680xx_read_buffer(struct target *t, target_addr_t a, uint32_t siz * * @return */ -static int dsp5680xx_checksum_memory(struct target *t, target_addr_t a, uint32_t s, +static int dsp5680xx_checksum_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t *checksum) { return ERROR_FAIL; } /** - * Calculates a signature over @a word_count words in the data from @a buff16. + * Calculates a signature over @a word_count words in the data from @a buff8. * The algorithm used is the same the FM uses, so the @a return may be used to compare * with the one generated by the FM module, and check if flashing was successful. * This algorithm is based on the perl script available from the Freescale website at FAQ 25630. * - * @param buff16 + * @param buff8 * @param word_count * * @return @@ -1609,7 +1603,7 @@ int dsp5680xx_f_protect_check(struct target *target, uint16_t *protected) * Some commands use the parameters @a address and @a data, others ignore them. * * @param target - * @param command Command to execute. + * @param c Command to execute. * @param address Command parameter. * @param data Command parameter. * @param hfm_ustat FM status register. @@ -1617,21 +1611,10 @@ int dsp5680xx_f_protect_check(struct target *target, uint16_t *protected) * * @return */ -static int dsp5680xx_f_ex(struct target *t, uint16_t c, uint32_t a, uint32_t d, - uint16_t *h, int p) +static int dsp5680xx_f_ex(struct target *target, uint16_t c, uint32_t address, uint32_t data, + uint16_t *hfm_ustat, int pmem) { - struct target *target = t; - uint32_t command = c; - - uint32_t address = a; - - uint32_t data = d; - - uint16_t *hfm_ustat = h; - - int pmem = p; - int retval; retval = core_load_TX_RX_high_addr_to_r0(target); @@ -1799,13 +1782,9 @@ static int set_fm_ck_div(struct target *target) * * @return */ -static int dsp5680xx_f_signature(struct target *t, uint32_t a, uint32_t words, +static int dsp5680xx_f_signature(struct target *target, uint32_t address, uint32_t words, uint16_t *signature) { - struct target *target = t; - - uint32_t address = a; - int retval; uint16_t hfm_ustat; diff --git a/src/target/riscv/riscv-013.c b/src/target/riscv/riscv-013.c index 8558ba891..32a7f0248 100644 --- a/src/target/riscv/riscv-013.c +++ b/src/target/riscv/riscv-013.c @@ -547,13 +547,15 @@ static dmi_status_t dmi_scan(struct target *target, uint32_t *address_in, } /** + * @param target * @param data_in The data we received from the target. - * @param dmi_op The operation to perform (read/write/nop). * @param dmi_busy_encountered * If non-NULL, will be updated to reflect whether DMI busy was * encountered while executing this operation or not. + * @param dmi_op The operation to perform (read/write/nop). * @param address The address argument to that operation. * @param data_out The data to send to the target. + * @param timeout_sec * @param exec When true, this scan will execute something, so extra RTI * cycles may be added. * @param ensure_success diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index 965055609..61a69d1bd 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -89,6 +89,8 @@ extern int gdb_actual_connections; * Initialize common semihosting support. * * @param target Pointer to the target to initialize. + * @param setup + * @param post_result * @return An error status if there is a problem during initialization. */ int semihosting_common_init(struct target *target, void *setup, diff --git a/src/target/target.c b/src/target/target.c index c752844b0..fa98c884b 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -803,6 +803,13 @@ static int target_soft_reset_halt(struct target *target) * algorithm. * * @param target used to run the algorithm + * @param num_mem_params + * @param mem_params + * @param num_reg_params + * @param reg_param + * @param entry_point + * @param exit_point + * @param timeout_ms * @param arch_info target-specific description of the algorithm. */ int target_run_algorithm(struct target *target, @@ -838,6 +845,12 @@ done: * Executes a target-specific native code algorithm and leaves it running. * * @param target used to run the algorithm + * @param num_mem_params + * @param mem_params + * @param num_reg_params + * @param reg_params + * @param entry_point + * @param exit_point * @param arch_info target-specific description of the algorithm. */ int target_start_algorithm(struct target *target, @@ -876,6 +889,12 @@ done: * Waits for an algorithm started with target_start_algorithm() to complete. * * @param target used to run the algorithm + * @param num_mem_params + * @param mem_params + * @param num_reg_params + * @param reg_params + * @param exit_point + * @param timeout_ms * @param arch_info target-specific description of the algorithm. */ int target_wait_algorithm(struct target *target, @@ -947,6 +966,7 @@ done: * @param entry_point address on the target to execute to start the algorithm * @param exit_point address at which to set a breakpoint to catch the * end of the algorithm; can be 0 if target triggers a breakpoint itself + * @param arch_info */ int target_run_flash_async_algorithm(struct target *target, From aaa6110d9b027acd1d027ef27c723ec9cf2381a0 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 2 Jan 2021 20:42:12 +0100 Subject: [PATCH 016/120] doc/manual/primer/autotools.txt: fix doxygen warning Commit ab90b8777855 ("configure: remove AM_MAINTAINER_MODE, effectively always enabling all the rules") removes the configure flag '--enable-maintainer-mode' and its documentation, but have left a reference to the removed subsection 'primermaintainermode' and this triggers a warning in doxygen: doc/manual/primer/autotools.txt:21: warning: unable to resolve reference to 'primermaintainermode' for \ref command Remove the obsoleted paragraph. Change-Id: I56e69ef033d546d159745bed1b47c6105827e7ae Signed-off-by: Antonio Borneo Fixes: ab90b8777855 ("configure: remove AM_MAINTAINER_MODE, effectively always enabling all the rules") Reviewed-on: http://openocd.zylin.com/6003 Tested-by: jenkins --- doc/manual/primer/autotools.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/doc/manual/primer/autotools.txt b/doc/manual/primer/autotools.txt index 3471eacd7..f038f0b2f 100644 --- a/doc/manual/primer/autotools.txt +++ b/doc/manual/primer/autotools.txt @@ -15,9 +15,6 @@ autotools in the correct sequence. When run after a fresh checkout, this script generates the build files required to compile the project, producing the project configure script. -After running @c configure, the @ref primermaintainermode settings will -handle most situations that require running these tools again. In some -cases, a fresh bootstrap may be still required. @subsection primerbootstrapcures Problems Solved By Bootstrap From 310c9800c72f37dd50e855513badc908fcfbafcf Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Mon, 11 Jan 2021 19:21:06 +0100 Subject: [PATCH 017/120] flash/stmqspi: fix build error with -Werror=maybe-uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit using gcc 9.3 on ubuntu focal fossa with -Werror=maybe-uninitialized we get this error: /src/flash/nor/stmqspi.c: In function ‘read_flash_id’: /src/flash/nor/stmqspi.c:1948:6: error: ‘retval’ may be used uninitialized Change-Id: Ifd8ae60df847fc61e22ca100c008e3914c9af79b Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6012 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Antonio Borneo --- src/flash/nor/stmqspi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/stmqspi.c b/src/flash/nor/stmqspi.c index f54e4975d..a013336a0 100644 --- a/src/flash/nor/stmqspi.c +++ b/src/flash/nor/stmqspi.c @@ -1945,7 +1945,7 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id1, uint32_t *id2) uint32_t io_base = stmqspi_info->io_base; uint8_t byte; unsigned int type, count, len1, len2; - int retval; + int retval = ERROR_OK; /* invalidate both ids */ *id1 = 0; From 404993b29f1304fb53202fb88147298465bfb525 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Mon, 11 Jan 2021 19:23:58 +0100 Subject: [PATCH 018/120] target/riscv: fix build error with -Werror=maybe-uninitialized MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit using gcc 9.3 on ubuntu focal fossa with -Werror=maybe-uninitialized we get this error: /src/target/riscv/riscv.c: In function ‘riscv_address_translate’: /src/target/riscv/riscv.c:1536:13: error: ‘pte’ may be used uninitialized Change-Id: I51e180b43f9b6996e4e4058db49c179b9f81bcdc Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6013 Tested-by: jenkins Reviewed-by: Tim Newsome Reviewed-by: Tarek BOCHKATI Reviewed-by: Antonio Borneo --- src/target/riscv/riscv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 0d1cee1bf..c26e6358f 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1446,7 +1446,7 @@ static int riscv_address_translate(struct target *target, uint64_t ppn_value; target_addr_t table_address; virt2phys_info_t *info; - uint64_t pte; + uint64_t pte = 0; int i; if (riscv_rtos_enabled(target)) From 2dc9c1df81b6458875233fc3710ab9d3e871743d Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 12 Jan 2021 11:57:18 +0100 Subject: [PATCH 019/120] cortex_m: [FIX] ARMv8-M does not support VECTRESET MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ref: Arm®v8-M Architecture Reference Manual (DDI0553B.m) D1.2.3: AIRCR, Application Interrupt and Reset Control Register Bit [0] is RES0 Change-Id: I6ef451b2c114487e2732852a60e86c292ffa6a50 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6014 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Antonio Borneo --- src/target/cortex_m.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index ac308b43b..ce2c426ce 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2011,8 +2011,8 @@ int cortex_m_examine(struct target *target) } LOG_DEBUG("cpuid: 0x%8.8" PRIx32 "", cpuid); - /* VECTRESET is not supported on Cortex-M0, M0+ and M1 */ - cortex_m->vectreset_supported = i > 1; + /* VECTRESET is supported only on ARMv7-M cores */ + cortex_m->vectreset_supported = !armv7m->arm.is_armv8m && !armv7m->arm.is_armv6m; if (i == 4) { target_read_u32(target, MVFR0, &mvfr0); From 0b248e04c1e58b374e82bad0361e42a5e8a96b77 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 5 Mar 2020 17:00:50 +0100 Subject: [PATCH 020/120] driver/ftdi: skip trst in swd mode When using the adapter olimex arm-jtag-swd (to convert to SWD a JTAG-only FTDI adapter), the pin trst on JTAG side is re-used to control the direction of pin SWDIO on SWD side. There is a single reset API at adapter driver to assert/deassert either srst and/or trst. A request to assert/deassert srst can cause also trst to change value, hanging the SWD communication. In SWD mode, ignore the value passed to trst. Change-Id: I5fe1eed851177d405d77ae6079da9642dc1a08f1 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6006 Tested-by: jenkins --- src/jtag/drivers/ftdi.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index 9d1c85cbd..9e47d3cad 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -524,17 +524,19 @@ static int ftdi_reset(int trst, int srst) LOG_DEBUG_IO("reset trst: %i srst %i", trst, srst); - if (trst == 1) { - if (sig_ntrst) - ftdi_set_signal(sig_ntrst, '0'); - else - LOG_ERROR("Can't assert TRST: nTRST signal is not defined"); - } else if (sig_ntrst && jtag_get_reset_config() & RESET_HAS_TRST && - trst == 0) { - if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN) - ftdi_set_signal(sig_ntrst, 'z'); - else - ftdi_set_signal(sig_ntrst, '1'); + if (!swd_mode) { + if (trst == 1) { + if (sig_ntrst) + ftdi_set_signal(sig_ntrst, '0'); + else + LOG_ERROR("Can't assert TRST: nTRST signal is not defined"); + } else if (sig_ntrst && jtag_get_reset_config() & RESET_HAS_TRST && + trst == 0) { + if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN) + ftdi_set_signal(sig_ntrst, 'z'); + else + ftdi_set_signal(sig_ntrst, '1'); + } } if (srst == 1) { From 8b7569c2196ea69e72d5daf5c7294d98feb20268 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 9 Jan 2021 19:51:42 +0100 Subject: [PATCH 021/120] configure.ac: drop macro 'AC_PROG_CC_C99' from autoconf 2.70 The macro AC_PROG_CC_C99 has been obsoleted by autoconf 2.70 and triggers a set of warnings from both 'aclocal' and 'autoconf'. The test of AC_PROG_CC_C99 is now included in AC_PROG_CC. For autoconf 2.69 and earlier the macro is still required, so cannot be simply dropped. Use a conditional test to avoid the warning on autoconf 2.70 but still use AC_PROG_CC_C99 on older autoconf. Change-Id: I5e8437f5a826fb63be6d07bcb5bb824f94683020 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6009 Tested-by: jenkins Reviewed-by: Marc Schink --- configure.ac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 012486666..6d0c7d096 100644 --- a/configure.ac +++ b/configure.ac @@ -25,7 +25,8 @@ AH_BOTTOM([ AC_LANG([C]) AC_PROG_CC -AC_PROG_CC_C99 +# autoconf 2.70 obsoletes AC_PROG_CC_C99 and includes it in AC_PROG_CC +m4_version_prereq([2.70],[],[AC_PROG_CC_C99]) AM_PROG_CC_C_O AC_PROG_RANLIB PKG_PROG_PKG_CONFIG([0.23]) From bd1adcffe7f3e51f490bf57889e7454816661196 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 8 Jan 2021 23:48:43 +0100 Subject: [PATCH 022/120] configure: drop macro 'AC_HEADER_TIME' The macro AC_HEADER_TIME has been obsoleted by autoconf 2.70. Not all systems provide 'sys/time.h', plus some old system didn't allowed to include both 'time.h' and 'sys/time.h' because 'time.h' was included by 'sys/time.h' and was not properly protected to allow multiple inclusion. The macro AC_HEADER_TIME helps to detect such odd case. Nowadays all the systems properly protect 'time.h', so its safe to unconditionally include 'time.h', even if it is also included by 'sys/time.h'. The case of systems without 'sys/time.h' is already covered by configure.ac through the directive AC_CHECK_HEADERS([sys/time.h]) Remove the obsoleted autoconf macro and simplify the code by including 'time.h' unconditionally and check HAVE_SYS_TIME_H to include 'sys/time.h'. Change-Id: Iddb3f3f1d90c22668b97f8e756e1b4f733367a7d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6010 Tested-by: jenkins Reviewed-by: Marc Schink --- configure.ac | 1 - src/helper/system.h | 14 +++----------- src/helper/time_support.h | 13 ++++--------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 6d0c7d096..d7133183c 100644 --- a/configure.ac +++ b/configure.ac @@ -81,7 +81,6 @@ AC_CHECK_HEADERS([arpa/inet.h ifaddrs.h netinet/in.h netinet/tcp.h net/if.h], [] AC_HEADER_ASSERT AC_HEADER_STDBOOL -AC_HEADER_TIME AC_C_BIGENDIAN diff --git a/src/helper/system.h b/src/helper/system.h index 97b3443be..1aaca3b33 100644 --- a/src/helper/system.h +++ b/src/helper/system.h @@ -28,19 +28,11 @@ #include #include #include +#include -/* +++ AC_HEADER_TIME +++ */ -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif +#ifdef HAVE_SYS_TIME_H +#include #endif -/* --- AC_HEADER_TIME --- */ /* +++ platform specific headers +++ */ #ifdef _WIN32 diff --git a/src/helper/time_support.h b/src/helper/time_support.h index 7abbdb24d..a9f2dffad 100644 --- a/src/helper/time_support.h +++ b/src/helper/time_support.h @@ -25,15 +25,10 @@ #ifndef OPENOCD_HELPER_TIME_SUPPORT_H #define OPENOCD_HELPER_TIME_SUPPORT_H -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else -# ifdef HAVE_SYS_TIME_H -# include -# else -# include -# endif +#include + +#ifdef HAVE_SYS_TIME_H +#include #endif int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y); From 047df630187bf5d54731aeaada33c639c57daf66 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sat, 23 Jan 2021 13:54:04 +0300 Subject: [PATCH 023/120] README.macOS: explain how to install suitable Texinfo Change-Id: Ic5906111f412eebd906a9be3fd0e133484def3eb Signed-off-by: Paul Fertser Reviewed-on: http://openocd.zylin.com/6026 Tested-by: jenkins Reviewed-by: Antonio Borneo --- Makefile.am | 2 +- README.OSX => README.macOS | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) rename README.OSX => README.macOS (81%) diff --git a/Makefile.am b/Makefile.am index c1de02da0..a6e7ab232 100644 --- a/Makefile.am +++ b/Makefile.am @@ -48,7 +48,7 @@ EXTRA_DIST += \ HACKING \ NEWTAPS \ README.Windows \ - README.OSX \ + README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ tools/logger.pl \ diff --git a/README.OSX b/README.macOS similarity index 81% rename from README.OSX rename to README.macOS index 979c64ba6..c532e67c6 100644 --- a/README.OSX +++ b/README.macOS @@ -1,10 +1,10 @@ -Building OpenOCD for OSX ------------------------- +Building OpenOCD for macOS +-------------------------- There are a few prerequisites you will need first: -- Xcode 5 (install from the AppStore) -- Command Line Tools (install from Xcode 5 -> Preferences -> Downloads) +- Xcode (install from the AppStore) +- Command Line Tools (install from Xcode -> Preferences -> Downloads) - Gentoo Prefix (http://www.gentoo.org/proj/en/gentoo-alt/prefix/bootstrap.xml) or - Homebrew (http://mxcl.github.io/homebrew/) @@ -12,6 +12,11 @@ There are a few prerequisites you will need first: - MacPorts (http://www.macports.org/install.php) +If you're building manually you need Texinfo version 5.0 or later. The +simplest way to get it is to use Homebrew (brew install texinfo) and +then ``export PATH=/usr/local/opt/texinfo/bin:$PATH``. + + With Gentoo Prefix you can build the release version or the latest devel version (-9999) the usual way described in the Gentoo documentation. Alternatively, install the prerequisites and build From 090209275bc7796eb6b5e3a23158683bc88e354c Mon Sep 17 00:00:00 2001 From: Bohdan Tymkiv Date: Fri, 22 Jan 2021 17:13:34 +0200 Subject: [PATCH 024/120] jlink: fix device discovery when network is off If user specifies a serial number for the jlink device, openocd extends the search to network jlink devices too, without checking if the host has a valid and functional network connection. If the network is not functional, libjaylink returns error. This error invalidates the discovery on USB, even if it was successful. Factor-out parts of the jlink_init into separate jlink_open_device function, use that function to firstly discover and match USB devices and, if matching device was not found on the USB bus and serial number was specified, repeat discovery and matching via TCP. Fixes: https://sourceforge.net/p/openocd/tickets/294/ Change-Id: Iea0de1640d4e5b21ecc7e9c1dd6d36f214d647c2 Signed-off-by: Bohdan Tymkiv Reviewed-on: http://openocd.zylin.com/6025 Reviewed-by: Antonio Borneo Tested-by: jenkins Reviewed-by: Marc Schink --- src/jtag/drivers/jlink.c | 176 ++++++++++++++++++++------------------- 1 file changed, 91 insertions(+), 85 deletions(-) diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index b915707ec..15d252cfb 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -553,20 +553,96 @@ static bool jlink_usb_location_equal(struct jaylink_device *dev) } +static int jlink_open_device(uint32_t ifaces, bool *found_device) +{ + int ret = jaylink_discovery_scan(jayctx, ifaces); + if (ret != JAYLINK_OK) { + LOG_ERROR("jaylink_discovery_scan() failed: %s.", jaylink_strerror(ret)); + jaylink_exit(jayctx); + return ERROR_JTAG_INIT_FAILED; + } + + size_t num_devices; + struct jaylink_device **devs; + ret = jaylink_get_devices(jayctx, &devs, &num_devices); + + if (ret != JAYLINK_OK) { + LOG_ERROR("jaylink_get_devices() failed: %s.", jaylink_strerror(ret)); + jaylink_exit(jayctx); + return ERROR_JTAG_INIT_FAILED; + } + + use_usb_location = (jtag_usb_get_location() != NULL); + + if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) { + LOG_ERROR("Multiple devices found, specify the desired device."); + jaylink_free_devices(devs, true); + jaylink_exit(jayctx); + return ERROR_JTAG_INIT_FAILED; + } + + *found_device = false; + + for (size_t i = 0; devs[i]; i++) { + struct jaylink_device *dev = devs[i]; + + if (use_serial_number) { + uint32_t tmp; + ret = jaylink_device_get_serial_number(dev, &tmp); + + if (ret == JAYLINK_ERR_NOT_AVAILABLE) { + continue; + } else if (ret != JAYLINK_OK) { + LOG_WARNING("jaylink_device_get_serial_number() failed: %s.", + jaylink_strerror(ret)); + continue; + } + + if (serial_number != tmp) + continue; + } + + if (use_usb_address) { + enum jaylink_usb_address address; + ret = jaylink_device_get_usb_address(dev, &address); + + if (ret == JAYLINK_ERR_NOT_SUPPORTED) { + continue; + } else if (ret != JAYLINK_OK) { + LOG_WARNING("jaylink_device_get_usb_address() failed: %s.", + jaylink_strerror(ret)); + continue; + } + + if (usb_address != address) + continue; + } + + if (use_usb_location && !jlink_usb_location_equal(dev)) + continue; + + ret = jaylink_open(dev, &devh); + + if (ret == JAYLINK_OK) { + *found_device = true; + break; + } + + LOG_ERROR("Failed to open device: %s.", jaylink_strerror(ret)); + } + + jaylink_free_devices(devs, true); + return ERROR_OK; +} + + static int jlink_init(void) { int ret; - struct jaylink_device **devs; - unsigned int i; - bool found_device; - uint32_t tmp; char *firmware_version; struct jaylink_hardware_version hwver; struct jaylink_hardware_status hwstatus; - enum jaylink_usb_address address; size_t length; - size_t num_devices; - uint32_t host_interfaces; LOG_DEBUG("Using libjaylink %s (compiled with %s).", jaylink_version_package_get_string(), JAYLINK_VERSION_PACKAGE_STRING); @@ -592,87 +668,17 @@ static int jlink_init(void) return ERROR_JTAG_INIT_FAILED; } - host_interfaces = JAYLINK_HIF_USB; + bool found_device; + ret = jlink_open_device(JAYLINK_HIF_USB, &found_device); + if (ret != ERROR_OK) + return ret; - if (use_serial_number) - host_interfaces |= JAYLINK_HIF_TCP; - - ret = jaylink_discovery_scan(jayctx, host_interfaces); - - if (ret != JAYLINK_OK) { - LOG_ERROR("jaylink_discovery_scan() failed: %s.", - jaylink_strerror(ret)); - jaylink_exit(jayctx); - return ERROR_JTAG_INIT_FAILED; + if (!found_device && use_serial_number) { + ret = jlink_open_device(JAYLINK_HIF_TCP, &found_device); + if (ret != ERROR_OK) + return ret; } - ret = jaylink_get_devices(jayctx, &devs, &num_devices); - - if (ret != JAYLINK_OK) { - LOG_ERROR("jaylink_get_devices() failed: %s.", jaylink_strerror(ret)); - jaylink_exit(jayctx); - return ERROR_JTAG_INIT_FAILED; - } - - use_usb_location = (jtag_usb_get_location() != NULL); - - if (!use_serial_number && !use_usb_address && !use_usb_location && num_devices > 1) { - LOG_ERROR("Multiple devices found, specify the desired device."); - jaylink_free_devices(devs, true); - jaylink_exit(jayctx); - return ERROR_JTAG_INIT_FAILED; - } - - found_device = false; - - for (i = 0; devs[i]; i++) { - struct jaylink_device *dev = devs[i]; - - if (use_serial_number) { - ret = jaylink_device_get_serial_number(dev, &tmp); - - if (ret == JAYLINK_ERR_NOT_AVAILABLE) { - continue; - } else if (ret != JAYLINK_OK) { - LOG_WARNING("jaylink_device_get_serial_number() failed: %s.", - jaylink_strerror(ret)); - continue; - } - - if (serial_number != tmp) - continue; - } - - if (use_usb_address) { - ret = jaylink_device_get_usb_address(dev, &address); - - if (ret == JAYLINK_ERR_NOT_SUPPORTED) { - continue; - } else if (ret != JAYLINK_OK) { - LOG_WARNING("jaylink_device_get_usb_address() failed: %s.", - jaylink_strerror(ret)); - continue; - } - - if (usb_address != address) - continue; - } - - if (use_usb_location && !jlink_usb_location_equal(dev)) - continue; - - ret = jaylink_open(dev, &devh); - - if (ret == JAYLINK_OK) { - found_device = true; - break; - } - - LOG_ERROR("Failed to open device: %s.", jaylink_strerror(ret)); - } - - jaylink_free_devices(devs, true); - if (!found_device) { LOG_ERROR("No J-Link device found."); jaylink_exit(jayctx); From 6643b145dc15ab26593170b25aa5dc411578d7fd Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sat, 23 Jan 2021 18:57:46 +0100 Subject: [PATCH 025/120] README: add missing items for 0.11 JTAG adapters Cadence DPI, Cypress Kitpro, FTDI FT232R, Linux GPIOD, Mellanox rshim, Nuvoton Nu-Link, Nu-Link2, NXP IMX GPIO, Remote Bitbang, TI XDS110, Xilinx XVC/PCIe Debug targets AArch64, Cortex-M (ARMv8-M), ARCv2, MIPS64, RISC-V, ST-STM8 Flash Drivers ATmega128RFA1, Atmel SAM, eSi-RISC, EZR32HG, MAX32, MXC, nRF52, PSoC6, Renesas RPC HF and SH QSPI, SiFive Freedom E, ST BlueNRG, STM32 QUAD/OCTO-SPI for Flash/FRAM/EEPROM, SWM050, TI CC13xx, TI CC26xx, TI CC32xx, TI MSP432, Winner Micro w600, Xilinx XCF Change-Id: I341618ac5d7189e4f98268cecd66c99447b72af8 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6027 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Paul Fertser --- README | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/README b/README index ed0a85856..fb3051f21 100644 --- a/README +++ b/README @@ -101,34 +101,40 @@ Supported hardware JTAG adapters ------------- -AICE, ARM-JTAG-EW, ARM-USB-OCD, ARM-USB-TINY, AT91RM9200, axm0432, -BCM2835, Bus Blaster, Buspirate, Chameleon, CMSIS-DAP, Cortino, DENX, -Digilent JTAG-SMT2, DLC 5, DLP-USB1232H, embedded projects, eStick, -FlashLINK, FlossJTAG, Flyswatter, Flyswatter2, Gateworks, Hoegl, ICDI, -ICEBear, J-Link, JTAG VPI, JTAGkey, JTAGkey2, JTAG-lock-pick, KT-Link, -Lisa/L, LPC1768-Stick, MiniModule, NGX, NXHX, OOCDLink, Opendous, -OpenJTAG, Openmoko, OpenRD, OSBDM, Presto, Redbee, RLink, SheevaPlug -devkit, Stellaris evkits, ST-LINK (SWO tracing supported), -STM32-PerformanceStick, STR9-comStick, sysfsgpio, TUMPA, Turtelizer, -ULINK, USB-A9260, USB-Blaster, USB-JTAG, USBprog, VPACLink, VSLLink, -Wiggler, XDS100v2, Xverve. +AICE, ARM-JTAG-EW, ARM-USB-OCD, ARM-USB-TINY, AT91RM9200, axm0432, BCM2835, +Bus Blaster, Buspirate, Cadence DPI, Chameleon, CMSIS-DAP, Cortino, +Cypress KitProg, DENX, Digilent JTAG-SMT2, DLC 5, DLP-USB1232H, +embedded projects, eStick, FlashLINK, FlossJTAG, Flyswatter, Flyswatter2, +FTDI FT232R, Gateworks, Hoegl, ICDI, ICEBear, J-Link, JTAG VPI, JTAGkey, +JTAGkey2, JTAG-lock-pick, KT-Link, Linux GPIOD, Lisa/L, LPC1768-Stick, +Mellanox rshim, MiniModule, NGX, Nuvoton Nu-Link, Nu-Link2, NXHX, NXP IMX GPIO, +OOCDLink, Opendous, OpenJTAG, Openmoko, OpenRD, OSBDM, Presto, Redbee, +Remote Bitbang, RLink, SheevaPlug devkit, Stellaris evkits, +ST-LINK (SWO tracing supported), STM32-PerformanceStick, STR9-comStick, +sysfsgpio, TI XDS110, TUMPA, Turtelizer, ULINK, USB-A9260, USB-Blaster, +USB-JTAG, USBprog, VPACLink, VSLLink, Wiggler, XDS100v2, Xilinx XVC/PCIe, +Xverve. Debug targets ------------- -ARM11, ARM7, ARM9, AVR32, Cortex-A, Cortex-R, Cortex-M, LS102x-SAP, -Feroceon/Dragonite, DSP563xx, DSP5680xx, EnSilica eSi-RISC, FA526, MIPS -EJTAG, NDS32, XScale, Intel Quark. +ARM: AArch64, ARM11, ARM7, ARM9, Cortex-A/R (v7-A/R), Cortex-M (ARMv{6/7/8}-M), +FA526, Feroceon/Dragonite, XScale. +ARCv2, AVR32, DSP563xx, DSP5680xx, EnSilica eSi-RISC, EJTAG (MIPS32, MIPS64), +Intel Quark, LS102x-SAP, NDS32, RISC-V, ST STM8. Flash drivers ------------- -ADUC702x, AT91SAM, ATH79, AVR, CFI, DSP5680xx, EFM32, EM357, eSi-TSMC, FM3, -FM4, Freedom E SPI, Kinetis, LPC8xx/LPC1xxx/LPC2xxx/LPC541xx, LPC2900, -LPCSPIFI, Marvell QSPI, Milandr, NIIET, NuMicro, PIC32mx, PSoC4, PSoC5LP, -SiM3x, Stellaris, STM32, STMSMI, STR7x, STR9x, nRF51; NAND controllers of -AT91SAM9, LPC3180, LPC32xx, i.MX31, MXC, NUC910, Orion/Kirkwood, S3C24xx, -S3C6400, XMC1xxx, XMC4xxx. +ADUC702x, AT91SAM, AT91SAM9 (NAND), ATH79, ATmega128RFA1, Atmel SAM, AVR, CFI, +DSP5680xx, EFM32, EM357, eSi-RISC, eSi-TSMC, EZR32HG, FM3, FM4, Freedom E SPI, +i.MX31, Kinetis, LPC8xx/LPC1xxx/LPC2xxx/LPC541xx, LPC2900, LPC3180, LPC32xx, +LPCSPIFI, Marvell QSPI, MAX32, Milandr, MXC, NIIET, nRF51, nRF52 , NuMicro, +NUC910, Orion/Kirkwood, PIC32mx, PSoC4/5LP/6, Renesas RPC HF and SH QSPI, +S3C24xx, S3C6400, SiM3x, SiFive Freedom E, Stellaris, ST BlueNRG, STM32, +STM32 QUAD/OCTO-SPI for Flash/FRAM/EEPROM, STMSMI, STR7x, STR9x, SWM050, +TI CC13xx, TI CC26xx, TI CC32xx, TI MSP432, Winner Micro w600, Xilinx XCF, +XMC1xxx, XMC4xxx. ================== From a5e526d8575cf63fe11babec85c0798ac3f4ad74 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 25 Jan 2021 00:23:21 +0300 Subject: [PATCH 026/120] The openocd-0.11.0-rc2 release candidate Signed-off-by: Paul Fertser --- NEWS | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 5c04e340f..36ee8fd2e 100644 --- a/NEWS +++ b/NEWS @@ -227,7 +227,7 @@ This release also contains a number of other important functional and cosmetic bugfixes. For more details about what has changed since the last release, see the git repository history: -http://sourceforge.net/p/openocd/code/ci/v0.11.0-rc1/log/?path= +http://sourceforge.net/p/openocd/code/ci/v0.11.0-rc2/log/?path= For older NEWS, see the NEWS files associated with each release diff --git a/configure.ac b/configure.ac index d7133183c..9a2a01b24 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.64) -AC_INIT([openocd], [0.11.0-rc1+dev], +AC_INIT([openocd], [0.11.0-rc2], [OpenOCD Mailing List ]) AC_CONFIG_SRCDIR([src/openocd.c]) AC_CONFIG_AUX_DIR([.]) From 5c17ce508ed5fd16fe7e42877199277996575625 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Mon, 25 Jan 2021 01:43:17 +0300 Subject: [PATCH 027/120] Restore +dev suffix Signed-off-by: Paul Fertser --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 9a2a01b24..158ba1599 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.64) -AC_INIT([openocd], [0.11.0-rc2], +AC_INIT([openocd], [0.11.0-rc2+dev], [OpenOCD Mailing List ]) AC_CONFIG_SRCDIR([src/openocd.c]) AC_CONFIG_AUX_DIR([.]) From 427552c078ea02c5b5a4c1492419dc6c3f4845dd Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 27 Jan 2021 23:53:12 +0100 Subject: [PATCH 028/120] steppenprobe: fix file permission Commit 895d4a599585 ("tcl/interface/ftdi: Add Steppenprobe open hardware interface") erroneously set the execution permission to the configuration file. Strip the execution permission. Change-Id: I556451d5e6fee4aee385451e8c90216a25b6ef46 Signed-off-by: Antonio Borneo Fixes: http://openocd.zylin.com/5653 Reviewed-on: http://openocd.zylin.com/6038 Reviewed-by: Paul Fertser Tested-by: Paul Fertser --- tcl/interface/ftdi/steppenprobe.cfg | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 tcl/interface/ftdi/steppenprobe.cfg diff --git a/tcl/interface/ftdi/steppenprobe.cfg b/tcl/interface/ftdi/steppenprobe.cfg old mode 100755 new mode 100644 From 3ead2633af913ee8777d69405e2dbef6a0fadc1d Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Mon, 1 Feb 2021 00:18:14 +0100 Subject: [PATCH 029/120] github: fix github wokflow while pushing a tag this fix permits to add correctly the generated artifact (windows binaries) into the release section. Change-Id: Ia982370d3a1e08c623ebcabb5ac97e9fb49d00e0 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6047 Tested-by: jenkins Reviewed-by: Antonio Borneo --- .github/workflows/snapshot.yml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index e9a95ffb5..9e871de66 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -85,19 +85,24 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }} path: ${{ env.ARTIFACT_PATH }} - - name: Get the upload URL for a release - id: get_release + - name: Create Release + id: create_release if: startsWith(github.ref, 'refs/tags/') - uses: bruceadams/get-release@v1.2.0 + uses: actions/create-release@v1.1.4 env: - GITHUB_TOKEN: ${{ github.token }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false - name: Release OpenOCD packaged for windows if: startsWith(github.ref, 'refs/tags/') uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ steps.get_release.outputs.upload_url }} + upload_url: ${{ steps.create_release.outputs.upload_url }} asset_path: ${{ env.ARTIFACT_PATH }} asset_name: ${{ env.ARTIFACT_NAME }} asset_content_type: application/gzip From 992508cb805af8a2437977aa1ed61a63a622cdb7 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Thu, 28 Jan 2021 23:27:37 +0900 Subject: [PATCH 030/120] doc: Fix type in Hooking up the JTAG Adapter We are talking about adapter connectivity in this chapter. It should be "dongles" instead of "cables". Change-Id: I7bd4307765517375caa2af86dfc929d0ef66c3e6 Signed-off-by: Yasushi SHOJI Reviewed-on: http://openocd.zylin.com/6040 Reviewed-by: Antonio Borneo Tested-by: jenkins --- doc/openocd.texi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 2658c75ea..4b31cbd0f 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -834,7 +834,7 @@ using Eclipse or some other GUI. Today's most common case is a dongle with a JTAG cable on one side (such as a ribbon cable with a 10-pin or 20-pin IDC connector) and a USB cable on the other. -Instead of USB, some cables use Ethernet; +Instead of USB, some dongles use Ethernet; older ones may use a PC parallel port, or even a serial port. @enumerate From 8a2f2993da3601b22640f9e53ed4c586d0f9db20 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Thu, 28 Jan 2021 23:31:41 +0900 Subject: [PATCH 031/120] doc/manual: Fix @subpage handling The subpage "thelist" used to have a title "Pending and Open Tasks" but the commit c41db358a0100ab changed it to "The List". With @subpage, it now renders: "The List of The List enumerates opportunities for" instead of "The List of Pending and Open Tasks enumerates opportunities for" This commit fix it to "The List enumerates opportunities for" Change-Id: Ifee0dcd9b3c9f7e651a8748a7afda99eedea3c5c Signed-off-by: Yasushi SHOJI Reviewed-on: http://openocd.zylin.com/6041 Tested-by: jenkins Reviewed-by: Antonio Borneo --- doc/manual/main.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/main.txt b/doc/manual/main.txt index c14096b57..14c64c2e7 100644 --- a/doc/manual/main.txt +++ b/doc/manual/main.txt @@ -9,7 +9,7 @@ and processes that have been developed by and for the OpenOCD community. Developers that want to contribute to OpenOCD should read the following sections before starting work: -- The List of @subpage thelist enumerates opportunities for improving or +- @subpage thelist enumerates opportunities for improving or extending the OpenOCD platform. If your ideas are on The List, you might check the mailing list archives to find the status of your feature (or bug). - The @subpage styleguide provides rules that developers should From f68ade529a9ec68032e23c8d3c75c36179b4103f Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Thu, 28 Jan 2021 23:40:52 +0900 Subject: [PATCH 032/120] doc/manual: Fix function name typo We have both the singular form, register_command(), and the plural form register_commands(). Change-Id: I905ea83988b8ac70dd809b02d53b646aa4d66697 Signed-off-by: Yasushi SHOJI Reviewed-on: http://openocd.zylin.com/6042 Reviewed-by: Antonio Borneo Tested-by: jenkins --- doc/manual/helper.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual/helper.txt b/doc/manual/helper.txt index 1b01b2e6b..d5710ddde 100644 --- a/doc/manual/helper.txt +++ b/doc/manual/helper.txt @@ -89,7 +89,7 @@ mode(s) of execution, and strings that provide usage and help text. A single handler may be registered using multiple names, but any name may have only one handler associated with it. -The @c register_commands() and @c register_commands() functions provide +The @c register_command() and @c register_commands() functions provide registration, while the @c unregister_command() and @c unregister_all_commands() functions will remove existing commands. These may be called at any time, allowing the command set to change in From 84a2302af790d28f5dd7e03620703710300305f1 Mon Sep 17 00:00:00 2001 From: Krzysztof Hockuba Date: Wed, 3 Feb 2021 23:01:29 +0100 Subject: [PATCH 033/120] Fix jtag_usb_location_equal for path members > 9 In case an USB location path contains path members larger than 9. The string_length variable is regardless decremented by 2 with assumption that the member is one digit length. For exmaple 1-12.2 will fail. This patch uses strlen to calculate digits in a path member. Change-Id: I9c26a04d0c6af13fec65157f222599497294e2b2 Signed-off-by: Krzysztof Hockuba Reviewed-on: http://openocd.zylin.com/6048 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/jtag_usb_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index 969ea8406..309f8c462 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -50,7 +50,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, goto done; } - string_length -= 1; + string_length -= strnlen(ptr, string_length); /* check bus mismatch */ if (atoi(ptr) != dev_bus) goto done; @@ -68,7 +68,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, break; path_step++; - string_length -= 2; + string_length -= strnlen(ptr, string_length) + 1; }; /* walked the full path, all elements match */ From 54ef790149918df40e6bc2220ffd52ade1b9669b Mon Sep 17 00:00:00 2001 From: Peter Mamonov Date: Mon, 12 Oct 2020 15:02:44 +0300 Subject: [PATCH 034/120] target: use proper macro for parsing watchpoint address Currently wp/rwp commands fail on 64-bit targets: > wp 0xffffffff80001400 4 addr option value ('0xffffffff80001400') is not valid Change-Id: I94d4af906b02b7bd463c8d79a6235a3646dfc434 Signed-off-by: Peter Mamonov Reviewed-on: http://openocd.zylin.com/6058 Tested-by: jenkins Reviewed-by: Andreas Fritiofson Reviewed-by: Antonio Borneo --- src/target/target.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index fa98c884b..033fc0714 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4056,7 +4056,7 @@ COMMAND_HANDLER(handle_wp_command) } enum watchpoint_rw type = WPT_ACCESS; - uint32_t addr = 0; + target_addr_t addr = 0; uint32_t length = 0; uint32_t data_value = 0x0; uint32_t data_mask = 0xffffffff; @@ -4086,7 +4086,7 @@ COMMAND_HANDLER(handle_wp_command) /* fall through */ case 2: COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); break; default: @@ -4106,8 +4106,8 @@ COMMAND_HANDLER(handle_rwp_command) if (CMD_ARGC != 1) return ERROR_COMMAND_SYNTAX_ERROR; - uint32_t addr; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], addr); + target_addr_t addr; + COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); struct target *target = get_current_target(CMD_CTX); watchpoint_remove(target, addr); From ba0f382137749b78b27ac58238735cc20a6fa847 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 11 Feb 2021 19:47:46 +0100 Subject: [PATCH 035/120] autotools: generate list of NEWS-xx file during configure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 4fc0f3530c51 ("Makefile.am: fix non-POSIX warning from automake") uses the BSD make extension '!=' to generate the list of files NEWS-xx, but it's not POSIX (yet), it's not backward compatible with GNU make 3.82 (used in CentOS 7, EOL scheduled for 2024) and depending on automake evolution it could trigger again the warning 'apparently' just fixed. Move in configure the generation of the file list. The only drawback is that when a developer adds a new NEWS-xx file, he/she has to run configure again before 'make distcheck', otherwise will get failure. Change-Id: Ia97e7f4e612655a97702f95e8451040539659b85 Signed-off-by: Antonio Borneo Reported-by: Jan Matyáš Reviewed-on: http://openocd.zylin.com/6054 Tested-by: jenkins Reviewed-by: Jan Matyas Reviewed-by: Andreas Fritiofson --- Makefile.am | 1 - configure.ac | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index a6e7ab232..75f0c0993 100644 --- a/Makefile.am +++ b/Makefile.am @@ -42,7 +42,6 @@ if INTERNAL_JIMTCL AM_CPPFLAGS += -I$(top_srcdir)/jimtcl \ -I$(top_builddir)/jimtcl endif -EXTRA_DIST_NEWS != ls $(srcdir)/NEWS-* EXTRA_DIST += \ BUGS \ HACKING \ diff --git a/configure.ac b/configure.ac index 158ba1599..f1fa5875f 100644 --- a/configure.ac +++ b/configure.ac @@ -854,6 +854,8 @@ AS_IF([test "x$gcc_warnings" = "xyes"], [ AC_SUBST([GCC_WARNINGS], [$GCC_WARNINGS]) ]) +AC_SUBST(EXTRA_DIST_NEWS, ["$(echo $srcdir/NEWS-*)"]) + AC_CONFIG_FILES([ Makefile ]) From 23d8831391bbd167e0061388c87e7ecf7b9891a7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 26 Feb 2021 22:35:39 +0100 Subject: [PATCH 036/120] target: avoid polling during 'resumed' event handler MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenOCD is based on a single main loop that schedules all the activities. At the execution of a TCL command, the timestamp is checked to eventually trigger the polling of the targets. This means that by executing a TCL command the polling can be triggered and detect a change of target's state. When openocd 'resumes' a target, the target can halt again by hitting a breakpoint. The 'resumed' event handler is started just after the target has been resumed, but it triggers a polling before the execution of its very first instruction. If the polling finds the target halted, it will run the 'halted' event handler, that will then be executed 'before' the pending 'resumed' handler. In case of gdb, a 'continue' command will restart the target but, polling (and halt detection) executed before the end of the resume process will hide the halt. As a consequence, the gdb will not be informed of the halt and will remains waiting as if the target is still running without showing the prompt. This can be verified by running on the target a firmware with a loop, run openocd with a dummy 'resumed' event, and let gdb to set a breakpoint in the loop. A 'continue' command will cause the target to halt again by hitting the breakpoint at the next loop iteration, but gdb will loose it and will not return the prompt. openocd -f board/st_nucleo_f4.cfg -c \ 'stm32f4x.cpu configure -event resumed {echo hello}' arm-none-eabi-gdb -ex 'target remote :3333' -ex 'b *$pc' -ex c Disable the polling while executing target's resume(). Document it and provide hints to developers to cope with future implementation. Change-Id: I3be830a8e7c2ef6278617cb4547a4d676b0ddeb5 Signed-off-by: Antonio Borneo Reported-by: Габитов Александр Фаритович Reviewed-on: http://openocd.zylin.com/6074 Reviewed-by: Tomas Vanek Tested-by: jenkins --- doc/openocd.texi | 13 +++++++++++++ src/target/target.c | 11 +++++++++++ 2 files changed, 24 insertions(+) diff --git a/doc/openocd.texi b/doc/openocd.texi index 4b31cbd0f..a5b94362f 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -5035,6 +5035,19 @@ when reset disables PLLs needed to use a fast clock. @* After target hardware trace configuration was changed @end itemize +@quotation Note +OpenOCD events are not supposed to be preempt by another event, but this +is not enforced in current code. Only the target event @b{resumed} is +executed with polling disabled; this avoids polling to trigger the event +@b{halted}, reversing the logical order of execution of their handlers. +Future versions of OpenOCD will prevent the event preemption and will +disable the schedule of polling during the event execution. Do not rely +on polling in any event handler; this means, don't expect the status of +a core to change during the execution of the handler. The event handler +will have to enable polling or use @command{$target_name arp_poll} to +check if the core has changed status. +@end quotation + @node Flash Commands @chapter Flash Commands diff --git a/src/target/target.c b/src/target/target.c index 033fc0714..cab84b06b 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -637,7 +637,18 @@ int target_resume(struct target *target, int current, target_addr_t address, * we poll. The CPU can even halt at the current PC as a result of * a software breakpoint being inserted by (a bug?) the application. */ + /* + * resume() triggers the event 'resumed'. The execution of TCL commands + * in the event handler causes the polling of targets. If the target has + * already halted for a breakpoint, polling will run the 'halted' event + * handler before the pending 'resumed' handler. + * Disable polling during resume() to guarantee the execution of handlers + * in the correct order. + */ + bool save_poll = jtag_poll_get_enabled(); + jtag_poll_set_enabled(false); retval = target->type->resume(target, current, address, handle_breakpoints, debug_execution); + jtag_poll_set_enabled(save_poll); if (retval != ERROR_OK) return retval; From 5f3bc3b279c648f5c751fcd4724206c6ce3e38c6 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Wed, 3 Mar 2021 21:57:33 +0100 Subject: [PATCH 037/120] tcl/target/eos_s3: fix variable's expansion typo TCL expands the variables only if preceded by a dollar sign. Add the missing dollar before the variable's name '_CPUTAPID'. Change-Id: Icc5d0dddf24f75d12ee63fee69e1b265e842ca43 Signed-off-by: Antonio Borneo Reported-by: Wes Cilldhaire Fixes: c3166b43e415 ("tcl/target: Add QuickLogic EOS S3 MCU configuration") Reviewed-on: http://openocd.zylin.com/6079 Tested-by: jenkins Reviewed-by: TM --- tcl/target/eos_s3.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tcl/target/eos_s3.cfg b/tcl/target/eos_s3.cfg index f6016fb30..150ef4e31 100644 --- a/tcl/target/eos_s3.cfg +++ b/tcl/target/eos_s3.cfg @@ -26,7 +26,7 @@ if { [info exists CPUTAPID] } { } } -swj_newdap $_CHIPNAME cpu -irlen 4 -irmask 0xf -expected-id _CPUTAPID +swj_newdap $_CHIPNAME cpu -irlen 4 -irmask 0xf -expected-id $_CPUTAPID dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu set _TARGETNAME $_CHIPNAME.cpu From f342aac0845a69d591ad39a025d74e9c765f6420 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 7 Mar 2021 13:36:49 +0300 Subject: [PATCH 038/120] The openocd-0.11.0 release Signed-off-by: Paul Fertser --- NEWS | 2 +- configure.ac | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 36ee8fd2e..4542aa28f 100644 --- a/NEWS +++ b/NEWS @@ -227,7 +227,7 @@ This release also contains a number of other important functional and cosmetic bugfixes. For more details about what has changed since the last release, see the git repository history: -http://sourceforge.net/p/openocd/code/ci/v0.11.0-rc2/log/?path= +http://sourceforge.net/p/openocd/code/ci/v0.11.0/log/?path= For older NEWS, see the NEWS files associated with each release diff --git a/configure.ac b/configure.ac index f1fa5875f..a5c9c9276 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.64) -AC_INIT([openocd], [0.11.0-rc2+dev], +AC_INIT([openocd], [0.11.0], [OpenOCD Mailing List ]) AC_CONFIG_SRCDIR([src/openocd.c]) AC_CONFIG_AUX_DIR([.]) From 4307d93eb00ac27373c62f08b8547b993b66fe82 Mon Sep 17 00:00:00 2001 From: Paul Fertser Date: Sun, 7 Mar 2021 15:44:45 +0300 Subject: [PATCH 039/120] Restore normal development cycle Signed-off-by: Paul Fertser --- NEWS | 205 +------------------------------------------- NEWS-0.11.0 | 238 +++++++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 2 +- 3 files changed, 240 insertions(+), 205 deletions(-) create mode 100644 NEWS-0.11.0 diff --git a/NEWS b/NEWS index 4542aa28f..9db6c5fee 100644 --- a/NEWS +++ b/NEWS @@ -2,232 +2,29 @@ This file includes highlights of the changes made in the OpenOCD source archive release. JTAG Layer: - * add debug level 4 for verbose I/O debug - * bitbang, add read buffer to improve performance - * Cadence SystemVerilog Direct Programming Interface (DPI) adapter driver - * CMSIS-DAP v2 (USB bulk based) adapter driver - * Cypress KitProg adapter driver - * FTDI FT232R sync bitbang adapter driver - * Linux GPIOD bitbang adapter driver through libgpiod - * Mellanox rshim USB or PCIe adapter driver - * Nuvoton Nu-Link and Nu-Link2 adapter drivers - * NXP IMX GPIO mmap based adapter driver - * ST-Link consolidate all versions in single config - * ST-Link read properly old USB serial numbers - * STLink/V3 support (for ST devices only !) - * STM8 SWIM transport - * TI XDS110 adapter driver - * Xilinx XVC/PCIe adapter driver Boundary Scan: Target Layer: - * 64 bit address support - * ARCv2 target support - * ARM Cortex-A hypervisor mode support - * ARM Cortex-M fast PC sampling support for profiling - * ARM generic CTI support - * ARM generic mem-ap target support - * ARMv7-A MMU tools - * ARMv7m traces add TCP stream server - * ARMv8 AARCH64 target support and semihosting support - * ARMv8 AARCH64 disassembler support through capstone library - * ARMv8-M target support - * EnSilica eSi-RISC target support, including instruction tracing - eSi-Trace support - * MIPS64 target support - * Motorola SREC S6 record image file support - * RISC-V target support - * SEGGER Real Time Transfer (RTT) initial support (for single target, - Cortex-M only) - * ST STM8 target support - * Various MIPS32 target improvements Flash Layer: - * Atheros (ath79) SPI interface support - * Atmel atmega128rfa1 support - * Atmel SAM D21, D51, DA1, E51, E53, E54, G55, R30 support - * Atmel SAMC2?N* support - * Cypress PSoC5LP, PSoC6 support - * EnSilica eSi-RISC support - * Foshan Synwit Tech SWM050 support - * Maxim Integrated MAX32XXX support - * Nordic Semiconductor nRF51822, nRF52810, nRF52832 support - * NXP Kinetis K27, K28, KE1x, KEAx, KL28, KL8x, KV5x, KWx support - * Renesas RPC HF support - * SH QSPI support - * SiFive Freedom E support - * Silicon Labs EFR-family, EZR32HG support - * ST BlueNRG support - * ST STM32 QUAD/OCTO-SPI interface support for Flash, FRAM and EEPROM - * ST STM32F72x, STM32F4x3, STM32H7xx support - * ST STM32G0xx, STM32G4xx, STM32L4x, STM32WB, STM32WL support - * ST STM32L5x support (non secure mode) - * TI CC13xx, CC26xx, CC32xx support - * TI MSP432 support - * Winner Micro w600 support - * Xilinx XCF platform support - * Various discrete SPI NOR flashes support Board, Target, and Interface Configuration Scripts: - * 8devices LIMA board config - * Achilles Instant-Development Kit Arria 10 board config - * Amazon Kindle 2 and DX board config - * Analog Devices ADSP-SC58x, ADSP-SC584-EZBRD board config - * Andes Technology ADP-XC7KFF676 board config - * Andes Technology Corvette-F1 board config - * ARM Musca A board config - * Arty Spartan 7 FPGA board config - * Atmel SAMD10 Xplained mini board config - * Atmel SAMD11 Xplained Pro board config - * Atmel SAM G55 Xplained Pro board config - * AVNET UltraZED EG StarterKit board config - * Blue Pill STM32F103C8 board config - * DP Busblaster v4.1a board config - * DPTechnics DPT-Board-v1 board config - * Emcraft imx8 SOM BSB board config - * Globalscale ESPRESSObin board config - * Kasli board config - * Kintex Ultrascale XCKU040 board config - * Knovative KC-100 board config - * LeMaker HiKey board config - * Microchip (Atmel) SAME54 Xplained Pro board config - * Microchip (Atmel) SAML11 Xplained Pro board config - * Nordic module NRF52 board config - * Numato Lab Mimas A7 board config - * NXP Freedom FRDM-LS1012A board config - * NXP IMX7SABRE board config - * NXP IMX8MP-EVK board config - * NXP MC-IMX8M-EVK board config - * QuickLogic QuickFeather board config - * Renesas R-Car E2, H2, M2 board config - * Renesas R-Car Salvator-X(S) board config - * Renesas RZ/A1H GR-Peach board config - * Rigado BMD-300 board config - * Sayma AMC board config - * Sifive e31arty, e51arty, hifive1 board config - * ST B-L475E-IOT01A board config - * ST BlueNRG idb007v1, idb008v1, idb011v1 board config - * ST STM32F412g discovery board config - * ST STM32F413h discovery board config - * ST STM32F469i discovery board config - * ST STM32F7 Nucleo board config - * ST STM32F723e discovery board config - * ST STM32F746g discovery board config - * ST STM32F769i discovery board config - * ST STM32H735g discovery board config - * ST STM32H743zi Nucleo board config - * ST STM32H745i discovery board config - * ST STM32H747i discovery board config - * ST STM32H750b discovery board config - * ST STM32H7b3i discovery board config - * ST STM32H7x_dual_qspi board config - * ST STM32H7x3i Eval boards config - * ST STM32L073 Nucleo board config - * ST STM32L476g discovery board config - * ST STM32L496g discovery board config - * ST STM32L4p5g discovery board config - * ST STM32L4r9i discovery board config - * ST STM32L5 Nucleo board config - * ST STM32MP15x DK2 board config - * ST STM32WB Nucleo board config - * ST STM8L152R8 Nucleo board config - * Synopsys DesignWare ARC EM board config - * Synopsys DesignWare ARC HSDK board config - * TI BeagleBone family boards config - * TI CC13xx, CC26xx, CC32xx LaunchPad board config - * TI MSP432 LaunchPad board config - * Tocoding Poplar board config - * TP-Link WDR4300 board config - * Allwinner V3s target config - * Andes Technology NDS V5 target config - * Atmel atmega128rfa1 target config - * ARM corelink SSE-200 target config - * Atheros_ar9344 target config - * Cypress PSoC5LP, PSoC6 target config - * EnSilica eSi-RISC target config - * Foshan Synwit Tech SWM050 target config - * GigaDevice GD32VF103 target config - * Hisilicon Hi3798 target config - * Hisilicon Hi6220 target config - * Infineon TLE987x target config - * Marvell Armada 3700 target config - * Maxim Integrated MAX32XXX target config - * Mellanox BlueField target config - * Microchip (Atmel) SAME5x, SAML1x target config - * NXP IMX6SX, IMX6UL, IMX7, IMX7ULP, IMX8 target config - * NXP Kinetis KE1xZ, KE1xF target config - * NXP LPC84x, LPC8Nxx, LS1012A, NHS31xx target config - * Qualcomm QCA4531 target config - * QuickLogic EOS S3 target config - * Renesas R-Car E2, H2, M2 target config - * Renesas R-Car Gen3 target config - * Renesas RZ/A1H target config - * Rockchip RK3308 target config - * ST BlueNRG target config - * ST STM32G0, STM32G4, STM32H7, STM32L0, STM32L5 target config - * ST STM32MP15x target config - * ST STM32WBx, STM32WLEx target config - * ST STM8L152, S003, S103, S105 target config - * Synopsys DesignWare ARC EM target config - * Synopsys DesignWare ARC HS Development Kit SoC target config - * TI CC13xx, CC26xx, CC32xx target config - * TI TNETC4401 target config - * Xilinx UltraScale+ target config - * Altera 5M570Z (MAXV family) CPLD config - * Xilinx Ultrascale, XCF CPLD config - * Intel (Altera) Arria10 FPGA config - * Cadence SystemVerilog Direct Programming Interface (DPI) interface config - * Cypress KitProg interface config - * Digilent SMT2 NC interface config - * DLN-2 example of Linux GPIOD interface config - * FTDI C232HM interface config - * HIE JTAG Debugger interface config - * In-Circuit's ICprog interface config - * isodebug isolated JTAG/SWD+UART interface config - * Mellanox rshim USB or PCIe interface config - * Nuvoton Nu-Link interface config - * NXP IMX GPIO mmap based interface config - * Steppenprobe open hardware interface config - * TI XDS110 interface config Server Layer: - * 64 bit address support - * default bind to IPv4 localhost - * gdb: allow multiple connections - * gdb: architecture element support - * gdb: vCont, vRun support - * telnet: handle Ctrl+A, Ctrl+E and Ctrl+K RTOS: - * Chromium-EC rtos support - * hwthread pseudo rtos support - * NuttX rtos support - * RIOT rtos support Documentation: - * Improve STM32 flash driver - * Various typo fix and improvements Build and Release: - * Add libutil to support jimtcl version 0.80 - * Clang warning fixes - * GitHub workflow for Win32 snapshot binaries - * Handle Tcl return values consistently - * Mitigation for CVE-2018-5704: Prevent some forms of Cross - Protocol Scripting attacks - * Support for libftdi 1.5 - * Travis-CI basic support - * Update libjaylink to version 0.2.0 - * Update jimtcl to version 0.79 - * Use external (optional) library capstone for ARM and AARCH64 disassembly This release also contains a number of other important functional and cosmetic bugfixes. For more details about what has changed since the last release, see the git repository history: -http://sourceforge.net/p/openocd/code/ci/v0.11.0/log/?path= +http://sourceforge.net/p/openocd/code/ci/v0.x.0/log/?path= For older NEWS, see the NEWS files associated with each release diff --git a/NEWS-0.11.0 b/NEWS-0.11.0 new file mode 100644 index 000000000..4542aa28f --- /dev/null +++ b/NEWS-0.11.0 @@ -0,0 +1,238 @@ +This file includes highlights of the changes made in the OpenOCD +source archive release. + +JTAG Layer: + * add debug level 4 for verbose I/O debug + * bitbang, add read buffer to improve performance + * Cadence SystemVerilog Direct Programming Interface (DPI) adapter driver + * CMSIS-DAP v2 (USB bulk based) adapter driver + * Cypress KitProg adapter driver + * FTDI FT232R sync bitbang adapter driver + * Linux GPIOD bitbang adapter driver through libgpiod + * Mellanox rshim USB or PCIe adapter driver + * Nuvoton Nu-Link and Nu-Link2 adapter drivers + * NXP IMX GPIO mmap based adapter driver + * ST-Link consolidate all versions in single config + * ST-Link read properly old USB serial numbers + * STLink/V3 support (for ST devices only !) + * STM8 SWIM transport + * TI XDS110 adapter driver + * Xilinx XVC/PCIe adapter driver + +Boundary Scan: + +Target Layer: + * 64 bit address support + * ARCv2 target support + * ARM Cortex-A hypervisor mode support + * ARM Cortex-M fast PC sampling support for profiling + * ARM generic CTI support + * ARM generic mem-ap target support + * ARMv7-A MMU tools + * ARMv7m traces add TCP stream server + * ARMv8 AARCH64 target support and semihosting support + * ARMv8 AARCH64 disassembler support through capstone library + * ARMv8-M target support + * EnSilica eSi-RISC target support, including instruction tracing + eSi-Trace support + * MIPS64 target support + * Motorola SREC S6 record image file support + * RISC-V target support + * SEGGER Real Time Transfer (RTT) initial support (for single target, + Cortex-M only) + * ST STM8 target support + * Various MIPS32 target improvements + +Flash Layer: + * Atheros (ath79) SPI interface support + * Atmel atmega128rfa1 support + * Atmel SAM D21, D51, DA1, E51, E53, E54, G55, R30 support + * Atmel SAMC2?N* support + * Cypress PSoC5LP, PSoC6 support + * EnSilica eSi-RISC support + * Foshan Synwit Tech SWM050 support + * Maxim Integrated MAX32XXX support + * Nordic Semiconductor nRF51822, nRF52810, nRF52832 support + * NXP Kinetis K27, K28, KE1x, KEAx, KL28, KL8x, KV5x, KWx support + * Renesas RPC HF support + * SH QSPI support + * SiFive Freedom E support + * Silicon Labs EFR-family, EZR32HG support + * ST BlueNRG support + * ST STM32 QUAD/OCTO-SPI interface support for Flash, FRAM and EEPROM + * ST STM32F72x, STM32F4x3, STM32H7xx support + * ST STM32G0xx, STM32G4xx, STM32L4x, STM32WB, STM32WL support + * ST STM32L5x support (non secure mode) + * TI CC13xx, CC26xx, CC32xx support + * TI MSP432 support + * Winner Micro w600 support + * Xilinx XCF platform support + * Various discrete SPI NOR flashes support + +Board, Target, and Interface Configuration Scripts: + * 8devices LIMA board config + * Achilles Instant-Development Kit Arria 10 board config + * Amazon Kindle 2 and DX board config + * Analog Devices ADSP-SC58x, ADSP-SC584-EZBRD board config + * Andes Technology ADP-XC7KFF676 board config + * Andes Technology Corvette-F1 board config + * ARM Musca A board config + * Arty Spartan 7 FPGA board config + * Atmel SAMD10 Xplained mini board config + * Atmel SAMD11 Xplained Pro board config + * Atmel SAM G55 Xplained Pro board config + * AVNET UltraZED EG StarterKit board config + * Blue Pill STM32F103C8 board config + * DP Busblaster v4.1a board config + * DPTechnics DPT-Board-v1 board config + * Emcraft imx8 SOM BSB board config + * Globalscale ESPRESSObin board config + * Kasli board config + * Kintex Ultrascale XCKU040 board config + * Knovative KC-100 board config + * LeMaker HiKey board config + * Microchip (Atmel) SAME54 Xplained Pro board config + * Microchip (Atmel) SAML11 Xplained Pro board config + * Nordic module NRF52 board config + * Numato Lab Mimas A7 board config + * NXP Freedom FRDM-LS1012A board config + * NXP IMX7SABRE board config + * NXP IMX8MP-EVK board config + * NXP MC-IMX8M-EVK board config + * QuickLogic QuickFeather board config + * Renesas R-Car E2, H2, M2 board config + * Renesas R-Car Salvator-X(S) board config + * Renesas RZ/A1H GR-Peach board config + * Rigado BMD-300 board config + * Sayma AMC board config + * Sifive e31arty, e51arty, hifive1 board config + * ST B-L475E-IOT01A board config + * ST BlueNRG idb007v1, idb008v1, idb011v1 board config + * ST STM32F412g discovery board config + * ST STM32F413h discovery board config + * ST STM32F469i discovery board config + * ST STM32F7 Nucleo board config + * ST STM32F723e discovery board config + * ST STM32F746g discovery board config + * ST STM32F769i discovery board config + * ST STM32H735g discovery board config + * ST STM32H743zi Nucleo board config + * ST STM32H745i discovery board config + * ST STM32H747i discovery board config + * ST STM32H750b discovery board config + * ST STM32H7b3i discovery board config + * ST STM32H7x_dual_qspi board config + * ST STM32H7x3i Eval boards config + * ST STM32L073 Nucleo board config + * ST STM32L476g discovery board config + * ST STM32L496g discovery board config + * ST STM32L4p5g discovery board config + * ST STM32L4r9i discovery board config + * ST STM32L5 Nucleo board config + * ST STM32MP15x DK2 board config + * ST STM32WB Nucleo board config + * ST STM8L152R8 Nucleo board config + * Synopsys DesignWare ARC EM board config + * Synopsys DesignWare ARC HSDK board config + * TI BeagleBone family boards config + * TI CC13xx, CC26xx, CC32xx LaunchPad board config + * TI MSP432 LaunchPad board config + * Tocoding Poplar board config + * TP-Link WDR4300 board config + * Allwinner V3s target config + * Andes Technology NDS V5 target config + * Atmel atmega128rfa1 target config + * ARM corelink SSE-200 target config + * Atheros_ar9344 target config + * Cypress PSoC5LP, PSoC6 target config + * EnSilica eSi-RISC target config + * Foshan Synwit Tech SWM050 target config + * GigaDevice GD32VF103 target config + * Hisilicon Hi3798 target config + * Hisilicon Hi6220 target config + * Infineon TLE987x target config + * Marvell Armada 3700 target config + * Maxim Integrated MAX32XXX target config + * Mellanox BlueField target config + * Microchip (Atmel) SAME5x, SAML1x target config + * NXP IMX6SX, IMX6UL, IMX7, IMX7ULP, IMX8 target config + * NXP Kinetis KE1xZ, KE1xF target config + * NXP LPC84x, LPC8Nxx, LS1012A, NHS31xx target config + * Qualcomm QCA4531 target config + * QuickLogic EOS S3 target config + * Renesas R-Car E2, H2, M2 target config + * Renesas R-Car Gen3 target config + * Renesas RZ/A1H target config + * Rockchip RK3308 target config + * ST BlueNRG target config + * ST STM32G0, STM32G4, STM32H7, STM32L0, STM32L5 target config + * ST STM32MP15x target config + * ST STM32WBx, STM32WLEx target config + * ST STM8L152, S003, S103, S105 target config + * Synopsys DesignWare ARC EM target config + * Synopsys DesignWare ARC HS Development Kit SoC target config + * TI CC13xx, CC26xx, CC32xx target config + * TI TNETC4401 target config + * Xilinx UltraScale+ target config + * Altera 5M570Z (MAXV family) CPLD config + * Xilinx Ultrascale, XCF CPLD config + * Intel (Altera) Arria10 FPGA config + * Cadence SystemVerilog Direct Programming Interface (DPI) interface config + * Cypress KitProg interface config + * Digilent SMT2 NC interface config + * DLN-2 example of Linux GPIOD interface config + * FTDI C232HM interface config + * HIE JTAG Debugger interface config + * In-Circuit's ICprog interface config + * isodebug isolated JTAG/SWD+UART interface config + * Mellanox rshim USB or PCIe interface config + * Nuvoton Nu-Link interface config + * NXP IMX GPIO mmap based interface config + * Steppenprobe open hardware interface config + * TI XDS110 interface config + +Server Layer: + * 64 bit address support + * default bind to IPv4 localhost + * gdb: allow multiple connections + * gdb: architecture element support + * gdb: vCont, vRun support + * telnet: handle Ctrl+A, Ctrl+E and Ctrl+K + +RTOS: + * Chromium-EC rtos support + * hwthread pseudo rtos support + * NuttX rtos support + * RIOT rtos support + +Documentation: + * Improve STM32 flash driver + * Various typo fix and improvements + +Build and Release: + * Add libutil to support jimtcl version 0.80 + * Clang warning fixes + * GitHub workflow for Win32 snapshot binaries + * Handle Tcl return values consistently + * Mitigation for CVE-2018-5704: Prevent some forms of Cross + Protocol Scripting attacks + * Support for libftdi 1.5 + * Travis-CI basic support + * Update libjaylink to version 0.2.0 + * Update jimtcl to version 0.79 + * Use external (optional) library capstone for ARM and AARCH64 disassembly + + +This release also contains a number of other important functional and +cosmetic bugfixes. For more details about what has changed since the +last release, see the git repository history: + +http://sourceforge.net/p/openocd/code/ci/v0.11.0/log/?path= + + +For older NEWS, see the NEWS files associated with each release +(i.e. NEWS-). + +For more information about contributing test reports, bug fixes, or new +features and device support, please read the new Developer Manual (or +the BUGS and PATCHES.txt files in the source archive). diff --git a/configure.ac b/configure.ac index a5c9c9276..a74f319ba 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_PREREQ(2.64) -AC_INIT([openocd], [0.11.0], +AC_INIT([openocd], [0.11.0+dev], [OpenOCD Mailing List ]) AC_CONFIG_SRCDIR([src/openocd.c]) AC_CONFIG_AUX_DIR([.]) From 431dd885368ec90fe2f74ba50bbe70577844615b Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Fri, 8 Jun 2018 16:48:27 -0500 Subject: [PATCH 040/120] tcl/target: Add K3 basic support Add basic connection details for AM654 and J721E SoCs from TI. See AM65x Technical Reference Manual (SPRUID7, April 2018) for further details: https://www.ti.com/lit/pdf/spruid7 See J721E Technical Reference Manual (SPRUIL1, May 2019) for further details: https://www.ti.com/lit/pdf/spruil1 See J7200 Technical Reference Manual (SPRUIU1, June 2020) for further details: https://www.ti.com/lit/pdf/spruiu1 See AM64X Technical Reference Manual (SPRUIM2, Nov 2020) for further details: https://www.ti.com/lit/pdf/spruim2 Change-Id: Ie5108c6ad6f1304a6bf5b9f81aa9ebd33b8a559d Signed-off-by: Nishanth Menon Reviewed-on: http://openocd.zylin.com/5182 Reviewed-by: Antonio Borneo Tested-by: jenkins --- tcl/target/ti_k3.cfg | 256 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 tcl/target/ti_k3.cfg diff --git a/tcl/target/ti_k3.cfg b/tcl/target/ti_k3.cfg new file mode 100644 index 000000000..d2aa53160 --- /dev/null +++ b/tcl/target/ti_k3.cfg @@ -0,0 +1,256 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/ +# +# Texas Instruments K3 devices: +# * AM654x: https://www.ti.com/lit/pdf/spruid7 +# Has 4 ARMV8 Cores and 2 R5 Cores and an M3 +# * J721E: https://www.ti.com/lit/pdf/spruil1 +# Has 2 ARMV8 Cores and 6 R5 Cores and an M3 +# * J7200: https://www.ti.com/lit/pdf/spruiu1 +# Has 2 ARMV8 Cores and 4 R5 Cores and an M3 +# * AM642: https://www.ti.com/lit/pdf/spruim2 +# Has 2 ARMV8 Cores and 4 R5 Cores, M4F and an M3 +# + +if { [info exists SOC] } { + set _soc $SOC +} else { + set _soc am654 +} + +# set V8_SMP_DEBUG to non 0 value in board if you'd like to use SMP debug +if { [info exists V8_SMP_DEBUG] } { + set _v8_smp_debug $V8_SMP_DEBUG +} else { + set _v8_smp_debug 0 +} + +# Common Definitions + +# CM3 the very first processor - all current SoCs have it. +set CM3_CTIBASE {0x3C016000} + +# M3 power-ap unlock offsets +set _m3_ap_unlock_offsets {0xf0 0x44} + +# All the ARMV8s are the next processors. +# CL0,CORE0 CL0,CORE1 CL1,CORE0 CL1,CORE1 +set ARMV8_DBGBASE {0x90410000 0x90510000 0x90810000 0x90910000} +set ARMV8_CTIBASE {0x90420000 0x90520000 0x90820000 0x90920000} + +# And we add up the R5s +# (0)MCU 0 (1)MCU 1 (2)MAIN_0_0 (3)MAIN_0_1 (4)MAIN_1_0 (5)MAIN_1_1 +set R5_DBGBASE {0x9d010000 0x9d012000 0x9d410000 0x9d412000 0x9d510000 0x9d512000} +set R5_CTIBASE {0x9d018000 0x9d019000 0x9d418000 0x9d419000 0x9d518000 0x9d519000} + +# Finally an M4F +set CM4_CTIBASE {0x20001000} + +# M4 may be present on some very few SoCs +set _mcu_m4_cores 0 +# M4 power-ap unlock offsets +set _m4_ap_unlock_offsets {0xf0 0x60} + +# Set configuration overrides for each SOC +switch $_soc { + am654 { + set _CHIPNAME am654 + set _K3_DAP_TAPID 0x0bb5a02f + + # AM654 has 2 clusters of 2 A53 cores each. + set _armv8_cpu_name a53 + set _armv8_cores 4 + + # AM654 has 1 cluster of 2 R5s cores. + set _r5_cores 2 + set _mcu_r5_cores 2 + set _mcu_base_core_id 0 + set _main0_r5_cores 0 + set _main0_base_core_id 0 + set _main1_r5_cores 0 + set _main1_base_core_id 0 + + # M3 power-ap unlock offsets + set _m3_ap_unlock_offsets {0xf0 0x50} + } + am642 { + set _CHIPNAME am642 + set _K3_DAP_TAPID 0x0bb3802f + + # AM642 has 1 clusters of 2 A53 cores each. + set _armv8_cpu_name a53 + set _armv8_cores 2 + set ARMV8_DBGBASE {0x90010000 0x90110000} + set ARMV8_CTIBASE {0x90020000 0x90120000} + + # AM642 has 2 cluster of 2 R5s cores. + set _r5_cores 4 + set _mcu_r5_cores 0 + set _mcu_base_core_id 0 + set _main0_r5_cores 2 + set _main0_base_core_id 0 + set _main1_r5_cores 2 + set _main1_base_core_id 2 + set R5_DBGBASE {0x9d410000 0x9d412000 0x9d510000 0x9d512000} + set R5_CTIBASE {0x9d418000 0x9d419000 0x9d518000 0x9d519000} + + # M4 processor + set _mcu_m4_cores 1 + } + j721e { + set _CHIPNAME j721e + set _K3_DAP_TAPID 0x0bb6402f + # J721E has 1 cluster of 2 A72 cores. + set _armv8_cpu_name a72 + set _armv8_cores 2 + + # J721E has 3 clusters of 2 R5 cores each. + set _r5_cores 6 + set _mcu_r5_cores 2 + set _mcu_base_core_id 0 + set _main0_r5_cores 2 + set _main0_base_core_id 2 + set _main1_r5_cores 2 + set _main1_base_core_id 4 + } + j7200 { + set _CHIPNAME j7200 + set _K3_DAP_TAPID 0x0bb6d02f + + # J7200 has 1 cluster of 2 A72 cores. + set _armv8_cpu_name a72 + set _armv8_cores 2 + + # J7200 has 2 clusters of 2 R5 cores each. + set _r5_cores 4 + set _mcu_r5_cores 2 + set _mcu_base_core_id 0 + set _main0_r5_cores 2 + set _main0_base_core_id 2 + set _main1_r5_cores 0 + set _main1_base_core_id 0 + set R5_DBGBASE {0x9d010000 0x9d012000 0x9d110000 0x9d112000} + set R5_CTIBASE {0x9d018000 0x9d019000 0x9d118000 0x9d119000} + + # M3 CTI base + set CM3_CTIBASE {0x20001000} + } + default { + echo "'$_soc' is invalid!" + } +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -expected-id $_K3_DAP_TAPID -ignore-version +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +set _TARGETNAME $_CHIPNAME.cpu + +set _CTINAME $_CHIPNAME.cti + +# M3 is always present +cti create $_CTINAME.m3 -dap $_CHIPNAME.dap -ap-num 7 -baseaddr [lindex $CM3_CTIBASE 0] +target create $_TARGETNAME.m3 cortex_m -dap $_CHIPNAME.dap -ap-num 7 -defer-examine +$_TARGETNAME.m3 configure -event reset-assert { } + +proc m3_up { args } { + # To access M3, we need to enable the JTAG access for the same. + # Ensure Power-AP unlocked + $::_CHIPNAME.dap apreg 3 [lindex $::_m3_ap_unlock_offsets 0] 0x00190000 + $::_CHIPNAME.dap apreg 3 [lindex $::_m3_ap_unlock_offsets 1] 0x00102098 + + $::_TARGETNAME.m3 arp_examine +} + +set _v8_smp_targets "" + +for { set _core 0 } { $_core < $_armv8_cores } { incr _core } { + + cti create $_CTINAME.$_armv8_cpu_name.$_core -dap $_CHIPNAME.dap -ap-num 1 \ + -baseaddr [lindex $ARMV8_CTIBASE $_core] + + target create $_TARGETNAME.$_armv8_cpu_name.$_core aarch64 -dap $_CHIPNAME.dap \ + -dbgbase [lindex $ARMV8_DBGBASE $_core] -cti $_CTINAME.$_armv8_cpu_name.$_core -defer-examine + + set _v8_smp_targets "$_v8_smp_targets $_TARGETNAME.$_armv8_cpu_name.$_core" +} + +# Setup ARMV8 proc commands based on CPU to prevent people confusing SoCs +set _armv8_up_cmd "$_armv8_cpu_name"_up +# Available if V8_SMP_DEBUG is set to non-zero value +set _armv8_smp_cmd "$_armv8_cpu_name"_smp + +if { $_v8_smp_debug == 0 } { + proc $_armv8_up_cmd { args } { + foreach { _core } [set args] { + $::_TARGETNAME.$::_armv8_cpu_name.$_core arp_examine + $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 dbginit + } + } +} else { + proc $_armv8_smp_cmd { args } { + for { set _core 0 } { $_core < $::_armv8_cores } { incr _core } { + $::_TARGETNAME.$::_armv8_cpu_name.$_core arp_examine + $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 dbginit + $::_TARGETNAME.$::_armv8_cpu_name.$_core aarch64 smp on + } + # Set Default target are core 0 + targets $::_TARGETNAME.$::_armv8_cpu_name.0 + } + + # Declare SMP + target smp $:::_v8_smp_targets +} + +for { set _core 0 } { $_core < $_r5_cores } { incr _core } { + cti create $_CTINAME.r5.$_core -dap $_CHIPNAME.dap -ap-num 1 \ + -baseaddr [lindex $R5_CTIBASE $_core] + + # inactive core examination will fail - wait till startup of additional core + target create $_TARGETNAME.r5.$_core cortex_r4 -dap $_CHIPNAME.dap \ + -dbgbase [lindex $R5_DBGBASE $_core] -ap-num 1 -defer-examine +} + +if { $_mcu_r5_cores != 0 } { + proc mcu_r5_up { args } { + foreach { _core } [set args] { + set _core [expr {$_core + $::_mcu_base_core_id}] + $::_TARGETNAME.r5.$_core arp_examine + $::_TARGETNAME.r5.$_core cortex_r4 dbginit + } + } +} + +if { $_main0_r5_cores != 0 } { + proc main0_r5_up { args } { + foreach { _core } [set args] { + set _core [expr {$_core + $::_main0_base_core_id}] + $::_TARGETNAME.r5.$_core arp_examine + $::_TARGETNAME.r5.$_core cortex_r4 dbginit + } + } +} + +if { $_main1_r5_cores != 0 } { + proc main1_r5_up { args } { + foreach { _core } [set args] { + set _core [expr {$_core + $::_main1_base_core_id}] + $::_TARGETNAME.r5.$_core arp_examine + $::_TARGETNAME.r5.$_core cortex_r4 dbginit + } + } +} + +if { $_mcu_m4_cores != 0 } { + cti create $_CTINAME.m4 -dap $_CHIPNAME.dap -ap-num 8 -baseaddr [lindex $CM4_CTIBASE 0] + target create $_TARGETNAME.m4 cortex_m -dap $_CHIPNAME.dap -ap-num 8 -defer-examine + $_TARGETNAME.m4 configure -event reset-assert { } + + proc m4_up { args } { + # To access M4, we need to enable the JTAG access for the same. + # Ensure Power-AP unlocked + $::_CHIPNAME.dap apreg 3 [lindex $::_m4_ap_unlock_offsets 0] 0x00190000 + $::_CHIPNAME.dap apreg 3 [lindex $::_m4_ap_unlock_offsets 1] 0x00102098 + + $::_TARGETNAME.m4 arp_examine + } +} From 39f8327639f005353e905002abd492e9616b217d Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Fri, 8 Jun 2018 16:48:27 -0500 Subject: [PATCH 041/120] tcl/board: Add AM654 EVM basic support Add basic connection details with AM654 evm Change-Id: Iea2240860e50ae42cf6f1617a10e24f63c6dd988 Signed-off-by: Nishanth Menon Reviewed-on: http://openocd.zylin.com/5183 Reviewed-by: Antonio Borneo Tested-by: jenkins --- tcl/board/ti_am654evm.cfg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tcl/board/ti_am654evm.cfg diff --git a/tcl/board/ti_am654evm.cfg b/tcl/board/ti_am654evm.cfg new file mode 100644 index 000000000..a661f6068 --- /dev/null +++ b/tcl/board/ti_am654evm.cfg @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/ +# +# Texas Instruments AM654 EVM/IDK Base Board +# + +# AM654 EVM has an xds110 onboard. +source [find interface/xds110.cfg] + +transport select jtag + +# default JTAG configuration has only SRST and no TRST +reset_config srst_only srst_push_pull + +# delay after SRST goes inactive +adapter srst delay 70 + +if { ![info exists SOC] } { + set SOC am654 +} + +source [find target/ti_k3.cfg] + +adapter speed 2500 From e8c7689c61686489bf273f5d61b0b257e6aa52f1 Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Sat, 11 May 2019 03:15:39 -0500 Subject: [PATCH 042/120] tcl/board: Add J721E EVM basic support Add basic connection details with J721E EVM Change-Id: I0c2d25252432914d8e371e81761a59c05924bd8e Signed-off-by: Nishanth Menon Reviewed-on: http://openocd.zylin.com/5185 Reviewed-by: Antonio Borneo Tested-by: jenkins --- tcl/board/ti_j721evm.cfg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tcl/board/ti_j721evm.cfg diff --git a/tcl/board/ti_j721evm.cfg b/tcl/board/ti_j721evm.cfg new file mode 100644 index 000000000..d0c4b7496 --- /dev/null +++ b/tcl/board/ti_j721evm.cfg @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/ +# +# Texas Instruments J721E EVM +# + +# J721E EVM has an xds110 onboard. +source [find interface/xds110.cfg] + +transport select jtag + +# default JTAG configuration has only SRST and no TRST +reset_config srst_only srst_push_pull + +# delay after SRST goes inactive +adapter srst delay 20 + +if { ![info exists SOC] } { + set SOC j721e +} + +source [find target/ti_k3.cfg] + +adapter speed 2500 From fe09811ea4d34c2ed50a38a956facf45be197214 Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Sun, 29 Nov 2020 21:01:24 -0600 Subject: [PATCH 043/120] tcl/board: Add J7200 EVM basic support Add basic connection details with J7200 EVM Change-Id: Ia8fa5033a693ac09849d33693c81b8cb206f17c1 Signed-off-by: Nishanth Menon Reviewed-on: http://openocd.zylin.com/5951 Reviewed-by: Antonio Borneo Tested-by: jenkins --- tcl/board/ti_j7200evm.cfg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tcl/board/ti_j7200evm.cfg diff --git a/tcl/board/ti_j7200evm.cfg b/tcl/board/ti_j7200evm.cfg new file mode 100644 index 000000000..cc70056fb --- /dev/null +++ b/tcl/board/ti_j7200evm.cfg @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/ +# +# Texas Instruments J7200 EVM +# + +# J7200 EVM has an xds110 onboard. +source [find interface/xds110.cfg] + +transport select jtag + +# default JTAG configuration has only SRST and no TRST +reset_config srst_only srst_push_pull + +# delay after SRST goes inactive +adapter srst delay 20 + +if { ![info exists SOC] } { + set SOC j7200 +} + +source [find target/ti_k3.cfg] + +adapter speed 2500 From 7e16194828a38382d4cf80604cd547b884f4ad97 Mon Sep 17 00:00:00 2001 From: Nishanth Menon Date: Mon, 30 Nov 2020 08:18:32 -0600 Subject: [PATCH 044/120] tcl/board: Add AM642 EVM basic support Add basic connection details with AM642 EVM Change-Id: I95dcf6afadb61bfd8456b79274eae863b834167d Signed-off-by: Nishanth Menon Reviewed-on: http://openocd.zylin.com/5952 Reviewed-by: Antonio Borneo Reviewed-by: Vignesh Raghavendra Tested-by: jenkins --- tcl/board/ti_am642evm.cfg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tcl/board/ti_am642evm.cfg diff --git a/tcl/board/ti_am642evm.cfg b/tcl/board/ti_am642evm.cfg new file mode 100644 index 000000000..e97fdcf13 --- /dev/null +++ b/tcl/board/ti_am642evm.cfg @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (C) 2019-2021 Texas Instruments Incorporated - http://www.ti.com/ +# +# Texas Instruments AM642 EVM +# + +# AM642 EVM has an xds110 onboard. +source [find interface/xds110.cfg] + +transport select jtag + +# default JTAG configuration has only SRST and no TRST +reset_config srst_only srst_push_pull + +# delay after SRST goes inactive +adapter srst delay 20 + +if { ![info exists SOC] } { + set SOC am642 +} + +source [find target/ti_k3.cfg] + +adapter speed 250 From cc9e3c2f7b04ba6da7e3b69161d78896c58503bd Mon Sep 17 00:00:00 2001 From: Anthony Ferranti Date: Wed, 1 Apr 2020 15:46:30 -0400 Subject: [PATCH 045/120] eMAG: Add Ampere eMAG config files Add board and target configuration files for Ampere eMAG8180 board and Ampere eMAG processor. Tested on an Ampere eMAG8180 development platform. Change-Id: I222653f0fc12d25202a7e469db3594076cbc38ed Signed-off-by: Anthony Ferranti Signed-off-by: Daniel Goehring Reviewed-on: http://openocd.zylin.com/5569 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/board/ampere_emag8180.cfg | 38 ++++++++++++ tcl/target/ampere_emag.cfg | 112 ++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) create mode 100644 tcl/board/ampere_emag8180.cfg create mode 100644 tcl/target/ampere_emag.cfg diff --git a/tcl/board/ampere_emag8180.cfg b/tcl/board/ampere_emag8180.cfg new file mode 100644 index 000000000..a122e0288 --- /dev/null +++ b/tcl/board/ampere_emag8180.cfg @@ -0,0 +1,38 @@ +# +# OpenOCD Board Configuration for eMAG Development Platform +# +# Copyright (c) 2019-2021, Ampere Computing LLC +# +# This program 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 program 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; +# +# + +# +# Configure JTAG speed +# + +adapter speed 2000 + +# +# Configure Resets +# + +jtag_ntrst_delay 100 +reset_config trst_only + +# +# Configure Targets +# + +source [find target/ampere_emag.cfg] diff --git a/tcl/target/ampere_emag.cfg b/tcl/target/ampere_emag.cfg new file mode 100644 index 000000000..7115a839d --- /dev/null +++ b/tcl/target/ampere_emag.cfg @@ -0,0 +1,112 @@ +# +# OpenOCD Target Configuration for eMAG ARMv8 Processor +# +# Copyright (c) 2019-2021, Ampere Computing LLC +# +# This program 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 program 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; +# +# + +# +# Configure defaults for target +# Can be overriden in board configuration file +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME emag +} + +if { [info exists NUMCORES] } { + set _NUMCORES $NUMCORES +} else { + set _NUMCORES 32 +} + +if { [info exists ENDIAN] } { + set _ENDIAN $ENDIAN +} else { + set _ENDIAN little +} + +if { [info exists CPUTAPID ] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x4BA00477 +} + +# +# Configure JTAG TAP +# + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0x3 -expected-id $_CPUTAPID +set _TAPNAME $_CHIPNAME.cpu + +set _DAPNAME ${_TAPNAME}_dap +set _APNUM 1 +dap create $_DAPNAME -chain-position $_TAPNAME +$_DAPNAME apsel $_APNUM + +# Create the DAP AP0 MEM-AP AHB-AP target +target create AHB mem_ap -endian $_ENDIAN -dap $_DAPNAME -ap-num 0 + +# Create the DAP AP1 MEM-AP APB-AP target +target create APB mem_ap -endian $_ENDIAN -dap $_DAPNAME -ap-num 1 + +# +# Configure target CPUs +# + +# Build string used to enable smp mode +set _SMP_STR "target smp" + +for {set _i 0} {$_i < $_NUMCORES} {incr _i} { + # Format a string to reference which CPU target to use + set _TARGETNAME [format "${_TAPNAME}_%02d" $_i] + + # Create and configure Cross Trigger Interface (CTI) - required for halt and resume + set _CTINAME $_TARGETNAME.cti + cti create $_CTINAME -dap $_DAPNAME -ap-num $_APNUM -baseaddr [expr 0xFC020000 + ($_i << 20)] + + # Create the target + target create $_TARGETNAME aarch64 -endian $_ENDIAN -dap $_DAPNAME -ap-num $_APNUM -cti $_CTINAME -coreid $_i + set _SMP_STR "$_SMP_STR $_TARGETNAME" + + # Clear CTI output/input enables that are not configured by OpenOCD for aarch64 + $_TARGETNAME configure -event examine-start [subst { + $_CTINAME write INEN0 0x00000000 + $_CTINAME write INEN1 0x00000000 + $_CTINAME write INEN2 0x00000000 + $_CTINAME write INEN3 0x00000000 + $_CTINAME write INEN4 0x00000000 + $_CTINAME write INEN5 0x00000000 + $_CTINAME write INEN6 0x00000000 + $_CTINAME write INEN7 0x00000000 + $_CTINAME write INEN8 0x00000000 + + $_CTINAME write OUTEN2 0x00000000 + $_CTINAME write OUTEN3 0x00000000 + $_CTINAME write OUTEN4 0x00000000 + $_CTINAME write OUTEN5 0x00000000 + $_CTINAME write OUTEN6 0x00000000 + $_CTINAME write OUTEN7 0x00000000 + $_CTINAME write OUTEN8 0x00000000 + }] + + # Enable OpenOCD HWTHREAD RTOS feature for GDB thread (CPU) selection support + # This feature presents CPU cores ("hardware threads") in an SMP system as threads to GDB + $_TARGETNAME configure -rtos hwthread +} +eval $_SMP_STR From 75d512bb973c1397a1f100626d44835274b216ea Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sun, 24 May 2020 17:55:44 +0100 Subject: [PATCH 046/120] stlink: separate stlink core from USB functions the introduced stlink_backend_s struct provides an API to separate USB internals from stlink core. this separation aims to ease: - stlink-server integration [1] - stlink driver split into modules: - stlink_core - stlink_usb - stlink_tcp [1] [1] refer to http://openocd.zylin.com/#/c/5633/ Change-Id: Iff6790942612ce1769ec4c75990914534e5e9e24 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5632 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/jtag/drivers/stlink_usb.c | 203 +++++++++++++++++++++++----------- 1 file changed, 141 insertions(+), 62 deletions(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 4545bcba0..6224070cb 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -1,4 +1,7 @@ /*************************************************************************** + * Copyright (C) 2020 by Tarek Bochkati * + * Tarek Bochkati * + * * * SWIM contributions by Ake Rehnman * * Copyright (C) 2017 Ake Rehnman * * ake.rehnman(at)gmail.com * @@ -119,12 +122,32 @@ struct stlink_usb_version { uint32_t flags; }; -/** */ -struct stlink_usb_handle_s { +struct stlink_usb_priv_s { /** */ struct libusb_device_handle *fd; /** */ struct libusb_transfer *trans; +}; + +struct stlink_backend_s { + /** */ + int (*open)(void *handle, struct hl_interface_param_s *param); + /** */ + int (*close)(void *handle); + /** */ + int (*xfer_noerrcheck)(void *handle, const uint8_t *buf, int size); + /** */ + int (*read_trace)(void *handle, const uint8_t *buf, int size); +}; + +/** */ +struct stlink_usb_handle_s { + /** */ + struct stlink_backend_s *backend; + /** */ + union { + struct stlink_usb_priv_s usb_backend_priv; + }; /** */ uint8_t rx_ep; /** */ @@ -161,6 +184,26 @@ struct stlink_usb_handle_s { bool reconnect_pending; }; +/** */ +static inline int stlink_usb_open(void *handle, struct hl_interface_param_s *param) +{ + struct stlink_usb_handle_s *h = handle; + return h->backend->open(handle, param); +} + +/** */ +static inline int stlink_usb_close(void *handle) +{ + struct stlink_usb_handle_s *h = handle; + return h->backend->close(handle); +} +/** */ +static inline int stlink_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int size) +{ + struct stlink_usb_handle_s *h = handle; + return h->backend->xfer_noerrcheck(handle, buf, size); +} + #define STLINK_SWIM_ERR_OK 0x00 #define STLINK_SWIM_BUSY 0x01 #define STLINK_DEBUG_ERR_OK 0x80 @@ -380,8 +423,6 @@ static unsigned int stlink_usb_block(void *handle) return STLINK_MAX_RW8; } - - #ifdef USE_LIBUSB_ASYNCIO static LIBUSB_CALL void sync_transfer_cb(struct libusb_transfer *transfer) @@ -545,7 +586,7 @@ static int stlink_usb_xfer_v1_get_status(void *handle) /* read status */ memset(h->cmdbuf, 0, STLINK_SG_SIZE); - ret = jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)h->cmdbuf, 13, + ret = jtag_libusb_bulk_read(h->usb_backend_priv.fd, h->rx_ep, (char *)h->cmdbuf, 13, STLINK_READ_TIMEOUT, &tr); if (ret || tr != 13) return ERROR_FAIL; @@ -602,7 +643,7 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int } return jtag_libusb_bulk_transfer_n( - h->fd, + h->usb_backend_priv.fd, transfers, n_transfers, STLINK_WRITE_TIMEOUT); @@ -615,20 +656,20 @@ static int stlink_usb_xfer_rw(void *handle, int cmdsize, const uint8_t *buf, int assert(handle != NULL); - ret = jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)h->cmdbuf, + ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)h->cmdbuf, cmdsize, STLINK_WRITE_TIMEOUT, &tr); if (ret || tr != cmdsize) return ERROR_FAIL; if (h->direction == h->tx_ep && size) { - ret = jtag_libusb_bulk_write(h->fd, h->tx_ep, (char *)buf, + ret = jtag_libusb_bulk_write(h->usb_backend_priv.fd, h->tx_ep, (char *)buf, size, STLINK_WRITE_TIMEOUT, &tr); if (ret || tr != size) { LOG_DEBUG("bulk write failed"); return ERROR_FAIL; } } else if (h->direction == h->rx_ep && size) { - ret = jtag_libusb_bulk_read(h->fd, h->rx_ep, (char *)buf, + ret = jtag_libusb_bulk_read(h->usb_backend_priv.fd, h->rx_ep, (char *)buf, size, STLINK_READ_TIMEOUT, &tr); if (ret || tr != size) { LOG_DEBUG("bulk read failed"); @@ -667,13 +708,29 @@ static int stlink_usb_xfer_v1_get_sense(void *handle) return ERROR_OK; } +/** */ +static int stlink_usb_usb_read_trace(void *handle, const uint8_t *buf, int size) +{ + struct stlink_usb_handle_s *h = handle; + int tr, ret; + + ret = jtag_libusb_bulk_read(h->usb_backend_priv.fd, h->trace_ep, (char *)buf, size, + STLINK_READ_TIMEOUT, &tr); + if (ret || tr != size) { + LOG_ERROR("bulk trace read failed"); + return ERROR_FAIL; + } + + return ERROR_OK; +} + /* transfers block in cmdbuf indicates number of bytes in the following data phase. Ignore the (eventual) error code in the received packet. */ -static int stlink_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int size) +static int stlink_usb_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int size) { int err, cmdsize = STLINK_CMD_SIZE_V2; struct stlink_usb_handle_s *h = handle; @@ -852,20 +909,12 @@ static int stlink_cmd_allow_retry(void *handle, const uint8_t *buf, int size) static int stlink_usb_read_trace(void *handle, const uint8_t *buf, int size) { struct stlink_usb_handle_s *h = handle; - int tr, ret; assert(handle != NULL); assert(h->version.flags & STLINK_F_HAS_TRACE); - ret = jtag_libusb_bulk_read(h->fd, h->trace_ep, (char *)buf, size, - STLINK_READ_TIMEOUT, &tr); - if (ret || tr != size) { - LOG_ERROR("bulk trace read failed"); - return ERROR_FAIL; - } - - return ERROR_OK; + return h->backend->read_trace(handle, buf, size); } /* @@ -2715,18 +2764,30 @@ static int stlink_speed(void *handle, int khz, bool query) } /** */ -static int stlink_usb_close(void *handle) +static int stlink_usb_usb_close(void *handle) { struct stlink_usb_handle_s *h = handle; - if (h && h->fd) { + if (h && h->usb_backend_priv.fd) { stlink_usb_exit_mode(h); /* do not check return code, it prevent us from closing jtag_libusb */ - jtag_libusb_close(h->fd); + jtag_libusb_close(h->usb_backend_priv.fd); } - free(h); + return ERROR_OK; +} + +/** */ +static int stlink_close(void *handle) +{ + if (handle != NULL) { + struct stlink_usb_handle_s *h = handle; + + stlink_usb_close(handle); + + free(h); + } return ERROR_OK; } @@ -2811,27 +2872,10 @@ static char *stlink_usb_get_alternate_serial(libusb_device_handle *device, } /** */ -static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode mode, void **fd) +static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param) { + struct stlink_usb_handle_s *h = handle; int err, retry_count = 1; - struct stlink_usb_handle_s *h; - - LOG_DEBUG("stlink_usb_open"); - - h = calloc(1, sizeof(struct stlink_usb_handle_s)); - - if (h == 0) { - LOG_DEBUG("malloc failed"); - return ERROR_FAIL; - } - - h->st_mode = mode; - - for (unsigned i = 0; param->vid[i]; i++) { - LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", - h->st_mode, param->vid[i], param->pid[i], - param->serial ? param->serial : ""); - } /* On certain host USB configurations(e.g. MacBook Air) @@ -2844,25 +2888,25 @@ static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode */ do { if (jtag_libusb_open(param->vid, param->pid, param->serial, - &h->fd, stlink_usb_get_alternate_serial) != ERROR_OK) { + &h->usb_backend_priv.fd, stlink_usb_get_alternate_serial) != ERROR_OK) { LOG_ERROR("open failed"); - goto error_open; + return ERROR_FAIL; } - jtag_libusb_set_configuration(h->fd, 0); + jtag_libusb_set_configuration(h->usb_backend_priv.fd, 0); - if (libusb_claim_interface(h->fd, 0) != ERROR_OK) { + if (libusb_claim_interface(h->usb_backend_priv.fd, 0) != ERROR_OK) { LOG_DEBUG("claim interface failed"); - goto error_open; + return ERROR_FAIL; } /* RX EP is common for all versions */ h->rx_ep = STLINK_RX_EP; uint16_t pid; - if (jtag_libusb_get_pid(libusb_get_device(h->fd), &pid) != ERROR_OK) { + if (jtag_libusb_get_pid(libusb_get_device(h->usb_backend_priv.fd), &pid) != ERROR_OK) { LOG_DEBUG("libusb_get_pid failed"); - goto error_open; + return ERROR_FAIL; } /* wrap version for first read */ @@ -2902,21 +2946,21 @@ static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode } else if (h->version.stlink == 1 || retry_count == 0) { LOG_ERROR("read version failed"); - goto error_open; + return ERROR_FAIL; } else { - err = libusb_release_interface(h->fd, 0); + err = libusb_release_interface(h->usb_backend_priv.fd, 0); if (err != ERROR_OK) { LOG_ERROR("release interface failed"); - goto error_open; + return ERROR_FAIL; } - err = libusb_reset_device(h->fd); + err = libusb_reset_device(h->usb_backend_priv.fd); if (err != ERROR_OK) { LOG_ERROR("reset device failed"); - goto error_open; + return ERROR_FAIL; } - jtag_libusb_close(h->fd); + jtag_libusb_close(h->usb_backend_priv.fd); /* Give the device one second to settle down and reenumerate. @@ -2926,8 +2970,44 @@ static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode } } while (1); + return ERROR_OK; +} + +static struct stlink_backend_s stlink_usb_backend = { + .open = stlink_usb_usb_open, + .close = stlink_usb_usb_close, + .xfer_noerrcheck = stlink_usb_usb_xfer_noerrcheck, + .read_trace = stlink_usb_usb_read_trace, +}; + +static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode, void **fd) +{ + struct stlink_usb_handle_s *h; + + LOG_DEBUG("stlink_open"); + + h = calloc(1, sizeof(struct stlink_usb_handle_s)); + + if (h == 0) { + LOG_DEBUG("malloc failed"); + return ERROR_FAIL; + } + + h->st_mode = mode; + + for (unsigned i = 0; param->vid[i]; i++) { + LOG_DEBUG("transport: %d vid: 0x%04x pid: 0x%04x serial: %s", + h->st_mode, param->vid[i], param->pid[i], + param->serial ? param->serial : ""); + } + + h->backend = &stlink_usb_backend; + + if (stlink_usb_open(h, param) != ERROR_OK) + goto error_open; + /* check if mode is supported */ - err = ERROR_OK; + int err = ERROR_OK; switch (h->st_mode) { case STLINK_MODE_DEBUG_SWD: @@ -2994,14 +3074,13 @@ static int stlink_usb_open(struct hl_interface_param_s *param, enum stlink_mode return ERROR_OK; error_open: - stlink_usb_close(h); - + stlink_close(h); return ERROR_FAIL; } static int stlink_usb_hl_open(struct hl_interface_param_s *param, void **fd) { - return stlink_usb_open(param, stlink_get_mode(param->transport), fd); + return stlink_open(param, stlink_get_mode(param->transport), fd); } static int stlink_config_trace(void *handle, bool enabled, @@ -3151,7 +3230,7 @@ struct hl_layout_api_s stlink_usb_layout_api = { /** */ .open = stlink_usb_hl_open, /** */ - .close = stlink_usb_close, + .close = stlink_close, /** */ .idcode = stlink_usb_idcode, /** */ @@ -3728,7 +3807,7 @@ static int stlink_dap_init(void) return ERROR_FAIL; } - retval = stlink_usb_open(&stlink_dap_param, mode, (void **)&stlink_dap_handle); + retval = stlink_open(&stlink_dap_param, mode, (void **)&stlink_dap_handle); if (retval != ERROR_OK) return retval; @@ -3748,7 +3827,7 @@ static int stlink_dap_quit(void) free((void *)stlink_dap_param.serial); stlink_dap_param.serial = NULL; - return stlink_usb_close(stlink_dap_handle); + return stlink_close(stlink_dap_handle); } /** */ From 4c0c6ebf02bbeeb7f6c6811a512f68b0594277c0 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 12 Jan 2021 23:58:53 +0100 Subject: [PATCH 047/120] stlink: support of ST-LINK TCP server using stlink-dap and hla Quote: The ST-LINK TCP server is an application to share the debug interface of a single ST-LINK board among several host applications, typically a debugging tool and a monitoring tool. Note: ST-Link TCP server does not support the SWIM transport. ST-LINK TCP server allows several applications to connect to the same ST-Link through sockets (TCP). To use ST-LINK TCP server: - using stlink-dap : use 'st-link backend tcp [port]' - using hla : use 'hla_stlink_backend tcp [port]' the default port value is 7184 Change-Id: I9b79f65267f04b1e978709934892160e65bd2d6d Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5633 Tested-by: jenkins Reviewed-by: Antonio Borneo --- doc/openocd.texi | 20 ++ src/jtag/drivers/stlink_usb.c | 507 ++++++++++++++++++++++++++++++++-- src/jtag/hla/hla_interface.c | 34 ++- src/jtag/hla/hla_interface.h | 4 + 4 files changed, 546 insertions(+), 19 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index a5b94362f..34f1bb653 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -3126,6 +3126,15 @@ Specifies the adapter layout to use. Pairs of vendor IDs and product IDs of the device. @end deffn +@deffn {Config Command} {hla_stlink_backend} (usb | tcp [port]) +@emph{ST-Link only:} Choose between 'exclusive' USB communication (the default backend) or +'shared' mode using ST-Link TCP server (the default port is 7184). + +@emph{Note:} ST-Link TCP server is a binary application provided by ST +available from @url{https://www.st.com/en/development-tools/st-link-server.html, +ST-LINK server software module}. +@end deffn + @deffn {Command} {hla_command} command Execute a custom adapter-specific command. The @var{command} string is passed as is to the underlying adapter layout handler. @@ -3146,6 +3155,17 @@ An error is returned for any AP number above the maximum allowed value. @emph{Note:} Either these same adapters and their older versions are also supported by @ref{hla_interface, the hla interface driver}. +@deffn {Config Command} {st-link backend} (usb | tcp [port]) +Choose between 'exclusive' USB communication (the default backend) or +'shared' mode using ST-Link TCP server (the default port is 7184). + +@emph{Note:} ST-Link TCP server is a binary application provided by ST +available from @url{https://www.st.com/en/development-tools/st-link-server.html, +ST-LINK server software module}. + +@emph{Note:} ST-Link TCP server does not support the SWIM transport. +@end deffn + @deffn {Config Command} {st-link serial} serial Specifies the serial number of the adapter. @end deffn diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 6224070cb..813af5578 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -45,6 +45,16 @@ #include +#include + +#ifdef HAVE_ARPA_INET_H +#include +#endif + +#ifdef HAVE_NETINET_TCP_H +#include +#endif + #include "libusb_helper.h" #ifdef HAVE_LIBUSB1 @@ -129,6 +139,21 @@ struct stlink_usb_priv_s { struct libusb_transfer *trans; }; +struct stlink_tcp_priv_s { + /** */ + int fd; + /** */ + bool connected; + /** */ + uint32_t device_id; + /** */ + uint32_t connect_id; + /** */ + uint8_t *send_buf; + /** */ + uint8_t *recv_buf; +}; + struct stlink_backend_s { /** */ int (*open)(void *handle, struct hl_interface_param_s *param); @@ -147,6 +172,7 @@ struct stlink_usb_handle_s { /** */ union { struct stlink_usb_priv_s usb_backend_priv; + struct stlink_tcp_priv_s tcp_backend_priv; }; /** */ uint8_t rx_ep; @@ -155,13 +181,13 @@ struct stlink_usb_handle_s { /** */ uint8_t trace_ep; /** */ - uint8_t cmdbuf[STLINK_SG_SIZE]; + uint8_t *cmdbuf; /** */ uint8_t cmdidx; /** */ uint8_t direction; /** */ - uint8_t databuf[STLINK_DATA_SIZE]; + uint8_t *databuf; /** */ uint32_t max_mem_packet; /** */ @@ -349,6 +375,39 @@ static inline int stlink_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, i #define REQUEST_SENSE 0x03 #define REQUEST_SENSE_LENGTH 18 +/* STLINK TCP commands */ +#define STLINK_TCP_CMD_REFRESH_DEVICE_LIST 0x00 +#define STLINK_TCP_CMD_GET_NB_DEV 0x01 +#define STLINK_TCP_CMD_GET_DEV_INFO 0x02 +#define STLINK_TCP_CMD_OPEN_DEV 0x03 +#define STLINK_TCP_CMD_CLOSE_DEV 0x04 +#define STLINK_TCP_CMD_SEND_USB_CMD 0x05 +#define STLINK_TCP_CMD_GET_SERVER_VERSION 0x06 +#define STLINK_TCP_CMD_GET_NB_OF_DEV_CLIENTS 0x07 + +/* STLINK TCP constants */ +#define OPENOCD_STLINK_TCP_API_VERSION 1 +#define STLINK_TCP_REQUEST_WRITE 0 +#define STLINK_TCP_REQUEST_READ 1 +#define STLINK_TCP_REQUEST_READ_SWO 3 +#define STLINK_TCP_SS_SIZE 4 +#define STLINK_TCP_USB_CMD_SIZE 32 +#define STLINK_TCP_SERIAL_SIZE 32 +#define STLINK_TCP_SEND_BUFFER_SIZE 10240 +#define STLINK_TCP_RECV_BUFFER_SIZE 10240 + +/* STLINK TCP command status */ +#define STLINK_TCP_SS_OK 0x00000001 +#define STLINK_TCP_SS_MEMORY_PROBLEM 0x00001000 +#define STLINK_TCP_SS_TIMEOUT 0x00001001 +#define STLINK_TCP_SS_BAD_PARAMETER 0x00001002 +#define STLINK_TCP_SS_OPEN_ERR 0x00001003 +#define STLINK_TCP_SS_TRUNCATED_DATA 0x00001052 +#define STLINK_TCP_SS_CMD_NOT_AVAILABLE 0x00001053 +#define STLINK_TCP_SS_TCP_ERROR 0x00002001 +#define STLINK_TCP_SS_TCP_CANT_CONNECT 0x00002002 +#define STLINK_TCP_SS_WIN32_ERROR 0x00010000 + /* * Map the relevant features, quirks and workaround for specific firmware * version of stlink @@ -763,6 +822,117 @@ static int stlink_usb_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int return ERROR_OK; } + +static int stlink_tcp_send_cmd(void *handle, int send_size, int recv_size, bool check_tcp_status) +{ + struct stlink_usb_handle_s *h = handle; + + assert(handle != NULL); + + /* send the TCP command */ + int sent_size = send(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.send_buf, send_size, 0); + if (sent_size != send_size) { + LOG_ERROR("failed to send USB CMD"); + if (sent_size == -1) + LOG_DEBUG("socket send error: %s (errno %d)", strerror(errno), errno); + else + LOG_DEBUG("sent size %d (expected %d)", sent_size, send_size); + return ERROR_FAIL; + } + + keep_alive(); + + /* read the TCP response */ + int received_size = recv(h->tcp_backend_priv.fd, (void *)h->tcp_backend_priv.recv_buf, recv_size, 0); + if (received_size != recv_size) { + LOG_ERROR("failed to receive USB CMD response"); + if (received_size == -1) + LOG_DEBUG("socket recv error: %s (errno %d)", strerror(errno), errno); + else + LOG_DEBUG("received size %d (expected %d)", received_size, recv_size); + return ERROR_FAIL; + } + + if (check_tcp_status) { + uint32_t tcp_ss = le_to_h_u32(h->tcp_backend_priv.recv_buf); + if (tcp_ss != STLINK_TCP_SS_OK) { + LOG_ERROR("TCP error status 0x%X", tcp_ss); + return ERROR_FAIL; + } + } + + return ERROR_OK; +} + +/** */ +static int stlink_tcp_xfer_noerrcheck(void *handle, const uint8_t *buf, int size) +{ + struct stlink_usb_handle_s *h = handle; + + int send_size = STLINK_TCP_USB_CMD_SIZE; + int recv_size = STLINK_TCP_SS_SIZE; + + assert(handle != NULL); + + /* prepare the TCP command */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_SEND_USB_CMD; + memset(&h->tcp_backend_priv.send_buf[1], 0, 3); /* reserved for alignment and future use, must be zero */ + h_u32_to_le(&h->tcp_backend_priv.send_buf[4], h->tcp_backend_priv.connect_id); + /* tcp_backend_priv.send_buf[8..23] already contains the constructed stlink command */ + h->tcp_backend_priv.send_buf[24] = h->direction; + memset(&h->tcp_backend_priv.send_buf[25], 0, 3); /* reserved for alignment and future use, must be zero */ + + h_u32_to_le(&h->tcp_backend_priv.send_buf[28], size); + + /* + * if the xfer is a write request (tx_ep) + * > then buf content will be copied + * into &cmdbuf[32]. + * else : the xfer is a read or trace read request (rx_ep or trace_ep) + * > the buf content will be filled from &databuf[4]. + * + * note : if h->direction is trace_ep, h->cmdbuf is zeros. + */ + + if (h->direction == h->tx_ep) { /* STLINK_TCP_REQUEST_WRITE */ + send_size += size; + if (send_size > STLINK_TCP_SEND_BUFFER_SIZE) { + LOG_ERROR("STLINK_TCP command buffer overflow"); + return ERROR_FAIL; + } + memcpy(&h->tcp_backend_priv.send_buf[32], buf, size); + } else { /* STLINK_TCP_REQUEST_READ or STLINK_TCP_REQUEST_READ_SWO */ + recv_size += size; + if (recv_size > STLINK_TCP_RECV_BUFFER_SIZE) { + LOG_ERROR("STLINK_TCP data buffer overflow"); + return ERROR_FAIL; + } + } + + int ret = stlink_tcp_send_cmd(h, send_size, recv_size, true); + if (ret != ERROR_OK) + return ret; + + if (h->direction != h->tx_ep) { + /* the read data is located in tcp_backend_priv.recv_buf[4] */ + /* most of the case it will be copying the data from tcp_backend_priv.recv_buf[4] + * to handle->cmd_buff which are the same, so let's avoid unnecessary copying */ + if (buf != &h->tcp_backend_priv.recv_buf[4]) + memcpy((uint8_t *)buf, &h->tcp_backend_priv.recv_buf[4], size); + } + + return ERROR_OK; +} + +/** */ +static int stlink_tcp_read_trace(void *handle, const uint8_t *buf, int size) +{ + struct stlink_usb_handle_s *h = handle; + + stlink_usb_init_buffer(h, h->trace_ep, 0); + return stlink_tcp_xfer_noerrcheck(handle, buf, size); +} + /** Converts an STLINK status code held in the first byte of a response to an openocd error, logs any error/wait status as debug output. @@ -2768,16 +2938,54 @@ static int stlink_usb_usb_close(void *handle) { struct stlink_usb_handle_s *h = handle; - if (h && h->usb_backend_priv.fd) { + if (!h) + return ERROR_OK; + + if (h->usb_backend_priv.fd) { stlink_usb_exit_mode(h); /* do not check return code, it prevent us from closing jtag_libusb */ jtag_libusb_close(h->usb_backend_priv.fd); } + free(h->cmdbuf); + free(h->databuf); + return ERROR_OK; } +/** */ +static int stlink_tcp_close(void *handle) +{ + struct stlink_usb_handle_s *h = handle; + + if (!h) + return ERROR_OK; + + int ret = ERROR_OK; + if (h->tcp_backend_priv.connected) { + if (h->tcp_backend_priv.connect_id) { + stlink_usb_exit_mode(h); + + /* close the stlink */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_CLOSE_DEV; + memset(&h->tcp_backend_priv.send_buf[1], 0, 4); /* reserved */ + h_u32_to_le(&h->tcp_backend_priv.send_buf[4], h->tcp_backend_priv.connect_id); + ret = stlink_tcp_send_cmd(h, 8, 4, true); + if (ret != ERROR_OK) + LOG_ERROR("cannot close the STLINK"); + } + + if (close_socket(h->tcp_backend_priv.fd) != 0) + LOG_ERROR("error closing the socket, errno: %s", strerror(errno)); + } + + free(h->tcp_backend_priv.send_buf); + free(h->tcp_backend_priv.recv_buf); + + return ret; +} + /** */ static int stlink_close(void *handle) { @@ -2877,6 +3085,12 @@ static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param) struct stlink_usb_handle_s *h = handle; int err, retry_count = 1; + h->cmdbuf = malloc(STLINK_SG_SIZE); + h->databuf = malloc(STLINK_DATA_SIZE); + + if (h->cmdbuf == NULL || h->databuf == NULL) + return ERROR_FAIL; + /* On certain host USB configurations(e.g. MacBook Air) STLINKv2 dongle seems to have its FW in a funky state if, @@ -2973,6 +3187,217 @@ static int stlink_usb_usb_open(void *handle, struct hl_interface_param_s *param) return ERROR_OK; } +/** */ +static int stlink_tcp_open(void *handle, struct hl_interface_param_s *param) +{ + struct stlink_usb_handle_s *h = handle; + int ret; + + /* SWIM is not supported using stlink-server */ + if (h->st_mode == STLINK_MODE_DEBUG_SWIM) { + LOG_ERROR("stlink-server does not support SWIM mode"); + return ERROR_FAIL; + } + + h->tcp_backend_priv.send_buf = malloc(STLINK_TCP_SEND_BUFFER_SIZE); + h->tcp_backend_priv.recv_buf = malloc(STLINK_TCP_RECV_BUFFER_SIZE); + + if (h->tcp_backend_priv.send_buf == NULL || h->tcp_backend_priv.recv_buf == NULL) + return ERROR_FAIL; + + h->cmdbuf = &h->tcp_backend_priv.send_buf[8]; + h->databuf = &h->tcp_backend_priv.recv_buf[4]; + + /* configure directions */ + h->rx_ep = STLINK_TCP_REQUEST_READ; + h->tx_ep = STLINK_TCP_REQUEST_WRITE; + h->trace_ep = STLINK_TCP_REQUEST_READ_SWO; + + h->tcp_backend_priv.fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + h->tcp_backend_priv.connected = false; + h->tcp_backend_priv.device_id = 0; + h->tcp_backend_priv.connect_id = 0; + + if (h->tcp_backend_priv.fd == -1) { + LOG_ERROR("error creating the socket, errno: %s", strerror(errno)); + return ERROR_FAIL; + } + + struct sockaddr_in serv; + memset(&serv, 0, sizeof(struct sockaddr_in)); + serv.sin_family = AF_INET; + serv.sin_port = htons(param->stlink_tcp_port); + serv.sin_addr.s_addr = inet_addr("127.0.0.1"); + + LOG_DEBUG("socket : %x", h->tcp_backend_priv.fd); + + int optval = 1; + if (setsockopt(h->tcp_backend_priv.fd, IPPROTO_TCP, TCP_NODELAY, (const void *)&optval, sizeof(int)) == -1) { + LOG_ERROR("cannot set sock option 'TCP_NODELAY', errno: %s", strerror(errno)); + return ERROR_FAIL; + } + + optval = STLINK_TCP_RECV_BUFFER_SIZE; + if (setsockopt(h->tcp_backend_priv.fd, SOL_SOCKET, SO_RCVBUF, (const void *)&optval, sizeof(int)) == -1) { + LOG_ERROR("cannot set sock option 'SO_RCVBUF', errno: %s", strerror(errno)); + return ERROR_FAIL; + } + + optval = STLINK_TCP_SEND_BUFFER_SIZE; + if (setsockopt(h->tcp_backend_priv.fd, SOL_SOCKET, SO_SNDBUF, (const void *)&optval, sizeof(int)) == -1) { + LOG_ERROR("cannot set sock option 'SO_SNDBUF', errno: %s", strerror(errno)); + return ERROR_FAIL; + } + + if (connect(h->tcp_backend_priv.fd, (const struct sockaddr *)&serv, sizeof(serv)) == -1) { + LOG_ERROR("cannot connect to stlink server, errno: %s", strerror(errno)); + return ERROR_FAIL; + } + + h->tcp_backend_priv.connected = true; + + LOG_INFO("connected to stlink-server"); + + /* print stlink-server version */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_GET_SERVER_VERSION; + h->tcp_backend_priv.send_buf[1] = OPENOCD_STLINK_TCP_API_VERSION; + memset(&h->tcp_backend_priv.send_buf[2], 0, 2); /* reserved */ + ret = stlink_tcp_send_cmd(h, 4, 16, false); + if (ret != ERROR_OK) { + LOG_ERROR("cannot get the stlink-server version"); + return ERROR_FAIL; + } + + uint32_t api_ver = le_to_h_u32(&h->tcp_backend_priv.recv_buf[0]); + uint32_t ver_major = le_to_h_u32(&h->tcp_backend_priv.recv_buf[4]); + uint32_t ver_minor = le_to_h_u32(&h->tcp_backend_priv.recv_buf[8]); + uint32_t ver_build = le_to_h_u32(&h->tcp_backend_priv.recv_buf[12]); + LOG_INFO("stlink-server API v%d, version %d.%d.%d", + api_ver, ver_major, ver_minor, ver_build); + + /* in stlink-server API v1 sending more than 1428 bytes will cause stlink-server + * to crash in windows: select a safe default value (1K) */ + if (api_ver < 2) + h->max_mem_packet = (1 << 10); + + /* refresh stlink list (re-enumerate) */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_REFRESH_DEVICE_LIST; + h->tcp_backend_priv.send_buf[1] = 0; /* don't clear the list, just refresh it */ + ret = stlink_tcp_send_cmd(h, 2, 4, true); + if (ret != ERROR_OK) + return ret; + + /* get the number of connected stlinks */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_GET_NB_DEV; + ret = stlink_tcp_send_cmd(h, 1, 4, false); + if (ret != ERROR_OK) + return ret; + + uint32_t connected_stlinks = le_to_h_u32(h->tcp_backend_priv.recv_buf); + + if (connected_stlinks == 0) { + LOG_ERROR("no ST-LINK detected"); + return ERROR_FAIL; + } + + LOG_DEBUG("%d ST-LINK detected", connected_stlinks); + + if (connected_stlinks > 255) { + LOG_WARNING("STLink server cannot handle more than 255 ST-LINK connected"); + connected_stlinks = 255; + } + + /* list all connected ST-Link and seek for the requested vid:pid and serial */ + char serial[STLINK_TCP_SERIAL_SIZE + 1] = {0}; + uint8_t stlink_used; + bool stlink_id_matched = false; + bool stlink_serial_matched = (param->serial == NULL); + + for (uint32_t stlink_id = 0; stlink_id < connected_stlinks; stlink_id++) { + /* get the stlink info */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_GET_DEV_INFO; + h->tcp_backend_priv.send_buf[1] = (uint8_t)stlink_id; + memset(&h->tcp_backend_priv.send_buf[2], 0, 2); /* reserved */ + h_u32_to_le(&h->tcp_backend_priv.send_buf[4], 41); /* size of TDeviceInfo2 */ + ret = stlink_tcp_send_cmd(h, 8, 45, true); + if (ret != ERROR_OK) + return ret; + + h->tcp_backend_priv.device_id = le_to_h_u32(&h->tcp_backend_priv.recv_buf[4]); + memcpy(serial, &h->tcp_backend_priv.recv_buf[8], STLINK_TCP_SERIAL_SIZE); + h->vid = le_to_h_u16(&h->tcp_backend_priv.recv_buf[40]); + h->pid = le_to_h_u16(&h->tcp_backend_priv.recv_buf[42]); + stlink_used = h->tcp_backend_priv.recv_buf[44]; + + /* check the vid:pid */ + for (int i = 0; param->vid[i]; i++) { + if (param->vid[i] == h->vid && param->pid[i] == h->pid) { + stlink_id_matched = true; + break; + } + } + + if (!stlink_id_matched) + continue; + + /* check the serial if specified */ + if (param->serial) { + /* ST-Link server fixes the buggy serial returned by old ST-Link DFU + * for further details refer to stlink_usb_get_alternate_serial + * so if the user passes the buggy serial, we need to fix it before + * comparing with the serial returned by ST-Link server */ + if (strlen(param->serial) == STLINK_SERIAL_LEN / 2) { + char fixed_serial[STLINK_SERIAL_LEN + 1]; + + for (unsigned int i = 0; i < STLINK_SERIAL_LEN; i += 2) + sprintf(fixed_serial + i, "%02X", param->serial[i / 2]); + + fixed_serial[STLINK_SERIAL_LEN] = '\0'; + + stlink_serial_matched = strcmp(fixed_serial, serial) == 0; + } else + stlink_serial_matched = strcmp(param->serial, serial) == 0; + } + + if (!stlink_serial_matched) + LOG_DEBUG("Device serial number '%s' doesn't match requested serial '%s'", + serial, param->serial); + else /* exit the search loop if there is match */ + break; + } + + if (!stlink_id_matched) { + LOG_ERROR("ST-LINK open failed (vid/pid mismatch)"); + return ERROR_FAIL; + } + + if (!stlink_serial_matched) { + LOG_ERROR("ST-LINK open failed (serial mismatch)"); + return ERROR_FAIL; + } + + /* check if device is 'exclusively' used by another application */ + if (stlink_used) { + LOG_ERROR("the selected device is already used"); + return ERROR_FAIL; + } + + LOG_DEBUG("transport: vid: 0x%04x pid: 0x%04x serial: %s", h->vid, h->pid, serial); + + /* now let's open the stlink */ + h->tcp_backend_priv.send_buf[0] = STLINK_TCP_CMD_OPEN_DEV; + memset(&h->tcp_backend_priv.send_buf[1], 0, 4); /* reserved */ + h_u32_to_le(&h->tcp_backend_priv.send_buf[4], h->tcp_backend_priv.device_id); + ret = stlink_tcp_send_cmd(h, 8, 8, true); + if (ret != ERROR_OK) + return ret; + + h->tcp_backend_priv.connect_id = le_to_h_u32(&h->tcp_backend_priv.recv_buf[4]); + + /* get stlink version */ + return stlink_usb_version(h); +} + static struct stlink_backend_s stlink_usb_backend = { .open = stlink_usb_usb_open, .close = stlink_usb_usb_close, @@ -2980,6 +3405,13 @@ static struct stlink_backend_s stlink_usb_backend = { .read_trace = stlink_usb_usb_read_trace, }; +static struct stlink_backend_s stlink_tcp_backend = { + .open = stlink_tcp_open, + .close = stlink_tcp_close, + .xfer_noerrcheck = stlink_tcp_xfer_noerrcheck, + .read_trace = stlink_tcp_read_trace, +}; + static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode, void **fd) { struct stlink_usb_handle_s *h; @@ -3001,7 +3433,10 @@ static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode param->serial ? param->serial : ""); } - h->backend = &stlink_usb_backend; + if (param->use_stlink_tcp) + h->backend = &stlink_tcp_backend; + else + h->backend = &stlink_usb_backend; if (stlink_usb_open(h, param) != ERROR_OK) goto error_open; @@ -3051,23 +3486,26 @@ static int stlink_open(struct hl_interface_param_s *param, enum stlink_mode mode return ERROR_OK; } - /* get cpuid, so we can determine the max page size - * start with a safe default */ - h->max_mem_packet = (1 << 10); + /* set max_mem_packet if it was not set by the low-level interface */ + if (h->max_mem_packet == 0) { + /* get cpuid, so we can determine the max page size + * start with a safe default */ + h->max_mem_packet = (1 << 10); - uint8_t buffer[4]; - stlink_usb_open_ap(h, 0); - err = stlink_usb_read_mem32(h, CPUID, 4, buffer); - if (err == ERROR_OK) { - uint32_t cpuid = le_to_h_u32(buffer); - int i = (cpuid >> 4) & 0xf; - if (i == 4 || i == 3) { - /* Cortex-M3/M4 has 4096 bytes autoincrement range */ - h->max_mem_packet = (1 << 12); + uint8_t buffer[4]; + stlink_usb_open_ap(h, 0); + err = stlink_usb_read_mem32(h, CPUID, 4, buffer); + if (err == ERROR_OK) { + uint32_t cpuid = le_to_h_u32(buffer); + int i = (cpuid >> 4) & 0xf; + if (i == 4 || i == 3) { + /* Cortex-M3/M4 has 4096 bytes autoincrement range */ + h->max_mem_packet = (1 << 12); + } } - } - LOG_DEBUG("Using TAR autoincrement: %" PRIu32, h->max_mem_packet); + LOG_DEBUG("Using TAR autoincrement: %" PRIu32, h->max_mem_packet); + } *fd = h; @@ -3749,6 +4187,32 @@ COMMAND_HANDLER(stlink_dap_vid_pid) return ERROR_OK; } +/** */ +COMMAND_HANDLER(stlink_dap_backend_command) +{ + /* default values */ + bool use_stlink_tcp = false; + uint16_t stlink_tcp_port = 7184; + + if (CMD_ARGC == 0 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; + else if (strcmp(CMD_ARGV[0], "usb") == 0) { + if (CMD_ARGC > 1) + return ERROR_COMMAND_SYNTAX_ERROR; + /* else use_stlink_tcp = false (already the case ) */ + } else if (strcmp(CMD_ARGV[0], "tcp") == 0) { + use_stlink_tcp = true; + if (CMD_ARGC == 2) + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], stlink_tcp_port); + } else + return ERROR_COMMAND_SYNTAX_ERROR; + + stlink_dap_param.use_stlink_tcp = use_stlink_tcp; + stlink_dap_param.stlink_tcp_port = stlink_tcp_port; + + return ERROR_OK; +} + /** */ static const struct command_registration stlink_dap_subcommand_handlers[] = { { @@ -3765,6 +4229,13 @@ static const struct command_registration stlink_dap_subcommand_handlers[] = { .help = "USB VID and PID of the adapter", .usage = "(vid pid)+", }, + { + .name = "backend", + .handler = &stlink_dap_backend_command, + .mode = COMMAND_CONFIG, + .help = "select which ST-Link backend to use", + .usage = "usb | tcp [port]", + }, COMMAND_REGISTRATION_DONE }; diff --git a/src/jtag/hla/hla_interface.c b/src/jtag/hla/hla_interface.c index 6691a9a32..04e01d252 100644 --- a/src/jtag/hla/hla_interface.c +++ b/src/jtag/hla/hla_interface.c @@ -35,7 +35,7 @@ #include -static struct hl_interface_s hl_if = { {0, 0, { 0 }, { 0 }, HL_TRANSPORT_UNKNOWN, false, -1}, 0, 0 }; +static struct hl_interface_s hl_if = { {0, 0, { 0 }, { 0 }, HL_TRANSPORT_UNKNOWN, false, -1, false, 7184}, 0, 0 }; int hl_interface_open(enum hl_transports tr) { @@ -292,6 +292,31 @@ COMMAND_HANDLER(hl_interface_handle_vid_pid_command) return ERROR_OK; } +COMMAND_HANDLER(hl_interface_handle_stlink_backend_command) +{ + /* default values */ + bool use_stlink_tcp = false; + uint16_t stlink_tcp_port = 7184; + + if (CMD_ARGC == 0 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; + else if (strcmp(CMD_ARGV[0], "usb") == 0) { + if (CMD_ARGC > 1) + return ERROR_COMMAND_SYNTAX_ERROR; + /* else use_stlink_tcp = false (already the case ) */ + } else if (strcmp(CMD_ARGV[0], "tcp") == 0) { + use_stlink_tcp = true; + if (CMD_ARGC == 2) + COMMAND_PARSE_NUMBER(u16, CMD_ARGV[1], stlink_tcp_port); + } else + return ERROR_COMMAND_SYNTAX_ERROR; + + hl_if.param.use_stlink_tcp = use_stlink_tcp; + hl_if.param.stlink_tcp_port = stlink_tcp_port; + + return ERROR_OK; +} + COMMAND_HANDLER(interface_handle_hla_command) { if (CMD_ARGC != 1) @@ -336,6 +361,13 @@ static const struct command_registration hl_interface_command_handlers[] = { .help = "the vendor and product ID of the adapter", .usage = "(vid pid)* ", }, + { + .name = "hla_stlink_backend", + .handler = &hl_interface_handle_stlink_backend_command, + .mode = COMMAND_CONFIG, + .help = "select which ST-Link backend to use", + .usage = "usb | tcp [port]", + }, { .name = "hla_command", .handler = &interface_handle_hla_command, diff --git a/src/jtag/hla/hla_interface.h b/src/jtag/hla/hla_interface.h index b6e4a8b92..a1c95cde1 100644 --- a/src/jtag/hla/hla_interface.h +++ b/src/jtag/hla/hla_interface.h @@ -46,6 +46,10 @@ struct hl_interface_param_s { bool connect_under_reset; /** Initial interface clock clock speed */ int initial_interface_speed; + /** */ + bool use_stlink_tcp; + /** */ + uint16_t stlink_tcp_port; }; struct hl_interface_s { From 307fe3730f1e8e48f41501b7f631e95f9dfc2a0d Mon Sep 17 00:00:00 2001 From: Jiri Kastner Date: Fri, 1 Jan 2021 23:27:11 +0100 Subject: [PATCH 048/120] tcl/target: add Rockchip RK3399 target Change-Id: I28f404b1e53fc9dbb04b3f939294ae248bbde183 Signed-off-by: Jiri Kastner Reviewed-on: http://openocd.zylin.com/5994 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/target/rk3399.cfg | 79 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tcl/target/rk3399.cfg diff --git a/tcl/target/rk3399.cfg b/tcl/target/rk3399.cfg new file mode 100644 index 000000000..1e90414fd --- /dev/null +++ b/tcl/target/rk3399.cfg @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Rockchip RK3399 Target +# https://rockchip.fr/RK3399%20datasheet%20V1.8.pdf +# https://rockchip.fr/Rockchip%20RK3399%20TRM%20V1.4%20Part1.pdf + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME rk3399 +} + +# +# Main DAP +# +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x5ba02477 +} + +adapter speed 12000 + +transport select swd + +# declare the one SWD tap to access the DAP +swd newdap $_CHIPNAME cpu -expected-id $_DAP_TAPID -ignore-version + +# create the DAP +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 +set _TARGETNAME $_CHIPNAME.lcore +# declare the 6 main application cores +set _smp_command "" + +set $_TARGETNAME.base(0) 0x80030000 +set $_TARGETNAME.base(1) 0x80032000 +set $_TARGETNAME.base(2) 0x80034000 +set $_TARGETNAME.base(3) 0x80036000 +set $_TARGETNAME.cti(0) 0x80038000 +set $_TARGETNAME.cti(1) 0x80039000 +set $_TARGETNAME.cti(2) 0x8003a000 +set $_TARGETNAME.cti(3) 0x8003b000 + + +set _TARGETNAME $_CHIPNAME.bcore +set $_TARGETNAME.base(4) 0x80210000 +set $_TARGETNAME.base(5) 0x80310000 +set $_TARGETNAME.cti(4) 0x80220000 +set $_TARGETNAME.cti(5) 0x80320000 + +set _cores 6 +for { set _core 0 } { $_core < $_cores } { incr _core 1 } { + if {$_core < 4} { + set _TARGETNAME $_CHIPNAME.lcore + } else { + set _TARGETNAME $_CHIPNAME.bcore + } + + + cti create cti$_core -dap $_CHIPNAME.dap -baseaddr [set $_TARGETNAME.cti($_core)] -ap-num 1 + + target create ${_TARGETNAME}$_core aarch64 \ + -dap $_CHIPNAME.dap -coreid $_core -cti cti$_core \ + -dbgbase [set $_TARGETNAME.base($_core)] + + if { $_core != 0 } { + ${_TARGETNAME}$_core configure -defer-examine + } else { + # uncomment to use hardware threads pseudo rtos + # ${_TARGETNAME}$_core configure -rtos hwthread" + ${_TARGETNAME}$_core configure -work-area-size 0x30000 -work-area-phys 0xff8c0000 \ + -work-area-backup 0 + } + set _smp_command "$_smp_command ${_TARGETNAME}$_core" +} + +target smp $_smp_command + +targets rk3399.lcore0 From a8b88acd994f758a02a48e2f6fb372caff887e75 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 25 Jan 2021 11:28:59 +0100 Subject: [PATCH 049/120] rtos: Remove typedef'd struct The C style guide forbids typedef'd structs, see 'Naming Rules'. Change-Id: Ia7c8218fb61ff0c74b6dd0d10fb51a77cf059c14 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6028 Tested-by: jenkins Reviewed-by: Andreas Fritiofson Reviewed-by: Antonio Borneo --- src/rtos/FreeRTOS.c | 6 +++--- src/rtos/ThreadX.c | 6 +++--- src/rtos/chibios.c | 6 +++--- src/rtos/chromium-ec.c | 4 ++-- src/rtos/eCos.c | 6 +++--- src/rtos/embKernel.c | 6 +++--- src/rtos/hwthread.c | 6 +++--- src/rtos/linux.c | 6 +++--- src/rtos/mqx.c | 4 ++-- src/rtos/nuttx.c | 6 +++--- src/rtos/riot.c | 6 +++--- src/rtos/rtos.c | 8 ++++---- src/rtos/rtos.h | 8 ++++---- src/rtos/uCOS-III.c | 4 ++-- 14 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/rtos/FreeRTOS.c b/src/rtos/FreeRTOS.c index ee9b48bb9..4d520b9b4 100644 --- a/src/rtos/FreeRTOS.c +++ b/src/rtos/FreeRTOS.c @@ -109,7 +109,7 @@ static int FreeRTOS_create(struct target *target); static int FreeRTOS_update_threads(struct rtos *rtos); static int FreeRTOS_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int FreeRTOS_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int FreeRTOS_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); struct rtos_type FreeRTOS_rtos = { .name = "FreeRTOS", @@ -474,11 +474,11 @@ static int FreeRTOS_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, return rtos_generic_stack_read(rtos->target, param->stacking_info_cm3, stack_ptr, reg_list, num_regs); } -static int FreeRTOS_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int FreeRTOS_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; *symbol_list = calloc( - ARRAY_SIZE(FreeRTOS_symbol_list), sizeof(symbol_table_elem_t)); + ARRAY_SIZE(FreeRTOS_symbol_list), sizeof(struct symbol_table_elem)); for (i = 0; i < ARRAY_SIZE(FreeRTOS_symbol_list); i++) { (*symbol_list)[i].symbol_name = FreeRTOS_symbol_list[i].name; diff --git a/src/rtos/ThreadX.c b/src/rtos/ThreadX.c index 7d58725c4..0b3fef07e 100644 --- a/src/rtos/ThreadX.c +++ b/src/rtos/ThreadX.c @@ -39,7 +39,7 @@ static bool ThreadX_detect_rtos(struct target *target); static int ThreadX_create(struct target *target); static int ThreadX_update_threads(struct rtos *rtos); static int ThreadX_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int ThreadX_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int ThreadX_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); @@ -479,11 +479,11 @@ static int ThreadX_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, return rtos_generic_stack_read(rtos->target, stacking_info, stack_ptr, reg_list, num_regs); } -static int ThreadX_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int ThreadX_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; *symbol_list = calloc( - ARRAY_SIZE(ThreadX_symbol_list), sizeof(symbol_table_elem_t)); + ARRAY_SIZE(ThreadX_symbol_list), sizeof(struct symbol_table_elem)); for (i = 0; i < ARRAY_SIZE(ThreadX_symbol_list); i++) (*symbol_list)[i].symbol_name = ThreadX_symbol_list[i]; diff --git a/src/rtos/chibios.c b/src/rtos/chibios.c index a56d3ce05..29abede80 100644 --- a/src/rtos/chibios.c +++ b/src/rtos/chibios.c @@ -107,7 +107,7 @@ static int chibios_create(struct target *target); static int chibios_update_threads(struct rtos *rtos); static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int chibios_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int chibios_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); struct rtos_type chibios_rtos = { .name = "chibios", @@ -131,7 +131,7 @@ enum chibios_symbol_values { CHIBIOS_VAL_CH_DEBUG = 2 }; -static symbol_table_elem_t chibios_symbol_list[] = { +static struct symbol_table_elem chibios_symbol_list[] = { { "rlist", 0, true}, /* Thread ready list */ { "ch", 0, true}, /* System data structure */ { "ch_debug", 0, false}, /* Memory Signature containing offsets of fields in rlist */ @@ -497,7 +497,7 @@ static int chibios_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, return rtos_generic_stack_read(rtos->target, param->stacking_info, stack_ptr, reg_list, num_regs); } -static int chibios_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int chibios_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { *symbol_list = malloc(sizeof(chibios_symbol_list)); diff --git a/src/rtos/chromium-ec.c b/src/rtos/chromium-ec.c index ae12a3bf5..1476f1969 100644 --- a/src/rtos/chromium-ec.c +++ b/src/rtos/chromium-ec.c @@ -360,12 +360,12 @@ static int chromium_ec_get_thread_reg_list(struct rtos *rtos, stack_ptr, reg_list, num_regs); } -static int chromium_ec_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int chromium_ec_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { size_t s; *symbol_list = calloc(ARRAY_SIZE(chromium_ec_symbol_list), - sizeof(symbol_table_elem_t)); + sizeof(struct symbol_table_elem)); if (!(*symbol_list)) { LOG_ERROR("Chromium-EC: out of memory"); return ERROR_FAIL; diff --git a/src/rtos/eCos.c b/src/rtos/eCos.c index e6b70730b..9501a5522 100644 --- a/src/rtos/eCos.c +++ b/src/rtos/eCos.c @@ -31,7 +31,7 @@ static bool eCos_detect_rtos(struct target *target); static int eCos_create(struct target *target); static int eCos_update_threads(struct rtos *rtos); static int eCos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int eCos_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int eCos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); struct eCos_thread_state { int value; @@ -351,11 +351,11 @@ static int eCos_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, return -1; } -static int eCos_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int eCos_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; *symbol_list = calloc( - ARRAY_SIZE(eCos_symbol_list), sizeof(symbol_table_elem_t)); + ARRAY_SIZE(eCos_symbol_list), sizeof(struct symbol_table_elem)); for (i = 0; i < ARRAY_SIZE(eCos_symbol_list); i++) (*symbol_list)[i].symbol_name = eCos_symbol_list[i]; diff --git a/src/rtos/embKernel.c b/src/rtos/embKernel.c index 2f04963b4..994cbc091 100644 --- a/src/rtos/embKernel.c +++ b/src/rtos/embKernel.c @@ -36,7 +36,7 @@ static int embKernel_create(struct target *target); static int embKernel_update_threads(struct rtos *rtos); static int embKernel_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int embKernel_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int embKernel_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); struct rtos_type embKernel_rtos = { .name = "embKernel", @@ -330,10 +330,10 @@ static int embKernel_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, return rtos_generic_stack_read(rtos->target, param->stacking_info, stack_ptr, reg_list, num_regs); } -static int embKernel_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int embKernel_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; - *symbol_list = calloc(ARRAY_SIZE(embKernel_symbol_list), sizeof(symbol_table_elem_t)); + *symbol_list = calloc(ARRAY_SIZE(embKernel_symbol_list), sizeof(struct symbol_table_elem)); for (i = 0; i < ARRAY_SIZE(embKernel_symbol_list); i++) (*symbol_list)[i].symbol_name = embKernel_symbol_list[i]; diff --git a/src/rtos/hwthread.c b/src/rtos/hwthread.c index e2d1ccf13..ce2408635 100644 --- a/src/rtos/hwthread.c +++ b/src/rtos/hwthread.c @@ -35,7 +35,7 @@ static int hwthread_get_thread_reg(struct rtos *rtos, int64_t thread_id, uint32_t reg_num, struct rtos_reg *rtos_reg); static int hwthread_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int hwthread_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int hwthread_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); static int hwthread_smp_init(struct target *target); static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value); @@ -328,10 +328,10 @@ static int hwthread_set_reg(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_va return reg->type->set(reg, reg_value); } -static int hwthread_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int hwthread_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { /* return an empty list, we don't have any symbols to look up */ - *symbol_list = calloc(1, sizeof(symbol_table_elem_t)); + *symbol_list = calloc(1, sizeof(struct symbol_table_elem)); (*symbol_list)[0].symbol_name = NULL; return 0; } diff --git a/src/rtos/linux.c b/src/rtos/linux.c index 0cb4b54c8..4b96a931d 100644 --- a/src/rtos/linux.c +++ b/src/rtos/linux.c @@ -246,11 +246,11 @@ static const char * const linux_symbol_list[] = { NULL }; -static int linux_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int linux_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; - *symbol_list = (symbol_table_elem_t *) - calloc(ARRAY_SIZE(linux_symbol_list), sizeof(symbol_table_elem_t)); + *symbol_list = (struct symbol_table_elem *) + calloc(ARRAY_SIZE(linux_symbol_list), sizeof(struct symbol_table_elem)); for (i = 0; i < ARRAY_SIZE(linux_symbol_list); i++) (*symbol_list)[i].symbol_name = linux_symbol_list[i]; diff --git a/src/rtos/mqx.c b/src/rtos/mqx.c index f45c15d23..0914e3104 100644 --- a/src/rtos/mqx.c +++ b/src/rtos/mqx.c @@ -540,9 +540,9 @@ static int mqx_get_thread_reg_list( } /* API function, export list of required symbols */ -static int mqx_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int mqx_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { - *symbol_list = calloc(ARRAY_SIZE(mqx_symbol_list), sizeof(symbol_table_elem_t)); + *symbol_list = calloc(ARRAY_SIZE(mqx_symbol_list), sizeof(struct symbol_table_elem)); if (NULL == *symbol_list) return ERROR_FAIL; /* export required symbols */ diff --git a/src/rtos/nuttx.c b/src/rtos/nuttx.c index 19b93bad1..6569e38f2 100644 --- a/src/rtos/nuttx.c +++ b/src/rtos/nuttx.c @@ -380,12 +380,12 @@ static int nuttx_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, (uint32_t)thread_id + xcpreg_offset, reg_list, num_regs); } -static int nuttx_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int nuttx_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { unsigned int i; - *symbol_list = (symbol_table_elem_t *) calloc(1, - sizeof(symbol_table_elem_t) * ARRAY_SIZE(nuttx_symbol_list)); + *symbol_list = (struct symbol_table_elem *) calloc(1, + sizeof(struct symbol_table_elem) * ARRAY_SIZE(nuttx_symbol_list)); for (i = 0; i < ARRAY_SIZE(nuttx_symbol_list); i++) (*symbol_list)[i].symbol_name = nuttx_symbol_list[i]; diff --git a/src/rtos/riot.c b/src/rtos/riot.c index 15cbb0f85..dcba8381c 100644 --- a/src/rtos/riot.c +++ b/src/rtos/riot.c @@ -35,7 +35,7 @@ static int riot_create(struct target *target); static int riot_update_threads(struct rtos *rtos); static int riot_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, struct rtos_reg **reg_list, int *num_regs); -static int riot_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]); +static int riot_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]); struct riot_thread_state { int value; @@ -360,9 +360,9 @@ static int riot_get_thread_reg_list(struct rtos *rtos, int64_t thread_id, num_regs); } -static int riot_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int riot_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { - *symbol_list = calloc(ARRAY_SIZE(riot_symbol_list), sizeof(symbol_table_elem_t)); + *symbol_list = calloc(ARRAY_SIZE(riot_symbol_list), sizeof(struct symbol_table_elem)); if (*symbol_list == NULL) { LOG_ERROR("RIOT: out of memory"); diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index d9ba735f2..91d9379f3 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -176,9 +176,9 @@ int gdb_thread_packet(struct connection *connection, char const *packet, int pac return target->rtos->gdb_thread_packet(connection, packet, packet_size); } -static symbol_table_elem_t *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr) +static struct symbol_table_elem *next_symbol(struct rtos *os, char *cur_symbol, uint64_t cur_addr) { - symbol_table_elem_t *s; + struct symbol_table_elem *s; if (!os->symbols) os->type->get_symbol_list_to_lookup(&os->symbols); @@ -200,7 +200,7 @@ static symbol_table_elem_t *next_symbol(struct rtos *os, char *cur_symbol, uint6 * if 'symbol' is not declared optional */ static bool is_symbol_mandatory(const struct rtos *os, const char *symbol) { - for (symbol_table_elem_t *s = os->symbols; s->symbol_name; ++s) { + for (struct symbol_table_elem *s = os->symbols; s->symbol_name; ++s) { if (!strcmp(s->symbol_name, symbol)) return !s->optional; } @@ -232,7 +232,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s uint64_t addr = 0; size_t reply_len; char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for null-termination */ - symbol_table_elem_t *next_sym = NULL; + struct symbol_table_elem *next_sym = NULL; struct target *target = get_target_from_connection(connection); struct rtos *os = target->rtos; diff --git a/src/rtos/rtos.h b/src/rtos/rtos.h index b437be0dd..b3fd01fca 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -31,11 +31,11 @@ struct reg; /** * Table should be terminated by an element with NULL in symbol_name */ -typedef struct symbol_table_elem_struct { +struct symbol_table_elem { const char *symbol_name; symbol_address_t address; bool optional; -} symbol_table_elem_t; +}; struct thread_detail { threadid_t threadid; @@ -47,7 +47,7 @@ struct thread_detail { struct rtos { const struct rtos_type *type; - symbol_table_elem_t *symbols; + struct symbol_table_elem *symbols; struct target *target; /* add a context variable instead of global variable */ /* The thread currently selected by gdb. */ @@ -78,7 +78,7 @@ struct rtos_type { struct rtos_reg **reg_list, int *num_regs); int (*get_thread_reg)(struct rtos *rtos, int64_t thread_id, uint32_t reg_num, struct rtos_reg *reg); - int (*get_symbol_list_to_lookup)(symbol_table_elem_t *symbol_list[]); + int (*get_symbol_list_to_lookup)(struct symbol_table_elem *symbol_list[]); int (*clean)(struct target *target); char * (*ps_command)(struct target *target); int (*set_reg)(struct rtos *rtos, uint32_t reg_num, uint8_t *reg_value); diff --git a/src/rtos/uCOS-III.c b/src/rtos/uCOS-III.c index 304d07c59..d62a2199b 100644 --- a/src/rtos/uCOS-III.c +++ b/src/rtos/uCOS-III.c @@ -508,9 +508,9 @@ static int uCOS_III_get_thread_reg_list(struct rtos *rtos, threadid_t threadid, num_regs); } -static int uCOS_III_get_symbol_list_to_lookup(symbol_table_elem_t *symbol_list[]) +static int uCOS_III_get_symbol_list_to_lookup(struct symbol_table_elem *symbol_list[]) { - *symbol_list = calloc(ARRAY_SIZE(uCOS_III_symbol_list), sizeof(symbol_table_elem_t)); + *symbol_list = calloc(ARRAY_SIZE(uCOS_III_symbol_list), sizeof(struct symbol_table_elem)); if (*symbol_list == NULL) { LOG_ERROR("uCOS-III: out of memory"); return ERROR_FAIL; From 5fd78b0523d81c00100e02e1aed0990624ff56c8 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Tue, 26 Jan 2021 09:04:57 +0100 Subject: [PATCH 050/120] flash/nand/lpc32xx: Remove typedef'd struct The C style guide forbids typedef'd structs, see 'Naming Rules'. Change-Id: I983dd52307136d1b5adb58d8c44c0c14422d31e2 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6032 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/flash/nand/lpc32xx.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/flash/nand/lpc32xx.c b/src/flash/nand/lpc32xx.c index d516522f3..6443beb39 100644 --- a/src/flash/nand/lpc32xx.c +++ b/src/flash/nand/lpc32xx.c @@ -60,14 +60,14 @@ static const int lp_ooblayout[] = { 58, 59, 60, 61, 62, 63 }; -typedef struct { +struct dmac_ll { volatile uint32_t dma_src; volatile uint32_t dma_dest; volatile uint32_t next_lli; volatile uint32_t next_ctrl; -} dmac_ll_t; +}; -static dmac_ll_t dmalist[(2048/256) * 2 + 1]; +static struct dmac_ll dmalist[(2048/256) * 2 + 1]; /* nand device lpc32xx */ @@ -867,14 +867,14 @@ static int lpc32xx_make_dma_list(uint32_t target_mem_base, uint32_t page_size, dmalist[i*2].dma_src = (do_read ? dmasrc : (dmasrc + i * 256)); dmalist[i*2].dma_dest = (do_read ? (dmadst + i * 256) : dmadst); dmalist[i*2].next_lli = - target_mem_base + (i*2 + 1) * sizeof(dmac_ll_t); + target_mem_base + (i*2 + 1) * sizeof(struct dmac_ll); dmalist[i*2].next_ctrl = ctrl; dmalist[(i*2) + 1].dma_src = 0x20020034;/* SLC_ECC */ dmalist[(i*2) + 1].dma_dest = target_mem_base + ECC_OFFS + i * 4; dmalist[(i*2) + 1].next_lli = - target_mem_base + (i*2 + 2) * sizeof(dmac_ll_t); + target_mem_base + (i*2 + 2) * sizeof(struct dmac_ll); dmalist[(i*2) + 1].next_ctrl = ecc_ctrl; } @@ -1063,7 +1063,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand, XXX: Assumes host and target have same byte sex. */ retval = target_write_memory(target, target_mem_base, 4, - nll * sizeof(dmac_ll_t) / 4, + nll * sizeof(struct dmac_ll) / 4, (uint8_t *)dmalist); if (ERROR_OK != retval) { LOG_ERROR("Could not write DMA descriptors to IRAM"); @@ -1104,7 +1104,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand, /* Write first descriptor to DMA controller */ retval = target_write_memory(target, 0x31000100, 4, - sizeof(dmac_ll_t) / 4, + sizeof(struct dmac_ll) / 4, (uint8_t *)dmalist); if (ERROR_OK != retval) { LOG_ERROR("Could not write DMA descriptor to DMAC"); @@ -1161,7 +1161,7 @@ static int lpc32xx_write_page_slc(struct nand_device *nand, /* Write OOB descriptor to DMA controller */ retval = target_write_memory(target, 0x31000100, 4, - sizeof(dmac_ll_t) / 4, + sizeof(struct dmac_ll) / 4, (uint8_t *)(&dmalist[nll-1])); if (ERROR_OK != retval) { LOG_ERROR("Could not write OOB DMA descriptor to DMAC"); @@ -1460,7 +1460,7 @@ static int lpc32xx_read_page_slc(struct nand_device *nand, XXX: Assumes host and target have same byte sex. */ retval = target_write_memory(target, target_mem_base, 4, - nll * sizeof(dmac_ll_t) / 4, + nll * sizeof(struct dmac_ll) / 4, (uint8_t *)dmalist); if (ERROR_OK != retval) { LOG_ERROR("Could not write DMA descriptors to IRAM"); @@ -1489,7 +1489,7 @@ static int lpc32xx_read_page_slc(struct nand_device *nand, /* Write first descriptor to DMA controller */ retval = target_write_memory(target, 0x31000100, 4, - sizeof(dmac_ll_t) / 4, (uint8_t *)dmalist); + sizeof(struct dmac_ll) / 4, (uint8_t *)dmalist); if (ERROR_OK != retval) { LOG_ERROR("Could not write DMA descriptor to DMAC"); return retval; From 02abae8cdf339d18b441ed152d8a8d17209341b1 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Tue, 26 Jan 2021 09:15:47 +0100 Subject: [PATCH 051/120] target/mips: Remove typedef'd struct The C style guide forbids typedef'd structs, see 'Naming Rules'. Change-Id: I449590251056c478c05105cdc18014ab4eb77ed8 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6033 Tested-by: jenkins Reviewed-by: Oleksij Rempel Reviewed-by: Antonio Borneo --- src/target/mips32_pracc.c | 2 +- src/target/mips32_pracc.h | 6 +++--- src/target/mips64_pracc.c | 10 +++++----- src/target/mips_ejtag.c | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/target/mips32_pracc.c b/src/target/mips32_pracc.c index d6bd1c58a..f8643fa2d 100644 --- a/src/target/mips32_pracc.c +++ b/src/target/mips32_pracc.c @@ -317,7 +317,7 @@ void pracc_add(struct pracc_queue_info *ctx, uint32_t addr, uint32_t instr) if (ctx->retval != ERROR_OK) /* On previous out of memory, return */ return; if (ctx->code_count == ctx->max_code) { - void *p = realloc(ctx->pracc_list, sizeof(pa_list) * (ctx->max_code + PRACC_BLOCK)); + void *p = realloc(ctx->pracc_list, sizeof(struct pa_list) * (ctx->max_code + PRACC_BLOCK)); if (p) { ctx->max_code += PRACC_BLOCK; ctx->pracc_list = p; diff --git a/src/target/mips32_pracc.h b/src/target/mips32_pracc.h index 911a69c5b..30edaec0a 100644 --- a/src/target/mips32_pracc.h +++ b/src/target/mips32_pracc.h @@ -47,10 +47,10 @@ #define PRACC_BLOCK 128 /* 1 Kbyte */ -typedef struct { +struct pa_list { uint32_t instr; uint32_t addr; -} pa_list; +}; struct pracc_queue_info { struct mips_ejtag *ejtag_info; @@ -59,7 +59,7 @@ struct pracc_queue_info { int code_count; int store_count; int max_code; /* max instructions with currently allocated memory */ - pa_list *pracc_list; /* Code and store addresses at dmseg */ + struct pa_list *pracc_list; /* Code and store addresses at dmseg */ }; void pracc_queue_init(struct pracc_queue_info *ctx); diff --git a/src/target/mips64_pracc.c b/src/target/mips64_pracc.c index 3080046f3..dbad248fc 100644 --- a/src/target/mips64_pracc.c +++ b/src/target/mips64_pracc.c @@ -24,7 +24,7 @@ #define STACK_DEPTH 32 -typedef struct { +struct mips64_pracc_context { uint64_t *local_iparam; unsigned num_iparam; uint64_t *local_oparam; @@ -34,7 +34,7 @@ typedef struct { uint64_t stack[STACK_DEPTH]; unsigned stack_offset; struct mips_ejtag *ejtag_info; -} mips64_pracc_context; +}; static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info, uint32_t *ctrl) { @@ -61,7 +61,7 @@ static int wait_for_pracc_rw(struct mips_ejtag *ejtag_info, uint32_t *ctrl) return ERROR_OK; } -static int mips64_pracc_exec_read(mips64_pracc_context *ctx, uint64_t address) +static int mips64_pracc_exec_read(struct mips64_pracc_context *ctx, uint64_t address) { struct mips_ejtag *ejtag_info = ctx->ejtag_info; unsigned offset; @@ -149,7 +149,7 @@ static int mips64_pracc_exec_read(mips64_pracc_context *ctx, uint64_t address) return jtag_execute_queue(); } -static int mips64_pracc_exec_write(mips64_pracc_context *ctx, uint64_t address) +static int mips64_pracc_exec_write(struct mips64_pracc_context *ctx, uint64_t address) { uint32_t ejtag_ctrl; uint64_t data; @@ -214,7 +214,7 @@ int mips64_pracc_exec(struct mips_ejtag *ejtag_info, { uint32_t ejtag_ctrl; uint64_t address = 0, address_prev = 0, data; - mips64_pracc_context ctx; + struct mips64_pracc_context ctx; int retval; int pass = 0; bool first_time_call = true; diff --git a/src/target/mips_ejtag.c b/src/target/mips_ejtag.c index 4b049fb4e..d4c019fbe 100644 --- a/src/target/mips_ejtag.c +++ b/src/target/mips_ejtag.c @@ -268,7 +268,7 @@ error: int mips_ejtag_exit_debug(struct mips_ejtag *ejtag_info) { - pa_list pracc_list = {.instr = MIPS32_DRET(ejtag_info->isa), .addr = 0}; + struct pa_list pracc_list = {.instr = MIPS32_DRET(ejtag_info->isa), .addr = 0}; struct pracc_queue_info ctx = {.max_code = 1, .pracc_list = &pracc_list, .code_count = 1, .store_count = 0}; /* execute our dret instruction */ From 547fa6eeb737b349b463269c3baea726e69662b4 Mon Sep 17 00:00:00 2001 From: Yasushi SHOJI Date: Thu, 28 Jan 2021 23:25:26 +0900 Subject: [PATCH 052/120] target: Remove redundant initialization of endianness target->endianness is initialized to TARGET_ENDIAN_UNKNOWN at 34 lines below, before calling target_configure. This initialization is redundant and not needed. Change-Id: Iea2d5e17a13c1a8b0b209ba7c20043736b520ef6 Signed-off-by: Yasushi SHOJI Reviewed-on: http://openocd.zylin.com/6039 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/target.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index cab84b06b..fe519f2ab 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5721,9 +5721,6 @@ static int target_create(Jim_GetOptInfo *goi) memcpy(target->type, target_types[x], sizeof(struct target_type)); - /* will be set by "-endian" */ - target->endianness = TARGET_ENDIAN_UNKNOWN; - /* default to first core, override with -coreid */ target->coreid = 0; From fa76e036b92b22e07c9e7b70fa9c4cf504170a45 Mon Sep 17 00:00:00 2001 From: Adrian Negreanu Date: Mon, 7 Dec 2020 14:54:05 +0200 Subject: [PATCH 053/120] cmsis_dap: remove DAP_MAX_CLOCK Discussed here: https://sourceforge.net/p/openocd/mailman/message/35466010/ Change-Id: Ic4d38a872f4b13b794ad0a8a2abdbe5bb21eced3 Signed-off-by: Adrian Negreanu Reviewed-on: http://openocd.zylin.com/5964 Tested-by: jenkins Reviewed-by: Bohdan Tymkiv Reviewed-by: Antonio Borneo --- src/jtag/drivers/cmsis_dap.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c index 16480ae1e..fd565398f 100644 --- a/src/jtag/drivers/cmsis_dap.c +++ b/src/jtag/drivers/cmsis_dap.c @@ -169,10 +169,6 @@ static const char * const info_caps_str[] = { "JTAG Supported" }; -/* max clock speed (kHz) */ -#define DAP_MAX_CLOCK 5000 - - struct pending_transfer_result { uint8_t cmd; uint32_t data; @@ -1544,9 +1540,6 @@ static int cmsis_dap_execute_queue(void) static int cmsis_dap_speed(int speed) { - if (speed > DAP_MAX_CLOCK) - LOG_INFO("High speed (adapter speed %d) may be limited by adapter firmware.", speed); - if (speed == 0) { LOG_ERROR("RTCK not supported. Set nonzero \"adapter speed\"."); return ERROR_JTAG_NOT_IMPLEMENTED; From 169e5bf1862ab52c4ba28a26f15124293d2bf443 Mon Sep 17 00:00:00 2001 From: Adrian Negreanu Date: Fri, 20 Nov 2020 18:53:51 +0200 Subject: [PATCH 054/120] armv7m_trace_itm_config: wait for ITMBusy to be cleared pg315 of CoreSight Components: It is recommended that the ITMEn bit is cleared and waits for the ITMBusy bit to be cleared, before changing any fields in the Control Register, otherwise the behavior can be unpredictable. Change-Id: Ie9a2b842825c98ee5edc9a35776320c668047769 Signed-off-by: Adrian Negreanu Reviewed-on: http://openocd.zylin.com/6043 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/armv7m_trace.c | 28 ++++++++++++++++++++++++++++ src/target/cortex_m.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index 10f14221d..32b48a7c5 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -24,6 +24,7 @@ #include #include #include +#include #define TRACE_BUF_SIZE 4096 @@ -162,6 +163,33 @@ int armv7m_trace_itm_config(struct target *target) if (retval != ERROR_OK) return retval; + /* pg315 of CoreSight Components + * It is recommended that the ITMEn bit is cleared and waits for the + * ITMBusy bit to be cleared, before changing any fields in the + * Control Register, otherwise the behavior can be unpredictable. + */ + uint32_t itm_tcr; + retval = target_read_u32(target, ITM_TCR, &itm_tcr); + if (retval != ERROR_OK) + return retval; + retval = target_write_u32(target, + ITM_TCR, + itm_tcr & ~ITM_TCR_ITMENA_BIT + ); + if (retval != ERROR_OK) + return retval; + + int64_t then = timeval_ms() + 1000; + do { + retval = target_read_u32(target, ITM_TCR, &itm_tcr); + if (retval != ERROR_OK) + return retval; + if (timeval_ms() > then) { + LOG_ERROR("timeout waiting for ITM_TCR_BUSY_BIT"); + return ERROR_FAIL; + } + } while (itm_tcr & ITM_TCR_BUSY_BIT); + /* Enable ITM, TXENA, set TraceBusID and other parameters */ retval = target_write_u32(target, ITM_TCR, (1 << 0) | (1 << 3) | (trace_config->itm_diff_timestamps << 1) | diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index b470fbd70..1e2197b1a 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -35,6 +35,8 @@ #define ITM_TER0 0xE0000E00 #define ITM_TPR 0xE0000E40 #define ITM_TCR 0xE0000E80 +#define ITM_TCR_ITMENA_BIT BIT(0) +#define ITM_TCR_BUSY_BIT BIT(23) #define ITM_LAR 0xE0000FB0 #define ITM_LAR_KEY 0xC5ACCE55 From 47fa000193a6de7c374b4cae075ddaae3917a0e4 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 29 Dec 2020 01:26:15 +0100 Subject: [PATCH 055/120] drivers/rlink: switch to libusb1 Convert the driver from libusb0 to libusb1. Change-Id: I17d14522db18b4050d462d23151ec97d3a315a7f Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5991 Tested-by: jenkins Reviewed-by: Marc Schink --- configure.ac | 2 +- src/jtag/drivers/rlink.c | 200 +++++++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 85 deletions(-) diff --git a/configure.ac b/configure.ac index a74f319ba..b6723a396 100644 --- a/configure.ac +++ b/configure.ac @@ -122,11 +122,11 @@ m4_define([USB1_ADAPTERS], [[cmsis_dap_v2], [CMSIS-DAP v2 Compliant Debugger], [CMSIS_DAP_USB]], [[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]], [[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]], + [[rlink], [Raisonance RLink JTAG Programmer], [RLINK]], [[aice], [Andes JTAG Programmer], [AICE]]]) m4_define([USB0_ADAPTERS], [[[usbprog], [USBProg JTAG Programmer], [USBPROG]], - [[rlink], [Raisonance RLink JTAG Programmer], [RLINK]], [[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]]) m4_define([HIDAPI_ADAPTERS], diff --git a/src/jtag/drivers/rlink.c b/src/jtag/drivers/rlink.c index be4ad08bf..006e7c5c7 100644 --- a/src/jtag/drivers/rlink.c +++ b/src/jtag/drivers/rlink.c @@ -33,7 +33,7 @@ #include "rlink_st7.h" #include "rlink_ep1_cmd.h" #include "rlink_dtc_cmd.h" -#include "usb_common.h" +#include "libusb_helper.h" /* This feature is made useless by running the DTC all the time. When automatic, the LED is on *whenever the DTC is running. Otherwise, USB messages are sent to turn it on and off. */ @@ -96,19 +96,20 @@ #define ST7_PC_TDO ST7_PC_IO9 #define ST7_PA_DBGACK ST7_PA_IO10 -static usb_dev_handle *pHDev; +static libusb_device_handle *pHDev; /* * ep1 commands are up to USB_EP1OUT_SIZE bytes in length. * This function takes care of zeroing the unused bytes before sending the packet. * Any reply packet is not handled by this function. */ -static int ep1_generic_commandl(usb_dev_handle *pHDev_param, size_t length, ...) +static int ep1_generic_commandl(libusb_device_handle *pHDev_param, size_t length, ...) { uint8_t usb_buffer[USB_EP1OUT_SIZE]; uint8_t *usb_buffer_p; va_list ap; int usb_ret; + int transferred; if (length > sizeof(usb_buffer)) length = sizeof(usb_buffer); @@ -127,25 +128,29 @@ static int ep1_generic_commandl(usb_dev_handle *pHDev_param, size_t length, ...) sizeof(usb_buffer) - (usb_buffer_p - usb_buffer) ); - usb_ret = usb_bulk_write( + usb_ret = jtag_libusb_bulk_write( pHDev_param, USB_EP1OUT_ADDR, (char *)usb_buffer, sizeof(usb_buffer), - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - return usb_ret; + if (usb_ret != ERROR_OK) + return usb_ret; + return transferred; } #if 0 static ssize_t ep1_memory_read( - usb_dev_handle *pHDev, uint16_t addr, + libusb_device_handle *pHDev_param, uint16_t addr, size_t length, uint8_t *buffer) { uint8_t usb_buffer[USB_EP1OUT_SIZE]; int usb_ret; size_t remain; ssize_t count; + int transferred; usb_buffer[0] = EP1_CMD_MEMORY_READ; memset( @@ -167,22 +172,24 @@ static ssize_t ep1_memory_read( usb_buffer[2] = addr; usb_buffer[3] = length; - usb_ret = usb_bulk_write( - pHDev, USB_EP1OUT_ADDR, - usb_buffer, sizeof(usb_buffer), - USB_TIMEOUT_MS + usb_ret = jtag_libusb_bulk_write( + pHDev_param, USB_EP1OUT_ADDR, + (char *)usb_buffer, sizeof(usb_buffer), + USB_TIMEOUT_MS, + &transferred ); - if (usb_ret < sizeof(usb_buffer)) + if (usb_ret != ERROR_OK || transferred < (int)sizeof(usb_buffer)) break; - usb_ret = usb_bulk_read( - pHDev, USB_EP1IN_ADDR, - buffer, length, - USB_TIMEOUT_MS + usb_ret = jtag_libusb_bulk_read( + pHDev_param, USB_EP1IN_ADDR, + (char *)buffer, length, + USB_TIMEOUT_MS, + &transferred ); - if (usb_ret < length) + if (usb_ret != ERROR_OK || transferred < (int)length) break; addr += length; @@ -195,7 +202,7 @@ static ssize_t ep1_memory_read( } #endif -static ssize_t ep1_memory_write(usb_dev_handle *pHDev_param, uint16_t addr, +static ssize_t ep1_memory_write(libusb_device_handle *pHDev_param, uint16_t addr, size_t length, uint8_t const *buffer) { uint8_t usb_buffer[USB_EP1OUT_SIZE]; @@ -228,13 +235,16 @@ static ssize_t ep1_memory_write(usb_dev_handle *pHDev_param, uint16_t addr, sizeof(usb_buffer) - 4 - length ); - usb_ret = usb_bulk_write( + int transferred; + + usb_ret = jtag_libusb_bulk_write( pHDev_param, USB_EP1OUT_ADDR, (char *)usb_buffer, sizeof(usb_buffer), - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if ((size_t)usb_ret < sizeof(usb_buffer)) + if (usb_ret != ERROR_OK || transferred < (int)sizeof(usb_buffer)) break; addr += length; @@ -248,7 +258,7 @@ static ssize_t ep1_memory_write(usb_dev_handle *pHDev_param, uint16_t addr, #if 0 -static ssize_t ep1_memory_writel(usb_dev_handle *pHDev, uint16_t addr, +static ssize_t ep1_memory_writel(libusb_device_handle *pHDev_param, uint16_t addr, size_t length, ...) { uint8_t buffer[USB_EP1OUT_SIZE - 4]; @@ -268,7 +278,7 @@ static ssize_t ep1_memory_writel(usb_dev_handle *pHDev, uint16_t addr, remain--; } - return ep1_memory_write(pHDev, addr, length, buffer); + return ep1_memory_write(pHDev_param, addr, length, buffer); } #endif @@ -285,7 +295,7 @@ static ssize_t ep1_memory_writel(usb_dev_handle *pHDev, uint16_t addr, static uint8_t dtc_entry_download; /* The buffer is specially formatted to represent a valid image to load into the DTC. */ -static int dtc_load_from_buffer(usb_dev_handle *pHDev_param, const uint8_t *buffer, +static int dtc_load_from_buffer(libusb_device_handle *pHDev_param, const uint8_t *buffer, size_t length) { struct header_s { @@ -400,6 +410,7 @@ static int dtc_start_download(void) { int usb_err; uint8_t ep2txr; + int transferred; /* set up for download mode and make sure EP2 is set up to transmit */ usb_err = ep1_generic_commandl( @@ -417,12 +428,13 @@ static int dtc_start_download(void) return usb_err; /* read back ep2txr */ - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)&ep2txr, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if (usb_err < 0) + if (usb_err != ERROR_OK) return usb_err; usb_err = ep1_generic_commandl( @@ -446,17 +458,18 @@ static int dtc_start_download(void) return usb_err; /* wait for completion */ - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)&ep2txr, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); return usb_err; } static int dtc_run_download( - usb_dev_handle *pHDev_param, + libusb_device_handle *pHDev_param, uint8_t *command_buffer, int command_buffer_size, uint8_t *reply_buffer, @@ -466,14 +479,16 @@ static int dtc_run_download( char dtc_status; int usb_err; int i; + int transferred; LOG_DEBUG("%d/%d", command_buffer_size, reply_buffer_size); - usb_err = usb_bulk_write( + usb_err = jtag_libusb_bulk_write( pHDev_param, USB_EP2OUT_ADDR, (char *)command_buffer, USB_EP2BANK_SIZE, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); if (usb_err < 0) return usb_err; @@ -492,11 +507,12 @@ static int dtc_run_download( if (usb_err < 0) return usb_err; - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev_param, USB_EP1IN_ADDR, &dtc_status, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); if (usb_err < 0) return usb_err; @@ -506,20 +522,21 @@ static int dtc_run_download( if (!--i) { LOG_ERROR("too many retries waiting for DTC status"); - return -ETIMEDOUT; + return LIBUSB_ERROR_TIMEOUT; } } if (reply_buffer && reply_buffer_size) { - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev_param, USB_EP2IN_ADDR, (char *)reply_buffer, reply_buffer_size, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if (usb_err < reply_buffer_size) { + if (usb_err != ERROR_OK || transferred < reply_buffer_size) { LOG_ERROR("Read of endpoint 2 returned %d, expected %d", usb_err, reply_buffer_size ); @@ -643,7 +660,7 @@ static int dtc_queue_run(void) reply_buffer, sizeof(reply_buffer) ); if (usb_err < 0) { - LOG_ERROR("dtc_run_download: %s", usb_strerror()); + LOG_ERROR("dtc_run_download: %s", libusb_error_name(usb_err)); exit(1); } @@ -918,6 +935,7 @@ static void rlink_reset(int trst, int srst) { uint8_t bitmap; int usb_err; + int transferred; /* Read port A for bit op */ usb_err = ep1_generic_commandl( @@ -928,17 +946,18 @@ static void rlink_reset(int trst, int srst) 1 ); if (usb_err < 0) { - LOG_ERROR("%s", usb_strerror()); + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)&bitmap, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if (usb_err < 1) { - LOG_ERROR("%s", usb_strerror()); + if (usb_err != ERROR_OK || transferred < 1) { + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } @@ -963,17 +982,18 @@ static void rlink_reset(int trst, int srst) 1 ); if (usb_err < 0) { - LOG_ERROR("%s", usb_strerror()); + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)&bitmap, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if (usb_err < 1) { - LOG_ERROR("%s", usb_strerror()); + if (usb_err != ERROR_OK || transferred < 1) { + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } @@ -993,17 +1013,18 @@ static void rlink_reset(int trst, int srst) EP1_CMD_DTC_GET_CACHED_STATUS ); if (usb_err < 0) { - LOG_ERROR("%s", usb_strerror()); + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } - usb_err = usb_bulk_read( + usb_err = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)&bitmap, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); - if (usb_err < 1) { - LOG_ERROR("%s", usb_strerror()); + if (usb_err != ERROR_OK || transferred < 1) { + LOG_ERROR("%s", libusb_error_name(usb_err)); exit(1); } } @@ -1390,8 +1411,9 @@ static int rlink_speed(int speed) exit(1); } - if (dtc_start_download() < 0) { - LOG_ERROR("starting DTC: %s", usb_strerror()); + int ret = dtc_start_download(); + if (ret < 0) { + LOG_ERROR("starting DTC: %s", libusb_error_name(ret)); exit(1); } @@ -1443,19 +1465,28 @@ static int rlink_init(void) { int i, j, retries; uint8_t reply_buffer[USB_EP1IN_SIZE]; + int transferred; - usb_init(); const uint16_t vids[] = { USB_IDVENDOR, 0 }; const uint16_t pids[] = { USB_IDPRODUCT, 0 }; - if (jtag_usb_open(vids, pids, &pHDev) != ERROR_OK) + if (jtag_libusb_open(vids, pids, NULL, &pHDev, NULL) != ERROR_OK) return ERROR_FAIL; - struct usb_device *dev = usb_device(pHDev); - if (dev->descriptor.bNumConfigurations > 1) { + struct libusb_device_descriptor descriptor; + struct libusb_device *usb_dev = libusb_get_device(pHDev); + int r = libusb_get_device_descriptor(usb_dev, &descriptor); + if (r < 0) { + LOG_ERROR("error %d getting device descriptor", r); + return ERROR_FAIL; + } + + if (descriptor.bNumConfigurations > 1) { LOG_ERROR("Whoops! NumConfigurations is not 1, don't know what to do..."); return ERROR_FAIL; } - if (dev->config->bNumInterfaces > 1) { + struct libusb_config_descriptor *config; + libusb_get_config_descriptor(usb_dev, 0, &config); + if (config->bNumInterfaces > 1) { LOG_ERROR("Whoops! NumInterfaces is not 1, don't know what to do..."); return ERROR_FAIL; } @@ -1463,29 +1494,27 @@ static int rlink_init(void) LOG_DEBUG("Opened device, pHDev = %p", pHDev); /* usb_set_configuration required under win32 */ - usb_set_configuration(pHDev, dev->config[0].bConfigurationValue); + libusb_set_configuration(pHDev, config->bConfigurationValue); retries = 3; do { - i = usb_claim_interface(pHDev, 0); - if (i) { - LOG_ERROR("usb_claim_interface: %s", usb_strerror()); -#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP - j = usb_detach_kernel_driver_np(pHDev, 0); - if (j) - LOG_ERROR("detach kernel driver: %s", usb_strerror()); -#endif + i = libusb_claim_interface(pHDev, 0); + if (i != LIBUSB_SUCCESS) { + LOG_ERROR("usb_claim_interface: %s", libusb_error_name(i)); + j = libusb_detach_kernel_driver(pHDev, 0); + if (j != LIBUSB_SUCCESS) + LOG_ERROR("detach kernel driver: %s", libusb_error_name(j)); } else { LOG_DEBUG("interface claimed!"); break; } } while (--retries); - if (i) { + if (i != LIBUSB_SUCCESS) { LOG_ERROR("Initialisation failed."); return ERROR_FAIL; } - if (usb_set_altinterface(pHDev, 0) != 0) { + if (libusb_set_interface_alt_setting(pHDev, 0, 0) != LIBUSB_SUCCESS) { LOG_ERROR("Failed to set interface."); return ERROR_FAIL; } @@ -1505,20 +1534,21 @@ static int rlink_init(void) EP1_CMD_GET_FWREV ); if (j < USB_EP1OUT_SIZE) { - LOG_ERROR("USB write error: %s", usb_strerror()); + LOG_ERROR("USB write error: %s", libusb_error_name(j)); return ERROR_FAIL; } - j = usb_bulk_read( + j = jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)reply_buffer, sizeof(reply_buffer), - 200 + 200, + &transferred ); - if (j != -ETIMEDOUT) + if (j != LIBUSB_ERROR_TIMEOUT) break; } - if (j < (int)sizeof(reply_buffer)) { - LOG_ERROR("USB read error: %s", usb_strerror()); + if (j != ERROR_OK || transferred != (int)sizeof(reply_buffer)) { + LOG_ERROR("USB read error: %s", libusb_error_name(j)); return ERROR_FAIL; } LOG_DEBUG(INTERFACE_NAME " firmware version: %d.%d.%d", @@ -1551,10 +1581,11 @@ static int rlink_init(void) ST7_PE_ADAPTER_SENSE_OUT ); - usb_bulk_read( + jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)reply_buffer, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); if ((reply_buffer[0] & ST7_PE_ADAPTER_SENSE_IN) != 0) @@ -1575,10 +1606,11 @@ static int rlink_init(void) 0x00 /* OR */ ); - usb_bulk_read( + jtag_libusb_bulk_read( pHDev, USB_EP1IN_ADDR, (char *)reply_buffer, 1, - USB_TIMEOUT_MS + USB_TIMEOUT_MS, + &transferred ); @@ -1654,8 +1686,8 @@ static int rlink_quit(void) ~0 ); - usb_release_interface(pHDev, 0); - usb_close(pHDev); + libusb_release_interface(pHDev, 0); + libusb_close(pHDev); return ERROR_OK; } From faaa42283f5c06830fe997b80d6c64f6469c6cf0 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 12 Nov 2020 15:27:01 +0100 Subject: [PATCH 056/120] stlink: fix execution order in stlink_config_trace() The change [1] guarantees that the value pointed by 'prescaler' gets always set, even when the adapter does not support the specific mode requested (e.g. sync), or during trace disabling. This works fine with the code in armv7m_trace_tpiu_config(), but requires all the parameters to be valid also to disable the trace (with 'enable==false'), otherwise returns error on incorrect parameters or even causes segmentation fault if pointers 'trace_freq' or 'prescaler' are NULL. Another problem in stlink_config_trace(), not linked with [1], is caused by a tentative to change the settings on an already enabled trace; the trace is disabled before the new parameters are fully validated and in case of invalid parameters the trace is not re-enabled. It would be more logical to first check all the parameters, then disable the trace, change the settings and re-enable the trace. Practically revert [1] by checking 'enable==false' at function entry, then disable trace and exit without any further check on the other parameters. For the case 'enable==true', validate all the function parameters then disable the trace, update the trace settings and re-enable the trace. Modify the caller armv7m_trace_tpiu_config() to initialize the variable 'prescaler' to a safe value to avoid the issue targeted by [1]. [1] commit 38277fa75280 ("jtag/drivers/stlink_usb: fix SWO prescaler") Change-Id: Ia6530682162ca2c9f5ac64301f2456f70cc07ed2 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5934 Tested-by: jenkins Reviewed-by: Adrian M Negreanu --- src/jtag/drivers/stlink_usb.c | 23 ++++++++++++++++------- src/target/armv7m_trace.c | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 813af5578..73169e1e4 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -3528,8 +3528,20 @@ static int stlink_config_trace(void *handle, bool enabled, { struct stlink_usb_handle_s *h = handle; - if (enabled && (!(h->version.flags & STLINK_F_HAS_TRACE) || - pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART)) { + if (!(h->version.flags & STLINK_F_HAS_TRACE)) { + LOG_ERROR("The attached ST-LINK version doesn't support trace"); + return ERROR_FAIL; + } + + if (!enabled) { + stlink_usb_trace_disable(h); + return ERROR_OK; + } + + assert(trace_freq != NULL); + assert(prescaler != NULL); + + if (pin_protocol != TPIU_PIN_PROTOCOL_ASYNC_UART) { LOG_ERROR("The attached ST-LINK version doesn't support this trace mode"); return ERROR_FAIL; } @@ -3538,14 +3550,12 @@ static int stlink_config_trace(void *handle, bool enabled, STLINK_V3_TRACE_MAX_HZ : STLINK_TRACE_MAX_HZ; /* Only concern ourselves with the frequency if the STlink is processing it. */ - if (enabled && *trace_freq > max_trace_freq) { + if (*trace_freq > max_trace_freq) { LOG_ERROR("ST-LINK doesn't support SWO frequency higher than %u", max_trace_freq); return ERROR_FAIL; } - stlink_usb_trace_disable(h); - if (!*trace_freq) *trace_freq = max_trace_freq; @@ -3567,8 +3577,7 @@ static int stlink_config_trace(void *handle, bool enabled, *prescaler = presc; - if (!enabled) - return ERROR_OK; + stlink_usb_trace_disable(h); h->trace.source_hz = *trace_freq; diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index 32b48a7c5..adfef2e9b 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -87,7 +87,7 @@ int armv7m_trace_tpiu_config(struct target *target) { struct armv7m_common *armv7m = target_to_armv7m(target); struct armv7m_trace_config *trace_config = &armv7m->trace_config; - uint16_t prescaler; + uint16_t prescaler = TPIU_ACPR_MAX_SWOSCALER + 1; int retval; target_unregister_timer_callback(armv7m_poll_trace, target); From f9509c92dba370be363f5641d3fefe2250bee10c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 13 Nov 2020 19:41:41 +0100 Subject: [PATCH 057/120] itm: rework itm commands before 'init' If the command 'itm port[s]' is issued before 'init', the ITM can not be programmed because OpenOCD cannot access the target yet. The configuration is recorded and applied after target examine. The current test to trigger the ITM delayed-programming is based on the TPIU configuration. This is allowed because the only use of ITM it so send data through TPIU. In case of system TPIU, not belonging anymore to the target, there is no more association between target ITM and system TPIU. Add a flag to record the pending ITM configuration requested before 'init' and test the flag to trigger the delayed-programming of the ITM. Change-Id: I101eb97a116d7925cd2ff068f3e8813fc008b08e Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6029 Tested-by: jenkins --- src/target/armv7m_trace.c | 10 ++++++---- src/target/armv7m_trace.h | 2 ++ src/target/cortex_m.c | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index adfef2e9b..02f3f1061 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -408,8 +408,9 @@ COMMAND_HANDLER(handle_itm_port_command) if (CMD_CTX->mode == COMMAND_EXEC) return armv7m_trace_itm_config(target); - else - return ERROR_OK; + + armv7m->trace_config.itm_deferred_config = true; + return ERROR_OK; } COMMAND_HANDLER(handle_itm_ports_command) @@ -427,8 +428,9 @@ COMMAND_HANDLER(handle_itm_ports_command) if (CMD_CTX->mode == COMMAND_EXEC) return armv7m_trace_itm_config(target); - else - return ERROR_OK; + + armv7m->trace_config.itm_deferred_config = true; + return ERROR_OK; } static const struct command_registration tpiu_command_handlers[] = { diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h index cdf79e74c..61142b1e3 100644 --- a/src/target/armv7m_trace.h +++ b/src/target/armv7m_trace.h @@ -78,6 +78,8 @@ struct armv7m_trace_config { bool itm_async_timestamps; /** Enable synchronisation packet transmission (for sync port only) */ bool itm_synchro_packets; + /** Config ITM after target examine */ + bool itm_deferred_config; /** Current frequency of TRACECLKIN (usually matches HCLK) */ unsigned int traceclkin_freq; diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index ce2c426ce..4580c10ff 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2082,10 +2082,11 @@ int cortex_m_examine(struct target *target) if (retval != ERROR_OK) return retval; - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) { + if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) armv7m_trace_tpiu_config(target); + + if (armv7m->trace_config.itm_deferred_config) armv7m_trace_itm_config(target); - } /* NOTE: FPB and DWT are both optional. */ From 184724d14e120a9901fedfe05692bcd270f5eb57 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 12 Oct 2020 00:11:46 +0200 Subject: [PATCH 058/120] arm_tpiu_swo: add support for independent TPIU and SWO This is supposed to replace big part of armv7m_trace.[ch], since TPIU is not only the one implemented in Cortex-M3 and M4. Change-Id: I7588d16cbefe9cdb371c52fb0aa5cdfb48518804 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5858 Tested-by: jenkins --- doc/openocd.texi | 154 +++++- src/openocd.c | 7 + src/target/Makefile.am | 2 + src/target/arm_tpiu_swo.c | 998 ++++++++++++++++++++++++++++++++++++++ src/target/arm_tpiu_swo.h | 9 + 5 files changed, 1164 insertions(+), 6 deletions(-) create mode 100644 src/target/arm_tpiu_swo.c create mode 100644 src/target/arm_tpiu_swo.h diff --git a/doc/openocd.texi b/doc/openocd.texi index 34f1bb653..bd4380a2b 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9503,13 +9503,146 @@ Selects whether interrupts will be processed when single stepping @end deffn -@subsection ARMv7-M specific commands +@subsection ARM CoreSight TPIU and SWO specific commands @cindex tracing @cindex SWO @cindex SWV @cindex TPIU -@cindex ITM -@cindex ETM + +ARM CoreSight provides several modules to generate debugging +information internally (ITM, DWT and ETM). Their output is directed +through TPIU or SWO modules to be captured externally either on an SWO pin (this +configuration is called SWV) or on a synchronous parallel trace port. + +ARM CoreSight provides independent HW blocks named TPIU and SWO each with its +own functionality. Embedded in Cortex-M3 and M4, ARM provides an optional HW +block that includes both TPIU and SWO functionalities and is again named TPIU, +which causes quite some confusion. +The registers map of all the TPIU and SWO implementations allows using a single +driver that detects at runtime the features available. + +The @command{tpiu} is used for either TPIU or SWO. +A convenient alias @command{swo} is available to help distinguish, in scripts, +the commands for SWO from the commands for TPIU. + +@deffn Command {swo} ... +Alias of @command{tpiu ...}. Can be used in scripts to distinguish the commands +for SWO from the commands for TPIU. +@end deffn + +@deffn Command {tpiu create} tpiu_name configparams... +Creates a TPIU or a SWO object. The two commands are equivalent. +Add the object in a list and add new commands (@command{@var{tpiu_name}}) +which are used for various purposes including additional configuration. + +@itemize @bullet +@item @var{tpiu_name} -- the name of the TPIU or SWO object. +This name is also used to create the object's command, referred to here +as @command{$tpiu_name}, and in other places where the TPIU or SWO needs to be identified. +@item @var{configparams} -- all parameters accepted by @command{$tpiu_name configure} are permitted. + +You @emph{must} set here the AP and MEM_AP base_address through @code{-dap @var{dap_name}}, +@code{-ap-num @var{ap_number}} and @code{-baseaddr @var{base_address}}. +@end itemize +@end deffn + +@deffn Command {tpiu names} +Lists all the TPIU or SWO objects created so far. The two commands are equivalent. +@end deffn + +@deffn Command {tpiu init} +Initialize all registered TPIU and SWO. The two commands are equivalent. +These commands are used internally during initialization. They can be issued +at any time after the initialization, too. +@end deffn + +@deffn Command {$tpiu_name cget} queryparm +Each configuration parameter accepted by @command{$tpiu_name configure} can be +individually queried, to return its current value. +The @var{queryparm} is a parameter name accepted by that command, such as @code{-dap}. +@end deffn + +@deffn Command {$tpiu_name configure} configparams... +The options accepted by this command may also be specified as parameters +to @command{tpiu create}. Their values can later be queried one at a time by +using the @command{$tpiu_name cget} command. + +@itemize @bullet +@item @code{-dap} @var{dap_name} -- names the DAP used to access this +TPIU. @xref{dapdeclaration,,DAP declaration}, on how to create and manage DAP instances. + +@item @code{-ap-num} @var{ap_number} -- sets DAP access port for TPIU, +@var{ap_number} is the numeric index of the DAP AP the TPIU is connected to. + +@item @code{-baseaddr} @var{base_address} -- sets the TPIU @var{base_address} where +to access the TPIU in the DAP AP memory space. + +@item @code{-protocol} (@option{sync}|@option{uart}|@option{manchester}) -- sets the +protocol used for trace data: +@itemize @minus +@item @option{sync} -- synchronous parallel trace output mode, using @var{port_width} + data bits (default); +@item @option{uart} -- use asynchronous SWO mode with NRZ (same as regular UART 8N1) coding; +@item @option{manchester} -- use asynchronous SWO mode with Manchester coding. +@end itemize + +@item @code{-event} @var{event_name} @var{event_body} -- assigns an event handler, +a TCL string which is evaluated when the event is triggered. The events +@code{pre-enable}, @code{post-enable}, @code{pre-disable} and @code{post-disable} +are defined for TPIU/SWO. +A typical use case for the event @code{pre-enable} is to enable the trace clock +of the TPIU. + +@item @code{-output} (@option{external}|@option{:}@var{port}|@var{filename}|@option{-}) -- specifies +the destination of the trace data: +@itemize @minus +@item @option{external} -- configure TPIU/SWO to let user capture trace +output externally, either with an additional UART or with a logic analyzer (default); +@item @option{-} -- configure TPIU/SWO and debug adapter to gather trace data +and forward it to @command{tcl_trace} command; +@item @option{:}@var{port} -- configure TPIU/SWO and debug adapter to gather +trace data, open a TCP server at port @var{port} and send the trace data to +each connected client; +@item @var{filename} -- configure TPIU/SWO and debug adapter to +gather trace data and append it to @var{filename}, which can be +either a regular file or a named pipe. +@end itemize + +@item @code{-traceclk} @var{TRACECLKIN_freq} -- mandatory parameter. +Specifies the frequency in Hz of the trace clock. For the TPIU embedded in +Cortex-M3 or M4, this is usually the same frequency as HCLK. For protocol +@option{sync} this is twice the frequency of the pin data rate. + +@item @code{-pin-freq} @var{trace_freq} -- specifies the expected data rate +in Hz of the SWO pin. Parameter used only on protocols @option{uart} and +@option{manchester}. Can be omitted to let the adapter driver select the +maximum supported rate automatically. + +@item @code{-port-width} @var{port_width} -- sets to @var{port_width} the width +of the synchronous parallel port used for trace output. Parameter used only on +protocol @option{sync}. If not specified, default value is @var{1}. + +@item @code{-formatter} (@option{0}|@option{1}) -- specifies if the formatter +should be enabled. Parameter used only on protocol @option{sync}. If not specified, +default value is @var{0}. +@end itemize +@end deffn + +@deffn Command {$tpiu_name enable} +Uses the parameters specified by the previous @command{$tpiu_name configure} +to configure and enable the TPIU or the SWO. +If required, the adapter is also configured and enabled to receive the trace +data. +This command can be used before @command{init}, but it will take effect only +after the @command{init}. +@end deffn + +@deffn Command {$tpiu_name disable} +Disable the TPIU or the SWO, terminating the receiving of the trace data. +@end deffn + + +TODO: remove the old tpiu commands @deffn Command {tpiu config} (@option{disable} | ((@option{external} | @option{internal (@var{filename} | @var{:port} | -)}) @ (@option{sync @var{port_width}} | ((@option{manchester} | @option{uart}) @var{formatter_enable})) @ @@ -9585,13 +9718,22 @@ baud with our custom divisor to get 12MHz) @item OpenOCD invocation line: @example openocd -f interface/stlink.cfg \ - -c "transport select hla_swd" \ - -f target/stm32l1.cfg \ - -c "tpiu config external uart off 24000000 12000000" +-c "transport select hla_swd" \ +-f target/stm32l1.cfg \ +-c "stm32l1.tpiu configure -protocol uart" \ +-c "stm32l1.tpiu configure -traceclk 24000000 -pin-freq 12000000" \ +-c "stm32l1.tpiu enable" @end example @end enumerate @end deffn +@subsection ARMv7-M specific commands +@cindex tracing +@cindex SWO +@cindex SWV +@cindex ITM +@cindex ETM + @deffn Command {itm port} @var{port} (@option{0}|@option{1}|@option{on}|@option{off}) Enable or disable trace output for ITM stimulus @var{port} (counting from 0). Port 0 is enabled on target creation automatically. diff --git a/src/openocd.c b/src/openocd.c index 83c35458b..4fec56338 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -173,6 +174,10 @@ COMMAND_HANDLER(handle_init_command) return ERROR_FAIL; command_context_mode(CMD_CTX, COMMAND_EXEC); + /* in COMMAND_EXEC, after target_examine(), only tpiu or only swo */ + if (command_run_line(CMD_CTX, "tpiu init") != ERROR_OK) + return ERROR_FAIL; + /* initialize telnet subsystem */ gdb_target_add_all(all_targets); @@ -255,6 +260,7 @@ static struct command_context *setup_command_handler(Jim_Interp *interp) &pld_register_commands, &cti_register_commands, &dap_register_commands, + &arm_tpiu_swo_register_commands, NULL }; for (unsigned i = 0; NULL != command_registrants[i]; i++) { @@ -355,6 +361,7 @@ int openocd_main(int argc, char *argv[]) flash_free_all_banks(); gdb_service_free(); + arm_tpiu_swo_cleanup_all(); server_free(); unregister_all_commands(cmd_ctx, NULL); diff --git a/src/target/Makefile.am b/src/target/Makefile.am index 1d30747b6..6605b678b 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -113,6 +113,7 @@ ARM_DEBUG_SRC = \ %D%/etm.c \ $(OOCD_TRACE_FILES) \ %D%/etm_dummy.c \ + %D%/arm_tpiu_swo.c \ %D%/arm_cti.c AVR32_SRC = \ @@ -214,6 +215,7 @@ ARC_SRC = \ %D%/etb.h \ %D%/etm.h \ %D%/etm_dummy.h \ + %D%/arm_tpiu_swo.h \ %D%/image.h \ %D%/mips32.h \ %D%/mips64.h \ diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c new file mode 100644 index 000000000..61891cb57 --- /dev/null +++ b/src/target/arm_tpiu_swo.c @@ -0,0 +1,998 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** + * @file + * This file implements support for the ARM CoreSight components Trace Port + * Interface Unit (TPIU) and Serial Wire Output (SWO). It also supports the + * CoreSight TPIU-Lite and the special TPIU version present with Cortex-M3 + * and Cortex-M4 (that includes SWO). + */ + +/* + * Relevant specifications from ARM include: + * + * CoreSight(tm) Components Technical Reference Manual ARM DDI 0314H + * CoreSight(tm) TPIU-Lite Technical Reference Manual ARM DDI 0317A + * Cortex(tm)-M3 Technical Reference Manual ARM DDI 0337G + * Cortex(tm)-M4 Technical Reference Manual ARM DDI 0439B + * CoreSight(tm) SoC-400 Technical Reference Manual ARM DDI 0480F + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "arm_tpiu_swo.h" + +#define TCP_SERVICE_NAME "tpiu_swo_trace" + +/* default for Cortex-M3 and Cortex-M4 specific TPIU */ +#define TPIU_SWO_DEFAULT_BASE 0xE0040000 + +#define TPIU_SSPSR_OFFSET 0x000 +#define TPIU_CSPSR_OFFSET 0x004 +#define TPIU_ACPR_OFFSET 0x010 +#define TPIU_SPPR_OFFSET 0x0F0 +#define TPIU_FFSR_OFFSET 0x300 +#define TPIU_FFCR_OFFSET 0x304 +#define TPIU_FSCR_OFFSET 0x308 +#define TPIU_DEVID_OFFSET 0xfc8 + +#define TPIU_ACPR_MAX_PRESCALER 0x1fff +#define TPIU_SPPR_PROTOCOL_SYNC 0x0 /**< synchronous trace output */ +#define TPIU_SPPR_PROTOCOL_MANCHESTER 0x1 /**< asynchronous output with NRZ coding */ +#define TPIU_SPPR_PROTOCOL_UART 0x2 /**< asynchronous output with Manchester coding */ +#define TPIU_DEVID_NOSUPPORT_SYNC BIT(9) +#define TPIU_DEVID_SUPPORT_MANCHESTER BIT(10) +#define TPIU_DEVID_SUPPORT_UART BIT(11) + +enum arm_tpiu_swo_event { + TPIU_SWO_EVENT_PRE_ENABLE, + TPIU_SWO_EVENT_POST_ENABLE, + TPIU_SWO_EVENT_PRE_DISABLE, + TPIU_SWO_EVENT_POST_DISABLE, +}; + +static const Jim_Nvp nvp_arm_tpiu_swo_event[] = { + { .value = TPIU_SWO_EVENT_PRE_ENABLE, .name = "pre-enable" }, + { .value = TPIU_SWO_EVENT_POST_ENABLE, .name = "post-enable" }, + { .value = TPIU_SWO_EVENT_PRE_DISABLE, .name = "pre-disable" }, + { .value = TPIU_SWO_EVENT_POST_DISABLE, .name = "post-disable" }, +}; + +struct arm_tpiu_swo_event_action { + enum arm_tpiu_swo_event event; + Jim_Interp *interp; + Jim_Obj *body; + struct arm_tpiu_swo_event_action *next; +}; + +struct arm_tpiu_swo_object { + struct list_head lh; + struct adiv5_mem_ap_spot spot; + char *name; + struct arm_tpiu_swo_event_action *event_action; + /* record enable before init */ + bool deferred_enable; + bool enabled; + bool en_capture; + /** Handle to output trace data in INTERNAL capture mode */ + /** Synchronous output port width */ + uint32_t port_width; + FILE *file; + /** output mode */ + unsigned int pin_protocol; + /** Enable formatter */ + bool en_formatter; + /** frequency of TRACECLKIN (usually matches HCLK) */ + unsigned int traceclkin_freq; + /** SWO pin frequency */ + unsigned int swo_pin_freq; + /** where to dump the captured output trace data */ + char *out_filename; + /** track TCP connections */ + struct list_head connections; +}; + +struct arm_tpiu_swo_connection { + struct list_head lh; + struct connection *connection; +}; + +struct arm_tpiu_swo_priv_connection { + struct arm_tpiu_swo_object *obj; +}; + +static LIST_HEAD(all_tpiu_swo); + +#define ARM_TPIU_SWO_TRACE_BUF_SIZE 4096 + +static int arm_tpiu_swo_poll_trace(void *priv) +{ + struct arm_tpiu_swo_object *obj = priv; + uint8_t buf[ARM_TPIU_SWO_TRACE_BUF_SIZE]; + size_t size = sizeof(buf); + struct arm_tpiu_swo_connection *c; + + int retval = adapter_poll_trace(buf, &size); + if (retval != ERROR_OK || !size) + return retval; + + target_call_trace_callbacks(/*target*/NULL, size, buf); + + if (obj->file) { + if (fwrite(buf, 1, size, obj->file) == size) { + fflush(obj->file); + } else { + LOG_ERROR("Error writing to the SWO trace destination file"); + return ERROR_FAIL; + } + } + + if (obj->out_filename && obj->out_filename[0] == ':') + list_for_each_entry(c, &obj->connections, lh) + if (connection_write(c->connection, buf, size) != (int)size) + retval = ERROR_FAIL; + + return ERROR_OK; +} + +static void arm_tpiu_swo_handle_event(struct arm_tpiu_swo_object *obj, enum arm_tpiu_swo_event event) +{ + for (struct arm_tpiu_swo_event_action *ea = obj->event_action; ea; ea = ea->next) { + if (ea->event != event) + continue; + + LOG_DEBUG("TPIU/SWO: %s event: %s (%d) action : %s", + obj->name, + Jim_Nvp_value2name_simple(nvp_arm_tpiu_swo_event, event)->name, + event, + Jim_GetString(ea->body, NULL)); + + /* prevent event execution to change current target */ + struct command_context *cmd_ctx = current_command_context(ea->interp); + struct target *saved_target = cmd_ctx->current_target; + int retval = Jim_EvalObj(ea->interp, ea->body); + cmd_ctx->current_target = saved_target; + + if (retval == JIM_RETURN) + retval = ea->interp->returnCode; + if (retval == JIM_OK || retval == ERROR_COMMAND_CLOSE_CONNECTION) + return; + + Jim_MakeErrorMessage(ea->interp); + LOG_USER("Error executing event %s on TPIU/SWO %s:\n%s", + Jim_Nvp_value2name_simple(nvp_arm_tpiu_swo_event, event)->name, + obj->name, + Jim_GetString(Jim_GetResult(ea->interp), NULL)); + /* clean both error code and stacktrace before return */ + Jim_Eval(ea->interp, "error \"\" \"\""); + return; + } +} + +static void arm_tpiu_swo_close_output(struct arm_tpiu_swo_object *obj) +{ + if (obj->file) { + fclose(obj->file); + obj->file = NULL; + } + if (obj->out_filename && obj->out_filename[0] == ':') + remove_service(TCP_SERVICE_NAME, &obj->out_filename[1]); +} + +int arm_tpiu_swo_cleanup_all(void) +{ + struct arm_tpiu_swo_object *obj, *tmp; + + list_for_each_entry_safe(obj, tmp, &all_tpiu_swo, lh) { + if (obj->enabled) + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_DISABLE); + + arm_tpiu_swo_close_output(obj); + + if (obj->en_capture) { + target_unregister_timer_callback(arm_tpiu_swo_poll_trace, obj); + + int retval = adapter_config_trace(false, 0, 0, NULL, 0, NULL); + if (retval != ERROR_OK) + LOG_ERROR("Failed to stop adapter's trace"); + } + + if (obj->enabled) + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_POST_DISABLE); + + struct arm_tpiu_swo_event_action *ea = obj->event_action; + while (ea) { + struct arm_tpiu_swo_event_action *next = ea->next; + Jim_DecrRefCount(ea->interp, ea->body); + free(ea); + ea = next; + } + + free(obj->name); + free(obj->out_filename); + free(obj); + } + + return ERROR_OK; +} + +static int arm_tpiu_swo_service_new_connection(struct connection *connection) +{ + struct arm_tpiu_swo_priv_connection *priv = connection->service->priv; + struct arm_tpiu_swo_object *obj = priv->obj; + struct arm_tpiu_swo_connection *c = malloc(sizeof(*c)); + if (!c) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + c->connection = connection; + list_add(&c->lh, &obj->connections); + return ERROR_OK; +} + +static int arm_tpiu_swo_service_input(struct connection *connection) +{ + /* read a dummy buffer to check if the connection is still active */ + long dummy; + int bytes_read = connection_read(connection, &dummy, sizeof(dummy)); + + if (bytes_read == 0) { + return ERROR_SERVER_REMOTE_CLOSED; + } else if (bytes_read == -1) { + LOG_ERROR("error during read: %s", strerror(errno)); + return ERROR_SERVER_REMOTE_CLOSED; + } + + return ERROR_OK; +} + +static int arm_tpiu_swo_service_connection_closed(struct connection *connection) +{ + struct arm_tpiu_swo_priv_connection *priv = connection->service->priv; + struct arm_tpiu_swo_object *obj = priv->obj; + struct arm_tpiu_swo_connection *c, *tmp; + + list_for_each_entry_safe(c, tmp, &obj->connections, lh) + if (c->connection == connection) { + list_del(&c->lh); + free(c); + return ERROR_OK; + } + LOG_ERROR("Failed to find connection to close!"); + return ERROR_FAIL; +} + +COMMAND_HANDLER(handle_arm_tpiu_swo_event_list) +{ + struct arm_tpiu_swo_object *obj = CMD_DATA; + + command_print(CMD, "Event actions for TPIU/SWO %s\n", obj->name); + command_print(CMD, "%-25s | Body", "Event"); + command_print(CMD, "------------------------- | " + "----------------------------------------"); + + for (struct arm_tpiu_swo_event_action *ea = obj->event_action; ea; ea = ea->next) { + Jim_Nvp *opt = Jim_Nvp_value2name_simple(nvp_arm_tpiu_swo_event, ea->event); + command_print(CMD, "%-25s | %s", + opt->name, Jim_GetString(ea->body, NULL)); + } + command_print(CMD, "***END***"); + return ERROR_OK; +} + +enum arm_tpiu_swo_cfg_param { + CFG_PORT_WIDTH, + CFG_PROTOCOL, + CFG_FORMATTER, + CFG_TRACECLKIN, + CFG_BITRATE, + CFG_OUTFILE, + CFG_EVENT, +}; + +static const Jim_Nvp nvp_arm_tpiu_swo_config_opts[] = { + { .name = "-port-width", .value = CFG_PORT_WIDTH }, + { .name = "-protocol", .value = CFG_PROTOCOL }, + { .name = "-formatter", .value = CFG_FORMATTER }, + { .name = "-traceclk", .value = CFG_TRACECLKIN }, + { .name = "-pin-freq", .value = CFG_BITRATE }, + { .name = "-output", .value = CFG_OUTFILE }, + { .name = "-event", .value = CFG_EVENT }, + /* handled by mem_ap_spot, added for Jim_GetOpt_NvpUnknown() */ + { .name = "-dap", .value = -1 }, + { .name = "-ap-num", .value = -1 }, + { .name = "-baseaddr", .value = -1 }, + { .name = NULL, .value = -1 }, +}; + +static const Jim_Nvp nvp_arm_tpiu_swo_protocol_opts[] = { + { .name = "sync", .value = TPIU_SPPR_PROTOCOL_SYNC }, + { .name = "uart", .value = TPIU_SPPR_PROTOCOL_UART }, + { .name = "manchester", .value = TPIU_SPPR_PROTOCOL_MANCHESTER }, + { .name = NULL, .value = -1 }, +}; + +static const Jim_Nvp nvp_arm_tpiu_swo_bool_opts[] = { + { .name = "on", .value = 1 }, + { .name = "yes", .value = 1 }, + { .name = "1", .value = 1 }, + { .name = "true", .value = 1 }, + { .name = "off", .value = 0 }, + { .name = "no", .value = 0 }, + { .name = "0", .value = 0 }, + { .name = "false", .value = 0 }, + { .name = NULL, .value = -1 }, +}; + +static int arm_tpiu_swo_configure(Jim_GetOptInfo *goi, struct arm_tpiu_swo_object *obj) +{ + assert(obj != NULL); + + if (goi->isconfigure && obj->enabled) { + Jim_SetResultFormatted(goi->interp, "Cannot configure TPIU/SWO; %s is enabled!", obj->name); + return JIM_ERR; + } + + /* parse config or cget options ... */ + while (goi->argc > 0) { + Jim_SetEmptyResult(goi->interp); + + int e = adiv5_jim_mem_ap_spot_configure(&obj->spot, goi); + if (e == JIM_OK) + continue; + if (e == JIM_ERR) + return e; + + Jim_Nvp *n; + e = Jim_GetOpt_Nvp(goi, nvp_arm_tpiu_swo_config_opts, &n); + if (e != JIM_OK) { + Jim_GetOpt_NvpUnknown(goi, nvp_arm_tpiu_swo_config_opts, 0); + return e; + } + + switch (n->value) { + case CFG_PORT_WIDTH: + if (goi->isconfigure) { + jim_wide port_width; + e = Jim_GetOpt_Wide(goi, &port_width); + if (e != JIM_OK) + return e; + if (port_width < 1 || port_width > 32) { + Jim_SetResultString(goi->interp, "Invalid port width!", -1); + return JIM_ERR; + } + obj->port_width = (uint32_t)port_width; + } else { + if (goi->argc) + goto err_no_params; + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->port_width)); + } + break; + case CFG_PROTOCOL: + if (goi->isconfigure) { + Jim_Nvp *p; + e = Jim_GetOpt_Nvp(goi, nvp_arm_tpiu_swo_protocol_opts, &p); + if (e != JIM_OK) + return e; + obj->pin_protocol = p->value; + } else { + if (goi->argc) + goto err_no_params; + Jim_Nvp *p; + e = Jim_Nvp_value2name(goi->interp, nvp_arm_tpiu_swo_protocol_opts, obj->pin_protocol, &p); + if (e != JIM_OK) { + Jim_SetResultString(goi->interp, "protocol error", -1); + return JIM_ERR; + } + Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, p->name, -1)); + } + break; + case CFG_FORMATTER: + if (goi->isconfigure) { + Jim_Nvp *p; + e = Jim_GetOpt_Nvp(goi, nvp_arm_tpiu_swo_bool_opts, &p); + if (e != JIM_OK) + return e; + obj->en_formatter = p->value; + } else { + if (goi->argc) + goto err_no_params; + Jim_Nvp *p; + e = Jim_Nvp_value2name(goi->interp, nvp_arm_tpiu_swo_bool_opts, obj->en_formatter, &p); + if (e != JIM_OK) { + Jim_SetResultString(goi->interp, "formatter error", -1); + return JIM_ERR; + } + Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, p->name, -1)); + } + break; + case CFG_TRACECLKIN: + if (goi->isconfigure) { + jim_wide clk; + e = Jim_GetOpt_Wide(goi, &clk); + if (e != JIM_OK) + return e; + obj->traceclkin_freq = clk; + } else { + if (goi->argc) + goto err_no_params; + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->traceclkin_freq)); + } + break; + case CFG_BITRATE: + if (goi->isconfigure) { + jim_wide clk; + e = Jim_GetOpt_Wide(goi, &clk); + if (e != JIM_OK) + return e; + obj->swo_pin_freq = clk; + } else { + if (goi->argc) + goto err_no_params; + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, obj->swo_pin_freq)); + } + break; + case CFG_OUTFILE: + if (goi->isconfigure) { + const char *s; + e = Jim_GetOpt_String(goi, &s, NULL); + if (e != JIM_OK) + return e; + if (s[0] == ':') { + char *end; + long port = strtol(s + 1, &end, 0); + if (port <= 0 || port > UINT16_MAX || *end != '\0') { + Jim_SetResultFormatted(goi->interp, "Invalid TCP port \'%s\'", s + 1); + return JIM_ERR; + } + } + free(obj->out_filename); + obj->out_filename = strdup(s); + if (!obj->out_filename) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + } else { + if (goi->argc) + goto err_no_params; + if (obj->out_filename) + Jim_SetResult(goi->interp, Jim_NewStringObj(goi->interp, obj->out_filename, -1)); + } + break; + case CFG_EVENT: + if (goi->isconfigure) { + if (goi->argc < 2) { + Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name? ?EVENT-BODY?"); + return JIM_ERR; + } + } else { + if (goi->argc != 1) { + Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "-event ?event-name?"); + return JIM_ERR; + } + } + + { + Jim_Nvp *p; + Jim_Obj *o; + struct arm_tpiu_swo_event_action *ea = obj->event_action; + + e = Jim_GetOpt_Nvp(goi, nvp_arm_tpiu_swo_event, &p); + if (e != JIM_OK) { + Jim_GetOpt_NvpUnknown(goi, nvp_arm_tpiu_swo_event, 1); + return e; + } + + while (ea) { + /* replace existing? */ + if (ea->event == (enum arm_tpiu_swo_event)p->value) + break; + ea = ea->next; + } + + if (goi->isconfigure) { + if (!ea) { + ea = calloc(1, sizeof(*ea)); + if (!ea) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + ea->next = obj->event_action; + obj->event_action = ea; + } + if (ea->body) + Jim_DecrRefCount(ea->interp, ea->body); + ea->event = p->value; + ea->interp = goi->interp; + Jim_GetOpt_Obj(goi, &o); + ea->body = Jim_DuplicateObj(goi->interp, o); + Jim_IncrRefCount(ea->body); + } else { + if (ea) + Jim_SetResult(goi->interp, Jim_DuplicateObj(goi->interp, ea->body)); + } + } + break; + } + } + + return JIM_OK; + +err_no_params: + Jim_WrongNumArgs(goi->interp, goi->argc, goi->argv, "NO PARAMS"); + return JIM_ERR; +} + +static int jim_arm_tpiu_swo_configure(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +{ + Jim_GetOptInfo goi; + + Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); + goi.isconfigure = !strcmp(Jim_GetString(argv[0], NULL), "configure"); + if (goi.argc < 1) { + Jim_WrongNumArgs(goi.interp, goi.argc, goi.argv, + "missing: -option ..."); + return JIM_ERR; + } + struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp); + return arm_tpiu_swo_configure(&goi, obj); +} + +static int wrap_write_u32(struct target *target, struct adiv5_ap *tpiu_ap, + target_addr_t address, uint32_t value) +{ + if (transport_is_hla()) + return target_write_u32(target, address, value); + else + return mem_ap_write_atomic_u32(tpiu_ap, address, value); +} + +static int wrap_read_u32(struct target *target, struct adiv5_ap *tpiu_ap, + target_addr_t address, uint32_t *value) +{ + if (transport_is_hla()) + return target_read_u32(target, address, value); + else + return mem_ap_read_atomic_u32(tpiu_ap, address, value); +} + +static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp); + struct command_context *cmd_ctx = current_command_context(interp); + struct adiv5_ap *tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num); + uint32_t value; + int retval; + + if (argc != 1) { + Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); + return JIM_ERR; + } + + if (cmd_ctx->mode == COMMAND_CONFIG) { + LOG_DEBUG("%s: enable deferred", obj->name); + obj->deferred_enable = true; + return JIM_OK; + } + + if (obj->enabled) + return JIM_OK; + + if (transport_is_hla() && obj->spot.ap_num > 0) { + LOG_ERROR("Invalid access port %d. Only AP#0 allowed with hla transport", obj->spot.ap_num); + return JIM_ERR; + } + + if (!obj->traceclkin_freq) { + LOG_ERROR("Trace clock-in frequency not set"); + return JIM_ERR; + } + + if (obj->pin_protocol == TPIU_SPPR_PROTOCOL_MANCHESTER || obj->pin_protocol == TPIU_SPPR_PROTOCOL_UART) + if (!obj->swo_pin_freq) { + LOG_ERROR("SWO pin frequency not set"); + return JIM_ERR; + } + + struct target *target = get_current_target(cmd_ctx); + + /* trigger the event before any attempt to R/W in the TPIU/SWO */ + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_ENABLE); + + retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_DEVID_OFFSET, &value); + if (retval != ERROR_OK) { + LOG_ERROR("Unable to read %s", obj->name); + return JIM_ERR; + } + switch (obj->pin_protocol) { + case TPIU_SPPR_PROTOCOL_SYNC: + value = !(value & TPIU_DEVID_NOSUPPORT_SYNC); + break; + case TPIU_SPPR_PROTOCOL_UART: + value &= TPIU_DEVID_SUPPORT_UART; + break; + case TPIU_SPPR_PROTOCOL_MANCHESTER: + value &= TPIU_DEVID_SUPPORT_MANCHESTER; + break; + default: + value = 0; + } + if (!value) { + Jim_Nvp *p; + Jim_Nvp_value2name(interp, nvp_arm_tpiu_swo_protocol_opts, obj->pin_protocol, &p); + LOG_ERROR("%s does not support protocol %s", obj->name, p->name); + return JIM_ERR; + } + + if (obj->pin_protocol == TPIU_SPPR_PROTOCOL_SYNC) { + retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_SSPSR_OFFSET, &value); + if (!(value & BIT(obj->port_width - 1))) { + LOG_ERROR("TPIU does not support port-width of %d bits", obj->port_width); + return JIM_ERR; + } + } + + uint16_t prescaler = 1; /* dummy value */ + unsigned int swo_pin_freq = obj->swo_pin_freq; /* could be replaced */ + + if (obj->out_filename && strcmp(obj->out_filename, "external") && obj->out_filename[0]) { + if (obj->out_filename[0] == ':') { + struct arm_tpiu_swo_priv_connection *priv = malloc(sizeof(*priv)); + if (!priv) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + priv->obj = obj; + LOG_INFO("starting trace server for %s on %s", obj->name, &obj->out_filename[1]); + retval = add_service("tpiu_swo_trace", &obj->out_filename[1], + CONNECTION_LIMIT_UNLIMITED, arm_tpiu_swo_service_new_connection, + arm_tpiu_swo_service_input, arm_tpiu_swo_service_connection_closed, + priv, NULL); + if (retval != ERROR_OK) { + LOG_ERROR("Can't configure trace TCP port %s", &obj->out_filename[1]); + return JIM_ERR; + } + } else if (strcmp(obj->out_filename, "-")) { + obj->file = fopen(obj->out_filename, "ab"); + if (!obj->file) { + LOG_ERROR("Can't open trace destination file \"%s\"", obj->out_filename); + return JIM_ERR; + } + } + + retval = adapter_config_trace(true, obj->pin_protocol, obj->port_width, + &swo_pin_freq, obj->traceclkin_freq, &prescaler); + if (retval != ERROR_OK) { + LOG_ERROR("Failed to start adapter's trace"); + arm_tpiu_swo_close_output(obj); + return JIM_ERR; + } + + if (obj->swo_pin_freq != swo_pin_freq) + LOG_INFO("SWO pin data rate adjusted by adapter to %d Hz", swo_pin_freq); + obj->swo_pin_freq = swo_pin_freq; + + target_register_timer_callback(arm_tpiu_swo_poll_trace, 1, + TARGET_TIMER_TYPE_PERIODIC, obj); + + obj->en_capture = true; + } else if (obj->pin_protocol == TPIU_SPPR_PROTOCOL_MANCHESTER || obj->pin_protocol == TPIU_SPPR_PROTOCOL_UART) { + prescaler = (obj->traceclkin_freq + obj->swo_pin_freq / 2) / obj->swo_pin_freq; + if (prescaler > TPIU_ACPR_MAX_PRESCALER) + prescaler = TPIU_ACPR_MAX_PRESCALER; + swo_pin_freq = obj->traceclkin_freq / prescaler; + + if (obj->swo_pin_freq != swo_pin_freq) + LOG_INFO("SWO pin data rate adjusted to %d Hz", swo_pin_freq); + obj->swo_pin_freq = swo_pin_freq; + } + + retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_CSPSR_OFFSET, BIT(obj->port_width - 1)); + if (retval != ERROR_OK) + goto error_exit; + + retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_ACPR_OFFSET, prescaler - 1); + if (retval != ERROR_OK) + goto error_exit; + + retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_SPPR_OFFSET, obj->pin_protocol); + if (retval != ERROR_OK) + goto error_exit; + + retval = wrap_read_u32(target, tpiu_ap, obj->spot.base + TPIU_FFCR_OFFSET, &value); + if (retval != ERROR_OK) + goto error_exit; + if (obj->en_formatter) + value |= BIT(1); + else + value &= ~BIT(1); + retval = wrap_write_u32(target, tpiu_ap, obj->spot.base + TPIU_FFCR_OFFSET, value); + if (retval != ERROR_OK) + goto error_exit; + + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_POST_ENABLE); + + obj->enabled = true; + return JIM_OK; + +error_exit: + LOG_ERROR("Error!"); + + if (obj->en_capture) { + obj->en_capture = false; + + arm_tpiu_swo_close_output(obj); + + target_unregister_timer_callback(arm_tpiu_swo_poll_trace, obj); + + retval = adapter_config_trace(false, 0, 0, NULL, 0, NULL); + if (retval != ERROR_OK) { + LOG_ERROR("Failed to stop adapter's trace"); + return JIM_ERR; + } + } + return JIM_ERR; +} + +static int jim_arm_tpiu_swo_disable(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + struct arm_tpiu_swo_object *obj = Jim_CmdPrivData(interp); + + if (argc != 1) { + Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); + return JIM_ERR; + } + + if (!obj->enabled) + return JIM_OK; + obj->enabled = false; + + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_DISABLE); + + if (obj->en_capture) { + obj->en_capture = false; + + arm_tpiu_swo_close_output(obj); + + target_unregister_timer_callback(arm_tpiu_swo_poll_trace, obj); + + int retval = adapter_config_trace(false, 0, 0, NULL, 0, NULL); + if (retval != ERROR_OK) { + LOG_ERROR("Failed to stop adapter's trace"); + return JIM_ERR; + } + } + + arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_POST_DISABLE); + return JIM_OK; +} + +static const struct command_registration arm_tpiu_swo_instance_command_handlers[] = { + { + .name = "configure", + .mode = COMMAND_ANY, + .jim_handler = jim_arm_tpiu_swo_configure, + .help = "configure a new TPIU/SWO for use", + .usage = "[attribute value ...]", + }, + { + .name = "cget", + .mode = COMMAND_ANY, + .jim_handler = jim_arm_tpiu_swo_configure, + .help = "returns the specified TPIU/SWO attribute", + .usage = "attribute", + }, + { + .name = "eventlist", + .mode = COMMAND_ANY, + .handler = handle_arm_tpiu_swo_event_list, + .help = "displays a table of events defined for this TPIU/SWO", + .usage = "", + }, + { + .name = "enable", + .mode = COMMAND_ANY, + .jim_handler = jim_arm_tpiu_swo_enable, + .usage = "", + .help = "Enables the TPIU/SWO output", + }, + { + .name = "disable", + .mode = COMMAND_EXEC, + .jim_handler = jim_arm_tpiu_swo_disable, + .usage = "", + .help = "Disables the TPIU/SWO output", + }, + COMMAND_REGISTRATION_DONE +}; + +static int arm_tpiu_swo_create(Jim_Interp *interp, struct arm_tpiu_swo_object *obj) +{ + struct command_context *cmd_ctx; + Jim_Cmd *cmd; + int e; + + cmd_ctx = current_command_context(interp); + assert(cmd_ctx != NULL); + + /* does this command exist? */ + cmd = Jim_GetCommand(interp, Jim_NewStringObj(interp, obj->name, -1), JIM_ERRMSG); + if (cmd) { + Jim_SetResultFormatted(interp, "Command: %s Exists", obj->name); + return JIM_ERR; + } + + /* now - create the new tpiu/swo name command */ + const struct command_registration obj_commands[] = { + { + .name = obj->name, + .mode = COMMAND_ANY, + .help = "tpiu/swo instance command group", + .usage = "", + .chain = arm_tpiu_swo_instance_command_handlers, + }, + COMMAND_REGISTRATION_DONE + }; + e = register_commands(cmd_ctx, NULL, obj_commands); + if (ERROR_OK != e) + return JIM_ERR; + + struct command *c = command_find_in_context(cmd_ctx, obj->name); + assert(c); + command_set_handler_data(c, obj); + + list_add_tail(&obj->lh, &all_tpiu_swo); + + return JIM_OK; +} + +static int jim_arm_tpiu_swo_create(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + Jim_GetOptInfo goi; + Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); + if (goi.argc < 1) { + Jim_WrongNumArgs(goi.interp, 1, goi.argv, "?name? ..options..."); + return JIM_ERR; + } + + struct arm_tpiu_swo_object *obj = calloc(1, sizeof(struct arm_tpiu_swo_object)); + if (!obj) { + LOG_ERROR("Out of memory"); + return JIM_ERR; + } + INIT_LIST_HEAD(&obj->connections); + adiv5_mem_ap_spot_init(&obj->spot); + obj->spot.base = TPIU_SWO_DEFAULT_BASE; + obj->port_width = 1; + + Jim_Obj *n; + Jim_GetOpt_Obj(&goi, &n); + obj->name = strdup(Jim_GetString(n, NULL)); + if (!obj->name) { + LOG_ERROR("Out of memory"); + free(obj); + return JIM_ERR; + } + + /* Do the rest as "configure" options */ + goi.isconfigure = 1; + int e = arm_tpiu_swo_configure(&goi, obj); + if (e != JIM_OK) + goto err_exit; + + if (!obj->spot.dap || obj->spot.ap_num == DP_APSEL_INVALID) { + Jim_SetResultString(goi.interp, "-dap and -ap-num required when creating TPIU", -1); + goto err_exit; + } + + e = arm_tpiu_swo_create(goi.interp, obj); + if (e != JIM_OK) + goto err_exit; + + return JIM_OK; + +err_exit: + free(obj->name); + free(obj->out_filename); + free(obj); + return JIM_ERR; +} + +static int jim_arm_tpiu_swo_names(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + struct arm_tpiu_swo_object *obj; + + if (argc != 1) { + Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); + return JIM_ERR; + } + Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0)); + list_for_each_entry(obj, &all_tpiu_swo, lh) { + Jim_ListAppendElement(interp, Jim_GetResult(interp), + Jim_NewStringObj(interp, obj->name, -1)); + } + return JIM_OK; +} + +static int jim_arm_tpiu_swo_init(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +{ + struct command_context *cmd_ctx = current_command_context(interp); + struct arm_tpiu_swo_object *obj; + int retval = JIM_OK; + + if (argc != 1) { + Jim_WrongNumArgs(interp, 1, argv, "Too many parameters"); + return JIM_ERR; + } + list_for_each_entry(obj, &all_tpiu_swo, lh) { + if (!obj->deferred_enable) + continue; + LOG_DEBUG("%s: running enable during init", obj->name); + int retval2 = command_run_linef(cmd_ctx, "%s enable", obj->name); + if (retval2 != ERROR_OK) + retval = JIM_ERR; + } + return retval; +} + +static const struct command_registration arm_tpiu_swo_subcommand_handlers[] = { + { + .name = "create", + .mode = COMMAND_ANY, + .jim_handler = jim_arm_tpiu_swo_create, + .usage = "name [-dap dap] [-ap-num num] [-address baseaddr]", + .help = "Creates a new TPIU or SWO object", + }, + { + .name = "names", + .mode = COMMAND_ANY, + .jim_handler = jim_arm_tpiu_swo_names, + .usage = "", + .help = "Lists all registered TPIU and SWO objects by name", + }, + { + .name = "init", + .mode = COMMAND_EXEC, + .jim_handler = jim_arm_tpiu_swo_init, + .usage = "", + .help = "Initialize TPIU and SWO", + }, + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration arm_tpiu_swo_command_handlers[] = { + { + .name = "tpiu", + .chain = arm_tpiu_swo_subcommand_handlers, + .usage = "", + .help = "tpiu command group", + }, + { + .name = "swo", + .chain = arm_tpiu_swo_subcommand_handlers, + .usage = "", + .help = "swo command group", + }, + COMMAND_REGISTRATION_DONE +}; + +int arm_tpiu_swo_register_commands(struct command_context *cmd_ctx) +{ + return register_commands(cmd_ctx, NULL, arm_tpiu_swo_command_handlers); +} diff --git a/src/target/arm_tpiu_swo.h b/src/target/arm_tpiu_swo.h new file mode 100644 index 000000000..e0aed71cb --- /dev/null +++ b/src/target/arm_tpiu_swo.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef OPENOCD_TARGET_ARM_TPIU_SWO_H +#define OPENOCD_TARGET_ARM_TPIU_SWO_H + +int arm_tpiu_swo_register_commands(struct command_context *cmd_ctx); +int arm_tpiu_swo_cleanup_all(void); + +#endif /* OPENOCD_TARGET_ARM_TPIU_SWO_H */ From c945d6e6160598894319860a92b602a192c2c268 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 12 Oct 2020 00:12:05 +0200 Subject: [PATCH 059/120] tcl/target: start using the new TPIU/SWO support Create the TPIU and SWO device in target config file. Replace the target event 'trace-config' with the TPIU/SWO event 'post-enable'. Extend the existing code in the event handler to properly set the gpio mode and speed to permit synchronous trace. This patch is not exhaustive of all the targets that have SWO, but has to be considered as an initial example. Change-Id: If4bbf364c0d2aef3ae49951e76507a3b1cfd58e7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5859 Tested-by: jenkins Reviewed-by: Adrian M Negreanu --- tcl/target/stm32f4x.cfg | 36 +++++++++++++++++++++++++++++++----- tcl/target/stm32h7x.cfg | 19 ++++++++++++++----- tcl/target/stm32mp15x.cfg | 11 +++++++++-- 3 files changed, 54 insertions(+), 12 deletions(-) diff --git a/tcl/target/stm32f4x.cfg b/tcl/target/stm32f4x.cfg index 15875336e..e94837f83 100644 --- a/tcl/target/stm32f4x.cfg +++ b/tcl/target/stm32f4x.cfg @@ -38,6 +38,8 @@ if { [info exists CPUTAPID] } { swj_newdap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +tpiu create $_CHIPNAME.tpiu -dap stm32f4x.dap -ap-num 0 -baseaddr 0xE0040000 + if {[using_jtag]} { jtag newtap $_CHIPNAME bs -irlen 5 } @@ -89,13 +91,37 @@ $_TARGETNAME configure -event examine-end { mmw 0xE0042008 0x00001800 0 } -$_TARGETNAME configure -event trace-config { - # Set TRACE_IOEN; TRACE_MODE is set to async; when using sync - # change this value accordingly to configure trace pins - # assignment - mmw 0xE0042004 0x00000020 0 +proc proc_post_enable {_chipname} { + targets $_chipname.cpu + + if { [$_chipname.tpiu cget -protocol] eq "sync" } { + switch [$_chipname.tpiu cget -port-width] { + 1 { + mmw 0xE0042004 0x00000060 0x000000c0 + mmw 0x40021020 0x00000000 0x0000ff00 + mmw 0x40021000 0x000000a0 0x000000f0 + mmw 0x40021008 0x000000f0 0x00000000 + } + 2 { + mmw 0xE0042004 0x000000a0 0x000000c0 + mmw 0x40021020 0x00000000 0x000fff00 + mmw 0x40021000 0x000002a0 0x000003f0 + mmw 0x40021008 0x000003f0 0x00000000 + } + 4 { + mmw 0xE0042004 0x000000e0 0x000000c0 + mmw 0x40021020 0x00000000 0x0fffff00 + mmw 0x40021000 0x00002aa0 0x00003ff0 + mmw 0x40021008 0x00003ff0 0x00000000 + } + } + } else { + mmw 0xE0042004 0x00000020 0x000000c0 + } } +$_CHIPNAME.tpiu configure -event post-enable "proc_post_enable $_CHIPNAME" + $_TARGETNAME configure -event reset-init { # Configure PLL to boost clock to HSI x 4 (64 MHz) mww 0x40023804 0x08012008 ;# RCC_PLLCFGR 16 Mhz /8 (M) * 128 (N) /4(P) diff --git a/tcl/target/stm32h7x.cfg b/tcl/target/stm32h7x.cfg index 8258e5031..26d0d9301 100644 --- a/tcl/target/stm32h7x.cfg +++ b/tcl/target/stm32h7x.cfg @@ -77,6 +77,8 @@ if {![using_hla]} { # STM32H7 provides an APB-AP at access port 2, which allows the access to # the debug and trace features on the system APB System Debug Bus (APB-D). target create $_CHIPNAME.ap2 mem_ap -dap $_CHIPNAME.dap -ap-num 2 + swo create $_CHIPNAME.swo -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00E3000 + tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE00F5000 } target create $_CHIPNAME.cpu0 cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap -ap-num 0 @@ -178,13 +180,20 @@ $_CHIPNAME.cpu0 configure -event examine-end { stm32h7x_dbgmcu_mmw 0x03C 0x00000800 0 # DBGMCU_APB4FZ1 |= WDGLSD1 | WDGLSD2 stm32h7x_dbgmcu_mmw 0x054 0x000C0000 0 -} -$_CHIPNAME.cpu0 configure -event trace-config { - # Set TRACECLKEN; TRACE_MODE is set to async; when using sync - # change this value accordingly to configure trace pins - # assignment + # Enable clock for tracing + # DBGMCU_CR |= TRACECLKEN stm32h7x_dbgmcu_mmw 0x004 0x00100000 0 + + # RM0399 (id 0x450) M7+M4 with SWO Funnel + # RM0433 (id 0x450) M7 with SWO Funnel + # RM0455 (id 0x480) M7 without SWO Funnel + # RM0468 (id 0x483) M7 without SWO Funnel + # Enable CM7 and CM4 slave ports in SWO trace Funnel + # Works ok also on devices single core and without SWO funnel + # Hack, use stm32h7x_dbgmcu_mmw with big offset to control SWTF + # SWTF_CTRL |= ENS0 | ENS1 + stm32h7x_dbgmcu_mmw 0x3000 0x00000003 0 } $_CHIPNAME.cpu0 configure -event reset-init { diff --git a/tcl/target/stm32mp15x.cfg b/tcl/target/stm32mp15x.cfg index 4a8bc866c..1b2ae7d5e 100644 --- a/tcl/target/stm32mp15x.cfg +++ b/tcl/target/stm32mp15x.cfg @@ -64,6 +64,9 @@ cti create $_CHIPNAME.cti.cpu0 -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE00D800 cti create $_CHIPNAME.cti.cpu1 -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE00D9000 cti create $_CHIPNAME.cti.cm4 -dap $_CHIPNAME.dap -ap-num 2 -baseaddr 0xE0043000 +swo create $_CHIPNAME.swo -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE0083000 +tpiu create $_CHIPNAME.tpiu -dap $_CHIPNAME.dap -ap-num 1 -baseaddr 0xE0093000 + # interface does not work while srst is asserted # this is target specific, valid for every board # Errata "2.3.5 Incorrect reset of glitch-free kernel clock switch" requires @@ -108,9 +111,13 @@ proc detect_cpu1 {} { if {! $dual_core} {$::_CHIPNAME.cpu1 configure -defer-examine} } +proc rcc_enable_traceclk {} { + $::_CHIPNAME.ap2 mww 0x5000080c 0x301 +} + # FIXME: most of handler below will be removed once reset framework get merged $_CHIPNAME.ap1 configure -event reset-deassert-pre {adapter deassert srst deassert trst;dap init;catch {$::_CHIPNAME.dap apid 1}} -$_CHIPNAME.ap2 configure -event reset-deassert-pre {dbgmcu_enable_debug} +$_CHIPNAME.ap2 configure -event reset-deassert-pre {dbgmcu_enable_debug;rcc_enable_traceclk} $_CHIPNAME.cpu0 configure -event reset-deassert-pre {$::_CHIPNAME.cpu0 arp_examine} $_CHIPNAME.cpu1 configure -event reset-deassert-pre {$::_CHIPNAME.cpu1 arp_examine allow-defer} $_CHIPNAME.cpu0 configure -event reset-deassert-post {toggle_cpu0_dbg_claim0} @@ -118,4 +125,4 @@ $_CHIPNAME.cm4 configure -event reset-deassert-post {$::_CHIPNAME.cm4 arp_exami $_CHIPNAME.ap1 configure -event examine-start {dap init} $_CHIPNAME.ap2 configure -event examine-start {dbgmcu_enable_debug} $_CHIPNAME.cpu0 configure -event examine-end {detect_cpu1} -$_CHIPNAME.ap2 configure -event examine-end {$::_CHIPNAME.cm4 arp_examine} +$_CHIPNAME.ap2 configure -event examine-end {rcc_enable_traceclk;$::_CHIPNAME.cm4 arp_examine} From dc7b32ea4a00a425a71b3309f3fceb07b8467592 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 13 Nov 2020 23:36:24 +0100 Subject: [PATCH 060/120] armv7m_trace: get rid of the old tpiu code Remove all the old tpiu code and replace it with a wrapper that uses the new commands, prints-out the new commands and informs about the deprecation. All the code that handles the deprecated tpiu commands is enclosed between the comments /* START_DEPRECATED_TPIU */ and /* END_DEPRECATED_TPIU */ so will be easy to remove it in the future. Change-Id: I70b0486770128203b923346382d9a90b8ec08439 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6030 Tested-by: jenkins Reviewed-by: Adrian M Negreanu --- doc/openocd.texi | 49 ------ src/jtag/interface.h | 2 +- src/target/arm_tpiu_swo.c | 197 ++++++++++++++++++++++- src/target/arm_tpiu_swo.h | 12 ++ src/target/armv7m_trace.c | 324 -------------------------------------- src/target/armv7m_trace.h | 51 +----- src/target/cortex_m.c | 10 +- src/target/hla_target.c | 5 + src/target/target.c | 5 + 9 files changed, 223 insertions(+), 432 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index bd4380a2b..0c1714e49 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9642,54 +9642,6 @@ Disable the TPIU or the SWO, terminating the receiving of the trace data. @end deffn -TODO: remove the old tpiu commands - -@deffn Command {tpiu config} (@option{disable} | ((@option{external} | @option{internal (@var{filename} | @var{:port} | -)}) @ - (@option{sync @var{port_width}} | ((@option{manchester} | @option{uart}) @var{formatter_enable})) @ - @var{TRACECLKIN_freq} [@var{trace_freq}])) - -ARMv7-M architecture provides several modules to generate debugging -information internally (ITM, DWT and ETM). Their output is directed -through TPIU to be captured externally either on an SWO pin (this -configuration is called SWV) or on a synchronous parallel trace port. - -This command configures the TPIU module of the target and, if internal -capture mode is selected, starts to capture trace output by using the -debugger adapter features. - -Some targets require additional actions to be performed in the -@b{trace-config} handler for trace port to be activated. - -Command options: -@itemize @minus -@item @option{disable} disable TPIU handling; -@item @option{external} configure TPIU to let user capture trace -output externally (with an additional UART or logic analyzer hardware). -@item @option{internal (@var{filename} | @var{:port} | -)} configure TPIU and debug adapter to -gather trace data then: - -@itemize @minus -@item append it to a regular file or a named pipe if @var{filename} is specified. -@item listen to a TCP/IP port if @var{:port} is specified, then broadcast the trace data over this port. -@item if '-' is specified, OpenOCD will forward trace data to @command{tcl_trace} command. -@*@b{Note:} while broadcasting to file or TCP, the forwarding to @command{tcl_trace} will remain active. -@end itemize - -@item @option{sync @var{port_width}} use synchronous parallel trace output -mode, and set port width to @var{port_width}. -@item @option{manchester} use asynchronous SWO mode with Manchester -coding. -@item @option{uart} use asynchronous SWO mode with NRZ (same as -regular UART 8N1) coding. -@item @var{formatter_enable} is @option{on} or @option{off} to enable -or disable TPIU formatter which needs to be used when both ITM and ETM -data is to be output via SWO. -@item @var{TRACECLKIN_freq} this should be specified to match target's -current TRACECLKIN frequency (usually the same as HCLK). -@item @var{trace_freq} trace port frequency. Can be omitted in -internal mode to let the adapter driver select the maximum supported -rate automatically. -@end itemize Example usage: @enumerate @@ -9725,7 +9677,6 @@ openocd -f interface/stlink.cfg \ -c "stm32l1.tpiu enable" @end example @end enumerate -@end deffn @subsection ARMv7-M specific commands @cindex tracing diff --git a/src/jtag/interface.h b/src/jtag/interface.h index 0884868a8..58bfd02b0 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -27,7 +27,7 @@ #include #include -#include +#include /* @file * The "Cable Helper API" is what the cable drivers can use to help diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c index 61891cb57..b492438d4 100644 --- a/src/target/arm_tpiu_swo.c +++ b/src/target/arm_tpiu_swo.c @@ -38,6 +38,12 @@ #include #include "arm_tpiu_swo.h" +/* START_DEPRECATED_TPIU */ +#include +#include +#define MSG "DEPRECATED \'tpiu config\' command: " +/* END_DEPRECATED_TPIU */ + #define TCP_SERVICE_NAME "tpiu_swo_trace" /* default for Cortex-M3 and Cortex-M4 specific TPIU */ @@ -53,9 +59,9 @@ #define TPIU_DEVID_OFFSET 0xfc8 #define TPIU_ACPR_MAX_PRESCALER 0x1fff -#define TPIU_SPPR_PROTOCOL_SYNC 0x0 /**< synchronous trace output */ -#define TPIU_SPPR_PROTOCOL_MANCHESTER 0x1 /**< asynchronous output with NRZ coding */ -#define TPIU_SPPR_PROTOCOL_UART 0x2 /**< asynchronous output with Manchester coding */ +#define TPIU_SPPR_PROTOCOL_SYNC (TPIU_PIN_PROTOCOL_SYNC) +#define TPIU_SPPR_PROTOCOL_MANCHESTER (TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER) +#define TPIU_SPPR_PROTOCOL_UART (TPIU_PIN_PROTOCOL_ASYNC_UART) #define TPIU_DEVID_NOSUPPORT_SYNC BIT(9) #define TPIU_DEVID_SUPPORT_MANCHESTER BIT(10) #define TPIU_DEVID_SUPPORT_UART BIT(11) @@ -106,6 +112,9 @@ struct arm_tpiu_swo_object { char *out_filename; /** track TCP connections */ struct list_head connections; + /* START_DEPRECATED_TPIU */ + bool recheck_ap_cur_target; + /* END_DEPRECATED_TPIU */ }; struct arm_tpiu_swo_connection { @@ -612,6 +621,31 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const struct target *target = get_current_target(cmd_ctx); + /* START_DEPRECATED_TPIU */ + if (obj->recheck_ap_cur_target) { + if (strcmp(target->type->name, "cortex_m") && + strcmp(target->type->name, "hla_target")) { + LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA"); + return JIM_ERR; + } + if (!target_was_examined(target)) { + LOG_ERROR(MSG "Current target not examined yet"); + return JIM_ERR; + } + struct cortex_m_common *cm = target_to_cm(target); + obj->recheck_ap_cur_target = false; + obj->spot.ap_num = cm->armv7m.debug_ap->ap_num; + tpiu_ap = dap_ap(obj->spot.dap, obj->spot.ap_num); + if (obj->spot.ap_num == 0) + LOG_INFO(MSG "Confirmed TPIU %s is on AP 0", obj->name); + else + LOG_INFO(MSG "Target %s is on AP %d. Revised command is " + "\'tpiu create %s -dap %s -ap-num %d\'", + target_name(target), obj->spot.ap_num, + obj->name, adiv5_dap_name(obj->spot.dap), obj->spot.ap_num); + } + /* END_DEPRECATED_TPIU */ + /* trigger the event before any attempt to R/W in the TPIU/SWO */ arm_tpiu_swo_handle_event(obj, TPIU_SWO_EVENT_PRE_ENABLE); @@ -951,6 +985,163 @@ static int jim_arm_tpiu_swo_init(Jim_Interp *interp, int argc, Jim_Obj *const *a return retval; } +/* START_DEPRECATED_TPIU */ +/* DEPRECATED: emulation of old command 'tpiu config' */ +COMMAND_HANDLER(handle_tpiu_deprecated_config_command) +{ + struct target *target = get_current_target(CMD_CTX); + struct arm_tpiu_swo_object *obj = NULL; + int retval; + + if (strcmp(target->type->name, "cortex_m") && + strcmp(target->type->name, "hla_target")) { + LOG_ERROR(MSG "Current target is not a Cortex-M nor a HLA"); + return ERROR_FAIL; + } + + if (!list_empty(&all_tpiu_swo)) { + obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh); + LOG_INFO(MSG "Using %s", obj->name); + } else { + struct cortex_m_common *cm = target_to_cm(target); + struct adiv5_private_config *pc = target->private_config; + struct adiv5_dap *dap = pc->dap; + int ap_num = pc->ap_num; + bool set_recheck_ap_cur_target = false; + + LOG_INFO(MSG "Adding a TPIU \'%s.tpiu\' in the configuration", target_name(target)); + + if (ap_num == DP_APSEL_INVALID && transport_is_hla()) + ap_num = 0; /* HLA should only support AP 0 */ + + if (ap_num == DP_APSEL_INVALID && target_was_examined(target)) + ap_num = cm->armv7m.debug_ap->ap_num; + + if (ap_num == DP_APSEL_INVALID) { + LOG_INFO(MSG "Target %s uses AP autodetection. Adding TPIU on AP 0; can be revised later", + target_name(target)); + ap_num = 0; + set_recheck_ap_cur_target = true; + } + + LOG_INFO(MSG "Running: \'tpiu create %s.tpiu -dap %s -ap-num %d\'", + target_name(target), adiv5_dap_name(dap), ap_num); + + retval = command_run_linef(CMD_CTX, "tpiu create %s.tpiu -dap %s -ap-num %d", + target_name(target), adiv5_dap_name(dap), ap_num); + if (retval != ERROR_OK) + return retval; + + obj = list_first_entry(&all_tpiu_swo, typeof(*obj), lh); + if (set_recheck_ap_cur_target) + obj->recheck_ap_cur_target = true; + } + + unsigned int cmd_idx = 0; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + + if (!strcmp(CMD_ARGV[cmd_idx], "disable")) { + if (CMD_ARGC != cmd_idx + 1) + return ERROR_COMMAND_SYNTAX_ERROR; + LOG_INFO(MSG "Running: \'%s disable\'", obj->name); + return command_run_linef(CMD_CTX, "%s disable", obj->name); + } + + const char *output = NULL; + const char *protocol; + const char *formatter = NULL; + const char *port_width = NULL; + const char *trace_clk; + const char *pin_clk = NULL; + if (!strcmp(CMD_ARGV[cmd_idx], "internal")) { + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + output = CMD_ARGV[cmd_idx]; + } else if (strcmp(CMD_ARGV[cmd_idx], "external")) + return ERROR_COMMAND_SYNTAX_ERROR; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + if (!strcmp(CMD_ARGV[cmd_idx], "sync")) { + protocol = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + port_width = CMD_ARGV[cmd_idx]; + } else { + if (strcmp(CMD_ARGV[cmd_idx], "manchester") && strcmp(CMD_ARGV[cmd_idx], "uart")) + return ERROR_COMMAND_SYNTAX_ERROR; + protocol = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + formatter = CMD_ARGV[cmd_idx]; + } + cmd_idx++; + if (CMD_ARGC == cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + trace_clk = CMD_ARGV[cmd_idx]; + cmd_idx++; + if (CMD_ARGC != cmd_idx) { + pin_clk = CMD_ARGV[cmd_idx]; + cmd_idx++; + } + if (CMD_ARGC != cmd_idx) + return ERROR_COMMAND_SYNTAX_ERROR; + + LOG_INFO(MSG "Running: \'%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s\'", + obj->name, protocol, trace_clk, + pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "", + output ? " -output " : "", output ? output : "", + formatter ? " -formatter " : "", formatter ? formatter : "", + port_width ? " -port-width " : "", port_width ? port_width : ""); + + retval = command_run_linef(CMD_CTX, + "%s configure -protocol %s -traceclk %s" "%s%s" "%s%s" "%s%s" "%s%s", + obj->name, protocol, trace_clk, + pin_clk ? " -pin-freq " : "", pin_clk ? pin_clk : "", + output ? " -output " : "", output ? output : "", + formatter ? " -formatter " : "", formatter ? formatter : "", + port_width ? " -port-width " : "", port_width ? port_width : ""); + if (retval != ERROR_OK) + return retval; + + LOG_INFO(MSG "Running: \'%s enable\'", obj->name); + retval = command_run_linef(CMD_CTX, "%s enable", obj->name); + if (retval != ERROR_OK) + return retval; + + target_handle_event(target, TARGET_EVENT_TRACE_CONFIG); + return ERROR_OK; +} + +static const struct command_registration arm_tpiu_deprecated_subcommand_handlers[] = { + { + .name = "config", + .handler = handle_tpiu_deprecated_config_command, + .mode = COMMAND_ANY, + .help = "Configure TPIU features, DEPRECATED, use \'tpiu create\'", + .usage = "(disable | " + "((external | internal ( | <:port> | -)) " + "(sync | ((manchester | uart) )) " + " []))", + }, + COMMAND_REGISTRATION_DONE +}; + +const struct command_registration arm_tpiu_deprecated_command_handlers[] = { + { + .name = "tpiu", + .chain = arm_tpiu_deprecated_subcommand_handlers, + .usage = "", + .help = "tpiu command group", + }, + COMMAND_REGISTRATION_DONE +}; +/* END_DEPRECATED_TPIU */ + static const struct command_registration arm_tpiu_swo_subcommand_handlers[] = { { .name = "create", diff --git a/src/target/arm_tpiu_swo.h b/src/target/arm_tpiu_swo.h index e0aed71cb..5904ce291 100644 --- a/src/target/arm_tpiu_swo.h +++ b/src/target/arm_tpiu_swo.h @@ -3,6 +3,18 @@ #ifndef OPENOCD_TARGET_ARM_TPIU_SWO_H #define OPENOCD_TARGET_ARM_TPIU_SWO_H +/* Values should match TPIU_SPPR_PROTOCOL_xxx */ +enum tpiu_pin_protocol { + TPIU_PIN_PROTOCOL_SYNC = 0, /**< synchronous trace output */ + TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER = 1, /**< asynchronous output with Manchester coding */ + TPIU_PIN_PROTOCOL_ASYNC_UART = 2, /**< asynchronous output with NRZ coding */ +}; + +/* START_DEPRECATED_TPIU */ +/* DEPRECATED: emulation of old command 'tpiu config' */ +extern const struct command_registration arm_tpiu_deprecated_command_handlers[]; +/* END_DEPRECATED_TPIU */ + int arm_tpiu_swo_register_commands(struct command_context *cmd_ctx); int arm_tpiu_swo_cleanup_all(void); diff --git a/src/target/armv7m_trace.c b/src/target/armv7m_trace.c index 02f3f1061..74ffaf5a4 100644 --- a/src/target/armv7m_trace.c +++ b/src/target/armv7m_trace.c @@ -26,133 +26,6 @@ #include #include -#define TRACE_BUF_SIZE 4096 - -static int armv7m_poll_trace(void *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - uint8_t buf[TRACE_BUF_SIZE]; - size_t size = sizeof(buf); - int retval; - - retval = adapter_poll_trace(buf, &size); - if (retval != ERROR_OK || !size) - return retval; - - target_call_trace_callbacks(target, size, buf); - - switch (armv7m->trace_config.internal_channel) { - case TRACE_INTERNAL_CHANNEL_FILE: - if (armv7m->trace_config.trace_file != NULL) { - if (fwrite(buf, 1, size, armv7m->trace_config.trace_file) == size) - fflush(armv7m->trace_config.trace_file); - else { - LOG_ERROR("Error writing to the trace destination file"); - return ERROR_FAIL; - } - } - break; - case TRACE_INTERNAL_CHANNEL_TCP: - if (armv7m->trace_config.trace_service != NULL) { - /* broadcast to all service connections */ - struct connection *connection = armv7m->trace_config.trace_service->connections; - retval = ERROR_OK; - while (connection) { - if (connection_write(connection, buf, size) != (int) size) - retval = ERROR_FAIL; - - connection = connection->next; - } - - if (retval != ERROR_OK) { - LOG_ERROR("Error streaming the trace to TCP/IP port"); - return ERROR_FAIL; - } - } - break; - case TRACE_INTERNAL_CHANNEL_TCL_ONLY: - /* nothing to do : - * the trace data is sent to TCL by calling the target_call_trace_callbacks - **/ - break; - default: - LOG_ERROR("unsupported trace internal channel"); - return ERROR_FAIL; - } - - return ERROR_OK; -} - -int armv7m_trace_tpiu_config(struct target *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - struct armv7m_trace_config *trace_config = &armv7m->trace_config; - uint16_t prescaler = TPIU_ACPR_MAX_SWOSCALER + 1; - int retval; - - target_unregister_timer_callback(armv7m_poll_trace, target); - - retval = adapter_config_trace(trace_config->config_type == TRACE_CONFIG_TYPE_INTERNAL, - trace_config->pin_protocol, trace_config->port_size, - &trace_config->trace_freq, trace_config->traceclkin_freq, &prescaler); - - if (retval != ERROR_OK) - return retval; - - if (trace_config->config_type == TRACE_CONFIG_TYPE_EXTERNAL) { - prescaler = trace_config->traceclkin_freq / trace_config->trace_freq; - - if (trace_config->traceclkin_freq % trace_config->trace_freq) { - prescaler++; - - int trace_freq = trace_config->traceclkin_freq / prescaler; - LOG_INFO("Can not obtain %u trace port frequency from %u " - "TRACECLKIN frequency, using %u instead", - trace_config->trace_freq, trace_config->traceclkin_freq, - trace_freq); - - trace_config->trace_freq = trace_freq; - } - } - - if (!trace_config->trace_freq) { - LOG_ERROR("Trace port frequency is 0, can't enable TPIU"); - return ERROR_FAIL; - } - - retval = target_write_u32(target, TPIU_CSPSR, 1 << trace_config->port_size); - if (retval != ERROR_OK) - return retval; - - retval = target_write_u32(target, TPIU_ACPR, prescaler - 1); - if (retval != ERROR_OK) - return retval; - - retval = target_write_u32(target, TPIU_SPPR, trace_config->pin_protocol); - if (retval != ERROR_OK) - return retval; - - uint32_t ffcr; - retval = target_read_u32(target, TPIU_FFCR, &ffcr); - if (retval != ERROR_OK) - return retval; - if (trace_config->formatter) - ffcr |= (1 << 1); - else - ffcr &= ~(1 << 1); - retval = target_write_u32(target, TPIU_FFCR, ffcr); - if (retval != ERROR_OK) - return retval; - - if (trace_config->config_type == TRACE_CONFIG_TYPE_INTERNAL) - target_register_timer_callback(armv7m_poll_trace, 1, - TARGET_TIMER_TYPE_PERIODIC, target); - - target_call_event_callbacks(target, TARGET_EVENT_TRACE_CONFIG); - - return ERROR_OK; -} - int armv7m_trace_itm_config(struct target *target) { struct armv7m_common *armv7m = target_to_armv7m(target); @@ -210,182 +83,6 @@ int armv7m_trace_itm_config(struct target *target) return ERROR_OK; } -static void close_trace_channel(struct armv7m_common *armv7m) -{ - switch (armv7m->trace_config.internal_channel) { - case TRACE_INTERNAL_CHANNEL_FILE: - if (armv7m->trace_config.trace_file) - fclose(armv7m->trace_config.trace_file); - armv7m->trace_config.trace_file = NULL; - break; - case TRACE_INTERNAL_CHANNEL_TCP: - if (armv7m->trace_config.trace_service) - remove_service(armv7m->trace_config.trace_service->name, armv7m->trace_config.trace_service->port); - armv7m->trace_config.trace_service = NULL; - break; - case TRACE_INTERNAL_CHANNEL_TCL_ONLY: - /* nothing to do: - * the trace polling is disabled in the beginning of armv7m_trace_tpiu_config - **/ - break; - default: - LOG_ERROR("unsupported trace internal channel"); - } -} - -static int trace_new_connection(struct connection *connection) -{ - /* nothing to do */ - return ERROR_OK; -} - -static int trace_input(struct connection *connection) -{ - /* create a dummy buffer to check if the connection is still active */ - const int buf_len = 100; - unsigned char buf[buf_len]; - int bytes_read = connection_read(connection, buf, buf_len); - - if (bytes_read == 0) - return ERROR_SERVER_REMOTE_CLOSED; - else if (bytes_read == -1) { - LOG_ERROR("error during read: %s", strerror(errno)); - return ERROR_SERVER_REMOTE_CLOSED; - } - - return ERROR_OK; -} - -static int trace_connection_closed(struct connection *connection) -{ - /* nothing to do, no connection->priv to free */ - return ERROR_OK; -} - -extern struct command_context *global_cmd_ctx; - -int armv7m_trace_tpiu_exit(struct target *target) -{ - struct armv7m_common *armv7m = target_to_armv7m(target); - - if (global_cmd_ctx->mode == COMMAND_CONFIG || - armv7m->trace_config.config_type == TRACE_CONFIG_TYPE_DISABLED) - return ERROR_OK; - - close_trace_channel(armv7m); - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_DISABLED; - return armv7m_trace_tpiu_config(target); -} - -COMMAND_HANDLER(handle_tpiu_config_command) -{ - struct target *target = get_current_target(CMD_CTX); - struct armv7m_common *armv7m = target_to_armv7m(target); - - unsigned int cmd_idx = 0; - - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - if (!strcmp(CMD_ARGV[cmd_idx], "disable")) { - if (CMD_ARGC == cmd_idx + 1) { - close_trace_channel(armv7m); - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_DISABLED; - if (CMD_CTX->mode == COMMAND_EXEC) - return armv7m_trace_tpiu_config(target); - else - return ERROR_OK; - } - } else if (!strcmp(CMD_ARGV[cmd_idx], "external") || - !strcmp(CMD_ARGV[cmd_idx], "internal")) { - close_trace_channel(armv7m); - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_EXTERNAL; - if (!strcmp(CMD_ARGV[cmd_idx], "internal")) { - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - armv7m->trace_config.config_type = TRACE_CONFIG_TYPE_INTERNAL; - armv7m->trace_config.internal_channel = TRACE_INTERNAL_CHANNEL_TCL_ONLY; - - if (strcmp(CMD_ARGV[cmd_idx], "-") != 0) { - if (CMD_ARGV[cmd_idx][0] == ':') { - armv7m->trace_config.internal_channel = TRACE_INTERNAL_CHANNEL_TCP; - - int ret = add_service("armv7m_trace", &(CMD_ARGV[cmd_idx][1]), - CONNECTION_LIMIT_UNLIMITED, trace_new_connection, trace_input, - trace_connection_closed, NULL, &armv7m->trace_config.trace_service); - if (ret != ERROR_OK) { - LOG_ERROR("Can't configure trace TCP port"); - return ERROR_FAIL; - } - } else { - armv7m->trace_config.internal_channel = TRACE_INTERNAL_CHANNEL_FILE; - armv7m->trace_config.trace_file = fopen(CMD_ARGV[cmd_idx], "ab"); - if (!armv7m->trace_config.trace_file) { - LOG_ERROR("Can't open trace destination file"); - return ERROR_FAIL; - } - } - } - } - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - if (!strcmp(CMD_ARGV[cmd_idx], "sync")) { - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_SYNC; - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[cmd_idx], armv7m->trace_config.port_size); - } else { - if (!strcmp(CMD_ARGV[cmd_idx], "manchester")) - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER; - else if (!strcmp(CMD_ARGV[cmd_idx], "uart")) - armv7m->trace_config.pin_protocol = TPIU_PIN_PROTOCOL_ASYNC_UART; - else - return ERROR_COMMAND_SYNTAX_ERROR; - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_ON_OFF(CMD_ARGV[cmd_idx], armv7m->trace_config.formatter); - } - - cmd_idx++; - if (CMD_ARGC == cmd_idx) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(uint, CMD_ARGV[cmd_idx], armv7m->trace_config.traceclkin_freq); - - cmd_idx++; - if (CMD_ARGC != cmd_idx) { - COMMAND_PARSE_NUMBER(uint, CMD_ARGV[cmd_idx], armv7m->trace_config.trace_freq); - cmd_idx++; - } else { - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_INTERNAL) { - LOG_ERROR("Trace port frequency can't be omitted in external capture mode"); - return ERROR_COMMAND_SYNTAX_ERROR; - } - armv7m->trace_config.trace_freq = 0; - } - - if (CMD_ARGC == cmd_idx) { - if (CMD_CTX->mode == COMMAND_EXEC) - return armv7m_trace_tpiu_config(target); - else - return ERROR_OK; - } - } - - return ERROR_COMMAND_SYNTAX_ERROR; -} - COMMAND_HANDLER(handle_itm_port_command) { struct target *target = get_current_target(CMD_CTX); @@ -433,20 +130,6 @@ COMMAND_HANDLER(handle_itm_ports_command) return ERROR_OK; } -static const struct command_registration tpiu_command_handlers[] = { - { - .name = "config", - .handler = handle_tpiu_config_command, - .mode = COMMAND_ANY, - .help = "Configure TPIU features", - .usage = "(disable | " - "((external | internal ( | <:port> | -)) " - "(sync | ((manchester | uart) )) " - " []))", - }, - COMMAND_REGISTRATION_DONE -}; - static const struct command_registration itm_command_handlers[] = { { .name = "port", @@ -466,13 +149,6 @@ static const struct command_registration itm_command_handlers[] = { }; const struct command_registration armv7m_trace_command_handlers[] = { - { - .name = "tpiu", - .mode = COMMAND_ANY, - .help = "tpiu command group", - .usage = "", - .chain = tpiu_command_handlers, - }, { .name = "itm", .mode = COMMAND_ANY, diff --git a/src/target/armv7m_trace.h b/src/target/armv7m_trace.h index 61142b1e3..eaee6a48f 100644 --- a/src/target/armv7m_trace.h +++ b/src/target/armv7m_trace.h @@ -18,33 +18,14 @@ #ifndef OPENOCD_TARGET_ARMV7M_TRACE_H #define OPENOCD_TARGET_ARMV7M_TRACE_H -#include #include #include /** * @file - * Holds the interface to TPIU, ITM and DWT configuration functions. + * Holds the interface to ITM and DWT configuration functions. */ -enum trace_config_type { - TRACE_CONFIG_TYPE_DISABLED, /**< tracing is disabled */ - TRACE_CONFIG_TYPE_EXTERNAL, /**< trace output is captured externally */ - TRACE_CONFIG_TYPE_INTERNAL /**< trace output is handled by OpenOCD adapter driver */ -}; - -enum trace_internal_channel { - TRACE_INTERNAL_CHANNEL_TCL_ONLY, /** trace data is sent only to 'tcl_trace' */ - TRACE_INTERNAL_CHANNEL_FILE, /** trace data is appended to a file */ - TRACE_INTERNAL_CHANNEL_TCP /** trace data is appended to a TCP/IP port*/ -}; - -enum tpiu_pin_protocol { - TPIU_PIN_PROTOCOL_SYNC, /**< synchronous trace output */ - TPIU_PIN_PROTOCOL_ASYNC_MANCHESTER, /**< asynchronous output with Manchester coding */ - TPIU_PIN_PROTOCOL_ASYNC_UART /**< asynchronous output with NRZ coding */ -}; - enum itm_ts_prescaler { ITM_TS_PRESCALE1, /**< no prescaling for the timestamp counter */ ITM_TS_PRESCALE4, /**< refclock divided by 4 for the timestamp counter */ @@ -53,19 +34,6 @@ enum itm_ts_prescaler { }; struct armv7m_trace_config { - /** Currently active trace capture mode */ - enum trace_config_type config_type; - - /** The used channel when internal mode is selected */ - enum trace_internal_channel internal_channel; - - /** Currently active trace output mode */ - enum tpiu_pin_protocol pin_protocol; - /** TPIU formatter enable/disable (in async mode) */ - bool formatter; - /** Synchronous output port width */ - uint32_t port_size; - /** Bitmask of currently enabled ITM stimuli */ uint32_t itm_ter[8]; /** Identifier for multi-source trace stream formatting */ @@ -80,27 +48,10 @@ struct armv7m_trace_config { bool itm_synchro_packets; /** Config ITM after target examine */ bool itm_deferred_config; - - /** Current frequency of TRACECLKIN (usually matches HCLK) */ - unsigned int traceclkin_freq; - /** Current frequency of trace port */ - unsigned int trace_freq; - /** Handle to output trace data in INTERNAL capture mode via file */ - FILE *trace_file; - /** Handle to output trace data in INTERNAL capture mode via tcp */ - struct service *trace_service; }; extern const struct command_registration armv7m_trace_command_handlers[]; -/** - * Configure hardware accordingly to the current TPIU target settings - */ -int armv7m_trace_tpiu_config(struct target *target); -/** - * Disable TPIU data gathering at exit - */ -int armv7m_trace_tpiu_exit(struct target *target); /** * Configure hardware accordingly to the current ITM target settings */ diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 4580c10ff..b998b7ac7 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -1648,8 +1648,6 @@ void cortex_m_deinit_target(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); - armv7m_trace_tpiu_exit(target); - free(cortex_m->fp_comparator_list); cortex_m_dwt_free(target); @@ -2082,9 +2080,6 @@ int cortex_m_examine(struct target *target) if (retval != ERROR_OK) return retval; - if (armv7m->trace_config.config_type != TRACE_CONFIG_TYPE_DISABLED) - armv7m_trace_tpiu_config(target); - if (armv7m->trace_config.itm_deferred_config) armv7m_trace_itm_config(target); @@ -2486,6 +2481,11 @@ static const struct command_registration cortex_m_command_handlers[] = { { .chain = armv7m_trace_command_handlers, }, + /* START_DEPRECATED_TPIU */ + { + .chain = arm_tpiu_deprecated_command_handlers, + }, + /* END_DEPRECATED_TPIU */ { .name = "cortex_m", .mode = COMMAND_EXEC, diff --git a/src/target/hla_target.c b/src/target/hla_target.c index 3d41387fd..ca8b5874a 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -630,6 +630,11 @@ static const struct command_registration adapter_command_handlers[] = { { .chain = rtt_target_command_handlers, }, + /* START_DEPRECATED_TPIU */ + { + .chain = arm_tpiu_deprecated_command_handlers, + }, + /* END_DEPRECATED_TPIU */ COMMAND_REGISTRATION_DONE }; diff --git a/src/target/target.c b/src/target/target.c index fe519f2ab..eb83daebb 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -4945,6 +4945,11 @@ no_params: } if (goi->isconfigure) { + /* START_DEPRECATED_TPIU */ + if (n->value == TARGET_EVENT_TRACE_CONFIG) + LOG_INFO("DEPRECATED target event %s", n->name); + /* END_DEPRECATED_TPIU */ + bool replace = true; if (teap == NULL) { /* create new */ From cb8e3fb2d925c6563c3520391c3b1c7e71d1b817 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 13 Nov 2020 23:39:26 +0100 Subject: [PATCH 061/120] server: revert commit 7e6556b3cad8 With the removal of old tpiu code, commit 7e6556b3cad8 ("server: permit the add_service function to return the created service") http://openocd.zylin.com/5717/ can be reverted. Fix also the new calls to add_service(). Change-Id: Ib7f2dfc6a9e829239e20313e0f121911085fdc00 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6031 Tested-by: jenkins Reviewed-by: Adrian M Negreanu --- src/server/gdb_server.c | 2 +- src/server/rtt_server.c | 2 +- src/server/server.c | 7 +------ src/server/server.h | 2 +- src/server/tcl_server.c | 2 +- src/server/telnet_server.c | 2 +- src/target/arm_tpiu_swo.c | 2 +- src/target/openrisc/jsp_server.c | 3 +-- 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index 9e44287fd..fc58971a7 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -3509,7 +3509,7 @@ static int gdb_target_start(struct target *target, const char *port) ret = add_service("gdb", port, target->gdb_max_connections, &gdb_new_connection, &gdb_input, - &gdb_connection_closed, gdb_service, NULL); + &gdb_connection_closed, gdb_service); /* initialize all targets gdb service with the same pointer */ { struct target_list *head; diff --git a/src/server/rtt_server.c b/src/server/rtt_server.c index 3c885cce0..d49e4d000 100644 --- a/src/server/rtt_server.c +++ b/src/server/rtt_server.c @@ -126,7 +126,7 @@ COMMAND_HANDLER(handle_rtt_start_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[1], service->channel); ret = add_service("rtt", CMD_ARGV[0], CONNECTION_LIMIT_UNLIMITED, - rtt_new_connection, rtt_input, rtt_connection_closed, service, NULL); + rtt_new_connection, rtt_input, rtt_connection_closed, service); if (ret != ERROR_OK) { free(service); diff --git a/src/server/server.c b/src/server/server.c index 114af7632..e53f37d0b 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -210,8 +210,7 @@ int add_service(char *name, new_connection_handler_t new_connection_handler, input_handler_t input_handler, connection_closed_handler_t connection_closed_handler, - void *priv, - struct service **new_service) + void *priv) { struct service *c, **p; struct hostent *hp; @@ -347,10 +346,6 @@ int add_service(char *name, ; *p = c; - /* if new_service is not NULL, return the created service into it */ - if (new_service) - *new_service = c; - return ERROR_OK; } diff --git a/src/server/server.h b/src/server/server.h index 99f5fe2ed..ff2ada9cb 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -77,7 +77,7 @@ struct service { int add_service(char *name, const char *port, int max_connections, new_connection_handler_t new_connection_handler, input_handler_t in_handler, connection_closed_handler_t close_handler, - void *priv, struct service **new_service); + void *priv); int remove_service(const char *name, const char *port); int server_host_os_entry(void); diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 07213ae79..1ecb827a1 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -285,7 +285,7 @@ int tcl_init(void) return add_service("tcl", tcl_port, CONNECTION_LIMIT_UNLIMITED, &tcl_new_connection, &tcl_input, - &tcl_closed, NULL, NULL); + &tcl_closed, NULL); } COMMAND_HANDLER(handle_tcl_port_command) diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index 4f88d3a54..407ab68ae 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -694,7 +694,7 @@ int telnet_init(char *banner) int ret = add_service("telnet", telnet_port, CONNECTION_LIMIT_UNLIMITED, telnet_new_connection, telnet_input, telnet_connection_closed, - telnet_service, NULL); + telnet_service); if (ret != ERROR_OK) { free(telnet_service); diff --git a/src/target/arm_tpiu_swo.c b/src/target/arm_tpiu_swo.c index b492438d4..2da52e892 100644 --- a/src/target/arm_tpiu_swo.c +++ b/src/target/arm_tpiu_swo.c @@ -697,7 +697,7 @@ static int jim_arm_tpiu_swo_enable(Jim_Interp *interp, int argc, Jim_Obj *const retval = add_service("tpiu_swo_trace", &obj->out_filename[1], CONNECTION_LIMIT_UNLIMITED, arm_tpiu_swo_service_new_connection, arm_tpiu_swo_service_input, arm_tpiu_swo_service_connection_closed, - priv, NULL); + priv); if (retval != ERROR_OK) { LOG_ERROR("Can't configure trace TCP port %s", &obj->out_filename[1]); return JIM_ERR; diff --git a/src/target/openrisc/jsp_server.c b/src/target/openrisc/jsp_server.c index b4b25665d..4dbe63527 100644 --- a/src/target/openrisc/jsp_server.c +++ b/src/target/openrisc/jsp_server.c @@ -207,8 +207,7 @@ int jsp_init(struct or1k_jtag *jtag_info, char *banner) jsp_new_connection, jsp_input, jsp_connection_closed, - jsp_service, - NULL); + jsp_service); } COMMAND_HANDLER(handle_jsp_port_command) From 5e57090203b36465c2f0560b92ca58cafb2c9e0b Mon Sep 17 00:00:00 2001 From: Felipe Balbi Date: Thu, 4 Feb 2021 14:50:15 +0200 Subject: [PATCH 062/120] Add configuration file for Olimex H405 Change-Id: I34a030f65ebe041408655ea9792346b146bd1092 Signed-off-by: Felipe Balbi Reviewed-on: http://openocd.zylin.com/6049 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/board/olimex_stm32_h405.cfg | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 tcl/board/olimex_stm32_h405.cfg diff --git a/tcl/board/olimex_stm32_h405.cfg b/tcl/board/olimex_stm32_h405.cfg new file mode 100644 index 000000000..f2f1d7f24 --- /dev/null +++ b/tcl/board/olimex_stm32_h405.cfg @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Olimex STM32-H405 eval board +# https://www.olimex.com/Products/ARM/ST/STM32-H405/ + +# Work-area size (RAM size) = 128kB for STM32F405RG device +set WORKAREASIZE 0x20000 + +source [find target/stm32f4x.cfg] From bc0c9907d6ba9a39a953482a2bb2195504999427 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Fri, 12 Feb 2021 21:12:43 +0100 Subject: [PATCH 063/120] cortex_m: avoid reading and writing non-existent registers Change-Id: Iedc24352c8d3444372da06d00fcec9603540f950 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6059 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/armv7m.c | 8 ++++---- src/target/cortex_m.c | 2 +- src/target/hla_target.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/target/armv7m.c b/src/target/armv7m.c index f14ce0d88..101094a97 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -166,10 +166,10 @@ int armv7m_restore_context(struct target *target) * packing of ARMV7M_PMSK_BPRI_FLTMSK_CTRL! * See also comments in the register table above */ for (i = cache->num_regs - 1; i >= 0; i--) { - if (cache->reg_list[i].dirty) { - armv7m->arm.write_core_reg(target, &cache->reg_list[i], i, - ARM_MODE_ANY, cache->reg_list[i].value); - } + struct reg *r = &cache->reg_list[i]; + + if (r->exist && r->dirty) + armv7m->arm.write_core_reg(target, r, i, ARM_MODE_ANY, r->value); } return ERROR_OK; diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index b998b7ac7..2a973e1f6 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -521,7 +521,7 @@ static int cortex_m_debug_entry(struct target *target) for (i = 0; i < num_regs; i++) { r = &armv7m->arm.core_cache->reg_list[i]; - if (!r->valid) + if (r->exist && !r->valid) arm->read_core_reg(target, r, i, ARM_MODE_ANY); } diff --git a/src/target/hla_target.c b/src/target/hla_target.c index ca8b5874a..9ac344245 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -226,7 +226,7 @@ static int adapter_load_context(struct target *target) for (int i = 0; i < num_regs; i++) { struct reg *r = &armv7m->arm.core_cache->reg_list[i]; - if (!r->valid) + if (r->exist && !r->valid) armv7m->arm.read_core_reg(target, r, i, ARM_MODE_ANY); } From a2569438380566a8eee339006f1923d4c147850d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 13 Feb 2021 14:40:18 +0100 Subject: [PATCH 064/120] jtag/nulink: add a space after PRIx32 Missing the space cause the hex value to be printed together with the following field. Add a space after PRIx32. Change-Id: I95824a9a8b8c0ad911d6c31f732d926cb3e0c068 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6060 Tested-by: jenkins Reviewed-by: Jonathan McDowell --- src/jtag/drivers/nulink_usb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jtag/drivers/nulink_usb.c b/src/jtag/drivers/nulink_usb.c index 00738ee4e..48a5c792e 100644 --- a/src/jtag/drivers/nulink_usb.c +++ b/src/jtag/drivers/nulink_usb.c @@ -253,7 +253,7 @@ static int nulink_usb_write_debug_reg(void *handle, uint32_t addr, uint32_t val) { struct nulink_usb_handle_s *h = handle; - LOG_DEBUG("nulink_usb_write_debug_reg 0x%08" PRIX32 "0x%08" PRIX32, addr, val); + LOG_DEBUG("nulink_usb_write_debug_reg 0x%08" PRIX32 " 0x%08" PRIX32, addr, val); nulink_usb_init_buffer(handle, 8 + 12 * 1); /* set command ID */ @@ -503,7 +503,7 @@ static int nulink_usb_read_mem8(void *handle, uint32_t addr, uint16_t len, aligned_addr = aligned_addr * 4; offset = addr - aligned_addr; LOG_DEBUG("nulink_usb_read_mem8: unaligned address addr 0x%08" PRIx32 - "/aligned addr 0x%08" PRIx32 "offset %" PRIu32, + "/aligned addr 0x%08" PRIx32 " offset %" PRIu32, addr, aligned_addr, offset); addr = aligned_addr; From 8132b77d612e88167e8f0c7bdc6aa9df3661fd4e Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 13 Feb 2021 23:28:16 +0100 Subject: [PATCH 065/120] stlink: swo: use completely the available buffer The buffer passed to stlink_usb_trace_read() is allocated of size *size and does not need to be zero-terminated. There is no reason to not fill its last byte. When checking the bytes available on swo, limit the retrieved byte length to *size. Change-Id: Iade0f8963118695931f13a8a3f1ab204911236b6 Signed-off-by: Antonio Borneo Reported-by: Adrian Negreanu Reviewed-on: http://openocd.zylin.com/6061 Tested-by: jenkins Reviewed-by: Adrian M Negreanu Reviewed-by: Tarek BOCHKATI --- src/jtag/drivers/stlink_usb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jtag/drivers/stlink_usb.c b/src/jtag/drivers/stlink_usb.c index 73169e1e4..a5f8bdff1 100644 --- a/src/jtag/drivers/stlink_usb.c +++ b/src/jtag/drivers/stlink_usb.c @@ -1967,7 +1967,7 @@ static int stlink_usb_trace_read(void *handle, uint8_t *buf, size_t *size) return res; size_t bytes_avail = le_to_h_u16(h->databuf); - *size = bytes_avail < *size ? bytes_avail : *size - 1; + *size = bytes_avail < *size ? bytes_avail : *size; if (*size > 0) { res = stlink_usb_read_trace(handle, buf, *size); From 210b7d2d1644c5c3dd1e59ffa684af56e3be498f Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 1 Feb 2021 21:23:35 +0100 Subject: [PATCH 066/120] flash/nor/stmqspi: Replace macros with static inline functions There is no good reason to use macros instead of static inline functions. The current code is hard maintain. For example, it changes variables outside of the macro scope. Also, it is conflicting with the C coding style. Change-Id: I5ac9d2ae076ef73c176d4e32b2e7e0a99fa875ab Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6046 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/flash/nor/stmqspi.c | 229 +++++++++++++++++++++++----------------- 1 file changed, 132 insertions(+), 97 deletions(-) diff --git a/src/flash/nor/stmqspi.c b/src/flash/nor/stmqspi.c index a013336a0..11aa43898 100644 --- a/src/flash/nor/stmqspi.c +++ b/src/flash/nor/stmqspi.c @@ -52,14 +52,6 @@ #undef SPIFLASH_READ #undef SPIFLASH_PAGE_PROGRAM -#define READ_REG(a) \ -({ \ - uint32_t _result; \ - \ - retval = target_read_u32(target, io_base + (a), &_result); \ - (retval == ERROR_OK) ? _result : 0x0; \ -}) - /* saved mode settings */ #define QSPI_MODE (stmqspi_info->saved_ccr & \ (0xF0000000U | QSPI_DCYC_MASK | QSPI_4LINE_MODE | QSPI_ALTB_MODE | QSPI_ADDR4)) @@ -156,23 +148,6 @@ #define OPI_CMD(cmd) ((OPI_MODE ? ((((uint16_t)(cmd)) << 8) | (~(cmd) & 0xFFU)) : (cmd))) -#define OCTOSPI_CMD(mode, ccr, ir) \ -({ \ - retval = target_write_u32(target, io_base + OCTOSPI_CR, \ - OCTOSPI_MODE | (mode)); \ - if (retval == ERROR_OK) \ - retval = target_write_u32(target, io_base + OCTOSPI_TCR, \ - (stmqspi_info->saved_tcr & ~OCTOSPI_DCYC_MASK) | \ - ((OPI_MODE && ((mode) == OCTOSPI_READ_MODE)) ? \ - (OPI_DUMMY << OCTOSPI_DCYC_POS) : 0)); \ - if (retval == ERROR_OK) \ - retval = target_write_u32(target, io_base + OCTOSPI_CCR, ccr); \ - if (retval == ERROR_OK) \ - retval = target_write_u32(target, io_base + OCTOSPI_IR, \ - OPI_CMD(ir)); \ - retval; \ -}) - /* convert uint32_t into 4 uint8_t in little endian byte order */ static inline uint32_t h_to_le_32(uint32_t val) { @@ -208,6 +183,35 @@ struct stmqspi_flash_bank { unsigned int sfdp_dummy2; /* number of dummy bytes for SFDP read for flash2 */ }; +static inline int octospi_cmd(struct flash_bank *bank, uint32_t mode, + uint32_t ccr, uint32_t ir) +{ + struct target *target = bank->target; + const struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; + const uint32_t io_base = stmqspi_info->io_base; + + int retval = target_write_u32(target, io_base + OCTOSPI_CR, + OCTOSPI_MODE | mode); + + if (retval != ERROR_OK) + return retval; + + retval = target_write_u32(target, io_base + OCTOSPI_TCR, + (stmqspi_info->saved_tcr & ~OCTOSPI_DCYC_MASK) | + ((OPI_MODE && (mode == OCTOSPI_READ_MODE)) ? + (OPI_DUMMY << OCTOSPI_DCYC_POS) : 0)); + + if (retval != ERROR_OK) + return retval; + + retval = target_write_u32(target, io_base + OCTOSPI_CCR, ccr); + + if (retval != ERROR_OK) + return retval; + + return target_write_u32(target, io_base + OCTOSPI_IR, OPI_CMD(ir)); +} + FLASH_BANK_COMMAND_HANDLER(stmqspi_flash_bank_command) { struct stmqspi_flash_bank *stmqspi_info; @@ -242,19 +246,19 @@ static int poll_busy(struct flash_bank *bank, int timeout) struct target *target = bank->target; struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; uint32_t io_base = stmqspi_info->io_base; - uint32_t spi_sr; - int retval; long long endtime; endtime = timeval_ms() + timeout; do { - spi_sr = READ_REG(SPI_SR); - if ((spi_sr & BIT(SPI_BUSY)) == 0) { - if (retval == ERROR_OK) { - /* Clear transmit finished flag */ - retval = target_write_u32(target, io_base + SPI_FCR, BIT(SPI_TCF)); - } + uint32_t spi_sr; + int retval = target_read_u32(target, io_base + SPI_SR, &spi_sr); + + if (retval != ERROR_OK) return retval; + + if ((spi_sr & BIT(SPI_BUSY)) == 0) { + /* Clear transmit finished flag */ + return target_write_u32(target, io_base + SPI_FCR, BIT(SPI_TCF)); } else LOG_DEBUG("busy: 0x%08X", spi_sr); alive_sleep(1); @@ -264,6 +268,21 @@ static int poll_busy(struct flash_bank *bank, int timeout) return ERROR_FLASH_OPERATION_FAILED; } +static int stmqspi_abort(struct flash_bank *bank) +{ + struct target *target = bank->target; + const struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; + const uint32_t io_base = stmqspi_info->io_base; + uint32_t cr; + + int retval = target_read_u32(target, io_base + SPI_CR, &cr); + + if (retval != ERROR_OK) + cr = 0; + + return target_write_u32(target, io_base + SPI_CR, cr | BIT(SPI_ABORT)); +} + /* Set to memory-mapped mode, e.g. after an error */ static int set_mm_mode(struct flash_bank *bank) { @@ -278,8 +297,7 @@ static int set_mm_mode(struct flash_bank *bank) return retval; /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -321,8 +339,7 @@ static int read_status_reg(struct flash_bank *bank, uint16_t *status) int count, retval; /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -340,7 +357,8 @@ static int read_status_reg(struct flash_bank *bank, uint16_t *status) /* Read status */ if (IS_OCTOSPI) { - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_STATUS, SPIFLASH_READ_STATUS); + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_STATUS, + SPIFLASH_READ_STATUS); if (OPI_MODE) { /* Dummy address 0, only required for 8-line mode */ retval = target_write_u32(target, io_base + SPI_AR, 0); @@ -355,7 +373,8 @@ static int read_status_reg(struct flash_bank *bank, uint16_t *status) *status = 0; /* for debugging only */ - (void)READ_REG(SPI_SR); + uint32_t dummy; + (void)target_read_u32(target, io_base + SPI_SR, &dummy); for ( ; count > 0; --count) { if ((stmqspi_info->saved_cr & (BIT(SPI_DUAL_FLASH) | BIT(SPI_FSEL_FLASH))) @@ -416,8 +435,7 @@ static int qspi_write_enable(struct flash_bank *bank) int retval; /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -428,7 +446,8 @@ static int qspi_write_enable(struct flash_bank *bank) /* Send write enable command */ if (IS_OCTOSPI) { - retval = OCTOSPI_CMD(OCTOSPI_WRITE_MODE, OCTOSPI_CCR_WRITE_ENABLE, SPIFLASH_WRITE_ENABLE); + retval = octospi_cmd(bank, OCTOSPI_WRITE_MODE, OCTOSPI_CCR_WRITE_ENABLE, + SPIFLASH_WRITE_ENABLE); if (OPI_MODE) { /* Dummy address 0, only required for 8-line mode */ retval = target_write_u32(target, io_base + SPI_AR, 0); @@ -527,7 +546,7 @@ COMMAND_HANDLER(stmqspi_handle_mass_erase_command) /* Send Mass Erase command */ if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_WRITE_MODE, OCTOSPI_CCR_MASS_ERASE, + retval = octospi_cmd(bank, OCTOSPI_WRITE_MODE, OCTOSPI_CCR_MASS_ERASE, stmqspi_info->dev.chip_erase_cmd); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_MASS_ERASE); @@ -714,10 +733,15 @@ COMMAND_HANDLER(stmqspi_handle_set) bank->size = stmqspi_info->dev.size_in_bytes << dual; io_base = stmqspi_info->io_base; - fsize = (READ_REG(SPI_DCR) >> SPI_FSIZE_POS) & (BIT(SPI_FSIZE_LEN) - 1); + + uint32_t dcr; + retval = target_read_u32(target, io_base + SPI_DCR, &dcr); + if (retval != ERROR_OK) return retval; + fsize = (dcr >> SPI_FSIZE_POS) & (BIT(SPI_FSIZE_LEN) - 1); + LOG_DEBUG("FSIZE = 0x%04x", fsize); if (bank->size == BIT(fsize + 1)) LOG_DEBUG("FSIZE in DCR(1) matches actual capacity. Beware of silicon bug in H7, L4+, MP1."); @@ -823,8 +847,7 @@ COMMAND_HANDLER(stmqspi_handle_cmd) } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -842,7 +865,7 @@ COMMAND_HANDLER(stmqspi_handle_cmd) goto err; if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_WRITE_MODE, + retval = octospi_cmd(bank, OCTOSPI_WRITE_MODE, (OCTOSPI_MODE_CCR & OCTOSPI_NO_ALTB & OCTOSPI_NO_ADDR & ((num_write == 1) ? OCTOSPI_NO_DATA : ~0U)), cmd_byte); else @@ -879,7 +902,7 @@ COMMAND_HANDLER(stmqspi_handle_cmd) if (retval != ERROR_OK) goto err; if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, (OCTOSPI_MODE_CCR & OCTOSPI_NO_DDTR & OCTOSPI_NO_ALTB & ~OCTOSPI_ADDR4 & ((num_write == 1) ? OCTOSPI_NO_ADDR : ~0U)) | (((num_write - 2) & 0x3U) << SPI_ADSIZE_POS), cmd_byte); @@ -930,7 +953,7 @@ static int qspi_erase_sector(struct flash_bank *bank, unsigned int sector) /* Send Sector Erase command */ if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_WRITE_MODE, OCTOSPI_CCR_SECTOR_ERASE, + retval = octospi_cmd(bank, OCTOSPI_WRITE_MODE, OCTOSPI_CCR_SECTOR_ERASE, stmqspi_info->dev.erase_cmd); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_SECTOR_ERASE); @@ -1059,7 +1082,6 @@ static int stmqspi_blank_check(struct flash_bank *bank) { struct target *target = bank->target; struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; - uint32_t io_base = stmqspi_info->io_base; struct duration bench; struct reg_param reg_params[2]; struct armv7m_algorithm armv7m_info; @@ -1082,8 +1104,7 @@ static int stmqspi_blank_check(struct flash_bank *bank) } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -1568,7 +1589,6 @@ static int stmqspi_read(struct flash_bank *bank, uint8_t *buffer, { struct target *target = bank->target; struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; - uint32_t io_base = stmqspi_info->io_base; int retval; LOG_DEBUG("%s: offset=0x%08" PRIx32 " count=0x%08" PRIx32, @@ -1590,8 +1610,7 @@ static int stmqspi_read(struct flash_bank *bank, uint8_t *buffer, } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -1608,7 +1627,6 @@ static int stmqspi_write(struct flash_bank *bank, const uint8_t *buffer, { struct target *target = bank->target; struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; - uint32_t io_base = stmqspi_info->io_base; unsigned int dual, sector; bool octal_dtr; int retval; @@ -1653,8 +1671,7 @@ static int stmqspi_write(struct flash_bank *bank, const uint8_t *buffer, } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -1671,7 +1688,6 @@ static int stmqspi_verify(struct flash_bank *bank, const uint8_t *buffer, { struct target *target = bank->target; struct stmqspi_flash_bank *stmqspi_info = bank->driver_priv; - uint32_t io_base = stmqspi_info->io_base; unsigned int dual; bool octal_dtr; int retval; @@ -1704,8 +1720,7 @@ static int stmqspi_verify(struct flash_bank *bank, const uint8_t *buffer, } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -1757,8 +1772,8 @@ static int find_sfdp_dummy(struct flash_bank *bank, int len) /* Read SFDP block */ if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_SFDP(len), - SPIFLASH_READ_SFDP); + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, + OCTOSPI_CCR_READ_SFDP(len), SPIFLASH_READ_SFDP); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_READ_SFDP); if (retval != ERROR_OK) @@ -1804,8 +1819,7 @@ static int find_sfdp_dummy(struct flash_bank *bank, int len) err: /* Abort operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); return retval; } @@ -1880,8 +1894,8 @@ static int read_sfdp_block(struct flash_bank *bank, uint32_t addr, /* Read SFDP block */ if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_SFDP(len), - SPIFLASH_READ_SFDP); + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, + OCTOSPI_CCR_READ_SFDP(len), SPIFLASH_READ_SFDP); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_READ_SFDP); if (retval != ERROR_OK) @@ -1959,8 +1973,7 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id1, uint32_t *id2) /* SPIFLASH_READ_MID causes device in octal mode to go berserk, so don't use in this case */ for (type = (IS_OCTOSPI && OPI_MODE) ? 1 : 0; type < 2 ; type++) { /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) goto err; @@ -1986,14 +1999,16 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id1, uint32_t *id2) switch (type) { case 0: if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_MID, SPIFLASH_READ_MID); + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, + OCTOSPI_CCR_READ_MID, SPIFLASH_READ_MID); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_READ_MID); break; case 1: if (IS_OCTOSPI) - retval = OCTOSPI_CMD(OCTOSPI_READ_MODE, OCTOSPI_CCR_READ_ID, SPIFLASH_READ_ID); + retval = octospi_cmd(bank, OCTOSPI_READ_MODE, + OCTOSPI_CCR_READ_ID, SPIFLASH_READ_ID); else retval = target_write_u32(target, io_base + QSPI_CCR, QSPI_CCR_READ_ID); break; @@ -2013,7 +2028,8 @@ static int read_flash_id(struct flash_bank *bank, uint32_t *id1, uint32_t *id2) } /* for debugging only */ - (void)READ_REG(SPI_SR); + uint32_t dummy; + (void)target_read_u32(target, io_base + SPI_SR, &dummy); /* Read ID from Data Register */ for (len1 = 0, len2 = 0; count > 0; --count) { @@ -2092,8 +2108,7 @@ static int stmqspi_probe(struct flash_bank *bank) } /* Abort any previous operation */ - retval = target_write_u32(target, io_base + SPI_CR, - READ_REG(SPI_CR) | BIT(SPI_ABORT)); + retval = stmqspi_abort(bank); if (retval != ERROR_OK) return retval; @@ -2112,43 +2127,59 @@ static int stmqspi_probe(struct flash_bank *bank) if (data == magic) { LOG_DEBUG("QSPI_ABR register present"); stmqspi_info->octo = false; - } else if (READ_REG(OCTOSPI_MAGIC) == OCTO_MAGIC_ID) { - LOG_DEBUG("OCTOSPI_MAGIC present"); - stmqspi_info->octo = true; } else { - LOG_ERROR("No QSPI, no OCTOSPI at 0x%08" PRIx32, io_base); - stmqspi_info->probed = false; - stmqspi_info->dev.name = "none"; - return ERROR_FAIL; + uint32_t magic_id; + + retval = target_read_u32(target, io_base + OCTOSPI_MAGIC, &magic_id); + + if (retval == ERROR_OK && magic_id == OCTO_MAGIC_ID) { + LOG_DEBUG("OCTOSPI_MAGIC present"); + stmqspi_info->octo = true; + } else { + LOG_ERROR("No QSPI, no OCTOSPI at 0x%08" PRIx32, io_base); + stmqspi_info->probed = false; + stmqspi_info->dev.name = "none"; + return ERROR_FAIL; + } } /* save current FSEL and DFM bits in QSPI/OCTOSPI_CR, current QSPI/OCTOSPI_CCR value */ - stmqspi_info->saved_cr = READ_REG(SPI_CR); + retval = target_read_u32(target, io_base + SPI_CR, &stmqspi_info->saved_cr); if (retval == ERROR_OK) - stmqspi_info->saved_ccr = READ_REG(SPI_CCR); + retval = target_read_u32(target, io_base + SPI_CCR, &stmqspi_info->saved_ccr); if (IS_OCTOSPI) { - uint32_t mtyp; + uint32_t dcr1; + + retval = target_read_u32(target, io_base + OCTOSPI_DCR1, &dcr1); - mtyp = ((READ_REG(OCTOSPI_DCR1) & OCTOSPI_MTYP_MASK)) >> OCTOSPI_MTYP_POS; if (retval == ERROR_OK) - stmqspi_info->saved_tcr = READ_REG(OCTOSPI_TCR); + retval = target_read_u32(target, io_base + OCTOSPI_TCR, + &stmqspi_info->saved_tcr); + if (retval == ERROR_OK) - stmqspi_info->saved_ir = READ_REG(OCTOSPI_IR); - if ((mtyp != 0x0) && (mtyp != 0x1)) { - retval = ERROR_FAIL; - LOG_ERROR("Only regular SPI protocol supported in OCTOSPI"); - } - if (retval == ERROR_OK) { - LOG_DEBUG("OCTOSPI at 0x%08" PRIx64 ", io_base at 0x%08" PRIx32 ", OCTOSPI_CR 0x%08" - PRIx32 ", OCTOSPI_CCR 0x%08" PRIx32 ", %d-byte addr", bank->base, io_base, - stmqspi_info->saved_cr, stmqspi_info->saved_ccr, SPI_ADSIZE); - } else { + retval = target_read_u32(target, io_base + OCTOSPI_IR, + &stmqspi_info->saved_ir); + + if (retval != ERROR_OK) { LOG_ERROR("No OCTOSPI at io_base 0x%08" PRIx32, io_base); stmqspi_info->probed = false; stmqspi_info->dev.name = "none"; return ERROR_FAIL; } + + const uint32_t mtyp = (dcr1 & OCTOSPI_MTYP_MASK) >> OCTOSPI_MTYP_POS; + + if ((mtyp != 0x0) && (mtyp != 0x1)) { + LOG_ERROR("Only regular SPI protocol supported in OCTOSPI"); + stmqspi_info->probed = false; + stmqspi_info->dev.name = "none"; + return ERROR_FAIL; + } + + LOG_DEBUG("OCTOSPI at 0x%08" PRIx64 ", io_base at 0x%08" PRIx32 ", OCTOSPI_CR 0x%08" + PRIx32 ", OCTOSPI_CCR 0x%08" PRIx32 ", %d-byte addr", bank->base, io_base, + stmqspi_info->saved_cr, stmqspi_info->saved_ccr, SPI_ADSIZE); } else { if (retval == ERROR_OK) { LOG_DEBUG("QSPI at 0x%08" PRIx64 ", io_base at 0x%08" PRIx32 ", QSPI_CR 0x%08" @@ -2301,10 +2332,14 @@ static int stmqspi_probe(struct flash_bank *bank) /* Set correct size value */ bank->size = stmqspi_info->dev.size_in_bytes << dual; - fsize = ((READ_REG(SPI_DCR) >> SPI_FSIZE_POS) & (BIT(SPI_FSIZE_LEN) - 1)); + uint32_t dcr; + retval = target_read_u32(target, io_base + SPI_DCR, &dcr); + if (retval != ERROR_OK) goto err; + fsize = (dcr >> SPI_FSIZE_POS) & (BIT(SPI_FSIZE_LEN) - 1); + LOG_DEBUG("FSIZE = 0x%04x", fsize); if (bank->size == BIT((fsize + 1))) LOG_DEBUG("FSIZE in DCR(1) matches actual capacity. Beware of silicon bug in H7, L4+, MP1."); From a909df7088c32ef455ad3f78041ea17ffde41795 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Fri, 19 Feb 2021 15:23:34 +0100 Subject: [PATCH 067/120] tcl/target: add BCM2835 configuration file This is the Broadcom chip used in the Raspberry Pi Model A, B, B+, the Compute Module, and the Raspberry Pi Zero. Partial information is available in raspberry pi website: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835 Change-Id: Ifeb012952473d624327e8c010ac5c886d9473aa0 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6067 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/target/bcm2835.cfg | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tcl/target/bcm2835.cfg diff --git a/tcl/target/bcm2835.cfg b/tcl/target/bcm2835.cfg new file mode 100644 index 000000000..32a03666c --- /dev/null +++ b/tcl/target/bcm2835.cfg @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# This is the Broadcom chip used in the Raspberry Pi Model A, B, B+, +# the Compute Module, and the Raspberry Pi Zero. + +# Partial information is available in raspberry pi website: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME bcm2835 +} + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x07b7617F +} + +jtag newtap $_CHIPNAME cpu -expected-id $_DAP_TAPID -irlen 5 +adapter speed 4000 + +target create $_CHIPNAME.cpu0 arm11 -chain-position $_CHIPNAME.cpu From f9b5e34e39fd7497fe9dfc965e2e3fa7e78616c1 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sat, 20 Feb 2021 23:21:53 +0100 Subject: [PATCH 068/120] tcl/target: add BCM2836 configuration file The Broadcom chip used in the Raspberry Pi 2 Model B Partial information is available in raspberry pi website: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836 Change-Id: I50b040db213c5b72f63d5f5534c552426c7376f9 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6068 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/target/bcm2836.cfg | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tcl/target/bcm2836.cfg diff --git a/tcl/target/bcm2836.cfg b/tcl/target/bcm2836.cfg new file mode 100644 index 000000000..04921315e --- /dev/null +++ b/tcl/target/bcm2836.cfg @@ -0,0 +1,59 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# The Broadcom chip used in the Raspberry Pi 2 Model B + +# Partial information is available in raspberry pi website: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2836 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME bcm2836 +} + +if { [info exists CHIPCORES] } { + set _cores $CHIPCORES +} else { + set _cores 4 +} + +if { [info exists USE_SMP] } { + set _USE_SMP $USE_SMP +} else { + set _USE_SMP 0 +} + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu -expected-id $_DAP_TAPID -irlen 4 +adapter speed 4000 + +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# MEM-AP for direct access +target create $_CHIPNAME.ap mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# these addresses are obtained from the ROM table via 'dap info 0' command +set _DBGBASE {0x80010000 0x80012000 0x80014000 0x80016000} + +set _smp_command "target smp" + +for { set _core 0 } { $_core < $_cores } { incr _core } { + set _TARGETNAME $_CHIPNAME.cpu$_core + + target create $_TARGETNAME cortex_a -dap $_CHIPNAME.dap -coreid $_core -dbgbase [lindex $_DBGBASE $_core] + $_TARGETNAME configure -event reset-assert-post { cortex_a dbginit } + + set _smp_command "$_smp_command $_CHIPNAME.cpu$_core" +} + +if {$_USE_SMP} { + eval $_smp_command +} + +# default target is cpu0 +targets $_CHIPNAME.cpu0 From 77e1841f6420715953628c39ee6e4f515331e5ae Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sat, 20 Feb 2021 23:40:56 +0100 Subject: [PATCH 069/120] tcl/target: add BCM2837 configuration file This is the Broadcom chip used in the Raspberry Pi 3, and in later models of the Raspberry Pi 2. Partial information is available in raspberry pi website: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2837 https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2837b0 Change-Id: I1188a7866304c59f670a543809aca3927174786e Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6069 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/target/bcm2837.cfg | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tcl/target/bcm2837.cfg diff --git a/tcl/target/bcm2837.cfg b/tcl/target/bcm2837.cfg new file mode 100644 index 000000000..749de3103 --- /dev/null +++ b/tcl/target/bcm2837.cfg @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# This is the Broadcom chip used in the Raspberry Pi 3, +# and in later models of the Raspberry Pi 2. + +# Partial information is available in raspberry pi website: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2837 +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2837b0 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME bcm2837 +} + +if { [info exists CHIPCORES] } { + set _cores $CHIPCORES +} else { + set _cores 4 +} + +if { [info exists USE_SMP] } { + set _USE_SMP $USE_SMP +} else { + set _USE_SMP 0 +} + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu -expected-id $_DAP_TAPID -irlen 4 +adapter speed 4000 + +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# MEM-AP for direct access +target create $_CHIPNAME.ap mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# these addresses are obtained from the ROM table via 'dap info 0' command +set _DBGBASE {0x80010000 0x80012000 0x80014000 0x80016000} +set _CTIBASE {0x80018000 0x80019000 0x8001a000 0x8001b000} + +set _smp_command "target smp" + +for { set _core 0 } { $_core < $_cores } { incr _core } { + set _CTINAME $_CHIPNAME.cti$_core + set _TARGETNAME $_CHIPNAME.cpu$_core + + cti create $_CTINAME -dap $_CHIPNAME.dap -ap-num 0 -baseaddr [lindex $_CTIBASE $_core] + target create $_TARGETNAME aarch64 -dap $_CHIPNAME.dap -ap-num 0 -dbgbase [lindex $_DBGBASE $_core] -cti $_CTINAME + $_TARGETNAME configure -event reset-assert-post { aarch64 dbginit } + + set _smp_command "$_smp_command $_TARGETNAME" +} + +if {$_USE_SMP} { + eval $_smp_command +} + +# default target is cpu0 +targets $_CHIPNAME.cpu0 From 06990a1a9e9ace74fc6e79a78b5405bb63cee6b0 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 18 Feb 2021 00:35:48 +0100 Subject: [PATCH 070/120] tcl/target: add BCM2711 configuration file The Broadcom BCM2711 used in Raspberry Pi 4 No documentation was found on Broadcom website Partial information is available in raspberry pi website: https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711/ Change-Id: I3db6c9af520af8ab4c21ad35ff0f2db28efc0325 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6066 Tested-by: jenkins Reviewed-by: Antonio Borneo --- tcl/target/bcm2711.cfg | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tcl/target/bcm2711.cfg diff --git a/tcl/target/bcm2711.cfg b/tcl/target/bcm2711.cfg new file mode 100644 index 000000000..f8d2b3a65 --- /dev/null +++ b/tcl/target/bcm2711.cfg @@ -0,0 +1,62 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +# The Broadcom BCM2711 used in Raspberry Pi 4 +# No documentation was found on Broadcom website + +# Partial information is available in raspberry pi website: +# https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2711/ + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME bcm2711 +} + +if { [info exists CHIPCORES] } { + set _cores $CHIPCORES +} else { + set _cores 4 +} + +if { [info exists USE_SMP] } { + set _USE_SMP $USE_SMP +} else { + set _USE_SMP 0 +} + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu -expected-id $_DAP_TAPID -irlen 4 +adapter speed 4000 + +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# MEM-AP for direct access +target create $_CHIPNAME.ap mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# these addresses are obtained from the ROM table via 'dap info 0' command +set _DBGBASE {0x80410000 0x80510000 0x80610000 0x80710000} +set _CTIBASE {0x80420000 0x80520000 0x80620000 0x80720000} + +set _smp_command "target smp" + +for { set _core 0 } { $_core < $_cores } { incr _core } { + set _CTINAME $_CHIPNAME.cti$_core + set _TARGETNAME $_CHIPNAME.cpu$_core + + cti create $_CTINAME -dap $_CHIPNAME.dap -ap-num 0 -baseaddr [lindex $_CTIBASE $_core] + target create $_TARGETNAME aarch64 -dap $_CHIPNAME.dap -ap-num 0 -dbgbase [lindex $_DBGBASE $_core] -cti $_CTINAME + + set _smp_command "$_smp_command $_TARGETNAME" +} + +if {$_USE_SMP} { + eval $_smp_command +} + +# default target is cpu0 +targets $_CHIPNAME.cpu0 From 266a945ad3e8b421f175910c21f385c5508c849a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 29 Nov 2020 22:25:37 +0100 Subject: [PATCH 071/120] jimtcl: update to version 0.80 (2020-10-29) Update jimtcl to version 0.80. Add a workaround in Makefile.am to allow 'make distcheck' with the new jimtcl. A fix is already merged upstream but will be part of the future release 0.81 of jimtcl. Change-Id: I1cebfb9c17179114960dc771e0b31836b4b9b058 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5949 Tested-by: jenkins --- Makefile.am | 2 ++ jimtcl | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 75f0c0993..85287c50f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -115,6 +115,8 @@ uninstall-hook: distclean-local: rm -rf Doxyfile doxygen rm -f $(srcdir)/jimtcl/configure.gnu +# FIXME: workaround for jimtcl 0.80 only. Remove from jimtcl 0.81 + rm -f jimtcl/examples.api/Makefile DISTCLEANFILES = doxygen.log diff --git a/jimtcl b/jimtcl index 0aa0fb4e3..fb923fab4 160000 --- a/jimtcl +++ b/jimtcl @@ -1 +1 @@ -Subproject commit 0aa0fb4e3a38d38a49de9eb585d93d63a370dcf6 +Subproject commit fb923fab4f0cf276c336d98692d00df6a943791d From 4c00f96fc2e32397da5b46ca3428a992333548da Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 8 Jan 2021 13:15:14 +0100 Subject: [PATCH 072/120] configure.ac: switch to autoconf 2.69 OpenOCD file configure.ac requires autoconf equal or newer then 2.64, which is quite old. These are the release dates so far: - autoconf-2.64 2009-07-26 - autoconf-2.65 2009-11-21 - autoconf-2.66 2010-07-02 - autoconf-2.67 2010-08-02 - autoconf-2.68 2010-09-22 - autoconf-2.69 2012-04-24 - autoconf-2.70 2020-12-08 Switch to autoconf 2.69, which is old enough to be the standard in current systems. This should reduce the effort on configure.ac compatibility. Change-Id: Ia7c78d2fa34c50ed5ccf4fb66ad3484369cf3b4a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6008 Tested-by: jenkins --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index b6723a396..a8c2e9daf 100644 --- a/configure.ac +++ b/configure.ac @@ -1,4 +1,4 @@ -AC_PREREQ(2.64) +AC_PREREQ([2.69]) AC_INIT([openocd], [0.11.0+dev], [OpenOCD Mailing List ]) AC_CONFIG_SRCDIR([src/openocd.c]) From 8d6f7c92239a54ce77d7a268f51b49445470fe00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Sanchez=20Siles?= Date: Sat, 13 Mar 2021 01:09:01 +0100 Subject: [PATCH 073/120] flash/stm32l4x: zero init stm32l4_flash_bank struct on flash bank initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is specially needed when, in the probe routine, device is not found among the stm32l4_parts. In this case, the stm32l4_flash_bank->part_info is undefined and inadvertentanly used afterwards: part_info = stm32l4_info->part_info; If the stm32l4_flash_bank is zero init, the probe routine checks for the validity of the part_info field in the previous struct and correctly detects the unsupported (or not found) condition, raising an error rather than a SIGSEGV Change-Id: I7d9d669fb3fa7f8f0903acd60046966b4acb0031 Signed-off-by: Raúl Sánchez Siles Reviewed-on: http://openocd.zylin.com/6103 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Oleksij Rempel Reviewed-by: Tomas Vanek --- src/flash/nor/stm32l4x.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 55a8d8ff3..89c5ac3fe 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -439,7 +439,7 @@ FLASH_BANK_COMMAND_HANDLER(stm32l4_flash_bank_command) if (CMD_ARGC < 6) return ERROR_COMMAND_SYNTAX_ERROR; - stm32l4_info = malloc(sizeof(struct stm32l4_flash_bank)); + stm32l4_info = calloc(1, sizeof(struct stm32l4_flash_bank)); if (!stm32l4_info) return ERROR_FAIL; /* Checkme: What better error to use?*/ bank->driver_priv = stm32l4_info; From ab0def0f3878c6521a5d1626e9123112c7875297 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 00:38:13 +0100 Subject: [PATCH 074/120] target/arm720t: remove command 'arm720t cp15' deprecated in v0.4.0 The command 'arm720t cp15' was marked as deprecated in release v0.4.0, almost 11 years ago. We can reasonably expect that in these years any user of OpenOCD has already migrated to v0.4.0 or to some newer release, thus has already updated any local/personal script. There is no run-time warning about the deprecation, but it is reported in the help and in the documentation. Drop the command already deprecated in v0.4.0. Change-Id: I2b325d0312d96ca5e5f0f1bad13bb162b3b75c52 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6082 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- doc/openocd.texi | 17 ---------- src/target/arm720t.c | 79 -------------------------------------------- 2 files changed, 96 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 0c1714e49..934c37e5d 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9114,23 +9114,6 @@ cables (FT2232), but might be unsafe if used with targets running at very low speeds, like the 32kHz startup clock of an AT91RM9200. @end deffn -@subsection ARM720T specific commands -@cindex ARM720T - -These commands are available to ARM720T based CPUs, -which are implementations of the ARMv4T architecture -based on the ARM7TDMI-S integer core. -They are available in addition to the ARM and ARM7/ARM9 commands. - -@deffn Command {arm720t cp15} opcode [value] -@emph{DEPRECATED -- avoid using this. -Use the @command{arm mrc} or @command{arm mcr} commands instead.} - -Display cp15 register returned by the ARM instruction @var{opcode}; -else if a @var{value} is provided, that value is written to that register. -The @var{opcode} should be the value of either an MRC or MCR instruction. -@end deffn - @subsection ARM9 specific commands @cindex ARM9 diff --git a/src/target/arm720t.c b/src/target/arm720t.c index e04cab2e7..daa44e46a 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -233,16 +233,6 @@ static void arm720t_pre_restore_context(struct target *target) arm720t_write_cp15(target, 0xee060f10, arm720t->far_reg); } -static int arm720t_verify_pointer(struct command_invocation *cmd, - struct arm720t_common *arm720t) -{ - if (arm720t->common_magic != ARM720T_COMMON_MAGIC) { - command_print(cmd, "target is not an ARM720"); - return ERROR_TARGET_INVALID; - } - return ERROR_OK; -} - static int arm720t_arch_state(struct target *target) { struct arm720t_common *arm720t = target_to_arm720(target); @@ -441,55 +431,6 @@ static int arm720t_target_create(struct target *target, Jim_Interp *interp) return arm720t_init_arch_info(target, arm720t, target->tap); } -COMMAND_HANDLER(arm720t_handle_cp15_command) -{ - int retval; - struct target *target = get_current_target(CMD_CTX); - struct arm720t_common *arm720t = target_to_arm720(target); - - retval = arm720t_verify_pointer(CMD, arm720t); - if (retval != ERROR_OK) - return retval; - - if (target->state != TARGET_HALTED) { - command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); - return ERROR_OK; - } - - /* one or more argument, access a single register (write if second argument is given */ - if (CMD_ARGC >= 1) { - uint32_t opcode; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], opcode); - - if (CMD_ARGC == 1) { - uint32_t value; - retval = arm720t_read_cp15(target, opcode, &value); - if (retval != ERROR_OK) { - command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); - return ERROR_OK; - } - - retval = jtag_execute_queue(); - if (retval != ERROR_OK) - return retval; - - command_print(CMD, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); - } else if (CMD_ARGC == 2) { - uint32_t value; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); - - retval = arm720t_write_cp15(target, opcode, value); - if (retval != ERROR_OK) { - command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); - return ERROR_OK; - } - command_print(CMD, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); - } - } - - return ERROR_OK; -} - static int arm720t_mrc(struct target *target, int cpnum, uint32_t op1, uint32_t op2, uint32_t CRn, uint32_t CRm, @@ -523,30 +464,10 @@ static int arm720t_mcr(struct target *target, int cpnum, value); } -static const struct command_registration arm720t_exec_command_handlers[] = { - { - .name = "cp15", - .handler = arm720t_handle_cp15_command, - .mode = COMMAND_EXEC, - /* prefer using less error-prone "arm mcr" or "arm mrc" */ - .help = "display/modify cp15 register using ARM opcode" - " (DEPRECATED)", - .usage = "instruction [value]", - }, - COMMAND_REGISTRATION_DONE -}; - static const struct command_registration arm720t_command_handlers[] = { { .chain = arm7_9_command_handlers, }, - { - .name = "arm720t", - .mode = COMMAND_ANY, - .help = "arm720t command group", - .usage = "", - .chain = arm720t_exec_command_handlers, - }, COMMAND_REGISTRATION_DONE }; From cda7bc9a4c6c1b665cfdd055397cc59483e40ef8 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 00:45:05 +0100 Subject: [PATCH 075/120] target/arm920t: remove command 'arm920t cp15i' deprecated in v0.4.0 The command 'arm920t cp15i' was marked as deprecated in release v0.4.0, almost 11 years ago. We can reasonably expect that in these years any user of OpenOCD has already migrated to v0.4.0 or to some newer release, thus has already updated any local/personal script. There is no run-time warning about the deprecation, but it is reported in the help and in the documentation. Drop the command already deprecated in v0.4.0. Change-Id: I755c4283e13e125558fcd73b15fe20498eae95ca Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6083 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- doc/openocd.texi | 12 ------- src/target/arm920t.c | 83 -------------------------------------------- 2 files changed, 95 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 934c37e5d..640687da5 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -9167,18 +9167,6 @@ shown in bits 38..33 of table 9-9 in the ARM920T TRM. (Not all registers can be written.) @end deffn -@deffn Command {arm920t cp15i} opcode [value [address]] -@emph{DEPRECATED -- avoid using this. -Use the @command{arm mrc} or @command{arm mcr} commands instead.} - -Interpreted access using ARM instruction @var{opcode}, which should -be the value of either an MRC or MCR instruction -(as shown tables 9-11, 9-12, and 9-13 in the ARM920T TRM). -If no @var{value} is provided, the result is displayed. -Else if that value is written using the specified @var{address}, -or using zero if no other address is provided. -@end deffn - @deffn Command {arm920t read_cache} filename Dump the content of ICache and DCache to a file named @file{filename}. @end deffn diff --git a/src/target/arm920t.c b/src/target/arm920t.c index c96975a77..80f6d7045 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -1511,80 +1511,6 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) return ERROR_OK; } -COMMAND_HANDLER(arm920t_handle_cp15i_command) -{ - int retval; - struct target *target = get_current_target(CMD_CTX); - struct arm920t_common *arm920t = target_to_arm920(target); - - retval = arm920t_verify_pointer(CMD, arm920t); - if (retval != ERROR_OK) - return retval; - - - if (target->state != TARGET_HALTED) { - command_print(CMD, "target must be stopped for " - "\"%s\" command", CMD_NAME); - return ERROR_OK; - } - - /* one argument, read a register. - * two arguments, write it. - */ - if (CMD_ARGC >= 1) { - uint32_t opcode; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], opcode); - - if (CMD_ARGC == 1) { - uint32_t value; - retval = arm920t_read_cp15_interpreted(target, - opcode, 0x0, &value); - if (retval != ERROR_OK) { - command_print(CMD, - "couldn't execute %8.8" PRIx32, - opcode); - /* REVISIT why lie? "return retval"? */ - return ERROR_OK; - } - - command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, - opcode, value); - } else if (CMD_ARGC == 2) { - uint32_t value; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); - retval = arm920t_write_cp15_interpreted(target, - opcode, value, 0); - if (retval != ERROR_OK) { - command_print(CMD, - "couldn't execute %8.8" PRIx32, - opcode); - /* REVISIT why lie? "return retval"? */ - return ERROR_OK; - } - command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, - opcode, value); - } else if (CMD_ARGC == 3) { - uint32_t value; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); - uint32_t address; - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], address); - retval = arm920t_write_cp15_interpreted(target, - opcode, value, address); - if (retval != ERROR_OK) { - command_print(CMD, - "couldn't execute %8.8" PRIx32, opcode); - /* REVISIT why lie? "return retval"? */ - return ERROR_OK; - } - command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32 - " %8.8" PRIx32, opcode, value, address); - } - } else - return ERROR_COMMAND_SYNTAX_ERROR; - - return ERROR_OK; -} - COMMAND_HANDLER(arm920t_handle_cache_info_command) { int retval; @@ -1640,15 +1566,6 @@ static const struct command_registration arm920t_exec_command_handlers[] = { .help = "display/modify cp15 register", .usage = "regnum [value]", }, - { - .name = "cp15i", - .handler = arm920t_handle_cp15i_command, - .mode = COMMAND_EXEC, - /* prefer using less error-prone "arm mcr" or "arm mrc" */ - .help = "display/modify cp15 register using ARM opcode" - " (DEPRECATED)", - .usage = "instruction [value [address]]", - }, { .name = "cache_info", .handler = arm920t_handle_cache_info_command, From d02e29dabaff43bf5fb2aa2ea7778ace2223545d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 00:22:49 +0100 Subject: [PATCH 076/120] openocd: remove command line flag -p/--pipe deprecated in v0.5.0 The OpenOCD command line flag -p/--pipe was marked as deprecated in release v0.5.0, more than 9 years ago. We can reasonably expect that in these 9 years any user of OpenOCD has already migrated to v0.5.0 or to some newer release, thus has already updated any local/personal script to get rid of the deprecated message. Drop the command line flag already deprecated in v0.5.0. Change-Id: I2faeb592ed2c2f67c2d3227f118093e39fcf4a8c Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6084 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- doc/openocd.texi | 3 --- src/helper/options.c | 10 +--------- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 640687da5..34168fdaa 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2155,9 +2155,6 @@ disables the gdb server. When using "pipe", also use log_output to redirect the log output to a file so as not to flood the stdin/out pipes. -The -p/--pipe option is deprecated and a warning is printed -as it is equivalent to passing in -c "gdb_port pipe; log_output openocd.log". - Any other string is interpreted as named pipe to listen to. Output pipe is the same name as input pipe, but with 'o' appended, e.g. /var/gdb, /var/gdbo. diff --git a/src/helper/options.c b/src/helper/options.c index 0ccbf5642..477d7b303 100644 --- a/src/helper/options.c +++ b/src/helper/options.c @@ -54,7 +54,6 @@ static const struct option long_options[] = { {"search", required_argument, 0, 's'}, {"log_output", required_argument, 0, 'l'}, {"command", required_argument, 0, 'c'}, - {"pipe", no_argument, 0, 'p'}, {0, 0, 0, 0} }; @@ -281,7 +280,7 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[]) /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long(argc, argv, "hvd::l:f:s:c:p", long_options, &option_index); + c = getopt_long(argc, argv, "hvd::l:f:s:c:", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) @@ -321,13 +320,6 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[]) if (optarg) add_config_command(optarg); break; - case 'p': - /* to replicate the old syntax this needs to be synchronous - * otherwise the gdb stdin will overflow with the warning message */ - command_run_line(cmd_ctx, "gdb_port pipe; log_output openocd.log"); - LOG_WARNING("deprecated option: -p/--pipe. Use '-c \"gdb_port pipe; " - "log_output openocd.log\"' instead."); - break; default: /* '?' */ /* getopt will emit an error message, all we have to do is bail. */ return ERROR_FAIL; From 70ead8ff5d2af43aa79fbc14f80fe370d569df52 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 31 Oct 2020 23:58:33 +0100 Subject: [PATCH 077/120] startup.tcl: remove commands already deprecated in v0.7.0 Some command were already marked as deprecated in release v0.7.0, more then 7 years ago, and for some of them the depredation date is even earlier. We can reasonably expect that in these 7 years any user of OpenOCD has already migrated to v0.7.0 or to some following intermediate build, thus has already updated any local/personal script to get rid of the deprecated message. Drop the commands already deprecated in v0.7.0. Change-Id: I81cdc415ab855ebf30980ef5199f9780c5d7f932 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6085 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- src/flash/startup.tcl | 11 ----------- src/jtag/startup.tcl | 43 +----------------------------------------- src/target/startup.tcl | 17 ----------------- 3 files changed, 1 insertion(+), 70 deletions(-) diff --git a/src/flash/startup.tcl b/src/flash/startup.tcl index 280a059a3..7d9dbc7da 100644 --- a/src/flash/startup.tcl +++ b/src/flash/startup.tcl @@ -119,14 +119,3 @@ proc stm32g4x args { eval stm32l4x $args } proc stm32l5x args { eval stm32l4x $args } proc stm32wbx args { eval stm32l4x $args } proc stm32wlx args { eval stm32l4x $args } - -# ease migration to updated flash driver -proc stm32x args { - echo "DEPRECATED! use 'stm32f1x $args' not 'stm32x $args'" - eval stm32f1x $args -} - -proc stm32f2xxx args { - echo "DEPRECATED! use 'stm32f2x $args' not 'stm32f2xxx $args'" - eval stm32f2x $args -} diff --git a/src/jtag/startup.tcl b/src/jtag/startup.tcl index 82327a39b..e5c3b0f75 100644 --- a/src/jtag/startup.tcl +++ b/src/jtag/startup.tcl @@ -117,23 +117,8 @@ proc jtag_ntrst_assert_width args { # JTAG-specific names despite the fact that the operations were not # specific to JTAG, or otherwise had troublesome/misleading names. # -# FIXME phase these aids out after about April 2011 +# FIXME phase these aids out after some releases # -proc jtag_khz args { - echo "DEPRECATED! use 'adapter speed' not 'jtag_khz'" - eval adapter speed $args -} - -proc jtag_nsrst_delay args { - echo "DEPRECATED! use 'adapter srst delay' not 'jtag_nsrst_delay'" - eval adapter srst delay $args -} - -proc jtag_nsrst_assert_width args { - echo "DEPRECATED! use 'adapter srst pulse_width' not 'jtag_nsrst_assert_width'" - eval adapter srst pulse_width $args -} - proc jtag_reset args { echo "DEPRECATED! use 'adapter \[de\]assert' not 'jtag_reset'" switch $args { @@ -150,32 +135,6 @@ proc jtag_reset args { } } -# stlink migration helpers -proc stlink_device_desc args { - echo "DEPRECATED! use 'hla_device_desc' not 'stlink_device_desc'" - eval hla_device_desc $args -} - -proc stlink_serial args { - echo "DEPRECATED! use 'hla_serial' not 'stlink_serial'" - eval hla_serial $args -} - -proc stlink_layout args { - echo "DEPRECATED! use 'hla_layout' not 'stlink_layout'" - eval hla_layout $args -} - -proc stlink_vid_pid args { - echo "DEPRECATED! use 'hla_vid_pid' not 'stlink_vid_pid'" - eval hla_vid_pid $args -} - -proc stlink args { - echo "DEPRECATED! use 'hla' not 'stlink'" - eval hla $args -} - proc adapter_khz args { echo "DEPRECATED! use 'adapter speed' not 'adapter_khz'" eval adapter speed $args diff --git a/src/target/startup.tcl b/src/target/startup.tcl index ca39b1816..a8f78ab49 100644 --- a/src/target/startup.tcl +++ b/src/target/startup.tcl @@ -179,12 +179,6 @@ proc using_hla {} { ######### -# Temporary migration aid. May be removed starting in January 2011. -proc armv4_5 params { - echo "DEPRECATED! use 'arm $params' not 'armv4_5 $params'" - arm $params -} - # Target/chain configuration scripts can either execute commands directly # or define a procedure which is executed once all configuration # scripts have completed. @@ -212,14 +206,3 @@ proc init_target_events {} { # Additionally board config scripts can define a procedure init_board that will be executed after init and init_targets proc init_board {} { } - -# deprecated target name cmds -proc cortex_m3 args { - echo "DEPRECATED! use 'cortex_m' not 'cortex_m3'" - eval cortex_m $args -} - -proc cortex_a8 args { - echo "DEPRECATED! use 'cortex_a' not 'cortex_a8'" - eval cortex_a $args -} From 64b486e74f9e492da2922cab127f6dcd454474fb Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 00:10:55 +0100 Subject: [PATCH 078/120] target: remove target names already deprecated in v0.8.0 Some target name were marked as deprecated in release v0.7.0 and v0.8.0, almost 7 years ago, and replaced with more 'actual' names. We can reasonably expect that in these 7 years any user of OpenOCD has already migrated to v0.8.0 or to some newer release, thus has already updated any local/personal script to get rid of the deprecated message. Drop the target names already deprecated in v0.8.0. Change-Id: I7c7491496db1b302b4eb1e9fc6090b58d4acf05a Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6086 Reviewed-by: Tarek BOCHKATI Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/cortex_a.c | 1 - src/target/cortex_m.c | 1 - src/target/hla_target.c | 1 - 3 files changed, 3 deletions(-) diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index d27c298b6..5018a91d4 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -3143,7 +3143,6 @@ static const struct command_registration cortex_a_command_handlers[] = { struct target_type cortexa_target = { .name = "cortex_a", - .deprecated_name = "cortex_a8", .poll = cortex_a_poll, .arch_state = armv7a_arch_state, diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index 2a973e1f6..6dc33c867 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -2501,7 +2501,6 @@ static const struct command_registration cortex_m_command_handlers[] = { struct target_type cortexm_target = { .name = "cortex_m", - .deprecated_name = "cortex_m3", .poll = cortex_m_poll, .arch_state = armv7m_arch_state, diff --git a/src/target/hla_target.c b/src/target/hla_target.c index 9ac344245..cd57dd207 100644 --- a/src/target/hla_target.c +++ b/src/target/hla_target.c @@ -640,7 +640,6 @@ static const struct command_registration adapter_command_handlers[] = { struct target_type hla_target = { .name = "hla_target", - .deprecated_name = "stm32_stlink", .init_target = adapter_init_target, .deinit_target = cortex_m_deinit_target, From 113f949ac11f28e4e653824bed11e48a2c699559 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 00:14:52 +0100 Subject: [PATCH 079/120] target: remove handling of target's deprecated_name We do not have anymore any deprecated target name. Drop the code to handle deprecated target names and the placehold in struct target_type. This patch is separated from the patch that drops the remaining deprecated target names to be ready to revert this if there is any need in the future. Change-Id: I96fca7ffa39d8292f81e79f115ea45c4a30035d7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6087 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/target/target.c | 9 --------- src/target/target_type.h | 1 - 2 files changed, 10 deletions(-) diff --git a/src/target/target.c b/src/target/target.c index eb83daebb..200368b13 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -5678,15 +5678,6 @@ static int target_create(Jim_GetOptInfo *goi) /* found */ break; } - - /* check for deprecated name */ - if (target_types[x]->deprecated_name) { - if (0 == strcmp(cp, target_types[x]->deprecated_name)) { - /* found */ - LOG_WARNING("target name is deprecated use: \'%s\'", target_types[x]->name); - break; - } - } } if (target_types[x] == NULL) { Jim_SetResultFormatted(goi->interp, "Unknown target type %s, try one of ", cp); diff --git a/src/target/target_type.h b/src/target/target_type.h index 4bdea721e..0f3df0002 100644 --- a/src/target/target_type.h +++ b/src/target/target_type.h @@ -40,7 +40,6 @@ struct target_type { * field directly, use target_type_name() instead. */ const char *name; - const char *deprecated_name; /* poll current target status */ int (*poll)(struct target *target); From 26a57b06cf3a11a5c002f0f85a2f3f4a05f630f7 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 10:41:47 +0100 Subject: [PATCH 080/120] oocd_trace: drop the code, deprecated in v0.10.0 The code for oocd_trace has been marked as deprecated in release v0.10.0, 4 years ago. Time to drop it! Change-Id: I989f8345dee4ff2369bcf5e2e2ace86bbd5aa6a5 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6088 Tested-by: jenkins --- configure.ac | 19 -- doc/openocd.texi | 23 --- src/target/Makefile.am | 8 - src/target/etm.c | 8 - src/target/oocd_trace.c | 417 ---------------------------------------- src/target/oocd_trace.h | 53 ----- 6 files changed, 528 deletions(-) delete mode 100644 src/target/oocd_trace.c delete mode 100644 src/target/oocd_trace.h diff --git a/configure.ac b/configure.ac index a8c2e9daf..7b5551656 100644 --- a/configure.ac +++ b/configure.ac @@ -328,11 +328,6 @@ AC_ARG_ENABLE([gw16012], AS_HELP_STRING([--enable-gw16012], [Enable building support for the Gateworks GW16012 JTAG Programmer]), [build_gw16012=$enableval], [build_gw16012=no]) -AC_ARG_ENABLE([oocd_trace], - AS_HELP_STRING([--enable-oocd_trace], - [Enable building support for some prototype OpenOCD+trace ETM capture hardware]), - [build_oocd_trace=$enableval], [build_oocd_trace=no]) - AC_ARG_ENABLE([buspirate], AS_HELP_STRING([--enable-buspirate], [Enable building support for the Buspirate]), [build_buspirate=$enableval], [build_buspirate=no]) @@ -600,12 +595,6 @@ AS_IF([test "x$build_gw16012" = "xyes"], [ AC_DEFINE([BUILD_GW16012], [0], [0 if you don't want the Gateworks GW16012 driver.]) ]) -AS_IF([test "x$build_oocd_trace" = "xyes"], [ - AC_DEFINE([BUILD_OOCD_TRACE], [1], [1 if you want the OpenOCD+trace ETM capture driver.]) -], [ - AC_DEFINE([BUILD_OOCD_TRACE], [0], [0 if you don't want the OpenOCD+trace ETM capture driver.]) -]) - AS_IF([test "x$build_buspirate" = "xyes"], [ AC_DEFINE([BUILD_BUSPIRATE], [1], [1 if you want the Buspirate JTAG driver.]) ], [ @@ -778,7 +767,6 @@ AM_CONDITIONAL([JTAG_DPI], [test "x$build_jtag_dpi" = "xyes" -o "x$build_jtag_dp AM_CONDITIONAL([USB_BLASTER_DRIVER], [test "x$enable_usb_blaster" != "xno" -o "x$enable_usb_blaster_2" != "xno"]) AM_CONDITIONAL([AMTJTAGACCEL], [test "x$build_amtjtagaccel" = "xyes"]) AM_CONDITIONAL([GW16012], [test "x$build_gw16012" = "xyes"]) -AM_CONDITIONAL([OOCD_TRACE], [test "x$build_oocd_trace" = "xyes"]) AM_CONDITIONAL([REMOTE_BITBANG], [test "x$build_remote_bitbang" = "xyes"]) AM_CONDITIONAL([BUSPIRATE], [test "x$build_buspirate" = "xyes"]) AM_CONDITIONAL([SYSFSGPIO], [test "x$build_sysfsgpio" = "xyes"]) @@ -885,13 +873,6 @@ m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, ]) echo -AS_IF([test "x$build_oocd_trace" = "xyes"], [ - echo 'WARNING! Deprecated configure option (--enable-oocd_trace)' - echo 'The oocd_trace driver is deprecated and will be removed in the next release.' - echo 'If you regularly use this driver, please report to the OpenOCD Mailing List.' - echo -]) - AS_IF([test "x$build_zy1000" = "xyes" -o "x$build_zy1000_master" = "xyes"], [ echo 'WARNING! Deprecated configure option (--enable-zy1000, --enable-zy1000-master)' echo 'Support for the ZY1000 platform is deprecated and will be removed in the next' diff --git a/doc/openocd.texi b/doc/openocd.texi index 34168fdaa..06d90faca 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -8866,29 +8866,6 @@ how the event caused trouble. @end deffn -@deffn {Trace Port Driver} oocd_trace -This driver isn't available unless OpenOCD was explicitly configured -with the @option{--enable-oocd_trace} option. You probably don't want -to configure it unless you've built the appropriate prototype hardware; -it's @emph{proof-of-concept} software. - -Use the @option{oocd_trace} driver if you are configuring an ETM that's -connected to an off-chip trace connector. - -@deffn {Config Command} {oocd_trace config} target tty -Associates the ETM for @var{target} with a trace driver which -collects data through the serial port @var{tty}. -@end deffn - -@deffn Command {oocd_trace resync} -Re-synchronizes with the capture clock. -@end deffn - -@deffn Command {oocd_trace status} -Reports whether the capture clock is locked or not. -@end deffn -@end deffn - @anchor{armcrosstrigger} @section ARM Cross-Trigger Interface @cindex CTI diff --git a/src/target/Makefile.am b/src/target/Makefile.am index 6605b678b..34a78517a 100644 --- a/src/target/Makefile.am +++ b/src/target/Makefile.am @@ -1,9 +1,3 @@ -if OOCD_TRACE -OOCD_TRACE_FILES = %D%/oocd_trace.c -else -OOCD_TRACE_FILES = -endif - %C%_libtarget_la_LIBADD = %D%/openrisc/libopenrisc.la \ %D%/riscv/libriscv.la @@ -111,7 +105,6 @@ ARM_DEBUG_SRC = \ %D%/trace.c \ %D%/etb.c \ %D%/etm.c \ - $(OOCD_TRACE_FILES) \ %D%/etm_dummy.c \ %D%/arm_tpiu_swo.c \ %D%/arm_cti.c @@ -225,7 +218,6 @@ ARC_SRC = \ %D%/mips32_pracc.h \ %D%/mips32_dmaacc.h \ %D%/mips64_pracc.h \ - %D%/oocd_trace.h \ %D%/register.h \ %D%/target.h \ %D%/target_type.h \ diff --git a/src/target/etm.c b/src/target/etm.c index faa941fed..19f3691bd 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -27,11 +27,6 @@ #include "register.h" #include "etm_dummy.h" -#if BUILD_OOCD_TRACE == 1 -#include "oocd_trace.h" -#endif - - /* * ARM "Embedded Trace Macrocell" (ETM) support -- direct JTAG access. * @@ -642,9 +637,6 @@ static int etm_write_reg(struct reg *reg, uint32_t value) static struct etm_capture_driver *etm_capture_drivers[] = { &etb_capture_driver, &etm_dummy_capture_driver, -#if BUILD_OOCD_TRACE == 1 - &oocd_trace_capture_driver, -#endif NULL }; diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c deleted file mode 100644 index f38916a0b..000000000 --- a/src/target/oocd_trace.c +++ /dev/null @@ -1,417 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Dominic Rath * - * Dominic.Rath@gmx.de * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "arm.h" -#include "etm.h" -#include "oocd_trace.h" - -/* - * This is "proof of concept" code, for prototype hardware: - * https://lists.berlios.de/pipermail/openocd-development/2007-September/000336.html - */ - -static int oocd_trace_read_reg(struct oocd_trace *oocd_trace, int reg, uint32_t *value) -{ - size_t bytes_written, bytes_read, bytes_to_read; - uint8_t cmd; - - cmd = 0x10 | (reg & 0x7); - bytes_written = write(oocd_trace->tty_fd, &cmd, 1); - if (bytes_written < 1) - return ERROR_FAIL; - - bytes_to_read = 4; - while (bytes_to_read > 0) { - bytes_read = read(oocd_trace->tty_fd, ((uint8_t *)value) + 4 - bytes_to_read, bytes_to_read); - bytes_to_read -= bytes_read; - } - - LOG_DEBUG("reg #%i: 0x%8.8x", reg, *value); - - return ERROR_OK; -} - -static int oocd_trace_write_reg(struct oocd_trace *oocd_trace, int reg, uint32_t value) -{ - size_t bytes_written; - uint8_t data[5]; - - data[0] = 0x18 | (reg & 0x7); - data[1] = value & 0xff; - data[2] = (value & 0xff00) >> 8; - data[3] = (value & 0xff0000) >> 16; - data[4] = (value & 0xff000000) >> 24; - - bytes_written = write(oocd_trace->tty_fd, data, 5); - if (bytes_written < 5) - return ERROR_FAIL; - - LOG_DEBUG("reg #%i: 0x%8.8x", reg, value); - - return ERROR_OK; -} - -static int oocd_trace_read_memory(struct oocd_trace *oocd_trace, uint8_t *data, uint32_t address, uint32_t size) -{ - size_t bytes_written, bytes_to_read; - ssize_t bytes_read; - uint8_t cmd; - - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_ADDRESS, address); - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_SDRAM_COUNTER, size); - - cmd = 0x20; - bytes_written = write(oocd_trace->tty_fd, &cmd, 1); - if (bytes_written < 1) - return ERROR_FAIL; - - bytes_to_read = size * 16; - while (bytes_to_read > 0) { - bytes_read = read(oocd_trace->tty_fd, - ((uint8_t *)data) + (size * 16) - bytes_to_read, bytes_to_read); - if (bytes_read < 0) - LOG_DEBUG("read() returned %zi (%s)", bytes_read, strerror(errno)); - else - bytes_to_read -= bytes_read; - } - - return ERROR_OK; -} - -static int oocd_trace_init(struct etm_context *etm_ctx) -{ - uint8_t trash[256]; - struct oocd_trace *oocd_trace = etm_ctx->capture_driver_priv; - size_t bytes_read; - - oocd_trace->tty_fd = open(oocd_trace->tty, O_RDWR | O_NOCTTY | O_NONBLOCK); - - if (oocd_trace->tty_fd < 0) { - LOG_ERROR("can't open tty"); - return ERROR_ETM_CAPTURE_INIT_FAILED; - } - - /* clear input & output buffers, then switch to "blocking mode" */ - tcflush(oocd_trace->tty_fd, TCOFLUSH); - tcflush(oocd_trace->tty_fd, TCIFLUSH); - fcntl(oocd_trace->tty_fd, F_SETFL, fcntl(oocd_trace->tty_fd, F_GETFL) & ~O_NONBLOCK); - - tcgetattr(oocd_trace->tty_fd, &oocd_trace->oldtio); /* save current port settings */ - - bzero(&oocd_trace->newtio, sizeof(oocd_trace->newtio)); - oocd_trace->newtio.c_cflag = CS8 | CLOCAL | CREAD | B2500000; - - oocd_trace->newtio.c_iflag = IGNPAR | IGNBRK | IXON | IXOFF; - oocd_trace->newtio.c_oflag = 0; - - /* set input mode (non-canonical, no echo,...) */ - oocd_trace->newtio.c_lflag = 0; - - cfmakeraw(&oocd_trace->newtio); - oocd_trace->newtio.c_cc[VTIME] = 1; /* inter-character timer used */ - oocd_trace->newtio.c_cc[VMIN] = 0; /* blocking read until 0 chars received */ - - tcflush(oocd_trace->tty_fd, TCIFLUSH); - tcsetattr(oocd_trace->tty_fd, TCSANOW, &oocd_trace->newtio); - - /* occasionally one bogus character is left in the input buffer - * read up any leftover characters to ensure communication is in sync */ - do { - bytes_read = read(oocd_trace->tty_fd, trash, sizeof(trash)); - if (bytes_read) - LOG_DEBUG("%zi bytes read", bytes_read); - } while (bytes_read > 0); - - return ERROR_OK; -} - -static trace_status_t oocd_trace_status(struct etm_context *etm_ctx) -{ - struct oocd_trace *oocd_trace = etm_ctx->capture_driver_priv; - uint32_t status; - - oocd_trace_read_reg(oocd_trace, OOCD_TRACE_STATUS, &status); - - /* if tracing is currently idle, return this information */ - if (etm_ctx->capture_status == TRACE_IDLE) - return etm_ctx->capture_status; - else if (etm_ctx->capture_status & TRACE_RUNNING) { - /* check Full bit to identify an overflow */ - if (status & 0x4) - etm_ctx->capture_status |= TRACE_OVERFLOWED; - - /* check Triggered bit to identify trigger condition */ - if (status & 0x2) - etm_ctx->capture_status |= TRACE_TRIGGERED; - - if (status & 0x1) { - etm_ctx->capture_status &= ~TRACE_RUNNING; - etm_ctx->capture_status |= TRACE_COMPLETED; - } - } - - return etm_ctx->capture_status; -} - -static int oocd_trace_read_trace(struct etm_context *etm_ctx) -{ - struct oocd_trace *oocd_trace = etm_ctx->capture_driver_priv; - uint32_t status, address; - uint32_t first_frame = 0x0; - uint32_t num_frames = 1048576; - uint8_t *trace_data; - uint32_t i; - - oocd_trace_read_reg(oocd_trace, OOCD_TRACE_STATUS, &status); - oocd_trace_read_reg(oocd_trace, OOCD_TRACE_ADDRESS, &address); - - /* check if we overflowed, and adjust first frame of the trace accordingly - * if we didn't overflow, read only up to the frame that would be written next, - * i.e. don't read invalid entries - */ - if (status & 0x4) - first_frame = address; - else - num_frames = address; - - /* read data into temporary array for unpacking - * one frame from OpenOCD + trace corresponds to 16 trace cycles - */ - trace_data = malloc(sizeof(uint8_t) * num_frames * 16); - oocd_trace_read_memory(oocd_trace, trace_data, first_frame, num_frames); - - if (etm_ctx->trace_depth > 0) - free(etm_ctx->trace_data); - - etm_ctx->trace_depth = num_frames * 16; - etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth); - - for (i = 0; i < num_frames * 16; i++) { - etm_ctx->trace_data[i].pipestat = (trace_data[i] & 0x7); - etm_ctx->trace_data[i].packet = (trace_data[i] & 0x78) >> 3; - etm_ctx->trace_data[i].flags = 0; - - if ((trace_data[i] & 0x80) >> 7) - etm_ctx->trace_data[i].flags |= ETMV1_TRACESYNC_CYCLE; - - if (etm_ctx->trace_data[i].pipestat == STAT_TR) { - etm_ctx->trace_data[i].pipestat = etm_ctx->trace_data[i].packet & 0x7; - etm_ctx->trace_data[i].flags |= ETMV1_TRIGGER_CYCLE; - } - } - - free(trace_data); - - return ERROR_OK; -} - -static int oocd_trace_start_capture(struct etm_context *etm_ctx) -{ - struct oocd_trace *oocd_trace = etm_ctx->capture_driver_priv; - uint32_t control = 0x1; /* 0x1: enabled */ - uint32_t trigger_count; - - if (((etm_ctx->control & ETM_PORT_MODE_MASK) != ETM_PORT_NORMAL) - || ((etm_ctx->control & ETM_PORT_WIDTH_MASK) != ETM_PORT_4BIT)) { - LOG_DEBUG("OpenOCD + trace only supports normal 4-bit ETM mode"); - return ERROR_ETM_PORTMODE_NOT_SUPPORTED; - } - - if ((etm_ctx->control & ETM_PORT_CLOCK_MASK) == ETM_PORT_HALF_CLOCK) - control |= 0x2; /* half rate clock, capture at twice the clock rate */ - - /* OpenOCD + trace holds up to 16 million samples, - * but trigger counts is set in multiples of 16 */ - trigger_count = (1048576 * /* trigger_percent */ 50) / 100; - - /* capturing always starts at address zero */ - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_ADDRESS, 0x0); - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_TRIGGER_COUNTER, trigger_count); - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_CONTROL, control); - - /* we're starting a new trace, initialize capture status */ - etm_ctx->capture_status = TRACE_RUNNING; - - return ERROR_OK; -} - -static int oocd_trace_stop_capture(struct etm_context *etm_ctx) -{ - struct oocd_trace *oocd_trace = etm_ctx->capture_driver_priv; - - /* trace stopped, just clear running flag, but preserve others */ - etm_ctx->capture_status &= ~TRACE_RUNNING; - - oocd_trace_write_reg(oocd_trace, OOCD_TRACE_CONTROL, 0x0); - - return ERROR_OK; -} - -COMMAND_HANDLER(handle_oocd_trace_config_command) -{ - struct target *target; - struct arm *arm; - - if (CMD_ARGC != 2) - return ERROR_COMMAND_SYNTAX_ERROR; - - target = get_current_target(CMD_CTX); - arm = target_to_arm(target); - if (!is_arm(arm)) { - command_print(CMD, "current target isn't an ARM"); - return ERROR_FAIL; - } - - if (arm->etm) { - struct oocd_trace *oocd_trace = malloc(sizeof(struct oocd_trace)); - - arm->etm->capture_driver_priv = oocd_trace; - oocd_trace->etm_ctx = arm->etm; - - /* copy name of TTY device used to communicate with OpenOCD + trace */ - oocd_trace->tty = strndup(CMD_ARGV[1], 256); - } else - LOG_ERROR("target has no ETM defined, OpenOCD + trace left unconfigured"); - - return ERROR_OK; -} - -COMMAND_HANDLER(handle_oocd_trace_status_command) -{ - struct target *target; - struct arm *arm; - struct oocd_trace *oocd_trace; - uint32_t status; - - target = get_current_target(CMD_CTX); - - arm = target_to_arm(target); - if (!is_arm(arm)) { - command_print(CMD, "current target isn't an ARM"); - return ERROR_FAIL; - } - - if (!arm->etm) { - command_print(CMD, "current target doesn't have an ETM configured"); - return ERROR_FAIL; - } - - if (strcmp(arm->etm->capture_driver->name, "oocd_trace") != 0) { - command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); - return ERROR_FAIL; - } - - oocd_trace = (struct oocd_trace *)arm->etm->capture_driver_priv; - - oocd_trace_read_reg(oocd_trace, OOCD_TRACE_STATUS, &status); - - if (status & 0x8) - command_print(CMD, "trace clock locked"); - else - command_print(CMD, "no trace clock"); - - return ERROR_OK; -} - -COMMAND_HANDLER(handle_oocd_trace_resync_command) -{ - struct target *target; - struct arm *arm; - struct oocd_trace *oocd_trace; - size_t bytes_written; - uint8_t cmd_array[1]; - - target = get_current_target(CMD_CTX); - - arm = target_to_arm(target); - if (!is_arm(arm)) { - command_print(CMD, "current target isn't an ARM"); - return ERROR_FAIL; - } - - if (!arm->etm) { - command_print(CMD, "current target doesn't have an ETM configured"); - return ERROR_FAIL; - } - - if (strcmp(arm->etm->capture_driver->name, "oocd_trace") != 0) { - command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); - return ERROR_FAIL; - } - - oocd_trace = (struct oocd_trace *)arm->etm->capture_driver_priv; - - cmd_array[0] = 0xf0; - - bytes_written = write(oocd_trace->tty_fd, cmd_array, 1); - if (bytes_written < 1) - return ERROR_FAIL; - - command_print(CMD, "requesting traceclock resync"); - LOG_DEBUG("resyncing traceclk pll"); - - return ERROR_OK; -} - -static const struct command_registration oocd_trace_all_command_handlers[] = { - { - .name = "config", - .handler = handle_oocd_trace_config_command, - .mode = COMMAND_CONFIG, - .usage = " ", - }, - { - .name = "status", - .handler = handle_oocd_trace_status_command, - .mode = COMMAND_EXEC, - .usage = "", - .help = "display OpenOCD + trace status", - }, - { - .name = "resync", - .handler = handle_oocd_trace_resync_command, - .mode = COMMAND_EXEC, - .usage = "", - .help = "resync OpenOCD + trace capture clock", - }, - COMMAND_REGISTRATION_DONE -}; -static const struct command_registration oocd_trace_command_handlers[] = { - { - .name = "oocd_trace", - .mode = COMMAND_ANY, - .help = "OpenOCD trace capture driver command group", - .usage = "", - .chain = oocd_trace_all_command_handlers, - }, - COMMAND_REGISTRATION_DONE -}; - -struct etm_capture_driver oocd_trace_capture_driver = { - .name = "oocd_trace", - .commands = oocd_trace_command_handlers, - .init = oocd_trace_init, - .status = oocd_trace_status, - .start_capture = oocd_trace_start_capture, - .stop_capture = oocd_trace_stop_capture, - .read_trace = oocd_trace_read_trace, -}; diff --git a/src/target/oocd_trace.h b/src/target/oocd_trace.h deleted file mode 100644 index e7584e4c9..000000000 --- a/src/target/oocd_trace.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007 by Dominic Rath * - * Dominic.Rath@gmx.de * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifndef OPENOCD_TARGET_OOCD_TRACE_H -#define OPENOCD_TARGET_OOCD_TRACE_H - -#include - -/* registers */ -enum { - OOCD_TRACE_ID = 0x7, - OOCD_TRACE_ADDRESS = 0x0, - OOCD_TRACE_TRIGGER_COUNTER = 0x01, - OOCD_TRACE_CONTROL = 0x2, - OOCD_TRACE_STATUS = 0x3, - OOCD_TRACE_SDRAM_COUNTER = 0x4, -}; - -/* commands */ -enum { - OOCD_TRACE_NOP = 0x0, - OOCD_TRACE_READ_REG = 0x10, - OOCD_TRACE_WRITE_REG = 0x18, - OOCD_TRACE_READ_RAM = 0x20, -/* OOCD_TRACE_WRITE_RAM = 0x28, */ - OOCD_TRACE_RESYNC = 0xf0, -}; - -struct oocd_trace { - struct etm_context *etm_ctx; - char *tty; - int tty_fd; - struct termios oldtio, newtio; -}; - -extern struct etm_capture_driver oocd_trace_capture_driver; - -#endif /* OPENOCD_TARGET_OOCD_TRACE_H */ From 58b95eac48cf0ad3316a911ddc79ce8973b88fd1 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 10:51:36 +0100 Subject: [PATCH 081/120] ioutil: drop the code, deprecated in v0.10.0 The code for ioutil has been marked as deprecated in release v0.10.0, 4 years ago. Time to drop it! Change-Id: I36dce1669ebe9acada5f9e752835c53e5214e3be Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6089 Tested-by: jenkins --- configure.ac | 13 - doc/openocd.texi | 60 ----- src/helper/Makefile.am | 7 - src/helper/ioutil.c | 534 -------------------------------------- src/helper/ioutil.h | 25 -- src/helper/ioutil_stubs.c | 28 -- src/openocd.c | 4 - 7 files changed, 671 deletions(-) delete mode 100644 src/helper/ioutil.c delete mode 100644 src/helper/ioutil.h delete mode 100644 src/helper/ioutil_stubs.c diff --git a/configure.ac b/configure.ac index 7b5551656..215d7a7f7 100644 --- a/configure.ac +++ b/configure.ac @@ -291,10 +291,6 @@ AC_ARG_ENABLE([zy1000], AS_HELP_STRING([--enable-zy1000], [Enable ZY1000 interface]), [build_zy1000=$enableval], [build_zy1000=no]) -AC_ARG_ENABLE([ioutil], - AS_HELP_STRING([--enable-ioutil], [Enable ioutil functions - useful for standalone OpenOCD implementations]), - [build_ioutil=$enableval], [build_ioutil=no]) - AS_CASE(["${host_cpu}"], [arm*|aarch64], [ AC_ARG_ENABLE([bcm2835gpio], @@ -757,7 +753,6 @@ AM_CONDITIONAL([GIVEIO], [test "x$parport_use_giveio" = "xyes"]) AM_CONDITIONAL([EP93XX], [test "x$build_ep93xx" = "xyes"]) AM_CONDITIONAL([ZY1000], [test "x$build_zy1000" = "xyes"]) AM_CONDITIONAL([ZY1000_MASTER], [test "x$build_zy1000_master" = "xyes"]) -AM_CONDITIONAL([IOUTIL], [test "x$build_ioutil" = "xyes"]) AM_CONDITIONAL([AT91RM9200], [test "x$build_at91rm9200" = "xyes"]) AM_CONDITIONAL([BCM2835GPIO], [test "x$build_bcm2835gpio" = "xyes"]) AM_CONDITIONAL([IMX_GPIO], [test "x$build_imx_gpio" = "xyes"]) @@ -880,11 +875,3 @@ AS_IF([test "x$build_zy1000" = "xyes" -o "x$build_zy1000_master" = "xyes"], [ echo 'Mailing List.' echo ]) - -AS_IF([test "x$build_ioutil" = "xyes"], [ - echo 'WARNING! Deprecated configure option (--enable-ioutil)' - echo 'Support for the ioutil functions is deprecated and will be removed in the next' - echo 'release. If you regularly depend on this functionality, please report to the' - echo 'OpenOCD Mailing List.' - echo -]) diff --git a/doc/openocd.texi b/doc/openocd.texi index 06d90faca..f52cfa7d9 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -8285,66 +8285,6 @@ with handlers for that event. @end quotation @end deffn -@section I/O Utilities - -These commands are available when -OpenOCD is built with @option{--enable-ioutil}. -They are mainly useful on embedded targets, -notably the ZY1000. -Hosts with operating systems have complementary tools. - -@emph{Note:} there are several more such commands. - -@deffn Command append_file filename [string]* -Appends the @var{string} parameters to -the text file @file{filename}. -Each string except the last one is followed by one space. -The last string is followed by a newline. -@end deffn - -@deffn Command cat filename -Reads and displays the text file @file{filename}. -@end deffn - -@deffn Command cp src_filename dest_filename -Copies contents from the file @file{src_filename} -into @file{dest_filename}. -@end deffn - -@deffn Command ip -@emph{No description provided.} -@end deffn - -@deffn Command ls -@emph{No description provided.} -@end deffn - -@deffn Command mac -@emph{No description provided.} -@end deffn - -@deffn Command meminfo -Display available RAM memory on OpenOCD host. -Used in OpenOCD regression testing scripts. -@end deffn - -@deffn Command peek -@emph{No description provided.} -@end deffn - -@deffn Command poke -@emph{No description provided.} -@end deffn - -@deffn Command rm filename -@c "rm" has both normal and Jim-level versions?? -Unlinks the file @file{filename}. -@end deffn - -@deffn Command trunc filename -Removes all data in the file @file{filename}. -@end deffn - @anchor{memoryaccess} @section Memory access commands @cindex memory access diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am index 2b3523f7a..bedc9f707 100644 --- a/src/helper/Makefile.am +++ b/src/helper/Makefile.am @@ -18,7 +18,6 @@ noinst_LTLIBRARIES += %D%/libhelper.la %D%/binarybuffer.h \ %D%/bits.h \ %D%/configuration.h \ - %D%/ioutil.h \ %D%/list.h \ %D%/util.h \ %D%/types.h \ @@ -32,12 +31,6 @@ noinst_LTLIBRARIES += %D%/libhelper.la %D%/jep106.inc \ %D%/jim-nvp.h -if IOUTIL -%C%_libhelper_la_SOURCES += %D%/ioutil.c -else -%C%_libhelper_la_SOURCES += %D%/ioutil_stubs.c -endif - %C%_libhelper_la_CFLAGS = $(AM_CFLAGS) if IS_MINGW # FD_* macros are sloppy with their signs on MinGW32 platform diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c deleted file mode 100644 index ffdeca898..000000000 --- a/src/helper/ioutil.c +++ /dev/null @@ -1,534 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2010 by Øyvind Harboe * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -/* this file contains various functionality useful to standalone systems */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "log.h" -#include "time_support.h" - -#ifdef HAVE_ARPA_INET_H -#include -#endif -#ifdef HAVE_DIRENT_H -#include -#endif -#ifdef HAVE_NETDB_H -#include -#endif -#ifdef HAVE_NET_IF_H -#include -#endif -#ifdef HAVE_SYS_IOCTL_H -#include -#endif -#ifdef HAVE_SYS_STAT_H -#include -#endif -#ifdef HAVE_IFADDRS_H -#include -#endif -#ifdef HAVE_MALLOC_H -#include -#endif - -/* loads a file and returns a pointer to it in memory. The file contains - * a 0 byte(sentinel) after len bytes - the length of the file. */ -static int load_file(const char *fileName, char **data, size_t *len) -{ - /* ensure returned length is always sane */ - *len = 0; - - FILE *pFile; - pFile = fopen(fileName, "rb"); - if (pFile == NULL) { - LOG_ERROR("Can't open %s", fileName); - return ERROR_FAIL; - } - if (fseek(pFile, 0, SEEK_END) != 0) { - LOG_ERROR("Can't open %s", fileName); - fclose(pFile); - return ERROR_FAIL; - } - long fsize = ftell(pFile); - if (fsize == -1) { - LOG_ERROR("Can't open %s", fileName); - fclose(pFile); - return ERROR_FAIL; - } - *len = fsize; - - if (fseek(pFile, 0, SEEK_SET) != 0) { - LOG_ERROR("Can't open %s", fileName); - fclose(pFile); - return ERROR_FAIL; - } - *data = malloc(*len + 1); - if (*data == NULL) { - LOG_ERROR("Can't open %s", fileName); - fclose(pFile); - return ERROR_FAIL; - } - - if (fread(*data, 1, *len, pFile) != *len) { - fclose(pFile); - free(*data); - LOG_ERROR("Can't open %s", fileName); - return ERROR_FAIL; - } - fclose(pFile); - - /* 0-byte after buffer (not included in *len) serves as a sentinel */ - (*data)[*len] = 0; - - return ERROR_OK; -} - -COMMAND_HANDLER(handle_cat_command) -{ - if (CMD_ARGC != 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - /* NOTE!!! we only have line printing capability so we print the entire file as a single - * line. */ - char *data; - size_t len; - - int retval = load_file(CMD_ARGV[0], &data, &len); - if (retval == ERROR_OK) { - command_print(CMD, "%s", data); - free(data); - } else - command_print(CMD, "%s not found", CMD_ARGV[0]); - - return ERROR_OK; -} - -COMMAND_HANDLER(handle_trunc_command) -{ - if (CMD_ARGC != 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - FILE *config_file = NULL; - config_file = fopen(CMD_ARGV[0], "w"); - if (config_file != NULL) - fclose(config_file); - - return ERROR_OK; -} - -#ifdef HAVE_MALLOC_H -COMMAND_HANDLER(handle_meminfo_command) -{ - static int prev; - struct mallinfo info; - - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - info = mallinfo(); - - if (prev > 0) - command_print(CMD, "Diff: %d", prev - info.fordblks); - prev = info.fordblks; - - command_print(CMD, "Available ram: %d", info.fordblks); - - return ERROR_OK; -} -#endif - -COMMAND_HANDLER(handle_append_command) -{ - if (CMD_ARGC < 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - int retval = ERROR_FAIL; - FILE *config_file = NULL; - - config_file = fopen(CMD_ARGV[0], "a"); - if (config_file != NULL) { - fseek(config_file, 0, SEEK_END); - - unsigned i; - for (i = 1; i < CMD_ARGC; i++) { - if (fwrite(CMD_ARGV[i], 1, strlen(CMD_ARGV[i]), - config_file) != strlen(CMD_ARGV[i])) - break; - if (i != CMD_ARGC - 1) { - if (fwrite(" ", 1, 1, config_file) != 1) - break; - } - } - if ((i == CMD_ARGC) && (fwrite("\n", 1, 1, config_file) == 1)) - retval = ERROR_OK; - - fclose(config_file); - } - - return retval; -} - -COMMAND_HANDLER(handle_cp_command) -{ - if (CMD_ARGC != 2) - return ERROR_COMMAND_SYNTAX_ERROR; - - /* NOTE!!! we only have line printing capability so we print the entire file as a single - * line. */ - char *data; - size_t len; - - int retval = load_file(CMD_ARGV[0], &data, &len); - if (retval != ERROR_OK) - return retval; - - FILE *f = fopen(CMD_ARGV[1], "wb"); - if (f == NULL) - retval = ERROR_COMMAND_SYNTAX_ERROR; - - size_t pos = 0; - for (;; ) { - size_t chunk = len - pos; - static const size_t maxChunk = 512 * 1024; /* ~1/sec */ - if (chunk > maxChunk) - chunk = maxChunk; - - if ((retval == ERROR_OK) && (fwrite(data + pos, 1, chunk, f) != chunk)) - retval = ERROR_COMMAND_SYNTAX_ERROR; - - if (retval != ERROR_OK) - break; - - command_print(CMD, "%zu", len - pos); - - pos += chunk; - - if (pos == len) - break; - } - - if (retval == ERROR_OK) - command_print(CMD, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]); - else - command_print(CMD, "copy failed"); - - free(data); - if (f != NULL) - fclose(f); - - if (retval != ERROR_OK) - unlink(CMD_ARGV[1]); - - return retval; -} - -COMMAND_HANDLER(handle_rm_command) -{ - if (CMD_ARGC != 1) - return ERROR_COMMAND_SYNTAX_ERROR; - - bool del = false; - if (rmdir(CMD_ARGV[0]) == 0) - del = true; - else if (unlink(CMD_ARGV[0]) == 0) - del = true; - - return del ? ERROR_OK : ERROR_FAIL; -} - -static int ioutil_Jim_Command_ls(Jim_Interp *interp, - int argc, - Jim_Obj * const *argv) -{ - if (argc != 2) { - Jim_WrongNumArgs(interp, 1, argv, "ls ?dir?"); - return JIM_ERR; - } - - const char *name = Jim_GetString(argv[1], NULL); - - DIR *dirp = NULL; - dirp = opendir(name); - if (dirp == NULL) - return JIM_ERR; - Jim_Obj *objPtr = Jim_NewListObj(interp, NULL, 0); - - for (;; ) { - struct dirent *entry = NULL; - entry = readdir(dirp); - if (entry == NULL) - break; - - if ((strcmp(".", entry->d_name) == 0) || (strcmp("..", entry->d_name) == 0)) - continue; - - Jim_ListAppendElement(interp, objPtr, - Jim_NewStringObj(interp, entry->d_name, strlen(entry->d_name))); - } - closedir(dirp); - - Jim_SetResult(interp, objPtr); - - return JIM_OK; -} - -static int ioutil_Jim_Command_peek(Jim_Interp *interp, - int argc, - Jim_Obj *const *argv) -{ - if (argc != 2) { - Jim_WrongNumArgs(interp, 1, argv, "peek ?address?"); - return JIM_ERR; - } - - long address; - if (Jim_GetLong(interp, argv[1], &address) != JIM_OK) - return JIM_ERR; - - int value = *((volatile int *) address); - - Jim_SetResult(interp, Jim_NewIntObj(interp, value)); - - return JIM_OK; -} - -static int ioutil_Jim_Command_poke(Jim_Interp *interp, - int argc, - Jim_Obj *const *argv) -{ - if (argc != 3) { - Jim_WrongNumArgs(interp, 1, argv, "poke ?address? ?value?"); - return JIM_ERR; - } - - long address; - if (Jim_GetLong(interp, argv[1], &address) != JIM_OK) - return JIM_ERR; - long value; - if (Jim_GetLong(interp, argv[2], &value) != JIM_OK) - return JIM_ERR; - - *((volatile int *) address) = value; - - return JIM_OK; -} - -/* not so pretty code to fish out ip number*/ -static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc, - Jim_Obj *const *argv) -{ -#if !defined(__CYGWIN__) - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); - - struct ifaddrs *ifa = NULL, *ifp = NULL; - - if (getifaddrs(&ifp) < 0) - return JIM_ERR; - - for (ifa = ifp; ifa; ifa = ifa->ifa_next) { - char ip[200]; - socklen_t salen; - - if (ifa->ifa_addr->sa_family == AF_INET) - salen = sizeof(struct sockaddr_in); - else if (ifa->ifa_addr->sa_family == AF_INET6) - salen = sizeof(struct sockaddr_in6); - else - continue; - - if (getnameinfo(ifa->ifa_addr, salen, ip, sizeof(ip), NULL, 0, - NI_NUMERICHOST) < 0) - continue; - - Jim_AppendString(interp, tclOutput, ip, strlen(ip)); - break; - - } - - freeifaddrs(ifp); -#else - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "fixme!!!", 0); - LOG_ERROR("NOT IMPLEMENTED!!!"); -#endif - Jim_SetResult(interp, tclOutput); - - return JIM_OK; -} - -#ifdef HAVE_SYS_IOCTL_H -#ifdef SIOCGIFHWADDR -/* not so pretty code to fish out eth0 mac address */ -static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc, - Jim_Obj *const *argv) -{ - struct ifreq *ifr, *ifend; - struct ifreq ifreq; - struct ifconf ifc; - struct ifreq ifs[5]; - int SockFD; - - SockFD = socket(AF_INET, SOCK_DGRAM, 0); - if (SockFD < 0) - return JIM_ERR; - - ifc.ifc_len = sizeof(ifs); - ifc.ifc_req = ifs; - if (ioctl(SockFD, SIOCGIFCONF, &ifc) < 0) { - close(SockFD); - return JIM_ERR; - } - - ifend = ifs + (ifc.ifc_len / sizeof(struct ifreq)); - for (ifr = ifc.ifc_req; ifr < ifend; ifr++) { - /* if (ifr->ifr_addr.sa_family == AF_INET) */ - { - if (strcmp("eth0", ifr->ifr_name) != 0) - continue; - strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name) - 1); - if (ioctl(SockFD, SIOCGIFHWADDR, &ifreq) < 0) { - close(SockFD); - return JIM_ERR; - } - - close(SockFD); - - Jim_Obj *tclOutput = Jim_NewStringObj(interp, "", 0); - - char buffer[256]; - sprintf(buffer, "%02x-%02x-%02x-%02x-%02x-%02x", - ifreq.ifr_hwaddr.sa_data[0]&0xff, - ifreq.ifr_hwaddr.sa_data[1]&0xff, - ifreq.ifr_hwaddr.sa_data[2]&0xff, - ifreq.ifr_hwaddr.sa_data[3]&0xff, - ifreq.ifr_hwaddr.sa_data[4]&0xff, - ifreq.ifr_hwaddr.sa_data[5]&0xff); - - Jim_AppendString(interp, tclOutput, buffer, strlen(buffer)); - - Jim_SetResult(interp, tclOutput); - - return JIM_OK; - } - } - close(SockFD); - - return JIM_ERR; - -} -#endif -#endif - -static const struct command_registration ioutil_command_handlers[] = { - { - .name = "cat", - .handler = handle_cat_command, - .mode = COMMAND_ANY, - .help = "display text file content", - .usage = "file_name", - }, - { - .name = "trunc", - .handler = handle_trunc_command, - .mode = COMMAND_ANY, - .help = "truncate a file to zero length", - .usage = "file_name", - }, - { - .name = "cp", - .handler = handle_cp_command, - .mode = COMMAND_ANY, - .help = "copy a file", - .usage = "src_file_name dst_file_name", - }, - { - .name = "append_file", - .handler = handle_append_command, - .mode = COMMAND_ANY, - .help = "append a variable number of strings to a file", - .usage = "file_name [, [, ...]]", - }, -#ifdef HAVE_MALLOC_H - { - .name = "meminfo", - .handler = handle_meminfo_command, - .mode = COMMAND_ANY, - .help = "display free heap space", - .usage = "", - }, -#endif - { - .name = "rm", - .mode = COMMAND_ANY, - .handler = handle_rm_command, - .help = "remove a directory or file", - .usage = "file_name", - }, - - /* - * Peek and poke are security holes -- they manipulate - * server-internal addresses. - */ - - /* jim handlers */ - { - .name = "peek", - .mode = COMMAND_ANY, - .jim_handler = ioutil_Jim_Command_peek, - .help = "peek at a memory address", - .usage = "address", - }, - { - .name = "poke", - .mode = COMMAND_ANY, - .jim_handler = ioutil_Jim_Command_poke, - .help = "poke at a memory address", - .usage = "address value", - }, - { - .name = "ls", - .mode = COMMAND_ANY, - .jim_handler = ioutil_Jim_Command_ls, - .help = "show a listing of files", - .usage = "dirname", - }, -#ifdef HAVE_SYS_IOCTL_H -#ifdef SIOCGIFHWADDR - { - .name = "mac", - .mode = COMMAND_ANY, - .jim_handler = ioutil_Jim_Command_mac, - .help = "show MAC address", - }, -#endif -#endif - { - .name = "ip", - .jim_handler = ioutil_Jim_Command_ip, - .mode = COMMAND_ANY, - .help = "show IP address", - }, - COMMAND_REGISTRATION_DONE -}; - -int ioutil_init(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, ioutil_command_handlers); -} diff --git a/src/helper/ioutil.h b/src/helper/ioutil.h deleted file mode 100644 index f060aab09..000000000 --- a/src/helper/ioutil.h +++ /dev/null @@ -1,25 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 Zachary T Welch * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifndef OPENOCD_HELPER_IOUTIL_H -#define OPENOCD_HELPER_IOUTIL_H - -struct command_context; - -int ioutil_init(struct command_context *cmd_ctx); - -#endif /* OPENOCD_HELPER_IOUTIL_H */ diff --git a/src/helper/ioutil_stubs.c b/src/helper/ioutil_stubs.c deleted file mode 100644 index 0d81fe665..000000000 --- a/src/helper/ioutil_stubs.c +++ /dev/null @@ -1,28 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 Zachary T Welch * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include -#endif -#include "ioutil.h" -#include "log.h" - -int ioutil_init(struct command_context *cmd_ctx) -{ - LOG_DEBUG("libocdhelper was built without I/O utility support"); - return ERROR_OK; -} diff --git a/src/openocd.c b/src/openocd.c index 4fec56338..fcefdbe70 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include @@ -341,9 +340,6 @@ int openocd_main(int argc, char *argv[]) if (util_init(cmd_ctx) != ERROR_OK) return EXIT_FAILURE; - if (ioutil_init(cmd_ctx) != ERROR_OK) - return EXIT_FAILURE; - if (rtt_init() != ERROR_OK) return EXIT_FAILURE; From b0fe92dba7c01adc25e5fe3552253a4a8c69ae1a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 1 Nov 2020 12:30:27 +0100 Subject: [PATCH 082/120] zy1000: drop the code, deprecated in v0.10.0 The code for zy1000 has been marked as deprecated in release v0.10.0, 4 years ago. Time to drop it! Change-Id: I08fca2a2bf8f616f031e15fd37dac3197a40ba50 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6090 Tested-by: jenkins --- configure.ac | 43 - doc/manual/jtag.txt | 1 - doc/openocd.texi | 42 +- src/jtag/Makefile.am | 4 - src/jtag/interfaces.c | 8 +- src/jtag/jtag.h | 11 - src/jtag/startup.tcl | 4 +- src/jtag/zy1000/jtag_minidriver.h | 182 ----- src/jtag/zy1000/zy1000.c | 1259 ----------------------------- tcl/board/zy1000.cfg | 117 --- 10 files changed, 5 insertions(+), 1666 deletions(-) delete mode 100644 src/jtag/zy1000/jtag_minidriver.h delete mode 100644 src/jtag/zy1000/zy1000.c delete mode 100644 tcl/board/zy1000.cfg diff --git a/configure.ac b/configure.ac index 215d7a7f7..71cfe21d6 100644 --- a/configure.ac +++ b/configure.ac @@ -283,14 +283,6 @@ AC_ARG_ENABLE([amtjtagaccel], AS_HELP_STRING([--enable-amtjtagaccel], [Enable building the Amontec JTAG-Accelerator driver]), [build_amtjtagaccel=$enableval], [build_amtjtagaccel=no]) -AC_ARG_ENABLE([zy1000_master], - AS_HELP_STRING([--enable-zy1000-master], [Use ZY1000 JTAG master registers]), - [build_zy1000_master=$enableval], [build_zy1000_master=no]) - -AC_ARG_ENABLE([zy1000], - AS_HELP_STRING([--enable-zy1000], [Enable ZY1000 interface]), - [build_zy1000=$enableval], [build_zy1000=no]) - AS_CASE(["${host_cpu}"], [arm*|aarch64], [ AC_ARG_ENABLE([bcm2835gpio], @@ -373,16 +365,6 @@ AC_ARG_ENABLE([internal-libjaylink], [use_internal_libjaylink=$enableval], [use_internal_libjaylink=yes]) build_minidriver=no -AC_MSG_CHECKING([whether to enable ZY1000 minidriver]) -AS_IF([test "x$build_zy1000" = "xyes"], [ - AS_IF([test "x$build_minidriver" = "xyes"], [ - AC_MSG_ERROR([Multiple minidriver options have been enabled.]) - ]) - AC_DEFINE([HAVE_JTAG_MINIDRIVER_H], [1], - [Define to 1 if you have the header file.]) - build_minidriver=yes -]) -AC_MSG_RESULT([$build_zy1000]) AC_ARG_ENABLE([remote-bitbang], AS_HELP_STRING([--enable-remote-bitbang], [Enable building support for the Remote Bitbang jtag driver]), @@ -521,18 +503,6 @@ AS_IF([test "x$build_ep93xx" = "xyes"], [ AC_DEFINE([BUILD_EP93XX], [0], [0 if you don't want ep93xx.]) ]) -AS_IF([test "x$build_zy1000" = "xyes"], [ - AC_DEFINE([BUILD_ZY1000], [1], [1 if you want ZY1000.]) -], [ - AC_DEFINE([BUILD_ZY1000], [0], [0 if you don't want ZY1000.]) -]) - -AS_IF([test "x$build_zy1000_master" = "xyes"], [ - AC_DEFINE([BUILD_ZY1000_MASTER], [1], [1 if you want ZY1000 JTAG master registers.]) -], [ - AC_DEFINE([BUILD_ZY1000_MASTER], [0], [0 if you don't want ZY1000 JTAG master registers.]) -]) - AS_IF([test "x$build_at91rm9200" = "xyes"], [ build_bitbang=yes AC_DEFINE([BUILD_AT91RM9200], [1], [1 if you want at91rm9200.]) @@ -687,9 +657,6 @@ PKG_CHECK_MODULES([LIBJAYLINK], [libjaylink >= 0.2], m4_define([PROCESS_ADAPTERS], [ m4_foreach([adapter], [$1], [ - AS_IF([test "x$build_zy1000" = "xyes"], [ - ADAPTER_VAR([adapter])=no - ]) AS_IF([test $2], [ AS_IF([test "x$ADAPTER_VAR([adapter])" != "xno"], [ AC_DEFINE([BUILD_]ADAPTER_SYM([adapter]), [1], [1 if you want the ]ADAPTER_DESC([adapter]).) @@ -751,8 +718,6 @@ AM_CONDITIONAL([PARPORT], [test "x$build_parport" = "xyes"]) AM_CONDITIONAL([DUMMY], [test "x$build_dummy" = "xyes"]) AM_CONDITIONAL([GIVEIO], [test "x$parport_use_giveio" = "xyes"]) AM_CONDITIONAL([EP93XX], [test "x$build_ep93xx" = "xyes"]) -AM_CONDITIONAL([ZY1000], [test "x$build_zy1000" = "xyes"]) -AM_CONDITIONAL([ZY1000_MASTER], [test "x$build_zy1000_master" = "xyes"]) AM_CONDITIONAL([AT91RM9200], [test "x$build_at91rm9200" = "xyes"]) AM_CONDITIONAL([BCM2835GPIO], [test "x$build_bcm2835gpio" = "xyes"]) AM_CONDITIONAL([IMX_GPIO], [test "x$build_imx_gpio" = "xyes"]) @@ -867,11 +832,3 @@ m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, ]) ]) echo - -AS_IF([test "x$build_zy1000" = "xyes" -o "x$build_zy1000_master" = "xyes"], [ - echo 'WARNING! Deprecated configure option (--enable-zy1000, --enable-zy1000-master)' - echo 'Support for the ZY1000 platform is deprecated and will be removed in the next' - echo 'release. If you regularly use this platform, please report to the OpenOCD' - echo 'Mailing List.' - echo -]) diff --git a/doc/manual/jtag.txt b/doc/manual/jtag.txt index 8f0804ce9..2653fc78f 100644 --- a/doc/manual/jtag.txt +++ b/doc/manual/jtag.txt @@ -36,7 +36,6 @@ asynchronous transactions. - declared in @c src/jtag/minidriver.h - used @a only by the core and minidriver implementations: - @c jtag_driver.c (in-tree OpenOCD drivers) - - @c zy1000/build/include/jtag_minidriver.h (ZY1000 minidriver) - future implementations (on other embedded hosts) - interface device drivers do @b not need this API. diff --git a/doc/openocd.texi b/doc/openocd.texi index f52cfa7d9..b3fe85404 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -298,7 +298,6 @@ The OpenOCD Bug Tracker is hosted on SourceForge: @cindex dongles @cindex FTDI @cindex wiggler -@cindex zy1000 @cindex printer port @cindex USB Adapter @cindex RTCK @@ -307,12 +306,7 @@ Defined: @b{dongle}: A small device that plugs into a computer and serves as an adapter .... [snip] In the OpenOCD case, this generally refers to @b{a small adapter} that -attaches to your computer via USB or the parallel port. One -exception is the Ultimate Solutions ZY1000, packaged as a small box you -attach via an ethernet cable. The ZY1000 has the advantage that it does not -require any drivers to be installed on the developer PC. It also has -a built in web interface. It supports RTCK/RCLK or adaptive clocking -and has a built-in relay to power cycle targets remotely. +attaches to your computer via USB or the parallel port. @section Choosing a Dongle @@ -334,26 +328,6 @@ Ethernet port needed? RTCK support (also known as ``adaptive clocking'')? @end enumerate -@section Stand-alone JTAG Probe - -The ZY1000 from Ultimate Solutions is technically not a dongle but a -stand-alone JTAG probe that, unlike most dongles, doesn't require any drivers -running on the developer's host computer. -Once installed on a network using DHCP or a static IP assignment, users can -access the ZY1000 probe locally or remotely from any host with access to the -IP address assigned to the probe. -The ZY1000 provides an intuitive web interface with direct access to the -OpenOCD debugger. -Users may also run a GDBSERVER directly on the ZY1000 to take full advantage -of GCC & GDB to debug any distribution of embedded Linux or NetBSD running on -the target. -The ZY1000 supports RTCK & RCLK or adaptive clocking and has a built-in relay -to power cycle the target remotely. - -For more information, visit: - -@b{ZY1000} See: @url{http://www.ultsol.com/index.php/component/content/article/8/210-zylin-zy1000-main} - @section USB FT2232 Based There are many USB JTAG dongles on the market, many of them based @@ -3222,20 +3196,6 @@ The string will be of the format "DDDD:BB:SS.F" such as "0000:65:00.1". @end deffn @end deffn -@deffn {Interface Driver} {ZY1000} -This is the Zylin ZY1000 JTAG debugger. -@end deffn - -@quotation Note -This defines some driver-specific commands, -which are not currently documented here. -@end quotation - -@deffn Command power [@option{on}|@option{off}] -Turn power switch to target on/off. -No arguments: print status. -@end deffn - @deffn {Interface Driver} {bcm2835gpio} This SoC is present in Raspberry Pi which is a cheap single-board computer exposing some GPIOs on its expansion header. diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am index b82914bcb..8bc87a484 100644 --- a/src/jtag/Makefile.am +++ b/src/jtag/Makefile.am @@ -8,10 +8,6 @@ CLEANFILES += %D%/minidriver_imp.h if MINIDRIVER -if ZY1000 -JTAG_SRCS += %D%/zy1000/zy1000.c -JTAG_MINIDRIVER_DIR = %D%/zy1000 -endif if MINIDRIVER_DUMMY JTAG_SRCS += %D%/minidummy/minidummy.c JTAG_MINIDRIVER_DIR = %D%/minidummy diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c index 061a78f9c..d229d8cb0 100644 --- a/src/jtag/interfaces.c +++ b/src/jtag/interfaces.c @@ -42,9 +42,7 @@ * that contain an adapter_driver structure that can added to this list. */ -#if BUILD_ZY1000 == 1 -extern struct adapter_driver zy1000_adapter_driver; -#elif defined(BUILD_MINIDRIVER_DUMMY) +#if defined(BUILD_MINIDRIVER_DUMMY) extern struct adapter_driver minidummy_adapter_driver; #else /* standard drivers */ #if BUILD_PARPORT == 1 @@ -162,9 +160,7 @@ extern struct adapter_driver rshim_dap_adapter_driver; * or some number of standard driver interfaces, never both. */ struct adapter_driver *adapter_drivers[] = { -#if BUILD_ZY1000 == 1 - &zy1000_adapter_driver, -#elif defined(BUILD_MINIDRIVER_DUMMY) +#if defined(BUILD_MINIDRIVER_DUMMY) &minidummy_adapter_driver, #else /* standard drivers */ #if BUILD_PARPORT == 1 diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 2fa580223..044d7c0c2 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -46,15 +46,6 @@ typedef enum tap_state { TAP_INVALID = -1, -#if BUILD_ZY1000 - /* These are the old numbers. Leave as-is for now... */ - TAP_RESET = 0, TAP_IDLE = 8, - TAP_DRSELECT = 1, TAP_DRCAPTURE = 2, TAP_DRSHIFT = 3, TAP_DREXIT1 = 4, - TAP_DRPAUSE = 5, TAP_DREXIT2 = 6, TAP_DRUPDATE = 7, - TAP_IRSELECT = 9, TAP_IRCAPTURE = 10, TAP_IRSHIFT = 11, TAP_IREXIT1 = 12, - TAP_IRPAUSE = 13, TAP_IREXIT2 = 14, TAP_IRUPDATE = 15, - -#else /* Proper ARM recommended numbers */ TAP_DREXIT2 = 0x0, TAP_DREXIT1 = 0x1, @@ -72,8 +63,6 @@ typedef enum tap_state { TAP_IRUPDATE = 0xd, TAP_IRCAPTURE = 0xe, TAP_RESET = 0x0f, - -#endif } tap_state_t; /** diff --git a/src/jtag/startup.tcl b/src/jtag/startup.tcl index e5c3b0f75..f1e69e591 100644 --- a/src/jtag/startup.tcl +++ b/src/jtag/startup.tcl @@ -29,7 +29,7 @@ proc init_reset { mode } { ######### # TODO: power_restore and power_dropout are currently neither -# documented nor supported except on ZY1000. +# documented nor supported. proc power_restore {} { echo "Sensed power restore, running reset init and halting GDB." @@ -55,7 +55,7 @@ proc power_dropout {} { ######### # TODO: srst_deasserted and srst_asserted are currently neither -# documented nor supported except on ZY1000. +# documented nor supported. proc srst_deasserted {} { echo "Sensed nSRST deasserted, running reset init and halting GDB." diff --git a/src/jtag/zy1000/jtag_minidriver.h b/src/jtag/zy1000/jtag_minidriver.h deleted file mode 100644 index 7d1ede5d4..000000000 --- a/src/jtag/zy1000/jtag_minidriver.h +++ /dev/null @@ -1,182 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2010 by Øyvind Harboe * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -/* used to test manual mode */ -#define TEST_MANUAL() 0 -#define VERBOSE(a) - -#if BUILD_ZY1000_MASTER - -#define ZY1000_PEEK(a, b) do {b = *((volatile uint32_t *)(a)); } while (0) -#define ZY1000_POKE(a, b) do {*((volatile uint32_t *)(a)) = b; } while (0) -extern volatile void *zy1000_jtag_master; -#define ZY1000_JTAG_BASE ((unsigned long)zy1000_jtag_master) - -#else - -/* redirect this to TCP/IP */ -#define ZY1000_JTAG_BASE 0 -extern void zy1000_tcpout(uint32_t address, uint32_t data); -extern uint32_t zy1000_tcpin(uint32_t address); -#define ZY1000_PEEK(a, b) b = zy1000_tcpin(a) -#define ZY1000_POKE(a, b) zy1000_tcpout(a, b) - -#endif - -#if BUILD_ZY1000_MASTER -/* FIFO empty? */ -static inline void waitIdle(void) -{ - uint32_t empty; - do { - ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty); - } while ((empty & 0x100) == 0); -} - -static inline void zy1000_flush_readqueue(void) -{ - /* Not used w/hardware fifo */ -} -static inline void zy1000_flush_callbackqueue(void) -{ - /* Not used w/hardware fifo */ -} -#else -extern void waitIdle(void); -void zy1000_flush_readqueue(void); -void zy1000_flush_callbackqueue(void); -void zy1000_jtag_add_callback4(jtag_callback_t callback, - jtag_callback_data_t data0, - jtag_callback_data_t data1, - jtag_callback_data_t data2, - jtag_callback_data_t data3); -void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0); -#endif - -static inline void waitQueue(void) -{ -/* waitIdle(); */ -} - -static inline void sampleShiftRegister(void) -{ -#if 0 - uint32_t dummy; - waitIdle(); - ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, dummy); -#endif -} - -static inline void setCurrentState(enum tap_state state) -{ - uint32_t a; - a = state; - int repeat = 0; - if (state == TAP_RESET) { - /* The FPGA nor we know the current state of the CPU TAP */ - /* controller. This will move it to TAP for sure. */ - /* */ - /* 5 should be enough here, 7 is what OpenOCD uses */ - repeat = 7; - } - waitQueue(); - sampleShiftRegister(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | a); - -} - -/* - * Enter state and cause repeat transitions *out* of that state. So if the endState != state, then - * the transition from state to endState counts as a transition out of state. - */ -static inline void shiftValueInner(const enum tap_state state, - const enum tap_state endState, - int repeat, - uint32_t value) -{ - uint32_t a, b; - a = state; - b = endState; - waitQueue(); - sampleShiftRegister(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value); -#if 1 -#if TEST_MANUAL() - if ((state == TAP_DRSHIFT) && (endState != TAP_DRSHIFT)) { - int i; - setCurrentState(state); - for (i = 0; i < repeat; i++) { - int tms; - tms = 0; - if ((i == repeat-1) && (state != endState)) - tms = 1; - /* shift out value */ - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, (((value >> i)&1) << 1) | tms); - } - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - waitIdle(); - /* ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); // set this state and things - * break => expected */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRPAUSE); /* set this and things will - * work => expected. Not - * setting this is not - * sufficient to make things - * break. */ - setCurrentState(endState); - } else - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); - -#else - /* fast version */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); -#endif -#else - /* maximum debug version */ - if ((repeat > 0) && ((state == TAP_DRSHIFT) || (state == TAP_SI))) { - int i; - /* sample shift register for every bit. */ - for (i = 0; i < repeat-1; i++) { - sampleShiftRegister(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> i); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | a); - } - sampleShiftRegister(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0xc, value >> (repeat-1)); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (1 << 8) | (a << 4) | b); - } else { - sampleShiftRegister(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x8, (repeat << 8) | (a << 4) | b); - } - sampleShiftRegister(); -#endif -} - -#if BUILD_ZY1000_MASTER -#define interface_jtag_add_callback(callback, in) callback(in) -#define interface_jtag_add_callback4(callback, in, data1, data2, \ - data3) jtag_set_error(callback(in, data1, data2, data3)) -#else -#define interface_jtag_add_callback(callback, in) zy1000_jtag_add_callback(callback, in) -#define interface_jtag_add_callback4(callback, in, data1, data2, data3) zy1000_jtag_add_callback4( \ - callback, \ - in, \ - data1, \ - data2, \ - data3) -#endif diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c deleted file mode 100644 index 669e6f45c..000000000 --- a/src/jtag/zy1000/zy1000.c +++ /dev/null @@ -1,1259 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2010 by Øyvind Harboe * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -/* This file supports the zy1000 debugger: - * - * http://www.ultsol.com/index.php/component/content/article/8/33-zylin-zy1000-jtag-probe - * - * The zy1000 is a standalone debugger that has a web interface and - * requires no drivers on the developer host as all communication - * is via TCP/IP. The zy1000 gets it performance(~400-700kBytes/s - * DCC downloads @ 16MHz target) as it has an FPGA to hardware - * accelerate the JTAG commands, while offering *very* low latency - * between OpenOCD and the FPGA registers. - * - * The disadvantage of the zy1000 is that it has a feeble CPU compared to - * a PC(ca. 50-500 DMIPS depending on how one counts it), whereas a PC - * is on the order of 10000 DMIPS(i.e. at a factor of 20-200). - * - * The zy1000 revc hardware is using an Altera Nios CPU, whereas the - * revb is using ARM7 + Xilinx. - * - * See Zylin web pages or contact Zylin for more information. - * - * The reason this code is in OpenOCD rather than OpenOCD linked with the - * ZY1000 code is that OpenOCD is the long road towards getting - * libopenocd into place. libopenocd will support both low performance, - * low latency systems(embedded) and high performance high latency - * systems(PCs). - */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include -#include - -#include - -/* Assume we're connecting to a revc w/60MHz clock. */ -#define ZYLIN_KHZ 60000 - -/* The software needs to check if it's in RCLK mode or not */ -static bool zy1000_rclk; - -static int zy1000_khz(int khz, int *jtag_speed) -{ - if (khz == 0) - *jtag_speed = 0; - else { - int speed; - /* Round speed up to nearest divisor. - * - * E.g. 16000kHz - * (64000 + 15999) / 16000 = 4 - * (4 + 1) / 2 = 2 - * 2 * 2 = 4 - * - * 64000 / 4 = 16000 - * - * E.g. 15999 - * (64000 + 15998) / 15999 = 5 - * (5 + 1) / 2 = 3 - * 3 * 2 = 6 - * - * 64000 / 6 = 10666 - * - */ - speed = (ZYLIN_KHZ + (khz - 1)) / khz; - speed = (speed + 1) / 2; - speed *= 2; - if (speed > 8190) { - /* maximum dividend */ - speed = 8190; - } - *jtag_speed = speed; - } - return ERROR_OK; -} - -static int zy1000_speed_div(int speed, int *khz) -{ - if (speed == 0) - *khz = 0; - else - *khz = ZYLIN_KHZ / speed; - - return ERROR_OK; -} - -static bool readPowerDropout(void) -{ - uint32_t state; - /* sample and clear power dropout */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x80); - ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, state); - bool powerDropout; - powerDropout = (state & 0x80) != 0; - return powerDropout; -} - - -static bool readSRST(void) -{ - uint32_t state; - /* sample and clear SRST sensing */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000040); - ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, state); - bool srstAsserted; - srstAsserted = (state & 0x40) != 0; - return srstAsserted; -} - -static int zy1000_srst_asserted(int *srst_asserted) -{ - *srst_asserted = readSRST(); - return ERROR_OK; -} - -static int zy1000_power_dropout(int *dropout) -{ - *dropout = readPowerDropout(); - return ERROR_OK; -} - -/* Wait for SRST to assert or deassert */ -static void waitSRST(bool asserted) -{ - bool first = true; - int64_t start = 0; - int64_t total = 0; - const char *mode = asserted ? "assert" : "deassert"; - - for (;; ) { - bool srstAsserted = readSRST(); - if ((asserted && srstAsserted) || (!asserted && !srstAsserted)) { - if (total > 1) - LOG_USER("SRST took %dms to %s", (int)total, mode); - break; - } - - if (first) { - first = false; - start = timeval_ms(); - } - - total = timeval_ms() - start; - - keep_alive(); - - if (total > 5000) { - LOG_ERROR("SRST took too long to %s: %" PRId64 "ms", mode, total); - break; - } - } -} - -void zy1000_reset(int trst, int srst) -{ - LOG_DEBUG("zy1000 trst=%d, srst=%d", trst, srst); - - /* flush the JTAG FIFO. Not flushing the queue before messing with - * reset has such interesting bugs as causing hard to reproduce - * RCLK bugs as RCLK will stop responding when TRST is asserted - */ - waitIdle(); - - if (!srst) - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000001); - else { - /* Danger!!! if clk != 0 when in - * idle in TAP_IDLE, reset halt on str912 will fail. - */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000001); - - waitSRST(true); - } - - if (!trst) - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x00000002); - else { - /* assert reset */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x00000002); - } - - if (trst || (srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) { - /* we're now in the RESET state until trst is deasserted */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_RESET); - } else { - /* We'll get RCLK failure when we assert TRST, so clear any false positives here */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400); - } - - /* wait for srst to float back up */ - if ((!srst && ((jtag_get_reset_config() & RESET_TRST_PULLS_SRST) == 0)) || - (!srst && !trst && (jtag_get_reset_config() & RESET_TRST_PULLS_SRST))) - waitSRST(false); -} - -int zy1000_speed(int speed) -{ - /* flush JTAG master FIFO before setting speed */ - waitIdle(); - - zy1000_rclk = false; - - if (speed == 0) { - /*0 means RCLK*/ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x100); - zy1000_rclk = true; - LOG_DEBUG("jtag_speed using RCLK"); - } else { - if (speed > 8190 || speed < 2) { - LOG_USER( - "valid ZY1000 jtag_speed=[8190,2]. With divisor is %dkHz / even values between 8190-2, i.e. min %dHz, max %dMHz", - ZYLIN_KHZ, - (ZYLIN_KHZ * 1000) / 8190, - ZYLIN_KHZ / (2 * 1000)); - return ERROR_COMMAND_SYNTAX_ERROR; - } - - int khz; - speed &= ~1; - zy1000_speed_div(speed, &khz); - LOG_USER("jtag_speed %d => JTAG clk=%d kHz", speed, khz); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x100); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x1c, speed); - } - return ERROR_OK; -} - -static bool savePower; - -static void setPower(bool power) -{ - savePower = power; - if (power) - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x8); - else - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x8); -} - -COMMAND_HANDLER(handle_power_command) -{ - switch (CMD_ARGC) { - case 1: { - bool enable; - COMMAND_PARSE_ON_OFF(CMD_ARGV[0], enable); - setPower(enable); - } - /* fall through */ - case 0: - LOG_INFO("Target power %s", savePower ? "on" : "off"); - break; - default: - return ERROR_COMMAND_SYNTAX_ERROR; - } - - return ERROR_OK; -} - -#if !BUILD_ZY1000_MASTER -static char *tcp_server = "notspecified"; -static int jim_zy1000_server(Jim_Interp *interp, int argc, Jim_Obj * const *argv) -{ - if (argc != 2) - return JIM_ERR; - - tcp_server = strdup(Jim_GetString(argv[1], NULL)); - - return JIM_OK; -} -#endif - -static int zylinjtag_Jim_Command_powerstatus(Jim_Interp *interp, - int argc, - Jim_Obj * const *argv) -{ - if (argc != 1) { - Jim_WrongNumArgs(interp, 1, argv, "powerstatus"); - return JIM_ERR; - } - - bool dropout = readPowerDropout(); - - Jim_SetResult(interp, Jim_NewIntObj(interp, dropout)); - - return JIM_OK; -} - -int zy1000_quit(void) -{ - - return ERROR_OK; -} - -int interface_jtag_execute_queue(void) -{ - uint32_t empty; - - waitIdle(); - - /* We must make sure to write data read back to memory location before we return - * from this fn - */ - zy1000_flush_readqueue(); - - /* and handle any callbacks... */ - zy1000_flush_callbackqueue(); - - if (zy1000_rclk) { - /* Only check for errors when using RCLK to speed up - * jtag over TCP/IP - */ - ZY1000_PEEK(ZY1000_JTAG_BASE + 0x10, empty); - /* clear JTAG error register */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x14, 0x400); - - if ((empty&0x400) != 0) { - LOG_WARNING("RCLK timeout"); - /* the error is informative only as we don't want to break the firmware if there - * is a false positive. - */ - /* return ERROR_FAIL; */ - } - } - return ERROR_OK; -} - -static void writeShiftValue(uint8_t *data, int bits); - -/* here we shuffle N bits out/in */ -static inline void scanBits(const uint8_t *out_value, - uint8_t *in_value, - int num_bits, - bool pause_now, - tap_state_t shiftState, - tap_state_t end_state) -{ - tap_state_t pause_state = shiftState; - for (int j = 0; j < num_bits; j += 32) { - int k = num_bits - j; - if (k > 32) { - k = 32; - /* we have more to shift out */ - } else if (pause_now) { - /* this was the last to shift out this time */ - pause_state = end_state; - } - - /* we have (num_bits + 7)/8 bytes of bits to toggle out. */ - /* bits are pushed out LSB to MSB */ - uint32_t value; - value = 0; - if (out_value != NULL) { - for (int l = 0; l < k; l += 8) - value |= out_value[(j + l)/8]<= 32 is not defined by the C standard - * and will in fact shift by &0x1f bits on nios */ - } - - shiftValueInner(shiftState, pause_state, k, value); - - if (in_value != NULL) - writeShiftValue(in_value + (j/8), k); - } -} - -static inline void scanFields(int num_fields, - const struct scan_field *fields, - tap_state_t shiftState, - tap_state_t end_state) -{ - for (int i = 0; i < num_fields; i++) { - scanBits(fields[i].out_value, - fields[i].in_value, - fields[i].num_bits, - (i == num_fields-1), - shiftState, - end_state); - } -} - -int interface_jtag_add_ir_scan(struct jtag_tap *active, - const struct scan_field *fields, - tap_state_t state) -{ - int scan_size = 0; - struct jtag_tap *tap, *nextTap; - tap_state_t pause_state = TAP_IRSHIFT; - - for (tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = nextTap) { - nextTap = jtag_tap_next_enabled(tap); - if (nextTap == NULL) - pause_state = state; - scan_size = tap->ir_length; - - /* search the list */ - if (tap == active) { - scanFields(1, fields, TAP_IRSHIFT, pause_state); - /* update device information */ - buf_cpy(fields[0].out_value, tap->cur_instr, scan_size); - - tap->bypass = 0; - } else { - /* if a device isn't listed, set it to BYPASS */ - assert(scan_size <= 32); - shiftValueInner(TAP_IRSHIFT, pause_state, scan_size, 0xffffffff); - - /* Optimization code will check what the cur_instr is set to, so - * we must set it to bypass value. - */ - buf_set_ones(tap->cur_instr, tap->ir_length); - - tap->bypass = 1; - } - } - - return ERROR_OK; -} - -int interface_jtag_add_plain_ir_scan(int num_bits, - const uint8_t *out_bits, - uint8_t *in_bits, - tap_state_t state) -{ - scanBits(out_bits, in_bits, num_bits, true, TAP_IRSHIFT, state); - return ERROR_OK; -} - -int interface_jtag_add_dr_scan(struct jtag_tap *active, - int num_fields, - const struct scan_field *fields, - tap_state_t state) -{ - struct jtag_tap *tap, *nextTap; - tap_state_t pause_state = TAP_DRSHIFT; - for (tap = jtag_tap_next_enabled(NULL); tap != NULL; tap = nextTap) { - nextTap = jtag_tap_next_enabled(tap); - if (nextTap == NULL) - pause_state = state; - - /* Find a range of fields to write to this tap */ - if (tap == active) { - assert(!tap->bypass); - - scanFields(num_fields, fields, TAP_DRSHIFT, pause_state); - } else { - /* Shift out a 0 for disabled tap's */ - assert(tap->bypass); - shiftValueInner(TAP_DRSHIFT, pause_state, 1, 0); - } - } - return ERROR_OK; -} - -int interface_jtag_add_plain_dr_scan(int num_bits, - const uint8_t *out_bits, - uint8_t *in_bits, - tap_state_t state) -{ - scanBits(out_bits, in_bits, num_bits, true, TAP_DRSHIFT, state); - return ERROR_OK; -} - -int interface_jtag_add_tlr(void) -{ - setCurrentState(TAP_RESET); - return ERROR_OK; -} - -int interface_jtag_add_reset(int req_trst, int req_srst) -{ - zy1000_reset(req_trst, req_srst); - return ERROR_OK; -} - -static int zy1000_jtag_add_clocks(int num_cycles, tap_state_t state, tap_state_t clockstate) -{ - /* num_cycles can be 0 */ - setCurrentState(clockstate); - - /* execute num_cycles, 32 at the time. */ - int i; - for (i = 0; i < num_cycles; i += 32) { - int num; - num = 32; - if (num_cycles-i < num) - num = num_cycles-i; - shiftValueInner(clockstate, clockstate, num, 0); - } - -#if !TEST_MANUAL() - /* finish in end_state */ - setCurrentState(state); -#else - tap_state_t t = TAP_IDLE; - /* test manual drive code on any target */ - int tms; - uint8_t tms_scan = tap_get_tms_path(t, state); - int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); - - for (i = 0; i < tms_count; i++) { - tms = (tms_scan >> i) & 1; - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, tms); - } - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, state); -#endif - - return ERROR_OK; -} - -int interface_jtag_add_runtest(int num_cycles, tap_state_t state) -{ - return zy1000_jtag_add_clocks(num_cycles, state, TAP_IDLE); -} - -int interface_jtag_add_clocks(int num_cycles) -{ - return zy1000_jtag_add_clocks(num_cycles, cmd_queue_cur_state, cmd_queue_cur_state); -} - -int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state state) -{ - /*wait for the fifo to be empty*/ - waitIdle(); - - for (unsigned i = 0; i < num_bits; i++) { - int tms; - - if (((seq[i/8] >> (i % 8)) & 1) == 0) - tms = 0; - else - tms = 1; - - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, tms); - } - - waitIdle(); - if (state != TAP_INVALID) - ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, state); - else { - /* this would be normal if - * we are switching to SWD mode */ - } - return ERROR_OK; -} - -int interface_jtag_add_pathmove(int num_states, const tap_state_t *path) -{ - int state_count; - int tms = 0; - - state_count = 0; - - tap_state_t cur_state = cmd_queue_cur_state; - - uint8_t seq[16]; - memset(seq, 0, sizeof(seq)); - assert(num_states < (int)((sizeof(seq) * 8))); - - while (num_states) { - if (tap_state_transition(cur_state, false) == path[state_count]) - tms = 0; - else if (tap_state_transition(cur_state, true) == path[state_count]) - tms = 1; - else { - LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", - tap_state_name(cur_state), tap_state_name(path[state_count])); - exit(-1); - } - - seq[state_count/8] = seq[state_count/8] | (tms << (state_count % 8)); - - cur_state = path[state_count]; - state_count++; - num_states--; - } - - return interface_add_tms_seq(state_count, seq, cur_state); -} - -static void jtag_pre_post_bits(struct jtag_tap *tap, int *pre, int *post) -{ - /* bypass bits before and after */ - int pre_bits = 0; - int post_bits = 0; - - bool found = false; - struct jtag_tap *cur_tap, *nextTap; - for (cur_tap = jtag_tap_next_enabled(NULL); cur_tap != NULL; cur_tap = nextTap) { - nextTap = jtag_tap_next_enabled(cur_tap); - if (cur_tap == tap) - found = true; - else { - if (found) - post_bits++; - else - pre_bits++; - } - } - *pre = pre_bits; - *post = post_bits; -} - -void embeddedice_write_dcc(struct jtag_tap *tap, - int reg_addr, - const uint8_t *buffer, - int little, - int count) -{ -#if 0 - int i; - for (i = 0; i < count; i++) { - embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, - little)); - buffer += 4; - } -#else - int pre_bits; - int post_bits; - jtag_pre_post_bits(tap, &pre_bits, &post_bits); - - if ((pre_bits > 32) || (post_bits + 6 > 32)) { - int i; - for (i = 0; i < count; i++) { - embeddedice_write_reg_inner(tap, reg_addr, - fast_target_buffer_get_u32(buffer, little)); - buffer += 4; - } - } else { - int i; - for (i = 0; i < count; i++) { - /* Fewer pokes means we get to use the FIFO more efficiently */ - shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, pre_bits, 0); - shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, - fast_target_buffer_get_u32(buffer, little)); - /* Danger! here we need to exit into the TAP_IDLE state to make - * DCC pick up this value. - */ - shiftValueInner(TAP_DRSHIFT, TAP_IDLE, 6 + post_bits, - (reg_addr | (1 << 5))); - buffer += 4; - } - } -#endif -} - -int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, - uint32_t opcode, - uint32_t *data, - size_t count) -{ - /* bypass bits before and after */ - int pre_bits; - int post_bits; - jtag_pre_post_bits(tap, &pre_bits, &post_bits); - post_bits += 2; - - if ((pre_bits > 32) || (post_bits > 32)) { - int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, - uint32_t opcode, uint32_t *data, size_t count); - return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count); - } else { - static const uint8_t zero; - - /* FIX!!!!!! the target_write_memory() API started this nasty problem - * with unaligned uint32_t * pointers... */ - const uint8_t *t = (const uint8_t *)data; - - while (--count > 0) { -#if 1 - /* Danger! This code doesn't update cmd_queue_cur_state, so - * invoking jtag_add_pathmove() before jtag_add_dr_scan() after - * this loop would fail! - */ - shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, pre_bits, 0); - - uint32_t value; - value = *t++; - value |= (*t++<<8); - value |= (*t++<<16); - value |= (*t++<<24); - - shiftValueInner(TAP_DRSHIFT, TAP_DRSHIFT, 32, value); - /* minimum 2 bits */ - shiftValueInner(TAP_DRSHIFT, TAP_DRPAUSE, post_bits, 0); - - /* copy & paste from arm11_dbgtap.c */ - /* TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE, TAP_DRSELECT, - * TAP_DRCAPTURE, TAP_DRSHIFT */ - /* KLUDGE! we have to flush the fifo or the Nios CPU locks up. - * This is probably a bug in the Avalon bus(cross clocking bridge?) - * or in the jtag registers module. - */ - waitIdle(); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 1); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 1); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 1); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - ZY1000_POKE(ZY1000_JTAG_BASE + 0x28, 0); - /* we don't have to wait for the queue to empty here */ - ZY1000_POKE(ZY1000_JTAG_BASE + 0x20, TAP_DRSHIFT); - waitIdle(); -#else - static const tap_state_t arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay[] = { - TAP_DREXIT2, TAP_DRUPDATE, TAP_IDLE, TAP_IDLE, TAP_IDLE, - TAP_DRSELECT, TAP_DRCAPTURE, TAP_DRSHIFT - }; - - struct scan_field fields[2] = { - { .num_bits = 32, .out_value = t }, - { .num_bits = 2, .out_value = &zero }, - }; - t += 4; - - jtag_add_dr_scan(tap, - 2, - fields, - TAP_IDLE); - - jtag_add_pathmove(ARRAY_SIZE(arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay), - arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay); -#endif - } - - struct scan_field fields[2] = { - { .num_bits = 32, .out_value = t }, - { .num_bits = 2, .out_value = &zero }, - }; - - /* This will happen on the last iteration updating cmd_queue_cur_state - * so we don't have to track it during the common code path - */ - jtag_add_dr_scan(tap, - 2, - fields, - TAP_IDLE); - - return jtag_execute_queue(); - } -} - -static const struct command_registration zy1000_commands[] = { - { - .name = "power", - .handler = handle_power_command, - .mode = COMMAND_ANY, - .help = "Turn power switch to target on/off. " - "With no arguments, prints status.", - .usage = "('on'|'off)", - }, -#if !BUILD_ZY1000_MASTER - { - .name = "zy1000_server", - .mode = COMMAND_ANY, - .jim_handler = jim_zy1000_server, - .help = "Tcpip address for ZY1000 server.", - .usage = "address", - }, -#endif - { - .name = "powerstatus", - .mode = COMMAND_ANY, - .jim_handler = zylinjtag_Jim_Command_powerstatus, - .help = "Returns power status of target", - }, - COMMAND_REGISTRATION_DONE -}; - -#if !BUILD_ZY1000_MASTER - -static int tcp_ip = -1; - -/* Write large packets if we can */ -static size_t out_pos; -static uint8_t out_buffer[16384]; -static size_t in_pos; -static size_t in_write; -static uint8_t in_buffer[16384]; - -static bool flush_writes(void) -{ - bool ok = (write(tcp_ip, out_buffer, out_pos) == (int)out_pos); - out_pos = 0; - return ok; -} - -static bool writeLong(uint32_t l) -{ - int i; - for (i = 0; i < 4; i++) { - uint8_t c = (l >> (i*8))&0xff; - out_buffer[out_pos++] = c; - if (out_pos >= sizeof(out_buffer)) { - if (!flush_writes()) - return false; - } - } - return true; -} - -static bool readLong(uint32_t *out_data) -{ - uint32_t data = 0; - int i; - for (i = 0; i < 4; i++) { - uint8_t c; - if (in_pos == in_write) { - /* If we have some data that we can send, send them before - * we wait for more data - */ - if (out_pos > 0) { - if (!flush_writes()) - return false; - } - - /* read more */ - int t; - t = read(tcp_ip, in_buffer, sizeof(in_buffer)); - if (t < 1) - return false; - in_write = (size_t) t; - in_pos = 0; - } - c = in_buffer[in_pos++]; - - data |= (c << (i*8)); - } - *out_data = data; - return true; -} - -enum ZY1000_CMD { - ZY1000_CMD_POKE = 0x0, - ZY1000_CMD_PEEK = 0x8, - ZY1000_CMD_SLEEP = 0x1, - ZY1000_CMD_WAITIDLE = 2 -}; - -#include /* for socket(), connect(), send(), and recv() */ -#include /* for sockaddr_in and inet_addr() */ - -/* We initialize this late since we need to know the server address - * first. - */ -static void tcpip_open(void) -{ - if (tcp_ip >= 0) - return; - - struct sockaddr_in echoServAddr;/* Echo server address */ - - /* Create a reliable, stream socket using TCP */ - tcp_ip = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); - if (tcp_ip < 0) { - fprintf(stderr, "Failed to connect to zy1000 server\n"); - exit(-1); - } - - /* Construct the server address structure */ - memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Zero out structure */ - echoServAddr.sin_family = AF_INET; /* Internet address family */ - echoServAddr.sin_addr.s_addr = inet_addr(tcp_server); /* Server IP address */ - echoServAddr.sin_port = htons(7777); /* Server port */ - - /* Establish the connection to the echo server */ - if (connect(tcp_ip, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) { - fprintf(stderr, "Failed to connect to zy1000 server\n"); - exit(-1); - } - - int flag = 1; - setsockopt(tcp_ip, /* socket affected */ - IPPROTO_TCP, /* set option at TCP level */ - TCP_NODELAY, /* name of option */ - (char *)&flag, /* the cast is historical cruft */ - sizeof(int)); /* length of option value */ - -} - -/* send a poke */ -void zy1000_tcpout(uint32_t address, uint32_t data) -{ - tcpip_open(); - if (!writeLong((ZY1000_CMD_POKE << 24) | address) || !writeLong(data)) { - fprintf(stderr, "Could not write to zy1000 server\n"); - exit(-1); - } -} - -/* By sending the wait to the server, we avoid a readback - * of status. Radically improves performance for this operation - * with long ping times. - */ -void waitIdle(void) -{ - tcpip_open(); - if (!writeLong((ZY1000_CMD_WAITIDLE << 24))) { - fprintf(stderr, "Could not write to zy1000 server\n"); - exit(-1); - } -} - -uint32_t zy1000_tcpin(uint32_t address) -{ - tcpip_open(); - - zy1000_flush_readqueue(); - - uint32_t data; - if (!writeLong((ZY1000_CMD_PEEK << 24) | address) || !readLong(&data)) { - fprintf(stderr, "Could not read from zy1000 server\n"); - exit(-1); - } - return data; -} - -int interface_jtag_add_sleep(uint32_t us) -{ - tcpip_open(); - if (!writeLong((ZY1000_CMD_SLEEP << 24)) || !writeLong(us)) { - fprintf(stderr, "Could not read from zy1000 server\n"); - exit(-1); - } - return ERROR_OK; -} - -/* queue a readback */ -#define readqueue_size 16384 -static struct { - uint8_t *dest; - int bits; -} readqueue[readqueue_size]; - -static int readqueue_pos; - -/* flush the readqueue, this means reading any data that - * we're expecting and store them into the final position - */ -void zy1000_flush_readqueue(void) -{ - if (readqueue_pos == 0) { - /* simply debugging by allowing easy breakpoints when there - * is something to do. */ - return; - } - int i; - tcpip_open(); - for (i = 0; i < readqueue_pos; i++) { - uint32_t value; - if (!readLong(&value)) { - fprintf(stderr, "Could not read from zy1000 server\n"); - exit(-1); - } - - uint8_t *in_value = readqueue[i].dest; - int k = readqueue[i].bits; - - /* we're shifting in data to MSB, shift data to be aligned for returning the value */ - value >>= 32-k; - - for (int l = 0; l < k; l += 8) - in_value[l/8] = (value >> l)&0xff; - } - readqueue_pos = 0; -} - -/* By queuing the callback's we avoid flushing the - * read queue until jtag_execute_queue(). This can - * reduce latency dramatically for cases where - * callbacks are used extensively. -*/ -#define callbackqueue_size 128 -static struct callbackentry { - jtag_callback_t callback; - jtag_callback_data_t data0; - jtag_callback_data_t data1; - jtag_callback_data_t data2; - jtag_callback_data_t data3; -} callbackqueue[callbackqueue_size]; - -static int callbackqueue_pos; - -void zy1000_jtag_add_callback4(jtag_callback_t callback, - jtag_callback_data_t data0, - jtag_callback_data_t data1, - jtag_callback_data_t data2, - jtag_callback_data_t data3) -{ - if (callbackqueue_pos >= callbackqueue_size) - zy1000_flush_callbackqueue(); - - callbackqueue[callbackqueue_pos].callback = callback; - callbackqueue[callbackqueue_pos].data0 = data0; - callbackqueue[callbackqueue_pos].data1 = data1; - callbackqueue[callbackqueue_pos].data2 = data2; - callbackqueue[callbackqueue_pos].data3 = data3; - callbackqueue_pos++; - - /* KLUDGE! - * make callbacks synchronous for now as minidriver requires callback - * to be synchronous. - * - * We can get away with making read and writes asynchronous so we - * don't completely kill performance. - */ - zy1000_flush_callbackqueue(); -} - -static int zy1000_jtag_convert_to_callback4(jtag_callback_data_t data0, - jtag_callback_data_t data1, - jtag_callback_data_t data2, - jtag_callback_data_t data3) -{ - ((jtag_callback1_t)data1)(data0); - return ERROR_OK; -} - -void zy1000_jtag_add_callback(jtag_callback1_t callback, jtag_callback_data_t data0) -{ - zy1000_jtag_add_callback4(zy1000_jtag_convert_to_callback4, - data0, - (jtag_callback_data_t)callback, - 0, - 0); -} - -void zy1000_flush_callbackqueue(void) -{ - /* we have to flush the read queue so we have access to - the data the callbacks will use - */ - zy1000_flush_readqueue(); - int i; - for (i = 0; i < callbackqueue_pos; i++) { - struct callbackentry *entry = &callbackqueue[i]; - jtag_set_error(entry->callback(entry->data0, entry->data1, entry->data2, - entry->data3)); - } - callbackqueue_pos = 0; -} - -static void writeShiftValue(uint8_t *data, int bits) -{ - waitIdle(); - - if (!writeLong((ZY1000_CMD_PEEK << 24) | (ZY1000_JTAG_BASE + 0xc))) { - fprintf(stderr, "Could not read from zy1000 server\n"); - exit(-1); - } - - if (readqueue_pos >= readqueue_size) - zy1000_flush_readqueue(); - - readqueue[readqueue_pos].dest = data; - readqueue[readqueue_pos].bits = bits; - readqueue_pos++; - - /* KLUDGE!!! minidriver requires readqueue to be synchronous */ - zy1000_flush_readqueue(); -} - -#else - -static void writeShiftValue(uint8_t *data, int bits) -{ - uint32_t value; - waitIdle(); - ZY1000_PEEK(ZY1000_JTAG_BASE + 0xc, value); - VERBOSE(LOG_INFO("getShiftValue %08x", value)); - - /* data in, LSB to MSB */ - /* we're shifting in data to MSB, shift data to be aligned for returning the value */ - value >>= 32 - bits; - - for (int l = 0; l < bits; l += 8) - data[l/8] = (value >> l)&0xff; -} - -#endif - -#if BUILD_ZY1000_MASTER - -#ifdef WATCHDOG_BASE -/* If we connect to port 8888 we must send a char every 10s or the board resets itself */ -static void watchdog_server(cyg_addrword_t data) -{ - int so_reuseaddr_option = 1; - - int fd = socket(AF_INET, SOCK_STREAM, 0); - if (fd == -1) { - LOG_ERROR("error creating socket: %s", strerror(errno)); - exit(-1); - } - - setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *) &so_reuseaddr_option, - sizeof(int)); - - struct sockaddr_in sin; - unsigned int address_size; - address_size = sizeof(sin); - memset(&sin, 0, sizeof(sin)); - sin.sin_family = AF_INET; - sin.sin_addr.s_addr = INADDR_ANY; - sin.sin_port = htons(8888); - - if (bind(fd, (struct sockaddr *) &sin, sizeof(sin)) == -1) { - LOG_ERROR("couldn't bind to socket: %s", strerror(errno)); - exit(-1); - } - - if (listen(fd, 1) == -1) { - LOG_ERROR("couldn't listen on socket: %s", strerror(errno)); - exit(-1); - } - - - for (;; ) { - int watchdog_ip = accept(fd, (struct sockaddr *) &sin, &address_size); - - /* Start watchdog, must be reset every 10 seconds. */ - HAL_WRITE_UINT32(WATCHDOG_BASE + 4, 4); - - if (watchdog_ip < 0) { - LOG_ERROR("couldn't open watchdog socket: %s", strerror(errno)); - exit(-1); - } - - int flag = 1; - setsockopt(watchdog_ip, /* socket affected */ - IPPROTO_TCP, /* set option at TCP level */ - TCP_NODELAY, /* name of option */ - (char *)&flag, /* the cast is historical cruft */ - sizeof(int)); /* length of option value */ - - - char buf; - for (;; ) { - if (read(watchdog_ip, &buf, 1) == 1) { - /* Reset timer */ - HAL_WRITE_UINT32(WATCHDOG_BASE + 8, 0x1234); - /* Echo so we can telnet in and see that resetting works */ - write(watchdog_ip, &buf, 1); - } else { - /* Stop tickling the watchdog, the CPU will reset in < 10 seconds - * now. - */ - return; - } - - } - - /* Never reached */ - } -} -#endif - -#endif - -#if BUILD_ZY1000_MASTER -int interface_jtag_add_sleep(uint32_t us) -{ - jtag_sleep(us); - return ERROR_OK; -} -#endif - -#if BUILD_ZY1000_MASTER -volatile void *zy1000_jtag_master; -#include -#endif - -int zy1000_init(void) -{ -#if BUILD_ZY1000_MASTER - int fd = open("/dev/mem", O_RDWR | O_SYNC); - if (fd == -1) { - LOG_ERROR("No access to /dev/mem"); - return ERROR_FAIL; - } -#ifndef REGISTERS_BASE -#define REGISTERS_BASE 0x9002000 -#define REGISTERS_SPAN 128 -#endif - - zy1000_jtag_master = mmap(0, - REGISTERS_SPAN, - PROT_READ | PROT_WRITE, - MAP_SHARED, - fd, - REGISTERS_BASE); - - if (zy1000_jtag_master == (void *) -1) { - close(fd); - LOG_ERROR("No access to /dev/mem"); - return ERROR_FAIL; - } -#endif - - ZY1000_POKE(ZY1000_JTAG_BASE + 0x10, 0x30); /* Turn on LED1 & LED2 */ - - setPower(true); /* on by default */ - - /* deassert resets. Important to avoid infinite loop waiting for SRST to deassert */ - zy1000_reset(0, 0); - - return ERROR_OK; -} - -static struct jtag_interface zy1000_interface = { - .supported = DEBUG_CAP_TMS_SEQ, - .execute_queue = NULL, -}; - -struct adapter_driver zy1000_adapter_driver = { - .name = "ZY1000", - .transports = jtag_only, - .commands = zy1000_commands, - - .init = zy1000_init, - .quit = zy1000_quit, - .speed = zy1000_speed, - .khz = zy1000_khz, - .speed_div = zy1000_speed_div, - .power_dropout = zy1000_power_dropout, - .srst_asserted = zy1000_srst_asserted, - - .jtag_ops = &zy1000_interface, -}; diff --git a/tcl/board/zy1000.cfg b/tcl/board/zy1000.cfg deleted file mode 100644 index e0d1ccf84..000000000 --- a/tcl/board/zy1000.cfg +++ /dev/null @@ -1,117 +0,0 @@ -#Script for ZY1000 - -#Atmel ties SRST & TRST together, at which point it makes -#no sense to use TRST, but use TMS instead. -# -#The annoying thing with tying SRST & TRST together is that -#there is no way to halt the CPU *before and during* the -#SRST reset, which means that the CPU will run a number -#of cycles before it can be halted(as much as milliseconds). -reset_config srst_only srst_pulls_trst - - -if { [info exists CHIPNAME] } { - set _CHIPNAME $CHIPNAME -} else { - set _CHIPNAME zy1000 -} - -if { [info exists ENDIAN] } { - set _ENDIAN $ENDIAN -} else { - set _ENDIAN little -} - - -#jtag scan chain -if { [info exists CPUTAPID] } { - set _CPUTAPID $CPUTAPID -} else { - set _CPUTAPID 0x1f0f0f0f -} -jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPUTAPID - -set _TARGETNAME $_CHIPNAME.cpu -target create $_TARGETNAME arm7tdmi -endian $_ENDIAN -chain-position $_TARGETNAME - -# at CPU CLK <32kHz this must be disabled -arm7_9 fast_memory_access enable -arm7_9 dcc_downloads enable - -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME cfi 0x01000000 0x200000 2 2 $_TARGETNAME - -$_TARGETNAME configure -event reset-init { - # Set up chip selects & timings - mww 0xFFE00000 0x0100273D - mww 0xFFE00004 0x08002125 - mww 0xFFEe0008 0x02002125 - mww 0xFFE0000c 0x03002125 - mww 0xFFE00010 0x40000000 - mww 0xFFE00014 0x50000000 - mww 0xFFE00018 0x60000000 - mww 0xFFE0001c 0x70000000 - mww 0xFFE00020 0x00000001 - mww 0xFFE00024 0x00000000 - - # remap - mww 0xFFFFF124 0xFFFFFFFF - mww 0xffff0010 0x100 - mww 0xffff0034 0x100 - - #disable 16x5x UART interrupts - mww 0x08020004 0 -} - -$_TARGETNAME configure -event gdb-attach { - # Without this gdb-attach will first time as probe will fail - reset init -} - -# required for usable performance. Used for lots of -# other things than flash programming. -$_TARGETNAME configure -work-area-phys 0x00020000 -work-area-size 0x20000 -work-area-backup 0 - -adapter speed 16000 - - -proc production_info {} { - return "Serial number is official MAC number. Format XXXXXXXXXXXX" -} - -# There is no return value from this procedure. If it is -# successful it does not throw an exception -# -# Progress messages are output via puts -proc production {firmwarefile serialnumber} { - if {[string length $serialnumber]!=12} { - echo "Invalid serial number" - return - } - - echo "Power cycling target" - power off - sleep 3000 - power on - sleep 1000 - reset init - flash write_image erase $firmwarefile 0x1000000 bin - verify_image $firmwarefile 0x1000000 bin - - # Big endian... weee!!!! - echo "Setting MAC number to $serialnumber" - flash fillw [expr 0x1030000-0x8] "0x[string range $serialnumber 2 3][string range $serialnumber 0 1]0000" 1 - flash fillw [expr 0x1030000-0x4] "0x[string range $serialnumber 10 11][string range $serialnumber 8 9][string range $serialnumber 6 7][string range $serialnumber 4 5]" 1 - echo "Production successful" -} - - -proc production_test {} { - power on - sleep 1000 - target_request debugmsgs enable - reset run - sleep 25000 - target_request debugmsgs disable - return "See IP address above..." -} From 25218e8935037367e419219f8c855d92a3163023 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 3 Nov 2020 16:50:49 +0100 Subject: [PATCH 083/120] jtag: remove minidriver code and minidriver-dummy With zy1000 removed, there is no other implementation that uses the minidriver, apart from the test/example minidriver-dummy. While the idea of the minidriver is probably still valid (that is to intercept jtag primitives before serialization), there is no current use case, no guarantee it is really working, and the way it was implemented (by macros and #if conditionals) is really hard to maintain and test. Let's let it rip in git history, from where it could eventually be taken back in a more modern implementation. The entry points of minidriver API are still in the code with the original names. Change-Id: I882e32cb26cf5842f9cba14e3badaf8948e3760d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6091 Tested-by: jenkins Reviewed-by: Tomas Vanek --- configure.ac | 30 ----- src/jtag/Makefile.am | 32 ----- src/jtag/adapter.c | 4 - src/jtag/core.c | 8 -- src/jtag/interfaces.c | 11 -- src/jtag/jtag.h | 3 - src/jtag/minidriver.h | 2 +- src/jtag/minidriver/minidriver_imp.h | 30 ----- src/jtag/minidummy/jtag_minidriver.h | 21 ---- src/jtag/minidummy/minidummy.c | 176 --------------------------- src/target/arm11_dbgtap.c | 21 +--- src/target/embeddedice.c | 4 - src/transport/transport.h | 2 +- 13 files changed, 3 insertions(+), 341 deletions(-) delete mode 100644 src/jtag/minidriver/minidriver_imp.h delete mode 100644 src/jtag/minidummy/jtag_minidriver.h delete mode 100644 src/jtag/minidummy/minidummy.c diff --git a/configure.ac b/configure.ac index 71cfe21d6..269452bb6 100644 --- a/configure.ac +++ b/configure.ac @@ -351,10 +351,6 @@ AS_CASE([$host_os], ]) ]) -AC_ARG_ENABLE([minidriver_dummy], - AS_HELP_STRING([--enable-minidriver-dummy], [Enable the dummy minidriver.]), - [build_minidriver_dummy=$enableval], [build_minidriver_dummy=no]) - AC_ARG_ENABLE([internal-jimtcl], AS_HELP_STRING([--disable-internal-jimtcl], [Disable building internal jimtcl]), [use_internal_jimtcl=$enableval], [use_internal_jimtcl=yes]) @@ -364,33 +360,10 @@ AC_ARG_ENABLE([internal-libjaylink], [Disable building internal libjaylink]), [use_internal_libjaylink=$enableval], [use_internal_libjaylink=yes]) -build_minidriver=no - AC_ARG_ENABLE([remote-bitbang], AS_HELP_STRING([--enable-remote-bitbang], [Enable building support for the Remote Bitbang jtag driver]), [build_remote_bitbang=$enableval], [build_remote_bitbang=no]) -AC_MSG_CHECKING([whether to enable dummy minidriver]) -AS_IF([test "x$build_minidriver_dummy" = "xyes"], [ - AS_IF([test "x$build_minidriver" = "xyes"], [ - AC_MSG_ERROR([Multiple minidriver options have been enabled.]) - ]) - build_minidriver=yes - AC_DEFINE([BUILD_MINIDRIVER_DUMMY], [1], [Use the dummy minidriver.]) - AC_DEFINE([HAVE_JTAG_MINIDRIVER_H], [1], - [Define to 1 if you have the header file.]) -]) -AC_MSG_RESULT([$build_minidriver_dummy]) - -AC_MSG_CHECKING([whether standard drivers can be built]) -AS_IF([test "x$build_minidriver" = "xyes"], [ - AC_MSG_RESULT([no]) - AC_MSG_WARN([Using the minidriver disables all other drivers.]) - sleep 2 -], [ - AC_MSG_RESULT([yes]) -]) - AS_CASE(["${host_cpu}"], [i?86|x86*], [], [ @@ -745,9 +718,6 @@ AM_CONDITIONAL([USE_LIBJAYLINK], [test "x$use_libjaylink" = "xyes"]) AM_CONDITIONAL([RSHIM], [test "x$build_rshim" = "xyes"]) AM_CONDITIONAL([HAVE_CAPSTONE], [test "x$enable_capstone" != "xno"]) -AM_CONDITIONAL([MINIDRIVER], [test "x$build_minidriver" = "xyes"]) -AM_CONDITIONAL([MINIDRIVER_DUMMY], [test "x$build_minidriver_dummy" = "xyes"]) - AM_CONDITIONAL([INTERNAL_JIMTCL], [test "x$use_internal_jimtcl" = "xyes"]) AM_CONDITIONAL([INTERNAL_LIBJAYLINK], [test "x$use_internal_libjaylink" = "xyes"]) diff --git a/src/jtag/Makefile.am b/src/jtag/Makefile.am index 8bc87a484..4ed5e7aa0 100644 --- a/src/jtag/Makefile.am +++ b/src/jtag/Makefile.am @@ -3,29 +3,6 @@ noinst_LTLIBRARIES += %D%/libjtag.la JTAG_SRCS = %D%/commands.c %C%_libjtag_la_LIBADD = -BUILT_SOURCES += %D%/minidriver_imp.h -CLEANFILES += %D%/minidriver_imp.h - -if MINIDRIVER - -if MINIDRIVER_DUMMY -JTAG_SRCS += %D%/minidummy/minidummy.c -JTAG_MINIDRIVER_DIR = %D%/minidummy -endif - -MINIDRIVER_IMP_DIR = %D%/minidriver - -%D%/jtag_minidriver.h: $(JTAG_MINIDRIVER_DIR)/jtag_minidriver.h - cp $< $@ - -BUILT_SOURCES += %D%/jtag_minidriver.h - -CLEANFILES += %D%/jtag_minidriver.h - -else - -MINIDRIVER_IMP_DIR = %D%/drivers - if HLADAPTER include %D%/hla/Makefile.am %C%_libjtag_la_LIBADD += $(top_builddir)/%D%/hla/libocdhla.la @@ -39,13 +16,6 @@ endif include %D%/drivers/Makefile.am %C%_libjtag_la_LIBADD += $(top_builddir)/%D%/drivers/libocdjtagdrivers.la -endif -# endif // MINIDRIVER - -%D%/minidriver_imp.h: $(MINIDRIVER_IMP_DIR)/minidriver_imp.h - cp $< $@ - - %C%_libjtag_la_SOURCES = \ %D%/adapter.c \ %D%/core.c \ @@ -59,8 +29,6 @@ endif %D%/interfaces.h \ %D%/minidriver.h \ %D%/jtag.h \ - %D%/minidriver/minidriver_imp.h \ - %D%/minidummy/jtag_minidriver.h \ %D%/swd.h \ %D%/swim.h \ %D%/tcl.h \ diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index af75917a3..cf579ede0 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -497,7 +497,6 @@ COMMAND_HANDLER(handle_adapter_reset_de_assert) (srst == VALUE_DEASSERT) ? SRST_DEASSERT : SRST_ASSERT); } -#ifndef HAVE_JTAG_MINIDRIVER_H #ifdef HAVE_LIBUSB_GET_PORT_NUMBERS COMMAND_HANDLER(handle_usb_location_command) { @@ -522,7 +521,6 @@ static const struct command_registration adapter_usb_command_handlers[] = { #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */ COMMAND_REGISTRATION_DONE }; -#endif /* MINIDRIVER */ static const struct command_registration adapter_srst_command_handlers[] = { { @@ -588,7 +586,6 @@ static const struct command_registration adapter_command_handlers[] = { .help = "Declare transports the adapter supports.", .usage = "transport ... ", }, -#ifndef HAVE_JTAG_MINIDRIVER_H { .name = "usb", .mode = COMMAND_ANY, @@ -596,7 +593,6 @@ static const struct command_registration adapter_command_handlers[] = { .usage = "", .chain = adapter_usb_command_handlers, }, -#endif /* MINIDRIVER */ { .name = "assert", .handler = handle_adapter_reset_de_assert, diff --git a/src/jtag/core.c b/src/jtag/core.c index 5abf832f8..6604c5ae8 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -426,7 +426,6 @@ static void jtag_add_scan_check(struct jtag_tap *active, void (*jtag_add_scan)( for (int i = 0; i < in_num_fields; i++) { if ((in_fields[i].check_value != NULL) && (in_fields[i].in_value != NULL)) { - /* this is synchronous for a minidriver */ jtag_add_callback4(jtag_check_value_mask_callback, (jtag_callback_data_t)in_fields[i].in_value, (jtag_callback_data_t)in_fields[i].check_value, @@ -953,12 +952,6 @@ int default_interface_jtag_execute_queue(void) int result = jtag->jtag_ops->execute_queue(); -#if !HAVE_JTAG_MINIDRIVER_H - /* Only build this if we use a regular driver with a command queue. - * Otherwise jtag_command_queue won't be found at compile/link time. Its - * definition is in jtag/commands.c, which is only built/linked by - * jtag/Makefile.am if MINIDRIVER_DUMMY || !MINIDRIVER, but those variables - * aren't accessible here. Use HAVE_JTAG_MINIDRIVER_H */ struct jtag_command *cmd = jtag_command_queue; while (debug_level >= LOG_LVL_DEBUG_IO && cmd) { switch (cmd->type) { @@ -1017,7 +1010,6 @@ int default_interface_jtag_execute_queue(void) } cmd = cmd->next; } -#endif return result; } diff --git a/src/jtag/interfaces.c b/src/jtag/interfaces.c index d229d8cb0..63faa9561 100644 --- a/src/jtag/interfaces.c +++ b/src/jtag/interfaces.c @@ -42,9 +42,6 @@ * that contain an adapter_driver structure that can added to this list. */ -#if defined(BUILD_MINIDRIVER_DUMMY) -extern struct adapter_driver minidummy_adapter_driver; -#else /* standard drivers */ #if BUILD_PARPORT == 1 extern struct adapter_driver parport_adapter_driver; #endif @@ -150,19 +147,12 @@ extern struct adapter_driver stlink_dap_adapter_driver; #if BUILD_RSHIM == 1 extern struct adapter_driver rshim_dap_adapter_driver; #endif -#endif /* standard drivers */ /** * The list of built-in JTAG interfaces, containing entries for those * drivers that were enabled by the @c configure script. - * - * The list should be defined to contain either one minidriver interface - * or some number of standard driver interfaces, never both. */ struct adapter_driver *adapter_drivers[] = { -#if defined(BUILD_MINIDRIVER_DUMMY) - &minidummy_adapter_driver, -#else /* standard drivers */ #if BUILD_PARPORT == 1 &parport_adapter_driver, #endif @@ -268,6 +258,5 @@ struct adapter_driver *adapter_drivers[] = { #if BUILD_RSHIM == 1 &rshim_dap_adapter_driver, #endif -#endif /* standard drivers */ NULL, }; diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index 044d7c0c2..86091e6a7 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -624,9 +624,6 @@ bool jtag_poll_get_enabled(void); */ void jtag_poll_set_enabled(bool value); - -/* The minidriver may have inline versions of some of the low - * level APIs that are used in inner loops. */ #include int jim_jtag_newtap(Jim_Interp *interp, int argc, Jim_Obj *const *argv); diff --git a/src/jtag/minidriver.h b/src/jtag/minidriver.h index ad830cc13..c6fdfafd3 100644 --- a/src/jtag/minidriver.h +++ b/src/jtag/minidriver.h @@ -45,7 +45,7 @@ /* this header will be provided by the minidriver implementation, */ /* and it may provide additional declarations that must be defined. */ -#include +#include int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, diff --git a/src/jtag/minidriver/minidriver_imp.h b/src/jtag/minidriver/minidriver_imp.h deleted file mode 100644 index 11d0fae72..000000000 --- a/src/jtag/minidriver/minidriver_imp.h +++ /dev/null @@ -1,30 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2005 by Dominic Rath * - * Copyright (C) 2007,2008 Øyvind Harboe * - * Copyright (C) 2009 Zachary T Welch * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifndef OPENOCD_JTAG_MINIDRIVER_MINIDRIVER_IMP_H -#define OPENOCD_JTAG_MINIDRIVER_MINIDRIVER_IMP_H - -#include - -#define jtag_add_callback(callback, in) interface_jtag_add_callback(callback, in) - -#define jtag_add_callback4(callback, in, data1, data2, data3) \ - interface_jtag_add_callback4(callback, in, data1, data2, data3) - -#endif /* OPENOCD_JTAG_MINIDRIVER_MINIDRIVER_IMP_H */ diff --git a/src/jtag/minidummy/jtag_minidriver.h b/src/jtag/minidummy/jtag_minidriver.h deleted file mode 100644 index 1708356a5..000000000 --- a/src/jtag/minidummy/jtag_minidriver.h +++ /dev/null @@ -1,21 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Øyvind Harboe * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#define interface_jtag_add_callback(callback, in) callback(in) - -#define interface_jtag_add_callback4(callback, in, data1, data2, data3) \ - jtag_set_error(callback(in, data1, data2, data3)) diff --git a/src/jtag/minidummy/minidummy.c b/src/jtag/minidummy/minidummy.c deleted file mode 100644 index 7ee206732..000000000 --- a/src/jtag/minidummy/minidummy.c +++ /dev/null @@ -1,176 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by Øyvind Harboe * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include - -static struct jtag_interface minidummy_interface = { - .execute_queue = NULL, -}; - -struct adapter_driver minidummy_adapter_driver = { - .name = "minidummy", - .transports = jtag_only, - .commands = NULL, - - .init = NULL, - .quit = NULL, - .speed = NULL, - .khz = NULL, - .speed_div = NULL, - .power_dropout = NULL, - .srst_asserted = NULL, - - .jtag_ops = &minidummy_interface, -}; - -int interface_jtag_execute_queue(void) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_ir_scan(struct jtag_tap *active, const struct scan_field *fields, - tap_state_t state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_plain_ir_scan(int num_bits, const uint8_t *out_bits, - uint8_t *in_bits, tap_state_t state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_dr_scan(struct jtag_tap *active, int num_fields, - const struct scan_field *fields, tap_state_t state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_plain_dr_scan(int num_bits, const uint8_t *out_bits, - uint8_t *in_bits, tap_state_t state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_tlr(void) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_reset(int req_trst, int req_srst) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_runtest(int num_cycles, tap_state_t state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_clocks(int num_cycles) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_jtag_add_sleep(uint32_t us) -{ - jtag_sleep(us); - return ERROR_OK; -} - -int interface_jtag_add_pathmove(int num_states, const tap_state_t *path) -{ - int state_count; - int tms = 0; - - state_count = 0; - - tap_state_t cur_state = cmd_queue_cur_state; - - while (num_states) { - if (tap_state_transition(cur_state, false) == path[state_count]) - tms = 0; - else if (tap_state_transition(cur_state, true) == path[state_count]) - tms = 1; - else { - LOG_ERROR("BUG: %s -> %s isn't a valid TAP transition", - tap_state_name(cur_state), tap_state_name(path[state_count])); - exit(-1); - } - - /* synchronously do the operation here */ - - cur_state = path[state_count]; - state_count++; - num_states--; - } - - - /* synchronously do the operation here */ - - return ERROR_OK; -} - -int interface_add_tms_seq(unsigned num_bits, const uint8_t *seq, enum tap_state state) -{ - /* synchronously do the operation here */ - - return ERROR_OK; -} - -void embeddedice_write_dcc(struct jtag_tap *tap, int reg_addr, const uint8_t *buffer, - int little, int count) -{ - int i; - for (i = 0; i < count; i++) { - embeddedice_write_reg_inner(tap, reg_addr, fast_target_buffer_get_u32(buffer, little)); - buffer += 4; - } -} - -int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, uint32_t opcode, - uint32_t *data, size_t count) -{ - int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, - uint32_t opcode, uint32_t *data, size_t count); - return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count); -} diff --git a/src/target/arm11_dbgtap.c b/src/target/arm11_dbgtap.c index 60be0096f..823ce5cc1 100644 --- a/src/target/arm11_dbgtap.c +++ b/src/target/arm11_dbgtap.c @@ -562,11 +562,7 @@ static const tap_state_t arm11_MOVE_DRPAUSE_IDLE_DRPAUSE_with_delay[] = { TAP_DRSHIFT }; -/* This inner loop can be implemented by the minidriver, oftentimes in hardware... The - * minidriver can call the default implementation as a fallback or implement it - * from scratch. - */ -int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, +static int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, uint32_t opcode, uint32_t *data, size_t count) @@ -629,21 +625,6 @@ int arm11_run_instr_data_to_core_noack_inner_default(struct jtag_tap *tap, return retval; } -int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, - uint32_t opcode, - uint32_t *data, - size_t count); - -#ifndef HAVE_JTAG_MINIDRIVER_H -int arm11_run_instr_data_to_core_noack_inner(struct jtag_tap *tap, - uint32_t opcode, - uint32_t *data, - size_t count) -{ - return arm11_run_instr_data_to_core_noack_inner_default(tap, opcode, data, count); -} -#endif - /** Execute one instruction via ITR repeatedly while * passing data to the core via DTR on each execution. * diff --git a/src/target/embeddedice.c b/src/target/embeddedice.c index 7c53c45c5..a29508baf 100644 --- a/src/target/embeddedice.c +++ b/src/target/embeddedice.c @@ -645,7 +645,6 @@ int embeddedice_handshake(struct arm_jtag *jtag_info, int hsbit, uint32_t timeou return ERROR_TARGET_TIMEOUT; } -#ifndef HAVE_JTAG_MINIDRIVER_H /** * This is an inner loop of the open loop DCC write of data to target */ @@ -660,6 +659,3 @@ void embeddedice_write_dcc(struct jtag_tap *tap, buffer += 4; } } -#else -/* provided by minidriver */ -#endif diff --git a/src/transport/transport.h b/src/transport/transport.h index 6bf6aaced..e04f78063 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -98,7 +98,7 @@ bool transport_is_dapdirect_jtag(void); bool transport_is_dapdirect_swd(void); bool transport_is_swim(void); -#if BUILD_HLADAPTER && !HAVE_JTAG_MINIDRIVER_H +#if BUILD_HLADAPTER bool transport_is_hla(void); #else static inline bool transport_is_hla(void) From 6c0151623cb09da6a80655cedf568db927ae2d93 Mon Sep 17 00:00:00 2001 From: Christian Hoff Date: Mon, 23 Nov 2020 14:34:56 +0100 Subject: [PATCH 084/120] aarch64: add support for "reset halt" Support halting the CPU directly after a reset. If halt is requested, the CPU stops directly at the reset vector, before any code is executed. This functionality was implemented using the Reset Catch debug event. Change-Id: If90d54c088442340376f0b588ba10267ea8e7327 Signed-off-by: Christian Hoff Reviewed-on: http://openocd.zylin.com/5947 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tarek BOCHKATI --- src/target/aarch64.c | 112 +++++++++++++++++++++++++++++++++++++---- src/target/armv8_dpm.h | 7 +++ 2 files changed, 110 insertions(+), 9 deletions(-) diff --git a/src/target/aarch64.c b/src/target/aarch64.c index d111a0568..e45803040 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -1677,22 +1677,102 @@ static int aarch64_remove_breakpoint(struct target *target, struct breakpoint *b * Cortex-A8 Reset functions */ +static int aarch64_enable_reset_catch(struct target *target, bool enable) +{ + struct armv8_common *armv8 = target_to_armv8(target); + uint32_t edecr; + int retval; + + retval = mem_ap_read_atomic_u32(armv8->debug_ap, + armv8->debug_base + CPUV8_DBG_EDECR, &edecr); + LOG_DEBUG("EDECR = 0x%08" PRIx32 ", enable=%d", edecr, enable); + if (retval != ERROR_OK) + return retval; + + if (enable) + edecr |= ECR_RCE; + else + edecr &= ~ECR_RCE; + + return mem_ap_write_atomic_u32(armv8->debug_ap, + armv8->debug_base + CPUV8_DBG_EDECR, edecr); +} + +static int aarch64_clear_reset_catch(struct target *target) +{ + struct armv8_common *armv8 = target_to_armv8(target); + uint32_t edesr; + int retval; + bool was_triggered; + + /* check if Reset Catch debug event triggered as expected */ + retval = mem_ap_read_atomic_u32(armv8->debug_ap, + armv8->debug_base + CPUV8_DBG_EDESR, &edesr); + if (retval != ERROR_OK) + return retval; + + was_triggered = !!(edesr & ESR_RC); + LOG_DEBUG("Reset Catch debug event %s", + was_triggered ? "triggered" : "NOT triggered!"); + + if (was_triggered) { + /* clear pending Reset Catch debug event */ + edesr &= ~ESR_RC; + retval = mem_ap_write_atomic_u32(armv8->debug_ap, + armv8->debug_base + CPUV8_DBG_EDESR, edesr); + if (retval != ERROR_OK) + return retval; + } + + return ERROR_OK; +} + static int aarch64_assert_reset(struct target *target) { struct armv8_common *armv8 = target_to_armv8(target); + enum reset_types reset_config = jtag_get_reset_config(); + int retval; LOG_DEBUG(" "); - /* FIXME when halt is requested, make it work somehow... */ - /* Issue some kind of warm reset. */ if (target_has_event_action(target, TARGET_EVENT_RESET_ASSERT)) target_handle_event(target, TARGET_EVENT_RESET_ASSERT); - else if (jtag_get_reset_config() & RESET_HAS_SRST) { + else if (reset_config & RESET_HAS_SRST) { + bool srst_asserted = false; + + if (target->reset_halt) { + if (target_was_examined(target)) { + + if (reset_config & RESET_SRST_NO_GATING) { + /* + * SRST needs to be asserted *before* Reset Catch + * debug event can be set up. + */ + adapter_assert_reset(); + srst_asserted = true; + + /* make sure to clear all sticky errors */ + mem_ap_write_atomic_u32(armv8->debug_ap, + armv8->debug_base + CPUV8_DBG_DRCR, DRCR_CSE); + } + + /* set up Reset Catch debug event to halt the CPU after reset */ + retval = aarch64_enable_reset_catch(target, true); + if (retval != ERROR_OK) + LOG_WARNING("%s: Error enabling Reset Catch debug event; the CPU will not halt immediately after reset!", + target_name(target)); + } else { + LOG_WARNING("%s: Target not examined, will not halt immediately after reset!", + target_name(target)); + } + } + /* REVISIT handle "pulls" cases, if there's * hardware that needs them to work. */ - adapter_assert_reset(); + if (!srst_asserted) + adapter_assert_reset(); } else { LOG_ERROR("%s: how to reset?", target_name(target)); return ERROR_FAIL; @@ -1721,23 +1801,37 @@ static int aarch64_deassert_reset(struct target *target) if (!target_was_examined(target)) return ERROR_OK; - retval = aarch64_poll(target); - if (retval != ERROR_OK) - return retval; - retval = aarch64_init_debug_access(target); if (retval != ERROR_OK) return retval; + retval = aarch64_poll(target); + if (retval != ERROR_OK) + return retval; + if (target->reset_halt) { + /* clear pending Reset Catch debug event */ + retval = aarch64_clear_reset_catch(target); + if (retval != ERROR_OK) + LOG_WARNING("%s: Clearing Reset Catch debug event failed", + target_name(target)); + + /* disable Reset Catch debug event */ + retval = aarch64_enable_reset_catch(target, false); + if (retval != ERROR_OK) + LOG_WARNING("%s: Disabling Reset Catch debug event failed", + target_name(target)); + if (target->state != TARGET_HALTED) { LOG_WARNING("%s: ran after reset and before halt ...", target_name(target)); retval = target_halt(target); + if (retval != ERROR_OK) + return retval; } } - return retval; + return ERROR_OK; } static int aarch64_write_cpu_memory_slow(struct target *target, diff --git a/src/target/armv8_dpm.h b/src/target/armv8_dpm.h index ee6f699de..a6cade345 100644 --- a/src/target/armv8_dpm.h +++ b/src/target/armv8_dpm.h @@ -16,6 +16,7 @@ #define OPENOCD_TARGET_ARMV8_DPM_H #include "arm_dpm.h" +#include "helper/bits.h" /* forward-declare struct armv8_common */ struct armv8_common; @@ -96,6 +97,12 @@ void armv8_dpm_report_wfar(struct arm_dpm *dpm, uint64_t wfar); #define DRCR_RESTART (1 << 1) #define DRCR_CLEAR_EXCEPTIONS (1 << 2) +/* ECR (Execution Control Register) bits */ +#define ECR_RCE BIT(1) + +/* ESR (Event Status Register) bits */ +#define ESR_RC BIT(1) + /* PRSR (processor debug status register) bits */ #define PRSR_PU (1 << 0) #define PRSR_SPD (1 << 1) From 41147e6fcde9bbbc485e35f6a9270907b2e38513 Mon Sep 17 00:00:00 2001 From: Tim Newsome Date: Wed, 3 Mar 2021 12:41:03 -0800 Subject: [PATCH 085/120] Implement CRC32 algorithm for RISC-V. Signed-off-by: Tim Newsome Change-Id: Id437f78e74e3d837ff203f84c4eeb996bfad9a01 Reviewed-on: http://openocd.zylin.com/6076 Reviewed-by: Jan Matyas Reviewed-by: Marc Schink Reviewed-by: Antonio Borneo Tested-by: jenkins --- contrib/loaders/checksum/Makefile | 24 +++- contrib/loaders/checksum/riscv32_crc.inc | 70 ++++++++++++ contrib/loaders/checksum/riscv64_crc.inc | 71 ++++++++++++ contrib/loaders/checksum/riscv_crc.c | 140 +++++++++++++++++++++++ src/target/image.c | 2 +- src/target/riscv/riscv.c | 81 ++++++++++++- 6 files changed, 382 insertions(+), 6 deletions(-) create mode 100644 contrib/loaders/checksum/riscv32_crc.inc create mode 100644 contrib/loaders/checksum/riscv64_crc.inc create mode 100644 contrib/loaders/checksum/riscv_crc.c diff --git a/contrib/loaders/checksum/Makefile b/contrib/loaders/checksum/Makefile index b9f59b8d8..623e42576 100644 --- a/contrib/loaders/checksum/Makefile +++ b/contrib/loaders/checksum/Makefile @@ -6,25 +6,41 @@ ARM_OBJCOPY ?= $(ARM_CROSS_COMPILE)objcopy ARM_AFLAGS = -EL +RISCV_CROSS_COMPILE ?= riscv64-unknown-elf- +RISCV_CC ?= $(RISCV_CROSS_COMPILE)gcc +RISCV_OBJCOPY ?= $(RISCV_CROSS_COMPILE)objcopy +RISCV32_CFLAGS = -march=rv32e -mabi=ilp32e -nostdlib -nostartfiles -Os -fPIC +RISCV64_CFLAGS = -march=rv64i -mabi=lp64 -nostdlib -nostartfiles -Os -fPIC + +all: arm riscv + arm: armv4_5_crc.inc armv7m_crc.inc +riscv: riscv32_crc.inc riscv64_crc.inc + armv4_5_%.elf: armv4_5_%.s $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv4_5_%.bin: armv4_5_%.elf $(ARM_OBJCOPY) -Obinary $< $@ -armv4_5_%.inc: armv4_5_%.bin - $(BIN2C) < $< > $@ - armv7m_%.elf: armv7m_%.s $(ARM_AS) $(ARM_AFLAGS) $< -o $@ armv7m_%.bin: armv7m_%.elf $(ARM_OBJCOPY) -Obinary $< $@ -armv7m_%.inc: armv7m_%.bin +%.inc: %.bin $(BIN2C) < $< > $@ +riscv32_%.elf: riscv_%.c + $(RISCV_CC) $(RISCV32_CFLAGS) $< -o $@ + +riscv64_%.elf: riscv_%.c + $(RISCV_CC) $(RISCV64_CFLAGS) $< -o $@ + +riscv%.bin: riscv%.elf + $(RISCV_OBJCOPY) -Obinary $< $@ + clean: -rm -f *.elf *.bin *.inc diff --git a/contrib/loaders/checksum/riscv32_crc.inc b/contrib/loaders/checksum/riscv32_crc.inc new file mode 100644 index 000000000..d6566d2c2 --- /dev/null +++ b/contrib/loaders/checksum/riscv32_crc.inc @@ -0,0 +1,70 @@ +/* Autogenerated with ../../../src/helper/bin2char.sh */ +0xb3,0x05,0xb5,0x00,0x93,0x07,0xf0,0xff,0x17,0x07,0x00,0x00,0x13,0x07,0x47,0x04, +0x63,0x1a,0xb5,0x00,0x13,0x85,0x07,0x00,0x73,0x00,0x10,0x00,0x13,0x85,0x07,0x00, +0x67,0x80,0x00,0x00,0x03,0x46,0x05,0x00,0x93,0x96,0x87,0x00,0x93,0xd7,0x87,0x01, +0xb3,0xc7,0xc7,0x00,0x93,0x97,0x27,0x00,0xb3,0x07,0xf7,0x00,0x83,0xa7,0x07,0x00, +0x13,0x05,0x15,0x00,0xb3,0xc7,0xf6,0x00,0x6f,0xf0,0x9f,0xfc,0x00,0x00,0x00,0x00, +0xb7,0x1d,0xc1,0x04,0x6e,0x3b,0x82,0x09,0xd9,0x26,0x43,0x0d,0xdc,0x76,0x04,0x13, +0x6b,0x6b,0xc5,0x17,0xb2,0x4d,0x86,0x1a,0x05,0x50,0x47,0x1e,0xb8,0xed,0x08,0x26, +0x0f,0xf0,0xc9,0x22,0xd6,0xd6,0x8a,0x2f,0x61,0xcb,0x4b,0x2b,0x64,0x9b,0x0c,0x35, +0xd3,0x86,0xcd,0x31,0x0a,0xa0,0x8e,0x3c,0xbd,0xbd,0x4f,0x38,0x70,0xdb,0x11,0x4c, +0xc7,0xc6,0xd0,0x48,0x1e,0xe0,0x93,0x45,0xa9,0xfd,0x52,0x41,0xac,0xad,0x15,0x5f, +0x1b,0xb0,0xd4,0x5b,0xc2,0x96,0x97,0x56,0x75,0x8b,0x56,0x52,0xc8,0x36,0x19,0x6a, +0x7f,0x2b,0xd8,0x6e,0xa6,0x0d,0x9b,0x63,0x11,0x10,0x5a,0x67,0x14,0x40,0x1d,0x79, +0xa3,0x5d,0xdc,0x7d,0x7a,0x7b,0x9f,0x70,0xcd,0x66,0x5e,0x74,0xe0,0xb6,0x23,0x98, +0x57,0xab,0xe2,0x9c,0x8e,0x8d,0xa1,0x91,0x39,0x90,0x60,0x95,0x3c,0xc0,0x27,0x8b, +0x8b,0xdd,0xe6,0x8f,0x52,0xfb,0xa5,0x82,0xe5,0xe6,0x64,0x86,0x58,0x5b,0x2b,0xbe, +0xef,0x46,0xea,0xba,0x36,0x60,0xa9,0xb7,0x81,0x7d,0x68,0xb3,0x84,0x2d,0x2f,0xad, +0x33,0x30,0xee,0xa9,0xea,0x16,0xad,0xa4,0x5d,0x0b,0x6c,0xa0,0x90,0x6d,0x32,0xd4, +0x27,0x70,0xf3,0xd0,0xfe,0x56,0xb0,0xdd,0x49,0x4b,0x71,0xd9,0x4c,0x1b,0x36,0xc7, +0xfb,0x06,0xf7,0xc3,0x22,0x20,0xb4,0xce,0x95,0x3d,0x75,0xca,0x28,0x80,0x3a,0xf2, +0x9f,0x9d,0xfb,0xf6,0x46,0xbb,0xb8,0xfb,0xf1,0xa6,0x79,0xff,0xf4,0xf6,0x3e,0xe1, +0x43,0xeb,0xff,0xe5,0x9a,0xcd,0xbc,0xe8,0x2d,0xd0,0x7d,0xec,0x77,0x70,0x86,0x34, +0xc0,0x6d,0x47,0x30,0x19,0x4b,0x04,0x3d,0xae,0x56,0xc5,0x39,0xab,0x06,0x82,0x27, +0x1c,0x1b,0x43,0x23,0xc5,0x3d,0x00,0x2e,0x72,0x20,0xc1,0x2a,0xcf,0x9d,0x8e,0x12, +0x78,0x80,0x4f,0x16,0xa1,0xa6,0x0c,0x1b,0x16,0xbb,0xcd,0x1f,0x13,0xeb,0x8a,0x01, +0xa4,0xf6,0x4b,0x05,0x7d,0xd0,0x08,0x08,0xca,0xcd,0xc9,0x0c,0x07,0xab,0x97,0x78, +0xb0,0xb6,0x56,0x7c,0x69,0x90,0x15,0x71,0xde,0x8d,0xd4,0x75,0xdb,0xdd,0x93,0x6b, +0x6c,0xc0,0x52,0x6f,0xb5,0xe6,0x11,0x62,0x02,0xfb,0xd0,0x66,0xbf,0x46,0x9f,0x5e, +0x08,0x5b,0x5e,0x5a,0xd1,0x7d,0x1d,0x57,0x66,0x60,0xdc,0x53,0x63,0x30,0x9b,0x4d, +0xd4,0x2d,0x5a,0x49,0x0d,0x0b,0x19,0x44,0xba,0x16,0xd8,0x40,0x97,0xc6,0xa5,0xac, +0x20,0xdb,0x64,0xa8,0xf9,0xfd,0x27,0xa5,0x4e,0xe0,0xe6,0xa1,0x4b,0xb0,0xa1,0xbf, +0xfc,0xad,0x60,0xbb,0x25,0x8b,0x23,0xb6,0x92,0x96,0xe2,0xb2,0x2f,0x2b,0xad,0x8a, +0x98,0x36,0x6c,0x8e,0x41,0x10,0x2f,0x83,0xf6,0x0d,0xee,0x87,0xf3,0x5d,0xa9,0x99, +0x44,0x40,0x68,0x9d,0x9d,0x66,0x2b,0x90,0x2a,0x7b,0xea,0x94,0xe7,0x1d,0xb4,0xe0, +0x50,0x00,0x75,0xe4,0x89,0x26,0x36,0xe9,0x3e,0x3b,0xf7,0xed,0x3b,0x6b,0xb0,0xf3, +0x8c,0x76,0x71,0xf7,0x55,0x50,0x32,0xfa,0xe2,0x4d,0xf3,0xfe,0x5f,0xf0,0xbc,0xc6, +0xe8,0xed,0x7d,0xc2,0x31,0xcb,0x3e,0xcf,0x86,0xd6,0xff,0xcb,0x83,0x86,0xb8,0xd5, +0x34,0x9b,0x79,0xd1,0xed,0xbd,0x3a,0xdc,0x5a,0xa0,0xfb,0xd8,0xee,0xe0,0x0c,0x69, +0x59,0xfd,0xcd,0x6d,0x80,0xdb,0x8e,0x60,0x37,0xc6,0x4f,0x64,0x32,0x96,0x08,0x7a, +0x85,0x8b,0xc9,0x7e,0x5c,0xad,0x8a,0x73,0xeb,0xb0,0x4b,0x77,0x56,0x0d,0x04,0x4f, +0xe1,0x10,0xc5,0x4b,0x38,0x36,0x86,0x46,0x8f,0x2b,0x47,0x42,0x8a,0x7b,0x00,0x5c, +0x3d,0x66,0xc1,0x58,0xe4,0x40,0x82,0x55,0x53,0x5d,0x43,0x51,0x9e,0x3b,0x1d,0x25, +0x29,0x26,0xdc,0x21,0xf0,0x00,0x9f,0x2c,0x47,0x1d,0x5e,0x28,0x42,0x4d,0x19,0x36, +0xf5,0x50,0xd8,0x32,0x2c,0x76,0x9b,0x3f,0x9b,0x6b,0x5a,0x3b,0x26,0xd6,0x15,0x03, +0x91,0xcb,0xd4,0x07,0x48,0xed,0x97,0x0a,0xff,0xf0,0x56,0x0e,0xfa,0xa0,0x11,0x10, +0x4d,0xbd,0xd0,0x14,0x94,0x9b,0x93,0x19,0x23,0x86,0x52,0x1d,0x0e,0x56,0x2f,0xf1, +0xb9,0x4b,0xee,0xf5,0x60,0x6d,0xad,0xf8,0xd7,0x70,0x6c,0xfc,0xd2,0x20,0x2b,0xe2, +0x65,0x3d,0xea,0xe6,0xbc,0x1b,0xa9,0xeb,0x0b,0x06,0x68,0xef,0xb6,0xbb,0x27,0xd7, +0x01,0xa6,0xe6,0xd3,0xd8,0x80,0xa5,0xde,0x6f,0x9d,0x64,0xda,0x6a,0xcd,0x23,0xc4, +0xdd,0xd0,0xe2,0xc0,0x04,0xf6,0xa1,0xcd,0xb3,0xeb,0x60,0xc9,0x7e,0x8d,0x3e,0xbd, +0xc9,0x90,0xff,0xb9,0x10,0xb6,0xbc,0xb4,0xa7,0xab,0x7d,0xb0,0xa2,0xfb,0x3a,0xae, +0x15,0xe6,0xfb,0xaa,0xcc,0xc0,0xb8,0xa7,0x7b,0xdd,0x79,0xa3,0xc6,0x60,0x36,0x9b, +0x71,0x7d,0xf7,0x9f,0xa8,0x5b,0xb4,0x92,0x1f,0x46,0x75,0x96,0x1a,0x16,0x32,0x88, +0xad,0x0b,0xf3,0x8c,0x74,0x2d,0xb0,0x81,0xc3,0x30,0x71,0x85,0x99,0x90,0x8a,0x5d, +0x2e,0x8d,0x4b,0x59,0xf7,0xab,0x08,0x54,0x40,0xb6,0xc9,0x50,0x45,0xe6,0x8e,0x4e, +0xf2,0xfb,0x4f,0x4a,0x2b,0xdd,0x0c,0x47,0x9c,0xc0,0xcd,0x43,0x21,0x7d,0x82,0x7b, +0x96,0x60,0x43,0x7f,0x4f,0x46,0x00,0x72,0xf8,0x5b,0xc1,0x76,0xfd,0x0b,0x86,0x68, +0x4a,0x16,0x47,0x6c,0x93,0x30,0x04,0x61,0x24,0x2d,0xc5,0x65,0xe9,0x4b,0x9b,0x11, +0x5e,0x56,0x5a,0x15,0x87,0x70,0x19,0x18,0x30,0x6d,0xd8,0x1c,0x35,0x3d,0x9f,0x02, +0x82,0x20,0x5e,0x06,0x5b,0x06,0x1d,0x0b,0xec,0x1b,0xdc,0x0f,0x51,0xa6,0x93,0x37, +0xe6,0xbb,0x52,0x33,0x3f,0x9d,0x11,0x3e,0x88,0x80,0xd0,0x3a,0x8d,0xd0,0x97,0x24, +0x3a,0xcd,0x56,0x20,0xe3,0xeb,0x15,0x2d,0x54,0xf6,0xd4,0x29,0x79,0x26,0xa9,0xc5, +0xce,0x3b,0x68,0xc1,0x17,0x1d,0x2b,0xcc,0xa0,0x00,0xea,0xc8,0xa5,0x50,0xad,0xd6, +0x12,0x4d,0x6c,0xd2,0xcb,0x6b,0x2f,0xdf,0x7c,0x76,0xee,0xdb,0xc1,0xcb,0xa1,0xe3, +0x76,0xd6,0x60,0xe7,0xaf,0xf0,0x23,0xea,0x18,0xed,0xe2,0xee,0x1d,0xbd,0xa5,0xf0, +0xaa,0xa0,0x64,0xf4,0x73,0x86,0x27,0xf9,0xc4,0x9b,0xe6,0xfd,0x09,0xfd,0xb8,0x89, +0xbe,0xe0,0x79,0x8d,0x67,0xc6,0x3a,0x80,0xd0,0xdb,0xfb,0x84,0xd5,0x8b,0xbc,0x9a, +0x62,0x96,0x7d,0x9e,0xbb,0xb0,0x3e,0x93,0x0c,0xad,0xff,0x97,0xb1,0x10,0xb0,0xaf, +0x06,0x0d,0x71,0xab,0xdf,0x2b,0x32,0xa6,0x68,0x36,0xf3,0xa2,0x6d,0x66,0xb4,0xbc, +0xda,0x7b,0x75,0xb8,0x03,0x5d,0x36,0xb5,0xb4,0x40,0xf7,0xb1, diff --git a/contrib/loaders/checksum/riscv64_crc.inc b/contrib/loaders/checksum/riscv64_crc.inc new file mode 100644 index 000000000..e131d7764 --- /dev/null +++ b/contrib/loaders/checksum/riscv64_crc.inc @@ -0,0 +1,71 @@ +/* Autogenerated with ../../../src/helper/bin2char.sh */ +0x93,0x07,0xf0,0xff,0x93,0x06,0xf0,0xff,0x17,0x06,0x00,0x00,0x13,0x06,0x06,0x05, +0x9b,0x85,0xf5,0xff,0x63,0x9a,0xd5,0x00,0x13,0x85,0x07,0x00,0x73,0x00,0x10,0x00, +0x13,0x85,0x07,0x00,0x67,0x80,0x00,0x00,0x83,0x48,0x05,0x00,0x1b,0xd7,0x87,0x01, +0x1b,0x98,0x87,0x00,0x33,0x47,0x17,0x01,0x13,0x17,0x27,0x00,0x33,0x07,0xe6,0x00, +0x83,0x27,0x07,0x00,0x13,0x05,0x15,0x00,0xb3,0xc7,0x07,0x01,0x9b,0x87,0x07,0x00, +0x6f,0xf0,0x1f,0xfc,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xb7,0x1d,0xc1,0x04, +0x6e,0x3b,0x82,0x09,0xd9,0x26,0x43,0x0d,0xdc,0x76,0x04,0x13,0x6b,0x6b,0xc5,0x17, +0xb2,0x4d,0x86,0x1a,0x05,0x50,0x47,0x1e,0xb8,0xed,0x08,0x26,0x0f,0xf0,0xc9,0x22, +0xd6,0xd6,0x8a,0x2f,0x61,0xcb,0x4b,0x2b,0x64,0x9b,0x0c,0x35,0xd3,0x86,0xcd,0x31, +0x0a,0xa0,0x8e,0x3c,0xbd,0xbd,0x4f,0x38,0x70,0xdb,0x11,0x4c,0xc7,0xc6,0xd0,0x48, +0x1e,0xe0,0x93,0x45,0xa9,0xfd,0x52,0x41,0xac,0xad,0x15,0x5f,0x1b,0xb0,0xd4,0x5b, +0xc2,0x96,0x97,0x56,0x75,0x8b,0x56,0x52,0xc8,0x36,0x19,0x6a,0x7f,0x2b,0xd8,0x6e, +0xa6,0x0d,0x9b,0x63,0x11,0x10,0x5a,0x67,0x14,0x40,0x1d,0x79,0xa3,0x5d,0xdc,0x7d, +0x7a,0x7b,0x9f,0x70,0xcd,0x66,0x5e,0x74,0xe0,0xb6,0x23,0x98,0x57,0xab,0xe2,0x9c, +0x8e,0x8d,0xa1,0x91,0x39,0x90,0x60,0x95,0x3c,0xc0,0x27,0x8b,0x8b,0xdd,0xe6,0x8f, +0x52,0xfb,0xa5,0x82,0xe5,0xe6,0x64,0x86,0x58,0x5b,0x2b,0xbe,0xef,0x46,0xea,0xba, +0x36,0x60,0xa9,0xb7,0x81,0x7d,0x68,0xb3,0x84,0x2d,0x2f,0xad,0x33,0x30,0xee,0xa9, +0xea,0x16,0xad,0xa4,0x5d,0x0b,0x6c,0xa0,0x90,0x6d,0x32,0xd4,0x27,0x70,0xf3,0xd0, +0xfe,0x56,0xb0,0xdd,0x49,0x4b,0x71,0xd9,0x4c,0x1b,0x36,0xc7,0xfb,0x06,0xf7,0xc3, +0x22,0x20,0xb4,0xce,0x95,0x3d,0x75,0xca,0x28,0x80,0x3a,0xf2,0x9f,0x9d,0xfb,0xf6, +0x46,0xbb,0xb8,0xfb,0xf1,0xa6,0x79,0xff,0xf4,0xf6,0x3e,0xe1,0x43,0xeb,0xff,0xe5, +0x9a,0xcd,0xbc,0xe8,0x2d,0xd0,0x7d,0xec,0x77,0x70,0x86,0x34,0xc0,0x6d,0x47,0x30, +0x19,0x4b,0x04,0x3d,0xae,0x56,0xc5,0x39,0xab,0x06,0x82,0x27,0x1c,0x1b,0x43,0x23, +0xc5,0x3d,0x00,0x2e,0x72,0x20,0xc1,0x2a,0xcf,0x9d,0x8e,0x12,0x78,0x80,0x4f,0x16, +0xa1,0xa6,0x0c,0x1b,0x16,0xbb,0xcd,0x1f,0x13,0xeb,0x8a,0x01,0xa4,0xf6,0x4b,0x05, +0x7d,0xd0,0x08,0x08,0xca,0xcd,0xc9,0x0c,0x07,0xab,0x97,0x78,0xb0,0xb6,0x56,0x7c, +0x69,0x90,0x15,0x71,0xde,0x8d,0xd4,0x75,0xdb,0xdd,0x93,0x6b,0x6c,0xc0,0x52,0x6f, +0xb5,0xe6,0x11,0x62,0x02,0xfb,0xd0,0x66,0xbf,0x46,0x9f,0x5e,0x08,0x5b,0x5e,0x5a, +0xd1,0x7d,0x1d,0x57,0x66,0x60,0xdc,0x53,0x63,0x30,0x9b,0x4d,0xd4,0x2d,0x5a,0x49, +0x0d,0x0b,0x19,0x44,0xba,0x16,0xd8,0x40,0x97,0xc6,0xa5,0xac,0x20,0xdb,0x64,0xa8, +0xf9,0xfd,0x27,0xa5,0x4e,0xe0,0xe6,0xa1,0x4b,0xb0,0xa1,0xbf,0xfc,0xad,0x60,0xbb, +0x25,0x8b,0x23,0xb6,0x92,0x96,0xe2,0xb2,0x2f,0x2b,0xad,0x8a,0x98,0x36,0x6c,0x8e, +0x41,0x10,0x2f,0x83,0xf6,0x0d,0xee,0x87,0xf3,0x5d,0xa9,0x99,0x44,0x40,0x68,0x9d, +0x9d,0x66,0x2b,0x90,0x2a,0x7b,0xea,0x94,0xe7,0x1d,0xb4,0xe0,0x50,0x00,0x75,0xe4, +0x89,0x26,0x36,0xe9,0x3e,0x3b,0xf7,0xed,0x3b,0x6b,0xb0,0xf3,0x8c,0x76,0x71,0xf7, +0x55,0x50,0x32,0xfa,0xe2,0x4d,0xf3,0xfe,0x5f,0xf0,0xbc,0xc6,0xe8,0xed,0x7d,0xc2, +0x31,0xcb,0x3e,0xcf,0x86,0xd6,0xff,0xcb,0x83,0x86,0xb8,0xd5,0x34,0x9b,0x79,0xd1, +0xed,0xbd,0x3a,0xdc,0x5a,0xa0,0xfb,0xd8,0xee,0xe0,0x0c,0x69,0x59,0xfd,0xcd,0x6d, +0x80,0xdb,0x8e,0x60,0x37,0xc6,0x4f,0x64,0x32,0x96,0x08,0x7a,0x85,0x8b,0xc9,0x7e, +0x5c,0xad,0x8a,0x73,0xeb,0xb0,0x4b,0x77,0x56,0x0d,0x04,0x4f,0xe1,0x10,0xc5,0x4b, +0x38,0x36,0x86,0x46,0x8f,0x2b,0x47,0x42,0x8a,0x7b,0x00,0x5c,0x3d,0x66,0xc1,0x58, +0xe4,0x40,0x82,0x55,0x53,0x5d,0x43,0x51,0x9e,0x3b,0x1d,0x25,0x29,0x26,0xdc,0x21, +0xf0,0x00,0x9f,0x2c,0x47,0x1d,0x5e,0x28,0x42,0x4d,0x19,0x36,0xf5,0x50,0xd8,0x32, +0x2c,0x76,0x9b,0x3f,0x9b,0x6b,0x5a,0x3b,0x26,0xd6,0x15,0x03,0x91,0xcb,0xd4,0x07, +0x48,0xed,0x97,0x0a,0xff,0xf0,0x56,0x0e,0xfa,0xa0,0x11,0x10,0x4d,0xbd,0xd0,0x14, +0x94,0x9b,0x93,0x19,0x23,0x86,0x52,0x1d,0x0e,0x56,0x2f,0xf1,0xb9,0x4b,0xee,0xf5, +0x60,0x6d,0xad,0xf8,0xd7,0x70,0x6c,0xfc,0xd2,0x20,0x2b,0xe2,0x65,0x3d,0xea,0xe6, +0xbc,0x1b,0xa9,0xeb,0x0b,0x06,0x68,0xef,0xb6,0xbb,0x27,0xd7,0x01,0xa6,0xe6,0xd3, +0xd8,0x80,0xa5,0xde,0x6f,0x9d,0x64,0xda,0x6a,0xcd,0x23,0xc4,0xdd,0xd0,0xe2,0xc0, +0x04,0xf6,0xa1,0xcd,0xb3,0xeb,0x60,0xc9,0x7e,0x8d,0x3e,0xbd,0xc9,0x90,0xff,0xb9, +0x10,0xb6,0xbc,0xb4,0xa7,0xab,0x7d,0xb0,0xa2,0xfb,0x3a,0xae,0x15,0xe6,0xfb,0xaa, +0xcc,0xc0,0xb8,0xa7,0x7b,0xdd,0x79,0xa3,0xc6,0x60,0x36,0x9b,0x71,0x7d,0xf7,0x9f, +0xa8,0x5b,0xb4,0x92,0x1f,0x46,0x75,0x96,0x1a,0x16,0x32,0x88,0xad,0x0b,0xf3,0x8c, +0x74,0x2d,0xb0,0x81,0xc3,0x30,0x71,0x85,0x99,0x90,0x8a,0x5d,0x2e,0x8d,0x4b,0x59, +0xf7,0xab,0x08,0x54,0x40,0xb6,0xc9,0x50,0x45,0xe6,0x8e,0x4e,0xf2,0xfb,0x4f,0x4a, +0x2b,0xdd,0x0c,0x47,0x9c,0xc0,0xcd,0x43,0x21,0x7d,0x82,0x7b,0x96,0x60,0x43,0x7f, +0x4f,0x46,0x00,0x72,0xf8,0x5b,0xc1,0x76,0xfd,0x0b,0x86,0x68,0x4a,0x16,0x47,0x6c, +0x93,0x30,0x04,0x61,0x24,0x2d,0xc5,0x65,0xe9,0x4b,0x9b,0x11,0x5e,0x56,0x5a,0x15, +0x87,0x70,0x19,0x18,0x30,0x6d,0xd8,0x1c,0x35,0x3d,0x9f,0x02,0x82,0x20,0x5e,0x06, +0x5b,0x06,0x1d,0x0b,0xec,0x1b,0xdc,0x0f,0x51,0xa6,0x93,0x37,0xe6,0xbb,0x52,0x33, +0x3f,0x9d,0x11,0x3e,0x88,0x80,0xd0,0x3a,0x8d,0xd0,0x97,0x24,0x3a,0xcd,0x56,0x20, +0xe3,0xeb,0x15,0x2d,0x54,0xf6,0xd4,0x29,0x79,0x26,0xa9,0xc5,0xce,0x3b,0x68,0xc1, +0x17,0x1d,0x2b,0xcc,0xa0,0x00,0xea,0xc8,0xa5,0x50,0xad,0xd6,0x12,0x4d,0x6c,0xd2, +0xcb,0x6b,0x2f,0xdf,0x7c,0x76,0xee,0xdb,0xc1,0xcb,0xa1,0xe3,0x76,0xd6,0x60,0xe7, +0xaf,0xf0,0x23,0xea,0x18,0xed,0xe2,0xee,0x1d,0xbd,0xa5,0xf0,0xaa,0xa0,0x64,0xf4, +0x73,0x86,0x27,0xf9,0xc4,0x9b,0xe6,0xfd,0x09,0xfd,0xb8,0x89,0xbe,0xe0,0x79,0x8d, +0x67,0xc6,0x3a,0x80,0xd0,0xdb,0xfb,0x84,0xd5,0x8b,0xbc,0x9a,0x62,0x96,0x7d,0x9e, +0xbb,0xb0,0x3e,0x93,0x0c,0xad,0xff,0x97,0xb1,0x10,0xb0,0xaf,0x06,0x0d,0x71,0xab, +0xdf,0x2b,0x32,0xa6,0x68,0x36,0xf3,0xa2,0x6d,0x66,0xb4,0xbc,0xda,0x7b,0x75,0xb8, +0x03,0x5d,0x36,0xb5,0xb4,0x40,0xf7,0xb1, diff --git a/contrib/loaders/checksum/riscv_crc.c b/contrib/loaders/checksum/riscv_crc.c new file mode 100644 index 000000000..e437b6616 --- /dev/null +++ b/contrib/loaders/checksum/riscv_crc.c @@ -0,0 +1,140 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * Copyright (C) 2009-2021 Free Software Foundation, Inc. + */ + +/* Copied from https://github.com/gcc-mirror/gcc/blob/master/libiberty/crc32.c + * and then tweaked a little. */ + +/* This table was generated by the following program. + #include + int + main () + { + unsigned int i, j; + unsigned int c; + int table[256]; + for (i = 0; i < 256; i++) + { + for (c = i << 24, j = 8; j > 0; --j) + c = c & 0x80000000 ? (c << 1) ^ 0x04c11db7 : (c << 1); + table[i] = c; + } + printf ("static const unsigned int crc32_table[] =\n{\n"); + for (i = 0; i < 256; i += 4) + { + printf (" 0x%08x, 0x%08x, 0x%08x, 0x%08x", + table[i + 0], table[i + 1], table[i + 2], table[i + 3]); + if (i + 4 < 256) + putchar (','); + putchar ('\n'); + } + printf ("};\n"); + return 0; + } + For more information on CRC, see, e.g., + http://www.ross.net/crc/download/crc_v3.txt. */ + +static const unsigned int crc32_table[] = { + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, + 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, + 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, + 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, + 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, + 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, + 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, + 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, + 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, + 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, + 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, + 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, + 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, + 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, + 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, + 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, + 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, + 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, + 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, + 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, + 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, + 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, + 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, + 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, + 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, + 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, + 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, + 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, + 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, + 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, + 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, + 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, + 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, + 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, + 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, + 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, + 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, + 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, + 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, + 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, + 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, + 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, + 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, + 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, + 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, + 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, + 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, + 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, + 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, + 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, + 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, + 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, + 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, + 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, + 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, + 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, + 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 +}; + +/* +@deftypefn Extension {unsigned int} crc32 (const unsigned char *@var{buf}, @ + int @var{len}, unsigned int @var{init}) +Compute the 32-bit CRC of @var{buf} which has length @var{len}. The +starting value is 0xffffffff. +This is used by the @command{gdb} remote protocol for the @samp{qCRC} +command. +This CRC can be specified as: + Width : 32 + Poly : 0x04c11db7 + Init : 0xffffffff + RefIn : false + RefOut : false + XorOut : 0 +This differs from the "standard" CRC-32 algorithm in that the values +are not reflected, and there is no final XOR value. These differences +make it easy to compose the values of multiple blocks. +@end deftypefn +*/ + +#include + +unsigned int +xcrc32(const unsigned char *buf, int len) +{ + uint32_t crc = 0xffffffff; + while (len--) { + crc = (crc << 8) ^ crc32_table[((crc >> 24) ^ *buf) & 255]; + buf++; + } + asm("mv a0, %0;" + "ebreak;" + : + : "r"(crc)); + return crc; +} diff --git a/src/target/image.c b/src/target/image.c index 20c6d77b2..e63cd0f9c 100644 --- a/src/target/image.c +++ b/src/target/image.c @@ -1052,7 +1052,7 @@ int image_calculate_checksum(const uint8_t *buffer, uint32_t nbytes, uint32_t *c keep_alive(); } - LOG_DEBUG("Calculating checksum done"); + LOG_DEBUG("Calculating checksum done; checksum=0x%" PRIx32, crc); *checksum = crc; return ERROR_OK; diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index c26e6358f..c883b4203 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -1853,7 +1853,86 @@ static int riscv_checksum_memory(struct target *target, target_addr_t address, uint32_t count, uint32_t *checksum) { - return ERROR_FAIL; + struct working_area *crc_algorithm; + struct reg_param reg_params[2]; + int retval; + + LOG_DEBUG("address=0x%" TARGET_PRIxADDR "; count=0x%" PRIx32, address, count); + + static const uint8_t riscv32_crc_code[] = { +#include "../../contrib/loaders/checksum/riscv32_crc.inc" + }; + static const uint8_t riscv64_crc_code[] = { +#include "../../contrib/loaders/checksum/riscv64_crc.inc" + }; + + static const uint8_t *crc_code; + + unsigned xlen = riscv_xlen(target); + unsigned crc_code_size; + if (xlen == 32) { + crc_code = riscv32_crc_code; + crc_code_size = sizeof(riscv32_crc_code); + } else { + crc_code = riscv64_crc_code; + crc_code_size = sizeof(riscv64_crc_code); + } + + if (count < crc_code_size * 4) { + /* Don't use the algorithm for relatively small buffers. It's faster + * just to read the memory. target_checksum_memory() will take care of + * that if we fail. */ + return ERROR_FAIL; + } + + retval = target_alloc_working_area(target, crc_code_size, &crc_algorithm); + if (retval != ERROR_OK) + return retval; + + if (crc_algorithm->address + crc_algorithm->size > address && + crc_algorithm->address < address + count) { + /* Region to checksum overlaps with the work area we've been assigned. + * Bail. (Would be better to manually checksum what we read there, and + * use the algorithm for the rest.) */ + target_free_working_area(target, crc_algorithm); + return ERROR_FAIL; + } + + retval = target_write_buffer(target, crc_algorithm->address, crc_code_size, + crc_code); + if (retval != ERROR_OK) { + LOG_ERROR("Failed to write code to " TARGET_ADDR_FMT ": %d", + crc_algorithm->address, retval); + target_free_working_area(target, crc_algorithm); + return retval; + } + + init_reg_param(®_params[0], "a0", xlen, PARAM_IN_OUT); + init_reg_param(®_params[1], "a1", xlen, PARAM_OUT); + buf_set_u64(reg_params[0].value, 0, xlen, address); + buf_set_u64(reg_params[1].value, 0, xlen, count); + + /* 20 second timeout/megabyte */ + int timeout = 20000 * (1 + (count / (1024 * 1024))); + + retval = target_run_algorithm(target, 0, NULL, 2, reg_params, + crc_algorithm->address, + 0, /* Leave exit point unspecified because we don't know. */ + timeout, NULL); + + if (retval == ERROR_OK) + *checksum = buf_get_u32(reg_params[0].value, 0, 32); + else + LOG_ERROR("error executing RISC-V CRC algorithm"); + + destroy_reg_param(®_params[0]); + destroy_reg_param(®_params[1]); + + target_free_working_area(target, crc_algorithm); + + LOG_DEBUG("checksum=0x%" PRIx32 ", result=%d", *checksum, retval); + + return retval; } /*** OpenOCD Helper Functions ***/ From 78462af05feec1627474d26a2c91fcdada5b180e Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Thu, 11 Mar 2021 00:36:17 +0100 Subject: [PATCH 086/120] telnet: support end and home keys this will help navigate to the line start and end easily Change-Id: I3f42eb5267df64c59a85ece67de5fce39a8843ec Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6094 Reviewed-by: Antonio Borneo Tested-by: jenkins --- src/server/telnet_server.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c index 407ab68ae..e9de4f033 100644 --- a/src/server/telnet_server.c +++ b/src/server/telnet_server.c @@ -596,6 +596,12 @@ static int telnet_input(struct connection *connection) telnet_history_up(connection); } else if (*buf_p == 'B') { /* cursor down */ telnet_history_down(connection); + } else if (*buf_p == 'F') { /* end key */ + telnet_move_cursor(connection, t_con->line_size); + t_con->state = TELNET_STATE_DATA; + } else if (*buf_p == 'H') { /* home key */ + telnet_move_cursor(connection, 0); + t_con->state = TELNET_STATE_DATA; } else if (*buf_p == '3') t_con->last_escape = *buf_p; else From 7bc687ade5b338bc182c4e69f35e05a2db00ca9f Mon Sep 17 00:00:00 2001 From: Andrew Wesie Date: Wed, 17 Mar 2021 10:23:16 -0500 Subject: [PATCH 087/120] tcl/interface/ftdi: Add miniWiggler debugger config Change-Id: I91f73a377cd9525008d09fda7a7c58d498014b74 Signed-off-by: Andrew Wesie Reviewed-on: http://openocd.zylin.com/6111 Reviewed-by: Antonio Borneo Tested-by: jenkins --- contrib/60-openocd.rules | 3 +++ tcl/interface/ftdi/miniwiggler.cfg | 34 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 tcl/interface/ftdi/miniwiggler.cfg diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index e0864b827..36bdb5318 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -90,6 +90,9 @@ ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f139", MODE="660", GROUP="plugdev", # Cypress KitProg in CMSIS-DAP mode ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f138", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Infineon DAP miniWiggler v3 +ATTRS{idVendor}=="058b", ATTRS{idProduct}=="0043", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Hilscher NXHX Boards ATTRS{idVendor}=="0640", ATTRS{idProduct}=="0028", MODE="660", GROUP="plugdev", TAG+="uaccess" diff --git a/tcl/interface/ftdi/miniwiggler.cfg b/tcl/interface/ftdi/miniwiggler.cfg new file mode 100644 index 000000000..6e53daede --- /dev/null +++ b/tcl/interface/ftdi/miniwiggler.cfg @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Infineon DAP miniWiggler V3 +# +# https://www.infineon.com/cms/en/product/evaluation-boards/kit_miniwiggler_3_usb/ +# +# Layout: FTDI FT2232 +# ADBUS0 TCK +# ADBUS1 TDI +# ADBUS2 TDO +# ADBUS3 TMS +# ADBUS4 nOE (output enable) +# ADBUS5 +# ADBUS6 +# ADBUS7 Blue LED +# +# ACBUS0 nTRST +# ACBUS1 nSRST +# ACUBS2 +# ACBUS3 +# ACBUS4 +# ACBUS5 +# ACBUS6 +# ACBUS7 +# + +adapter driver ftdi +ftdi_device_desc "DAS JDS miniWiggler V3.1" +ftdi_vid_pid 0x058b 0x0043 + +ftdi_channel 0 +ftdi_layout_init 0x0008 0x001b +ftdi_layout_signal nTRST -data 0x0100 -oe 0x0100 +ftdi_layout_signal nSRST -data 0x0200 -oe 0x0200 From 84af95bb54926f9cec10673362457aa99415c0cd Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Wed, 14 Oct 2020 18:07:14 +0100 Subject: [PATCH 088/120] aarch64: handle semihosting in aarch32 state Change-Id: I0e868d617db126a2b258e27b11979b75b5bb72f5 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5860 Tested-by: jenkins Reviewed-by: Matthias Welwarsky Reviewed-by: Antonio Borneo --- src/target/arm_semihosting.c | 57 +++++++++++++++++++++++++++++++++++- src/target/armv8.c | 7 ----- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/src/target/arm_semihosting.c b/src/target/arm_semihosting.c index 723be577e..9de7048f4 100644 --- a/src/target/arm_semihosting.c +++ b/src/target/arm_semihosting.c @@ -123,6 +123,22 @@ static int post_result(struct target *target) uint64_t pc = buf_get_u64(arm->core_cache->reg_list[32].value, 0, 64); buf_set_u64(arm->pc->value, 0, 64, pc + 4); arm->pc->dirty = true; + } else if (arm->core_state == ARM_STATE_ARM) { + /* return value in R0 */ + buf_set_u32(arm->core_cache->reg_list[0].value, 0, 32, target->semihosting->result); + arm->core_cache->reg_list[0].dirty = true; + + uint32_t pc = buf_get_u32(arm->core_cache->reg_list[32].value, 0, 32); + buf_set_u32(arm->pc->value, 0, 32, pc + 4); + arm->pc->dirty = true; + } else if (arm->core_state == ARM_STATE_THUMB) { + /* return value in R0 */ + buf_set_u32(arm->core_cache->reg_list[0].value, 0, 32, target->semihosting->result); + arm->core_cache->reg_list[0].dirty = true; + + uint32_t pc = buf_get_u32(arm->core_cache->reg_list[32].value, 0, 32); + buf_set_u32(arm->pc->value, 0, 32, pc + 2); + arm->pc->dirty = true; } } else { /* resume execution, this will be pc+2 to skip over the @@ -275,6 +291,16 @@ int arm_semihosting(struct target *target, int *retval) if (target->debug_reason != DBG_REASON_BREAKPOINT) return 0; + /* According to ARM Semihosting for AArch32 and AArch64: + * The HLT encodings are new in version 2.0 of the semihosting specification. + * Where possible, have semihosting callers continue to use the previously + * existing trap instructions to ensure compatibility with legacy semihosting + * implementations. + * These trap instructions are HLT for A64, SVC on A+R profile A32 or T32, + * and BKPT on M profile. + * However, it is necessary to change from SVC to HLT instructions to support + * AArch32 semihosting properly in a mixed AArch32/AArch64 system. */ + if (arm->core_state == ARM_STATE_AARCH64) { uint32_t insn = 0; r = arm->pc; @@ -284,9 +310,38 @@ int arm_semihosting(struct target *target, int *retval) if (*retval != ERROR_OK) return 1; - /* bkpt 0xAB */ + /* HLT 0xF000 */ if (insn != 0xD45E0000) return 0; + } else if (arm->core_state == ARM_STATE_ARM) { + r = arm->pc; + pc = buf_get_u32(arm->pc->value, 0, 32); + + /* A32 instruction => check for HLT 0xF000 (0xE10F0070) */ + uint32_t insn = 0; + + *retval = target_read_u32(target, pc, &insn); + + if (*retval != ERROR_OK) + return 1; + + /* HLT 0xF000*/ + if (insn != 0xE10F0070) + return 0; + } else if (arm->core_state == ARM_STATE_THUMB) { + r = arm->pc; + pc = buf_get_u32(arm->pc->value, 0, 32); + + /* T32 instruction => check for HLT 0x3C (0xBABC) */ + uint16_t insn = 0; + *retval = target_read_u16(target, pc, &insn); + + if (*retval != ERROR_OK) + return 1; + + /* HLT 0x3C*/ + if (insn != 0xBABC) + return 0; } else return 1; } else { diff --git a/src/target/armv8.c b/src/target/armv8.c index 95efdc90b..6bf3b110d 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -1098,13 +1098,6 @@ int armv8_handle_cache_info_command(struct command_invocation *cmd, static int armv8_setup_semihosting(struct target *target, int enable) { - struct arm *arm = target_to_arm(target); - - if (arm->core_state != ARM_STATE_AARCH64) { - LOG_ERROR("semihosting only supported in AArch64 state\n"); - return ERROR_FAIL; - } - return ERROR_OK; } From 6db49eb8858023654084088c73d968e190aec491 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Fri, 12 Mar 2021 18:38:02 +0100 Subject: [PATCH 089/120] build: remove warnings with gcc 11 This removes some warnings which prevent a successful build with -Werror which is enabled by default. I'm using gcc 11, so maybe others are not getting this warnings yet. In src/flash/nor/numicro.c the debug messages were misleadingly indented. In src/target/arm920t.c the array size where smaller than expected from the receiving function. Change-Id: I66f5c6a63beb9f9416e73b726299297476c884d8 Signed-off-by: Rene Kita Reviewed-on: http://openocd.zylin.com/6104 Reviewed-by: Jonathan McDowell Tested-by: jenkins Reviewed-by: Tomas Vanek Reviewed-by: Antonio Borneo --- src/flash/nor/numicro.c | 6 +++--- src/target/arm920t.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/flash/nor/numicro.c b/src/flash/nor/numicro.c index 7609fa81c..1971daa24 100644 --- a/src/flash/nor/numicro.c +++ b/src/flash/nor/numicro.c @@ -1243,7 +1243,7 @@ static uint32_t numicro_fmc_cmd(struct target *target, uint32_t cmd, uint32_t ad retval = target_read_u32(target, NUMICRO_FLASH_ISPTRG, &status); if (retval != ERROR_OK) return retval; - LOG_DEBUG("status: 0x%" PRIx32 "", status); + LOG_DEBUG("status: 0x%" PRIx32 "", status); if ((status & (ISPTRG_ISPGO)) == 0) break; if (timeout-- <= 0) { @@ -1512,7 +1512,7 @@ static int numicro_erase(struct flash_bank *bank, unsigned int first, retval = target_read_u32(target, NUMICRO_FLASH_ISPTRG, &status); if (retval != ERROR_OK) return retval; - LOG_DEBUG("status: 0x%" PRIx32 "", status); + LOG_DEBUG("status: 0x%" PRIx32 "", status); if (status == 0) break; if (timeout-- <= 0) { @@ -1601,7 +1601,7 @@ static int numicro_write(struct flash_bank *bank, const uint8_t *buffer, retval = target_read_u32(target, NUMICRO_FLASH_ISPTRG, &status); if (retval != ERROR_OK) return retval; - LOG_DEBUG("status: 0x%" PRIx32 "", status); + LOG_DEBUG("status: 0x%" PRIx32 "", status); if (status == 0) break; if (timeout-- <= 0) { diff --git a/src/target/arm920t.c b/src/target/arm920t.c index 80f6d7045..a45dc6420 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -245,8 +245,8 @@ static int arm920t_read_cp15_interpreted(struct target *target, uint32_t cp15_opcode, uint32_t address, uint32_t *value) { struct arm *arm = target_to_arm(target); - uint32_t *regs_p[1]; - uint32_t regs[2]; + uint32_t *regs_p[16]; + uint32_t regs[16]; uint32_t cp15c15 = 0x0; struct reg *r = arm->core_cache->reg_list; @@ -295,7 +295,7 @@ int arm920t_write_cp15_interpreted(struct target *target, { uint32_t cp15c15 = 0x0; struct arm *arm = target_to_arm(target); - uint32_t regs[2]; + uint32_t regs[16]; struct reg *r = arm->core_cache->reg_list; /* load value, address into R0, R1 */ From eca4f964b47d317a0eb4b148f11588cec0e3bf60 Mon Sep 17 00:00:00 2001 From: Evgeniy Didin Date: Mon, 15 Mar 2021 16:30:13 +0300 Subject: [PATCH 090/120] target/arc: refactor ARC register numbers defines For Zephyr rtos support it is necessary to define general register numbers for architecture. There were some already in arc.h file. Let's define ARC registers numbers as a set instead of separate defines. Change-Id: I63742b8608f9556c2ec9bd2661a0fd9cf88e9b74 Signed-off-by: Evgeniy Didin Reviewed-on: http://openocd.zylin.com/6105 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/target/arc.c | 6 +++--- src/target/arc.h | 49 +++++++++++++++++++++++++++++++++++++++++--- src/target/arc_cmd.c | 4 ++-- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/src/target/arc.c b/src/target/arc.c index 8e568455e..694ac6f85 100644 --- a/src/target/arc.c +++ b/src/target/arc.c @@ -227,7 +227,7 @@ static int arc_get_register(struct reg *reg) if (desc->is_core) { /* Accessing to R61/R62 registers causes Jtag hang */ - if (desc->arch_num == CORE_R61_NUM || desc->arch_num == CORE_R62_NUM) { + if (desc->arch_num == ARC_R61 || desc->arch_num == ARC_R62) { LOG_ERROR("It is forbidden to read core registers 61 and 62."); return ERROR_FAIL; } @@ -267,8 +267,8 @@ static int arc_set_register(struct reg *reg, uint8_t *buf) return ERROR_TARGET_NOT_HALTED; /* Accessing to R61/R62 registers causes Jtag hang */ - if (desc->is_core && (desc->arch_num == CORE_R61_NUM || - desc->arch_num == CORE_R62_NUM)) { + if (desc->is_core && (desc->arch_num == ARC_R61 || + desc->arch_num == ARC_R62)) { LOG_ERROR("It is forbidden to write core registers 61 and 62."); return ERROR_FAIL; } diff --git a/src/target/arc.h b/src/target/arc.h index aeb326cb5..8d44bfa41 100644 --- a/src/target/arc.h +++ b/src/target/arc.h @@ -45,9 +45,52 @@ #define AUX_STATUS32_REG_HALT_BIT BIT(0) #define AUX_STATUS32_REG_IE_BIT BIT(31) /* STATUS32[31] = IE field */ -/* Reserved core registers */ -#define CORE_R61_NUM (61) -#define CORE_R62_NUM (62) +/* ARC register numbers */ +enum { + ARC_R0, + ARC_R1, + ARC_R2, + ARC_R3, + ARC_R4, + ARC_R5, + ARC_R6, + ARC_R7, + ARC_R8, + ARC_R9, + ARC_R10, + ARC_R11, + ARC_R12, + ARC_R13, + ARC_R14, + ARC_R15, + ARC_R16, + ARC_R17, + ARC_R18, + ARC_R19, + ARC_R20, + ARC_R21, + ARC_R22, + ARC_R23, + ARC_R24, + ARC_R25, + ARC_GP = 26, + ARC_FP = 27, + ARC_SP = 28, + ARC_ILINK = 29, + ARC_R30, + ARC_BLINK = 31, + ARC_LP_COUNT = 60, + + /* Reserved registers */ + ARC_R61 = 61, + ARC_R62 = 62, + + ARC_PCL = 63, + ARC_PC = 64, + ARC_LP_START = 65, + ARC_LP_END = 66, + ARC_STATUS32 = 67, +}; #define CORE_REG_MAX_NUMBER (63) diff --git a/src/target/arc_cmd.c b/src/target/arc_cmd.c index 18f5cb8f4..5c5247b88 100644 --- a/src/target/arc_cmd.c +++ b/src/target/arc_cmd.c @@ -382,7 +382,7 @@ static int jim_arc_get_core_reg(Jim_Interp *interp, int argc, Jim_Obj * const *a /* Register number */ JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi, ®num)); - if (regnum > CORE_REG_MAX_NUMBER || regnum == CORE_R61_NUM || regnum == CORE_R62_NUM) { + if (regnum > CORE_REG_MAX_NUMBER || regnum == ARC_R61 || regnum == ARC_R62) { Jim_SetResultFormatted(goi.interp, "Core register number %i " "is invalid. Must less then 64 and not 61 and 62.", regnum); return JIM_ERR; @@ -425,7 +425,7 @@ static int jim_arc_set_core_reg(Jim_Interp *interp, int argc, Jim_Obj * const *a /* Register number */ JIM_CHECK_RETVAL(arc_cmd_jim_get_uint32(&goi, ®num)); - if (regnum > CORE_REG_MAX_NUMBER || regnum == CORE_R61_NUM || regnum == CORE_R62_NUM) { + if (regnum > CORE_REG_MAX_NUMBER || regnum == ARC_R61 || regnum == ARC_R62) { Jim_SetResultFormatted(goi.interp, "Core register number %i " "is invalid. Must less then 64 and not 61 and 62.", regnum); return JIM_ERR; From 08c7b904c38b97f9de72a19196b295652f051268 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Tue, 12 Feb 2019 13:51:54 +0100 Subject: [PATCH 091/120] drivers: USB Blaster II: claim interface before using it If not, multiple instances of OOCD can concurrently use it. Change-Id: I48cc9d90521d1dcc7720c6e8bec74f45972d16f7 Signed-off-by: Oleksij Rempel Reviewed-on: http://openocd.zylin.com/4589 Tested-by: jenkins Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- .../usb_blaster/ublast2_access_libusb.c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c index 6f15fa70a..82dc95071 100644 --- a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c +++ b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c @@ -133,6 +133,11 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, return ERROR_FAIL; } + if (libusb_claim_interface(libusb_dev, 0)) { + LOG_ERROR("unable to claim interface"); + return ERROR_JTAG_INIT_FAILED; + } + ublast2_firmware_image.base_address = 0; ublast2_firmware_image.base_address_set = false; @@ -184,6 +189,13 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, image_close(&ublast2_firmware_image); + /* + * Release claimed interface. Most probably it is already disconnected + * and re-enumerated as new devices after firmware upload, so we do + * not need to care about errors. + */ + libusb_release_interface(libusb_dev, 0); + return ERROR_OK; } @@ -228,6 +240,12 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low) } } + if (libusb_claim_interface(low->libusb_dev, 0)) { + LOG_ERROR("unable to claim interface"); + jtag_libusb_close(low->libusb_dev); + return ERROR_JTAG_INIT_FAILED; + } + char buffer[5]; jtag_libusb_control_transfer(low->libusb_dev, LIBUSB_REQUEST_TYPE_VENDOR | @@ -246,6 +264,9 @@ static int ublast2_libusb_init(struct ublast_lowlevel *low) static int ublast2_libusb_quit(struct ublast_lowlevel *low) { + if (libusb_release_interface(low->libusb_dev, 0)) + LOG_ERROR("usb release interface failed"); + jtag_libusb_close(low->libusb_dev); return ERROR_OK; }; From f09aa77c0ca6f9f926be8a4508e9de58284052f6 Mon Sep 17 00:00:00 2001 From: Oleksij Rempel Date: Thu, 18 Mar 2021 18:47:35 +0100 Subject: [PATCH 092/120] drivers: USB Blaster II: close file and release USB device if firmware handling failed In case of some error, the USB device and firmware file are still claimed. Make sure refcounting is properly accounted for both cases. Change-Id: I933114f68e59280e58372c0941a0062fe96ab340 Signed-off-by: Oleksij Rempel Reviewed-on: http://openocd.zylin.com/6115 Tested-by: jenkins Reviewed-by: Tomas Vanek Reviewed-by: Antonio Borneo --- src/jtag/drivers/usb_blaster/ublast2_access_libusb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c index 82dc95071..4dec89b11 100644 --- a/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c +++ b/src/jtag/drivers/usb_blaster/ublast2_access_libusb.c @@ -144,7 +144,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, int ret = image_open(&ublast2_firmware_image, low->firmware_path, "ihex"); if (ret != ERROR_OK) { LOG_ERROR("Could not load firmware image"); - return ret; + goto error_release_usb; } /** A host loader program must write 0x01 to the CPUCS register @@ -172,7 +172,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, &ublast2_firmware_image, i); if (ret != ERROR_OK) { LOG_ERROR("Error while downloading the firmware"); - return ret; + goto error_close_firmware; } } @@ -187,8 +187,10 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, 1, 100); +error_close_firmware: image_close(&ublast2_firmware_image); +error_release_usb: /* * Release claimed interface. Most probably it is already disconnected * and re-enumerated as new devices after firmware upload, so we do @@ -196,7 +198,7 @@ static int load_usb_blaster_firmware(struct libusb_device_handle *libusb_dev, */ libusb_release_interface(libusb_dev, 0); - return ERROR_OK; + return ret; } static int ublast2_libusb_init(struct ublast_lowlevel *low) From e15c2e8a8c6369052ec8898f40ec4a82b5495493 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 18 Mar 2021 16:14:04 +0100 Subject: [PATCH 093/120] README: update requested autoconf version 2.69 Commit 4c00f96fc2e3 ("configure.ac: switch to autoconf 2.69") changes the required minor version of autoconf. Update the README file accordingly. Change-Id: I98b32b888ff531300f03c4ef9ebcbf8110509e52 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6114 Tested-by: jenkins Reviewed-by: Marc Schink --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index fb3051f21..1c5f19277 100644 --- a/README +++ b/README @@ -220,7 +220,7 @@ You'll also need: Additionally, for building from git: -- autoconf >= 2.64 +- autoconf >= 2.69 - automake >= 1.14 - texinfo >= 5.0 From 6448f70e0940d051eb4847231480e4805e99966a Mon Sep 17 00:00:00 2001 From: Andrew Wesie Date: Sun, 7 Mar 2021 17:48:27 +0900 Subject: [PATCH 094/120] tcl/interface/ftdi: Add PLS SPC5 debugger config Change-Id: I694201db0811beebc94e87822c87fbfc6aecc4c4 Signed-off-by: Andrew Wesie Reviewed-on: http://openocd.zylin.com/6081 Tested-by: jenkins Reviewed-by: Antonio Borneo --- contrib/60-openocd.rules | 3 +++ tcl/interface/ftdi/pls_spc5.cfg | 36 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tcl/interface/ftdi/pls_spc5.cfg diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index 36bdb5318..0358b6010 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -163,6 +163,9 @@ ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="02a5", MODE="660", GROUP="plugdev", # TI Tiva-based ICDI and XDS110 probes in DFU mode ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00ff", MODE="660", GROUP="plugdev", TAG+="uaccess" +# PLS USB/JTAG Adapter for SPC5xxx +ATTRS{idVendor}=="263d", ATTRS{idProduct}=="4001", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Ambiq Micro EVK and Debug boards. ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6010", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6011", MODE="660", GROUP="plugdev", TAG+="uaccess" diff --git a/tcl/interface/ftdi/pls_spc5.cfg b/tcl/interface/ftdi/pls_spc5.cfg new file mode 100644 index 000000000..806f920fe --- /dev/null +++ b/tcl/interface/ftdi/pls_spc5.cfg @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# PLS SPC5-UDESTK +# +# https://www.st.com/en/development-tools/spc5-udestk.html +# +# Reference the SPC56D Discovery schematics. +# +# Layout: FTDI FT2232 +# ADBUS0 TCK +# ADBUS1 TDI +# ADBUS2 TDO +# ADBUS3 TMS +# ADBUS4 TMS +# ADBUS5 RTCK +# ADBUS6 +# ADBUS7 LED1 +# +# ACBUS0 nTRST +# ACBUS1 nSRST (external pull-down) +# ACUBS2 +# ACBUS3 +# ACBUS4 +# ACBUS5 nSRST direction (input=L, output=H, external pull-down) +# ACBUS6 TMS direction (input=L, output=H, external pull-up) +# ACBUS7 LED2 +# + +adapter driver ftdi +ftdi_device_desc "PLS USB/JTAG Adapter for SPC5xxx" +ftdi_vid_pid 0x263d 0x4001 + +ftdi_channel 0 +ftdi_layout_init 0x0008 0x000b +ftdi_layout_signal nTRST -data 0x0100 -oe 0x0100 +ftdi_layout_signal nSRST -ndata 0x2000 -oe 0x2000 From b5889776339eb1a3106cc4639b43d9c58b573ec6 Mon Sep 17 00:00:00 2001 From: Mischa Studer Date: Wed, 24 Feb 2021 13:24:51 +0100 Subject: [PATCH 095/120] flash/nor/cfi: fix uninitialized write-mem pointer In flash/nor/cfi.c:835 struct cfi_info is allocated by malloc(). As write-mem was uninitialized the pointer pointed to an out of range address, which led to a segmentation fault and crashed openocd. This happened during flash-command of an external flash-bank, using cfi. Use calloc() instead. While on it check for NULL return and remove unnecessary initialzation. Change-Id: I0e2ffb90559afe7f090837023428dcc06b2e29f6 Signed-off-by: Mischa Studer Reviewed-on: http://openocd.zylin.com/6070 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/cfi.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/flash/nor/cfi.c b/src/flash/nor/cfi.c index 5f5071e69..c9eb38b9b 100644 --- a/src/flash/nor/cfi.c +++ b/src/flash/nor/cfi.c @@ -832,17 +832,13 @@ int cfi_flash_bank_cmd(struct flash_bank *bank, unsigned int argc, const char ** return ERROR_FLASH_BANK_INVALID; } - cfi_info = malloc(sizeof(struct cfi_flash_bank)); - cfi_info->probed = false; - cfi_info->erase_region_info = NULL; - cfi_info->pri_ext = NULL; + cfi_info = calloc(1, sizeof(struct cfi_flash_bank)); + if (cfi_info == NULL) { + LOG_ERROR("No memory for flash bank info"); + return ERROR_FAIL; + } bank->driver_priv = cfi_info; - cfi_info->x16_as_x8 = false; - cfi_info->jedec_probe = false; - cfi_info->not_cfi = false; - cfi_info->data_swap = false; - for (unsigned i = 6; i < argc; i++) { if (strcmp(argv[i], "x16_as_x8") == 0) cfi_info->x16_as_x8 = true; From f13bb10e267f9d474901a0f7b4fbb2975920668c Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Tue, 22 Dec 2020 09:24:59 +0100 Subject: [PATCH 096/120] flash/nor/atsame5: add SAME51G18A and SAME51G19A devices Change-Id: Icbb49c76594152e9c5da1c7465675de26c86540e Signed-off-by: Tomas Vanek Reported-by: mikewolak@users.sourceforge.net Fixes: https://sourceforge.net/p/openocd/tickets/288/ Reviewed-on: http://openocd.zylin.com/5984 Tested-by: jenkins --- src/flash/nor/atsame5.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index ed0bef463..50e56a72a 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -113,7 +113,7 @@ struct samd_part { }; /* See SAM D5x/E5x Family Silicon Errata and Data Sheet Clarification - * DS80000748B */ + * DS80000748K */ /* Known SAMD51 parts. */ static const struct samd_part samd51_parts[] = { { 0x00, "SAMD51P20A", 1024, 256 }, @@ -134,6 +134,8 @@ static const struct samd_part same51_parts[] = { { 0x02, "SAME51J19A", 512, 192 }, { 0x03, "SAME51J18A", 256, 128 }, { 0x04, "SAME51J20A", 1024, 256 }, + { 0x05, "SAME51G19A", 512, 192 }, /* New in rev D */ + { 0x06, "SAME51G18A", 256, 128 }, /* New in rev D */ }; /* Known SAME53 parts. */ From b8fd9aecb12a5d930cf3e3e09cede4cd6787e847 Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Sun, 22 Mar 2020 20:39:44 +0100 Subject: [PATCH 097/120] stm32l4x: add OTP support for STM32 G0/G4/L4/L4+/L5/WB/WL devices this is a rework of #5320 started by Andreas then abandoned. same syntax as in stm32f2x driver: enable OTP for writing > stm32l4x otp 1 enable write to OTP > flash write_bank 1 foo.bin 0 > flash filld 0x1FFF7000 0xDeadBeafBaadF00d 1 read OTP > mdw 0x1FFF7000 4 disable OTP > stm32l4x otp 1 disable Change-Id: Id7d7c163b35d7a3f406dc200d7e2fc293b0675c2 Signed-off-by: Andreas Bolsch Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5537 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/openocd.texi | 11 +++ src/flash/nor/stm32l4x.c | 160 ++++++++++++++++++++++++++++++++++++++- tcl/target/stm32g0x.cfg | 4 +- tcl/target/stm32g4x.cfg | 4 +- tcl/target/stm32l4x.cfg | 4 +- tcl/target/stm32l5x.cfg | 3 +- tcl/target/stm32wbx.cfg | 4 +- tcl/target/stm32wlx.cfg | 4 +- 8 files changed, 182 insertions(+), 12 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index b3fe85404..6cce952d4 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -7179,6 +7179,17 @@ the chip identification register, and autoconfigures itself. flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME @end example +If you use OTP (One-Time Programmable) memory define it as a second bank +as per the following example. +@example +flash bank $_FLASHNAME stm32l4x 0x1FFF7000 0 0 0 $_TARGETNAME +@end example + +@deffn Command {stm32l4x otp} num (@option{enable}|@option{disable}|@option{show}) +Enables or disables OTP write commands for bank @var{num}. +The @var{num} parameter is a value shown by @command{flash banks}. +@end deffn + Note that some devices have been found that have a flash size register that contains an invalid value, to workaround this issue you can override the probed value used by the flash driver. However, specifying a wrong value might lead to a completely diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 89c5ac3fe..492d0dde1 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -171,6 +171,8 @@ struct stm32l4_part_info { const uint32_t flash_regs_base; const uint32_t *default_flash_regs; const uint32_t fsize_addr; + const uint32_t otp_base; + const uint32_t otp_size; }; struct stm32l4_flash_bank { @@ -183,6 +185,7 @@ struct stm32l4_flash_bank { uint32_t wrpxxr_mask; const struct stm32l4_part_info *part_info; const uint32_t *flash_regs; + bool otp_enabled; }; /* human readable list of families this drivers supports (sorted alphabetically) */ @@ -263,6 +266,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x435, @@ -274,6 +279,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x460, @@ -285,6 +292,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x461, @@ -296,6 +305,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x462, @@ -307,6 +318,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x464, @@ -318,6 +331,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x466, @@ -329,6 +344,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x468, @@ -340,6 +357,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x469, @@ -351,6 +370,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x470, @@ -362,6 +383,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x471, @@ -373,6 +396,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x472, @@ -384,6 +409,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l5_ns_flash_regs, .fsize_addr = 0x0BFA05E0, + .otp_base = 0x0BFA0000, + .otp_size = 512, }, { .id = 0x479, @@ -395,6 +422,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x495, @@ -406,6 +435,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x496, @@ -417,6 +448,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, { .id = 0x497, @@ -428,6 +461,8 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, + .otp_base = 0x1FFF7000, + .otp_size = 1024, }, }; @@ -439,6 +474,10 @@ FLASH_BANK_COMMAND_HANDLER(stm32l4_flash_bank_command) if (CMD_ARGC < 6) return ERROR_COMMAND_SYNTAX_ERROR; + /* fix-up bank base address: 0 is used for normal flash memory */ + if (bank->base == 0) + bank->base = STM32_FLASH_BANK_BASE; + stm32l4_info = calloc(1, sizeof(struct stm32l4_flash_bank)); if (!stm32l4_info) return ERROR_FAIL; /* Checkme: What better error to use?*/ @@ -449,11 +488,43 @@ FLASH_BANK_COMMAND_HANDLER(stm32l4_flash_bank_command) bank->write_start_alignment = bank->write_end_alignment = 8; stm32l4_info->probed = false; + stm32l4_info->otp_enabled = false; stm32l4_info->user_bank_size = bank->size; return ERROR_OK; } +static inline bool stm32l4_is_otp(struct flash_bank *bank) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + return bank->base == stm32l4_info->part_info->otp_base; +} + +static int stm32l4_otp_enable(struct flash_bank *bank, bool enable) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + + if (!stm32l4_is_otp(bank)) + return ERROR_FAIL; + + char *op_str = enable ? "enabled" : "disabled"; + + LOG_INFO("OTP memory (bank #%d) is %s%s for write commands", + bank->bank_number, + stm32l4_info->otp_enabled == enable ? "already " : "", + op_str); + + stm32l4_info->otp_enabled = enable; + + return ERROR_OK; +} + +static inline bool stm32l4_otp_is_enabled(struct flash_bank *bank) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + return stm32l4_info->otp_enabled; +} + static inline uint32_t stm32l4_get_flash_reg(struct flash_bank *bank, uint32_t reg_offset) { struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; @@ -693,6 +764,11 @@ static int stm32l4_erase(struct flash_bank *bank, unsigned int first, assert((first <= last) && (last < bank->num_sectors)); + if (stm32l4_is_otp(bank)) { + LOG_ERROR("cannot erase OTP memory"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; @@ -749,6 +825,11 @@ static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first, struct target *target = bank->target; struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + if (stm32l4_is_otp(bank)) { + LOG_ERROR("cannot protect/unprotect OTP memory"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + if (target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; @@ -883,6 +964,11 @@ static int stm32l4_write(struct flash_bank *bank, const uint8_t *buffer, { int retval = ERROR_OK, retval2; + if (stm32l4_is_otp(bank) && !stm32l4_otp_is_enabled(bank)) { + LOG_ERROR("OTP memory is disabled for write commands"); + return ERROR_FAIL; + } + if (bank->target->state != TARGET_HALTED) { LOG_ERROR("Target not halted"); return ERROR_TARGET_NOT_HALTED; @@ -1001,6 +1087,29 @@ static int stm32l4_probe(struct flash_bank *bank) LOG_INFO("device idcode = 0x%08" PRIx32 " (%s)", stm32l4_info->idcode, device_info); + if (stm32l4_is_otp(bank)) { + bank->size = part_info->otp_size; + + LOG_INFO("OTP size is %d bytes, base address is " TARGET_ADDR_FMT, bank->size, bank->base); + + /* OTP memory is considered as one sector */ + free(bank->sectors); + bank->num_sectors = 1; + bank->sectors = alloc_block_array(0, part_info->otp_size, 1); + + if (!bank->sectors) { + LOG_ERROR("failed to allocate bank sectors"); + return ERROR_FAIL; + } + + + stm32l4_info->probed = true; + return ERROR_OK; + } else if (bank->base != STM32_FLASH_BANK_BASE) { + LOG_ERROR("invalid bank base address"); + return ERROR_FAIL; + } + /* get flash size from target. */ retval = target_read_u16(target, part_info->fsize_addr, &flash_size_kb); @@ -1175,7 +1284,6 @@ static int stm32l4_probe(struct flash_bank *bank) free(bank->sectors); bank->size = (flash_size_kb + gap_size_kb) * 1024; - bank->base = STM32_FLASH_BANK_BASE; bank->num_sectors = num_pages; bank->sectors = malloc(sizeof(struct flash_sector) * bank->num_sectors); if (bank->sectors == NULL) { @@ -1227,6 +1335,7 @@ static int get_stm32l4_info(struct flash_bank *bank, char *buf, int buf_size) if (stm32l4_info->probed) snprintf(buf + buf_len, buf_size - buf_len, " - %s-bank", + stm32l4_is_otp(bank) ? "OTP" : stm32l4_info->dual_bank_mode ? "Flash dual" : "Flash single"); return ERROR_OK; @@ -1244,6 +1353,11 @@ static int stm32l4_mass_erase(struct flash_bank *bank) struct target *target = bank->target; struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + if (stm32l4_is_otp(bank)) { + LOG_ERROR("cannot erase OTP memory"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + uint32_t action = FLASH_MER1; if (stm32l4_info->part_info->has_dual_bank) @@ -1410,6 +1524,11 @@ COMMAND_HANDLER(stm32l4_handle_lock_command) if (ERROR_OK != retval) return retval; + if (stm32l4_is_otp(bank)) { + LOG_ERROR("cannot lock/unlock OTP memory"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + target = bank->target; if (target->state != TARGET_HALTED) { @@ -1439,6 +1558,11 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) if (ERROR_OK != retval) return retval; + if (stm32l4_is_otp(bank)) { + LOG_ERROR("cannot lock/unlock OTP memory"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + target = bank->target; if (target->state != TARGET_HALTED) { @@ -1456,6 +1580,33 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) return ERROR_OK; } +COMMAND_HANDLER(stm32l4_handle_otp_command) +{ + if (CMD_ARGC < 2) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct flash_bank *bank; + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); + if (ERROR_OK != retval) + return retval; + + if (!stm32l4_is_otp(bank)) { + command_print(CMD, "the specified bank is not an OTP memory"); + return ERROR_FAIL; + } + if (strcmp(CMD_ARGV[1], "enable") == 0) + stm32l4_otp_enable(bank, true); + else if (strcmp(CMD_ARGV[1], "disable") == 0) + stm32l4_otp_enable(bank, false); + else if (strcmp(CMD_ARGV[1], "show") == 0) + command_print(CMD, "OTP memory bank #%d is %s for write commands.", + bank->bank_number, stm32l4_otp_is_enabled(bank) ? "enabled" : "disabled"); + else + return ERROR_COMMAND_SYNTAX_ERROR; + + return ERROR_OK; +} + static const struct command_registration stm32l4_exec_command_handlers[] = { { .name = "lock", @@ -1499,6 +1650,13 @@ static const struct command_registration stm32l4_exec_command_handlers[] = { .usage = "bank_id", .help = "Force re-load of device options (will cause device reset).", }, + { + .name = "otp", + .handler = stm32l4_handle_otp_command, + .mode = COMMAND_EXEC, + .usage = " ", + .help = "OTP (One Time Programmable) memory write enable/disable", + }, COMMAND_REGISTRATION_DONE }; diff --git a/tcl/target/stm32g0x.cfg b/tcl/target/stm32g0x.cfg index 50836ea82..7df530655 100644 --- a/tcl/target/stm32g0x.cfg +++ b/tcl/target/stm32g0x.cfg @@ -38,8 +38,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME # reasonable default adapter speed 2000 diff --git a/tcl/target/stm32g4x.cfg b/tcl/target/stm32g4x.cfg index 9f144a07e..360447bd5 100644 --- a/tcl/target/stm32g4x.cfg +++ b/tcl/target/stm32g4x.cfg @@ -47,8 +47,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME if { [info exists QUADSPI] && $QUADSPI } { set a [llength [flash list]] diff --git a/tcl/target/stm32l4x.cfg b/tcl/target/stm32l4x.cfg index 7f08f3c4b..589979193 100644 --- a/tcl/target/stm32l4x.cfg +++ b/tcl/target/stm32l4x.cfg @@ -47,8 +47,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME if { [info exists QUADSPI] && $QUADSPI } { set a [llength [flash list]] diff --git a/tcl/target/stm32l5x.cfg b/tcl/target/stm32l5x.cfg index bf5636094..92083b9e0 100644 --- a/tcl/target/stm32l5x.cfg +++ b/tcl/target/stm32l5x.cfg @@ -53,7 +53,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 # declare non-secure flash -flash bank $_CHIPNAME.flash_ns stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash_ns stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x0BFA0000 0 0 0 $_TARGETNAME # Common knowledges tells JTAG speed should be <= F_CPU/6. # F_CPU after reset is MSI 4MHz, so use F_JTAG = 500 kHz to stay on diff --git a/tcl/target/stm32wbx.cfg b/tcl/target/stm32wbx.cfg index 90f53bb96..6467667de 100644 --- a/tcl/target/stm32wbx.cfg +++ b/tcl/target/stm32wbx.cfg @@ -46,8 +46,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME # Common knowledges tells JTAG speed should be <= F_CPU/6. # F_CPU after reset is MSI 4MHz, so use F_JTAG = 500 kHz to stay on diff --git a/tcl/target/stm32wlx.cfg b/tcl/target/stm32wlx.cfg index ba16fab6b..961850ad1 100644 --- a/tcl/target/stm32wlx.cfg +++ b/tcl/target/stm32wlx.cfg @@ -46,8 +46,8 @@ target create $_TARGETNAME cortex_m -endian $_ENDIAN -dap $_CHIPNAME.dap $_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 -set _FLASHNAME $_CHIPNAME.flash -flash bank $_FLASHNAME stm32l4x 0 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.flash stm32l4x 0x08000000 0 0 0 $_TARGETNAME +flash bank $_CHIPNAME.otp stm32l4x 0x1fff7000 0 0 0 $_TARGETNAME # Common knowledges tells JTAG speed should be <= F_CPU/6. # F_CPU after reset is MSI 4MHz, so use F_JTAG = 500 kHz to stay on From 03e2bc0f3b12c45f9b537bece1fef0520c2298bd Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 3 Nov 2020 00:50:24 +0100 Subject: [PATCH 098/120] flash/stm32l4x: enhance protect handler to use efficiently all WRP areas stm32l4_protect: was using one WRP area per bank, without checking if it is already protecting some sectors. protection algo is more complicated than that, before using a WRP area we should check if it is already used, then either reuse it for extension (or reduction) or use a free area. introduce a new command: stm32l4x wrp_info bank_num ['bank1'|'bank2'] this command lists the protected areas using WRP. Note: for some devices like STM32L4R/S in single bank mode, all 4 WRP areas are usable for that bank, to manage this case an attribute 'use_all_wrpxx' was introduced into stm32l4_part_info and used later in protection handlers example usage: $ telnet localhost 4444 > flash probe 0 device idcode = 0x10036470 (STM32L4R/L4Sxx - Rev: Y) flash size = 2048kbytes flash mode : dual-bank flash 'stm32l4x' found at 0x08000000 > stm32l4x wrp_info 0 no protected areas > flash protect 0 0 4 on set protection for sectors 0 through 4 on flash bank 0 > flash protect 0 8 9 on set protection for sectors 8 through 9 on flash bank 0 > stm32l4x wrp_info 0 protected areas: [0,4][8,9] > flash protect 0 6 6 on the device WRPxy are not enough to set the requested protection failed setting protection for blocks 6 to 6 > flash protect 0 3 5 on set protection for sectors 3 through 5 on flash bank 0 > stm32l4x wrp_info 0 protected areas: [0,5][8,9] > flash protect 0 6 7 on set protection for sectors 6 through 7 on flash bank 0 > stm32l4x wrp_info 0 protected areas: [0,9] > flash protect 0 5 6 off cleared protection for sectors 5 through 6 on flash bank 0 > stm32l4x wrp_info 0 protected areas: [0,4][7,9] Change-Id: I42bd84fa66edd93406e18c6d89310faa5267ffa7 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6107 Tested-by: jenkins Reviewed-by: Tomas Vanek --- doc/openocd.texi | 14 ++ src/flash/nor/stm32l4x.c | 444 ++++++++++++++++++++++++++++++++++----- 2 files changed, 401 insertions(+), 57 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 6cce952d4..45c9ffae8 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -7249,6 +7249,20 @@ Area A for bank 1. The above example set WRP1AR_END=255, WRP1AR_START=0. This will effectively write protect all sectors in flash bank 1. @end deffn +@deffn Command {stm32l4x wrp_info} num [device_bank] +List the protected areas using WRP. +The @var{num} parameter is a value shown by @command{flash banks}. +@var{device_bank} parameter is optional, possible values 'bank1' or 'bank2', +if not specified, the command will display the whole flash protected areas. + +@b{Note:} @var{device_bank} is different from banks created using @code{flash bank}. +Devices supported in this flash driver, can have main flash memory organized +in single or dual-banks mode. +Thus the usage of @var{device_bank} is meaningful only in dual-bank mode, to get +write protected areas in a specific @var{device_bank} + +@end deffn + @deffn Command {stm32l4x option_load} num Forces a re-load of the option byte registers. Will cause a system reset of the device. The @var{num} parameter is a value shown by @command{flash banks}. diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 492d0dde1..681638161 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -168,6 +168,9 @@ struct stm32l4_part_info { const size_t num_revs; const uint16_t max_flash_size_kb; const bool has_dual_bank; + /* this field is used for dual bank devices only, it indicates if the + * 4 WRPxx are usable if the device is configured in single-bank mode */ + const bool use_all_wrpxx; const uint32_t flash_regs_base; const uint32_t *default_flash_regs; const uint32_t fsize_addr; @@ -188,6 +191,21 @@ struct stm32l4_flash_bank { bool otp_enabled; }; +enum stm32_bank_id { + STM32_BANK1, + STM32_BANK2, + STM32_ALL_BANKS +}; + +struct stm32l4_wrp { + enum stm32l4_flash_reg_index reg_idx; + uint32_t value; + bool used; + int first; + int last; + int offset; +}; + /* human readable list of families this drivers supports (sorted alphabetically) */ static const char *device_families = "STM32G0/G4/L4/L4+/L5/WB/WL"; @@ -263,6 +281,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L47/L48xx", .max_flash_size_kb = 1024, .has_dual_bank = true, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -276,6 +295,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L43/L44xx", .max_flash_size_kb = 256, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -289,6 +309,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32G07/G08xx", .max_flash_size_kb = 128, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -302,6 +323,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L49/L4Axx", .max_flash_size_kb = 1024, .has_dual_bank = true, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -315,6 +337,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L45/L46xx", .max_flash_size_kb = 512, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -328,6 +351,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L41/L42xx", .max_flash_size_kb = 128, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -341,6 +365,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32G03/G04xx", .max_flash_size_kb = 64, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -354,6 +379,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32G43/G44xx", .max_flash_size_kb = 128, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -367,6 +393,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32G47/G48xx", .max_flash_size_kb = 512, .has_dual_bank = true, + .use_all_wrpxx = true, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -380,6 +407,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L4R/L4Sxx", .max_flash_size_kb = 2048, .has_dual_bank = true, + .use_all_wrpxx = true, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -393,6 +421,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L4P5/L4Q5x", .max_flash_size_kb = 1024, .has_dual_bank = true, + .use_all_wrpxx = true, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -406,6 +435,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32L55/L56xx", .max_flash_size_kb = 512, .has_dual_bank = true, + .use_all_wrpxx = true, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l5_ns_flash_regs, .fsize_addr = 0x0BFA05E0, @@ -419,6 +449,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32G49/G4Axx", .max_flash_size_kb = 512, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -432,6 +463,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32WB5x", .max_flash_size_kb = 1024, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -445,6 +477,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32WB3x", .max_flash_size_kb = 512, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -458,6 +491,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .device_str = "STM32WLEx", .max_flash_size_kb = 256, .has_dual_bank = false, + .use_all_wrpxx = false, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -494,6 +528,63 @@ FLASH_BANK_COMMAND_HANDLER(stm32l4_flash_bank_command) return ERROR_OK; } +/* bitmap helper extension */ +struct range { + unsigned int start; + unsigned int end; +}; + +static void bitmap_to_ranges(unsigned long *bitmap, unsigned int nbits, + struct range *ranges, unsigned int *ranges_count) { + *ranges_count = 0; + bool last_bit = 0, cur_bit; + for (unsigned int i = 0; i < nbits; i++) { + cur_bit = test_bit(i, bitmap); + + if (cur_bit && !last_bit) { + (*ranges_count)++; + ranges[*ranges_count - 1].start = i; + ranges[*ranges_count - 1].end = i; + } else if (cur_bit && last_bit) { + /* update (increment) the end this range */ + ranges[*ranges_count - 1].end = i; + } + + last_bit = cur_bit; + } +} + +static inline int range_print_one(struct range *range, char *str) +{ + if (range->start == range->end) + return sprintf(str, "[%d]", range->start); + + return sprintf(str, "[%d,%d]", range->start, range->end); +} + +static char *range_print_alloc(struct range *ranges, unsigned int ranges_count) +{ + /* each range will be printed like the following: [start,end] + * start and end, both are unsigned int, an unsigned int takes 10 characters max + * plus 3 characters for '[', ',' and ']' + * thus means each range can take maximum 23 character + * after each range we add a ' ' as separator and finally we need the '\0' + * if the ranges_count is zero we reserve one char for '\0' to return an empty string */ + char *str = calloc(1, ranges_count * (24 * sizeof(char)) + 1); + char *ptr = str; + + for (unsigned int i = 0; i < ranges_count; i++) { + ptr += range_print_one(&(ranges[i]), ptr); + + if (i < ranges_count - 1) + *(ptr++) = ' '; + } + + return str; +} + +/* end of bitmap helper extension */ + static inline bool stm32l4_is_otp(struct flash_bank *bank) { struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; @@ -706,53 +797,125 @@ err_lock: return retval2; } -static int stm32l4_protect_check(struct flash_bank *bank) +static int stm32l4_get_one_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy, + enum stm32l4_flash_reg_index reg_idx, int offset) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + int ret; + + wrpxy->reg_idx = reg_idx; + wrpxy->offset = offset; + + ret = stm32l4_read_flash_reg_by_index(bank, wrpxy->reg_idx , &wrpxy->value); + if (ret != ERROR_OK) + return ret; + + wrpxy->first = (wrpxy->value & stm32l4_info->wrpxxr_mask) + wrpxy->offset; + wrpxy->last = ((wrpxy->value >> 16) & stm32l4_info->wrpxxr_mask) + wrpxy->offset; + wrpxy->used = wrpxy->first <= wrpxy->last; + + return ERROR_OK; +} + +static int stm32l4_get_all_wrpxy(struct flash_bank *bank, enum stm32_bank_id dev_bank_id, + struct stm32l4_wrp *wrpxy, unsigned int *n_wrp) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + int ret; + + *n_wrp = 0; + + /* for single bank devices there is 2 WRP regions. + * for dual bank devices there is 2 WRP regions per bank, + * if configured as single bank only 2 WRP are usable + * except for STM32L4R/S/P/Q, G4 cat3, L5 ... all 4 WRP are usable + * note: this should be revised, if a device will have the SWAP banks option + */ + + int wrp2y_sectors_offset = -1; /* -1 : unused */ + + /* if bank_id is BANK1 or ALL_BANKS */ + if (dev_bank_id != STM32_BANK2) { + /* get FLASH_WRP1AR */ + ret = stm32l4_get_one_wrpxy(bank, &wrpxy[(*n_wrp)++], STM32_FLASH_WRP1AR_INDEX, 0); + if (ret != ERROR_OK) + return ret; + + /* get WRP1BR */ + ret = stm32l4_get_one_wrpxy(bank, &wrpxy[(*n_wrp)++], STM32_FLASH_WRP1BR_INDEX, 0); + if (ret != ERROR_OK) + return ret; + + /* for some devices (like STM32L4R/S) in single-bank mode, the 4 WRPxx are usable */ + if (stm32l4_info->part_info->use_all_wrpxx && !stm32l4_info->dual_bank_mode) + wrp2y_sectors_offset = 0; + } + + /* if bank_id is BANK2 or ALL_BANKS */ + if (dev_bank_id != STM32_BANK1 && stm32l4_info->dual_bank_mode) + wrp2y_sectors_offset = stm32l4_info->bank1_sectors; + + if (wrp2y_sectors_offset > -1) { + /* get WRP2AR */ + ret = stm32l4_get_one_wrpxy(bank, &wrpxy[(*n_wrp)++], STM32_FLASH_WRP2AR_INDEX, wrp2y_sectors_offset); + if (ret != ERROR_OK) + return ret; + + /* get WRP2BR */ + ret = stm32l4_get_one_wrpxy(bank, &wrpxy[(*n_wrp)++], STM32_FLASH_WRP2BR_INDEX, wrp2y_sectors_offset); + if (ret != ERROR_OK) + return ret; + } + + return ERROR_OK; +} + +static int stm32l4_write_one_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy) { struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; - uint32_t wrp1ar, wrp1br, wrp2ar, wrp2br; - stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_WRP1AR_INDEX, &wrp1ar); - stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_WRP1BR_INDEX, &wrp1br); - if (stm32l4_info->part_info->has_dual_bank) { - stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_WRP2AR_INDEX, &wrp2ar); - stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_WRP2BR_INDEX, &wrp2br); - } else { - /* prevent uninitialized errors */ - wrp2ar = 0; - wrp2br = 0; + int wrp_start = wrpxy->first - wrpxy->offset; + int wrp_end = wrpxy->last - wrpxy->offset; + + uint32_t wrp_value = (wrp_start & stm32l4_info->wrpxxr_mask) | ((wrp_end & stm32l4_info->wrpxxr_mask) << 16); + + return stm32l4_write_option(bank, stm32l4_info->flash_regs[wrpxy->reg_idx], wrp_value, 0xffffffff); +} + +static int stm32l4_write_all_wrpxy(struct flash_bank *bank, struct stm32l4_wrp *wrpxy, unsigned int n_wrp) +{ + int ret; + + for (unsigned int i = 0; i < n_wrp; i++) { + ret = stm32l4_write_one_wrpxy(bank, &wrpxy[i]); + if (ret != ERROR_OK) + return ret; } - const uint8_t wrp1a_start = wrp1ar & stm32l4_info->wrpxxr_mask; - const uint8_t wrp1a_end = (wrp1ar >> 16) & stm32l4_info->wrpxxr_mask; - const uint8_t wrp1b_start = wrp1br & stm32l4_info->wrpxxr_mask; - const uint8_t wrp1b_end = (wrp1br >> 16) & stm32l4_info->wrpxxr_mask; - const uint8_t wrp2a_start = wrp2ar & stm32l4_info->wrpxxr_mask; - const uint8_t wrp2a_end = (wrp2ar >> 16) & stm32l4_info->wrpxxr_mask; - const uint8_t wrp2b_start = wrp2br & stm32l4_info->wrpxxr_mask; - const uint8_t wrp2b_end = (wrp2br >> 16) & stm32l4_info->wrpxxr_mask; + return ERROR_OK; +} - for (unsigned int i = 0; i < bank->num_sectors; i++) { - if (i < stm32l4_info->bank1_sectors) { - if (((i >= wrp1a_start) && - (i <= wrp1a_end)) || - ((i >= wrp1b_start) && - (i <= wrp1b_end))) - bank->sectors[i].is_protected = 1; - else - bank->sectors[i].is_protected = 0; - } else { - assert(stm32l4_info->part_info->has_dual_bank == true); - uint8_t snb; - snb = i - stm32l4_info->bank1_sectors; - if (((snb >= wrp2a_start) && - (snb <= wrp2a_end)) || - ((snb >= wrp2b_start) && - (snb <= wrp2b_end))) - bank->sectors[i].is_protected = 1; - else - bank->sectors[i].is_protected = 0; +static int stm32l4_protect_check(struct flash_bank *bank) +{ + unsigned int n_wrp; + struct stm32l4_wrp wrpxy[4]; + + int ret = stm32l4_get_all_wrpxy(bank, STM32_ALL_BANKS, wrpxy, &n_wrp); + if (ret != ERROR_OK) + return ret; + + /* initialize all sectors as unprotected */ + for (unsigned int i = 0; i < bank->num_sectors; i++) + bank->sectors[i].is_protected = 0; + + /* now check WRPxy and mark the protected sectors */ + for (unsigned int i = 0; i < n_wrp; i++) { + if (wrpxy[i].used) { + for (int s = wrpxy[i].first; s <= wrpxy[i].last; s++) + bank->sectors[s].is_protected = 1; } } + return ERROR_OK; } @@ -819,11 +982,12 @@ err_lock: return retval2; } -static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first, - unsigned int last) +static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first, unsigned int last) { struct target *target = bank->target; struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + int ret = ERROR_OK; + unsigned int i; if (stm32l4_is_otp(bank)) { LOG_ERROR("cannot protect/unprotect OTP memory"); @@ -835,29 +999,116 @@ static int stm32l4_protect(struct flash_bank *bank, int set, unsigned int first, return ERROR_TARGET_NOT_HALTED; } - int ret = ERROR_OK; - /* Bank 2 */ - uint32_t reg_value = 0xFF; /* Default to bank un-protected */ + /* the requested sectors could be located into bank1 and/or bank2 */ + bool use_bank2 = false; if (last >= stm32l4_info->bank1_sectors) { - if (set == 1) { - uint8_t begin = first > stm32l4_info->bank1_sectors ? first : 0x00; - reg_value = ((last & 0xFF) << 16) | begin; + if (first < stm32l4_info->bank1_sectors) { + /* the requested sectors for (un)protection are shared between + * bank 1 and 2, then split the operation */ + + /* 1- deal with bank 1 sectors */ + LOG_DEBUG("The requested sectors for %s are shared between bank 1 and 2", + set ? "protection" : "unprotection"); + ret = stm32l4_protect(bank, set, first, stm32l4_info->bank1_sectors - 1); + if (ret != ERROR_OK) + return ret; + + /* 2- then continue with bank 2 sectors */ + first = stm32l4_info->bank1_sectors; } - ret = stm32l4_write_option(bank, stm32l4_info->flash_regs[STM32_FLASH_WRP2AR_INDEX], reg_value, 0xffffffff); + use_bank2 = true; } - /* Bank 1 */ - reg_value = 0xFF; /* Default to bank un-protected */ - if (first < stm32l4_info->bank1_sectors) { - if (set == 1) { - uint8_t end = last >= stm32l4_info->bank1_sectors ? 0xFF : last; - reg_value = (end << 16) | (first & 0xFF); + + /* refresh the sectors' protection */ + ret = stm32l4_protect_check(bank); + if (ret != ERROR_OK) + return ret; + + /* check if the desired protection is already configured */ + for (i = first; i <= last; i++) { + if (bank->sectors[i].is_protected != set) + break; + else if (i == last) { + LOG_INFO("The specified sectors are already %s", set ? "protected" : "unprotected"); + return ERROR_OK; } - - ret = stm32l4_write_option(bank, stm32l4_info->flash_regs[STM32_FLASH_WRP1AR_INDEX], reg_value, 0xffffffff); } - return ret; + /* all sectors from first to last (or part of them) could have different + * protection other than the requested */ + unsigned int n_wrp; + struct stm32l4_wrp wrpxy[4]; + + ret = stm32l4_get_all_wrpxy(bank, use_bank2 ? STM32_BANK2 : STM32_BANK1, wrpxy, &n_wrp); + if (ret != ERROR_OK) + return ret; + + /* use bitmap and range helpers to optimize the WRP usage */ + DECLARE_BITMAP(pages, bank->num_sectors); + bitmap_zero(pages, bank->num_sectors); + + for (i = 0; i < n_wrp; i++) { + if (wrpxy[i].used) { + for (int p = wrpxy[i].first; p <= wrpxy[i].last; p++) + set_bit(p, pages); + } + } + + /* we have at most 'n_wrp' WRP areas + * add one range if the user is trying to protect a fifth range */ + struct range ranges[n_wrp + 1]; + unsigned int ranges_count = 0; + + bitmap_to_ranges(pages, bank->num_sectors, ranges, &ranges_count); + + /* pretty-print the currently protected ranges */ + if (ranges_count > 0) { + char *ranges_str = range_print_alloc(ranges, ranges_count); + LOG_DEBUG("current protected areas: %s", ranges_str); + free(ranges_str); + } else + LOG_DEBUG("current protected areas: none"); + + if (set) { /* flash protect */ + for (i = first; i <= last; i++) + set_bit(i, pages); + } else { /* flash unprotect */ + for (i = first; i <= last; i++) + clear_bit(i, pages); + } + + /* check the ranges_count after the user request */ + bitmap_to_ranges(pages, bank->num_sectors, ranges, &ranges_count); + + /* pretty-print the requested areas for protection */ + if (ranges_count > 0) { + char *ranges_str = range_print_alloc(ranges, ranges_count); + LOG_DEBUG("requested areas for protection: %s", ranges_str); + free(ranges_str); + } else + LOG_DEBUG("requested areas for protection: none"); + + if (ranges_count > n_wrp) { + LOG_ERROR("cannot set the requested protection " + "(only %u write protection areas are available)" , n_wrp); + return ERROR_FAIL; + } + + /* re-init all WRPxy as disabled (first > last)*/ + for (i = 0; i < n_wrp; i++) { + wrpxy[i].first = wrpxy[i].offset + 1; + wrpxy[i].last = wrpxy[i].offset; + } + + /* then configure WRPxy areas */ + for (i = 0; i < ranges_count; i++) { + wrpxy[i].first = ranges[i].start; + wrpxy[i].last = ranges[i].end; + } + + /* finally write WRPxy registers */ + return stm32l4_write_all_wrpxy(bank, wrpxy, n_wrp); } /* Count is in double-words */ @@ -1580,6 +1831,78 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) return ERROR_OK; } +COMMAND_HANDLER(stm32l4_handle_wrp_info_command) +{ + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; + + struct flash_bank *bank; + int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); + if (ERROR_OK != retval) + return retval; + + if (stm32l4_is_otp(bank)) { + LOG_ERROR("OTP memory does not have write protection areas"); + return ERROR_FLASH_OPER_UNSUPPORTED; + } + + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + enum stm32_bank_id dev_bank_id = STM32_ALL_BANKS; + if (CMD_ARGC == 2) { + if (strcmp(CMD_ARGV[1], "bank1") == 0) + dev_bank_id = STM32_BANK1; + else if (strcmp(CMD_ARGV[1], "bank2") == 0) + dev_bank_id = STM32_BANK2; + else + return ERROR_COMMAND_ARGUMENT_INVALID; + } + + if (dev_bank_id == STM32_BANK2) { + if (!stm32l4_info->part_info->has_dual_bank) { + LOG_ERROR("this device has no second bank"); + return ERROR_FAIL; + } else if (!stm32l4_info->dual_bank_mode) { + LOG_ERROR("this device is configured in single bank mode"); + return ERROR_FAIL; + } + } + + int ret; + unsigned int n_wrp, i; + struct stm32l4_wrp wrpxy[4]; + + ret = stm32l4_get_all_wrpxy(bank, dev_bank_id, wrpxy, &n_wrp); + if (ret != ERROR_OK) + return ret; + + /* use bitmap and range helpers to better describe protected areas */ + DECLARE_BITMAP(pages, bank->num_sectors); + bitmap_zero(pages, bank->num_sectors); + + for (i = 0; i < n_wrp; i++) { + if (wrpxy[i].used) { + for (int p = wrpxy[i].first; p <= wrpxy[i].last; p++) + set_bit(p, pages); + } + } + + /* we have at most 'n_wrp' WRP areas */ + struct range ranges[n_wrp]; + unsigned int ranges_count = 0; + + bitmap_to_ranges(pages, bank->num_sectors, ranges, &ranges_count); + + if (ranges_count > 0) { + /* pretty-print the protected ranges */ + char *ranges_str = range_print_alloc(ranges, ranges_count); + command_print(CMD, "protected areas: %s", ranges_str); + free(ranges_str); + } else + command_print(CMD, "no protected areas"); + + return ERROR_OK; +} + COMMAND_HANDLER(stm32l4_handle_otp_command) { if (CMD_ARGC < 2) @@ -1643,6 +1966,13 @@ static const struct command_registration stm32l4_exec_command_handlers[] = { .usage = "bank_id reg_offset value mask", .help = "Write device option bit fields with provided value.", }, + { + .name = "wrp_info", + .handler = stm32l4_handle_wrp_info_command, + .mode = COMMAND_EXEC, + .usage = "bank_id [bank1|bank2]", + .help = "list the protected areas using WRP", + }, { .name = "option_load", .handler = stm32l4_handle_option_load_command, From 88fa831839cf7e45f66064c9c74cfcf59b8d8c7e Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 3 Nov 2020 01:07:00 +0100 Subject: [PATCH 099/120] flash/stm32l4x: introduce stm32l4_part_info.flags for devices features instead of adding a new member into stm32l4_part_info for every relevant feature, .flags serves as container for the devices' features. identified features: F_HAS_DUAL_BANK, F_USE_ALL_WRPXX, F_HAS_TZ Change-Id: I3093e54c6509dec33043ebe6f87675198bf1967a Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5540 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/stm32l4x.c | 72 ++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 681638161..bfedc8d66 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -116,6 +116,19 @@ #define FLASH_ERASE_TIMEOUT 250 + +/* relevant STM32L4 flags ****************************************************/ +#define F_NONE 0 +/* this flag indicates if the device flash is with dual bank architecture */ +#define F_HAS_DUAL_BANK BIT(0) +/* this flags is used for dual bank devices only, it indicates if the + * 4 WRPxx are usable if the device is configured in single-bank mode */ +#define F_USE_ALL_WRPXX BIT(1) +/* this flag indicates if the device embeds a TrustZone security feature */ +#define F_HAS_TZ BIT(2) +/* end of STM32L4 flags ******************************************************/ + + enum stm32l4_flash_reg_index { STM32_FLASH_ACR_INDEX, STM32_FLASH_KEYR_INDEX, @@ -167,10 +180,7 @@ struct stm32l4_part_info { const struct stm32l4_rev *revs; const size_t num_revs; const uint16_t max_flash_size_kb; - const bool has_dual_bank; - /* this field is used for dual bank devices only, it indicates if the - * 4 WRPxx are usable if the device is configured in single-bank mode */ - const bool use_all_wrpxx; + const uint32_t flags; /* one bit per feature, see STM32L4 flags: macros F_XXX */ const uint32_t flash_regs_base; const uint32_t *default_flash_regs; const uint32_t fsize_addr; @@ -280,8 +290,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_415_revs), .device_str = "STM32L47/L48xx", .max_flash_size_kb = 1024, - .has_dual_bank = true, - .use_all_wrpxx = false, + .flags = F_HAS_DUAL_BANK, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -294,8 +303,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_435_revs), .device_str = "STM32L43/L44xx", .max_flash_size_kb = 256, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -308,8 +316,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_460_revs), .device_str = "STM32G07/G08xx", .max_flash_size_kb = 128, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -322,8 +329,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_461_revs), .device_str = "STM32L49/L4Axx", .max_flash_size_kb = 1024, - .has_dual_bank = true, - .use_all_wrpxx = false, + .flags = F_HAS_DUAL_BANK, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -336,8 +342,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_462_revs), .device_str = "STM32L45/L46xx", .max_flash_size_kb = 512, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -350,8 +355,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_464_revs), .device_str = "STM32L41/L42xx", .max_flash_size_kb = 128, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -364,8 +368,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_466_revs), .device_str = "STM32G03/G04xx", .max_flash_size_kb = 64, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -378,8 +381,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_468_revs), .device_str = "STM32G43/G44xx", .max_flash_size_kb = 128, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -392,8 +394,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_469_revs), .device_str = "STM32G47/G48xx", .max_flash_size_kb = 512, - .has_dual_bank = true, - .use_all_wrpxx = true, + .flags = F_HAS_DUAL_BANK | F_USE_ALL_WRPXX, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -406,8 +407,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_470_revs), .device_str = "STM32L4R/L4Sxx", .max_flash_size_kb = 2048, - .has_dual_bank = true, - .use_all_wrpxx = true, + .flags = F_HAS_DUAL_BANK | F_USE_ALL_WRPXX, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -420,8 +420,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_471_revs), .device_str = "STM32L4P5/L4Q5x", .max_flash_size_kb = 1024, - .has_dual_bank = true, - .use_all_wrpxx = true, + .flags = F_HAS_DUAL_BANK | F_USE_ALL_WRPXX, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -434,8 +433,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_472_revs), .device_str = "STM32L55/L56xx", .max_flash_size_kb = 512, - .has_dual_bank = true, - .use_all_wrpxx = true, + .flags = F_HAS_DUAL_BANK | F_USE_ALL_WRPXX | F_HAS_TZ, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l5_ns_flash_regs, .fsize_addr = 0x0BFA05E0, @@ -448,8 +446,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_479_revs), .device_str = "STM32G49/G4Axx", .max_flash_size_kb = 512, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x40022000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -462,8 +459,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_495_revs), .device_str = "STM32WB5x", .max_flash_size_kb = 1024, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -476,8 +472,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_496_revs), .device_str = "STM32WB3x", .max_flash_size_kb = 512, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -490,8 +485,7 @@ static const struct stm32l4_part_info stm32l4_parts[] = { .num_revs = ARRAY_SIZE(stm32_497_revs), .device_str = "STM32WLEx", .max_flash_size_kb = 256, - .has_dual_bank = false, - .use_all_wrpxx = false, + .flags = F_NONE, .flash_regs_base = 0x58004000, .default_flash_regs = stm32l4_flash_regs, .fsize_addr = 0x1FFF75E0, @@ -847,7 +841,7 @@ static int stm32l4_get_all_wrpxy(struct flash_bank *bank, enum stm32_bank_id dev return ret; /* for some devices (like STM32L4R/S) in single-bank mode, the 4 WRPxx are usable */ - if (stm32l4_info->part_info->use_all_wrpxx && !stm32l4_info->dual_bank_mode) + if ((stm32l4_info->part_info->flags & F_USE_ALL_WRPXX) && !stm32l4_info->dual_bank_mode) wrp2y_sectors_offset = 0; } @@ -1611,7 +1605,7 @@ static int stm32l4_mass_erase(struct flash_bank *bank) uint32_t action = FLASH_MER1; - if (stm32l4_info->part_info->has_dual_bank) + if (stm32l4_info->part_info->flags & F_HAS_DUAL_BANK) action |= FLASH_MER2; if (target->state != TARGET_HALTED) { @@ -1858,7 +1852,7 @@ COMMAND_HANDLER(stm32l4_handle_wrp_info_command) } if (dev_bank_id == STM32_BANK2) { - if (!stm32l4_info->part_info->has_dual_bank) { + if (!(stm32l4_info->part_info->flags & F_HAS_DUAL_BANK)) { LOG_ERROR("this device has no second bank"); return ERROR_FAIL; } else if (!stm32l4_info->dual_bank_mode) { From 6405d35f324f767c2ab88da12a600cb8e6c25f0e Mon Sep 17 00:00:00 2001 From: Tarek BOCHKATI Date: Tue, 3 Nov 2020 01:22:53 +0100 Subject: [PATCH 100/120] flash/stm32l4x: probe tzen and rdp values introduction of 'enum stm32l4_rdp' enumerating possible RDP levels for devices with and without TrustZone. also in 'stm32l4_flash_bank' structure we added and rdp and tzen members to store read values by the helper 'stm32l4_sync_rdp_tzen' these new members are used to display security and protection status while probing the flash. Change-Id: Icf883189715278a3323fe210d295047678b16592 Signed-off-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/5541 Tested-by: jenkins Reviewed-by: Tomas Vanek --- src/flash/nor/stm32l4x.c | 65 +++++++++++++++++++++++++++++++++++----- src/flash/nor/stm32l4x.h | 6 ++-- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index bfedc8d66..594bce039 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -143,6 +143,13 @@ enum stm32l4_flash_reg_index { STM32_FLASH_REG_INDEX_NUM, }; +enum stm32l4_rdp { + RDP_LEVEL_0 = 0xAA, + RDP_LEVEL_0_5 = 0x55, /* for devices with TrustZone enabled */ + RDP_LEVEL_1 = 0x00, + RDP_LEVEL_2 = 0xCC +}; + static const uint32_t stm32l4_flash_regs[STM32_FLASH_REG_INDEX_NUM] = { [STM32_FLASH_ACR_INDEX] = 0x000, [STM32_FLASH_KEYR_INDEX] = 0x008, @@ -199,6 +206,8 @@ struct stm32l4_flash_bank { const struct stm32l4_part_info *part_info; const uint32_t *flash_regs; bool otp_enabled; + enum stm32l4_rdp rdp; + bool tzen; }; enum stm32_bank_id { @@ -610,6 +619,35 @@ static inline bool stm32l4_otp_is_enabled(struct flash_bank *bank) return stm32l4_info->otp_enabled; } +static void stm32l4_sync_rdp_tzen(struct flash_bank *bank, uint32_t optr_value) +{ + struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; + + bool tzen = false; + + if (stm32l4_info->part_info->flags & F_HAS_TZ) + tzen = (optr_value & FLASH_TZEN) != 0; + + uint32_t rdp = optr_value & FLASH_RDP_MASK; + + /* for devices without TrustZone: + * RDP level 0 and 2 values are to 0xAA and 0xCC + * Any other value corresponds to RDP level 1 + * for devices with TrusZone: + * RDP level 0 and 2 values are 0xAA and 0xCC + * RDP level 0.5 value is 0x55 only if TZEN = 1 + * Any other value corresponds to RDP level 1, including 0x55 if TZEN = 0 + */ + + if (rdp != RDP_LEVEL_0 && rdp != RDP_LEVEL_2) { + if (!tzen || (tzen && rdp != RDP_LEVEL_0_5)) + rdp = RDP_LEVEL_1; + } + + stm32l4_info->tzen = tzen; + stm32l4_info->rdp = rdp; +} + static inline uint32_t stm32l4_get_flash_reg(struct flash_bank *bank, uint32_t reg_offset) { struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; @@ -1332,6 +1370,22 @@ static int stm32l4_probe(struct flash_bank *bank) LOG_INFO("device idcode = 0x%08" PRIx32 " (%s)", stm32l4_info->idcode, device_info); + /* read flash option register */ + retval = stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_OPTR_INDEX, &options); + if (retval != ERROR_OK) + return retval; + + stm32l4_sync_rdp_tzen(bank, options); + + if (part_info->flags & F_HAS_TZ) + LOG_INFO("TZEN = %d : TrustZone %s by option bytes", + stm32l4_info->tzen, + stm32l4_info->tzen ? "enabled" : "disabled"); + + LOG_INFO("RDP level %s (0x%02X)", + stm32l4_info->rdp == RDP_LEVEL_0 ? "0" : stm32l4_info->rdp == RDP_LEVEL_0_5 ? "0.5" : "1", + stm32l4_info->rdp); + if (stm32l4_is_otp(bank)) { bank->size = part_info->otp_size; @@ -1347,7 +1401,6 @@ static int stm32l4_probe(struct flash_bank *bank) return ERROR_FAIL; } - stm32l4_info->probed = true; return ERROR_OK; } else if (bank->base != STM32_FLASH_BANK_BASE) { @@ -1379,11 +1432,6 @@ static int stm32l4_probe(struct flash_bank *bank) /* did we assign a flash size? */ assert((flash_size_kb != 0xffff) && flash_size_kb); - /* read flash option register */ - retval = stm32l4_read_flash_reg_by_index(bank, STM32_FLASH_OPTR_INDEX, &options); - if (retval != ERROR_OK) - return retval; - stm32l4_info->bank1_sectors = 0; stm32l4_info->hole_sectors = 0; @@ -1783,7 +1831,8 @@ COMMAND_HANDLER(stm32l4_handle_lock_command) /* set readout protection level 1 by erasing the RDP option byte */ struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; - if (stm32l4_write_option(bank, stm32l4_info->flash_regs[STM32_FLASH_OPTR_INDEX], 0, 0x000000FF) != ERROR_OK) { + if (stm32l4_write_option(bank, stm32l4_info->flash_regs[STM32_FLASH_OPTR_INDEX], + RDP_LEVEL_1, FLASH_RDP_MASK) != ERROR_OK) { command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } @@ -1817,7 +1866,7 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) struct stm32l4_flash_bank *stm32l4_info = bank->driver_priv; if (stm32l4_write_option(bank, stm32l4_info->flash_regs[STM32_FLASH_OPTR_INDEX], - RDP_LEVEL_0, 0x000000FF) != ERROR_OK) { + RDP_LEVEL_0, FLASH_RDP_MASK) != ERROR_OK) { command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } diff --git a/src/flash/nor/stm32l4x.h b/src/flash/nor/stm32l4x.h index 3e810a03c..41b5ff82d 100644 --- a/src/flash/nor/stm32l4x.h +++ b/src/flash/nor/stm32l4x.h @@ -56,9 +56,9 @@ #define OPTKEY1 0x08192A3B #define OPTKEY2 0x4C5D6E7F -#define RDP_LEVEL_0 0xAA -#define RDP_LEVEL_1 0xBB -#define RDP_LEVEL_2 0xCC +/* FLASH_OPTR register bits */ +#define FLASH_RDP_MASK 0xFF +#define FLASH_TZEN (1 << 31) /* other registers */ #define DBGMCU_IDCODE_G0 0x40015800 From a5b5907506b3ce782662dc413b1e20ae0d43e346 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20S=C3=A1nchez=20Siles?= Date: Mon, 15 Mar 2021 13:53:17 +0100 Subject: [PATCH 101/120] build: Fix out-of-tree with --disable-dependency-tracking configure flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After bootstrapping build, if we want to do an out-of-tree build (ie: in the OOT-build dir) we have a build failure because build system relies on the OOT-build/src directory exists ```sh ./bootstrap mkdir OOT-build cd OOT-build ../configure --disable-dependency-tracking -- -- ... make $ LANG=C make cat ../src/helper/startup.tcl ../src/jtag/startup.tcl ../src/target/startup.tcl ../src/server/startup.tcl ../src/flash/startup.tcl | ../src/helper/bin2char.sh > src/startup_tcl.inc || { rm -f src/startup_tcl.inc; false; } /bin/bash: line 1: src/startup_tcl.inc: No such file or directory make: *** [Makefile:6603: src/startup_tcl.inc] Error 1 ``` These kind of errors are fixed indicating relevant directory creation in Makefile.am before actually relying on it. Change-Id: I8185fd41ef942184597dc4c0092796034572cbe1 Signed-off-by: Raúl Sánchez Siles Reviewed-on: http://openocd.zylin.com/6106 Tested-by: jenkins Reviewed-by: Antonio Borneo --- src/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Makefile.am b/src/Makefile.am index 781c1e74f..432c31e14 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,6 +65,7 @@ BUILT_SOURCES += %D%/startup_tcl.inc # Convert .tcl to c-array %D%/startup_tcl.inc: $(STARTUP_TCL_SRCS) + mkdir -p %D% cat $^ | $(BIN2C) > $@ || { rm -f $@; false; } # add generated files to make clean list From 36ae487ed04b0e072ff68c70a6775ec6aa6c1725 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Fri, 26 Mar 2021 13:10:07 +0100 Subject: [PATCH 102/120] jimtcl: add temporary workaround for memory leak in jimtcl 0.80 The API Jim_CreateCommand() in latest version of jimtcl leaks the memory allocated internally by jimtcl when it converts the string command-name to a Jim_Obj. The fix is already merged upstream and would be available in next jimtcl 0.81, expected in ~6 months, hopefully before the next tag for OpenOCD v0.12.0. OpenOCD v0.11.0 is distributed with jimtcl 0.79. Debian distributes jimtcl as a separate library package and today it's still on 0.79. It make sense to keep using jimtcl 0.80 in current development cycle to test it further. But having this background memory leak noise hides the eventual new memory leaks that could come from the development activity. This patch uses the internal jimtcl API Jim_CreateCommandObj() and correctly free the internal object, avoiding the memory leak. Being an internal API, it is not accessible if OpenOCD is linked with an external jimtcl library. Nevertheless, building jimtcl as a submodule of OpenOCD makes the trick effective. The scope of this patch is thus limited at developers that build OpenOCD with jimtcl submodule and need to control and debug memory leaks. This patch is supposed to be removed as soon as jimtcl 0.81 gets available. The added code is located, on purpose, in an area of the file that hopefully will not conflict other patches pending in gerrit. Change-Id: I4d300ad21bdb6c616c3f0f14b429b4fdf360900d Signed-off-by: Antonio Borneo Reported-by: Tarek BOCHKATI Reviewed-on: http://openocd.zylin.com/6130 Tested-by: jenkins Reviewed-by: Tomas Vanek Reviewed-by: Oleksij Rempel Reviewed-by: Jonathan McDowell --- src/helper/command.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/helper/command.c b/src/helper/command.c index 0a711e514..e2726f258 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -117,6 +117,40 @@ static void command_log_capture_finish(struct log_capture_state *state) free(state); } +/* + * FIXME: workaround for memory leak in jimtcl 0.80 + * Jim API Jim_CreateCommand() converts the command name in a Jim object and + * does not free the object. Fixed for jimtcl 0.81 by e4416cf86f0b + * Use the internal jimtcl API Jim_CreateCommandObj, not exported by jim.h, + * and override the bugged API through preprocessor's macro. + * This workaround works only when jimtcl is compiled as OpenOCD submodule. + * If jimtcl is linked-in from a precompiled library, either static or dynamic, + * the symbol Jim_CreateCommandObj is not exported and the build will use the + * bugged API. + * To be removed when OpenOCD will switch to jimtcl 0.81 + */ +#if JIM_VERSION == 80 +static int workaround_createcommand(Jim_Interp *interp, const char *cmdName, + Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc); +int Jim_CreateCommandObj(Jim_Interp *interp, Jim_Obj *cmdNameObj, + Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc) +__attribute__((weak, alias("workaround_createcommand"))); +static int workaround_createcommand(Jim_Interp *interp, const char *cmdName, + Jim_CmdProc *cmdProc, void *privData, Jim_DelCmdProc *delProc) +{ + if ((void *)Jim_CreateCommandObj == (void *)workaround_createcommand) + return Jim_CreateCommand(interp, cmdName, cmdProc, privData, delProc); + + Jim_Obj *cmd_name = Jim_NewStringObj(interp, cmdName, -1); + Jim_IncrRefCount(cmd_name); + int retval = Jim_CreateCommandObj(interp, cmd_name, cmdProc, privData, delProc); + Jim_DecrRefCount(interp, cmd_name); + return retval; +} +#define Jim_CreateCommand workaround_createcommand +#endif /* JIM_VERSION == 80 */ +/* FIXME: end of workaround for memory leak in jimtcl 0.80 */ + static int command_retval_set(Jim_Interp *interp, int retval) { int *return_retval = Jim_GetAssocData(interp, "retval"); From 5df84889021a6972a1678896ccf085219ffd908a Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 7 Mar 2021 23:19:07 +0100 Subject: [PATCH 103/120] udev rules: add missing ftdi USB VID/PID All ftdi devices require a dedicated line in the udev rules, but some USB VID/PID present in interface and board config file is missing in udev rules. Add the missing ftdi devices in udev rules. Change-Id: I850a4a95a2d4bb63b3fd09be803be8c23c4d6b49 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6101 Tested-by: jenkins --- contrib/60-openocd.rules | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index 0358b6010..73a81803e 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -32,8 +32,19 @@ ATTRS{idVendor}=="0403", ATTRS{idProduct}=="8220", MODE="660", GROUP="plugdev", ATTRS{idVendor}=="0403", ATTRS{idProduct}=="8a98", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="0403", ATTRS{idProduct}=="8a99", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Marvell OpenRD JTAGKey FT2232D B +ATTRS{idVendor}=="0403", ATTRS{idProduct}=="9e90", MODE="660", GROUP="plugdev", TAG+="uaccess" + # XDS100v2 ATTRS{idVendor}=="0403", ATTRS{idProduct}=="a6d0", MODE="660", GROUP="plugdev", TAG+="uaccess" +# XDS100v3 +ATTRS{idVendor}=="0403", ATTRS{idProduct}=="a6d1", MODE="660", GROUP="plugdev", TAG+="uaccess" + +# OOCDLink +ATTRS{idVendor}=="0403", ATTRS{idProduct}=="baf8", MODE="660", GROUP="plugdev", TAG+="uaccess" + +# Kristech KT-Link +ATTRS{idVendor}=="0403", ATTRS{idProduct}=="bbe2", MODE="660", GROUP="plugdev", TAG+="uaccess" # Xverve Signalyzer Tool (DT-USB-ST), Signalyzer LITE (DT-USB-SLITE) ATTRS{idVendor}=="0403", ATTRS{idProduct}=="bca0", MODE="660", GROUP="plugdev", TAG+="uaccess" @@ -93,6 +104,9 @@ ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="f138", MODE="660", GROUP="plugdev", # Infineon DAP miniWiggler v3 ATTRS{idVendor}=="058b", ATTRS{idProduct}=="0043", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Hitex LPC1768-Stick +ATTRS{idVendor}=="0640", ATTRS{idProduct}=="0026", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Hilscher NXHX Boards ATTRS{idVendor}=="0640", ATTRS{idProduct}=="0028", MODE="660", GROUP="plugdev", TAG+="uaccess" @@ -102,6 +116,9 @@ ATTRS{idVendor}=="0640", ATTRS{idProduct}=="002c", MODE="660", GROUP="plugdev", # Hitex STM32-PerformanceStick ATTRS{idVendor}=="0640", ATTRS{idProduct}=="002d", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Hitex Cortino +ATTRS{idVendor}=="0640", ATTRS{idProduct}=="0032", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Altera USB Blaster ATTRS{idVendor}=="09fb", ATTRS{idProduct}=="6001", MODE="660", GROUP="plugdev", TAG+="uaccess" @@ -163,9 +180,15 @@ ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="02a5", MODE="660", GROUP="plugdev", # TI Tiva-based ICDI and XDS110 probes in DFU mode ATTRS{idVendor}=="1cbe", ATTRS{idProduct}=="00ff", MODE="660", GROUP="plugdev", TAG+="uaccess" +# isodebug v1 +ATTRS{idVendor}=="22b7", ATTRS{idProduct}=="150d", MODE="660", GROUP="plugdev", TAG+="uaccess" + # PLS USB/JTAG Adapter for SPC5xxx ATTRS{idVendor}=="263d", ATTRS{idProduct}=="4001", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Numato Mimas A7 - Artix 7 FPGA Board +ATTRS{idVendor}=="2a19", ATTRS{idProduct}=="1009", MODE="660", GROUP="plugdev", TAG+="uaccess" + # Ambiq Micro EVK and Debug boards. ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6010", MODE="660", GROUP="plugdev", TAG+="uaccess" ATTRS{idVendor}=="2aec", ATTRS{idProduct}=="6011", MODE="660", GROUP="plugdev", TAG+="uaccess" From bc7d36d886ab547a344866bdd13ffd60d460752c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 7 Mar 2021 23:49:30 +0100 Subject: [PATCH 104/120] udev rules: add missing Altera USB Blaster devices All Altera USB Blaster devices require a dedicated line in the udev rules, but some USB VID/PID present in interface and board config file is missing in udev rules. Add the missing Altera USB Blaster devices in udev rules. While there, fix an incorrect pair VID/PID that are reported swapped inside a comment. Change-Id: I2d67e90b10db99ef2638405585859c1393456f65 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6102 Tested-by: jenkins --- contrib/60-openocd.rules | 6 ++++++ tcl/board/altera_sockit.cfg | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contrib/60-openocd.rules b/contrib/60-openocd.rules index 73a81803e..a3046be8f 100644 --- a/contrib/60-openocd.rules +++ b/contrib/60-openocd.rules @@ -121,6 +121,9 @@ ATTRS{idVendor}=="0640", ATTRS{idProduct}=="0032", MODE="660", GROUP="plugdev", # Altera USB Blaster ATTRS{idVendor}=="09fb", ATTRS{idProduct}=="6001", MODE="660", GROUP="plugdev", TAG+="uaccess" +# Altera USB Blaster2 +ATTRS{idVendor}=="09fb", ATTRS{idProduct}=="6010", MODE="660", GROUP="plugdev", TAG+="uaccess" +ATTRS{idVendor}=="09fb", ATTRS{idProduct}=="6810", MODE="660", GROUP="plugdev", TAG+="uaccess" # Amontec JTAGkey-HiSpeed ATTRS{idVendor}=="0fbb", ATTRS{idProduct}=="1000", MODE="660", GROUP="plugdev", TAG+="uaccess" @@ -166,6 +169,9 @@ ATTRS{idVendor}=="15ba", ATTRS{idProduct}=="002a", MODE="660", GROUP="plugdev", # Olimex ARM-USB-OCD-H ATTRS{idVendor}=="15ba", ATTRS{idProduct}=="002b", MODE="660", GROUP="plugdev", TAG+="uaccess" +# ixo-usb-jtag - Emulation of a Altera Bus Blaster I on a Cypress FX2 IC +ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="06ad", MODE="660", GROUP="plugdev", TAG+="uaccess" + # USBprog with OpenOCD firmware ATTRS{idVendor}=="1781", ATTRS{idProduct}=="0c63", MODE="660", GROUP="plugdev", TAG+="uaccess" diff --git a/tcl/board/altera_sockit.cfg b/tcl/board/altera_sockit.cfg index eb4c863fa..b7c7993fe 100644 --- a/tcl/board/altera_sockit.cfg +++ b/tcl/board/altera_sockit.cfg @@ -12,7 +12,7 @@ adapter driver usb_blaster source [find target/altera_fpgasoc.cfg] # If the USB Blaster II were supported, these settings would be needed -#usb_blaster_vid_pid 0x6810 0x09fb +#usb_blaster_vid_pid 0x09fb 0x6810 #usb_blaster_device_desc "USB-Blaster II" adapter speed 100 From 5c53e2cd41ac9d35ba7a92a4b7b46e2e7c359f47 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 29 Dec 2020 21:52:56 +0100 Subject: [PATCH 105/120] drivers/usbprog: switch to libusb1 Convert the driver from libusb0 to libusb1. Change-Id: I3f334f2d02515d612097955e714910a587169990 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5992 Tested-by: jenkins --- configure.ac | 4 +-- src/jtag/drivers/usbprog.c | 50 ++++++++++++++++++++------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/configure.ac b/configure.ac index 269452bb6..800ced5e9 100644 --- a/configure.ac +++ b/configure.ac @@ -123,11 +123,11 @@ m4_define([USB1_ADAPTERS], [[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]], [[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]], [[rlink], [Raisonance RLink JTAG Programmer], [RLINK]], + [[usbprog], [USBProg JTAG Programmer], [USBPROG]], [[aice], [Andes JTAG Programmer], [AICE]]]) m4_define([USB0_ADAPTERS], - [[[usbprog], [USBProg JTAG Programmer], [USBPROG]], - [[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]]) + [[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]]) m4_define([HIDAPI_ADAPTERS], [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP_HID]], diff --git a/src/jtag/drivers/usbprog.c b/src/jtag/drivers/usbprog.c index 627e4653d..44db61ec0 100644 --- a/src/jtag/drivers/usbprog.c +++ b/src/jtag/drivers/usbprog.c @@ -34,7 +34,7 @@ #include #include -#include "usb_common.h" +#include "libusb_helper.h" #define VID 0x1781 #define PID 0x0c63 @@ -64,7 +64,7 @@ static void usbprog_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int #define WRITE_TMS_CHAIN 0x0A struct usbprog_jtag { - struct usb_dev_handle *usb_handle; + struct libusb_device_handle *usb_handle; }; static struct usbprog_jtag *usbprog_jtag_handle; @@ -350,21 +350,19 @@ struct usb_bus *busses; struct usbprog_jtag *usbprog_jtag_open(void) { - usb_set_debug(10); - usb_init(); - const uint16_t vids[] = { VID, 0 }; const uint16_t pids[] = { PID, 0 }; - struct usb_dev_handle *dev; - if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + struct libusb_device_handle *dev; + + if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK) return NULL; struct usbprog_jtag *tmp = malloc(sizeof(struct usbprog_jtag)); tmp->usb_handle = dev; - usb_set_configuration(dev, 1); - usb_claim_interface(dev, 0); - usb_set_altinterface(dev, 0); + libusb_set_configuration(dev, 1); + libusb_claim_interface(dev, 0); + libusb_set_interface_alt_setting(dev, 0, 0); return tmp; } @@ -372,21 +370,23 @@ struct usbprog_jtag *usbprog_jtag_open(void) #if 0 static void usbprog_jtag_close(struct usbprog_jtag *usbprog_jtag) { - usb_close(usbprog_jtag->usb_handle); + libusb_close(usbprog_jtag->usb_handle); free(usbprog_jtag); } #endif static unsigned char usbprog_jtag_message(struct usbprog_jtag *usbprog_jtag, char *msg, int msglen) { - int res = usb_bulk_write(usbprog_jtag->usb_handle, 3, msg, msglen, 100); + int transferred; + + int res = jtag_libusb_bulk_write(usbprog_jtag->usb_handle, 3, msg, msglen, 100, &transferred); if ((msg[0] == 2) || (msg[0] == 1) || (msg[0] == 4) || (msg[0] == 0) || (msg[0] == 6) || (msg[0] == 0x0A) || (msg[0] == 9)) return 1; - if (res == msglen) { + if (res == ERROR_OK && transferred == msglen) { /* LOG_INFO("HALLLLOOO %i",(int)msg[0]); */ - res = usb_bulk_read(usbprog_jtag->usb_handle, 0x82, msg, 2, 100); - if (res > 0) + res = jtag_libusb_bulk_read(usbprog_jtag->usb_handle, 0x82, msg, 2, 100, &transferred); + if (res == ERROR_OK && transferred > 0) return (unsigned char)msg[1]; else return -1; @@ -428,11 +428,13 @@ static void usbprog_jtag_write_and_read(struct usbprog_jtag *usbprog_jtag, char bufindex++; } - if (usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000) == 64) { + int transferred; + int res = jtag_libusb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000, &transferred); + if (res == ERROR_OK && transferred == 64) { /* LOG_INFO("HALLLLOOO2 %i",(int)tmp[0]); */ usleep(1); int timeout = 0; - while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000) < 1) { + while (jtag_libusb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 1000, &transferred) != ERROR_OK) { timeout++; if (timeout > 10) break; @@ -469,12 +471,13 @@ static void usbprog_jtag_read_tdo(struct usbprog_jtag *usbprog_jtag, char *buffe tmp[1] = (char)(send_bits >> 8); /* high */ tmp[2] = (char)(send_bits); /* low */ - usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 3, 1000); + int transferred; + jtag_libusb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 3, 1000, &transferred); /* LOG_INFO("HALLLLOOO3 %i",(int)tmp[0]); */ int timeout = 0; usleep(1); - while (usb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10) < 1) { + while (jtag_libusb_bulk_read(usbprog_jtag->usb_handle, 0x82, tmp, 64, 10, &transferred) != ERROR_OK) { timeout++; if (timeout > 10) break; @@ -513,7 +516,8 @@ static void usbprog_jtag_write_tdi(struct usbprog_jtag *usbprog_jtag, char *buff tmp[3 + i] = buffer[bufindex]; bufindex++; } - usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000); + int transferred; + jtag_libusb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, 64, 1000, &transferred); } } @@ -582,15 +586,15 @@ static void usbprog_jtag_tms_collect(char tms_scan) static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag) { - int i; /* LOG_INFO("TMS SEND"); */ if (tms_chain_index > 0) { char tmp[tms_chain_index + 2]; tmp[0] = WRITE_TMS_CHAIN; tmp[1] = (char)(tms_chain_index); - for (i = 0; i < tms_chain_index + 1; i++) + for (int i = 0; i < tms_chain_index + 1; i++) tmp[2 + i] = tms_chain[i]; - usb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, tms_chain_index + 2, 1000); + int transferred; + jtag_libusb_bulk_write(usbprog_jtag->usb_handle, 3, tmp, tms_chain_index + 2, 1000, &transferred); tms_chain_index = 0; } } From ef41652cafe093f21d30e3116029b023b40bbc50 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 28 Dec 2020 23:51:32 +0100 Subject: [PATCH 106/120] drivers/arm-jtag-ew: switch to libusb1 Convert the driver from libusb0 to libusb1. Change-Id: Idef0b6cf10fab583bc8d13b3b4fadd5cc368c090 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5990 Tested-by: jenkins --- configure.ac | 3 ++- src/jtag/drivers/arm-jtag-ew.c | 47 +++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/configure.ac b/configure.ac index 800ced5e9..1a52ffb99 100644 --- a/configure.ac +++ b/configure.ac @@ -122,12 +122,13 @@ m4_define([USB1_ADAPTERS], [[cmsis_dap_v2], [CMSIS-DAP v2 Compliant Debugger], [CMSIS_DAP_USB]], [[osbdm], [OSBDM (JTAG only) Programmer], [OSBDM]], [[opendous], [eStick/opendous JTAG Programmer], [OPENDOUS]], + [[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]], [[rlink], [Raisonance RLink JTAG Programmer], [RLINK]], [[usbprog], [USBProg JTAG Programmer], [USBPROG]], [[aice], [Andes JTAG Programmer], [AICE]]]) m4_define([USB0_ADAPTERS], - [[[armjtagew], [Olimex ARM-JTAG-EW Programmer], [ARMJTAGEW]]]) + []) m4_define([HIDAPI_ADAPTERS], [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP_HID]], diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index 40d52acb9..d7afbe24d 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -22,8 +22,7 @@ #include #include -#include -#include "usb_common.h" +#include "libusb_helper.h" #define USB_VID 0x15ba #define USB_PID 0x001e @@ -75,7 +74,7 @@ static void armjtagew_tap_append_scan(int length, uint8_t *buffer, struct scan_c /* ARM-JTAG-EW lowlevel functions */ struct armjtagew { - struct usb_dev_handle *usb_handle; + struct libusb_device_handle *usb_handle; }; static struct armjtagew *armjtagew_usb_open(void); @@ -684,35 +683,37 @@ static int armjtagew_tap_execute(void) static struct armjtagew *armjtagew_usb_open(void) { - usb_init(); - const uint16_t vids[] = { USB_VID, 0 }; const uint16_t pids[] = { USB_PID, 0 }; - struct usb_dev_handle *dev; - if (jtag_usb_open(vids, pids, &dev) != ERROR_OK) + struct libusb_device_handle *dev; + + if (jtag_libusb_open(vids, pids, NULL, &dev, NULL) != ERROR_OK) return NULL; struct armjtagew *result = malloc(sizeof(struct armjtagew)); result->usb_handle = dev; #if 0 - /* usb_set_configuration required under win32 */ - usb_set_configuration(dev, dev->config[0].bConfigurationValue); + /* libusb_set_configuration required under win32 */ + struct libusb_config_descriptor *config; + struct libusb_device *usb_dev = libusb_get_device(dev); + libusb_get_config_descriptor(usb_dev, 0, &config); + libusb_set_configuration(dev, config->bConfigurationValue); #endif - usb_claim_interface(dev, 0); + libusb_claim_interface(dev, 0); #if 0 /* * This makes problems under Mac OS X. And is not needed * under Windows. Hopefully this will not break a linux build */ - usb_set_altinterface(dev, 0); + libusb_set_interface_alt_setting(dev, 0, 0); #endif return result; } static void armjtagew_usb_close(struct armjtagew *armjtagew) { - usb_close(armjtagew->usb_handle); + libusb_close(armjtagew->usb_handle); free(armjtagew); } @@ -725,13 +726,13 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in if (result == out_length) { result = armjtagew_usb_read(armjtagew, in_length); if (result != in_length) { - LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", + LOG_ERROR("jtag_libusb_bulk_read failed (requested=%d, result=%d)", in_length, result); return -1; } } else { - LOG_ERROR("usb_bulk_write failed (requested=%d, result=%d)", out_length, result); + LOG_ERROR("jtag_libusb_bulk_write failed (requested=%d, result=%d)", out_length, result); return -1; } return 0; @@ -741,6 +742,7 @@ static int armjtagew_usb_message(struct armjtagew *armjtagew, int out_length, in static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length) { int result; + int transferred; if (out_length > ARMJTAGEW_OUT_BUFFER_SIZE) { LOG_ERROR("armjtagew_write illegal out_length=%d (max=%d)", @@ -749,29 +751,34 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length) return -1; } - result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, - (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT); + result = jtag_libusb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, + (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT, &transferred); LOG_DEBUG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(usb_out_buffer, out_length); #endif - return result; + if (result != ERROR_OK) + return -1; + return transferred; } /* Read data from USB into in_buffer. */ static int armjtagew_usb_read(struct armjtagew *armjtagew, int exp_in_length) { - int result = usb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, - (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT); + int transferred; + int result = jtag_libusb_bulk_read(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_IN, + (char *)usb_in_buffer, exp_in_length, ARMJTAGEW_USB_TIMEOUT, &transferred); LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(usb_in_buffer, result); #endif - return result; + if (result != ERROR_OK) + return -1; + return transferred; } #ifdef _DEBUG_USB_COMMS_ From 68e50415a115f3b80b7d1a1b580287745b281a5c Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Tue, 29 Dec 2020 22:07:41 +0100 Subject: [PATCH 107/120] openocd: drop dependency from libusb0 Now that the old drivers have been converted to libusb1, there is no need to keep the build dependency from libusb0. Drop libusb0 from configure and makefiles, remove the libusb0 helper and remove libusb0 and libusb-compat from the README files. Change-Id: Icc05be74ae5971ba6cbb67d39107c709a4d826e6 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5993 Tested-by: jenkins --- README | 3 +- README.Windows | 4 --- README.macOS | 4 +-- configure.ac | 10 +----- src/jtag/aice/Makefile.am | 2 +- src/jtag/drivers/Makefile.am | 7 ----- src/jtag/drivers/usb_common.c | 57 ----------------------------------- src/jtag/drivers/usb_common.h | 26 ---------------- 8 files changed, 5 insertions(+), 108 deletions(-) delete mode 100644 src/jtag/drivers/usb_common.c delete mode 100644 src/jtag/drivers/usb_common.h diff --git a/README b/README index 1c5f19277..34dac0b1b 100644 --- a/README +++ b/README @@ -224,8 +224,7 @@ Additionally, for building from git: - automake >= 1.14 - texinfo >= 5.0 -USB-based adapters depend on libusb-1.0 and some older drivers require -libusb-0.1 or libusb-compat-0.1. A compatible implementation, such as +USB-based adapters depend on libusb-1.0. A compatible implementation, such as FreeBSD's, additionally needs the corresponding .pc files. USB-Blaster, ASIX Presto and OpenJTAG interface adapter diff --git a/README.Windows b/README.Windows index 6c616f38a..7326a356c 100644 --- a/README.Windows +++ b/README.Windows @@ -40,10 +40,6 @@ WinUSB.sys to the composite parent instead of the specific interface. To do that one needs to activate an advanced option in the Zadig installer. -For the old drivers that use libusb-0.1 API you might need to link -against libusb-win32 headers and install the corresponding driver with -Zadig. - If you need to use the same adapter with other applications that may require another driver, a solution for Windows Vista and above is to activate the IgnoreHWSerNum registry setting for the USB device. diff --git a/README.macOS b/README.macOS index c532e67c6..91d5e9261 100644 --- a/README.macOS +++ b/README.macOS @@ -27,14 +27,14 @@ With Homebrew you can either run: brew install [--HEAD] openocd (where optional --HEAD asks brew to install the current git version) or - brew install libtool automake libusb [libusb-compat] [hidapi] [libftdi] + brew install libtool automake libusb [hidapi] [libftdi] (to install the needed dependencies and then proceed with the manual building procedure) For building with MacPorts you need to run: sudo port install libtool automake autoconf pkgconfig \ - libusb [libusb-compat] [libftdi1] + libusb [libftdi1] You should also specify LDFLAGS and CPPFLAGS to allow configure to use MacPorts' libraries, so run configure like this: diff --git a/configure.ac b/configure.ac index 1a52ffb99..5c7dab570 100644 --- a/configure.ac +++ b/configure.ac @@ -127,9 +127,6 @@ m4_define([USB1_ADAPTERS], [[usbprog], [USBProg JTAG Programmer], [USBPROG]], [[aice], [Andes JTAG Programmer], [AICE]]]) -m4_define([USB0_ADAPTERS], - []) - m4_define([HIDAPI_ADAPTERS], [[[cmsis_dap], [CMSIS-DAP Compliant Debugger], [CMSIS_DAP_HID]], [[nulink], [Nu-Link Programmer], [HLADAPTER_NULINK]]]) @@ -249,7 +246,6 @@ m4_define([AC_ARG_ADAPTERS], [ AC_ARG_ADAPTERS([ USB1_ADAPTERS, - USB0_ADAPTERS, HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, @@ -585,8 +581,6 @@ PKG_CHECK_MODULES([LIBUSB1], [libusb-1.0], [ AC_MSG_WARN([libusb-1.x not found, trying legacy libusb-0.1 as a fallback; consider installing libusb-1.x instead]) ]) -PKG_CHECK_MODULES([LIBUSB0], [libusb], [use_libusb0=yes], [use_libusb0=no]) - AC_ARG_WITH([capstone], AS_HELP_STRING([--with-capstone], [Use Capstone disassembly library (default=auto)]) , [ @@ -648,7 +642,6 @@ m4_define([PROCESS_ADAPTERS], [ ]) PROCESS_ADAPTERS([USB1_ADAPTERS], ["x$use_libusb1" = "xyes"], [libusb-1.x]) -PROCESS_ADAPTERS([USB0_ADAPTERS], ["x$use_libusb0" = "xyes"], [libusb-0.1]) PROCESS_ADAPTERS([HIDAPI_ADAPTERS], ["x$use_hidapi" = "xyes"], [hidapi]) PROCESS_ADAPTERS([HIDAPI_USB1_ADAPTERS], ["x$use_hidapi" = "xyes" -a "x$use_libusb1" = "xyes"], [hidapi and libusb-1.x]) PROCESS_ADAPTERS([LIBFTDI_ADAPTERS], ["x$use_libftdi" = "xyes"], [libftdi]) @@ -705,7 +698,6 @@ AM_CONDITIONAL([REMOTE_BITBANG], [test "x$build_remote_bitbang" = "xyes"]) AM_CONDITIONAL([BUSPIRATE], [test "x$build_buspirate" = "xyes"]) AM_CONDITIONAL([SYSFSGPIO], [test "x$build_sysfsgpio" = "xyes"]) AM_CONDITIONAL([XLNX_PCIE_XVC], [test "x$build_xlnx_pcie_xvc" = "xyes"]) -AM_CONDITIONAL([USE_LIBUSB0], [test "x$use_libusb0" = "xyes"]) AM_CONDITIONAL([USE_LIBUSB1], [test "x$use_libusb1" = "xyes"]) AM_CONDITIONAL([IS_CYGWIN], [test "x$is_cygwin" = "xyes"]) AM_CONDITIONAL([IS_MINGW], [test "x$is_mingw" = "xyes"]) @@ -784,7 +776,7 @@ echo echo echo OpenOCD configuration summary echo -------------------------------------------------- -m4_foreach([adapter], [USB1_ADAPTERS, USB0_ADAPTERS, +m4_foreach([adapter], [USB1_ADAPTERS, HIDAPI_ADAPTERS, HIDAPI_USB1_ADAPTERS, LIBFTDI_ADAPTERS, LIBFTDI_USB1_ADAPTERS, LIBGPIOD_ADAPTERS, diff --git a/src/jtag/aice/Makefile.am b/src/jtag/aice/Makefile.am index 97e38258a..b6a7ba922 100644 --- a/src/jtag/aice/Makefile.am +++ b/src/jtag/aice/Makefile.am @@ -1,6 +1,6 @@ noinst_LTLIBRARIES += %D%/libocdaice.la -%C%_libocdaice_la_CPPFLAGS = -I$(top_srcdir)/src/jtag/drivers $(AM_CPPFLAGS) $(LIBUSB1_CFLAGS) $(LIBUSB0_CFLAGS) +%C%_libocdaice_la_CPPFLAGS = -I$(top_srcdir)/src/jtag/drivers $(AM_CPPFLAGS) $(LIBUSB1_CFLAGS) %C%_libocdaice_la_SOURCES = \ %D%/aice_transport.c \ %D%/aice_interface.c \ diff --git a/src/jtag/drivers/Makefile.am b/src/jtag/drivers/Makefile.am index f7a54b003..da60f366e 100644 --- a/src/jtag/drivers/Makefile.am +++ b/src/jtag/drivers/Makefile.am @@ -27,12 +27,6 @@ DRIVERFILES += %D%/libusb_helper.c %C%_libocdjtagdrivers_la_LIBADD += $(LIBUSB1_LIBS) endif -if USE_LIBUSB0 -DRIVERFILES += %D%/usb_common.c -%C%_libocdjtagdrivers_la_CPPFLAGS += $(LIBUSB0_CFLAGS) -%C%_libocdjtagdrivers_la_LIBADD += $(LIBUSB0_LIBS) -endif - if USE_LIBFTDI %C%_libocdjtagdrivers_la_CPPFLAGS += $(LIBFTDI_CFLAGS) %C%_libocdjtagdrivers_la_LIBADD += $(LIBFTDI_LIBS) @@ -203,7 +197,6 @@ DRIVERHEADERS = \ %D%/rlink_dtc_cmd.h \ %D%/rlink_ep1_cmd.h \ %D%/rlink_st7.h \ - %D%/usb_common.h \ %D%/versaloon/usbtoxxx/usbtoxxx.h \ %D%/versaloon/usbtoxxx/usbtoxxx_internal.h \ %D%/versaloon/versaloon.h \ diff --git a/src/jtag/drivers/usb_common.c b/src/jtag/drivers/usb_common.c deleted file mode 100644 index 1b7602d19..000000000 --- a/src/jtag/drivers/usb_common.c +++ /dev/null @@ -1,57 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Zachary T Welch * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include "usb_common.h" -#include "log.h" - - -static bool jtag_usb_match(struct usb_device *dev, - const uint16_t vids[], const uint16_t pids[]) -{ - for (unsigned i = 0; vids[i] && pids[i]; i++) { - if (dev->descriptor.idVendor == vids[i] && - dev->descriptor.idProduct == pids[i]) - return true; - } - return false; -} - -int jtag_usb_open(const uint16_t vids[], const uint16_t pids[], - struct usb_dev_handle **out) -{ - usb_find_busses(); - usb_find_devices(); - - struct usb_bus *busses = usb_get_busses(); - for (struct usb_bus *bus = busses; bus; bus = bus->next) { - for (struct usb_device *dev = bus->devices; dev; dev = dev->next) { - if (!jtag_usb_match(dev, vids, pids)) - continue; - - *out = usb_open(dev); - if (NULL == *out) { - LOG_ERROR("usb_open() failed with %s", usb_strerror()); - return ERROR_FAIL; - } - return ERROR_OK; - } - } - return ERROR_FAIL; -} diff --git a/src/jtag/drivers/usb_common.h b/src/jtag/drivers/usb_common.h deleted file mode 100644 index 4d2bd2686..000000000 --- a/src/jtag/drivers/usb_common.h +++ /dev/null @@ -1,26 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Zachary T Welch * - * * - * This program 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 program 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 . * - ***************************************************************************/ - -#ifndef OPENOCD_JTAG_DRIVERS_USB_COMMON_H -#define OPENOCD_JTAG_DRIVERS_USB_COMMON_H - -#include - -int jtag_usb_open(const uint16_t vids[], const uint16_t pids[], - struct usb_dev_handle **out); - -#endif /* OPENOCD_JTAG_DRIVERS_USB_COMMON_H */ From fed42ccfd3dff0c3dcfa7f017bbd26eff3d4f15c Mon Sep 17 00:00:00 2001 From: Adrian Negreanu Date: Fri, 6 Nov 2020 11:57:04 +0200 Subject: [PATCH 108/120] cmsis-dap: don't update the packet size across backends. The hidapi cmsis-dap backend is using a packet_size of 64+1: 64 is the bMaxPacketSize0 and 1 is the hid Report-Id. In hidapi::hid_write(), the packet_size is decremented by 1 and stored for the next transfer. The packet_size is now valid bMaxPacketSize0=64, so when hid_read() is called, libusb_bulk_transfer() finishes w/o timeout. For the libusb bulk backend, the same packet_size of 64+1 is used, but there's no hid_write() to decrement and store it for the next read. So the next time a read is done, it will try to read 64+1 bytes. Fix this by putting the packet logic within each backend. Use calloc() to allocate the struct cmsis_dap to be on safer side. Change-Id: I0c450adbc7674d5fcd8208dd23062d5cdd209efd Signed-off-by: Adrian Negreanu Reviewed-on: http://openocd.zylin.com/5920 Tested-by: jenkins Reviewed-by: Tarek BOCHKATI Reviewed-by: Tomas Vanek --- src/jtag/drivers/cmsis_dap.c | 42 ++++++++------------------- src/jtag/drivers/cmsis_dap.h | 4 +++ src/jtag/drivers/cmsis_dap_usb_bulk.c | 37 +++++++++++++++++++++-- src/jtag/drivers/cmsis_dap_usb_hid.c | 40 ++++++++++++++++++++----- 4 files changed, 83 insertions(+), 40 deletions(-) diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c index fd565398f..7a5acc314 100644 --- a/src/jtag/drivers/cmsis_dap.c +++ b/src/jtag/drivers/cmsis_dap.c @@ -225,16 +225,12 @@ static int cmsis_dap_open(void) { const struct cmsis_dap_backend *backend = NULL; - struct cmsis_dap *dap = malloc(sizeof(struct cmsis_dap)); + struct cmsis_dap *dap = calloc(1, sizeof(struct cmsis_dap)); if (dap == NULL) { LOG_ERROR("unable to allocate memory"); return ERROR_FAIL; } - dap->caps = 0; - dap->mode = 0; - dap->packet_size = 0; /* initialized by backend */ - if (cmsis_dap_backend >= 0) { /* Use forced backend */ backend = cmsis_dap_backends[cmsis_dap_backend]; @@ -257,17 +253,7 @@ static int cmsis_dap_open(void) return ERROR_FAIL; } - assert(dap->packet_size > 0); - dap->backend = backend; - dap->packet_buffer = malloc(dap->packet_size); - - if (dap->packet_buffer == NULL) { - LOG_ERROR("unable to allocate memory"); - dap->backend->close(dap); - free(dap); - return ERROR_FAIL; - } cmsis_dap_handle = dap; @@ -929,24 +915,20 @@ static int cmsis_dap_init(void) if (data[0] == 2) { /* short */ uint16_t pkt_sz = data[1] + (data[2] << 8); + if (pkt_sz != cmsis_dap_handle->packet_size) { - /* 4 bytes of command header + 5 bytes per register - * write. For bulk read sequences just 4 bytes are - * needed per transfer, so this is suboptimal. */ - pending_queue_len = (pkt_sz - 4) / 5; + /* 4 bytes of command header + 5 bytes per register + * write. For bulk read sequences just 4 bytes are + * needed per transfer, so this is suboptimal. */ + pending_queue_len = (pkt_sz - 4) / 5; - if (cmsis_dap_handle->packet_size != pkt_sz + 1) { - /* reallocate buffer */ - cmsis_dap_handle->packet_size = pkt_sz + 1; - cmsis_dap_handle->packet_buffer = realloc(cmsis_dap_handle->packet_buffer, - cmsis_dap_handle->packet_size); - if (cmsis_dap_handle->packet_buffer == NULL) { - LOG_ERROR("unable to reallocate memory"); - return ERROR_FAIL; - } + free(cmsis_dap_handle->packet_buffer); + retval = cmsis_dap_handle->backend->packet_buffer_alloc(cmsis_dap_handle, pkt_sz); + if (retval != ERROR_OK) + return retval; + + LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRIu16, pkt_sz); } - - LOG_DEBUG("CMSIS-DAP: Packet Size = %" PRId16, pkt_sz); } /* INFO_ID_PKT_CNT - byte */ diff --git a/src/jtag/drivers/cmsis_dap.h b/src/jtag/drivers/cmsis_dap.h index 054621cd5..a096a95c0 100644 --- a/src/jtag/drivers/cmsis_dap.h +++ b/src/jtag/drivers/cmsis_dap.h @@ -13,6 +13,7 @@ struct cmsis_dap { uint16_t packet_size; int packet_count; uint8_t *packet_buffer; + uint16_t packet_buffer_size; uint8_t caps; uint8_t mode; }; @@ -23,10 +24,13 @@ struct cmsis_dap_backend { void (*close)(struct cmsis_dap *dap); int (*read)(struct cmsis_dap *dap, int timeout_ms); int (*write)(struct cmsis_dap *dap, int len, int timeout_ms); + int (*packet_buffer_alloc)(struct cmsis_dap *dap, unsigned int pkt_sz); }; extern const struct cmsis_dap_backend cmsis_dap_hid_backend; extern const struct cmsis_dap_backend cmsis_dap_usb_backend; extern const struct command_registration cmsis_dap_usb_subcommand_handlers[]; +#define REPORT_ID_SIZE 1 + #endif diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index 0134c0376..7efea5166 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -50,6 +50,9 @@ struct cmsis_dap_backend_data { static int cmsis_dap_usb_interface = -1; +static void cmsis_dap_usb_close(struct cmsis_dap *dap); +static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz); + static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], char *serial) { int err; @@ -356,12 +359,21 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p return ERROR_FAIL; } - dap->packet_size = packet_size + 1; /* "+ 1" for compatibility with the HID backend */ + dap->packet_size = packet_size; + dap->packet_buffer_size = packet_size + REPORT_ID_SIZE; dap->bdata->usb_ctx = ctx; dap->bdata->dev_handle = dev_handle; dap->bdata->ep_out = ep_out; dap->bdata->ep_in = ep_in; dap->bdata->interface = interface_num; + + dap->packet_buffer = malloc(dap->packet_buffer_size); + if (dap->packet_buffer == NULL) { + LOG_ERROR("unable to allocate memory"); + cmsis_dap_usb_close(dap); + return ERROR_FAIL; + } + return ERROR_OK; } @@ -381,6 +393,8 @@ static void cmsis_dap_usb_close(struct cmsis_dap *dap) libusb_exit(dap->bdata->usb_ctx); free(dap->bdata); dap->bdata = NULL; + free(dap->packet_buffer); + dap->packet_buffer = NULL; } static int cmsis_dap_usb_read(struct cmsis_dap *dap, int timeout_ms) @@ -399,7 +413,7 @@ static int cmsis_dap_usb_read(struct cmsis_dap *dap, int timeout_ms) } } - memset(&dap->packet_buffer[transferred], 0, dap->packet_size - transferred); + memset(&dap->packet_buffer[transferred], 0, dap->packet_buffer_size - transferred); return transferred; } @@ -411,7 +425,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms) /* skip the first byte that is only used by the HID backend */ err = libusb_bulk_transfer(dap->bdata->dev_handle, dap->bdata->ep_out, - dap->packet_buffer + 1, txlen - 1, &transferred, timeout_ms); + dap->packet_buffer + REPORT_ID_SIZE, txlen - REPORT_ID_SIZE, &transferred, timeout_ms); if (err) { if (err == LIBUSB_ERROR_TIMEOUT) { return ERROR_TIMEOUT_REACHED; @@ -424,6 +438,22 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms) return transferred; } +static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) +{ + unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE; + uint8_t *buf = malloc(packet_buffer_size); + if (buf == NULL) { + LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); + return ERROR_FAIL; + } + + dap->packet_buffer = buf; + dap->packet_size = pkt_sz; + dap->packet_buffer_size = packet_buffer_size; + + return ERROR_OK; +} + COMMAND_HANDLER(cmsis_dap_handle_usb_interface_command) { if (CMD_ARGC == 1) @@ -451,4 +481,5 @@ const struct cmsis_dap_backend cmsis_dap_usb_backend = { .close = cmsis_dap_usb_close, .read = cmsis_dap_usb_read, .write = cmsis_dap_usb_write, + .packet_buffer_alloc = cmsis_dap_usb_alloc, }; diff --git a/src/jtag/drivers/cmsis_dap_usb_hid.c b/src/jtag/drivers/cmsis_dap_usb_hid.c index 681aef171..b290d6f81 100644 --- a/src/jtag/drivers/cmsis_dap_usb_hid.c +++ b/src/jtag/drivers/cmsis_dap_usb_hid.c @@ -40,12 +40,13 @@ #include "cmsis_dap.h" -#define PACKET_SIZE (64 + 1) /* 64 bytes plus report id */ - struct cmsis_dap_backend_data { hid_device *dev_handle; }; +static void cmsis_dap_hid_close(struct cmsis_dap *dap); +static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz); + static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t pids[], char *serial) { hid_device *dev = NULL; @@ -145,7 +146,7 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p * without this info we cannot communicate with the adapter. * For the moment we have to hard code the packet size */ - dap->packet_size = PACKET_SIZE; + unsigned int packet_size = 64; /* atmel cmsis-dap uses 512 byte reports */ /* except when it doesn't e.g. with mEDBG on SAMD10 Xplained @@ -153,10 +154,16 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p /* TODO: HID report descriptor should be parsed instead of * hardcoding a match by VID */ if (target_vid == 0x03eb && target_pid != 0x2145 && target_pid != 0x2175) - dap->packet_size = 512 + 1; + packet_size = 512; dap->bdata->dev_handle = dev; + int retval = cmsis_dap_hid_alloc(dap, packet_size); + if (retval != ERROR_OK) { + cmsis_dap_hid_close(dap); + return ERROR_FAIL; + } + return ERROR_OK; } @@ -166,11 +173,13 @@ static void cmsis_dap_hid_close(struct cmsis_dap *dap) hid_exit(); free(dap->bdata); dap->bdata = NULL; + free(dap->packet_buffer); + dap->packet_buffer = NULL; } static int cmsis_dap_hid_read(struct cmsis_dap *dap, int timeout_ms) { - int retval = hid_read_timeout(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_size, timeout_ms); + int retval = hid_read_timeout(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_buffer_size, timeout_ms); if (retval == 0) { return ERROR_TIMEOUT_REACHED; @@ -187,10 +196,10 @@ static int cmsis_dap_hid_write(struct cmsis_dap *dap, int txlen, int timeout_ms) (void) timeout_ms; /* Pad the rest of the TX buffer with 0's */ - memset(dap->packet_buffer + txlen, 0, dap->packet_size - txlen); + memset(dap->packet_buffer + txlen, 0, dap->packet_buffer_size - txlen); /* write data to device */ - int retval = hid_write(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_size); + int retval = hid_write(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_buffer_size); if (retval == -1) { LOG_ERROR("error writing data: %ls", hid_error(dap->bdata->dev_handle)); return ERROR_FAIL; @@ -199,10 +208,27 @@ static int cmsis_dap_hid_write(struct cmsis_dap *dap, int txlen, int timeout_ms) return retval; } +static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) +{ + unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE; + uint8_t *buf = malloc(packet_buffer_size); + if (buf == NULL) { + LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); + return ERROR_FAIL; + } + + dap->packet_buffer = buf; + dap->packet_size = pkt_sz; + dap->packet_buffer_size = packet_buffer_size; + + return ERROR_OK; +} + const struct cmsis_dap_backend cmsis_dap_hid_backend = { .name = "hid", .open = cmsis_dap_hid_open, .close = cmsis_dap_hid_close, .read = cmsis_dap_hid_read, .write = cmsis_dap_hid_write, + .packet_buffer_alloc = cmsis_dap_hid_alloc, }; From 01030fb893546ddd522a1557d8c00868b3e45f60 Mon Sep 17 00:00:00 2001 From: Tomas Vanek Date: Tue, 23 Mar 2021 09:12:26 +0100 Subject: [PATCH 109/120] drivers/cmsis-dap: tidy up buffer access Each one of CMSIS-DAP command handlers was responsible for setting HID report number, which in case of USB bulk transport was not used at all. The command had to be filled with 1 byte offset whereas the response was read without an offset. Introduce 'command' and 'response' pointers into struct cmsis_dap. Use them for filling the command and read the response respectively. CMSIS-DAP command parameter are now at positions as documented in https://arm-software.github.io/CMSIS_5/DAP/html/group__DAP__Commands__gr.html Adjust buffer allocation for HID and USB bulk transports. While on it, use h_u32_to_le() and h_u16_to_le() instead of per-byte writes. Change-Id: Ib0808d6826ba0e254c1007ace8b743405536332a Signed-off-by: Tomas Vanek Reviewed-on: http://openocd.zylin.com/6120 Reviewed-by: Adrian M Negreanu Tested-by: jenkins Reviewed-by: Tarek BOCHKATI --- src/jtag/drivers/cmsis_dap.c | 217 ++++++++++++-------------- src/jtag/drivers/cmsis_dap.h | 2 + src/jtag/drivers/cmsis_dap_usb_bulk.c | 15 +- src/jtag/drivers/cmsis_dap_usb_hid.c | 9 +- 4 files changed, 123 insertions(+), 120 deletions(-) diff --git a/src/jtag/drivers/cmsis_dap.c b/src/jtag/drivers/cmsis_dap.c index 7a5acc314..eb973642c 100644 --- a/src/jtag/drivers/cmsis_dap.c +++ b/src/jtag/drivers/cmsis_dap.c @@ -307,17 +307,14 @@ static int cmsis_dap_xfer(struct cmsis_dap *dap, int txlen) static int cmsis_dap_cmd_DAP_SWJ_Pins(uint8_t pins, uint8_t mask, uint32_t delay, uint8_t *input) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_SWJ_PINS; - buffer[2] = pins; - buffer[3] = mask; - buffer[4] = delay & 0xff; - buffer[5] = (delay >> 8) & 0xff; - buffer[6] = (delay >> 16) & 0xff; - buffer[7] = (delay >> 24) & 0xff; - retval = cmsis_dap_xfer(cmsis_dap_handle, 8); + command[0] = CMD_DAP_SWJ_PINS; + command[1] = pins; + command[2] = mask; + h_u32_to_le(&command[3], delay); + + retval = cmsis_dap_xfer(cmsis_dap_handle, 7); if (retval != ERROR_OK) { LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_PINS failed."); @@ -325,7 +322,7 @@ static int cmsis_dap_cmd_DAP_SWJ_Pins(uint8_t pins, uint8_t mask, uint32_t delay } if (input) - *input = buffer[1]; + *input = cmsis_dap_handle->response[1]; return ERROR_OK; } @@ -333,19 +330,17 @@ static int cmsis_dap_cmd_DAP_SWJ_Pins(uint8_t pins, uint8_t mask, uint32_t delay static int cmsis_dap_cmd_DAP_SWJ_Clock(uint32_t swj_clock) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; /* set clock in Hz */ swj_clock *= 1000; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_SWJ_CLOCK; - buffer[2] = swj_clock & 0xff; - buffer[3] = (swj_clock >> 8) & 0xff; - buffer[4] = (swj_clock >> 16) & 0xff; - buffer[5] = (swj_clock >> 24) & 0xff; - retval = cmsis_dap_xfer(cmsis_dap_handle, 6); - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + command[0] = CMD_DAP_SWJ_CLOCK; + h_u32_to_le(&command[1], swj_clock); + + retval = cmsis_dap_xfer(cmsis_dap_handle, 5); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_DAP_SWJ_CLOCK failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -357,7 +352,7 @@ static int cmsis_dap_cmd_DAP_SWJ_Clock(uint32_t swj_clock) static int cmsis_dap_cmd_DAP_SWJ_Sequence(uint8_t s_len, const uint8_t *sequence) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; #ifdef CMSIS_DAP_JTAG_DEBUG LOG_DEBUG("cmsis-dap TMS sequence: len=%d", s_len); @@ -367,14 +362,12 @@ static int cmsis_dap_cmd_DAP_SWJ_Sequence(uint8_t s_len, const uint8_t *sequence printf("\n"); #endif - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_SWJ_SEQ; - buffer[2] = s_len; - bit_copy(&buffer[3], 0, sequence, 0, s_len); + command[0] = CMD_DAP_SWJ_SEQ; + command[1] = s_len; + bit_copy(&command[2], 0, sequence, 0, s_len); - retval = cmsis_dap_xfer(cmsis_dap_handle, DIV_ROUND_UP(s_len, 8) + 3); - - if (retval != ERROR_OK || buffer[1] != DAP_OK) + retval = cmsis_dap_xfer(cmsis_dap_handle, 2 + DIV_ROUND_UP(s_len, 8)); + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) return ERROR_FAIL; return ERROR_OK; @@ -383,19 +376,19 @@ static int cmsis_dap_cmd_DAP_SWJ_Sequence(uint8_t s_len, const uint8_t *sequence static int cmsis_dap_cmd_DAP_Info(uint8_t info, uint8_t **data) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_INFO; - buffer[2] = info; - retval = cmsis_dap_xfer(cmsis_dap_handle, 3); + command[0] = CMD_DAP_INFO; + command[1] = info; + + retval = cmsis_dap_xfer(cmsis_dap_handle, 2); if (retval != ERROR_OK) { LOG_ERROR("CMSIS-DAP command CMD_INFO failed."); return ERROR_JTAG_DEVICE_ERROR; } - *data = &(buffer[1]); + *data = &cmsis_dap_handle->response[1]; return ERROR_OK; } @@ -403,15 +396,15 @@ static int cmsis_dap_cmd_DAP_Info(uint8_t info, uint8_t **data) static int cmsis_dap_cmd_DAP_LED(uint8_t led, uint8_t state) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_LED; - buffer[2] = led; - buffer[3] = state; - retval = cmsis_dap_xfer(cmsis_dap_handle, 4); + command[0] = CMD_DAP_LED; + command[1] = led; + command[2] = state; - if (retval != ERROR_OK || buffer[1] != 0x00) { + retval = cmsis_dap_xfer(cmsis_dap_handle, 3); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_LED failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -422,19 +415,19 @@ static int cmsis_dap_cmd_DAP_LED(uint8_t led, uint8_t state) static int cmsis_dap_cmd_DAP_Connect(uint8_t mode) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_CONNECT; - buffer[2] = mode; - retval = cmsis_dap_xfer(cmsis_dap_handle, 3); + command[0] = CMD_DAP_CONNECT; + command[1] = mode; + + retval = cmsis_dap_xfer(cmsis_dap_handle, 2); if (retval != ERROR_OK) { LOG_ERROR("CMSIS-DAP command CMD_CONNECT failed."); return ERROR_JTAG_DEVICE_ERROR; } - if (buffer[1] != mode) { + if (cmsis_dap_handle->response[1] != mode) { LOG_ERROR("CMSIS-DAP failed to connect in mode (%d)", mode); return ERROR_JTAG_DEVICE_ERROR; } @@ -445,13 +438,13 @@ static int cmsis_dap_cmd_DAP_Connect(uint8_t mode) static int cmsis_dap_cmd_DAP_Disconnect(void) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_DISCONNECT; - retval = cmsis_dap_xfer(cmsis_dap_handle, 2); + command[0] = CMD_DAP_DISCONNECT; - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + retval = cmsis_dap_xfer(cmsis_dap_handle, 1); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_DISCONNECT failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -462,18 +455,16 @@ static int cmsis_dap_cmd_DAP_Disconnect(void) static int cmsis_dap_cmd_DAP_TFER_Configure(uint8_t idle, uint16_t retry_count, uint16_t match_retry) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_TFER_CONFIGURE; - buffer[2] = idle; - buffer[3] = retry_count & 0xff; - buffer[4] = (retry_count >> 8) & 0xff; - buffer[5] = match_retry & 0xff; - buffer[6] = (match_retry >> 8) & 0xff; - retval = cmsis_dap_xfer(cmsis_dap_handle, 7); + command[0] = CMD_DAP_TFER_CONFIGURE; + command[1] = idle; + h_u16_to_le(&command[2], retry_count); + h_u16_to_le(&command[4], match_retry); - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + retval = cmsis_dap_xfer(cmsis_dap_handle, 6); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_TFER_Configure failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -484,14 +475,14 @@ static int cmsis_dap_cmd_DAP_TFER_Configure(uint8_t idle, uint16_t retry_count, static int cmsis_dap_cmd_DAP_SWD_Configure(uint8_t cfg) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_SWD_CONFIGURE; - buffer[2] = cfg; - retval = cmsis_dap_xfer(cmsis_dap_handle, 3); + command[0] = CMD_DAP_SWD_CONFIGURE; + command[1] = cfg; - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + retval = cmsis_dap_xfer(cmsis_dap_handle, 2); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_SWD_Configure failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -503,15 +494,14 @@ static int cmsis_dap_cmd_DAP_SWD_Configure(uint8_t cfg) static int cmsis_dap_cmd_DAP_Delay(uint16_t delay_us) { int retval; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_DELAY; - buffer[2] = delay_us & 0xff; - buffer[3] = (delay_us >> 8) & 0xff; - retval = cmsis_dap_xfer(cmsis_dap_handle, 4); + command[0] = CMD_DAP_DELAY; + h_u16_to_le(&command[1], delay_us); - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + retval = cmsis_dap_xfer(cmsis_dap_handle, 3); + + if (retval != ERROR_OK || cmsis_dap_handle->response[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_Delay failed."); return ERROR_JTAG_DEVICE_ERROR; } @@ -522,7 +512,7 @@ static int cmsis_dap_cmd_DAP_Delay(uint16_t delay_us) static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap) { - uint8_t *buffer = dap->packet_buffer; + uint8_t *command = cmsis_dap_handle->command; struct pending_request_block *block = &pending_fifo[pending_fifo_put_idx]; LOG_DEBUG_IO("Executing %d queued transactions from FIFO index %d", block->transfer_count, pending_fifo_put_idx); @@ -535,11 +525,10 @@ static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap) if (block->transfer_count == 0) goto skip; - size_t idx = 0; - buffer[idx++] = 0; /* report number */ - buffer[idx++] = CMD_DAP_TFER; - buffer[idx++] = 0x00; /* DAP Index */ - buffer[idx++] = block->transfer_count; + command[0] = CMD_DAP_TFER; + command[1] = 0x00; /* DAP Index */ + command[2] = block->transfer_count; + size_t idx = 3; for (int i = 0; i < block->transfer_count; i++) { struct pending_transfer_result *transfer = &(block->transfers[i]); @@ -570,12 +559,10 @@ static void cmsis_dap_swd_write_from_queue(struct cmsis_dap *dap) data &= ~CORUNDETECT; } - buffer[idx++] = (cmd >> 1) & 0x0f; + command[idx++] = (cmd >> 1) & 0x0f; if (!(cmd & SWD_CMD_RnW)) { - buffer[idx++] = (data) & 0xff; - buffer[idx++] = (data >> 8) & 0xff; - buffer[idx++] = (data >> 16) & 0xff; - buffer[idx++] = (data >> 24) & 0xff; + h_u32_to_le(&command[idx], data); + idx += 4; } } @@ -601,7 +588,6 @@ skip: static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms) { - uint8_t *buffer = dap->packet_buffer; struct pending_request_block *block = &pending_fifo[pending_fifo_get_idx]; if (pending_fifo_block_count == 0) @@ -618,30 +604,33 @@ static void cmsis_dap_swd_read_process(struct cmsis_dap *dap, int timeout_ms) goto skip; } - if (buffer[2] & 0x08) { - LOG_DEBUG("CMSIS-DAP Protocol Error @ %d (wrong parity)", buffer[1]); + uint8_t *resp = dap->response; + uint8_t transfer_count = resp[1]; + uint8_t ack = resp[2] & 0x07; + if (resp[2] & 0x08) { + LOG_DEBUG("CMSIS-DAP Protocol Error @ %d (wrong parity)", transfer_count); queued_retval = ERROR_FAIL; goto skip; } - uint8_t ack = buffer[2] & 0x07; if (ack != SWD_ACK_OK) { - LOG_DEBUG("SWD ack not OK @ %d %s", buffer[1], + LOG_DEBUG("SWD ack not OK @ %d %s", transfer_count, ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK"); queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL; goto skip; } - if (block->transfer_count != buffer[1]) + if (block->transfer_count != transfer_count) LOG_ERROR("CMSIS-DAP transfer count mismatch: expected %d, got %d", - block->transfer_count, buffer[1]); + block->transfer_count, transfer_count); - LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %d", buffer[1], pending_fifo_get_idx); + LOG_DEBUG_IO("Received results of %d queued transactions FIFO index %d", + transfer_count, pending_fifo_get_idx); size_t idx = 3; - for (int i = 0; i < buffer[1]; i++) { + for (int i = 0; i < transfer_count; i++) { struct pending_transfer_result *transfer = &(block->transfers[i]); if (transfer->cmd & SWD_CMD_RnW) { static uint32_t last_read; - uint32_t data = le_to_h_u32(&buffer[idx]); + uint32_t data = le_to_h_u32(&resp[idx]); uint32_t tmp = data; idx += 4; @@ -1145,20 +1134,21 @@ static void cmsis_dap_flush(void) LOG_DEBUG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture", queued_seq_count, queued_seq_buf_end, pending_scan_result_count); - /* prep CMSIS-DAP packet */ - uint8_t *buffer = cmsis_dap_handle->packet_buffer; - buffer[0] = 0; /* report number */ - buffer[1] = CMD_DAP_JTAG_SEQ; - buffer[2] = queued_seq_count; - memcpy(buffer + 3, queued_seq_buf, queued_seq_buf_end); + /* prepare CMSIS-DAP packet */ + uint8_t *command = cmsis_dap_handle->command; + command[0] = CMD_DAP_JTAG_SEQ; + command[1] = queued_seq_count; + memcpy(&command[2], queued_seq_buf, queued_seq_buf_end); #ifdef CMSIS_DAP_JTAG_DEBUG - debug_parse_cmsis_buf(buffer, queued_seq_buf_end + 3); + debug_parse_cmsis_buf(command, queued_seq_buf_end + 2); #endif /* send command to USB device */ - int retval = cmsis_dap_xfer(cmsis_dap_handle, queued_seq_buf_end + 3); - if (retval != ERROR_OK || buffer[1] != DAP_OK) { + int retval = cmsis_dap_xfer(cmsis_dap_handle, queued_seq_buf_end + 2); + + uint8_t *resp = cmsis_dap_handle->response; + if (retval != ERROR_OK || resp[1] != DAP_OK) { LOG_ERROR("CMSIS-DAP command CMD_DAP_JTAG_SEQ failed."); exit(-1); } @@ -1166,7 +1156,7 @@ static void cmsis_dap_flush(void) #ifdef CMSIS_DAP_JTAG_DEBUG LOG_DEBUG_IO("USB response buf:"); for (int c = 0; c < queued_seq_buf_end + 3; ++c) - printf("%02X ", buffer[c]); + printf("%02X ", resp[c]); printf("\n"); #endif @@ -1177,10 +1167,10 @@ static void cmsis_dap_flush(void) i, pending_scan_result_count, scan->length, scan->first + 2, scan->buffer_offset); #ifdef CMSIS_DAP_JTAG_DEBUG for (uint32_t b = 0; b < DIV_ROUND_UP(scan->length, 8); ++b) - printf("%02X ", buffer[2+scan->first+b]); + printf("%02X ", resp[2+scan->first+b]); printf("\n"); #endif - bit_copy(scan->buffer, scan->buffer_offset, buffer + 2 + scan->first, 0, scan->length); + bit_copy(scan->buffer, scan->buffer_offset, &resp[2 + scan->first], 0, scan->length); } /* reset */ @@ -1554,22 +1544,21 @@ COMMAND_HANDLER(cmsis_dap_handle_cmd_command) { int retval; unsigned i; - uint8_t *buffer = cmsis_dap_handle->packet_buffer; - - buffer[0] = 0; /* report number */ + uint8_t *command = cmsis_dap_handle->command; for (i = 0; i < CMD_ARGC; i++) - buffer[i + 1] = strtoul(CMD_ARGV[i], NULL, 16); + command[i] = strtoul(CMD_ARGV[i], NULL, 16); - retval = cmsis_dap_xfer(cmsis_dap_handle, CMD_ARGC + 1); + retval = cmsis_dap_xfer(cmsis_dap_handle, CMD_ARGC); if (retval != ERROR_OK) { LOG_ERROR("CMSIS-DAP command failed."); return ERROR_JTAG_DEVICE_ERROR; } + uint8_t *resp = cmsis_dap_handle->response; LOG_INFO("Returned data %02" PRIx8 " %02" PRIx8 " %02" PRIx8 " %02" PRIx8, - buffer[1], buffer[2], buffer[3], buffer[4]); + resp[1], resp[2], resp[3], resp[4]); return ERROR_OK; } diff --git a/src/jtag/drivers/cmsis_dap.h b/src/jtag/drivers/cmsis_dap.h index a096a95c0..c9f24c896 100644 --- a/src/jtag/drivers/cmsis_dap.h +++ b/src/jtag/drivers/cmsis_dap.h @@ -14,6 +14,8 @@ struct cmsis_dap { int packet_count; uint8_t *packet_buffer; uint16_t packet_buffer_size; + uint8_t *command; + uint8_t *response; uint8_t caps; uint8_t mode; }; diff --git a/src/jtag/drivers/cmsis_dap_usb_bulk.c b/src/jtag/drivers/cmsis_dap_usb_bulk.c index 7efea5166..c9ee53d2e 100644 --- a/src/jtag/drivers/cmsis_dap_usb_bulk.c +++ b/src/jtag/drivers/cmsis_dap_usb_bulk.c @@ -360,7 +360,7 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p } dap->packet_size = packet_size; - dap->packet_buffer_size = packet_size + REPORT_ID_SIZE; + dap->packet_buffer_size = packet_size; dap->bdata->usb_ctx = ctx; dap->bdata->dev_handle = dev_handle; dap->bdata->ep_out = ep_out; @@ -374,6 +374,9 @@ static int cmsis_dap_usb_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p return ERROR_FAIL; } + dap->command = dap->packet_buffer; + dap->response = dap->packet_buffer; + return ERROR_OK; } @@ -425,7 +428,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms) /* skip the first byte that is only used by the HID backend */ err = libusb_bulk_transfer(dap->bdata->dev_handle, dap->bdata->ep_out, - dap->packet_buffer + REPORT_ID_SIZE, txlen - REPORT_ID_SIZE, &transferred, timeout_ms); + dap->packet_buffer, txlen, &transferred, timeout_ms); if (err) { if (err == LIBUSB_ERROR_TIMEOUT) { return ERROR_TIMEOUT_REACHED; @@ -440,8 +443,7 @@ static int cmsis_dap_usb_write(struct cmsis_dap *dap, int txlen, int timeout_ms) static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) { - unsigned int packet_buffer_size = pkt_sz + REPORT_ID_SIZE; - uint8_t *buf = malloc(packet_buffer_size); + uint8_t *buf = malloc(pkt_sz); if (buf == NULL) { LOG_ERROR("unable to allocate CMSIS-DAP packet buffer"); return ERROR_FAIL; @@ -449,7 +451,10 @@ static int cmsis_dap_usb_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) dap->packet_buffer = buf; dap->packet_size = pkt_sz; - dap->packet_buffer_size = packet_buffer_size; + dap->packet_buffer_size = pkt_sz; + + dap->command = dap->packet_buffer; + dap->response = dap->packet_buffer; return ERROR_OK; } diff --git a/src/jtag/drivers/cmsis_dap_usb_hid.c b/src/jtag/drivers/cmsis_dap_usb_hid.c index b290d6f81..e83ad1feb 100644 --- a/src/jtag/drivers/cmsis_dap_usb_hid.c +++ b/src/jtag/drivers/cmsis_dap_usb_hid.c @@ -164,6 +164,8 @@ static int cmsis_dap_hid_open(struct cmsis_dap *dap, uint16_t vids[], uint16_t p return ERROR_FAIL; } + dap->command = dap->packet_buffer + REPORT_ID_SIZE; + dap->response = dap->packet_buffer; return ERROR_OK; } @@ -195,8 +197,10 @@ static int cmsis_dap_hid_write(struct cmsis_dap *dap, int txlen, int timeout_ms) { (void) timeout_ms; + dap->packet_buffer[0] = 0; /* HID report number */ + /* Pad the rest of the TX buffer with 0's */ - memset(dap->packet_buffer + txlen, 0, dap->packet_buffer_size - txlen); + memset(dap->command + txlen, 0, dap->packet_size - txlen); /* write data to device */ int retval = hid_write(dap->bdata->dev_handle, dap->packet_buffer, dap->packet_buffer_size); @@ -221,6 +225,9 @@ static int cmsis_dap_hid_alloc(struct cmsis_dap *dap, unsigned int pkt_sz) dap->packet_size = pkt_sz; dap->packet_buffer_size = packet_buffer_size; + dap->command = dap->packet_buffer + REPORT_ID_SIZE; + dap->response = dap->packet_buffer; + return ERROR_OK; } From 659e2e9da9a7d570827984cb3afdb2a44c3672e3 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 25 Apr 2020 17:19:28 +0200 Subject: [PATCH 110/120] LICENSES: move the GPL-2.0 license as required by checkpatch The script spdxcheck.py (used by checkpatch.pl) searches for the license files in a dedicated folder, split in the subfolders: "preferred", "dual", "deprecated", "exceptions". Move the GPL-2.0 license from COPYING to the subfolder preferred, adding the header required by spdxcheck.py. The header is copied from equivalent file in the Linux kernel, made by Thomas Gleixner . Note: the license in COPYING matches exactly https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt Add a minimalist COPYING in the top directory, as required by automake, pointing to the files in LICENSES. Change-Id: I1fd0abc57b554d74f0b00fabd6c8c822b2c4acb5 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5967 Tested-by: jenkins --- COPYING | 341 +---------------------------------- LICENSES/preferred/GPL-2.0 | 355 +++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + 3 files changed, 362 insertions(+), 335 deletions(-) create mode 100644 LICENSES/preferred/GPL-2.0 diff --git a/COPYING b/COPYING index d159169d1..b95181f53 100644 --- a/COPYING +++ b/COPYING @@ -1,339 +1,10 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 +OpenOCD is provided under: - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. + SPDX-License-Identifier: GPL-2.0-or-later - Preamble +Being under the terms of the GNU General Public License version 2 or +later, according with: - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. + LICENSES/preferred/GPL-2.0 - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program 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 program 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, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. +All contributions to OpenOCD are subject to this COPYING file. diff --git a/LICENSES/preferred/GPL-2.0 b/LICENSES/preferred/GPL-2.0 new file mode 100644 index 000000000..2ca4651c3 --- /dev/null +++ b/LICENSES/preferred/GPL-2.0 @@ -0,0 +1,355 @@ +Valid-License-Identifier: GPL-2.0 +Valid-License-Identifier: GPL-2.0-only +Valid-License-Identifier: GPL-2.0-or-later +SPDX-URL: https://spdx.org/licenses/GPL-2.0.html +Usage-Guide: + To use this license in source code, put one of the following SPDX + tag/value pairs into a comment according to the placement + guidelines in the licensing rules documentation. + For 'GNU General Public License (GPL) version 2 only' use: + SPDX-License-Identifier: GPL-2.0 + or + SPDX-License-Identifier: GPL-2.0-only + For 'GNU General Public License (GPL) version 2 or any later version' use: + SPDX-License-Identifier: GPL-2.0-or-later +License-Text: + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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 program 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Makefile.am b/Makefile.am index 85287c50f..cdd4ccb42 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ EXTRA_DIST += \ README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ + LICENSES/preferred/GPL-2.0 \ tools/logger.pl \ tools/rlink_make_speed_table \ tools/st7_dtc_as \ From ba4cc258d2a350efe7deea1845ad3ee72e8578fc Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 7 Dec 2020 23:25:39 +0100 Subject: [PATCH 111/120] LICENSES: add the GPL-3.0 license for stand-alone code The stand-alone application "contrib/itmdump.c" is released as GPL-3.0-or-later. Add GPL-3.0 license in the licenses list. Copy in subfolder stand-alone the GPL-3.0 from https://www.gnu.org/licenses/gpl-3.0.txt adding the header required by spdxcheck.py. Change-Id: I238efc411e07ed6bc1eba23edbc91b3825c3d2c7 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5968 Tested-by: jenkins --- LICENSES/stand-alone/GPL-3.0 | 690 +++++++++++++++++++++++++++++++++++ Makefile.am | 1 + 2 files changed, 691 insertions(+) create mode 100644 LICENSES/stand-alone/GPL-3.0 diff --git a/LICENSES/stand-alone/GPL-3.0 b/LICENSES/stand-alone/GPL-3.0 new file mode 100644 index 000000000..97dde3ee8 --- /dev/null +++ b/LICENSES/stand-alone/GPL-3.0 @@ -0,0 +1,690 @@ +Valid-License-Identifier: GPL-3.0 +Valid-License-Identifier: GPL-3.0-only +Valid-License-Identifier: GPL-3.0-or-later +SPDX-URL: https://spdx.org/licenses/GPL-3.0.html +Usage-Guide: + To use this license in source code, put one of the following SPDX + tag/value pairs into a comment according to the placement + guidelines in the licensing rules documentation. + For 'GNU General Public License (GPL) version 3 only' use: + SPDX-License-Identifier: GPL-3.0 + or + SPDX-License-Identifier: GPL-3.0-only + For 'GNU General Public License (GPL) version 3 or any later version' use: + SPDX-License-Identifier: GPL-3.0-or-later +License-Text: + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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 3 of the License, or + (at your option) any later version. + + This program 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 . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/Makefile.am b/Makefile.am index cdd4ccb42..83865e444 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ EXTRA_DIST += \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ LICENSES/preferred/GPL-2.0 \ + LICENSES/stand-alone/GPL-3.0 \ tools/logger.pl \ tools/rlink_make_speed_table \ tools/st7_dtc_as \ From 98ab7a4eba683a29ee6c969d76c600460519f38d Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Mon, 7 Dec 2020 15:28:16 +0100 Subject: [PATCH 112/120] LICENSES: add the GFDL-1.2 license The documentation of OpenOCD is released under the GNU Free Documentation License, version 1.2, with embedded some part of OpenOCD code released under the GNU GPL-2.0-or-later. Update doc/fdl.texi with latest minor fixes as in https://www.gnu.org/licenses/old-licenses/fdl-1.2.texi Update doc/openocd.texi and move here the license chapter title Add license file LICENSES/preferred/GFDL-1.2 from https://www.gnu.org/licenses/old-licenses/fdl-1.2.txt and add the required tags for reference and tooling, coping mostly from the Linux kernel license file in the 'deprecated' folder. Add a readme file to link to the existing texinfo copy of the license. Change-Id: Ief96e0686257be7a70d4eeec442848bd6494763d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5969 Tested-by: jenkins --- LICENSES/preferred/GFDL-1.2 | 412 ++++++++++++++++++++++++ LICENSES/preferred/gfdl-1.2.texi.readme | 4 + Makefile.am | 2 + doc/fdl.texi | 8 +- doc/openocd.texi | 2 + 5 files changed, 424 insertions(+), 4 deletions(-) create mode 100644 LICENSES/preferred/GFDL-1.2 create mode 100644 LICENSES/preferred/gfdl-1.2.texi.readme diff --git a/LICENSES/preferred/GFDL-1.2 b/LICENSES/preferred/GFDL-1.2 new file mode 100644 index 000000000..9217d9c8e --- /dev/null +++ b/LICENSES/preferred/GFDL-1.2 @@ -0,0 +1,412 @@ +Valid-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later +Valid-License-Identifier: GFDL-1.2-no-invariants-or-later +SPDX-URL: https://spdx.org/licenses/GFDL-1.2-no-invariants-or-later.html +Usage-Guide: + The GNU Free Documentation License should only be used without + Invariant Sections, Front-Cover Texts or Back-Cover Texts. + It should not be used for new documents. + To use the license in source code, put the following SPDX tag/value pair + into a comment according to the placement guidelines in the licensing + rules documentation: + SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later + or + SPDX-License-Identifier: GFDL-1.2-no-invariants-or-later +License-Text: + + GNU Free Documentation License + Version 1.2, November 2002 + + + Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + +0. PREAMBLE + +The purpose of this License is to make a manual, textbook, or other +functional and useful document "free" in the sense of freedom: to +assure everyone the effective freedom to copy and redistribute it, +with or without modifying it, either commercially or noncommercially. +Secondarily, this License preserves for the author and publisher a way +to get credit for their work, while not being considered responsible +for modifications made by others. + +This License is a kind of "copyleft", which means that derivative +works of the document must themselves be free in the same sense. It +complements the GNU General Public License, which is a copyleft +license designed for free software. + +We have designed this License in order to use it for manuals for free +software, because free software needs free documentation: a free +program should come with manuals providing the same freedoms that the +software does. But this License is not limited to software manuals; +it can be used for any textual work, regardless of subject matter or +whether it is published as a printed book. We recommend this License +principally for works whose purpose is instruction or reference. + + +1. APPLICABILITY AND DEFINITIONS + +This License applies to any manual or other work, in any medium, that +contains a notice placed by the copyright holder saying it can be +distributed under the terms of this License. Such a notice grants a +world-wide, royalty-free license, unlimited in duration, to use that +work under the conditions stated herein. The "Document", below, +refers to any such manual or work. Any member of the public is a +licensee, and is addressed as "you". You accept the license if you +copy, modify or distribute the work in a way requiring permission +under copyright law. + +A "Modified Version" of the Document means any work containing the +Document or a portion of it, either copied verbatim, or with +modifications and/or translated into another language. + +A "Secondary Section" is a named appendix or a front-matter section of +the Document that deals exclusively with the relationship of the +publishers or authors of the Document to the Document's overall subject +(or to related matters) and contains nothing that could fall directly +within that overall subject. (Thus, if the Document is in part a +textbook of mathematics, a Secondary Section may not explain any +mathematics.) The relationship could be a matter of historical +connection with the subject or with related matters, or of legal, +commercial, philosophical, ethical or political position regarding +them. + +The "Invariant Sections" are certain Secondary Sections whose titles +are designated, as being those of Invariant Sections, in the notice +that says that the Document is released under this License. If a +section does not fit the above definition of Secondary then it is not +allowed to be designated as Invariant. The Document may contain zero +Invariant Sections. If the Document does not identify any Invariant +Sections then there are none. + +The "Cover Texts" are certain short passages of text that are listed, +as Front-Cover Texts or Back-Cover Texts, in the notice that says that +the Document is released under this License. A Front-Cover Text may +be at most 5 words, and a Back-Cover Text may be at most 25 words. + +A "Transparent" copy of the Document means a machine-readable copy, +represented in a format whose specification is available to the +general public, that is suitable for revising the document +straightforwardly with generic text editors or (for images composed of +pixels) generic paint programs or (for drawings) some widely available +drawing editor, and that is suitable for input to text formatters or +for automatic translation to a variety of formats suitable for input +to text formatters. A copy made in an otherwise Transparent file +format whose markup, or absence of markup, has been arranged to thwart +or discourage subsequent modification by readers is not Transparent. +An image format is not Transparent if used for any substantial amount +of text. A copy that is not "Transparent" is called "Opaque". + +Examples of suitable formats for Transparent copies include plain +ASCII without markup, Texinfo input format, LaTeX input format, SGML +or XML using a publicly available DTD, and standard-conforming simple +HTML, PostScript or PDF designed for human modification. Examples of +transparent image formats include PNG, XCF and JPG. Opaque formats +include proprietary formats that can be read and edited only by +proprietary word processors, SGML or XML for which the DTD and/or +processing tools are not generally available, and the +machine-generated HTML, PostScript or PDF produced by some word +processors for output purposes only. + +The "Title Page" means, for a printed book, the title page itself, +plus such following pages as are needed to hold, legibly, the material +this License requires to appear in the title page. For works in +formats which do not have any title page as such, "Title Page" means +the text near the most prominent appearance of the work's title, +preceding the beginning of the body of the text. + +A section "Entitled XYZ" means a named subunit of the Document whose +title either is precisely XYZ or contains XYZ in parentheses following +text that translates XYZ in another language. (Here XYZ stands for a +specific section name mentioned below, such as "Acknowledgements", +"Dedications", "Endorsements", or "History".) To "Preserve the Title" +of such a section when you modify the Document means that it remains a +section "Entitled XYZ" according to this definition. + +The Document may include Warranty Disclaimers next to the notice which +states that this License applies to the Document. These Warranty +Disclaimers are considered to be included by reference in this +License, but only as regards disclaiming warranties: any other +implication that these Warranty Disclaimers may have is void and has +no effect on the meaning of this License. + + +2. VERBATIM COPYING + +You may copy and distribute the Document in any medium, either +commercially or noncommercially, provided that this License, the +copyright notices, and the license notice saying this License applies +to the Document are reproduced in all copies, and that you add no other +conditions whatsoever to those of this License. You may not use +technical measures to obstruct or control the reading or further +copying of the copies you make or distribute. However, you may accept +compensation in exchange for copies. If you distribute a large enough +number of copies you must also follow the conditions in section 3. + +You may also lend copies, under the same conditions stated above, and +you may publicly display copies. + + +3. COPYING IN QUANTITY + +If you publish printed copies (or copies in media that commonly have +printed covers) of the Document, numbering more than 100, and the +Document's license notice requires Cover Texts, you must enclose the +copies in covers that carry, clearly and legibly, all these Cover +Texts: Front-Cover Texts on the front cover, and Back-Cover Texts on +the back cover. Both covers must also clearly and legibly identify +you as the publisher of these copies. The front cover must present +the full title with all words of the title equally prominent and +visible. You may add other material on the covers in addition. +Copying with changes limited to the covers, as long as they preserve +the title of the Document and satisfy these conditions, can be treated +as verbatim copying in other respects. + +If the required texts for either cover are too voluminous to fit +legibly, you should put the first ones listed (as many as fit +reasonably) on the actual cover, and continue the rest onto adjacent +pages. + +If you publish or distribute Opaque copies of the Document numbering +more than 100, you must either include a machine-readable Transparent +copy along with each Opaque copy, or state in or with each Opaque copy +a computer-network location from which the general network-using +public has access to download using public-standard network protocols +a complete Transparent copy of the Document, free of added material. +If you use the latter option, you must take reasonably prudent steps, +when you begin distribution of Opaque copies in quantity, to ensure +that this Transparent copy will remain thus accessible at the stated +location until at least one year after the last time you distribute an +Opaque copy (directly or through your agents or retailers) of that +edition to the public. + +It is requested, but not required, that you contact the authors of the +Document well before redistributing any large number of copies, to give +them a chance to provide you with an updated version of the Document. + + +4. MODIFICATIONS + +You may copy and distribute a Modified Version of the Document under +the conditions of sections 2 and 3 above, provided that you release +the Modified Version under precisely this License, with the Modified +Version filling the role of the Document, thus licensing distribution +and modification of the Modified Version to whoever possesses a copy +of it. In addition, you must do these things in the Modified Version: + +A. Use in the Title Page (and on the covers, if any) a title distinct + from that of the Document, and from those of previous versions + (which should, if there were any, be listed in the History section + of the Document). You may use the same title as a previous version + if the original publisher of that version gives permission. +B. List on the Title Page, as authors, one or more persons or entities + responsible for authorship of the modifications in the Modified + Version, together with at least five of the principal authors of the + Document (all of its principal authors, if it has fewer than five), + unless they release you from this requirement. +C. State on the Title page the name of the publisher of the + Modified Version, as the publisher. +D. Preserve all the copyright notices of the Document. +E. Add an appropriate copyright notice for your modifications + adjacent to the other copyright notices. +F. Include, immediately after the copyright notices, a license notice + giving the public permission to use the Modified Version under the + terms of this License, in the form shown in the Addendum below. +G. Preserve in that license notice the full lists of Invariant Sections + and required Cover Texts given in the Document's license notice. +H. Include an unaltered copy of this License. +I. Preserve the section Entitled "History", Preserve its Title, and add + to it an item stating at least the title, year, new authors, and + publisher of the Modified Version as given on the Title Page. If + there is no section Entitled "History" in the Document, create one + stating the title, year, authors, and publisher of the Document as + given on its Title Page, then add an item describing the Modified + Version as stated in the previous sentence. +J. Preserve the network location, if any, given in the Document for + public access to a Transparent copy of the Document, and likewise + the network locations given in the Document for previous versions + it was based on. These may be placed in the "History" section. + You may omit a network location for a work that was published at + least four years before the Document itself, or if the original + publisher of the version it refers to gives permission. +K. For any section Entitled "Acknowledgements" or "Dedications", + Preserve the Title of the section, and preserve in the section all + the substance and tone of each of the contributor acknowledgements + and/or dedications given therein. +L. Preserve all the Invariant Sections of the Document, + unaltered in their text and in their titles. Section numbers + or the equivalent are not considered part of the section titles. +M. Delete any section Entitled "Endorsements". Such a section + may not be included in the Modified Version. +N. Do not retitle any existing section to be Entitled "Endorsements" + or to conflict in title with any Invariant Section. +O. Preserve any Warranty Disclaimers. + +If the Modified Version includes new front-matter sections or +appendices that qualify as Secondary Sections and contain no material +copied from the Document, you may at your option designate some or all +of these sections as invariant. To do this, add their titles to the +list of Invariant Sections in the Modified Version's license notice. +These titles must be distinct from any other section titles. + +You may add a section Entitled "Endorsements", provided it contains +nothing but endorsements of your Modified Version by various +parties--for example, statements of peer review or that the text has +been approved by an organization as the authoritative definition of a +standard. + +You may add a passage of up to five words as a Front-Cover Text, and a +passage of up to 25 words as a Back-Cover Text, to the end of the list +of Cover Texts in the Modified Version. Only one passage of +Front-Cover Text and one of Back-Cover Text may be added by (or +through arrangements made by) any one entity. If the Document already +includes a cover text for the same cover, previously added by you or +by arrangement made by the same entity you are acting on behalf of, +you may not add another; but you may replace the old one, on explicit +permission from the previous publisher that added the old one. + +The author(s) and publisher(s) of the Document do not by this License +give permission to use their names for publicity for or to assert or +imply endorsement of any Modified Version. + + +5. COMBINING DOCUMENTS + +You may combine the Document with other documents released under this +License, under the terms defined in section 4 above for modified +versions, provided that you include in the combination all of the +Invariant Sections of all of the original documents, unmodified, and +list them all as Invariant Sections of your combined work in its +license notice, and that you preserve all their Warranty Disclaimers. + +The combined work need only contain one copy of this License, and +multiple identical Invariant Sections may be replaced with a single +copy. If there are multiple Invariant Sections with the same name but +different contents, make the title of each such section unique by +adding at the end of it, in parentheses, the name of the original +author or publisher of that section if known, or else a unique number. +Make the same adjustment to the section titles in the list of +Invariant Sections in the license notice of the combined work. + +In the combination, you must combine any sections Entitled "History" +in the various original documents, forming one section Entitled +"History"; likewise combine any sections Entitled "Acknowledgements", +and any sections Entitled "Dedications". You must delete all sections +Entitled "Endorsements". + + +6. COLLECTIONS OF DOCUMENTS + +You may make a collection consisting of the Document and other documents +released under this License, and replace the individual copies of this +License in the various documents with a single copy that is included in +the collection, provided that you follow the rules of this License for +verbatim copying of each of the documents in all other respects. + +You may extract a single document from such a collection, and distribute +it individually under this License, provided you insert a copy of this +License into the extracted document, and follow this License in all +other respects regarding verbatim copying of that document. + + +7. AGGREGATION WITH INDEPENDENT WORKS + +A compilation of the Document or its derivatives with other separate +and independent documents or works, in or on a volume of a storage or +distribution medium, is called an "aggregate" if the copyright +resulting from the compilation is not used to limit the legal rights +of the compilation's users beyond what the individual works permit. +When the Document is included in an aggregate, this License does not +apply to the other works in the aggregate which are not themselves +derivative works of the Document. + +If the Cover Text requirement of section 3 is applicable to these +copies of the Document, then if the Document is less than one half of +the entire aggregate, the Document's Cover Texts may be placed on +covers that bracket the Document within the aggregate, or the +electronic equivalent of covers if the Document is in electronic form. +Otherwise they must appear on printed covers that bracket the whole +aggregate. + + +8. TRANSLATION + +Translation is considered a kind of modification, so you may +distribute translations of the Document under the terms of section 4. +Replacing Invariant Sections with translations requires special +permission from their copyright holders, but you may include +translations of some or all Invariant Sections in addition to the +original versions of these Invariant Sections. You may include a +translation of this License, and all the license notices in the +Document, and any Warranty Disclaimers, provided that you also include +the original English version of this License and the original versions +of those notices and disclaimers. In case of a disagreement between +the translation and the original version of this License or a notice +or disclaimer, the original version will prevail. + +If a section in the Document is Entitled "Acknowledgements", +"Dedications", or "History", the requirement (section 4) to Preserve +its Title (section 1) will typically require changing the actual +title. + + +9. TERMINATION + +You may not copy, modify, sublicense, or distribute the Document except +as expressly provided for under this License. Any other attempt to +copy, modify, sublicense or distribute the Document is void, and will +automatically terminate your rights under this License. However, +parties who have received copies, or rights, from you under this +License will not have their licenses terminated so long as such +parties remain in full compliance. + + +10. FUTURE REVISIONS OF THIS LICENSE + +The Free Software Foundation may publish new, revised versions +of the GNU Free Documentation License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. See +https://www.gnu.org/licenses/. + +Each version of the License is given a distinguishing version number. +If the Document specifies that a particular numbered version of this +License "or any later version" applies to it, you have the option of +following the terms and conditions either of that specified version or +of any later version that has been published (not as a draft) by the +Free Software Foundation. If the Document does not specify a version +number of this License, you may choose any version ever published (not +as a draft) by the Free Software Foundation. + + +ADDENDUM: How to use this License for your documents + +To use this License in a document you have written, include a copy of +the License in the document and put the following copyright and +license notices just after the title page: + + Copyright (c) YEAR YOUR NAME. + Permission is granted to copy, distribute and/or modify this document + under the terms of the GNU Free Documentation License, Version 1.2 + or any later version published by the Free Software Foundation; + with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. + A copy of the license is included in the section entitled "GNU + Free Documentation License". + +If you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, +replace the "with...Texts." line with this: + + with the Invariant Sections being LIST THEIR TITLES, with the + Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. + +If you have Invariant Sections without Cover Texts, or some other +combination of the three, merge those two alternatives to suit the +situation. + +If your document contains nontrivial examples of program code, we +recommend releasing these examples in parallel under your choice of +free software license, such as the GNU General Public License, +to permit their use in free software. diff --git a/LICENSES/preferred/gfdl-1.2.texi.readme b/LICENSES/preferred/gfdl-1.2.texi.readme new file mode 100644 index 000000000..9375c7913 --- /dev/null +++ b/LICENSES/preferred/gfdl-1.2.texi.readme @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later + +The texinfo version of the license gfdl-1.2 is distributed in the +file doc/fdl.texi . diff --git a/Makefile.am b/Makefile.am index 83865e444..8698c42c5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,8 @@ EXTRA_DIST += \ README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ + LICENSES/preferred/GFDL-1.2 \ + LICENSES/preferred/gfdl-1.2.texi.readme \ LICENSES/preferred/GPL-2.0 \ LICENSES/stand-alone/GPL-3.0 \ tools/logger.pl \ diff --git a/doc/fdl.texi b/doc/fdl.texi index 33b2a1646..2189f80a6 100644 --- a/doc/fdl.texi +++ b/doc/fdl.texi @@ -1,6 +1,5 @@ @c -*-texinfo-*- -@node License -@appendix The GNU Free Documentation License. +@c The GNU Free Documentation License. @center Version 1.2, November 2002 @c This file is intended to be included within another document, @@ -396,7 +395,7 @@ The Free Software Foundation may publish new, revised versions of the GNU Free Documentation License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. See -@uref{http://www.gnu.org/copyleft/}. +@uref{https://www.gnu.org/licenses/}. Each version of the License is given a distinguishing version number. If the Document specifies that a particular numbered version of this @@ -408,7 +407,8 @@ number of this License, you may choose any version ever published (not as a draft) by the Free Software Foundation. @end enumerate -@unnumberedsec ADDENDUM: How to use this License for your documents +@page +@heading ADDENDUM: How to use this License for your documents To use this License in a document you have written, include a copy of the License in the document and put the following copyright and diff --git a/doc/openocd.texi b/doc/openocd.texi index 45c9ffae8..2cba45ecd 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -11833,6 +11833,8 @@ foreach who @{A B C D E@} @} @end example +@node License +@appendix The GNU Free Documentation License. @include fdl.texi @node OpenOCD Concept Index From 87479e379a4015af126b9ff093c1b561c8d9f476 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Thu, 28 Dec 2017 16:27:15 +0100 Subject: [PATCH 113/120] LICENSES: add the BSD 2-clause "Simplified" license Add the full text of the BSD 2-clause "Simplified" license to OpenOCD tree. It was copied directly from: https://spdx.org/licenses/BSD-2-Clause.html#licenseText Add the required tags for reference and tooling. Change-Id: I1c2fb8ad7510ddd0d745308c0a9acc2764c31f4e Signed-off-by: Thomas Gleixner Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5970 Tested-by: jenkins --- LICENSES/preferred/BSD-2-Clause | 32 ++++++++++++++++++++++++++++++++ Makefile.am | 1 + 2 files changed, 33 insertions(+) create mode 100644 LICENSES/preferred/BSD-2-Clause diff --git a/LICENSES/preferred/BSD-2-Clause b/LICENSES/preferred/BSD-2-Clause new file mode 100644 index 000000000..da366e2ce --- /dev/null +++ b/LICENSES/preferred/BSD-2-Clause @@ -0,0 +1,32 @@ +Valid-License-Identifier: BSD-2-Clause +SPDX-URL: https://spdx.org/licenses/BSD-2-Clause.html +Usage-Guide: + To use the BSD 2-clause "Simplified" License put the following SPDX + tag/value pair into a comment according to the placement guidelines in + the licensing rules documentation: + SPDX-License-Identifier: BSD-2-Clause +License-Text: + +Copyright (c) . All rights reserved. + +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. + +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. diff --git a/Makefile.am b/Makefile.am index 8698c42c5..664430acb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ EXTRA_DIST += \ README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ + LICENSES/preferred/BSD-2-Clause \ LICENSES/preferred/GFDL-1.2 \ LICENSES/preferred/gfdl-1.2.texi.readme \ LICENSES/preferred/GPL-2.0 \ From 69adc83a5fff2eff63f223d951c3bc2aaf6deae0 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Thu, 28 Dec 2017 16:27:16 +0100 Subject: [PATCH 114/120] LICENSES: add the BSD 3-clause "New" or "Revised" License Add the full text of the BSD 3-clause "New" or "Revised" License to OpenOCD tree. It was copied directly from: https://spdx.org/licenses/BSD-3-Clause.html#licenseText Add the required tags for reference and tooling. Change-Id: I0e7977ed92af9d58a4a72152dd792045b237f2f0 Signed-off-by: Thomas Gleixner Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5971 Tested-by: jenkins --- LICENSES/preferred/BSD-3-Clause | 36 +++++++++++++++++++++++++++++++++ Makefile.am | 1 + 2 files changed, 37 insertions(+) create mode 100644 LICENSES/preferred/BSD-3-Clause diff --git a/LICENSES/preferred/BSD-3-Clause b/LICENSES/preferred/BSD-3-Clause new file mode 100644 index 000000000..34c7f057c --- /dev/null +++ b/LICENSES/preferred/BSD-3-Clause @@ -0,0 +1,36 @@ +Valid-License-Identifier: BSD-3-Clause +SPDX-URL: https://spdx.org/licenses/BSD-3-Clause.html +Usage-Guide: + To use the BSD 3-clause "New" or "Revised" License put the following SPDX + tag/value pair into a comment according to the placement guidelines in + the licensing rules documentation: + SPDX-License-Identifier: BSD-3-Clause +License-Text: + +Copyright (c) . All rights reserved. + +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. diff --git a/Makefile.am b/Makefile.am index 664430acb..8f52a395d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,7 @@ EXTRA_DIST += \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ LICENSES/preferred/BSD-2-Clause \ + LICENSES/preferred/BSD-3-Clause \ LICENSES/preferred/GFDL-1.2 \ LICENSES/preferred/gfdl-1.2.texi.readme \ LICENSES/preferred/GPL-2.0 \ From 5bf4640639c1855e4f2968b629e55bfffbdcdd76 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Thu, 10 Dec 2020 23:59:01 +0100 Subject: [PATCH 115/120] LICENSES: add the BSD 1-clause license Add the full text of the BSD 1-clause license. It was copied directly from: https://spdx.org/licenses/BSD-1-Clause.html#licenseText Add the required tags for reference and tooling. Change-Id: I71444e6a45d0e77fc57220cf1d579c010a27fdf3 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5972 Tested-by: jenkins --- LICENSES/preferred/BSD-1-Clause | 28 ++++++++++++++++++++++++++++ Makefile.am | 1 + 2 files changed, 29 insertions(+) create mode 100644 LICENSES/preferred/BSD-1-Clause diff --git a/LICENSES/preferred/BSD-1-Clause b/LICENSES/preferred/BSD-1-Clause new file mode 100644 index 000000000..c63b05bf5 --- /dev/null +++ b/LICENSES/preferred/BSD-1-Clause @@ -0,0 +1,28 @@ +Valid-License-Identifier: BSD-1-Clause +SPDX-URL: https://spdx.org/licenses/BSD-1-Clause.html +Usage-Guide: + To use the BSD 1-clause License put the following SPDX + tag/value pair into a comment according to the placement guidelines in + the licensing rules documentation: + SPDX-License-Identifier: BSD-1-Clause +License-Text: + +Copyright (c) . All rights reserved. + +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. + +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. diff --git a/Makefile.am b/Makefile.am index 8f52a395d..21b7c418d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ EXTRA_DIST += \ README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ + LICENSES/preferred/BSD-1-Clause \ LICENSES/preferred/BSD-2-Clause \ LICENSES/preferred/BSD-3-Clause \ LICENSES/preferred/GFDL-1.2 \ From 96aaa77f72a721f058f3863f270c2ba3d8d68871 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sat, 12 Dec 2020 11:50:56 +0100 Subject: [PATCH 116/120] LICENSES: add 'license-rules.txt' Add a file to the LICENSES directory to describe how file licenses should be described in all the OpenOCD files, using the SPDX identifier, as well as where all licenses should be in the source tree for people to refer to (LICENSES/). This file is mainly copied from the Linux kernel file in Documentation/process/license-rules.rst originally written by Thomas Gleixner , with specific adaptations for OpenOCD. Change-Id: I7a98fc756df90dc86dbc6e0c47c009a610a0318d Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/5973 Tested-by: jenkins Reviewed-by: Tim Newsome --- COPYING | 6 + LICENSES/license-rules.txt | 218 +++++++++++++++++++++++++++++++++++++ Makefile.am | 1 + 3 files changed, 225 insertions(+) create mode 100644 LICENSES/license-rules.txt diff --git a/COPYING b/COPYING index b95181f53..0e8db929e 100644 --- a/COPYING +++ b/COPYING @@ -7,4 +7,10 @@ later, according with: LICENSES/preferred/GPL-2.0 +In addition, other licenses may also apply. Please see: + + LICENSES/license-rules.txt + +for more details. + All contributions to OpenOCD are subject to this COPYING file. diff --git a/LICENSES/license-rules.txt b/LICENSES/license-rules.txt new file mode 100644 index 000000000..8d0c0a0ee --- /dev/null +++ b/LICENSES/license-rules.txt @@ -0,0 +1,218 @@ +# SPDX-License-Identifier: GPL-2.0-or-later OR GFDL-1.2-no-invariants-or-later + +OpenOCD licensing rules +======================= + +The OpenOCD source code is provided under the terms of the GNU General +Public License version 2 or later (GPL-2.0-or-later), as provided in +LICENSES/preferred/GPL-2.0. + +The OpenOCD documentation is provided under the terms of the GNU Free +Documentation License version 1.2 or later without Invariant Sections +(GFDL-1.2-no-invariants-or-later). + +Few stand-alone applications coexist in the same code tree of OpenOCD +and are provided under the terms of the GNU General Public License +version 3 (GPL-3.0), as provided in LICENSES/stand-alone/GPL-3.0. + +This documentation file provides a description of how each source file +should be annotated to make its license clear and unambiguous. +It doesn't replace the OpenOCD's license. + +The license described in the COPYING file applies to the OpenOCD source +as a whole, though individual source files can have a different license +which is required to be compatible with the GPL-2.0: + + GPL-1.0-or-later : GNU General Public License v1.0 or later + GPL-2.0-or-later : GNU General Public License v2.0 or later + LGPL-2.0 : GNU Library General Public License v2 only + LGPL-2.0-or-later : GNU Library General Public License v2 or later + LGPL-2.1 : GNU Lesser General Public License v2.1 only + LGPL-2.1-or-later : GNU Lesser General Public License v2.1 or later + +Aside from that, individual files can be provided under a dual license, +e.g. one of the compatible GPL variants and alternatively under a +permissive license like BSD, MIT etc. + +The common way of expressing the license of a source file is to add the +matching boilerplate text into the top comment of the file. Due to +formatting, typos etc. these "boilerplates" are hard to validate for +tools which are used in the context of license compliance. + +An alternative to boilerplate text is the use of Software Package Data +Exchange (SPDX) license identifiers in each source file. SPDX license +identifiers are machine parsable and precise shorthands for the license +under which the content of the file is contributed. SPDX license +identifiers are managed by the SPDX Workgroup at the Linux Foundation and +have been agreed on by partners throughout the industry, tool vendors, and +legal teams. For further information see https://spdx.org/ + +OpenOCD requires the precise SPDX identifier in all source files. +The valid identifiers used in OpenOCD are explained in the section +`License identifiers` and have been retrieved from the official SPDX +license list at https://spdx.org/licenses/ along with the license texts. + +License identifier syntax +------------------------- + +1. Placement: + + The SPDX license identifier in OpenOCD files shall be added at the + first possible line in a file which can contain a comment. For the + majority of files this is the first line, except for scripts which + require the '#!PATH_TO_INTERPRETER' in the first line. For those + scripts the SPDX identifier goes into the second line. + +2. Style: + + The SPDX license identifier is added in form of a comment. The comment + style depends on the file type:: + + C source: // SPDX-License-Identifier: + C header: /* SPDX-License-Identifier: */ + ASM: /* SPDX-License-Identifier: */ + makefiles: # SPDX-License-Identifier: + scripts: # SPDX-License-Identifier: + texinfo: @c SPDX-License-Identifier: + text: # SPDX-License-Identifier: + + If a specific tool cannot handle the standard comment style, then the + appropriate comment mechanism which the tool accepts shall be used. This + is the reason for having the "/\* \*/" style comment in C header + files. There was build breakage observed with generated .lds files where + 'ld' failed to parse the C++ comment. This has been fixed by now, but + there are still older assembler tools which cannot handle C++ style + comments. + +3. Syntax: + + A is either an SPDX short form license + identifier found on the SPDX License List, or the combination of two + SPDX short form license identifiers separated by "WITH" when a license + exception applies. When multiple licenses apply, an expression consists + of keywords "AND", "OR" separating sub-expressions and surrounded by + "(", ")" . + + License identifiers for licenses like [L]GPL with the 'or later' option + are constructed by using a "-or-later": + + // SPDX-License-Identifier: GPL-2.0-or-later + // SPDX-License-Identifier: LGPL-2.1-or-later + + WITH should be used when there is a modifier to a license needed. + Exceptions can only be used with particular License identifiers. The + valid License identifiers are listed in the tags of the exception text + file. + + OR should be used if the file is dual licensed and only one license is + to be selected. For example, some source files are available under dual + licenses: + + // SPDX-License-Identifier: GPL-2.0-or-later OR BSD-1-Clause + // SPDX-License-Identifier: GPL-2.0-or-later OR BSD-2-Clause + // SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause + + AND should be used if the file has multiple licenses whose terms all + apply to use the file. For example, if code is inherited from another + project and permission has been given to put it in OpenOCD, but the + original license terms need to remain in effect:: + + // SPDX-License-Identifier: GPL-2.0-or-later AND MIT + +License identifiers +------------------- + +The licenses currently used, as well as the licenses for code added to +OpenOCD, can be broken down into: + +1. `Preferred licenses`: + + Whenever possible these licenses should be used as they are known to be + fully compatible and widely used. These licenses are available from the + directory: + + LICENSES/preferred/ + + in the OpenOCD source tree. + + The files in this directory contain the full license text and + `Metatags`. The file names are identical to the SPDX license + identifier which shall be used for the license in source files. + + Examples: + + LICENSES/preferred/GPL-2.0 + + Contains the GPL version 2 license text and the required metatags. + + `Metatags`: + + The following meta tags must be available in a license file: + + - Valid-License-Identifier: + + One or more lines which declare which License Identifiers are valid + inside the project to reference this particular license text. Usually + this is a single valid identifier, but e.g. for licenses with the 'or + later' options two identifiers are valid. + + - SPDX-URL: + + The URL of the SPDX page which contains additional information related + to the license. + + - Usage-Guidance: + + Freeform text for usage advice. The text must include correct examples + for the SPDX license identifiers as they should be put into source + files according to the `License identifier syntax` guidelines. + + - License-Text: + + All text after this tag is treated as the original license text + + File format examples:: + + Valid-License-Identifier: GPL-2.0 + Valid-License-Identifier: GPL-2.0-only + Valid-License-Identifier: GPL-2.0-or-later + SPDX-URL: https://spdx.org/licenses/GPL-2.0.html + Usage-Guide: + To use this license in source code, put one of the following SPDX + tag/value pairs into a comment according to the placement + guidelines in the licensing rules documentation. + For 'GNU General Public License (GPL) version 2 only' use: + SPDX-License-Identifier: GPL-2.0 + or + SPDX-License-Identifier: GPL-2.0-only + For 'GNU General Public License (GPL) version 2 or any later version' use: + SPDX-License-Identifier: GPL-2.0-or-later + License-Text: + Full license text + +2. Stand-alone licenses: + + These licenses should only be used for stand-alone applications that are + distributed with OpenOCD but are not included in the OpenOCD binary. + These licenses are available from the directory: + + LICENSES/stand-alone/ + + in the OpenOCD source tree. + + Examples: + + SPDX-License-Identifier: GPL-3.0 + +The format and requirements of the license files in the other sub-directories +of directory + + LICENSES + +have to follow the same format and requirements of the `Preferred licenses`. + +All SPDX license identifiers and exceptions must have a corresponding file +in the LICENSES subdirectories. This is required to allow tool +verification (e.g. checkpatch.pl) and to have the licenses ready to read +and extract right from the source, which is recommended by various FOSS +organizations, e.g. the `FSFE REUSE initiative `. diff --git a/Makefile.am b/Makefile.am index 21b7c418d..fc444f127 100644 --- a/Makefile.am +++ b/Makefile.am @@ -50,6 +50,7 @@ EXTRA_DIST += \ README.macOS \ $(EXTRA_DIST_NEWS) \ Doxyfile.in \ + LICENSES/license-rules.txt \ LICENSES/preferred/BSD-1-Clause \ LICENSES/preferred/BSD-2-Clause \ LICENSES/preferred/BSD-3-Clause \ From 134d7d5a5876a53a10ecb2eeac8d193bdddcea81 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Fri, 2 Apr 2021 11:17:00 +0200 Subject: [PATCH 117/120] doc/manual/style: Do not use 'Yoda conditions' For more details, see: https://en.wikipedia.org/wiki/Yoda_conditions https://sektorvanskijlen.wordpress.com/2019/05/16/conditional-inversion-very-harmful-myth/ Change-Id: If1a8a5f1d0fd345b7cc0c7b5dee6d0d47f9d7fc2 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6132 Reviewed-by: Tarek BOCHKATI Tested-by: jenkins Reviewed-by: Oleksij Rempel Reviewed-by: Antonio Borneo Reviewed-by: Tomas Vanek --- doc/manual/style.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual/style.txt b/doc/manual/style.txt index dad3bb440..c3fcfd782 100644 --- a/doc/manual/style.txt +++ b/doc/manual/style.txt @@ -135,13 +135,13 @@ should write statements like the following: @code // separate statements should be preferred result = foo(); -if (ERROR_OK != result) +if (result != ERROR_OK) ... @endcode More directly, do @b not combine these kinds of statements: @code // Combined statements should be avoided -if (ERROR_OK != (result = foo())) +if ((result = foo()) != ERROR_OK) return result; @endcode From 0ec9018040c2fd77807d80225b34e2fc7fb23e82 Mon Sep 17 00:00:00 2001 From: Marc Schink Date: Mon, 5 Apr 2021 15:40:35 +0200 Subject: [PATCH 118/120] doc/manual/style: Fix comments The comments currently used are not rendered. Change-Id: I3fcfb6aee4dea9c4f9186a7aec70d382a1abd634 Signed-off-by: Marc Schink Reviewed-on: http://openocd.zylin.com/6133 Tested-by: jenkins Reviewed-by: Antonio Borneo --- doc/manual/style.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/manual/style.txt b/doc/manual/style.txt index c3fcfd782..755709fb0 100644 --- a/doc/manual/style.txt +++ b/doc/manual/style.txt @@ -114,9 +114,9 @@ pthreads require modest and predictable stack usage. - static inline functions should be preferred over macros: @code -/** do NOT define macro-like functions like this... */ +/* do NOT define macro-like functions like this... */ #define CUBE(x) ((x) * (x) * (x)) -/** instead, define the same expression using a C99 inline function */ +/* instead, define the same expression using a C99 inline function */ static inline int cube(int x) { return x * x * x; } @endcode - Functions should be declared static unless required by other modules From 651b861d5d5f1e361faee37a10c7d7ce03aa6afa Mon Sep 17 00:00:00 2001 From: Liming Sun Date: Fri, 9 Nov 2018 16:17:25 -0500 Subject: [PATCH 119/120] target/aarch64: Add watchpoint support There are some breakpoint/watchpoint related code in armv8_dpm.c, but seems not working for aarch64. Target aarch64 has its own breakpoint implementation in aarch64.c. This commit follows the same logic to add watchpoint support for target aarch64. This commit also increases the size of stop_reason[] in function gdb_signal_reply() since the old size is too small to fit in a 64-bit address, such as ffff8000115e6980. Change-Id: I907dc0e648130e36b434220f570c37d0e8eb5ce1 Signed-off-by: Liming Sun Signed-off-by: Daniel Goehring Reviewed-on: http://openocd.zylin.com/4761 Tested-by: jenkins Reviewed-by: Liming Sun Reviewed-by: Kevin Burke Reviewed-by: Matthias Welwarsky Reviewed-by: Antonio Borneo --- src/server/gdb_server.c | 2 +- src/target/aarch64.c | 222 +++++++++++++++++++++++++++++++++++++++- src/target/aarch64.h | 5 + src/target/armv8_dpm.c | 6 +- 4 files changed, 228 insertions(+), 7 deletions(-) diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index fc58971a7..002b5873b 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -728,7 +728,7 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio { struct gdb_connection *gdb_connection = connection->priv; char sig_reply[65]; - char stop_reason[20]; + char stop_reason[32]; char current_thread[25]; int sig_reply_len; int signal_var; diff --git a/src/target/aarch64.c b/src/target/aarch64.c index e45803040..d6b12cd59 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -1651,7 +1651,6 @@ static int aarch64_add_hybrid_breakpoint(struct target *target, return aarch64_set_hybrid_breakpoint(target, breakpoint); /* ??? */ } - static int aarch64_remove_breakpoint(struct target *target, struct breakpoint *breakpoint) { struct aarch64_common *aarch64 = target_to_aarch64(target); @@ -1673,6 +1672,207 @@ static int aarch64_remove_breakpoint(struct target *target, struct breakpoint *b return ERROR_OK; } +/* Setup hardware Watchpoint Register Pair */ +static int aarch64_set_watchpoint(struct target *target, + struct watchpoint *watchpoint) +{ + int retval; + int wp_i = 0; + uint32_t control, offset, length; + struct aarch64_common *aarch64 = target_to_aarch64(target); + struct armv8_common *armv8 = &aarch64->armv8_common; + struct aarch64_brp *wp_list = aarch64->wp_list; + + if (watchpoint->set) { + LOG_WARNING("watchpoint already set"); + return ERROR_OK; + } + + while (wp_list[wp_i].used && (wp_i < aarch64->wp_num)) + wp_i++; + if (wp_i >= aarch64->wp_num) { + LOG_ERROR("ERROR Can not find free Watchpoint Register Pair"); + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } + + control = (1 << 0) /* enable */ + | (3 << 1) /* both user and privileged access */ + | (1 << 13); /* higher mode control */ + + switch (watchpoint->rw) { + case WPT_READ: + control |= 1 << 3; + break; + case WPT_WRITE: + control |= 2 << 3; + break; + case WPT_ACCESS: + control |= 3 << 3; + break; + } + + /* Match up to 8 bytes. */ + offset = watchpoint->address & 7; + length = watchpoint->length; + if (offset + length > sizeof(uint64_t)) { + length = sizeof(uint64_t) - offset; + LOG_WARNING("Adjust watchpoint match inside 8-byte boundary"); + } + for (; length > 0; offset++, length--) + control |= (1 << offset) << 5; + + wp_list[wp_i].value = watchpoint->address & 0xFFFFFFFFFFFFFFF8ULL; + wp_list[wp_i].control = control; + + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WVR_BASE + 16 * wp_list[wp_i].BRPn, + (uint32_t)(wp_list[wp_i].value & 0xFFFFFFFF)); + if (retval != ERROR_OK) + return retval; + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WVR_BASE + 4 + 16 * wp_list[wp_i].BRPn, + (uint32_t)(wp_list[wp_i].value >> 32)); + if (retval != ERROR_OK) + return retval; + + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WCR_BASE + 16 * wp_list[wp_i].BRPn, + control); + if (retval != ERROR_OK) + return retval; + LOG_DEBUG("wp %i control 0x%0" PRIx32 " value 0x%" TARGET_PRIxADDR, wp_i, + wp_list[wp_i].control, wp_list[wp_i].value); + + /* Ensure that halting debug mode is enable */ + retval = aarch64_set_dscr_bits(target, DSCR_HDE, DSCR_HDE); + if (retval != ERROR_OK) { + LOG_DEBUG("Failed to set DSCR.HDE"); + return retval; + } + + wp_list[wp_i].used = 1; + watchpoint->set = wp_i + 1; + + return ERROR_OK; +} + +/* Clear hardware Watchpoint Register Pair */ +static int aarch64_unset_watchpoint(struct target *target, + struct watchpoint *watchpoint) +{ + int retval, wp_i; + struct aarch64_common *aarch64 = target_to_aarch64(target); + struct armv8_common *armv8 = &aarch64->armv8_common; + struct aarch64_brp *wp_list = aarch64->wp_list; + + if (!watchpoint->set) { + LOG_WARNING("watchpoint not set"); + return ERROR_OK; + } + + wp_i = watchpoint->set - 1; + if ((wp_i < 0) || (wp_i >= aarch64->wp_num)) { + LOG_DEBUG("Invalid WP number in watchpoint"); + return ERROR_OK; + } + LOG_DEBUG("rwp %i control 0x%0" PRIx32 " value 0x%0" PRIx64, wp_i, + wp_list[wp_i].control, wp_list[wp_i].value); + wp_list[wp_i].used = 0; + wp_list[wp_i].value = 0; + wp_list[wp_i].control = 0; + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WCR_BASE + 16 * wp_list[wp_i].BRPn, + wp_list[wp_i].control); + if (retval != ERROR_OK) + return retval; + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WVR_BASE + 16 * wp_list[wp_i].BRPn, + wp_list[wp_i].value); + if (retval != ERROR_OK) + return retval; + + retval = aarch64_dap_write_memap_register_u32(target, armv8->debug_base + + CPUV8_DBG_WVR_BASE + 4 + 16 * wp_list[wp_i].BRPn, + (uint32_t)wp_list[wp_i].value); + if (retval != ERROR_OK) + return retval; + watchpoint->set = 0; + + return ERROR_OK; +} + +static int aarch64_add_watchpoint(struct target *target, + struct watchpoint *watchpoint) +{ + int retval; + struct aarch64_common *aarch64 = target_to_aarch64(target); + + if (aarch64->wp_num_available < 1) { + LOG_INFO("no hardware watchpoint available"); + return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; + } + + retval = aarch64_set_watchpoint(target, watchpoint); + if (retval == ERROR_OK) + aarch64->wp_num_available--; + + return retval; +} + +static int aarch64_remove_watchpoint(struct target *target, + struct watchpoint *watchpoint) +{ + struct aarch64_common *aarch64 = target_to_aarch64(target); + + if (watchpoint->set) { + aarch64_unset_watchpoint(target, watchpoint); + aarch64->wp_num_available++; + } + + return ERROR_OK; +} + +/** + * find out which watchpoint hits + * get exception address and compare the address to watchpoints + */ +int aarch64_hit_watchpoint(struct target *target, + struct watchpoint **hit_watchpoint) +{ + if (target->debug_reason != DBG_REASON_WATCHPOINT) + return ERROR_FAIL; + + struct armv8_common *armv8 = target_to_armv8(target); + + uint64_t exception_address; + struct watchpoint *wp; + + exception_address = armv8->dpm.wp_pc; + + if (exception_address == 0xFFFFFFFF) + return ERROR_FAIL; + + /**********************************************************/ + /* see if a watchpoint address matches a value read from */ + /* the EDWAR register. Testing shows that on some ARM CPUs*/ + /* the EDWAR value needs to have 8 added to it so we add */ + /* that check as well not sure if that is a core bug) */ + /**********************************************************/ + for (exception_address = armv8->dpm.wp_pc; exception_address <= (armv8->dpm.wp_pc + 8); + exception_address += 8) { + for (wp = target->watchpoints; wp; wp = wp->next) { + if ((exception_address >= wp->address) && (exception_address < (wp->address + wp->length))) { + *hit_watchpoint = wp; + if (exception_address != armv8->dpm.wp_pc) + LOG_DEBUG("watchpoint hit required EDWAR to be increased by 8"); + return ERROR_OK; + } + } + } + + return ERROR_FAIL; +} + /* * Cortex-A8 Reset functions */ @@ -2461,7 +2661,20 @@ static int aarch64_examine_first(struct target *target) aarch64->brp_list[i].BRPn = i; } - LOG_DEBUG("Configured %i hw breakpoints", aarch64->brp_num); + /* Setup Watchpoint Register Pairs */ + aarch64->wp_num = (uint32_t)((debug >> 20) & 0x0F) + 1; + aarch64->wp_num_available = aarch64->wp_num; + aarch64->wp_list = calloc(aarch64->wp_num, sizeof(struct aarch64_brp)); + for (i = 0; i < aarch64->wp_num; i++) { + aarch64->wp_list[i].used = 0; + aarch64->wp_list[i].type = BRP_NORMAL; + aarch64->wp_list[i].value = 0; + aarch64->wp_list[i].control = 0; + aarch64->wp_list[i].BRPn = i; + } + + LOG_DEBUG("Configured %i hw breakpoints, %i watchpoints", + aarch64->brp_num, aarch64->wp_num); target->state = TARGET_UNKNOWN; target->debug_reason = DBG_REASON_NOTHALTED; @@ -2977,8 +3190,9 @@ struct target_type aarch64_target = { .add_context_breakpoint = aarch64_add_context_breakpoint, .add_hybrid_breakpoint = aarch64_add_hybrid_breakpoint, .remove_breakpoint = aarch64_remove_breakpoint, - .add_watchpoint = NULL, - .remove_watchpoint = NULL, + .add_watchpoint = aarch64_add_watchpoint, + .remove_watchpoint = aarch64_remove_watchpoint, + .hit_watchpoint = aarch64_hit_watchpoint, .commands = aarch64_command_handlers, .target_create = aarch64_target_create, diff --git a/src/target/aarch64.h b/src/target/aarch64.h index d7886a3d7..7c0ddf868 100644 --- a/src/target/aarch64.h +++ b/src/target/aarch64.h @@ -62,6 +62,11 @@ struct aarch64_common { int brp_num_available; struct aarch64_brp *brp_list; + /* Watchpoint register pairs */ + int wp_num; + int wp_num_available; + struct aarch64_brp *wp_list; + struct armv8_common armv8_common; enum aarch64_isrmasking_mode isrmasking_mode; diff --git a/src/target/armv8_dpm.c b/src/target/armv8_dpm.c index 1e88a445f..e7d0f864e 100644 --- a/src/target/armv8_dpm.c +++ b/src/target/armv8_dpm.c @@ -1465,8 +1465,10 @@ int armv8_dpm_setup(struct arm_dpm *dpm) } /* watchpoint setup */ - target->type->add_watchpoint = dpmv8_add_watchpoint; - target->type->remove_watchpoint = dpmv8_remove_watchpoint; + if (!target->type->add_watchpoint) { + target->type->add_watchpoint = dpmv8_add_watchpoint; + target->type->remove_watchpoint = dpmv8_remove_watchpoint; + } /* FIXME add vector catch support */ From 0f06d943366154963c6f5eb70f52e70f64fe5c71 Mon Sep 17 00:00:00 2001 From: Antonio Borneo Date: Sun, 20 Dec 2020 21:13:58 +0100 Subject: [PATCH 120/120] mem_ap: allow GDB connections The target mem_ap is a convenient way to access buses, memory and peripherals behind an ARM AP. The current implementation provides only access through OpenOCD commands, because GDB remote protocol has to interact with a CPU and has to operate on CPU states and registers. Using GDB to access the memory is welcome, because GDB can resolve the symbol's address from an ELF file and can nicely display the content of complex struct and data types. Extend mem_ap target with the bare minimal support for a remote GDB connection, by emulating a fake basic ARM core. It means that only a GDB that has support for ARM can be used (either 'aarch64', 'arm' or 'multiarch' GDB). This is not seen as a big limitation, because the mem_ap target is mainly used on ARM based devices. Add a minimalist register description for the fake CPU. Fill the field 'debug_reason' as expected by GDB server. Call the target halted event to reply to GDB halt requests. For backward compatibility, don't open the GDB port by default. If needed, it has to be specified at 'target create' or 'configure' with the flag '-gdb-port'. Change-Id: I5a1b7adb749746516f5d4ffc6193c47b70132364 Signed-off-by: Antonio Borneo Reviewed-on: http://openocd.zylin.com/6034 Tested-by: jenkins --- doc/openocd.texi | 8 +++- src/target/mem_ap.c | 93 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 4 deletions(-) diff --git a/doc/openocd.texi b/doc/openocd.texi index 2cba45ecd..6b74243b8 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -4509,7 +4509,13 @@ The current implementation supports eSi-32xx cores. @item @code{hla_target} -- a Cortex-M alternative to work with HL adapters like ST-Link. @item @code{ls1_sap} -- this is the SAP on NXP LS102x CPUs, allowing access to physical memory addresses independently of CPU cores. -@item @code{mem_ap} -- this is an ARM debug infrastructure Access Port without a CPU, through which bus read and write cycles can be generated; it may be useful for working with non-CPU hardware behind an AP or during development of support for new CPUs. +@item @code{mem_ap} -- this is an ARM debug infrastructure Access Port without +a CPU, through which bus read and write cycles can be generated; it may be +useful for working with non-CPU hardware behind an AP or during development of +support for new CPUs. +It's possible to connect a GDB client to this target (the GDB port has to be +specified, @xref{gdbportoverride,,option -gdb-port}), and a fake ARM core will +be emulated to comply to GDB remote protocol. @item @code{mips_m4k} -- a MIPS core. @item @code{mips_mips64} -- a MIPS64 core. @item @code{nds32_v2} -- this is an Andes NDS32 v2 core. diff --git a/src/target/mem_ap.c b/src/target/mem_ap.c index 7ed41c63c..89c0c02c0 100644 --- a/src/target/mem_ap.c +++ b/src/target/mem_ap.c @@ -20,6 +20,7 @@ #include "target_type.h" #include "arm.h" #include "arm_adi_v5.h" +#include "register.h" #include @@ -55,6 +56,9 @@ static int mem_ap_target_create(struct target *target, Jim_Interp *interp) target->arch_info = mem_ap; + if (!target->gdb_port_override) + target->gdb_port_override = strdup("disabled"); + return ERROR_OK; } @@ -62,6 +66,7 @@ static int mem_ap_init_target(struct command_context *cmd_ctx, struct target *ta { LOG_DEBUG("%s", __func__); target->state = TARGET_UNKNOWN; + target->debug_reason = DBG_REASON_UNDEFINED; return ERROR_OK; } @@ -82,8 +87,10 @@ static int mem_ap_arch_state(struct target *target) static int mem_ap_poll(struct target *target) { - if (target->state == TARGET_UNKNOWN) + if (target->state == TARGET_UNKNOWN) { target->state = TARGET_RUNNING; + target->debug_reason = DBG_REASON_NOTHALTED; + } return ERROR_OK; } @@ -92,6 +99,8 @@ static int mem_ap_halt(struct target *target) { LOG_DEBUG("%s", __func__); target->state = TARGET_HALTED; + target->debug_reason = DBG_REASON_DBGRQ; + target_call_event_callbacks(target, TARGET_EVENT_HALTED); return ERROR_OK; } @@ -100,6 +109,7 @@ static int mem_ap_resume(struct target *target, int current, target_addr_t addre { LOG_DEBUG("%s", __func__); target->state = TARGET_RUNNING; + target->debug_reason = DBG_REASON_NOTHALTED; return ERROR_OK; } @@ -108,12 +118,15 @@ static int mem_ap_step(struct target *target, int current, target_addr_t address { LOG_DEBUG("%s", __func__); target->state = TARGET_HALTED; + target->debug_reason = DBG_REASON_DBGRQ; + target_call_event_callbacks(target, TARGET_EVENT_HALTED); return ERROR_OK; } static int mem_ap_assert_reset(struct target *target) { target->state = TARGET_RESET; + target->debug_reason = DBG_REASON_UNDEFINED; LOG_DEBUG("%s", __func__); return ERROR_OK; @@ -127,6 +140,7 @@ static int mem_ap_examine(struct target *target) mem_ap->ap = dap_ap(mem_ap->arm.dap, mem_ap->ap_num); target_set_examined(target); target->state = TARGET_UNKNOWN; + target->debug_reason = DBG_REASON_UNDEFINED; return mem_ap_init(mem_ap->ap); } @@ -135,15 +149,85 @@ static int mem_ap_examine(struct target *target) static int mem_ap_deassert_reset(struct target *target) { - if (target->reset_halt) + if (target->reset_halt) { target->state = TARGET_HALTED; - else + target->debug_reason = DBG_REASON_DBGRQ; + target_call_event_callbacks(target, TARGET_EVENT_HALTED); + } else { target->state = TARGET_RUNNING; + target->debug_reason = DBG_REASON_NOTHALTED; + } LOG_DEBUG("%s", __func__); return ERROR_OK; } +static int mem_ap_reg_get(struct reg *reg) +{ + return ERROR_OK; +} + +static int mem_ap_reg_set(struct reg *reg, uint8_t *buf) +{ + return ERROR_OK; +} + +static struct reg_arch_type mem_ap_reg_arch_type = { + .get = mem_ap_reg_get, + .set = mem_ap_reg_set, +}; + +const char *mem_ap_get_gdb_arch(struct target *target) +{ + return "arm"; +} + +/* + * Dummy ARM register emulation: + * reg[0..15]: 32 bits, r0~r12, sp, lr, pc + * reg[16..23]: 96 bits, f0~f7 + * reg[24]: 32 bits, fps + * reg[25]: 32 bits, cpsr + * + * Set 'exist' only to reg[0..15], so initial response to GDB is correct + */ +#define NUM_REGS 26 +#define MAX_REG_SIZE 96 +#define REG_EXIST(n) ((n) < 16) +#define REG_SIZE(n) ((((n) >= 16) && ((n) < 24)) ? 96 : 32) + +struct mem_ap_alloc_reg_list { + /* reg_list must be the first field */ + struct reg *reg_list[NUM_REGS]; + struct reg regs[NUM_REGS]; + uint8_t regs_value[MAX_REG_SIZE / 8]; +}; + +static int mem_ap_get_gdb_reg_list(struct target *target, struct reg **reg_list[], + int *reg_list_size, enum target_register_class reg_class) +{ + struct mem_ap_alloc_reg_list *mem_ap_alloc = calloc(1, sizeof(struct mem_ap_alloc_reg_list)); + if (!mem_ap_alloc) { + LOG_ERROR("Out of memory"); + return ERROR_FAIL; + } + + *reg_list = mem_ap_alloc->reg_list; + *reg_list_size = NUM_REGS; + struct reg *regs = mem_ap_alloc->regs; + + for (int i = 0; i < NUM_REGS; i++) { + regs[i].number = i; + regs[i].value = mem_ap_alloc->regs_value; + regs[i].size = REG_SIZE(i); + regs[i].exist = REG_EXIST(i); + regs[i].type = &mem_ap_reg_arch_type; + (*reg_list)[i] = ®s[i]; + } + + return ERROR_OK; +} + static int mem_ap_read_memory(struct target *target, target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer) { @@ -192,6 +276,9 @@ struct target_type mem_ap_target = { .assert_reset = mem_ap_assert_reset, .deassert_reset = mem_ap_deassert_reset, + .get_gdb_arch = mem_ap_get_gdb_arch, + .get_gdb_reg_list = mem_ap_get_gdb_reg_list, + .read_memory = mem_ap_read_memory, .write_memory = mem_ap_write_memory, };