1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-28 21:26:14 +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

@ -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,7 +27,6 @@ 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);

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,7 +6,7 @@
#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);

View file

@ -1,6 +1,8 @@
#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];

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