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

Don't pass the mmc struct around

This commit is contained in:
TuxSH 2018-05-06 17:22:12 +02:00
parent 8c7492654c
commit 4265dc7b65
9 changed files with 18 additions and 35 deletions

View file

@ -5,6 +5,7 @@
#include "sd_utils.h"
#include "stage2.h"
#include "sdmmc.h"
#include "lib/fatfs/ff.h"
#include "lib/printk.h"
#include "display/video_fb.h"
@ -115,7 +116,6 @@ 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);
f_unmount("");
/* Jump to Stage 2. */

View file

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

View file

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

View file

@ -40,28 +40,28 @@ static int stage2_ini_handler(void *user, const char *section, const char *name,
stage2_entrypoint_t load_stage2(const char *bct0) {
stage2_config_t config = {0};
if (ini_parse_string(bct0, stage2_ini_handler, &config) < 0) {
printk("Error: Failed to parse BCT.ini!\n");
generic_panic();
}
if (config.load_address == 0 || config.path[0] == '\x00') {
printk("Error: Failed to determine where to load stage2!\n");
generic_panic();
}
printk("[DEBUG] Stage 2 Config:\n");
printk(" File Path: %s\n", config.path);
printk(" Load Address: 0x%08x\n", config.load_address);
printk(" Entrypoint: 0x%p\n", config.entrypoint);
if (!read_sd_file((void *)config.load_address, 0x100000, config.path)) {
printk("Error: Failed to read stage2 (%s)!\n", config.path);
generic_panic();
}
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path));
return config.entrypoint;
}

View file

@ -26,7 +26,6 @@ typedef struct {
uint32_t *lfb;
uint32_t console_row;
uint32_t console_col;
void *sd_mmc;
} stage2_args_t;
const char *stage2_get_program_path(void);

View file

@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include "utils.h"
#include "hwinit.h"
#include "loader.h"
@ -34,8 +36,10 @@ int main(int argc, void **argv) {
/* Setup console/stdout. */
console_resume(args.lfb, args.console_row, args.console_col);
resume_sd_state((struct mmc *)args.sd_mmc);
fsdev_mount_all();
initialize_sd();
if(fsdev_mount_all() == -1) {
perror("Failed to mount at least one FAT parition");
}
fsdev_set_default_device("sdmc");
/* Copy the BCT0 from unsafe primary memory into our memory. */

View file

@ -7,14 +7,6 @@
struct mmc sd_mmc;
static int initialized_sd = 0;
void save_sd_state(void **mmc) {
*mmc = &sd_mmc;
}
void resume_sd_state(void *mmc) {
sd_mmc = *(struct mmc *)mmc;
initialized_sd = 1;
}
int initialize_sd(void) {
if (initialized_sd) {
return 1;
@ -23,6 +15,9 @@ int initialize_sd(void) {
if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) {
printf("Initialized SD card!\n");
initialized_sd = 1;
} else {
printf("Failed to initialize the SD card!\n");
return 0;
}
return initialized_sd;
}

View file

@ -4,9 +4,7 @@
#include "utils.h"
#include "sdmmc.h"
void save_sd_state(void **mmc);
void resume_sd_state(void *mmc);
int initialize_sd(void);
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);
#endif

View file

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