mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
Don't pass the mmc struct around
This commit is contained in:
parent
8c7492654c
commit
4265dc7b65
9 changed files with 18 additions and 35 deletions
|
@ -5,6 +5,7 @@
|
||||||
#include "sd_utils.h"
|
#include "sd_utils.h"
|
||||||
#include "stage2.h"
|
#include "stage2.h"
|
||||||
#include "sdmmc.h"
|
#include "sdmmc.h"
|
||||||
|
#include "lib/fatfs/ff.h"
|
||||||
#include "lib/printk.h"
|
#include "lib/printk.h"
|
||||||
#include "display/video_fb.h"
|
#include "display/video_fb.h"
|
||||||
|
|
||||||
|
@ -115,7 +116,6 @@ int main(void) {
|
||||||
args->lfb = (uint32_t *)lfb_base;
|
args->lfb = (uint32_t *)lfb_base;
|
||||||
args->console_col = video_get_col();
|
args->console_col = video_get_col();
|
||||||
args->console_row = video_get_row();
|
args->console_row = video_get_row();
|
||||||
save_sd_state(&args->sd_mmc);
|
|
||||||
f_unmount("");
|
f_unmount("");
|
||||||
|
|
||||||
/* Jump to Stage 2. */
|
/* Jump to Stage 2. */
|
||||||
|
|
|
@ -10,15 +10,6 @@ FATFS sd_fs;
|
||||||
static int initialized_sd = 0;
|
static int initialized_sd = 0;
|
||||||
static int mounted_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) {
|
int initialize_sd(void) {
|
||||||
if (initialized_sd) {
|
if (initialized_sd) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -3,11 +3,8 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "sdmmc.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);
|
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -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_entrypoint_t load_stage2(const char *bct0) {
|
||||||
stage2_config_t config = {0};
|
stage2_config_t config = {0};
|
||||||
|
|
||||||
if (ini_parse_string(bct0, stage2_ini_handler, &config) < 0) {
|
if (ini_parse_string(bct0, stage2_ini_handler, &config) < 0) {
|
||||||
printk("Error: Failed to parse BCT.ini!\n");
|
printk("Error: Failed to parse BCT.ini!\n");
|
||||||
generic_panic();
|
generic_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.load_address == 0 || config.path[0] == '\x00') {
|
if (config.load_address == 0 || config.path[0] == '\x00') {
|
||||||
printk("Error: Failed to determine where to load stage2!\n");
|
printk("Error: Failed to determine where to load stage2!\n");
|
||||||
generic_panic();
|
generic_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("[DEBUG] Stage 2 Config:\n");
|
printk("[DEBUG] Stage 2 Config:\n");
|
||||||
printk(" File Path: %s\n", config.path);
|
printk(" File Path: %s\n", config.path);
|
||||||
printk(" Load Address: 0x%08x\n", config.load_address);
|
printk(" Load Address: 0x%08x\n", config.load_address);
|
||||||
printk(" Entrypoint: 0x%p\n", config.entrypoint);
|
printk(" Entrypoint: 0x%p\n", config.entrypoint);
|
||||||
|
|
||||||
if (!read_sd_file((void *)config.load_address, 0x100000, config.path)) {
|
if (!read_sd_file((void *)config.load_address, 0x100000, config.path)) {
|
||||||
printk("Error: Failed to read stage2 (%s)!\n", config.path);
|
printk("Error: Failed to read stage2 (%s)!\n", config.path);
|
||||||
generic_panic();
|
generic_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path));
|
strncpy(g_stage2_path, config.path, sizeof(g_stage2_path));
|
||||||
|
|
||||||
return config.entrypoint;
|
return config.entrypoint;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ typedef struct {
|
||||||
uint32_t *lfb;
|
uint32_t *lfb;
|
||||||
uint32_t console_row;
|
uint32_t console_row;
|
||||||
uint32_t console_col;
|
uint32_t console_col;
|
||||||
void *sd_mmc;
|
|
||||||
} stage2_args_t;
|
} stage2_args_t;
|
||||||
|
|
||||||
const char *stage2_get_program_path(void);
|
const char *stage2_get_program_path(void);
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <errno.h>
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "hwinit.h"
|
#include "hwinit.h"
|
||||||
#include "loader.h"
|
#include "loader.h"
|
||||||
|
@ -34,8 +36,10 @@ int main(int argc, void **argv) {
|
||||||
/* Setup console/stdout. */
|
/* Setup console/stdout. */
|
||||||
console_resume(args.lfb, args.console_row, args.console_col);
|
console_resume(args.lfb, args.console_row, args.console_col);
|
||||||
|
|
||||||
resume_sd_state((struct mmc *)args.sd_mmc);
|
initialize_sd();
|
||||||
fsdev_mount_all();
|
if(fsdev_mount_all() == -1) {
|
||||||
|
perror("Failed to mount at least one FAT parition");
|
||||||
|
}
|
||||||
fsdev_set_default_device("sdmc");
|
fsdev_set_default_device("sdmc");
|
||||||
|
|
||||||
/* Copy the BCT0 from unsafe primary memory into our memory. */
|
/* Copy the BCT0 from unsafe primary memory into our memory. */
|
||||||
|
|
|
@ -7,14 +7,6 @@
|
||||||
struct mmc sd_mmc;
|
struct mmc sd_mmc;
|
||||||
static int initialized_sd = 0;
|
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) {
|
int initialize_sd(void) {
|
||||||
if (initialized_sd) {
|
if (initialized_sd) {
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -23,6 +15,9 @@ int initialize_sd(void) {
|
||||||
if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) {
|
if (sdmmc_init(&sd_mmc, SWITCH_MICROSD) == 0) {
|
||||||
printf("Initialized SD card!\n");
|
printf("Initialized SD card!\n");
|
||||||
initialized_sd = 1;
|
initialized_sd = 1;
|
||||||
|
} else {
|
||||||
|
printf("Failed to initialize the SD card!\n");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return initialized_sd;
|
return initialized_sd;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,7 @@
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "sdmmc.h"
|
#include "sdmmc.h"
|
||||||
|
|
||||||
void save_sd_state(void **mmc);
|
int initialize_sd(void);
|
||||||
void resume_sd_state(void *mmc);
|
|
||||||
|
|
||||||
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);
|
size_t read_sd_file(void *dst, size_t dst_size, const char *filename);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,7 +14,6 @@ typedef struct {
|
||||||
uint32_t *lfb;
|
uint32_t *lfb;
|
||||||
uint32_t console_row;
|
uint32_t console_row;
|
||||||
uint32_t console_col;
|
uint32_t console_col;
|
||||||
void *sd_mmc;
|
|
||||||
} stage2_args_t;
|
} stage2_args_t;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue