1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (c) 2020, Heinrich Schuchardt <xypron.glpk@gmx.de>
12 DECLARE_GLOBAL_DATA_PTR;
14 #define BUFFER_SIZE 480
16 static void append(char **buf, char *buf_end, const char *fmt, ...)
19 size_t size = buf_end - *buf;
22 vsnprintf(*buf, size, fmt, args);
27 static int log_syslog_emit(struct log_device *ldev, struct log_rec *rec)
30 int fmt = gd->log_fmt;
31 char msg[BUFFER_SIZE];
32 char *msg_end = msg + BUFFER_SIZE;
37 struct in_addr bcast_ip;
38 unsigned int log_level;
41 /* Setup packet buffers */
45 /* Disable hardware and put it into the reset state */
47 /* Set current device according to environment variables */
49 /* Get hardware ready for send and receive operations */
56 memset(msg, 0, BUFFER_SIZE);
58 /* Set ethernet header */
59 eth_hdr_size = net_set_ether((uchar *)ptr, net_bcast_ethaddr, PROT_IP);
62 ptr += IP_UDP_HDR_SIZE;
66 * The syslog log levels defined in RFC 5424 match the U-Boot ones up to
69 log_level = rec->level;
72 /* Leave high bits as 0 to write a 'kernel message' */
74 /* Write log message to buffer */
75 append(&ptr, msg_end, "<%u>", log_level);
76 log_hostname = env_get("log_hostname");
78 append(&ptr, msg_end, "%s ", log_hostname);
79 append(&ptr, msg_end, "uboot: ");
80 if (fmt & BIT(LOGF_LEVEL))
81 append(&ptr, msg_end, "%s.",
82 log_get_level_name(rec->level));
83 if (fmt & BIT(LOGF_CAT))
84 append(&ptr, msg_end, "%s,",
85 log_get_cat_name(rec->cat));
86 if (fmt & BIT(LOGF_FILE))
87 append(&ptr, msg_end, "%s:", rec->file);
88 if (fmt & BIT(LOGF_LINE))
89 append(&ptr, msg_end, "%d-", rec->line);
90 if (fmt & BIT(LOGF_FUNC))
91 append(&ptr, msg_end, "%s()", rec->func);
92 if (fmt & BIT(LOGF_MSG))
93 append(&ptr, msg_end, "%s%s",
94 fmt != BIT(LOGF_MSG) ? " " : "", rec->msg);
95 /* Consider trailing 0x00 */
98 debug("log message: '%s'\n", log_msg);
100 /* Broadcast message */
101 bcast_ip.s_addr = 0xFFFFFFFFL;
102 net_set_udp_header((uchar *)iphdr, bcast_ip, 514, 514, ptr - log_msg);
103 net_send_packet((uchar *)msg, ptr - msg);
109 LOG_DRIVER(syslog) = {
111 .emit = log_syslog_emit,