History log of /linux-master/tools/spi/spidev_test.c
Revision Date Author Comments
# b229a7f5 30-May-2023 Boerge Struempfel <boerge.struempfel@gmail.com>

spi: spidev_test Add three missing spi mode bits

Added the three missing spi mode bits SPI_3WIRE_HIZ, SPI_RX_CPHA_FLIP,
and SPI_MOSI_IDLE_LOW.

Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
Link: https://lore.kernel.org/r/20230530141641.1155691-6-boerge.struempfel@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 113f36f2 30-May-2023 Boerge Struempfel <boerge.struempfel@gmail.com>

spi: spidev_test: Sorted the options into logical groups

In order to increase usability, the command line options are sorted into
logical groups. In addition, the usage string was sorted alphabetically,
and the missing parameters '8','i' and 'o' were added. Furthermore, the
option descriptions were moved further to the right, in order to allow
for longer option names.

Signed-off-by: Boerge Struempfel <boerge.struempfel@gmail.com>
Link: https://lore.kernel.org/r/20230530141641.1155691-5-boerge.struempfel@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>


# 41ecad2c 12-Jun-2022 David Fries <David@fries.net>

spi: spidev_test: Warn when the mode is not the requested mode

Print a warning if the device mode doesn't match the requested mode.
The user doesn't enter the mode in hex so it isn't obvious when
setting the mode succeeds that the mode isn't the requested mode. The
kernel logs a message, it will be more visible if the test also prints
a warning. I was testing --quad, which is unsupported, but doesn't
cause the mode request to fail.

Signed-off-by: David Fries <David@Fries.net>
Link: https://lore.kernel.org/r/YqbNnSGtWHe/GG7w@spacedout.fries.net
Signed-off-by: Mark Brown <broonie@kernel.org>


# bd207791 11-Jun-2020 Qing Zhang <zhangqing@loongson.cn>

spi: tools: Make default_tx/rx and input_tx static

Fix the following sparse warning:

./spidev_test.c:50:9: warning: symbol 'default_tx' was not declared. Should it be static?
./spidev_test.c:59:9: warning: symbol 'default_rx' was not declared. Should it be static?
./spidev_test.c:60:6: warning: symbol 'input_tx' was not declared. Should it be static?

Signed-off-by: Qing Zhang <zhangqing@loongson.cn>
Link: https://lore.kernel.org/r/1591880212-13479-1-git-send-email-zhangqing@loongson.cn
Signed-off-by: Mark Brown <broonie@kernel.org>


# 9ec8ade8 07-Jun-2020 Geert Uytterhoeven <geert+renesas@glider.be>

spi: spidev_test: Use %u to format unsigned numbers

Consistently use %u to format unsigned numbers.
For "bits" this doesn't matter that much, as it is "uint8_t".
However, "speed" is "uint32_t", so in case people use "-s -1" to force
the maximum, they would see:

max speed: -1 Hz (4294967 KHz)

While at it, use "k" (kilo) instead of "K" (kelvin) in "kHz".

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20200608100049.30648-1-geert+renesas@glider.be
Signed-off-by: Mark Brown <broonie@kernel.org>


# 896fa735 15-Apr-2020 Geert Uytterhoeven <geert+renesas@glider.be>

spi: spidev_test: Add support for Octal mode data transfers

Add support for octal transfers using the -8/--octal command line
parameter.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/20200416101835.14573-3-geert+renesas@glider.be
Signed-off-by: Mark Brown <broonie@kernel.org>


# 470a072e 12-Feb-2020 Tiezhu Yang <yangtiezhu@loongson.cn>

spi: spidev_test: Use perror() only if errno is not 0

It is better to use perror() only if errno is not 0, it should use printf()
when errno is 0, otherwise there exists redudant ": Success".

E.g. without this patch:

$ ./spidev_test -p 1234 --input test.bin
only one of -p and --input may be selected: Success
Aborted (core dumped)

With this patch:

$ ./spidev_test -p 1234 --input test.bin
only one of -p and --input may be selected
Aborted (core dumped)

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/1581567368-8055-3-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Mark Brown <broonie@kernel.org>


# 1f3c3632 12-Feb-2020 Tiezhu Yang <yangtiezhu@loongson.cn>

spi: spidev_test: Check input_tx and input_file first after parse options

It is better to check input_tx and input_file first after parse options.
Otherwise, it will do some useless operations when both -p and --input
are selected.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/1581567368-8055-2-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Mark Brown <broonie@kernel.org>


# 020bd6c4 12-Feb-2020 Tiezhu Yang <yangtiezhu@loongson.cn>

spi: spidev_test: Remove break after exit statement

When call print_usage() in parse_opts(), it will exit directly.
Since break is not useful after exit statement, remove it.

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://lore.kernel.org/r/1581567368-8055-1-git-send-email-yangtiezhu@loongson.cn
Signed-off-by: Mark Brown <broonie@kernel.org>


# 84a14ae8 28-May-2019 Thomas Gleixner <tglx@linutronix.de>

treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 178

Based on 1 normalized pattern(s):

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

extracted by the scancode license scanner the SPDX license identifier

GPL-2.0-only

has been chosen to replace the boilerplate/reference in 24 file(s).

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Alexios Zavras <alexios.zavras@intel.com>
Reviewed-by: Steve Winslow <swinslow@gmail.com>
Reviewed-by: Allison Randal <allison@lohutok.net>
Reviewed-by: Richard Fontana <rfontana@redhat.com>
Cc: linux-spdx@vger.kernel.org
Link: https://lkml.kernel.org/r/20190528170026.162703968@linutronix.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# 35386dfd 03-Sep-2018 Geert Uytterhoeven <geert+renesas@glider.be>

spi: spidev_test: Improve decoded text part of hex dump

- Print spaces as spaces,
- Do not print characters > 126, as they will be shown as garbage
in the modern UTF-8 era,
- Use a normal period instead of its hexadecimal ASCII value,
- Delimit the text part with pipe symbols on both sides (was left side
only), without any spaces, to make it clear where the decoded text
starts and ends,
- Drop a useless comment.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 9006a7b3 21-Mar-2017 Frode Isaksen <fisaksen@baylibre.com>

spi: spidev_test: add option to continuously transfer data

Add option to send+recv <size> bytes with <iter> iterations
and show the transfer rate every 5 seconds.
Example:
rate: tx 4235.2kbps, rx 4235.2kbps
total: tx 4882.8KB, rx 4882.8KB

Signed-off-by: Frode Isaksen <fisaksen@baylibre.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# e634b76c 04-Nov-2016 Michal Vokáč <vokac.m@gmail.com>

spi: spidev_test: Fix input file check when transferring file

Check the input file fd instead of spidev fd.
The spidev fd is supposed to be OK otherwise the transfer_file() function
would not be called at all.

Signed-off-by: Michal Vokáč <vokac.m@gmail.com>
Reviewed-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 0278b34b 09-Sep-2016 Geert Uytterhoeven <geert+renesas@glider.be>

spi: spidev_test: Fix buffer overflow in unescape()

Sometimes spidev_test crashes with:

*** Error in `spidev_test': munmap_chunk(): invalid pointer: 0x00022020 ***
Aborted

or just

Segmentation fault

This is due to transfer_escaped_string() miscalculating the required
size of the buffer by one byte, causing a buffer overflow in unescape().

Drop the bogus "+ 1" in the strlen() parameter to fix this.

Note that unescape() never copies the zero-terminator of the source
string, so it writes at most as many bytes as the length of the source
string.

Fixes: 30061915be6e3a2c (spi: spidev_test: Added input buffer from the terminal)
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: <stable@vger.kernel.org> # v4.5+


# 8736f802 12-Aug-2016 Baruch Siach <baruch@tkos.co.il>

spi: spidev_test: fix build with musl libc

spidev.h uses _IOC_SIZEBITS directly. musl libc does not provide this macro
unless linux/ioctl.h is included explicitly. Fixes build failures like:

In file included from .../host/usr/arm-buildroot-linux-musleabihf/sysroot/usr/include/sys/ioctl.h:7:0,
from .../build/spidev_test-v3.15/spidev_test.c:20:
.../build/spidev_test-v3.15/spidev_test.c: In function ‘transfer’:
.../build/spidev_test-v3.15/spidev_test.c:75:18: error: ‘_IOC_SIZEBITS’ undeclared (first use in this function)
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
^

Signed-off-by: Baruch Siach <baruch@tkos.co.il>
Signed-off-by: Mark Brown <broonie@kernel.org>


# edd3899c 04-Dec-2015 Fabio Estevam <fabio.estevam@freescale.com>

spi: spidev_test: Fix typo in error message

Fix the spelling of 'output' in the error message.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# b2cfc904 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: spidev_test: fix whitespace

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# a20874f7 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: spidev_test: check error

Check the result of sscanf to verify a result was found.
report and error and abort if pattern was not found.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 983b27886 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: spidev_test: output to a file

For testing of larger data transfers, output unmodified data
directly to a file.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 7af475a5 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: spidev_test: accept input from a file

Add input file support to facilitate testing larger data.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 5c437a40 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: spidev_test: transfer_escaped_string function

Move the input_tx code into its own small function.
This cleans up some variables from main() that are used only here.
While we are at it, check malloc calls instead of assuming they succeed.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>


# 5eca4d84 18-Nov-2015 Joshua Clayton <stillcompiling@gmail.com>

spi: Move spi code from Documentation to tools

Jon Corbet requested this code moved with the last changeset,
https://lkml.org/lkml/2015/3/1/144,
but the patch was not applied because it missed the Makefile.
Moved spidev_test, spidev_fdx and their Makefile infrastructure.

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>