1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-11-10 06:01:52 +00:00

exo/mariko_fatal: add sdmmc write function

This commit is contained in:
Michael Scire 2020-11-16 20:35:47 -08:00 committed by SciresM
parent a2c89a8f3f
commit 5f6942aec8

View file

@ -79,4 +79,29 @@ namespace ams::secmon::fatal {
return ResultSuccess();
}
Result WriteSdCard(size_t sector_index, size_t sector_count, const void *src, size_t size) {
/* Validate that our buffer is valid. */
AMS_ASSERT(size >= sector_count * sdmmc::SectorSize);
/* Repeatedly read sectors. */
const u8 *src_u8 = static_cast<const u8 *>(src);
void * const dma_buffer = GetSdCardDmaBuffer();
while (sector_count > 0) {
/* Copy sectors into the DMA buffer. */
const size_t cur_sectors = std::min(sector_count, SdCardDmaBufferSectors);
const size_t cur_size = cur_sectors * sdmmc::SectorSize;
std::memcpy(dma_buffer, src_u8, cur_size);
/* Write sectors to the sd card. */
R_TRY(sdmmc::Write(Port, sector_index, cur_sectors, dma_buffer, cur_size));
/* Advance. */
src_u8 += cur_size;
sector_index += cur_sectors;
sector_count -= cur_sectors;
}
return ResultSuccess();
}
}