From patchwork Fri Jul 13 10:16:45 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 9983 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2E2A323E1B for ; Fri, 13 Jul 2012 10:19:20 +0000 (UTC) Received: from mail-gh0-f180.google.com (mail-gh0-f180.google.com [209.85.160.180]) by fiordland.canonical.com (Postfix) with ESMTP id F262EA18223 for ; Fri, 13 Jul 2012 10:19:19 +0000 (UTC) Received: by mail-gh0-f180.google.com with SMTP id z12so3670584ghb.11 for ; Fri, 13 Jul 2012 03:19:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=XkYUH34W6Hs9GMosyQsaSShIvoQZBoirUsLIU6Ji9LA=; b=nnw+PyHaplnnSOeMfeQdLqVjiyh6V9OR6bIbYJhYJtHurP0CW9u4zupAtP608bn5wj hunD7mJy+tFPg3IksziEAjEr3fB72XyR+2IRmiwBh0g255mklAGDC15Rd04Cp9g9nA2F kBHVxGWt1tiOnsBSHyM6EDbLRlul5rk0hBRsVHE68h5iYV6hNwXtAcMgNNCVyO0384fh 6z4GAEYvOCFsqemlONrSo1GFGAlOb6NgOUowNzNtQ5aCbE38c2+IgwgAgtvgAanRXekd L5JxLIFpEjT9xmFUccu9dWAG7j7TmPZCU4qklxtOfc9McVAQis4BpiAGCMHrxWLSe/E3 gZFA== Received: by 10.50.40.193 with SMTP id z1mr463498igk.0.1342174759560; Fri, 13 Jul 2012 03:19:19 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.241.2 with SMTP id lc2csp13698ibb; Fri, 13 Jul 2012 03:19:19 -0700 (PDT) Received: by 10.68.223.198 with SMTP id qw6mr2729457pbc.94.1342174758925; Fri, 13 Jul 2012 03:19:18 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id pv10si13925349pbb.64.2012.07.13.03.19.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jul 2012 03:19:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id rr4so6369113pbb.37 for ; Fri, 13 Jul 2012 03:19:18 -0700 (PDT) Received: by 10.68.233.132 with SMTP id tw4mr2582008pbc.61.1342174758675; Fri, 13 Jul 2012 03:19:18 -0700 (PDT) Received: from localhost (c-71-204-165-222.hsd1.ca.comcast.net. [71.204.165.222]) by mx.google.com with ESMTPS id ng8sm5759333pbc.13.2012.07.13.03.19.17 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 13 Jul 2012 03:19:18 -0700 (PDT) From: Anton Vorontsov To: Russell King , Jason Wessel Cc: =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Colin Cross , John Stultz , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, kernel-team@android.com, kgdb-bugreport@lists.sourceforge.net Subject: [PATCH 5/8] ARM: kgdb_fiq: Implement knocking into KDB via escape command Date: Fri, 13 Jul 2012 03:16:45 -0700 Message-Id: <1342174608-22407-5-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <20120713101605.GA16139@lizard> References: <20120713101605.GA16139@lizard> X-Gm-Message-State: ALoCoQm2bwm8f0ZIatTO60Yauoov6iDTut6+rGwGe+Vb+ptO6XqeorEhRjw0Zz/rU0DpccAMhEZ9 As Colin Cross noticed, serial ports could be noisy, so occasional characters once in a while are possible. So, considering the noise possibility, entering the debugger on any received byte is unacceptable for production devices. This changes KGDB FIQ behaviour in a such way so that we have to type the GDB-protocol "$3#33" command to actually enter the debugger, the kernel will print the following prompt: Type $3#33 to enter the debugger. This is the exactly the same command we use to escape from KGDB to KDB, so it should be all pretty familiar. For convenience, there is a kgdb_fiq.knock kernel command line option, when set to 0, this turns the special command to just a return key press, so the kernel will be printing this: Hit to enter the debugger. Suggested-by: Colin Cross Signed-off-by: Anton Vorontsov --- arch/arm/kernel/kgdb_fiq.c | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/arch/arm/kernel/kgdb_fiq.c b/arch/arm/kernel/kgdb_fiq.c index 7ec9979..5308697 100644 --- a/arch/arm/kernel/kgdb_fiq.c +++ b/arch/arm/kernel/kgdb_fiq.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,51 @@ static int kgdb_fiq_enabled; module_param_named(enable, kgdb_fiq_enabled, int, 0600); MODULE_PARM_DESC(enable, "set to 1 to enable FIQ KGDB"); +static bool kgdb_fiq_knock = 1; +module_param_named(knock, kgdb_fiq_knock, bool, 0600); +MODULE_PARM_DESC(knock, "'$3#33' command must be used to enter the debugger"); + +/* + * "Serial ports are often noisy, especially when muxed over another port (we + * often use serial over the headset connector). Noise on the async command + * line just causes characters that are ignored, on a command line that blocked + * execution noise would be catastrophic." -- Colin Cross + * + * So, this small function implements KGDB/KDB knocking on the serial line: we + * won't enter the debugger until we receive a known magic phrase (which is + * actually "$3#33", known as "escape to KDB" command. If knocking is disabled, + * just pressing the return key is enough to enter the debugger. + */ +static bool kgdb_fiq_poll_knock(void) +{ + static int n; + int c = -1; + get_char_func *getc; + const char *magic = "$3#33"; + size_t m = strlen(magic); + + for (getc = &kdb_poll_funcs[0]; *getc; ++getc) { + c = (*getc)(); + if (c >= 0) + break; + } + + if (!kgdb_fiq_knock && (c == '\r' || c == '\n')) { + return 1; + } else if (c == magic[n]) { + kdb_printf("%c", c); + n = (n + 1) % m; + if (!n) + return 1; + } else { + n = 0; + kdb_printf("\n%s %s to enter the debugger.\n", + kgdb_fiq_knock ? "Type" : "Hit", + kgdb_fiq_knock ? magic : ""); + } + return 0; +} + static unsigned int kgdb_fiq; static void (*kgdb_enable_fiq)(unsigned int irq, bool on); static bool (*is_kgdb_fiq)(unsigned int irq); @@ -33,6 +79,8 @@ asmlinkage void __exception_irq_entry kgdb_fiq_do_handle(struct pt_regs *regs) { if (!is_kgdb_fiq(kgdb_fiq)) return; + if (!kgdb_fiq_poll_knock()) + return; nmi_enter(); kgdb_handle_exception(1, 0, 0, regs);