allow emmc writes (to write warmboot to emusd), allow unaligned emmc writes
This commit is contained in:
3
fusee/program/source/fatfs/fusee_diskio.cpp
vendored
3
fusee/program/source/fatfs/fusee_diskio.cpp
vendored
@@ -32,8 +32,7 @@ bool diskio_read_system(void *dst, size_t size, size_t sector_index, size_t sect
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool diskio_write_system(size_t sector_index, size_t sector_count, const void *src, size_t size) {
|
bool diskio_write_system(size_t sector_index, size_t sector_count, const void *src, size_t size) {
|
||||||
/* Don't allow writes to eMMC GPP partition */
|
return R_SUCCEEDED(::ams::nxboot::WriteMmc(::ams::sdmmc::MmcPartition::MmcPartition_UserData, sector_index, sector_count, src, size));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool diskio_read_boot1(void *dst, size_t size, size_t sector_index, size_t sector_count) {
|
bool diskio_read_boot1(void *dst, size_t size, size_t sector_index, size_t sector_count) {
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ namespace ams::fs {
|
|||||||
private:
|
private:
|
||||||
void EnsureFile(int id);
|
void EnsureFile(int id);
|
||||||
public:
|
public:
|
||||||
MultiFileStorage(const char *base_path);
|
MultiFileStorage(const char *base_path, OpenMode mode);
|
||||||
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
virtual Result Read(s64 offset, void *buffer, size_t size) override;
|
||||||
virtual Result Flush() override;
|
virtual Result Flush() override;
|
||||||
virtual Result GetSize(s64 *out) override;
|
virtual Result GetSize(s64 *out) override;
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace ams::fs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiFileStorage::MultiFileStorage(const char *base_path) {
|
MultiFileStorage::MultiFileStorage(const char *base_path, fs::OpenMode mode) {
|
||||||
util::Strlcpy(m_base_path, base_path, sizeof(m_base_path) - 2);
|
util::Strlcpy(m_base_path, base_path, sizeof(m_base_path) - 2);
|
||||||
m_file_path_ofs = strlen(m_base_path);
|
m_file_path_ofs = strlen(m_base_path);
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ namespace ams::fs {
|
|||||||
|
|
||||||
std::memcpy(m_base_path + m_file_path_ofs, "00", 3);
|
std::memcpy(m_base_path + m_file_path_ofs, "00", 3);
|
||||||
Result r;
|
Result r;
|
||||||
if (R_FAILED(r = fs::OpenFile(std::addressof(m_handles[0]), m_base_path, fs::OpenMode_Read))) {
|
if (R_FAILED(r = fs::OpenFile(std::addressof(m_handles[0]), m_base_path, mode))) {
|
||||||
nxboot::ShowFatalError("Failed to open part %02d (%s): 0x%08" PRIx32 "!\n", 0, m_base_path, r.GetValue());
|
nxboot::ShowFatalError("Failed to open part %02d (%s): 0x%08" PRIx32 "!\n", 0, m_base_path, r.GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ namespace ams::nxboot {
|
|||||||
/* Create partition */
|
/* Create partition */
|
||||||
/* TODO: construct boot0 storage from path instead */
|
/* TODO: construct boot0 storage from path instead */
|
||||||
g_boot0_storage = AllocateObject<fs::FileHandleStorage>(boot0_file);
|
g_boot0_storage = AllocateObject<fs::FileHandleStorage>(boot0_file);
|
||||||
g_user_storage = AllocateObject<EmummcFileStorage>(path);
|
g_user_storage = AllocateObject<EmummcFileStorage>(path, fs::OpenMode_Read);
|
||||||
} else {
|
} else {
|
||||||
ShowFatalError("Unknown emummc type %d\n", static_cast<int>(emummc_cfg.base_cfg.type));
|
ShowFatalError("Unknown emummc type %d\n", static_cast<int>(emummc_cfg.base_cfg.type));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace ams::nxboot {
|
|||||||
memcpy(path + strlen(path), "/SD/", 5);
|
memcpy(path + strlen(path), "/SD/", 5);
|
||||||
path[sizeof(path) - 1] = '\x00';
|
path[sizeof(path) - 1] = '\x00';
|
||||||
|
|
||||||
g_emusd_storage = AllocateObject<fs::MultiFileStorage>(path);
|
g_emusd_storage = AllocateObject<fs::MultiFileStorage>(path, fs::OpenMode_ReadWrite);
|
||||||
} else {
|
} else {
|
||||||
ShowFatalError("Invalid emuSD config!\n");
|
ShowFatalError("Invalid emuSD config!\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -622,7 +622,7 @@ namespace ams::nxboot {
|
|||||||
|
|
||||||
/* Determine whether we're using emummc. */
|
/* Determine whether we're using emummc. */
|
||||||
const bool emummc_driver_enabled = ConfigureEmummc();
|
const bool emummc_driver_enabled = ConfigureEmummc();
|
||||||
const bool emummc_enabled = GetEmummcConfig().emmc_cfg.IsActive();
|
const bool emummc_enabled = GetEmummcConfig().emmc_cfg.IsActive();
|
||||||
|
|
||||||
/* Initialize emummc. */
|
/* Initialize emummc. */
|
||||||
/* NOTE: SYSTEM:/ accessible past this point. */
|
/* NOTE: SYSTEM:/ accessible past this point. */
|
||||||
|
|||||||
@@ -498,17 +498,16 @@ namespace ams::sdmmc::impl {
|
|||||||
Result MmcDeviceAccessor::OnReadWrite(u32 sector_index, u32 num_sectors, void *buf, size_t buf_size, bool is_read) {
|
Result MmcDeviceAccessor::OnReadWrite(u32 sector_index, u32 num_sectors, void *buf, size_t buf_size, bool is_read) {
|
||||||
/* Get the sector index alignment. */
|
/* Get the sector index alignment. */
|
||||||
u32 sector_index_alignment = 0;
|
u32 sector_index_alignment = 0;
|
||||||
|
|
||||||
|
/* Allow unaligned writes for exosphere/fusee */
|
||||||
|
/* TODO: bad */
|
||||||
|
#ifndef ATMOSPHERE_IS_EXOSPHERE
|
||||||
if (!is_read) {
|
if (!is_read) {
|
||||||
#ifdef ATMOSPHERE_IS_EXOSPHERE
|
|
||||||
/* Allow unaligned writes */
|
|
||||||
/* TODO: bad */
|
|
||||||
constexpr u32 MmcWriteSectorAlignment = 0;
|
|
||||||
#else
|
|
||||||
constexpr u32 MmcWriteSectorAlignment = 16_KB / SectorSize;
|
constexpr u32 MmcWriteSectorAlignment = 16_KB / SectorSize;
|
||||||
#endif
|
|
||||||
sector_index_alignment = MmcWriteSectorAlignment;
|
sector_index_alignment = MmcWriteSectorAlignment;
|
||||||
AMS_ABORT_UNLESS(util::IsAligned(sector_index, MmcWriteSectorAlignment));
|
AMS_ABORT_UNLESS(util::IsAligned(sector_index, MmcWriteSectorAlignment));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Do the read/write. */
|
/* Do the read/write. */
|
||||||
R_RETURN(BaseDeviceAccessor::ReadWriteMultiple(sector_index, num_sectors, sector_index_alignment, buf, buf_size, is_read));
|
R_RETURN(BaseDeviceAccessor::ReadWriteMultiple(sector_index, num_sectors, sector_index_alignment, buf, buf_size, is_read));
|
||||||
|
|||||||
Reference in New Issue
Block a user