blob: 66ae17f3df9942a4ffd16003314bd1ab727e8257 [file] [log] [blame]
Sjoerd Simons35f53ed2015-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 Glassf11478f2019-12-28 10:45:07 -070013#include <hang.h>
Sjoerd Simons35f53ed2015-12-04 23:27:38 +010014#if !defined(CONFIG_PANIC_HANG)
15#include <command.h>
16#endif
Simon Glassdbd79542020-05-10 11:40:11 -060017#include <linux/delay.h>
Tony Dinh88d0f5b2023-03-14 17:24:26 -070018#include <stdio.h>
Sjoerd Simons35f53ed2015-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 Dinh88d0f5b2023-03-14 17:24:26 -070028 flush(); /* flush the panic message before reset */
29
Sjoerd Simons35f53ed2015-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 Kiernand07d0a02018-04-19 04:32:55 +000044#if CONFIG_IS_ENABLED(PRINTF)
Sjoerd Simons35f53ed2015-12-04 23:27:38 +010045 va_list args;
46 va_start(args, fmt);
47 vprintf(fmt, args);
48 va_end(args);
Alex Kiernand07d0a02018-04-19 04:32:55 +000049#endif
Sjoerd Simons35f53ed2015-12-04 23:27:38 +010050 panic_finish();
51}
Alex Kiernan93c4d212018-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}