fusee: Improve integration with the new logging system

fusee: Implement log level configuration from BCT.ini
This commit is contained in:
hexkyz 2018-09-28 21:12:59 +01:00
parent 2e6983d214
commit ca0e41e8a0
16 changed files with 98 additions and 139 deletions

View file

@ -20,17 +20,21 @@
#include "vsprintf.h"
/* default log level for screen output */
ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_MANDATORY;
ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_NONE;
void log_set_log_level(ScreenLogLevel log_level) {
g_screen_log_level = log_level;
}
ScreenLogLevel log_get_log_level() {
return g_screen_log_level;
}
void log_to_uart(const char *message) {
/* TODO: add UART logging */
}
void print_to_screen(ScreenLogLevel screen_log_level, char *message) {
static void print_to_screen(ScreenLogLevel screen_log_level, char *message) {
/* don't print to screen if below log level */
if(screen_log_level > g_screen_log_level) return;
@ -58,7 +62,7 @@ void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args)
print_to_screen(screen_log_level, buf);
}
void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) {
static void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) {
char typebuf[] = "[%s] %s";
/* apply prefix and append message format */

View file

@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FUSEE_PRIMARY_PRINT_H
#define FUSEE_PRIMARY_PRINT_H
#ifndef FUSEE_LOG_H
#define FUSEE_LOG_H
#define PRINT_MESSAGE_MAX_LENGTH 512
@ -32,10 +32,10 @@ typedef enum {
SCREEN_LOG_LEVEL_NO_PREFIX = 0x100 /* OR this to your LOG_LEVEL to prevent prefix creation */
} ScreenLogLevel;
/* TODO: make this configurable by BCT.ini */
extern ScreenLogLevel g_screen_log_level;
void log_set_log_level(ScreenLogLevel screen_log_level);
ScreenLogLevel log_get_log_level();
void log_to_uart(const char *message);
void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args);
void print(ScreenLogLevel screen_log_level, const char* fmt, ...);

View file

@ -26,6 +26,8 @@
#include "sdmmc/sdmmc.h"
#include "lib/fatfs/ff.h"
#include "lib/log.h"
#include "lib/vsprintf.h"
#include "lib/ini.h"
#include "display/video_fb.h"
extern void (*__program_exit_callback)(int rc);
@ -33,6 +35,8 @@ extern void (*__program_exit_callback)(int rc);
static void *g_framebuffer;
static char g_bct0_buffer[BCTO_MAX_SIZE];
#define CONFIG_LOG_LEVEL_KEY "log_level"
#define DEFAULT_BCT0_FOR_DEBUG \
"BCT0\n"\
"[stage1]\n"\
@ -45,25 +49,41 @@ static const char *load_config(void) {
print(SCREEN_LOG_LEVEL_DEBUG, "Failed to read BCT0 from SD!\n");
print(SCREEN_LOG_LEVEL_DEBUG, "Using default BCT0!\n");
memcpy(g_bct0_buffer, DEFAULT_BCT0_FOR_DEBUG, sizeof(DEFAULT_BCT0_FOR_DEBUG));
/* TODO: Stop using default. */
/* printk("Error: Failed to load BCT.ini!\n");
* generic_panic(); */
}
if (memcmp(g_bct0_buffer, "BCT0", 4) != 0) {
fatal_error("Unexpected magic in BCT.ini!\n");
}
/* Return pointer to first line of the ini. */
const char *bct0 = g_bct0_buffer;
while (*bct0 && *bct0 != '\n') {
bct0++;
}
if (!bct0) {
fatal_error("BCT.ini has no newline!\n");
}
return bct0;
}
static int config_ini_handler(void *user, const char *section, const char *name, const char *value) {
if (strcmp(section, "config") == 0) {
if (strcmp(name, CONFIG_LOG_LEVEL_KEY) == 0) {
ScreenLogLevel *config_log_level = (ScreenLogLevel *)user;
int log_level = 0;
sscanf(value, "%d", &log_level);
*config_log_level = (ScreenLogLevel)log_level;
} else {
return 0;
}
} else {
return 0;
}
return 1;
}
static void setup_env(void) {
g_framebuffer = (void *)0xC0000000;
@ -111,20 +131,26 @@ int main(void) {
const char *stage2_path;
stage2_args_t *stage2_args;
uint32_t stage2_version = 0;
/* Set the SDMMC's driver logging level. */
sdmmc_set_log_level(SDMMC_LOG_INFO);
ScreenLogLevel log_level = SCREEN_LOG_LEVEL_MANDATORY;
/* Initialize the display, console, etc. */
setup_env();
/* Load the BCT0 configuration ini off of the SD. */
bct0 = load_config();
/* Extract the logging level from the BCT.ini file. */
if (ini_parse_string(bct0, config_ini_handler, &log_level) < 0) {
fatal_error("Failed to parse BCT.ini!\n");
}
/* Override the global logging level. */
log_set_log_level(log_level);
/* Say hello. */
print(SCREEN_LOG_LEVEL_MANDATORY, "Welcome to Atmosph\xe8re Fus\xe9" "e!\n");
print(SCREEN_LOG_LEVEL_DEBUG, "Using color linear framebuffer at 0x%p!\n", g_framebuffer);
/* Load the BCT0 configuration ini off of the SD. */
bct0 = load_config();
/* Load the loader payload into DRAM. */
load_stage2(bct0);
@ -133,6 +159,7 @@ int main(void) {
strcpy(g_chainloader_arg_data, stage2_path);
stage2_args = (stage2_args_t *)(g_chainloader_arg_data + strlen(stage2_path) + 1); /* May be unaligned. */
memcpy(&stage2_args->version, &stage2_version, 4);
stage2_args->log_level = log_level;
stage2_args->display_initialized = false;
strcpy(stage2_args->bct0, bct0);
g_chainloader_argc = 2;

View file

@ -32,39 +32,12 @@
#include "../max7762x.h"
#include "../lib/log.h"
static SdmmcLogLevel g_sdmmc_log_level = SDMMC_LOG_NONE;
void sdmmc_set_log_level(SdmmcLogLevel log_level)
static void sdmmc_print(sdmmc_t *sdmmc, ScreenLogLevel screen_log_level, char *fmt, va_list list)
{
g_sdmmc_log_level = log_level;
}
static void sdmmc_print(sdmmc_t *sdmmc, SdmmcLogLevel log_level, char *fmt, va_list list)
{
if (log_level > g_sdmmc_log_level)
if (screen_log_level > log_get_log_level())
return;
char sdmmc_fmt[] = "%s: ";
ScreenLogLevel screen_log_level = SCREEN_LOG_LEVEL_ERROR;
switch (log_level) {
case SDMMC_LOG_ERROR:
screen_log_level = SCREEN_LOG_LEVEL_ERROR;
break;
case SDMMC_LOG_WARN:
screen_log_level = SCREEN_LOG_LEVEL_WARNING;
break;
case SDMMC_LOG_INFO:
screen_log_level = SCREEN_LOG_LEVEL_DEBUG;
break;
case SDMMC_LOG_DEBUG:
screen_log_level = SCREEN_LOG_LEVEL_DEBUG;
break;
default:
break;
}
print(screen_log_level, sdmmc_fmt, sdmmc->name);
print(screen_log_level, "%s: ", sdmmc->name);
vprint(screen_log_level, fmt, list);
print(screen_log_level | SCREEN_LOG_LEVEL_NO_PREFIX, "\n");
}
@ -74,7 +47,7 @@ void sdmmc_error(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_ERROR, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_ERROR, fmt, list);
va_end(list);
}
@ -83,7 +56,7 @@ void sdmmc_warn(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_WARN, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_WARNING, fmt, list);
va_end(list);
}
@ -92,7 +65,7 @@ void sdmmc_info(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_INFO, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_INFO, fmt, list);
va_end(list);
}
@ -101,7 +74,7 @@ void sdmmc_debug(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_DEBUG, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_DEBUG, fmt, list);
va_end(list);
}

View file

@ -181,15 +181,6 @@
#define SDMMC_RSP_SPI_R5 (SDMMC_RSP_SPI_S1|SDMMC_RSP_SPI_S2)
#define SDMMC_RSP_SPI_R7 (SDMMC_RSP_SPI_S1|SDMMC_RSP_SPI_B4)
/* Internal logging */
typedef enum {
SDMMC_LOG_NONE = 0,
SDMMC_LOG_ERROR = 1,
SDMMC_LOG_WARN = 2,
SDMMC_LOG_INFO = 3,
SDMMC_LOG_DEBUG = 4
} SdmmcLogLevel;
/* SDMMC controllers */
typedef enum {
SDMMC_1 = 0,
@ -306,7 +297,6 @@ int sdmmc_execute_tuning(sdmmc_t *sdmmc, SdmmcBusSpeed bus_speed, uint32_t opcod
int sdmmc_send_cmd(sdmmc_t *sdmmc, sdmmc_command_t *cmd, sdmmc_request_t *req, uint32_t *num_blocks_out);
int sdmmc_load_response(sdmmc_t *sdmmc, uint32_t flags, uint32_t *resp);
int sdmmc_abort(sdmmc_t *sdmmc, uint32_t opcode);
void sdmmc_set_log_level(SdmmcLogLevel log_level);
void sdmmc_error(sdmmc_t *sdmmc, char *fmt, ...);
void sdmmc_warn(sdmmc_t *sdmmc, char *fmt, ...);
void sdmmc_info(sdmmc_t *sdmmc, char *fmt, ...);

View file

@ -14,17 +14,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include "utils.h"
#include "display/video_fb.h"
#include "fs_utils.h"
#include "stage2.h"
#include "chainloader.h"
#include "lib/log.h"
#include "lib/vsprintf.h"
#include "lib/ini.h"
#include "lib/fatfs/ff.h"
#include "fs_utils.h"
#include "utils.h"
char g_stage2_path[0x100] = {0};

View file

@ -17,7 +17,14 @@
#ifndef FUSEE_STAGE2_H
#define FUSEE_STAGE2_H
#include "sdmmc/sdmmc_core.h"
#include <stdbool.h>
#include <stdint.h>
#include "display/video_fb.h"
#include "lib/log.h"
#include "lib/vsprintf.h"
#include "lib/ini.h"
#include "lib/fatfs/ff.h"
/* TODO: Is there a more concise way to do this? */
#define STAGE2_ARGV_PROGRAM_PATH 0
@ -37,6 +44,7 @@ typedef struct {
typedef struct {
uint32_t version;
ScreenLogLevel log_level;
bool display_initialized;
char bct0[BCTO_MAX_SIZE];
} stage2_args_t;

View file

@ -14,12 +14,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <malloc.h>
#include <sys/iosupport.h>
#include "console.h"
#include "di.h"
#include "display/video_fb.h"
@ -181,7 +175,6 @@ void *console_get_framebuffer(bool enable_display) {
if (g_framebuffer != NULL && enable_display) {
console_init_display();
}
return g_framebuffer;
}
@ -189,8 +182,6 @@ int console_display(const void *framebuffer) {
if (!g_display_initialized) {
console_init_display();
}
/* TODO: does this work? */
display_init_framebuffer((void *)framebuffer);
return 0;
}
@ -199,7 +190,6 @@ int console_resume(void) {
if (!g_display_initialized) {
console_init_display();
} else {
/* TODO: does this work? */
display_init_framebuffer(g_framebuffer);
}
return 0;

View file

@ -17,6 +17,13 @@
#ifndef FUSEE_CONSOLE_H
#define FUSEE_CONSOLE_H
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <errno.h>
#include <malloc.h>
#include <sys/iosupport.h>
int console_init(bool display_initialized);
void *console_get_framebuffer(bool enable_display);
int console_display(const void *framebuffer); /* Must be page-aligned */

View file

@ -19,17 +19,21 @@
#include <stdio.h>
/* default log level for screen output */
ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_MANDATORY;
ScreenLogLevel g_screen_log_level = SCREEN_LOG_LEVEL_NONE;
void log_set_log_level(ScreenLogLevel log_level) {
g_screen_log_level = log_level;
}
ScreenLogLevel log_get_log_level() {
return g_screen_log_level;
}
void log_to_uart(const char *message) {
/* TODO: add UART logging */
}
void print_to_screen(ScreenLogLevel screen_log_level, char *message) {
static void print_to_screen(ScreenLogLevel screen_log_level, char *message) {
/* don't print to screen if below log level */
if(screen_log_level > g_screen_log_level) return;
@ -57,7 +61,7 @@ void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args)
print_to_screen(screen_log_level, buf);
}
void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) {
static void add_prefix(ScreenLogLevel screen_log_level, const char *fmt, char *buf) {
char typebuf[] = "[%s] %s";
/* apply prefix and append message format */

View file

@ -14,8 +14,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FUSEE_SECONDARY_PRINT_H
#define FUSEE_SECONDARY_PRINT_H
#ifndef FUSEE_LOG_H
#define FUSEE_LOG_H
#define PRINT_MESSAGE_MAX_LENGTH 512
@ -32,10 +32,10 @@ typedef enum {
SCREEN_LOG_LEVEL_NO_PREFIX = 0x100 /* OR this to your LOG_LEVEL to prevent prefix creation */
} ScreenLogLevel;
/* TODO: make this configurable by BCT.ini */
extern ScreenLogLevel g_screen_log_level;
void log_set_log_level(ScreenLogLevel screen_log_level);
ScreenLogLevel log_get_log_level();
void log_to_uart(const char *message);
void vprint(ScreenLogLevel screen_log_level, const char *fmt, va_list args);
void print(ScreenLogLevel screen_log_level, const char* fmt, ...);

View file

@ -52,8 +52,6 @@ static void setup_env(void) {
if (nxfs_mount_all() < 0) {
fatal_error("Failed to mount at least one parition: %s\n", strerror(errno));
}
/* TODO: What other hardware init should we do here? */
}
static void cleanup_env(void) {
@ -87,8 +85,8 @@ int main(int argc, void **argv) {
generic_panic();
}
/* Set the SDMMC's driver logging level. */
sdmmc_set_log_level(SDMMC_LOG_INFO);
/* Override the global logging level. */
log_set_log_level(g_stage2_args->log_level);
/* Initialize the display, console, FS, etc. */
setup_env();

View file

@ -32,39 +32,12 @@
#include "../max7762x.h"
#include "../lib/log.h"
static SdmmcLogLevel g_sdmmc_log_level = SDMMC_LOG_NONE;
void sdmmc_set_log_level(SdmmcLogLevel log_level)
static void sdmmc_print(sdmmc_t *sdmmc, ScreenLogLevel screen_log_level, char *fmt, va_list list)
{
g_sdmmc_log_level = log_level;
}
static void sdmmc_print(sdmmc_t *sdmmc, SdmmcLogLevel log_level, char *fmt, va_list list)
{
if (log_level > g_sdmmc_log_level)
if (screen_log_level > log_get_log_level())
return;
char sdmmc_fmt[] = "%s: ";
ScreenLogLevel screen_log_level = SCREEN_LOG_LEVEL_ERROR;
switch (log_level) {
case SDMMC_LOG_ERROR:
screen_log_level = SCREEN_LOG_LEVEL_ERROR;
break;
case SDMMC_LOG_WARN:
screen_log_level = SCREEN_LOG_LEVEL_WARNING;
break;
case SDMMC_LOG_INFO:
screen_log_level = SCREEN_LOG_LEVEL_DEBUG;
break;
case SDMMC_LOG_DEBUG:
screen_log_level = SCREEN_LOG_LEVEL_DEBUG;
break;
default:
break;
}
print(screen_log_level, sdmmc_fmt, sdmmc->name);
print(screen_log_level, "%s: ", sdmmc->name);
vprint(screen_log_level, fmt, list);
print(screen_log_level | SCREEN_LOG_LEVEL_NO_PREFIX, "\n");
}
@ -74,7 +47,7 @@ void sdmmc_error(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_ERROR, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_ERROR, fmt, list);
va_end(list);
}
@ -83,7 +56,7 @@ void sdmmc_warn(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_WARN, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_WARNING, fmt, list);
va_end(list);
}
@ -92,7 +65,7 @@ void sdmmc_info(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_INFO, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_INFO, fmt, list);
va_end(list);
}
@ -101,7 +74,7 @@ void sdmmc_debug(sdmmc_t *sdmmc, char *fmt, ...)
va_list list;
va_start(list, fmt);
sdmmc_print(sdmmc, SDMMC_LOG_DEBUG, fmt, list);
sdmmc_print(sdmmc, SCREEN_LOG_LEVEL_DEBUG, fmt, list);
va_end(list);
}

View file

@ -181,15 +181,6 @@
#define SDMMC_RSP_SPI_R5 (SDMMC_RSP_SPI_S1|SDMMC_RSP_SPI_S2)
#define SDMMC_RSP_SPI_R7 (SDMMC_RSP_SPI_S1|SDMMC_RSP_SPI_B4)
/* Internal logging */
typedef enum {
SDMMC_LOG_NONE = 0,
SDMMC_LOG_ERROR = 1,
SDMMC_LOG_WARN = 2,
SDMMC_LOG_INFO = 3,
SDMMC_LOG_DEBUG = 4
} SdmmcLogLevel;
/* SDMMC controllers */
typedef enum {
SDMMC_1 = 0,
@ -306,7 +297,6 @@ int sdmmc_execute_tuning(sdmmc_t *sdmmc, SdmmcBusSpeed bus_speed, uint32_t opcod
int sdmmc_send_cmd(sdmmc_t *sdmmc, sdmmc_command_t *cmd, sdmmc_request_t *req, uint32_t *num_blocks_out);
int sdmmc_load_response(sdmmc_t *sdmmc, uint32_t flags, uint32_t *resp);
int sdmmc_abort(sdmmc_t *sdmmc, uint32_t opcode);
void sdmmc_set_log_level(SdmmcLogLevel log_level);
void sdmmc_error(sdmmc_t *sdmmc, char *fmt, ...);
void sdmmc_warn(sdmmc_t *sdmmc, char *fmt, ...);
void sdmmc_info(sdmmc_t *sdmmc, char *fmt, ...);

View file

@ -14,7 +14,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "console.h"
#include "di.h"
#include "timers.h"
#include "splash_screen.h"
@ -36,7 +36,7 @@ static void render_bmp(const uint32_t *bmp_data, uint32_t *framebuffer, uint32_t
}
/* Re-initialize the frame buffer. */
display_init_framebuffer(framebuffer);
console_display(framebuffer);
}
void display_splash_screen_bmp(const char *custom_splash_path, void *fb_address) {

View file

@ -17,8 +17,9 @@
#ifndef FUSEE_STAGE2_H
#define FUSEE_STAGE2_H
#include "utils.h"
#include "lib/log.h"
#include "sdmmc/sdmmc.h"
#include "utils.h"
/* TODO: Is there a more concise way to do this? */
#define STAGE2_ARGV_PROGRAM_PATH 0
@ -29,6 +30,7 @@
typedef struct {
uint32_t version;
ScreenLogLevel log_level;
bool display_initialized;
char bct0[BCTO_MAX_SIZE];
} stage2_args_t;