aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-05-17 10:21:45 +0200
committerHarald Welte <laforge@gnumonks.org>2019-05-17 10:22:00 +0200
commitbdf1b35fbbefcfe4545d1dd4ee6e30d05920b102 (patch)
tree5d0b2e99fa54131d8d6c2162d811ae43640c7721
parentdda661c298e010b26b61dc9229f6cbcb4ddfa3b2 (diff)
integrate libosmocore logging into firmware
We do so using our own 'raw' log target to avoid the 4k-on-stack buffer of libosmocore _output() function. Change-Id: I7a10b5b2b50bcee0154a1fa3fc43756aec836226
-rw-r--r--sysmoOCTSIM/gcc/Makefile3
-rw-r--r--sysmoOCTSIM/libosmo_emb.c112
-rw-r--r--sysmoOCTSIM/logging.h8
-rw-r--r--sysmoOCTSIM/main.c9
4 files changed, 129 insertions, 3 deletions
diff --git a/sysmoOCTSIM/gcc/Makefile b/sysmoOCTSIM/gcc/Makefile
index 3001015..640fdff 100644
--- a/sysmoOCTSIM/gcc/Makefile
+++ b/sysmoOCTSIM/gcc/Makefile
@@ -83,6 +83,7 @@ hal/src/hal_init.o \
gcc/gcc/startup_same54.o \
hal/src/hal_usb_device.o \
main.o \
+libosmo_emb.o \
manual_test.o \
talloc.o \
usb_descriptors.o \
@@ -136,6 +137,7 @@ OBJS_AS_ARGS += \
"gcc/gcc/startup_same54.o" \
"hal/src/hal_usb_device.o" \
"main.o" \
+"libosmo_emb.o" \
"manual_test.o" \
"talloc.o" \
"usb_descriptors.o" \
@@ -195,6 +197,7 @@ DEPS_AS_ARGS += \
"hal/src/hal_usart_async_rings.d" \
"hpl/osc32kctrl/hpl_osc32kctrl.d" \
"main.d" \
+"libosmo_emb.d" \
"manual_test.d" \
"talloc.d" \
"usb_descriptors.d" \
diff --git a/sysmoOCTSIM/libosmo_emb.c b/sysmoOCTSIM/libosmo_emb.c
new file mode 100644
index 0000000..b5be6f1
--- /dev/null
+++ b/sysmoOCTSIM/libosmo_emb.c
@@ -0,0 +1,112 @@
+/* Integration of libosmocore into our bare-iron embedded target */
+
+#include <string.h>
+#include <stdio.h>
+#include <osmocom/core/utils.h>
+#include <osmocom/core/msgb.h>
+
+
+extern void *g_tall_ctx;
+void *g_msgb_ctx;
+
+/***********************************************************************
+ * Logging
+ ***********************************************************************/
+
+#include "logging.h"
+#include <osmocom/core/logging.h>
+
+static const struct log_info_cat log_info_cat[] = {
+ [DUSB] = {
+ .name = "USB",
+ .description = "USB Transport",
+ .enabled = 1,
+ .loglevel = LOGL_NOTICE,
+ },
+ [DCCID] = {
+ .name = "CCID",
+ .description = "CCID Core",
+ .color = "\033[1;35m",
+ .enabled = 1,
+ .loglevel = LOGL_DEBUG,
+ },
+};
+
+static const struct log_info log_info = {
+ .cat = log_info_cat,
+ .num_cat = ARRAY_SIZE(log_info_cat),
+};
+
+/* call-back function to the logging framework. We use this instead of the libosmocore
+ * provided target, as libosmocore wants to put 4kB on the stack. */
+static void stderr_raw_output(struct log_target *target, int subsys, unsigned int level,
+ const char *file, int line, int cont, const char *format, va_list ap)
+{
+ if (!cont) {
+ /* TODO: Timestamp? */
+ if (target->print_category)
+ fprintf(stderr, "%s ", log_category_name(subsys));
+
+ if (target->print_level)
+ fprintf(stderr, "%s ", log_level_str(level));
+
+ if (target->print_category_hex)
+ fprintf(stderr, "<%4.4x> ", subsys);
+
+ if (target->print_filename_pos == LOG_FILENAME_POS_HEADER_END) {
+ const char *bn;
+ switch (target->print_filename2) {
+ case LOG_FILENAME_NONE:
+ break;
+ case LOG_FILENAME_PATH:
+ fprintf(stderr, "%s:%d ", file, line);
+ break;
+ case LOG_FILENAME_BASENAME:
+ bn = strrchr(file, '/');
+ if (!bn || !bn[1])
+ bn = file;
+ else
+ bn++;
+ fprintf(stderr, "%s:%d ", bn, line);
+ break;
+ }
+ }
+ }
+ vfprintf(stderr, format, ap);
+ /* TODO: LOG_FILENAME_POS_LINE_END; we cannot modify the format string here :/ */
+ int fmt_len = strlen(format);
+ if (fmt_len && format[fmt_len-1] == '\n')
+ fputc('\r', stderr);
+}
+
+static struct log_target *log_target_create_stderr_raw(void)
+{
+ struct log_target *target;
+
+ target = log_target_create();
+ if (!target)
+ return NULL;
+
+ target->type = LOG_TGT_TYPE_STDERR;
+ target->raw_output = stderr_raw_output;
+ target->print_category = true;
+ target->print_level = true;
+
+ return target;
+}
+
+void libosmo_emb_init(void)
+{
+ struct log_target *stderr_target;
+
+ /* msgb */
+ g_msgb_ctx = talloc_pool(g_tall_ctx, 20480);
+ talloc_set_memlimit(g_msgb_ctx, 20480);
+ msgb_talloc_ctx_init(g_msgb_ctx, 0);
+
+ /* logging */
+ log_init(&log_info, g_tall_ctx);
+ stderr_target = log_target_create_stderr_raw();
+ log_add_target(stderr_target);
+ log_set_all_filter(stderr_target, 1);
+}
diff --git a/sysmoOCTSIM/logging.h b/sysmoOCTSIM/logging.h
new file mode 100644
index 0000000..900f88e
--- /dev/null
+++ b/sysmoOCTSIM/logging.h
@@ -0,0 +1,8 @@
+#pragma once
+
+#include <osmocom/core/logging.h>
+
+enum {
+ DUSB,
+ DCCID
+};
diff --git a/sysmoOCTSIM/main.c b/sysmoOCTSIM/main.c
index 80b52dc..01ea0a8 100644
--- a/sysmoOCTSIM/main.c
+++ b/sysmoOCTSIM/main.c
@@ -946,11 +946,12 @@ DEFUN(sim_iccid, cmd_sim_iccid, "sim-iccid", "Read ICCID from SIM card")
}
extern void testmode_init(void);
+extern void libosmo_emb_init(void);
#include "talloc.h"
+#include "logging.h"
#include <osmocom/core/msgb.h>
void *g_tall_ctx;
-void *g_msgb_ctx;
DEFUN(_talloc_report, cmd_talloc_report, "talloc-report", "Generate a talloc report")
{
@@ -1039,8 +1040,10 @@ int main(void)
talloc_enable_null_tracking();
g_tall_ctx = talloc_named_const(NULL, 0, "global");
printf("g_tall_ctx=%p\r\n", g_tall_ctx);
- g_msgb_ctx = talloc_pool(g_tall_ctx, 20480);
- talloc_set_memlimit(g_msgb_ctx, 20480);
+
+ libosmo_emb_init();
+
+ LOGP(DUSB, LOGL_ERROR, "foobar usb\n");
command_print_prompt();
while (true) { // main loop