Module 14 · Lesson 28 of 92

Kernel hangs and the watchdog

Use early kernel logs to identify a suspect initcall and keep a hardware watchdog from interrupting a controlled bring-up session.

  • Beginner to advanced
  • 8 min read
  • 13 min lab
What you will need

Ubuntu 24.04 in WSL2 or a VM for the exercises. Live diagnosis requires a BeagleBone or Raspberry Pi 4 or 5 with a working serial console and access to the target boot arguments.

Your place in the module
By the end you can 4 objectives
  • Choose boot arguments that expose early kernel messages and initcall progress.
  • Identify the last completed initcall and the last initcall entered in a serial capture.
  • Choose a supported watchdog strategy that covers the interval from bootloader handoff to the suspected hang.
  • Distinguish a repeatable initcall stall from a loss of serial output or a watchdog reset.
Video coming soonKernel hangs and the watchdog
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Diagnosing a hung board
  • A ROM UART boot request identifies a ROM boot path, while an SPL marker confirms execution reached SPL
  • The PC identifies where the processor halted, and the surrounding instructions and registers explain what it was doing
  • The linker map shows linked addresses, and addr2line uses the matching ELF
01

Keep early kernel messages visible

3 min read

Once U-Boot hands off, a hang moves into the kernel's early boot. This lesson answers how initcall_debug and earlycon localise a kernel hang, and how to keep the watchdog from rebooting you mid-debug.

Linux can produce kernel messages before the regular serial console is ready to print them. If boot stalls during that interval, the terminal can stop at the bootloader handoff even though the kernel has executed code. The earlycon boot argument enables a supported early console so those messages can reach your capture sooner. Keep the regular console= setting for the target too, so you can observe the boot after the regular console takes over. The kernel’s command-line parameters

Use the UART you have already verified on the target. On a device-tree boot, bare earlycon can use the UART named by /chosen/stdout-path when the selected UART has a supported early-console implementation. Check that the path in the device tree actually passed to Linux resolves to the UART attached to your serial adapter. If the board needs an explicit earlycon= specification, use the early-console driver and UART address appropriate to that target. A working U-Boot prompt confirms that the host can receive from a UART at the bootloader’s settings. It leaves open which UART Linux will select and whether Linux can access it.

For a diagnostic boot, retain the existing boot arguments needed to start the system, including the normal serial console and root filesystem settings. Remove quiet if present and append earlycon initcall_debug loglevel=8 using the temporary boot-argument mechanism available on the target. loglevel=8 permits debug-priority messages on the console. If the boot reaches a shell, cat /proc/cmdline shows which arguments Linux actually received. A known-good boot with the same logging settings gives you a reference for both the early messages and the transition to the normal serial console. A capture that stops around that transition gives you a reason to check the two console selections before changing a driver.

no_console_suspend is useful when the failing sequence involves a suspend or resume transition. It tells Linux to keep consoles enabled during that transition, so you can still receive messages if the UART remains usable. Hardware can still lose its clock or power. For a stall during ordinary boot before any such transition, start with the early console and initcall tracing. Adding no_console_suspend cannot make an unconfigured early console print or keep a hardware watchdog fed.

Serial output across kernel handoffBootloaderhandoffEarlyconsoleearlyconenablesearlyprintingRegularconsoleconsole=selects theongoingoutputBootloaderhandoffEarlyconsoleearlyconenablesearlyprintingRegularconsoleconsole=selects theongoingoutput
Follow the serial capture from early kernel output through regular console registration

Capture from before handoff and keep the text through any return to the bootloader. Preserve complete lines and any truncated final line. A reset can cut off transmission while a line is still being sent. Keep the kernel image and device tree the same between diagnostic runs unless one is the variable you intend to test. Extra serial output also takes time. If adding tracing causes a previously successful boot to reset, compare elapsed time to reset before assuming the kernel has acquired a new hang.

02

Find the last initcall that entered

3 min read

An can register a driver or initialise a subsystem. With initcall_debug, the kernel reports a calling message before invoking an initcall and an initcall completion message with returned after the function returns. The completion includes a return value and elapsed time. The kernel prints these as calling <symbol> @ <pid> and initcall <symbol> returned <value> after <n> usecs at debug priority (KERN_DEBUG in init/main.c), which is why loglevel=8 is in the argument list. Use the function symbol to match entry and completion. Other kernel messages can appear between the two, so the adjacent lines alone may tell you very little.

Read back from the end of the capture and find the last visible calling message. Check whether the same function has a subsequent returned message. If its entry consistently appears without a completion, and the console stays usable through the point you are examining, investigate that function and the calls it makes. A function can wait inside another routine, so the symbol identifies where execution entered the suspect code. For instance, if a driver registers synchronously and registration calls into a device probe, inspect what that probe waits for. A register poll with a finite timeout has a different expected outcome from a poll that waits indefinitely for a hardware bit.

Also record the last initcall with a complete entry and return pair. Even when the return value indicates an error, that function has returned control to its caller. The error can still explain a later failure, so preserve it in your notes. If the trace ends with a complete pair and shows no next entry, record the last completed symbol and leave the next execution point open. If there are no initcall entries at all, check whether the kernel received the tracing argument and whether the UART was usable before concluding that the stall preceded the traced calls.

Match each initcall entry to its returnEntrymessageRecordfunctionsymbolInitcallexecutesMay enterotherroutinesReturnmessageMatch thesame symbolEntrymessageRecordfunctionsymbolInitcallexecutesMay enterotherroutinesReturnmessageMatch thesame symbol
Use entry and return messages to distinguish completed initialisation from a suspect call

Here is a way to review a saved capture on Ubuntu. The filter shows the two message forms and keeps their line numbers in the full file.

bash
grep -nE 'calling[[:space:]]+|initcall[[:space:]].*returned' boot.log

Use the result as an index. Read the surrounding lines in boot.log, including messages from the device being initialised, and check whether the bootloader banner reappears. Keep each boot’s entries and completions together when the file contains multiple attempts. A completion in a later boot tells you nothing about whether the function returned in the earlier boot. For a repeatable stall, compare the suspect symbol and any preceding hardware messages across attempts.

Suppose one capture includes a completed controller initcall, then the entry to a different initcall, followed by silence. With the watchdog managed, the same entry stays unmatched on the next run and the board remains powered without restarting. You now have a specific source-level starting point in the kernel build used on the board. Identify the function in that source and inspect its blocking calls first. If you can rebuild it, focused messages immediately before and after a suspected wait can narrow the location further. If the capture instead ends at different functions on different attempts, check reset timing and the console handoff before assigning the failure to any one function.

03

Keep the hardware watchdog from ending the run

3 min read

A may already be active when Linux starts. Feeding it reloads the timer. Once the bootloader transfers control, its normal feed code stops running. If the kernel hangs before its watchdog driver can take over, the timer can expire even though you saw the bootloader feed it just before handoff. A quiet interval followed by a new bootloader banner confirms that another boot began. A watchdog reset indication, where the board exposes one, helps establish the cause. Consistent timing suggests a watchdog deadline, while the reset indication gives you more direct evidence.

Find out which stage arms the watchdog and whether the hardware allows that stage to stop it. On a dedicated bring-up board, use the supported stop mechanism before handoff if the timer can be stopped. For example, if your U-Boot build exposes a wdt command for the selected watchdog and supports stopping that device, use wdt stop at the prompt and check the result. Check the boot path as well, since a later step can arm the timer again. If SPL or firmware starts a watchdog that cannot be stopped once armed, a debug build or setting in that earlier stage can leave it unarmed where the board supports that choice. The relevant control belongs to the stage that actually owns the timer.

If the watchdog must stay armed, use a longer timeout when supported or arrange for a feed path that runs by the deadline. A final feed just before handoff buys one timeout interval. Use that interval when it is long enough to collect the evidence or reach the next feed. Once a suitable Linux driver has registered the device and reported that the hardware is already running, the watchdog core can handle keepalives before userspace takes control, subject to its configuration. That arrangement depends on the kernel reaching driver registration and continuing to run the code that sends the keepalives. A userspace process feeding /dev/watchdog is useful once userspace and the driver are available. It cannot cover an early stall that prevents either from starting. The Linux WatchDog Timer Driver Core kernel API

Watchdog timing across handoffBootloaderfeeds timerKernelstartsRefreshbeforeexpiryExit from step 2: Timer expiresBoard resetsBootloaderfeeds timerKernelstartsExit from step 2: TimerexpiresBoard resetsRefreshbeforeexpiry
A watchdog armed at handoff needs another refresh before its deadline
Check which timer is armed

The kernel argument nowatchdog disables Linux’s soft and hard lockup detectors. Stopping a hardware reset timer requires a control supported by the device and its owner. Opening /dev/watchdog as a test can start the hardware watchdog, and some configurations prevent it from being stopped once started.

Compare two captures using the same kernel, device tree and logging arguments, with the watchdog setting as the deliberate change. If the board used to restart and now stays at the same incomplete initcall past the previous reset interval, the reset was interrupting your observation and the stall still needs investigation. If boot completes with extra watchdog time, compare the completed initcalls and boot duration. A slow initialisation path or the time spent printing diagnostics may have exceeded the original deadline. Record the observed outcome before changing the suspected code. Restore the normal watchdog configuration when the controlled debugging session ends.

A serial trace can tell you which function deserves attention even when the board gives you no shell. To see the exact instruction or wait inside that function, you need access to the halted CPU. The module's JTAG lessons earlier in this session showed how to establish that connection. The next lesson, Building a kernel defconfig, moves from debugging to configuring the kernel for the board.

Key takeaways

  • earlycon can expose kernel messages before the regular serial console takes over.
  • initcall_debug reports initcall entry and return. A repeatable unmatched entry identifies where to start investigating.
  • no_console_suspend keeps console output enabled during suspend and resume debugging.
  • A watchdog armed before Linux needs a stop, a longer timeout, or a working feed path before its deadline.
Reflect
  1. Explain to a colleague, in two sentences: choose boot arguments that expose early kernel messages and initcall progress.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

References and further reading

Find your next step

↑ ↓ to move · Enter to open · Esc to close