VIM3 KDGB over serial

Which system do you use? Android, Ubuntu, OOWOW or others?

Ubuntu 20.4

Which version of system do you use? Please provide the version of the system here:

Kernel 4.9

Please describe your issue below:

cmdline :

(system_a)root@B60P212-11361:~# cat /proc/cmdline
rootfstype=ext4 rootflags=data=writeback rw fsck.repair=yes net.ifnames=0 jtag=disable console=ttyS0,115200n8 consoleblank=0 kgdboc=ttyS0,115200 kgdbwait 

KCONFIG


# CONFIG_SERIAL_KGDB_NMI is not set
CONFIG_HAVE_ARCH_KGDB=y
CONFIG_KGDB=y
CONFIG_KGDB_SERIAL_CONSOLE=y
# CONFIG_KGDB_TESTS is not set
# CONFIG_KGDB_KDB is not set

Post a console log of your issue below:

# echo g > /proc/sysrq-trigger
[  919.916177] sysrq: HELP : loglevel(0-9) reboot(b) crash(c) terminate-all-tasks(e) memory-full-oom-kill(f) kill-all-tasks(i) thaw-filesystems(j) sak(k) show-backtrace-all-active-cpus(l) show-memory-usage(m) nice-all-RT-tasks(n) poweroff(o) show-registers(p) show-all-timers(q) unraw(r) sync(s) show-task-states(t) unmount(u) show-blocked-tasks(w) dis intr to riggger wdt rst(x) dump-ftrace-buffer(z)


Are there any documents / support for KGDB over serial for VIM3? Did anyone have experience with it? .I expect the kernel to wait for my dgb session, but it just goes through .

Hi @Ehsan2754

We don’t maintian 4.9 kernel anymore, could you check on latest 5.15 kernel image?

https://dl.khadas.com/products/vim3/firmware/ubuntu/emmc/ubuntu-24.04/vim3-ubuntu-24.04-gnome-linux-5.15-fenix-1.7.4-250423-emmc.img.xz

Regards,
Nick

Hi @numbqq . I tried the following image kernel configuration on my kernel 5.15 build from the khadas github on my AMLOGIC 311D board [VIM3] with the console=ttyS0,115200n8 consoleblank=0 kgdboc=ttyS0,115200 kgdbwait and the kernel doesnt wait for the gdb over serial. can you please evaluate on your side ?

Hello @Ehsan2754

Please apply this patch to common_drivers and try again.

diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
index 1e58c80cd..ce7b827aa 100644
--- a/drivers/tty/serial/meson_uart.c
+++ b/drivers/tty/serial/meson_uart.c
@@ -14,6 +14,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/of.h>
@@ -84,6 +85,9 @@

 #define AML_UART_DEV_NAME              "ttyS"

+#define AML_UART_POLL_USEC      5
+#define AML_UART_TIMEOUT_USEC       10000
+
 static struct uart_driver meson_uart_driver;
 static int support_sysrq;
 static unsigned int xtal_tick_en;
@@ -531,6 +535,64 @@ static void meson_uart_config_port(struct uart_port *port, int flags)
        }
 }

+#ifdef CONFIG_CONSOLE_POLL
+/*
+ * Console polling routines for writing and reading from the uart while
+ * in an interrupt or debug context (i.e. kgdb).
+ */
+
+static int meson_uart_poll_get_char(struct uart_port *port)
+{
+    u32 c;
+    unsigned long flags;
+
+spin_lock_irqsave(&port->lock, flags);
+
+    if (readl(port->membase + AML_UART_STATUS) & AML_UART_RX_EMPTY)
+        c = NO_POLL_CHAR;
+    else
+        c = readl(port->membase + AML_UART_RFIFO);
+
+       spin_unlock_irqrestore(&port->lock, flags);
+
+    return c;
+}
+
+static void meson_uart_poll_put_char(struct uart_port *port, unsigned char c)
+{
+    unsigned long flags;
+    u32 reg;
+    int ret;
+
+       spin_lock_irqsave(&port->lock, flags);
+
+    /* Wait until FIFO is empty or timeout */
+    ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg,
+                    reg & AML_UART_TX_EMPTY,
+                    AML_UART_POLL_USEC,
+                    AML_UART_TIMEOUT_USEC);
+    if (ret == -ETIMEDOUT) {
+        dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n");
+        goto out;
+    }
+
+    /* Write the character */
+    writel(c, port->membase + AML_UART_WFIFO);
+
+    /* Wait until FIFO is empty or timeout */
+    ret = readl_poll_timeout_atomic(port->membase + AML_UART_STATUS, reg,
+                    reg & AML_UART_TX_EMPTY,
+                    AML_UART_POLL_USEC,
+                    AML_UART_TIMEOUT_USEC);
+    if (ret == -ETIMEDOUT)
+        dev_err(port->dev, "Timeout waiting for UART TX EMPTY\n");
+
+out:
+       spin_unlock_irqrestore(&port->lock, flags);
+}
+
+#endif /* CONFIG_CONSOLE_POLL */
+
 static const struct uart_ops meson_uart_ops = {
        .set_mctrl      = meson_uart_set_mctrl,
        .get_mctrl      = meson_uart_get_mctrl,
@@ -546,6 +608,10 @@ static const struct uart_ops meson_uart_ops = {
        .request_port   = meson_uart_request_port,
        .release_port   = meson_uart_release_port,
        .verify_port    = meson_uart_verify_port,
+#ifdef CONFIG_CONSOLE_POLL
+    .poll_get_char  = meson_uart_poll_get_char,
+    .poll_put_char  = meson_uart_poll_put_char,
+#endif
 };

 #ifdef CONFIG_AMLOGIC_SERIAL_MESON_CONSOLE

Add defconfig:

diff --git a/arch/arm64/configs/kvims_defconfig b/arch/arm64/configs/kvims_defconfig
index a9cdd73a0..e0ac35b50 100644
--- a/arch/arm64/configs/kvims_defconfig
+++ b/arch/arm64/configs/kvims_defconfig
@@ -94,7 +94,6 @@ CONFIG_CRYPTO_SHA2_ARM64_CE=y
 CONFIG_CRYPTO_SHA512_ARM64_CE=y
 CONFIG_CRYPTO_GHASH_ARM64_CE=y
 CONFIG_CRYPTO_AES_ARM64_CE_BLK=y
-CONFIG_KPROBES=y
 CONFIG_JUMP_LABEL=y
 CONFIG_MODULES=y
 CONFIG_MODULE_UNLOAD=y
@@ -2293,7 +2292,9 @@ CONFIG_PRINTK_CALLER=y
 CONFIG_DYNAMIC_DEBUG_CORE=y
 CONFIG_HEADERS_INSTALL=y
 # CONFIG_SECTION_MISMATCH_WARN_ONLY is not set
-CONFIG_MAGIC_SYSRQ=y
+CONFIG_KGDB=y
+CONFIG_KGDB_KDB=y
+CONFIG_KDB_KEYBOARD=y
 CONFIG_UBSAN=y
 CONFIG_UBSAN_TRAP=y
 # CONFIG_UBSAN_SHIFT is not set

Add command line to /boot/uEnv.txt

kgdboc=ttyS0,115200 kgdbwait

It works on my side now: