mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-15 03:27:49 +01:00
exo: read first two sd card sectors in mariko_fatal
This commit is contained in:
parent
7bcd5c6e3b
commit
898fe61034
@ -18,6 +18,12 @@
|
||||
|
||||
namespace ams::secmon::fatal {
|
||||
|
||||
namespace {
|
||||
|
||||
constinit u8 g_test_buffer[sdmmc::SectorSize * 2];
|
||||
|
||||
}
|
||||
|
||||
void Main() {
|
||||
/* Set library register addresses. */
|
||||
actmon::SetRegisterAddress(MemoryRegionVirtualDeviceActivityMonitor.GetAddress());
|
||||
@ -43,6 +49,20 @@ namespace ams::secmon::fatal {
|
||||
Result result = InitializeSdCard();
|
||||
AMS_SECMON_LOG("InitializeSdCard: %08x\n", result.GetValue());
|
||||
|
||||
/* Get the connection status. */
|
||||
sdmmc::SpeedMode speed_mode;
|
||||
sdmmc::BusWidth bus_width;
|
||||
result = CheckSdCardConnection(std::addressof(speed_mode), std::addressof(bus_width));
|
||||
AMS_SECMON_LOG("CheckSdCardConnection: %08x\n", result.GetValue());
|
||||
AMS_SECMON_LOG(" Speed Mode: %u\n", static_cast<u32>(speed_mode));
|
||||
AMS_SECMON_LOG(" Bus Width: %u\n", static_cast<u32>(bus_width));
|
||||
|
||||
/* Read the first two sectors from the SD Card. */
|
||||
std::memset(g_test_buffer, 0xCC, sizeof(g_test_buffer));
|
||||
result = ReadSdCard(g_test_buffer, sizeof(g_test_buffer), 0, sizeof(g_test_buffer) / sdmmc::SectorSize);
|
||||
AMS_SECMON_LOG("ReadSdCard: %08x\n", result.GetValue());
|
||||
AMS_DUMP(g_test_buffer, sizeof(g_test_buffer));
|
||||
|
||||
/* TODO */
|
||||
AMS_INFINITE_LOOP();
|
||||
}
|
||||
|
@ -26,23 +26,55 @@ namespace ams::secmon::fatal {
|
||||
return MemoryRegionVirtualDramSdmmcMappedData.GetPointer<u8>() + MemoryRegionVirtualDramSdmmcMappedData.GetSize() - mmu::PageSize;
|
||||
}
|
||||
|
||||
ALWAYS_INLINE u8 *GetSdCardDmaBuffer() {
|
||||
return MemoryRegionVirtualDramSdmmcMappedData.GetPointer<u8>();
|
||||
}
|
||||
|
||||
constexpr inline size_t SdCardDmaBufferSize = MemoryRegionVirtualDramSdmmcMappedData.GetSize() - mmu::PageSize;
|
||||
constexpr inline size_t SdCardDmaBufferSectors = SdCardDmaBufferSize / sdmmc::SectorSize;
|
||||
static_assert(util::IsAligned(SdCardDmaBufferSize, sdmmc::SectorSize));
|
||||
|
||||
}
|
||||
|
||||
Result InitializeSdCard() {
|
||||
/* Map main memory for the sdmmc device. */
|
||||
AMS_SECMON_LOG("%s\n", "Initializing Device Page Table.");
|
||||
InitializeDevicePageTableForSdmmc1();
|
||||
AMS_SECMON_LOG("%s\n", "Initialized Device Page Table.");
|
||||
|
||||
/* Initialize sdmmc library. */
|
||||
sdmmc::Initialize(Port);
|
||||
AMS_SECMON_LOG("%s\n", "Initialized Sdmmc Port.");
|
||||
|
||||
sdmmc::SetSdCardWorkBuffer(Port, GetSdCardWorkBuffer(), sdmmc::SdCardWorkBufferSize);
|
||||
AMS_SECMON_LOG("%s\n", "Set SD Card Work Buffer.");
|
||||
|
||||
R_TRY(sdmmc::Activate(Port));
|
||||
AMS_SECMON_LOG("%s\n", "Activated.");
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
Result CheckSdCardConnection(sdmmc::SpeedMode *out_sm, sdmmc::BusWidth *out_bw) {
|
||||
return sdmmc::CheckSdCardConnection(out_sm, out_bw, Port);
|
||||
}
|
||||
|
||||
Result ReadSdCard(void *dst, size_t size, size_t sector_index, size_t sector_count) {
|
||||
/* Validate that our buffer is valid. */
|
||||
AMS_ASSERT(size >= sector_count * sdmmc::SectorSize);
|
||||
|
||||
/* Repeatedly read sectors. */
|
||||
u8 *dst_u8 = static_cast<u8 *>(dst);
|
||||
void * const dma_buffer = GetSdCardDmaBuffer();
|
||||
while (sector_count > 0) {
|
||||
/* Read sectors into the DMA buffer. */
|
||||
const size_t cur_sectors = std::min(sector_count, SdCardDmaBufferSectors);
|
||||
const size_t cur_size = cur_sectors * sdmmc::SectorSize;
|
||||
R_TRY(sdmmc::Read(dma_buffer, cur_size, Port, sector_index, cur_sectors));
|
||||
|
||||
/* Copy data from the DMA buffer to the output. */
|
||||
std::memcpy(dst_u8, dma_buffer, cur_size);
|
||||
|
||||
/* Advance. */
|
||||
dst_u8 += cur_size;
|
||||
sector_index += cur_sectors;
|
||||
sector_count -= cur_sectors;
|
||||
}
|
||||
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
@ -19,5 +19,7 @@
|
||||
namespace ams::secmon::fatal {
|
||||
|
||||
Result InitializeSdCard();
|
||||
Result CheckSdCardConnection(sdmmc::SpeedMode *out_sm, sdmmc::BusWidth *out_bw);
|
||||
Result ReadSdCard(void *dst, size_t size, size_t sector_index, size_t sector_count);
|
||||
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ namespace ams::secmon {
|
||||
}
|
||||
|
||||
/* Acquire exclusive access to exception handling logic. */
|
||||
if (g_is_locked.exchange(true)) {
|
||||
if (!g_is_locked.exchange(true)) {
|
||||
/* Invoke the exception handler impl. */
|
||||
ExceptionHandlerImpl(lr, sp);
|
||||
|
||||
|
@ -37,6 +37,12 @@ namespace ams::dd {
|
||||
return secmon::MemoryRegionVirtualDeviceApbMisc.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceApbMisc.GetAddress();
|
||||
} else if (secmon::MemoryRegionPhysicalDeviceSdmmc.Contains(phys_addr, size)) {
|
||||
return secmon::MemoryRegionVirtualDeviceSdmmc.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceSdmmc.GetAddress();
|
||||
} else if (secmon::MemoryRegionPhysicalDevicePmc.Contains(phys_addr, size)) {
|
||||
return secmon::MemoryRegionVirtualDevicePmc.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDevicePmc.GetAddress();
|
||||
} else if (secmon::MemoryRegionPhysicalDeviceI2c5.Contains(phys_addr, size)) {
|
||||
return secmon::MemoryRegionVirtualDeviceI2c5.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceI2c5.GetAddress();
|
||||
} else if (secmon::MemoryRegionPhysicalDeviceI2c1.Contains(phys_addr, size)) {
|
||||
return secmon::MemoryRegionVirtualDeviceI2c1.GetAddress() + phys_addr - secmon::MemoryRegionPhysicalDeviceI2c1.GetAddress();
|
||||
} else {
|
||||
AMS_UNUSED(size);
|
||||
return static_cast<uintptr_t>(phys_addr);
|
||||
|
@ -747,13 +747,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
SdHostStandardController::SdHostStandardController(dd::PhysicalAddress registers_phys_addr, size_t registers_size) {
|
||||
/* Translate the physical address to a address. */
|
||||
#if defined(ATMOSPHERE_IS_STRATOSPHERE)
|
||||
const uintptr_t registers_addr = dd::QueryIoMapping(registers_phys_addr, registers_size);
|
||||
#else
|
||||
/* TODO: Discriminate between bpmp, exosphere address? */
|
||||
AMS_UNUSED(registers_size);
|
||||
const uintptr_t registers_addr = static_cast<uintptr_t>(registers_phys_addr);
|
||||
#endif
|
||||
const uintptr_t registers_addr = dd::QueryIoMapping(registers_phys_addr, registers_size);
|
||||
|
||||
/* Set registers. */
|
||||
AMS_ABORT_UNLESS(registers_addr != 0);
|
||||
|
Loading…
Reference in New Issue
Block a user