1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
11 #include <asm/global_data.h>
13 DECLARE_GLOBAL_DATA_PTR;
15 #define BUFFER_SIZE 480
17 static void append(char **buf, char *buf_end, const char *fmt, ...)
20 size_t size = buf_end - *buf;
23 vsnprintf(*buf, size, fmt, args);
28 static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec)
31 int fmt = gd->log_fmt;
32 char msg[BUFFER_SIZE];
33 char *msg_end = msg + BUFFER_SIZE;
38 struct in_addr bcast_ip;
39 unsigned int log_level;
42 /* Setup packet buffers */
46 /* Disable hardware and put it into the reset state */
48 /* Set current device according to environment variables */
50 /* Get hardware ready for send and receive operations */
57 memset(msg, 0, BUFFER_SIZE);
59 /* Set ethernet header */
60 eth_hdr_size = net_set_ether((uchar *)ptr, net_bcast_ethaddr, PROT_IP);
63 ptr += IP_UDP_HDR_SIZE;
67 * The syslog log levels defined in RFC 5424 match the U-Boot ones up to
70 log_level = rec->level;
73 /* Leave high bits as 0 to write a 'kernel message' */
75 /* Write log message to buffer */
76 append(&ptr, msg_end, "<%u>", log_level);
77 log_hostname = env_get("log_hostname");
79 append(&ptr, msg_end, "%s ", log_hostname);
80 append(&ptr, msg_end, "uboot: ");
81 if (fmt & BIT(LOGF_LEVEL))
82 append(&ptr, msg_end, "%s.",
83 log_get_level_name(rec->level));
84 if (fmt & BIT(LOGF_CAT))
85 append(&ptr, msg_end, "%s,",
86 log_get_cat_name(rec->cat));
87 if (fmt & BIT(LOGF_FILE))
88 append(&ptr, msg_end, "%s:", rec->file);
89 if (fmt & BIT(LOGF_LINE))
90 append(&ptr, msg_end, "%d-", rec->line);
91 if (fmt & BIT(LOGF_FUNC))
92 append(&ptr, msg_end, "%s()", rec->func);
93 if (fmt & BIT(LOGF_MSG))
94 append(&ptr, msg_end, "%s%s",
95 fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
96 /* Consider trailing 0x00 */
99 debug("log message: '%s'\n", log_msg);
101 /* Broadcast message */
102 bcast_ip.s_addr = 0xFFFFFFFFL;
103 net_set_udp_header((uchar *)iphdr, bcast_ip, 514, 514, ptr - log_msg);
104 net_send_packet((uchar *)msg, ptr - msg);
110 LOG_DRIVER(syslog) = {
112 .emit = log_syslog_emit,