Skip to content

Commit 23d5b73

Browse files
nivedita76ardbiesheuvel
authored andcommitted
efi/libstub: Implement printk-style logging
Use the efi_printk function in efi_info/efi_err, and add efi_debug. This allows formatted output at different log levels. Add the notion of a loglevel instead of just quiet/not-quiet, and parse the efi=debug kernel parameter in addition to quiet. Signed-off-by: Arvind Sankar <[email protected]> Link: https://lore.kernel.org/r/[email protected]/ Signed-off-by: Ard Biesheuvel <[email protected]>
1 parent 8fb331e commit 23d5b73

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

drivers/firmware/efi/libstub/efi-stub-helper.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
#include <linux/efi.h>
1313
#include <linux/kernel.h>
14+
#include <linux/printk.h> /* For CONSOLE_LOGLEVEL_* */
1415
#include <asm/efi.h>
1516

1617
#include "efistub.h"
1718

1819
bool efi_nochunk;
1920
bool efi_nokaslr;
2021
bool efi_noinitrd;
21-
bool efi_quiet;
22+
int efi_loglevel = CONSOLE_LOGLEVEL_DEFAULT;
2223
bool efi_novamap;
2324

2425
static bool efi_nosoftreserve;
@@ -58,6 +59,28 @@ int efi_printk(const char *fmt, ...)
5859
char printf_buf[256];
5960
va_list args;
6061
int printed;
62+
int loglevel = printk_get_level(fmt);
63+
64+
switch (loglevel) {
65+
case '0' ... '9':
66+
loglevel -= '0';
67+
break;
68+
default:
69+
/*
70+
* Use loglevel -1 for cases where we just want to print to
71+
* the screen.
72+
*/
73+
loglevel = -1;
74+
break;
75+
}
76+
77+
if (loglevel >= efi_loglevel)
78+
return 0;
79+
80+
if (loglevel >= 0)
81+
efi_puts("EFI stub: ");
82+
83+
fmt = printk_skip_level(fmt);
6184

6285
va_start(args, fmt);
6386
printed = vsnprintf(printf_buf, sizeof(printf_buf), fmt, args);
@@ -100,7 +123,7 @@ efi_status_t efi_parse_options(char const *cmdline)
100123
if (!strcmp(param, "nokaslr")) {
101124
efi_nokaslr = true;
102125
} else if (!strcmp(param, "quiet")) {
103-
efi_quiet = true;
126+
efi_loglevel = CONSOLE_LOGLEVEL_QUIET;
104127
} else if (!strcmp(param, "noinitrd")) {
105128
efi_noinitrd = true;
106129
} else if (!strcmp(param, "efi") && val) {
@@ -114,6 +137,8 @@ efi_status_t efi_parse_options(char const *cmdline)
114137
efi_disable_pci_dma = true;
115138
if (parse_option_str(val, "no_disable_early_pci_dma"))
116139
efi_disable_pci_dma = false;
140+
if (parse_option_str(val, "debug"))
141+
efi_loglevel = CONSOLE_LOGLEVEL_DEBUG;
117142
} else if (!strcmp(param, "video") &&
118143
val && strstarts(val, "efifb:")) {
119144
efi_parse_option_graphics(val + strlen("efifb:"));

drivers/firmware/efi/libstub/efistub.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/compiler.h>
77
#include <linux/efi.h>
88
#include <linux/kernel.h>
9+
#include <linux/kern_levels.h>
910
#include <linux/types.h>
1011
#include <asm/efi.h>
1112

@@ -34,7 +35,7 @@
3435
extern bool efi_nochunk;
3536
extern bool efi_nokaslr;
3637
extern bool efi_noinitrd;
37-
extern bool efi_quiet;
38+
extern int efi_loglevel;
3839
extern bool efi_novamap;
3940

4041
extern const efi_system_table_t *efi_system_table;
@@ -49,11 +50,12 @@ extern const efi_system_table_t *efi_system_table;
4950

5051
#endif
5152

52-
#define efi_info(msg) do { \
53-
if (!efi_quiet) efi_puts("EFI stub: "msg); \
54-
} while (0)
55-
56-
#define efi_err(msg) efi_puts("EFI stub: ERROR: "msg)
53+
#define efi_info(fmt, ...) \
54+
efi_printk(KERN_INFO fmt, ##__VA_ARGS__)
55+
#define efi_err(fmt, ...) \
56+
efi_printk(KERN_ERR "ERROR: " fmt, ##__VA_ARGS__)
57+
#define efi_debug(fmt, ...) \
58+
efi_printk(KERN_DEBUG "DEBUG: " fmt, ##__VA_ARGS__)
5759

5860
/* Helper macros for the usual case of using simple C variables: */
5961
#ifndef fdt_setprop_inplace_var

0 commit comments

Comments
 (0)