License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 15:07:57 +01:00
// SPDX-License-Identifier: GPL-2.0
2006-05-21 20:58:10 -07:00
/*
* Watchdog Driver Test Program
*/
2016-07-19 17:41:22 +02:00
# include <errno.h>
2006-05-21 20:58:10 -07:00
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include <unistd.h>
# include <fcntl.h>
2012-05-17 15:07:48 +05:30
# include <signal.h>
2017-07-01 14:57:26 +02:00
# include <getopt.h>
2006-05-21 20:58:10 -07:00
# include <sys/ioctl.h>
# include <linux/types.h>
# include <linux/watchdog.h>
2017-07-01 14:57:29 +02:00
# define DEFAULT_PING_RATE 1
2006-05-21 20:58:10 -07:00
int fd ;
2016-06-21 18:00:15 -05:00
const char v = ' V ' ;
2019-09-17 20:40:23 +02:00
static const char sopts [ ] = " bdehp:t:Tn:NLf:i " ;
2017-07-01 14:57:26 +02:00
static const struct option lopts [ ] = {
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
This option allows reporting to userspace the cause of the last boot
(POR/watchdog reset), being helpful in e.g. automated test-cases.
Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
- check if watchdog drivers properly implement WDIOF_CARDRESET.
- check the last boot status, if WDIOF_CARDRESET is implemented.
Make the `-b, --bootstatus` option one-shot. That means, skip the
keepalive mechanism if `-b` is provided on the command line, as we
are only interested in the boot status information.
Tested on Rcar-H3 Salvator-X board:
********************** Cold boot finished
salvator-x:/home/root# ./watchdog-test -h
Usage: ./watchdog-test [options]
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
Watchdog card disabled.
Watchdog timeout set to 1 seconds.
Watchdog ping rate set to 2 seconds.
Watchdog card enabled.
Watchdog Ticking Away!
********************** Reboot due to watchdog trigger finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Watchdog.
salvator-x:/home/root#
salvator-x:/home/root# reboot
********************** Reboot due to user action finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
{ " bootstatus " , no_argument , NULL , ' b ' } ,
2017-07-01 14:57:26 +02:00
{ " disable " , no_argument , NULL , ' d ' } ,
{ " enable " , no_argument , NULL , ' e ' } ,
{ " help " , no_argument , NULL , ' h ' } ,
{ " pingrate " , required_argument , NULL , ' p ' } ,
{ " timeout " , required_argument , NULL , ' t ' } ,
2018-09-26 15:23:09 -06:00
{ " gettimeout " , no_argument , NULL , ' T ' } ,
{ " pretimeout " , required_argument , NULL , ' n ' } ,
{ " getpretimeout " , no_argument , NULL , ' N ' } ,
2018-11-30 10:35:41 -07:00
{ " gettimeleft " , no_argument , NULL , ' L ' } ,
2019-08-30 15:32:23 -04:00
{ " file " , required_argument , NULL , ' f ' } ,
2019-09-17 20:40:23 +02:00
{ " info " , no_argument , NULL , ' i ' } ,
2017-07-01 14:57:26 +02:00
{ NULL , no_argument , NULL , 0x0 }
} ;
2006-05-21 20:58:10 -07:00
/*
* This function simply sends an IOCTL to the driver , which in turn ticks
* the PC Watchdog card to reset its internal timer so it doesn ' t trigger
* a computer reset .
*/
2009-09-22 16:43:42 -07:00
static void keep_alive ( void )
2006-05-21 20:58:10 -07:00
{
2017-07-01 14:57:25 +02:00
int dummy ;
int ret ;
2006-05-21 20:58:10 -07:00
2017-07-01 14:57:25 +02:00
ret = ioctl ( fd , WDIOC_KEEPALIVE , & dummy ) ;
if ( ! ret )
printf ( " . " ) ;
2006-05-21 20:58:10 -07:00
}
/*
* The main program . Run the program with " -d " to disable the card ,
* or " -e " to enable the card .
*/
2012-05-17 15:07:48 +05:30
2012-07-23 10:46:11 -07:00
static void term ( int sig )
2012-05-17 15:07:48 +05:30
{
2017-07-01 14:57:25 +02:00
int ret = write ( fd , & v , 1 ) ;
2016-07-19 17:41:22 +02:00
2017-07-01 14:57:25 +02:00
close ( fd ) ;
if ( ret < 0 )
printf ( " \n Stopping watchdog ticks failed (%d)... \n " , errno ) ;
else
printf ( " \n Stopping watchdog ticks... \n " ) ;
exit ( 0 ) ;
2012-05-17 15:07:48 +05:30
}
2017-07-01 14:57:26 +02:00
static void usage ( char * progname )
{
printf ( " Usage: %s [options] \n " , progname ) ;
2019-08-30 18:31:33 -04:00
printf ( " -f, --file \t \t Open watchdog device file \n " ) ;
printf ( " \t \t \t Default is /dev/watchdog \n " ) ;
2019-09-17 20:40:23 +02:00
printf ( " -i, --info \t \t Show watchdog_info \n " ) ;
2019-08-30 18:31:33 -04:00
printf ( " -b, --bootstatus \t Get last boot status (Watchdog/POR) \n " ) ;
printf ( " -d, --disable \t \t Turn off the watchdog timer \n " ) ;
printf ( " -e, --enable \t \t Turn on the watchdog timer \n " ) ;
printf ( " -h, --help \t \t Print the help message \n " ) ;
printf ( " -p, --pingrate=P \t Set ping rate to P seconds (default %d) \n " ,
DEFAULT_PING_RATE ) ;
printf ( " -t, --timeout=T \t Set timeout to T seconds \n " ) ;
printf ( " -T, --gettimeout \t Get the timeout \n " ) ;
printf ( " -n, --pretimeout=T \t Set the pretimeout to T seconds \n " ) ;
printf ( " -N, --getpretimeout \t Get the pretimeout \n " ) ;
printf ( " -L, --gettimeleft \t Get the time left until timer expires \n " ) ;
2017-07-01 14:57:26 +02:00
printf ( " \n " ) ;
printf ( " Parameters are parsed left-to-right in real-time. \n " ) ;
printf ( " Example: %s -d -t 10 -p 5 -e \n " , progname ) ;
2018-09-26 15:23:09 -06:00
printf ( " Example: %s -t 12 -T -n 7 -N \n " , progname ) ;
2017-07-01 14:57:26 +02:00
}
2006-05-21 20:58:10 -07:00
int main ( int argc , char * argv [ ] )
{
2017-07-01 14:57:25 +02:00
int flags ;
2017-07-01 14:57:29 +02:00
unsigned int ping_rate = DEFAULT_PING_RATE ;
2017-07-01 14:57:25 +02:00
int ret ;
2017-07-01 14:57:26 +02:00
int c ;
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
This option allows reporting to userspace the cause of the last boot
(POR/watchdog reset), being helpful in e.g. automated test-cases.
Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
- check if watchdog drivers properly implement WDIOF_CARDRESET.
- check the last boot status, if WDIOF_CARDRESET is implemented.
Make the `-b, --bootstatus` option one-shot. That means, skip the
keepalive mechanism if `-b` is provided on the command line, as we
are only interested in the boot status information.
Tested on Rcar-H3 Salvator-X board:
********************** Cold boot finished
salvator-x:/home/root# ./watchdog-test -h
Usage: ./watchdog-test [options]
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
Watchdog card disabled.
Watchdog timeout set to 1 seconds.
Watchdog ping rate set to 2 seconds.
Watchdog card enabled.
Watchdog Ticking Away!
********************** Reboot due to watchdog trigger finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Watchdog.
salvator-x:/home/root#
salvator-x:/home/root# reboot
********************** Reboot due to user action finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
int oneshot = 0 ;
2019-08-30 15:32:23 -04:00
char * file = " /dev/watchdog " ;
2019-09-17 20:40:22 +02:00
struct watchdog_info info ;
2010-04-05 11:31:29 +01:00
2017-07-01 14:57:25 +02:00
setbuf ( stdout , NULL ) ;
2016-06-21 18:00:14 -05:00
2019-08-30 15:32:23 -04:00
while ( ( c = getopt_long ( argc , argv , sopts , lopts , NULL ) ) ! = - 1 ) {
if ( c = = ' f ' )
file = optarg ;
}
fd = open ( file , O_WRONLY ) ;
2006-05-21 20:58:10 -07:00
2017-07-01 14:57:25 +02:00
if ( fd = = - 1 ) {
2018-09-26 13:07:11 -06:00
if ( errno = = ENOENT )
2019-08-30 15:32:23 -04:00
printf ( " Watchdog device (%s) not found. \n " , file ) ;
2018-09-26 13:07:11 -06:00
else if ( errno = = EACCES )
printf ( " Run watchdog as root. \n " ) ;
else
printf ( " Watchdog device open failed %s \n " ,
strerror ( errno ) ) ;
2017-07-01 14:57:25 +02:00
exit ( - 1 ) ;
}
2006-05-21 20:58:10 -07:00
2019-09-17 20:40:22 +02:00
/*
* Validate that ` file ` is a watchdog device
*/
ret = ioctl ( fd , WDIOC_GETSUPPORT , & info ) ;
if ( ret ) {
printf ( " WDIOC_GETSUPPORT error '%s' \n " , strerror ( errno ) ) ;
close ( fd ) ;
exit ( ret ) ;
}
2019-08-30 15:32:23 -04:00
optind = 0 ;
2017-07-01 14:57:26 +02:00
while ( ( c = getopt_long ( argc , argv , sopts , lopts , NULL ) ) ! = - 1 ) {
switch ( c ) {
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
This option allows reporting to userspace the cause of the last boot
(POR/watchdog reset), being helpful in e.g. automated test-cases.
Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
- check if watchdog drivers properly implement WDIOF_CARDRESET.
- check the last boot status, if WDIOF_CARDRESET is implemented.
Make the `-b, --bootstatus` option one-shot. That means, skip the
keepalive mechanism if `-b` is provided on the command line, as we
are only interested in the boot status information.
Tested on Rcar-H3 Salvator-X board:
********************** Cold boot finished
salvator-x:/home/root# ./watchdog-test -h
Usage: ./watchdog-test [options]
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
Watchdog card disabled.
Watchdog timeout set to 1 seconds.
Watchdog ping rate set to 2 seconds.
Watchdog card enabled.
Watchdog Ticking Away!
********************** Reboot due to watchdog trigger finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Watchdog.
salvator-x:/home/root#
salvator-x:/home/root# reboot
********************** Reboot due to user action finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
case ' b ' :
flags = 0 ;
oneshot = 1 ;
ret = ioctl ( fd , WDIOC_GETBOOTSTATUS , & flags ) ;
if ( ! ret )
printf ( " Last boot is caused by: %s. \n " , ( flags ! = 0 ) ?
" Watchdog " : " Power-On-Reset " ) ;
else
2018-09-26 15:23:08 -06:00
printf ( " WDIOC_GETBOOTSTATUS error '%s' \n " , strerror ( errno ) ) ;
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
This option allows reporting to userspace the cause of the last boot
(POR/watchdog reset), being helpful in e.g. automated test-cases.
Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
- check if watchdog drivers properly implement WDIOF_CARDRESET.
- check the last boot status, if WDIOF_CARDRESET is implemented.
Make the `-b, --bootstatus` option one-shot. That means, skip the
keepalive mechanism if `-b` is provided on the command line, as we
are only interested in the boot status information.
Tested on Rcar-H3 Salvator-X board:
********************** Cold boot finished
salvator-x:/home/root# ./watchdog-test -h
Usage: ./watchdog-test [options]
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
Watchdog card disabled.
Watchdog timeout set to 1 seconds.
Watchdog ping rate set to 2 seconds.
Watchdog card enabled.
Watchdog Ticking Away!
********************** Reboot due to watchdog trigger finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Watchdog.
salvator-x:/home/root#
salvator-x:/home/root# reboot
********************** Reboot due to user action finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
break ;
2017-07-01 14:57:26 +02:00
case ' d ' :
2017-07-01 14:57:25 +02:00
flags = WDIOS_DISABLECARD ;
ret = ioctl ( fd , WDIOC_SETOPTIONS , & flags ) ;
if ( ! ret )
printf ( " Watchdog card disabled. \n " ) ;
2018-09-26 16:37:43 -06:00
else {
2018-09-26 15:23:08 -06:00
printf ( " WDIOS_DISABLECARD error '%s' \n " , strerror ( errno ) ) ;
2018-09-26 16:37:43 -06:00
oneshot = 1 ;
}
2017-07-01 14:57:26 +02:00
break ;
case ' e ' :
2017-07-01 14:57:25 +02:00
flags = WDIOS_ENABLECARD ;
ret = ioctl ( fd , WDIOC_SETOPTIONS , & flags ) ;
if ( ! ret )
printf ( " Watchdog card enabled. \n " ) ;
2018-09-26 16:37:43 -06:00
else {
2018-09-26 15:23:08 -06:00
printf ( " WDIOS_ENABLECARD error '%s' \n " , strerror ( errno ) ) ;
2018-09-26 16:37:43 -06:00
oneshot = 1 ;
}
2017-07-01 14:57:26 +02:00
break ;
case ' p ' :
ping_rate = strtoul ( optarg , NULL , 0 ) ;
2017-07-01 14:57:29 +02:00
if ( ! ping_rate )
ping_rate = DEFAULT_PING_RATE ;
2017-07-01 14:57:26 +02:00
printf ( " Watchdog ping rate set to %u seconds. \n " , ping_rate ) ;
break ;
case ' t ' :
2017-07-01 14:57:27 +02:00
flags = strtoul ( optarg , NULL , 0 ) ;
2017-07-01 14:57:25 +02:00
ret = ioctl ( fd , WDIOC_SETTIMEOUT , & flags ) ;
if ( ! ret )
printf ( " Watchdog timeout set to %u seconds. \n " , flags ) ;
2018-09-26 16:37:43 -06:00
else {
2018-09-26 15:23:08 -06:00
printf ( " WDIOC_SETTIMEOUT error '%s' \n " , strerror ( errno ) ) ;
2018-09-26 16:37:43 -06:00
oneshot = 1 ;
}
2017-07-01 14:57:26 +02:00
break ;
2018-09-26 15:23:09 -06:00
case ' T ' :
oneshot = 1 ;
ret = ioctl ( fd , WDIOC_GETTIMEOUT , & flags ) ;
if ( ! ret )
printf ( " WDIOC_GETTIMEOUT returns %u seconds. \n " , flags ) ;
else
printf ( " WDIOC_GETTIMEOUT error '%s' \n " , strerror ( errno ) ) ;
break ;
case ' n ' :
flags = strtoul ( optarg , NULL , 0 ) ;
ret = ioctl ( fd , WDIOC_SETPRETIMEOUT , & flags ) ;
if ( ! ret )
printf ( " Watchdog pretimeout set to %u seconds. \n " , flags ) ;
2018-09-26 16:37:43 -06:00
else {
2018-09-26 15:23:09 -06:00
printf ( " WDIOC_SETPRETIMEOUT error '%s' \n " , strerror ( errno ) ) ;
2018-09-26 16:37:43 -06:00
oneshot = 1 ;
}
2018-09-26 15:23:09 -06:00
break ;
case ' N ' :
oneshot = 1 ;
ret = ioctl ( fd , WDIOC_GETPRETIMEOUT , & flags ) ;
if ( ! ret )
printf ( " WDIOC_GETPRETIMEOUT returns %u seconds. \n " , flags ) ;
else
printf ( " WDIOC_GETPRETIMEOUT error '%s' \n " , strerror ( errno ) ) ;
break ;
2018-11-30 10:35:41 -07:00
case ' L ' :
oneshot = 1 ;
ret = ioctl ( fd , WDIOC_GETTIMELEFT , & flags ) ;
if ( ! ret )
printf ( " WDIOC_GETTIMELEFT returns %u seconds. \n " , flags ) ;
else
printf ( " WDIOC_GETTIMELEFT error '%s' \n " , strerror ( errno ) ) ;
break ;
2019-08-30 15:32:23 -04:00
case ' f ' :
/* Handled above */
break ;
2019-09-17 20:40:23 +02:00
case ' i ' :
/*
* watchdog_info was obtained as part of file open
* validation . So we just show it here .
*/
oneshot = 1 ;
printf ( " watchdog_info: \n " ) ;
printf ( " identity: \t \t %s \n " , info . identity ) ;
printf ( " firmware_version: \t %u \n " ,
info . firmware_version ) ;
printf ( " options: \t \t %08x \n " , info . options ) ;
break ;
2018-11-30 10:35:41 -07:00
2017-07-01 14:57:26 +02:00
default :
usage ( argv [ 0 ] ) ;
2017-07-01 14:57:25 +02:00
goto end ;
}
}
2006-05-21 20:58:10 -07:00
selftests: watchdog: get boot reason via WDIOC_GETBOOTSTATUS
Some watchdog drivers implement WDIOF_CARDRESET feature. As example,
see commit b6ef36d2c1e3 ("watchdog: qcom: Report reboot reason").
This option allows reporting to userspace the cause of the last boot
(POR/watchdog reset), being helpful in e.g. automated test-cases.
Add support for WDIOC_GETBOOTSTATUS in the test code, to be able to:
- check if watchdog drivers properly implement WDIOF_CARDRESET.
- check the last boot status, if WDIOF_CARDRESET is implemented.
Make the `-b, --bootstatus` option one-shot. That means, skip the
keepalive mechanism if `-b` is provided on the command line, as we
are only interested in the boot status information.
Tested on Rcar-H3 Salvator-X board:
********************** Cold boot finished
salvator-x:/home/root# ./watchdog-test -h
Usage: ./watchdog-test [options]
-b, --bootstatus Get last boot status (Watchdog/POR)
-d, --disable Turn off the watchdog timer
-e, --enable Turn on the watchdog timer
-h, --help Print the help message
-p, --pingrate=P Set ping rate to P seconds (default 1)
-t, --timeout=T Set timeout to T seconds
Parameters are parsed left-to-right in real-time.
Example: ./watchdog-test -d -t 10 -p 5 -e
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
salvator-x:/home/root# ./watchdog-test -d -t 1 -p 2 -e
Watchdog card disabled.
Watchdog timeout set to 1 seconds.
Watchdog ping rate set to 2 seconds.
Watchdog card enabled.
Watchdog Ticking Away!
********************** Reboot due to watchdog trigger finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Watchdog.
salvator-x:/home/root#
salvator-x:/home/root# reboot
********************** Reboot due to user action finished
salvator-x:/home/root# ./watchdog-test -b
Last boot is caused by: Power-On-Reset.
salvator-x:/home/root#
Signed-off-by: Eugeniu Rosca <erosca@de.adit-jv.com>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
2017-07-01 14:57:30 +02:00
if ( oneshot )
goto end ;
2017-07-01 14:57:25 +02:00
printf ( " Watchdog Ticking Away! \n " ) ;
2015-06-29 11:46:17 -05:00
2017-07-01 14:57:25 +02:00
signal ( SIGINT , term ) ;
2012-05-17 15:07:48 +05:30
2017-07-01 14:57:25 +02:00
while ( 1 ) {
keep_alive ( ) ;
sleep ( ping_rate ) ;
}
2012-05-14 23:42:02 +05:30
end :
2017-07-01 14:57:25 +02:00
ret = write ( fd , & v , 1 ) ;
if ( ret < 0 )
printf ( " Stopping watchdog ticks failed (%d)... \n " , errno ) ;
close ( fd ) ;
return 0 ;
2006-05-21 20:58:10 -07:00
}