mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
started on centralized printing/logging
some character problems with "atmosphère" and such strings
This commit is contained in:
parent
a2b4d9168d
commit
840242b68e
4 changed files with 134 additions and 10 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include "gpt.h"
|
#include "gpt.h"
|
||||||
#include "display/video_fb.h"
|
#include "display/video_fb.h"
|
||||||
#include "sdmmc/sdmmc.h"
|
#include "sdmmc/sdmmc.h"
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
extern void (*__program_exit_callback)(int rc);
|
extern void (*__program_exit_callback)(int rc);
|
||||||
|
|
||||||
|
@ -91,23 +92,23 @@ int main(int argc, void **argv) {
|
||||||
/* Initialize the display, console, FS, etc. */
|
/* Initialize the display, console, FS, etc. */
|
||||||
setup_env();
|
setup_env();
|
||||||
|
|
||||||
printf(u8"Welcome to Atmosphère Fusée Stage 2!\n");
|
print(PRINT_LOG_MANDATORY, u8"Welcome to Atmosphère Fusée Stage 2!\n");
|
||||||
printf("Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]);
|
print(PRINT_LOG_DEBUG, "Stage 2 executing from: %s\n", (const char *)argv[STAGE2_ARGV_PROGRAM_PATH]);
|
||||||
|
|
||||||
/* This will load all remaining binaries off of the SD. */
|
/* This will load all remaining binaries off of the SD. */
|
||||||
load_payload(g_stage2_args->bct0);
|
load_payload(g_stage2_args->bct0);
|
||||||
|
|
||||||
printf("Loaded payloads!\n");
|
print(PRINT_LOG_INFO, "Loaded payloads!\n");
|
||||||
|
|
||||||
g_do_nxboot = loader_ctx->chainload_entrypoint == 0;
|
g_do_nxboot = loader_ctx->chainload_entrypoint == 0;
|
||||||
if (g_do_nxboot) {
|
if (g_do_nxboot) {
|
||||||
printf("Now performing nxboot.\n");
|
print(PRINT_LOG_INFO, "Now performing nxboot.\n");
|
||||||
uint32_t boot_memaddr = nxboot_main();
|
uint32_t boot_memaddr = nxboot_main();
|
||||||
nxboot_finish(boot_memaddr);
|
nxboot_finish(boot_memaddr);
|
||||||
} else {
|
} else {
|
||||||
/* TODO: What else do we want to do in terms of argc/argv? */
|
/* TODO: What else do we want to do in terms of argc/argv? */
|
||||||
const char *path = get_loader_ctx()->file_paths_to_load[get_loader_ctx()->file_id_of_entrypoint];
|
const char *path = get_loader_ctx()->file_paths_to_load[get_loader_ctx()->file_id_of_entrypoint];
|
||||||
printf("Now chainloading.\n");
|
print(PRINT_LOG_INFO, "Now chainloading.\n");
|
||||||
g_chainloader_argc = 1;
|
g_chainloader_argc = 1;
|
||||||
strcpy(g_chainloader_arg_data, path);
|
strcpy(g_chainloader_arg_data, path);
|
||||||
}
|
}
|
||||||
|
|
84
fusee/fusee-secondary/src/print.c
Normal file
84
fusee/fusee-secondary/src/print.c
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "print.h"
|
||||||
|
|
||||||
|
#include "display/video_fb.h"
|
||||||
|
|
||||||
|
PrintLogLevel g_print_log_level = PRINT_LOG_DEBUG;
|
||||||
|
|
||||||
|
void vprintk(const char *fmt, va_list args)
|
||||||
|
{
|
||||||
|
char buf[PRINT_MESSAGE_MAX_LENGTH];
|
||||||
|
vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, fmt, args);
|
||||||
|
video_puts(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void printk(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list list;
|
||||||
|
va_start(list, fmt);
|
||||||
|
vprintk(fmt, list);
|
||||||
|
va_end(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* print - logs a message based on its message_level
|
||||||
|
*
|
||||||
|
* If the level is below g_message_level it will not be shown
|
||||||
|
* but logged to UART (UART is TO DO)
|
||||||
|
*/
|
||||||
|
void print(PrintLogLevel printLogLevel, const char * fmt, ...)
|
||||||
|
{
|
||||||
|
char typebuf[] = "[%s] %s";
|
||||||
|
char buf[PRINT_MESSAGE_MAX_LENGTH] = {};
|
||||||
|
|
||||||
|
/* apply prefix and append message format */
|
||||||
|
/* TODO: add coloring to the output */
|
||||||
|
switch(printLogLevel)
|
||||||
|
{
|
||||||
|
case PRINT_LOG_DEBUG:
|
||||||
|
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "DEBUG", fmt);
|
||||||
|
break;
|
||||||
|
case PRINT_LOG_INFO:
|
||||||
|
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "INFO", fmt);
|
||||||
|
break;
|
||||||
|
case PRINT_LOG_MANDATORY:
|
||||||
|
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, "%s", fmt);
|
||||||
|
break;
|
||||||
|
case PRINT_LOG_WARNING:
|
||||||
|
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "WARNING", fmt);
|
||||||
|
break;
|
||||||
|
case PRINT_LOG_ERROR:
|
||||||
|
snprintf(buf, PRINT_MESSAGE_MAX_LENGTH, typebuf, "ERROR", fmt);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* input arguments for UART logging */
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
vsnprintf(buf, PRINT_MESSAGE_MAX_LENGTH, buf, args);
|
||||||
|
va_end(args);
|
||||||
|
|
||||||
|
/* TODO: implement SD and/or UART logging */
|
||||||
|
|
||||||
|
/* don't print to screen if below log level */
|
||||||
|
if (printLogLevel < g_print_log_level) return;
|
||||||
|
|
||||||
|
printk(buf);
|
||||||
|
}
|
38
fusee/fusee-secondary/src/print.h
Normal file
38
fusee/fusee-secondary/src/print.h
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms and conditions of the GNU General Public License,
|
||||||
|
* version 2, as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||||
|
* more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FUSEE_PRINT_H
|
||||||
|
#define FUSEE_PRINT_H
|
||||||
|
|
||||||
|
#define PRINT_MESSAGE_MAX_LENGTH 512
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
PRINT_LOG_DEBUG = 0,
|
||||||
|
PRINT_LOG_INFO,
|
||||||
|
PRINT_LOG_MANDATORY,
|
||||||
|
PRINT_LOG_WARNING,
|
||||||
|
PRINT_LOG_ERROR
|
||||||
|
} PrintLogLevel;
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "../../fusee-primary/src/lib/vsprintf.h"
|
||||||
|
|
||||||
|
extern PrintLogLevel g_print_log_level;
|
||||||
|
|
||||||
|
//void vprintk(const char *fmt, va_list args);
|
||||||
|
void print(PrintLogLevel printLogLevel, const char* fmt, ...);
|
||||||
|
|
||||||
|
#endif
|
|
@ -31,6 +31,7 @@
|
||||||
#include "../pmc.h"
|
#include "../pmc.h"
|
||||||
#include "../max7762x.h"
|
#include "../max7762x.h"
|
||||||
#include "../lib/driver_utils.h"
|
#include "../lib/driver_utils.h"
|
||||||
|
#include "../print.h"
|
||||||
|
|
||||||
static SdmmcLogLevel g_sdmmc_log_level = SDMMC_LOG_NONE;
|
static SdmmcLogLevel g_sdmmc_log_level = SDMMC_LOG_NONE;
|
||||||
|
|
||||||
|
@ -46,21 +47,21 @@ static void sdmmc_print(sdmmc_t *sdmmc, SdmmcLogLevel log_level, char *fmt, va_l
|
||||||
|
|
||||||
switch (log_level) {
|
switch (log_level) {
|
||||||
case SDMMC_LOG_ERROR:
|
case SDMMC_LOG_ERROR:
|
||||||
printk("%s [ERROR]: ", sdmmc->name);
|
print(PRINT_LOG_ERROR, "%s", sdmmc->name);
|
||||||
break;
|
break;
|
||||||
case SDMMC_LOG_WARN:
|
case SDMMC_LOG_WARN:
|
||||||
printk("%s [WARN]: ", sdmmc->name);
|
print(PRINT_LOG_WARNING, "%s", sdmmc->name);
|
||||||
break;
|
break;
|
||||||
case SDMMC_LOG_INFO:
|
case SDMMC_LOG_INFO:
|
||||||
printk("%s [INFO]: ", sdmmc->name);
|
print(PRINT_LOG_INFO, "%s", sdmmc->name);
|
||||||
break;
|
break;
|
||||||
case SDMMC_LOG_DEBUG:
|
case SDMMC_LOG_DEBUG:
|
||||||
printk("%s [DEBUG]: ", sdmmc->name);
|
print(PRINT_LOG_DEBUG, "%s", sdmmc->name);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
vprintk(fmt, list);
|
vprintk(fmt, list);
|
||||||
printk("\n");
|
printk("\n");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue