blob: 66ae17f3df9942a4ffd16003314bd1ab727e8257 [file] [log] [blame]
Sjoerd Simons2b22a992015-12-04 23:27:38 +01001/*
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 Glassdb41d652019-12-28 10:45:07 -070013#include <hang.h>
Sjoerd Simons2b22a992015-12-04 23:27:38 +010014#if !defined(CONFIG_PANIC_HANG)
15#include <command.h>
16#endif
Simon Glassc05ed002020-05-10 11:40:11 -060017#include <linux/delay.h>
Tony Dinhc5f4cdb2023-03-14 17:24:26 -070018#include <stdio.h>
Sjoerd Simons2b22a992015-12-04 23:27:38 +010019
20static void panic_finish(void) __attribute__ ((noreturn));
21
22static void panic_finish(void)
23{
24 putc('\n');
25#if defined(CONFIG_PANIC_HANG)
26 hang();
27#else
Tony Dinhc5f4cdb2023-03-14 17:24:26 -070028 flush(); /* flush the panic message before reset */
29
Sjoerd Simons2b22a992015-12-04 23:27:38 +010030 do_reset(NULL, 0, 0, NULL);
31#endif
32 while (1)
33 ;
34}
35
36void panic_str(const char *str)
37{
38 puts(str);
39 panic_finish();
40}
41
42void panic(const char *fmt, ...)
43{
Alex Kiernan4f1eed72018-04-19 04:32:55 +000044#if CONFIG_IS_ENABLED(PRINTF)
Sjoerd Simons2b22a992015-12-04 23:27:38 +010045 va_list args;
46 va_start(args, fmt);
47 vprintf(fmt, args);
48 va_end(args);
Alex Kiernan4f1eed72018-04-19 04:32:55 +000049#endif
Sjoerd Simons2b22a992015-12-04 23:27:38 +010050 panic_finish();
51}
Alex Kiernane21c03b2018-04-19 04:32:56 +000052
53void __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}