diff options
194 files changed, 3439 insertions, 4565 deletions
@@ -103,7 +103,7 @@ patch: Now every time OpenOCD is run, coverage info in your build directory is updated. Running `gcov src/path/file.c` will generate a report. -Please consider performing these additonal checks where appropriate +Please consider performing these additional checks where appropriate (especially Clang Static Analyzer for big portions of new code) and mention the results (e.g. "Valgrind-clean, no new Clang analyzer warnings") in the commit message. @@ -174,7 +174,7 @@ wget http://openocd.zylin.com/tools/hooks/commit-msg mv commit-msg .git/hooks chmod +x .git/hooks/commit-msg @endcode - \note A script exists to simplify the two items above. execute: + \note A script exists to simplify the two items above. Execute: @code tools/initial.sh <username> @endcode @@ -186,7 +186,7 @@ git config --global user.email "john@smith.org" @endcode -# Work on your patches. Split the work into multiple small patches that can be reviewed and - applied seperately and safely to the OpenOCD + applied separately and safely to the OpenOCD repository. @code while(!done) { @@ -365,7 +365,6 @@ to complete: - committing to git - Review Users' Guide for documentation errors or omissions - "capture" and "ocd_find" commands - - "ocd_" prefix on various stuff - Update Developer's Manual (doxygen output) - Add documentation describing the architecture of each module - Provide more Technical Primers to bootstrap contributor knowledge diff --git a/configure.ac b/configure.ac index ab05cc6..c151e1f 100644 --- a/configure.ac +++ b/configure.ac @@ -111,7 +111,7 @@ m4_define([ADAPTER_OPT], [m4_translit(ADAPTER_ARG($1), [_], [-])]) m4_define([USB1_ADAPTERS], [[[ftdi], [MPSSE mode of FTDI based devices], [FTDI]], [[ftdi_oscan1], [cJTAG OSCAN1 tunneled thru MPSSE], [FTDI_OSCAN1]], - [[stlink], [ST-Link JTAG Programmer], [HLADAPTER_STLINK]], + [[stlink], [ST-Link Programmer], [HLADAPTER_STLINK]], [[ti_icdi], [TI ICDI JTAG Programmer], [HLADAPTER_ICDI]], [[ulink], [Keil ULINK JTAG Programmer], [ULINK]], [[usb_blaster_2], [Altera USB-Blaster II Compatible], [USB_BLASTER_2]], @@ -173,7 +173,6 @@ AC_ARG_ENABLE([werror], [gcc_werror=$enableval], [gcc_werror=$gcc_warnings]) # set default verbose options, overridden by following options -debug_jtag_io=no debug_usb_io=no debug_usb_comms=no @@ -181,16 +180,10 @@ AC_ARG_ENABLE([verbose], AS_HELP_STRING([--enable-verbose], [Enable verbose JTAG I/O messages (for debugging).]), [ - debug_jtag_io=$enableval debug_usb_io=$enableval debug_usb_comms=$enableval ], []) -AC_ARG_ENABLE([verbose_jtag_io], - AS_HELP_STRING([--enable-verbose-jtag-io], - [Enable verbose JTAG I/O messages (for debugging).]), - [debug_jtag_io=$enableval], []) - AC_ARG_ENABLE([verbose_usb_io], AS_HELP_STRING([--enable-verbose-usb-io], [Enable verbose USB I/O messages (for debugging)]), @@ -201,12 +194,6 @@ AC_ARG_ENABLE([verbose_usb_comms], [Enable verbose USB communication messages (for debugging)]), [debug_usb_comms=$enableval], []) -AC_MSG_CHECKING([whether to enable verbose JTAG I/O messages]); -AC_MSG_RESULT([$debug_jtag_io]) -AS_IF([test "x$debug_jtag_io" = "xyes"], [ - AC_DEFINE([_DEBUG_JTAG_IO_],[1], [Print verbose JTAG I/O messages]) -]) - AC_MSG_CHECKING([whether to enable verbose USB I/O messages]); AC_MSG_RESULT([$debug_usb_io]) AS_IF([test "x$debug_usb_io" = "xyes"], [ @@ -776,7 +763,7 @@ AS_IF([test "x${gcc_werror}" = "xyes"], [ GCC_WARNINGS="${GCC_WARNINGS} -Werror" ]) -# overide default gcc cflags +# override default gcc cflags AS_IF([test "x$gcc_warnings" = "xyes"], [ AC_SUBST([GCC_WARNINGS], [$GCC_WARNINGS]) ]) diff --git a/contrib/loaders/flash/stm32/stm32h7x.S b/contrib/loaders/flash/stm32/stm32h7x.S index f910bfb..f0d3295 100644 --- a/contrib/loaders/flash/stm32/stm32h7x.S +++ b/contrib/loaders/flash/stm32/stm32h7x.S @@ -48,8 +48,8 @@ #define STM32_FLASH_CR_OFFSET 0x0C /* offset of CR register in FLASH struct */ #define STM32_FLASH_SR_OFFSET 0x10 /* offset of SR register in FLASH struct */ #define STM32_CR_PROG 0x00000032 /* PSIZE64 | PG */ -#define STM32_SR_BUSY_MASK 0x00000001 /* BSY */ -#define STM32_SR_ERROR_MASK 0x03ee0000 /* DBECCERR | SNECCERR | RDSERR | RDPERR | OPERR +#define STM32_SR_QW_MASK 0x00000004 /* QW */ +#define STM32_SR_ERROR_MASK 0x07ee0000 /* DBECCERR | SNECCERR | RDSERR | RDPERR | OPERR | INCERR | STRBERR | PGSERR | WRPERR */ .thumb_func @@ -73,6 +73,7 @@ wait_fifo: mov r7, #8 /* program by 8 words = 32 bytes */ write_flash: + dsb ldr r6, [r5], #0x04 /* read one word from src, increment ptr */ str r6, [r2], #0x04 /* write one word to dst, increment ptr */ dsb @@ -84,7 +85,7 @@ write_flash: busy: ldr r6, [r4, #STM32_FLASH_SR_OFFSET] - tst r6, #STM32_SR_BUSY_MASK + tst r6, #STM32_SR_QW_MASK bne busy /* operation in progress, wait ... */ ldr r7, =STM32_SR_ERROR_MASK diff --git a/contrib/loaders/flash/stm32/stm32h7x.inc b/contrib/loaders/flash/stm32/stm32h7x.inc index 174354c..ec14de0 100644 --- a/contrib/loaders/flash/stm32/stm32h7x.inc +++ b/contrib/loaders/flash/stm32/stm32h7x.inc @@ -1,7 +1,7 @@ /* Autogenerated with ../../../../src/helper/bin2char.sh */ -0x45,0x68,0x06,0x68,0x26,0xb3,0x76,0x1b,0x42,0xbf,0x76,0x18,0x36,0x1a,0x08,0x3e, -0x20,0x2e,0xf6,0xd3,0x4f,0xf0,0x32,0x06,0xe6,0x60,0x4f,0xf0,0x08,0x07,0x55,0xf8, -0x04,0x6b,0x42,0xf8,0x04,0x6b,0xbf,0xf3,0x4f,0x8f,0x8d,0x42,0x28,0xbf,0x00,0xf1, -0x08,0x05,0x01,0x3f,0xf3,0xd1,0x26,0x69,0x16,0xf0,0x01,0x0f,0xfb,0xd1,0x05,0x4f, -0x3e,0x42,0x03,0xd1,0x45,0x60,0x01,0x3b,0xdb,0xd1,0x01,0xe0,0x00,0x27,0x47,0x60, -0x30,0x46,0x00,0xbe,0x00,0x00,0xee,0x03, +0x45,0x68,0x06,0x68,0x36,0xb3,0x76,0x1b,0x42,0xbf,0x76,0x18,0x36,0x1a,0x08,0x3e, +0x20,0x2e,0xf6,0xd3,0x4f,0xf0,0x32,0x06,0xe6,0x60,0x4f,0xf0,0x08,0x07,0xbf,0xf3, +0x4f,0x8f,0x55,0xf8,0x04,0x6b,0x42,0xf8,0x04,0x6b,0xbf,0xf3,0x4f,0x8f,0x8d,0x42, +0x28,0xbf,0x00,0xf1,0x08,0x05,0x01,0x3f,0xf1,0xd1,0x26,0x69,0x16,0xf0,0x04,0x0f, +0xfb,0xd1,0x05,0x4f,0x3e,0x42,0x03,0xd1,0x45,0x60,0x01,0x3b,0xd9,0xd1,0x01,0xe0, +0x00,0x27,0x47,0x60,0x30,0x46,0x00,0xbe,0x00,0x00,0xee,0x07, diff --git a/contrib/rpc_examples/ocd_rpc_example.py b/contrib/rpc_examples/ocd_rpc_example.py index 6c8529c..4b1516a 100755 --- a/contrib/rpc_examples/ocd_rpc_example.py +++ b/contrib/rpc_examples/ocd_rpc_example.py @@ -85,16 +85,17 @@ class OpenOcd: return data def readVariable(self, address): - raw = self.send("ocd_mdw 0x%x" % address).split(": ") + raw = self.send("mdw 0x%x" % address).split(": ") return None if (len(raw) < 2) else strToHex(raw[1]) def readMemory(self, wordLen, address, n): self.send("array unset output") # better to clear the array before self.send("mem2array output %d 0x%x %d" % (wordLen, address, n)) - output = self.send("ocd_echo $output").split(" ") + output = [*map(int, self.send("return $output").split(" "))] + d = dict([tuple(output[i:i + 2]) for i in range(0, len(output), 2)]) - return [int(output[2*i+1]) for i in range(len(output)//2)] + return [d[k] for k in sorted(d.keys())] def writeVariable(self, address, value): assert value is not None @@ -115,8 +116,8 @@ if __name__ == "__main__": with OpenOcd() as ocd: ocd.send("reset") - show(ocd.send("ocd_echo \"echo says hi!\"")[:-1]) - show(ocd.send("capture \"ocd_halt\"")[:-1]) + show(ocd.send("capture { echo \"echo says hi!\" }")[:-1]) + show(ocd.send("capture \"halt\"")[:-1]) # Read the first few words at the RAM region (put starting adress of RAM # region into 'addr') diff --git a/contrib/rpc_examples/ocdrpc.hs b/contrib/rpc_examples/ocdrpc.hs index 27fb1ae..9a80cdd 100644 --- a/contrib/rpc_examples/ocdrpc.hs +++ b/contrib/rpc_examples/ocdrpc.hs @@ -39,7 +39,7 @@ mdwParser = (manyTill anyChar (string ": ") *> ocdMdw :: (InputStream ByteString, OutputStream ByteString) -> Integer -> Integer -> IO [Integer] ocdMdw s start count = do - s <- ocdExec s $ "ocd_mdw " ++ show start ++ " " ++ show count + s <- ocdExec s $ "mdw " ++ show start ++ " " ++ show count case parseOnly mdwParser (pack s) of Right r -> return $ concat r diff --git a/doc/manual/primer/commands.txt b/doc/manual/primer/commands.txt index a626f56..8ea2282 100644 --- a/doc/manual/primer/commands.txt +++ b/doc/manual/primer/commands.txt @@ -16,7 +16,7 @@ COMMAND_HANDLER(handle_hello_command) const char *sep, *name; int retval = CALL_COMMAND_HANDLER(handle_hello_args); if (ERROR_OK == retval) - command_print(CMD_CTX, "Greetings%s%s!", sep, name); + command_print(CMD, "Greetings%s%s!", sep, name); return retval; } @endcode diff --git a/doc/openocd.texi b/doc/openocd.texi index 7337686..9aeeb1c 100644 --- a/doc/openocd.texi +++ b/doc/openocd.texi @@ -2370,8 +2370,8 @@ Returns the name of the debug adapter driver being used. @end deffn @anchor{adapter_usb_location} -@deffn Command {adapter usb location} <bus>-<port>[.<port>]... -Specifies the physical USB port of the adapter to use. The path +@deffn Command {adapter usb location} [<bus>-<port>[.<port>]...] +Displays or specifies the physical USB port of the adapter to use. The path roots at @var{bus} and walks down the physical ports, with each @var{port} option specifying a deeper level in the bus topology, the last @var{port} denoting where the target adapter is actually plugged. @@ -2514,7 +2514,7 @@ and are not restricted to containing only decimal digits.) @deffn {Config Command} {ftdi_location} <bus>-<port>[.<port>]... @emph{DEPRECATED -- avoid using this. -Use the @xref{adapter_usb_location, adapter usb location} command instead.} +Use the command @ref{adapter_usb_location,,adapter usb location} instead.} Specifies the physical USB port of the adapter to use. The path roots at @var{bus} and walks down the physical ports, with each @@ -3895,10 +3895,14 @@ devices do not set the ack bit until sometime later. @section Other TAP commands +@deffn Command {jtag cget} dotted.name @option{-idcode} +Get the value of the IDCODE found in hardware. +@end deffn + @deffn Command {jtag cget} dotted.name @option{-event} event_name @deffnx Command {jtag configure} dotted.name @option{-event} event_name handler At this writing this TAP attribute -mechanism is used only for event handling. +mechanism is limited and used mostly for event handling. (It is not a direct analogue of the @code{cget}/@code{configure} mechanism for debugger targets.) See the next section for information about the available events. @@ -4367,6 +4371,7 @@ compact Thumb2 instruction set. The current implementation supports eSi-32xx cores. @item @code{fa526} -- resembles arm920 (w/o Thumb) @item @code{feroceon} -- resembles arm926 +@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{mips_m4k} -- a MIPS core @item @code{xscale} -- this is actually an architecture, not a CPU type. It is based on the ARMv5 architecture. @@ -4375,14 +4380,14 @@ The current implementation supports three JTAG TAP cores: @item @code{ls1_sap} -- this is the SAP on NXP LS102x CPUs, allowing access to physical memory addresses independently of CPU cores. @itemize @minus -@item @code{OpenCores TAP} (See: @url{http://opencores.org/project,jtag}) +@item @code{OpenCores TAP} (See: @url{http://opencores.org/project@comma{}jtag}) @item @code{Altera Virtual JTAG TAP} (See: @url{http://www.altera.com/literature/ug/ug_virtualjtag.pdf}) @item @code{Xilinx BSCAN_* virtual JTAG interface} (See: @url{http://www.xilinx.com/support/documentation/sw_manuals/xilinx14_2/spartan6_hdl.pdf}) @end itemize And two debug interfaces cores: @itemize @minus -@item @code{Advanced debug interface} (See: @url{http://opencores.org/project,adv_debug_sys}) -@item @code{SoC Debug Interface} (See: @url{http://opencores.org/project,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 @end itemize @end deffn @@ -4683,23 +4688,35 @@ Invokes the handler for the event named @var{event_name}. code, for example by the reset code in @file{startup.tcl}.) @end deffn -@deffn Command {$target_name mdw} addr [count] -@deffnx Command {$target_name mdh} addr [count] -@deffnx Command {$target_name mdb} addr [count] +@deffn Command {$target_name mdd} [phys] addr [count] +@deffnx Command {$target_name mdw} [phys] addr [count] +@deffnx Command {$target_name mdh} [phys] addr [count] +@deffnx Command {$target_name mdb} [phys] addr [count] Display contents of address @var{addr}, as +64-bit doublewords (@command{mdd}), 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}), or 8-bit bytes (@command{mdb}). +When the current target has an MMU which is present and active, +@var{addr} is interpreted as a virtual address. +Otherwise, or if the optional @var{phys} flag is specified, +@var{addr} is interpreted as a physical address. If @var{count} is specified, displays that many units. (If you want to manipulate the data instead of displaying it, see the @code{mem2array} primitives.) @end deffn -@deffn Command {$target_name mww} addr word -@deffnx Command {$target_name mwh} addr halfword -@deffnx Command {$target_name mwb} addr byte -Writes the specified @var{word} (32 bits), -@var{halfword} (16 bits), or @var{byte} (8-bit) pattern, +@deffn Command {$target_name mwd} [phys] addr doubleword [count] +@deffnx Command {$target_name mww} [phys] addr word [count] +@deffnx Command {$target_name mwh} [phys] addr halfword [count] +@deffnx Command {$target_name mwb} [phys] addr byte [count] +Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits), +@var{halfword} (16 bits), or @var{byte} (8-bit) value, at the specified address @var{addr}. +When the current target has an MMU which is present and active, +@var{addr} is interpreted as a virtual address. +Otherwise, or if the optional @var{phys} flag is specified, +@var{addr} is interpreted as a physical address. +If @var{count} is specified, fills that many units of consecutive address. @end deffn @anchor{targetevents} @@ -4909,7 +4926,6 @@ Use it in board specific configuration files, not interactively. @end quotation @end deffn -@comment the REAL name for this command is "ocd_flash_banks" @comment less confusing would be: "flash list" (like "nand list") @deffn Command {flash banks} Prints a one-line summary of each device that was @@ -6986,6 +7002,23 @@ unlock str9 device. @end deffn +@deffn {Flash Driver} swm050 +@cindex swm050 +All members of the swm050 microcontroller family from Foshan Synwit Tech. + +@example +flash bank $_FLASHNAME swm050 0x0 0x2000 0 0 $_TARGETNAME +@end example + +One swm050-specific command is defined: + +@deffn Command {swm050 mass_erase} bank_id +Erases the entire flash bank. +@end deffn + +@end deffn + + @deffn {Flash Driver} tms470 Most members of the TMS470 microcontroller family from Texas Instruments include internal flash and use ARM7TDMI cores. @@ -7466,67 +7499,6 @@ or @code{read_page} methods, so @command{nand raw_access} won't change any behavior. @end deffn -@section mFlash - -@subsection mFlash Configuration -@cindex mFlash Configuration - -@deffn {Config Command} {mflash bank} soc base RST_pin target -Configures a mflash for @var{soc} host bank at -address @var{base}. -The pin number format depends on the host GPIO naming convention. -Currently, the mflash driver supports s3c2440 and pxa270. - -Example for s3c2440 mflash where @var{RST pin} is GPIO B1: - -@example -mflash bank $_FLASHNAME s3c2440 0x10000000 1b 0 -@end example - -Example for pxa270 mflash where @var{RST pin} is GPIO 43: - -@example -mflash bank $_FLASHNAME pxa270 0x08000000 43 0 -@end example -@end deffn - -@subsection mFlash commands -@cindex mFlash commands - -@deffn Command {mflash config pll} frequency -Configure mflash PLL. -The @var{frequency} is the mflash input frequency, in Hz. -Issuing this command will erase mflash's whole internal nand and write new pll. -After this command, mflash needs power-on-reset for normal operation. -If pll was newly configured, storage and boot(optional) info also need to be update. -@end deffn - -@deffn Command {mflash config boot} -Configure bootable option. -If bootable option is set, mflash offer the first 8 sectors -(4kB) for boot. -@end deffn - -@deffn Command {mflash config storage} -Configure storage information. -For the normal storage operation, this information must be -written. -@end deffn - -@deffn Command {mflash dump} num filename offset size -Dump @var{size} bytes, starting at @var{offset} bytes from the -beginning of the bank @var{num}, to the file named @var{filename}. -@end deffn - -@deffn Command {mflash probe} -Probe mflash. -@end deffn - -@deffn Command {mflash write} num filename offset -Write the binary file @var{filename} to mflash bank @var{num}, starting at -@var{offset} bytes from the beginning of the bank. -@end deffn - @node Flash Programming @chapter Flash Programming @@ -7940,10 +7912,12 @@ Please use their TARGET object siblings to avoid making assumptions about what TAP is the current target, or about MMU configuration. @end enumerate -@deffn Command mdw [phys] addr [count] +@deffn Command mdd [phys] addr [count] +@deffnx Command mdw [phys] addr [count] @deffnx Command mdh [phys] addr [count] @deffnx Command mdb [phys] addr [count] Display contents of address @var{addr}, as +64-bit doublewords (@command{mdd}), 32-bit words (@command{mdw}), 16-bit halfwords (@command{mdh}), or 8-bit bytes (@command{mdb}). When the current target has an MMU which is present and active, @@ -7955,16 +7929,18 @@ If @var{count} is specified, displays that many units. see the @code{mem2array} primitives.) @end deffn -@deffn Command mww [phys] addr word -@deffnx Command mwh [phys] addr halfword -@deffnx Command mwb [phys] addr byte -Writes the specified @var{word} (32 bits), +@deffn Command mwd [phys] addr doubleword [count] +@deffnx Command mww [phys] addr word [count] +@deffnx Command mwh [phys] addr halfword [count] +@deffnx Command mwb [phys] addr byte [count] +Writes the specified @var{doubleword} (64 bits), @var{word} (32 bits), @var{halfword} (16 bits), or @var{byte} (8-bit) value, at the specified address @var{addr}. When the current target has an MMU which is present and active, @var{addr} is interpreted as a virtual address. Otherwise, or if the optional @var{phys} flag is specified, @var{addr} is interpreted as a physical address. +If @var{count} is specified, fills that many units of consecutive address. @end deffn @anchor{imageaccess} @@ -9073,7 +9049,7 @@ Enable or disable trace output for all ITM stimulus ports. @subsection Cortex-M specific commands @cindex Cortex-M -@deffn Command {cortex_m maskisr} (@option{auto}|@option{on}|@option{off}) +@deffn Command {cortex_m maskisr} (@option{auto}|@option{on}|@option{off}|@option{steponly}) Control masking (disabling) interrupts during target step/resume. The @option{auto} option handles interrupts during stepping in a way that they @@ -9083,6 +9059,11 @@ the next instruction where the core was halted. After the step interrupts are enabled again. If the interrupt handlers don't complete within 500ms, the step command leaves with the core running. +The @option{steponly} option disables interrupts during single-stepping but +enables them during normal execution. This can be used as a partial workaround +for 702596 erratum in Cortex-M7 r0p1. See "Cortex-M7 (AT610) and Cortex-M7 with +FPU (AT611) Software Developer Errata Notice" from ARM for further details. + Note that a free hardware (FPB) breakpoint is required for the @option{auto} option. If no breakpoint is available at the time of the step, then the step is taken with interrupts enabled, i.e. the same way the @option{off} option @@ -9165,6 +9146,14 @@ Selects whether interrupts will be processed when single stepping. The default c @option{on}. @end deffn +@deffn Command {$target_name catch_exc} [@option{off}|@option{sec_el1}|@option{sec_el3}|@option{nsec_el1}|@option{nsec_el2}]+ +Cause @command{$target_name} to halt when an exception is taken. Any combination of +Secure (sec) EL1/EL3 or Non-Secure (nsec) EL1/EL2 is valid. The target +@command{$target_name} will halt before taking the exception. In order to resume +the target, the exception catch must be disabled again with @command{$target_name catch_exc off}. +Issuing the command without options prints the current configuration. +@end deffn + @section EnSilica eSi-RISC Architecture eSi-RISC is a highly configurable microprocessor architecture for embedded systems @@ -9308,7 +9297,7 @@ collection. @deffn Command {esirisc trace init} Initialize trace collection. This command must be called any time the -configuration changes. If an trace buffer has been configured, the contents will +configuration changes. If a trace buffer has been configured, the contents will be overwritten when trace collection starts. @end deffn @@ -9342,14 +9331,6 @@ be copied to an in-memory buffer identified by the @option{address} and @option{size} options using DMA. @end deffn -@deffn Command {$target_name catch_exc} [@option{off}|@option{sec_el1}|@option{sec_el3}|@option{nsec_el1}|@option{nsec_el2}]+ -Cause @command{$target_name} to halt when an exception is taken. Any combination of -Secure (sec) EL1/EL3 or Non-Secure (nsec) EL1/EL2 is valid. The target -@command{$target_name} will halt before taking the exception. In order to resume -the target, the exception catch must be disabled again with @command{$target_name catch_exc off}. -Issuing the command without options prints the current configuration. -@end deffn - @section Intel Architecture Intel Quark X10xx is the first product in the Quark family of SoCs. It is an IA-32 @@ -9530,13 +9511,12 @@ The following commands can be used to authenticate to a RISC-V system. Eg. a trivial challenge-response protocol could be implemented as follows in a configuration file, immediately following @command{init}: @example -set challenge [ocd_riscv authdata_read] +set challenge [riscv authdata_read] riscv authdata_write [expr $challenge + 1] @end example @deffn Command {riscv authdata_read} -Return the 32-bit value read from authdata. Note that to get read value back in -a TCL script, it needs to be invoked as @command{ocd_riscv authdata_read}. +Return the 32-bit value read from authdata. @end deffn @deffn Command {riscv authdata_write} value @@ -9549,9 +9529,7 @@ The following commands allow direct access to the Debug Module Interface, which can be used to interact with custom debug features. @deffn Command {riscv dmi_read} -Perform a 32-bit DMI read at address, returning the value. Note that to get -read value back in a TCL script, it needs to be invoked as @command{ocd_riscv -dmi_read}. +Perform a 32-bit DMI read at address, returning the value. @end deffn @deffn Command {riscv dmi_write} address value @@ -10435,10 +10413,6 @@ should be passed in to the proc in question. By "low-level," we mean commands that a human would typically not invoke directly. -Some low-level commands need to be prefixed with "ocd_"; e.g. -@command{ocd_flash_banks} -is the low-level API upon which @command{flash banks} is implemented. - @itemize @bullet @item @b{mem2array} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}> @@ -10446,7 +10420,7 @@ Read memory and return as a Tcl array for script processing @item @b{array2mem} <@var{varname}> <@var{width}> <@var{addr}> <@var{nelems}> Convert a Tcl array to memory locations and write the values -@item @b{ocd_flash_banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...] +@item @b{flash banks} <@var{driver}> <@var{base}> <@var{size}> <@var{chip_width}> <@var{bus_width}> <@var{target}> [@option{driver options} ...] Return information about the flash banks @@ -10505,8 +10479,8 @@ interpreter terminating it with @code{0x1a} and wait for the return value (it will be terminated with @code{0x1a} as well). This can be repeated as many times as desired without reopening the connection. -Remember that most of the OpenOCD commands need to be prefixed with -@code{ocd_} to get the results back. Sometimes you might also need the +It is not needed anymore to prefix the OpenOCD commands with +@code{ocd_} to get the results back. But sometimes you might need the @command{capture} command. See @file{contrib/rpc_examples/} for specific client implementations. diff --git a/guess-rev.sh b/guess-rev.sh index 7adbe28..efe2659 100755 --- a/guess-rev.sh +++ b/guess-rev.sh @@ -79,5 +79,5 @@ if rev=`svn info 2>/dev/null | grep '^Last Changed Rev'`; then exit fi -# There's no reecognized repository; we must be a snapshot. +# There's no recognized repository; we must be a snapshot. printf -- '-snapshot' diff --git a/src/flash/Makefile.am b/src/flash/Makefile.am index a1b46f8..4c70702 100644 --- a/src/flash/Makefile.am +++ b/src/flash/Makefile.am @@ -1,7 +1,6 @@ noinst_LTLIBRARIES += %D%/libflash.la %C%_libflash_la_SOURCES = \ - %D%/common.c %D%/common.h \ - %D%/mflash.c %D%/mflash.h + %D%/common.c %D%/common.h %C%_libflash_la_LIBADD = \ %D%/nor/libocdflashnor.la \ diff --git a/src/flash/mflash.c b/src/flash/mflash.c deleted file mode 100644 index 4c95d21..0000000 --- a/src/flash/mflash.c +++ /dev/null @@ -1,1449 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by unsik Kim <donari75@gmail.com> * - * * - * 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 <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "mflash.h" -#include <target/target.h> -#include <helper/time_support.h> -#include <helper/fileio.h> -#include <helper/log.h> - -static int s3c2440_set_gpio_to_output(struct mflash_gpio_num gpio); -static int s3c2440_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val); -static int pxa270_set_gpio_to_output(struct mflash_gpio_num gpio); -static int pxa270_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val); - -static struct mflash_bank *mflash_bank; - -static struct mflash_gpio_drv pxa270_gpio = { - .name = "pxa270", - .set_gpio_to_output = pxa270_set_gpio_to_output, - .set_gpio_output_val = pxa270_set_gpio_output_val -}; - -static struct mflash_gpio_drv s3c2440_gpio = { - .name = "s3c2440", - .set_gpio_to_output = s3c2440_set_gpio_to_output, - .set_gpio_output_val = s3c2440_set_gpio_output_val -}; - -static struct mflash_gpio_drv *mflash_gpio[] = { - &pxa270_gpio, - &s3c2440_gpio, - NULL -}; - -#define PXA270_GAFR0_L 0x40E00054 -#define PXA270_GAFR3_U 0x40E00070 -#define PXA270_GAFR3_U_RESERVED_BITS 0xfffc0000u -#define PXA270_GPDR0 0x40E0000C -#define PXA270_GPDR3 0x40E0010C -#define PXA270_GPDR3_RESERVED_BITS 0xfe000000u -#define PXA270_GPSR0 0x40E00018 -#define PXA270_GPCR0 0x40E00024 - -static int pxa270_set_gpio_to_output(struct mflash_gpio_num gpio) -{ - uint32_t addr, value, mask; - struct target *target = mflash_bank->target; - int ret; - - /* remove alternate function. */ - mask = 0x3u << (gpio.num & 0xF)*2; - - addr = PXA270_GAFR0_L + (gpio.num >> 4) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value &= ~mask; - if (addr == PXA270_GAFR3_U) - value &= ~PXA270_GAFR3_U_RESERVED_BITS; - - ret = target_write_u32(target, addr, value); - if (ret != ERROR_OK) - return ret; - - /* set direction to output */ - mask = 0x1u << (gpio.num & 0x1F); - - addr = PXA270_GPDR0 + (gpio.num >> 5) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value |= mask; - if (addr == PXA270_GPDR3) - value &= ~PXA270_GPDR3_RESERVED_BITS; - - ret = target_write_u32(target, addr, value); - return ret; -} - -static int pxa270_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val) -{ - uint32_t addr, value, mask; - struct target *target = mflash_bank->target; - int ret; - - mask = 0x1u << (gpio.num & 0x1F); - - if (val) - addr = PXA270_GPSR0 + (gpio.num >> 5) * 4; - else - addr = PXA270_GPCR0 + (gpio.num >> 5) * 4; - - ret = target_read_u32(target, addr, &value); - if (ret != ERROR_OK) - return ret; - - value |= mask; - - ret = target_write_u32(target, addr, value); - - return ret; -} - -#define S3C2440_GPACON 0x56000000 -#define S3C2440_GPADAT 0x56000004 -#define S3C2440_GPJCON 0x560000d0 -#define S3C2440_GPJDAT 0x560000d4 - -static int s3c2440_set_gpio_to_output(struct mflash_gpio_num gpio) -{ - uint32_t data, mask, gpio_con; - struct target *target = mflash_bank->target; - int ret; - - if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') - gpio_con = S3C2440_GPACON + (gpio.port[0] - 'a') * 0x10; - else if (gpio.port[0] == 'j') - gpio_con = S3C2440_GPJCON; - else { - LOG_ERROR("mflash: invalid port %d%s", gpio.num, gpio.port); - return ERROR_COMMAND_SYNTAX_ERROR; - } - - ret = target_read_u32(target, gpio_con, &data); - - if (ret == ERROR_OK) { - if (gpio.port[0] == 'a') { - mask = 1 << gpio.num; - data &= ~mask; - } else { - mask = 3 << gpio.num * 2; - data &= ~mask; - data |= (1 << gpio.num * 2); - } - - ret = target_write_u32(target, gpio_con, data); - } - return ret; -} - -static int s3c2440_set_gpio_output_val(struct mflash_gpio_num gpio, uint8_t val) -{ - uint32_t data, mask, gpio_dat; - struct target *target = mflash_bank->target; - int ret; - - if (gpio.port[0] >= 'a' && gpio.port[0] <= 'h') - gpio_dat = S3C2440_GPADAT + (gpio.port[0] - 'a') * 0x10; - else if (gpio.port[0] == 'j') - gpio_dat = S3C2440_GPJDAT; - else { - LOG_ERROR("mflash: invalid port %d%s", gpio.num, gpio.port); - return ERROR_COMMAND_SYNTAX_ERROR; - } - - ret = target_read_u32(target, gpio_dat, &data); - - if (ret == ERROR_OK) { - mask = 1 << gpio.num; - if (val) - data |= mask; - else - data &= ~mask; - - ret = target_write_u32(target, gpio_dat, data); - } - return ret; -} - -static int mg_hdrst(uint8_t level) -{ - return mflash_bank->gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, level); -} - -static int mg_init_gpio(void) -{ - int ret; - struct mflash_gpio_drv *gpio_drv = mflash_bank->gpio_drv; - - ret = gpio_drv->set_gpio_to_output(mflash_bank->rst_pin); - if (ret != ERROR_OK) - return ret; - - ret = gpio_drv->set_gpio_output_val(mflash_bank->rst_pin, 1); - - return ret; -} - -static int mg_dsk_wait(mg_io_type_wait wait_local, uint32_t time_var) -{ - uint8_t status, error; - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - int ret; - long long t = 0; - - struct duration bench; - duration_start(&bench); - - while (time_var) { - - ret = target_read_u8(target, mg_task_reg + MG_REG_STATUS, &status); - if (ret != ERROR_OK) - return ret; - - if (status & mg_io_rbit_status_busy) { - if (wait_local == mg_io_wait_bsy) - return ERROR_OK; - } else { - switch (wait_local) { - case mg_io_wait_not_bsy: - return ERROR_OK; - case mg_io_wait_rdy_noerr: - if (status & mg_io_rbit_status_ready) - return ERROR_OK; - break; - case mg_io_wait_drq_noerr: - if (status & mg_io_rbit_status_data_req) - return ERROR_OK; - break; - default: - break; - } - - /* Now we check the error condition! */ - if (status & mg_io_rbit_status_error) { - ret = target_read_u8(target, mg_task_reg + MG_REG_ERROR, &error); - if (ret != ERROR_OK) - return ret; - - LOG_ERROR("mflash: io error 0x%02x", error); - - return ERROR_MG_IO; - } - - switch (wait_local) { - case mg_io_wait_rdy: - if (status & mg_io_rbit_status_ready) - return ERROR_OK; - /* fallthrough */ - case mg_io_wait_drq: - if (status & mg_io_rbit_status_data_req) - return ERROR_OK; - /* fallthrough */ - default: - break; - } - } - - ret = duration_measure(&bench); - if (ERROR_OK == ret) - t = duration_elapsed(&bench) * 1000.0; - else - LOG_ERROR("mflash: duration measurement failed: %d", ret); - - if (t > time_var) - break; - } - - LOG_ERROR("mflash: timeout occured"); - return ERROR_MG_TIMEOUT; -} - -static int mg_dsk_srst(uint8_t on) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - uint8_t value; - int ret; - - ret = target_read_u8(target, mg_task_reg + MG_REG_DRV_CTRL, &value); - if (ret != ERROR_OK) - return ret; - - if (on) - value |= (mg_io_rbit_devc_srst); - else - value &= ~mg_io_rbit_devc_srst; - - ret = target_write_u8(target, mg_task_reg + MG_REG_DRV_CTRL, value); - return ret; -} - -static int mg_dsk_io_cmd(uint32_t sect_num, uint32_t cnt, uint8_t cmd) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - uint8_t value; - int ret; - - ret = mg_dsk_wait(mg_io_wait_rdy_noerr, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - value = mg_io_rval_dev_drv_master | mg_io_rval_dev_lba_mode | ((sect_num >> 24) & 0xf); - - ret = target_write_u8(target, mg_task_reg + MG_REG_DRV_HEAD, value); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_CNT, (uint8_t)cnt); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_NUM, (uint8_t)sect_num); - ret |= target_write_u8(target, mg_task_reg + MG_REG_CYL_LOW, (uint8_t)(sect_num >> 8)); - ret |= target_write_u8(target, mg_task_reg + MG_REG_CYL_HIGH, (uint8_t)(sect_num >> 16)); - - if (ret != ERROR_OK) - return ret; - - return target_write_u8(target, mg_task_reg + MG_REG_COMMAND, cmd); -} - -static int mg_dsk_drv_info(void) -{ - struct target *target = mflash_bank->target; - uint32_t mg_buff = mflash_bank->base + MG_BUFFER_OFFSET; - int ret; - - ret = mg_dsk_io_cmd(0, 1, mg_io_cmd_identify); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: read drive info"); - - if (!mflash_bank->drv_info) - mflash_bank->drv_info = malloc(sizeof(struct mg_drv_info)); - - ret = target_read_memory(target, mg_buff, 2, - sizeof(mg_io_type_drv_info) >> 1, - (uint8_t *)&mflash_bank->drv_info->drv_id); - if (ret != ERROR_OK) - return ret; - - mflash_bank->drv_info->tot_sects = - (uint32_t)(mflash_bank->drv_info->drv_id.total_user_addressable_sectors_hi << 16) - + mflash_bank->drv_info->drv_id.total_user_addressable_sectors_lo; - - return target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_read); -} - -static int mg_mflash_rst(void) -{ - int ret; - - ret = mg_init_gpio(); - if (ret != ERROR_OK) - return ret; - - ret = mg_hdrst(0); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_hdrst(1); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_not_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_srst(1); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_srst(0); - if (ret != ERROR_OK) - return ret; - - ret = mg_dsk_wait(mg_io_wait_not_bsy, MG_OEM_DISK_WAIT_TIME_LONG); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: reset ok"); - - return ERROR_OK; -} - -static int mg_mflash_probe(void) -{ - int ret = mg_mflash_rst(); - if (ret != ERROR_OK) - return ret; - - return mg_dsk_drv_info(); -} - -COMMAND_HANDLER(mg_probe_cmd) -{ - int ret; - - ret = mg_mflash_probe(); - - if (ret == ERROR_OK) { - command_print(CMD_CTX, - "mflash (total %" PRIu32 " sectors) found at 0x%8.8" PRIx32 "", - mflash_bank->drv_info->tot_sects, - mflash_bank->base); - } - - return ret; -} - -static int mg_mflash_do_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t i, address; - int ret; - struct target *target = mflash_bank->target; - uint8_t *buff_ptr = buff; - - ret = mg_dsk_io_cmd(sect_num, sect_cnt, mg_io_cmd_read); - if (ret != ERROR_OK) - return ret; - - address = mflash_bank->base + MG_BUFFER_OFFSET; - - struct duration bench; - duration_start(&bench); - - for (i = 0; i < sect_cnt; i++) { - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_read_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); - if (ret != ERROR_OK) - return ret; - - buff_ptr += MG_MFLASH_SECTOR_SIZE; - - ret = target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_read); - if (ret != ERROR_OK) - return ret; - - LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector read", sect_num + i, - (sect_num + i) * MG_MFLASH_SECTOR_SIZE); - - ret = duration_measure(&bench); - if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) { - LOG_INFO("mflash: read %" PRIu32 "'th sectors", sect_num + i); - duration_start(&bench); - } - } - - return mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_NORMAL); -} - -static int mg_mflash_read_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t quotient, residue, i; - uint8_t *buff_ptr = buff; - int ret = ERROR_OK; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", - sect_num, buff_ptr); - ret = mg_mflash_do_read_sects(buff_ptr, sect_num, 256); - if (ret != ERROR_OK) - return ret; - - sect_num += 256; - buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE; - } - - if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIx32 " buff : %p", - sect_num, buff_ptr); - return mg_mflash_do_read_sects(buff_ptr, sect_num, residue); - } - - return ret; -} - -static int mg_mflash_do_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt, - uint8_t cmd) -{ - uint32_t i, address; - int ret; - struct target *target = mflash_bank->target; - uint8_t *buff_ptr = buff; - - ret = mg_dsk_io_cmd(sect_num, sect_cnt, cmd); - if (ret != ERROR_OK) - return ret; - - address = mflash_bank->base + MG_BUFFER_OFFSET; - - struct duration bench; - duration_start(&bench); - - for (i = 0; i < sect_cnt; i++) { - ret = mg_dsk_wait(mg_io_wait_drq, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_write_memory(target, address, 2, MG_MFLASH_SECTOR_SIZE / 2, buff_ptr); - if (ret != ERROR_OK) - return ret; - - buff_ptr += MG_MFLASH_SECTOR_SIZE; - - ret = target_write_u8(target, - mflash_bank->base + MG_REG_OFFSET + MG_REG_COMMAND, - mg_io_cmd_confirm_write); - if (ret != ERROR_OK) - return ret; - - LOG_DEBUG("mflash: %" PRIu32 " (0x%8.8" PRIx32 ") sector write", sect_num + i, - (sect_num + i) * MG_MFLASH_SECTOR_SIZE); - - ret = duration_measure(&bench); - if ((ERROR_OK == ret) && (duration_elapsed(&bench) > 3)) { - LOG_INFO("mflash: wrote %" PRIu32 "'th sectors", sect_num + i); - duration_start(&bench); - } - } - - if (cmd == mg_io_cmd_write) - ret = mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_NORMAL); - else - ret = mg_dsk_wait(mg_io_wait_rdy, MG_OEM_DISK_WAIT_TIME_LONG); - - return ret; -} - -static int mg_mflash_write_sects(void *buff, uint32_t sect_num, uint32_t sect_cnt) -{ - uint32_t quotient, residue, i; - uint8_t *buff_ptr = buff; - int ret = ERROR_OK; - - quotient = sect_cnt >> 8; - residue = sect_cnt % 256; - - for (i = 0; i < quotient; i++) { - LOG_DEBUG("mflash: sect num : %" PRIu32 "buff : %p", sect_num, - buff_ptr); - ret = mg_mflash_do_write_sects(buff_ptr, sect_num, 256, mg_io_cmd_write); - if (ret != ERROR_OK) - return ret; - - sect_num += 256; - buff_ptr += 256 * MG_MFLASH_SECTOR_SIZE; - } - - if (residue) { - LOG_DEBUG("mflash: sect num : %" PRIu32 " buff : %p", sect_num, - buff_ptr); - return mg_mflash_do_write_sects(buff_ptr, sect_num, residue, mg_io_cmd_write); - } - - return ret; -} - -static int mg_mflash_read(uint32_t addr, uint8_t *buff, uint32_t len) -{ - uint8_t *buff_ptr = buff; - uint8_t sect_buff[MG_MFLASH_SECTOR_SIZE]; - uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num; - int ret = ERROR_OK; - - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - if (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK) { - - next_sec_addr = (cur_addr + MG_MFLASH_SECTOR_SIZE) & ~MG_MFLASH_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - if (end_addr < next_sec_addr) { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - end_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte from sector offset 0x%8.8" PRIx32 "", - end_addr - cur_addr, - cur_addr); - cur_addr = end_addr; - } else { - memcpy(buff_ptr, - sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - next_sec_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte from sector offset 0x%8.8" PRIx32 "", - next_sec_addr - cur_addr, - cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - } - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - next_sec_addr = cur_addr + MG_MFLASH_SECTOR_SIZE; - - while (next_sec_addr <= end_addr) { - cnt++; - next_sec_addr += MG_MFLASH_SECTOR_SIZE; - } - - if (cnt) { - ret = mg_mflash_read_sects(buff_ptr, sect_num, cnt); - if (ret != ERROR_OK) - return ret; - } - - buff_ptr += cnt * MG_MFLASH_SECTOR_SIZE; - cur_addr += cnt * MG_MFLASH_SECTOR_SIZE; - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - memcpy(buff_ptr, sect_buff, end_addr - cur_addr); - LOG_DEBUG("mflash: copies %u byte", (unsigned)(end_addr - cur_addr)); - } - } - - return ret; -} - -static int mg_mflash_write(uint32_t addr, uint8_t *buff, uint32_t len) -{ - uint8_t *buff_ptr = buff; - uint8_t sect_buff[MG_MFLASH_SECTOR_SIZE]; - uint32_t cur_addr, next_sec_addr, end_addr, cnt, sect_num; - int ret = ERROR_OK; - - cnt = 0; - cur_addr = addr; - end_addr = addr + len; - - if (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK) { - - next_sec_addr = (cur_addr + MG_MFLASH_SECTOR_SIZE) & ~MG_MFLASH_SECTOR_SIZE_MASK; - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - if (end_addr < next_sec_addr) { - memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - buff_ptr, - end_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte to sector offset 0x%8.8" PRIx32 "", - end_addr - cur_addr, - cur_addr); - cur_addr = end_addr; - } else { - memcpy(sect_buff + (cur_addr & MG_MFLASH_SECTOR_SIZE_MASK), - buff_ptr, - next_sec_addr - cur_addr); - LOG_DEBUG( - "mflash: copies %" PRIu32 " byte to sector offset 0x%8.8" PRIx32 "", - next_sec_addr - cur_addr, - cur_addr); - buff_ptr += (next_sec_addr - cur_addr); - cur_addr = next_sec_addr; - } - - ret = mg_mflash_write_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - } - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - next_sec_addr = cur_addr + MG_MFLASH_SECTOR_SIZE; - - while (next_sec_addr <= end_addr) { - cnt++; - next_sec_addr += MG_MFLASH_SECTOR_SIZE; - } - - if (cnt) { - ret = mg_mflash_write_sects(buff_ptr, sect_num, cnt); - if (ret != ERROR_OK) - return ret; - } - - buff_ptr += cnt * MG_MFLASH_SECTOR_SIZE; - cur_addr += cnt * MG_MFLASH_SECTOR_SIZE; - - if (cur_addr < end_addr) { - - sect_num = cur_addr >> MG_MFLASH_SECTOR_SIZE_SHIFT; - ret = mg_mflash_read_sects(sect_buff, sect_num, 1); - if (ret != ERROR_OK) - return ret; - - memcpy(sect_buff, buff_ptr, end_addr - cur_addr); - LOG_DEBUG("mflash: copies %" PRIu32 " byte", end_addr - cur_addr); - ret = mg_mflash_write_sects(sect_buff, sect_num, 1); - } - } - - return ret; -} - -COMMAND_HANDLER(mg_write_cmd) -{ - uint32_t address, cnt, res, i; - uint8_t *buffer; - struct fileio *fileio; - int ret; - - if (CMD_ARGC != 3) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], address); - - ret = fileio_open(&fileio, CMD_ARGV[1], FILEIO_READ, FILEIO_BINARY); - if (ret != ERROR_OK) - return ret; - - size_t filesize; - buffer = malloc(MG_FILEIO_CHUNK); - if (!buffer) { - fileio_close(fileio); - return ERROR_FAIL; - } - int retval = fileio_size(fileio, &filesize); - if (retval != ERROR_OK) { - fileio_close(fileio); - free(buffer); - return retval; - } - - cnt = filesize / MG_FILEIO_CHUNK; - res = filesize % MG_FILEIO_CHUNK; - - struct duration bench; - duration_start(&bench); - - size_t buf_cnt; - for (i = 0; i < cnt; i++) { - ret = fileio_read(fileio, MG_FILEIO_CHUNK, buffer, &buf_cnt); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - ret = mg_mflash_write(address, buffer, MG_FILEIO_CHUNK); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - address += MG_FILEIO_CHUNK; - } - - if (res) { - ret = fileio_read(fileio, res, buffer, &buf_cnt); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - ret = mg_mflash_write(address, buffer, res); - if (ret != ERROR_OK) - goto mg_write_cmd_err; - } - - if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD_CTX, "wrote %zu bytes from file %s " - "in %fs (%0.3f kB/s)", filesize, CMD_ARGV[1], - duration_elapsed(&bench), duration_kbps(&bench, filesize)); - } - - free(buffer); - fileio_close(fileio); - - return ERROR_OK; - -mg_write_cmd_err: - free(buffer); - fileio_close(fileio); - - return ret; -} - -COMMAND_HANDLER(mg_dump_cmd) -{ - uint32_t address, size, cnt, res, i; - uint8_t *buffer; - struct fileio *fileio; - int ret; - - if (CMD_ARGC != 4) - return ERROR_COMMAND_SYNTAX_ERROR; - - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], address); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], size); - - ret = fileio_open(&fileio, CMD_ARGV[1], FILEIO_WRITE, FILEIO_BINARY); - if (ret != ERROR_OK) - return ret; - - buffer = malloc(MG_FILEIO_CHUNK); - if (!buffer) { - fileio_close(fileio); - return ERROR_FAIL; - } - - cnt = size / MG_FILEIO_CHUNK; - res = size % MG_FILEIO_CHUNK; - - struct duration bench; - duration_start(&bench); - - size_t size_written; - for (i = 0; i < cnt; i++) { - ret = mg_mflash_read(address, buffer, MG_FILEIO_CHUNK); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - ret = fileio_write(fileio, MG_FILEIO_CHUNK, buffer, &size_written); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - address += MG_FILEIO_CHUNK; - } - - if (res) { - ret = mg_mflash_read(address, buffer, res); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - ret = fileio_write(fileio, res, buffer, &size_written); - if (ret != ERROR_OK) - goto mg_dump_cmd_err; - } - - if (duration_measure(&bench) == ERROR_OK) { - command_print(CMD_CTX, "dump image (address 0x%8.8" PRIx32 " " - "size %" PRIu32 ") to file %s in %fs (%0.3f kB/s)", - address, size, CMD_ARGV[1], - duration_elapsed(&bench), duration_kbps(&bench, size)); - } - - free(buffer); - fileio_close(fileio); - - return ERROR_OK; - -mg_dump_cmd_err: - free(buffer); - fileio_close(fileio); - - return ret; -} - -static int mg_set_feature(mg_feature_id feature, mg_feature_val config) -{ - struct target *target = mflash_bank->target; - uint32_t mg_task_reg = mflash_bank->base + MG_REG_OFFSET; - int ret; - - ret = mg_dsk_wait(mg_io_wait_rdy_noerr, MG_OEM_DISK_WAIT_TIME_NORMAL); - if (ret != ERROR_OK) - return ret; - - ret = target_write_u8(target, mg_task_reg + MG_REG_FEATURE, feature); - ret |= target_write_u8(target, mg_task_reg + MG_REG_SECT_CNT, config); - ret |= target_write_u8(target, mg_task_reg + MG_REG_COMMAND, - mg_io_cmd_set_feature); - - return ret; -} - -static int mg_is_valid_pll(double XIN, int N, double CLK_OUT, int NO) -{ - double v1 = XIN / N; - double v2 = CLK_OUT * NO; - - if (v1 < 1000000 || v1 > 15000000 || v2 < 100000000 || v2 > 500000000) - return ERROR_MG_INVALID_PLL; - - return ERROR_OK; -} - -static int mg_pll_get_M(unsigned short feedback_div) -{ - int i, M; - - for (i = 1, M = 0; i < 512; i <<= 1, feedback_div >>= 1) - M += (feedback_div & 1) * i; - - return M + 2; -} - -static int mg_pll_get_N(unsigned char input_div) -{ - int i, N; - - for (i = 1, N = 0; i < 32; i <<= 1, input_div >>= 1) - N += (input_div & 1) * i; - - return N + 2; -} - -static int mg_pll_get_NO(unsigned char output_div) -{ - int i, NO; - - for (i = 0, NO = 1; i < 2; ++i, output_div >>= 1) - if (output_div & 1) - NO = NO << 1; - - return NO; -} - -static double mg_do_calc_pll(double XIN, mg_pll_t *p_pll_val, int is_approximate) -{ - unsigned short i; - unsigned char j, k; - int M, N, NO; - double CLK_OUT; - double DIV = 1; - double ROUND = 0; - - if (is_approximate) { - DIV = 1000000; - ROUND = 500000; - } - - for (i = 0; i < MG_PLL_MAX_FEEDBACKDIV_VAL; ++i) { - M = mg_pll_get_M(i); - - for (j = 0; j < MG_PLL_MAX_INPUTDIV_VAL; ++j) { - N = mg_pll_get_N(j); - - for (k = 0; k < MG_PLL_MAX_OUTPUTDIV_VAL; ++k) { - NO = mg_pll_get_NO(k); - - CLK_OUT = XIN * ((double)M / N) / NO; - - if ((int)((CLK_OUT + ROUND) / DIV) - == (int)(MG_PLL_CLK_OUT / DIV)) { - if (mg_is_valid_pll(XIN, N, CLK_OUT, NO) == ERROR_OK) { - p_pll_val->lock_cyc = - (int)(XIN * MG_PLL_STD_LOCKCYCLE / - MG_PLL_STD_INPUTCLK); - p_pll_val->feedback_div = i; - p_pll_val->input_div = j; - p_pll_val->output_div = k; - - return CLK_OUT; - } - } - } - } - } - - return 0; -} - -static double mg_calc_pll(double XIN, mg_pll_t *p_pll_val) -{ - double CLK_OUT; - - CLK_OUT = mg_do_calc_pll(XIN, p_pll_val, 0); - - if (!CLK_OUT) - return mg_do_calc_pll(XIN, p_pll_val, 1); - else - return CLK_OUT; -} - -static int mg_verify_interface(void) -{ - uint16_t buff[MG_MFLASH_SECTOR_SIZE >> 1]; - uint16_t i, j; - uint32_t address = mflash_bank->base + MG_BUFFER_OFFSET; - struct target *target = mflash_bank->target; - int ret; - - for (j = 0; j < 10; j++) { - for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) - buff[i] = i; - - ret = target_write_memory(target, address, 2, - MG_MFLASH_SECTOR_SIZE / 2, (uint8_t *)buff); - if (ret != ERROR_OK) - return ret; - - memset(buff, 0xff, MG_MFLASH_SECTOR_SIZE); - - ret = target_read_memory(target, address, 2, - MG_MFLASH_SECTOR_SIZE / 2, (uint8_t *)buff); - if (ret != ERROR_OK) - return ret; - - for (i = 0; i < MG_MFLASH_SECTOR_SIZE >> 1; i++) { - if (buff[i] != i) { - LOG_ERROR("mflash: verify interface fail"); - return ERROR_MG_INTERFACE; - } - } - } - - LOG_INFO("mflash: verify interface ok"); - return ret; -} - -static const char g_strSEG_SerialNum[20] = { - 'G', 'm', 'n', 'i', '-', 'e', 'e', 'S', 'g', 'a', 'e', 'l', - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 -}; - -static const char g_strSEG_FWRev[8] = { - 'F', 'X', 'L', 'T', '2', 'v', '0', '.' -}; - -static const char g_strSEG_ModelNum[40] = { - 'F', 'X', 'A', 'L', 'H', 'S', '2', 0x20, '0', '0', 's', '7', - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 -}; - -static void mg_gen_ataid(mg_io_type_drv_info *pSegIdDrvInfo) -{ - /* b15 is ATA device(0) , b7 is Removable Media Device */ - pSegIdDrvInfo->general_configuration = 0x045A; - /* 128MB : Cylinder=> 977 , Heads=> 8 , Sectors=> 32 - * 256MB : Cylinder=> 980 , Heads=> 16 , Sectors=> 32 - * 384MB : Cylinder=> 745 , Heads=> 16 , Sectors=> 63 - */ - pSegIdDrvInfo->number_of_cylinders = 0x02E9; - pSegIdDrvInfo->reserved1 = 0x0; - pSegIdDrvInfo->number_of_heads = 0x10; - pSegIdDrvInfo->unformatted_bytes_per_track = 0x0; - pSegIdDrvInfo->unformatted_bytes_per_sector = 0x0; - pSegIdDrvInfo->sectors_per_track = 0x3F; - pSegIdDrvInfo->vendor_unique1[0] = 0x000B; - pSegIdDrvInfo->vendor_unique1[1] = 0x7570; - pSegIdDrvInfo->vendor_unique1[2] = 0x8888; - - memcpy(pSegIdDrvInfo->serial_number, g_strSEG_SerialNum, 20); - /* 0x2 : dual buffer */ - pSegIdDrvInfo->buffer_type = 0x2; - /* buffer size : 2KB */ - pSegIdDrvInfo->buffer_sector_size = 0x800; - pSegIdDrvInfo->number_of_ecc_bytes = 0; - - memcpy(pSegIdDrvInfo->firmware_revision, g_strSEG_FWRev, 8); - - memcpy(pSegIdDrvInfo->model_number, g_strSEG_ModelNum, 40); - - pSegIdDrvInfo->maximum_block_transfer = 0x4; - pSegIdDrvInfo->vendor_unique2 = 0x0; - pSegIdDrvInfo->dword_io = 0x00; - /* b11 : IORDY support(PIO Mode 4), b10 : Disable/Enbale IORDY - * b9 : LBA support, b8 : DMA mode support - */ - pSegIdDrvInfo->capabilities = 0x1 << 9; - - pSegIdDrvInfo->reserved2 = 0x4000; - pSegIdDrvInfo->vendor_unique3 = 0x00; - /* PIOMode-2 support */ - pSegIdDrvInfo->pio_cycle_timing_mode = 0x02; - pSegIdDrvInfo->vendor_unique4 = 0x00; - /* MultiWord-2 support */ - pSegIdDrvInfo->dma_cycle_timing_mode = 0x00; - /* b1 : word64~70 is valid - * b0 : word54~58 are valid and reflect the current numofcyls,heads,sectors - * b2 : If device supports Ultra DMA , set to one to vaildate word88 - */ - pSegIdDrvInfo->translation_fields_valid = (0x1 << 1) | (0x1 << 0); - pSegIdDrvInfo->number_of_current_cylinders = 0x02E9; - pSegIdDrvInfo->number_of_current_heads = 0x10; - pSegIdDrvInfo->current_sectors_per_track = 0x3F; - pSegIdDrvInfo->current_sector_capacity_lo = 0x7570; - pSegIdDrvInfo->current_sector_capacity_hi = 0x000B; - - pSegIdDrvInfo->multi_sector_count = 0x04; - /* b8 : Multiple secotr setting valid , b[7:0] num of secotrs per block */ - pSegIdDrvInfo->multi_sector_setting_valid = 0x01; - pSegIdDrvInfo->total_user_addressable_sectors_lo = 0x7570; - pSegIdDrvInfo->total_user_addressable_sectors_hi = 0x000B; - pSegIdDrvInfo->single_dma_modes_supported = 0x00; - pSegIdDrvInfo->single_dma_transfer_active = 0x00; - /* b2 :Multi-word DMA mode 2, b1 : Multi-word DMA mode 1 */ - pSegIdDrvInfo->multi_dma_modes_supported = (0x1 << 0); - /* b2 :Multi-word DMA mode 2, b1 : Multi-word DMA mode 1 */ - pSegIdDrvInfo->multi_dma_transfer_active = (0x1 << 0); - /* b0 : PIO Mode-3 support, b1 : PIO Mode-4 support */ - pSegIdDrvInfo->adv_pio_mode = 0x00; - /* 480(0x1E0)nsec for Multi-word DMA mode0 - * 150(0x96) nsec for Multi-word DMA mode1 - * 120(0x78) nsec for Multi-word DMA mode2 - */ - pSegIdDrvInfo->min_dma_cyc = 0x1E0; - pSegIdDrvInfo->recommend_dma_cyc = 0x1E0; - pSegIdDrvInfo->min_pio_cyc_no_iordy = 0x1E0; - pSegIdDrvInfo->min_pio_cyc_with_iordy = 0x1E0; - memset(pSegIdDrvInfo->reserved3, 0x00, 22); - /* b7 : ATA/ATAPI-7 ,b6 : ATA/ATAPI-6 ,b5 : ATA/ATAPI-5,b4 : ATA/ATAPI-4 */ - pSegIdDrvInfo->major_ver_num = 0x7E; - /* 0x1C : ATA/ATAPI-6 T13 1532D revision1 */ - pSegIdDrvInfo->minor_ver_num = 0x19; - /* NOP/READ BUFFER/WRITE BUFFER/Power management feature set support */ - pSegIdDrvInfo->feature_cmd_set_suprt0 = 0x7068; - /* Features/command set is valid/Advanced Pwr management/CFA feature set - * not support - */ - pSegIdDrvInfo->feature_cmd_set_suprt1 = 0x400C; - pSegIdDrvInfo->feature_cmd_set_suprt2 = 0x4000; - /* READ/WRITE BUFFER/PWR Management enable */ - pSegIdDrvInfo->feature_cmd_set_en0 = 0x7000; - /* CFA feature is disabled / Advancde power management disable */ - pSegIdDrvInfo->feature_cmd_set_en1 = 0x0; - pSegIdDrvInfo->feature_cmd_set_en2 = 0x4000; - pSegIdDrvInfo->reserved4 = 0x0; - /* 0x1 * 2minutes */ - pSegIdDrvInfo->req_time_for_security_er_done = 0x19; - pSegIdDrvInfo->req_time_for_enhan_security_er_done = 0x19; - /* Advanced power management level 1 */ - pSegIdDrvInfo->adv_pwr_mgm_lvl_val = 0x0; - pSegIdDrvInfo->reserved5 = 0x0; - memset(pSegIdDrvInfo->reserved6, 0x00, 68); - /* Security mode feature is disabled */ - pSegIdDrvInfo->security_stas = 0x0; - memset(pSegIdDrvInfo->vendor_uniq_bytes, 0x00, 62); - /* CFA power mode 1 support in maximum 200mA */ - pSegIdDrvInfo->cfa_pwr_mode = 0x0100; - memset(pSegIdDrvInfo->reserved7, 0x00, 190); -} - -static int mg_storage_config(void) -{ - uint8_t buff[512]; - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - mg_gen_ataid((mg_io_type_drv_info *)(void *)buff); - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_update_stgdrvinfo); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: storage config ok"); - return ret; -} - -static int mg_boot_config(void) -{ - uint8_t buff[512]; - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - memset(buff, 0xff, 512); - - buff[0] = mg_op_mode_snd; /* operation mode */ - buff[1] = MG_UNLOCK_OTP_AREA; - buff[2] = 4; /* boot size */ - *((uint32_t *)(void *)(buff + 4)) = 0; /* XIP size */ - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_update_xipinfo); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: boot config ok"); - return ret; -} - -static int mg_set_pll(mg_pll_t *pll) -{ - uint8_t buff[512]; - int ret; - - memset(buff, 0xff, 512); - /* PLL Lock cycle and Feedback 9bit Divider */ - memcpy(buff, &pll->lock_cyc, sizeof(uint32_t)); - memcpy(buff + 4, &pll->feedback_div, sizeof(uint16_t)); - buff[6] = pll->input_div; /* PLL Input 5bit Divider */ - buff[7] = pll->output_div; /* PLL Output Divider */ - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_do_write_sects(buff, 0, 1, mg_vcmd_wr_pll); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: set pll ok"); - return ret; -} - -static int mg_erase_nand(void) -{ - int ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_vcmd); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_do_write_sects(NULL, 0, 0, mg_vcmd_purge_nand); - if (ret != ERROR_OK) - return ret; - - ret = mg_set_feature(mg_feature_id_transmode, mg_feature_val_trans_default); - if (ret != ERROR_OK) - return ret; - - LOG_INFO("mflash: erase nand ok"); - return ret; -} - -COMMAND_HANDLER(mg_config_cmd) -{ - double fin, fout; - mg_pll_t pll; - int ret; - - ret = mg_verify_interface(); - if (ret != ERROR_OK) - return ret; - - ret = mg_mflash_rst(); - if (ret != ERROR_OK) - return ret; - - switch (CMD_ARGC) { - case 2: - if (!strcmp(CMD_ARGV[1], "boot")) - return mg_boot_config(); - else if (!strcmp(CMD_ARGV[1], "storage")) - return mg_storage_config(); - else - return ERROR_COMMAND_NOTFOUND; - break; - case 3: - if (!strcmp(CMD_ARGV[1], "pll")) { - unsigned long freq; - COMMAND_PARSE_NUMBER(ulong, CMD_ARGV[2], freq); - fin = freq; - - if (fin > MG_PLL_CLK_OUT) { - LOG_ERROR("mflash: input freq. is too large"); - return ERROR_MG_INVALID_OSC; - } - - fout = mg_calc_pll(fin, &pll); - - if (!fout) { - LOG_ERROR("mflash: cannot generate valid pll"); - return ERROR_MG_INVALID_PLL; - } - - LOG_INFO("mflash: Fout=%" PRIu32 " Hz, feedback=%u," - "indiv=%u, outdiv=%u, lock=%u", - (uint32_t)fout, pll.feedback_div, - pll.input_div, pll.output_div, - pll.lock_cyc); - - ret = mg_erase_nand(); - if (ret != ERROR_OK) - return ret; - - return mg_set_pll(&pll); - } else - return ERROR_COMMAND_NOTFOUND; - break; - default: - return ERROR_COMMAND_SYNTAX_ERROR; - } -} - -static const struct command_registration mflash_exec_command_handlers[] = { - { - .name = "probe", - .handler = mg_probe_cmd, - .mode = COMMAND_EXEC, - .help = "Detect bank configuration information", - }, - { - .name = "write", - .handler = mg_write_cmd, - .mode = COMMAND_EXEC, - /* FIXME bank_num is unused */ - .usage = "bank_num filename address", - .help = "Write binary file at the specified address.", - }, - { - .name = "dump", - .handler = mg_dump_cmd, - .mode = COMMAND_EXEC, - /* FIXME bank_num is unused */ - .usage = "bank_num filename address size", - .help = "Write specified number of bytes from a binary file " - "to the specified, address.", - }, - { - .name = "config", - .handler = mg_config_cmd, - .mode = COMMAND_EXEC, - .help = "Configure MFLASH options.", - .usage = "('boot'|'storage'|'pll' frequency)", - }, - COMMAND_REGISTRATION_DONE -}; - -static int mflash_init_drivers(struct command_context *cmd_ctx) -{ - if (!mflash_bank) - return ERROR_OK; - return register_commands(cmd_ctx, NULL, mflash_exec_command_handlers); -} - -COMMAND_HANDLER(handle_mflash_init_command) -{ - if (CMD_ARGC != 0) - return ERROR_COMMAND_SYNTAX_ERROR; - - static bool mflash_initialized; - if (mflash_initialized) { - LOG_INFO("'mflash init' has already been called"); - return ERROR_OK; - } - mflash_initialized = true; - - LOG_DEBUG("Initializing mflash devices..."); - return mflash_init_drivers(CMD_CTX); -} - -COMMAND_HANDLER(mg_bank_cmd) -{ - struct target *target; - int i; - - if (CMD_ARGC < 4) - return ERROR_COMMAND_SYNTAX_ERROR; - - target = get_target(CMD_ARGV[3]); - if (target == NULL) { - LOG_ERROR("target '%s' not defined", CMD_ARGV[3]); - return ERROR_FAIL; - } - - mflash_bank = calloc(sizeof(struct mflash_bank), 1); - COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], mflash_bank->base); - /** @todo Verify how this parsing should work, then document it. */ - char *str; - mflash_bank->rst_pin.num = strtoul(CMD_ARGV[2], &str, 0); - if (*str) - mflash_bank->rst_pin.port[0] = (uint16_t) - tolower((unsigned)str[0]); - - mflash_bank->target = target; - - for (i = 0; mflash_gpio[i]; i++) { - if (!strcmp(mflash_gpio[i]->name, CMD_ARGV[0])) - mflash_bank->gpio_drv = mflash_gpio[i]; - } - - if (!mflash_bank->gpio_drv) { - LOG_ERROR("%s is unsupported soc", CMD_ARGV[0]); - return ERROR_MG_UNSUPPORTED_SOC; - } - - return ERROR_OK; -} - -static const struct command_registration mflash_config_command_handlers[] = { - { - .name = "bank", - .handler = mg_bank_cmd, - .mode = COMMAND_CONFIG, - .help = "configure a mflash device bank", - .usage = "soc_type base_addr pin_id target", - }, - { - .name = "init", - .mode = COMMAND_CONFIG, - .handler = handle_mflash_init_command, - .help = "initialize mflash devices", - .usage = "" - }, - COMMAND_REGISTRATION_DONE -}; -static const struct command_registration mflash_command_handler[] = { - { - .name = "mflash", - .mode = COMMAND_ANY, - .help = "mflash command group", - .usage = "", - .chain = mflash_config_command_handlers, - }, - COMMAND_REGISTRATION_DONE -}; -int mflash_register_commands(struct command_context *cmd_ctx) -{ - return register_commands(cmd_ctx, NULL, mflash_command_handler); -} diff --git a/src/flash/mflash.h b/src/flash/mflash.h deleted file mode 100644 index 18da403..0000000 --- a/src/flash/mflash.h +++ /dev/null @@ -1,289 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2007-2008 by unsik Kim <donari75@gmail.com> * - * * - * 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 <http://www.gnu.org/licenses/>. * - ***************************************************************************/ - -#ifndef OPENOCD_FLASH_MFLASH_H -#define OPENOCD_FLASH_MFLASH_H - -struct command_context; - -typedef unsigned long mg_io_uint32; -typedef unsigned short mg_io_uint16; -typedef unsigned char mg_io_uint8; - -struct mflash_gpio_num { - char port[2]; - signed short num; -}; - -struct mflash_gpio_drv { - const char *name; - int (*set_gpio_to_output)(struct mflash_gpio_num gpio); - int (*set_gpio_output_val)(struct mflash_gpio_num gpio, uint8_t val); -}; - -typedef struct _mg_io_type_drv_info { - - mg_io_uint16 general_configuration; /* 00 */ - mg_io_uint16 number_of_cylinders; /* 01 */ - mg_io_uint16 reserved1; /* 02 */ - mg_io_uint16 number_of_heads; /* 03 */ - mg_io_uint16 unformatted_bytes_per_track; /* 04 */ - mg_io_uint16 unformatted_bytes_per_sector; /* 05 */ - mg_io_uint16 sectors_per_track; /* 06 */ - mg_io_uint16 vendor_unique1[3]; /* 07/08/09 */ - - mg_io_uint8 serial_number[20]; /* 10~19 */ - - mg_io_uint16 buffer_type; /* 20 */ - mg_io_uint16 buffer_sector_size; /* 21 */ - mg_io_uint16 number_of_ecc_bytes; /* 22 */ - - mg_io_uint8 firmware_revision[8]; /* 23~26 */ - mg_io_uint8 model_number[40]; /* 27 */ - - mg_io_uint8 maximum_block_transfer; /* 47 low byte */ - mg_io_uint8 vendor_unique2; /* 47 high byte */ - mg_io_uint16 dword_io; /* 48 */ - - mg_io_uint16 capabilities; /* 49 */ - mg_io_uint16 reserved2; /* 50 */ - - mg_io_uint8 vendor_unique3; /* 51 low byte */ - mg_io_uint8 pio_cycle_timing_mode; /* 51 high byte */ - mg_io_uint8 vendor_unique4; /* 52 low byte */ - mg_io_uint8 dma_cycle_timing_mode; /* 52 high byte */ - mg_io_uint16 translation_fields_valid; /* 53 (low bit) */ - mg_io_uint16 number_of_current_cylinders; /* 54 */ - mg_io_uint16 number_of_current_heads; /* 55 */ - mg_io_uint16 current_sectors_per_track; /* 56 */ - mg_io_uint16 current_sector_capacity_lo; /* 57 & 58 */ - mg_io_uint16 current_sector_capacity_hi; /* 57 & 58 */ - mg_io_uint8 multi_sector_count; /* 59 low */ - mg_io_uint8 multi_sector_setting_valid; /* 59 high (low bit) */ - - mg_io_uint16 total_user_addressable_sectors_lo; /* 60 & 61 */ - mg_io_uint16 total_user_addressable_sectors_hi; /* 60 & 61 */ - - mg_io_uint8 single_dma_modes_supported; /* 62 low byte */ - mg_io_uint8 single_dma_transfer_active; /* 62 high byte */ - mg_io_uint8 multi_dma_modes_supported; /* 63 low byte */ - mg_io_uint8 multi_dma_transfer_active; /* 63 high byte */ - mg_io_uint16 adv_pio_mode; - mg_io_uint16 min_dma_cyc; - mg_io_uint16 recommend_dma_cyc; - mg_io_uint16 min_pio_cyc_no_iordy; - mg_io_uint16 min_pio_cyc_with_iordy; - mg_io_uint8 reserved3[22]; - mg_io_uint16 major_ver_num; - mg_io_uint16 minor_ver_num; - mg_io_uint16 feature_cmd_set_suprt0; - mg_io_uint16 feature_cmd_set_suprt1; - mg_io_uint16 feature_cmd_set_suprt2; - mg_io_uint16 feature_cmd_set_en0; - mg_io_uint16 feature_cmd_set_en1; - mg_io_uint16 feature_cmd_set_en2; - mg_io_uint16 reserved4; - mg_io_uint16 req_time_for_security_er_done; - mg_io_uint16 req_time_for_enhan_security_er_done; - mg_io_uint16 adv_pwr_mgm_lvl_val; - mg_io_uint16 reserved5; - mg_io_uint16 re_of_hw_rst; - mg_io_uint8 reserved6[68]; - mg_io_uint16 security_stas; - mg_io_uint8 vendor_uniq_bytes[62]; - mg_io_uint16 cfa_pwr_mode; - mg_io_uint8 reserved7[186]; - - mg_io_uint16 scts_per_secure_data_unit; - mg_io_uint16 integrity_word; - -} mg_io_type_drv_info; - -typedef struct _mg_pll_t { - unsigned int lock_cyc; - unsigned short feedback_div; /* 9bit divider */ - unsigned char input_div; /* 5bit divider */ - unsigned char output_div; /* 2bit divider */ -} mg_pll_t; - -struct mg_drv_info { - mg_io_type_drv_info drv_id; - uint32_t tot_sects; -}; - -struct mflash_bank { - uint32_t base; - - struct mflash_gpio_num rst_pin; - - struct mflash_gpio_drv *gpio_drv; - struct target *target; - struct mg_drv_info *drv_info; -}; - -int mflash_register_commands(struct command_context *cmd_ctx); - -#define MG_MFLASH_SECTOR_SIZE (0x200) /* 512Bytes = 2^9 */ -#define MG_MFLASH_SECTOR_SIZE_MASK (0x200-1) -#define MG_MFLASH_SECTOR_SIZE_SHIFT (9) - -#define MG_BUFFER_OFFSET 0x8000 -#define MG_REG_OFFSET 0xC000 -#define MG_REG_FEATURE 0x2 /* write case */ -#define MG_REG_ERROR 0x2 /* read case */ -#define MG_REG_SECT_CNT 0x4 -#define MG_REG_SECT_NUM 0x6 -#define MG_REG_CYL_LOW 0x8 -#define MG_REG_CYL_HIGH 0xA -#define MG_REG_DRV_HEAD 0xC -#define MG_REG_COMMAND 0xE /* write case */ -#define MG_REG_STATUS 0xE /* read case */ -#define MG_REG_DRV_CTRL 0x10 -#define MG_REG_BURST_CTRL 0x12 - -#define MG_OEM_DISK_WAIT_TIME_LONG 15000 /* msec */ -#define MG_OEM_DISK_WAIT_TIME_NORMAL 3000 /* msec */ -#define MG_OEM_DISK_WAIT_TIME_SHORT 1000 /* msec */ - -#define MG_PLL_CLK_OUT 66000000.0 /* 66Mhz */ -#define MG_PLL_MAX_FEEDBACKDIV_VAL 512 -#define MG_PLL_MAX_INPUTDIV_VAL 32 -#define MG_PLL_MAX_OUTPUTDIV_VAL 4 - -#define MG_PLL_STD_INPUTCLK 12000000.0 /* 12Mhz */ -#define MG_PLL_STD_LOCKCYCLE 10000 - -#define MG_UNLOCK_OTP_AREA 0xFF - -#define MG_FILEIO_CHUNK 1048576 - -#define ERROR_MG_IO (-1600) -#define ERROR_MG_TIMEOUT (-1601) -#define ERROR_MG_INVALID_PLL (-1603) -#define ERROR_MG_INTERFACE (-1604) -#define ERROR_MG_INVALID_OSC (-1605) -#define ERROR_MG_UNSUPPORTED_SOC (-1606) - -typedef enum _mg_io_type_wait { - - mg_io_wait_bsy = 1, - mg_io_wait_not_bsy = 2, - mg_io_wait_rdy = 3, - mg_io_wait_drq = 4, /* wait for data request */ - mg_io_wait_drq_noerr = 5, /* wait for DRQ but ignore the error status bit */ - mg_io_wait_rdy_noerr = 6 /* wait for ready, but ignore error status bit */ - -} mg_io_type_wait; - -/*= "Status Register" bit masks. */ -typedef enum _mg_io_type_rbit_status { - - mg_io_rbit_status_error = 0x01, /* error bit in status register */ - mg_io_rbit_status_corrected_error = 0x04, /* corrected error in status register */ - mg_io_rbit_status_data_req = 0x08, /* data request bit in status register */ - mg_io_rbit_status_seek_done = 0x10, /* DSC - Drive Seek Complete */ - mg_io_rbit_status_write_fault = 0x20, /* DWF - Drive Write Fault */ - mg_io_rbit_status_ready = 0x40, - mg_io_rbit_status_busy = 0x80 - -} mg_io_type_rbit_status; - -/*= "Error Register" bit masks. */ -typedef enum _mg_io_type_rbit_error { - - mg_io_rbit_err_general = 0x01, - mg_io_rbit_err_aborted = 0x04, - mg_io_rbit_err_bad_sect_num = 0x10, - mg_io_rbit_err_uncorrectable = 0x40, - mg_io_rbit_err_bad_block = 0x80 - -} mg_io_type_rbit_error; - -/* = "Device Control Register" bit. */ -typedef enum _mg_io_type_rbit_devc { - - mg_io_rbit_devc_intr = 0x02, /* interrupt enable bit (1:disable, 0:enable) */ - mg_io_rbit_devc_srst = 0x04 /* softwrae reset bit (1:assert, 0:de-assert) */ - -} mg_io_type_rbit_devc; - -/* "Drive Select/Head Register" values. */ -typedef enum _mg_io_type_rval_dev { - - mg_io_rval_dev_must_be_on = 0x80, /* These 1 bits are always on */ - mg_io_rval_dev_drv_master = (0x00 | mg_io_rval_dev_must_be_on), /* Master */ - mg_io_rval_dev_drv_slave0 = (0x10 | mg_io_rval_dev_must_be_on), /* Slave0 */ - mg_io_rval_dev_drv_slave1 = (0x20 | mg_io_rval_dev_must_be_on), /* Slave1 */ - mg_io_rval_dev_drv_slave2 = (0x30 | mg_io_rval_dev_must_be_on), /* Slave2 */ - mg_io_rval_dev_lba_mode = (0x40 | mg_io_rval_dev_must_be_on) - -} mg_io_type_rval_dev; - -typedef enum _mg_io_type_cmd { - mg_io_cmd_read = 0x20, - mg_io_cmd_write = 0x30, - - mg_io_cmd_setmul = 0xC6, - mg_io_cmd_readmul = 0xC4, - mg_io_cmd_writemul = 0xC5, - - mg_io_cmd_idle = 0x97, /* 0xE3 */ - mg_io_cmd_idle_immediate = 0x95, /* 0xE1 */ - - mg_io_cmd_setsleep = 0x99, /* 0xE6 */ - mg_io_cmd_stdby = 0x96, /* 0xE2 */ - mg_io_cmd_stdby_immediate = 0x94, /* 0xE0 */ - - mg_io_cmd_identify = 0xEC, - mg_io_cmd_set_feature = 0xEF, - - mg_io_cmd_confirm_write = 0x3C, - mg_io_cmd_confirm_read = 0x40, - mg_io_cmd_wakeup = 0xC3 - -} mg_io_type_cmd; - -typedef enum _mg_feature_id { - mg_feature_id_transmode = 0x3 -} mg_feature_id; - -typedef enum _mg_feature_val { - mg_feature_val_trans_default = 0x0, - mg_feature_val_trans_vcmd = 0x3, - mg_feature_val_trand_vcmds = 0x2 -} mg_feature_val; - -typedef enum _mg_vcmd { - mg_vcmd_update_xipinfo = 0xFA, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_verify_fwpatch = 0xFB, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_update_stgdrvinfo = 0xFC, /* IOM identificatin info program command */ - mg_vcmd_prep_fwpatch = 0xFD, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_exe_fwpatch = 0xFE, /* FWPATCH commmand through IOM I/O */ - mg_vcmd_wr_pll = 0x8B, - mg_vcmd_purge_nand = 0x8C, /* Only for Seagle */ - mg_vcmd_lock_otp = 0x8D, - mg_vcmd_rd_otp = 0x8E, - mg_vcmd_wr_otp = 0x8F -} mg_vcmd; - -typedef enum _mg_opmode { - mg_op_mode_xip = 1, /* TRUE XIP */ - mg_op_mode_snd = 2, /* BOOT + Storage */ - mg_op_mode_stg = 0 /* Only Storage */ -} mg_opmode; - -#endif /* OPENOCD_FLASH_MFLASH_H */ diff --git a/src/flash/nand/at91sam9.c b/src/flash/nand/at91sam9.c index 0af12b2..47c0505 100644 --- a/src/flash/nand/at91sam9.c +++ b/src/flash/nand/at91sam9.c @@ -547,14 +547,14 @@ COMMAND_HANDLER(handle_at91sam9_cle_command) unsigned num, address_line; if (CMD_ARGC != 2) { - command_print(CMD_CTX, "incorrect number of arguments for 'at91sam9 cle' command"); + command_print(CMD, "incorrect number of arguments for 'at91sam9 cle' command"); return ERROR_OK; } COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_OK; } @@ -582,7 +582,7 @@ COMMAND_HANDLER(handle_at91sam9_ale_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -610,7 +610,7 @@ COMMAND_HANDLER(handle_at91sam9_rdy_busy_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -641,7 +641,7 @@ COMMAND_HANDLER(handle_at91sam9_ce_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "invalid nand device number: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } diff --git a/src/flash/nand/core.c b/src/flash/nand/core.c index 7428d22..b9ac793 100644 --- a/src/flash/nand/core.c +++ b/src/flash/nand/core.c @@ -217,7 +217,7 @@ COMMAND_HELPER(nand_command_get_device, unsigned name_index, COMMAND_PARSE_NUMBER(uint, str, num); *nand = get_nand_device_by_num(num); if (!*nand) { - command_print(CMD_CTX, "NAND flash device '%s' not found", str); + command_print(CMD, "NAND flash device '%s' not found", str); return ERROR_COMMAND_SYNTAX_ERROR; } return ERROR_OK; diff --git a/src/flash/nand/fileio.c b/src/flash/nand/fileio.c index 64c32c0..f65f957 100644 --- a/src/flash/nand/fileio.c +++ b/src/flash/nand/fileio.c @@ -54,12 +54,12 @@ void nand_fileio_init(struct nand_fileio_state *state) state->oob_format = NAND_OOB_NONE; } -int nand_fileio_start(struct command_context *cmd_ctx, +int nand_fileio_start(struct command_invocation *cmd, struct nand_device *nand, const char *filename, int filemode, struct nand_fileio_state *state) { if (state->address % nand->page_size) { - command_print(cmd_ctx, "only page-aligned addresses are supported"); + command_print(cmd, "only page-aligned addresses are supported"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -69,7 +69,7 @@ int nand_fileio_start(struct command_context *cmd_ctx, int retval = fileio_open(&state->fileio, filename, filemode, FILEIO_BINARY); if (ERROR_OK != retval) { const char *msg = (FILEIO_READ == filemode) ? "read" : "write"; - command_print(cmd_ctx, "failed to open '%s' for %s access", + command_print(cmd, "failed to open '%s' for %s access", filename, msg); return retval; } @@ -131,7 +131,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, return retval; if (NULL == nand->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_NAND_DEVICE_NOT_PROBED; } @@ -139,7 +139,7 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, if (need_size) { COMMAND_PARSE_NUMBER(u32, CMD_ARGV[3], state->size); if (state->size % nand->page_size) { - command_print(CMD_CTX, "only page-aligned sizes are supported"); + command_print(CMD, "only page-aligned sizes are supported"); return ERROR_COMMAND_SYNTAX_ERROR; } } @@ -155,13 +155,13 @@ COMMAND_HELPER(nand_fileio_parse_args, struct nand_fileio_state *state, else if (sw_ecc && !strcmp(CMD_ARGV[i], "oob_softecc_kw")) state->oob_format |= NAND_OOB_SW_ECC_KW; else { - command_print(CMD_CTX, "unknown option: %s", CMD_ARGV[i]); + command_print(CMD, "unknown option: %s", CMD_ARGV[i]); return ERROR_COMMAND_SYNTAX_ERROR; } } } - retval = nand_fileio_start(CMD_CTX, nand, CMD_ARGV[1], filemode, state); + retval = nand_fileio_start(CMD, nand, CMD_ARGV[1], filemode, state); if (ERROR_OK != retval) return retval; diff --git a/src/flash/nand/fileio.h b/src/flash/nand/fileio.h index af6c766..6a094c2 100644 --- a/src/flash/nand/fileio.h +++ b/src/flash/nand/fileio.h @@ -41,7 +41,7 @@ struct nand_fileio_state { }; void nand_fileio_init(struct nand_fileio_state *state); -int nand_fileio_start(struct command_context *cmd_ctx, +int nand_fileio_start(struct command_invocation *cmd, struct nand_device *nand, const char *filename, int filemode, struct nand_fileio_state *state); int nand_fileio_cleanup(struct nand_fileio_state *state); diff --git a/src/flash/nand/lpc3180.c b/src/flash/nand/lpc3180.c index d15fdce..389c18a 100644 --- a/src/flash/nand/lpc3180.c +++ b/src/flash/nand/lpc3180.c @@ -237,7 +237,7 @@ static int lpc3180_init(struct nand_device *nand) /* SLC_CFG = 0x (Force nCE assert, DMA ECC enabled, ECC enabled, DMA burst enabled, *DMA read from SLC, WIDTH = bus_width) */ - target_write_u32(target, 0x20020014, 0x3e | (bus_width == 16) ? 1 : 0); + target_write_u32(target, 0x20020014, 0x3e | ((bus_width == 16) ? 1 : 0)); /* SLC_IEN = 3 (INT_RDY_EN = 1) ,(INT_TC_STAT = 1) */ target_write_u32(target, 0x20020020, 0x03); @@ -1290,7 +1290,7 @@ COMMAND_HANDLER(handle_lpc3180_select_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); struct nand_device *nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "nand device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "nand device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -1310,10 +1310,10 @@ COMMAND_HANDLER(handle_lpc3180_select_command) } if (lpc3180_info->selected_controller == LPC3180_MLC_CONTROLLER) - command_print(CMD_CTX, "%s controller selected", + command_print(CMD, "%s controller selected", selected[lpc3180_info->selected_controller]); else - command_print(CMD_CTX, + command_print(CMD, lpc3180_info->is_bulk ? "%s controller selected bulk mode is available" : "%s controller selected bulk mode is not available", selected[lpc3180_info->selected_controller]); diff --git a/src/flash/nand/lpc32xx.c b/src/flash/nand/lpc32xx.c index 1ed16df..058d9a5 100644 --- a/src/flash/nand/lpc32xx.c +++ b/src/flash/nand/lpc32xx.c @@ -332,7 +332,7 @@ static int lpc32xx_init(struct nand_device *nand) WIDTH = bus_width) */ retval = target_write_u32(target, 0x20020014, - 0x3e | (bus_width == 16) ? 1 : 0); + 0x3e | ((bus_width == 16) ? 1 : 0)); if (ERROR_OK != retval) { LOG_ERROR("could not set SLC_CFG"); return ERROR_NAND_OPERATION_FAILED; @@ -1760,7 +1760,7 @@ COMMAND_HANDLER(handle_lpc32xx_select_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], num); struct nand_device *nand = get_nand_device_by_num(num); if (!nand) { - command_print(CMD_CTX, "nand device '#%s' is out of bounds", + command_print(CMD, "nand device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -1778,7 +1778,7 @@ COMMAND_HANDLER(handle_lpc32xx_select_command) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "%s controller selected", + command_print(CMD, "%s controller selected", selected[lpc32xx_info->selected_controller]); return ERROR_OK; diff --git a/src/flash/nand/mxc.c b/src/flash/nand/mxc.c index 6be4160..b541157 100644 --- a/src/flash/nand/mxc.c +++ b/src/flash/nand/mxc.c @@ -157,7 +157,7 @@ COMMAND_HANDLER(handle_mxc_biswap_command) int retval = CALL_COMMAND_HANDLER(nand_command_get_device, 0, &nand); if (retval != ERROR_OK) { - command_print(CMD_CTX, "invalid nand device number or name: %s", CMD_ARGV[0]); + command_print(CMD, "invalid nand device number or name: %s", CMD_ARGV[0]); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -169,9 +169,9 @@ COMMAND_HANDLER(handle_mxc_biswap_command) mxc_nf_info->flags.biswap_enabled = false; } if (mxc_nf_info->flags.biswap_enabled) - command_print(CMD_CTX, "BI-swapping enabled on %s", nand->name); + command_print(CMD, "BI-swapping enabled on %s", nand->name); else - command_print(CMD_CTX, "BI-swapping disabled on %s", nand->name); + command_print(CMD, "BI-swapping disabled on %s", nand->name); return ERROR_OK; } @@ -193,7 +193,8 @@ static const struct command_registration mxc_nand_command_handler[] = { .name = "mxc", .mode = COMMAND_ANY, .help = "MXC NAND flash controller commands", - .chain = mxc_sub_command_handlers + .chain = mxc_sub_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nand/tcl.c b/src/flash/nand/tcl.c index d9738c5..5480e0d 100644 --- a/src/flash/nand/tcl.c +++ b/src/flash/nand/tcl.c @@ -37,20 +37,20 @@ COMMAND_HANDLER(handle_nand_list_command) int i; if (!nand_devices) { - command_print(CMD_CTX, "no NAND flash devices configured"); + command_print(CMD, "no NAND flash devices configured"); return ERROR_OK; } for (p = nand_devices, i = 0; p; p = p->next, i++) { if (p->device) - command_print(CMD_CTX, "#%i: %s (%s) " + command_print(CMD, "#%i: %s (%s) " "pagesize: %i, buswidth: %i,\n\t" "blocksize: %i, blocks: %i", i, p->device->name, p->manufacturer->name, p->page_size, p->bus_width, p->erase_size, p->num_blocks); else - command_print(CMD_CTX, "#%i: not probed", i); + command_print(CMD, "#%i: not probed", i); } return ERROR_OK; @@ -87,7 +87,7 @@ COMMAND_HANDLER(handle_nand_info_command) return retval; if (NULL == p->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_OK; } @@ -97,7 +97,7 @@ COMMAND_HANDLER(handle_nand_info_command) if (last >= p->num_blocks) last = p->num_blocks - 1; - command_print(CMD_CTX, + command_print(CMD, "#%i: %s (%s) pagesize: %i, buswidth: %i, erasesize: %i", i++, p->device->name, @@ -123,7 +123,7 @@ COMMAND_HANDLER(handle_nand_info_command) else bad_state = " (block condition unknown)"; - command_print(CMD_CTX, + command_print(CMD, "\t#%i: 0x%8.8" PRIx32 " (%" PRId32 "kB) %s%s", j, p->blocks[j].offset, @@ -147,7 +147,7 @@ COMMAND_HANDLER(handle_nand_probe_command) retval = nand_probe(p); if (retval == ERROR_OK) { - command_print(CMD_CTX, "NAND flash device '%s (%s)' found", + command_print(CMD, "NAND flash device '%s (%s)' found", p->device->name, p->manufacturer->name); } @@ -189,7 +189,7 @@ COMMAND_HANDLER(handle_nand_erase_command) retval = nand_erase(p, offset, offset + length - 1); if (retval == ERROR_OK) { - command_print(CMD_CTX, "erased blocks %lu to %lu " + command_print(CMD, "erased blocks %lu to %lu " "on NAND flash device #%s '%s'", offset, offset + length - 1, CMD_ARGV[0], p->device->name); @@ -233,7 +233,7 @@ COMMAND_HANDLER(handle_nand_check_bad_blocks_command) retval = nand_build_bbt(p, first, last); if (retval == ERROR_OK) { - command_print(CMD_CTX, "checked NAND flash device for bad blocks, " + command_print(CMD, "checked NAND flash device for bad blocks, " "use \"nand info\" command to list blocks"); } @@ -253,7 +253,7 @@ COMMAND_HANDLER(handle_nand_write_command) while (s.size > 0) { int bytes_read = nand_fileio_read(nand, &s); if (bytes_read <= 0) { - command_print(CMD_CTX, "error while reading file"); + command_print(CMD, "error while reading file"); nand_fileio_cleanup(&s); return ERROR_FAIL; } @@ -262,7 +262,7 @@ COMMAND_HANDLER(handle_nand_write_command) retval = nand_write_page(nand, s.address / nand->page_size, s.page, s.page_size, s.oob, s.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "failed writing file %s " + command_print(CMD, "failed writing file %s " "to NAND flash %s at offset 0x%8.8" PRIx32, CMD_ARGV[1], CMD_ARGV[0], s.address); nand_fileio_cleanup(&s); @@ -272,7 +272,7 @@ COMMAND_HANDLER(handle_nand_write_command) } if (nand_fileio_finish(&s) == ERROR_OK) { - command_print(CMD_CTX, "wrote file %s to NAND flash %s up to " + command_print(CMD, "wrote file %s to NAND flash %s up to " "offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", CMD_ARGV[1], CMD_ARGV[0], s.address, duration_elapsed(&s.bench), duration_kbps(&s.bench, total_bytes)); @@ -294,7 +294,7 @@ COMMAND_HANDLER(handle_nand_verify_command) dev.address = file.address; dev.size = file.size; dev.oob_format = file.oob_format; - retval = nand_fileio_start(CMD_CTX, nand, NULL, FILEIO_NONE, &dev); + retval = nand_fileio_start(CMD, nand, NULL, FILEIO_NONE, &dev); if (ERROR_OK != retval) return retval; @@ -302,7 +302,7 @@ COMMAND_HANDLER(handle_nand_verify_command) retval = nand_read_page(nand, dev.address / dev.page_size, dev.page, dev.page_size, dev.oob, dev.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "reading NAND flash page failed"); + command_print(CMD, "reading NAND flash page failed"); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); return retval; @@ -310,7 +310,7 @@ COMMAND_HANDLER(handle_nand_verify_command) int bytes_read = nand_fileio_read(nand, &file); if (bytes_read <= 0) { - command_print(CMD_CTX, "error while reading file"); + command_print(CMD, "error while reading file"); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); return ERROR_FAIL; @@ -318,7 +318,7 @@ COMMAND_HANDLER(handle_nand_verify_command) if ((dev.page && memcmp(dev.page, file.page, dev.page_size)) || (dev.oob && memcmp(dev.oob, file.oob, dev.oob_size))) { - command_print(CMD_CTX, "NAND flash contents differ " + command_print(CMD, "NAND flash contents differ " "at 0x%8.8" PRIx32, dev.address); nand_fileio_cleanup(&dev); nand_fileio_cleanup(&file); @@ -330,7 +330,7 @@ COMMAND_HANDLER(handle_nand_verify_command) } if (nand_fileio_finish(&file) == ERROR_OK) { - command_print(CMD_CTX, "verified file %s in NAND flash %s " + command_print(CMD, "verified file %s in NAND flash %s " "up to offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", CMD_ARGV[1], CMD_ARGV[0], dev.address, duration_elapsed(&file.bench), duration_kbps(&file.bench, dev.size)); @@ -354,7 +354,7 @@ COMMAND_HANDLER(handle_nand_dump_command) retval = nand_read_page(nand, s.address / nand->page_size, s.page, s.page_size, s.oob, s.oob_size); if (ERROR_OK != retval) { - command_print(CMD_CTX, "reading NAND flash page failed"); + command_print(CMD, "reading NAND flash page failed"); nand_fileio_cleanup(&s); return retval; } @@ -374,7 +374,7 @@ COMMAND_HANDLER(handle_nand_dump_command) return retval; if (nand_fileio_finish(&s) == ERROR_OK) { - command_print(CMD_CTX, "dumped %zu bytes in %fs (%0.3f KiB/s)", + command_print(CMD, "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize, duration_elapsed(&s.bench), duration_kbps(&s.bench, filesize)); } @@ -392,7 +392,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command) return retval; if (NULL == p->device) { - command_print(CMD_CTX, "#%s: not probed", CMD_ARGV[0]); + command_print(CMD, "#%s: not probed", CMD_ARGV[0]); return ERROR_OK; } @@ -400,7 +400,7 @@ COMMAND_HANDLER(handle_nand_raw_access_command) COMMAND_PARSE_ENABLE(CMD_ARGV[1], p->use_raw); const char *msg = p->use_raw ? "enabled" : "disabled"; - command_print(CMD_CTX, "raw access is %s", msg); + command_print(CMD, "raw access is %s", msg); return ERROR_OK; } @@ -411,6 +411,7 @@ static const struct command_registration nand_exec_command_handlers[] = { .handler = handle_nand_list_command, .mode = COMMAND_EXEC, .help = "list configured NAND flash devices", + .usage = "", }, { .name = "info", @@ -500,15 +501,15 @@ COMMAND_HANDLER(handle_nand_init_command) static int nand_list_walker(struct nand_flash_controller *c, void *x) { - struct command_context *cmd_ctx = x; - command_print(cmd_ctx, " %s", c->name); + struct command_invocation *cmd = x; + command_print(cmd, " %s", c->name); return ERROR_OK; } COMMAND_HANDLER(handle_nand_list_drivers) { - command_print(CMD_CTX, "Available NAND flash controller drivers:"); - return nand_driver_walk(&nand_list_walker, CMD_CTX); + command_print(CMD, "Available NAND flash controller drivers:"); + return nand_driver_walk(&nand_list_walker, CMD); } static COMMAND_HELPER(create_nand_device, const char *bank_name, diff --git a/src/flash/nor/Makefile.am b/src/flash/nor/Makefile.am index 135128e..34f91ce 100644 --- a/src/flash/nor/Makefile.am +++ b/src/flash/nor/Makefile.am @@ -63,6 +63,7 @@ NOR_DRIVERS = \ %D%/str7x.c \ %D%/str9x.c \ %D%/str9xpec.c \ + %D%/swm050.c \ %D%/tms470.c \ %D%/virtual.c \ %D%/w600.c \ diff --git a/src/flash/nor/ambiqmicro.c b/src/flash/nor/ambiqmicro.c index a536d54..b1e3e72 100644 --- a/src/flash/nor/ambiqmicro.c +++ b/src/flash/nor/ambiqmicro.c @@ -791,9 +791,9 @@ COMMAND_HANDLER(ambiqmicro_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "ambiqmicro mass erase complete"); + command_print(CMD, "ambiqmicro mass erase complete"); } else - command_print(CMD_CTX, "ambiqmicro mass erase failed"); + command_print(CMD, "ambiqmicro mass erase failed"); return ERROR_OK; } @@ -815,9 +815,9 @@ COMMAND_HANDLER(ambiqmicro_handle_page_erase_command) return retval; if (ambiqmicro_erase(bank, first, last) == ERROR_OK) - command_print(CMD_CTX, "ambiqmicro page erase complete"); + command_print(CMD, "ambiqmicro page erase complete"); else - command_print(CMD_CTX, "ambiqmicro page erase failed"); + command_print(CMD, "ambiqmicro page erase failed"); return ERROR_OK; } @@ -838,7 +838,7 @@ COMMAND_HANDLER(ambiqmicro_handle_program_otp_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], offset); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], count); - command_print(CMD_CTX, "offset=0x%08x count=%d", offset, count); + command_print(CMD, "offset=0x%08x count=%d", offset, count); CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); diff --git a/src/flash/nor/at91sam3.c b/src/flash/nor/at91sam3.c index 2d61a87..2457c15 100644 --- a/src/flash/nor/at91sam3.c +++ b/src/flash/nor/at91sam3.c @@ -249,14 +249,14 @@ struct sam3_reg_list { static struct sam3_chip *all_sam3_chips; -static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) +static struct sam3_chip *get_current_sam3(struct command_invocation *cmd) { struct target *t; static struct sam3_chip *p; - t = get_current_target(cmd_ctx); + t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd_ctx, "No current target?"); + command_print(cmd, "No current target?"); return NULL; } @@ -264,7 +264,7 @@ static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd_ctx, "No SAM3 chips exist?"); + command_print(cmd, "No SAM3 chips exist?"); return NULL; } @@ -273,7 +273,7 @@ static struct sam3_chip *get_current_sam3(struct command_context *cmd_ctx) return p; p = p->next; } - command_print(cmd_ctx, "Cannot find SAM3 chip?"); + command_print(cmd, "Cannot find SAM3 chip?"); return NULL; } @@ -3538,7 +3538,7 @@ done: COMMAND_HANDLER(sam3_handle_info_command) { struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; @@ -3549,7 +3549,7 @@ COMMAND_HANDLER(sam3_handle_info_command) if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(CMD_CTX, + command_print(CMD, "Please define bank %d via command: flash bank %s ... ", x, at91sam3_flash.name); @@ -3598,7 +3598,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) int r, who; struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; @@ -3608,7 +3608,7 @@ COMMAND_HANDLER(sam3_handle_gpnvm_command) } if (pChip->details.bank[0].pBank == NULL) { - command_print(CMD_CTX, "Bank0 must be defined first via: flash bank %s ...", + command_print(CMD, "Bank0 must be defined first via: flash bank %s ...", at91sam3_flash.name); return ERROR_FAIL; } @@ -3647,22 +3647,22 @@ showall: r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "sam3-gpnvm%u: %u", x, v); + command_print(CMD, "sam3-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); - command_print(CMD_CTX, "sam3-gpnvm%u: %u", who, v); + command_print(CMD, "sam3-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "sam3-gpnvm invalid GPNVM: %u", who); + command_print(CMD, "sam3-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "Missing GPNVM number"); + command_print(CMD, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3672,7 +3672,7 @@ showall: (0 == strcmp("clear", CMD_ARGV[0]))) /* quietly accept both */ r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); else { - command_print(CMD_CTX, "Unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "Unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -3682,7 +3682,7 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) { struct sam3_chip *pChip; - pChip = get_current_sam3(CMD_CTX); + pChip = get_current_sam3(CMD); if (!pChip) return ERROR_OK; @@ -3697,7 +3697,7 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v); if (v > 200000) { /* absurd slow clock of 200Khz? */ - command_print(CMD_CTX, "Absurd/illegal slow clock freq: %d\n", (int)(v)); + command_print(CMD, "Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; } pChip->cfg.slow_freq = v; @@ -3705,11 +3705,11 @@ COMMAND_HANDLER(sam3_handle_slowclk_command) } default: /* error */ - command_print(CMD_CTX, "Too many parameters"); + command_print(CMD, "Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(CMD_CTX, "Slowclk freq: %d.%03dkhz", + command_print(CMD, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq / 1000), (int)(pChip->cfg.slow_freq % 1000)); return ERROR_OK; @@ -3731,6 +3731,7 @@ static const struct command_registration at91sam3_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91sam3 chip" "and its flash configuration.", + .usage = "", }, { .name = "slowclk", diff --git a/src/flash/nor/at91sam4.c b/src/flash/nor/at91sam4.c index 446f798..621754c 100644 --- a/src/flash/nor/at91sam4.c +++ b/src/flash/nor/at91sam4.c @@ -228,14 +228,14 @@ struct sam4_reg_list { static struct sam4_chip *all_sam4_chips; -static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) +static struct sam4_chip *get_current_sam4(struct command_invocation *cmd) { struct target *t; static struct sam4_chip *p; - t = get_current_target(cmd_ctx); + t = get_current_target(cmd->ctx); if (!t) { - command_print(cmd_ctx, "No current target?"); + command_print(cmd, "No current target?"); return NULL; } @@ -243,7 +243,7 @@ static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) if (!p) { /* this should not happen */ /* the command is not registered until the chip is created? */ - command_print(cmd_ctx, "No SAM4 chips exist?"); + command_print(cmd, "No SAM4 chips exist?"); return NULL; } @@ -252,7 +252,7 @@ static struct sam4_chip *get_current_sam4(struct command_context *cmd_ctx) return p; p = p->next; } - command_print(cmd_ctx, "Cannot find SAM4 chip?"); + command_print(cmd, "Cannot find SAM4 chip?"); return NULL; } @@ -3018,7 +3018,7 @@ done: COMMAND_HANDLER(sam4_handle_info_command) { struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; @@ -3029,7 +3029,7 @@ COMMAND_HANDLER(sam4_handle_info_command) if (pChip->details.bank[0].pBank == NULL) { x = 0; need_define: - command_print(CMD_CTX, + command_print(CMD, "Please define bank %d via command: flash bank %s ... ", x, at91sam4_flash.name); @@ -3078,7 +3078,7 @@ COMMAND_HANDLER(sam4_handle_gpnvm_command) int r, who; struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; @@ -3088,7 +3088,7 @@ COMMAND_HANDLER(sam4_handle_gpnvm_command) } if (pChip->details.bank[0].pBank == NULL) { - command_print(CMD_CTX, "Bank0 must be defined first via: flash bank %s ...", + command_print(CMD, "Bank0 must be defined first via: flash bank %s ...", at91sam4_flash.name); return ERROR_FAIL; } @@ -3127,23 +3127,23 @@ showall: r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "sam4-gpnvm%u: %u", x, v); + command_print(CMD, "sam4-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)(who)) < pChip->details.n_gpnvms)) { r = FLASHD_GetGPNVM(&(pChip->details.bank[0]), who, &v); if (r == ERROR_OK) - command_print(CMD_CTX, "sam4-gpnvm%u: %u", who, v); + command_print(CMD, "sam4-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "sam4-gpnvm invalid GPNVM: %u", who); + command_print(CMD, "sam4-gpnvm invalid GPNVM: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "Missing GPNVM number"); + command_print(CMD, "Missing GPNVM number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3153,7 +3153,7 @@ showall: (0 == strcmp("clear", CMD_ARGV[0]))) /* quietly accept both */ r = FLASHD_ClrGPNVM(&(pChip->details.bank[0]), who); else { - command_print(CMD_CTX, "Unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "Unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; @@ -3163,7 +3163,7 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) { struct sam4_chip *pChip; - pChip = get_current_sam4(CMD_CTX); + pChip = get_current_sam4(CMD); if (!pChip) return ERROR_OK; @@ -3178,7 +3178,7 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], v); if (v > 200000) { /* absurd slow clock of 200Khz? */ - command_print(CMD_CTX, "Absurd/illegal slow clock freq: %d\n", (int)(v)); + command_print(CMD, "Absurd/illegal slow clock freq: %d\n", (int)(v)); return ERROR_COMMAND_SYNTAX_ERROR; } pChip->cfg.slow_freq = v; @@ -3186,11 +3186,11 @@ COMMAND_HANDLER(sam4_handle_slowclk_command) } default: /* error */ - command_print(CMD_CTX, "Too many parameters"); + command_print(CMD, "Too many parameters"); return ERROR_COMMAND_SYNTAX_ERROR; break; } - command_print(CMD_CTX, "Slowclk freq: %d.%03dkhz", + command_print(CMD, "Slowclk freq: %d.%03dkhz", (int)(pChip->cfg.slow_freq / 1000), (int)(pChip->cfg.slow_freq % 1000)); return ERROR_OK; @@ -3212,6 +3212,7 @@ static const struct command_registration at91sam4_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91sam4 chip" "and its flash configuration.", + .usage = "", }, { .name = "slowclk", diff --git a/src/flash/nor/at91sam4l.c b/src/flash/nor/at91sam4l.c index 1c2402f..d356398 100644 --- a/src/flash/nor/at91sam4l.c +++ b/src/flash/nor/at91sam4l.c @@ -668,7 +668,8 @@ static const struct command_registration at91sam4l_exec_command_handlers[] = { .name = "smap_reset_deassert", .handler = sam4l_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "deasert internal reset held by SMAP" + .help = "deassert internal reset held by SMAP", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/at91sam7.c b/src/flash/nor/at91sam7.c index 15b93a2..232260b 100644 --- a/src/flash/nor/at91sam7.c +++ b/src/flash/nor/at91sam7.c @@ -1067,7 +1067,7 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) if (bank == NULL) return ERROR_FLASH_BANK_INVALID; if (strcmp(bank->driver->name, "at91sam7")) { - command_print(CMD_CTX, "not an at91sam7 flash bank '%s'", CMD_ARGV[0]); + command_print(CMD, "not an at91sam7 flash bank '%s'", CMD_ARGV[0]); return ERROR_FLASH_BANK_INVALID; } if (bank->target->state != TARGET_HALTED) { @@ -1091,7 +1091,7 @@ COMMAND_HANDLER(at91sam7_handle_gpnvm_command) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], bit); if ((bit < 0) || (bit >= at91sam7_info->num_nvmbits)) { - command_print(CMD_CTX, + command_print(CMD, "gpnvm bit '#%s' is out of bounds for target %s", CMD_ARGV[0], at91sam7_info->target_name); diff --git a/src/flash/nor/at91samd.c b/src/flash/nor/at91samd.c index ad0da5d..b6cff9a 100644 --- a/src/flash/nor/at91samd.c +++ b/src/flash/nor/at91samd.c @@ -947,9 +947,9 @@ COMMAND_HANDLER(samd_handle_chip_erase_command) * perform the erase. */ res = target_write_u8(target, SAMD_DSU + SAMD_DSU_CTRL_EXT, (1<<4)); if (res == ERROR_OK) - command_print(CMD_CTX, "chip erase started"); + command_print(CMD, "chip erase started"); else - command_print(CMD_CTX, "write to DSU CTRL failed"); + command_print(CMD, "write to DSU CTRL failed"); } return res; @@ -961,7 +961,7 @@ COMMAND_HANDLER(samd_handle_set_security_command) struct target *target = get_current_target(CMD_CTX); if (CMD_ARGC < 1 || (CMD_ARGC >= 1 && (strcmp(CMD_ARGV[0], "enable")))) { - command_print(CMD_CTX, "supply the \"enable\" argument to proceed."); + command_print(CMD, "supply the \"enable\" argument to proceed."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -975,9 +975,9 @@ COMMAND_HANDLER(samd_handle_set_security_command) /* Check (and clear) error conditions */ if (res == ERROR_OK) - command_print(CMD_CTX, "chip secured on next power-cycle"); + command_print(CMD, "chip secured on next power-cycle"); else - command_print(CMD_CTX, "failed to secure chip"); + command_print(CMD, "failed to secure chip"); } return res; @@ -1008,7 +1008,7 @@ COMMAND_HANDLER(samd_handle_eeprom_command) } if (code > 6) { - command_print(CMD_CTX, "Invalid EEPROM size. Please see " + command_print(CMD, "Invalid EEPROM size. Please see " "datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1022,10 +1022,10 @@ COMMAND_HANDLER(samd_handle_eeprom_command) uint32_t size = ((val >> 4) & 0x7); /* grab size code */ if (size == 0x7) - command_print(CMD_CTX, "EEPROM is disabled"); + command_print(CMD, "EEPROM is disabled"); else { /* Otherwise, 6 is 256B, 0 is 16KB */ - command_print(CMD_CTX, "EEPROM size is %u bytes", + command_print(CMD, "EEPROM size is %u bytes", (2 << (13 - size))); } } @@ -1038,7 +1038,7 @@ COMMAND_HANDLER(samd_handle_eeprom_command) static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value) { if (num >= CMD_ARGC) { - command_print(CMD_CTX, "Too few Arguments."); + command_print(CMD, "Too few Arguments."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1049,12 +1049,12 @@ static COMMAND_HELPER(get_u64_from_hexarg, unsigned int num, uint64_t *value) *value = strtoull(&(CMD_ARGV[num][2]), &check, 16); if ((value == 0 && errno == ERANGE) || check == NULL || *check != 0) { - command_print(CMD_CTX, "Invalid 64-bit hex value in argument %d.", + command_print(CMD, "Invalid 64-bit hex value in argument %d.", num + 1); return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Argument %d needs to be a hex value.", num + 1); + command_print(CMD, "Argument %d needs to be a hex value.", num + 1); return ERROR_COMMAND_SYNTAX_ERROR; } return ERROR_OK; @@ -1067,7 +1067,7 @@ COMMAND_HANDLER(samd_handle_nvmuserrow_command) if (target) { if (CMD_ARGC > 2) { - command_print(CMD_CTX, "Too much Arguments given."); + command_print(CMD, "Too much Arguments given."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1105,7 +1105,7 @@ COMMAND_HANDLER(samd_handle_nvmuserrow_command) uint64_t value; res = read_userrow(target, &value); if (res == ERROR_OK) - command_print(CMD_CTX, "NVMUSERROW: 0x%016"PRIX64, value); + command_print(CMD, "NVMUSERROW: 0x%016"PRIX64, value); else LOG_ERROR("NVMUSERROW could not be read."); } @@ -1145,7 +1145,7 @@ COMMAND_HANDLER(samd_handle_bootloader_command) } if (code > 6) { - command_print(CMD_CTX, "Invalid bootloader size. Please " + command_print(CMD, "Invalid bootloader size. Please " "see datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1166,7 +1166,7 @@ COMMAND_HANDLER(samd_handle_bootloader_command) nb = (2 << (8 - size)) * page_size; /* There are 4 pages per row */ - command_print(CMD_CTX, "Bootloader size is %" PRIu32 " bytes (%" PRIu32 " rows)", + command_print(CMD, "Bootloader size is %" PRIu32 " bytes (%" PRIu32 " rows)", nb, (uint32_t)(nb / (page_size * 4))); } } @@ -1217,7 +1217,8 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .name = "dsu_reset_deassert", .handler = samd_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "Deasert internal reset held by DSU." + .help = "Deassert internal reset held by DSU.", + .usage = "", }, { .name = "info", @@ -1225,6 +1226,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Print information about the current at91samd chip " "and its flash configuration.", + .usage = "", }, { .name = "chip-erase", @@ -1232,6 +1234,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { .mode = COMMAND_EXEC, .help = "Erase the entire Flash by using the Chip-" "Erase feature in the Device Service Unit (DSU).", + .usage = "", }, { .name = "set-security", @@ -1241,6 +1244,7 @@ static const struct command_registration at91samd_exec_command_handlers[] = { "This makes it impossible to read the Flash contents. " "The only way to undo this is to issue the chip-erase " "command.", + .usage = "'enable'", }, { .name = "eeprom", diff --git a/src/flash/nor/atsame5.c b/src/flash/nor/atsame5.c index 833177e..eac7847 100644 --- a/src/flash/nor/atsame5.c +++ b/src/flash/nor/atsame5.c @@ -765,9 +765,9 @@ COMMAND_HANDLER(same5_handle_chip_erase_command) * perform the erase. */ int res = target_write_u8(target, SAMD_DSU + SAMD_DSU_CTRL_EXT, (1<<4)); if (res == ERROR_OK) - command_print(CMD_CTX, "chip erase started"); + command_print(CMD, "chip erase started"); else - command_print(CMD_CTX, "write to DSU CTRL failed"); + command_print(CMD, "write to DSU CTRL failed"); return res; } @@ -781,7 +781,7 @@ COMMAND_HANDLER(same5_handle_userpage_command) return ERROR_FAIL; if (CMD_ARGC > 2) { - command_print(CMD_CTX, "Too much Arguments given."); + command_print(CMD, "Too much Arguments given."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -806,7 +806,7 @@ COMMAND_HANDLER(same5_handle_userpage_command) int res2 = target_read_memory(target, SAMD_USER_ROW, 4, 2, buffer); if (res2 == ERROR_OK) { uint64_t value = target_buffer_get_u64(target, buffer); - command_print(CMD_CTX, "USER PAGE: 0x%016"PRIX64, value); + command_print(CMD, "USER PAGE: 0x%016"PRIX64, value); } else { LOG_ERROR("USER PAGE could not be read."); } @@ -829,7 +829,7 @@ COMMAND_HANDLER(same5_handle_bootloader_command) unsigned long size = strtoul(CMD_ARGV[0], NULL, 0); uint32_t code = (size + 8191) / 8192; if (code > 15) { - command_print(CMD_CTX, "Invalid bootloader size. Please " + command_print(CMD, "Invalid bootloader size. Please " "see datasheet for a list valid sizes."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -842,7 +842,7 @@ COMMAND_HANDLER(same5_handle_bootloader_command) if (res2 == ERROR_OK) { uint32_t code = (val >> 26) & 0xf; /* grab size code */ uint32_t size = (15 - code) * 8192; - command_print(CMD_CTX, "Bootloader protected in the first %" + command_print(CMD, "Bootloader protected in the first %" PRIu32 " bytes", size); } @@ -893,12 +893,14 @@ COMMAND_HANDLER(samd_handle_reset_deassert) static const struct command_registration same5_exec_command_handlers[] = { { .name = "dsu_reset_deassert", + .usage = "", .handler = samd_handle_reset_deassert, .mode = COMMAND_EXEC, - .help = "Deasert internal reset held by DSU." + .help = "Deassert internal reset held by DSU." }, { .name = "chip-erase", + .usage = "", .handler = same5_handle_chip_erase_command, .mode = COMMAND_EXEC, .help = "Erase the entire Flash by using the Chip-" diff --git a/src/flash/nor/atsamv.c b/src/flash/nor/atsamv.c index 5beeefc..d6f1a0a 100644 --- a/src/flash/nor/atsamv.c +++ b/src/flash/nor/atsamv.c @@ -672,22 +672,22 @@ showall: r = samv_get_gpnvm(target, x, &v); if (r != ERROR_OK) break; - command_print(CMD_CTX, "samv-gpnvm%u: %u", x, v); + command_print(CMD, "samv-gpnvm%u: %u", x, v); } return r; } if ((who >= 0) && (((unsigned)who) < SAMV_NUM_GPNVM_BITS)) { r = samv_get_gpnvm(target, who, &v); - command_print(CMD_CTX, "samv-gpnvm%u: %u", who, v); + command_print(CMD, "samv-gpnvm%u: %u", who, v); return r; } else { - command_print(CMD_CTX, "invalid gpnvm: %u", who); + command_print(CMD, "invalid gpnvm: %u", who); return ERROR_COMMAND_SYNTAX_ERROR; } } if (who == -1) { - command_print(CMD_CTX, "missing gpnvm number"); + command_print(CMD, "missing gpnvm number"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -696,7 +696,7 @@ showall: else if (!strcmp("clr", CMD_ARGV[0]) || !strcmp("clear", CMD_ARGV[0])) r = samv_clear_gpnvm(target, who); else { - command_print(CMD_CTX, "unknown command: %s", CMD_ARGV[0]); + command_print(CMD, "unknown command: %s", CMD_ARGV[0]); r = ERROR_COMMAND_SYNTAX_ERROR; } return r; diff --git a/src/flash/nor/avrf.c b/src/flash/nor/avrf.c index 6969f77..178567e 100644 --- a/src/flash/nor/avrf.c +++ b/src/flash/nor/avrf.c @@ -433,9 +433,9 @@ COMMAND_HANDLER(avrf_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "avr mass erase complete"); + command_print(CMD, "avr mass erase complete"); } else - command_print(CMD_CTX, "avr mass erase failed"); + command_print(CMD, "avr mass erase failed"); LOG_DEBUG("%s", __func__); return ERROR_OK; diff --git a/src/flash/nor/core.h b/src/flash/nor/core.h index f6bd0cf..ff5cb60 100644 --- a/src/flash/nor/core.h +++ b/src/flash/nor/core.h @@ -45,9 +45,12 @@ struct flash_sector { uint32_t size; /** * Indication of erasure status: 0 = not erased, 1 = erased, - * other = unknown. Set by @c flash_driver_s::erase_check. + * other = unknown. Set by @c flash_driver_s::erase_check only. * - * Flag is not used in protection block + * This information must be considered stale immediately. + * Don't set it in flash_driver_s::erase or a device mass_erase + * Don't clear it in flash_driver_s::write + * The flag is not used in a protection block */ int is_erased; /** @@ -118,7 +121,7 @@ struct flash_bank { /** * The number of sectors on this chip. This value will - * be set intially to 0, and the flash driver must set this to + * be set initially to 0, and the flash driver must set this to * some non-zero value during "probe()" or "auto_probe()". */ int num_sectors; @@ -127,12 +130,12 @@ struct flash_bank { /** * The number of protection blocks in this bank. This value - * is set intially to 0 and sectors are used as protection blocks. + * is set initially to 0 and sectors are used as protection blocks. * Driver probe can set protection blocks array to work with * protection granularity different than sector size. */ int num_prot_blocks; - /** Array of protection blocks, allocated and initilized by the flash driver */ + /** Array of protection blocks, allocated and initialized by the flash driver */ struct flash_sector *prot_blocks; struct flash_bank *next; /**< The next flash bank on this chip */ @@ -239,8 +242,8 @@ struct flash_bank *get_flash_bank_by_name_noprobe(const char *name); */ int get_flash_bank_by_num(int num, struct flash_bank **bank); /** - * Retreives @a bank from a command argument, reporting errors parsing - * the bank identifier or retreiving the specified bank. The bank + * Retrieves @a bank from a command argument, reporting errors parsing + * the bank identifier or retrieving the specified bank. The bank * may be identified by its bank number or by @c name.instance, where * @a instance is driver-specific. * @param name_index The index to the string in args containing the diff --git a/src/flash/nor/drivers.c b/src/flash/nor/drivers.c index 955d149..551f389 100644 --- a/src/flash/nor/drivers.c +++ b/src/flash/nor/drivers.c @@ -77,6 +77,7 @@ extern const struct flash_driver stmsmi_flash; extern const struct flash_driver str7x_flash; extern const struct flash_driver str9x_flash; extern const struct flash_driver str9xpec_flash; +extern const struct flash_driver swm050_flash; extern const struct flash_driver tms470_flash; extern const struct flash_driver virtual_flash; extern const struct flash_driver w600_flash; @@ -146,6 +147,7 @@ static const struct flash_driver * const flash_drivers[] = { &str7x_flash, &str9x_flash, &str9xpec_flash, + &swm050_flash, &tms470_flash, &virtual_flash, &xcf_flash, diff --git a/src/flash/nor/efm32.c b/src/flash/nor/efm32.c index d2ac3a8..83d133f 100644 --- a/src/flash/nor/efm32.c +++ b/src/flash/nor/efm32.c @@ -1093,7 +1093,7 @@ COMMAND_HANDLER(efm32x_handle_debuglock_command) return retval; } - command_print(CMD_CTX, "efm32x debug interface locked, reset the device to apply"); + command_print(CMD, "efm32x debug interface locked, reset the device to apply"); return ERROR_OK; } diff --git a/src/flash/nor/em357.c b/src/flash/nor/em357.c index e6b2728..38fb731 100644 --- a/src/flash/nor/em357.c +++ b/src/flash/nor/em357.c @@ -776,7 +776,7 @@ COMMAND_HANDLER(em357_handle_lock_command) } if (em357_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to erase options"); + command_print(CMD, "em357 failed to erase options"); return ERROR_OK; } @@ -784,11 +784,11 @@ COMMAND_HANDLER(em357_handle_lock_command) em357_info->option_bytes.RDP = 0; if (em357_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to lock device"); + command_print(CMD, "em357 failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "em357 locked"); + command_print(CMD, "em357 locked"); return ERROR_OK; } @@ -813,16 +813,16 @@ COMMAND_HANDLER(em357_handle_unlock_command) } if (em357_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to unlock device"); + command_print(CMD, "em357 failed to unlock device"); return ERROR_OK; } if (em357_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "em357 failed to lock device"); + command_print(CMD, "em357 failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "em357 unlocked.\n" + command_print(CMD, "em357 unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -886,9 +886,9 @@ COMMAND_HANDLER(em357_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "em357 mass erase complete"); + command_print(CMD, "em357 mass erase complete"); } else - command_print(CMD_CTX, "em357 mass erase failed"); + command_print(CMD, "em357 mass erase failed"); return retval; } diff --git a/src/flash/nor/esirisc_flash.c b/src/flash/nor/esirisc_flash.c index 948d001..3bed065 100644 --- a/src/flash/nor/esirisc_flash.c +++ b/src/flash/nor/esirisc_flash.c @@ -92,7 +92,7 @@ #endif #define CONTROL_TIMEOUT 5000 /* 5s */ -#define PAGE_SIZE 4096 +#define FLASH_PAGE_SIZE 4096 #define PB_MAX 32 #define NUM_NS_PER_S 1000000000ULL @@ -264,7 +264,7 @@ static int esirisc_flash_erase(struct flash_bank *bank, int first, int last) (void)esirisc_flash_disable_protect(bank); for (int page = first; page < last; ++page) { - uint32_t address = page * PAGE_SIZE; + uint32_t address = page * FLASH_PAGE_SIZE; target_write_u32(target, esirisc_info->cfg + ADDRESS, address); @@ -464,8 +464,8 @@ static int esirisc_flash_probe(struct flash_bank *bank) if (target->state != TARGET_HALTED) return ERROR_TARGET_NOT_HALTED; - bank->num_sectors = bank->size / PAGE_SIZE; - bank->sectors = alloc_block_array(0, PAGE_SIZE, bank->num_sectors); + bank->num_sectors = bank->size / FLASH_PAGE_SIZE; + bank->sectors = alloc_block_array(0, FLASH_PAGE_SIZE, bank->num_sectors); retval = esirisc_flash_init(bank); if (retval != ERROR_OK) { @@ -516,7 +516,7 @@ COMMAND_HANDLER(handle_esirisc_flash_mass_erase_command) retval = esirisc_flash_mass_erase(bank); - command_print(CMD_CTX, "mass erase %s", + command_print(CMD, "mass erase %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; @@ -536,7 +536,7 @@ COMMAND_HANDLER(handle_esirisc_flash_ref_erase_command) retval = esirisc_flash_ref_erase(bank); - command_print(CMD_CTX, "erase reference cell %s", + command_print(CMD, "erase reference cell %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; diff --git a/src/flash/nor/faux.c b/src/flash/nor/faux.c index 49b6dcc..a894d03 100644 --- a/src/flash/nor/faux.c +++ b/src/flash/nor/faux.c @@ -109,6 +109,7 @@ static const struct command_registration faux_command_handlers[] = { .mode = COMMAND_ANY, .help = "faux flash command group", .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/fm3.c b/src/flash/nor/fm3.c index f2da2af..eeefa3f 100644 --- a/src/flash/nor/fm3.c +++ b/src/flash/nor/fm3.c @@ -958,9 +958,9 @@ COMMAND_HANDLER(fm3_handle_chip_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "fm3 chip erase complete"); + command_print(CMD, "fm3 chip erase complete"); } else { - command_print(CMD_CTX, "fm3 chip erase failed"); + command_print(CMD, "fm3 chip erase failed"); } return ERROR_OK; diff --git a/src/flash/nor/kinetis.c b/src/flash/nor/kinetis.c index 22c5d5c..687a337 100644 --- a/src/flash/nor/kinetis.c +++ b/src/flash/nor/kinetis.c @@ -2895,7 +2895,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) flex_nvm_partition_code = (uint8_t)((sim_fcfg1 >> 8) & 0x0f); switch (flex_nvm_partition_code) { case 0: - command_print(CMD_CTX, "No EEPROM backup, data flash only"); + command_print(CMD, "No EEPROM backup, data flash only"); break; case 1: case 2: @@ -2903,10 +2903,10 @@ COMMAND_HANDLER(kinetis_nvm_partition) case 4: case 5: case 6: - command_print(CMD_CTX, "EEPROM backup %d KB", 4 << flex_nvm_partition_code); + command_print(CMD, "EEPROM backup %d KB", 4 << flex_nvm_partition_code); break; case 8: - command_print(CMD_CTX, "No data flash, EEPROM backup only"); + command_print(CMD, "No data flash, EEPROM backup only"); break; case 0x9: case 0xA: @@ -2914,13 +2914,13 @@ COMMAND_HANDLER(kinetis_nvm_partition) case 0xC: case 0xD: case 0xE: - command_print(CMD_CTX, "data flash %d KB", 4 << (flex_nvm_partition_code & 7)); + command_print(CMD, "data flash %d KB", 4 << (flex_nvm_partition_code & 7)); break; case 0xf: - command_print(CMD_CTX, "No EEPROM backup, data flash only (DEPART not set)"); + command_print(CMD, "No EEPROM backup, data flash only (DEPART not set)"); break; default: - command_print(CMD_CTX, "Unsupported EEPROM backup size code 0x%02" PRIx8, flex_nvm_partition_code); + command_print(CMD, "Unsupported EEPROM backup size code 0x%02" PRIx8, flex_nvm_partition_code); } return ERROR_OK; @@ -2986,7 +2986,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) if (result != ERROR_OK) return result; - command_print(CMD_CTX, "FlexNVM partition set. Please reset MCU."); + command_print(CMD, "FlexNVM partition set. Please reset MCU."); if (k_chip) { first_nvm_bank = k_chip->num_pflash_blocks; @@ -2996,7 +2996,7 @@ COMMAND_HANDLER(kinetis_nvm_partition) k_chip->probed = false; } - command_print(CMD_CTX, "FlexNVM banks will be re-probed to set new data flash size."); + command_print(CMD, "FlexNVM banks will be re-probed to set new data flash size."); return ERROR_OK; } @@ -3015,12 +3015,12 @@ COMMAND_HANDLER(kinetis_fcf_source_handler) } if (allow_fcf_writes) { - command_print(CMD_CTX, "Arbitrary Flash Configuration Field writes enabled."); - command_print(CMD_CTX, "Protection info writes to FCF disabled."); + command_print(CMD, "Arbitrary Flash Configuration Field writes enabled."); + command_print(CMD, "Protection info writes to FCF disabled."); LOG_WARNING("BEWARE: incorrect flash configuration may permanently lock the device."); } else { - command_print(CMD_CTX, "Protection info writes to Flash Configuration Field enabled."); - command_print(CMD_CTX, "Arbitrary FCF writes disabled. Mode safe from unwanted locking of the device."); + command_print(CMD, "Protection info writes to Flash Configuration Field enabled."); + command_print(CMD, "Arbitrary FCF writes disabled. Mode safe from unwanted locking of the device."); } return ERROR_OK; @@ -3035,7 +3035,7 @@ COMMAND_HANDLER(kinetis_fopt_handler) fcf_fopt = (uint8_t)strtoul(CMD_ARGV[0], NULL, 0); fcf_fopt_configured = true; } else { - command_print(CMD_CTX, "FCF_FOPT 0x%02" PRIx8, fcf_fopt); + command_print(CMD, "FCF_FOPT 0x%02" PRIx8, fcf_fopt); } return ERROR_OK; @@ -3074,7 +3074,8 @@ static const struct command_registration kinetis_security_command_handlers[] = { .usage = "", .handler = kinetis_mdm_mass_erase, }, - { .name = "reset", + { + .name = "reset", .mode = COMMAND_EXEC, .help = "Issue a reset via the MDM-AP", .usage = "", @@ -3126,6 +3127,7 @@ static const struct command_registration kinetis_exec_command_handlers[] = { .mode = COMMAND_CONFIG, .help = "Driver creates additional banks if device with two/four flash blocks is probed", .handler = kinetis_create_banks_handler, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/lpc2000.c b/src/flash/nor/lpc2000.c index cb3f58e..2a69af6 100644 --- a/src/flash/nor/lpc2000.c +++ b/src/flash/nor/lpc2000.c @@ -1579,11 +1579,11 @@ COMMAND_HANDLER(lpc2000_handle_part_id_command) int status_code = get_lpc2000_part_id(bank, &part_id); if (status_code != 0x0) { if (status_code == ERROR_FLASH_OPERATION_FAILED) { - command_print(CMD_CTX, "no sufficient working area specified, can't access LPC2000 IAP interface"); + command_print(CMD, "no sufficient working area specified, can't access LPC2000 IAP interface"); } else - command_print(CMD_CTX, "lpc2000 IAP returned status code %i", status_code); + command_print(CMD, "lpc2000 IAP returned status code %i", status_code); } else - command_print(CMD_CTX, "lpc2000 part id: 0x%8.8" PRIx32, part_id); + command_print(CMD, "lpc2000 part id: 0x%8.8" PRIx32, part_id); return retval; } diff --git a/src/flash/nor/lpc2900.c b/src/flash/nor/lpc2900.c index c798e44..5412c93 100644 --- a/src/flash/nor/lpc2900.c +++ b/src/flash/nor/lpc2900.c @@ -501,7 +501,7 @@ COMMAND_HANDLER(lpc2900_handle_signature_command) if (status != ERROR_OK) return status; - command_print(CMD_CTX, "signature: 0x%8.8" PRIx32 + command_print(CMD, "signature: 0x%8.8" PRIx32 ":0x%8.8" PRIx32 ":0x%8.8" PRIx32 ":0x%8.8" PRIx32, @@ -595,11 +595,11 @@ COMMAND_HANDLER(lpc2900_handle_password_command) lpc2900_info->risky = !strcmp(CMD_ARGV[1], ISS_PASSWORD); if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Wrong password (use '%s')", ISS_PASSWORD); + command_print(CMD, "Wrong password (use '%s')", ISS_PASSWORD); return ERROR_COMMAND_ARGUMENT_INVALID; } - command_print(CMD_CTX, + command_print(CMD, "Potentially dangerous operation allowed in next command!"); return ERROR_OK; @@ -622,7 +622,7 @@ COMMAND_HANDLER(lpc2900_handle_write_custom_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed!"); + command_print(CMD, "Command execution not allowed!"); return ERROR_COMMAND_ARGUMENT_INVALID; } lpc2900_info->risky = 0; @@ -721,7 +721,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed! " + command_print(CMD, "Command execution not allowed! " "(use 'password' command first)"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -734,7 +734,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) if ((first >= bank->num_sectors) || (last >= bank->num_sectors) || (first > last)) { - command_print(CMD_CTX, "Illegal sector range"); + command_print(CMD, "Illegal sector range"); return ERROR_COMMAND_ARGUMENT_INVALID; } @@ -773,7 +773,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_sector_command) } } - command_print(CMD_CTX, + command_print(CMD, "Sectors security will become effective after next power cycle"); /* Update the sector security status */ @@ -803,7 +803,7 @@ COMMAND_HANDLER(lpc2900_handle_secure_jtag_command) /* Check if command execution is allowed. */ if (!lpc2900_info->risky) { - command_print(CMD_CTX, "Command execution not allowed! " + command_print(CMD, "Command execution not allowed! " "(use 'password' command first)"); return ERROR_COMMAND_ARGUMENT_INVALID; } diff --git a/src/flash/nor/max32xxx.c b/src/flash/nor/max32xxx.c index 12e3db9..3bf4b22 100644 --- a/src/flash/nor/max32xxx.c +++ b/src/flash/nor/max32xxx.c @@ -772,7 +772,7 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command) int retval = CALL_COMMAND_HANDLER(flash_command_get_bank, 0, &bank); if (CMD_ARGC < 1) { - command_print(CMD_CTX, "max32xxx mass_erase <bank>"); + command_print(CMD, "max32xxx mass_erase <bank>"); return ERROR_OK; } @@ -784,9 +784,9 @@ COMMAND_HANDLER(max32xxx_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "max32xxx mass erase complete"); + command_print(CMD, "max32xxx mass erase complete"); } else - command_print(CMD_CTX, "max32xxx mass erase failed"); + command_print(CMD, "max32xxx mass erase failed"); return ERROR_OK; } @@ -799,7 +799,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) uint32_t addr, len; if (CMD_ARGC != 3) { - command_print(CMD_CTX, "max32xxx protection_set <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_set <bank> <addr> <size>"); return ERROR_OK; } @@ -811,7 +811,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) /* Convert the range to the page numbers */ if (1 != sscanf(CMD_ARGV[1], "0x%"SCNx32, &addr)) { LOG_WARNING("Error parsing address"); - command_print(CMD_CTX, "max32xxx protection_set <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_set <bank> <addr> <size>"); return ERROR_FAIL; } /* Mask off the top portion on the address */ @@ -819,7 +819,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) if (1 != sscanf(CMD_ARGV[2], "0x%"SCNx32, &len)) { LOG_WARNING("Error parsing length"); - command_print(CMD_CTX, "max32xxx protection_set <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_set <bank> <addr> <size>"); return ERROR_FAIL; } @@ -840,9 +840,9 @@ COMMAND_HANDLER(max32xxx_handle_protection_set_command) len = addr + (len / info->sector_size) - 1; if (max32xxx_protect(bank, 1, addr, len) == ERROR_OK) - command_print(CMD_CTX, "max32xxx protection set complete"); + command_print(CMD, "max32xxx protection set complete"); else - command_print(CMD_CTX, "max32xxx protection set failed"); + command_print(CMD, "max32xxx protection set failed"); return ERROR_OK; } @@ -855,7 +855,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) uint32_t addr, len; if (CMD_ARGC != 3) { - command_print(CMD_CTX, "max32xxx protection_clr <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_clr <bank> <addr> <size>"); return ERROR_OK; } @@ -867,7 +867,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) /* Convert the range to the page numbers */ if (1 != sscanf(CMD_ARGV[1], "0x%"SCNx32, &addr)) { LOG_WARNING("Error parsing address"); - command_print(CMD_CTX, "max32xxx protection_clr <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_clr <bank> <addr> <size>"); return ERROR_FAIL; } /* Mask off the top portion on the address */ @@ -875,7 +875,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) if (1 != sscanf(CMD_ARGV[2], "0x%"SCNx32, &len)) { LOG_WARNING("Error parsing length"); - command_print(CMD_CTX, "max32xxx protection_clr <bank> <addr> <size>"); + command_print(CMD, "max32xxx protection_clr <bank> <addr> <size>"); return ERROR_FAIL; } @@ -896,9 +896,9 @@ COMMAND_HANDLER(max32xxx_handle_protection_clr_command) len = addr + (len / info->sector_size) - 1; if (max32xxx_protect(bank, 0, addr, len) == ERROR_OK) - command_print(CMD_CTX, "max32xxx protection clear complete"); + command_print(CMD, "max32xxx protection clear complete"); else - command_print(CMD_CTX, "max32xxx protection clear failed"); + command_print(CMD, "max32xxx protection clear failed"); return ERROR_OK; } @@ -911,7 +911,7 @@ COMMAND_HANDLER(max32xxx_handle_protection_check_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "max32xxx protection_check <bank>"); + command_print(CMD, "max32xxx protection_check <bank>"); return ERROR_OK; } @@ -977,6 +977,7 @@ static const struct command_registration max32xxx_command_handlers[] = { .mode = COMMAND_EXEC, .help = "max32xxx flash command group", .chain = max32xxx_exec_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/niietcm4.c b/src/flash/nor/niietcm4.c index b034ee1..7b67bb8 100644 --- a/src/flash/nor/niietcm4.c +++ b/src/flash/nor/niietcm4.c @@ -425,9 +425,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_read_byte_command) retval = target_read_u32(target, UFMD, &uflash_data); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "Read userflash %s region:\n" - "address = 0x%04x,\n" - "value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); + command_print(CMD, "Read userflash %s region:\n" + "address = 0x%04x,\n" + "value = 0x%02x.", CMD_ARGV[0], uflash_addr, uflash_data); return retval; } @@ -467,10 +467,10 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command) int page_num = uflash_addr/USERFLASH_PAGE_SIZE; - command_print(CMD_CTX, "Write userflash %s region:\n" - "address = 0x%04x,\n" - "value = 0x%02x.\n" - "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); + command_print(CMD, "Write userflash %s region:\n" + "address = 0x%04x,\n" + "value = 0x%02x.\n" + "Please wait ... ", CMD_ARGV[0], uflash_addr, uflash_data); /* dump */ uint32_t uflash_dump[USERFLASH_PAGE_SIZE]; niietcm4_dump_uflash_page(bank, uflash_dump, page_num, mem_type); @@ -483,7 +483,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_write_byte_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, page_num, mem_type); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -520,7 +520,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_full_erase_command) retval = niietcm4_uopstatus_check(bank); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "Userflash full erase done!"); + command_print(CMD, "Userflash full erase done!"); return retval; } @@ -563,7 +563,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_erase_command) return retval; } - command_print(CMD_CTX, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last); + command_print(CMD, "Erase %s userflash pages %d through %d done!", CMD_ARGV[0], first, last); return retval; } @@ -621,9 +621,9 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command) return retval; if (uflash_data & INFOWORD3_LOCK_IFB_UF) - command_print(CMD_CTX, "All sectors of info userflash are not protected!"); + command_print(CMD, "All sectors of info userflash are not protected!"); else - command_print(CMD_CTX, "All sectors of info userflash are protected!"); + command_print(CMD, "All sectors of info userflash are protected!"); } else { uflash_addr = UF_LOCK_ADDR; uflash_cmd = UFMC_MAGIC_KEY | UFMC_READ_IFB; @@ -645,10 +645,10 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_check_command) for (j = 0; j < 8; j++) { if (uflash_data & 0x1) - command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is not protected!", + command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is not protected!", i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE); else - command_print(CMD_CTX, "Userflash sector #%03d: 0x%04x (0x100) is protected!", + command_print(CMD, "Userflash sector #%03d: 0x%04x (0x100) is protected!", i*8+j, (i*8+j)*USERFLASH_PAGE_SIZE); uflash_data = uflash_data >> 1; } @@ -693,11 +693,11 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command) int set; if (strcmp("on", CMD_ARGV[3]) == 0) { - command_print(CMD_CTX, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ", + command_print(CMD, "Try to enable %s userflash sectors %d through %d protection. Please wait ... ", CMD_ARGV[0], first, last); set = 1; } else if (strcmp("off", CMD_ARGV[3]) == 0) { - command_print(CMD_CTX, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ", + command_print(CMD, "Try to disable %s userflash sectors %d through %d protection. Please wait ... ", CMD_ARGV[0], first, last); set = 0; } else @@ -707,7 +707,7 @@ COMMAND_HANDLER(niietcm4_handle_uflash_protect_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -733,10 +733,10 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command) int set; if (strcmp("on", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to enable bootflash info region remap. Please wait ..."); + command_print(CMD, "Try to enable bootflash info region remap. Please wait ..."); set = 1; } else if (strcmp("off", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to disable bootflash info region remap. Please wait ..."); + command_print(CMD, "Try to disable bootflash info region remap. Please wait ..."); set = 0; } else return ERROR_COMMAND_SYNTAX_ERROR; @@ -756,7 +756,7 @@ COMMAND_HANDLER(niietcm4_handle_bflash_info_remap_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -814,11 +814,11 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command) else return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "Try to configure external memory boot interface:\n" - "port = %s\n" - "pin = %s\n" - "func = %s\n" - "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]); + command_print(CMD, "Try to configure external memory boot interface:\n" + "port = %s\n" + "pin = %s\n" + "func = %s\n" + "Please wait ...", CMD_ARGV[0], CMD_ARGV[1], CMD_ARGV[2]); /* dump */ uint32_t uflash_dump[USERFLASH_PAGE_SIZE]; niietcm4_dump_uflash_page(bank, uflash_dump, 0, 1); @@ -833,7 +833,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_cfg_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -861,10 +861,10 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command) int set; if (strcmp("on", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to enable boot from external memory. Please wait ..."); + command_print(CMD, "Try to enable boot from external memory. Please wait ..."); set = 1; } else if (strcmp("off", CMD_ARGV[0]) == 0) { - command_print(CMD_CTX, "Try to disable boot from external memory. Please wait ..."); + command_print(CMD, "Try to disable boot from external memory. Please wait ..."); set = 0; } else return ERROR_COMMAND_SYNTAX_ERROR; @@ -884,7 +884,7 @@ COMMAND_HANDLER(niietcm4_handle_extmem_boot_command) /* write dump to userflash */ niietcm4_load_uflash_page(bank, uflash_dump, 0, 1); - command_print(CMD_CTX, "done!"); + command_print(CMD, "done!"); return retval; } @@ -900,7 +900,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command) return retval; struct target *target = bank->target; - command_print(CMD_CTX, "Try to perform service mode erase. Please wait ..."); + command_print(CMD, "Try to perform service mode erase. Please wait ..."); retval = target_write_u32(target, SERVICE_MODE_ERASE_ADDR, 1); if (retval != ERROR_OK) @@ -923,7 +923,7 @@ COMMAND_HANDLER(niietcm4_handle_service_mode_erase_command) } busy_sleep(1); /* can use busy sleep for short times. */ } - command_print(CMD_CTX, "done! All data erased."); + command_print(CMD, "done! All data erased."); return retval; } @@ -938,7 +938,7 @@ COMMAND_HANDLER(niietcm4_handle_driver_info_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "niietcm4 flash driver\n" + command_print(CMD, "niietcm4 flash driver\n" "version: %d.%d\n" "author: Bogdan Kolbov\n" "mail: kolbov@niiet.ru", diff --git a/src/flash/nor/nrf5.c b/src/flash/nor/nrf5.c index aab80f9..4041bfb 100644 --- a/src/flash/nor/nrf5.c +++ b/src/flash/nor/nrf5.c @@ -1118,6 +1118,7 @@ static const struct command_registration nrf5_exec_command_handlers[] = { .handler = nrf5_handle_mass_erase_command, .mode = COMMAND_EXEC, .help = "Erase all flash contents of the chip.", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/numicro.c b/src/flash/nor/numicro.c index 8d8abd5..c62af04 100644 --- a/src/flash/nor/numicro.c +++ b/src/flash/nor/numicro.c @@ -1827,11 +1827,11 @@ COMMAND_HANDLER(numicro_handle_chip_erase_command) retval = numicro_fmc_cmd(target, ISPCMD_CHIPERASE, 0, 0, &rdat); if (retval != ERROR_OK) { - command_print(CMD_CTX, "numicro chip_erase failed"); + command_print(CMD, "numicro chip_erase failed"); return retval; } - command_print(CMD_CTX, "numicro chip_erase complete"); + command_print(CMD, "numicro chip_erase complete"); return ERROR_OK; } @@ -1856,6 +1856,7 @@ static const struct command_registration numicro_exec_command_handlers[] = { .handler = numicro_handle_chip_erase_command, .mode = COMMAND_EXEC, .help = "chip erase through ISP.", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/pic32mx.c b/src/flash/nor/pic32mx.c index 5ad4cb7..81ffdc4 100644 --- a/src/flash/nor/pic32mx.c +++ b/src/flash/nor/pic32mx.c @@ -858,7 +858,7 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) return retval; if (address < bank->base || address >= (bank->base + bank->size)) { - command_print(CMD_CTX, "flash address '%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "flash address '%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } @@ -870,9 +870,9 @@ COMMAND_HANDLER(pic32mx_handle_pgm_word_command) res = ERROR_FLASH_OPERATION_FAILED; if (res == ERROR_OK) - command_print(CMD_CTX, "pic32mx pgm word complete"); + command_print(CMD, "pic32mx pgm word complete"); else - command_print(CMD_CTX, "pic32mx pgm word failed (status = 0x%x)", status); + command_print(CMD, "pic32mx pgm word failed (status = 0x%x)", status); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) int timeout = 10; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "pic32mx unlock <bank>"); + command_print(CMD, "pic32mx unlock <bank>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -907,7 +907,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) mips_ejtag_drscan_8(ejtag_info, &mchip_cmd); if (mchip_cmd & (1 << 7)) { /* device is not locked */ - command_print(CMD_CTX, "pic32mx is already unlocked, erasing anyway"); + command_print(CMD, "pic32mx is already unlocked, erasing anyway"); } /* unlock/erase device */ @@ -931,7 +931,7 @@ COMMAND_HANDLER(pic32mx_handle_unlock_command) /* select ejtag tap */ mips_ejtag_set_instr(ejtag_info, MTAP_SW_ETAP); - command_print(CMD_CTX, "pic32mx unlocked.\n" + command_print(CMD, "pic32mx unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); diff --git a/src/flash/nor/psoc4.c b/src/flash/nor/psoc4.c index 0058f2d..1eb6a26 100644 --- a/src/flash/nor/psoc4.c +++ b/src/flash/nor/psoc4.c @@ -913,9 +913,9 @@ COMMAND_HANDLER(psoc4_handle_mass_erase_command) retval = psoc4_mass_erase(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "psoc mass erase complete"); + command_print(CMD, "psoc mass erase complete"); else - command_print(CMD_CTX, "psoc mass erase failed"); + command_print(CMD, "psoc mass erase failed"); return retval; } diff --git a/src/flash/nor/psoc5lp.c b/src/flash/nor/psoc5lp.c index 66e2b07..7f801f2 100644 --- a/src/flash/nor/psoc5lp.c +++ b/src/flash/nor/psoc5lp.c @@ -1501,9 +1501,9 @@ COMMAND_HANDLER(psoc5lp_handle_mass_erase_command) retval = psoc5lp_spc_erase_all(bank->target); if (retval == ERROR_OK) - command_print(CMD_CTX, "PSoC 5LP erase succeeded"); + command_print(CMD, "PSoC 5LP erase succeeded"); else - command_print(CMD_CTX, "PSoC 5LP erase failed"); + command_print(CMD, "PSoC 5LP erase failed"); return retval; } diff --git a/src/flash/nor/stellaris.c b/src/flash/nor/stellaris.c index 6b6f6e8..9c4c4bc 100644 --- a/src/flash/nor/stellaris.c +++ b/src/flash/nor/stellaris.c @@ -1336,9 +1336,9 @@ COMMAND_HANDLER(stellaris_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stellaris mass erase complete"); + command_print(CMD, "stellaris mass erase complete"); } else - command_print(CMD_CTX, "stellaris mass erase failed"); + command_print(CMD, "stellaris mass erase failed"); return ERROR_OK; } diff --git a/src/flash/nor/stm32f1x.c b/src/flash/nor/stm32f1x.c index d5d59c6..cf10e37 100644 --- a/src/flash/nor/stm32f1x.c +++ b/src/flash/nor/stm32f1x.c @@ -1186,7 +1186,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) return retval; if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } @@ -1194,11 +1194,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.rdp = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to lock device"); + command_print(CMD, "stm32x failed to lock device"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x locked"); + command_print(CMD, "stm32x locked"); return ERROR_OK; } @@ -1227,16 +1227,16 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) return retval; if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to unlock device"); + command_print(CMD, "stm32x failed to unlock device"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x unlocked.\n" + command_print(CMD, "stm32x unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1281,30 +1281,30 @@ COMMAND_HANDLER(stm32x_handle_options_read_command) return retval; if (optionbyte & (1 << OPT_ERROR)) - command_print(CMD_CTX, "option byte complement error"); + command_print(CMD, "option byte complement error"); - command_print(CMD_CTX, "option byte register = 0x%" PRIx32 "", optionbyte); - command_print(CMD_CTX, "write protection register = 0x%" PRIx32 "", protection); + command_print(CMD, "option byte register = 0x%" PRIx32 "", optionbyte); + command_print(CMD, "write protection register = 0x%" PRIx32 "", protection); - command_print(CMD_CTX, "read protection: %s", + command_print(CMD, "read protection: %s", (optionbyte & (1 << OPT_READOUT)) ? "on" : "off"); /* user option bytes are offset depending on variant */ optionbyte >>= stm32x_info->option_offset; - command_print(CMD_CTX, "watchdog: %sware", + command_print(CMD, "watchdog: %sware", (optionbyte & (1 << OPT_RDWDGSW)) ? "soft" : "hard"); - command_print(CMD_CTX, "stop mode: %sreset generated upon entry", + command_print(CMD, "stop mode: %sreset generated upon entry", (optionbyte & (1 << OPT_RDRSTSTOP)) ? "no " : ""); - command_print(CMD_CTX, "standby mode: %sreset generated upon entry", + command_print(CMD, "standby mode: %sreset generated upon entry", (optionbyte & (1 << OPT_RDRSTSTDBY)) ? "no " : ""); if (stm32x_info->has_dual_banks) - command_print(CMD_CTX, "boot: bank %d", (optionbyte & (1 << OPT_BFB2)) ? 0 : 1); + command_print(CMD, "boot: bank %d", (optionbyte & (1 << OPT_BFB2)) ? 0 : 1); - command_print(CMD_CTX, "user data = 0x%02" PRIx16 "", user_data); + command_print(CMD, "user data = 0x%02" PRIx16 "", user_data); return ERROR_OK; } @@ -1383,7 +1383,7 @@ COMMAND_HANDLER(stm32x_handle_options_write_command) } if (stm32x_erase_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to erase options"); + command_print(CMD, "stm32x failed to erase options"); return ERROR_OK; } @@ -1391,11 +1391,11 @@ COMMAND_HANDLER(stm32x_handle_options_write_command) stm32x_info->option_bytes.data = useropt; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32x failed to write options"); + command_print(CMD, "stm32x failed to write options"); return ERROR_OK; } - command_print(CMD_CTX, "stm32x write options complete.\n" + command_print(CMD, "stm32x write options complete.\n" "INFO: %spower cycle is required " "for the new settings to take effect.", stm32x_info->can_load_options @@ -1504,9 +1504,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32x mass erase complete"); + command_print(CMD, "stm32x mass erase complete"); } else - command_print(CMD_CTX, "stm32x mass erase failed"); + command_print(CMD, "stm32x mass erase failed"); return retval; } diff --git a/src/flash/nor/stm32f2x.c b/src/flash/nor/stm32f2x.c index 23f0030..b49e76e 100644 --- a/src/flash/nor/stm32f2x.c +++ b/src/flash/nor/stm32f2x.c @@ -1415,7 +1415,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1423,11 +1423,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.RDP = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", bank->driver->name); + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s locked", bank->driver->name); + command_print(CMD, "%s locked", bank->driver->name); return ERROR_OK; } @@ -1454,7 +1454,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1466,11 +1466,11 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s unlocked.\n" + command_print(CMD, "%s unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect.", bank->driver->name); @@ -1525,7 +1525,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32x mass_erase <bank>"); + command_print(CMD, "stm32x mass_erase <bank>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1540,9 +1540,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32x mass erase complete"); + command_print(CMD, "stm32x mass erase complete"); } else { - command_print(CMD_CTX, "stm32x mass erase failed"); + command_print(CMD, "stm32x mass erase failed"); } return retval; @@ -1555,7 +1555,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_read_command) struct stm32x_flash_bank *stm32x_info = NULL; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "stm32f2x options_read <bank>"); + command_print(CMD, "stm32f2x options_read <bank>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1572,20 +1572,20 @@ COMMAND_HANDLER(stm32f2x_handle_options_read_command) if (stm32x_info->has_boot_addr) { uint32_t boot_addr = stm32x_info->option_bytes.boot_addr; - command_print(CMD_CTX, "stm32f2x user_options 0x%03X," + command_print(CMD, "stm32f2x user_options 0x%03X," " boot_add0 0x%04X, boot_add1 0x%04X", stm32x_info->option_bytes.user_options, boot_addr & 0xffff, (boot_addr & 0xffff0000) >> 16); if (stm32x_info->has_optcr2_pcrop) { - command_print(CMD_CTX, "stm32f2x optcr2_pcrop 0x%08X", + command_print(CMD, "stm32f2x optcr2_pcrop 0x%08X", stm32x_info->option_bytes.optcr2_pcrop); } } else { - command_print(CMD_CTX, "stm32f2x user_options 0x%03X", + command_print(CMD, "stm32f2x user_options 0x%03X", stm32x_info->option_bytes.user_options); } } else { - command_print(CMD_CTX, "stm32f2x user_options 0x%02X", + command_print(CMD, "stm32f2x user_options 0x%02X", stm32x_info->option_bytes.user_options); } @@ -1601,7 +1601,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) uint16_t user_options, boot_addr0, boot_addr1, options_mask; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32f2x options_write <bank> ..."); + command_print(CMD, "stm32f2x options_write <bank> ..."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1616,7 +1616,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) stm32x_info = bank->driver_priv; if (stm32x_info->has_boot_addr) { if (CMD_ARGC != 4) { - command_print(CMD_CTX, "stm32f2x options_write <bank> <user_options>" + command_print(CMD, "stm32f2x options_write <bank> <user_options>" " <boot_addr0> <boot_addr1>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1625,7 +1625,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) stm32x_info->option_bytes.boot_addr = boot_addr0 | (((uint32_t) boot_addr1) << 16); } else { if (CMD_ARGC != 2) { - command_print(CMD_CTX, "stm32f2x options_write <bank> <user_options>"); + command_print(CMD, "stm32f2x options_write <bank> <user_options>"); return ERROR_COMMAND_SYNTAX_ERROR; } } @@ -1634,14 +1634,14 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) options_mask = !stm32x_info->has_extra_options ? ~0xfc : ~(((0xf00 << (stm32x_info->protection_bits - 12)) | 0xff) & 0xffc); if (user_options & options_mask) { - command_print(CMD_CTX, "stm32f2x invalid user_options"); + command_print(CMD, "stm32f2x invalid user_options"); return ERROR_COMMAND_ARGUMENT_INVALID; } stm32x_info->option_bytes.user_options = user_options; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32f2x failed to write options"); + command_print(CMD, "stm32f2x failed to write options"); return ERROR_OK; } @@ -1649,7 +1649,7 @@ COMMAND_HANDLER(stm32f2x_handle_options_write_command) /* ... and reprogramming of whole flash */ stm32x_info->probed = false; - command_print(CMD_CTX, "stm32f2x write options complete.\n" + command_print(CMD, "stm32f2x write options complete.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); return retval; @@ -1663,7 +1663,7 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) uint32_t optcr2_pcrop; if (CMD_ARGC != 2) { - command_print(CMD_CTX, "stm32f2x optcr2_write <bank> <optcr2_value>"); + command_print(CMD, "stm32f2x optcr2_write <bank> <optcr2_value>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1673,11 +1673,11 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) stm32x_info = bank->driver_priv; if (!stm32x_info->has_optcr2_pcrop) { - command_print(CMD_CTX, "no optcr2 register"); + command_print(CMD, "no optcr2 register"); return ERROR_COMMAND_ARGUMENT_INVALID; } - command_print(CMD_CTX, "INFO: To disable PCROP, set PCROP_RDP" + command_print(CMD, "INFO: To disable PCROP, set PCROP_RDP" " with PCROPi bits STILL SET, then\nlock device and" " finally unlock it. Clears PCROP and mass erases flash."); @@ -1689,18 +1689,18 @@ COMMAND_HANDLER(stm32f2x_handle_optcr2_write_command) stm32x_info->option_bytes.optcr2_pcrop = optcr2_pcrop; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "stm32f2x failed to write options"); + command_print(CMD, "stm32f2x failed to write options"); return ERROR_OK; } - command_print(CMD_CTX, "stm32f2x optcr2_write complete."); + command_print(CMD, "stm32f2x optcr2_write complete."); return retval; } COMMAND_HANDLER(stm32x_handle_otp_command) { if (CMD_ARGC < 2) { - command_print(CMD_CTX, "stm32x otp <bank> (enable|disable|show)"); + command_print(CMD, "stm32x otp <bank> (enable|disable|show)"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1714,7 +1714,7 @@ COMMAND_HANDLER(stm32x_handle_otp_command) } else if (strcmp(CMD_ARGV[1], "disable") == 0) { stm32x_otp_disable(bank); } else if (strcmp(CMD_ARGV[1], "show") == 0) { - command_print(CMD_CTX, + command_print(CMD, "OTP memory bank #%d is %s for write commands.", bank->bank_number, stm32x_is_otp_unlocked(bank) ? "enabled" : "disabled"); @@ -1722,7 +1722,7 @@ COMMAND_HANDLER(stm32x_handle_otp_command) return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Failed: not an OTP bank."); + command_print(CMD, "Failed: not an OTP bank."); } return retval; diff --git a/src/flash/nor/stm32h7x.c b/src/flash/nor/stm32h7x.c index ce89bb4..fd6bf9a 100644 --- a/src/flash/nor/stm32h7x.c +++ b/src/flash/nor/stm32h7x.c @@ -38,18 +38,18 @@ #define FLASH_SR 0x10 #define FLASH_CCR 0x14 #define FLASH_OPTCR 0x18 -#define FLASH_OPTCUR 0x1C -#define FLASH_OPTPRG 0x20 +#define FLASH_OPTSR_CUR 0x1C +#define FLASH_OPTSR_PRG 0x20 #define FLASH_OPTCCR 0x24 -#define FLASH_WPSNCUR 0x38 -#define FLASH_WPSNPRG 0x3C +#define FLASH_WPSN_CUR 0x38 +#define FLASH_WPSN_PRG 0x3C /* FLASH_CR register bits */ #define FLASH_LOCK (1 << 0) #define FLASH_PG (1 << 1) #define FLASH_SER (1 << 2) -#define FLASH_BER_CMD (1 << 3) +#define FLASH_BER (1 << 3) #define FLASH_PSIZE_8 (0 << 4) #define FLASH_PSIZE_16 (1 << 4) #define FLASH_PSIZE_32 (2 << 4) @@ -61,6 +61,7 @@ /* FLASH_SR register bits */ #define FLASH_BSY (1 << 0) /* Operation in progress */ +#define FLASH_QW (1 << 2) /* Operation queue in progress */ #define FLASH_WRPERR (1 << 17) /* Write protection error */ #define FLASH_PGSERR (1 << 18) /* Programming sequence error */ #define FLASH_STRBERR (1 << 19) /* Strobe error */ @@ -114,7 +115,6 @@ struct stm32h7x_part_info { const struct stm32h7x_rev *revs; size_t num_revs; unsigned int page_size; - unsigned int pages_per_sector; uint16_t max_flash_size_kb; uint8_t has_dual_bank; uint16_t first_bank_size_kb; /* Used when has_dual_bank is true */ @@ -132,7 +132,7 @@ struct stm32h7x_flash_bank { }; static const struct stm32h7x_rev stm32_450_revs[] = { - { 0x1000, "A" }, { 0x1001, "Z" }, { 0x1003, "Y" }, + { 0x1000, "A" }, { 0x1001, "Z" }, { 0x1003, "Y" }, { 0x2001, "X" }, }; static const struct stm32h7x_part_info stm32h7x_parts[] = { @@ -140,7 +140,7 @@ static const struct stm32h7x_part_info stm32h7x_parts[] = { .id = 0x450, .revs = stm32_450_revs, .num_revs = ARRAY_SIZE(stm32_450_revs), - .device_str = "STM32H7xx 2M", + .device_str = "STM32H74x/75x", .page_size = 128, /* 128 KB */ .max_flash_size_kb = 2048, .first_bank_size_kb = 1024, @@ -184,33 +184,33 @@ static inline int stm32x_get_flash_status(struct flash_bank *bank, uint32_t *sta return target_read_u32(target, stm32x_get_flash_reg(bank, FLASH_SR), status); } -static int stm32x_wait_status_busy(struct flash_bank *bank, int timeout) +static int stm32x_wait_flash_op_queue(struct flash_bank *bank, int timeout) { struct target *target = bank->target; struct stm32h7x_flash_bank *stm32x_info = bank->driver_priv; uint32_t status; int retval; - /* wait for busy to clear */ + /* wait for flash operations completion */ for (;;) { retval = stm32x_get_flash_status(bank, &status); if (retval != ERROR_OK) { - LOG_INFO("wait_status_busy, target_read_u32 : error : remote address 0x%x", stm32x_info->flash_base); + LOG_INFO("wait_flash_op_queue, target_read_u32 : error : remote address 0x%x", stm32x_info->flash_base); return retval; } - if ((status & FLASH_BSY) == 0) + if ((status & FLASH_QW) == 0) break; if (timeout-- <= 0) { - LOG_INFO("wait_status_busy, time out expired, status: 0x%" PRIx32 "", status); + LOG_INFO("wait_flash_op_queue, time out expired, status: 0x%" PRIx32 "", status); return ERROR_FAIL; } alive_sleep(1); } if (status & FLASH_WRPERR) { - LOG_INFO("wait_status_busy, WRPERR : error : remote address 0x%x", stm32x_info->flash_base); + LOG_INFO("wait_flash_op_queue, WRPERR : error : remote address 0x%x", stm32x_info->flash_base); retval = ERROR_FAIL; } @@ -313,7 +313,7 @@ static int stm32x_read_options(struct flash_bank *bank) stm32x_info = bank->driver_priv; /* read current option bytes */ - int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCUR, &optiondata); + int retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_CUR, &optiondata); if (retval != ERROR_OK) return retval; @@ -321,19 +321,19 @@ static int stm32x_read_options(struct flash_bank *bank) stm32x_info->option_bytes.user_options = optiondata & 0xfc; stm32x_info->option_bytes.RDP = (optiondata >> 8) & 0xff; stm32x_info->option_bytes.user2_options = (optiondata >> 16) & 0xff; - stm32x_info->option_bytes.user3_options = (optiondata >> 24) & 0x83; + stm32x_info->option_bytes.user3_options = (optiondata >> 24) & 0xa3; if (stm32x_info->option_bytes.RDP != 0xAA) LOG_INFO("Device Security Bit Set"); /* read current WPSN option bytes */ - retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSNCUR, &optiondata); + retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_CUR, &optiondata); if (retval != ERROR_OK) return retval; stm32x_info->option_bytes.protection = optiondata & 0xff; /* read current WPSN2 option bytes */ - retval = target_read_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSNCUR, &optiondata); + retval = target_read_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_CUR, &optiondata); if (retval != ERROR_OK) return retval; stm32x_info->option_bytes.protection2 = optiondata & 0xff; @@ -357,30 +357,30 @@ static int stm32x_write_options(struct flash_bank *bank) optiondata = stm32x_info->option_bytes.user_options; optiondata |= (stm32x_info->option_bytes.RDP << 8); optiondata |= (stm32x_info->option_bytes.user2_options & 0xff) << 16; - optiondata |= (stm32x_info->option_bytes.user3_options & 0x83) << 24; + optiondata |= (stm32x_info->option_bytes.user3_options & 0xa3) << 24; /* program options */ - retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTPRG, optiondata); - if (retval != ERROR_OK) - return retval; + retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTSR_PRG, optiondata); + if (retval != ERROR_OK) + return retval; optiondata = stm32x_info->option_bytes.protection & 0xff; /* Program protection WPSNPRG */ - retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSNPRG, optiondata); - if (retval != ERROR_OK) - return retval; + retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_WPSN_PRG, optiondata); + if (retval != ERROR_OK) + return retval; optiondata = stm32x_info->option_bytes.protection2 & 0xff; /* Program protection WPSNPRG2 */ - retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSNPRG, optiondata); - if (retval != ERROR_OK) - return retval; + retval = target_write_u32(target, FLASH_REG_BASE_B1 + FLASH_WPSN_PRG, optiondata); + if (retval != ERROR_OK) + return retval; optiondata = 0x40000000; /* Remove OPT error flag before programming */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCCR, optiondata); - if (retval != ERROR_OK) - return retval; + if (retval != ERROR_OK) + return retval; /* start programming cycle */ retval = target_write_u32(target, FLASH_REG_BASE_B0 + FLASH_OPTCR, OPT_START); @@ -393,14 +393,14 @@ static int stm32x_write_options(struct flash_bank *bank) uint32_t status; retval = target_read_u32(target, FLASH_REG_BASE_B0 + FLASH_SR, &status); if (retval != ERROR_OK) { - LOG_INFO("stm32x_write_options: wait_status_busy : error"); + LOG_INFO("stm32x_write_options: wait_flash_op_queue : error"); return retval; } - if ((status & FLASH_BSY) == 0) + if ((status & FLASH_QW) == 0) break; if (timeout-- <= 0) { - LOG_INFO("wait_status_busy, time out expired, status: 0x%" PRIx32 "", status); + LOG_INFO("wait_flash_op_queue, time out expired, status: 0x%" PRIx32 "", status); return ERROR_FAIL; } alive_sleep(1); @@ -459,12 +459,12 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last) /* Sector Erase To erase a sector, follow the procedure below: - 1. Check that no Flash memory operation is ongoing by checking the BSY bit in the + 1. Check that no Flash memory operation is ongoing by checking the QW bit in the FLASH_SR register 2. Set the SER bit and select the sector you wish to erase (SNB) in the FLASH_CR register 3. Set the STRT bit in the FLASH_CR register - 4. Wait for the BSY bit to be cleared + 4. Wait for flash operations completion */ for (int i = first; i <= last; i++) { LOG_DEBUG("erase sector %d", i); @@ -480,7 +480,7 @@ static int stm32x_erase(struct flash_bank *bank, int first, int last) LOG_ERROR("Error erase sector %d", i); return retval; } - retval = stm32x_wait_status_busy(bank, FLASH_ERASE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_ERASE_TIMEOUT); if (retval != ERROR_OK) { LOG_ERROR("erase time-out or operation error sector %d", i); @@ -687,11 +687,11 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, /* Standard programming The Flash memory programming sequence is as follows: - 1. Check that no main Flash memory operation is ongoing by checking the BSY bit in the + 1. Check that no main Flash memory operation is ongoing by checking the QW bit in the FLASH_SR register. 2. Set the PG bit in the FLASH_CR register 3. 8 x Word access (or Force Write FW) - 4. Wait for the BSY bit to be cleared + 4. Wait for flash operations completion */ while (blocks_remaining > 0) { retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_PG | FLASH_PSIZE_64); @@ -702,7 +702,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, if (retval != ERROR_OK) goto flash_lock; - retval = stm32x_wait_status_busy(bank, FLASH_WRITE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT); if (retval != ERROR_OK) goto flash_lock; @@ -725,7 +725,7 @@ static int stm32x_write(struct flash_bank *bank, const uint8_t *buffer, if (retval != ERROR_OK) goto flash_lock; - retval = stm32x_wait_status_busy(bank, FLASH_WRITE_TIMEOUT); + retval = stm32x_wait_flash_op_queue(bank, FLASH_WRITE_TIMEOUT); if (retval != ERROR_OK) goto flash_lock; } @@ -951,7 +951,7 @@ COMMAND_HANDLER(stm32x_handle_lock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -959,11 +959,11 @@ COMMAND_HANDLER(stm32x_handle_lock_command) stm32x_info->option_bytes.RDP = 0; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s locked", bank->driver->name); + command_print(CMD, "%s locked", bank->driver->name); return ERROR_OK; } @@ -997,7 +997,7 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) } if (stm32x_read_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to read options", bank->driver->name); + command_print(CMD, "%s failed to read options", bank->driver->name); return ERROR_OK; } @@ -1006,10 +1006,10 @@ COMMAND_HANDLER(stm32x_handle_unlock_command) stm32x_info->option_bytes.RDP = 0xAA; if (stm32x_write_options(bank) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } - command_print(CMD_CTX, "%s unlocked.\n", bank->driver->name); + command_print(CMD, "%s unlocked.\n", bank->driver->name); return ERROR_OK; } @@ -1029,16 +1029,16 @@ static int stm32x_mass_erase(struct flash_bank *bank) return retval; /* mass erase flash memory bank */ - retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_BER_CMD | FLASH_PSIZE_64); + retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), FLASH_BER | FLASH_PSIZE_64); if (retval != ERROR_OK) return retval; retval = target_write_u32(target, stm32x_get_flash_reg(bank, FLASH_CR), - FLASH_BER_CMD | FLASH_PSIZE_64 | FLASH_START); + FLASH_BER | FLASH_PSIZE_64 | FLASH_START); if (retval != ERROR_OK) return retval; - retval = stm32x_wait_status_busy(bank, 30000); + retval = stm32x_wait_flash_op_queue(bank, 30000); if (retval != ERROR_OK) return retval; @@ -1055,7 +1055,7 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) int i; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32h7x mass_erase <bank>"); + command_print(CMD, "stm32h7x mass_erase <bank>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1070,9 +1070,9 @@ COMMAND_HANDLER(stm32x_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32h7x mass erase complete"); + command_print(CMD, "stm32h7x mass erase complete"); } else { - command_print(CMD_CTX, "stm32h7x mass erase failed"); + command_print(CMD, "stm32h7x mass erase failed"); } return retval; diff --git a/src/flash/nor/stm32l4x.c b/src/flash/nor/stm32l4x.c index 3d4303b..f680542 100644 --- a/src/flash/nor/stm32l4x.c +++ b/src/flash/nor/stm32l4x.c @@ -835,7 +835,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) uint32_t action; if (CMD_ARGC < 1) { - command_print(CMD_CTX, "stm32l4x mass_erase <STM32L4 bank>"); + command_print(CMD, "stm32l4x mass_erase <STM32L4 bank>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -851,9 +851,9 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32l4x mass erase complete"); + command_print(CMD, "stm32l4x mass erase complete"); } else { - command_print(CMD_CTX, "stm32l4x mass erase failed"); + command_print(CMD, "stm32l4x mass erase failed"); } return retval; @@ -862,7 +862,7 @@ COMMAND_HANDLER(stm32l4_handle_mass_erase_command) COMMAND_HANDLER(stm32l4_handle_option_read_command) { if (CMD_ARGC < 2) { - command_print(CMD_CTX, "stm32l4x option_read <STM32L4 bank> <option_reg offset>"); + command_print(CMD, "stm32l4x option_read <STM32L4 bank> <option_reg offset>"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -880,7 +880,7 @@ COMMAND_HANDLER(stm32l4_handle_option_read_command) if (ERROR_OK != retval) return retval; - command_print(CMD_CTX, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32 "", reg_addr, value); + command_print(CMD, "Option Register: <0x%" PRIx32 "> = 0x%" PRIx32 "", reg_addr, value); return retval; } @@ -888,7 +888,7 @@ COMMAND_HANDLER(stm32l4_handle_option_read_command) COMMAND_HANDLER(stm32l4_handle_option_write_command) { if (CMD_ARGC < 3) { - command_print(CMD_CTX, "stm32l4x option_write <STM32L4 bank> <option_reg offset> <value> [mask]"); + command_print(CMD, "stm32l4x option_write <STM32L4 bank> <option_reg offset> <value> [mask]"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -906,7 +906,7 @@ COMMAND_HANDLER(stm32l4_handle_option_write_command) if (CMD_ARGC > 3) mask = strtoul(CMD_ARGV[3], NULL, 16); - command_print(CMD_CTX, "%s Option written.\n" + command_print(CMD, "%s Option written.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect.", bank->driver->name); @@ -937,7 +937,7 @@ COMMAND_HANDLER(stm32l4_handle_option_load_command) /* Write the OBLLAUNCH bit in CR -> Cause device "POR" and option bytes reload */ retval = target_write_u32(target, stm32l4_get_flash_reg(bank, STM32_FLASH_CR), FLASH_OBLLAUNCH); - command_print(CMD_CTX, "stm32l4x option load (POR) completed."); + command_print(CMD, "stm32l4x option load (POR) completed."); return retval; } @@ -962,7 +962,7 @@ COMMAND_HANDLER(stm32l4_handle_lock_command) /* set readout protection level 1 by erasing the RDP option byte */ if (stm32l4_write_option(bank, STM32_FLASH_OPTR, 0, 0x000000FF) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to lock device", bank->driver->name); + command_print(CMD, "%s failed to lock device", bank->driver->name); return ERROR_OK; } @@ -989,7 +989,7 @@ COMMAND_HANDLER(stm32l4_handle_unlock_command) } if (stm32l4_write_option(bank, STM32_FLASH_OPTR, RDP_LEVEL_0, 0x000000FF) != ERROR_OK) { - command_print(CMD_CTX, "%s failed to unlock device", bank->driver->name); + command_print(CMD, "%s failed to unlock device", bank->driver->name); return ERROR_OK; } diff --git a/src/flash/nor/stm32lx.c b/src/flash/nor/stm32lx.c index 2778010..e6473f8 100644 --- a/src/flash/nor/stm32lx.c +++ b/src/flash/nor/stm32lx.c @@ -324,9 +324,9 @@ COMMAND_HANDLER(stm32lx_handle_mass_erase_command) for (i = 0; i < bank->num_sectors; i++) bank->sectors[i].is_erased = 1; - command_print(CMD_CTX, "stm32lx mass erase complete"); + command_print(CMD, "stm32lx mass erase complete"); } else { - command_print(CMD_CTX, "stm32lx mass erase failed"); + command_print(CMD, "stm32lx mass erase failed"); } return retval; @@ -345,9 +345,9 @@ COMMAND_HANDLER(stm32lx_handle_lock_command) retval = stm32lx_lock(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "STM32Lx locked, takes effect after power cycle."); + command_print(CMD, "STM32Lx locked, takes effect after power cycle."); else - command_print(CMD_CTX, "STM32Lx lock failed"); + command_print(CMD, "STM32Lx lock failed"); return retval; } @@ -365,9 +365,9 @@ COMMAND_HANDLER(stm32lx_handle_unlock_command) retval = stm32lx_unlock(bank); if (retval == ERROR_OK) - command_print(CMD_CTX, "STM32Lx unlocked, takes effect after power cycle."); + command_print(CMD, "STM32Lx unlocked, takes effect after power cycle."); else - command_print(CMD_CTX, "STM32Lx unlock failed"); + command_print(CMD, "STM32Lx unlock failed"); return retval; } diff --git a/src/flash/nor/str9xpec.c b/src/flash/nor/str9xpec.c index b618706..6e1ecf3 100644 --- a/src/flash/nor/str9xpec.c +++ b/src/flash/nor/str9xpec.c @@ -746,7 +746,7 @@ COMMAND_HANDLER(str9xpec_handle_part_id_command) idcode = buf_get_u32(buffer, 0, 32); - command_print(CMD_CTX, "str9xpec part id: 0x%8.8" PRIx32 "", idcode); + command_print(CMD, "str9xpec part id: 0x%8.8" PRIx32 "", idcode); free(buffer); @@ -780,33 +780,33 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_read_command) /* boot bank */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_CSMAPBIT, 1)) - command_print(CMD_CTX, "CS Map: bank1"); + command_print(CMD, "CS Map: bank1"); else - command_print(CMD_CTX, "CS Map: bank0"); + command_print(CMD, "CS Map: bank0"); /* OTP lock */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_OTPBIT, 1)) - command_print(CMD_CTX, "OTP Lock: OTP Locked"); + command_print(CMD, "OTP Lock: OTP Locked"); else - command_print(CMD_CTX, "OTP Lock: OTP Unlocked"); + command_print(CMD, "OTP Lock: OTP Unlocked"); /* LVD Threshold */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDTHRESBIT, 1)) - command_print(CMD_CTX, "LVD Threshold: 2.7v"); + command_print(CMD, "LVD Threshold: 2.7v"); else - command_print(CMD_CTX, "LVD Threshold: 2.4v"); + command_print(CMD, "LVD Threshold: 2.4v"); /* LVD reset warning */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDWARNBIT, 1)) - command_print(CMD_CTX, "LVD Reset Warning: VDD or VDDQ Inputs"); + command_print(CMD, "LVD Reset Warning: VDD or VDDQ Inputs"); else - command_print(CMD_CTX, "LVD Reset Warning: VDD Input Only"); + command_print(CMD, "LVD Reset Warning: VDD Input Only"); /* LVD reset select */ if (buf_get_u32(str9xpec_info->options, STR9XPEC_OPT_LVDSELBIT, 1)) - command_print(CMD_CTX, "LVD Reset Selection: VDD or VDDQ Inputs"); + command_print(CMD, "LVD Reset Selection: VDD or VDDQ Inputs"); else - command_print(CMD_CTX, "LVD Reset Selection: VDD Input Only"); + command_print(CMD, "LVD Reset Selection: VDD Input Only"); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_options_write_command) if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS) return ERROR_FLASH_OPERATION_FAILED; - command_print(CMD_CTX, "str9xpec write options complete.\n" + command_print(CMD, "str9xpec write options complete.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1017,7 +1017,7 @@ COMMAND_HANDLER(str9xpec_handle_flash_unlock_command) if ((status & ISC_STATUS_ERROR) != STR9XPEC_ISC_SUCCESS) return ERROR_FLASH_OPERATION_FAILED; - command_print(CMD_CTX, "str9xpec unlocked.\n" + command_print(CMD, "str9xpec unlocked.\n" "INFO: a reset or power cycle is required " "for the new settings to take effect."); @@ -1045,19 +1045,19 @@ COMMAND_HANDLER(str9xpec_handle_flash_enable_turbo_command) tap0 = str9xpec_info->tap; if (tap0 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap0) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap0) invalid chain?"); return ERROR_FAIL; } tap1 = tap0->next_tap; if (tap1 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap1) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap1) invalid chain?"); return ERROR_FAIL; } tap2 = tap1->next_tap; if (tap2 == NULL) { /* things are *WRONG* */ - command_print(CMD_CTX, "**STR9FLASH** (tap2) invalid chain?"); + command_print(CMD, "**STR9FLASH** (tap2) invalid chain?"); return ERROR_FAIL; } @@ -1177,9 +1177,10 @@ static const struct command_registration str9xpec_config_command_handlers[] = { }, { .name = "part_id", + .usage = "<bank>", .handler = str9xpec_handle_part_id_command, .mode = COMMAND_EXEC, - .help = "print part id of str9xpec flash bank <num>", + .help = "print part id of str9xpec flash bank", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/swm050.c b/src/flash/nor/swm050.c new file mode 100644 index 0000000..241207d --- /dev/null +++ b/src/flash/nor/swm050.c @@ -0,0 +1,211 @@ +/*************************************************************************** + * Copyright (C) 2019 Icenowy Zheng <icenowy@aosc.io> * + * Copyright (C) 2019 Caleb Szalacinski <contact@skiboy.net> * + * * + * 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 <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "imp.h" +#include <target/image.h> + +#define SWM050_DELAY 100 + +#define SWM050_FLASH_PAGE_SIZE 0x200 +#define SWM050_FLASH_PAGES 16 + +#define SWM050_CPU_ID 0xE000ED00 +#define SWM050_CPU_ID_VAL 0x410CC200 + +#define SWM050_FLASH_REG1 0x1F000000 +#define SWM050_FLASH_REG2 0x1F000038 +#define SWM050_FLASH_KEY 0xAAAAAAAA + +#define SWM050_SYSCTL_CFG_0 0x400F0000 +#define SWM050_SYSCTL_DBLF 0x400F0008 + +static int swm050_erase(struct flash_bank *bank, int first, int last) +{ + struct target *target = bank->target; + int retval, curr_page; + uint32_t curr_addr; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + /* Perform erase */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x4); + if (retval != ERROR_OK) + return retval; + + for (curr_page = first; curr_page <= last; curr_page++) { + curr_addr = bank->base + (SWM050_FLASH_PAGE_SIZE * curr_page); + /* Perform write */ + retval = target_write_u32(target, curr_addr, SWM050_FLASH_KEY); + if (retval != ERROR_OK) + return retval; + alive_sleep(SWM050_DELAY); + } + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int swm050_write(struct flash_bank *bank, const uint8_t *buffer, uint32_t offset, uint32_t count) +{ + struct target *target = bank->target; + int retval; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + retval = ERROR_TARGET_NOT_HALTED; + return retval; + } + + /* Perform write */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x1); + if (retval != ERROR_OK) + return retval; + + retval = target_write_memory(target, bank->base + offset, 4, count/4, buffer); + if (retval != ERROR_OK) + return retval; + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +static int swm050_probe(struct flash_bank *bank) +{ + return ERROR_OK; +} + +static int swm050_mass_erase(struct flash_bank *bank) +{ + struct target *target = bank->target; + int retval; + + if (target->state != TARGET_HALTED) { + LOG_ERROR("Target not halted"); + return ERROR_TARGET_NOT_HALTED; + } + + /* Perform mass erase */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x6); + if (retval != ERROR_OK) + return retval; + retval = target_write_u32(target, SWM050_FLASH_REG2, 0x1); + if (retval != ERROR_OK) + return retval; + retval = target_write_u32(target, 0x0, SWM050_FLASH_KEY); + if (retval != ERROR_OK) + return retval; + + alive_sleep(SWM050_DELAY); + + /* Close flash interface */ + retval = target_write_u32(target, SWM050_FLASH_REG1, 0x0); + if (retval != ERROR_OK) + return retval; + + return ERROR_OK; +} + +COMMAND_HANDLER(swm050_handle_mass_erase_command) +{ + if (CMD_ARGC < 1) + 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; + + retval = swm050_mass_erase(bank); + if (retval == ERROR_OK) + command_print(CMD, "swm050 mass erase complete"); + else + command_print(CMD, "swm050 mass erase failed"); + + return retval; +} + +FLASH_BANK_COMMAND_HANDLER(swm050_flash_bank_command) +{ + if (bank->sectors) { + free(bank->sectors); + bank->sectors = NULL; + } + bank->write_start_alignment = 4; + bank->write_end_alignment = 4; + bank->size = SWM050_FLASH_PAGE_SIZE * SWM050_FLASH_PAGES; + + bank->num_sectors = SWM050_FLASH_PAGES; + bank->sectors = alloc_block_array(0, SWM050_FLASH_PAGE_SIZE, SWM050_FLASH_PAGES); + if (!bank->sectors) + return ERROR_FAIL; + + for (int i = 0; i < bank->num_sectors; i++) + bank->sectors[i].is_protected = 0; + + return ERROR_OK; +} + +static const struct command_registration swm050_exec_command_handlers[] = { + { + .name = "mass_erase", + .handler = swm050_handle_mass_erase_command, + .mode = COMMAND_EXEC, + .usage = "bank_id", + .help = "Erase entire flash device.", + }, + COMMAND_REGISTRATION_DONE +}; + +static const struct command_registration swm050_command_handlers[] = { + { + .name = "swm050", + .mode = COMMAND_ANY, + .help = "swm050 flash command group", + .usage = "", + .chain = swm050_exec_command_handlers, + }, + COMMAND_REGISTRATION_DONE +}; + +struct flash_driver swm050_flash = { + .name = "swm050", + .commands = swm050_command_handlers, + .flash_bank_command = swm050_flash_bank_command, + .erase = swm050_erase, + .write = swm050_write, + .read = default_flash_read, + .probe = swm050_probe, + .auto_probe = swm050_probe, + .erase_check = default_flash_blank_check, + .free_driver_priv = default_flash_free_driver_priv, +}; diff --git a/src/flash/nor/tcl.c b/src/flash/nor/tcl.c index 6e216e6..bd313a0 100644 --- a/src/flash/nor/tcl.c +++ b/src/flash/nor/tcl.c @@ -111,7 +111,7 @@ COMMAND_HANDLER(handle_flash_info_command) if (retval == ERROR_FLASH_OPER_UNSUPPORTED) LOG_WARNING("Flash protection check is not implemented."); - command_print(CMD_CTX, + command_print(CMD, "#%d : %s at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", buswidth %i, chipwidth %i", p->bank_number, @@ -140,7 +140,7 @@ COMMAND_HANDLER(handle_flash_info_command) else if (!show_sectors || !prot_block_available) protect_state = "protection state unknown"; - command_print(CMD_CTX, + command_print(CMD, "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", j, block_array[j].offset, @@ -152,7 +152,7 @@ COMMAND_HANDLER(handle_flash_info_command) if (p->driver->info != NULL) { retval = p->driver->info(p, buf, sizeof(buf)); if (retval == ERROR_OK) - command_print(CMD_CTX, "%s", buf); + command_print(CMD, "%s", buf); else LOG_ERROR("error retrieving flash info"); } @@ -176,12 +176,12 @@ COMMAND_HANDLER(handle_flash_probe_command) if (p) { retval = p->driver->probe(p); if (retval == ERROR_OK) - command_print(CMD_CTX, + command_print(CMD, "flash '%s' found at " TARGET_ADDR_FMT, p->driver->name, p->base); } else { - command_print(CMD_CTX, "flash bank '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "flash bank '#%s' is out of bounds", CMD_ARGV[0]); retval = ERROR_FAIL; } @@ -202,9 +202,9 @@ COMMAND_HANDLER(handle_flash_erase_check_command) int j; retval = p->driver->erase_check(p); if (retval == ERROR_OK) - command_print(CMD_CTX, "successfully checked erase state"); + command_print(CMD, "successfully checked erase state"); else { - command_print(CMD_CTX, + command_print(CMD, "unknown error when checking erase state of flash bank #%s at " TARGET_ADDR_FMT, CMD_ARGV[0], @@ -222,7 +222,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command) erase_state = "erase state unknown"; blank = false; - command_print(CMD_CTX, + command_print(CMD, "\t#%3i: 0x%8.8" PRIx32 " (0x%" PRIx32 " %" PRIi32 "kB) %s", j, p->sectors[j].offset, @@ -232,7 +232,7 @@ COMMAND_HANDLER(handle_flash_erase_check_command) } if (blank) - command_print(CMD_CTX, "\tBank is erased"); + command_print(CMD, "\tBank is erased"); return retval; } @@ -267,7 +267,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); if (length <= 0) { - command_print(CMD_CTX, "Length must be >0"); + command_print(CMD, "Length must be >0"); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -289,7 +289,7 @@ COMMAND_HANDLER(handle_flash_erase_address_command) retval = flash_erase_address_range(target, do_pad, address, length); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "erased address " TARGET_ADDR_FMT " (length %" + command_print(CMD, "erased address " TARGET_ADDR_FMT " (length %" PRIi32 ")" " in %fs (%0.3f KiB/s)", address, length, duration_elapsed(&bench), duration_kbps(&bench, length)); @@ -320,13 +320,13 @@ COMMAND_HANDLER(handle_flash_erase_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], last); if (!(first <= last)) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "first sector must be <= last"); return ERROR_FAIL; } if (!(last <= (uint32_t)(p->num_sectors - 1))) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "last sector must be <= %" PRIu32, p->num_sectors - 1); return ERROR_FAIL; @@ -338,7 +338,7 @@ COMMAND_HANDLER(handle_flash_erase_command) retval = flash_driver_erase(p, first, last); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "erased sectors %" PRIu32 " " + command_print(CMD, "erased sectors %" PRIu32 " " "through %" PRIu32 " on flash bank %d " "in %fs", first, last, p->bank_number, duration_elapsed(&bench)); } @@ -377,14 +377,14 @@ COMMAND_HANDLER(handle_flash_protect_command) COMMAND_PARSE_ON_OFF(CMD_ARGV[3], set); if (!(first <= last)) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "first %s must be <= last", (p->num_prot_blocks) ? "block" : "sector"); return ERROR_FAIL; } if (!(last <= (uint32_t)(num_blocks - 1))) { - command_print(CMD_CTX, "ERROR: " + command_print(CMD, "ERROR: " "last %s must be <= %" PRIu32, (p->num_prot_blocks) ? "block" : "sector", num_blocks - 1); @@ -393,7 +393,7 @@ COMMAND_HANDLER(handle_flash_protect_command) retval = flash_driver_protect(p, set, first, last); if (retval == ERROR_OK) { - command_print(CMD_CTX, "%s protection for %s %" PRIu32 + command_print(CMD, "%s protection for %s %" PRIu32 " through %" PRIu32 " on flash bank %d", (set) ? "set" : "cleared", (p->num_prot_blocks) ? "blocks" : "sectors", @@ -421,12 +421,12 @@ COMMAND_HANDLER(handle_flash_write_image_command) auto_erase = 1; CMD_ARGV++; CMD_ARGC--; - command_print(CMD_CTX, "auto erase enabled"); + command_print(CMD, "auto erase enabled"); } else if (strcmp(CMD_ARGV[0], "unlock") == 0) { auto_unlock = true; CMD_ARGV++; CMD_ARGC--; - command_print(CMD_CTX, "auto unlock enabled"); + command_print(CMD, "auto unlock enabled"); } else break; } @@ -463,7 +463,7 @@ COMMAND_HANDLER(handle_flash_write_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %" PRIu32 " bytes from file %s " + command_print(CMD, "wrote %" PRIu32 " bytes from file %s " "in %fs (%0.3f KiB/s)", written, CMD_ARGV[0], duration_elapsed(&bench), duration_kbps(&bench, written)); } @@ -602,7 +602,7 @@ COMMAND_HANDLER(handle_flash_fill_command) } if ((retval == ERROR_OK) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %" PRIu32 " bytes to " TARGET_ADDR_FMT + command_print(CMD, "wrote %" PRIu32 " bytes to " TARGET_ADDR_FMT " in %fs (%0.3f KiB/s)", size_bytes, address, duration_elapsed(&bench), duration_kbps(&bench, size_bytes)); } @@ -716,7 +716,7 @@ COMMAND_HANDLER(handle_flash_write_bank_command) free(buffer); if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "wrote %zu bytes from file %s to flash bank %u" + command_print(CMD, "wrote %zu bytes from file %s to flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", length, CMD_ARGV[1], bank->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, length)); @@ -798,7 +798,7 @@ COMMAND_HANDLER(handle_flash_read_bank_command) } if (duration_measure(&bench) == ERROR_OK) - command_print(CMD_CTX, "wrote %zd bytes to file %s from flash bank %u" + command_print(CMD, "wrote %zd bytes to file %s from flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", written, CMD_ARGV[1], p->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, written)); @@ -900,23 +900,23 @@ COMMAND_HANDLER(handle_flash_verify_bank_command) } if (duration_measure(&bench) == ERROR_OK) - command_print(CMD_CTX, "read %zd bytes from file %s and flash bank %u" + command_print(CMD, "read %zd bytes from file %s and flash bank %u" " at offset 0x%8.8" PRIx32 " in %fs (%0.3f KiB/s)", length, CMD_ARGV[1], p->bank_number, offset, duration_elapsed(&bench), duration_kbps(&bench, length)); differ = memcmp(buffer_file, buffer_flash, length); - command_print(CMD_CTX, "contents %s", differ ? "differ" : "match"); + command_print(CMD, "contents %s", differ ? "differ" : "match"); if (differ) { uint32_t t; int diffs = 0; for (t = 0; t < length; t++) { if (buffer_flash[t] == buffer_file[t]) continue; - command_print(CMD_CTX, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", + command_print(CMD, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", diffs, t + offset, buffer_flash[t], buffer_file[t]); if (diffs++ >= 127) { - command_print(CMD_CTX, "More than 128 errors, the rest are not printed."); + command_print(CMD, "More than 128 errors, the rest are not printed."); break; } keep_alive(); @@ -952,7 +952,7 @@ COMMAND_HANDLER(handle_flash_padded_value_command) COMMAND_PARSE_NUMBER(u8, CMD_ARGV[1], p->default_padded_value); - command_print(CMD_CTX, "Default padded value set to 0x%" PRIx8 " for flash bank %u", \ + command_print(CMD, "Default padded value set to 0x%" PRIx8 " for flash bank %u", \ p->default_padded_value, p->bank_number); return retval; @@ -985,7 +985,7 @@ static const struct command_registration flash_exec_command_handlers[] = { .name = "erase_sector", .handler = handle_flash_erase_command, .mode = COMMAND_EXEC, - .usage = "bank_id first_sector_num last_sector_num", + .usage = "bank_id first_sector_num (last_sector_num|'last')", .help = "Erase a range of sectors in a flash bank.", }, { @@ -1167,7 +1167,7 @@ COMMAND_HANDLER(handle_flash_banks_command) unsigned n = 0; for (struct flash_bank *p = flash_bank_list(); p; p = p->next, n++) { - LOG_USER("#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", " + command_print(CMD, "#%d : %s (%s) at " TARGET_ADDR_FMT ", size 0x%8.8" PRIx32 ", " "buswidth %u, chipwidth %u", p->bank_number, p->name, p->driver->name, p->base, p->size, p->bus_width, p->chip_width); @@ -1239,12 +1239,14 @@ static const struct command_registration flash_config_command_handlers[] = { .mode = COMMAND_CONFIG, .handler = handle_flash_init_command, .help = "Initialize flash devices.", + .usage = "", }, { .name = "banks", .mode = COMMAND_ANY, .handler = handle_flash_banks_command, .help = "Display table with information about flash banks.", + .usage = "", }, { .name = "list", @@ -1260,6 +1262,7 @@ static const struct command_registration flash_command_handlers[] = { .mode = COMMAND_ANY, .help = "NOR flash command group", .chain = flash_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/flash/nor/tms470.c b/src/flash/nor/tms470.c index 195d1ae..90557b8 100644 --- a/src/flash/nor/tms470.c +++ b/src/flash/nor/tms470.c @@ -301,7 +301,7 @@ COMMAND_HANDLER(tms470_handle_flash_keyset_command) int start = (0 == strncmp(CMD_ARGV[i], "0x", 2)) ? 2 : 0; if (1 != sscanf(&CMD_ARGV[i][start], "%" SCNx32 "", &flashKeys[i])) { - command_print(CMD_CTX, "could not process flash key %s", + command_print(CMD, "could not process flash key %s", CMD_ARGV[i]); LOG_ERROR("could not process flash key %s", CMD_ARGV[i]); return ERROR_COMMAND_SYNTAX_ERROR; @@ -310,19 +310,19 @@ COMMAND_HANDLER(tms470_handle_flash_keyset_command) keysSet = 1; } else if (CMD_ARGC != 0) { - command_print(CMD_CTX, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); + command_print(CMD, "tms470 flash_keyset <key0> <key1> <key2> <key3>"); return ERROR_COMMAND_SYNTAX_ERROR; } if (keysSet) { - command_print(CMD_CTX, + command_print(CMD, "using flash keys 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 ", 0x%08" PRIx32 "", flashKeys[0], flashKeys[1], flashKeys[2], flashKeys[3]); } else - command_print(CMD_CTX, "flash keys not set"); + command_print(CMD, "flash keys not set"); return ERROR_OK; } @@ -352,12 +352,12 @@ COMMAND_HANDLER(tms470_handle_osc_megahertz_command) if (oscMHz <= 0) { LOG_ERROR("osc_megahertz must be positive and non-zero!"); - command_print(CMD_CTX, "osc_megahertz must be positive and non-zero!"); + command_print(CMD, "osc_megahertz must be positive and non-zero!"); oscMHz = 12; return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "osc_megahertz=%d", oscMHz); + command_print(CMD, "osc_megahertz=%d", oscMHz); return ERROR_OK; } @@ -375,7 +375,7 @@ COMMAND_HANDLER(tms470_handle_plldis_command) plldis = plldis ? 1 : 0; } - command_print(CMD_CTX, "plldis=%d", plldis); + command_print(CMD, "plldis=%d", plldis); return ERROR_OK; } diff --git a/src/flash/nor/xmc4xxx.c b/src/flash/nor/xmc4xxx.c index c56adb5..d6a1ad4 100644 --- a/src/flash/nor/xmc4xxx.c +++ b/src/flash/nor/xmc4xxx.c @@ -1284,9 +1284,9 @@ COMMAND_HANDLER(xmc4xxx_handle_flash_password_command) fb->pw_set = true; - command_print(CMD_CTX, "XMC4xxx flash passwords set to:\n"); - command_print(CMD_CTX, "-0x%08"PRIx32"\n", fb->pw1); - command_print(CMD_CTX, "-0x%08"PRIx32"\n", fb->pw2); + command_print(CMD, "XMC4xxx flash passwords set to:\n"); + command_print(CMD, "-0x%08"PRIx32"\n", fb->pw1); + command_print(CMD, "-0x%08"PRIx32"\n", fb->pw2); return ERROR_OK; } @@ -1329,7 +1329,8 @@ static const struct command_registration xmc4xxx_exec_command_handlers[] = { .usage = "bank_id user_level[0-1]", .help = "Permanently Removes flash protection (read and write) " "for the specified user level", - }, COMMAND_REGISTRATION_DONE + }, + COMMAND_REGISTRATION_DONE }; static const struct command_registration xmc4xxx_command_handlers[] = { diff --git a/src/hello.c b/src/hello.c index 25938bc..a1c00c0 100644 --- a/src/hello.c +++ b/src/hello.c @@ -89,7 +89,7 @@ COMMAND_HANDLER(handle_hello_command) const char *sep, *name; int retval = CALL_COMMAND_HANDLER(handle_hello_args, &sep, &name); if (ERROR_OK == retval) - command_print(CMD_CTX, "Greetings%s%s!", sep, name); + command_print(CMD, "Greetings%s%s!", sep, name); return retval; } @@ -105,8 +105,8 @@ const struct command_registration hello_command_handlers[] = { .name = "foo", .mode = COMMAND_ANY, .help = "example command handler skeleton", - .chain = foo_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/helper/Makefile.am b/src/helper/Makefile.am index e0f7f49..2b3523f 100644 --- a/src/helper/Makefile.am +++ b/src/helper/Makefile.am @@ -16,6 +16,7 @@ noinst_LTLIBRARIES += %D%/libhelper.la %D%/jep106.c \ %D%/jim-nvp.c \ %D%/binarybuffer.h \ + %D%/bits.h \ %D%/configuration.h \ %D%/ioutil.h \ %D%/list.h \ diff --git a/src/helper/binarybuffer.h b/src/helper/binarybuffer.h index f1da8c4..7ac221e 100644 --- a/src/helper/binarybuffer.h +++ b/src/helper/binarybuffer.h @@ -118,7 +118,7 @@ static inline uint32_t buf_get_u32(const uint8_t *_buffer, uint32_t result = 0; for (unsigned i = first; i < first + num; i++) { if (((buffer[i / 8] >> (i % 8)) & 1) == 1) - result |= 1 << (i - first); + result |= 1U << (i - first); } return result; } diff --git a/src/helper/bits.h b/src/helper/bits.h new file mode 100644 index 0000000..464584d --- /dev/null +++ b/src/helper/bits.h @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2018, STMicroelectronics - All Rights Reserved + * Author(s): Antonio Borneo <borneo.antonio@gmail.com> for STMicroelectronics + * + * 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 <http://www.gnu.org/licenses/>. + */ + +/* + * The content of this file is mainly copied/inspired from Linux kernel + * code in include/linux/types.h include/linux/bitmap.h include/linux/bitops.h + */ + +#ifndef OPENOCD_HELPER_BITS_H +#define OPENOCD_HELPER_BITS_H + +#include <helper/types.h> + +#define BIT(nr) (1UL << (nr)) +#define BITS_PER_BYTE 8 +#define BITS_PER_LONG (BITS_PER_BYTE * sizeof(long)) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define DECLARE_BITMAP(name, bits) unsigned long name[BITS_TO_LONGS(bits)] + +/** + * bitmap_zero - Clears all the bits in memory + * @dst: the address of the bitmap + * @nbits: the number of bits to clear + */ +static inline void bitmap_zero(unsigned long *dst, unsigned int nbits) +{ + unsigned int len = BITS_TO_LONGS(nbits) * sizeof(unsigned long); + memset(dst, 0, len); +} + +/** + * clear_bit - Clear a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + */ +static inline void clear_bit(unsigned int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p &= ~mask; +} + +/** + * set_bit - Set a bit in memory + * @nr: the bit to set + * @addr: the address to start counting from + */ +static inline void set_bit(unsigned int nr, volatile unsigned long *addr) +{ + unsigned long mask = BIT_MASK(nr); + unsigned long *p = ((unsigned long *)addr) + BIT_WORD(nr); + + *p |= mask; +} + +/** + * test_bit - Determine whether a bit is set + * @nr: bit number to test + * @addr: Address to start counting from + */ +static inline int test_bit(unsigned int nr, const volatile unsigned long *addr) +{ + return 1UL & (addr[BIT_WORD(nr)] >> (nr % BITS_PER_LONG)); +} + +#endif /* OPENOCD_HELPER_BITS_H */ diff --git a/src/helper/command.c b/src/helper/command.c index 7a3c2d4..d969933 100644 --- a/src/helper/command.c +++ b/src/helper/command.c @@ -190,7 +190,7 @@ struct command_context *current_command_context(Jim_Interp *interp) } static int script_command_run(Jim_Interp *interp, - int argc, Jim_Obj * const *argv, struct command *c, bool capture) + int argc, Jim_Obj * const *argv, struct command *c) { target_call_timer_callbacks_now(); LOG_USER_N("%s", ""); /* Keep GDB connection alive*/ @@ -200,15 +200,9 @@ static int script_command_run(Jim_Interp *interp, if (NULL == words) return JIM_ERR; - struct log_capture_state *state = NULL; - if (capture) - state = command_log_capture_start(interp); - struct command_context *cmd_ctx = current_command_context(interp); int retval = run_command(cmd_ctx, c, (const char **)words, nwords); - command_log_capture_finish(state); - script_command_args_free(words, nwords); return command_retval_set(interp, retval); } @@ -220,7 +214,7 @@ static int script_command(Jim_Interp *interp, int argc, Jim_Obj *const *argv) struct command *c = interp->cmdPrivData; assert(c); script_debug(interp, c->name, argc, argv); - return script_command_run(interp, argc, argv, c, true); + return script_command_run(interp, argc, argv, c); } static struct command *command_root(struct command *c) @@ -316,7 +310,7 @@ static struct command *command_new(struct command_context *cmd_ctx, * arguments. */ if ((cr->jim_handler == NULL) && (cr->usage == NULL)) { - LOG_DEBUG("BUG: command '%s%s%s' does not have the " + LOG_ERROR("BUG: command '%s%s%s' does not have the " "'.usage' field filled out", parent && parent->name ? parent->name : "", parent && parent->name ? " " : "", @@ -357,27 +351,11 @@ static int register_command_handler(struct command_context *cmd_ctx, struct command *c) { Jim_Interp *interp = cmd_ctx->interp; - char *ocd_name = alloc_printf("ocd_%s", c->name); - if (NULL == ocd_name) - return JIM_ERR; - LOG_DEBUG("registering '%s'...", ocd_name); + LOG_DEBUG("registering '%s'...", c->name); Jim_CmdProc *func = c->handler ? &script_command : &command_unknown; - int retval = Jim_CreateCommand(interp, ocd_name, func, c, NULL); - free(ocd_name); - if (JIM_OK != retval) - return retval; - - /* we now need to add an overrideable proc */ - char *override_name = alloc_printf( - "proc %s {args} {eval ocd_bouncer %s $args}", - c->name, c->name); - if (NULL == override_name) - return JIM_ERR; - - retval = Jim_Eval_Named(interp, override_name, 0, 0); - free(override_name); + int retval = Jim_CreateCommand(interp, c->name, func, c, NULL); return retval; } @@ -502,7 +480,7 @@ void command_output_text(struct command_context *context, const char *data) context->output_handler(context, data); } -void command_print_sameline(struct command_context *context, const char *format, ...) +void command_print_sameline(struct command_invocation *cmd, const char *format, ...) { char *string; @@ -510,13 +488,13 @@ void command_print_sameline(struct command_context *context, const char *format, va_start(ap, format); string = alloc_vprintf(format, ap); - if (string != NULL) { + if (string != NULL && cmd) { /* we want this collected in the log + we also want to pick it up as a tcl return * value. * * The latter bit isn't precisely neat, but will do for now. */ - LOG_USER_N("%s", string); + Jim_AppendString(cmd->ctx->interp, cmd->output, string, -1); /* We already printed it above * command_output_text(context, string); */ free(string); @@ -525,7 +503,7 @@ void command_print_sameline(struct command_context *context, const char *format, va_end(ap); } -void command_print(struct command_context *context, const char *format, ...) +void command_print(struct command_invocation *cmd, const char *format, ...) { char *string; @@ -533,7 +511,7 @@ void command_print(struct command_context *context, const char *format, ...) va_start(ap, format); string = alloc_vprintf(format, ap); - if (string != NULL) { + if (string != NULL && cmd) { strcat(string, "\n"); /* alloc_vprintf guaranteed the buffer to be at least one *char longer */ /* we want this collected in the log + we also want to pick it up as a tcl return @@ -541,7 +519,7 @@ void command_print(struct command_context *context, const char *format, ...) * * The latter bit isn't precisely neat, but will do for now. */ - LOG_USER_N("%s", string); + Jim_AppendString(cmd->ctx->interp, cmd->output, string, -1); /* We already printed it above * command_output_text(context, string); */ free(string); @@ -628,6 +606,9 @@ static int run_command(struct command_context *context, if (c->jim_handler_data) context->current_target_override = c->jim_handler_data; + cmd.output = Jim_NewEmptyStringObj(context->interp); + Jim_IncrRefCount(cmd.output); + int retval = c->handler(&cmd); if (c->jim_handler_data) @@ -642,15 +623,17 @@ static int run_command(struct command_context *context, } } else if (retval == ERROR_COMMAND_CLOSE_CONNECTION) { /* just fall through for a shutdown request */ - } else if (retval != ERROR_OK) { - /* we do not print out an error message because the command *should* - * have printed out an error - */ - char *full_name = command_name(c, ' '); - LOG_DEBUG("Command '%s' failed with error code %d", - full_name ? full_name : c->name, retval); - free(full_name); + } else { + if (retval != ERROR_OK) { + char *full_name = command_name(c, ' '); + LOG_DEBUG("Command '%s' failed with error code %d", + full_name ? full_name : c->name, retval); + free(full_name); + } + /* Use the command output as the Tcl result */ + Jim_SetResult(context->interp, cmd.output); } + Jim_DecrRefCount(context->interp, cmd.output); return retval; } @@ -669,9 +652,11 @@ int command_run_line(struct command_context *context, char *line) * happen when the Jim Tcl interpreter is provided by eCos for * instance. */ + struct target *saved_target_override = context->current_target_override; context->current_target_override = NULL; Jim_Interp *interp = context->interp; + struct command_context *old_context = Jim_GetAssocData(interp, "context"); Jim_DeleteAssocData(interp, "context"); retcode = Jim_SetAssocData(interp, "context", NULL, context); if (retcode == JIM_OK) { @@ -684,25 +669,19 @@ int command_run_line(struct command_context *context, char *line) Jim_DeleteAssocData(interp, "retval"); } Jim_DeleteAssocData(interp, "context"); + int inner_retcode = Jim_SetAssocData(interp, "context", NULL, old_context); + if (retcode == JIM_OK) + retcode = inner_retcode; } + context->current_target_override = saved_target_override; if (retcode == JIM_OK) { const char *result; int reslen; result = Jim_GetString(Jim_GetResult(interp), &reslen); if (reslen > 0) { - int i; - char buff[256 + 1]; - for (i = 0; i < reslen; i += 256) { - int chunk; - chunk = reslen - i; - if (chunk > 256) - chunk = 256; - strncpy(buff, result + i, chunk); - buff[chunk] = 0; - LOG_USER_N("%s", buff); - } - LOG_USER_N("\n"); + command_output_text(context, result); + command_output_text(context, "\n"); } retval = ERROR_OK; } else if (retcode == JIM_EXIT) { @@ -712,6 +691,7 @@ int command_run_line(struct command_context *context, char *line) return retcode; } else { Jim_MakeErrorMessage(interp); + /* error is broadcast */ LOG_USER("%s", Jim_GetString(Jim_GetResult(interp), NULL)); if (retval == ERROR_OK) { @@ -827,8 +807,6 @@ static COMMAND_HELPER(command_help_find, struct command *head, if (0 == CMD_ARGC) return ERROR_COMMAND_SYNTAX_ERROR; *out = command_find(head, CMD_ARGV[0]); - if (NULL == *out && strncmp(CMD_ARGV[0], "ocd_", 4) == 0) - *out = command_find(head, CMD_ARGV[0] + 4); if (NULL == *out) return ERROR_COMMAND_SYNTAX_ERROR; if (--CMD_ARGC == 0) @@ -982,34 +960,85 @@ COMMAND_HANDLER(handle_help_command) } static int command_unknown_find(unsigned argc, Jim_Obj *const *argv, - struct command *head, struct command **out, bool top_level) + struct command *head, struct command **out) { if (0 == argc) return argc; const char *cmd_name = Jim_GetString(argv[0], NULL); struct command *c = command_find(head, cmd_name); - if (NULL == c && top_level && strncmp(cmd_name, "ocd_", 4) == 0) - c = command_find(head, cmd_name + 4); if (NULL == c) return argc; *out = c; - return command_unknown_find(--argc, ++argv, (*out)->children, out, false); + return command_unknown_find(--argc, ++argv, (*out)->children, out); +} + +static char *alloc_concatenate_strings(int argc, Jim_Obj * const *argv) +{ + char *prev, *all; + int i; + + assert(argc >= 1); + + all = strdup(Jim_GetString(argv[0], NULL)); + if (!all) { + LOG_ERROR("Out of memory"); + return NULL; + } + + for (i = 1; i < argc; ++i) { + prev = all; + all = alloc_printf("%s %s", all, Jim_GetString(argv[i], NULL)); + free(prev); + if (!all) { + LOG_ERROR("Out of memory"); + return NULL; + } + } + + return all; +} + +static int run_usage(Jim_Interp *interp, int argc_valid, int argc, Jim_Obj * const *argv) +{ + struct command_context *cmd_ctx = current_command_context(interp); + char *command; + int retval; + + assert(argc_valid >= 1); + assert(argc >= argc_valid); + + command = alloc_concatenate_strings(argc_valid, argv); + if (!command) + return JIM_ERR; + + retval = command_run_linef(cmd_ctx, "usage %s", command); + if (retval != ERROR_OK) { + LOG_ERROR("unable to execute command \"usage %s\"", command); + return JIM_ERR; + } + + if (argc_valid == argc) + LOG_ERROR("%s: command requires more arguments", command); + else { + free(command); + command = alloc_concatenate_strings(argc - argc_valid, argv + argc_valid); + if (!command) + return JIM_ERR; + LOG_ERROR("invalid subcommand \"%s\"", command); + } + + free(command); + return retval; } static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { const char *cmd_name = Jim_GetString(argv[0], NULL); - if (strcmp(cmd_name, "unknown") == 0) { - if (argc == 1) - return JIM_OK; - argc--; - argv++; - } script_debug(interp, cmd_name, argc, argv); struct command_context *cmd_ctx = current_command_context(interp); struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc, argv, c, &c, true); + int remaining = command_unknown_find(argc, argv, c, &c); /* if nothing could be consumed, then it's really an unknown command */ if (remaining == argc) { const char *cmd = Jim_GetString(argv[0], NULL); @@ -1017,7 +1046,6 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } - bool found = true; Jim_Obj *const *start; unsigned count; if (c->handler || c->jim_handler) { @@ -1025,14 +1053,10 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) count = remaining + 1; start = argv + (argc - remaining - 1); } else { - c = command_find(cmd_ctx->commands, "usage"); - if (NULL == c) { - LOG_ERROR("unknown command, but usage is missing too"); - return JIM_ERR; - } count = argc - remaining; start = argv; - found = false; + run_usage(interp, count, argc, start); + return JIM_ERR; } /* pass the command through to the intended handler */ if (c->jim_handler) { @@ -1043,7 +1067,7 @@ static int command_unknown(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return (*c->jim_handler)(interp, count, start); } - return script_command_run(interp, count, start, c, found); + return script_command_run(interp, count, start, c); } static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -1053,7 +1077,7 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (argc > 1) { struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc - 1, argv + 1, c, &c, true); + int remaining = command_unknown_find(argc - 1, argv + 1, c, &c); /* if nothing could be consumed, then it's an unknown command */ if (remaining == argc - 1) { Jim_SetResultString(interp, "unknown", -1); @@ -1082,32 +1106,6 @@ static int jim_command_mode(Jim_Interp *interp, int argc, Jim_Obj *const *argv) return JIM_OK; } -static int jim_command_type(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - if (1 == argc) - return JIM_ERR; - - struct command_context *cmd_ctx = current_command_context(interp); - struct command *c = cmd_ctx->commands; - int remaining = command_unknown_find(argc - 1, argv + 1, c, &c, true); - /* if nothing could be consumed, then it's an unknown command */ - if (remaining == argc - 1) { - Jim_SetResultString(interp, "unknown", -1); - return JIM_OK; - } - - if (c->jim_handler) - Jim_SetResultString(interp, "native", -1); - else if (c->handler) - Jim_SetResultString(interp, "simple", -1); - else if (remaining == 0) - Jim_SetResultString(interp, "group", -1); - else - Jim_SetResultString(interp, "unknown", -1); - - return JIM_OK; -} - int help_add_command(struct command_context *cmd_ctx, struct command *parent, const char *cmd_name, const char *help_text, const char *usage) { @@ -1119,7 +1117,7 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, .name = cmd_name, .mode = COMMAND_ANY, .help = help_text, - .usage = usage, + .usage = usage ? : "", }; nc = register_command(cmd_ctx, parent, &cr); if (NULL == nc) { @@ -1144,8 +1142,9 @@ int help_add_command(struct command_context *cmd_ctx, struct command *parent, if (usage) { bool replaced = false; if (nc->usage) { + if (*nc->usage) + replaced = true; free(nc->usage); - replaced = true; } nc->usage = strdup(usage); if (replaced) @@ -1227,15 +1226,6 @@ static const struct command_registration command_subcommand_handlers[] = { "Returns 'unknown' if an unknown command is given. " "Command can be multiple tokens.", }, - { - .name = "type", - .mode = COMMAND_ANY, - .jim_handler = jim_command_type, - .usage = "command_name [...]", - .help = "Returns the type of built-in command:" - "'native', 'simple', 'group', or 'unknown'. " - "Command can be multiple tokens.", - }, COMMAND_REGISTRATION_DONE }; @@ -1294,6 +1284,7 @@ static const struct command_registration command_builtin_handlers[] = { .mode = COMMAND_ANY, .help = "core command group (introspection)", .chain = command_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1403,6 +1394,7 @@ void process_jim_events(struct command_context *cmd_ctx) return ERROR_COMMAND_ARGUMENT_INVALID; \ } \ char *end; \ + errno = 0; \ *ul = func(str, &end, 0); \ if (*end) { \ LOG_ERROR("Invalid command argument"); \ diff --git a/src/helper/command.h b/src/helper/command.h index f9c02e5..733ba42 100644 --- a/src/helper/command.h +++ b/src/helper/command.h @@ -79,6 +79,7 @@ struct command_invocation { const char *name; unsigned argc; const char **argv; + Jim_Obj *output; }; /** @@ -122,6 +123,11 @@ struct command_invocation { #define COMMAND_HELPER(name, extra ...) __COMMAND_HANDLER(name, extra) /** + * Use this macro to access the command being handled, + * rather than accessing the variable directly. It may be moved. + */ +#define CMD (cmd) +/** * Use this macro to access the context of the command being handled, * rather than accessing the variable directly. It may be moved. */ @@ -348,9 +354,9 @@ struct command_context *copy_command_context(struct command_context *cmd_ctx); */ void command_done(struct command_context *context); -void command_print(struct command_context *context, const char *format, ...) +void command_print(struct command_invocation *cmd, const char *format, ...) __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 2, 3))); -void command_print_sameline(struct command_context *context, const char *format, ...) +void command_print_sameline(struct command_invocation *cmd, const char *format, ...) __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 2, 3))); int command_run_line(struct command_context *context, char *line); int command_run_linef(struct command_context *context, const char *format, ...) @@ -404,7 +410,7 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); do { \ int retval_macro_tmp = parse_ ## type(in, &(out)); \ if (ERROR_OK != retval_macro_tmp) { \ - command_print(CMD_CTX, stringify(out) \ + command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ return retval_macro_tmp; \ } \ @@ -424,9 +430,9 @@ DECLARE_PARSE_WRAPPER(_target_addr, target_addr_t); bool value; \ int retval_macro_tmp = command_parse_bool_arg(in, &value); \ if (ERROR_OK != retval_macro_tmp) { \ - command_print(CMD_CTX, stringify(out) \ + command_print(CMD, stringify(out) \ " option value ('%s') is not valid", in); \ - command_print(CMD_CTX, " choices are '%s' or '%s'", \ + command_print(CMD, " choices are '%s' or '%s'", \ on, off); \ return retval_macro_tmp; \ } \ diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index f1123cd..d4f39e2 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -113,10 +113,10 @@ COMMAND_HANDLER(handle_cat_command) int retval = load_file(CMD_ARGV[0], &data, &len); if (retval == ERROR_OK) { - command_print(CMD_CTX, "%s", data); + command_print(CMD, "%s", data); free(data); } else - command_print(CMD_CTX, "%s not found", CMD_ARGV[0]); + command_print(CMD, "%s not found", CMD_ARGV[0]); return ERROR_OK; } @@ -146,10 +146,10 @@ COMMAND_HANDLER(handle_meminfo_command) info = mallinfo(); if (prev > 0) - command_print(CMD_CTX, "Diff: %d", prev - info.fordblks); + command_print(CMD, "Diff: %d", prev - info.fordblks); prev = info.fordblks; - command_print(CMD_CTX, "Available ram: %d", info.fordblks); + command_print(CMD, "Available ram: %d", info.fordblks); return ERROR_OK; } @@ -217,7 +217,7 @@ COMMAND_HANDLER(handle_cp_command) if (retval != ERROR_OK) break; - command_print(CMD_CTX, "%zu", len - pos); + command_print(CMD, "%zu", len - pos); pos += chunk; @@ -226,9 +226,9 @@ COMMAND_HANDLER(handle_cp_command) } if (retval == ERROR_OK) - command_print(CMD_CTX, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]); + command_print(CMD, "Copied %s to %s", CMD_ARGV[0], CMD_ARGV[1]); else - command_print(CMD_CTX, "copy failed"); + command_print(CMD, "copy failed"); if (data != NULL) free(data); @@ -472,6 +472,7 @@ static const struct command_registration ioutil_command_handlers[] = { .handler = handle_meminfo_command, .mode = COMMAND_ANY, .help = "display free heap space", + .usage = "", }, #endif { diff --git a/src/helper/log.c b/src/helper/log.c index f980774..d65430c 100644 --- a/src/helper/log.c +++ b/src/helper/log.c @@ -213,7 +213,7 @@ COMMAND_HANDLER(handle_debug_level_command) } else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "debug_level: %i", debug_level); + command_print(CMD, "debug_level: %i", debug_level); return ERROR_OK; } @@ -236,7 +236,7 @@ COMMAND_HANDLER(handle_log_output_command) return ERROR_OK; } -static struct command_registration log_command_handlers[] = { +static const struct command_registration log_command_handlers[] = { { .name = "log_output", .handler = handle_log_output_command, diff --git a/src/helper/options.c b/src/helper/options.c index 12755e0..b60d58d 100644 --- a/src/helper/options.c +++ b/src/helper/options.c @@ -269,19 +269,14 @@ int parse_cmdline_args(struct command_context *cmd_ctx, int argc, char *argv[]) break; case 'd': /* --debug | -d */ { - char *command = alloc_printf("debug_level %s", optarg ? optarg : "3"); - int retval = command_run_line(cmd_ctx, command); - free(command); + int retval = command_run_linef(cmd_ctx, "debug_level %s", optarg ? optarg : "3"); if (retval != ERROR_OK) return retval; break; } case 'l': /* --log_output | -l */ - if (optarg) { - char *command = alloc_printf("log_output %s", optarg); - command_run_line(cmd_ctx, command); - free(command); - } + if (optarg) + command_run_linef(cmd_ctx, "log_output %s", optarg); break; case 'c': /* --command | -c */ if (optarg) diff --git a/src/helper/startup.tcl b/src/helper/startup.tcl index 2578de9..691e382 100644 --- a/src/helper/startup.tcl +++ b/src/helper/startup.tcl @@ -3,43 +3,6 @@ # Embedded into OpenOCD executable # - -# We need to explicitly redirect this to the OpenOCD command -# as Tcl defines the exit proc -proc exit {} { - ocd_throw exit -} - -# All commands are registered with an 'ocd_' prefix, while the "real" -# command is a wrapper that calls this function. Its primary purpose is -# to discard 'handler' command output. -# Due to the two nested proc calls, this wrapper has to explicitly run -# the wrapped command in the stack frame two levels above. -proc ocd_bouncer {name args} { - set cmd [format "ocd_%s" $name] - set type [eval ocd_command type $cmd $args] - set errcode error - set skiplevel [expr [eval info level] > 1 ? 2 : 1] - if {$type == "native"} { - return [uplevel $skiplevel $cmd $args] - } else {if {$type == "simple"} { - set errcode [catch {uplevel $skiplevel $cmd $args}] - if {$errcode == 0} { - return "" - } else { - # 'classic' commands output error message as part of progress output - set errmsg "" - } - } else {if {$type == "group"} { - catch {eval ocd_usage $name $args} - set errmsg [format "%s: command requires more arguments" \ - [concat $name " " $args]] - } else { - set errmsg [format "invalid subcommand \"%s\"" $args] - }}} - return -code $errcode $errmsg -} - # Try flipping / and \ to find file if the filename does not # match the precise spelling proc find {filename} { diff --git a/src/jtag/adapter.c b/src/jtag/adapter.c index 3fb52a7..29a9613 100644 --- a/src/jtag/adapter.c +++ b/src/jtag/adapter.c @@ -66,30 +66,6 @@ static int jim_adapter_name(Jim_Interp *interp, int argc, Jim_Obj * const *argv) return JIM_OK; } -static int default_khz(int khz, int *jtag_speed) -{ - LOG_ERROR("Translation from khz to jtag_speed not implemented"); - return ERROR_FAIL; -} - -static int default_speed_div(int speed, int *khz) -{ - LOG_ERROR("Translation from jtag_speed to khz not implemented"); - return ERROR_FAIL; -} - -static int default_power_dropout(int *dropout) -{ - *dropout = 0; /* by default we can't detect power dropout */ - return ERROR_OK; -} - -static int default_srst_asserted(int *srst_asserted) -{ - *srst_asserted = 0; /* by default we can't detect srst asserted */ - return ERROR_OK; -} - COMMAND_HANDLER(interface_transport_command) { char **transports; @@ -114,10 +90,10 @@ COMMAND_HANDLER(handle_interface_list_command) if (strcmp(CMD_NAME, "interface_list") == 0 && CMD_ARGC > 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "The following debug interfaces are available:"); + command_print(CMD, "The following debug interfaces are available:"); for (unsigned i = 0; NULL != jtag_interfaces[i]; i++) { const char *name = jtag_interfaces[i]->name; - command_print(CMD_CTX, "%u: %s", i + 1, name); + command_print(CMD, "%u: %s", i + 1, name); } return ERROR_OK; @@ -150,29 +126,7 @@ COMMAND_HANDLER(handle_interface_command) jtag_interface = jtag_interfaces[i]; - /* LEGACY SUPPORT ... adapter drivers must declare what - * transports they allow. Until they all do so, assume - * the legacy drivers are JTAG-only - */ - if (!jtag_interface->transports) - LOG_WARNING("Adapter driver '%s' did not declare " - "which transports it allows; assuming " - "legacy JTAG-only", jtag_interface->name); - retval = allow_transports(CMD_CTX, jtag_interface->transports - ? jtag_interface->transports : jtag_only); - if (ERROR_OK != retval) - return retval; - - if (jtag_interface->khz == NULL) - jtag_interface->khz = default_khz; - if (jtag_interface->speed_div == NULL) - jtag_interface->speed_div = default_speed_div; - if (jtag_interface->power_dropout == NULL) - jtag_interface->power_dropout = default_power_dropout; - if (jtag_interface->srst_asserted == NULL) - jtag_interface->srst_asserted = default_srst_asserted; - - return ERROR_OK; + return allow_transports(CMD_CTX, jtag_interface->transports); } /* no valid interface was found (i.e. the configuration option, @@ -394,7 +348,7 @@ next: modes[5] = ""; } - command_print(CMD_CTX, "%s %s%s%s%s%s", + command_print(CMD, "%s %s%s%s%s%s", modes[0], modes[1], modes[2], modes[3], modes[4], modes[5]); @@ -411,7 +365,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_delay_command) jtag_set_nsrst_delay(delay); } - command_print(CMD_CTX, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay()); + command_print(CMD, "adapter_nsrst_delay: %u", jtag_get_nsrst_delay()); return ERROR_OK; } @@ -425,7 +379,7 @@ COMMAND_HANDLER(handle_adapter_nsrst_assert_width_command) jtag_set_nsrst_assert_width(width); } - command_print(CMD_CTX, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); + command_print(CMD, "adapter_nsrst_assert_width: %u", jtag_get_nsrst_assert_width()); return ERROR_OK; } @@ -450,9 +404,9 @@ COMMAND_HANDLER(handle_adapter_khz_command) return retval; if (cur_speed) - command_print(CMD_CTX, "adapter speed: %d kHz", cur_speed); + command_print(CMD, "adapter speed: %d kHz", cur_speed); else - command_print(CMD_CTX, "adapter speed: RCLK - adaptive"); + command_print(CMD, "adapter speed: RCLK - adaptive"); return retval; } @@ -464,7 +418,7 @@ COMMAND_HANDLER(handle_usb_location_command) if (CMD_ARGC == 1) jtag_usb_set_location(CMD_ARGV[0]); - command_print(CMD_CTX, "adapter usb location: %s", jtag_usb_get_location()); + command_print(CMD, "adapter usb location: %s", jtag_usb_get_location()); return ERROR_OK; } @@ -476,8 +430,8 @@ static const struct command_registration adapter_usb_command_handlers[] = { .name = "location", .handler = &handle_usb_location_command, .mode = COMMAND_CONFIG, - .help = "set the USB bus location of the USB device", - .usage = "<bus>-port[.port]...", + .help = "display or set the USB bus location of the USB device", + .usage = "[<bus>-port[.port]...]", }, #endif /* HAVE_LIBUSB_GET_PORT_NUMBERS */ COMMAND_REGISTRATION_DONE @@ -555,6 +509,7 @@ static const struct command_registration interface_command_handlers[] = { .handler = handle_interface_list_command, .mode = COMMAND_ANY, .help = "List all built-in debug adapter interfaces (drivers)", + .usage = "", }, { .name = "reset_config", diff --git a/src/jtag/aice/aice_interface.c b/src/jtag/aice/aice_interface.c index c758bb4..c83b8c2 100644 --- a/src/jtag/aice/aice_interface.c +++ b/src/jtag/aice/aice_interface.c @@ -150,7 +150,7 @@ static int aice_execute_reset(struct jtag_command *cmd) static int last_trst; int retval = ERROR_OK; - DEBUG_JTAG_IO("reset trst: %d", cmd->cmd.reset->trst); + LOG_DEBUG_IO("reset trst: %d", cmd->cmd.reset->trst); if (cmd->cmd.reset->trst != last_trst) { if (cmd->cmd.reset->trst) @@ -269,10 +269,10 @@ COMMAND_HANDLER(aice_handle_aice_info_command) { LOG_DEBUG("aice_handle_aice_info_command"); - command_print(CMD_CTX, "Description: %s", param.device_desc); - command_print(CMD_CTX, "Serial number: %s", param.serial); + command_print(CMD, "Description: %s", param.device_desc); + command_print(CMD, "Serial number: %s", param.serial); if (strncmp(aice_port->name, "aice_pipe", 9) == 0) - command_print(CMD_CTX, "Adapter: %s", param.adapter_name); + command_print(CMD, "Adapter: %s", param.adapter_name); return ERROR_OK; } diff --git a/src/jtag/aice/aice_transport.c b/src/jtag/aice/aice_transport.c index 0658318..15ebcac 100644 --- a/src/jtag/aice/aice_transport.c +++ b/src/jtag/aice/aice_transport.c @@ -165,9 +165,9 @@ COMMAND_HANDLER(handle_scan_chain_command) aice_scan_jtag_chain(); tap = jtag_all_taps(); - command_print(CMD_CTX, + command_print(CMD, " TapName Enabled IdCode Expected IrLen IrCap IrMask"); - command_print(CMD_CTX, + command_print(CMD, "-- ------------------- -------- ---------- ---------- ----- ----- ------"); while (tap) { @@ -183,7 +183,7 @@ COMMAND_HANDLER(handle_scan_chain_command) expected = buf_get_u32(tap->expected, 0, tap->ir_length); expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length); - command_print(CMD_CTX, + command_print(CMD, "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x", tap->abs_chain_position, tap->dotted_name, @@ -200,7 +200,7 @@ COMMAND_HANDLER(handle_scan_chain_command) if (tap->ignore_version) expected_id[2] = '*'; - command_print(CMD_CTX, + command_print(CMD, " %s", expected_id); } diff --git a/src/jtag/aice/aice_usb.c b/src/jtag/aice/aice_usb.c index f67ea7c..324ec7c 100644 --- a/src/jtag/aice/aice_usb.c +++ b/src/jtag/aice/aice_usb.c @@ -400,7 +400,7 @@ static int aice_usb_write(uint8_t *out_buffer, int out_length) result = usb_bulk_write_ex(aice_handler.usb_handle, aice_handler.usb_write_ep, (char *)out_buffer, out_length, AICE_USB_TIMEOUT); - DEBUG_JTAG_IO("aice_usb_write, out_length = %i, result = %i", + LOG_DEBUG_IO("aice_usb_write, out_length = %i, result = %i", out_length, result); return result; @@ -412,7 +412,7 @@ static int aice_usb_read(uint8_t *in_buffer, int expected_size) int32_t result = usb_bulk_read_ex(aice_handler.usb_handle, aice_handler.usb_read_ep, (char *)in_buffer, expected_size, AICE_USB_TIMEOUT); - DEBUG_JTAG_IO("aice_usb_read, result = %" PRId32, result); + LOG_DEBUG_IO("aice_usb_read, result = %" PRId32, result); return result; } @@ -2812,7 +2812,7 @@ static int aice_issue_reset_hold(uint32_t coreid) /* set no_dbgi_pin to 0 */ uint32_t pin_status; aice_read_ctrl(AICE_READ_CTRL_GET_JTAG_PIN_STATUS, &pin_status); - if (pin_status | 0x4) + if (pin_status & 0x4) aice_write_ctrl(AICE_WRITE_CTRL_JTAG_PIN_STATUS, pin_status & (~0x4)); /* issue restart */ diff --git a/src/jtag/commands.c b/src/jtag/commands.c index e2d22cc..3352e03 100644 --- a/src/jtag/commands.c +++ b/src/jtag/commands.c @@ -193,33 +193,33 @@ int jtag_build_buffer(const struct scan_command *cmd, uint8_t **buffer) bit_count = 0; - DEBUG_JTAG_IO("%s num_fields: %i", + LOG_DEBUG_IO("%s num_fields: %i", cmd->ir_scan ? "IRSCAN" : "DRSCAN", cmd->num_fields); for (i = 0; i < cmd->num_fields; i++) { if (cmd->fields[i].out_value) { -#ifdef _DEBUG_JTAG_IO_ - char *char_buf = buf_to_str(cmd->fields[i].out_value, - (cmd->fields[i].num_bits > DEBUG_JTAG_IOZ) - ? DEBUG_JTAG_IOZ - : cmd->fields[i].num_bits, 16); - - LOG_DEBUG("fields[%i].out_value[%i]: 0x%s", i, - cmd->fields[i].num_bits, char_buf); - free(char_buf); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { + char *char_buf = buf_to_str(cmd->fields[i].out_value, + (cmd->fields[i].num_bits > DEBUG_JTAG_IOZ) + ? DEBUG_JTAG_IOZ + : cmd->fields[i].num_bits, 16); + + LOG_DEBUG("fields[%i].out_value[%i]: 0x%s", i, + cmd->fields[i].num_bits, char_buf); + free(char_buf); + } buf_set_buf(cmd->fields[i].out_value, 0, *buffer, bit_count, cmd->fields[i].num_bits); } else { - DEBUG_JTAG_IO("fields[%i].out_value[%i]: NULL", + LOG_DEBUG_IO("fields[%i].out_value[%i]: NULL", i, cmd->fields[i].num_bits); } bit_count += cmd->fields[i].num_bits; } - /*DEBUG_JTAG_IO("bit_count totalling: %i", bit_count); */ + /*LOG_DEBUG_IO("bit_count totalling: %i", bit_count); */ return bit_count; } @@ -242,16 +242,16 @@ int jtag_read_buffer(uint8_t *buffer, const struct scan_command *cmd) uint8_t *captured = buf_set_buf(buffer, bit_count, malloc(DIV_ROUND_UP(num_bits, 8)), 0, num_bits); -#ifdef _DEBUG_JTAG_IO_ - char *char_buf = buf_to_str(captured, - (num_bits > DEBUG_JTAG_IOZ) + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { + char *char_buf = buf_to_str(captured, + (num_bits > DEBUG_JTAG_IOZ) ? DEBUG_JTAG_IOZ - : num_bits, 16); + : num_bits, 16); - LOG_DEBUG("fields[%i].in_value[%i]: 0x%s", - i, num_bits, char_buf); - free(char_buf); -#endif + LOG_DEBUG("fields[%i].in_value[%i]: 0x%s", + i, num_bits, char_buf); + free(char_buf); + } if (cmd->fields[i].in_value) buf_cpy(captured, cmd->fields[i].in_value, num_bits); diff --git a/src/jtag/core.c b/src/jtag/core.c index 876faae..5e7c1e4 100644 --- a/src/jtag/core.c +++ b/src/jtag/core.c @@ -1007,7 +1007,7 @@ static bool jtag_examine_chain_match_tap(const struct jtag_tap *tap) return true; /* optionally ignore the JTAG version field - bits 28-31 of IDCODE */ - uint32_t mask = tap->ignore_version ? ~(0xf << 28) : ~0; + uint32_t mask = tap->ignore_version ? ~(0xfU << 28) : ~0U; uint32_t idcode = tap->idcode & mask; /* Loop over the expected identification codes and test for a match */ @@ -1348,19 +1348,6 @@ int adapter_init(struct command_context *cmd_ctx) return retval; jtag = jtag_interface; - /* LEGACY SUPPORT ... adapter drivers must declare what - * transports they allow. Until they all do so, assume - * the legacy drivers are JTAG-only - */ - if (!transports_are_declared()) { - LOG_ERROR("Adapter driver '%s' did not declare " - "which transports it allows; assuming " - "JTAG-only", jtag->name); - retval = allow_transports(cmd_ctx, jtag_only); - if (retval != ERROR_OK) - return retval; - } - if (jtag->speed == NULL) { LOG_INFO("This adapter doesn't support configurable speed"); return ERROR_OK; @@ -1611,14 +1598,18 @@ static int adapter_khz_to_speed(unsigned khz, int *speed) { LOG_DEBUG("convert khz to interface specific speed value"); speed_khz = khz; - if (jtag != NULL) { - LOG_DEBUG("have interface set up"); - int speed_div1; - int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); - if (ERROR_OK != retval) - return retval; - *speed = speed_div1; + if (!jtag) + return ERROR_OK; + LOG_DEBUG("have interface set up"); + if (!jtag->khz) { + LOG_ERROR("Translation from khz to jtag_speed not implemented"); + return ERROR_FAIL; } + int speed_div1; + int retval = jtag->khz(jtag_get_speed_khz(), &speed_div1); + if (ERROR_OK != retval) + return retval; + *speed = speed_div1; return ERROR_OK; } @@ -1681,7 +1672,13 @@ int jtag_get_speed_readable(int *khz) int retval = jtag_get_speed(&jtag_speed_var); if (retval != ERROR_OK) return retval; - return jtag ? jtag->speed_div(jtag_speed_var, khz) : ERROR_OK; + if (!jtag) + return ERROR_OK; + if (!jtag->speed_div) { + LOG_ERROR("Translation from jtag_speed to khz not implemented"); + return ERROR_FAIL; + } + return jtag->speed_div(jtag_speed_var, khz); } void jtag_set_verify(bool enable) @@ -1712,12 +1709,20 @@ int jtag_power_dropout(int *dropout) LOG_ERROR("No Valid JTAG Interface Configured."); exit(-1); } - return jtag->power_dropout(dropout); + if (jtag->power_dropout) + return jtag->power_dropout(dropout); + + *dropout = 0; /* by default we can't detect power dropout */ + return ERROR_OK; } int jtag_srst_asserted(int *srst_asserted) { - return jtag->srst_asserted(srst_asserted); + if (jtag->srst_asserted) + return jtag->srst_asserted(srst_asserted); + + *srst_asserted = 0; /* by default we can't detect srst asserted */ + return ERROR_OK; } enum reset_types jtag_get_reset_config(void) diff --git a/src/jtag/drivers/amt_jtagaccel.c b/src/jtag/drivers/amt_jtagaccel.c index 57c0ce6..045672f 100644 --- a/src/jtag/drivers/amt_jtagaccel.c +++ b/src/jtag/drivers/amt_jtagaccel.c @@ -343,35 +343,27 @@ static int amt_jtagaccel_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1) tap_set_state(TAP_RESET); amt_jtagaccel_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", - cmd->cmd.runtest->num_cycles, - cmd->cmd.runtest->end_state); -#endif + LOG_DEBUG_IO("runtest %i cycles, end in %i", + cmd->cmd.runtest->num_cycles, + cmd->cmd.runtest->end_state); amt_jtagaccel_end_state(cmd->cmd.runtest->end_state); amt_jtagaccel_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); amt_jtagaccel_end_state(cmd->cmd.statemove->end_state); amt_jtagaccel_state_move(); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); -#endif + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); amt_jtagaccel_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); type = jtag_scan_type(cmd->cmd.scan); @@ -382,9 +374,7 @@ static int amt_jtagaccel_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %" PRIi32, cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: @@ -548,7 +538,7 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = %u", amt_jtagaccel_port); + command_print(CMD, "parport port = %u", amt_jtagaccel_port); return ERROR_OK; } @@ -556,7 +546,7 @@ COMMAND_HANDLER(amt_jtagaccel_handle_parport_port_command) COMMAND_HANDLER(amt_jtagaccel_handle_rtck_command) { if (CMD_ARGC == 0) { - command_print(CMD_CTX, + command_print(CMD, "amt_jtagaccel RTCK feature %s", (rtck_enabled) ? "enabled" : "disabled"); return ERROR_OK; @@ -596,6 +586,7 @@ static const struct command_registration amtjtagaccel_command_handlers[] = { struct jtag_interface amt_jtagaccel_interface = { .name = "amt_jtagaccel", + .transports = jtag_only, .commands = amtjtagaccel_command_handlers, .init = amt_jtagaccel_init, diff --git a/src/jtag/drivers/arm-jtag-ew.c b/src/jtag/drivers/arm-jtag-ew.c index d9ea367..285bf9b 100644 --- a/src/jtag/drivers/arm-jtag-ew.c +++ b/src/jtag/drivers/arm-jtag-ew.c @@ -106,7 +106,7 @@ static int armjtagew_execute_queue(void) while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %i", + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ cmd->cmd.runtest->end_state); @@ -115,14 +115,14 @@ static int armjtagew_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); armjtagew_end_state(cmd->cmd.statemove->end_state); armjtagew_state_move(); break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %i", \ + LOG_DEBUG_IO("pathmove: %i states, end in %i", \ cmd->cmd.pathmove->num_states, \ cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -131,12 +131,12 @@ static int armjtagew_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); armjtagew_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - DEBUG_JTAG_IO("scan input, length = %d", scan_size); + LOG_DEBUG_IO("scan input, length = %d", scan_size); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(buffer, (scan_size + 7) / 8); @@ -148,7 +148,7 @@ static int armjtagew_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); @@ -160,7 +160,7 @@ static int armjtagew_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); armjtagew_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; @@ -490,6 +490,7 @@ static const struct command_registration armjtagew_command_handlers[] = { .handler = &armjtagew_handle_armjtagew_info_command, .mode = COMMAND_EXEC, .help = "query armjtagew info", + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -646,7 +647,7 @@ static int armjtagew_tap_execute(void) /* Copy to buffer */ buf_set_buf(tdo_buffer, first, buffer, 0, length); - DEBUG_JTAG_IO("pending scan result, length = %d", length); + LOG_DEBUG_IO("pending scan result, length = %d", length); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(buffer, byte_length); @@ -746,7 +747,7 @@ static int armjtagew_usb_write(struct armjtagew *armjtagew, int out_length) result = usb_bulk_write(armjtagew->usb_handle, ARMJTAGEW_EPT_BULK_OUT, \ (char *)usb_out_buffer, out_length, ARMJTAGEW_USB_TIMEOUT); - DEBUG_JTAG_IO("armjtagew_usb_write, out_length = %d, result = %d", out_length, result); + 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); @@ -760,7 +761,7 @@ 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); - DEBUG_JTAG_IO("armjtagew_usb_read, result = %d", result); + LOG_DEBUG_IO("armjtagew_usb_read, result = %d", result); #ifdef _DEBUG_USB_COMMS_ armjtagew_debug_buffer(usb_in_buffer, result); diff --git a/src/jtag/drivers/at91rm9200.c b/src/jtag/drivers/at91rm9200.c index 0015da0..ac65563 100644 --- a/src/jtag/drivers/at91rm9200.c +++ b/src/jtag/drivers/at91rm9200.c @@ -183,7 +183,8 @@ static const struct command_registration at91rm9200_command_handlers[] = { .name = "at91rm9200_device", .handler = &at91rm9200_handle_device_command, .mode = COMMAND_CONFIG, - .help = "query armjtagew info", + .help = "Set at91rm9200 device [default \"rea_ecr\"]", + .usage = "<device>", }, COMMAND_REGISTRATION_DONE }; @@ -191,6 +192,7 @@ static const struct command_registration at91rm9200_command_handlers[] = { struct jtag_interface at91rm9200_interface = { .name = "at91rm9200", .execute_queue = bitbang_execute_queue, + .transports = jtag_only, .commands = at91rm9200_command_handlers, .init = at91rm9200_init, .quit = at91rm9200_quit, diff --git a/src/jtag/drivers/bcm2835gpio.c b/src/jtag/drivers/bcm2835gpio.c index 38ef163..36e10b6 100644 --- a/src/jtag/drivers/bcm2835gpio.c +++ b/src/jtag/drivers/bcm2835gpio.c @@ -199,7 +199,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "BCM2835 GPIO config: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -211,7 +211,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tck = %d", tck_gpio); + command_print(CMD, "BCM2835 GPIO config: tck = %d", tck_gpio); return ERROR_OK; } @@ -220,7 +220,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tms = %d", tms_gpio); + command_print(CMD, "BCM2835 GPIO config: tms = %d", tms_gpio); return ERROR_OK; } @@ -229,7 +229,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tdo = %d", tdo_gpio); + command_print(CMD, "BCM2835 GPIO config: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -238,7 +238,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: tdi = %d", tdi_gpio); + command_print(CMD, "BCM2835 GPIO config: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -247,7 +247,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: srst = %d", srst_gpio); + command_print(CMD, "BCM2835 GPIO config: srst = %d", srst_gpio); return ERROR_OK; } @@ -256,7 +256,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "BCM2835 GPIO config: trst = %d", trst_gpio); + command_print(CMD, "BCM2835 GPIO config: trst = %d", trst_gpio); return ERROR_OK; } @@ -269,7 +269,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "BCM2835 GPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -281,7 +281,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "BCM2835 num: swclk = %d", swclk_gpio); + command_print(CMD, "BCM2835 num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -290,7 +290,7 @@ COMMAND_HANDLER(bcm2835gpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "BCM2835 num: swdio = %d", swdio_gpio); + command_print(CMD, "BCM2835 num: swdio = %d", swdio_gpio); return ERROR_OK; } @@ -300,6 +300,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], speed_coeff); COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } + + command_print(CMD, "BCM2835 GPIO: speed_coeffs = %d, speed_offset = %d", + speed_coeff, speed_offset); return ERROR_OK; } @@ -307,6 +310,9 @@ COMMAND_HANDLER(bcm2835gpio_handle_peripheral_base) { if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], bcm2835_peri_base); + + command_print(CMD, "BCM2835 GPIO: peripheral_base = 0x%08x", + bcm2835_peri_base); return ERROR_OK; } @@ -316,74 +322,84 @@ static const struct command_registration bcm2835gpio_command_handlers[] = { .handler = &bcm2835gpio_handle_jtag_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for tck, tms, tdi, tdo. (in that order)", - .usage = "(tck tms tdi tdo)* ", + .usage = "[tck tms tdi tdo]", }, { .name = "bcm2835gpio_tck_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tck, .mode = COMMAND_CONFIG, .help = "gpio number for tck.", + .usage = "[tck]", }, { .name = "bcm2835gpio_tms_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tms, .mode = COMMAND_CONFIG, .help = "gpio number for tms.", + .usage = "[tms]", }, { .name = "bcm2835gpio_tdo_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tdo, .mode = COMMAND_CONFIG, .help = "gpio number for tdo.", + .usage = "[tdo]", }, { .name = "bcm2835gpio_tdi_num", .handler = &bcm2835gpio_handle_jtag_gpionum_tdi, .mode = COMMAND_CONFIG, .help = "gpio number for tdi.", + .usage = "[tdi]", }, { .name = "bcm2835gpio_swd_nums", .handler = &bcm2835gpio_handle_swd_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for swclk, swdio. (in that order)", - .usage = "(swclk swdio)* ", + .usage = "[swclk swdio]", }, { .name = "bcm2835gpio_swclk_num", .handler = &bcm2835gpio_handle_swd_gpionum_swclk, .mode = COMMAND_CONFIG, .help = "gpio number for swclk.", + .usage = "[swclk]", }, { .name = "bcm2835gpio_swdio_num", .handler = &bcm2835gpio_handle_swd_gpionum_swdio, .mode = COMMAND_CONFIG, .help = "gpio number for swdio.", + .usage = "[swdio]", }, { .name = "bcm2835gpio_srst_num", .handler = &bcm2835gpio_handle_jtag_gpionum_srst, .mode = COMMAND_CONFIG, .help = "gpio number for srst.", + .usage = "[srst]", }, { .name = "bcm2835gpio_trst_num", .handler = &bcm2835gpio_handle_jtag_gpionum_trst, .mode = COMMAND_CONFIG, .help = "gpio number for trst.", + .usage = "[trst]", }, { .name = "bcm2835gpio_speed_coeffs", .handler = &bcm2835gpio_handle_speed_coeffs, .mode = COMMAND_CONFIG, .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.", + .usage = "[SPEED_COEFF SPEED_OFFSET]", }, { .name = "bcm2835gpio_peripheral_base", .handler = &bcm2835gpio_handle_peripheral_base, .mode = COMMAND_CONFIG, .help = "peripheral base to access GPIOs (RPi1 0x20000000, RPi2 0x3F000000).", + .usage = "[base]", }, COMMAND_REGISTRATION_DONE diff --git a/src/jtag/drivers/bitbang.c b/src/jtag/drivers/bitbang.c index da4fb33..b5078c0 100644 --- a/src/jtag/drivers/bitbang.c +++ b/src/jtag/drivers/bitbang.c @@ -100,7 +100,7 @@ static int bitbang_execute_tms(struct jtag_command *cmd) unsigned num_bits = cmd->cmd.tms->num_bits; const uint8_t *bits = cmd->cmd.tms->bits; - DEBUG_JTAG_IO("TMS: %d bits", num_bits); + LOG_DEBUG_IO("TMS: %d bits", num_bits); int tms = 0; for (unsigned i = 0; i < num_bits; i++) { @@ -315,11 +315,9 @@ int bitbang_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) tap_set_state(TAP_RESET); @@ -328,11 +326,9 @@ int bitbang_execute_queue(void) return ERROR_FAIL; break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); -#endif bitbang_end_state(cmd->cmd.runtest->end_state); if (bitbang_runtest(cmd->cmd.runtest->num_cycles) != ERROR_OK) return ERROR_FAIL; @@ -347,32 +343,26 @@ int bitbang_execute_queue(void) break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); -#endif bitbang_end_state(cmd->cmd.statemove->end_state); if (bitbang_state_move(0) != ERROR_OK) return ERROR_FAIL; break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1])); -#endif if (bitbang_path_move(cmd->cmd.pathmove) != ERROR_OK) return ERROR_FAIL; break; case JTAG_SCAN: bitbang_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan %d bits; end in %s", + LOG_DEBUG_IO("%s scan %d bits; end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(cmd->cmd.scan->end_state)); -#endif type = jtag_scan_type(cmd->cmd.scan); if (bitbang_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size) != ERROR_OK) @@ -383,9 +373,7 @@ int bitbang_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %" PRIi32, cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_TMS: diff --git a/src/jtag/drivers/bitq.c b/src/jtag/drivers/bitq.c index 55dfe0a..9b4eeed 100644 --- a/src/jtag/drivers/bitq.c +++ b/src/jtag/drivers/bitq.c @@ -59,9 +59,7 @@ static void bitq_in_proc(void) int tdo = bitq_interface->in(); if (tdo < 0) { -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("bitq in EOF"); -#endif + LOG_DEBUG_IO("bitq in EOF"); return; } if (in_mask == 0x01) @@ -228,9 +226,7 @@ int bitq_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) @@ -241,37 +237,26 @@ int bitq_execute_queue(void) break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); bitq_end_state(cmd->cmd.runtest->end_state); bitq_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); bitq_end_state(cmd->cmd.statemove->end_state); bitq_state_move(tap_get_end_state()); /* uncoditional TAP move */ break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif bitq_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); - if (cmd->cmd.scan->ir_scan) - LOG_DEBUG("scan ir"); - else - LOG_DEBUG("scan dr"); -#endif + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan %s", cmd->cmd.scan->ir_scan ? "ir" : "dr"); bitq_end_state(cmd->cmd.scan->end_state); bitq_scan(cmd->cmd.scan); if (tap_get_state() != tap_get_end_state()) @@ -279,9 +264,7 @@ int bitq_execute_queue(void) break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); bitq_interface->sleep(cmd->cmd.sleep->us); if (bitq_interface->in_rdy()) bitq_in_proc(); diff --git a/src/jtag/drivers/buspirate.c b/src/jtag/drivers/buspirate.c index 35649c2..872896b 100644 --- a/src/jtag/drivers/buspirate.c +++ b/src/jtag/drivers/buspirate.c @@ -171,7 +171,7 @@ static int buspirate_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest ->end_state)); @@ -181,7 +181,7 @@ static int buspirate_execute_queue(void) ->num_cycles); break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove ->end_state)); buspirate_end_state(cmd->cmd.statemove @@ -189,7 +189,7 @@ static int buspirate_execute_queue(void) buspirate_state_move(); break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove ->path[cmd->cmd.pathmove @@ -199,7 +199,7 @@ static int buspirate_execute_queue(void) cmd->cmd.pathmove->path); break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %s", + LOG_DEBUG_IO("scan end in %s", tap_state_name(cmd->cmd.scan ->end_state)); @@ -214,7 +214,7 @@ static int buspirate_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); /* flush buffers, so we can reset */ @@ -226,12 +226,12 @@ static int buspirate_execute_queue(void) cmd->cmd.reset->srst); break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); buspirate_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_STABLECLOCKS: - DEBUG_JTAG_IO("stable clock %i cycles", cmd->cmd.stableclocks->num_cycles); + LOG_DEBUG_IO("stable clock %i cycles", cmd->cmd.stableclocks->num_cycles); buspirate_stableclocks(cmd->cmd.stableclocks->num_cycles); break; default: @@ -491,6 +491,7 @@ static const struct command_registration buspirate_command_handlers[] = { .handler = &buspirate_handle_adc_command, .mode = COMMAND_EXEC, .help = "reads voltages on adc pins", + .usage = "", }, { .name = "buspirate_vreg", @@ -623,7 +624,7 @@ static void buspirate_runtest(int num_cycles) for (i = 0; i < num_cycles; i++) buspirate_tap_append(0, 0); - DEBUG_JTAG_IO("runtest: cur_state %s end_state %s", + LOG_DEBUG_IO("runtest: cur_state %s end_state %s", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state())); @@ -1311,7 +1312,7 @@ static int buspirate_swd_switch_seq(enum swd_special_seq seq) { const uint8_t *sequence; int sequence_len; - uint8_t tmp[64]; + uint32_t no_bytes, sequence_offset; switch (seq) { case LINE_RESET: @@ -1334,15 +1335,24 @@ static int buspirate_swd_switch_seq(enum swd_special_seq seq) return ERROR_FAIL; } - /* FIXME: all above sequences fit into one pirate command for now - * but it may cause trouble later - */ + no_bytes = sequence_len; + sequence_offset = 0; + + while (no_bytes) { + uint8_t tmp[17]; + uint32_t to_send; + + to_send = no_bytes > 16 ? 16 : no_bytes; + + tmp[0] = 0x10 + ((to_send - 1) & 0x0F); + memcpy(tmp + 1, &sequence[sequence_offset], to_send); - tmp[0] = 0x10 + ((sequence_len - 1) & 0x0F); - memcpy(tmp + 1, sequence, sequence_len); + buspirate_serial_write(buspirate_fd, tmp, to_send + 1); + buspirate_serial_read(buspirate_fd, tmp, to_send + 1); - buspirate_serial_write(buspirate_fd, tmp, sequence_len + 1); - buspirate_serial_read(buspirate_fd, tmp, sequence_len + 1); + no_bytes -= to_send; + sequence_offset += to_send; + } return ERROR_OK; } diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 14a23d4..d52d698 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -1246,7 +1246,7 @@ static void cmsis_dap_flush(void) if (!queued_seq_count) return; - DEBUG_JTAG_IO("Flushing %d queued sequences (%d bytes) with %d pending scan results to capture", + 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 */ @@ -1268,7 +1268,7 @@ static void cmsis_dap_flush(void) } #ifdef CMSIS_DAP_JTAG_DEBUG - DEBUG_JTAG_IO("USB response buf:"); + LOG_DEBUG_IO("USB response buf:"); for (int c = 0; c < queued_seq_buf_end + 3; ++c) printf("%02X ", buffer[c]); printf("\n"); @@ -1277,7 +1277,7 @@ static void cmsis_dap_flush(void) /* copy scan results into client buffers */ for (int i = 0; i < pending_scan_result_count; ++i) { struct pending_scan_result *scan = &pending_scan_results[i]; - DEBUG_JTAG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits", + LOG_DEBUG_IO("Copying pending_scan_result %d/%d: %d bits from byte %d -> buffer + %d bits", 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) @@ -1302,7 +1302,7 @@ static void cmsis_dap_flush(void) static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int s_offset, bool tms, uint8_t *tdo_buffer, int tdo_buffer_offset) { - DEBUG_JTAG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d", + LOG_DEBUG_IO("[at %d] %d bits, tms %s, seq offset %d, tdo buf %p, tdo offset %d", queued_seq_buf_end, s_len, tms ? "HIGH" : "LOW", s_offset, tdo_buffer, tdo_buffer_offset); @@ -1310,12 +1310,12 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int return; if (s_len > 64) { - DEBUG_JTAG_IO("START JTAG SEQ SPLIT"); + LOG_DEBUG_IO("START JTAG SEQ SPLIT"); for (int offset = 0; offset < s_len; offset += 64) { int len = s_len - offset; if (len > 64) len = 64; - DEBUG_JTAG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset); + LOG_DEBUG_IO("Splitting long jtag sequence: %d-bit chunk starting at offset %d", len, offset); cmsis_dap_add_jtag_sequence( len, sequence, @@ -1325,7 +1325,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int tdo_buffer == NULL ? 0 : (tdo_buffer_offset + offset) ); } - DEBUG_JTAG_IO("END JTAG SEQ SPLIT"); + LOG_DEBUG_IO("END JTAG SEQ SPLIT"); return; } @@ -1362,7 +1362,7 @@ static void cmsis_dap_add_jtag_sequence(int s_len, const uint8_t *sequence, int /* queue a sequence of bits to clock out TMS, executing if the buffer is full */ static void cmsis_dap_add_tms_sequence(const uint8_t *sequence, int s_len) { - DEBUG_JTAG_IO("%d bits: %02X", s_len, *sequence); + LOG_DEBUG_IO("%d bits: %02X", s_len, *sequence); /* we use a series of CMD_DAP_JTAG_SEQ commands to toggle TMS, because even though it seems ridiculously inefficient, it allows us to combine TMS and scan sequences into the same @@ -1383,7 +1383,7 @@ static void cmsis_dap_state_move(void) tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); tms_scan_bits = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); - DEBUG_JTAG_IO("state move from %s to %s: %d clocks, %02X on tms", + LOG_DEBUG_IO("state move from %s to %s: %d clocks, %02X on tms", tap_state_name(tap_get_state()), tap_state_name(tap_get_end_state()), tms_scan_bits, tms_scan); cmsis_dap_add_tms_sequence(&tms_scan, tms_scan_bits); @@ -1395,7 +1395,7 @@ static void cmsis_dap_state_move(void) /* Execute a JTAG scan operation by queueing TMS and TDI/TDO sequences */ static void cmsis_dap_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ @@ -1429,7 +1429,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -1437,7 +1437,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) field->num_bits); if (i == cmd->cmd.scan->num_fields - 1 && tap_get_state() != tap_get_end_state()) { - DEBUG_JTAG_IO("Last field and have to move out of SHIFT state"); + LOG_DEBUG_IO("Last field and have to move out of SHIFT state"); /* Last field, and we're leaving IRSHIFT/DRSHIFT. Clock last bit during tap * movement. This last field can't have length zero, it was checked above. */ cmsis_dap_add_jtag_sequence( @@ -1471,7 +1471,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) 0); tap_set_state(tap_state_transition(tap_get_state(), 0)); } else { - DEBUG_JTAG_IO("Internal field, staying in SHIFT state afterwards"); + LOG_DEBUG_IO("Internal field, staying in SHIFT state afterwards"); /* Clocking part of a sequence into DR or IR with TMS=0, leaving TMS=0 at the end so we can continue later */ cmsis_dap_add_jtag_sequence( @@ -1489,7 +1489,7 @@ static void cmsis_dap_execute_scan(struct jtag_command *cmd) cmsis_dap_state_move(); } - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } @@ -1519,7 +1519,7 @@ static void cmsis_dap_pathmove(int num_states, tap_state_t *path) static void cmsis_dap_execute_pathmove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("pathmove: %i states, end in %i", + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -1557,7 +1557,7 @@ static void cmsis_dap_runtest(int num_cycles) static void cmsis_dap_execute_runtest(struct jtag_command *cmd) { - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); cmsis_dap_end_state(cmd->cmd.runtest->end_state); @@ -1566,13 +1566,13 @@ static void cmsis_dap_execute_runtest(struct jtag_command *cmd) static void cmsis_dap_execute_stableclocks(struct jtag_command *cmd) { - DEBUG_JTAG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); + LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); cmsis_dap_stableclocks(cmd->cmd.runtest->num_cycles); } static void cmsis_dap_execute_tms(struct jtag_command *cmd) { - DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); + LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); cmsis_dap_cmd_DAP_SWJ_Sequence(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits); } @@ -1653,15 +1653,6 @@ static int cmsis_dap_khz(int khz, int *jtag_speed) return ERROR_OK; } -static int_least32_t cmsis_dap_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - cmsis_dap_speed(hz / 1000); - - return hz; -} - - COMMAND_HANDLER(cmsis_dap_handle_info_command) { if (cmsis_dap_get_version_info() == ERROR_OK) @@ -1790,7 +1781,6 @@ static const struct command_registration cmsis_dap_command_handlers[] = { static const struct swd_driver cmsis_dap_swd_driver = { .init = cmsis_dap_swd_init, - .frequency = cmsis_dap_swd_frequency, .switch_seq = cmsis_dap_swd_switch_seq, .read_reg = cmsis_dap_swd_read_reg, .write_reg = cmsis_dap_swd_write_reg, diff --git a/src/jtag/drivers/dummy.c b/src/jtag/drivers/dummy.c index db1ba13..4e5b615 100644 --- a/src/jtag/drivers/dummy.c +++ b/src/jtag/drivers/dummy.c @@ -136,8 +136,8 @@ static const struct command_registration dummy_command_handlers[] = { .name = "dummy", .mode = COMMAND_ANY, .help = "dummy interface driver commands", - .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE, }; diff --git a/src/jtag/drivers/ep93xx.c b/src/jtag/drivers/ep93xx.c index 36fc777..4cf3184 100644 --- a/src/jtag/drivers/ep93xx.c +++ b/src/jtag/drivers/ep93xx.c @@ -55,6 +55,7 @@ struct jtag_interface ep93xx_interface = { .supported = DEBUG_CAP_TMS_SEQ, .execute_queue = bitbang_execute_queue, + .transports = jtag_only, .init = ep93xx_init, .quit = ep93xx_quit, diff --git a/src/jtag/drivers/ft232r.c b/src/jtag/drivers/ft232r.c index e16bcdc..8cda76e 100644 --- a/src/jtag/drivers/ft232r.c +++ b/src/jtag/drivers/ft232r.c @@ -442,7 +442,7 @@ COMMAND_HANDLER(ft232r_handle_jtag_nums_command) if (tdo_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R nums: TCK = %d %s, TMS = %d %s, TDI = %d %s, TDO = %d %s", tck_gpio, ft232r_bit_number_to_name(tck_gpio), tms_gpio, ft232r_bit_number_to_name(tms_gpio), @@ -462,7 +462,7 @@ COMMAND_HANDLER(ft232r_handle_tck_num_command) if (tck_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TCK = %d %s", tck_gpio, ft232r_bit_number_to_name(tck_gpio)); return ERROR_OK; @@ -478,7 +478,7 @@ COMMAND_HANDLER(ft232r_handle_tms_num_command) if (tms_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TMS = %d %s", tms_gpio, ft232r_bit_number_to_name(tms_gpio)); return ERROR_OK; @@ -494,7 +494,7 @@ COMMAND_HANDLER(ft232r_handle_tdo_num_command) if (tdo_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TDO = %d %s", tdo_gpio, ft232r_bit_number_to_name(tdo_gpio)); return ERROR_OK; @@ -510,7 +510,7 @@ COMMAND_HANDLER(ft232r_handle_tdi_num_command) if (tdi_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TDI = %d %s", tdi_gpio, ft232r_bit_number_to_name(tdi_gpio)); return ERROR_OK; @@ -526,7 +526,7 @@ COMMAND_HANDLER(ft232r_handle_trst_num_command) if (ntrst_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: TRST = %d %s", ntrst_gpio, ft232r_bit_number_to_name(ntrst_gpio)); return ERROR_OK; @@ -542,7 +542,7 @@ COMMAND_HANDLER(ft232r_handle_srst_num_command) if (nsysrst_gpio < 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R num: SRST = %d %s", nsysrst_gpio, ft232r_bit_number_to_name(nsysrst_gpio)); return ERROR_OK; @@ -555,7 +555,7 @@ COMMAND_HANDLER(ft232r_handle_restore_serial_command) else if (CMD_ARGC != 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, + command_print(CMD, "FT232R restore serial: 0x%04X (%s)", ft232r_restore_bitmode, ft232r_restore_bitmode == 0xFFFF ? "disabled" : "enabled"); @@ -675,7 +675,7 @@ static int syncbb_execute_tms(struct jtag_command *cmd) unsigned num_bits = cmd->cmd.tms->num_bits; const uint8_t *bits = cmd->cmd.tms->bits; - DEBUG_JTAG_IO("TMS: %d bits", num_bits); + LOG_DEBUG_IO("TMS: %d bits", num_bits); int tms = 0; for (unsigned i = 0; i < num_bits; i++) { diff --git a/src/jtag/drivers/ftdi.c b/src/jtag/drivers/ftdi.c index 6fbcbce..48f8d83 100644 --- a/src/jtag/drivers/ftdi.c +++ b/src/jtag/drivers/ftdi.c @@ -329,7 +329,7 @@ static void move_to_state(tap_state_t goal_state) int tms_count = tap_get_tms_path_len(start_state, goal_state); assert(tms_count <= 8); - DEBUG_JTAG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); + LOG_DEBUG_IO("start=%s goal=%s", tap_state_name(start_state), tap_state_name(goal_state)); /* Track state transitions step by step */ for (int i = 0; i < tms_count; i++) @@ -391,7 +391,7 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) int i; static const uint8_t zero; - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); @@ -412,14 +412,14 @@ static void ftdi_execute_runtest(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("runtest: %i, end in %s", + LOG_DEBUG_IO("runtest: %i, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(tap_get_end_state())); } static void ftdi_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); ftdi_end_state(cmd->cmd.statemove->end_state); @@ -435,7 +435,7 @@ static void ftdi_execute_statemove(struct jtag_command *cmd) */ static void ftdi_execute_tms(struct jtag_command *cmd) { - DEBUG_JTAG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); + LOG_DEBUG_IO("TMS: %d bits", cmd->cmd.tms->num_bits); /* TODO: Missing tap state tracking, also missing from ft2232.c! */ DO_CLOCK_TMS_CS_OUT(mpsse_ctx, @@ -451,7 +451,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) tap_state_t *path = cmd->cmd.pathmove->path; int num_states = cmd->cmd.pathmove->num_states; - DEBUG_JTAG_IO("pathmove: %i states, current: %s end: %s", num_states, + LOG_DEBUG_IO("pathmove: %i states, current: %s end: %s", num_states, tap_state_name(tap_get_state()), tap_state_name(path[num_states-1])); @@ -459,7 +459,7 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) unsigned bit_count = 0; uint8_t tms_byte = 0; - DEBUG_JTAG_IO("-"); + LOG_DEBUG_IO("-"); /* this loop verifies that the path is legal and logs each state in the path */ while (num_states--) { @@ -499,18 +499,18 @@ static void ftdi_execute_pathmove(struct jtag_command *cmd) static void ftdi_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ while (cmd->cmd.scan->num_fields > 0 && cmd->cmd.scan->fields[cmd->cmd.scan->num_fields - 1].num_bits == 0) { cmd->cmd.scan->num_fields--; - DEBUG_JTAG_IO("discarding trailing empty field"); + LOG_DEBUG_IO("discarding trailing empty field"); } if (cmd->cmd.scan->num_fields == 0) { - DEBUG_JTAG_IO("empty scan, doing nothing"); + LOG_DEBUG_IO("empty scan, doing nothing"); return; } @@ -529,7 +529,7 @@ static void ftdi_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -579,14 +579,14 @@ static void ftdi_execute_scan(struct jtag_command *cmd) if (tap_get_state() != tap_get_end_state()) move_to_state(tap_get_end_state()); - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } static void ftdi_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1 @@ -622,17 +622,17 @@ static void ftdi_execute_reset(struct jtag_command *cmd) ftdi_set_signal(srst, 'z'); } - DEBUG_JTAG_IO("trst: %i, srst: %i", + LOG_DEBUG_IO("trst: %i, srst: %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); } static void ftdi_execute_sleep(struct jtag_command *cmd) { - DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); mpsse_flush(mpsse_ctx); jtag_sleep(cmd->cmd.sleep->us); - DEBUG_JTAG_IO("sleep %" PRIi32 " usec while in %s", + LOG_DEBUG_IO("sleep %" PRIi32 " usec while in %s", cmd->cmd.sleep->us, tap_state_name(tap_get_state())); } @@ -656,7 +656,7 @@ static void ftdi_execute_stableclocks(struct jtag_command *cmd) num_cycles -= this_len; } - DEBUG_JTAG_IO("clocks %i while in %s", + LOG_DEBUG_IO("clocks %i while in %s", cmd->cmd.stableclocks->num_cycles, tap_state_name(tap_get_state())); } @@ -1262,7 +1262,7 @@ COMMAND_HANDLER(ftdi_handle_tdo_sample_edge_command) } n = Jim_Nvp_value2name_simple(nvp_ftdi_jtag_modes, ftdi_jtag_mode); - command_print(CMD_CTX, "ftdi samples TDO on %s edge of TCK", n->name); + command_print(CMD, "ftdi samples TDO on %s edge of TCK", n->name); return ERROR_OK; } @@ -1558,14 +1558,6 @@ static void ftdi_swd_write_reg(uint8_t cmd, uint32_t value, uint32_t ap_delay_cl ftdi_swd_queue_cmd(cmd, NULL, value, ap_delay_clk); } -static int_least32_t ftdi_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - freq = mpsse_set_frequency(mpsse_ctx, hz); - - return freq; -} - static int ftdi_swd_switch_seq(enum swd_special_seq seq) { switch (seq) { @@ -1594,7 +1586,6 @@ static int ftdi_swd_switch_seq(enum swd_special_seq seq) static const struct swd_driver ftdi_swd = { .init = ftdi_swd_init, - .frequency = ftdi_swd_frequency, .switch_seq = ftdi_swd_switch_seq, .read_reg = ftdi_swd_read_reg, .write_reg = ftdi_swd_write_reg, diff --git a/src/jtag/drivers/gw16012.c b/src/jtag/drivers/gw16012.c index f668996..e65f56c 100644 --- a/src/jtag/drivers/gw16012.c +++ b/src/jtag/drivers/gw16012.c @@ -297,43 +297,33 @@ static int gw16012_execute_queue(void) while (cmd) { switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); if (cmd->cmd.reset->trst == 1) tap_set_state(TAP_RESET); gw16012_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif gw16012_end_state(cmd->cmd.runtest->end_state); gw16012_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); gw16012_end_state(cmd->cmd.statemove->end_state); gw16012_state_move(); break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif gw16012_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: gw16012_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); type = jtag_scan_type(cmd->cmd.scan); -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan (%i) %i bit end in %i", (cmd->cmd.scan->ir_scan) ? "ir" : "dr", + LOG_DEBUG_IO("%s scan (%i) %i bit end in %i", (cmd->cmd.scan->ir_scan) ? "ir" : "dr", type, scan_size, cmd->cmd.scan->end_state); -#endif gw16012_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) retval = ERROR_JTAG_QUEUE_FAILED; @@ -341,9 +331,7 @@ static int gw16012_execute_queue(void) free(buffer); break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: @@ -515,7 +503,7 @@ COMMAND_HANDLER(gw16012_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = %u", gw16012_port); + command_print(CMD, "parport port = %u", gw16012_port); return ERROR_OK; } @@ -535,6 +523,7 @@ static const struct command_registration gw16012_command_handlers[] = { struct jtag_interface gw16012_interface = { .name = "gw16012", + .transports = jtag_only, .commands = gw16012_command_handlers, .init = gw16012_init, diff --git a/src/jtag/drivers/imx_gpio.c b/src/jtag/drivers/imx_gpio.c index f42692c..4923dab 100644 --- a/src/jtag/drivers/imx_gpio.c +++ b/src/jtag/drivers/imx_gpio.c @@ -221,7 +221,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "imx_gpio GPIO config: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -233,7 +233,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tck = %d", tck_gpio); + command_print(CMD, "imx_gpio GPIO config: tck = %d", tck_gpio); return ERROR_OK; } @@ -242,7 +242,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tms = %d", tms_gpio); + command_print(CMD, "imx_gpio GPIO config: tms = %d", tms_gpio); return ERROR_OK; } @@ -251,7 +251,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tdo = %d", tdo_gpio); + command_print(CMD, "imx_gpio GPIO config: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -260,7 +260,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: tdi = %d", tdi_gpio); + command_print(CMD, "imx_gpio GPIO config: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -269,7 +269,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: srst = %d", srst_gpio); + command_print(CMD, "imx_gpio GPIO config: srst = %d", srst_gpio); return ERROR_OK; } @@ -278,7 +278,7 @@ COMMAND_HANDLER(imx_gpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "imx_gpio GPIO config: trst = %d", trst_gpio); + command_print(CMD, "imx_gpio GPIO config: trst = %d", trst_gpio); return ERROR_OK; } @@ -291,7 +291,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "imx_gpio GPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -303,7 +303,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "imx_gpio num: swclk = %d", swclk_gpio); + command_print(CMD, "imx_gpio num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -312,7 +312,7 @@ COMMAND_HANDLER(imx_gpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "imx_gpio num: swdio = %d", swdio_gpio); + command_print(CMD, "imx_gpio num: swdio = %d", swdio_gpio); return ERROR_OK; } @@ -322,6 +322,9 @@ COMMAND_HANDLER(imx_gpio_handle_speed_coeffs) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], speed_coeff); COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], speed_offset); } + + command_print(CMD, "imx_gpio: speed_coeffs = %d, speed_offset = %d", + speed_coeff, speed_offset); return ERROR_OK; } @@ -329,6 +332,9 @@ COMMAND_HANDLER(imx_gpio_handle_peripheral_base) { if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], imx_gpio_peri_base); + + command_print(CMD, "imx_gpio: peripheral_base = 0x%08x", + imx_gpio_peri_base); return ERROR_OK; } @@ -338,74 +344,84 @@ static const struct command_registration imx_gpio_command_handlers[] = { .handler = &imx_gpio_handle_jtag_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for tck, tms, tdi, tdo. (in that order)", - .usage = "(tck tms tdi tdo)* ", + .usage = "[tck tms tdi tdo]", }, { .name = "imx_gpio_tck_num", .handler = &imx_gpio_handle_jtag_gpionum_tck, .mode = COMMAND_CONFIG, .help = "gpio number for tck.", + .usage = "[tck]", }, { .name = "imx_gpio_tms_num", .handler = &imx_gpio_handle_jtag_gpionum_tms, .mode = COMMAND_CONFIG, .help = "gpio number for tms.", + .usage = "[tms]", }, { .name = "imx_gpio_tdo_num", .handler = &imx_gpio_handle_jtag_gpionum_tdo, .mode = COMMAND_CONFIG, .help = "gpio number for tdo.", + .usage = "[tdo]", }, { .name = "imx_gpio_tdi_num", .handler = &imx_gpio_handle_jtag_gpionum_tdi, .mode = COMMAND_CONFIG, .help = "gpio number for tdi.", + .usage = "[tdi]", }, { .name = "imx_gpio_swd_nums", .handler = &imx_gpio_handle_swd_gpionums, .mode = COMMAND_CONFIG, .help = "gpio numbers for swclk, swdio. (in that order)", - .usage = "(swclk swdio)* ", + .usage = "[swclk swdio]", }, { .name = "imx_gpio_swclk_num", .handler = &imx_gpio_handle_swd_gpionum_swclk, .mode = COMMAND_CONFIG, .help = "gpio number for swclk.", + .usage = "[swclk]", }, { .name = "imx_gpio_swdio_num", .handler = &imx_gpio_handle_swd_gpionum_swdio, .mode = COMMAND_CONFIG, .help = "gpio number for swdio.", + .usage = "[swdio]", }, { .name = "imx_gpio_srst_num", .handler = &imx_gpio_handle_jtag_gpionum_srst, .mode = COMMAND_CONFIG, .help = "gpio number for srst.", + .usage = "[srst]", }, { .name = "imx_gpio_trst_num", .handler = &imx_gpio_handle_jtag_gpionum_trst, .mode = COMMAND_CONFIG, .help = "gpio number for trst.", + .usage = "[trst]", }, { .name = "imx_gpio_speed_coeffs", .handler = &imx_gpio_handle_speed_coeffs, .mode = COMMAND_CONFIG, .help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.", + .usage = "[SPEED_COEFF SPEED_OFFSET]", }, { .name = "imx_gpio_peripheral_base", .handler = &imx_gpio_handle_peripheral_base, .mode = COMMAND_CONFIG, .help = "peripheral base to access GPIOs (0x0209c000 for most IMX).", + .usage = "[base]", }, COMMAND_REGISTRATION_DONE diff --git a/src/jtag/drivers/jlink.c b/src/jtag/drivers/jlink.c index 1eae827..09b3a85 100644 --- a/src/jtag/drivers/jlink.c +++ b/src/jtag/drivers/jlink.c @@ -38,6 +38,7 @@ #include <jtag/interface.h> #include <jtag/swd.h> #include <jtag/commands.h> +#include <jtag/drivers/jtag_usb_common.h> #include <libjaylink/libjaylink.h> @@ -50,6 +51,7 @@ static uint8_t caps[JAYLINK_DEV_EXT_CAPS_SIZE]; static uint32_t serial_number; static bool use_serial_number; +static bool use_usb_location; static enum jaylink_usb_address usb_address; static bool use_usb_address; static enum jaylink_target_interface iface = JAYLINK_TIF_JTAG; @@ -122,13 +124,13 @@ static int queued_retval; static void jlink_execute_stableclocks(struct jtag_command *cmd) { - DEBUG_JTAG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); + LOG_DEBUG_IO("stableclocks %i cycles", cmd->cmd.runtest->num_cycles); jlink_stableclocks(cmd->cmd.runtest->num_cycles); } static void jlink_execute_runtest(struct jtag_command *cmd) { - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); jlink_end_state(cmd->cmd.runtest->end_state); @@ -137,7 +139,7 @@ static void jlink_execute_runtest(struct jtag_command *cmd) static void jlink_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); jlink_end_state(cmd->cmd.statemove->end_state); jlink_state_move(); @@ -145,7 +147,7 @@ static void jlink_execute_statemove(struct jtag_command *cmd) static void jlink_execute_pathmove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("pathmove: %i states, end in %i", + LOG_DEBUG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -154,7 +156,7 @@ static void jlink_execute_pathmove(struct jtag_command *cmd) static void jlink_execute_scan(struct jtag_command *cmd) { - DEBUG_JTAG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", + LOG_DEBUG_IO("%s type:%d", cmd->cmd.scan->ir_scan ? "IRSCAN" : "DRSCAN", jtag_scan_type(cmd->cmd.scan)); /* Make sure there are no trailing fields with num_bits == 0, or the logic below will fail. */ @@ -188,7 +190,7 @@ static void jlink_execute_scan(struct jtag_command *cmd) for (int i = 0; i < cmd->cmd.scan->num_fields; i++, field++) { scan_size += field->num_bits; - DEBUG_JTAG_IO("%s%s field %d/%d %d bits", + LOG_DEBUG_IO("%s%s field %d/%d %d bits", field->in_value ? "in" : "", field->out_value ? "out" : "", i, @@ -240,14 +242,14 @@ static void jlink_execute_scan(struct jtag_command *cmd) jlink_state_move(); } - DEBUG_JTAG_IO("%s scan, %i bits, end in %s", + LOG_DEBUG_IO("%s scan, %i bits, end in %s", (cmd->cmd.scan->ir_scan) ? "IR" : "DR", scan_size, tap_state_name(tap_get_end_state())); } static void jlink_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); jlink_flush(); @@ -257,7 +259,7 @@ static void jlink_execute_reset(struct jtag_command *cmd) static void jlink_execute_sleep(struct jtag_command *cmd) { - DEBUG_JTAG_IO("sleep %" PRIi32 "", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32 "", cmd->cmd.sleep->us); jlink_flush(); jtag_sleep(cmd->cmd.sleep->us); } @@ -534,6 +536,31 @@ static int jaylink_log_handler(const struct jaylink_context *ctx, return 0; } +static bool jlink_usb_location_equal(struct jaylink_device *dev) +{ + int retval; + uint8_t bus; + uint8_t *ports; + size_t num_ports; + bool equal = false; + + retval = jaylink_device_get_usb_bus_ports(dev, &bus, &ports, &num_ports); + + if (retval == JAYLINK_ERR_NOT_SUPPORTED) { + return false; + } else if (retval != JAYLINK_OK) { + LOG_WARNING("jaylink_device_get_usb_bus_ports() failed: %s.", + jaylink_strerror(retval)); + return false; + } + + equal = jtag_usb_location_equal(bus, ports, num_ports); + free(ports); + + return equal; +} + + static int jlink_init(void) { int ret; @@ -595,7 +622,9 @@ static int jlink_init(void) return ERROR_JTAG_INIT_FAILED; } - if (!use_serial_number && !use_usb_address && num_devices > 1) { + 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); @@ -605,8 +634,10 @@ static int jlink_init(void) 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(devs[i], &tmp); + ret = jaylink_device_get_serial_number(dev, &tmp); if (ret == JAYLINK_ERR_NOT_AVAILABLE) { continue; @@ -621,7 +652,7 @@ static int jlink_init(void) } if (use_usb_address) { - ret = jaylink_device_get_usb_address(devs[i], &address); + ret = jaylink_device_get_usb_address(dev, &address); if (ret == JAYLINK_ERR_NOT_SUPPORTED) { continue; @@ -635,7 +666,10 @@ static int jlink_init(void) continue; } - ret = jaylink_open(devs[i], &devh); + if (use_usb_location && !jlink_usb_location_equal(dev)) + continue; + + ret = jaylink_open(dev, &devh); if (ret == JAYLINK_OK) { found_device = true; @@ -923,17 +957,17 @@ COMMAND_HANDLER(jlink_usb_command) int tmp; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink usb."); + command_print(CMD, "Need exactly one argument for jlink usb."); return ERROR_COMMAND_SYNTAX_ERROR; } if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } if (tmp < JAYLINK_USB_ADDRESS_0 || tmp > JAYLINK_USB_ADDRESS_3) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } @@ -950,17 +984,17 @@ COMMAND_HANDLER(jlink_serial_command) int ret; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink serial."); + command_print(CMD, "Need exactly one argument for jlink serial."); return ERROR_COMMAND_SYNTAX_ERROR; } ret = jaylink_parse_serial_number(CMD_ARGV[0], &serial_number); if (ret == JAYLINK_ERR) { - command_print(CMD_CTX, "Invalid serial number: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid serial number: %s.", CMD_ARGV[0]); return ERROR_FAIL; } else if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_parse_serial_number() failed: %s.", + command_print(CMD, "jaylink_parse_serial_number() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } @@ -979,20 +1013,20 @@ COMMAND_HANDLER(jlink_handle_hwstatus_command) ret = jaylink_get_hardware_status(devh, &status); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_get_hardware_status() failed: %s.", + command_print(CMD, "jaylink_get_hardware_status() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } - command_print(CMD_CTX, "VTarget = %u.%03u V", + command_print(CMD, "VTarget = %u.%03u V", status.target_voltage / 1000, status.target_voltage % 1000); - command_print(CMD_CTX, "TCK = %u TDI = %u TDO = %u TMS = %u SRST = %u " + command_print(CMD, "TCK = %u TDI = %u TDO = %u TMS = %u SRST = %u " "TRST = %u", status.tck, status.tdi, status.tdo, status.tms, status.tres, status.trst); if (status.target_voltage < 1500) - command_print(CMD_CTX, "Target voltage too low. Check target power."); + command_print(CMD, "Target voltage too low. Check target power."); return ERROR_OK; } @@ -1003,7 +1037,7 @@ COMMAND_HANDLER(jlink_handle_free_memory_command) uint32_t tmp; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_GET_FREE_MEMORY)) { - command_print(CMD_CTX, "Retrieval of free memory is not supported by " + command_print(CMD, "Retrieval of free memory is not supported by " "the device."); return ERROR_OK; } @@ -1011,12 +1045,12 @@ COMMAND_HANDLER(jlink_handle_free_memory_command) ret = jaylink_get_free_memory(devh, &tmp); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_get_free_memory() failed: %s.", + command_print(CMD, "jaylink_get_free_memory() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } - command_print(CMD_CTX, "Device has %u bytes of free memory.", tmp); + command_print(CMD, "Device has %u bytes of free memory.", tmp); return ERROR_OK; } @@ -1038,10 +1072,10 @@ COMMAND_HANDLER(jlink_handle_jlink_jtag_command) return ERROR_FAIL; } - command_print(CMD_CTX, "JTAG command version: %i", version); + command_print(CMD, "JTAG command version: %i", version); } else if (CMD_ARGC == 1) { if (sscanf(CMD_ARGV[0], "%i", &tmp) != 1) { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1053,11 +1087,11 @@ COMMAND_HANDLER(jlink_handle_jlink_jtag_command) jtag_command_version = JAYLINK_JTAG_VERSION_3; break; default: - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } } else { - command_print(CMD_CTX, "Need exactly one argument for jlink jtag."); + command_print(CMD, "Need exactly one argument for jlink jtag."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1070,13 +1104,13 @@ COMMAND_HANDLER(jlink_handle_target_power_command) int enable; if (CMD_ARGC != 1) { - command_print(CMD_CTX, "Need exactly one argument for jlink " + command_print(CMD, "Need exactly one argument for jlink " "targetpower."); return ERROR_COMMAND_SYNTAX_ERROR; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) { - command_print(CMD_CTX, "Target power supply is not supported by the " + command_print(CMD, "Target power supply is not supported by the " "device."); return ERROR_OK; } @@ -1086,14 +1120,14 @@ COMMAND_HANDLER(jlink_handle_target_power_command) } else if (!strcmp(CMD_ARGV[0], "off")) { enable = false; } else { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_FAIL; } ret = jaylink_set_target_power(devh, enable); if (ret != JAYLINK_OK) { - command_print(CMD_CTX, "jaylink_set_target_power() failed: %s.", + command_print(CMD, "jaylink_set_target_power() failed: %s.", jaylink_strerror(ret)); return ERROR_FAIL; } @@ -1101,49 +1135,49 @@ COMMAND_HANDLER(jlink_handle_target_power_command) return ERROR_OK; } -static void show_config_usb_address(struct command_context *ctx) +static void show_config_usb_address(struct command_invocation *cmd) { if (config.usb_address != tmp_config.usb_address) - command_print(ctx, "USB address: %u [%u]", config.usb_address, + command_print(cmd, "USB address: %u [%u]", config.usb_address, tmp_config.usb_address); else - command_print(ctx, "USB address: %u", config.usb_address); + command_print(cmd, "USB address: %u", config.usb_address); } -static void show_config_ip_address(struct command_context *ctx) +static void show_config_ip_address(struct command_invocation *cmd) { if (!memcmp(config.ip_address, tmp_config.ip_address, 4)) - command_print(ctx, "IP address: %d.%d.%d.%d", + command_print(cmd, "IP address: %d.%d.%d.%d", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0]); else - command_print(ctx, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd, "IP address: %d.%d.%d.%d [%d.%d.%d.%d]", config.ip_address[3], config.ip_address[2], config.ip_address[1], config.ip_address[0], tmp_config.ip_address[3], tmp_config.ip_address[2], tmp_config.ip_address[1], tmp_config.ip_address[0]); if (!memcmp(config.subnet_mask, tmp_config.subnet_mask, 4)) - command_print(ctx, "Subnet mask: %d.%d.%d.%d", + command_print(cmd, "Subnet mask: %d.%d.%d.%d", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0]); else - command_print(ctx, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", + command_print(cmd, "Subnet mask: %d.%d.%d.%d [%d.%d.%d.%d]", config.subnet_mask[3], config.subnet_mask[2], config.subnet_mask[1], config.subnet_mask[0], tmp_config.subnet_mask[3], tmp_config.subnet_mask[2], tmp_config.subnet_mask[1], tmp_config.subnet_mask[0]); } -static void show_config_mac_address(struct command_context *ctx) +static void show_config_mac_address(struct command_invocation *cmd) { if (!memcmp(config.mac_address, tmp_config.mac_address, 6)) - command_print(ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", + command_print(cmd, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], config.mac_address[1], config.mac_address[0]); else - command_print(ctx, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " + command_print(cmd, "MAC address: %.02x:%.02x:%.02x:%.02x:%.02x:%.02x " "[%.02x:%.02x:%.02x:%.02x:%.02x:%.02x]", config.mac_address[5], config.mac_address[4], config.mac_address[3], config.mac_address[2], @@ -1153,7 +1187,7 @@ static void show_config_mac_address(struct command_context *ctx) tmp_config.mac_address[1], tmp_config.mac_address[0]); } -static void show_config_target_power(struct command_context *ctx) +static void show_config_target_power(struct command_invocation *cmd) { const char *target_power; const char *current_target_power; @@ -1169,24 +1203,24 @@ static void show_config_target_power(struct command_context *ctx) current_target_power = "on"; if (config.target_power != tmp_config.target_power) - command_print(ctx, "Target power supply: %s [%s]", target_power, + command_print(cmd, "Target power supply: %s [%s]", target_power, current_target_power); else - command_print(ctx, "Target power supply: %s", target_power); + command_print(cmd, "Target power supply: %s", target_power); } -static void show_config(struct command_context *ctx) +static void show_config(struct command_invocation *cmd) { - command_print(ctx, "J-Link device configuration:"); + command_print(cmd, "J-Link device configuration:"); - show_config_usb_address(ctx); + show_config_usb_address(cmd); if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) - show_config_target_power(ctx); + show_config_target_power(cmd); if (jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - show_config_ip_address(ctx); - show_config_mac_address(ctx); + show_config_ip_address(cmd); + show_config_mac_address(cmd); } } @@ -1346,27 +1380,27 @@ COMMAND_HANDLER(jlink_handle_config_usb_address_command) uint8_t tmp; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!CMD_ARGC) { - show_config_usb_address(CMD_CTX); + show_config_usb_address(CMD); } else if (CMD_ARGC == 1) { if (sscanf(CMD_ARGV[0], "%" SCNd8, &tmp) != 1) { - command_print(CMD_CTX, "Invalid USB address: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid USB address: %s.", CMD_ARGV[0]); return ERROR_FAIL; } if (tmp > JAYLINK_USB_ADDRESS_3) { - command_print(CMD_CTX, "Invalid USB address: %u.", tmp); + command_print(CMD, "Invalid USB address: %u.", tmp); return ERROR_FAIL; } tmp_config.usb_address = tmp; } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " "usb."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1379,32 +1413,32 @@ COMMAND_HANDLER(jlink_handle_config_target_power_command) int enable; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_SET_TARGET_POWER)) { - command_print(CMD_CTX, "Target power supply is not supported by the " + command_print(CMD, "Target power supply is not supported by the " "device."); return ERROR_OK; } if (!CMD_ARGC) { - show_config_target_power(CMD_CTX); + show_config_target_power(CMD); } else if (CMD_ARGC == 1) { if (!strcmp(CMD_ARGV[0], "on")) { enable = true; } else if (!strcmp(CMD_ARGV[0], "off")) { enable = false; } else { - command_print(CMD_CTX, "Invalid argument: %s.", CMD_ARGV[0]); + command_print(CMD, "Invalid argument: %s.", CMD_ARGV[0]); return ERROR_FAIL; } tmp_config.target_power = enable; } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " "targetpower."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1420,25 +1454,25 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) const char *str; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - command_print(CMD_CTX, "Ethernet connectivity is not supported by the " + command_print(CMD, "Ethernet connectivity is not supported by the " "device."); return ERROR_OK; } if (!CMD_ARGC) { - show_config_mac_address(CMD_CTX); + show_config_mac_address(CMD); } else if (CMD_ARGC == 1) { str = CMD_ARGV[0]; if ((strlen(str) != 17) || (str[2] != ':' || str[5] != ':' || \ str[8] != ':' || str[11] != ':' || str[14] != ':')) { - command_print(CMD_CTX, "Invalid MAC address format."); + command_print(CMD, "Invalid MAC address format."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1448,18 +1482,18 @@ COMMAND_HANDLER(jlink_handle_config_mac_address_command) } if (!(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5])) { - command_print(CMD_CTX, "Invalid MAC address: zero address."); + command_print(CMD, "Invalid MAC address: zero address."); return ERROR_COMMAND_SYNTAX_ERROR; } if (!(0x01 & addr[0])) { - command_print(CMD_CTX, "Invalid MAC address: multicast address."); + command_print(CMD, "Invalid MAC address: multicast address."); return ERROR_COMMAND_SYNTAX_ERROR; } memcpy(tmp_config.mac_address, addr, sizeof(addr)); } else { - command_print(CMD_CTX, "Need exactly one argument for jlink config " + command_print(CMD, "Need exactly one argument for jlink config " " mac."); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1508,19 +1542,19 @@ COMMAND_HANDLER(jlink_handle_config_ip_address_command) uint8_t subnet_bits = 24; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_ETHERNET)) { - command_print(CMD_CTX, "Ethernet connectivity is not supported by the " + command_print(CMD, "Ethernet connectivity is not supported by the " "device."); return ERROR_OK; } if (!CMD_ARGC) { - show_config_ip_address(CMD_CTX); + show_config_ip_address(CMD); } else { if (!string_to_ip(CMD_ARGV[0], ip_address, &i)) return ERROR_COMMAND_SYNTAX_ERROR; @@ -1565,19 +1599,19 @@ COMMAND_HANDLER(jlink_handle_config_write_command) int ret; if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Reading configuration is not supported by the " + command_print(CMD, "Reading configuration is not supported by the " "device."); return ERROR_OK; } if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_WRITE_CONFIG)) { - command_print(CMD_CTX, "Writing configuration is not supported by the " + command_print(CMD, "Writing configuration is not supported by the " "device."); return ERROR_OK; } if (!memcmp(&config, &tmp_config, sizeof(struct device_config))) { - command_print(CMD_CTX, "Operation not performed due to no changes in " + command_print(CMD, "Operation not performed due to no changes in " "the configuration."); return ERROR_OK; } @@ -1602,7 +1636,7 @@ COMMAND_HANDLER(jlink_handle_config_write_command) } memcpy(&tmp_config, &config, sizeof(struct device_config)); - command_print(CMD_CTX, "The new device configuration applies after power " + command_print(CMD, "The new device configuration applies after power " "cycling the J-Link device."); return ERROR_OK; @@ -1611,12 +1645,12 @@ COMMAND_HANDLER(jlink_handle_config_write_command) COMMAND_HANDLER(jlink_handle_config_command) { if (!jaylink_has_cap(caps, JAYLINK_DEV_CAP_READ_CONFIG)) { - command_print(CMD_CTX, "Device doesn't support reading configuration."); + command_print(CMD, "Device doesn't support reading configuration."); return ERROR_OK; } if (CMD_ARGC == 0) - show_config(CMD_CTX); + show_config(CMD); return ERROR_OK; } @@ -1732,7 +1766,7 @@ COMMAND_HANDLER(jlink_handle_emucom_read_command) return ERROR_FAIL; } - command_print(CMD_CTX, "%s", buf + length); + command_print(CMD, "%s", buf + length); free(buf); return ERROR_OK; @@ -1772,13 +1806,15 @@ static const struct command_registration jlink_config_subcommand_handlers[] = { .name = "reset", .handler = &jlink_handle_config_reset_command, .mode = COMMAND_EXEC, - .help = "undo configuration changes" + .help = "undo configuration changes", + .usage = "", }, { .name = "write", .handler = &jlink_handle_config_write_command, .mode = COMMAND_EXEC, - .help = "write configuration to the device" + .help = "write configuration to the device", + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1820,13 +1856,15 @@ static const struct command_registration jlink_subcommand_handlers[] = { .name = "freemem", .handler = &jlink_handle_free_memory_command, .mode = COMMAND_EXEC, - .help = "show free device memory" + .help = "show free device memory", + .usage = "", }, { .name = "hwstatus", .handler = &jlink_handle_hwstatus_command, .mode = COMMAND_EXEC, - .help = "show the hardware status" + .help = "show the hardware status", + .usage = "", }, { .name = "usb", @@ -1849,12 +1887,14 @@ static const struct command_registration jlink_subcommand_handlers[] = { .help = "access the device configuration. If no argument is given " "this will show the device configuration", .chain = jlink_config_subcommand_handlers, + .usage = "[<cmd>]", }, { .name = "emucom", .mode = COMMAND_EXEC, .help = "access EMUCOM channel", - .chain = jlink_emucom_subcommand_handlers + .chain = jlink_emucom_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1865,6 +1905,7 @@ static const struct command_registration jlink_command_handlers[] = { .mode = COMMAND_ANY, .help = "perform jlink management", .chain = jlink_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -1888,14 +1929,6 @@ static void jlink_swd_read_reg(uint8_t cmd, uint32_t *value, uint32_t ap_delay_c jlink_swd_queue_cmd(cmd, value, 0, ap_delay_clk); } -static int_least32_t jlink_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - jlink_speed(hz / 1000); - - return hz; -} - /***************************************************************************/ /* J-Link tap functions */ @@ -1997,7 +2030,7 @@ static int jlink_flush(void) buf_set_buf(tdo_buffer, p->first, p->buffer, p->buffer_offset, p->length); - DEBUG_JTAG_IO("Pending scan result, length = %d.", p->length); + LOG_DEBUG_IO("Pending scan result, length = %d.", p->length); } jlink_tap_init(); @@ -2171,7 +2204,6 @@ static void jlink_swd_queue_cmd(uint8_t cmd, uint32_t *dst, uint32_t data, uint3 static const struct swd_driver jlink_swd = { .init = &jlink_swd_init, - .frequency = &jlink_swd_frequency, .switch_seq = &jlink_swd_switch_seq, .read_reg = &jlink_swd_read_reg, .write_reg = &jlink_swd_write_reg, diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index 637e6c7..6337272 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -15,18 +15,18 @@ static char *jtag_usb_location; * ------ * 16 chars */ -#define JTAG_USB_MAX_LOCATION_LENGHT 16 +#define JTAG_USB_MAX_LOCATION_LENGTH 16 void jtag_usb_set_location(const char *location) { - if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGHT) == - JTAG_USB_MAX_LOCATION_LENGHT) + if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGTH) == + JTAG_USB_MAX_LOCATION_LENGTH) LOG_WARNING("usb location string is too long!!\n"); if (jtag_usb_location) free(jtag_usb_location); - jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGHT); + jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH); } const char *jtag_usb_get_location(void) @@ -37,13 +37,13 @@ const char *jtag_usb_get_location(void) bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, size_t path_len) { - size_t path_step, string_lengh; + size_t path_step, string_length; char *ptr, *loc; bool equal = false; /* strtok need non const char */ - loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGHT); - string_lengh = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT); + loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGTH); + string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH); ptr = strtok(loc, "-"); if (ptr == NULL) { @@ -51,7 +51,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, goto done; } - string_lengh -= 1; + string_length -= 1; /* check bus mismatch */ if (atoi(ptr) != dev_bus) goto done; @@ -69,15 +69,12 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, break; path_step++; - string_lengh -= 2; + string_length -= 2; }; /* walked the full path, all elements match */ - if (path_step == path_len && !string_lengh) + if (path_step == path_len && !string_length) equal = true; - else - LOG_WARNING("excluded by device path option: %s\n", - jtag_usb_get_location()); done: free(loc); diff --git a/src/jtag/drivers/jtag_vpi.c b/src/jtag/drivers/jtag_vpi.c index 35c7031..1033ced 100644 --- a/src/jtag/drivers/jtag_vpi.c +++ b/src/jtag/drivers/jtag_vpi.c @@ -319,7 +319,7 @@ static int jtag_vpi_runtest(int cycles, tap_state_t state) if (retval != ERROR_OK) return retval; - retval = jtag_vpi_queue_tdi(NULL, cycles, TAP_SHIFT); + retval = jtag_vpi_queue_tdi(NULL, cycles, NO_TAP_SHIFT); if (retval != ERROR_OK) return retval; @@ -328,7 +328,27 @@ static int jtag_vpi_runtest(int cycles, tap_state_t state) static int jtag_vpi_stableclocks(int cycles) { - return jtag_vpi_queue_tdi(NULL, cycles, TAP_SHIFT); + uint8_t tms_bits[4]; + int cycles_remain = cycles; + int nb_bits; + int retval; + const int CYCLES_ONE_BATCH = sizeof(tms_bits) * 8; + + assert(cycles >= 0); + + /* use TMS=1 in TAP RESET state, TMS=0 in all other stable states */ + memset(&tms_bits, (tap_get_state() == TAP_RESET) ? 0xff : 0x00, sizeof(tms_bits)); + + /* send the TMS bits */ + while (cycles_remain > 0) { + nb_bits = (cycles_remain < CYCLES_ONE_BATCH) ? cycles_remain : CYCLES_ONE_BATCH; + retval = jtag_vpi_tms_seq(tms_bits, nb_bits); + if (retval != ERROR_OK) + return retval; + cycles_remain -= nb_bits; + } + + return ERROR_OK; } static int jtag_vpi_execute_queue(void) diff --git a/src/jtag/drivers/mpsse.c b/src/jtag/drivers/mpsse.c index 43e924e..c0d883b 100644 --- a/src/jtag/drivers/mpsse.c +++ b/src/jtag/drivers/mpsse.c @@ -30,26 +30,22 @@ #define LIBUSB_CALL #endif -#ifdef _DEBUG_JTAG_IO_ -#define DEBUG_IO(expr...) LOG_DEBUG(expr) #define DEBUG_PRINT_BUF(buf, len) \ do { \ - char buf_string[32 * 3 + 1]; \ - int buf_string_pos = 0; \ - for (int i = 0; i < len; i++) { \ - buf_string_pos += sprintf(buf_string + buf_string_pos, " %02x", buf[i]); \ - if (i % 32 == 32 - 1) { \ - LOG_DEBUG("%s", buf_string); \ - buf_string_pos = 0; \ + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) { \ + char buf_string[32 * 3 + 1]; \ + int buf_string_pos = 0; \ + for (int i = 0; i < len; i++) { \ + buf_string_pos += sprintf(buf_string + buf_string_pos, " %02x", buf[i]); \ + if (i % 32 == 32 - 1) { \ + LOG_DEBUG_IO("%s", buf_string); \ + buf_string_pos = 0; \ + } \ } \ + if (buf_string_pos > 0) \ + LOG_DEBUG_IO("%s", buf_string);\ } \ - if (buf_string_pos > 0) \ - LOG_DEBUG("%s", buf_string);\ } while (0) -#else -#define DEBUG_IO(expr...) do {} while (0) -#define DEBUG_PRINT_BUF(buf, len) do {} while (0) -#endif #define FTDI_DEVICE_OUT_REQTYPE (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE) #define FTDI_DEVICE_IN_REQTYPE (0x80 | LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_RECIPIENT_DEVICE) @@ -459,7 +455,7 @@ static unsigned buffer_read_space(struct mpsse_ctx *ctx) static void buffer_write_byte(struct mpsse_ctx *ctx, uint8_t data) { - DEBUG_IO("%02x", data); + LOG_DEBUG_IO("%02x", data); assert(ctx->write_count < ctx->write_size); ctx->write_buffer[ctx->write_count++] = data; } @@ -467,7 +463,7 @@ static void buffer_write_byte(struct mpsse_ctx *ctx, uint8_t data) static unsigned buffer_write(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, unsigned bit_count) { - DEBUG_IO("%d bits", bit_count); + LOG_DEBUG_IO("%d bits", bit_count); assert(ctx->write_count + DIV_ROUND_UP(bit_count, 8) <= ctx->write_size); bit_copy(ctx->write_buffer + ctx->write_count, 0, out, out_offset, bit_count); ctx->write_count += DIV_ROUND_UP(bit_count, 8); @@ -477,7 +473,7 @@ static unsigned buffer_write(struct mpsse_ctx *ctx, const uint8_t *out, unsigned static unsigned buffer_add_read(struct mpsse_ctx *ctx, uint8_t *in, unsigned in_offset, unsigned bit_count, unsigned offset) { - DEBUG_IO("%d bits, offset %d", bit_count, offset); + LOG_DEBUG_IO("%d bits, offset %d", bit_count, offset); assert(ctx->read_count + DIV_ROUND_UP(bit_count, 8) <= ctx->read_size); bit_copy_queued(&ctx->read_queue, in, in_offset, ctx->read_buffer + ctx->read_count, offset, bit_count); @@ -501,10 +497,10 @@ void mpsse_clock_data(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_of unsigned in_offset, unsigned length, uint8_t mode) { /* TODO: Fix MSB first modes */ - DEBUG_IO("%s%s %d bits", in ? "in" : "", out ? "out" : "", length); + LOG_DEBUG_IO("%s%s %d bits", in ? "in" : "", out ? "out" : "", length); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -577,11 +573,11 @@ void mpsse_clock_tms_cs_out(struct mpsse_ctx *ctx, const uint8_t *out, unsigned void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_offset, uint8_t *in, unsigned in_offset, unsigned length, bool tdi, uint8_t mode) { - DEBUG_IO("%sout %d bits, tdi=%d", in ? "in" : "", length, tdi); + LOG_DEBUG_IO("%sout %d bits, tdi=%d", in ? "in" : "", length, tdi); assert(out); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -627,10 +623,10 @@ void mpsse_clock_tms_cs(struct mpsse_ctx *ctx, const uint8_t *out, unsigned out_ void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -644,10 +640,10 @@ void mpsse_set_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t d void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t dir) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -661,10 +657,10 @@ void mpsse_set_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t data, uint8_t void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -677,10 +673,10 @@ void mpsse_read_data_bits_low_byte(struct mpsse_ctx *ctx, uint8_t *data) void mpsse_read_data_bits_high_byte(struct mpsse_ctx *ctx, uint8_t *data) { - DEBUG_IO("-"); + LOG_DEBUG_IO("-"); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -695,7 +691,7 @@ static void single_byte_boolean_helper(struct mpsse_ctx *ctx, bool var, uint8_t uint8_t val_if_false) { if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -716,7 +712,7 @@ void mpsse_set_divisor(struct mpsse_ctx *ctx, uint16_t divisor) LOG_DEBUG("%d", divisor); if (ctx->retval != ERROR_OK) { - DEBUG_IO("Ignoring command due to previous error"); + LOG_DEBUG_IO("Ignoring command due to previous error"); return; } @@ -818,7 +814,7 @@ static LIBUSB_CALL void read_cb(struct libusb_transfer *transfer) } } - DEBUG_IO("raw chunk %d, transferred %d of %d", transfer->actual_length, res->transferred, + LOG_DEBUG_IO("raw chunk %d, transferred %d of %d", transfer->actual_length, res->transferred, ctx->read_count); if (!res->done) @@ -833,7 +829,7 @@ static LIBUSB_CALL void write_cb(struct libusb_transfer *transfer) res->transferred += transfer->actual_length; - DEBUG_IO("transferred %d of %d", res->transferred, ctx->write_count); + LOG_DEBUG_IO("transferred %d of %d", res->transferred, ctx->write_count); DEBUG_PRINT_BUF(transfer->buffer, transfer->actual_length); @@ -852,13 +848,13 @@ int mpsse_flush(struct mpsse_ctx *ctx) int retval = ctx->retval; if (retval != ERROR_OK) { - DEBUG_IO("Ignoring flush due to previous error"); + LOG_DEBUG_IO("Ignoring flush due to previous error"); assert(ctx->write_count == 0 && ctx->read_count == 0); ctx->retval = ERROR_OK; return retval; } - DEBUG_IO("write %d%s, read %d", ctx->write_count, ctx->read_count ? "+1" : "", + LOG_DEBUG_IO("write %d%s, read %d", ctx->write_count, ctx->read_count ? "+1" : "", ctx->read_count); assert(ctx->write_count > 0 || ctx->read_count == 0); /* No read data without write data */ diff --git a/src/jtag/drivers/opendous.c b/src/jtag/drivers/opendous.c index 458df34..5f352af 100644 --- a/src/jtag/drivers/opendous.c +++ b/src/jtag/drivers/opendous.c @@ -185,7 +185,7 @@ COMMAND_HANDLER(opendous_handle_opendous_hw_jtag_command) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "opendous hw jtag %i", opendous_hw_jtag_version); + command_print(CMD, "opendous hw jtag %i", opendous_hw_jtag_version); break; case 1: { @@ -215,6 +215,7 @@ static const struct command_registration opendous_command_handlers[] = { .handler = &opendous_handle_opendous_info_command, .mode = COMMAND_EXEC, .help = "show opendous info", + .usage = "", }, { .name = "opendous_hw_jtag", @@ -235,6 +236,7 @@ static const struct command_registration opendous_command_handlers[] = { struct jtag_interface opendous_interface = { .name = "opendous", + .transports = jtag_only, .commands = opendous_command_handlers, .execute_queue = opendous_execute_queue, .init = opendous_init, @@ -251,7 +253,7 @@ static int opendous_execute_queue(void) while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ cmd->cmd.runtest->end_state); if (cmd->cmd.runtest->end_state != -1) @@ -260,7 +262,7 @@ static int opendous_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); if (cmd->cmd.statemove->end_state != -1) opendous_end_state(cmd->cmd.statemove->end_state); @@ -268,7 +270,7 @@ static int opendous_execute_queue(void) break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %i", \ + LOG_DEBUG_IO("pathmove: %i states, end in %i", \ cmd->cmd.pathmove->num_states, \ cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); @@ -276,13 +278,13 @@ static int opendous_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state); + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); if (cmd->cmd.scan->end_state != -1) opendous_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - DEBUG_JTAG_IO("scan input, length = %d", scan_size); + LOG_DEBUG_IO("scan input, length = %d", scan_size); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(buffer, (scan_size + 7) / 8); @@ -292,7 +294,7 @@ static int opendous_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); opendous_tap_execute(); @@ -302,7 +304,7 @@ static int opendous_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %" PRIi32, cmd->cmd.sleep->us); opendous_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; @@ -527,7 +529,7 @@ void opendous_simple_command(uint8_t command, uint8_t _data) { int result; - DEBUG_JTAG_IO("0x%02x 0x%02x", command, _data); + LOG_DEBUG_IO("0x%02x 0x%02x", command, _data); usb_out_buffer[0] = 2; usb_out_buffer[1] = 0; @@ -596,7 +598,7 @@ void opendous_tap_append_step(int tms, int tdi) void opendous_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command) { - DEBUG_JTAG_IO("append scan, length = %d", length); + LOG_DEBUG_IO("append scan, length = %d", length); struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length]; int i; @@ -678,7 +680,7 @@ int opendous_tap_execute(void) /* Copy to buffer */ buf_set_buf(tdo_buffer, first, buffer, 0, length); - DEBUG_JTAG_IO("pending scan result, length = %d", length); + LOG_DEBUG_IO("pending scan result, length = %d", length); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(buffer, byte_length_out); @@ -769,7 +771,7 @@ int opendous_usb_write(struct opendous_jtag *opendous_jtag, int out_length) LOG_DEBUG("USB write end: %d bytes", result); #endif - DEBUG_JTAG_IO("opendous_usb_write, out_length = %d, result = %d", out_length, result); + LOG_DEBUG_IO("opendous_usb_write, out_length = %d, result = %d", out_length, result); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(usb_out_buffer, out_length); @@ -795,7 +797,7 @@ int opendous_usb_read(struct opendous_jtag *opendous_jtag) #ifdef _DEBUG_USB_COMMS_ LOG_DEBUG("USB read end: %d bytes", result); #endif - DEBUG_JTAG_IO("opendous_usb_read, result = %d", result); + LOG_DEBUG_IO("opendous_usb_read, result = %d", result); #ifdef _DEBUG_USB_COMMS_ opendous_debug_buffer(usb_in_buffer, result); diff --git a/src/jtag/drivers/openjtag.c b/src/jtag/drivers/openjtag.c index 8f11b4b..7a3aa23 100644 --- a/src/jtag/drivers/openjtag.c +++ b/src/jtag/drivers/openjtag.c @@ -292,7 +292,7 @@ static int openjtag_buf_read_standard( qty - *bytes_read); if (retval < 0) { *bytes_read = 0; - DEBUG_JTAG_IO("ftdi_read_data: %s", + LOG_DEBUG_IO("ftdi_read_data: %s", ftdi_get_error_string(&ftdic)); return ERROR_JTAG_DEVICE_ERROR; } @@ -574,7 +574,7 @@ static int openjtag_execute_tap_queue(void) while (len > 0) { if (len <= 8 && openjtag_variant != OPENJTAG_VARIANT_CY7C65215) { - DEBUG_JTAG_IO("bits < 8 buf = 0x%X, will be 0x%X", + LOG_DEBUG_IO("bits < 8 buf = 0x%X, will be 0x%X", usb_rx_buf[rx_offs], usb_rx_buf[rx_offs] >> (8 - len)); buffer[count] = usb_rx_buf[rx_offs] >> (8 - len); len = 0; @@ -609,8 +609,8 @@ static void openjtag_add_byte(char buf) { if (usb_tx_buf_offs == OPENJTAG_BUFFER_SIZE) { - DEBUG_JTAG_IO("Forcing execute_tap_queue"); - DEBUG_JTAG_IO("TX Buff offs=%d", usb_tx_buf_offs); + LOG_DEBUG_IO("Forcing execute_tap_queue"); + LOG_DEBUG_IO("TX Buff offs=%d", usb_tx_buf_offs); openjtag_execute_tap_queue(); } @@ -624,8 +624,8 @@ static void openjtag_add_scan(uint8_t *buffer, int length, struct scan_command * /* Ensure space to send long chains */ /* We add two byte for each eight (or less) bits, one for command, one for data */ if (usb_tx_buf_offs + (DIV_ROUND_UP(length, 8) * 2) >= OPENJTAG_BUFFER_SIZE) { - DEBUG_JTAG_IO("Forcing execute_tap_queue from scan"); - DEBUG_JTAG_IO("TX Buff offs=%d len=%d", usb_tx_buf_offs, DIV_ROUND_UP(length, 8) * 2); + LOG_DEBUG_IO("Forcing execute_tap_queue from scan"); + LOG_DEBUG_IO("TX Buff offs=%d len=%d", usb_tx_buf_offs, DIV_ROUND_UP(length, 8) * 2); openjtag_execute_tap_queue(); } @@ -670,7 +670,7 @@ static void openjtag_add_scan(uint8_t *buffer, int length, struct scan_command * static void openjtag_execute_reset(struct jtag_command *cmd) { - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); uint8_t buf = 0x00; @@ -703,7 +703,7 @@ static void openjtag_set_state(uint8_t openocd_state) static void openjtag_execute_statemove(struct jtag_command *cmd) { - DEBUG_JTAG_IO("state move to %i", cmd->cmd.statemove->end_state); + LOG_DEBUG_IO("state move to %i", cmd->cmd.statemove->end_state); tap_set_end_state(cmd->cmd.statemove->end_state); @@ -719,7 +719,7 @@ static void openjtag_execute_scan(struct jtag_command *cmd) int scan_size, old_state; uint8_t *buffer; - DEBUG_JTAG_IO("scan ends in %s", tap_state_name(cmd->cmd.scan->end_state)); + LOG_DEBUG_IO("scan ends in %s", tap_state_name(cmd->cmd.scan->end_state)); /* get scan info */ tap_set_end_state(cmd->cmd.scan->end_state); @@ -778,7 +778,7 @@ static void openjtag_execute_runtest(struct jtag_command *cmd) static void openjtag_execute_command(struct jtag_command *cmd) { - DEBUG_JTAG_IO("openjtag_execute_command %i", cmd->type); + LOG_DEBUG_IO("openjtag_execute_command %i", cmd->type); switch (cmd->type) { case JTAG_RESET: openjtag_execute_reset(cmd); @@ -894,6 +894,7 @@ static const struct command_registration openjtag_command_handlers[] = { struct jtag_interface openjtag_interface = { .name = "openjtag", + .transports = jtag_only, .commands = openjtag_command_handlers, .execute_queue = openjtag_execute_queue, diff --git a/src/jtag/drivers/parport.c b/src/jtag/drivers/parport.c index 14fa9df..8e44dcb 100644 --- a/src/jtag/drivers/parport.c +++ b/src/jtag/drivers/parport.c @@ -413,7 +413,7 @@ COMMAND_HANDLER(parport_handle_parport_port_command) } } - command_print(CMD_CTX, "parport port = 0x%" PRIx16 "", parport_port); + command_print(CMD, "parport port = 0x%" PRIx16 "", parport_port); return ERROR_OK; } @@ -470,7 +470,7 @@ COMMAND_HANDLER(parport_handle_parport_toggling_time_command) } } - command_print(CMD_CTX, "parport toggling time = %" PRIu32 " ns", + command_print(CMD, "parport toggling time = %" PRIu32 " ns", parport_toggling_time_ns); return ERROR_OK; @@ -517,6 +517,7 @@ static const struct command_registration parport_command_handlers[] = { struct jtag_interface parport_interface = { .name = "parport", .supported = DEBUG_CAP_TMS_SEQ, + .transports = jtag_only, .commands = parport_command_handlers, .init = parport_init, diff --git a/src/jtag/drivers/presto.c b/src/jtag/drivers/presto.c index 29bc811..2a94d06 100644 --- a/src/jtag/drivers/presto.c +++ b/src/jtag/drivers/presto.c @@ -563,6 +563,7 @@ static int presto_jtag_quit(void) struct jtag_interface presto_interface = { .name = "presto", + .transports = jtag_only, .commands = presto_command_handlers, .execute_queue = bitq_execute_queue, diff --git a/src/jtag/drivers/remote_bitbang.c b/src/jtag/drivers/remote_bitbang.c index 1f8fc1a..a354894 100644 --- a/src/jtag/drivers/remote_bitbang.c +++ b/src/jtag/drivers/remote_bitbang.c @@ -345,6 +345,7 @@ static const struct command_registration remote_bitbang_command_handlers[] = { struct jtag_interface remote_bitbang_interface = { .name = "remote_bitbang", .execute_queue = &bitbang_execute_queue, + .transports = jtag_only, .commands = remote_bitbang_command_handlers, .init = &remote_bitbang_init, .quit = &remote_bitbang_quit, diff --git a/src/jtag/drivers/rlink.c b/src/jtag/drivers/rlink.c index 3f9e332..317e8b8 100644 --- a/src/jtag/drivers/rlink.c +++ b/src/jtag/drivers/rlink.c @@ -1299,11 +1299,9 @@ static int rlink_execute_queue(void) switch (cmd->type) { case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); -#endif if ((cmd->cmd.reset->trst == 1) || (cmd->cmd.reset->srst && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST))) @@ -1311,37 +1309,29 @@ static int rlink_execute_queue(void) rlink_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); break; case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", + LOG_DEBUG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, cmd->cmd.runtest->end_state); -#endif if (cmd->cmd.runtest->end_state != -1) rlink_end_state(cmd->cmd.runtest->end_state); rlink_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); if (cmd->cmd.statemove->end_state != -1) rlink_end_state(cmd->cmd.statemove->end_state); rlink_state_move(); break; case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", - cmd->cmd.pathmove->num_states, - cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif + LOG_DEBUG_IO("pathmove: %i states, end in %i", + cmd->cmd.pathmove->num_states, + cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); rlink_path_move(cmd->cmd.pathmove); break; case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("%s scan end in %i", - (cmd->cmd.scan->ir_scan) ? "IR" : "DR", - cmd->cmd.scan->end_state); -#endif + LOG_DEBUG_IO("%s scan end in %i", + (cmd->cmd.scan->ir_scan) ? "IR" : "DR", + cmd->cmd.scan->end_state); if (cmd->cmd.scan->end_state != -1) rlink_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); @@ -1350,9 +1340,7 @@ static int rlink_execute_queue(void) retval = ERROR_FAIL; break; case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); jtag_sleep(cmd->cmd.sleep->us); break; default: @@ -1674,6 +1662,7 @@ static int rlink_quit(void) struct jtag_interface rlink_interface = { .name = "rlink", + .transports = jtag_only, .init = rlink_init, .quit = rlink_quit, .speed = rlink_speed, diff --git a/src/jtag/drivers/sysfsgpio.c b/src/jtag/drivers/sysfsgpio.c index 90e93f5..eb4941e 100644 --- a/src/jtag/drivers/sysfsgpio.c +++ b/src/jtag/drivers/sysfsgpio.c @@ -356,7 +356,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "SysfsGPIO nums: tck = %d, tms = %d, tdi = %d, tdo = %d", tck_gpio, tms_gpio, tdi_gpio, tdo_gpio); @@ -368,7 +368,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tck) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tck_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tck = %d", tck_gpio); + command_print(CMD, "SysfsGPIO num: tck = %d", tck_gpio); return ERROR_OK; } @@ -377,7 +377,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tms) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tms_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tms = %d", tms_gpio); + command_print(CMD, "SysfsGPIO num: tms = %d", tms_gpio); return ERROR_OK; } @@ -386,7 +386,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tdo) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdo_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tdo = %d", tdo_gpio); + command_print(CMD, "SysfsGPIO num: tdo = %d", tdo_gpio); return ERROR_OK; } @@ -395,7 +395,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_tdi) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], tdi_gpio); - command_print(CMD_CTX, "SysfsGPIO num: tdi = %d", tdi_gpio); + command_print(CMD, "SysfsGPIO num: tdi = %d", tdi_gpio); return ERROR_OK; } @@ -404,7 +404,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_srst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], srst_gpio); - command_print(CMD_CTX, "SysfsGPIO num: srst = %d", srst_gpio); + command_print(CMD, "SysfsGPIO num: srst = %d", srst_gpio); return ERROR_OK; } @@ -413,7 +413,7 @@ COMMAND_HANDLER(sysfsgpio_handle_jtag_gpionum_trst) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], trst_gpio); - command_print(CMD_CTX, "SysfsGPIO num: trst = %d", trst_gpio); + command_print(CMD, "SysfsGPIO num: trst = %d", trst_gpio); return ERROR_OK; } @@ -426,7 +426,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionums) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, + command_print(CMD, "SysfsGPIO nums: swclk = %d, swdio = %d", swclk_gpio, swdio_gpio); @@ -438,7 +438,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionum_swclk) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swclk_gpio); - command_print(CMD_CTX, "SysfsGPIO num: swclk = %d", swclk_gpio); + command_print(CMD, "SysfsGPIO num: swclk = %d", swclk_gpio); return ERROR_OK; } @@ -447,7 +447,7 @@ COMMAND_HANDLER(sysfsgpio_handle_swd_gpionum_swdio) if (CMD_ARGC == 1) COMMAND_PARSE_NUMBER(int, CMD_ARGV[0], swdio_gpio); - command_print(CMD_CTX, "SysfsGPIO num: swdio = %d", swdio_gpio); + command_print(CMD, "SysfsGPIO num: swdio = %d", swdio_gpio); return ERROR_OK; } diff --git a/src/jtag/drivers/ulink.c b/src/jtag/drivers/ulink.c index 550df1c..bbe08aa 100644 --- a/src/jtag/drivers/ulink.c +++ b/src/jtag/drivers/ulink.c @@ -187,12 +187,7 @@ void ulink_clear_queue(struct ulink *device); int ulink_append_queue(struct ulink *device, struct ulink_cmd *ulink_cmd); int ulink_execute_queued_commands(struct ulink *device, int timeout); -#ifdef _DEBUG_JTAG_IO_ -const char *ulink_cmd_id_string(uint8_t id); -void ulink_print_command(struct ulink_cmd *ulink_cmd); -void ulink_print_queue(struct ulink *device); -static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f); -#endif +static void ulink_print_queue(struct ulink *device); int ulink_append_scan_cmd(struct ulink *device, enum scan_type scan_type, @@ -708,9 +703,8 @@ int ulink_execute_queued_commands(struct ulink *device, int timeout) int ret, i, index_out, index_in, count_out, count_in, transferred; uint8_t buffer[64]; -#ifdef _DEBUG_JTAG_IO_ - ulink_print_queue(device); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + ulink_print_queue(device); index_out = 0; count_out = 0; @@ -759,71 +753,69 @@ int ulink_execute_queued_commands(struct ulink *device, int timeout) return ERROR_OK; } -#ifdef _DEBUG_JTAG_IO_ - /** * Convert an OpenULINK command ID (\a id) to a human-readable string. * * @param id the OpenULINK command ID. * @return the corresponding human-readable string. */ -const char *ulink_cmd_id_string(uint8_t id) +static const char *ulink_cmd_id_string(uint8_t id) { switch (id) { - case CMD_SCAN_IN: - return "CMD_SCAN_IN"; - break; - case CMD_SLOW_SCAN_IN: - return "CMD_SLOW_SCAN_IN"; - break; - case CMD_SCAN_OUT: - return "CMD_SCAN_OUT"; - break; - case CMD_SLOW_SCAN_OUT: - return "CMD_SLOW_SCAN_OUT"; - break; - case CMD_SCAN_IO: - return "CMD_SCAN_IO"; - break; - case CMD_SLOW_SCAN_IO: - return "CMD_SLOW_SCAN_IO"; - break; - case CMD_CLOCK_TMS: - return "CMD_CLOCK_TMS"; - break; - case CMD_SLOW_CLOCK_TMS: - return "CMD_SLOW_CLOCK_TMS"; - break; - case CMD_CLOCK_TCK: - return "CMD_CLOCK_TCK"; - break; - case CMD_SLOW_CLOCK_TCK: - return "CMD_SLOW_CLOCK_TCK"; - break; - case CMD_SLEEP_US: - return "CMD_SLEEP_US"; - break; - case CMD_SLEEP_MS: - return "CMD_SLEEP_MS"; - break; - case CMD_GET_SIGNALS: - return "CMD_GET_SIGNALS"; - break; - case CMD_SET_SIGNALS: - return "CMD_SET_SIGNALS"; - break; - case CMD_CONFIGURE_TCK_FREQ: - return "CMD_CONFIGURE_TCK_FREQ"; - break; - case CMD_SET_LEDS: - return "CMD_SET_LEDS"; - break; - case CMD_TEST: - return "CMD_TEST"; - break; - default: - return "CMD_UNKNOWN"; - break; + case CMD_SCAN_IN: + return "CMD_SCAN_IN"; + break; + case CMD_SLOW_SCAN_IN: + return "CMD_SLOW_SCAN_IN"; + break; + case CMD_SCAN_OUT: + return "CMD_SCAN_OUT"; + break; + case CMD_SLOW_SCAN_OUT: + return "CMD_SLOW_SCAN_OUT"; + break; + case CMD_SCAN_IO: + return "CMD_SCAN_IO"; + break; + case CMD_SLOW_SCAN_IO: + return "CMD_SLOW_SCAN_IO"; + break; + case CMD_CLOCK_TMS: + return "CMD_CLOCK_TMS"; + break; + case CMD_SLOW_CLOCK_TMS: + return "CMD_SLOW_CLOCK_TMS"; + break; + case CMD_CLOCK_TCK: + return "CMD_CLOCK_TCK"; + break; + case CMD_SLOW_CLOCK_TCK: + return "CMD_SLOW_CLOCK_TCK"; + break; + case CMD_SLEEP_US: + return "CMD_SLEEP_US"; + break; + case CMD_SLEEP_MS: + return "CMD_SLEEP_MS"; + break; + case CMD_GET_SIGNALS: + return "CMD_GET_SIGNALS"; + break; + case CMD_SET_SIGNALS: + return "CMD_SET_SIGNALS"; + break; + case CMD_CONFIGURE_TCK_FREQ: + return "CMD_CONFIGURE_TCK_FREQ"; + break; + case CMD_SET_LEDS: + return "CMD_SET_LEDS"; + break; + case CMD_TEST: + return "CMD_TEST"; + break; + default: + return "CMD_UNKNOWN"; + break; } } @@ -832,7 +824,7 @@ const char *ulink_cmd_id_string(uint8_t id) * * @param ulink_cmd pointer to OpenULINK command. */ -void ulink_print_command(struct ulink_cmd *ulink_cmd) +static void ulink_print_command(struct ulink_cmd *ulink_cmd) { int i; @@ -850,7 +842,7 @@ void ulink_print_command(struct ulink_cmd *ulink_cmd) * * @param device pointer to struct ulink identifying ULINK driver instance. */ -void ulink_print_queue(struct ulink *device) +static void ulink_print_queue(struct ulink *device) { struct ulink_cmd *current; @@ -860,8 +852,6 @@ void ulink_print_queue(struct ulink *device) ulink_print_command(current); } -#endif /* _DEBUG_JTAG_IO_ */ - /** * Perform JTAG scan * @@ -1367,7 +1357,6 @@ int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay) return ERROR_OK; } -#ifdef _DEBUG_JTAG_IO_ /** * Calculate frequency for a given delay value. * @@ -1378,16 +1367,14 @@ int ulink_calculate_delay(enum ulink_delay_type type, long f, int *delay) * * @param type for which command to calculate the delay value. * @param delay delay value for which to calculate the resulting TCK frequency. - * @param f where to store the resulting TCK frequency. - * @return on success: ERROR_OK - * @return on failure: ERROR_FAIL + * @return the resulting TCK frequency */ -static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long *f) +static long ulink_calculate_frequency(enum ulink_delay_type type, int delay) { - float t, f_float, f_rounded; + float t, f_float; if (delay > 255) - return ERROR_FAIL; + return 0; switch (type) { case DELAY_CLOCK_TCK: @@ -1421,17 +1408,12 @@ static int ulink_calculate_frequency(enum ulink_delay_type type, int delay, long t = (float)(4E-6) * (float)(delay) + (float)(1.3132E-5); break; default: - return ERROR_FAIL; - break; + return 0; } f_float = 1.0 / t; - f_rounded = roundf(f_float); - *f = (long)f_rounded; - - return ERROR_OK; + return roundf(f_float); } -#endif /******************* Interface between OpenULINK and OpenOCD ******************/ @@ -2065,31 +2047,21 @@ static int ulink_khz(int khz, int *jtag_speed) return ret; } -#ifdef _DEBUG_JTAG_IO_ - long f_tck = 0, f_tms = 0, f_scan_in = 0, f_scan_out = 0, f_scan_io = 0; - - ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck, - &f_tck); - ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms, - &f_tms); - ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in, - &f_scan_in); - ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out, - &f_scan_out); - ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io, - &f_scan_io); - - DEBUG_JTAG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),", - ulink_handle->delay_clock_tck, f_tck); - DEBUG_JTAG_IO(" delay_tms = %i (%li Hz),", - ulink_handle->delay_clock_tms, f_tms); - DEBUG_JTAG_IO(" delay_scan_in = %i (%li Hz),", - ulink_handle->delay_scan_in, f_scan_in); - DEBUG_JTAG_IO(" delay_scan_out = %i (%li Hz),", - ulink_handle->delay_scan_out, f_scan_out); - DEBUG_JTAG_IO(" delay_scan_io = %i (%li Hz),", - ulink_handle->delay_scan_io, f_scan_io); -#endif + LOG_DEBUG_IO("ULINK TCK setup: delay_tck = %i (%li Hz),", + ulink_handle->delay_clock_tck, + ulink_calculate_frequency(DELAY_CLOCK_TCK, ulink_handle->delay_clock_tck)); + LOG_DEBUG_IO(" delay_tms = %i (%li Hz),", + ulink_handle->delay_clock_tms, + ulink_calculate_frequency(DELAY_CLOCK_TMS, ulink_handle->delay_clock_tms)); + LOG_DEBUG_IO(" delay_scan_in = %i (%li Hz),", + ulink_handle->delay_scan_in, + ulink_calculate_frequency(DELAY_SCAN_IN, ulink_handle->delay_scan_in)); + LOG_DEBUG_IO(" delay_scan_out = %i (%li Hz),", + ulink_handle->delay_scan_out, + ulink_calculate_frequency(DELAY_SCAN_OUT, ulink_handle->delay_scan_out)); + LOG_DEBUG_IO(" delay_scan_io = %i (%li Hz),", + ulink_handle->delay_scan_io, + ulink_calculate_frequency(DELAY_SCAN_IO, ulink_handle->delay_scan_io)); /* Configure the ULINK device with the new delay values */ ret = ulink_append_configure_tck_cmd(ulink_handle, diff --git a/src/jtag/drivers/usb_blaster/usb_blaster.c b/src/jtag/drivers/usb_blaster/usb_blaster.c index 8ccf871..165ebdc 100644 --- a/src/jtag/drivers/usb_blaster/usb_blaster.c +++ b/src/jtag/drivers/usb_blaster/usb_blaster.c @@ -174,7 +174,7 @@ static int ublast_buf_read(uint8_t *buf, unsigned size, uint32_t *bytes_read) int ret = info.drv->read(info.drv, buf, size, bytes_read); char *str = hexdump(buf, *bytes_read); - DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str, + LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str, *bytes_read); free(str); return ret; @@ -185,7 +185,7 @@ static int ublast_buf_write(uint8_t *buf, int size, uint32_t *bytes_written) int ret = info.drv->write(info.drv, buf, size, bytes_written); char *str = hexdump(buf, *bytes_written); - DEBUG_JTAG_IO("(size=%d, buf=[%s]) -> %u", size, str, + LOG_DEBUG_IO("(size=%d, buf=[%s]) -> %u", size, str, *bytes_written); free(str); return ret; @@ -266,7 +266,7 @@ static void ublast_queue_byte(uint8_t abyte) info.buf[info.bufidx++] = abyte; if (nb_buf_remaining() == 0) ublast_flush_buffer(); - DEBUG_JTAG_IO("(byte=0x%02x)", abyte); + LOG_DEBUG_IO("(byte=0x%02x)", abyte); } /** @@ -337,7 +337,7 @@ static void ublast_clock_tms(int tms) { uint8_t out; - DEBUG_JTAG_IO("(tms=%d)", !!tms); + LOG_DEBUG_IO("(tms=%d)", !!tms); info.tms = !!tms; info.tdi = 0; out = ublast_build_out(SCAN_OUT); @@ -354,7 +354,7 @@ static void ublast_idle_clock(void) { uint8_t out = ublast_build_out(SCAN_OUT); - DEBUG_JTAG_IO("."); + LOG_DEBUG_IO("."); ublast_queue_byte(out); } @@ -375,7 +375,7 @@ static void ublast_clock_tdi(int tdi, enum scan_type type) { uint8_t out; - DEBUG_JTAG_IO("(tdi=%d)", !!tdi); + LOG_DEBUG_IO("(tdi=%d)", !!tdi); info.tdi = !!tdi; out = ublast_build_out(SCAN_OUT); @@ -400,7 +400,7 @@ static void ublast_clock_tdi_flip_tms(int tdi, enum scan_type type) { uint8_t out; - DEBUG_JTAG_IO("(tdi=%d)", !!tdi); + LOG_DEBUG_IO("(tdi=%d)", !!tdi); info.tdi = !!tdi; info.tms = !info.tms; @@ -430,7 +430,7 @@ static void ublast_queue_bytes(uint8_t *bytes, int nb_bytes) info.bufidx + nb_bytes); exit(-1); } - DEBUG_JTAG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes, + LOG_DEBUG_IO("(nb_bytes=%d, bytes=[0x%02x, ...])", nb_bytes, bytes ? bytes[0] : 0); if (bytes) memcpy(&info.buf[info.bufidx], bytes, nb_bytes); @@ -457,7 +457,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip) { int i; - DEBUG_JTAG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits); + LOG_DEBUG_IO("(bits=%02x..., nb_bits=%d)", bits[0], nb_bits); for (i = skip; i < nb_bits; i++) ublast_clock_tms((bits[i / 8] >> (i % 8)) & 0x01); ublast_idle_clock(); @@ -469,7 +469,7 @@ static void ublast_tms_seq(const uint8_t *bits, int nb_bits, int skip) */ static void ublast_tms(struct tms_command *cmd) { - DEBUG_JTAG_IO("(num_bits=%d)", cmd->num_bits); + LOG_DEBUG_IO("(num_bits=%d)", cmd->num_bits); ublast_tms_seq(cmd->bits, cmd->num_bits, 0); } @@ -487,7 +487,7 @@ static void ublast_path_move(struct pathmove_command *cmd) { int i; - DEBUG_JTAG_IO("(num_states=%d, last_state=%d)", + LOG_DEBUG_IO("(num_states=%d, last_state=%d)", cmd->num_states, cmd->path[cmd->num_states - 1]); for (i = 0; i < cmd->num_states; i++) { if (tap_state_transition(tap_get_state(), false) == cmd->path[i]) @@ -512,7 +512,7 @@ static void ublast_state_move(tap_state_t state, int skip) uint8_t tms_scan; int tms_len; - DEBUG_JTAG_IO("(from %s to %s)", tap_state_name(tap_get_state()), + LOG_DEBUG_IO("(from %s to %s)", tap_state_name(tap_get_state()), tap_state_name(state)); if (tap_get_state() == state) return; @@ -541,7 +541,7 @@ static int ublast_read_byteshifted_tdos(uint8_t *buf, int nb_bytes) unsigned int retlen; int ret = ERROR_OK; - DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8); + LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bytes * 8); ublast_flush_buffer(); while (ret == ERROR_OK && nb_bytes > 0) { ret = ublast_buf_read(buf, nb_bytes, &retlen); @@ -573,7 +573,7 @@ static int ublast_read_bitbang_tdos(uint8_t *buf, int nb_bits) unsigned int retlen; uint8_t tmp[8]; - DEBUG_JTAG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits); + LOG_DEBUG_IO("%s(buf=%p, num_bits=%d)", __func__, buf, nb_bits); /* * Ensure all previous bitbang writes were issued to the dongle, so that @@ -688,7 +688,7 @@ static void ublast_queue_tdi(uint8_t *bits, int nb_bits, enum scan_type scan) static void ublast_runtest(int cycles, tap_state_t state) { - DEBUG_JTAG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state); + LOG_DEBUG_IO("%s(cycles=%i, end_state=%d)", __func__, cycles, state); ublast_state_move(TAP_IDLE, 0); ublast_queue_tdi(NULL, cycles, SCAN_OUT); @@ -697,7 +697,7 @@ static void ublast_runtest(int cycles, tap_state_t state) static void ublast_stableclocks(int cycles) { - DEBUG_JTAG_IO("%s(cycles=%i)", __func__, cycles); + LOG_DEBUG_IO("%s(cycles=%i)", __func__, cycles); ublast_queue_tdi(NULL, cycles, SCAN_OUT); } @@ -727,7 +727,7 @@ static int ublast_scan(struct scan_command *cmd) ublast_state_move(TAP_DRSHIFT, 0); log_buf = hexdump(buf, DIV_ROUND_UP(scan_bits, 8)); - DEBUG_JTAG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__, + LOG_DEBUG_IO("%s(scan=%s, type=%s, bits=%d, buf=[%s], end_state=%d)", __func__, cmd->ir_scan ? "IRSCAN" : "DRSCAN", type2str[type], scan_bits, log_buf, cmd->end_state); @@ -749,7 +749,7 @@ static int ublast_scan(struct scan_command *cmd) static void ublast_usleep(int us) { - DEBUG_JTAG_IO("%s(us=%d)", __func__, us); + LOG_DEBUG_IO("%s(us=%d)", __func__, us); jtag_sleep(us); } @@ -1068,6 +1068,7 @@ static const struct command_registration ublast_command_handlers[] = { struct jtag_interface usb_blaster_interface = { .name = "usb_blaster", + .transports = jtag_only, .commands = ublast_command_handlers, .supported = DEBUG_CAP_TMS_SEQ, diff --git a/src/jtag/drivers/usbprog.c b/src/jtag/drivers/usbprog.c index d81c329..35a9520 100644 --- a/src/jtag/drivers/usbprog.c +++ b/src/jtag/drivers/usbprog.c @@ -103,62 +103,50 @@ static int usbprog_execute_queue(void) while (cmd) { switch (cmd->type) { - case JTAG_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("reset trst: %i srst %i", - cmd->cmd.reset->trst, - cmd->cmd.reset->srst); -#endif - if (cmd->cmd.reset->trst == 1) - tap_set_state(TAP_RESET); - usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); - break; - case JTAG_RUNTEST: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest %i cycles, end in %i", - cmd->cmd.runtest->num_cycles, - cmd->cmd.runtest->end_state); -#endif - usbprog_end_state(cmd->cmd.runtest->end_state); - usbprog_runtest(cmd->cmd.runtest->num_cycles); - break; - case JTAG_TLR_RESET: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("statemove end in %i", cmd->cmd.statemove->end_state); -#endif - usbprog_end_state(cmd->cmd.statemove->end_state); - usbprog_state_move(); - break; - case JTAG_PATHMOVE: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("pathmove: %i states, end in %i", - cmd->cmd.pathmove->num_states, - cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); -#endif - usbprog_path_move(cmd->cmd.pathmove); - break; - case JTAG_SCAN: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("scan end in %i", cmd->cmd.scan->end_state); -#endif - usbprog_end_state(cmd->cmd.scan->end_state); - scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); - type = jtag_scan_type(cmd->cmd.scan); - usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); - if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) - return ERROR_JTAG_QUEUE_FAILED; - if (buffer) - free(buffer); - break; - case JTAG_SLEEP: -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("sleep %i", cmd->cmd.sleep->us); -#endif - jtag_sleep(cmd->cmd.sleep->us); - break; - default: - LOG_ERROR("BUG: unknown JTAG command type encountered"); - exit(-1); + case JTAG_RESET: + LOG_DEBUG_IO("reset trst: %i srst %i", + cmd->cmd.reset->trst, + cmd->cmd.reset->srst); + if (cmd->cmd.reset->trst == 1) + tap_set_state(TAP_RESET); + usbprog_reset(cmd->cmd.reset->trst, cmd->cmd.reset->srst); + break; + case JTAG_RUNTEST: + LOG_DEBUG_IO("runtest %i cycles, end in %i", + cmd->cmd.runtest->num_cycles, + cmd->cmd.runtest->end_state); + usbprog_end_state(cmd->cmd.runtest->end_state); + usbprog_runtest(cmd->cmd.runtest->num_cycles); + break; + case JTAG_TLR_RESET: + LOG_DEBUG_IO("statemove end in %i", cmd->cmd.statemove->end_state); + usbprog_end_state(cmd->cmd.statemove->end_state); + usbprog_state_move(); + break; + case JTAG_PATHMOVE: + LOG_DEBUG_IO("pathmove: %i states, end in %i", + cmd->cmd.pathmove->num_states, + cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1]); + usbprog_path_move(cmd->cmd.pathmove); + break; + case JTAG_SCAN: + LOG_DEBUG_IO("scan end in %i", cmd->cmd.scan->end_state); + usbprog_end_state(cmd->cmd.scan->end_state); + scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); + type = jtag_scan_type(cmd->cmd.scan); + usbprog_scan(cmd->cmd.scan->ir_scan, type, buffer, scan_size); + if (jtag_read_buffer(buffer, cmd->cmd.scan) != ERROR_OK) + return ERROR_JTAG_QUEUE_FAILED; + if (buffer) + free(buffer); + break; + case JTAG_SLEEP: + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); + jtag_sleep(cmd->cmd.sleep->us); + break; + default: + LOG_ERROR("BUG: unknown JTAG command type encountered"); + exit(-1); } cmd = cmd->next; @@ -270,10 +258,8 @@ static void usbprog_runtest(int num_cycles) usbprog_write(0, 0, 0); } -#ifdef _DEBUG_JTAG_IO_ - LOG_DEBUG("runtest: cur_state %s end_state %s", tap_state_name( + LOG_DEBUG_IO("runtest: cur_state %s end_state %s", tap_state_name( tap_get_state()), tap_state_name(tap_get_end_state())); -#endif /* finish in end_state */ /* @@ -612,6 +598,7 @@ static void usbprog_jtag_tms_send(struct usbprog_jtag *usbprog_jtag) struct jtag_interface usbprog_interface = { .name = "usbprog", + .transports = jtag_only, .execute_queue = usbprog_execute_queue, .init = usbprog_init, diff --git a/src/jtag/drivers/vsllink.c b/src/jtag/drivers/vsllink.c index 6f7e9ca..4907ef0 100644 --- a/src/jtag/drivers/vsllink.c +++ b/src/jtag/drivers/vsllink.c @@ -82,9 +82,7 @@ struct vsllink { static int vsllink_usb_open(struct vsllink *vsllink); static void vsllink_usb_close(struct vsllink *vsllink); -#if defined _DEBUG_JTAG_IO_ static void vsllink_debug_buffer(uint8_t *buffer, int length); -#endif static int tap_length; static int tap_buffer_size; @@ -103,14 +101,14 @@ static int vsllink_execute_queue(void) enum scan_type type; uint8_t *buffer; - DEBUG_JTAG_IO("-------------------------------------" + LOG_DEBUG_IO("-------------------------------------" " vsllink " "-------------------------------------"); while (cmd != NULL) { switch (cmd->type) { case JTAG_RUNTEST: - DEBUG_JTAG_IO("runtest %i cycles, end in %s", + LOG_DEBUG_IO("runtest %i cycles, end in %s", cmd->cmd.runtest->num_cycles, tap_state_name(cmd->cmd.runtest->end_state)); @@ -119,7 +117,7 @@ static int vsllink_execute_queue(void) break; case JTAG_TLR_RESET: - DEBUG_JTAG_IO("statemove end in %s", + LOG_DEBUG_IO("statemove end in %s", tap_state_name(cmd->cmd.statemove->end_state)); vsllink_end_state(cmd->cmd.statemove->end_state); @@ -127,7 +125,7 @@ static int vsllink_execute_queue(void) break; case JTAG_PATHMOVE: - DEBUG_JTAG_IO("pathmove: %i states, end in %s", + LOG_DEBUG_IO("pathmove: %i states, end in %s", cmd->cmd.pathmove->num_states, tap_state_name(cmd->cmd.pathmove->path[cmd->cmd.pathmove->num_states - 1])); @@ -135,7 +133,7 @@ static int vsllink_execute_queue(void) break; case JTAG_SCAN: - DEBUG_JTAG_IO("JTAG Scan..."); + LOG_DEBUG_IO("JTAG Scan..."); vsllink_end_state(cmd->cmd.scan->end_state); @@ -143,23 +141,21 @@ static int vsllink_execute_queue(void) cmd->cmd.scan, &buffer); if (cmd->cmd.scan->ir_scan) - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG Scan write IR(%d bits), " "end in %s:", scan_size, tap_state_name(cmd->cmd.scan->end_state)); else - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG Scan write DR(%d bits), " "end in %s:", scan_size, tap_state_name(cmd->cmd.scan->end_state)); -#ifdef _DEBUG_JTAG_IO_ - vsllink_debug_buffer(buffer, - DIV_ROUND_UP(scan_size, 8)); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + vsllink_debug_buffer(buffer, DIV_ROUND_UP(scan_size, 8)); type = jtag_scan_type(cmd->cmd.scan); @@ -169,7 +165,7 @@ static int vsllink_execute_queue(void) break; case JTAG_RESET: - DEBUG_JTAG_IO("reset trst: %i srst %i", + LOG_DEBUG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); @@ -183,13 +179,13 @@ static int vsllink_execute_queue(void) break; case JTAG_SLEEP: - DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); + LOG_DEBUG_IO("sleep %i", cmd->cmd.sleep->us); vsllink_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); break; case JTAG_STABLECLOCKS: - DEBUG_JTAG_IO("add %d clocks", + LOG_DEBUG_IO("add %d clocks", cmd->cmd.stableclocks->num_cycles); switch (tap_get_state()) { @@ -219,7 +215,7 @@ static int vsllink_execute_queue(void) break; case JTAG_TMS: - DEBUG_JTAG_IO("add %d jtag tms", + LOG_DEBUG_IO("add %d jtag tms", cmd->cmd.tms->num_bits); vsllink_tms(cmd->cmd.tms->num_bits, cmd->cmd.tms->bits); @@ -681,13 +677,11 @@ static int vsllink_jtag_execute(void) command = pending_scan_result->command; buf_set_buf(tdo_buffer, src_first, buffer, dest_first, length); -#ifdef _DEBUG_JTAG_IO_ - DEBUG_JTAG_IO( + LOG_DEBUG_IO( "JTAG scan read(%d bits, from src %d bits to dest %d bits):", length, src_first, dest_first); - vsllink_debug_buffer(buffer + dest_first / 8, - DIV_ROUND_UP(length, 7)); -#endif + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + vsllink_debug_buffer(buffer + dest_first / 8, DIV_ROUND_UP(length, 7)); if (last) { if (jtag_read_buffer(buffer, command) @@ -895,7 +889,6 @@ static void vsllink_usb_close(struct vsllink *vsllink) #define BYTES_PER_LINE 16 -#if defined _DEBUG_JTAG_IO_ static void vsllink_debug_buffer(uint8_t *buffer, int length) { char line[81]; @@ -904,46 +897,57 @@ static void vsllink_debug_buffer(uint8_t *buffer, int length) int j; for (i = 0; i < length; i += BYTES_PER_LINE) { - snprintf(line, 5, "%04x", i); + snprintf(line, 5, "%04x", i & 0xffff); for (j = i; j < i + BYTES_PER_LINE && j < length; j++) { snprintf(s, 4, " %02x", buffer[j]); strcat(line, s); } - LOG_DEBUG("%s", line); + LOG_DEBUG_IO("%s", line); } } -#endif /* _DEBUG_JTAG_IO_ */ static const struct command_registration vsllink_command_handlers[] = { { .name = "vsllink_usb_vid", .handler = &vsllink_handle_usb_vid_command, .mode = COMMAND_CONFIG, + .help = "Set USB VID", + .usage = "<vid>", }, { .name = "vsllink_usb_pid", .handler = &vsllink_handle_usb_pid_command, .mode = COMMAND_CONFIG, + .help = "Set USB PID", + .usage = "<pid>", }, { .name = "vsllink_usb_serial", .handler = &vsllink_handle_usb_serial_command, .mode = COMMAND_CONFIG, + .help = "Set or disable check for USB serial", + .usage = "[<serial>]", }, { .name = "vsllink_usb_bulkin", .handler = &vsllink_handle_usb_bulkin_command, .mode = COMMAND_CONFIG, + .help = "Set USB input endpoint", + .usage = "<ep_in>", }, { .name = "vsllink_usb_bulkout", .handler = &vsllink_handle_usb_bulkout_command, .mode = COMMAND_CONFIG, + .help = "Set USB output endpoint", + .usage = "<ep_out>", }, { .name = "vsllink_usb_interface", .handler = &vsllink_handle_usb_interface_command, .mode = COMMAND_CONFIG, + .help = "Set USB output interface", + .usage = "<interface>", }, COMMAND_REGISTRATION_DONE }; @@ -952,7 +956,6 @@ static const char * const vsllink_transports[] = {"jtag", "swd", NULL}; static const struct swd_driver vsllink_swd_driver = { .init = vsllink_swd_init, - .frequency = vsllink_swd_frequency, .switch_seq = vsllink_swd_switch_seq, .read_reg = vsllink_swd_read_reg, .write_reg = vsllink_swd_write_reg, diff --git a/src/jtag/drivers/xds110.c b/src/jtag/drivers/xds110.c index 20b8178..f25023b 100644 --- a/src/jtag/drivers/xds110.c +++ b/src/jtag/drivers/xds110.c @@ -1925,13 +1925,6 @@ static int xds110_khz(int khz, int *jtag_speed) return ERROR_OK; } -static int_least32_t xds110_swd_frequency(int_least32_t hz) -{ - if (hz > 0) - xds110_speed(hz / 1000); - return hz; -} - COMMAND_HANDLER(xds110_handle_info_command) { xds110_show_info(); @@ -2032,7 +2025,6 @@ static const struct command_registration xds110_command_handlers[] = { static const struct swd_driver xds110_swd_driver = { .init = xds110_swd_init, - .frequency = xds110_swd_frequency, .switch_seq = xds110_swd_switch_seq, .read_reg = xds110_swd_read_reg, .write_reg = xds110_swd_write_reg, diff --git a/src/jtag/interface.c b/src/jtag/interface.c index e12b2ae..de132bb 100644 --- a/src/jtag/interface.c +++ b/src/jtag/interface.c @@ -376,15 +376,13 @@ tap_state_t tap_state_by_name(const char *name) return TAP_INVALID; } -#ifdef _DEBUG_JTAG_IO_ - #define JTAG_DEBUG_STATE_APPEND(buf, len, bit) \ do { buf[len] = bit ? '1' : '0'; } while (0) #define JTAG_DEBUG_STATE_PRINT(a, b, astr, bstr) \ - DEBUG_JTAG_IO("TAP/SM: %9s -> %5s\tTMS: %s\tTDI: %s", \ + LOG_DEBUG_IO("TAP/SM: %9s -> %5s\tTMS: %s\tTDI: %s", \ tap_state_name(a), tap_state_name(b), astr, bstr) -tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, +tap_state_t jtag_debug_state_machine_(const void *tms_buf, const void *tdi_buf, unsigned tap_bits, tap_state_t next_state) { const uint8_t *tms_buffer; @@ -401,13 +399,13 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, /* set startstate (and possibly last, if tap_bits == 0) */ last_state = next_state; - DEBUG_JTAG_IO("TAP/SM: START state: %s", tap_state_name(next_state)); + LOG_DEBUG_IO("TAP/SM: START state: %s", tap_state_name(next_state)); tms_buffer = (const uint8_t *)tms_buf; tdi_buffer = (const uint8_t *)tdi_buf; tap_bytes = DIV_ROUND_UP(tap_bits, 8); - DEBUG_JTAG_IO("TAP/SM: TMS bits: %u (bytes: %u)", tap_bits, tap_bytes); + LOG_DEBUG_IO("TAP/SM: TMS bits: %u (bytes: %u)", tap_bits, tap_bytes); tap_out_bits = 0; for (cur_byte = 0; cur_byte < tap_bytes; cur_byte++) { @@ -452,11 +450,10 @@ tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, JTAG_DEBUG_STATE_PRINT(last_state, next_state, tms_str, tdi_str); } - DEBUG_JTAG_IO("TAP/SM: FINAL state: %s", tap_state_name(next_state)); + LOG_DEBUG_IO("TAP/SM: FINAL state: %s", tap_state_name(next_state)); return next_state; } -#endif /* _DEBUG_JTAG_IO_ */ void tap_use_new_tms_table(bool use_new) { diff --git a/src/jtag/interface.h b/src/jtag/interface.h index e6fa0ca..905f1eb 100644 --- a/src/jtag/interface.h +++ b/src/jtag/interface.h @@ -56,18 +56,11 @@ void tap_set_state_impl(tap_state_t new_state); * @param new_state The state we think the TAPs are currently in (or * are about to enter). */ -#if defined(_DEBUG_JTAG_IO_) #define tap_set_state(new_state) \ do { \ - LOG_DEBUG("tap_set_state(%s)", tap_state_name(new_state)); \ + LOG_DEBUG_IO("tap_set_state(%s)", tap_state_name(new_state)); \ tap_set_state_impl(new_state); \ } while (0) -#else -static inline void tap_set_state(tap_state_t new_state) -{ - tap_set_state_impl(new_state); -} -#endif /** * This function gets the state of the "state follower" which tracks the @@ -164,7 +157,7 @@ void tap_use_new_tms_table(bool use_new); /** @returns True if new TMS table is active; false otherwise. */ bool tap_uses_new_tms_table(void); -#ifdef _DEBUG_JTAG_IO_ + /** * @brief Prints verbose TAP state transitions for the given TMS/TDI buffers. * @param tms_buf must points to a buffer containing the TMS bitstream. @@ -173,15 +166,18 @@ bool tap_uses_new_tms_table(void); * @param start_tap_state must specify the current TAP state. * @returns the final TAP state; pass as @a start_tap_state in following call. */ -tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, - unsigned tap_len, tap_state_t start_tap_state); -#else static inline tap_state_t jtag_debug_state_machine(const void *tms_buf, const void *tdi_buf, unsigned tap_len, tap_state_t start_tap_state) { - return start_tap_state; + /* Private declaration */ + tap_state_t jtag_debug_state_machine_(const void *tms_buf, const void *tdi_buf, + unsigned tap_len, tap_state_t start_tap_state); + + if (LOG_LEVEL_IS(LOG_LVL_DEBUG_IO)) + return jtag_debug_state_machine_(tms_buf, tdi_buf, tap_len, start_tap_state); + else + return start_tap_state; } -#endif /* _DEBUG_JTAG_IO_ */ /** * Represents a driver for a debugging interface. diff --git a/src/jtag/jtag.h b/src/jtag/jtag.h index a6891c0..c93243c 100644 --- a/src/jtag/jtag.h +++ b/src/jtag/jtag.h @@ -25,14 +25,6 @@ #include <helper/binarybuffer.h> #include <helper/log.h> -#ifdef _DEBUG_JTAG_IO_ -#define DEBUG_JTAG_IO(expr ...) \ - do { if (1) LOG_DEBUG(expr); } while (0) -#else -#define DEBUG_JTAG_IO(expr ...) \ - do { if (0) LOG_DEBUG(expr); } while (0) -#endif - #ifndef DEBUG_JTAG_IOZ #define DEBUG_JTAG_IOZ 64 #endif diff --git a/src/jtag/minidummy/minidummy.c b/src/jtag/minidummy/minidummy.c index b7c989f..2f26004 100644 --- a/src/jtag/minidummy/minidummy.c +++ b/src/jtag/minidummy/minidummy.c @@ -28,6 +28,7 @@ struct jtag_interface minidummy_interface = { .name = "minidummy", .execute_queue = NULL, .speed = NULL, + .transports = jtag_only, .commands = NULL, .init = NULL, .quit = NULL, diff --git a/src/jtag/swd.h b/src/jtag/swd.h index 3ff4de0..0b32105 100644 --- a/src/jtag/swd.h +++ b/src/jtag/swd.h @@ -233,24 +233,6 @@ struct swd_driver { int (*init)(void); /** - * Set the SWCLK frequency of the SWD link. - * - * The driver should round the desired value, downwards if possible, to - * the nearest supported frequency. A negative value should be ignored - * and can be used to query the current setting. If the driver does not - * support a variable frequency a fixed, nominal, value should be - * returned. - * - * If the frequency is increased, it must not apply before the currently - * queued transactions are executed. If the frequency is lowered, it may - * apply immediately. - * - * @param hz The desired frequency in Hz. - * @return The actual resulting frequency after rounding. - */ - int_least32_t (*frequency)(int_least32_t hz); - - /** * Queue a special SWDIO sequence. * * @param seq The special sequence to generate. diff --git a/src/jtag/tcl.c b/src/jtag/tcl.c index 7683014..cbdf2ad 100644 --- a/src/jtag/tcl.c +++ b/src/jtag/tcl.c @@ -307,11 +307,13 @@ static const struct command_registration jtag_command_handlers_to_move[] = { enum jtag_tap_cfg_param { - JCFG_EVENT + JCFG_EVENT, + JCFG_IDCODE, }; static Jim_Nvp nvp_config_opts[] = { { .name = "-event", .value = JCFG_EVENT }, + { .name = "-idcode", .value = JCFG_IDCODE }, { .name = NULL, .value = -1 } }; @@ -404,8 +406,23 @@ static int jtag_tap_configure_cmd(Jim_GetOptInfo *goi, struct jtag_tap *tap) if (e != JIM_OK) return e; break; + case JCFG_IDCODE: + if (goi->isconfigure) { + Jim_SetResultFormatted(goi->interp, + "not settable: %s", n->name); + return JIM_ERR; + } else { + if (goi->argc != 0) { + Jim_WrongNumArgs(goi->interp, + goi->argc, goi->argv, + "NO PARAMS"); + return JIM_ERR; + } + } + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, tap->idcode)); + break; default: - Jim_SetResultFormatted(goi->interp, "unknown event: %s", n->name); + Jim_SetResultFormatted(goi->interp, "unknown value: %s", n->name); return JIM_ERR; } } @@ -622,6 +639,7 @@ static int jim_newtap_cmd(Jim_GetOptInfo *goi) static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e) { struct jtag_tap_event_action *jteap; + int retval; for (jteap = tap->event_action; jteap != NULL; jteap = jteap->next) { if (jteap->event != e) @@ -632,7 +650,11 @@ static void jtag_tap_handle_event(struct jtag_tap *tap, enum jtag_event e) tap->dotted_name, e, nvp->name, Jim_GetString(jteap->body, NULL)); - if (Jim_EvalObj(jteap->interp, jteap->body) != JIM_OK) { + retval = Jim_EvalObj(jteap->interp, jteap->body); + if (retval == JIM_RETURN) + retval = jteap->interp->returnCode; + + if (retval != JIM_OK) { Jim_MakeErrorMessage(jteap->interp); LOG_USER("%s", Jim_GetString(Jim_GetResult(jteap->interp), NULL)); continue; @@ -935,9 +957,9 @@ COMMAND_HANDLER(handle_scan_chain_command) char expected_id[12]; tap = jtag_all_taps(); - command_print(CMD_CTX, + command_print(CMD, " TapName Enabled IdCode Expected IrLen IrCap IrMask"); - command_print(CMD_CTX, + command_print(CMD, "-- ------------------- -------- ---------- ---------- ----- ----- ------"); while (tap) { @@ -953,7 +975,7 @@ COMMAND_HANDLER(handle_scan_chain_command) expected = buf_get_u32(tap->expected, 0, tap->ir_length); expected_mask = buf_get_u32(tap->expected_mask, 0, tap->ir_length); - command_print(CMD_CTX, + command_print(CMD, "%2d %-18s %c 0x%08x %s %5d 0x%02x 0x%02x", tap->abs_chain_position, tap->dotted_name, @@ -970,7 +992,7 @@ COMMAND_HANDLER(handle_scan_chain_command) if (tap->ignore_version) expected_id[2] = '*'; - command_print(CMD_CTX, + command_print(CMD, " %s", expected_id); } @@ -991,7 +1013,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_delay_command) jtag_set_ntrst_delay(delay); } - command_print(CMD_CTX, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); + command_print(CMD, "jtag_ntrst_delay: %u", jtag_get_ntrst_delay()); return ERROR_OK; } @@ -1005,7 +1027,7 @@ COMMAND_HANDLER(handle_jtag_ntrst_assert_width_command) jtag_set_ntrst_assert_width(delay); } - command_print(CMD_CTX, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); + command_print(CMD, "jtag_ntrst_assert_width: %u", jtag_get_ntrst_assert_width()); return ERROR_OK; } @@ -1030,9 +1052,9 @@ COMMAND_HANDLER(handle_jtag_rclk_command) return retval; if (cur_khz) - command_print(CMD_CTX, "RCLK not supported - fallback to %d kHz", cur_khz); + command_print(CMD, "RCLK not supported - fallback to %d kHz", cur_khz); else - command_print(CMD_CTX, "RCLK - adaptive"); + command_print(CMD, "RCLK - adaptive"); return retval; } @@ -1131,7 +1153,7 @@ COMMAND_HANDLER(handle_irscan_command) tap = jtag_tap_by_string(CMD_ARGV[i*2]); if (tap == NULL) { free(fields); - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[i*2]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[i*2]); return ERROR_FAIL; } @@ -1176,7 +1198,7 @@ COMMAND_HANDLER(handle_verify_ircapture_command) } const char *status = jtag_will_verify_capture_ir() ? "enabled" : "disabled"; - command_print(CMD_CTX, "verify Capture-IR is %s", status); + command_print(CMD, "verify Capture-IR is %s", status); return ERROR_OK; } @@ -1193,7 +1215,7 @@ COMMAND_HANDLER(handle_verify_jtag_command) } const char *status = jtag_will_verify() ? "enabled" : "disabled"; - command_print(CMD_CTX, "verify jtag capture is %s", status); + command_print(CMD, "verify jtag capture is %s", status); return ERROR_OK; } @@ -1215,7 +1237,7 @@ COMMAND_HANDLER(handle_tms_sequence_command) tap_use_new_tms_table(use_new_table); } - command_print(CMD_CTX, "tms sequence is %s", + command_print(CMD, "tms sequence is %s", tap_uses_new_tms_table() ? "short" : "long"); return ERROR_OK; diff --git a/src/jtag/zy1000/zy1000.c b/src/jtag/zy1000/zy1000.c index 4e53dd1..1734983 100644 --- a/src/jtag/zy1000/zy1000.c +++ b/src/jtag/zy1000/zy1000.c @@ -1242,6 +1242,7 @@ struct jtag_interface zy1000_interface = { .supported = DEBUG_CAP_TMS_SEQ, .execute_queue = NULL, .speed = zy1000_speed, + .transports = jtag_only, .commands = zy1000_commands, .init = zy1000_init, .quit = zy1000_quit, diff --git a/src/openocd.c b/src/openocd.c index f084dd4..2a9a0b3 100644 --- a/src/openocd.c +++ b/src/openocd.c @@ -36,7 +36,6 @@ #include <flash/nor/core.h> #include <flash/nand/core.h> #include <pld/pld.h> -#include <flash/mflash.h> #include <target/arm_cti.h> #include <target/arm_adi_v5.h> @@ -165,9 +164,6 @@ COMMAND_HANDLER(handle_init_command) if (command_run_line(CMD_CTX, "flash init") != ERROR_OK) return ERROR_FAIL; - if (command_run_line(CMD_CTX, "mflash init") != ERROR_OK) - return ERROR_FAIL; - if (command_run_line(CMD_CTX, "nand init") != ERROR_OK) return ERROR_FAIL; @@ -257,7 +253,6 @@ struct command_context *setup_command_handler(Jim_Interp *interp) &flash_register_commands, &nand_register_commands, &pld_register_commands, - &mflash_register_commands, &cti_register_commands, &dap_register_commands, NULL diff --git a/src/pld/pld.c b/src/pld/pld.c index 5210b97..ef7993c 100644 --- a/src/pld/pld.c +++ b/src/pld/pld.c @@ -116,12 +116,12 @@ COMMAND_HANDLER(handle_pld_devices_command) int i = 0; if (!pld_devices) { - command_print(CMD_CTX, "no pld devices configured"); + command_print(CMD, "no pld devices configured"); return ERROR_OK; } for (p = pld_devices; p; p = p->next) - command_print(CMD_CTX, "#%i: %s", i++, p->driver->name); + command_print(CMD, "#%i: %s", i++, p->driver->name); return ERROR_OK; } @@ -141,13 +141,13 @@ COMMAND_HANDLER(handle_pld_load_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id); p = get_pld_device_by_num(dev_id); if (!p) { - command_print(CMD_CTX, "pld device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } retval = p->driver->load(p, CMD_ARGV[1]); if (retval != ERROR_OK) { - command_print(CMD_CTX, "failed loading file %s to pld device %u", + command_print(CMD, "failed loading file %s to pld device %u", CMD_ARGV[1], dev_id); switch (retval) { } @@ -156,7 +156,7 @@ COMMAND_HANDLER(handle_pld_load_command) gettimeofday(&end, NULL); timeval_subtract(&duration, &end, &start); - command_print(CMD_CTX, "loaded file %s to pld device %u in %jis %jius", + command_print(CMD, "loaded file %s to pld device %u in %jis %jius", CMD_ARGV[1], dev_id, (intmax_t)duration.tv_sec, (intmax_t)duration.tv_usec); } @@ -170,6 +170,7 @@ static const struct command_registration pld_exec_command_handlers[] = { .handler = handle_pld_devices_command, .mode = COMMAND_EXEC, .help = "list configured pld devices", + .usage = "", }, { .name = "load", diff --git a/src/pld/virtex2.c b/src/pld/virtex2.c index 4e385e9..934a680 100644 --- a/src/pld/virtex2.c +++ b/src/pld/virtex2.c @@ -183,13 +183,13 @@ COMMAND_HANDLER(virtex2_handle_read_stat_command) COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id); device = get_pld_device_by_num(dev_id); if (!device) { - command_print(CMD_CTX, "pld device '#%s' is out of bounds", CMD_ARGV[0]); + command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]); return ERROR_OK; } virtex2_read_stat(device, &status); - command_print(CMD_CTX, "virtex2 status register: 0x%8.8" PRIx32 "", status); + command_print(CMD, "virtex2 status register: 0x%8.8" PRIx32 "", status); return ERROR_OK; } @@ -205,7 +205,7 @@ PLD_DEVICE_COMMAND_HANDLER(virtex2_pld_device_command) tap = jtag_tap_by_string(CMD_ARGV[1]); if (tap == NULL) { - command_print(CMD_CTX, "Tap: %s does not exist", CMD_ARGV[1]); + command_print(CMD, "Tap: %s does not exist", CMD_ARGV[1]); return ERROR_OK; } diff --git a/src/rtos/nuttx.c b/src/rtos/nuttx.c index 61fd9aa..8c3076e 100644 --- a/src/rtos/nuttx.c +++ b/src/rtos/nuttx.c @@ -174,7 +174,7 @@ static int rcmd_offset(const char *cmd, const char *name) static int nuttx_thread_packet(struct connection *connection, char const *packet, int packet_size) { - char cmd[GDB_BUFFER_SIZE / 2] = ""; + char cmd[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for nul-termination */ if (!strncmp(packet, "qRcmd", 5)) { size_t len = unhexify((uint8_t *)cmd, packet + 6, sizeof(cmd)); diff --git a/src/rtos/rtos.c b/src/rtos/rtos.c index 96dc99b..b402f2d 100644 --- a/src/rtos/rtos.c +++ b/src/rtos/rtos.c @@ -226,7 +226,7 @@ int rtos_qsymbol(struct connection *connection, char const *packet, int packet_s int rtos_detected = 0; uint64_t addr = 0; size_t reply_len; - char reply[GDB_BUFFER_SIZE], cur_sym[GDB_BUFFER_SIZE / 2] = ""; + char reply[GDB_BUFFER_SIZE + 1], cur_sym[GDB_BUFFER_SIZE / 2 + 1] = ""; /* Extra byte for nul-termination */ symbol_table_elem_t *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 35420b1..d0c2050 100644 --- a/src/rtos/rtos.h +++ b/src/rtos/rtos.h @@ -65,7 +65,7 @@ struct rtos { struct rtos_reg { uint32_t number; uint32_t size; - uint8_t value[8]; + uint8_t value[16]; }; struct rtos_type { diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c index a7d9442..8374985 100644 --- a/src/server/gdb_server.c +++ b/src/server/gdb_server.c @@ -67,7 +67,7 @@ struct target_desc_format { /* private connection data for GDB */ struct gdb_connection { - char buffer[GDB_BUFFER_SIZE]; + char buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */ char *buf_p; int buf_cnt; int ctrl_c; @@ -736,8 +736,6 @@ static void gdb_signal_reply(struct target *target, struct connection *connectio struct target *ct; if (target->rtos != NULL) { target->rtos->current_threadid = target->rtos->current_thread; - LOG_DEBUG("[%s] current_threadid=%" PRId64, target_name(target), - target->rtos->current_threadid); target->rtos->gdb_target_for_threadid(connection, target->rtos->current_threadid, &ct); } else { ct = target; @@ -905,7 +903,6 @@ static void gdb_frontend_halted(struct target *target, struct connection *connec static int gdb_target_callback_event_handler(struct target *target, enum target_event event, void *priv) { - int retval; struct connection *connection = priv; struct gdb_service *gdb_service = connection->service->priv; @@ -919,11 +916,6 @@ static int gdb_target_callback_event_handler(struct target *target, case TARGET_EVENT_HALTED: target_call_event_callbacks(target, TARGET_EVENT_GDB_END); break; - case TARGET_EVENT_GDB_FLASH_ERASE_START: - retval = jtag_execute_queue(); - if (retval != ERROR_OK) - return retval; - break; default: break; } @@ -1421,8 +1413,6 @@ static int gdb_error(struct connection *connection, int retval) /* We don't have to worry about the default 2 second timeout for GDB packets, * because GDB breaks up large memory reads into smaller reads. - * - * 8191 bytes by the looks of it. Why 8191 bytes instead of 8192????? */ static int gdb_read_memory_packet(struct connection *connection, char const *packet, int packet_size) @@ -1656,7 +1646,7 @@ static int gdb_breakpoint_watchpoint_packet(struct connection *connection, char *separator; int retval; - LOG_DEBUG("[%d]", target->coreid); + LOG_DEBUG("[%s]", target_name(target)); type = strtoul(packet + 1, &separator, 16); @@ -2629,7 +2619,7 @@ static int gdb_query_packet(struct connection *connection, &pos, &size, "PacketSize=%x;qXfer:memory-map:read%c;qXfer:features:read%c;qXfer:threads:read+;QStartNoAckMode+;vContSupported+", - (GDB_BUFFER_SIZE - 1), + GDB_BUFFER_SIZE, ((gdb_use_memory_map == 1) && (flash_get_bank_count() > 0)) ? '+' : '-', (gdb_target_desc_supported == 1) ? '+' : '-'); @@ -2821,13 +2811,11 @@ static bool gdb_handle_vcont_packet(struct connection *connection, const char *p if (parse[0] == 'c') { parse += 1; - packet_size -= 1; /* check if thread-id follows */ if (parse[0] == ':') { int64_t tid; parse += 1; - packet_size -= 1; tid = strtoll(parse, &endp, 16); if (tid == thread_id) { @@ -3146,7 +3134,7 @@ static void gdb_sig_halted(struct connection *connection) static int gdb_input_inner(struct connection *connection) { /* Do not allocate this on the stack */ - static char gdb_packet_buffer[GDB_BUFFER_SIZE]; + static char gdb_packet_buffer[GDB_BUFFER_SIZE + 1]; /* Extra byte for nul-termination */ struct target *target; char const *packet = gdb_packet_buffer; @@ -3169,7 +3157,7 @@ static int gdb_input_inner(struct connection *connection) * drain the rest of the buffer. */ do { - packet_size = GDB_BUFFER_SIZE-1; + packet_size = GDB_BUFFER_SIZE; retval = gdb_get_packet(connection, gdb_packet_buffer, &packet_size); if (retval != ERROR_OK) return retval; @@ -3530,7 +3518,7 @@ COMMAND_HANDLER(handle_gdb_sync_command) return ERROR_COMMAND_SYNTAX_ERROR; if (current_gdb_connection == NULL) { - command_print(CMD_CTX, + command_print(CMD, "gdb_sync command can only be run from within gdb using \"monitor gdb_sync\""); return ERROR_FAIL; } @@ -3735,6 +3723,7 @@ static const struct command_registration gdb_command_handlers[] = { .handler = handle_gdb_save_tdesc_command, .mode = COMMAND_EXEC, .help = "Save the target description file", + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/server/server.c b/src/server/server.c index 539bdaf..9e63f74 100644 --- a/src/server/server.c +++ b/src/server/server.c @@ -769,7 +769,7 @@ COMMAND_HANDLER(handle_bindto_command) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "bindto name: %s", bindto_name); + command_print(CMD, "bindto name: %s", bindto_name); break; case 1: free(bindto_name); @@ -828,7 +828,7 @@ COMMAND_HELPER(server_port_command, unsigned short *out) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%d", *out); + command_print(CMD, "%d", *out); break; case 1: { @@ -847,7 +847,7 @@ COMMAND_HELPER(server_pipe_command, char **out) { switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%s", *out); + command_print(CMD, "%s", *out); break; case 1: { diff --git a/src/server/tcl_server.c b/src/server/tcl_server.c index 0676c88..1ec45ff 100644 --- a/src/server/tcl_server.c +++ b/src/server/tcl_server.c @@ -246,7 +246,7 @@ static int tcl_input(struct connection *connection) retval = tcl_output(connection, result, reslen); if (retval != ERROR_OK) return retval; - /* Always output ctrl-d as end of line to allow multiline results */ + /* Always output ctrl-z as end of line to allow multiline results */ tcl_output(connection, "\x1a", 1); } diff --git a/src/svf/svf.c b/src/svf/svf.c index 223af7e..759ba52 100644 --- a/src/svf/svf.c +++ b/src/svf/svf.c @@ -382,7 +382,7 @@ COMMAND_HANDLER(handle_svf_command) if (strcmp(CMD_ARGV[i], "-tap") == 0) { tap = jtag_tap_by_string(CMD_ARGV[i+1]); if (!tap) { - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[i+1]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[i+1]); return ERROR_FAIL; } i++; @@ -401,7 +401,7 @@ COMMAND_HANDLER(handle_svf_command) svf_fd = fopen(CMD_ARGV[i], "r"); if (svf_fd == NULL) { int err = errno; - command_print(CMD_CTX, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err)); + command_print(CMD, "open(\"%s\"): %s", CMD_ARGV[i], strerror(err)); /* no need to free anything now */ return ERROR_COMMAND_SYNTAX_ERROR; } else @@ -534,7 +534,7 @@ COMMAND_HANDLER(handle_svf_command) time_measure_m = time_measure_s / 60; time_measure_s %= 60; if (time_measure_ms < 1000) - command_print(CMD_CTX, + command_print(CMD, "\r\nTime used: %dm%ds%" PRId64 "ms ", time_measure_m, time_measure_s, @@ -579,13 +579,13 @@ free_all: svf_free_xxd_para(&svf_para.sir_para); if (ERROR_OK == ret) - command_print(CMD_CTX, + command_print(CMD, "svf file programmed %s for %d commands with %d errors", (svf_ignore_error > 1) ? "unsuccessfully" : "successfully", command_num, (svf_ignore_error > 1) ? (svf_ignore_error - 1) : 0); else - command_print(CMD_CTX, "svf file programmed failed"); + command_print(CMD, "svf file programmed failed"); svf_ignore_error = 0; return ret; diff --git a/src/target/aarch64.c b/src/target/aarch64.c index ff68e3a..7acb472 100644 --- a/src/target/aarch64.c +++ b/src/target/aarch64.c @@ -29,6 +29,7 @@ #include "armv8_opcodes.h" #include "armv8_cache.h" #include "arm_semihosting.h" +#include "jtag/interface.h" #include "smp.h" #include <helper/time_support.h> @@ -1662,7 +1663,7 @@ static int aarch64_assert_reset(struct target *target) /* REVISIT handle "pulls" cases, if there's * hardware that needs them to work. */ - jtag_add_reset(0, 1); + adapter_assert_reset(); } else { LOG_ERROR("%s: how to reset?", target_name(target)); return ERROR_FAIL; @@ -1686,7 +1687,7 @@ static int aarch64_deassert_reset(struct target *target) LOG_DEBUG(" "); /* be certain SRST is off */ - jtag_add_reset(0, 0); + adapter_deassert_reset(); if (!target_was_examined(target)) return ERROR_OK; @@ -2533,7 +2534,7 @@ COMMAND_HANDLER(aarch64_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct armv8_common *armv8 = target_to_armv8(target); - return armv8_handle_cache_info_command(CMD_CTX, + return armv8_handle_cache_info_command(CMD, &armv8->armv8_mmu.armv8_cache); } @@ -2572,7 +2573,7 @@ COMMAND_HANDLER(aarch64_mask_interrupts_command) } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, aarch64->isrmasking_mode); - command_print(CMD_CTX, "aarch64 interrupt mask %s", n->name); + command_print(CMD, "aarch64 interrupt mask %s", n->name); return ERROR_OK; } diff --git a/src/target/adi_v5_swd.c b/src/target/adi_v5_swd.c index d92e296..594b508 100644 --- a/src/target/adi_v5_swd.c +++ b/src/target/adi_v5_swd.c @@ -352,6 +352,7 @@ static const struct command_registration swd_handlers[] = { .mode = COMMAND_ANY, .help = "SWD command group", .chain = swd_commands, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/arm720t.c b/src/target/arm720t.c index b592ffc..abe5f1c 100644 --- a/src/target/arm720t.c +++ b/src/target/arm720t.c @@ -233,11 +233,11 @@ static void arm720t_pre_restore_context(struct target *target) arm720t_write_cp15(target, 0xee060f10, arm720t->far_reg); } -static int arm720t_verify_pointer(struct command_context *cmd_ctx, +static int arm720t_verify_pointer(struct command_invocation *cmd, struct arm720t_common *arm720t) { if (arm720t->common_magic != ARM720T_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM720"); + command_print(cmd, "target is not an ARM720"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -442,12 +442,12 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm720t_common *arm720t = target_to_arm720(target); - retval = arm720t_verify_pointer(CMD_CTX, arm720t); + retval = arm720t_verify_pointer(CMD, arm720t); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -460,7 +460,7 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) uint32_t value; retval = arm720t_read_cp15(target, opcode, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); + command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); return ERROR_OK; } @@ -468,17 +468,17 @@ COMMAND_HANDLER(arm720t_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); + 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_CTX, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); + command_print(CMD, "couldn't access cp15 with opcode 0x%8.8" PRIx32 "", opcode); return ERROR_OK; } - command_print(CMD_CTX, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); + command_print(CMD, "0x%8.8" PRIx32 ": 0x%8.8" PRIx32 "", opcode, value); } } diff --git a/src/target/arm7_9_common.c b/src/target/arm7_9_common.c index c6a8a26..b2962d1 100644 --- a/src/target/arm7_9_common.c +++ b/src/target/arm7_9_common.c @@ -2747,14 +2747,14 @@ COMMAND_HANDLER(handle_arm7_9_dbgrq_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->use_dbgrq); - command_print(CMD_CTX, + command_print(CMD, "use of EmbeddedICE dbgrq instead of breakpoint for target halt %s", (arm7_9->use_dbgrq) ? "enabled" : "disabled"); @@ -2767,14 +2767,14 @@ COMMAND_HANDLER(handle_arm7_9_fast_memory_access_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->fast_memory_access); - command_print(CMD_CTX, + command_print(CMD, "fast memory access is %s", (arm7_9->fast_memory_access) ? "enabled" : "disabled"); @@ -2787,14 +2787,14 @@ COMMAND_HANDLER(handle_arm7_9_dcc_downloads_command) struct arm7_9_common *arm7_9 = target_to_arm7_9(target); if (!is_arm7_9(arm7_9)) { - command_print(CMD_CTX, "current target isn't an ARM7/ARM9 target"); + command_print(CMD, "current target isn't an ARM7/ARM9 target"); return ERROR_TARGET_INVALID; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], arm7_9->dcc_downloads); - command_print(CMD_CTX, + command_print(CMD, "dcc downloads are %s", (arm7_9->dcc_downloads) ? "enabled" : "disabled"); @@ -2864,7 +2864,7 @@ int arm7_9_init_arch_info(struct target *target, struct arm7_9_common *arm7_9) static const struct command_registration arm7_9_any_command_handlers[] = { { - "dbgrq", + .name = "dbgrq", .handler = handle_arm7_9_dbgrq_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", @@ -2872,7 +2872,7 @@ static const struct command_registration arm7_9_any_command_handlers[] = { "for target halt requests", }, { - "fast_memory_access", + .name = "fast_memory_access", .handler = handle_arm7_9_fast_memory_access_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", @@ -2880,7 +2880,7 @@ static const struct command_registration arm7_9_any_command_handlers[] = { "but potentially safer accesses", }, { - "dcc_downloads", + .name = "dcc_downloads", .handler = handle_arm7_9_dcc_downloads_command, .mode = COMMAND_ANY, .usage = "['enable'|'disable']", diff --git a/src/target/arm920t.c b/src/target/arm920t.c index ed9d388..2ecf218 100644 --- a/src/target/arm920t.c +++ b/src/target/arm920t.c @@ -507,11 +507,11 @@ void arm920t_pre_restore_context(struct target *target) static const char arm920_not[] = "target is not an ARM920"; -static int arm920t_verify_pointer(struct command_context *cmd_ctx, +static int arm920t_verify_pointer(struct command_invocation *cmd, struct arm920t_common *arm920t) { if (arm920t->common_magic != ARM920T_COMMON_MAGIC) { - command_print(cmd_ctx, arm920_not); + command_print(cmd, arm920_not); return ERROR_TARGET_INVALID; } @@ -869,7 +869,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) int segment, index_t; struct reg *r; - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1103,7 +1103,7 @@ COMMAND_HANDLER(arm920t_handle_read_cache_command) /* restore CP15 MMU and Cache settings */ arm920t_write_cp15_physical(target, CP15PHYS_CTRL, cp15_ctrl_saved); - command_print(CMD_CTX, "cache content successfully output to %s", + command_print(CMD, "cache content successfully output to %s", CMD_ARGV[0]); fclose(output); @@ -1151,7 +1151,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) int victim; struct reg *r; - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; @@ -1415,7 +1415,7 @@ COMMAND_HANDLER(arm920t_handle_read_mmu_command) (i_tlb[i].cam & 0x20) ? "(valid)" : "(invalid)"); } - command_print(CMD_CTX, "mmu content successfully output to %s", + command_print(CMD, "mmu content successfully output to %s", CMD_ARGV[0]); fclose(output); @@ -1451,12 +1451,12 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for " + command_print(CMD, "target must be stopped for " "\"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1472,7 +1472,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) uint32_t value; retval = arm920t_read_cp15_physical(target, address, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %i", address); return ERROR_OK; } @@ -1480,7 +1480,7 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "%i: %8.8" PRIx32, + command_print(CMD, "%i: %8.8" PRIx32, address, value); } else if (CMD_ARGC == 2) { uint32_t value; @@ -1488,12 +1488,12 @@ COMMAND_HANDLER(arm920t_handle_cp15_command) retval = arm920t_write_cp15_physical(target, address, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %i", address); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%i: %8.8" PRIx32, + command_print(CMD, "%i: %8.8" PRIx32, address, value); } } @@ -1507,13 +1507,13 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for " + command_print(CMD, "target must be stopped for " "\"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1530,14 +1530,14 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_read_cp15_interpreted(target, opcode, 0x0, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32, + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, opcode, value); } else if (CMD_ARGC == 2) { uint32_t value; @@ -1545,13 +1545,13 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_write_cp15_interpreted(target, opcode, value, 0); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32, + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32, opcode, value); } else if (CMD_ARGC == 3) { uint32_t value; @@ -1561,12 +1561,12 @@ COMMAND_HANDLER(arm920t_handle_cp15i_command) retval = arm920t_write_cp15_interpreted(target, opcode, value, address); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't execute %8.8" PRIx32, opcode); /* REVISIT why lie? "return retval"? */ return ERROR_OK; } - command_print(CMD_CTX, "%8.8" PRIx32 ": %8.8" PRIx32 + command_print(CMD, "%8.8" PRIx32 ": %8.8" PRIx32 " %8.8" PRIx32, opcode, value, address); } } else @@ -1581,11 +1581,11 @@ COMMAND_HANDLER(arm920t_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct arm920t_common *arm920t = target_to_arm920(target); - retval = arm920t_verify_pointer(CMD_CTX, arm920t); + retval = arm920t_verify_pointer(CMD, arm920t); if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, + return armv4_5_handle_cache_info_command(CMD, &arm920t->armv4_5_mmu.armv4_5_cache); } diff --git a/src/target/arm926ejs.c b/src/target/arm926ejs.c index 3f22a8a..ac30485 100644 --- a/src/target/arm926ejs.c +++ b/src/target/arm926ejs.c @@ -501,11 +501,11 @@ static void arm926ejs_pre_restore_context(struct target *target) static const char arm926_not[] = "target is not an ARM926"; -static int arm926ejs_verify_pointer(struct command_context *cmd_ctx, +static int arm926ejs_verify_pointer(struct command_invocation *cmd, struct arm926ejs_common *arm926) { if (arm926->common_magic != ARM926EJS_COMMON_MAGIC) { - command_print(cmd_ctx, arm926_not); + command_print(cmd, arm926_not); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -729,11 +729,11 @@ COMMAND_HANDLER(arm926ejs_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct arm926ejs_common *arm926ejs = target_to_arm926(target); - retval = arm926ejs_verify_pointer(CMD_CTX, arm926ejs); + retval = arm926ejs_verify_pointer(CMD, arm926ejs); if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, &arm926ejs->armv4_5_mmu.armv4_5_cache); + return armv4_5_handle_cache_info_command(CMD, &arm926ejs->armv4_5_mmu.armv4_5_cache); } static int arm926ejs_virt2phys(struct target *target, target_addr_t virtual, target_addr_t *physical) diff --git a/src/target/arm946e.c b/src/target/arm946e.c index 5e25d71..112631a 100644 --- a/src/target/arm946e.c +++ b/src/target/arm946e.c @@ -99,11 +99,11 @@ static int arm946e_target_create(struct target *target, Jim_Interp *interp) return ERROR_OK; } -static int arm946e_verify_pointer(struct command_context *cmd_ctx, +static int arm946e_verify_pointer(struct command_invocation *cmd, struct arm946e_common *arm946e) { if (arm946e->common_magic != ARM946E_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM946"); + command_print(cmd, "target is not an ARM946"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -549,70 +549,54 @@ int arm946e_read_memory(struct target *target, target_addr_t address, return ERROR_OK; } -static int jim_arm946e_cp15(Jim_Interp *interp, int argc, Jim_Obj * const *argv) +COMMAND_HANDLER(arm946e_handle_cp15) { /* one or two arguments, access a single register (write if second argument is given) */ - if (argc < 2 || argc > 3) { - Jim_WrongNumArgs(interp, 1, argv, "addr [value]"); - return JIM_ERR; - } - - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx != NULL); + if (CMD_ARGC < 1 || CMD_ARGC > 2) + return ERROR_COMMAND_SYNTAX_ERROR; - struct target *target = get_current_target(cmd_ctx); - if (target == NULL) { - LOG_ERROR("arm946e: no current target"); - return JIM_ERR; - } + struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - int retval = arm946e_verify_pointer(cmd_ctx, arm946e); + int retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) - return JIM_ERR; + return retval; if (target->state != TARGET_HALTED) { - command_print(cmd_ctx, "target %s must be stopped for \"cp15\" command", target_name(target)); - return JIM_ERR; + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); + return ERROR_TARGET_NOT_HALTED; } - long l; uint32_t address; - retval = Jim_GetLong(interp, argv[1], &l); - address = l; - if (JIM_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); - if (argc == 2) { + if (CMD_ARGC == 1) { uint32_t value; retval = arm946e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } retval = jtag_execute_queue(); if (retval != ERROR_OK) - return JIM_ERR; - char buf[20]; - sprintf(buf, "0x%08" PRIx32, value); + return retval; + /* Return value in hex format */ - Jim_SetResultString(interp, buf, -1); - } else if (argc == 3) { + command_print(CMD, "0x%08" PRIx32, value); + } else if (CMD_ARGC == 2) { uint32_t value; - retval = Jim_GetLong(interp, argv[2], &l); - value = l; - if (JIM_OK != retval) - return retval; + COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); + retval = arm946e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(cmd_ctx, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); - return JIM_ERR; + command_print(CMD, "%s cp15 reg %" PRIi32 " access failed", target_name(target), address); + return retval; } if (address == CP15_CTL) arm946e_update_cp15_caches(target, value); } - return JIM_OK; + return ERROR_OK; } COMMAND_HANDLER(arm946e_handle_idcache) @@ -624,12 +608,12 @@ COMMAND_HANDLER(arm946e_handle_idcache) struct target *target = get_current_target(CMD_CTX); struct arm946e_common *arm946e = target_to_arm946(target); - retval = arm946e_verify_pointer(CMD_CTX, arm946e); + retval = arm946e_verify_pointer(CMD, arm946e); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_TARGET_NOT_HALTED; } @@ -639,9 +623,9 @@ COMMAND_HANDLER(arm946e_handle_idcache) bool bena = ((arm946e->cp15_control_reg & (icache ? CP15_CTL_ICACHE : CP15_CTL_DCACHE)) != 0) && (arm946e->cp15_control_reg & 0x1); if (csize == 0) - command_print(CMD_CTX, "%s-cache absent", icache ? "I" : "D"); + command_print(CMD, "%s-cache absent", icache ? "I" : "D"); else - command_print(CMD_CTX, "%s-cache size: %" PRIu32 "K, %s", + command_print(CMD, "%s-cache size: %" PRIu32 "K, %s", icache ? "I" : "D", csize, bena ? "enabled" : "disabled"); return ERROR_OK; } @@ -659,7 +643,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) /* Do not invalidate or change state, if cache is absent */ if (csize == 0) { - command_print(CMD_CTX, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); + command_print(CMD, "%s-cache absent, '%s' operation undefined", icache ? "I" : "D", CMD_ARGV[0]); return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } @@ -703,7 +687,7 @@ COMMAND_HANDLER(arm946e_handle_idcache) static const struct command_registration arm946e_exec_command_handlers[] = { { .name = "cp15", - .jim_handler = jim_arm946e_cp15, + .handler = arm946e_handle_cp15, .mode = COMMAND_EXEC, .usage = "regnum [value]", .help = "read/modify cp15 register", diff --git a/src/target/arm966e.c b/src/target/arm966e.c index c9d7f01..8462f54 100644 --- a/src/target/arm966e.c +++ b/src/target/arm966e.c @@ -56,11 +56,11 @@ static int arm966e_target_create(struct target *target, Jim_Interp *interp) return arm966e_init_arch_info(target, arm966e, target->tap); } -static int arm966e_verify_pointer(struct command_context *cmd_ctx, +static int arm966e_verify_pointer(struct command_invocation *cmd, struct arm966e_common *arm966e) { if (arm966e->common_magic != ARM966E_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an ARM966"); + command_print(cmd, "target is not an ARM966"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -170,12 +170,12 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) struct target *target = get_current_target(CMD_CTX); struct arm966e_common *arm966e = target_to_arm966(target); - retval = arm966e_verify_pointer(CMD_CTX, arm966e); + retval = arm966e_verify_pointer(CMD, arm966e); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -188,7 +188,7 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) uint32_t value; retval = arm966e_read_cp15(target, address, &value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, address); return ERROR_OK; @@ -197,19 +197,19 @@ COMMAND_HANDLER(arm966e_handle_cp15_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "%" PRIi32 ": %8.8" PRIx32, address, value); } else if (CMD_ARGC == 2) { uint32_t value; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], value); retval = arm966e_write_cp15(target, address, value); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, address); return ERROR_OK; } - command_print(CMD_CTX, "%" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "%" PRIi32 ": %8.8" PRIx32, address, value); } } diff --git a/src/target/arm9tdmi.c b/src/target/arm9tdmi.c index 6425027..6ab06ed 100644 --- a/src/target/arm9tdmi.c +++ b/src/target/arm9tdmi.c @@ -801,7 +801,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* it's uncommon, but some ARM7 chips can support this */ if (arm7_9->common_magic != ARM7_9_COMMON_MAGIC || !arm7_9->has_vector_catch) { - command_print(CMD_CTX, "target doesn't have EmbeddedICE " + command_print(CMD, "target doesn't have EmbeddedICE " "with vector_catch"); return ERROR_TARGET_INVALID; } @@ -834,7 +834,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* complain if vector wasn't found */ if (!arm9tdmi_vectors[j].name) { - command_print(CMD_CTX, "vector '%s' not found, leaving current setting unchanged", CMD_ARGV[i]); + command_print(CMD, "vector '%s' not found, leaving current setting unchanged", CMD_ARGV[i]); /* reread current setting */ vector_catch_value = buf_get_u32( @@ -852,7 +852,7 @@ COMMAND_HANDLER(handle_arm9tdmi_catch_vectors_command) /* output current settings */ for (unsigned i = 0; arm9tdmi_vectors[i].name; i++) { - command_print(CMD_CTX, "%s: %s", arm9tdmi_vectors[i].name, + command_print(CMD, "%s: %s", arm9tdmi_vectors[i].name, (vector_catch_value & arm9tdmi_vectors[i].value) ? "catch" : "don't catch"); } diff --git a/src/target/arm_adi_v5.c b/src/target/arm_adi_v5.c index 021d02a..d2ec960 100644 --- a/src/target/arm_adi_v5.c +++ b/src/target/arm_adi_v5.c @@ -914,7 +914,8 @@ int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_a ((id_val & IDR_TYPE) == type_to_find)) { /* type matches*/ LOG_DEBUG("Found %s at AP index: %d (IDR=0x%08" PRIX32 ")", - (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" : + (type_to_find == AP_TYPE_AHB3_AP) ? "AHB3-AP" : + (type_to_find == AP_TYPE_AHB5_AP) ? "AHB5-AP" : (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" : (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" : (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown", @@ -926,7 +927,8 @@ int dap_find_ap(struct adiv5_dap *dap, enum ap_type type_to_find, struct adiv5_a } LOG_DEBUG("No %s found", - (type_to_find == AP_TYPE_AHB_AP) ? "AHB-AP" : + (type_to_find == AP_TYPE_AHB3_AP) ? "AHB3-AP" : + (type_to_find == AP_TYPE_AHB5_AP) ? "AHB5-AP" : (type_to_find == AP_TYPE_APB_AP) ? "APB-AP" : (type_to_find == AP_TYPE_AXI_AP) ? "AXI-AP" : (type_to_find == AP_TYPE_JTAG_AP) ? "JTAG-AP" : "Unknown"); @@ -1190,7 +1192,7 @@ static const struct { { ANY_ID, 0x343, "TI DAPCTL", "", }, /* from OMAP3 memmap */ }; -static int dap_rom_display(struct command_context *cmd_ctx, +static int dap_rom_display(struct command_invocation *cmd, struct adiv5_ap *ap, uint32_t dbgbase, int depth) { int retval; @@ -1199,7 +1201,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, char tabs[16] = ""; if (depth > 16) { - command_print(cmd_ctx, "\tTables too deep"); + command_print(cmd, "\tTables too deep"); return ERROR_FAIL; } @@ -1207,25 +1209,25 @@ static int dap_rom_display(struct command_context *cmd_ctx, snprintf(tabs, sizeof(tabs), "[L%02d] ", depth); uint32_t base_addr = dbgbase & 0xFFFFF000; - command_print(cmd_ctx, "\t\tComponent base address 0x%08" PRIx32, base_addr); + command_print(cmd, "\t\tComponent base address 0x%08" PRIx32, base_addr); retval = dap_read_part_id(ap, base_addr, &cid, &pid); if (retval != ERROR_OK) { - command_print(cmd_ctx, "\t\tCan't read component, the corresponding core might be turned off"); + command_print(cmd, "\t\tCan't read component, the corresponding core might be turned off"); return ERROR_OK; /* Don't abort recursion */ } if (!is_dap_cid_ok(cid)) { - command_print(cmd_ctx, "\t\tInvalid CID 0x%08" PRIx32, cid); + command_print(cmd, "\t\tInvalid CID 0x%08" PRIx32, cid); return ERROR_OK; /* Don't abort recursion */ } /* component may take multiple 4K pages */ uint32_t size = (pid >> 36) & 0xf; if (size > 0) - command_print(cmd_ctx, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); + command_print(cmd, "\t\tStart address 0x%08" PRIx32, (uint32_t)(base_addr - 0x1000 * size)); - command_print(cmd_ctx, "\t\tPeripheral ID 0x%010" PRIx64, pid); + command_print(cmd, "\t\tPeripheral ID 0x%010" PRIx64, pid); uint8_t class = (cid >> 12) & 0xf; uint16_t part_num = pid & 0xfff; @@ -1233,12 +1235,12 @@ static int dap_rom_display(struct command_context *cmd_ctx, if (designer_id & 0x80) { /* JEP106 code */ - command_print(cmd_ctx, "\t\tDesigner is 0x%03" PRIx16 ", %s", + command_print(cmd, "\t\tDesigner is 0x%03" PRIx16 ", %s", designer_id, jep106_manufacturer(designer_id >> 8, designer_id & 0x7f)); } else { /* Legacy ASCII ID, clear invalid bits */ designer_id &= 0x7f; - command_print(cmd_ctx, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", + command_print(cmd, "\t\tDesigner ASCII code 0x%02" PRIx16 ", %s", designer_id, designer_id == 0x41 ? "ARM" : "<unknown>"); } @@ -1260,8 +1262,8 @@ static int dap_rom_display(struct command_context *cmd_ctx, break; } - command_print(cmd_ctx, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); - command_print(cmd_ctx, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); + command_print(cmd, "\t\tPart is 0x%" PRIx16", %s %s", part_num, type, full); + command_print(cmd, "\t\tComponent class is 0x%" PRIx8 ", %s", class, class_description[class]); if (class == 1) { /* ROM Table */ uint32_t memtype; @@ -1270,9 +1272,9 @@ static int dap_rom_display(struct command_context *cmd_ctx, return retval; if (memtype & 0x01) - command_print(cmd_ctx, "\t\tMEMTYPE system memory present on bus"); + command_print(cmd, "\t\tMEMTYPE system memory present on bus"); else - command_print(cmd_ctx, "\t\tMEMTYPE system memory not present: dedicated debug bus"); + command_print(cmd, "\t\tMEMTYPE system memory not present: dedicated debug bus"); /* Read ROM table entries from base address until we get 0x00000000 or reach the reserved area */ for (uint16_t entry_offset = 0; entry_offset < 0xF00; entry_offset += 4) { @@ -1280,17 +1282,17 @@ static int dap_rom_display(struct command_context *cmd_ctx, retval = mem_ap_read_atomic_u32(ap, base_addr | entry_offset, &romentry); if (retval != ERROR_OK) return retval; - command_print(cmd_ctx, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", + command_print(cmd, "\t%sROMTABLE[0x%x] = 0x%" PRIx32 "", tabs, entry_offset, romentry); if (romentry & 0x01) { /* Recurse */ - retval = dap_rom_display(cmd_ctx, ap, base_addr + (romentry & 0xFFFFF000), depth + 1); + retval = dap_rom_display(cmd, ap, base_addr + (romentry & 0xFFFFF000), depth + 1); if (retval != ERROR_OK) return retval; } else if (romentry != 0) { - command_print(cmd_ctx, "\t\tComponent not present"); + command_print(cmd, "\t\tComponent not present"); } else { - command_print(cmd_ctx, "\t%s\tEnd of ROM table", tabs); + command_print(cmd, "\t%s\tEnd of ROM table", tabs); break; } } @@ -1412,7 +1414,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, } break; case 6: - major = "Perfomance Monitor"; + major = "Performance Monitor"; switch (minor) { case 0: subtype = "other"; @@ -1435,7 +1437,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, } break; } - command_print(cmd_ctx, "\t\tType is 0x%02" PRIx8 ", %s, %s", + command_print(cmd, "\t\tType is 0x%02" PRIx8 ", %s, %s", (uint8_t)(devtype & 0xff), major, subtype); /* REVISIT also show 0xfc8 DevId */ @@ -1444,7 +1446,7 @@ static int dap_rom_display(struct command_context *cmd_ctx, return ERROR_OK; } -int dap_info_command(struct command_context *cmd_ctx, +int dap_info_command(struct command_invocation *cmd, struct adiv5_ap *ap) { int retval; @@ -1456,27 +1458,30 @@ int dap_info_command(struct command_context *cmd_ctx, if (retval != ERROR_OK) return retval; - command_print(cmd_ctx, "AP ID register 0x%8.8" PRIx32, apid); + command_print(cmd, "AP ID register 0x%8.8" PRIx32, apid); if (apid == 0) { - command_print(cmd_ctx, "No AP found at this ap 0x%x", ap->ap_num); + command_print(cmd, "No AP found at this ap 0x%x", ap->ap_num); return ERROR_FAIL; } switch (apid & (IDR_JEP106 | IDR_TYPE)) { case IDR_JEP106_ARM | AP_TYPE_JTAG_AP: - command_print(cmd_ctx, "\tType is JTAG-AP"); + command_print(cmd, "\tType is JTAG-AP"); break; - case IDR_JEP106_ARM | AP_TYPE_AHB_AP: - command_print(cmd_ctx, "\tType is MEM-AP AHB"); + case IDR_JEP106_ARM | AP_TYPE_AHB3_AP: + command_print(cmd, "\tType is MEM-AP AHB3"); + break; + case IDR_JEP106_ARM | AP_TYPE_AHB5_AP: + command_print(cmd, "\tType is MEM-AP AHB5"); break; case IDR_JEP106_ARM | AP_TYPE_APB_AP: - command_print(cmd_ctx, "\tType is MEM-AP APB"); + command_print(cmd, "\tType is MEM-AP APB"); break; case IDR_JEP106_ARM | AP_TYPE_AXI_AP: - command_print(cmd_ctx, "\tType is MEM-AP AXI"); + command_print(cmd, "\tType is MEM-AP AXI"); break; default: - command_print(cmd_ctx, "\tUnknown AP type"); + command_print(cmd, "\tUnknown AP type"); break; } @@ -1485,17 +1490,17 @@ int dap_info_command(struct command_context *cmd_ctx, */ mem_ap = (apid & IDR_CLASS) == AP_CLASS_MEM_AP; if (mem_ap) { - command_print(cmd_ctx, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); + command_print(cmd, "MEM-AP BASE 0x%8.8" PRIx32, dbgbase); if (dbgbase == 0xFFFFFFFF || (dbgbase & 0x3) == 0x2) { - command_print(cmd_ctx, "\tNo ROM table present"); + command_print(cmd, "\tNo ROM table present"); } else { if (dbgbase & 0x01) - command_print(cmd_ctx, "\tValid ROM table present"); + command_print(cmd, "\tValid ROM table present"); else - command_print(cmd_ctx, "\tROM table in legacy format"); + command_print(cmd, "\tROM table in legacy format"); - dap_rom_display(cmd_ctx, ap, dbgbase & 0xFFFFF000, 0); + dap_rom_display(cmd, ap, dbgbase & 0xFFFFF000, 0); } } @@ -1646,7 +1651,7 @@ COMMAND_HANDLER(handle_dap_info_command) return ERROR_COMMAND_SYNTAX_ERROR; } - return dap_info_command(CMD_CTX, &dap->ap[apsel]); + return dap_info_command(CMD, &dap->ap[apsel]); } COMMAND_HANDLER(dap_baseaddr_command) @@ -1681,7 +1686,7 @@ COMMAND_HANDLER(dap_baseaddr_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32, baseaddr); + command_print(CMD, "0x%8.8" PRIx32, baseaddr); return retval; } @@ -1703,7 +1708,7 @@ COMMAND_HANDLER(dap_memaccess_command) } dap->ap[dap->apsel].memaccess_tck = memaccess_tck; - command_print(CMD_CTX, "memory bus access delay set to %" PRIi32 " tck", + command_print(CMD, "memory bus access delay set to %" PRIi32 " tck", dap->ap[dap->apsel].memaccess_tck); return ERROR_OK; @@ -1716,7 +1721,7 @@ COMMAND_HANDLER(dap_apsel_command) switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "%" PRIi32, dap->apsel); + command_print(CMD, "%" PRIi32, dap->apsel); return ERROR_OK; case 1: COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], apsel); @@ -1740,12 +1745,12 @@ COMMAND_HANDLER(dap_apcsw_command) switch (CMD_ARGC) { case 0: - command_print(CMD_CTX, "ap %" PRIi32 " selected, csw 0x%8.8" PRIx32, + command_print(CMD, "ap %" PRIi32 " selected, csw 0x%8.8" PRIx32, dap->apsel, apcsw); return ERROR_OK; case 1: if (strcmp(CMD_ARGV[0], "default") == 0) - csw_val = CSW_DEFAULT; + csw_val = CSW_AHB_DEFAULT; else COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], csw_val); @@ -1801,7 +1806,7 @@ COMMAND_HANDLER(dap_apid_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%8.8" PRIx32, apid); + command_print(CMD, "0x%8.8" PRIx32, apid); return retval; } @@ -1853,7 +1858,7 @@ COMMAND_HANDLER(dap_apreg_command) return retval; if (CMD_ARGC == 2) - command_print(CMD_CTX, "0x%08" PRIx32, value); + command_print(CMD, "0x%08" PRIx32, value); return retval; } @@ -1884,7 +1889,7 @@ COMMAND_HANDLER(dap_dpreg_command) return retval; if (CMD_ARGC == 1) - command_print(CMD_CTX, "0x%08" PRIx32, value); + command_print(CMD, "0x%08" PRIx32, value); return retval; } @@ -1906,7 +1911,7 @@ COMMAND_HANDLER(dap_ti_be_32_quirks_command) return ERROR_COMMAND_SYNTAX_ERROR; } dap->ti_be_32_quirks = enable; - command_print(CMD_CTX, "TI BE-32 quirks mode %s", + command_print(CMD, "TI BE-32 quirks mode %s", enable ? "enabled" : "disabled"); return 0; diff --git a/src/target/arm_adi_v5.h b/src/target/arm_adi_v5.h index 96291a7..6e2d8a1 100644 --- a/src/target/arm_adi_v5.h +++ b/src/target/arm_adi_v5.h @@ -112,15 +112,34 @@ #define CSW_ADDRINC_PACKED (2UL << 4) #define CSW_DEVICE_EN (1UL << 6) #define CSW_TRIN_PROG (1UL << 7) -/* all fields in bits 12 and above are implementation-defined! */ + +/* All fields in bits 12 and above are implementation-defined + * Defaults for AHB/AXI in "Standard Memory Access Port Definitions" from ADI + * Some bits are shared between buses + */ #define CSW_SPIDEN (1UL << 23) -#define CSW_HPROT1 (1UL << 25) /* AHB: Privileged */ -#define CSW_MASTER_DEBUG (1UL << 29) /* AHB: set HMASTER signals to AHB-AP ID */ -#define CSW_SPROT (1UL << 30) #define CSW_DBGSWENABLE (1UL << 31) -/* initial value of csw_default used for MEM-AP transfers */ -#define CSW_DEFAULT (CSW_HPROT1 | CSW_MASTER_DEBUG | CSW_DBGSWENABLE) +/* AHB: Privileged */ +#define CSW_AHB_HPROT1 (1UL << 25) +/* AHB: set HMASTER signals to AHB-AP ID */ +#define CSW_AHB_MASTER_DEBUG (1UL << 29) +/* AHB5: non-secure access via HNONSEC + * AHB3: SBO, UNPREDICTABLE if zero */ +#define CSW_AHB_SPROT (1UL << 30) +/* AHB: initial value of csw_default */ +#define CSW_AHB_DEFAULT (CSW_AHB_HPROT1 | CSW_AHB_MASTER_DEBUG | CSW_DBGSWENABLE) + +/* AXI: Privileged */ +#define CSW_AXI_ARPROT0_PRIV (1UL << 28) +/* AXI: Non-secure */ +#define CSW_AXI_ARPROT1_NONSEC (1UL << 29) +/* AXI: initial value of csw_default */ +#define CSW_AXI_DEFAULT (CSW_AXI_ARPROT0_PRIV | CSW_AXI_ARPROT1_NONSEC | CSW_DBGSWENABLE) + +/* APB: initial value of csw_default */ +#define CSW_APB_DEFAULT (CSW_DBGSWENABLE) + /* Fields of the MEM-AP's IDR register */ #define IDR_REV (0xFUL << 28) @@ -307,9 +326,10 @@ enum ap_class { */ enum ap_type { AP_TYPE_JTAG_AP = 0x0, /* JTAG-AP - JTAG master for controlling other JTAG devices */ - AP_TYPE_AHB_AP = 0x1, /* AHB Memory-AP */ + AP_TYPE_AHB3_AP = 0x1, /* AHB3 Memory-AP */ AP_TYPE_APB_AP = 0x2, /* APB Memory-AP */ AP_TYPE_AXI_AP = 0x4, /* AXI Memory-AP */ + AP_TYPE_AHB5_AP = 0x5, /* AHB5 Memory-AP. */ }; /** @@ -526,7 +546,7 @@ extern const struct command_registration dap_instance_commands[]; struct arm_dap_object; extern struct adiv5_dap *dap_instance_by_jim_obj(Jim_Interp *interp, Jim_Obj *o); extern struct adiv5_dap *adiv5_get_dap(struct arm_dap_object *obj); -extern int dap_info_command(struct command_context *cmd_ctx, +extern int dap_info_command(struct command_invocation *cmd, struct adiv5_ap *ap); extern int dap_register_commands(struct command_context *cmd_ctx); extern const char *adiv5_dap_name(struct adiv5_dap *self); diff --git a/src/target/arm_cti.c b/src/target/arm_cti.c index f333792..3f063b8 100644 --- a/src/target/arm_cti.c +++ b/src/target/arm_cti.c @@ -252,7 +252,7 @@ COMMAND_HANDLER(handle_cti_dump) return JIM_ERR; for (int i = 0; i < (int)ARRAY_SIZE(cti_names); i++) - command_print(CMD_CTX, "%8.8s (0x%04"PRIx32") 0x%08"PRIx32, + command_print(CMD, "%8.8s (0x%04"PRIx32") 0x%08"PRIx32, cti_names[i].label, cti_names[i].offset, *cti_names[i].p_val); return JIM_OK; @@ -336,7 +336,7 @@ COMMAND_HANDLER(handle_cti_read) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "0x%08"PRIx32, value); + command_print(CMD, "0x%08"PRIx32, value); return ERROR_OK; } @@ -576,6 +576,7 @@ static const struct command_registration cti_command_handlers[] = { .mode = COMMAND_CONFIG, .help = "CTI commands", .chain = cti_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/arm_dap.c b/src/target/arm_dap.c index 119e511..fbcfe0d 100644 --- a/src/target/arm_dap.c +++ b/src/target/arm_dap.c @@ -56,7 +56,7 @@ static void dap_instance_init(struct adiv5_dap *dap) /* Number of bits for tar autoincrement, impl. dep. at least 10 */ dap->ap[i].tar_autoincr_block = (1<<10); /* default CSW value */ - dap->ap[i].csw_default = CSW_DEFAULT; + dap->ap[i].csw_default = CSW_AHB_DEFAULT; } INIT_LIST_HEAD(&dap->cmd_journal); } @@ -331,7 +331,7 @@ COMMAND_HANDLER(handle_dap_info_command) return ERROR_COMMAND_SYNTAX_ERROR; } - return dap_info_command(CMD_CTX, &dap->ap[apsel]); + return dap_info_command(CMD, &dap->ap[apsel]); } static const struct command_registration dap_subcommand_handlers[] = { @@ -373,6 +373,7 @@ static const struct command_registration dap_commands[] = { .mode = COMMAND_CONFIG, .help = "DAP commands", .chain = dap_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/armv4_5.c b/src/target/armv4_5.c index e16a9ec..53a6b22 100644 --- a/src/target/armv4_5.c +++ b/src/target/armv4_5.c @@ -778,17 +778,17 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) struct reg *regs; if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "error: target must be halted for register accesses"); + command_print(CMD, "error: target must be halted for register accesses"); return ERROR_FAIL; } if (arm->core_type != ARM_MODE_ANY) { - command_print(CMD_CTX, + command_print(CMD, "Microcontroller Profile not supported - use standard reg cmd"); return ERROR_OK; } @@ -799,7 +799,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) } if (!arm->full_context) { - command_print(CMD_CTX, "error: target doesn't support %s", + command_print(CMD, "error: target doesn't support %s", CMD_NAME); return ERROR_FAIL; } @@ -828,7 +828,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) shadow = "shadow "; break; } - command_print(CMD_CTX, "%s%s mode %sregisters", + command_print(CMD, "%s%s mode %sregisters", sep, name, shadow); /* display N rows of up to 4 registers each */ @@ -855,7 +855,7 @@ COMMAND_HANDLER(handle_armv4_5_reg_command) "%8s: %8.8" PRIx32 " ", reg->name, value); } - command_print(CMD_CTX, "%s", output); + command_print(CMD, "%s", output); } } @@ -868,13 +868,13 @@ COMMAND_HANDLER(handle_armv4_5_core_state_command) struct arm *arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (arm->core_type == ARM_MODE_THREAD) { /* armv7m not supported */ - command_print(CMD_CTX, "Unsupported Command"); + command_print(CMD, "Unsupported Command"); return ERROR_OK; } @@ -885,7 +885,7 @@ COMMAND_HANDLER(handle_armv4_5_core_state_command) arm->core_state = ARM_STATE_THUMB; } - command_print(CMD_CTX, "core state: %s", arm_state_strings[arm->core_state]); + command_print(CMD, "core state: %s", arm_state_strings[arm->core_state]); return ERROR_OK; } @@ -906,7 +906,7 @@ COMMAND_HANDLER(handle_arm_disassemble_command) int thumb = 0; if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } @@ -928,7 +928,7 @@ COMMAND_HANDLER(handle_arm_disassemble_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); if (address & 0x01) { if (!thumb) { - command_print(CMD_CTX, "Disassemble as Thumb"); + command_print(CMD, "Disassemble as Thumb"); thumb = 1; } address &= ~1; @@ -963,7 +963,7 @@ usage: if (retval != ERROR_OK) break; } - command_print(CMD_CTX, "%s", cur_instruction.text); + command_print(CMD, "%s", cur_instruction.text); address += cur_instruction.instruction_size; } @@ -1140,28 +1140,28 @@ static const struct command_registration arm_exec_command_handlers[] = { .usage = "cpnum op1 CRn CRm op2", }, { - "semihosting", + .name = "semihosting", .handler = handle_common_semihosting_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting operations", }, { - "semihosting_cmdline", + .name = "semihosting_cmdline", .handler = handle_common_semihosting_cmdline, .mode = COMMAND_EXEC, .usage = "arguments", .help = "command line arguments to be passed to program", }, { - "semihosting_fileio", + .name = "semihosting_fileio", .handler = handle_common_semihosting_fileio_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting fileio operations", }, { - "semihosting_resexit", + .name = "semihosting_resexit", .handler = handle_common_semihosting_resumable_exit_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", diff --git a/src/target/armv4_5_cache.c b/src/target/armv4_5_cache.c index bd0091d..eda8cb7 100644 --- a/src/target/armv4_5_cache.c +++ b/src/target/armv4_5_cache.c @@ -76,23 +76,23 @@ int armv4_5_identify_cache(uint32_t cache_type_reg, struct armv4_5_cache_common return ERROR_OK; } -int armv4_5_handle_cache_info_command(struct command_context *cmd_ctx, struct armv4_5_cache_common *armv4_5_cache) +int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache) { if (armv4_5_cache->ctype == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } - command_print(cmd_ctx, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, + command_print(cmd, "cache type: 0x%1.1x, %s", armv4_5_cache->ctype, (armv4_5_cache->separate) ? "separate caches" : "unified cache"); - command_print(cmd_ctx, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd, "D-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->d_u_size.linelen, armv4_5_cache->d_u_size.associativity, armv4_5_cache->d_u_size.nsets, armv4_5_cache->d_u_size.cachesize); - command_print(cmd_ctx, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", + command_print(cmd, "I-Cache: linelen %i, associativity %i, nsets %i, cachesize 0x%x", armv4_5_cache->i_size.linelen, armv4_5_cache->i_size.associativity, armv4_5_cache->i_size.nsets, diff --git a/src/target/armv4_5_cache.h b/src/target/armv4_5_cache.h index 2fd1ca3..768938f 100644 --- a/src/target/armv4_5_cache.h +++ b/src/target/armv4_5_cache.h @@ -19,7 +19,7 @@ #ifndef OPENOCD_TARGET_ARMV4_5_CACHE_H #define OPENOCD_TARGET_ARMV4_5_CACHE_H -struct command_context; +struct command_invocation; struct armv4_5_cachesize { int linelen; @@ -42,7 +42,7 @@ int armv4_5_identify_cache(uint32_t cache_type_reg, int armv4_5_cache_state(uint32_t cp15_control_reg, struct armv4_5_cache_common *cache); -int armv4_5_handle_cache_info_command(struct command_context *cmd_ctx, +int armv4_5_handle_cache_info_command(struct command_invocation *cmd, struct armv4_5_cache_common *armv4_5_cache); enum { diff --git a/src/target/armv7a.c b/src/target/armv7a.c index f9594c9..2be70b7 100644 --- a/src/target/armv7a.c +++ b/src/target/armv7a.c @@ -229,7 +229,7 @@ COMMAND_HANDLER(handle_cache_l2x) if (CMD_ARGC != 2) return ERROR_COMMAND_SYNTAX_ERROR; - /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ + /* command_print(CMD, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way); @@ -239,7 +239,7 @@ COMMAND_HANDLER(handle_cache_l2x) return ERROR_OK; } -int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, +int armv7a_handle_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache) { struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *) @@ -248,7 +248,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, int cl; if (armv7a_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } @@ -256,7 +256,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, struct armv7a_arch_cache *arch = &(armv7a_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd_ctx, + command_print(cmd, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -269,7 +269,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, } if (arch->ctype >= 2) { - command_print(cmd_ctx, + command_print(cmd, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -283,7 +283,7 @@ int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, } if (l2x_cache != NULL) - command_print(cmd_ctx, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", + command_print(cmd, "Outer unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); return ERROR_OK; @@ -307,23 +307,21 @@ static int armv7a_read_mpidr(struct target *target) if (retval != ERROR_OK) goto done; - /* ARMv7R uses a different format for MPIDR. - * When configured uniprocessor (most R cores) it reads as 0. - * This will need to be implemented for multiprocessor ARMv7R cores. */ - if (armv7a->is_armv7r) { - if (mpidr) - LOG_ERROR("MPIDR nonzero in ARMv7-R target"); - goto done; - } - - if (mpidr & 1<<31) { + /* Is register in Multiprocessing Extensions register format? */ + if (mpidr & MPIDR_MP_EXT) { + LOG_DEBUG("%s: MPIDR 0x%" PRIx32, target_name(target), mpidr); armv7a->multi_processor_system = (mpidr >> 30) & 1; + armv7a->multi_threading_processor = (mpidr >> 24) & 1; + armv7a->level2_id = (mpidr >> 16) & 0xf; armv7a->cluster_id = (mpidr >> 8) & 0xf; - armv7a->cpu_id = mpidr & 0x3; - LOG_INFO("%s cluster %x core %x %s", target_name(target), + armv7a->cpu_id = mpidr & 0xf; + LOG_INFO("%s: MPIDR level2 %x, cluster %x, core %x, %s, %s", + target_name(target), + armv7a->level2_id, armv7a->cluster_id, armv7a->cpu_id, - armv7a->multi_processor_system == 0 ? "multi core" : "mono core"); + armv7a->multi_processor_system == 0 ? "multi core" : "mono core", + armv7a->multi_threading_processor == 1 ? "SMT" : "no SMT"); } else LOG_ERROR("MPIDR not in multiprocessor format"); @@ -584,8 +582,7 @@ static const struct command_registration l2_cache_commands[] = { .name = "l2x", .handler = handle_cache_l2x, .mode = COMMAND_EXEC, - .help = "configure l2x cache " - "", + .help = "configure l2x cache", .usage = "[base_addr] [number_of_way]", }, COMMAND_REGISTRATION_DONE diff --git a/src/target/armv7a.h b/src/target/armv7a.h index 1e88c98..0ef04c1 100644 --- a/src/target/armv7a.h +++ b/src/target/armv7a.h @@ -108,6 +108,8 @@ struct armv7a_common { struct adiv5_ap *debug_ap; /* mdir */ uint8_t multi_processor_system; + uint8_t multi_threading_processor; + uint8_t level2_id; uint8_t cluster_id; uint8_t cpu_id; bool is_armv7r; @@ -183,11 +185,14 @@ static inline bool is_armv7a(struct armv7a_common *armv7a) #define DBG_VCR_PREF_ABORT_MASK ((1 << 27) | (1 << 3)) #define DBG_VCR_SVC_MASK ((1 << 26) | (1 << 2)) +/* Masks for Multiprocessor Affinity Register */ +#define MPIDR_MP_EXT (1UL << 31) + int armv7a_arch_state(struct target *target); int armv7a_identify_cache(struct target *target); int armv7a_init_arch_info(struct target *target, struct armv7a_common *armv7a); -int armv7a_handle_cache_info_command(struct command_context *cmd_ctx, +int armv7a_handle_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache); int armv7a_read_ttbcr(struct target *target); diff --git a/src/target/armv7a_cache.c b/src/target/armv7a_cache.c index 7435aab..921ba9b 100644 --- a/src/target/armv7a_cache.c +++ b/src/target/armv7a_cache.c @@ -431,7 +431,7 @@ COMMAND_HANDLER(arm7a_l1_cache_info_cmd) struct target *target = get_current_target(CMD_CTX); struct armv7a_common *armv7a = target_to_armv7a(target); - return armv7a_handle_cache_info_command(CMD_CTX, + return armv7a_handle_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } @@ -513,7 +513,7 @@ COMMAND_HANDLER(arm7a_cache_disable_auto_cmd) struct armv7a_common *armv7a = target_to_armv7a(target); if (CMD_ARGC == 0) { - command_print(CMD_CTX, "auto cache is %s", + command_print(CMD, "auto cache is %s", armv7a->armv7a_mmu.armv7a_cache.auto_cache_enabled ? "enabled" : "disabled"); return ERROR_OK; } diff --git a/src/target/armv7a_cache_l2x.c b/src/target/armv7a_cache_l2x.c index e181f26..72e12b4 100644 --- a/src/target/armv7a_cache_l2x.c +++ b/src/target/armv7a_cache_l2x.c @@ -173,18 +173,18 @@ done: return retval; } -static int arm7a_handle_l2x_cache_info_command(struct command_context *cmd_ctx, +static int arm7a_handle_l2x_cache_info_command(struct command_invocation *cmd, struct armv7a_cache_common *armv7a_cache) { struct armv7a_l2x_cache *l2x_cache = (struct armv7a_l2x_cache *) (armv7a_cache->outer_cache); if (armv7a_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } - command_print(cmd_ctx, + command_print(cmd, "L2 unified cache Base Address 0x%" PRIx32 ", %" PRId32 " ways", l2x_cache->base, l2x_cache->way); @@ -235,7 +235,7 @@ COMMAND_HANDLER(arm7a_l2x_cache_info_command) if (retval) return retval; - return arm7a_handle_l2x_cache_info_command(CMD_CTX, + return arm7a_handle_l2x_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } @@ -312,7 +312,7 @@ COMMAND_HANDLER(armv7a_l2x_cache_conf_cmd) if (CMD_ARGC != 2) return ERROR_COMMAND_SYNTAX_ERROR; - /* command_print(CMD_CTX, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ + /* command_print(CMD, "%s %s", CMD_ARGV[0], CMD_ARGV[1]); */ COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], base); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], way); diff --git a/src/target/armv7a_mmu.c b/src/target/armv7a_mmu.c index 153bfcc..f83228d 100644 --- a/src/target/armv7a_mmu.c +++ b/src/target/armv7a_mmu.c @@ -34,101 +34,15 @@ #define SCTLR_BIT_AFE (1 << 29) -/* method adapted to Cortex-A : reused ARM v4 v5 method */ -int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val) -{ - uint32_t first_lvl_descriptor = 0x0; - uint32_t second_lvl_descriptor = 0x0; - int retval; - struct armv7a_common *armv7a = target_to_armv7a(target); - uint32_t ttbidx = 0; /* default to ttbr0 */ - uint32_t ttb_mask; - uint32_t va_mask; - uint32_t ttb; - - if (target->state != TARGET_HALTED) - LOG_INFO("target not halted, using cached values for translation table!"); - - /* if va is above the range handled by ttbr0, select ttbr1 */ - if (va > armv7a->armv7a_mmu.ttbr_range[0]) { - /* select ttb 1 */ - ttbidx = 1; - } - - ttb = armv7a->armv7a_mmu.ttbr[ttbidx]; - ttb_mask = armv7a->armv7a_mmu.ttbr_mask[ttbidx]; - va_mask = 0xfff00000 & armv7a->armv7a_mmu.ttbr_range[ttbidx]; - - LOG_DEBUG("ttb_mask %" PRIx32 " va_mask %" PRIx32 " ttbidx %i", - ttb_mask, va_mask, ttbidx); - retval = armv7a->armv7a_mmu.read_physical_memory(target, - (ttb & ttb_mask) | ((va & va_mask) >> 18), - 4, 1, (uint8_t *)&first_lvl_descriptor); - if (retval != ERROR_OK) - return retval; - first_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *) - &first_lvl_descriptor); - /* reuse armv4_5 piece of code, specific armv7a changes may come later */ - LOG_DEBUG("1st lvl desc: %8.8" PRIx32 "", first_lvl_descriptor); - - if ((first_lvl_descriptor & 0x3) == 0) { - /* Avoid LOG_ERROR, probably GDB is guessing the stack frame */ - LOG_WARNING("Address translation failure [1]: va %8.8" PRIx32 "", va); - return ERROR_TARGET_TRANSLATION_FAULT; - } - - if ((first_lvl_descriptor & 0x40002) == 2) { - /* section descriptor */ - *val = (first_lvl_descriptor & 0xfff00000) | (va & 0x000fffff); - return ERROR_OK; - } else if ((first_lvl_descriptor & 0x40002) == 0x40002) { - /* supersection descriptor */ - if (first_lvl_descriptor & 0x00f001e0) { - LOG_ERROR("Physical address does not fit into 32 bits"); - return ERROR_TARGET_TRANSLATION_FAULT; - } - *val = (first_lvl_descriptor & 0xff000000) | (va & 0x00ffffff); - return ERROR_OK; - } - - /* page table */ - retval = armv7a->armv7a_mmu.read_physical_memory(target, - (first_lvl_descriptor & 0xfffffc00) | ((va & 0x000ff000) >> 10), - 4, 1, (uint8_t *)&second_lvl_descriptor); - if (retval != ERROR_OK) - return retval; - - second_lvl_descriptor = target_buffer_get_u32(target, (uint8_t *) - &second_lvl_descriptor); - - LOG_DEBUG("2nd lvl desc: %8.8" PRIx32 "", second_lvl_descriptor); - - if ((second_lvl_descriptor & 0x3) == 0) { - /* Avoid LOG_ERROR, probably GDB is guessing the stack frame */ - LOG_WARNING("Address translation failure [2]: va %8.8" PRIx32 "", va); - return ERROR_TARGET_TRANSLATION_FAULT; - } - - if ((second_lvl_descriptor & 0x3) == 1) { - /* large page descriptor */ - *val = (second_lvl_descriptor & 0xffff0000) | (va & 0x0000ffff); - } else { - /* small page descriptor */ - *val = (second_lvl_descriptor & 0xfffff000) | (va & 0x00000fff); - } - - return ERROR_OK; -} - /* V7 method VA TO PA */ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, - uint32_t *val, int meminfo) + target_addr_t *val, int meminfo) { int retval = ERROR_FAIL; struct armv7a_common *armv7a = target_to_armv7a(target); struct arm_dpm *dpm = armv7a->arm.dpm; - uint32_t virt = va & ~0xfff; - uint32_t NOS, NS, INNER, OUTER; + uint32_t virt = va & ~0xfff, value; + uint32_t NOS, NS, INNER, OUTER, SS; *val = 0xdeadbeef; retval = dpm->prepare(dpm); if (retval != ERROR_OK) @@ -142,21 +56,39 @@ int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, goto done; retval = dpm->instr_read_data_r0(dpm, ARMV4_5_MRC(15, 0, 0, 7, 4, 0), - val); - /* decode memory attribute */ - NOS = (*val >> 10) & 1; /* Not Outer shareable */ - NS = (*val >> 9) & 1; /* Non secure */ - INNER = (*val >> 4) & 0x7; - OUTER = (*val >> 2) & 0x3; - + &value); if (retval != ERROR_OK) goto done; - *val = (*val & ~0xfff) + (va & 0xfff); + + /* decode memory attribute */ + SS = (value >> 1) & 1; +#if !BUILD_TARGET64 + if (SS) { + LOG_ERROR("Super section found with no-64 bit address support"); + return ERROR_FAIL; + } +#endif + NOS = (value >> 10) & 1; /* Not Outer shareable */ + NS = (value >> 9) & 1; /* Non secure */ + INNER = (value >> 4) & 0x7; + OUTER = (value >> 2) & 0x3; + + if (SS) { + /* PAR[31:24] contains PA[31:24] */ + *val = value & 0xff000000; + /* PAR [23:16] contains PA[39:32] */ + *val |= (target_addr_t)(value & 0x00ff0000) << 16; + /* PA[23:12] is the same as VA[23:12] */ + *val |= (va & 0xffffff); + } else { + *val = (value & ~0xfff) + (va & 0xfff); + } if (meminfo) { - LOG_INFO("%" PRIx32 " : %" PRIx32 " %s outer shareable %s secured", + LOG_INFO("%" PRIx32 " : %" TARGET_PRIxADDR " %s outer shareable %s secured %s super section", va, *val, NOS == 1 ? "not" : " ", - NS == 1 ? "not" : ""); + NS == 1 ? "not" : "", + SS == 0 ? "not" : ""); switch (OUTER) { case 0: LOG_INFO("outer: Non-Cacheable"); diff --git a/src/target/armv7a_mmu.h b/src/target/armv7a_mmu.h index 4372aa8..36cd9d1 100644 --- a/src/target/armv7a_mmu.h +++ b/src/target/armv7a_mmu.h @@ -19,9 +19,8 @@ #ifndef OPENOCD_TARGET_ARMV7A_MMU_H #define OPENOCD_TARGET_ARMV7A_MMU_H -extern int armv7a_mmu_translate_va(struct target *target, uint32_t va, uint32_t *val); extern int armv7a_mmu_translate_va_pa(struct target *target, uint32_t va, - uint32_t *val, int meminfo); + target_addr_t *val, int meminfo); extern const struct command_registration armv7a_mmu_command_handlers[]; diff --git a/src/target/armv7m.c b/src/target/armv7m.c index 3d73b29..4b37774 100644 --- a/src/target/armv7m.c +++ b/src/target/armv7m.c @@ -191,7 +191,7 @@ static int armv7m_get_core_reg(struct reg *reg) if (target->state != TARGET_HALTED) return ERROR_TARGET_NOT_HALTED; - retval = arm->read_core_reg(target, reg, armv7m_reg->num, arm->core_mode); + retval = arm->read_core_reg(target, reg, reg->number, arm->core_mode); return retval; } diff --git a/src/target/armv8.c b/src/target/armv8.c index c8cfcae..e736937 100644 --- a/src/target/armv8.c +++ b/src/target/armv8.c @@ -646,7 +646,7 @@ int armv8_read_mpidr(struct armv8_common *armv8) retval = dpm->instr_read_data_r0(dpm, armv8_opcode(armv8, READ_REG_MPIDR), &mpidr); if (retval != ERROR_OK) goto done; - if (mpidr & 1<<31) { + if (mpidr & 1U<<31) { armv8->multi_processor_system = (mpidr >> 30) & 1; armv8->cluster_id = (mpidr >> 8) & 0xf; armv8->cpu_id = mpidr & 0x3; @@ -1054,7 +1054,7 @@ COMMAND_HANDLER(armv8_handle_exception_catch_command) return ERROR_FAIL; } - command_print(CMD_CTX, "Exception Catch: Secure: %s, Non-Secure: %s", sec, nsec); + command_print(CMD, "Exception Catch: Secure: %s, Non-Secure: %s", sec, nsec); return ERROR_OK; } @@ -1079,16 +1079,16 @@ COMMAND_HANDLER(armv8_handle_exception_catch_command) return ERROR_OK; } -int armv8_handle_cache_info_command(struct command_context *cmd_ctx, +int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache) { if (armv8_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } if (armv8_cache->display_cache_info) - armv8_cache->display_cache_info(cmd_ctx, armv8_cache); + armv8_cache->display_cache_info(cmd, armv8_cache); return ERROR_OK; } diff --git a/src/target/armv8.h b/src/target/armv8.h index af00e52..1a61145 100644 --- a/src/target/armv8.h +++ b/src/target/armv8.h @@ -170,7 +170,7 @@ struct armv8_cache_common { /* l2 external unified cache if some */ void *l2_cache; int (*flush_all_data_cache)(struct target *target); - int (*display_cache_info)(struct command_context *cmd_ctx, + int (*display_cache_info)(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache); }; @@ -301,7 +301,7 @@ int armv8_mmu_translate_va_pa(struct target *target, target_addr_t va, target_addr_t *val, int meminfo); int armv8_mmu_translate_va(struct target *target, target_addr_t va, target_addr_t *val); -int armv8_handle_cache_info_command(struct command_context *cmd_ctx, +int armv8_handle_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache); void armv8_set_cpsr(struct arm *arm, uint32_t cpsr); diff --git a/src/target/armv8_cache.c b/src/target/armv8_cache.c index 40965eb..41c85c9 100644 --- a/src/target/armv8_cache.c +++ b/src/target/armv8_cache.c @@ -188,13 +188,13 @@ done: return retval; } -static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx, +static int armv8_handle_inner_cache_info_command(struct command_invocation *cmd, struct armv8_cache_common *armv8_cache) { int cl; if (armv8_cache->info == -1) { - command_print(cmd_ctx, "cache not yet identified"); + command_print(cmd, "cache not yet identified"); return ERROR_OK; } @@ -202,7 +202,7 @@ static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx struct armv8_arch_cache *arch = &(armv8_cache->arch[cl]); if (arch->ctype & 1) { - command_print(cmd_ctx, + command_print(cmd, "L%d I-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 @@ -215,7 +215,7 @@ static int armv8_handle_inner_cache_info_command(struct command_context *cmd_ctx } if (arch->ctype >= 2) { - command_print(cmd_ctx, + command_print(cmd, "L%d D-Cache: linelen %" PRIi32 ", associativity %" PRIi32 ", nsets %" PRIi32 diff --git a/src/target/cortex_a.c b/src/target/cortex_a.c index 6eb6aa9..b3a8a41 100644 --- a/src/target/cortex_a.c +++ b/src/target/cortex_a.c @@ -55,6 +55,7 @@ #include "target_type.h" #include "arm_opcodes.h" #include "arm_semihosting.h" +#include "jtag/interface.h" #include "transport/transport.h" #include "smp.h" #include <helper/time_support.h> @@ -70,6 +71,8 @@ static int cortex_a_set_hybrid_breakpoint(struct target *target, struct breakpoint *breakpoint); static int cortex_a_unset_breakpoint(struct target *target, struct breakpoint *breakpoint); +static int cortex_a_wait_dscr_bits(struct target *target, uint32_t mask, + uint32_t value, uint32_t *dscr); static int cortex_a_mmu(struct target *target, int *enabled); static int cortex_a_mmu_modify(struct target *target, int enable); static int cortex_a_virt2phys(struct target *target, @@ -250,21 +253,21 @@ static int cortex_a_wait_instrcmpl(struct target *target, uint32_t *dscr, bool f * Writes final value of DSCR into *dscr. Pass force to force always * reading DSCR at least once. */ struct armv7a_common *armv7a = target_to_armv7a(target); - int64_t then = timeval_ms(); - while ((*dscr & DSCR_INSTR_COMP) == 0 || force) { - force = false; - int retval = mem_ap_read_atomic_u32(armv7a->debug_ap, + int retval; + + if (force) { + retval = mem_ap_read_atomic_u32(armv7a->debug_ap, armv7a->debug_base + CPUDBG_DSCR, dscr); if (retval != ERROR_OK) { LOG_ERROR("Could not read DSCR register"); return retval; } - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for InstrCompl=1"); - return ERROR_FAIL; - } } - return ERROR_OK; + + retval = cortex_a_wait_dscr_bits(target, DSCR_INSTR_COMP, DSCR_INSTR_COMP, dscr); + if (retval != ERROR_OK) + LOG_ERROR("Error waiting for InstrCompl=1"); + return retval; } /* To reduce needless round-trips, pass in a pointer to the current @@ -293,19 +296,12 @@ static int cortex_a_exec_opcode(struct target *target, if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - do { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) { - LOG_ERROR("Could not read DSCR register"); - return retval; - } - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for cortex_a_exec_opcode"); - return ERROR_FAIL; - } - } while ((dscr & DSCR_INSTR_COMP) == 0); /* Wait for InstrCompl bit to be set */ + /* Wait for InstrCompl bit to be set */ + retval = cortex_a_wait_instrcmpl(target, &dscr, true); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for cortex_a_exec_opcode"); + return retval; + } if (dscr_p) *dscr_p = dscr; @@ -359,17 +355,11 @@ static int cortex_a_read_dcc(struct cortex_a_common *a, uint32_t *data, dscr = *dscr_p; /* Wait for DTRRXfull */ - int64_t then = timeval_ms(); - while ((dscr & DSCR_DTR_TX_FULL) == 0) { - retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, - a->armv7a_common.debug_base + CPUDBG_DSCR, - &dscr); - if (retval != ERROR_OK) - return retval; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for read dcc"); - return ERROR_FAIL; - } + retval = cortex_a_wait_dscr_bits(a->armv7a_common.arm.target, + DSCR_DTR_TX_FULL, DSCR_DTR_TX_FULL, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for read dcc"); + return retval; } retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, @@ -391,19 +381,10 @@ static int cortex_a_dpm_prepare(struct arm_dpm *dpm) int retval; /* set up invariant: INSTR_COMP is set after ever DPM operation */ - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(a->armv7a_common.debug_ap, - a->armv7a_common.debug_base + CPUDBG_DSCR, - &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_INSTR_COMP) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for dpm prepare"); - return ERROR_FAIL; - } + retval = cortex_a_wait_instrcmpl(dpm->arm->target, &dscr, true); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for dpm prepare"); + return retval; } /* this "should never happen" ... */ @@ -752,7 +733,7 @@ static int cortex_a_poll(struct target *target) static int cortex_a_halt(struct target *target) { - int retval = ERROR_OK; + int retval; uint32_t dscr; struct armv7a_common *armv7a = target_to_armv7a(target); @@ -765,18 +746,12 @@ static int cortex_a_halt(struct target *target) if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_CORE_HALTED) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for halt"); - return ERROR_FAIL; - } + dscr = 0; /* force read of dscr */ + retval = cortex_a_wait_dscr_bits(target, DSCR_CORE_HALTED, + DSCR_CORE_HALTED, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for halt"); + return retval; } target->debug_reason = DBG_REASON_DBGRQ; @@ -915,18 +890,12 @@ static int cortex_a_internal_restart(struct target *target) if (retval != ERROR_OK) return retval; - int64_t then = timeval_ms(); - for (;; ) { - retval = mem_ap_read_atomic_u32(armv7a->debug_ap, - armv7a->debug_base + CPUDBG_DSCR, &dscr); - if (retval != ERROR_OK) - return retval; - if ((dscr & DSCR_CORE_RESTARTED) != 0) - break; - if (timeval_ms() > then + 1000) { - LOG_ERROR("Timeout waiting for resume"); - return ERROR_FAIL; - } + dscr = 0; /* force read of dscr */ + retval = cortex_a_wait_dscr_bits(target, DSCR_CORE_RESTARTED, + DSCR_CORE_RESTARTED, &dscr); + if (retval != ERROR_OK) { + LOG_ERROR("Error waiting for resume"); + return retval; } target->debug_reason = DBG_REASON_NOTHALTED; @@ -1206,6 +1175,8 @@ static int cortex_a_step(struct target *target, int current, target_addr_t addre retval = cortex_a_poll(target); if (retval != ERROR_OK) return retval; + if (target->state == TARGET_HALTED) + break; if (timeval_ms() > then + 1000) { LOG_ERROR("timeout waiting for target halt"); return ERROR_FAIL; @@ -1689,7 +1660,7 @@ static int cortex_a_assert_reset(struct target *target) */ if (transport_is_swd() || (target->reset_halt && (jtag_get_reset_config() & RESET_SRST_NO_GATING))) - jtag_add_reset(0, 1); + adapter_assert_reset(); } else { LOG_ERROR("%s: how to reset?", target_name(target)); @@ -1712,7 +1683,7 @@ static int cortex_a_deassert_reset(struct target *target) LOG_DEBUG(" "); /* be certain SRST is off */ - jtag_add_reset(0, 0); + adapter_deassert_reset(); if (target_was_examined(target)) { retval = cortex_a_poll(target); @@ -1763,14 +1734,22 @@ static int cortex_a_wait_dscr_bits(struct target *target, uint32_t mask, { /* Waits until the specified bit(s) of DSCR take on a specified value. */ struct armv7a_common *armv7a = target_to_armv7a(target); - int64_t then = timeval_ms(); + int64_t then; int retval; - while ((*dscr & mask) != value) { + if ((*dscr & mask) == value) + return ERROR_OK; + + then = timeval_ms(); + while (1) { retval = mem_ap_read_atomic_u32(armv7a->debug_ap, armv7a->debug_base + CPUDBG_DSCR, dscr); - if (retval != ERROR_OK) + if (retval != ERROR_OK) { + LOG_ERROR("Could not read DSCR register"); return retval; + } + if ((*dscr & mask) == value) + break; if (timeval_ms() > then + 1000) { LOG_ERROR("timeout waiting for DSCR bit change"); return ERROR_FAIL; @@ -2944,7 +2923,7 @@ static int cortex_a_virt2phys(struct target *target, if (retval != ERROR_OK) return retval; return armv7a_mmu_translate_va_pa(target, (uint32_t)virt, - (uint32_t *)phys, 1); + phys, 1); } COMMAND_HANDLER(cortex_a_handle_cache_info_command) @@ -2952,7 +2931,7 @@ COMMAND_HANDLER(cortex_a_handle_cache_info_command) struct target *target = get_current_target(CMD_CTX); struct armv7a_common *armv7a = target_to_armv7a(target); - return armv7a_handle_cache_info_command(CMD_CTX, + return armv7a_handle_cache_info_command(CMD, &armv7a->armv7a_mmu.armv7a_cache); } @@ -2991,7 +2970,7 @@ COMMAND_HANDLER(handle_cortex_a_mask_interrupts_command) } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_a->isrmasking_mode); - command_print(CMD_CTX, "cortex_a interrupt mask %s", n->name); + command_print(CMD, "cortex_a interrupt mask %s", n->name); return ERROR_OK; } @@ -3017,7 +2996,7 @@ COMMAND_HANDLER(handle_cortex_a_dacrfixup_command) } n = Jim_Nvp_value2name_simple(nvp_dacrfixup_modes, cortex_a->dacrfixup_mode); - command_print(CMD_CTX, "cortex_a domain access control fixup %s", n->name); + command_print(CMD, "cortex_a domain access control fixup %s", n->name); return ERROR_OK; } diff --git a/src/target/cortex_m.c b/src/target/cortex_m.c index d341d45..7f59401 100644 --- a/src/target/cortex_m.c +++ b/src/target/cortex_m.c @@ -136,6 +136,83 @@ static int cortex_m_write_debug_halt_mask(struct target *target, return mem_ap_write_atomic_u32(armv7m->debug_ap, DCB_DHCSR, cortex_m->dcb_dhcsr); } +static int cortex_m_set_maskints(struct target *target, bool mask) +{ + struct cortex_m_common *cortex_m = target_to_cm(target); + if (!!(cortex_m->dcb_dhcsr & C_MASKINTS) != mask) + return cortex_m_write_debug_halt_mask(target, mask ? C_MASKINTS : 0, mask ? 0 : C_MASKINTS); + else + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_halt(struct target *target) +{ + struct cortex_m_common *cortex_m = target_to_cm(target); + switch (cortex_m->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* interrupts taken at resume, whether for step or run -> no mask */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> mask now if MASKINTS + * erratum, otherwise only mask before stepping */ + return cortex_m_set_maskints(target, cortex_m->maskints_erratum); + } + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_run(struct target *target) +{ + switch (target_to_cm(target)->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* interrupts taken at resume, whether for step or run -> no mask */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> no mask */ + return cortex_m_set_maskints(target, false); + } + return ERROR_OK; +} + +static int cortex_m_set_maskints_for_step(struct target *target) +{ + switch (target_to_cm(target)->isrmasking_mode) { + case CORTEX_M_ISRMASK_AUTO: + /* the auto-interrupt should already be done -> mask */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_OFF: + /* interrupts never masked */ + return cortex_m_set_maskints(target, false); + + case CORTEX_M_ISRMASK_ON: + /* interrupts always masked */ + return cortex_m_set_maskints(target, true); + + case CORTEX_M_ISRMASK_STEPONLY: + /* interrupts masked for single step only -> mask */ + return cortex_m_set_maskints(target, true); + } + return ERROR_OK; +} + static int cortex_m_clear_halt(struct target *target) { struct cortex_m_common *cortex_m = target_to_cm(target); @@ -237,11 +314,8 @@ static int cortex_m_endreset_event(struct target *target) return retval; } - /* Restore proper interrupt masking setting. */ - if (cortex_m->isrmasking_mode == CORTEX_M_ISRMASK_ON) - cortex_m_write_debug_halt_mask(target, C_MASKINTS, 0); - else - cortex_m_write_debug_halt_mask(target, 0, C_MASKINTS); + /* Restore proper interrupt masking setting for running CPU. */ + cortex_m_set_maskints_for_run(target); /* Enable features controlled by ITM and DWT blocks, and catch only * the vectors we were told to pay attention to. @@ -318,7 +392,9 @@ static int cortex_m_examine_debug_reason(struct target *target) target->debug_reason = DBG_REASON_WATCHPOINT; else if (cortex_m->nvic_dfsr & DFSR_VCATCH) target->debug_reason = DBG_REASON_BREAKPOINT; - else /* EXTERNAL, HALTED */ + else if (cortex_m->nvic_dfsr & DFSR_EXTERNAL) + target->debug_reason = DBG_REASON_DBGRQ; + else /* HALTED */ target->debug_reason = DBG_REASON_UNDEFINED; } @@ -405,6 +481,10 @@ static int cortex_m_debug_entry(struct target *target) LOG_DEBUG(" "); + /* Do this really early to minimize the window where the MASKINTS erratum + * can pile up pending interrupts. */ + cortex_m_set_maskints_for_halt(target); + cortex_m_clear_halt(target); retval = mem_ap_read_atomic_u32(armv7m->debug_ap, DCB_DHCSR, &cortex_m->dcb_dhcsr); if (retval != ERROR_OK) @@ -614,6 +694,10 @@ static int cortex_m_halt(struct target *target) /* Write to Debug Halting Control and Status Register */ cortex_m_write_debug_halt_mask(target, C_HALT, 0); + /* Do this really early to minimize the window where the MASKINTS erratum + * can pile up pending interrupts. */ + cortex_m_set_maskints_for_halt(target); + target->debug_reason = DBG_REASON_DBGRQ; return ERROR_OK; @@ -632,6 +716,11 @@ static int cortex_m_soft_reset_halt(struct target *target) * core, not the peripherals */ LOG_WARNING("soft_reset_halt is deprecated, please use 'reset halt' instead."); + /* Set C_DEBUGEN */ + retval = cortex_m_write_debug_halt_mask(target, 0, C_STEP | C_MASKINTS); + if (retval != ERROR_OK) + return retval; + /* Enter debug state on reset; restore DEMCR in endreset_event() */ retval = mem_ap_write_u32(armv7m->debug_ap, DCB_DEMCR, TRCENA | VC_HARDERR | VC_BUSERR | VC_CORERESET); @@ -767,6 +856,7 @@ static int cortex_m_resume(struct target *target, int current, } /* Restart core */ + cortex_m_set_maskints_for_run(target); cortex_m_write_debug_halt_mask(target, 0, C_HALT); target->debug_reason = DBG_REASON_NOTHALTED; @@ -829,10 +919,12 @@ static int cortex_m_step(struct target *target, int current, * a normal step, otherwise we have to manually step over the bkpt * instruction - as such simulate a step */ if (bkpt_inst_found == false) { - /* Automatic ISR masking mode off: Just step over the next instruction */ - if ((cortex_m->isrmasking_mode != CORTEX_M_ISRMASK_AUTO)) + if ((cortex_m->isrmasking_mode != CORTEX_M_ISRMASK_AUTO)) { + /* Automatic ISR masking mode off: Just step over the next + * instruction, with interrupts on or off as appropriate. */ + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - else { + } else { /* Process interrupts during stepping in a way they don't interfere * debugging. * @@ -871,8 +963,9 @@ static int cortex_m_step(struct target *target, int current, LOG_DEBUG("Stepping over next instruction with interrupts disabled"); cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - /* Re-enable interrupts */ - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); } else { @@ -891,12 +984,17 @@ static int cortex_m_step(struct target *target, int current, bool tmp_bp_set = (retval == ERROR_OK); /* No more breakpoints left, just do a step */ - if (!tmp_bp_set) + if (!tmp_bp_set) { + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - else { + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); + } else { /* Start the core */ LOG_DEBUG("Starting core to serve pending interrupts"); int64_t t_start = timeval_ms(); + cortex_m_set_maskints_for_run(target); cortex_m_write_debug_halt_mask(target, 0, C_HALT | C_STEP); /* Wait for pending handlers to complete or timeout */ @@ -924,12 +1022,14 @@ static int cortex_m_step(struct target *target, int current, "leaving target running"); } else { /* Step over next instruction with interrupts disabled */ + cortex_m_set_maskints_for_step(target); cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); cortex_m_write_debug_halt_mask(target, C_STEP, C_HALT); - /* Re-enable interrupts */ - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + /* Re-enable interrupts if appropriate */ + cortex_m_write_debug_halt_mask(target, C_HALT, 0); + cortex_m_set_maskints_for_halt(target); } } } @@ -1031,8 +1131,7 @@ static int cortex_m_assert_reset(struct target *target) if (!target->reset_halt) { /* Set/Clear C_MASKINTS in a separate operation */ - if (cortex_m->dcb_dhcsr & C_MASKINTS) - cortex_m_write_debug_halt_mask(target, 0, C_MASKINTS); + cortex_m_set_maskints_for_run(target); /* clear any debug flags before resuming */ cortex_m_clear_halt(target); @@ -1104,7 +1203,7 @@ static int cortex_m_assert_reset(struct target *target) } target->state = TARGET_RESET; - jtag_add_sleep(50000); + jtag_sleep(50000); register_cache_invalidate(cortex_m->armv7m.arm.core_cache); @@ -1297,18 +1396,8 @@ int cortex_m_remove_breakpoint(struct target *target, struct breakpoint *breakpo int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint) { int dwt_num = 0; - uint32_t mask, temp; struct cortex_m_common *cortex_m = target_to_cm(target); - /* watchpoint params were validated earlier */ - mask = 0; - temp = watchpoint->length; - while (temp) { - temp >>= 1; - mask++; - } - mask--; - /* REVISIT Don't fully trust these "not used" records ... users * may set up breakpoints by hand, e.g. dual-address data value * watchpoint using comparator #1; comparator #0 matching cycle @@ -1331,11 +1420,22 @@ int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint target_write_u32(target, comparator->dwt_comparator_address + 0, comparator->comp); - comparator->mask = mask; - target_write_u32(target, comparator->dwt_comparator_address + 4, - comparator->mask); + if ((cortex_m->dwt_devarch & 0x1FFFFF) != DWT_DEVARCH_ARMV8M) { + uint32_t mask = 0, temp; + + /* watchpoint params were validated earlier */ + temp = watchpoint->length; + while (temp) { + temp >>= 1; + mask++; + } + mask--; + + comparator->mask = mask; + target_write_u32(target, comparator->dwt_comparator_address + 4, + comparator->mask); - switch (watchpoint->rw) { + switch (watchpoint->rw) { case WPT_READ: comparator->function = 5; break; @@ -1345,7 +1445,26 @@ int cortex_m_set_watchpoint(struct target *target, struct watchpoint *watchpoint case WPT_ACCESS: comparator->function = 7; break; + } + } else { + uint32_t data_size = watchpoint->length >> 1; + comparator->mask = (watchpoint->length >> 1) | 1; + + switch (watchpoint->rw) { + case WPT_ACCESS: + comparator->function = 4; + break; + case WPT_WRITE: + comparator->function = 5; + break; + case WPT_READ: + comparator->function = 6; + break; + } + comparator->function = comparator->function | (1 << 4) | + (data_size << 10); } + target_write_u32(target, comparator->dwt_comparator_address + 8, comparator->function); @@ -1888,6 +2007,9 @@ void cortex_m_dwt_setup(struct cortex_m_common *cm, struct target *target) return; } + target_read_u32(target, DWT_DEVARCH, &cm->dwt_devarch); + LOG_DEBUG("DWT_DEVARCH: 0x%" PRIx32, cm->dwt_devarch); + cm->dwt_num_comp = (dwtcr >> 28) & 0xF; cm->dwt_comp_available = cm->dwt_num_comp; cm->dwt_comparator_list = calloc(cm->dwt_num_comp, @@ -1976,6 +2098,15 @@ static void cortex_m_dwt_free(struct target *target) #define MVFR1_DEFAULT_M7_SP 0x11000011 #define MVFR1_DEFAULT_M7_DP 0x12000011 +static int cortex_m_find_mem_ap(struct adiv5_dap *swjdp, + struct adiv5_ap **debug_ap) +{ + if (dap_find_ap(swjdp, AP_TYPE_AHB3_AP, debug_ap) == ERROR_OK) + return ERROR_OK; + + return dap_find_ap(swjdp, AP_TYPE_AHB5_AP, debug_ap); +} + int cortex_m_examine(struct target *target) { int retval; @@ -1990,7 +2121,7 @@ int cortex_m_examine(struct target *target) if (!armv7m->stlink) { if (cortex_m->apsel == DP_APSEL_INVALID) { /* Search for the MEM-AP */ - retval = dap_find_ap(swjdp, AP_TYPE_AHB_AP, &armv7m->debug_ap); + retval = cortex_m_find_mem_ap(swjdp, &armv7m->debug_ap); if (retval != ERROR_OK) { LOG_ERROR("Could not find MEM-AP to control the core"); return retval; @@ -2018,14 +2149,31 @@ int cortex_m_examine(struct target *target) /* Get CPU Type */ i = (cpuid >> 4) & 0xf; + switch (cpuid & ARM_CPUID_PARTNO_MASK) { + case CORTEX_M23_PARTNO: + i = 23; + break; + + case CORTEX_M33_PARTNO: + i = 33; + break; + + default: + break; + } + + LOG_DEBUG("Cortex-M%d r%" PRId8 "p%" PRId8 " processor detected", i, (uint8_t)((cpuid >> 20) & 0xf), (uint8_t)((cpuid >> 0) & 0xf)); + cortex_m->maskints_erratum = false; if (i == 7) { uint8_t rev, patch; rev = (cpuid >> 20) & 0xf; patch = (cpuid >> 0) & 0xf; - if ((rev == 0) && (patch < 2)) - LOG_WARNING("Silicon bug: single stepping will enter pending exception handler!"); + if ((rev == 0) && (patch < 2)) { + LOG_WARNING("Silicon bug: single stepping may enter pending exception handler!"); + cortex_m->maskints_erratum = true; + } } LOG_DEBUG("cpuid: 0x%8.8" PRIx32 "", cpuid); @@ -2041,7 +2189,7 @@ int cortex_m_examine(struct target *target) LOG_DEBUG("Cortex-M%d floating point feature FPv4_SP found", i); armv7m->fp_feature = FPv4_SP; } - } else if (i == 7) { + } else if (i == 7 || i == 33) { target_read_u32(target, MVFR0, &mvfr0); target_read_u32(target, MVFR1, &mvfr1); @@ -2271,11 +2419,11 @@ static int cortex_m_target_create(struct target *target, Jim_Interp *interp) /*--------------------------------------------------------------------------*/ -static int cortex_m_verify_pointer(struct command_context *cmd_ctx, +static int cortex_m_verify_pointer(struct command_invocation *cmd, struct cortex_m_common *cm) { if (cm->common_magic != CORTEX_M_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not a Cortex-M"); + command_print(cmd, "target is not a Cortex-M"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -2309,7 +2457,7 @@ COMMAND_HANDLER(handle_cortex_m_vector_catch_command) { "reset", VC_CORERESET, }, }; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; @@ -2364,7 +2512,7 @@ write: } for (unsigned i = 0; i < ARRAY_SIZE(vec_ids); i++) { - command_print(CMD_CTX, "%9s: %s", vec_ids[i].name, + command_print(CMD, "%9s: %s", vec_ids[i].name, (demcr & vec_ids[i].mask) ? "catch" : "ignore"); } @@ -2381,17 +2529,18 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) { .name = "auto", .value = CORTEX_M_ISRMASK_AUTO }, { .name = "off", .value = CORTEX_M_ISRMASK_OFF }, { .name = "on", .value = CORTEX_M_ISRMASK_ON }, + { .name = "steponly", .value = CORTEX_M_ISRMASK_STEPONLY }, { .name = NULL, .value = -1 }, }; const Jim_Nvp *n; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -2400,16 +2549,11 @@ COMMAND_HANDLER(handle_cortex_m_mask_interrupts_command) if (n->name == NULL) return ERROR_COMMAND_SYNTAX_ERROR; cortex_m->isrmasking_mode = n->value; - - - if (cortex_m->isrmasking_mode == CORTEX_M_ISRMASK_ON) - cortex_m_write_debug_halt_mask(target, C_HALT | C_MASKINTS, 0); - else - cortex_m_write_debug_halt_mask(target, C_HALT, C_MASKINTS); + cortex_m_set_maskints_for_halt(target); } n = Jim_Nvp_value2name_simple(nvp_maskisr_modes, cortex_m->isrmasking_mode); - command_print(CMD_CTX, "cortex_m interrupt mask %s", n->name); + command_print(CMD, "cortex_m interrupt mask %s", n->name); return ERROR_OK; } @@ -2421,7 +2565,7 @@ COMMAND_HANDLER(handle_cortex_m_reset_config_command) int retval; char *reset_config; - retval = cortex_m_verify_pointer(CMD_CTX, cortex_m); + retval = cortex_m_verify_pointer(CMD, cortex_m); if (retval != ERROR_OK) return retval; @@ -2454,7 +2598,7 @@ COMMAND_HANDLER(handle_cortex_m_reset_config_command) break; } - command_print(CMD_CTX, "cortex_m reset_config %s", reset_config); + command_print(CMD, "cortex_m reset_config %s", reset_config); return ERROR_OK; } @@ -2465,7 +2609,7 @@ static const struct command_registration cortex_m_exec_command_handlers[] = { .handler = handle_cortex_m_mask_interrupts_command, .mode = COMMAND_EXEC, .help = "mask cortex_m interrupts", - .usage = "['auto'|'on'|'off']", + .usage = "['auto'|'on'|'off'|'steponly']", }, { .name = "vector_catch", diff --git a/src/target/cortex_m.h b/src/target/cortex_m.h index 4b20746..54d7a02 100644 --- a/src/target/cortex_m.h +++ b/src/target/cortex_m.h @@ -38,6 +38,12 @@ #define ITM_LAR_KEY 0xC5ACCE55 #define CPUID 0xE000ED00 + +#define ARM_CPUID_PARTNO_MASK 0xFFF0 + +#define CORTEX_M23_PARTNO 0xD200 +#define CORTEX_M33_PARTNO 0xD210 + /* Debug Control Block */ #define DCB_DHCSR 0xE000EDF0 #define DCB_DCRSR 0xE000EDF4 @@ -52,6 +58,9 @@ #define DWT_COMP0 0xE0001020 #define DWT_MASK0 0xE0001024 #define DWT_FUNCTION0 0xE0001028 +#define DWT_DEVARCH 0xE0001FBC + +#define DWT_DEVARCH_ARMV8M 0x101A02 #define FP_CTRL 0xE0002000 #define FP_REMAP 0xE0002004 @@ -127,6 +136,7 @@ #define DFSR_BKPT 2 #define DFSR_DWTTRAP 4 #define DFSR_VCATCH 8 +#define DFSR_EXTERNAL 16 #define FPCR_CODE 0 #define FPCR_LITERAL 1 @@ -159,6 +169,7 @@ enum cortex_m_isrmasking_mode { CORTEX_M_ISRMASK_AUTO, CORTEX_M_ISRMASK_OFF, CORTEX_M_ISRMASK_ON, + CORTEX_M_ISRMASK_STEPONLY, }; struct cortex_m_common { @@ -179,6 +190,7 @@ struct cortex_m_common { /* Data Watchpoint and Trace (DWT) */ int dwt_num_comp; int dwt_comp_available; + uint32_t dwt_devarch; struct cortex_m_dwt_comparator *dwt_comparator_list; struct reg_cache *dwt_cache; @@ -190,6 +202,10 @@ struct cortex_m_common { struct armv7m_common armv7m; int apsel; + + /* Whether this target has the erratum that makes C_MASKINTS not apply to + * already pending interrupts */ + bool maskints_erratum; }; static inline struct cortex_m_common * diff --git a/src/target/dsp563xx.c b/src/target/dsp563xx.c index 5f13384..6a5c868 100644 --- a/src/target/dsp563xx.c +++ b/src/target/dsp563xx.c @@ -475,6 +475,7 @@ static void dsp563xx_build_reg_cache(struct target *target) reg_list[i].value = calloc(1, 4); reg_list[i].dirty = false; reg_list[i].valid = false; + reg_list[i].exist = true; reg_list[i].type = &dsp563xx_reg_type; reg_list[i].arch_info = &arch_info[i]; } @@ -1875,67 +1876,6 @@ static int dsp563xx_remove_watchpoint(struct target *target, struct watchpoint * return ERROR_TARGET_RESOURCE_NOT_AVAILABLE; } -static void handle_md_output(struct command_context *cmd_ctx, - struct target *target, - uint32_t address, - unsigned size, - unsigned count, - const uint8_t *buffer) -{ - const unsigned line_bytecnt = 32; - unsigned line_modulo = line_bytecnt / size; - - char output[line_bytecnt * 4 + 1]; - unsigned output_len = 0; - - const char *value_fmt; - switch (size) { - case 4: - value_fmt = "%8.8x "; - break; - case 2: - value_fmt = "%4.4x "; - break; - case 1: - value_fmt = "%2.2x "; - break; - default: - /* "can't happen", caller checked */ - LOG_ERROR("invalid memory read size: %u", size); - return; - } - - for (unsigned i = 0; i < count; i++) { - if (i % line_modulo == 0) - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - "0x%8.8x: ", - (unsigned) (address + i)); - - uint32_t value = 0; - const uint8_t *value_ptr = buffer + i * size; - switch (size) { - case 4: - value = target_buffer_get_u32(target, value_ptr); - break; - case 2: - value = target_buffer_get_u16(target, value_ptr); - break; - case 1: - value = *value_ptr; - } - output_len += snprintf(output + output_len, - sizeof(output) - output_len, - value_fmt, - value); - - if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); - output_len = 0; - } - } -} - static int dsp563xx_add_custom_watchpoint(struct target *target, uint32_t address, uint32_t memType, enum watchpoint_rw rw, enum watchpoint_condition cond) { @@ -2208,7 +2148,7 @@ COMMAND_HANDLER(dsp563xx_mem_command) err = dsp563xx_read_memory(target, mem_type, address, sizeof(uint32_t), count, buffer); if (err == ERROR_OK) - handle_md_output(CMD_CTX, target, address, sizeof(uint32_t), count, buffer); + target_handle_md_output(CMD, target, address, sizeof(uint32_t), count, buffer); } else { b = buffer; diff --git a/src/target/esirisc.c b/src/target/esirisc.c index 3d2954f..c928445 100644 --- a/src/target/esirisc.c +++ b/src/target/esirisc.c @@ -1680,7 +1680,7 @@ COMMAND_HANDLER(handle_esirisc_cache_arch_command) } } - command_print(CMD_CTX, "esirisc cache_arch %s", esirisc_cache_arch_name(esirisc)); + command_print(CMD, "esirisc cache_arch %s", esirisc_cache_arch_name(esirisc)); return ERROR_OK; } @@ -1698,7 +1698,7 @@ COMMAND_HANDLER(handle_esirisc_flush_caches_command) retval = esirisc_flush_caches(target); - command_print(CMD_CTX, "cache flush %s", + command_print(CMD, "cache flush %s", (retval == ERROR_OK) ? "successful" : "failed"); return retval; @@ -1748,7 +1748,7 @@ COMMAND_HANDLER(handle_esirisc_hwdc_command) } for (size_t i = 0; i < ARRAY_SIZE(esirisc_hwdc_masks); ++i) - command_print(CMD_CTX, "%9s: %s", esirisc_hwdc_masks[i].name, + command_print(CMD, "%9s: %s", esirisc_hwdc_masks[i].name, (esirisc->hwdc_save & esirisc_hwdc_masks[i].mask) ? "enabled" : "disabled"); return ERROR_OK; diff --git a/src/target/esirisc_trace.c b/src/target/esirisc_trace.c index 4e0a155..6a7d5a2 100644 --- a/src/target/esirisc_trace.c +++ b/src/target/esirisc_trace.c @@ -385,9 +385,9 @@ static int esirisc_trace_read_buffer(struct target *target, uint8_t *buffer) buffer_cur - trace_info->buffer_start, buffer); } -static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze_full(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); const uint32_t num_bits = size * 8; int retval; @@ -403,7 +403,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * case ESIRISC_TRACE_ID_EXECUTE: case ESIRISC_TRACE_ID_STALL: case ESIRISC_TRACE_ID_BRANCH: - command_print(cmd_ctx, "%s", esirisc_trace_id_strings[id]); + command_print(cmd, "%s", esirisc_trace_id_strings[id]); break; case ESIRISC_TRACE_ID_EXTENDED: { @@ -417,7 +417,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * case ESIRISC_TRACE_EXT_ID_STOP: case ESIRISC_TRACE_EXT_ID_WAIT: case ESIRISC_TRACE_EXT_ID_MULTICYCLE: - command_print(cmd_ctx, "%s", esirisc_trace_ext_id_strings[ext_id]); + command_print(cmd, "%s", esirisc_trace_ext_id_strings[ext_id]); break; case ESIRISC_TRACE_EXT_ID_ERET: @@ -430,11 +430,11 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "%s PC: 0x%" PRIx32, + command_print(cmd, "%s PC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], pc); if (ext_id == ESIRISC_TRACE_EXT_ID_END_PC) { - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; } break; @@ -450,7 +450,7 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, + command_print(cmd, "%s EID: 0x%" PRIx32 ", EPC: 0x%" PRIx32, esirisc_trace_ext_id_strings[ext_id], eid, epc); break; } @@ -461,34 +461,34 @@ static int esirisc_trace_analyze_full(struct command_context *cmd_ctx, uint8_t * if (retval != ERROR_OK) goto fail; - command_print(cmd_ctx, "repeats %" PRId32 " %s", count, + command_print(cmd, "repeats %" PRId32 " %s", count, (count == 1) ? "time" : "times"); break; } case ESIRISC_TRACE_EXT_ID_END: - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; default: - command_print(cmd_ctx, "invalid extended trace ID: %" PRId32, ext_id); + command_print(cmd, "invalid extended trace ID: %" PRId32, ext_id); return ERROR_FAIL; } break; } default: - command_print(cmd_ctx, "invalid trace ID: %" PRId32, id); + command_print(cmd, "invalid trace ID: %" PRId32, id); return ERROR_FAIL; } } fail: - command_print(cmd_ctx, "trace buffer too small"); + command_print(cmd, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } -static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze_simple(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; const uint32_t end_of_trace = BIT_MASK(trace_info->pc_bits) << 1; @@ -504,45 +504,45 @@ static int esirisc_trace_analyze_simple(struct command_context *cmd_ctx, uint8_t break; if (pc == end_of_trace) { - command_print(cmd_ctx, "--- end of trace ---"); + command_print(cmd, "--- end of trace ---"); return ERROR_OK; } - command_print(cmd_ctx, "PC: 0x%" PRIx32, pc); + command_print(cmd, "PC: 0x%" PRIx32, pc); } - command_print(cmd_ctx, "trace buffer too small"); + command_print(cmd, "trace buffer too small"); return ERROR_BUF_TOO_SMALL; } -static int esirisc_trace_analyze(struct command_context *cmd_ctx, uint8_t *buffer, uint32_t size) +static int esirisc_trace_analyze(struct command_invocation *cmd, uint8_t *buffer, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; switch (trace_info->format) { case ESIRISC_TRACE_FORMAT_FULL: - command_print(cmd_ctx, "--- full pipeline ---"); - return esirisc_trace_analyze_full(cmd_ctx, buffer, size); + command_print(cmd, "--- full pipeline ---"); + return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_BRANCH: - command_print(cmd_ctx, "--- branches taken ---"); - return esirisc_trace_analyze_full(cmd_ctx, buffer, size); + command_print(cmd, "--- branches taken ---"); + return esirisc_trace_analyze_full(cmd, buffer, size); case ESIRISC_TRACE_FORMAT_ICACHE: - command_print(cmd_ctx, "--- icache misses ---"); - return esirisc_trace_analyze_simple(cmd_ctx, buffer, size); + command_print(cmd, "--- icache misses ---"); + return esirisc_trace_analyze_simple(cmd, buffer, size); default: - command_print(cmd_ctx, "invalid trace format: %i", trace_info->format); + command_print(cmd, "invalid trace format: %i", trace_info->format); return ERROR_FAIL; } } -static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) +static int esirisc_trace_analyze_buffer(struct command_invocation *cmd) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; uint8_t *buffer; @@ -552,7 +552,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -560,7 +560,7 @@ static int esirisc_trace_analyze_buffer(struct command_context *cmd_ctx) if (retval != ERROR_OK) goto done; - retval = esirisc_trace_analyze(cmd_ctx, buffer, size); + retval = esirisc_trace_analyze(cmd, buffer, size); done: free(buffer); @@ -568,16 +568,16 @@ done: return retval; } -static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx, +static int esirisc_trace_analyze_memory(struct command_invocation *cmd, target_addr_t address, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); uint8_t *buffer; int retval; buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -585,7 +585,7 @@ static int esirisc_trace_analyze_memory(struct command_context *cmd_ctx, if (retval != ERROR_OK) goto done; - retval = esirisc_trace_analyze(cmd_ctx, buffer, size); + retval = esirisc_trace_analyze(cmd, buffer, size); done: free(buffer); @@ -593,7 +593,7 @@ done: return retval; } -static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filename, +static int esirisc_trace_dump(struct command_invocation *cmd, const char *filename, uint8_t *buffer, uint32_t size) { struct fileio *fileio; @@ -602,24 +602,24 @@ static int esirisc_trace_dump(struct command_context *cmd_ctx, const char *filen retval = fileio_open(&fileio, filename, FILEIO_WRITE, FILEIO_BINARY); if (retval != ERROR_OK) { - command_print(cmd_ctx, "could not open dump file: %s", filename); + command_print(cmd, "could not open dump file: %s", filename); return retval; } retval = fileio_write(fileio, size, buffer, &size_written); if (retval == ERROR_OK) - command_print(cmd_ctx, "trace data dumped to: %s", filename); + command_print(cmd, "trace data dumped to: %s", filename); else - command_print(cmd_ctx, "could not write dump file: %s", filename); + command_print(cmd, "could not write dump file: %s", filename); fileio_close(fileio); return retval; } -static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char *filename) +static int esirisc_trace_dump_buffer(struct command_invocation *cmd, const char *filename) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct esirisc_common *esirisc = target_to_esirisc(target); struct esirisc_trace *trace_info = &esirisc->trace_info; uint8_t *buffer; @@ -629,7 +629,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char size = esirisc_trace_buffer_size(trace_info); buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -637,7 +637,7 @@ static int esirisc_trace_dump_buffer(struct command_context *cmd_ctx, const char if (retval != ERROR_OK) goto done; - retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size); + retval = esirisc_trace_dump(cmd, filename, buffer, size); done: free(buffer); @@ -645,16 +645,16 @@ done: return retval; } -static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char *filename, +static int esirisc_trace_dump_memory(struct command_invocation *cmd, const char *filename, target_addr_t address, uint32_t size) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); uint8_t *buffer; int retval; buffer = calloc(1, size); if (buffer == NULL) { - command_print(cmd_ctx, "out of memory"); + command_print(cmd, "out of memory"); return ERROR_FAIL; } @@ -662,7 +662,7 @@ static int esirisc_trace_dump_memory(struct command_context *cmd_ctx, const char if (retval != ERROR_OK) goto done; - retval = esirisc_trace_dump(cmd_ctx, filename, buffer, size); + retval = esirisc_trace_dump(cmd, filename, buffer, size); done: free(buffer); @@ -676,13 +676,13 @@ COMMAND_HANDLER(handle_esirisc_trace_init_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_init(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace initialized"); + command_print(CMD, "trace initialized"); return retval; } @@ -694,42 +694,42 @@ COMMAND_HANDLER(handle_esirisc_trace_info_command) struct esirisc_trace *trace_info = &esirisc->trace_info; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } if (esirisc_trace_is_fifo(trace_info)) - command_print(CMD_CTX, "trace FIFO address: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace FIFO address: 0x%" TARGET_PRIxADDR, trace_info->buffer_start); else { - command_print(CMD_CTX, "trace buffer start: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace buffer start: 0x%" TARGET_PRIxADDR, trace_info->buffer_start); - command_print(CMD_CTX, "trace buffer end: 0x%" TARGET_PRIxADDR, + command_print(CMD, "trace buffer end: 0x%" TARGET_PRIxADDR, trace_info->buffer_end); - command_print(CMD_CTX, "trace buffer will %swrap", + command_print(CMD, "trace buffer will %swrap", trace_info->buffer_wrap ? "" : "not "); } - command_print(CMD_CTX, "flow control: %s", + command_print(CMD, "flow control: %s", trace_info->flow_control ? "enabled" : "disabled"); - command_print(CMD_CTX, "trace format: %s", + command_print(CMD, "trace format: %s", esirisc_trace_format_strings[trace_info->format]); - command_print(CMD_CTX, "number of PC bits: %i", trace_info->pc_bits); + command_print(CMD, "number of PC bits: %i", trace_info->pc_bits); - command_print(CMD_CTX, "start trigger: %s", + command_print(CMD, "start trigger: %s", esirisc_trace_trigger_strings[trace_info->start_trigger]); - command_print(CMD_CTX, "start data: 0x%" PRIx32, trace_info->start_data); - command_print(CMD_CTX, "start mask: 0x%" PRIx32, trace_info->start_mask); + command_print(CMD, "start data: 0x%" PRIx32, trace_info->start_data); + command_print(CMD, "start mask: 0x%" PRIx32, trace_info->start_mask); - command_print(CMD_CTX, "stop trigger: %s", + command_print(CMD, "stop trigger: %s", esirisc_trace_trigger_strings[trace_info->stop_trigger]); - command_print(CMD_CTX, "stop data: 0x%" PRIx32, trace_info->stop_data); - command_print(CMD_CTX, "stop mask: 0x%" PRIx32, trace_info->stop_mask); + command_print(CMD, "stop data: 0x%" PRIx32, trace_info->stop_data); + command_print(CMD, "stop mask: 0x%" PRIx32, trace_info->stop_mask); - command_print(CMD_CTX, "trigger delay: %s", + command_print(CMD, "trigger delay: %s", esirisc_trace_delay_strings[trace_info->delay]); - command_print(CMD_CTX, "trigger delay cycles: %i", trace_info->delay_cycles); + command_print(CMD, "trigger delay cycles: %i", trace_info->delay_cycles); return ERROR_OK; } @@ -741,7 +741,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command) uint32_t status; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -749,7 +749,7 @@ COMMAND_HANDLER(handle_esirisc_trace_status_command) if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, "trace is %s%s%s%s", + command_print(CMD, "trace is %s%s%s%s", (status & STATUS_T) ? "started" : "stopped", (status & STATUS_TD) ? ", disabled" : "", (status & STATUS_W) ? ", wrapped" : "", @@ -764,13 +764,13 @@ COMMAND_HANDLER(handle_esirisc_trace_start_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_start(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace started"); + command_print(CMD, "trace started"); return retval; } @@ -781,13 +781,13 @@ COMMAND_HANDLER(handle_esirisc_trace_stop_command) struct esirisc_common *esirisc = target_to_esirisc(target); if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } int retval = esirisc_trace_stop(target); if (retval == ERROR_OK) - command_print(CMD_CTX, "trace stopped"); + command_print(CMD, "trace stopped"); return retval; } @@ -801,7 +801,7 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command) uint32_t size; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -817,16 +817,16 @@ COMMAND_HANDLER(handle_esirisc_trace_analyze_command) * as arguments as a workaround. */ if (esirisc_trace_is_fifo(trace_info)) { - command_print(CMD_CTX, "analyze from FIFO not supported"); + command_print(CMD, "analyze from FIFO not supported"); return ERROR_FAIL; } - return esirisc_trace_analyze_buffer(CMD_CTX); + return esirisc_trace_analyze_buffer(CMD); } else { COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size); - return esirisc_trace_analyze_memory(CMD_CTX, address, size); + return esirisc_trace_analyze_memory(CMD, address, size); } } @@ -839,7 +839,7 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command) uint32_t size; if (!esirisc->has_trace) { - command_print(CMD_CTX, "target does not support trace"); + command_print(CMD, "target does not support trace"); return ERROR_FAIL; } @@ -849,16 +849,16 @@ COMMAND_HANDLER(handle_esirisc_trace_dump_command) if (CMD_ARGC == 1) { /* also see: handle_esirisc_trace_analyze_command() */ if (esirisc_trace_is_fifo(trace_info)) { - command_print(CMD_CTX, "dump from FIFO not supported"); + command_print(CMD, "dump from FIFO not supported"); return ERROR_FAIL; } - return esirisc_trace_dump_buffer(CMD_CTX, CMD_ARGV[0]); + return esirisc_trace_dump_buffer(CMD, CMD_ARGV[0]); } else { COMMAND_PARSE_ADDRESS(CMD_ARGV[0], address); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], size); - return esirisc_trace_dump_memory(CMD_CTX, CMD_ARGV[2], address, size); + return esirisc_trace_dump_memory(CMD, CMD_ARGV[2], address, size); } } @@ -946,7 +946,7 @@ COMMAND_HANDLER(handle_esirisc_trace_format_command) COMMAND_PARSE_NUMBER(int, CMD_ARGV[1], pc_bits); if (pc_bits < 1 || pc_bits > 31) { - command_print(CMD_CTX, "invalid pc_bits: %i; must be 1..31", pc_bits); + command_print(CMD, "invalid pc_bits: %i; must be 1..31", pc_bits); return ERROR_COMMAND_SYNTAX_ERROR; } diff --git a/src/target/etb.c b/src/target/etb.c index 98a90a5..392c6ad 100644 --- a/src/target/etb.c +++ b/src/target/etb.c @@ -344,13 +344,13 @@ COMMAND_HANDLER(handle_etb_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETB: '%s' isn't an ARM", CMD_ARGV[0]); + command_print(CMD, "ETB: '%s' isn't an ARM", CMD_ARGV[0]); return ERROR_FAIL; } tap = jtag_tap_by_string(CMD_ARGV[1]); if (tap == NULL) { - command_print(CMD_CTX, "ETB: TAP %s does not exist", CMD_ARGV[1]); + command_print(CMD, "ETB: TAP %s does not exist", CMD_ARGV[1]); return ERROR_FAIL; } @@ -382,17 +382,17 @@ COMMAND_HANDLER(handle_etb_trigger_percent_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETB: current target isn't an ARM"); + command_print(CMD, "ETB: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "ETB: target has no ETM configured"); + command_print(CMD, "ETB: target has no ETM configured"); return ERROR_FAIL; } if (etm->capture_driver != &etb_capture_driver) { - command_print(CMD_CTX, "ETB: target not using ETB"); + command_print(CMD, "ETB: target not using ETB"); return ERROR_FAIL; } etb = arm->etm->capture_driver_priv; @@ -402,13 +402,13 @@ COMMAND_HANDLER(handle_etb_trigger_percent_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], new_value); if ((new_value < 2) || (new_value > 100)) - command_print(CMD_CTX, + command_print(CMD, "valid percentages are 2%% to 100%%"); else etb->trigger_percent = (unsigned) new_value; } - command_print(CMD_CTX, "%d percent of tracebuffer fills after trigger", + command_print(CMD, "%d percent of tracebuffer fills after trigger", etb->trigger_percent); return ERROR_OK; @@ -441,6 +441,7 @@ static const struct command_registration etb_command_handlers[] = { .mode = COMMAND_ANY, .help = "Embedded Trace Buffer command group", .chain = etb_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/etm.c b/src/target/etm.c index 6a00c23..5751348 100644 --- a/src/target/etm.c +++ b/src/target/etm.c @@ -859,7 +859,7 @@ static int etmv1_data(struct etm_context *ctx, int size, uint32_t *data) return 0; } -static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context *cmd_ctx) +static int etmv1_analyze_trace(struct etm_context *ctx, struct command_invocation *cmd) { int retval; struct arm_instruction instruction; @@ -869,7 +869,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * ctx->capture_driver->read_trace(ctx); if (ctx->trace_depth == 0) { - command_print(cmd_ctx, "Trace is empty."); + command_print(cmd, "Trace is empty."); return ERROR_OK; } @@ -893,7 +893,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * int current_pc_ok = ctx->pc_ok; if (ctx->trace_data[ctx->pipe_index].flags & ETMV1_TRIGGER_CYCLE) - command_print(cmd_ctx, "--- trigger ---"); + command_print(cmd, "--- trigger ---"); /* instructions execute in IE/D or BE/D cycles */ if ((pipestat == STAT_IE) || (pipestat == STAT_ID)) @@ -942,7 +942,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * next_pc = ctx->last_branch; break; case 0x1: /* tracing enabled */ - command_print(cmd_ctx, + command_print(cmd, "--- tracing enabled at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -950,7 +950,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * continue; break; case 0x2: /* trace restarted after FIFO overflow */ - command_print(cmd_ctx, + command_print(cmd, "--- trace restarted after FIFO overflow at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -958,7 +958,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * continue; break; case 0x3: /* exit from debug state */ - command_print(cmd_ctx, + command_print(cmd, "--- exit from debug state at 0x%8.8" PRIx32 " ---", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -971,7 +971,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * * we have to move on with the next trace cycle */ if (!current_pc_ok) { - command_print(cmd_ctx, + command_print(cmd, "--- periodic synchronization point at 0x%8.8" PRIx32 " ---", next_pc); ctx->current_pc = next_pc; @@ -998,9 +998,9 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * || ((ctx->last_branch >= 0xffff0000) && (ctx->last_branch <= 0xffff0020))) { if ((ctx->last_branch & 0xff) == 0x10) - command_print(cmd_ctx, "data abort"); + command_print(cmd, "data abort"); else { - command_print(cmd_ctx, + command_print(cmd, "exception vector 0x%2.2" PRIx32 "", ctx->last_branch); ctx->current_pc = ctx->last_branch; @@ -1058,7 +1058,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * ctx->ptr_ok = 1; if (ctx->ptr_ok) - command_print(cmd_ctx, + command_print(cmd, "address: 0x%8.8" PRIx32 "", ctx->last_ptr); } @@ -1073,7 +1073,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * uint32_t data; if (etmv1_data(ctx, 4, &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd_ctx, + command_print(cmd, "data: 0x%8.8" PRIx32 "", data); } @@ -1084,7 +1084,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * if (etmv1_data(ctx, arm_access_size(&instruction), &data) != 0) return ERROR_ETM_ANALYSIS_FAILED; - command_print(cmd_ctx, "data: 0x%8.8" PRIx32 "", data); + command_print(cmd, "data: 0x%8.8" PRIx32 "", data); } } @@ -1119,7 +1119,7 @@ static int etmv1_analyze_trace(struct etm_context *ctx, struct command_context * (cycles == 1) ? "cycle" : "cycles"); } - command_print(cmd_ctx, "%s%s%s", + command_print(cmd, "%s%s%s", instruction.text, (pipestat == STAT_IN) ? " (not executed)" : "", cycles_text); @@ -1156,7 +1156,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update, else if (strcmp(CMD_ARGV[0], "all") == 0) tracemode = ETM_CTRL_TRACE_DATA | ETM_CTRL_TRACE_ADDR; else { - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[0]); + command_print(CMD, "invalid option '%s'", CMD_ARGV[0]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1176,7 +1176,7 @@ static COMMAND_HELPER(handle_etm_tracemode_command_update, tracemode |= ETM_CTRL_CONTEXTID_32; break; default: - command_print(CMD_CTX, "invalid option '%s'", CMD_ARGV[1]); + command_print(CMD, "invalid option '%s'", CMD_ARGV[1]); return ERROR_COMMAND_SYNTAX_ERROR; } @@ -1207,13 +1207,13 @@ COMMAND_HANDLER(handle_etm_tracemode_command) struct etm_context *etm; if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1235,47 +1235,47 @@ COMMAND_HANDLER(handle_etm_tracemode_command) * or couldn't be written; display actual hardware state... */ - command_print(CMD_CTX, "current tracemode configuration:"); + command_print(CMD, "current tracemode configuration:"); switch (tracemode & ETM_CTRL_TRACE_MASK) { default: - command_print(CMD_CTX, "data tracing: none"); + command_print(CMD, "data tracing: none"); break; case ETM_CTRL_TRACE_DATA: - command_print(CMD_CTX, "data tracing: data only"); + command_print(CMD, "data tracing: data only"); break; case ETM_CTRL_TRACE_ADDR: - command_print(CMD_CTX, "data tracing: address only"); + command_print(CMD, "data tracing: address only"); break; case ETM_CTRL_TRACE_DATA | ETM_CTRL_TRACE_ADDR: - command_print(CMD_CTX, "data tracing: address and data"); + command_print(CMD, "data tracing: address and data"); break; } switch (tracemode & ETM_CTRL_CONTEXTID_MASK) { case ETM_CTRL_CONTEXTID_NONE: - command_print(CMD_CTX, "contextid tracing: none"); + command_print(CMD, "contextid tracing: none"); break; case ETM_CTRL_CONTEXTID_8: - command_print(CMD_CTX, "contextid tracing: 8 bit"); + command_print(CMD, "contextid tracing: 8 bit"); break; case ETM_CTRL_CONTEXTID_16: - command_print(CMD_CTX, "contextid tracing: 16 bit"); + command_print(CMD, "contextid tracing: 16 bit"); break; case ETM_CTRL_CONTEXTID_32: - command_print(CMD_CTX, "contextid tracing: 32 bit"); + command_print(CMD, "contextid tracing: 32 bit"); break; } if (tracemode & ETM_CTRL_CYCLE_ACCURATE) - command_print(CMD_CTX, "cycle-accurate tracing enabled"); + command_print(CMD, "cycle-accurate tracing enabled"); else - command_print(CMD_CTX, "cycle-accurate tracing disabled"); + command_print(CMD, "cycle-accurate tracing disabled"); if (tracemode & ETM_CTRL_BRANCH_OUTPUT) - command_print(CMD_CTX, "full branch address output enabled"); + command_print(CMD, "full branch address output enabled"); else - command_print(CMD_CTX, "full branch address output disabled"); + command_print(CMD, "full branch address output disabled"); #define TRACEMODE_MASK ( \ ETM_CTRL_CONTEXTID_MASK \ @@ -1331,7 +1331,7 @@ COMMAND_HANDLER(handle_etm_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "target '%s' is '%s'; not an ARM", + command_print(CMD, "target '%s' is '%s'; not an ARM", target_name(target), target_type_name(target)); return ERROR_FAIL; @@ -1382,7 +1382,7 @@ COMMAND_HANDLER(handle_etm_config_command) portmode |= ETM_PORT_2BIT; break; default: - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port width '%s'", CMD_ARGV[1]); return ERROR_FAIL; } @@ -1394,7 +1394,7 @@ COMMAND_HANDLER(handle_etm_config_command) else if (strcmp("demultiplexed", CMD_ARGV[2]) == 0) portmode |= ETM_PORT_DEMUXED; else { - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port mode '%s', must be 'normal', 'multiplexed' or 'demultiplexed'", CMD_ARGV[2]); return ERROR_FAIL; @@ -1405,7 +1405,7 @@ COMMAND_HANDLER(handle_etm_config_command) else if (strcmp("full", CMD_ARGV[3]) == 0) portmode |= ETM_PORT_FULL_CLOCK; else { - command_print(CMD_CTX, + command_print(CMD, "unsupported ETM port clocking '%s', must be 'full' or 'half'", CMD_ARGV[3]); return ERROR_FAIL; @@ -1461,44 +1461,44 @@ COMMAND_HANDLER(handle_etm_info_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } - command_print(CMD_CTX, "ETM v%d.%d", + command_print(CMD, "ETM v%d.%d", etm->bcd_vers >> 4, etm->bcd_vers & 0xf); - command_print(CMD_CTX, "pairs of address comparators: %i", + command_print(CMD, "pairs of address comparators: %i", (int) (etm->config >> 0) & 0x0f); - command_print(CMD_CTX, "data comparators: %i", + command_print(CMD, "data comparators: %i", (int) (etm->config >> 4) & 0x0f); - command_print(CMD_CTX, "memory map decoders: %i", + command_print(CMD, "memory map decoders: %i", (int) (etm->config >> 8) & 0x1f); - command_print(CMD_CTX, "number of counters: %i", + command_print(CMD, "number of counters: %i", (int) (etm->config >> 13) & 0x07); - command_print(CMD_CTX, "sequencer %spresent", + command_print(CMD, "sequencer %spresent", (int) (etm->config & (1 << 16)) ? "" : "not "); - command_print(CMD_CTX, "number of ext. inputs: %i", + command_print(CMD, "number of ext. inputs: %i", (int) (etm->config >> 17) & 0x07); - command_print(CMD_CTX, "number of ext. outputs: %i", + command_print(CMD, "number of ext. outputs: %i", (int) (etm->config >> 20) & 0x07); - command_print(CMD_CTX, "FIFO full %spresent", + command_print(CMD, "FIFO full %spresent", (int) (etm->config & (1 << 23)) ? "" : "not "); if (etm->bcd_vers < 0x20) - command_print(CMD_CTX, "protocol version: %i", + command_print(CMD, "protocol version: %i", (int) (etm->config >> 28) & 0x07); else { - command_print(CMD_CTX, + command_print(CMD, "coprocessor and memory access %ssupported", (etm->config & (1 << 26)) ? "" : "not "); - command_print(CMD_CTX, "trace start/stop %spresent", + command_print(CMD, "trace start/stop %spresent", (etm->config & (1 << 26)) ? "" : "not "); - command_print(CMD_CTX, "number of context comparators: %i", + command_print(CMD, "number of context comparators: %i", (int) (etm->config >> 24) & 0x03); } @@ -1549,30 +1549,30 @@ COMMAND_HANDLER(handle_etm_info_command) LOG_ERROR("Illegal max_port_size"); return ERROR_FAIL; } - command_print(CMD_CTX, "max. port size: %i", max_port_size); + command_print(CMD, "max. port size: %i", max_port_size); if (etm->bcd_vers < 0x30) { - command_print(CMD_CTX, "half-rate clocking %ssupported", + command_print(CMD, "half-rate clocking %ssupported", (config & (1 << 3)) ? "" : "not "); - command_print(CMD_CTX, "full-rate clocking %ssupported", + command_print(CMD, "full-rate clocking %ssupported", (config & (1 << 4)) ? "" : "not "); - command_print(CMD_CTX, "normal trace format %ssupported", + command_print(CMD, "normal trace format %ssupported", (config & (1 << 5)) ? "" : "not "); - command_print(CMD_CTX, "multiplex trace format %ssupported", + command_print(CMD, "multiplex trace format %ssupported", (config & (1 << 6)) ? "" : "not "); - command_print(CMD_CTX, "demultiplex trace format %ssupported", + command_print(CMD, "demultiplex trace format %ssupported", (config & (1 << 7)) ? "" : "not "); } else { /* REVISIT show which size and format are selected ... */ - command_print(CMD_CTX, "current port size %ssupported", + command_print(CMD, "current port size %ssupported", (config & (1 << 10)) ? "" : "not "); - command_print(CMD_CTX, "current trace format %ssupported", + command_print(CMD, "current trace format %ssupported", (config & (1 << 11)) ? "" : "not "); } if (etm->bcd_vers >= 0x21) - command_print(CMD_CTX, "fetch comparisons %ssupported", + command_print(CMD, "fetch comparisons %ssupported", (config & (1 << 17)) ? "not " : ""); - command_print(CMD_CTX, "FIFO full %ssupported", + command_print(CMD, "FIFO full %ssupported", (config & (1 << 8)) ? "" : "not "); return ERROR_OK; @@ -1588,13 +1588,13 @@ COMMAND_HANDLER(handle_etm_status_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1608,7 +1608,7 @@ COMMAND_HANDLER(handle_etm_status_command) if (etm_get_reg(reg) == ERROR_OK) { unsigned s = buf_get_u32(reg->value, 0, reg->size); - command_print(CMD_CTX, "etm: %s%s%s%s", + command_print(CMD, "etm: %s%s%s%s", /* bit(1) == progbit */ (etm->bcd_vers >= 0x12) ? ((s & (1 << 1)) @@ -1626,21 +1626,21 @@ COMMAND_HANDLER(handle_etm_status_command) /* Trace Port Driver status */ trace_status = etm->capture_driver->status(etm); if (trace_status == TRACE_IDLE) - command_print(CMD_CTX, "%s: idle", etm->capture_driver->name); + command_print(CMD, "%s: idle", etm->capture_driver->name); else { static char *completed = " completed"; static char *running = " is running"; static char *overflowed = ", overflowed"; static char *triggered = ", triggered"; - command_print(CMD_CTX, "%s: trace collection%s%s%s", + command_print(CMD, "%s: trace collection%s%s%s", etm->capture_driver->name, (trace_status & TRACE_RUNNING) ? running : completed, (trace_status & TRACE_OVERFLOWED) ? overflowed : "", (trace_status & TRACE_TRIGGERED) ? triggered : ""); if (etm->trace_depth > 0) { - command_print(CMD_CTX, "%i frames of trace data read", + command_print(CMD, "%i frames of trace data read", (int)(etm->trace_depth)); } } @@ -1660,20 +1660,20 @@ COMMAND_HANDLER(handle_etm_image_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->image) { image_close(etm_ctx->image); free(etm_ctx->image); - command_print(CMD_CTX, "previously loaded image found and closed"); + command_print(CMD, "previously loaded image found and closed"); } etm_ctx->image = malloc(sizeof(struct image)); @@ -1711,24 +1711,24 @@ COMMAND_HANDLER(handle_etm_dump_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->capture_driver->status == TRACE_IDLE) { - command_print(CMD_CTX, "trace capture wasn't enabled, no trace data captured"); + command_print(CMD, "trace capture wasn't enabled, no trace data captured"); return ERROR_OK; } if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING) { /* TODO: if on-the-fly capture is to be supported, this needs to be changed */ - command_print(CMD_CTX, "trace capture not completed"); + command_print(CMD, "trace capture not completed"); return ERROR_FAIL; } @@ -1768,18 +1768,18 @@ COMMAND_HANDLER(handle_etm_load_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } if (etm_ctx->capture_driver->status(etm_ctx) & TRACE_RUNNING) { - command_print(CMD_CTX, "trace capture running, stop first"); + command_print(CMD, "trace capture running, stop first"); return ERROR_FAIL; } @@ -1794,7 +1794,7 @@ COMMAND_HANDLER(handle_etm_load_command) } if (filesize % 4) { - command_print(CMD_CTX, "size isn't a multiple of 4, no valid trace data"); + command_print(CMD, "size isn't a multiple of 4, no valid trace data"); fileio_close(file); return ERROR_FAIL; } @@ -1812,7 +1812,7 @@ COMMAND_HANDLER(handle_etm_load_command) } etm_ctx->trace_data = malloc(sizeof(struct etmv1_trace_data) * etm_ctx->trace_depth); if (etm_ctx->trace_data == NULL) { - command_print(CMD_CTX, "not enough memory to perform operation"); + command_print(CMD, "not enough memory to perform operation"); fileio_close(file); return ERROR_FAIL; } @@ -1842,13 +1842,13 @@ COMMAND_HANDLER(handle_etm_start_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1887,13 +1887,13 @@ COMMAND_HANDLER(handle_etm_stop_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } @@ -1923,14 +1923,14 @@ COMMAND_HANDLER(handle_etm_trigger_debug_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: %s isn't an ARM", + command_print(CMD, "ETM: %s isn't an ARM", target_name(target)); return ERROR_FAIL; } etm = arm->etm; if (!etm) { - command_print(CMD_CTX, "ETM: no ETM configured for %s", + command_print(CMD, "ETM: no ETM configured for %s", target_name(target)); return ERROR_FAIL; } @@ -1955,7 +1955,7 @@ COMMAND_HANDLER(handle_etm_trigger_debug_command) buf_set_u32(etm_ctrl_reg->value, 0, 32, etm->control); } - command_print(CMD_CTX, "ETM: %s debug halt", + command_print(CMD, "ETM: %s debug halt", (etm->control & ETM_CTRL_DBGRQ) ? "triggers" : "does not trigger"); @@ -1972,33 +1972,33 @@ COMMAND_HANDLER(handle_etm_analyze_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "ETM: current target isn't an ARM"); + command_print(CMD, "ETM: current target isn't an ARM"); return ERROR_FAIL; } etm_ctx = arm->etm; if (!etm_ctx) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + command_print(CMD, "current target doesn't have an ETM configured"); return ERROR_FAIL; } - retval = etmv1_analyze_trace(etm_ctx, CMD_CTX); + retval = etmv1_analyze_trace(etm_ctx, CMD); if (retval != ERROR_OK) { /* FIX! error should be reported inside etmv1_analyze_trace() */ switch (retval) { case ERROR_ETM_ANALYSIS_FAILED: - command_print(CMD_CTX, + command_print(CMD, "further analysis failed (corrupted trace data or just end of data"); break; case ERROR_TRACE_INSTRUCTION_UNAVAILABLE: - command_print(CMD_CTX, + command_print(CMD, "no instruction for current address available, analysis aborted"); break; case ERROR_TRACE_IMAGE_UNAVAILABLE: - command_print(CMD_CTX, "no image available for trace analysis"); + command_print(CMD, "no image available for trace analysis"); break; default: - command_print(CMD_CTX, "unknown error"); + command_print(CMD, "unknown error"); } } diff --git a/src/target/etm_dummy.c b/src/target/etm_dummy.c index b18ce17..ba53c7a 100644 --- a/src/target/etm_dummy.c +++ b/src/target/etm_dummy.c @@ -37,7 +37,7 @@ COMMAND_HANDLER(handle_etm_dummy_config_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "target '%s' isn't an ARM", CMD_ARGV[0]); + command_print(CMD, "target '%s' isn't an ARM", CMD_ARGV[0]); return ERROR_FAIL; } @@ -66,6 +66,7 @@ static const struct command_registration etm_dummy_command_handlers[] = { .mode = COMMAND_ANY, .help = "Dummy ETM capture driver command group", .chain = etm_dummy_config_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/mem_ap.c b/src/target/mem_ap.c index 584e19d..29cd37a 100644 --- a/src/target/mem_ap.c +++ b/src/target/mem_ap.c @@ -140,7 +140,7 @@ static int mem_ap_read_memory(struct target *target, target_addr_t address, { struct mem_ap *mem_ap = target->arch_info; - LOG_DEBUG("Reading memory at physical address 0x" TARGET_ADDR_FMT + LOG_DEBUG("Reading memory at physical address " TARGET_ADDR_FMT "; size %" PRId32 "; count %" PRId32, address, size, count); if (count == 0 || buffer == NULL) @@ -155,7 +155,7 @@ static int mem_ap_write_memory(struct target *target, target_addr_t address, { struct mem_ap *mem_ap = target->arch_info; - LOG_DEBUG("Writing memory at physical address 0x" TARGET_ADDR_FMT + LOG_DEBUG("Writing memory at physical address " TARGET_ADDR_FMT "; size %" PRId32 "; count %" PRId32, address, size, count); if (count == 0 || buffer == NULL) diff --git a/src/target/mips32.c b/src/target/mips32.c index d9d8ba9..5260032 100644 --- a/src/target/mips32.c +++ b/src/target/mips32.c @@ -905,11 +905,11 @@ cleanup: return 1; /* only one block has been checked */ } -static int mips32_verify_pointer(struct command_context *cmd_ctx, +static int mips32_verify_pointer(struct command_invocation *cmd, struct mips32_common *mips32) { if (mips32->common_magic != MIPS32_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an MIPS32"); + command_print(cmd, "target is not an MIPS32"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -927,12 +927,12 @@ COMMAND_HANDLER(mips32_handle_cp0_command) struct mips_ejtag *ejtag_info = &mips32->ejtag_info; - retval = mips32_verify_pointer(CMD_CTX, mips32); + retval = mips32_verify_pointer(CMD, mips32); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -949,12 +949,12 @@ COMMAND_HANDLER(mips32_handle_cp0_command) retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, cp0_reg); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } else if (CMD_ARGC == 3) { @@ -962,12 +962,12 @@ COMMAND_HANDLER(mips32_handle_cp0_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value); retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access cp0 reg %" PRIi32 ", select %" PRIi32, cp0_reg, cp0_sel); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } } @@ -986,13 +986,13 @@ COMMAND_HANDLER(mips32_handle_scan_delay_command) else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "scan delay: %d nsec", ejtag_info->scan_delay); + command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay); if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) { ejtag_info->mode = 0; - command_print(CMD_CTX, "running in legacy mode"); + command_print(CMD, "running in legacy mode"); } else { ejtag_info->mode = 1; - command_print(CMD_CTX, "running in fast queued mode"); + command_print(CMD, "running in fast queued mode"); } return ERROR_OK; diff --git a/src/target/mips_m4k.c b/src/target/mips_m4k.c index 653d732..ad27520 100644 --- a/src/target/mips_m4k.c +++ b/src/target/mips_m4k.c @@ -1270,11 +1270,11 @@ static int mips_m4k_bulk_write_memory(struct target *target, target_addr_t addre return retval; } -static int mips_m4k_verify_pointer(struct command_context *cmd_ctx, +static int mips_m4k_verify_pointer(struct command_invocation *cmd, struct mips_m4k_common *mips_m4k) { if (mips_m4k->common_magic != MIPSM4K_COMMON_MAGIC) { - command_print(cmd_ctx, "target is not an MIPS_M4K"); + command_print(cmd, "target is not an MIPS_M4K"); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -1287,12 +1287,12 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) struct mips_m4k_common *mips_m4k = target_to_m4k(target); struct mips_ejtag *ejtag_info = &mips_m4k->mips32.ejtag_info; - retval = mips_m4k_verify_pointer(CMD_CTX, mips_m4k); + retval = mips_m4k_verify_pointer(CMD, mips_m4k); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -1308,12 +1308,12 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) uint32_t value; retval = mips32_cp0_read(ejtag_info, &value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access reg %" PRIi32, cp0_reg); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } else if (CMD_ARGC == 3) { @@ -1321,12 +1321,12 @@ COMMAND_HANDLER(mips_m4k_handle_cp0_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], value); retval = mips32_cp0_write(ejtag_info, value, cp0_reg, cp0_sel); if (retval != ERROR_OK) { - command_print(CMD_CTX, + command_print(CMD, "couldn't access cp0 reg %" PRIi32 ", select %" PRIi32, cp0_reg, cp0_sel); return ERROR_OK; } - command_print(CMD_CTX, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, + command_print(CMD, "cp0 reg %" PRIi32 ", select %" PRIi32 ": %8.8" PRIx32, cp0_reg, cp0_sel, value); } } @@ -1345,13 +1345,13 @@ COMMAND_HANDLER(mips_m4k_handle_scan_delay_command) else if (CMD_ARGC > 1) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "scan delay: %d nsec", ejtag_info->scan_delay); + command_print(CMD, "scan delay: %d nsec", ejtag_info->scan_delay); if (ejtag_info->scan_delay >= MIPS32_SCAN_DELAY_LEGACY_MODE) { ejtag_info->mode = 0; - command_print(CMD_CTX, "running in legacy mode"); + command_print(CMD, "running in legacy mode"); } else { ejtag_info->mode = 1; - command_print(CMD_CTX, "running in fast queued mode"); + command_print(CMD, "running in fast queued mode"); } return ERROR_OK; diff --git a/src/target/nds32_cmd.c b/src/target/nds32_cmd.c index 500651d..1accf6f 100644 --- a/src/target/nds32_cmd.c +++ b/src/target/nds32_cmd.c @@ -46,7 +46,7 @@ COMMAND_HANDLER(handle_nds32_dssim_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -57,7 +57,7 @@ COMMAND_HANDLER(handle_nds32_dssim_command) nds32->step_isr_enable = false; } - command_print(CMD_CTX, "%s: $INT_MASK.DSSIM: %d", target_name(target), + command_print(CMD, "%s: $INT_MASK.DSSIM: %d", target_name(target), nds32->step_isr_enable); return ERROR_OK; @@ -71,7 +71,7 @@ COMMAND_HANDLER(handle_nds32_memory_access_command) struct nds32_memory *memory = &(nds32->memory); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -88,7 +88,7 @@ COMMAND_HANDLER(handle_nds32_memory_access_command) aice_memory_access(aice, memory->access_channel); } else { - command_print(CMD_CTX, "%s: memory access channel: %s", + command_print(CMD, "%s: memory access channel: %s", target_name(target), NDS_MEMORY_ACCESS_NAME[memory->access_channel]); } @@ -103,18 +103,18 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) struct aice_port_s *aice = target_to_aice(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (nds32->edm.access_control == false) { - command_print(CMD_CTX, "%s does not support ACC_CTL. " + command_print(CMD, "%s does not support ACC_CTL. " "Set memory mode to MEMORY", target_name(target)); nds32->memory.mode = NDS_MEMORY_SELECT_MEM; } else if (nds32->edm.direct_access_local_memory == false) { - command_print(CMD_CTX, "%s does not support direct access " + command_print(CMD, "%s does not support direct access " "local memory. Set memory mode to MEMORY", target_name(target)); nds32->memory.mode = NDS_MEMORY_SELECT_MEM; @@ -128,13 +128,13 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) nds32->memory.mode = NDS_MEMORY_SELECT_MEM; } else if (strcmp(CMD_ARGV[0], "ilm") == 0) { if (nds32->memory.ilm_base == 0) - command_print(CMD_CTX, "%s does not support ILM", + command_print(CMD, "%s does not support ILM", target_name(target)); else nds32->memory.mode = NDS_MEMORY_SELECT_ILM; } else if (strcmp(CMD_ARGV[0], "dlm") == 0) { if (nds32->memory.dlm_base == 0) - command_print(CMD_CTX, "%s does not support DLM", + command_print(CMD, "%s does not support DLM", target_name(target)); else nds32->memory.mode = NDS_MEMORY_SELECT_DLM; @@ -145,7 +145,7 @@ COMMAND_HANDLER(handle_nds32_memory_mode_command) } } - command_print(CMD_CTX, "%s: memory mode: %s", + command_print(CMD, "%s: memory mode: %s", target_name(target), NDS_MEMORY_SELECT_NAME[nds32->memory.mode]); @@ -162,7 +162,7 @@ COMMAND_HANDLER(handle_nds32_cache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -173,30 +173,30 @@ COMMAND_HANDLER(handle_nds32_cache_command) /* D$ write back */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Write back data cache...failed", + command_print(CMD, "%s: Write back data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Write back data cache...done", + command_print(CMD, "%s: Write back data cache...done", target_name(target)); /* D$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate data cache...failed", + command_print(CMD, "%s: Invalidate data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate data cache...done", + command_print(CMD, "%s: Invalidate data cache...done", target_name(target)); } else { if (dcache->line_size == 0) - command_print(CMD_CTX, "%s: No data cache", + command_print(CMD, "%s: No data cache", target_name(target)); else - command_print(CMD_CTX, "%s: Data cache disabled", + command_print(CMD, "%s: Data cache disabled", target_name(target)); } @@ -204,23 +204,23 @@ COMMAND_HANDLER(handle_nds32_cache_command) /* I$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate instruction cache...failed", + command_print(CMD, "%s: Invalidate instruction cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate instruction cache...done", + command_print(CMD, "%s: Invalidate instruction cache...done", target_name(target)); } else { if (icache->line_size == 0) - command_print(CMD_CTX, "%s: No instruction cache", + command_print(CMD, "%s: No instruction cache", target_name(target)); else - command_print(CMD_CTX, "%s: Instruction cache disabled", + command_print(CMD, "%s: Instruction cache disabled", target_name(target)); } } else - command_print(CMD_CTX, "No valid parameter"); + command_print(CMD, "No valid parameter"); } return ERROR_OK; @@ -235,14 +235,14 @@ COMMAND_HANDLER(handle_nds32_icache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (icache->line_size == 0) { - command_print(CMD_CTX, "%s: No instruction cache", + command_print(CMD, "%s: No instruction cache", target_name(target)); return ERROR_OK; } @@ -252,15 +252,15 @@ COMMAND_HANDLER(handle_nds32_icache_command) /* I$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1I_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate instruction cache...failed", + command_print(CMD, "%s: Invalidate instruction cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate instruction cache...done", + command_print(CMD, "%s: Invalidate instruction cache...done", target_name(target)); } else { - command_print(CMD_CTX, "%s: Instruction cache disabled", + command_print(CMD, "%s: Instruction cache disabled", target_name(target)); } } else if (strcmp(CMD_ARGV[0], "enable") == 0) { @@ -274,7 +274,7 @@ COMMAND_HANDLER(handle_nds32_icache_command) } else if (strcmp(CMD_ARGV[0], "dump") == 0) { /* TODO: dump cache content */ } else { - command_print(CMD_CTX, "%s: No valid parameter", target_name(target)); + command_print(CMD, "%s: No valid parameter", target_name(target)); } } @@ -290,14 +290,14 @@ COMMAND_HANDLER(handle_nds32_dcache_command) int result; if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } if (CMD_ARGC > 0) { if (dcache->line_size == 0) { - command_print(CMD_CTX, "%s: No data cache", target_name(target)); + command_print(CMD, "%s: No data cache", target_name(target)); return ERROR_OK; } @@ -306,26 +306,26 @@ COMMAND_HANDLER(handle_nds32_dcache_command) /* D$ write back */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_WBALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Write back data cache...failed", + command_print(CMD, "%s: Write back data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Write back data cache...done", + command_print(CMD, "%s: Write back data cache...done", target_name(target)); /* D$ invalidate */ result = aice_cache_ctl(aice, AICE_CACHE_CTL_L1D_INVALALL, 0); if (result != ERROR_OK) { - command_print(CMD_CTX, "%s: Invalidate data cache...failed", + command_print(CMD, "%s: Invalidate data cache...failed", target_name(target)); return result; } - command_print(CMD_CTX, "%s: Invalidate data cache...done", + command_print(CMD, "%s: Invalidate data cache...done", target_name(target)); } else { - command_print(CMD_CTX, "%s: Data cache disabled", + command_print(CMD, "%s: Data cache disabled", target_name(target)); } } else if (strcmp(CMD_ARGV[0], "enable") == 0) { @@ -339,7 +339,7 @@ COMMAND_HANDLER(handle_nds32_dcache_command) } else if (strcmp(CMD_ARGV[0], "dump") == 0) { /* TODO: dump cache content */ } else { - command_print(CMD_CTX, "%s: No valid parameter", target_name(target)); + command_print(CMD, "%s: No valid parameter", target_name(target)); } } @@ -352,7 +352,7 @@ COMMAND_HANDLER(handle_nds32_auto_break_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -364,10 +364,10 @@ COMMAND_HANDLER(handle_nds32_auto_break_command) } if (nds32->auto_convert_hw_bp) - command_print(CMD_CTX, "%s: convert sw break to hw break on ROM: on", + command_print(CMD, "%s: convert sw break to hw break on ROM: on", target_name(target)); else - command_print(CMD_CTX, "%s: convert sw break to hw break on ROM: off", + command_print(CMD, "%s: convert sw break to hw break on ROM: off", target_name(target)); return ERROR_OK; @@ -379,7 +379,7 @@ COMMAND_HANDLER(handle_nds32_virtual_hosting_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -391,9 +391,9 @@ COMMAND_HANDLER(handle_nds32_virtual_hosting_command) } if (nds32->virtual_hosting) - command_print(CMD_CTX, "%s: virtual hosting: on", target_name(target)); + command_print(CMD, "%s: virtual hosting: on", target_name(target)); else - command_print(CMD_CTX, "%s: virtual hosting: off", target_name(target)); + command_print(CMD, "%s: virtual hosting: off", target_name(target)); return ERROR_OK; } @@ -404,7 +404,7 @@ COMMAND_HANDLER(handle_nds32_global_stop_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -429,7 +429,7 @@ COMMAND_HANDLER(handle_nds32_soft_reset_halt_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -454,7 +454,7 @@ COMMAND_HANDLER(handle_nds32_boot_time_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -470,7 +470,7 @@ COMMAND_HANDLER(handle_nds32_login_edm_passcode_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -485,7 +485,7 @@ COMMAND_HANDLER(handle_nds32_login_edm_operation_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -516,7 +516,7 @@ COMMAND_HANDLER(handle_nds32_reset_halt_as_init_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -536,7 +536,7 @@ COMMAND_HANDLER(handle_nds32_keep_target_edm_ctl_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -556,7 +556,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -581,7 +581,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) read_addr, &instruction)) return ERROR_FAIL; - command_print(CMD_CTX, "%s", instruction.text); + command_print(CMD, "%s", instruction.text); read_addr += instruction.instruction_size; i++; @@ -599,7 +599,7 @@ COMMAND_HANDLER(handle_nds32_decode_command) if (ERROR_OK != nds32_evaluate_opcode(nds32, opcode, addr, &instruction)) return ERROR_FAIL; - command_print(CMD_CTX, "%s", instruction.text); + command_print(CMD, "%s", instruction.text); } else return ERROR_FAIL; @@ -612,7 +612,7 @@ COMMAND_HANDLER(handle_nds32_word_access_mem_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -632,11 +632,11 @@ COMMAND_HANDLER(handle_nds32_query_target_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } - command_print(CMD_CTX, "OCD"); + command_print(CMD, "OCD"); return ERROR_OK; } @@ -647,7 +647,7 @@ COMMAND_HANDLER(handle_nds32_query_endian_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } @@ -655,9 +655,9 @@ COMMAND_HANDLER(handle_nds32_query_endian_command) nds32_get_mapped_reg(nds32, IR0, &value_psw); if (value_psw & 0x20) - command_print(CMD_CTX, "%s: BE", target_name(target)); + command_print(CMD, "%s: BE", target_name(target)); else - command_print(CMD_CTX, "%s: LE", target_name(target)); + command_print(CMD, "%s: LE", target_name(target)); return ERROR_OK; } @@ -668,11 +668,11 @@ COMMAND_HANDLER(handle_nds32_query_cpuid_command) struct nds32 *nds32 = target_to_nds32(target); if (!is_nds32(nds32)) { - command_print(CMD_CTX, "current target isn't an Andes core"); + command_print(CMD, "current target isn't an Andes core"); return ERROR_FAIL; } - command_print(CMD_CTX, "CPUID: %s", target_name(target)); + command_print(CMD, "CPUID: %s", target_name(target)); return ERROR_OK; } diff --git a/src/target/oocd_trace.c b/src/target/oocd_trace.c index 627366d..f38916a 100644 --- a/src/target/oocd_trace.c +++ b/src/target/oocd_trace.c @@ -277,7 +277,7 @@ COMMAND_HANDLER(handle_oocd_trace_config_command) target = get_current_target(CMD_CTX); arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } @@ -306,17 +306,17 @@ COMMAND_HANDLER(handle_oocd_trace_status_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (!arm->etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + 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_CTX, "current target's ETM capture driver isn't 'oocd_trace'"); + command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); return ERROR_FAIL; } @@ -325,9 +325,9 @@ COMMAND_HANDLER(handle_oocd_trace_status_command) oocd_trace_read_reg(oocd_trace, OOCD_TRACE_STATUS, &status); if (status & 0x8) - command_print(CMD_CTX, "trace clock locked"); + command_print(CMD, "trace clock locked"); else - command_print(CMD_CTX, "no trace clock"); + command_print(CMD, "no trace clock"); return ERROR_OK; } @@ -344,17 +344,17 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command) arm = target_to_arm(target); if (!is_arm(arm)) { - command_print(CMD_CTX, "current target isn't an ARM"); + command_print(CMD, "current target isn't an ARM"); return ERROR_FAIL; } if (!arm->etm) { - command_print(CMD_CTX, "current target doesn't have an ETM configured"); + 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_CTX, "current target's ETM capture driver isn't 'oocd_trace'"); + command_print(CMD, "current target's ETM capture driver isn't 'oocd_trace'"); return ERROR_FAIL; } @@ -366,7 +366,7 @@ COMMAND_HANDLER(handle_oocd_trace_resync_command) if (bytes_written < 1) return ERROR_FAIL; - command_print(CMD_CTX, "requesting traceclock resync"); + command_print(CMD, "requesting traceclock resync"); LOG_DEBUG("resyncing traceclk pll"); return ERROR_OK; diff --git a/src/target/openrisc/or1k.c b/src/target/openrisc/or1k.c index 34b1b07..1e5db8c 100644 --- a/src/target/openrisc/or1k.c +++ b/src/target/openrisc/or1k.c @@ -1291,7 +1291,7 @@ COMMAND_HANDLER(or1k_tap_list_command_handler) list_for_each_entry(or1k_tap, &tap_list, list) { if (or1k_tap->name) - command_print(CMD_CTX, "%s", or1k_tap->name); + command_print(CMD, "%s", or1k_tap->name); } return ERROR_OK; @@ -1339,7 +1339,7 @@ COMMAND_HANDLER(or1k_du_list_command_handler) list_for_each_entry(or1k_du, &du_list, list) { if (or1k_du->name) - command_print(CMD_CTX, "%s", or1k_du->name); + command_print(CMD, "%s", or1k_du->name); } return ERROR_OK; @@ -1374,28 +1374,28 @@ COMMAND_HANDLER(or1k_addreg_command_handler) static const struct command_registration or1k_hw_ip_command_handlers[] = { { - "tap_select", + .name = "tap_select", .handler = or1k_tap_select_command_handler, .mode = COMMAND_ANY, .usage = "tap_select name", .help = "Select the TAP core to use", }, { - "tap_list", + .name = "tap_list", .handler = or1k_tap_list_command_handler, .mode = COMMAND_ANY, .usage = "tap_list", .help = "Display available TAP core", }, { - "du_select", + .name = "du_select", .handler = or1k_du_select_command_handler, .mode = COMMAND_ANY, .usage = "du_select name", .help = "Select the Debug Unit core to use", }, { - "du_list", + .name = "du_list", .handler = or1k_du_list_command_handler, .mode = COMMAND_ANY, .usage = "select_tap name", @@ -1406,7 +1406,7 @@ static const struct command_registration or1k_hw_ip_command_handlers[] = { static const struct command_registration or1k_reg_command_handlers[] = { { - "addreg", + .name = "addreg", .handler = or1k_addreg_command_handler, .mode = COMMAND_ANY, .usage = "addreg name addr feature group", diff --git a/src/target/riscv/riscv.c b/src/target/riscv/riscv.c index 0c9b84c..6392774 100644 --- a/src/target/riscv/riscv.c +++ b/src/target/riscv/riscv.c @@ -455,16 +455,8 @@ static int riscv_init_target(struct command_context *cmd_ctx, return ERROR_OK; } -static void riscv_deinit_target(struct target *target) +static void riscv_free_registers(struct target *target) { - LOG_DEBUG("riscv_deinit_target()"); - struct target_type *tt = get_target_type(target); - if (tt) { - tt->deinit_target(target); - riscv_info_t *info = (riscv_info_t *) target->arch_info; - free(info->reg_names); - free(info); - } /* Free the shared structure use for most registers. */ if (target->reg_cache) { if (target->reg_cache->reg_list) { @@ -477,6 +469,21 @@ static void riscv_deinit_target(struct target *target) } free(target->reg_cache); } +} + +static void riscv_deinit_target(struct target *target) +{ + LOG_DEBUG("riscv_deinit_target()"); + struct target_type *tt = get_target_type(target); + if (tt) { + tt->deinit_target(target); + riscv_info_t *info = (riscv_info_t *) target->arch_info; + free(info->reg_names); + free(info); + } + + riscv_free_registers(target); + target->arch_info = NULL; } @@ -2046,7 +2053,7 @@ COMMAND_HANDLER(riscv_authdata_read) uint32_t value; if (r->authdata_read(target, &value) != ERROR_OK) return ERROR_FAIL; - command_print(CMD_CTX, "0x%" PRIx32, value); + command_print(CMD, "0x%" PRIx32, value); return ERROR_OK; } else { LOG_ERROR("authdata_read is not implemented for this target."); @@ -2099,7 +2106,7 @@ COMMAND_HANDLER(riscv_dmi_read) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], address); if (r->dmi_read(target, &value, address) != ERROR_OK) return ERROR_FAIL; - command_print(CMD_CTX, "0x%" PRIx32, value); + command_print(CMD, "0x%" PRIx32, value); return ERROR_OK; } else { LOG_ERROR("dmi_read is not implemented for this target."); @@ -2402,28 +2409,28 @@ extern __COMMAND_HANDLER(handle_common_semihosting_cmdline); */ static const struct command_registration arm_exec_command_handlers[] = { { - "semihosting", + .name = "semihosting", .handler = handle_common_semihosting_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting operations", }, { - "semihosting_cmdline", + .name = "semihosting_cmdline", .handler = handle_common_semihosting_cmdline, .mode = COMMAND_EXEC, .usage = "arguments", .help = "command line arguments to be passed to program", }, { - "semihosting_fileio", + .name = "semihosting_fileio", .handler = handle_common_semihosting_fileio_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", .help = "activate support for semihosting fileio operations", }, { - "semihosting_resexit", + .name = "semihosting_resexit", .handler = handle_common_semihosting_resumable_exit_command, .mode = COMMAND_EXEC, .usage = "['enable'|'disable']", @@ -3065,11 +3072,7 @@ int riscv_init_registers(struct target *target) { RISCV_INFO(info); - if (target->reg_cache) { - if (target->reg_cache->reg_list) - free(target->reg_cache->reg_list); - free(target->reg_cache); - } + riscv_free_registers(target); target->reg_cache = calloc(1, sizeof(*target->reg_cache)); target->reg_cache->name = "RISC-V Registers"; diff --git a/src/target/semihosting_common.c b/src/target/semihosting_common.c index 5920789..ce6a791 100644 --- a/src/target/semihosting_common.c +++ b/src/target/semihosting_common.c @@ -1470,7 +1470,7 @@ __COMMAND_HANDLER(handle_common_semihosting_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } @@ -1493,7 +1493,7 @@ __COMMAND_HANDLER(handle_common_semihosting_command) semihosting->is_active = is_active; } - command_print(CMD_CTX, "semihosting is %s", + command_print(CMD, "semihosting is %s", semihosting->is_active ? "enabled" : "disabled"); @@ -1512,19 +1512,19 @@ __COMMAND_HANDLER(handle_common_semihosting_fileio_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } if (!semihosting->is_active) { - command_print(CMD_CTX, "semihosting not yet enabled for current target"); + command_print(CMD, "semihosting not yet enabled for current target"); return ERROR_FAIL; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], semihosting->is_fileio); - command_print(CMD_CTX, "semihosting fileio is %s", + command_print(CMD, "semihosting fileio is %s", semihosting->is_fileio ? "enabled" : "disabled"); @@ -1543,7 +1543,7 @@ __COMMAND_HANDLER(handle_common_semihosting_cmdline) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } @@ -1558,7 +1558,7 @@ __COMMAND_HANDLER(handle_common_semihosting_cmdline) semihosting->cmdline = cmdline; } - command_print(CMD_CTX, "semihosting command line is [%s]", + command_print(CMD, "semihosting command line is [%s]", semihosting->cmdline); return ERROR_OK; @@ -1575,19 +1575,19 @@ __COMMAND_HANDLER(handle_common_semihosting_resumable_exit_command) struct semihosting *semihosting = target->semihosting; if (!semihosting) { - command_print(CMD_CTX, "semihosting not supported for current target"); + command_print(CMD, "semihosting not supported for current target"); return ERROR_FAIL; } if (!semihosting->is_active) { - command_print(CMD_CTX, "semihosting not yet enabled for current target"); + command_print(CMD, "semihosting not yet enabled for current target"); return ERROR_FAIL; } if (CMD_ARGC > 0) COMMAND_PARSE_ENABLE(CMD_ARGV[0], semihosting->has_resumable_exit); - command_print(CMD_CTX, "semihosting resumable exit is %s", + command_print(CMD, "semihosting resumable exit is %s", semihosting->has_resumable_exit ? "enabled" : "disabled"); diff --git a/src/target/smp.c b/src/target/smp.c index f42d8ab..acd4628 100644 --- a/src/target/smp.c +++ b/src/target/smp.c @@ -106,7 +106,7 @@ COMMAND_HANDLER(default_handle_smp_command) return ERROR_COMMAND_SYNTAX_ERROR; if (!CMD_ARGC) { - command_print(CMD_CTX, "%s", target->smp ? "on" : "off"); + command_print(CMD, "%s", target->smp ? "on" : "off"); return ERROR_OK; } @@ -166,7 +166,7 @@ COMMAND_HANDLER(handle_smp_gdb_command) target->gdb_service->core[1] = coreid; } - command_print(CMD_CTX, "gdb coreid %" PRId32 " -> %" PRId32, target->gdb_service->core[0] + command_print(CMD, "gdb coreid %" PRId32 " -> %" PRId32, target->gdb_service->core[0] , target->gdb_service->core[1]); } return ERROR_OK; diff --git a/src/target/stm8.c b/src/target/stm8.c index b62ff13..fcfc170 100644 --- a/src/target/stm8.c +++ b/src/target/stm8.c @@ -2147,7 +2147,7 @@ COMMAND_HANDLER(stm8_handle_enable_step_irq_command) stm8->enable_step_irq = enable; } msg = stm8->enable_step_irq ? "enabled" : "disabled"; - command_print(CMD_CTX, "enable_step_irq = %s", msg); + command_print(CMD, "enable_step_irq = %s", msg); return ERROR_OK; } @@ -2163,7 +2163,7 @@ COMMAND_HANDLER(stm8_handle_enable_stm8l_command) stm8->enable_stm8l = enable; } msg = stm8->enable_stm8l ? "enabled" : "disabled"; - command_print(CMD_CTX, "enable_stm8l = %s", msg); + command_print(CMD, "enable_stm8l = %s", msg); stm8_init_flash_regs(stm8->enable_stm8l, stm8); return ERROR_OK; } diff --git a/src/target/target.c b/src/target/target.c index 36e63f9..cec46cc 100644 --- a/src/target/target.c +++ b/src/target/target.c @@ -375,12 +375,6 @@ uint16_t target_buffer_get_u16(struct target *target, const uint8_t *buffer) return be_to_h_u16(buffer); } -/* read a uint8_t from a buffer in target memory endianness */ -static uint8_t target_buffer_get_u8(struct target *target, const uint8_t *buffer) -{ - return *buffer & 0x0ff; -} - /* write a uint64_t to a buffer in target memory endianness */ void target_buffer_set_u64(struct target *target, uint8_t *buffer, uint64_t value) { @@ -640,7 +634,7 @@ int target_resume(struct target *target, int current, target_addr_t address, return retval; } -static int target_process_reset(struct command_context *cmd_ctx, enum target_reset_mode reset_mode) +static int target_process_reset(struct command_invocation *cmd, enum target_reset_mode reset_mode) { char buf[100]; int retval; @@ -664,13 +658,13 @@ static int target_process_reset(struct command_context *cmd_ctx, enum target_res jtag_poll_set_enabled(false); sprintf(buf, "ocd_process_reset %s", n->name); - retval = Jim_Eval(cmd_ctx->interp, buf); + retval = Jim_Eval(cmd->ctx->interp, buf); jtag_poll_set_enabled(save_poll); if (retval != JIM_OK) { - Jim_MakeErrorMessage(cmd_ctx->interp); - command_print(NULL, "%s\n", Jim_GetString(Jim_GetResult(cmd_ctx->interp), NULL)); + Jim_MakeErrorMessage(cmd->ctx->interp); + command_print(cmd, "%s", Jim_GetString(Jim_GetResult(cmd->ctx->interp), NULL)); return ERROR_FAIL; } @@ -1221,7 +1215,24 @@ int target_get_gdb_reg_list(struct target *target, struct reg **reg_list[], int *reg_list_size, enum target_register_class reg_class) { - return target->type->get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); + int result = target->type->get_gdb_reg_list(target, reg_list, + reg_list_size, reg_class); + if (result != ERROR_OK) { + *reg_list = NULL; + *reg_list_size = 0; + } + return result; +} + +int target_get_gdb_reg_list_noread(struct target *target, + struct reg **reg_list[], int *reg_list_size, + enum target_register_class reg_class) +{ + if (target->type->get_gdb_reg_list_noread && + target->type->get_gdb_reg_list_noread(target, reg_list, + reg_list_size, reg_class) == ERROR_OK) + return ERROR_OK; + return target_get_gdb_reg_list(target, reg_list, reg_list_size, reg_class); } int target_get_gdb_reg_list_noread(struct target *target, @@ -1604,9 +1615,9 @@ int target_call_event_callbacks(struct target *target, enum target_event event) target_call_event_callbacks(target, TARGET_EVENT_GDB_HALT); } - LOG_DEBUG("target event %i (%s) for core %d", event, + LOG_DEBUG("target event %i (%s) for core %s", event, Jim_Nvp_value2name_simple(nvp_target_event, event)->name, - target->coreid); + target_name(target)); target_handle_event(target, event); @@ -2590,23 +2601,23 @@ int target_write_phys_u8(struct target *target, target_addr_t address, uint8_t v return retval; } -static int find_target(struct command_context *cmd_ctx, const char *name) +static int find_target(struct command_invocation *cmd, const char *name) { struct target *target = get_target(name); if (target == NULL) { - LOG_ERROR("Target: %s is unknown, try one of:\n", name); + command_print(cmd, "Target: %s is unknown, try one of:\n", name); return ERROR_FAIL; } if (!target->tap->enabled) { - LOG_USER("Target: TAP %s is disabled, " + command_print(cmd, "Target: TAP %s is disabled, " "can't be the current target\n", target->tap->dotted_name); return ERROR_FAIL; } - cmd_ctx->current_target = target; - if (cmd_ctx->current_target_override) - cmd_ctx->current_target_override = target; + cmd->ctx->current_target = target; + if (cmd->ctx->current_target_override) + cmd->ctx->current_target_override = target; return ERROR_OK; } @@ -2616,7 +2627,7 @@ COMMAND_HANDLER(handle_targets_command) { int retval = ERROR_OK; if (CMD_ARGC == 1) { - retval = find_target(CMD_CTX, CMD_ARGV[0]); + retval = find_target(CMD, CMD_ARGV[0]); if (retval == ERROR_OK) { /* we're done! */ return retval; @@ -2624,8 +2635,8 @@ COMMAND_HANDLER(handle_targets_command) } struct target *target = all_targets; - command_print(CMD_CTX, " TargetName Type Endian TapName State "); - command_print(CMD_CTX, "-- ------------------ ---------- ------ ------------------ ------------"); + command_print(CMD, " TargetName Type Endian TapName State "); + command_print(CMD, "-- ------------------ ---------- ------ ------------------ ------------"); while (target) { const char *state; char marker = ' '; @@ -2639,7 +2650,7 @@ COMMAND_HANDLER(handle_targets_command) marker = '*'; /* keep columns lined up to match the headers above */ - command_print(CMD_CTX, + command_print(CMD, "%2d%c %-18s %-10s %-6s %-18s %s", target->target_number, marker, @@ -2850,7 +2861,7 @@ COMMAND_HANDLER(handle_reg_command) while (cache) { unsigned i; - command_print(CMD_CTX, "===== %s", cache->name); + command_print(CMD, "===== %s", cache->name); for (i = 0, reg = cache->reg_list; i < cache->num_regs; @@ -2904,7 +2915,7 @@ COMMAND_HANDLER(handle_reg_command) } if (!reg) { - command_print(CMD_CTX, "%i is out of bounds, the current target " + command_print(CMD, "%i is out of bounds, the current target " "has only %i registers (0 - %i)", num, count, count - 1); return ERROR_OK; } @@ -2935,7 +2946,7 @@ COMMAND_HANDLER(handle_reg_command) } } value = buf_to_str(reg->value, reg->size, 16); - command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); + command_print(CMD, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); return ERROR_OK; } @@ -2955,7 +2966,7 @@ COMMAND_HANDLER(handle_reg_command) } value = buf_to_str(reg->value, reg->size, 16); - command_print(CMD_CTX, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); + command_print(CMD, "%s (/%i): 0x%s", reg->name, (int)(reg->size), value); free(value); free(buf); @@ -2966,7 +2977,7 @@ COMMAND_HANDLER(handle_reg_command) return ERROR_COMMAND_SYNTAX_ERROR; not_found: - command_print(CMD_CTX, "register %s not found in current target", CMD_ARGV[0]); + command_print(CMD, "register %s not found in current target", CMD_ARGV[0]); return ERROR_OK; } @@ -2976,9 +2987,9 @@ COMMAND_HANDLER(handle_poll_command) struct target *target = get_current_target(CMD_CTX); if (CMD_ARGC == 0) { - command_print(CMD_CTX, "background polling: %s", + command_print(CMD, "background polling: %s", jtag_poll_get_enabled() ? "on" : "off"); - command_print(CMD_CTX, "TAP: %s (%s)", + command_print(CMD, "TAP: %s (%s)", target->tap->dotted_name, target->tap->enabled ? "enabled" : "disabled"); if (!target->tap->enabled) @@ -3104,7 +3115,7 @@ COMMAND_HANDLER(handle_reset_command) } /* reset *all* targets */ - return target_process_reset(CMD_CTX, reset_mode); + return target_process_reset(CMD, reset_mode); } @@ -3150,7 +3161,7 @@ COMMAND_HANDLER(handle_step_command) return target->type->step(target, current_pc, addr, 1); } -static void handle_md_output(struct command_context *cmd_ctx, +void target_handle_md_output(struct command_invocation *cmd, struct target *target, target_addr_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -3208,7 +3219,7 @@ static void handle_md_output(struct command_context *cmd_ctx, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); + command_print(cmd, "%s", output); output_len = 0; } } @@ -3265,7 +3276,7 @@ COMMAND_HANDLER(handle_md_command) struct target *target = get_current_target(CMD_CTX); int retval = fn(target, address, size, count, buffer); if (ERROR_OK == retval) - handle_md_output(CMD_CTX, target, address, size, count, buffer); + target_handle_md_output(CMD, target, address, size, count, buffer); free(buffer); @@ -3438,7 +3449,7 @@ COMMAND_HANDLER(handle_load_image_command) for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); retval = ERROR_FAIL; @@ -3475,7 +3486,7 @@ COMMAND_HANDLER(handle_load_image_command) break; } image_size += length; - command_print(CMD_CTX, "%u bytes written at address " TARGET_ADDR_FMT "", + command_print(CMD, "%u bytes written at address " TARGET_ADDR_FMT "", (unsigned int)length, image.sections[i].base_address + offset); } @@ -3484,7 +3495,7 @@ COMMAND_HANDLER(handle_load_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "downloaded %" PRIu32 " bytes " + command_print(CMD, "downloaded %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); } @@ -3545,7 +3556,7 @@ COMMAND_HANDLER(handle_dump_image_command) retval = fileio_size(fileio, &filesize); if (retval != ERROR_OK) return retval; - command_print(CMD_CTX, + command_print(CMD, "dumped %zu bytes in %fs (%0.3f KiB/s)", filesize, duration_elapsed(&bench), duration_kbps(&bench, filesize)); } @@ -3610,7 +3621,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); break; @@ -3661,14 +3672,14 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver uint32_t t; for (t = 0; t < buf_cnt; t++) { if (data[t] != buffer[t]) { - command_print(CMD_CTX, + command_print(CMD, "diff %d address 0x%08x. Was 0x%02x instead of 0x%02x", diffs, (unsigned)(t + image.sections[i].base_address), data[t], buffer[t]); if (diffs++ >= 127) { - command_print(CMD_CTX, "More than 128 errors, the rest are not printed."); + command_print(CMD, "More than 128 errors, the rest are not printed."); free(data); free(buffer); goto done; @@ -3680,7 +3691,7 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver free(data); } } else { - command_print(CMD_CTX, "address " TARGET_ADDR_FMT " length 0x%08zx", + command_print(CMD, "address " TARGET_ADDR_FMT " length 0x%08zx", image.sections[i].base_address, buf_cnt); } @@ -3689,12 +3700,12 @@ static COMMAND_HELPER(handle_verify_image_command_internal, enum verify_mode ver image_size += buf_cnt; } if (diffs > 0) - command_print(CMD_CTX, "No more differences found."); + command_print(CMD, "No more differences found."); done: if (diffs > 0) retval = ERROR_FAIL; if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "verified %" PRIu32 " bytes " + command_print(CMD, "verified %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); } @@ -3719,32 +3730,32 @@ COMMAND_HANDLER(handle_test_image_command) return CALL_COMMAND_HANDLER(handle_verify_image_command_internal, IMAGE_TEST); } -static int handle_bp_command_list(struct command_context *cmd_ctx) +static int handle_bp_command_list(struct command_invocation *cmd) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); struct breakpoint *breakpoint = target->breakpoints; while (breakpoint) { if (breakpoint->type == BKPT_SOFT) { char *buf = buf_to_str(breakpoint->orig_instr, breakpoint->length, 16); - command_print(cmd_ctx, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", + command_print(cmd, "IVA breakpoint: " TARGET_ADDR_FMT ", 0x%x, %i, 0x%s", breakpoint->address, breakpoint->length, breakpoint->set, buf); free(buf); } else { if ((breakpoint->address == 0) && (breakpoint->asid != 0)) - command_print(cmd_ctx, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", + command_print(cmd, "Context breakpoint: 0x%8.8" PRIx32 ", 0x%x, %i", breakpoint->asid, breakpoint->length, breakpoint->set); else if ((breakpoint->address != 0) && (breakpoint->asid != 0)) { - command_print(cmd_ctx, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd, "Hybrid breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); - command_print(cmd_ctx, "\t|--->linked with ContextID: 0x%8.8" PRIx32, + command_print(cmd, "\t|--->linked with ContextID: 0x%8.8" PRIx32, breakpoint->asid); } else - command_print(cmd_ctx, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", + command_print(cmd, "Breakpoint(IVA): " TARGET_ADDR_FMT ", 0x%x, %i", breakpoint->address, breakpoint->length, breakpoint->set); } @@ -3754,17 +3765,17 @@ static int handle_bp_command_list(struct command_context *cmd_ctx) return ERROR_OK; } -static int handle_bp_command_set(struct command_context *cmd_ctx, +static int handle_bp_command_set(struct command_invocation *cmd, target_addr_t addr, uint32_t asid, uint32_t length, int hw) { - struct target *target = get_current_target(cmd_ctx); + struct target *target = get_current_target(cmd->ctx); int retval; if (asid == 0) { retval = breakpoint_add(target, addr, length, hw); /* error is always logged in breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "breakpoint set at " TARGET_ADDR_FMT "", addr); + command_print(cmd, "breakpoint set at " TARGET_ADDR_FMT "", addr); } else if (addr == 0) { if (target->type->add_context_breakpoint == NULL) { @@ -3774,7 +3785,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, retval = context_breakpoint_add(target, asid, length, hw); /* error is always logged in context_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd, "Context breakpoint set at 0x%8.8" PRIx32 "", asid); } else { if (target->type->add_hybrid_breakpoint == NULL) { @@ -3784,7 +3795,7 @@ static int handle_bp_command_set(struct command_context *cmd_ctx, retval = hybrid_breakpoint_add(target, addr, asid, length, hw); /* error is always logged in hybrid_breakpoint_add(), do not print it again */ if (ERROR_OK == retval) - command_print(cmd_ctx, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); + command_print(cmd, "Hybrid breakpoint set at 0x%8.8" PRIx32 "", asid); } return retval; } @@ -3798,13 +3809,13 @@ COMMAND_HANDLER(handle_bp_command) switch (CMD_ARGC) { case 0: - return handle_bp_command_list(CMD_CTX); + return handle_bp_command_list(CMD); case 2: asid = 0; COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); case 3: if (strcmp(CMD_ARGV[2], "hw") == 0) { @@ -3812,13 +3823,13 @@ COMMAND_HANDLER(handle_bp_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); asid = 0; - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); } else if (strcmp(CMD_ARGV[2], "hw_ctx") == 0) { hw = BKPT_HARD; COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], asid); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], length); addr = 0; - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); } /* fallthrough */ case 4: @@ -3826,7 +3837,7 @@ COMMAND_HANDLER(handle_bp_command) COMMAND_PARSE_ADDRESS(CMD_ARGV[0], addr); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[1], asid); COMMAND_PARSE_NUMBER(u32, CMD_ARGV[2], length); - return handle_bp_command_set(CMD_CTX, addr, asid, length, hw); + return handle_bp_command_set(CMD, addr, asid, length, hw); default: return ERROR_COMMAND_SYNTAX_ERROR; @@ -3855,7 +3866,7 @@ COMMAND_HANDLER(handle_wp_command) struct watchpoint *watchpoint = target->watchpoints; while (watchpoint) { - command_print(CMD_CTX, "address: " TARGET_ADDR_FMT + command_print(CMD, "address: " TARGET_ADDR_FMT ", len: 0x%8.8" PRIx32 ", r/w/a: %i, value: 0x%8.8" PRIx32 ", mask: 0x%8.8" PRIx32, @@ -3947,7 +3958,7 @@ COMMAND_HANDLER(handle_virt2phys_command) struct target *target = get_current_target(CMD_CTX); int retval = target->type->virt2phys(target, va, &pa); if (retval == ERROR_OK) - command_print(CMD_CTX, "Physical address " TARGET_ADDR_FMT "", pa); + command_print(CMD, "Physical address " TARGET_ADDR_FMT "", pa); return retval; } @@ -4140,7 +4151,7 @@ COMMAND_HANDLER(handle_profile_command) write_gmon(samples, num_of_samples, CMD_ARGV[1], with_range, start_address, end_address, target, duration_ms); - command_print(CMD_CTX, "Wrote %s", CMD_ARGV[1]); + command_print(CMD, "Wrote %s", CMD_ARGV[1]); free(samples); return retval; @@ -4557,6 +4568,7 @@ static int target_array2mem(Jim_Interp *interp, struct target *target, void target_handle_event(struct target *target, enum target_event e) { struct target_event_action *teap; + int retval; for (teap = target->event_action; teap != NULL; teap = teap->next) { if (teap->event == e) { @@ -4575,10 +4587,19 @@ void target_handle_event(struct target *target, enum target_event e) struct command_context *cmd_ctx = current_command_context(teap->interp); struct target *saved_target_override = cmd_ctx->current_target_override; cmd_ctx->current_target_override = target; + retval = Jim_EvalObj(teap->interp, teap->body); - if (Jim_EvalObj(teap->interp, teap->body) != JIM_OK) { + if (retval == JIM_RETURN) + retval = teap->interp->returnCode; + + if (retval != JIM_OK) { Jim_MakeErrorMessage(teap->interp); - command_print(NULL, "%s\n", Jim_GetString(Jim_GetResult(teap->interp), NULL)); + LOG_USER("Error executing event %s on target %s:\n%s", + Jim_Nvp_value2name_simple(nvp_target_event, e)->name, + target_name(target), + Jim_GetString(Jim_GetResult(teap->interp), NULL)); + /* clean both error code and stacktrace before return */ + Jim_Eval(teap->interp, "error \"\" \"\""); } cmd_ctx->current_target_override = saved_target_override; @@ -4856,7 +4877,7 @@ no_params: if (goi->argc != 0) goto no_params; } - Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, target->working_area_size)); + Jim_SetResult(goi->interp, Jim_NewIntObj(goi->interp, target->coreid)); /* loop for more */ break; @@ -4919,6 +4940,12 @@ no_params: case TCFG_GDB_PORT: if (goi->isconfigure) { + struct command_context *cmd_ctx = current_command_context(goi->interp); + if (cmd_ctx->mode != COMMAND_CONFIG) { + Jim_SetResultString(goi->interp, "-gdb-port must be configured before 'init'", -1); + return JIM_ERR; + } + const char *s; e = Jim_GetOpt_String(goi, &s, NULL); if (e != JIM_OK) @@ -4954,228 +4981,6 @@ static int jim_target_configure(Jim_Interp *interp, int argc, Jim_Obj * const *a return target_configure(&goi, target); } -static int jim_target_mw(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - const char *cmd_name = Jim_GetString(argv[0], NULL); - - Jim_GetOptInfo goi; - Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); - - if (goi.argc < 2 || goi.argc > 4) { - Jim_SetResultFormatted(goi.interp, - "usage: %s [phys] <address> <data> [<count>]", cmd_name); - return JIM_ERR; - } - - target_write_fn fn; - fn = target_write_memory; - - int e; - if (strcmp(Jim_GetString(argv[1], NULL), "phys") == 0) { - /* consume it */ - struct Jim_Obj *obj; - e = Jim_GetOpt_Obj(&goi, &obj); - if (e != JIM_OK) - return e; - - fn = target_write_phys_memory; - } - - jim_wide a; - e = Jim_GetOpt_Wide(&goi, &a); - if (e != JIM_OK) - return e; - - jim_wide b; - e = Jim_GetOpt_Wide(&goi, &b); - if (e != JIM_OK) - return e; - - jim_wide c = 1; - if (goi.argc == 1) { - e = Jim_GetOpt_Wide(&goi, &c); - if (e != JIM_OK) - return e; - } - - /* all args must be consumed */ - if (goi.argc != 0) - return JIM_ERR; - - struct target *target = Jim_CmdPrivData(goi.interp); - unsigned data_size; - if (strcasecmp(cmd_name, "mww") == 0) - data_size = 4; - else if (strcasecmp(cmd_name, "mwh") == 0) - data_size = 2; - else if (strcasecmp(cmd_name, "mwb") == 0) - data_size = 1; - else { - LOG_ERROR("command '%s' unknown: ", cmd_name); - return JIM_ERR; - } - - return (target_fill_mem(target, a, fn, data_size, b, c) == ERROR_OK) ? JIM_OK : JIM_ERR; -} - -/** -* @brief Reads an array of words/halfwords/bytes from target memory starting at specified address. -* -* Usage: mdw [phys] <address> [<count>] - for 32 bit reads -* mdh [phys] <address> [<count>] - for 16 bit reads -* mdb [phys] <address> [<count>] - for 8 bit reads -* -* Count defaults to 1. -* -* Calls target_read_memory or target_read_phys_memory depending on -* the presence of the "phys" argument -* Reads the target memory in blocks of max. 32 bytes, and returns an array of ints formatted -* to int representation in base16. -* Also outputs read data in a human readable form using command_print -* -* @param phys if present target_read_phys_memory will be used instead of target_read_memory -* @param address address where to start the read. May be specified in decimal or hex using the standard "0x" prefix -* @param count optional count parameter to read an array of values. If not specified, defaults to 1. -* @returns: JIM_ERR on error or JIM_OK on success and sets the result string to an array of ascii formatted numbers -* on success, with [<count>] number of elements. -* -* In case of little endian target: -* Example1: "mdw 0x00000000" returns "10123456" -* Exmaple2: "mdh 0x00000000 1" returns "3456" -* Example3: "mdb 0x00000000" returns "56" -* Example4: "mdh 0x00000000 2" returns "3456 1012" -* Example5: "mdb 0x00000000 3" returns "56 34 12" -**/ -static int jim_target_md(Jim_Interp *interp, int argc, Jim_Obj *const *argv) -{ - const char *cmd_name = Jim_GetString(argv[0], NULL); - - Jim_GetOptInfo goi; - Jim_GetOpt_Setup(&goi, interp, argc - 1, argv + 1); - - if ((goi.argc < 1) || (goi.argc > 3)) { - Jim_SetResultFormatted(goi.interp, - "usage: %s [phys] <address> [<count>]", cmd_name); - return JIM_ERR; - } - - int (*fn)(struct target *target, - target_addr_t address, uint32_t size, uint32_t count, uint8_t *buffer); - fn = target_read_memory; - - int e; - if (strcmp(Jim_GetString(argv[1], NULL), "phys") == 0) { - /* consume it */ - struct Jim_Obj *obj; - e = Jim_GetOpt_Obj(&goi, &obj); - if (e != JIM_OK) - return e; - - fn = target_read_phys_memory; - } - - /* Read address parameter */ - jim_wide addr; - e = Jim_GetOpt_Wide(&goi, &addr); - if (e != JIM_OK) - return JIM_ERR; - - /* If next parameter exists, read it out as the count parameter, if not, set it to 1 (default) */ - jim_wide count; - if (goi.argc == 1) { - e = Jim_GetOpt_Wide(&goi, &count); - if (e != JIM_OK) - return JIM_ERR; - } else - count = 1; - - /* all args must be consumed */ - if (goi.argc != 0) - return JIM_ERR; - - jim_wide dwidth = 1; /* shut up gcc */ - if (strcasecmp(cmd_name, "mdw") == 0) - dwidth = 4; - else if (strcasecmp(cmd_name, "mdh") == 0) - dwidth = 2; - else if (strcasecmp(cmd_name, "mdb") == 0) - dwidth = 1; - else { - LOG_ERROR("command '%s' unknown: ", cmd_name); - return JIM_ERR; - } - - /* convert count to "bytes" */ - int bytes = count * dwidth; - - struct target *target = Jim_CmdPrivData(goi.interp); - uint8_t target_buf[32]; - jim_wide x, y, z; - while (bytes > 0) { - y = (bytes < 16) ? bytes : 16; /* y = min(bytes, 16); */ - - /* Try to read out next block */ - e = fn(target, addr, dwidth, y / dwidth, target_buf); - - if (e != ERROR_OK) { - Jim_SetResultFormatted(interp, "error reading target @ 0x%08lx", (long)addr); - return JIM_ERR; - } - - command_print_sameline(NULL, "0x%08x ", (int)(addr)); - switch (dwidth) { - case 4: - for (x = 0; x < 16 && x < y; x += 4) { - z = target_buffer_get_u32(target, &(target_buf[x])); - command_print_sameline(NULL, "%08x ", (int)(z)); - } - for (; (x < 16) ; x += 4) - command_print_sameline(NULL, " "); - break; - case 2: - for (x = 0; x < 16 && x < y; x += 2) { - z = target_buffer_get_u16(target, &(target_buf[x])); - command_print_sameline(NULL, "%04x ", (int)(z)); - } - for (; (x < 16) ; x += 2) - command_print_sameline(NULL, " "); - break; - case 1: - default: - for (x = 0 ; (x < 16) && (x < y) ; x += 1) { - z = target_buffer_get_u8(target, &(target_buf[x])); - command_print_sameline(NULL, "%02x ", (int)(z)); - } - for (; (x < 16) ; x += 1) - command_print_sameline(NULL, " "); - break; - } - /* ascii-ify the bytes */ - for (x = 0 ; x < y ; x++) { - if ((target_buf[x] >= 0x20) && - (target_buf[x] <= 0x7e)) { - /* good */ - } else { - /* smack it */ - target_buf[x] = '.'; - } - } - /* space pad */ - while (x < 16) { - target_buf[x] = ' '; - x++; - } - /* terminate */ - target_buf[16] = 0; - /* print - with a newline */ - command_print_sameline(NULL, "%s\n", target_buf); - /* NEXT... */ - bytes -= 16; - addr += 16; - } - return JIM_OK; -} - static int jim_target_mem2array(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { @@ -5389,27 +5194,25 @@ static int jim_target_wait_state(Jim_Interp *interp, int argc, Jim_Obj *const *a /* List for human, Events defined for this target. * scripts/programs should use 'name cget -event NAME' */ -static int jim_target_event_list(Jim_Interp *interp, int argc, Jim_Obj *const *argv) +COMMAND_HANDLER(handle_target_event_list) { - struct command_context *cmd_ctx = current_command_context(interp); - assert(cmd_ctx != NULL); - - struct target *target = Jim_CmdPrivData(interp); + struct target *target = get_current_target(CMD_CTX); struct target_event_action *teap = target->event_action; - command_print(cmd_ctx, "Event actions for target (%d) %s\n", + + command_print(CMD, "Event actions for target (%d) %s\n", target->target_number, target_name(target)); - command_print(cmd_ctx, "%-25s | Body", "Event"); - command_print(cmd_ctx, "------------------------- | " + command_print(CMD, "%-25s | Body", "Event"); + command_print(CMD, "------------------------- | " "----------------------------------------"); while (teap) { Jim_Nvp *opt = Jim_Nvp_value2name_simple(nvp_target_event, teap->event); - command_print(cmd_ctx, "%-25s | %s", + command_print(CMD, "%-25s | %s", opt->name, Jim_GetString(teap->body, NULL)); teap = teap->next; } - command_print(cmd_ctx, "***END***"); - return JIM_OK; + command_print(CMD, "***END***"); + return ERROR_OK; } static int jim_target_current_state(Jim_Interp *interp, int argc, Jim_Obj *const *argv) { @@ -5444,7 +5247,7 @@ static int jim_target_invoke_event(Jim_Interp *interp, int argc, Jim_Obj *const static const struct command_registration target_instance_command_handlers[] = { { .name = "configure", - .mode = COMMAND_CONFIG, + .mode = COMMAND_ANY, .jim_handler = jim_target_configure, .help = "configure a new target for use", .usage = "[target_attribute ...]", @@ -5457,44 +5260,58 @@ static const struct command_registration target_instance_command_handlers[] = { .usage = "target_attribute", }, { + .name = "mwd", + .handler = handle_mw_command, + .mode = COMMAND_EXEC, + .help = "Write 64-bit word(s) to target memory", + .usage = "address data [count]", + }, + { .name = "mww", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write 32-bit word(s) to target memory", .usage = "address data [count]", }, { .name = "mwh", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write 16-bit half-word(s) to target memory", .usage = "address data [count]", }, { .name = "mwb", + .handler = handle_mw_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_mw, .help = "Write byte(s) to target memory", .usage = "address data [count]", }, { + .name = "mdd", + .handler = handle_md_command, + .mode = COMMAND_EXEC, + .help = "Display target memory as 64-bit words", + .usage = "address [count]", + }, + { .name = "mdw", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 32-bit words", .usage = "address [count]", }, { .name = "mdh", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 16-bit half-words", .usage = "address [count]", }, { .name = "mdb", + .handler = handle_md_command, .mode = COMMAND_EXEC, - .jim_handler = jim_target_md, .help = "Display target memory as 8-bit bytes", .usage = "address [count]", }, @@ -5516,9 +5333,10 @@ static const struct command_registration target_instance_command_handlers[] = { }, { .name = "eventlist", + .handler = handle_target_event_list, .mode = COMMAND_EXEC, - .jim_handler = jim_target_event_list, .help = "displays a table of events defined for this target", + .usage = "", }, { .name = "curstate", @@ -5917,6 +5735,7 @@ static const struct command_registration target_subcommand_handlers[] = { .mode = COMMAND_CONFIG, .handler = handle_target_init_command, .help = "initialize targets", + .usage = "", }, { .name = "create", @@ -6006,7 +5825,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload_num = image.num_sections; fastload = malloc(sizeof(struct FastLoad)*image.num_sections); if (fastload == NULL) { - command_print(CMD_CTX, "out of memory"); + command_print(CMD, "out of memory"); image_close(&image); return ERROR_FAIL; } @@ -6014,7 +5833,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) for (i = 0; i < image.num_sections; i++) { buffer = malloc(image.sections[i].size); if (buffer == NULL) { - command_print(CMD_CTX, "error allocating buffer for section (%d bytes)", + command_print(CMD, "error allocating buffer for section (%d bytes)", (int)(image.sections[i].size)); retval = ERROR_FAIL; break; @@ -6046,7 +5865,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload[i].data = malloc(length); if (fastload[i].data == NULL) { free(buffer); - command_print(CMD_CTX, "error allocating buffer for section (%" PRIu32 " bytes)", + command_print(CMD, "error allocating buffer for section (%" PRIu32 " bytes)", length); retval = ERROR_FAIL; break; @@ -6055,7 +5874,7 @@ COMMAND_HANDLER(handle_fast_load_image_command) fastload[i].length = length; image_size += length; - command_print(CMD_CTX, "%u bytes written at address 0x%8.8x", + command_print(CMD, "%u bytes written at address 0x%8.8x", (unsigned int)length, ((unsigned int)(image.sections[i].base_address + offset))); } @@ -6064,11 +5883,11 @@ COMMAND_HANDLER(handle_fast_load_image_command) } if ((ERROR_OK == retval) && (duration_measure(&bench) == ERROR_OK)) { - command_print(CMD_CTX, "Loaded %" PRIu32 " bytes " + command_print(CMD, "Loaded %" PRIu32 " bytes " "in %fs (%0.3f KiB/s)", image_size, duration_elapsed(&bench), duration_kbps(&bench, image_size)); - command_print(CMD_CTX, + command_print(CMD, "WARNING: image has not been loaded to target!" "You can issue a 'fast_load' to finish loading."); } @@ -6095,7 +5914,7 @@ COMMAND_HANDLER(handle_fast_load_command) int retval = ERROR_OK; for (i = 0; i < fastload_num; i++) { struct target *target = get_current_target(CMD_CTX); - command_print(CMD_CTX, "Write to 0x%08x, length 0x%08x", + command_print(CMD, "Write to 0x%08x, length 0x%08x", (unsigned int)(fastload[i].address), (unsigned int)(fastload[i].length)); retval = target_write_buffer(target, fastload[i].address, fastload[i].length, fastload[i].data); @@ -6105,7 +5924,7 @@ COMMAND_HANDLER(handle_fast_load_command) } if (retval == ERROR_OK) { int64_t after = timeval_ms(); - command_print(CMD_CTX, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0)); + command_print(CMD, "Loaded image %f kBytes/s", (float)(size/1024.0)/((float)(after-ms)/1000.0)); } return retval; } @@ -6123,8 +5942,8 @@ static const struct command_registration target_command_handlers[] = { .name = "target", .mode = COMMAND_CONFIG, .help = "configure target", - .chain = target_subcommand_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; @@ -6160,7 +5979,7 @@ COMMAND_HANDLER(handle_ps_command) if ((target->rtos) && (target->rtos->type) && (target->rtos->type->ps_command)) { display = target->rtos->type->ps_command(target); - command_print(CMD_CTX, "%s", display); + command_print(CMD, "%s", display); free(display); return ERROR_OK; } else { @@ -6169,13 +5988,13 @@ COMMAND_HANDLER(handle_ps_command) } } -static void binprint(struct command_context *cmd_ctx, const char *text, const uint8_t *buf, int size) +static void binprint(struct command_invocation *cmd, const char *text, const uint8_t *buf, int size) { if (text != NULL) - command_print_sameline(cmd_ctx, "%s", text); + command_print_sameline(cmd, "%s", text); for (int i = 0; i < size; i++) - command_print_sameline(cmd_ctx, " %02x", buf[i]); - command_print(cmd_ctx, " "); + command_print_sameline(cmd, " %02x", buf[i]); + command_print(cmd, " "); } COMMAND_HANDLER(handle_test_mem_access_command) @@ -6227,7 +6046,7 @@ COMMAND_HANDLER(handle_test_mem_access_command) read_ref[i] = rand(); read_buf[i] = read_ref[i]; } - command_print_sameline(CMD_CTX, + command_print_sameline(CMD, "Test read %" PRIu32 " x %d @ %d to %saligned buffer: ", count, size, offset, host_offset ? "un" : ""); @@ -6240,10 +6059,10 @@ COMMAND_HANDLER(handle_test_mem_access_command) duration_measure(&bench); if (retval == ERROR_TARGET_UNALIGNED_ACCESS) { - command_print(CMD_CTX, "Unsupported alignment"); + command_print(CMD, "Unsupported alignment"); goto next; } else if (retval != ERROR_OK) { - command_print(CMD_CTX, "Memory read failed"); + command_print(CMD, "Memory read failed"); goto next; } @@ -6253,13 +6072,13 @@ COMMAND_HANDLER(handle_test_mem_access_command) /* check result */ int result = memcmp(read_ref, read_buf, host_bufsiz); if (result == 0) { - command_print(CMD_CTX, "Pass in %fs (%0.3f KiB/s)", + command_print(CMD, "Pass in %fs (%0.3f KiB/s)", duration_elapsed(&bench), duration_kbps(&bench, count * size)); } else { - command_print(CMD_CTX, "Compare failed"); - binprint(CMD_CTX, "ref:", read_ref, host_bufsiz); - binprint(CMD_CTX, "buf:", read_buf, host_bufsiz); + command_print(CMD, "Compare failed"); + binprint(CMD, "ref:", read_ref, host_bufsiz); + binprint(CMD, "buf:", read_buf, host_bufsiz); } next: free(read_ref); @@ -6299,13 +6118,13 @@ out: for (size_t i = 0; i < host_bufsiz; i++) write_buf[i] = rand(); - command_print_sameline(CMD_CTX, + command_print_sameline(CMD, "Test write %" PRIu32 " x %d @ %d from %saligned buffer: ", count, size, offset, host_offset ? "un" : ""); retval = target_write_memory(target, wa->address, 1, num_bytes, test_pattern); if (retval != ERROR_OK) { - command_print(CMD_CTX, "Test pattern write failed"); + command_print(CMD, "Test pattern write failed"); goto nextw; } @@ -6322,30 +6141,30 @@ out: duration_measure(&bench); if (retval == ERROR_TARGET_UNALIGNED_ACCESS) { - command_print(CMD_CTX, "Unsupported alignment"); + command_print(CMD, "Unsupported alignment"); goto nextw; } else if (retval != ERROR_OK) { - command_print(CMD_CTX, "Memory write failed"); + command_print(CMD, "Memory write failed"); goto nextw; } /* read back */ retval = target_read_memory(target, wa->address, 1, num_bytes, read_buf); if (retval != ERROR_OK) { - command_print(CMD_CTX, "Test pattern write failed"); + command_print(CMD, "Test pattern write failed"); goto nextw; } /* check result */ int result = memcmp(read_ref, read_buf, num_bytes); if (result == 0) { - command_print(CMD_CTX, "Pass in %fs (%0.3f KiB/s)", + command_print(CMD, "Pass in %fs (%0.3f KiB/s)", duration_elapsed(&bench), duration_kbps(&bench, count * size)); } else { - command_print(CMD_CTX, "Compare failed"); - binprint(CMD_CTX, "ref:", read_ref, num_bytes); - binprint(CMD_CTX, "buf:", read_buf, num_bytes); + command_print(CMD, "Compare failed"); + binprint(CMD, "ref:", read_ref, num_bytes); + binprint(CMD, "buf:", read_buf, num_bytes); } nextw: free(read_ref); @@ -6458,7 +6277,7 @@ static const struct command_registration target_exec_command_handlers[] = { .name = "mdd", .handler = handle_md_command, .mode = COMMAND_EXEC, - .help = "display memory words", + .help = "display memory double-words", .usage = "['phys'] address [count]", }, { @@ -6486,7 +6305,7 @@ static const struct command_registration target_exec_command_handlers[] = { .name = "mwd", .handler = handle_mw_command, .mode = COMMAND_EXEC, - .help = "write memory word", + .help = "write memory double-word", .usage = "['phys'] address value [count]", }, { @@ -6515,7 +6334,7 @@ static const struct command_registration target_exec_command_handlers[] = { .handler = handle_bp_command, .mode = COMMAND_EXEC, .help = "list or set hardware or software breakpoint", - .usage = "<address> [<asid>] <length> ['hw'|'hw_ctx']", + .usage = "[<address> [<asid>] <length> ['hw'|'hw_ctx']]", }, { .name = "rbp", diff --git a/src/target/target.h b/src/target/target.h index 160ac4a..957a7d0 100644 --- a/src/target/target.h +++ b/src/target/target.h @@ -36,6 +36,7 @@ struct reg; struct trace; struct command_context; +struct command_invocation; struct breakpoint; struct watchpoint; struct mem_param; @@ -739,6 +740,10 @@ int target_arch_state(struct target *target); void target_handle_event(struct target *t, enum target_event e); +void target_handle_md_output(struct command_invocation *cmd, + struct target *target, target_addr_t address, unsigned size, + unsigned count, const uint8_t *buffer); + #define ERROR_TARGET_INVALID (-300) #define ERROR_TARGET_INIT_FAILED (-301) #define ERROR_TARGET_TIMEOUT (-302) diff --git a/src/target/target_request.c b/src/target/target_request.c index 6ca204b..c1da1a2 100644 --- a/src/target/target_request.c +++ b/src/target/target_request.c @@ -56,7 +56,7 @@ static int target_asciimsg(struct target *target, uint32_t length) LOG_DEBUG("%s", msg); while (c) { - command_print(c->cmd_ctx, "%s", msg); + command_output_text(c->cmd_ctx, msg); c = c->next; } @@ -100,7 +100,7 @@ static int target_hexmsg(struct target *target, int size, uint32_t length) LOG_DEBUG("%s", line); while (c) { - command_print(c->cmd_ctx, "%s", line); + command_output_text(c->cmd_ctx, line); c = c->next; } c = target->dbgmsg; @@ -283,7 +283,7 @@ COMMAND_HANDLER(handle_target_request_debugmsgs_command) return ERROR_COMMAND_SYNTAX_ERROR; } - command_print(CMD_CTX, "receiving debug messages from current target %s", + command_print(CMD, "receiving debug messages from current target %s", (receiving) ? (charmsg_mode ? "charmsg" : "enabled") : "disabled"); return ERROR_OK; } diff --git a/src/target/testee.c b/src/target/testee.c index 5b6cced..236ac9a 100644 --- a/src/target/testee.c +++ b/src/target/testee.c @@ -30,8 +30,8 @@ static const struct command_registration testee_command_handlers[] = { .name = "testee", .mode = COMMAND_ANY, .help = "testee target commands", - .chain = hello_command_handlers, + .usage = "", }, COMMAND_REGISTRATION_DONE }; diff --git a/src/target/trace.c b/src/target/trace.c index 63c477f..943bf1f 100644 --- a/src/target/trace.c +++ b/src/target/trace.c @@ -53,7 +53,7 @@ COMMAND_HANDLER(handle_trace_point_command) uint32_t i; for (i = 0; i < trace->num_trace_points; i++) { - command_print(CMD_CTX, "trace point 0x%8.8" PRIx32 " (%lld times hit)", + command_print(CMD, "trace point 0x%8.8" PRIx32 " (%lld times hit)", trace->trace_points[i].address, (long long)trace->trace_points[i].hit_counter); } @@ -108,14 +108,14 @@ COMMAND_HANDLER(handle_trace_history_command) COMMAND_PARSE_NUMBER(u32, CMD_ARGV[0], trace->trace_history_size); trace->trace_history = malloc(sizeof(uint32_t) * trace->trace_history_size); - command_print(CMD_CTX, "new trace history size: %i", (int)(trace->trace_history_size)); + command_print(CMD, "new trace history size: %i", (int)(trace->trace_history_size)); } else { uint32_t i; uint32_t first = 0; uint32_t last = trace->trace_history_pos; if (!trace->trace_history_size) { - command_print(CMD_CTX, "trace history buffer is not allocated"); + command_print(CMD, "trace history buffer is not allocated"); return ERROR_OK; } @@ -128,11 +128,11 @@ COMMAND_HANDLER(handle_trace_history_command) if (trace->trace_history[i % trace->trace_history_size] < trace->num_trace_points) { uint32_t address; address = trace->trace_points[trace->trace_history[i % trace->trace_history_size]].address; - command_print(CMD_CTX, "trace point %i: 0x%8.8" PRIx32 "", + command_print(CMD, "trace point %i: 0x%8.8" PRIx32 "", (int)(trace->trace_history[i % trace->trace_history_size]), address); } else - command_print(CMD_CTX, "trace point %i: -not defined-", + command_print(CMD, "trace point %i: -not defined-", (int)(trace->trace_history[i % trace->trace_history_size])); } } diff --git a/src/target/x86_32_common.c b/src/target/x86_32_common.c index 011e7d8..b85e451 100644 --- a/src/target/x86_32_common.c +++ b/src/target/x86_32_common.c @@ -1340,7 +1340,7 @@ static int write_hw_reg_from_cache(struct target *t, int num) } /* x86 32 commands */ -static void handle_iod_output(struct command_context *cmd_ctx, +static void handle_iod_output(struct command_invocation *cmd, struct target *target, uint32_t address, unsigned size, unsigned count, const uint8_t *buffer) { @@ -1392,7 +1392,7 @@ static void handle_iod_output(struct command_context *cmd_ctx, value_fmt, value); if ((i % line_modulo == line_modulo - 1) || (i == count - 1)) { - command_print(cmd_ctx, "%s", output); + command_print(cmd, "%s", output); output_len = 0; } } @@ -1429,7 +1429,7 @@ COMMAND_HANDLER(handle_iod_command) struct target *target = get_current_target(CMD_CTX); int retval = x86_32_common_read_io(target, address, size, buffer); if (ERROR_OK == retval) - handle_iod_output(CMD_CTX, target, address, size, count, buffer); + handle_iod_output(CMD, target, address, size, count, buffer); free(buffer); return retval; } diff --git a/src/target/xscale.c b/src/target/xscale.c index 09abd9e..1a099c9 100644 --- a/src/target/xscale.c +++ b/src/target/xscale.c @@ -138,11 +138,11 @@ static int xscale_set_reg_u32(struct reg *reg, uint32_t value) static const char xscale_not[] = "target is not an XScale"; -static int xscale_verify_pointer(struct command_context *cmd_ctx, +static int xscale_verify_pointer(struct command_invocation *cmd, struct xscale_common *xscale) { if (xscale->common_magic != XSCALE_COMMON_MAGIC) { - command_print(cmd_ctx, xscale_not); + command_print(cmd, xscale_not); return ERROR_TARGET_INVALID; } return ERROR_OK; @@ -2654,16 +2654,16 @@ static inline void xscale_branch_address(struct xscale_trace_data *trace_data, static inline void xscale_display_instruction(struct target *target, uint32_t pc, struct arm_instruction *instruction, - struct command_context *cmd_ctx) + struct command_invocation *cmd) { int retval = xscale_read_instruction(target, pc, instruction); if (retval == ERROR_OK) - command_print(cmd_ctx, "%s", instruction->text); + command_print(cmd, "%s", instruction->text); else - command_print(cmd_ctx, "0x%8.8" PRIx32 "\t<not found in image>", pc); + command_print(cmd, "0x%8.8" PRIx32 "\t<not found in image>", pc); } -static int xscale_analyze_trace(struct target *target, struct command_context *cmd_ctx) +static int xscale_analyze_trace(struct target *target, struct command_invocation *cmd) { struct xscale_common *xscale = target_to_xscale(target); struct xscale_trace_data *trace_data = xscale->trace.data; @@ -2771,7 +2771,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c count = trace_data->entries[i].data & 0x0f; for (j = 0; j < count; j++) { xscale_display_instruction(target, current_pc, &instruction, - cmd_ctx); + cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -2779,7 +2779,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c * rollover and some exceptions: undef, swi, prefetch abort. */ if ((trace_msg_type == 15) || (exception > 0 && exception < 4)) { xscale_display_instruction(target, current_pc, &instruction, - cmd_ctx); + cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -2787,13 +2787,13 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c continue; if (exception) { - command_print(cmd_ctx, "--- exception %i ---", exception); + command_print(cmd, "--- exception %i ---", exception); continue; } /* not exception or rollover; next instruction is a branch and is * not included in the count */ - xscale_display_instruction(target, current_pc, &instruction, cmd_ctx); + xscale_display_instruction(target, current_pc, &instruction, cmd); /* for direct branches, extract branch destination from instruction */ if ((trace_msg_type == 8) || (trace_msg_type == 12)) { @@ -2813,7 +2813,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c } if (current_pc == 0) - command_print(cmd_ctx, "address unknown"); + command_print(cmd, "address unknown"); continue; } @@ -2855,7 +2855,7 @@ static int xscale_analyze_trace(struct target *target, struct command_context *c /* display remaining instructions */ for (i = 0; i < gap_count; i++) { - xscale_display_instruction(target, current_pc, &instruction, cmd_ctx); + xscale_display_instruction(target, current_pc, &instruction, cmd); current_pc += xscale->trace.core_state == ARM_STATE_ARM ? 4 : 2; } @@ -2895,6 +2895,7 @@ static void xscale_build_reg_cache(struct target *target) (*cache_p)->reg_list[i].size = 32; (*cache_p)->reg_list[i].arch_info = &arch_info[i]; (*cache_p)->reg_list[i].type = &xscale_reg_type; + (*cache_p)->reg_list[i].exist = true; arch_info[i] = xscale_reg_arch_info[i]; arch_info[i].target = target; } @@ -3032,7 +3033,7 @@ COMMAND_HANDLER(xscale_handle_debug_handler_command) } xscale = target_to_xscale(target); - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3066,7 +3067,7 @@ COMMAND_HANDLER(xscale_handle_cache_clean_address_command) return ERROR_FAIL; } xscale = target_to_xscale(target); - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3086,11 +3087,11 @@ COMMAND_HANDLER(xscale_handle_cache_info_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; - return armv4_5_handle_cache_info_command(CMD_CTX, &xscale->armv4_5_mmu.armv4_5_cache); + return armv4_5_handle_cache_info_command(CMD, &xscale->armv4_5_mmu.armv4_5_cache); } static int xscale_virt2phys(struct target *target, @@ -3131,12 +3132,12 @@ COMMAND_HANDLER(xscale_handle_mmu_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3150,7 +3151,7 @@ COMMAND_HANDLER(xscale_handle_mmu_command) xscale->armv4_5_mmu.mmu_enabled = enable; } - command_print(CMD_CTX, "mmu %s", + command_print(CMD, "mmu %s", (xscale->armv4_5_mmu.mmu_enabled) ? "enabled" : "disabled"); return ERROR_OK; @@ -3161,12 +3162,12 @@ COMMAND_HANDLER(xscale_handle_idcache_command) struct target *target = get_current_target(CMD_CTX); struct xscale_common *xscale = target_to_xscale(target); - int retval = xscale_verify_pointer(CMD_CTX, xscale); + int retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3195,7 +3196,7 @@ COMMAND_HANDLER(xscale_handle_idcache_command) xscale->armv4_5_mmu.armv4_5_cache.i_cache_enabled : xscale->armv4_5_mmu.armv4_5_cache.d_u_cache_enabled; const char *msg = enabled ? "enabled" : "disabled"; - command_print(CMD_CTX, "%s %s", CMD_NAME, msg); + command_print(CMD, "%s %s", CMD_NAME, msg); return ERROR_OK; } @@ -3222,7 +3223,7 @@ COMMAND_HANDLER(xscale_handle_vector_catch_command) uint32_t catch = 0; struct reg *dcsr_reg = &xscale->reg_cache->reg_list[XSCALE_DCSR]; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; @@ -3257,7 +3258,7 @@ COMMAND_HANDLER(xscale_handle_vector_catch_command) dcsr_value = buf_get_u32(dcsr_reg->value, 0, 32); for (unsigned i = 0; i < ARRAY_SIZE(vec_ids); i++) { - command_print(CMD_CTX, "%15s: %s", vec_ids[i].name, + command_print(CMD, "%15s: %s", vec_ids[i].name, (dcsr_value & vec_ids[i].mask) ? "catch" : "ignore"); } @@ -3272,23 +3273,23 @@ COMMAND_HANDLER(xscale_handle_vector_table_command) int err = 0; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (CMD_ARGC == 0) { /* print current settings */ int idx; - command_print(CMD_CTX, "active user-set static vectors:"); + command_print(CMD, "active user-set static vectors:"); for (idx = 1; idx < 8; idx++) if (xscale->static_low_vectors_set & (1 << idx)) - command_print(CMD_CTX, + command_print(CMD, "low %d: 0x%" PRIx32, idx, xscale->static_low_vectors[idx]); for (idx = 1; idx < 8; idx++) if (xscale->static_high_vectors_set & (1 << idx)) - command_print(CMD_CTX, + command_print(CMD, "high %d: 0x%" PRIx32, idx, xscale->static_high_vectors[idx]); @@ -3330,12 +3331,12 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) uint32_t dcsr_value; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3354,7 +3355,7 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) if (CMD_ARGC >= 3) COMMAND_PARSE_NUMBER(int, CMD_ARGV[2], buffcount); if (buffcount < 1) { /* invalid */ - command_print(CMD_CTX, "fill buffer count must be > 0"); + command_print(CMD, "fill buffer count must be > 0"); xscale->trace.mode = XSCALE_TRACE_DISABLED; return ERROR_COMMAND_SYNTAX_ERROR; } @@ -3371,11 +3372,11 @@ COMMAND_HANDLER(xscale_handle_trace_buffer_command) if (xscale->trace.mode != XSCALE_TRACE_DISABLED) { char fill_string[12]; sprintf(fill_string, "fill %d", xscale->trace.buffer_fill); - command_print(CMD_CTX, "trace buffer enabled (%s)", + command_print(CMD, "trace buffer enabled (%s)", (xscale->trace.mode == XSCALE_TRACE_FILL) ? fill_string : "wrap"); } else - command_print(CMD_CTX, "trace buffer disabled"); + command_print(CMD, "trace buffer disabled"); dcsr_value = buf_get_u32(xscale->reg_cache->reg_list[XSCALE_DCSR].value, 0, 32); if (xscale->trace.mode == XSCALE_TRACE_FILL) @@ -3395,14 +3396,14 @@ COMMAND_HANDLER(xscale_handle_trace_image_command) if (CMD_ARGC < 1) return ERROR_COMMAND_SYNTAX_ERROR; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (xscale->trace.image) { image_close(xscale->trace.image); free(xscale->trace.image); - command_print(CMD_CTX, "previously loaded image found and closed"); + command_print(CMD, "previously loaded image found and closed"); } xscale->trace.image = malloc(sizeof(struct image)); @@ -3434,12 +3435,12 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) struct fileio *file; int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } @@ -3449,7 +3450,7 @@ COMMAND_HANDLER(xscale_handle_dump_trace_command) trace_data = xscale->trace.data; if (!trace_data) { - command_print(CMD_CTX, "no trace data collected"); + command_print(CMD, "no trace data collected"); return ERROR_OK; } @@ -3482,11 +3483,11 @@ COMMAND_HANDLER(xscale_handle_analyze_trace_buffer_command) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; - xscale_analyze_trace(target, CMD_CTX); + xscale_analyze_trace(target, CMD); return ERROR_OK; } @@ -3497,12 +3498,12 @@ COMMAND_HANDLER(xscale_handle_cp15) struct xscale_common *xscale = target_to_xscale(target); int retval; - retval = xscale_verify_pointer(CMD_CTX, xscale); + retval = xscale_verify_pointer(CMD, xscale); if (retval != ERROR_OK) return retval; if (target->state != TARGET_HALTED) { - command_print(CMD_CTX, "target must be stopped for \"%s\" command", CMD_NAME); + command_print(CMD, "target must be stopped for \"%s\" command", CMD_NAME); return ERROR_OK; } uint32_t reg_no = 0; @@ -3536,7 +3537,7 @@ COMMAND_HANDLER(xscale_handle_cp15) reg_no = XSCALE_CPACCESS; break; default: - command_print(CMD_CTX, "invalid register number"); + command_print(CMD, "invalid register number"); return ERROR_COMMAND_SYNTAX_ERROR; } reg = &xscale->reg_cache->reg_list[reg_no]; @@ -3548,7 +3549,7 @@ COMMAND_HANDLER(xscale_handle_cp15) /* read cp15 control register */ xscale_get_reg(reg); value = buf_get_u32(reg->value, 0, 32); - command_print(CMD_CTX, "%s (/%i): 0x%" PRIx32 "", reg->name, (int)(reg->size), + command_print(CMD, "%s (/%i): 0x%" PRIx32 "", reg->name, (int)(reg->size), value); } else if (CMD_ARGC == 2) { uint32_t value; @@ -3577,6 +3578,7 @@ static const struct command_registration xscale_exec_command_handlers[] = { .handler = xscale_handle_cache_info_command, .mode = COMMAND_EXEC, .help = "display information about CPU caches", + .usage = "", }, { .name = "mmu", diff --git a/src/transport/transport.c b/src/transport/transport.c index 7085947..77db9e2 100644 --- a/src/transport/transport.c +++ b/src/transport/transport.c @@ -258,10 +258,10 @@ COMMAND_HANDLER(handle_transport_list) if (CMD_ARGC != 0) return ERROR_COMMAND_SYNTAX_ERROR; - command_print(CMD_CTX, "The following transports are available:"); + command_print(CMD, "The following transports are available:"); for (struct transport *t = transport_list; t; t = t->next) - command_print(CMD_CTX, "\t%s", t->name); + command_print(CMD, "\t%s", t->name); return ERROR_OK; } diff --git a/src/xsvf/xsvf.c b/src/xsvf/xsvf.c index 63c8915..e574c6f 100644 --- a/src/xsvf/xsvf.c +++ b/src/xsvf/xsvf.c @@ -249,14 +249,14 @@ COMMAND_HANDLER(handle_xsvf_command) if (strcmp(CMD_ARGV[0], "plain") != 0) { tap = jtag_tap_by_string(CMD_ARGV[0]); if (!tap) { - command_print(CMD_CTX, "Tap: %s unknown", CMD_ARGV[0]); + command_print(CMD, "Tap: %s unknown", CMD_ARGV[0]); return ERROR_FAIL; } } xsvf_fd = open(filename, O_RDONLY); if (xsvf_fd < 0) { - command_print(CMD_CTX, "file \"%s\" not found", filename); + command_print(CMD, "file \"%s\" not found", filename); return ERROR_FAIL; } @@ -1005,7 +1005,7 @@ COMMAND_HANDLER(handle_xsvf_command) } if (tdo_mismatch) { - command_print(CMD_CTX, + command_print(CMD, "TDO mismatch, somewhere near offset %lu in xsvf file, aborting", file_offset); @@ -1014,14 +1014,14 @@ COMMAND_HANDLER(handle_xsvf_command) if (unsupported) { off_t offset = lseek(xsvf_fd, 0, SEEK_CUR) - 1; - command_print(CMD_CTX, + command_print(CMD, "unsupported xsvf command (0x%02X) at offset %jd, aborting", uc, (intmax_t)offset); return ERROR_FAIL; } if (do_abort) { - command_print(CMD_CTX, "premature end of xsvf file detected, aborting"); + command_print(CMD, "premature end of xsvf file detected, aborting"); return ERROR_FAIL; } @@ -1036,7 +1036,7 @@ COMMAND_HANDLER(handle_xsvf_command) close(xsvf_fd); - command_print(CMD_CTX, "XSVF file programmed successfully"); + command_print(CMD, "XSVF file programmed successfully"); return ERROR_OK; } diff --git a/tcl/board/arm_musca_a.cfg b/tcl/board/arm_musca_a.cfg new file mode 100644 index 0000000..fa7cf5e --- /dev/null +++ b/tcl/board/arm_musca_a.cfg @@ -0,0 +1,44 @@ +# +# Configuration script for ARM Musca-A development board +# +# For now we do not support Musca A flash programming using OpenOCD. However, a +# work area is configured for flash programming speed up. +# +# GDB considers all memory as RAM unless target supplies a memory map. +# OpenOCD will only send memory map if flash banks are configured. Otherwise, +# configure GDB after connection by issuing following commands: +# (gdb) mem 0x10200000 0x109FFFFF ro +# (gdb) mem 0x00200000 0x009FFFFF ro +# (gdb) set mem inaccessible-by-default off + +# ARM Musca A board supports both JTAG and SWD transports. +source [find target/swj-dp.tcl] + +# set a safe JTAG clock speed, can be overridden +adapter_khz 1000 + +global _CHIPNAME +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME MUSCA_A +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x6ba00477 +} + +# Enable CPU1 debugging as a separate GDB target +set _ENABLE_CPU1 1 + +# Musca A1 has 32KB SRAM banks. Override default work-area-size to 8KB per CPU +set WORKAREASIZE_CPU0 0x2000 +set WORKAREASIZE_CPU1 0x2000 + +# Set SRAM bank 1 to be used for work area. Override here if needed. +set WORKAREAADDR_CPU0 0x30008000 +set WORKAREAADDR_CPU1 0x3000A000 + +source [find target/arm_corelink_sse200.cfg] diff --git a/tcl/board/kindle2.cfg b/tcl/board/kindle2.cfg new file mode 100644 index 0000000..f32b2a3 --- /dev/null +++ b/tcl/board/kindle2.cfg @@ -0,0 +1,181 @@ +# Board configuration file for Amazon Kindle Model No. D00701 and D00801 +# AKA Kindle 2nd generation and Kindle DX +# using a Freescale MCIMX31LDVKN5D i.MX31 processor +# +# Pins at J9 40-Pin FFC-A: +# 1 - GND +# 16 - TRSTB +# 17 - TDI +# 18 - TMS +# 19 - TCK +# 20 - RTCK +# 21 - TDO +# 22 - DE +# 25 - BOOT_MODE4 +# 27 - BOOT_MODE2 + +source [find target/imx31.cfg] +source [find target/imx.cfg] + +$_TARGETNAME configure -event reset-init { kindle2_init } +$_TARGETNAME configure -event reset-start { adapter_khz 1000 } + +# 8MiB NOR Flash +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME cfi 0xa0000000 0x800000 2 2 $_TARGETNAME + +# 16kiB internal SRAM +$_TARGETNAME configure -work-area-phys 0x1fffc000 \ + -work-area-size 0x4000 -work-area-backup 0 + +# FIXME: currently SRST is not wired to the system +reset_config trst_only +jtag_ntrst_assert_width 10 +jtag_ntrst_delay 30 + +# this is broken but enabled by default +arm11 memwrite burst disable + +adapter_khz 1000 +ftdi_tdo_sample_edge falling + +proc kindle2_init {} { + imx3x_reset + kindle2_clock_setup + disable_mmu_and_cache + kindle2_misc_init + kindle2_sdram_init + arm core_state arm +} + +proc kindle2_clock_setup {} { + # CCMR: clock from FPM/CKIL + mww 0x53f80000 0x074b0b7b + # IPU_CONF + mww 0x53fc0000 0x040 + # 398MHz + mww 0x53f80004 0xff871650 + mww 0x53f80010 0x00331c23 +} + +proc kindle2_misc_init { } { + # AIPS1 + mww 0x43f00040 0x0 + mww 0x43f00044 0x0 + mww 0x43f00048 0x0 + mww 0x43f0004c 0x0 + mww 0x43f00050 0x0 + mww 0x43f00000 0x77777777 + mww 0x43f00004 0x77777777 + + # AIPS2 + mww 0x53f00040 0x0 + mww 0x53f00044 0x0 + mww 0x53f00048 0x0 + mww 0x53f0004c 0x0 + mww 0x53f00050 0x0 + mww 0x53f00000 0x77777777 + mww 0x53f00004 0x77777777 + + # Start 16 bit NorFlash Initialization on CS0 + mww 0xb8002000 0x0000cc03 + mww 0xb8002004 0xa0330d01 + mww 0xb8002008 0x00220800 +} + +proc disable_mmu_and_cache {} { + # Mode Supervisor, disable FIQ, IRQ and imprecise data aborts + reg cpsr 0x1d3 + + # flush entire BTAC + arm mcr 15 0 7 5 6 0 + # invalidate instruction and data cache + # MCR CP15, 0, R1, C7, C7, 0 + arm mcr 15 0 7 7 0 + + # clean and invalidate cache + arm mcr 15 0 7 15 0 + + # disable MMU and caches + arm mcr 15 0 1 0 0 0 + + arm mcr 15 0 15 2 4 0 + + # invalidate TLBs + arm mcr 15 0 8 7 0 0 + + # Drain the write buffer + arm mcr 15 0 7 10 4 0 + + # start from AIPS 2GB region + arm mcr 15 0 15 2 4 0x40000015 +} + +proc kindle2_sdram_init {} { + #-------------------------------------------- + # Samsung K4X1G323PC-8GC3 32Mx32 Mobile DDR SDRAM + #-------------------------------------------- + # SDCLK + mww 0x43fac26c 0 + + # CAS + mww 0x43fac270 0 + + # RAS + mww 0x43fac274 0 + + # CS2 (CSD0) + mww 0x43fac27c 0x1000 + + # DQM3 + mww 0x43fac284 0 + + # DQM2, DQM1, DQM0, SD31-SD0, A25-A0, MA10 (0x288..0x2dc) + mww 0x43fac288 0 + mww 0x43fac28c 0 + mww 0x43fac290 0 + mww 0x43fac294 0 + mww 0x43fac298 0 + mww 0x43fac29c 0 + mww 0x43fac2a0 0 + mww 0x43fac2a4 0 + mww 0x43fac2a8 0 + mww 0x43fac2ac 0 + mww 0x43fac2b0 0 + mww 0x43fac2b4 0 + mww 0x43fac2b8 0 + mww 0x43fac2bc 0 + mww 0x43fac2c0 0 + mww 0x43fac2c4 0 + mww 0x43fac2c8 0 + mww 0x43fac2cc 0 + mww 0x43fac2d0 0 + mww 0x43fac2d4 0 + mww 0x43fac2d8 0 + mww 0x43fac2dc 0 + + # ? + mww 0xb8002000 0x00006602 + mww 0xb8002004 0x00000501 + mww 0xb8002008 0x00000000 + + # LPDDR1 Initialization script + mww 0xb8001010 0x00000002 + mww 0xb8001010 0x00000004 + # ESDCFG0: set timing paramters + mww 0xb8001004 0x007fff7f + # ESDCTL0: select Prechare-All mode + mww 0xb8001000 0x92100000 + mww 0x80000f00 0x12344321 + # ESDCTL0: Auto Refresh + mww 0xb8001000 0xa2100000 + mww 0x80000000 0x12344321 + mww 0x80000000 0x12344321 + # ESDCTL0: Load Mode Register + mww 0xb8001000 0xb2100000 + mwb 0x80000033 0xda + mwb 0x81000000 0xff + # ESDCTL0: enable Auto-Refresh + mww 0xb8001000 0x82226080 + mww 0x80000000 0xdeadbeef +} diff --git a/tcl/board/microchip_saml11_xplained_pro.cfg b/tcl/board/microchip_saml11_xplained_pro.cfg new file mode 100644 index 0000000..3558a8e --- /dev/null +++ b/tcl/board/microchip_saml11_xplained_pro.cfg @@ -0,0 +1,10 @@ +# +# Microchip (formerly Atmel) SAM L11 Xplained Pro Evaluation Kit. +# https://www.microchip.com/DevelopmentTools/ProductDetails/dm320205 +# + +source [find interface/cmsis-dap.cfg] +adapter_khz 1000 + +set CHIPNAME saml11 +source [find target/atsaml1x.cfg] diff --git a/tcl/board/renesas_gr_peach.cfg b/tcl/board/renesas_gr_peach.cfg new file mode 100644 index 0000000..ee6efe0 --- /dev/null +++ b/tcl/board/renesas_gr_peach.cfg @@ -0,0 +1,5 @@ +# Renesas RZ/A1H GR-Peach board + +reset_config srst_only + +source [find target/renesas_r7s72100.cfg] diff --git a/tcl/board/rigado_bmd300_ek.cfg b/tcl/board/rigado_bmd300_ek.cfg new file mode 100644 index 0000000..04e5e1f --- /dev/null +++ b/tcl/board/rigado_bmd300_ek.cfg @@ -0,0 +1,11 @@ +# +# Rigado BMD-300 Evaluation Kit +# +# https://www.rigado.com/products/modules/bmd-300/ +# + +source [find interface/jlink.cfg] +transport select swd +adapter_khz 1000 + +source [find target/nrf52.cfg] diff --git a/tcl/target/arm_corelink_sse200.cfg b/tcl/target/arm_corelink_sse200.cfg new file mode 100644 index 0000000..ca30649 --- /dev/null +++ b/tcl/target/arm_corelink_sse200.cfg @@ -0,0 +1,71 @@ +# +# Configuration script for Arm CoreLink SSE-200 Subsystem based IoT SoCs. +# + +global TARGET +set TARGET $_CHIPNAME + +swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# +# SRAM on ARM CoreLink SSE-200 can be 4 banks of 8/16/32/64 KB +# We will configure work area assuming 8-KB bank size in SRAM bank 1. +# Also SRAM start addresses defaults to secure mode alias. +# These values can be overridden as per board configuration +# + +global _WORKAREASIZE_CPU0 +if { [info exists WORKAREASIZE_CPU0] } { + set _WORKAREASIZE_CPU0 $WORKAREASIZE_CPU0 +} else { + set _WORKAREASIZE_CPU0 0x1000 +} + +global _WORKAREAADDR_CPU0 +if { [info exists WORKAREAADDR_CPU0] } { + set _WORKAREAADDR_CPU0 $WORKAREAADDR_CPU0 +} else { + set _WORKAREAADDR_CPU0 0x30008000 +} + +# +# Target configuration for Cortex M33 Core 0 on ARM CoreLink SSE-200 +# Core 0 is the boot core and will always be configured. +# + +target create ${TARGET}.CPU0 cortex_m -dap $_CHIPNAME.dap -ap-num 1 -coreid 0 + +${TARGET}.CPU0 configure -work-area-phys $_WORKAREAADDR_CPU0 -work-area-size $_WORKAREASIZE_CPU0 -work-area-backup 0 + +${TARGET}.CPU0 cortex_m reset_config sysresetreq + +# +# Target configuration for Cortex M33 Core 1 on ARM CoreLink SSE-200 +# Core 1 is optional and locked at boot until core 0 unlocks it. +# + +if { $_ENABLE_CPU1 } { + global _WORKAREASIZE_CPU1 + if { [info exists WORKAREASIZE_CPU1] } { + set _WORKAREASIZE_CPU1 $WORKAREASIZE_CPU1 + } else { + set _WORKAREASIZE_CPU1 0x1000 + } + + global _WORKAREAADDR_CPU1 + if { [info exists WORKAREAADDR_CPU1] } { + set _WORKAREAADDR_CPU1 $WORKAREAADDR_CPU1 + } else { + set _WORKAREAADDR_CPU1 0x30009000 + } + + target create ${TARGET}.CPU1 cortex_m -dap $_CHIPNAME.dap -ap-num 2 -coreid 1 + + ${TARGET}.CPU1 configure -work-area-phys $_WORKAREAADDR_CPU1 -work-area-size $_WORKAREASIZE_CPU1 -work-area-backup 0 + + ${TARGET}.CPU1 cortex_m reset_config vectreset +} + +# Make sure the default target is the boot core +targets ${TARGET}.CPU0 diff --git a/tcl/target/atsaml1x.cfg b/tcl/target/atsaml1x.cfg new file mode 100644 index 0000000..3486746 --- /dev/null +++ b/tcl/target/atsaml1x.cfg @@ -0,0 +1,31 @@ +# +# Microchip (formerly Atmel) SAM L1x target +# +# Note: These devices support SWD only. +# + +transport select swd + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME saml1x +} + +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x800 +} + +swd newdap $_CHIPNAME cpu -expected-id 0x0bf11477 +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap + +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE -work-area-backup 0 + +if {![using_hla]} { + cortex_m reset_config sysresetreq +} diff --git a/tcl/target/imx6.cfg b/tcl/target/imx6.cfg index 8a32517..f359346 100644 --- a/tcl/target/imx6.cfg +++ b/tcl/target/imx6.cfg @@ -1,4 +1,10 @@ -# Freescale i.MX6 series single/dual/quad core processor +# +# Freescale i.MX6 series +# +# Supports 6Q 6D 6QP 6DP 6DL 6S 6SL 6SLL +# +# Some imx6 chips have Cortex-A7 or an Cortex-M and need special handling +# if { [info exists CHIPNAME] } { set _CHIPNAME $CHIPNAME @@ -8,9 +14,9 @@ if { [info exists CHIPNAME] } { # CoreSight Debug Access Port if { [info exists DAP_TAPID] } { - set _DAP_TAPID $DAP_TAPID + set _DAP_TAPID $DAP_TAPID } else { - set _DAP_TAPID 0x4ba00477 + set _DAP_TAPID 0x4ba00477 } jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ @@ -20,18 +26,34 @@ jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f # System JTAG Controller + +# List supported SJC TAPIDs from imx reference manuals: +set _SJC_TAPID_6Q 0x0191c01d +set _SJC_TAPID_6D 0x0191e01d +set _SJC_TAPID_6QP 0x3191c01d +set _SJC_TAPID_6DP 0x3191d01d +set _SJC_TAPID_6DL 0x0891a01d +set _SJC_TAPID_6S 0x0891b01d +set _SJC_TAPID_6SL 0x0891f01d +set _SJC_TAPID_6SLL 0x088c201d + +# Allow external override of the first SJC TAPID if { [info exists SJC_TAPID] } { - set _SJC_TAPID $SJC_TAPID + set _SJC_TAPID $SJC_TAPID } else { - set _SJC_TAPID 0x0191c01d + set _SJC_TAPID $_SJC_TAPID_6Q } -set _SJC_TAPID2 0x2191c01d -set _SJC_TAPID3 0x2191e01d -set _SJC_TAPID4 0x1191c01d jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ - -expected-id $_SJC_TAPID -expected-id $_SJC_TAPID2 \ - -expected-id $_SJC_TAPID3 -expected-id $_SJC_TAPID4 + -ignore-version \ + -expected-id $_SJC_TAPID \ + -expected-id $_SJC_TAPID_6QP \ + -expected-id $_SJC_TAPID_6DP \ + -expected-id $_SJC_TAPID_6D \ + -expected-id $_SJC_TAPID_6DL \ + -expected-id $_SJC_TAPID_6S \ + -expected-id $_SJC_TAPID_6SL \ + -expected-id $_SJC_TAPID_6SLL # GDB target: Cortex-A9, using DAP, configuring only one core # Base addresses of cores: diff --git a/tcl/target/imx6sx.cfg b/tcl/target/imx6sx.cfg new file mode 100644 index 0000000..d3fae8a --- /dev/null +++ b/tcl/target/imx6sx.cfg @@ -0,0 +1,50 @@ +# +# Freescale i.MX6SoloX +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx6sx +} + +# 2x CoreSight Debug Access Port for Cortex-M4 and Cortex-A9 +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu_m4 -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID +dap create $_CHIPNAME.dap_m4 -chain-position $_CHIPNAME.cpu_m4 + +jtag newtap $_CHIPNAME cpu_a9 -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID +dap create $_CHIPNAME.dap_a9 -chain-position $_CHIPNAME.cpu_a9 + +# SDMA / no IDCODE +jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f + +# System JTAG Controller +if { [info exists SJC_TAPID] } { + set _SJC_TAPID $SJC_TAPID +} else { + set _SJC_TAPID 0x0891c01d +} +jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ + -expected-id $_SJC_TAPID -ignore-version + +# Cortex-A9 (boot core) +target create $_CHIPNAME.cpu_a9 cortex_a -dap $_CHIPNAME.dap_a9 \ + -coreid 0 -dbgbase 0x82150000 + +# Cortex-M4 (default off) +target create $_CHIPNAME.cpu_m4 cortex_m -dap $_CHIPNAME.dap_m4 \ + -ap-num 0 -defer-examine + +# AHB mem-ap target +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap_a9 -ap-num 0 + +# Default target is Cortex-A9 +targets $_CHIPNAME.cpu_a9 diff --git a/tcl/target/imx6ul.cfg b/tcl/target/imx6ul.cfg new file mode 100644 index 0000000..f42aa63 --- /dev/null +++ b/tcl/target/imx6ul.cfg @@ -0,0 +1,50 @@ +# +# Freescale i.MX6UltraLite series: 6UL 6ULL 6ULZ +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx6ul +} + +# CoreSight Debug Access Port +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID + +# SDMA / no IDCODE +jtag newtap $_CHIPNAME sdma -irlen 4 -ircapture 0x00 -irmask 0x0f + +# System JTAG Controller +set _SJC_TAPID_6UL 0x0891d01d +set _SJC_TAPID_6ULL 0x0891e01d +set _SJC_TAPID_6ULZ 0x1891e01d + +# Allow external override of the first SJC TAPID +if { [info exists SJC_TAPID] } { + set _SJC_TAPID $SJC_TAPID +} else { + set _SJC_TAPID $_SJC_TAPID_6UL +} + +jtag newtap $_CHIPNAME sjc -irlen 5 -ircapture 0x01 -irmask 0x1f \ + -ignore-version \ + -expected-id $_SJC_TAPID \ + -expected-id $_SJC_TAPID_6ULL \ + -expected-id $_SJC_TAPID_6ULZ \ + +# Create DAP +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# Main AHB bus +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# Cortex-A7 single core +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_a -dap $_CHIPNAME.dap -dbgbase 0x82130000 diff --git a/tcl/target/imx7.cfg b/tcl/target/imx7.cfg index f47dd7d..ea23deb 100644 --- a/tcl/target/imx7.cfg +++ b/tcl/target/imx7.cfg @@ -37,4 +37,9 @@ set _TARGETNAME_2 $_CHIPNAME.cpu_m4 target create $_TARGETNAME_2 cortex_m -dap $_CHIPNAME.dap -ap-num 4 \ -defer-examine +# +# AHB mem-ap target +# +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + targets $_TARGETNAME.0 diff --git a/tcl/target/imx7ulp.cfg b/tcl/target/imx7ulp.cfg new file mode 100644 index 0000000..879fcf8 --- /dev/null +++ b/tcl/target/imx7ulp.cfg @@ -0,0 +1,36 @@ +# +# NXP i.MX7ULP: Cortex-A7 + Cortex-M4 +# + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME imx7ulp +} + +# CoreSight Debug Access Port +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + # TAPID is from FreeScale! + set _DAP_TAPID 0x188e101d +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f \ + -expected-id $_DAP_TAPID + +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu + +# Cortex-A7 +target create $_CHIPNAME.cpu_a7 cortex_a -dap $_CHIPNAME.dap \ + -coreid 0 -dbgbase 0x80030000 + +# Cortex-M4 +# Boots by default so don't defer examination +target create $_CHIPNAME.cpu_m4 cortex_m -dap $_CHIPNAME.dap -ap-num 3 + +# AHB main soc bus +target create $_CHIPNAME.ahb mem_ap -dap $_CHIPNAME.dap -ap-num 0 + +# Default is Cortex-A7 +targets $_CHIPNAME.cpu_a7 diff --git a/tcl/target/imx8m.cfg b/tcl/target/imx8m.cfg index 5d7acbe..e3b7d24 100644 --- a/tcl/target/imx8m.cfg +++ b/tcl/target/imx8m.cfg @@ -52,7 +52,13 @@ for { set _core 0 } { $_core < $_cores } { incr _core } { } eval $_smp_command -targets $_TARGETNAME.0 # declare the auxiliary Cortex-M4 core on AP #4 -target create ${_CHIPNAME}.m4 cortex_m -dap ${_CHIPNAME}.dap -ap-num 4 +target create ${_CHIPNAME}.m4 cortex_m -dap ${_CHIPNAME}.dap -ap-num 4 \ + -defer-examine + +# AHB-AP for direct access to soc bus +target create ${_CHIPNAME}.ahb mem_ap -dap ${_CHIPNAME}.dap -ap-num 0 + +# default target is A53 core 0 +targets $_TARGETNAME.0 diff --git a/tcl/target/psoc4.cfg b/tcl/target/psoc4.cfg index eb51847..544e109 100644 --- a/tcl/target/psoc4.cfg +++ b/tcl/target/psoc4.cfg @@ -179,7 +179,7 @@ proc ocd_process_reset_inner { MODE } { } # Check if PSoC CPU is stopped in system ROM - set pc [ocd_reg pc] + set pc [reg pc] regsub {pc[^:]*: } $pc "" pc if { $pc < 0x10000000 || $pc > 0x1000ffff } { set hint "" diff --git a/tcl/target/renesas_r7s72100.cfg b/tcl/target/renesas_r7s72100.cfg new file mode 100644 index 0000000..f9466fc --- /dev/null +++ b/tcl/target/renesas_r7s72100.cfg @@ -0,0 +1,25 @@ +# Renesas R-Car RZ/A1H +# https://www.renesas.com/eu/en/products/microcontrollers-microprocessors/rz/rza/rza1h.html + +if { [info exists DAP_TAPID] } { + set _DAP_TAPID $DAP_TAPID +} else { + set _DAP_TAPID 0x4ba00477 +} + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME r7s72100 +} + +jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x01 -irmask 0x0f -expected-id $_DAP_TAPID + +# Configuring only one core using DAP. +# Base addresses of cores: +# core 0 - 0x80030000 +set _TARGETNAME $_CHIPNAME.ca9 +dap create ${_CHIPNAME}.dap -chain-position $_CHIPNAME.cpu +target create ${_TARGETNAME} cortex_a -dap ${_CHIPNAME}.dap -coreid 0 -dbgbase 0x80030000 + +targets ${_TARGETNAME} diff --git a/tcl/target/renesas_rcar_gen3.cfg b/tcl/target/renesas_rcar_gen3.cfg index a6eef67..2c478b2 100644 --- a/tcl/target/renesas_rcar_gen3.cfg +++ b/tcl/target/renesas_rcar_gen3.cfg @@ -47,17 +47,17 @@ switch $_soc { set _num_cr7 1 set _boot_core CA57 } - V3H { + V3M { set _CHIPNAME r8a77970 set _num_ca57 0 - set _num_ca53 4 + set _num_ca53 2 set _num_cr7 1 set _boot_core CA53 } - V3M { + V3H { set _CHIPNAME r8a77980 set _num_ca57 0 - set _num_ca53 2 + set _num_ca53 4 set _num_cr7 1 set _boot_core CA53 } diff --git a/tcl/target/stm32f7x.cfg b/tcl/target/stm32f7x.cfg index b777c61..ba1d12f 100755 --- a/tcl/target/stm32f7x.cfg +++ b/tcl/target/stm32f7x.cfg @@ -51,6 +51,19 @@ set _FLASHNAME $_CHIPNAME.flash flash bank $_FLASHNAME stm32f2x 0 0 0 0 $_TARGETNAME flash bank $_CHIPNAME.otp stm32f2x 0x1ff0f000 0 0 0 $_TARGETNAME +# On the STM32F7, the Flash is mapped at address 0x08000000 via the AXI and +# also address 0x00200000 via the ITCM. The former mapping is read-write in +# hardware, while the latter is read-only. By presenting an alias, we +# accomplish two things: +# (1) We allow writing at 0x00200000 (because the alias acts identically to the +# original bank), which allows code intended to run from that address to +# also be linked for loading at that address, simplifying linking. +# (2) We allow the proper memory map to be delivered to GDB, which will cause +# it to use hardware breakpoints at the 0x00200000 mapping (correctly +# identifying it as Flash), which it would otherwise not do. Configuring +# the Flash via ITCM alias as virtual +flash bank $_CHIPNAME.itcm-flash.alias virtual 0x00200000 0 0 0 $_TARGETNAME $_FLASHNAME + # adapter speed should be <= F_CPU/6. F_CPU after reset is 16MHz, so use F_JTAG = 2MHz adapter_khz 2000 diff --git a/tcl/target/swm050.cfg b/tcl/target/swm050.cfg new file mode 100644 index 0000000..a819f9c --- /dev/null +++ b/tcl/target/swm050.cfg @@ -0,0 +1,45 @@ +# Synwit SWM050 + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + set _CHIPNAME swm050 +} +set _CHIPSERIES swm050 + +if { [info exists WORKAREASIZE] } { + set _WORKAREASIZE $WORKAREASIZE +} else { + set _WORKAREASIZE 0x400 +} + +if { [info exists CPUTAPID] } { + set _CPUTAPID $CPUTAPID +} else { + set _CPUTAPID 0x410CC200 +} + +swd newdap $_CHIPNAME cpu -expected-id $_CPUTAPID +dap create $_CHIPNAME.dap -chain-position $_CHIPNAME.cpu +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -dap $_CHIPNAME.dap +$_TARGETNAME configure -work-area-phys 0x20000000 -work-area-size $_WORKAREASIZE +set _FLASHNAME $_CHIPNAME.flash +flash bank $_FLASHNAME swm050 0x0 0x2000 0 0 $_TARGETNAME + + +$_TARGETNAME configure -event reset-init { + # Stop the watchdog, just to be safe + mww 0x40019000 0x00 + # Set clock divider value to 1 + mww 0x400F0000 0x01 + # Set system clock to 18Mhz + mww 0x400F0008 0x00 +} + +# SWM050 (Cortex-M0 core) supports SYSRESETREQ +if {![using_hla]} { + # if srst is not fitted use SYSRESETREQ to + # perform a soft reset + cortex_m reset_config sysresetreq +} |