1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-05 19:51:45 +00:00

Instead of passing FatFS structs around, unmount; other changes

This commit is contained in:
TuxSH 2018-05-05 17:33:49 +02:00
parent 0fca6c2296
commit 67b76cc8f1
12 changed files with 54 additions and 76 deletions

View file

@ -92,7 +92,7 @@ int main(void) {
printk("Please do not seek support for it until it is done.\n");
generic_panic();
#endif
/* Try to load the SBK into the security engine, if possible. */
/* TODO: Should this be done later? */
load_sbk();
@ -115,11 +115,10 @@ int main(void) {
args->lfb = (uint32_t *)lfb_base;
args->console_col = video_get_col();
args->console_row = video_get_row();
save_sd_state(&args->sd_mmc, &args->sd_fs);
save_sd_state(&args->sd_mmc);
f_unmount("");
/* Jump to Stage 2. */
stage2_entrypoint(STAGE2_ARGC, stage2_argv);
return 0;
}

View file

@ -10,15 +10,13 @@ FATFS sd_fs;
static int initialized_sd = 0;
static int mounted_sd = 0;
void save_sd_state(void **mmc, void **ff) {
void save_sd_state(void **mmc) {
*mmc = &sd_mmc;
*ff = &ff;
}
void resume_sd_state(void *mmc, void *ff) {
void resume_sd_state(void *mmc) {
sd_mmc = *(struct mmc *)mmc;
sd_fs = *(FATFS *)ff;
initialized_sd = 1;
mounted_sd = 1;
}
int initialize_sd(void) {

View file

@ -5,8 +5,8 @@
#include "sdmmc.h"
#include "lib/fatfs/ff.h"
void save_sd_state(void **mmc, void **ff);
void resume_sd_state(void *mmc, void *ff);
void save_sd_state(void **mmc);
void resume_sd_state(void *mmc);
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);

View file

@ -27,10 +27,9 @@ typedef struct {
uint32_t console_row;
uint32_t console_col;
void *sd_mmc;
void *sd_fs;
} stage2_args_t;
const char *stage2_get_program_path(void);
stage2_entrypoint_t load_stage2(const char *bct0);
#endif
#endif

View file

@ -19,7 +19,7 @@ static int loadlist_entry_ini_handler(void *user, const char *section, const cha
load_file_t *load_file_ctx = (load_file_t *)user;
uintptr_t x = 0;
const char *ext = NULL;
if (strcmp(section, "stage2") == 0) {
if (strstr(name, load_file_ctx->key) == name) {
ext = name + strlen(load_file_ctx->key);
@ -51,33 +51,33 @@ bool validate_load_address(uintptr_t load_addr) {
void load_list_entry(const char *key) {
load_file_t load_file_ctx = {0};
load_file_ctx.key = key;
printk("Loading %s\n", key);
if (ini_parse_string(get_loader_ctx()->bct0, loadlist_entry_ini_handler, &load_file_ctx) < 0) {
printk("Error: Failed to parse BCT.ini!\n");
generic_panic();
}
if (load_file_ctx.load_address == 0 || load_file_ctx.path[0] == '\x00') {
printk("Error: Failed to determine where to load %s!\n", key);
generic_panic();
}
printk("Loading %s from %s to 0x%08x\n", key, load_file_ctx.path, load_file_ctx.load_address);
if (!validate_load_address(load_file_ctx.load_address)) {
printk("Error: Load address 0x%08x is invalid!\n");
generic_panic();
}
/* Read file off of SD. */
load_file_ctx.load_size = read_sd_file((void *)load_file_ctx.load_address, LOADER_FILESIZE_MAX, load_file_ctx.path);
if (load_file_ctx.load_size == 0) {
printk("Error: Failed to read %s!\n", load_file_ctx.path);
generic_panic();
}
/* Check for special keys. */
if (strcmp(key, LOADER_PACKAGE2_KEY) == 0) {
get_loader_ctx()->package2_loadfile = load_file_ctx;
@ -92,26 +92,26 @@ void load_list_entry(const char *key) {
void parse_loadlist(const char *ll) {
printk("Parsing load list: %s\n", ll);
char load_list[0x200] = {0};
strncpy(load_list, ll, 0x200);
char *entry, *p;
/* entry will point to the start of the current entry. p will point to the current location in the list. */
entry = load_list;
p = load_list;
while (*p) {
if (*p == ' ' || *p == '\t') {
/* We're at the end of an entry. */
*p = '\x00';
/* Load the entry. */
load_list_entry(entry);
/* Skip to the next delimiter. */
for (; *p == ' ' || *p == '\t' || *p == '\x00'; p++) { }
if (*p != '|') {
if (*p != '|') {
printk("Error: Load list is malformed!\n");
generic_panic();
} else {
@ -132,7 +132,7 @@ void parse_loadlist(const char *ll) {
static int loadlist_ini_handler(void *user, const char *section, const char *name, const char *value) {
loader_ctx_t *loader_ctx = (loader_ctx_t *)user;
uintptr_t x = 0;
if (strcmp(section, "stage2") == 0) {
if (strcmp(name, LOADER_LOADLIST_KEY) == 0) {
parse_loadlist(value);
@ -153,12 +153,12 @@ static int loadlist_ini_handler(void *user, const char *section, const char *nam
void load_payload(const char *bct0) {
loader_ctx_t *ctx = get_loader_ctx();
/* Set BCT0 global. */
ctx->bct0 = bct0;
if (ini_parse_string(ctx->bct0, loadlist_ini_handler, ctx) < 0) {
printk("Error: Failed to parse BCT.ini!\n");
generic_panic();
}
}
}

View file

@ -6,6 +6,7 @@
#include "sd_utils.h"
#include "lib/printk.h"
#include "display/video_fb.h"
#include "fs_dev.h"
/* TODO: Add a #define for this size, somewhere. Also, primary can only actually load 0x7000. */
char g_bct0[0x8000];
@ -30,7 +31,9 @@ int main(int argc, void **argv) {
generic_panic();
}
resume_sd_state((struct mmc *)args.sd_mmc, (FATFS *)args.sd_fs);
resume_sd_state((struct mmc *)args.sd_mmc);
fsdev_mount_all();
fsdev_set_default_device("sdmc");
/* Copy the BCT0 from unsafe primary memory into our memory. */
strncpy(g_bct0, args.bct0, sizeof(g_bct0));
@ -48,6 +51,9 @@ int main(int argc, void **argv) {
printk("Loaded payloads!\n");
/* Unmount everything (this causes all open files to be flushed and closed) */
fsdev_unmount_all();
if (loader_ctx->chainload_entrypoint != NULL) {
/* TODO: What do we want to do in terms of argc/argv? */
loader_ctx->chainload_entrypoint(0, NULL);

View file

@ -1,3 +1,4 @@
#include <stdio.h>
#include "sd_utils.h"
#include "hwinit.h"
#include "sdmmc.h"
@ -6,19 +7,14 @@
/* This is used by diskio.h. */
struct mmc sd_mmc;
FATFS sd_fs;
static int initialized_sd = 0;
static int mounted_sd = 0;
void save_sd_state(void **mmc, void **ff) {
void save_sd_state(void **mmc) {
*mmc = &sd_mmc;
*ff = &ff;
}
void resume_sd_state(void *mmc, void *ff) {
void resume_sd_state(void *mmc) {
sd_mmc = *(struct mmc *)mmc;
sd_fs = *(FATFS *)ff;
initialized_sd = 1;
mounted_sd = 1;
}
int initialize_sd(void) {
@ -33,33 +29,13 @@ int initialize_sd(void) {
return initialized_sd;
}
int mount_sd(void) {
if (mounted_sd) {
return 1;
}
if (f_mount(&sd_fs, "", 1) == FR_OK) {
printk("Mounted SD card!\n");
mounted_sd = 1;
}
return mounted_sd;
}
size_t read_sd_file(void *dst, size_t dst_size, const char *filename) {
if (!initialized_sd && initialize_sd() == 0) {
FILE *file = fopen(filename, "rb");
if (file == NULL) {
return 0;
} else {
size_t sz = fread(dst, 1, dst_size, file);
fclose(file);
return sz;
}
if (!mounted_sd && mount_sd() == 0) {
return 0;
}
FIL f;
if (f_open(&f, filename, FA_READ) != FR_OK) {
return 0;
}
UINT br;
int res = f_read(&f, dst, dst_size, &br);
f_close(&f);
return res == FR_OK ? (int)br : 0;
}

View file

@ -3,10 +3,9 @@
#include "utils.h"
#include "sdmmc.h"
#include "lib/fatfs/ff.h"
void save_sd_state(void **mmc, void **ff);
void resume_sd_state(void *mmc, void *ff);
void save_sd_state(void **mmc);
void resume_sd_state(void *mmc);
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);

View file

@ -6,16 +6,16 @@
#include "display/video_fb.h"
void display_splash_screen_bmp(const char *custom_splash_path) {
unsigned char *splash_screen = g_default_splash_screen;
uint8_t *splash_screen = g_default_splash_screen;
if (custom_splash_path != NULL && custom_splash_path[0] != '\x00') {
if (!read_sd_file(splash_screen, sizeof(g_default_splash_screen), custom_splash_path)) {
printk("Error: Failed to read custom splash screen from %s!\n", custom_splash_path);
generic_panic();
}
}
/* TODO: Display the splash screen. It should be a pointer to a BMP, at this point. */
/* Display the splash screen for three seconds. */
wait(3000000);
}
}

View file

@ -1,9 +1,11 @@
#ifndef FUSEE_SPLASH_SCREEN_H
#define FUSEE_SPLASH_SCREEN_H
#include <stdint.h>
/* TODO: Actually make this a real thing. */
extern unsigned char g_default_splash_screen[1];
void display_splash_screen_bmp(const char *custom_splash_path);
#endif
#endif

View file

@ -1,3 +1,3 @@
#include "splash_screen.h"
unsigned char g_default_splash_screen[1] = {0};
uint8_t g_default_splash_screen[1] = {0};

View file

@ -15,7 +15,6 @@ typedef struct {
uint32_t console_row;
uint32_t console_col;
void *sd_mmc;
void *sd_fs;
} stage2_args_t;
#endif
#endif