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 |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 18 | |
| 19 | static void panic_finish(void) __attribute__ ((noreturn)); |
| 20 | |
| 21 | static void panic_finish(void) |
| 22 | { |
| 23 | putc('\n'); |
| 24 | #if defined(CONFIG_PANIC_HANG) |
| 25 | hang(); |
| 26 | #else |
| 27 | udelay(100000); /* allow messages to go out */ |
| 28 | do_reset(NULL, 0, 0, NULL); |
| 29 | #endif |
| 30 | while (1) |
| 31 | ; |
| 32 | } |
| 33 | |
| 34 | void panic_str(const char *str) |
| 35 | { |
| 36 | puts(str); |
| 37 | panic_finish(); |
| 38 | } |
| 39 | |
| 40 | void panic(const char *fmt, ...) |
| 41 | { |
Alex Kiernan | d07d0a0 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 42 | #if CONFIG_IS_ENABLED(PRINTF) |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 43 | va_list args; |
| 44 | va_start(args, fmt); |
| 45 | vprintf(fmt, args); |
| 46 | va_end(args); |
Alex Kiernan | d07d0a0 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 47 | #endif |
Sjoerd Simons | 35f53ed | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 48 | panic_finish(); |
| 49 | } |
Alex Kiernan | 93c4d21 | 2018-04-19 04:32:56 +0000 | [diff] [blame] | 50 | |
| 51 | void __assert_fail(const char *assertion, const char *file, unsigned int line, |
| 52 | const char *function) |
| 53 | { |
| 54 | /* This will not return */ |
| 55 | panic("%s:%u: %s: Assertion `%s' failed.", file, line, function, |
| 56 | assertion); |
| 57 | } |