Skip to content

Commit

Permalink
Added support to load the arm9bootloader file from the arm9loaderhaxf…
Browse files Browse the repository at this point in the history
…older

Added the BOOTCTR9 section for configurations like logging and key time
Added the extended splash screen, which shows the loaded payload
changed the ascii splash to show bootctr9
Some minor fixes
  • Loading branch information
Hartie95 committed Mar 8, 2016
1 parent 8153641 commit e02cd92
Show file tree
Hide file tree
Showing 12 changed files with 306 additions and 122 deletions.
27 changes: 16 additions & 11 deletions bootloader/bootloaderloader/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,29 @@
#include "fatfs/ff.h"

#define BOOTLOADER_PAYLOAD_ADDRESS 0x24F00000
#define BOOTLOADER_PAYLOAD_SIZE 0x00100000
#define PAYLOAD_SIZE 0x00100000

FATFS fs;

int main()
void loadAndRunPayload(const char* payloadName, u32 payloadAddress)
{
FATFS fs;
FIL payload;
u32 br;

if(f_open(&payload, payloadName, FA_READ | FA_OPEN_EXISTING) == FR_OK)
{
f_read(&payload, (void*)payloadAddress, PAYLOAD_SIZE, (UINT*)&br);
f_close(&payload);
f_mount(&fs, "0:", 1);
((void (*)())payloadAddress)();
}
}

int main()
{
if(f_mount(&fs, "0:", 1) == FR_OK)
{
if(f_open(&payload, "arm9bootloader.bin", FA_READ | FA_OPEN_EXISTING) == FR_OK)
{
f_read(&payload, BOOTLOADER_PAYLOAD_ADDRESS, BOOTLOADER_PAYLOAD_SIZE, &br);
f_close(&payload);
f_mount(&fs, "0:", 1);
((void (*)())BOOTLOADER_PAYLOAD_ADDRESS)();
}
loadAndRunPayload("arm9loaderhax/arm9bootloader.bin", BOOTLOADER_PAYLOAD_ADDRESS);
loadAndRunPayload("arm9bootloader.bin", BOOTLOADER_PAYLOAD_ADDRESS);
}

i2cWriteRegister(I2C_DEV_MCU, 0x20, (u8)(1<<0));
Expand Down
16 changes: 14 additions & 2 deletions bootloader/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@
typedef struct {
char* section;
char path[64];
unsigned long long delay;
unsigned long long splashDelay;
unsigned long payload;
unsigned long offset;
int splash;
char splash_image[64];
char splash_image[64];
unsigned int screenEnabled;
} configuration;

typedef struct {
char* section;
unsigned long long keyDelay;
int bootsplash;
char bootsplash_image[64];
bool fileLog;
bool screenLog;
unsigned int screenEnabled;
} loaderConfiguration;


#define MATCH(s, n) strcmp(section, s) == 0 && strcmp(name, n) == 0
int handler(void *user, const char *section, const char *name, const char *value);
int handlerLoaderConfiguration(void *user, const char *section, const char *name, const char *value);
1 change: 1 addition & 0 deletions bootloader/include/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
#define KEY_Y (1 << 11)


u32 WaitTimeForInput(u32 waittime);
u32 InputWait();
u32 GetInput();
3 changes: 2 additions & 1 deletion bootloader/include/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
#include "common.h"


int initLog();
int initLog(bool _fileLoggingEnabled, bool _screenLoggingEnabled);
void openLogFile();
void closeLogFile();
void debug(const char *format, ...);
void panic(const char *format, ...);
Expand Down
20 changes: 16 additions & 4 deletions bootloader/include/splash.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
#pragma once

#include "common.h"
#include "config.h"

#define ASCII_ART_TEMPLATE (" _ __\n" \
"|_) _ _ _|_/ _|_ __\n" \
"|_)(_)(_) |_\\__ |_ |\n" \

#define ASCII_ART_TEMPLATE (" _ __ _\n" \
"|_) _ _ _|_/ _|_ __(_)\n" \
"|_)(_)(_) |_\\__ |_ | /\n" \
"%s\n" \
"\n" \
"is loading...")

#define ASCII_ART_TEMPLATE_EXTENDET (" _ __ _\n" \
"|_) _ _ _|_/ _|_ __(_)\n" \
"|_)(_)(_) |_\\__ |_ | /\n" \
"%s\n" \
"\n" \
"Payload: %s")

bool drawBootSplash(loaderConfiguration* loaderConfig);
bool drawSplash(configuration* app);
int splash_ascii(void);
int splash_ascii_extendet(const char* payloadName);
int splash_image(char *splash_path);
int splash_image_extendet(char *splash_path,const char* payloadName);
37 changes: 28 additions & 9 deletions bootloader/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ int numberToInt(const char* value)

int handler(void *user, const char *section, const char *name, const char *value)
{
configuration *pconfig = (configuration *) user;
if (MATCH(pconfig->section, "path")) {
strcpy (pconfig->path,value);
} else if (MATCH(pconfig->section, "delay")) {
pconfig->delay = myAtoi(value);
} else if (MATCH(pconfig->section, "payload")) {
pconfig->payload = myAtoi(value);
} else if (MATCH(pconfig->section, "offset")) {
configuration *pconfig = (configuration *) user;
if (MATCH(pconfig->section, "path")) {
strcpy (pconfig->path,value);
} else if (MATCH(pconfig->section, "delay")) {
pconfig->splashDelay = myAtoi(value);
} else if (MATCH(pconfig->section, "payload")) {
pconfig->payload = myAtoi(value);
} else if (MATCH(pconfig->section, "offset")) {
pconfig->offset = numberToInt(value);
} else if (MATCH(pconfig->section, "splash")) {
pconfig->splash = myAtoi(value);
Expand All @@ -112,5 +112,24 @@ int handler(void *user, const char *section, const char *name, const char *value
} else if (MATCH(pconfig->section, "screenEnabled")) {
pconfig->screenEnabled = myAtoi(value);
}
return 1;
return 1;
}

int handlerLoaderConfiguration(void *user, const char *section, const char *name, const char *value)
{
loaderConfiguration *pconfig = (configuration *) user;
if (MATCH(pconfig->section, "key_delay")) {
pconfig->keyDelay = myAtoi(value);
}else if (MATCH(pconfig->section, "boot_splash")) {
pconfig->bootsplash = myAtoi(value);
} else if (MATCH(pconfig->section, "boot_splash_image")) {
strcpy (pconfig->bootsplash_image,value);
} else if (MATCH(pconfig->section, "fileLog")) {
pconfig->fileLog = myAtoi(value);
} else if (MATCH(pconfig->section, "screenLog")) {
pconfig->screenLog = myAtoi(value);
} else if (MATCH(pconfig->section, "screenEnabled")) {
pconfig->screenEnabled = myAtoi(value);
}
return 1;
}
10 changes: 10 additions & 0 deletions bootloader/source/hid.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#include "hid.h"


u32 WaitTimeForInput(u32 waittime) {
for(volatile u64 i=0;i<0xEFF*waittime;i++)
{
u32 pad_state = (~HID_STATE)&0xFFF;
if (pad_state!=0)
return pad_state;
}
return 0;
}
u32 InputWait() {
u32 pad_state_old = HID_STATE;
while (true) {
Expand Down
66 changes: 42 additions & 24 deletions bootloader/source/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,55 @@
#define LOGNAME_BACKUP "/arm9bootloader.log"

static FIL logFile;
bool logFileOpened=false;
bool fileLoggingEnabled = false;
bool screenLoggingEnabled = false;

int initLog()
int initLog(bool _fileLoggingEnabled, bool _screenLoggingEnabled)
{
screenLoggingEnabled = _screenLoggingEnabled;
if(_fileLoggingEnabled)
openLogFile();

return 0;
}

void openLogFile()
{
if (f_open(&logFile, LOGNAME, FA_READ | FA_WRITE | FA_CREATE_ALWAYS ) != FR_OK)
{
if (f_open(&logFile, LOGNAME_BACKUP, FA_READ | FA_WRITE | FA_CREATE_ALWAYS ) != FR_OK)
shutdown();
}
logFileOpened=true;
f_sync (&logFile);
return;
}
f_puts ("opened logfile\n", &logFile);
f_sync (&logFile);

return 0;
fileLoggingEnabled=true;
}


void closeLogFile()
{
if(logFileOpened==true)
if(fileLoggingEnabled==true)
{
f_close(&logFile);
logFileOpened=false;
fileLoggingEnabled=false;
}
}

void logToFile(char *msg)
{
if(fileLoggingEnabled)
{
f_puts (msg, &logFile);
f_putc ('\n', &logFile);
f_sync (&logFile);
}
}

void logToScreen(char *msg)
{
if(screenLoggingEnabled)
{
drawDebug(msg);
}
}

Expand All @@ -48,31 +74,23 @@ void debug(const char *format, ...)
vsnprintf(str, 256, format, va);
va_end(va);

if(logFileOpened)
{
f_puts (str, &logFile);
f_putc ('\n', &logFile);
f_sync (&logFile);
}
drawDebug(str);
logToFile(str);
logToScreen(str);
}

void panic(const char *format, ...)
{
char str[256];
va_list va;
screenLoggingEnabled=true;

va_start(va, format);
vsnprintf(str, 256, format, va);
va_end(va);

if(logFileOpened)
{
debug("ERROR:");
debug(str);
}
drawDebug(str);
drawDebug("Press any key to shutdown");

debug("ERROR: %s",str);
logToScreen("Press any key to shutdown");
InputWait();
shutdown();
}
Expand Down
Loading

0 comments on commit e02cd92

Please sign in to comment.