Sjoerd Simons | 2b22a99 | 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 | |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 12 | #include <hang.h> |
Sjoerd Simons | 2b22a99 | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 13 | #if !defined(CONFIG_PANIC_HANG) |
| 14 | #include <command.h> |
| 15 | #endif |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
Tony Dinh | c5f4cdb | 2023-03-14 17:24:26 -0700 | [diff] [blame] | 17 | #include <stdio.h> |
Sjoerd Simons | 2b22a99 | 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 |
Tony Dinh | c5f4cdb | 2023-03-14 17:24:26 -0700 | [diff] [blame] | 27 | flush(); /* flush the panic message before reset */ |
| 28 | |
Sjoerd Simons | 2b22a99 | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 29 | do_reset(NULL, 0, 0, NULL); |
| 30 | #endif |
| 31 | while (1) |
| 32 | ; |
| 33 | } |
| 34 | |
| 35 | void panic_str(const char *str) |
| 36 | { |
| 37 | puts(str); |
| 38 | panic_finish(); |
| 39 | } |
| 40 | |
| 41 | void panic(const char *fmt, ...) |
| 42 | { |
Alex Kiernan | 4f1eed7 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 43 | #if CONFIG_IS_ENABLED(PRINTF) |
Sjoerd Simons | 2b22a99 | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 44 | va_list args; |
| 45 | va_start(args, fmt); |
| 46 | vprintf(fmt, args); |
| 47 | va_end(args); |
Alex Kiernan | 4f1eed7 | 2018-04-19 04:32:55 +0000 | [diff] [blame] | 48 | #endif |
Sjoerd Simons | 2b22a99 | 2015-12-04 23:27:38 +0100 | [diff] [blame] | 49 | panic_finish(); |
| 50 | } |
Alex Kiernan | e21c03b | 2018-04-19 04:32:56 +0000 | [diff] [blame] | 51 | |
| 52 | void __assert_fail(const char *assertion, const char *file, unsigned int line, |
| 53 | const char *function) |
| 54 | { |
| 55 | /* This will not return */ |
| 56 | panic("%s:%u: %s: Assertion `%s' failed.", file, line, function, |
| 57 | assertion); |
| 58 | } |