file based emmc emummc, some other stuff
This commit is contained in:
2
Makefile
2
Makefile
@@ -35,7 +35,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
|
||||
mc.o sdram.o minerva.o \
|
||||
gpio.o pinmux.o pmc.o se.o smmu.o tsec.o uart.o \
|
||||
fuse.o kfuse.o \
|
||||
sdmmc.o sdmmc_driver.o emmc.o sd.o emummc.o \
|
||||
sdmmc.o sdmmc_driver.o emmc.o sd.o emummc.o emummc_file_based.o \
|
||||
bq24193.o max17050.o max7762x.o max77620-rtc.o \
|
||||
hw_init.o boot_storage.o \
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include <storage/mbr_gpt.h>
|
||||
#include <gfx_utils.h>
|
||||
#include <utils/list.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
|
||||
static u16 emmc_errors[3] = { 0 }; // Init and Read/Write errors.
|
||||
static u32 emmc_mode = EMMC_MMC_HS400;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "emummc.h"
|
||||
#include "emummc_file_based.h"
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <libs/fatfs/ff.h>
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef EMUMMC_H
|
||||
#define EMUMMC_H
|
||||
#ifndef _EMUMMC_FILE_BASED_H
|
||||
#define _EMUMMC_FILE_BASED_H
|
||||
|
||||
#include <bdk.h>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <storage/emummc.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
#include <utils/types.h>
|
||||
|
||||
#define BIS_CLUSTER_SECTORS 32
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
*/
|
||||
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/emummc.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <usb/usbd.h>
|
||||
|
||||
@@ -786,6 +786,7 @@ int hos_launch(ini_sec_t *cfg)
|
||||
}
|
||||
|
||||
// Check if SD Card is GPT.
|
||||
// TODO: not relevant with emuSD
|
||||
if (sd_is_gpt())
|
||||
{
|
||||
_hos_crit_error("SD has GPT only!");
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -24,6 +25,7 @@
|
||||
#include "emummc.h"
|
||||
#include "../config.h"
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
|
||||
extern hekate_config h_cfg;
|
||||
emummc_cfg_t emu_cfg = { 0 };
|
||||
@@ -123,6 +125,20 @@ bool emummc_set_path(char *path)
|
||||
goto out;
|
||||
}
|
||||
|
||||
// strcpy(emu_cfg.emummc_file_based_path, "sd:");
|
||||
strcpy(emu_cfg.emummc_file_based_path, "");
|
||||
strcat(emu_cfg.emummc_file_based_path, path);
|
||||
strcat(emu_cfg.emummc_file_based_path, "/file_emmc_based");
|
||||
if (!f_stat(emu_cfg.emummc_file_based_path, NULL))
|
||||
{
|
||||
emu_cfg.sector = 0;
|
||||
emu_cfg.path = path;
|
||||
emu_cfg.enabled = 4;
|
||||
|
||||
found = true;
|
||||
goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
|
||||
if (found)
|
||||
@@ -157,7 +173,7 @@ static int emummc_raw_get_part_off(int part_idx)
|
||||
|
||||
int emummc_storage_init_mmc()
|
||||
{
|
||||
FILINFO fno;
|
||||
// FILINFO fno;
|
||||
emu_cfg.active_part = 0;
|
||||
|
||||
// Always init eMMC even when in emuMMC. eMMC is needed from the emuMMC driver anyway.
|
||||
@@ -167,43 +183,59 @@ int emummc_storage_init_mmc()
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
return 0;
|
||||
|
||||
if (emu_cfg.enabled == 1 && !sd_mount())
|
||||
goto out;
|
||||
bool file_based = false;
|
||||
|
||||
if (!emu_cfg.sector)
|
||||
{
|
||||
strcpy(emu_cfg.emummc_file_based_path, "sd:");
|
||||
strcat(emu_cfg.emummc_file_based_path, emu_cfg.path);
|
||||
strcat(emu_cfg.emummc_file_based_path, "/eMMC");
|
||||
|
||||
if (f_stat(emu_cfg.emummc_file_based_path, &fno))
|
||||
{
|
||||
EPRINTF("Failed to open eMMC folder.");
|
||||
goto out;
|
||||
if(emu_cfg.enabled == 4){
|
||||
// emmc based
|
||||
if(!emu_cfg.sector){
|
||||
// file based
|
||||
if(!emmc_mount()){
|
||||
return 1;
|
||||
}
|
||||
strcpy(emu_cfg.emummc_file_based_path, "emmc:");
|
||||
strcat(emu_cfg.emummc_file_based_path, emu_cfg.path);
|
||||
strcat(emu_cfg.emummc_file_based_path, "/eMMC");
|
||||
file_based = true;
|
||||
}else{
|
||||
// raw based
|
||||
// emmc already initialized
|
||||
}
|
||||
f_chmod(emu_cfg.emummc_file_based_path, AM_ARC, AM_ARC);
|
||||
|
||||
strcat(emu_cfg.emummc_file_based_path, "/00");
|
||||
if (f_stat(emu_cfg.emummc_file_based_path, &fno))
|
||||
{
|
||||
EPRINTF("Failed to open emuMMC rawnand.");
|
||||
goto out;
|
||||
}else{
|
||||
// sd based
|
||||
if(!emu_cfg.sector){
|
||||
// file based
|
||||
if(!sd_mount()){
|
||||
return 1;
|
||||
}
|
||||
strcpy(emu_cfg.emummc_file_based_path, "sd:");
|
||||
strcat(emu_cfg.emummc_file_based_path, emu_cfg.path);
|
||||
strcat(emu_cfg.emummc_file_based_path, "/eMMC");
|
||||
file_based = true;
|
||||
}else{
|
||||
// raw based
|
||||
if(!sd_initialize(false)){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
emu_cfg.file_based_part_size = fno.fsize >> 9;
|
||||
}
|
||||
|
||||
if(file_based){
|
||||
return emummc_storage_file_based_init(emu_cfg.emummc_file_based_path) == 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
out:
|
||||
return 1;
|
||||
}
|
||||
|
||||
int emummc_storage_end()
|
||||
{
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable || emu_cfg.enabled == 4)
|
||||
if(!h_cfg.emummc_force_disable && emu_cfg.enabled && !emu_cfg.sector){
|
||||
emummc_storage_file_based_end();
|
||||
}
|
||||
if(!emu_cfg.enabled || h_cfg.emummc_force_disable || emu_cfg.enabled == 4){
|
||||
emmc_end();
|
||||
else
|
||||
}else{
|
||||
sd_end();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -211,7 +243,7 @@ int emummc_storage_end()
|
||||
int emummc_storage_read(u32 sector, u32 num_sectors, void *buf)
|
||||
{
|
||||
sdmmc_storage_t *storage = emu_cfg.enabled == 4 ? &emmc_storage : &sd_storage;
|
||||
FIL fp;
|
||||
// FIL fp;
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
return sdmmc_storage_read(&emmc_storage, sector, num_sectors, buf);
|
||||
else if (emu_cfg.sector)
|
||||
@@ -222,33 +254,34 @@ int emummc_storage_read(u32 sector, u32 num_sectors, void *buf)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!emu_cfg.active_part)
|
||||
{
|
||||
u32 file_part = sector / emu_cfg.file_based_part_size;
|
||||
sector = sector % emu_cfg.file_based_part_size;
|
||||
if (file_part >= 10)
|
||||
itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
|
||||
else
|
||||
{
|
||||
emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
|
||||
itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 1, 10);
|
||||
}
|
||||
}
|
||||
if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_READ))
|
||||
{
|
||||
EPRINTF("Failed to open emuMMC image.");
|
||||
return 0;
|
||||
}
|
||||
f_lseek(&fp, (u64)sector << 9);
|
||||
if (f_read(&fp, buf, (u64)num_sectors << 9, NULL))
|
||||
{
|
||||
EPRINTF("Failed to read emuMMC image.");
|
||||
f_close(&fp);
|
||||
return 0;
|
||||
}
|
||||
return emummc_storage_file_based_read(sector, num_sectors, buf);
|
||||
// if (!emu_cfg.active_part)
|
||||
// {
|
||||
// u32 file_part = sector / emu_cfg.file_based_part_size;
|
||||
// sector = sector % emu_cfg.file_based_part_size;
|
||||
// if (file_part >= 10)
|
||||
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
|
||||
// else
|
||||
// {
|
||||
// emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
|
||||
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 1, 10);
|
||||
// }
|
||||
// }
|
||||
// if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_READ))
|
||||
// {
|
||||
// EPRINTF("Failed to open emuMMC image.");
|
||||
// return 0;
|
||||
// }
|
||||
// f_lseek(&fp, (u64)sector << 9);
|
||||
// if (f_read(&fp, buf, (u64)num_sectors << 9, NULL))
|
||||
// {
|
||||
// EPRINTF("Failed to read emuMMC image.");
|
||||
// f_close(&fp);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
f_close(&fp);
|
||||
return 1;
|
||||
// f_close(&fp);
|
||||
// return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
@@ -257,7 +290,7 @@ int emummc_storage_read(u32 sector, u32 num_sectors, void *buf)
|
||||
int emummc_storage_write(u32 sector, u32 num_sectors, void *buf)
|
||||
{
|
||||
sdmmc_storage_t *storage = emu_cfg.enabled == 4 ? &emmc_storage : &sd_storage;
|
||||
FIL fp;
|
||||
// FIL fp;
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable)
|
||||
return sdmmc_storage_write(&emmc_storage, sector, num_sectors, buf);
|
||||
else if (emu_cfg.sector)
|
||||
@@ -268,31 +301,32 @@ int emummc_storage_write(u32 sector, u32 num_sectors, void *buf)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!emu_cfg.active_part)
|
||||
{
|
||||
u32 file_part = sector / emu_cfg.file_based_part_size;
|
||||
sector = sector % emu_cfg.file_based_part_size;
|
||||
if (file_part >= 10)
|
||||
itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
|
||||
else
|
||||
{
|
||||
emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
|
||||
itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 1, 10);
|
||||
}
|
||||
}
|
||||
return emummc_storage_file_based_write(sector, num_sectors, buf);
|
||||
// if (!emu_cfg.active_part)
|
||||
// {
|
||||
// u32 file_part = sector / emu_cfg.file_based_part_size;
|
||||
// sector = sector % emu_cfg.file_based_part_size;
|
||||
// if (file_part >= 10)
|
||||
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 2, 10);
|
||||
// else
|
||||
// {
|
||||
// emu_cfg.emummc_file_based_path[strlen(emu_cfg.emummc_file_based_path) - 2] = '0';
|
||||
// itoa(file_part, emu_cfg.emummc_file_based_path + strlen(emu_cfg.emummc_file_based_path) - 1, 10);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_WRITE))
|
||||
return 0;
|
||||
// if (f_open(&fp, emu_cfg.emummc_file_based_path, FA_WRITE))
|
||||
// return 0;
|
||||
|
||||
f_lseek(&fp, (u64)sector << 9);
|
||||
if (f_write(&fp, buf, (u64)num_sectors << 9, NULL))
|
||||
{
|
||||
f_close(&fp);
|
||||
return 0;
|
||||
}
|
||||
// f_lseek(&fp, (u64)sector << 9);
|
||||
// if (f_write(&fp, buf, (u64)num_sectors << 9, NULL))
|
||||
// {
|
||||
// f_close(&fp);
|
||||
// return 0;
|
||||
// }
|
||||
|
||||
f_close(&fp);
|
||||
return 1;
|
||||
// f_close(&fp);
|
||||
// return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,40 +334,28 @@ int emummc_storage_set_mmc_partition(u32 partition)
|
||||
{
|
||||
emu_cfg.active_part = partition;
|
||||
|
||||
if(h_cfg.emummc_force_disable){
|
||||
emmc_set_partition(partition);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!emu_cfg.enabled){
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!emu_cfg.sector){
|
||||
emummc_storage_file_base_set_partition(partition);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(emu_cfg.enabled != 4){
|
||||
emmc_set_partition(partition);
|
||||
}else{
|
||||
emmc_set_partition(EMMC_GPP);
|
||||
}
|
||||
|
||||
if (!emu_cfg.enabled || h_cfg.emummc_force_disable || emu_cfg.sector)
|
||||
return 1;
|
||||
else
|
||||
{
|
||||
strcpy(emu_cfg.emummc_file_based_path, "sd:");
|
||||
strcat(emu_cfg.emummc_file_based_path, emu_cfg.path);
|
||||
strcat(emu_cfg.emummc_file_based_path, "/eMMC");
|
||||
|
||||
switch (partition)
|
||||
{
|
||||
case 0:
|
||||
strcat(emu_cfg.emummc_file_based_path, "/00");
|
||||
break;
|
||||
case 1:
|
||||
strcat(emu_cfg.emummc_file_based_path, "/BOOT0");
|
||||
break;
|
||||
case 2:
|
||||
strcat(emu_cfg.emummc_file_based_path, "/BOOT1");
|
||||
break;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sdmmc_storage_t *emummc_get_storage(){
|
||||
// TODO: should return &emummc_storage if emummc lives on emmc
|
||||
return emu_cfg.enabled == 4 ? &emmc_storage : &sd_storage;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ OBJS += $(addprefix $(BUILDDIR)/$(TARGET)/, \
|
||||
bm92t36.o bq24193.o max17050.o max7762x.o max77620-rtc.o regulator_5v.o \
|
||||
touch.o joycon.o tmp451.o fan.o \
|
||||
usbd.o xusbd.o usb_descriptors.o usb_gadget_ums.o usb_gadget_hid.o \
|
||||
hw_init.o boot_storage.o sfd.o mbr_gpt.o emummc.o \
|
||||
hw_init.o boot_storage.o sfd.o mbr_gpt.o emummc_file_based.o \
|
||||
)
|
||||
|
||||
# Utilities.
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include <mem/heap.h>
|
||||
#include <storage/boot_storage.h>
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/emummc.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
#include <storage/mbr_gpt.h>
|
||||
#include <storage/nx_emmc_bis.h>
|
||||
#include <storage/sd.h>
|
||||
|
||||
@@ -54,7 +54,7 @@ void save_emusd_cfg(u32 part_idx, u32 sector_start){
|
||||
// Add config entry.
|
||||
f_puts("[emusd]\nenabled=", &fp);
|
||||
if(sector_start){
|
||||
f_puts("1", &fp);
|
||||
f_puts("4", &fp);
|
||||
}else{
|
||||
f_puts("0", &fp);
|
||||
}
|
||||
|
||||
@@ -923,7 +923,9 @@ static void _launch_hos(u8 autoboot, u8 autoboot_list)
|
||||
|
||||
void (*main_ptr)() = (void *)nyx_str->hekate;
|
||||
|
||||
boot_storage_end();
|
||||
sd_end();
|
||||
emmc_end();
|
||||
|
||||
hw_deinit(false, 0);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
#include <libs/fatfs/ff.h>
|
||||
#include <storage/boot_storage.h>
|
||||
#include <storage/emmc.h>
|
||||
#include <storage/emummc.h>
|
||||
#include <storage/emummc_file_based.h>
|
||||
#include <storage/mbr_gpt.h>
|
||||
#include <storage/sd.h>
|
||||
#include <storage/sdmmc.h>
|
||||
|
||||
@@ -224,8 +224,12 @@ static int _stat_and_copy_files(const char *src, const char *dst, char *path, u3
|
||||
|
||||
// Open directory.
|
||||
res = f_opendir(&dir, path);
|
||||
if (res != FR_OK)
|
||||
if (res != FR_OK){
|
||||
if(res == FR_NO_PATH){
|
||||
return FR_OK;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
if (labels)
|
||||
lv_label_set_text(labels[0], path);
|
||||
|
||||
Reference in New Issue
Block a user