mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* some debug patches
@ 2012-01-26 13:26 Sascha Hauer
  2012-01-26 13:26 ` [PATCH 1/7] console: remove unused function prototypes Sascha Hauer
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

Being forced to do debugging this morning I created some patches
to make this easier. initcall tracing now works with regular
debug() statements and not with LL debug functions anymore which
are not implemented for most architectures. Also, we do no
longer hang when an initcall fails which increases the chance
that the user gets some clue what went wrong.

Sascha Hauer (7):
      console: remove unused function prototypes
      kfifo: change kfifo_init to work with a preallocated fifo
      console: make it work without malloc
      ARM: panic on div 0
      initcalls: do not hang if an initcall fails
      startup: use regular debug statements in initcall debugging
      Add dump_stack function

 arch/arm/cpu/interrupts.c      |    5 ++++
 arch/arm/include/asm/barebox.h |   39 ++-----------------------------
 arch/arm/lib/div0.c            |    2 +-
 common/console.c               |   49 ++++++++++++++++++++++++++--------------
 common/startup.c               |   10 ++-----
 include/common.h               |    9 +++++++
 include/console.h              |   13 ----------
 include/kfifo.h                |    2 +-
 lib/kfifo.c                    |   23 +++++++-----------
 lib/vsprintf.c                 |    2 +
 10 files changed, 65 insertions(+), 89 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/7] console: remove unused function prototypes
  2012-01-26 13:26 some debug patches Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 2/7] kfifo: change kfifo_init to work with a preallocated fifo Sascha Hauer
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/console.h |   13 -------------
 1 files changed, 0 insertions(+), 13 deletions(-)

diff --git a/include/console.h b/include/console.h
index c0817f6..47e8600 100644
--- a/include/console.h
+++ b/include/console.h
@@ -56,17 +56,4 @@ extern struct list_head console_list;
 
 #define CFG_PBSIZE (CONFIG_CBSIZE+sizeof(CONFIG_PROMPT)+16)
 
-void early_console_putc(void *base, char c);
-void early_console_init(void *base, int baudrate);
-
-void early_console_start(const char *name, int baudrate);
-
-/*
- * Resolve an early console name to a pointer pointing
- * to the consoles base address, usually implemented in
- * board setup file.
- */
-void *get_early_console_base(const char *name);
-
 #endif
-
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/7] kfifo: change kfifo_init to work with a preallocated fifo
  2012-01-26 13:26 some debug patches Sascha Hauer
  2012-01-26 13:26 ` [PATCH 1/7] console: remove unused function prototypes Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 3/7] console: make it work without malloc Sascha Hauer
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

kfifo currently only works with dynamically allocated fifos.
Change the currently unused kfifo_init to take a preallocated
fifo. This allows for statically initialized fifos.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/kfifo.h |    2 +-
 lib/kfifo.c     |   23 +++++++++--------------
 2 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/include/kfifo.h b/include/kfifo.h
index 3eb03cb..2987e0b 100644
--- a/include/kfifo.h
+++ b/include/kfifo.h
@@ -28,7 +28,7 @@ struct kfifo {
 	unsigned int out;	/* data is extracted from off. (out % size) */
 };
 
-struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size);
+void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size);
 struct kfifo *kfifo_alloc(unsigned int size);
 void kfifo_free(struct kfifo *fifo);
 
diff --git a/lib/kfifo.c b/lib/kfifo.c
index 27d44e9..a2f3727 100644
--- a/lib/kfifo.c
+++ b/lib/kfifo.c
@@ -34,19 +34,11 @@
  * Do NOT pass the kfifo to kfifo_free() after use! Simply free the
  * &struct kfifo with free().
  */
-struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size)
+void kfifo_init(struct kfifo *fifo, unsigned char *buffer, unsigned int size)
 {
-	struct kfifo *fifo;
-
-	fifo = malloc(sizeof(struct kfifo));
-	if (!fifo)
-		return NULL;
-
 	fifo->buffer = buffer;
 	fifo->size = size;
 	fifo->in = fifo->out = 0;
-
-	return fifo;
 }
 
 /**
@@ -60,18 +52,21 @@ struct kfifo *kfifo_init(unsigned char *buffer, unsigned int size)
 struct kfifo *kfifo_alloc(unsigned int size)
 {
 	unsigned char *buffer;
-	struct kfifo *ret;
+	struct kfifo *fifo;
 
 	buffer = malloc(size);
 	if (!buffer)
 		return NULL;
 
-	ret = kfifo_init(buffer, size);
-
-	if (!ret)
+	fifo = malloc(sizeof(struct kfifo));
+	if (!fifo) {
 		free(buffer);
+		return NULL;
+	}
+
+	kfifo_init(fifo, buffer, size);
 
-	return ret;
+	return fifo;
 }
 
 /**
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/7] console: make it work without malloc
  2012-01-26 13:26 some debug patches Sascha Hauer
  2012-01-26 13:26 ` [PATCH 1/7] console: remove unused function prototypes Sascha Hauer
  2012-01-26 13:26 ` [PATCH 2/7] kfifo: change kfifo_init to work with a preallocated fifo Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 4/7] ARM: panic on div 0 Sascha Hauer
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

This changes the dynamically allocated kfifos to statically initialized
ones. This makes the console work without malloc and thus safe to be
called before malloc is initialized.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c |   49 ++++++++++++++++++++++++++++++++-----------------
 1 files changed, 32 insertions(+), 17 deletions(-)

diff --git a/common/console.c b/common/console.c
index 88c4010..abc0627 100644
--- a/common/console.c
+++ b/common/console.c
@@ -40,8 +40,9 @@
 LIST_HEAD(console_list);
 EXPORT_SYMBOL(console_list);
 
-#define CONSOLE_UNINITIALIZED	0
-#define CONSOLE_INIT_FULL	1
+#define CONSOLE_UNINITIALIZED		0
+#define CONSOLE_INITIALIZED_BUFFER	1
+#define CONSOLE_INIT_FULL		2
 
 static int initialized = 0;
 
@@ -109,17 +110,25 @@ static int console_baudrate_set(struct device_d *dev, struct param_d *param,
 	return 0;
 }
 
-static struct kfifo *console_input_buffer;
-static struct kfifo *console_output_buffer;
+#define CONSOLE_BUFFER_SIZE	1024
 
-static int getc_buffer_flush(void)
+static char console_input_buffer[CONSOLE_BUFFER_SIZE];
+static char console_output_buffer[CONSOLE_BUFFER_SIZE];
+
+static struct kfifo __console_input_fifo;
+static struct kfifo __console_output_fifo;
+static struct kfifo *console_input_fifo = &__console_input_fifo;
+static struct kfifo *console_output_fifo = &__console_output_fifo;
+
+static void console_init_early(void)
 {
-	console_input_buffer = kfifo_alloc(1024);
-	console_output_buffer = kfifo_alloc(1024);
-	return 0;
-}
+	kfifo_init(console_input_fifo, console_input_buffer,
+			CONSOLE_BUFFER_SIZE);
+	kfifo_init(console_output_fifo, console_output_buffer,
+			CONSOLE_BUFFER_SIZE);
 
-postcore_initcall(getc_buffer_flush);
+	initialized = CONSOLE_INITIALIZED_BUFFER;
+}
 
 int console_register(struct console_device *newcdev)
 {
@@ -127,6 +136,9 @@ int console_register(struct console_device *newcdev)
 	int first = 0;
 	char ch;
 
+	if (initialized == CONSOLE_UNINITIALIZED)
+		console_init_early();
+
 	dev->id = -1;
 	strcpy(dev->name, "cs");
 	dev->type_data = newcdev;
@@ -154,8 +166,7 @@ int console_register(struct console_device *newcdev)
 
 	list_add_tail(&newcdev->list, &console_list);
 
-
-	while (kfifo_getc(console_output_buffer, &ch) == 0)
+	while (kfifo_getc(console_output_fifo, &ch) == 0)
 		console_putc(CONSOLE_STDOUT, ch);
 	if (first)
 		barebox_banner();
@@ -226,16 +237,16 @@ int getc(void)
 	start = get_time_ns();
 	while (1) {
 		if (tstc_raw()) {
-			kfifo_putc(console_input_buffer, getc_raw());
+			kfifo_putc(console_input_fifo, getc_raw());
 
 			start = get_time_ns();
 		}
 		if (is_timeout(start, 100 * USECOND) &&
-				kfifo_len(console_input_buffer))
+				kfifo_len(console_input_fifo))
 			break;
 	}
 
-	kfifo_getc(console_input_buffer, &ch);
+	kfifo_getc(console_input_fifo, &ch);
 	return ch;
 }
 EXPORT_SYMBOL(getc);
@@ -252,7 +263,7 @@ EXPORT_SYMBOL(fgetc);
 
 int tstc(void)
 {
-	return kfifo_len(console_input_buffer) || tstc_raw();
+	return kfifo_len(console_input_fifo) || tstc_raw();
 }
 EXPORT_SYMBOL(tstc);
 
@@ -263,7 +274,11 @@ void console_putc(unsigned int ch, char c)
 
 	switch (init) {
 	case CONSOLE_UNINITIALIZED:
-		kfifo_putc(console_output_buffer, c);
+		console_init_early();
+		/* fall through */
+
+	case CONSOLE_INITIALIZED_BUFFER:
+		kfifo_putc(console_output_fifo, c);
 		return;
 
 	case CONSOLE_INIT_FULL:
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/7] ARM: panic on div 0
  2012-01-26 13:26 some debug patches Sascha Hauer
                   ` (2 preceding siblings ...)
  2012-01-26 13:26 ` [PATCH 3/7] console: make it work without malloc Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 5/7] initcalls: do not hang if an initcall fails Sascha Hauer
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

hang() only outputs 'reset the board' whereas panic
can be passed a string which we can use to output
some more information what is happening.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/lib/div0.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/lib/div0.c b/arch/arm/lib/div0.c
index 99d6b85..6313c672 100644
--- a/arch/arm/lib/div0.c
+++ b/arch/arm/lib/div0.c
@@ -27,5 +27,5 @@ extern void __div0(void);
 /* Replacement (=dummy) for GNU/Linux division-by zero handler */
 void __div0 (void)
 {
-	hang();
+	panic("division by zero\n");
 }
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/7] initcalls: do not hang if an initcall fails
  2012-01-26 13:26 some debug patches Sascha Hauer
                   ` (3 preceding siblings ...)
  2012-01-26 13:26 ` [PATCH 4/7] ARM: panic on div 0 Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 6/7] startup: use regular debug statements in initcall debugging Sascha Hauer
  2012-01-26 13:26 ` [PATCH 7/7] Add dump_stack function Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

Currently we just hang when an initcall fails. This resulted
in most initcalls just returning 0 unconditionally. Instead
of hanging which usually leaves the user without a clue what
happened just continue and hope for the best.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/startup.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index 180fdc3..d39748b 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -124,10 +124,7 @@ void start_barebox (void)
 		PUTS_LL("<<");
 		PUTHEX_LL(*initcall);
 		result = (*initcall)();
-		PUTC_LL('>');
-		if (result)
-			hang();
-		PUTS_LL(">\n");
+		PUTS_LL(">>\n");
 	}
 
 	PUTS_LL("initcalls done\n");
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 6/7] startup: use regular debug statements in initcall debugging
  2012-01-26 13:26 some debug patches Sascha Hauer
                   ` (4 preceding siblings ...)
  2012-01-26 13:26 ` [PATCH 5/7] initcalls: do not hang if an initcall fails Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  2012-01-26 13:26 ` [PATCH 7/7] Add dump_stack function Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

Now that we don't need malloc for the console anymore it's
safe to call printf anytime, so switch the initcall debugging
to regular debug() statements..

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/startup.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/common/startup.c b/common/startup.c
index d39748b..abd1b77 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -121,13 +121,12 @@ void start_barebox (void)
 
 	for (initcall = __barebox_initcalls_start;
 			initcall < __barebox_initcalls_end; initcall++) {
-		PUTS_LL("<<");
-		PUTHEX_LL(*initcall);
+		debug("initcall-> %pS\n", *initcall);
 		result = (*initcall)();
-		PUTS_LL(">>\n");
+		debug("initcall<- %pS (%d)\n", *initcall, result);
 	}
 
-	PUTS_LL("initcalls done\n");
+	debug("initcalls done\n");
 
 	display_meminfo();
 
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 7/7] Add dump_stack function
  2012-01-26 13:26 some debug patches Sascha Hauer
                   ` (5 preceding siblings ...)
  2012-01-26 13:26 ` [PATCH 6/7] startup: use regular debug statements in initcall debugging Sascha Hauer
@ 2012-01-26 13:26 ` Sascha Hauer
  6 siblings, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2012-01-26 13:26 UTC (permalink / raw)
  To: barebox

At least ARM allows us to dump the stack, but we currently
have no prototype for this. Add a dump_stack prototype and
provide a static inline function for architectures without
stack dump support. Also, call dump_stack() in panic() to
provide more information in the case of a panic.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/cpu/interrupts.c      |    5 +++++
 arch/arm/include/asm/barebox.h |   39 +++------------------------------------
 include/common.h               |    9 +++++++++
 lib/vsprintf.c                 |    2 ++
 4 files changed, 19 insertions(+), 36 deletions(-)

diff --git a/arch/arm/cpu/interrupts.c b/arch/arm/cpu/interrupts.c
index 3d2077f..c4f9113 100644
--- a/arch/arm/cpu/interrupts.c
+++ b/arch/arm/cpu/interrupts.c
@@ -73,6 +73,11 @@ void show_regs (struct pt_regs *regs)
 #endif
 }
 
+void dump_stack(void)
+{
+	unwind_backtrace(NULL);
+}
+
 static void __noreturn do_exception(struct pt_regs *pt_regs)
 {
 	show_regs(pt_regs);
diff --git a/arch/arm/include/asm/barebox.h b/arch/arm/include/asm/barebox.h
index c9372da..2b08d68 100644
--- a/arch/arm/include/asm/barebox.h
+++ b/arch/arm/include/asm/barebox.h
@@ -1,41 +1,8 @@
-/*
- * (C) Copyright 2002
- * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
- * Marius Groeger <mgroeger@sysgo.de>
- *
- * (C) Copyright 2002
- * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
- * Alex Zuepke <azu@sysgo.de>
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
- * MA 02111-1307 USA
- *
- ********************************************************************
- * NOTE: This header file defines an interface to barebox. Including
- * this (unmodified) header file in another file is considered normal
- * use of barebox, and does *not* fall under the heading of "derived
- * work".
- ********************************************************************
- */
-
 #ifndef _BAREBOX_H_
 #define _BAREBOX_H_	1
 
-//typedef struct bd_info {} bd_t;
+#ifdef CONFIG_ARM_UNWIND
+#define ARCH_HAS_STACK_DUMP
+#endif
 
 #endif	/* _BAREBOX_H_ */
diff --git a/include/common.h b/include/common.h
index 2f37dd8..74a697d 100644
--- a/include/common.h
+++ b/include/common.h
@@ -119,6 +119,15 @@ uint32_t crc32_no_comp(uint32_t, const void*, unsigned int);
 /* common/console.c */
 int	ctrlc (void);
 
+#ifdef ARCH_HAS_STACK_DUMP
+void dump_stack(void);
+#else
+static inline void dump_stack(void)
+{
+	printf("no stack data available\n");
+}
+#endif
+
 #define MEMAREA_SIZE_SPECIFIED 1
 
 struct memarea_info {
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 4165f97..9763515 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -625,6 +625,8 @@ void __noreturn panic(const char *fmt, ...)
 	putchar('\n');
 	va_end(args);
 
+	dump_stack();
+
 	led_trigger(LED_TRIGGER_PANIC, TRIGGER_ENABLE);
 
 #if defined (CONFIG_PANIC_HANG)
-- 
1.7.8.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-01-26 13:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-26 13:26 some debug patches Sascha Hauer
2012-01-26 13:26 ` [PATCH 1/7] console: remove unused function prototypes Sascha Hauer
2012-01-26 13:26 ` [PATCH 2/7] kfifo: change kfifo_init to work with a preallocated fifo Sascha Hauer
2012-01-26 13:26 ` [PATCH 3/7] console: make it work without malloc Sascha Hauer
2012-01-26 13:26 ` [PATCH 4/7] ARM: panic on div 0 Sascha Hauer
2012-01-26 13:26 ` [PATCH 5/7] initcalls: do not hang if an initcall fails Sascha Hauer
2012-01-26 13:26 ` [PATCH 6/7] startup: use regular debug statements in initcall debugging Sascha Hauer
2012-01-26 13:26 ` [PATCH 7/7] Add dump_stack function Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox