[PATCH v3 08/23] watchdog: add and use Kconfig HAS_WATCHDOG_RUNNING

Troy Kisky troykiskyboundary at gmail.com
Mon Mar 13 22:31:30 CET 2023


defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
is a common pattern. Create an new config symbol
HAS_WATCHDOG_RUNNING to express it.

Signed-off-by: Troy Kisky <troykiskyboundary at gmail.com>
---

Changes in v3:
        new patch to address Tom's concerns

 arch/arm/mach-omap2/boot-common.c   |  5 ++---
 arch/m68k/lib/time.c                |  7 +++----
 arch/powerpc/lib/interrupts.c       |  5 ++---
 arch/powerpc/lib/ticks.S            |  2 +-
 board/astro/mcf5373l/fpga.c         | 10 ++++------
 boot/image-board.c                  |  2 +-
 cmd/ximg.c                          | 10 ++++------
 common/board_f.c                    |  4 ++--
 common/spl/Kconfig                  |  4 ++++
 drivers/crypto/aspeed/aspeed_hace.c |  2 +-
 drivers/crypto/hash/hash_sw.c       |  2 +-
 drivers/timer/mpc83xx_timer.c       |  5 ++---
 drivers/watchdog/Kconfig            |  3 +++
 fs/cramfs/uncompress.c              |  9 ++++-----
 include/watchdog.h                  |  7 ++-----
 lib/bzip2/bzlib.c                   |  5 ++---
 lib/bzip2/bzlib_decompress.c        | 20 ++++++++------------
 lib/crc32.c                         |  2 +-
 lib/md5.c                           |  2 +-
 lib/sha1.c                          |  2 +-
 lib/sha256.c                        |  2 +-
 lib/sha512.c                        |  2 +-
 22 files changed, 51 insertions(+), 61 deletions(-)

diff --git a/arch/arm/mach-omap2/boot-common.c b/arch/arm/mach-omap2/boot-common.c
index 9a342a1bf95..928a4136781 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -302,9 +302,8 @@ void spl_board_init(void)
 #if defined(CONFIG_AM33XX) && defined(CONFIG_SPL_MUSB_NEW)
 	arch_misc_init();
 #endif
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	hw_watchdog_init();
-#endif
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+		hw_watchdog_init();
 #ifdef CONFIG_AM33XX
 	am33xx_spl_board_init();
 #endif
diff --git a/arch/m68k/lib/time.c b/arch/m68k/lib/time.c
index 2ce69088d94..4a9841667b7 100644
--- a/arch/m68k/lib/time.c
+++ b/arch/m68k/lib/time.c
@@ -70,11 +70,10 @@ void dtimer_interrupt(void *not_used)
 		timerp->ter = (DTIM_DTER_CAP | DTIM_DTER_REF);
 		timestamp++;
 
-		#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
-		if (CFG_SYS_WATCHDOG_FREQ && (timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0) {
+		if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING) &&
+		    CFG_SYS_WATCHDOG_FREQ &&
+		    !(timestamp % CFG_SYS_WATCHDOG_FREQ))
 			schedule();
-		}
-		#endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 		return;
 	}
 }
diff --git a/arch/powerpc/lib/interrupts.c b/arch/powerpc/lib/interrupts.c
index df312dfa28e..f76b2db9025 100644
--- a/arch/powerpc/lib/interrupts.c
+++ b/arch/powerpc/lib/interrupts.c
@@ -79,10 +79,9 @@ void timer_interrupt(struct pt_regs *regs)
 
 	timestamp++;
 
-#if defined(CONFIG_WATCHDOG) || defined (CONFIG_HW_WATCHDOG)
-	if (CFG_SYS_WATCHDOG_FREQ && (timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0)
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING) &&
+	    CFG_SYS_WATCHDOG_FREQ && !(timestamp % CFG_SYS_WATCHDOG_FREQ))
 		schedule();
-#endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 
 #ifdef CONFIG_LED_STATUS
 	status_led_tick(timestamp);
diff --git a/arch/powerpc/lib/ticks.S b/arch/powerpc/lib/ticks.S
index 8647d77cc9a..dd9afe693df 100644
--- a/arch/powerpc/lib/ticks.S
+++ b/arch/powerpc/lib/ticks.S
@@ -41,7 +41,7 @@ wait_ticks:
 	addc    r14, r4, r14	/* Compute end time lower */
 	addze	r15, r3		/*     and end time upper */
 
-#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 	bl	schedule	/* Trigger watchdog, if needed */
 #endif
 1:	bl	get_ticks	/* Get current time */
diff --git a/board/astro/mcf5373l/fpga.c b/board/astro/mcf5373l/fpga.c
index f85737432b3..3e1f507cdfe 100644
--- a/board/astro/mcf5373l/fpga.c
+++ b/board/astro/mcf5373l/fpga.c
@@ -122,9 +122,8 @@ int altera_write_fn(const void *buf, size_t len, int flush, int cookie)
 		} while (i > 0);
 
 		if (bytecount % len_40 == 0) {
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-			schedule();
-#endif
+			if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+				schedule();
 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
 			putc('.');	/* let them know we are alive */
 #endif
@@ -342,9 +341,8 @@ int xilinx_fastwr_config_fn(void *buf, size_t len, int flush, int cookie)
 			val <<= 1;
 		}
 		if (bytecount % len_40 == 0) {
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-			schedule();
-#endif
+			if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+				schedule();
 #ifdef CONFIG_SYS_FPGA_PROG_FEEDBACK
 			putc('.');	/* let them know we are alive */
 #endif
diff --git a/boot/image-board.c b/boot/image-board.c
index 25b60ec30b3..48215bdef78 100644
--- a/boot/image-board.c
+++ b/boot/image-board.c
@@ -173,7 +173,7 @@ void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
 	if (to == from)
 		return;
 
-	if (IS_ENABLED(CONFIG_HW_WATCHDOG) || IS_ENABLED(CONFIG_WATCHDOG)) {
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)) {
 		if (to > from) {
 			from += len;
 			to += len;
diff --git a/cmd/ximg.c b/cmd/ximg.c
index 60ed2c9f6f9..a42a944ae19 100644
--- a/cmd/ximg.c
+++ b/cmd/ximg.c
@@ -186,8 +186,7 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 	if (argc > 3) {
 		switch (comp) {
 		case IH_COMP_NONE:
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-			{
+			if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)) {
 				size_t l = len;
 				size_t tail;
 				void *to = (void *) dest;
@@ -203,11 +202,10 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 					from += tail;
 					l -= tail;
 				}
+			} else {
+				printf("   Loading part %d ... ", part);
+				memmove((char *)dest, (char *)data, len);
 			}
-#else	/* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
-			printf("   Loading part %d ... ", part);
-			memmove((char *) dest, (char *)data, len);
-#endif	/* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
 			break;
 #ifdef CONFIG_GZIP
 		case IH_COMP_GZIP:
diff --git a/common/board_f.c b/common/board_f.c
index f3c1ab53b1c..54220bc1d3b 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -84,7 +84,7 @@ __weak void blue_led_off(void) {}
  * a structure...
  */
 
-#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 static int init_func_watchdog_init(void)
 {
 # if defined(CONFIG_HW_WATCHDOG) && \
@@ -106,7 +106,7 @@ int init_func_watchdog_reset(void)
 
 	return 0;
 }
-#endif /* CONFIG_WATCHDOG */
+#endif /* HAS_WATCHDOG_RUNNING */
 
 __weak void board_add_ram_info(int use_default)
 {
diff --git a/common/spl/Kconfig b/common/spl/Kconfig
index 2c042ad3066..8f0edd66225 100644
--- a/common/spl/Kconfig
+++ b/common/spl/Kconfig
@@ -1444,6 +1444,10 @@ config SPL_WATCHDOG
 	  detects no activity for a while (such as a software crash). This
 	  enables the drivers in drivers/watchdog as part of an SPL build.
 
+config SPL_HAS_WATCHDOG_RUNNING
+	def_bool y if SPL_WATCHDOG || HW_WATCHDOG
+	depends on HAS_WATCHDOG_RUNNING
+
 config SPL_YMODEM_SUPPORT
 	bool "Support loading using Ymodem"
 	depends on SPL_SERIAL
diff --git a/drivers/crypto/aspeed/aspeed_hace.c b/drivers/crypto/aspeed/aspeed_hace.c
index 6b6c8fa6588..28a39e7b599 100644
--- a/drivers/crypto/aspeed/aspeed_hace.c
+++ b/drivers/crypto/aspeed/aspeed_hace.c
@@ -288,7 +288,7 @@ static int aspeed_hace_digest_wd(struct udevice *dev, enum HASH_ALGO algo,
 	if (rc)
 		return rc;
 
-	if (IS_ENABLED(CONFIG_HW_WATCHDOG) || CONFIG_IS_ENABLED(WATCHDOG)) {
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)) {
 		cur = ibuf;
 		end = ibuf + ilen;
 
diff --git a/drivers/crypto/hash/hash_sw.c b/drivers/crypto/hash/hash_sw.c
index d8065d68ea4..51cead45a4f 100644
--- a/drivers/crypto/hash/hash_sw.c
+++ b/drivers/crypto/hash/hash_sw.c
@@ -244,7 +244,7 @@ static int sw_hash_digest_wd(struct udevice *dev, enum HASH_ALGO algo,
 	if (rc)
 		return rc;
 
-	if (IS_ENABLED(CONFIG_HW_WATCHDOG) || CONFIG_IS_ENABLED(WATCHDOG)) {
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)) {
 		cur = ibuf;
 		end = ibuf + ilen;
 
diff --git a/drivers/timer/mpc83xx_timer.c b/drivers/timer/mpc83xx_timer.c
index 7814cb6a5d6..a0858cc49b5 100644
--- a/drivers/timer/mpc83xx_timer.c
+++ b/drivers/timer/mpc83xx_timer.c
@@ -174,10 +174,9 @@ void timer_interrupt(struct pt_regs *regs)
 
 	priv->timestamp++;
 
-#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
-	if (CFG_SYS_WATCHDOG_FREQ && (priv->timestamp % (CFG_SYS_WATCHDOG_FREQ)) == 0)
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING) &&
+	    CFG_SYS_WATCHDOG_FREQ && !(priv->timestamp % CFG_SYS_WATCHDOG_FREQ))
 		schedule();
-#endif    /* CONFIG_WATCHDOG || CONFIG_HW_WATCHDOG */
 
 #ifdef CONFIG_LED_STATUS
 	status_led_tick(priv->timestamp);
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index b5ac8f7f50d..46c0c1efedf 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -35,6 +35,9 @@ config WATCHDOG_TIMEOUT_MSECS
 	help
 	  Watchdog timeout in msec
 
+config HAS_WATCHDOG_RUNNING
+	def_bool y if WATCHDOG || HW_WATCHDOG
+
 config HW_WATCHDOG
 	bool
 
diff --git a/fs/cramfs/uncompress.c b/fs/cramfs/uncompress.c
index 0d071b69f4c..80000110d5d 100644
--- a/fs/cramfs/uncompress.c
+++ b/fs/cramfs/uncompress.c
@@ -62,11 +62,10 @@ int cramfs_uncompress_init (void)
 	stream.next_in = 0;
 	stream.avail_in = 0;
 
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	stream.outcb = (cb_func)cyclic_run;
-#else
-	stream.outcb = Z_NULL;
-#endif /* CONFIG_HW_WATCHDOG */
+	if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+		stream.outcb = (cb_func)cyclic_run;
+	else
+		stream.outcb = Z_NULL;
 
 	err = inflateInit (&stream);
 	if (err != Z_OK) {
diff --git a/include/watchdog.h b/include/watchdog.h
index ac5f11e376f..60086e1ae30 100644
--- a/include/watchdog.h
+++ b/include/watchdog.h
@@ -20,7 +20,7 @@
  */
 int init_func_watchdog_reset(void);
 
-#if defined(CONFIG_WATCHDOG) || defined(CONFIG_HW_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #define INIT_FUNC_WATCHDOG_INIT	init_func_watchdog_init,
 #define INIT_FUNC_WATCHDOG_RESET	init_func_watchdog_reset,
 #else
@@ -35,10 +35,7 @@ int init_func_watchdog_reset(void);
 /*
  * Prototypes from $(CPU)/cpu.c.
  */
-
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	void hw_watchdog_init(void);
-#endif
+void hw_watchdog_init(void);
 
 #if defined(CONFIG_MPC85xx)
 	void init_85xx_watchdog(void);
diff --git a/lib/bzip2/bzlib.c b/lib/bzip2/bzlib.c
index bd589aa810c..904ff1332be 100644
--- a/lib/bzip2/bzlib.c
+++ b/lib/bzip2/bzlib.c
@@ -843,9 +843,8 @@ int BZ_API(BZ2_bzDecompress) ( bz_stream *strm )
    if (s->strm != strm) return BZ_PARAM_ERROR;
 
    while (True) {
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	schedule();
-#endif
+      if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+	 schedule();
       if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
       if (s->state == BZ_X_OUTPUT) {
 	 if (s->smallDecompress)
diff --git a/lib/bzip2/bzlib_decompress.c b/lib/bzip2/bzlib_decompress.c
index 3b417d57b27..51f21d1e7f6 100644
--- a/lib/bzip2/bzlib_decompress.c
+++ b/lib/bzip2/bzlib_decompress.c
@@ -417,9 +417,8 @@ Int32 BZ2_decompress ( DState* s )
 
       while (True) {
 
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	schedule();
-#endif
+	 if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+	    schedule();
 	 if (nextSym == EOB) break;
 
 	 if (nextSym == BZ_RUNA || nextSym == BZ_RUNB) {
@@ -502,9 +501,8 @@ Int32 BZ2_decompress ( DState* s )
 		  if (s->mtfbase[0] == 0) {
 		     kk = MTFA_SIZE-1;
 		     for (ii = 256 / MTFL_SIZE-1; ii >= 0; ii--) {
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-			schedule();
-#endif
+			if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+			   schedule();
 			for (jj = MTFL_SIZE-1; jj >= 0; jj--) {
 			   s->mtfa[kk] = s->mtfa[s->mtfbase[ii] + jj];
 			   kk--;
@@ -567,9 +565,8 @@ Int32 BZ2_decompress ( DState* s )
 	 }
 	    while (i != s->origPtr);
 
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	schedule();
-#endif
+	 if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+	    schedule();
 	 s->tPos = s->origPtr;
 	 s->nblock_used = 0;
 	 if (s->blockRandomised) {
@@ -582,9 +579,8 @@ Int32 BZ2_decompress ( DState* s )
 
       } else {
 
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
-	schedule();
-#endif
+	 if (CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING))
+	    schedule();
 	 /*-- compute the T^(-1) vector --*/
 	 for (i = 0; i < nblock; i++) {
 	    uc = (UChar)(s->tt[i] & 0xff);
diff --git a/lib/crc32.c b/lib/crc32.c
index 12c104c62a4..124fadb62b0 100644
--- a/lib/crc32.c
+++ b/lib/crc32.c
@@ -14,7 +14,7 @@
 #else
 #include <common.h>
 #include <efi_loader.h>
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #define PET_WDG
 #endif
 #endif
diff --git a/lib/md5.c b/lib/md5.c
index 20d5e87814b..fb1a2b4ef61 100644
--- a/lib/md5.c
+++ b/lib/md5.c
@@ -29,7 +29,7 @@
 
 #ifndef USE_HOSTCC
 #include <common.h>
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #include <watchdog.h>
 #define PET_WDG
 #endif
diff --git a/lib/sha1.c b/lib/sha1.c
index cd5d7aead8d..9661fe487a7 100644
--- a/lib/sha1.c
+++ b/lib/sha1.c
@@ -19,7 +19,7 @@
 #ifndef USE_HOSTCC
 #include <common.h>
 #include <linux/string.h>
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #define PET_WDG
 #endif
 #else
diff --git a/lib/sha256.c b/lib/sha256.c
index 8e1c3992674..5aa7ad7b5c0 100644
--- a/lib/sha256.c
+++ b/lib/sha256.c
@@ -8,7 +8,7 @@
 #ifndef USE_HOSTCC
 #include <common.h>
 #include <linux/string.h>
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #define PET_WDG
 #endif
 #else
diff --git a/lib/sha512.c b/lib/sha512.c
index a504281bf93..389c792bd22 100644
--- a/lib/sha512.c
+++ b/lib/sha512.c
@@ -13,7 +13,7 @@
 #ifndef USE_HOSTCC
 #include <common.h>
 #include <linux/string.h>
-#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+#if CONFIG_IS_ENABLED(HAS_WATCHDOG_RUNNING)
 #define PET_WDG
 #endif
 #else
-- 
2.34.1



More information about the U-Boot mailing list