Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/lib/vsprintf.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | */ |
| 6 | |
| 7 | /* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */ |
| 8 | /* |
| 9 | * Wirzenius wrote this portably, Torvalds fucked it up :-) |
| 10 | */ |
| 11 | |
| 12 | #include <common.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 13 | #include <hang.h> |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 14 | #if !defined(CONFIG_PANIC_HANG) |
| 15 | #include <command.h> |
| 16 | #endif |
| 17 | |
| 18 | static void panic_finish(void) __attribute__ ((noreturn)); |
| 19 | |
| 20 | static void panic_finish(void) |
| 21 | { |
| 22 | putc('\n'); |
| 23 | #if defined(CONFIG_PANIC_HANG) |
| 24 | hang(); |
| 25 | #else |
| 26 | udelay(100000); /* allow messages to go out */ |
| 27 | do_reset(NULL, 0, 0, NULL); |
| 28 | #endif |
| 29 | while (1) |
| 30 | ; |
| 31 | } |
| 32 | |
| 33 | void panic_str(const char *str) |
| 34 | { |
| 35 | puts(str); |
| 36 | panic_finish(); |
| 37 | } |
| 38 | |
| 39 | void panic(const char *fmt, ...) |
| 40 | { |
Alex Kiernan | d07d0a0 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 41 | #if CONFIG_IS_ENABLED(PRINTF) |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 42 | va_list args; |
| 43 | va_start(args, fmt); |
| 44 | vprintf(fmt, args); |
| 45 | va_end(args); |
Alex Kiernan | d07d0a0 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 46 | #endif |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 47 | panic_finish(); |
| 48 | } |
Alex Kiernan | 93c4d21 | 2018-04-19 04:32:56 +0000 | [diff] [blame] | 49 | |
| 50 | void __assert_fail(const char *assertion, const char *file, unsigned int line, |
| 51 | const char *function) |
| 52 | { |
| 53 | /* This will not return */ |
| 54 | panic("%s:%u: %s: Assertion `%s' failed.", file, line, function, |
| 55 | assertion); |
| 56 | } |