diff --git a/bootloader/storage/emusd.c b/bootloader/storage/emusd.c new file mode 100644 index 00000000..89a1aa7e --- /dev/null +++ b/bootloader/storage/emusd.c @@ -0,0 +1,70 @@ +#include "emusd.h" +#include +#include +#include + +emusd_cfg_t emu_sd_cfg = {0}; + +void emusd_load_cfg() +{ + emu_sd_cfg.enabled = 0; + emu_sd_cfg.fs_ver = 0; + emu_sd_cfg.id = 0; + emu_sd_cfg.sector = 0; + if(!emu_sd_cfg.path) { + emu_sd_cfg.path = (char*)malloc(0x200); + } + if(emu_sd_cfg.emummc_file_based_path){ + emu_sd_cfg.emummc_file_based_path = (char*)malloc(0x200); + } + + LIST_INIT(ini_sections); + if(ini_parse(&ini_sections, "emuSD/emusd.ini", false)) + { + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) + { + if(ini_sec->type == INI_CHOICE) + { + if(strcmp(ini_sec->name, "emusd")){ + continue; + } + + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + if(!strcmp(kv->key, "enabled")){ + emu_sd_cfg.enabled = atoi(kv->val); + } else if(!strcmp(kv->key, "sector")){ + emu_sd_cfg.sector = strtol(kv->val, NULL, 16); + } + } + break; + } + } + } +} + +bool emusd_set_path(char *path) { + FIL fp; + bool found = false; + char sd_path[0x80]; + + // TODO: use emu_sd.file_path instead + strcpy(sd_path, path); + strcat(sd_path, "/raw_emmc_based"); + + if(!f_open(&fp, sd_path, FA_READ)) + { + if(!f_read(&fp, &emu_sd_cfg.sector, 4, NULL)){ + if(emu_sd_cfg.sector){ + found = true; + emu_sd_cfg.enabled = 4; + goto out; + } + } + } + + // TODO: file based / SD partition based support + + out: + return found; +} \ No newline at end of file diff --git a/bootloader/storage/emusd.h b/bootloader/storage/emusd.h new file mode 100644 index 00000000..f6839677 --- /dev/null +++ b/bootloader/storage/emusd.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2019-2021 CTCaer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _EMUSD_H +#define _EMUSD_H + +#include + +typedef struct _emusd_cfg_t +{ + int enabled; + u64 sector; + u32 id; + char *path; + // Internal. + int fs_ver; + char *emummc_file_based_path; + +} emusd_cfg_t; + +extern emusd_cfg_t emu_sd_cfg; + +void emusd_load_cfg(); +bool emusd_set_path(char *path); +int emusd_storage_init_mmc(); +int emusd_storage_end(); +int emusd_storage_read(u32 sector, u32 num_sectors, void *buf); +int emusd_storage_write(u32 sector, u32 num_sectors, void *buf); +sdmmc_storage_t *emusd_get_storage(); + +#endif \ No newline at end of file