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