From c038c7839c0b6b42e75231440a86e498b5c7843b Mon Sep 17 00:00:00 2001 From: ivoszbg Date: Tue, 14 Jun 2022 19:51:51 +0300 Subject: [PATCH] lib: Move debug print function into a separate file Signed-off-by: Ivaylo Ivanov --- include/lib/debug.h | 12 ++++++++++++ include/main.h | 3 +-- lib/Kconfig | 10 +++++----- lib/Makefile | 1 + lib/debug/debug.c | 18 ++++++++++++++++++ lib/simplefb/simplefb.c | 13 ------------- main/main.c | 12 +++--------- 7 files changed, 40 insertions(+), 29 deletions(-) create mode 100644 include/lib/debug.h create mode 100644 lib/debug/debug.c diff --git a/include/lib/debug.h b/include/lib/debug.h new file mode 100644 index 0000000..85536ca --- /dev/null +++ b/include/lib/debug.h @@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ + +#ifndef DEBUG_H_ /* Include guard */ +#define DEBUG_H_ + +extern void draw_text(volatile char *fb, char *text, int textX, int textY, int width, int stride); +long int debug_linecount = 0; + +#endif diff --git a/include/main.h b/include/main.h index d48ebcf..e6cb95c 100644 --- a/include/main.h +++ b/include/main.h @@ -11,8 +11,7 @@ extern void load_kernel(void* dtb, void* x1, void* x2, void* x3, void* kernel); extern void soc_init(void); extern void board_init(void); -extern void draw_text(volatile char *fb, char *text, int textX, int textY); -extern void debug_printfb(volatile char *fb, char *text, int textX, int width, int stride); +extern void printk(char *text); /* Define our own 128 bit memcpy */ void memcpy(void *dest, void *src, int size) diff --git a/lib/Kconfig b/lib/Kconfig index 5ef5e7f..2b7c7b9 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -1,7 +1,7 @@ menu "Libraries" -config SIMPLE_FB - bool "Support for Simple Framebuffer" - default y - help - Say Y if you want to have Framebuffer output. + config SIMPLE_FB + bool "Support for Simple Framebuffer" + default y + help + Say Y if you want to have Framebuffer output. endmenu diff --git a/lib/Makefile b/lib/Makefile index bb8ed81..4f35f46 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1 +1,2 @@ lib-$(CONFIG_SIMPLE_FB) += simplefb/simplefb.o +lib-y += debug/debug.o diff --git a/lib/debug/debug.c b/lib/debug/debug.c new file mode 100644 index 0000000..2ccc7ee --- /dev/null +++ b/lib/debug/debug.c @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2022, Ivaylo Ivanov + */ +#include + +void printk(char *text) { +#ifdef CONFIG_SIMPLE_FB + /* IMPORTANT: Limit the linecount */ + if(debug_linecount > 100 || debug_linecount < 0) + debug_linecount = 0; + + draw_text((char*)CONFIG_FRAMEBUFFER_BASE, "[uniLoader] ", 0, (20 + (debug_linecount * 30)), CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); + draw_text((char*)CONFIG_FRAMEBUFFER_BASE, text, 0 + (12 * 8), (20 + (debug_linecount * 30)), CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); + + debug_linecount++; +#endif +} diff --git a/lib/simplefb/simplefb.c b/lib/simplefb/simplefb.c index 1aa2e42..9f2ae41 100644 --- a/lib/simplefb/simplefb.c +++ b/lib/simplefb/simplefb.c @@ -8,8 +8,6 @@ #include #include -int debug_linecount = 0; - void clean_fb(volatile char *fb, char *text, int width, int height, int stride) { for (volatile char *addr = fb; addr < fb + (width * height * stride); addr += stride) *(int*) (addr) = 0x0; @@ -61,17 +59,6 @@ void draw_text(volatile char *fb, char *text, int textX, int textY, int width, i } } -void debug_printfb(volatile char *fb, char *text, int textX, int width, int stride) { - /* IMPORTANT: Limit the linecount */ - if(debug_linecount > 100 || debug_linecount < 0) - debug_linecount = 0; - - draw_text(fb, "[uniLoader] ", textX, (20 + (debug_linecount * 30)), width, stride); - draw_text(fb, text, textX + 96, (20 + (debug_linecount * 30)), width, stride); - - debug_linecount++; -} - /* Helper functions */ font_params get_font_params() { font_params params = {.width=FONTW, .height=FONTH}; diff --git a/main/main.c b/main/main.c index 0c827ee..afdf9bf 100644 --- a/main/main.c +++ b/main/main.c @@ -10,19 +10,13 @@ void main(void* dt, void* kernel) { /* Initialize SoC and Board specific peripherals/quirks */ soc_init(); - #ifdef CONFIG_SIMPLE_FB - debug_printfb((char*)CONFIG_FRAMEBUFFER_BASE, "soc_init() passed!", 0, CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); - #endif + printk("soc_init() passed!"); board_init(); - #ifdef CONFIG_SIMPLE_FB - debug_printfb((char*)CONFIG_FRAMEBUFFER_BASE, "board_init() passed!", 0, CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); - #endif + printk("board_init() passed!"); /* Copy kernel to memory and boot */ - #ifdef CONFIG_SIMPLE_FB - debug_printfb((char*)CONFIG_FRAMEBUFFER_BASE, "Booting linux...", 0, CONFIG_FRAMEBUFFER_WIDTH, CONFIG_FRAMEBUFFER_STRIDE); - #endif + printk("Booting linux..."); memcpy((void*)CONFIG_PAYLOAD_ENTRY, kernel, (unsigned long) &kernel_size); load_kernel(dt, 0, 0, 0, (void*)CONFIG_PAYLOAD_ENTRY); }