diff --git a/exosphere/mariko_fatal/source/fatal_abort_impl.cpp b/exosphere/mariko_fatal/source/fatal_abort_impl.cpp index 3ee576e23..c04b115b5 100644 --- a/exosphere/mariko_fatal/source/fatal_abort_impl.cpp +++ b/exosphere/mariko_fatal/source/fatal_abort_impl.cpp @@ -19,6 +19,8 @@ namespace ams::diag { void AbortImpl() { AMS_SECMON_LOG("AbortImpl was called\n"); + AMS_LOG_FLUSH(); + reg::Write(0x4, 0xAAAAAAAA); /* TODO: Reboot */ AMS_INFINITE_LOOP(); diff --git a/exosphere/mariko_fatal/source/fatal_main.cpp b/exosphere/mariko_fatal/source/fatal_main.cpp index 8fd1be9d5..58f73c49c 100644 --- a/exosphere/mariko_fatal/source/fatal_main.cpp +++ b/exosphere/mariko_fatal/source/fatal_main.cpp @@ -76,6 +76,7 @@ namespace ams::secmon::fatal { } /* TODO */ + AMS_LOG_FLUSH(); AMS_INFINITE_LOOP(); } diff --git a/exosphere/mariko_fatal/source/fatal_sdmmc.cpp b/exosphere/mariko_fatal/source/fatal_sdmmc.cpp index daca825ff..ef7035682 100644 --- a/exosphere/mariko_fatal/source/fatal_sdmmc.cpp +++ b/exosphere/mariko_fatal/source/fatal_sdmmc.cpp @@ -45,6 +45,7 @@ namespace ams::secmon::fatal { sdmmc::SetSdCardWorkBuffer(Port, GetSdCardWorkBuffer(), sdmmc::SdCardWorkBufferSize); + //sdmmc::Deactivate(Port); R_TRY(sdmmc::Activate(Port)); return ResultSuccess(); diff --git a/libraries/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp b/libraries/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp index 97d6560c1..8e71a691c 100644 --- a/libraries/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp +++ b/libraries/libvapours/include/vapours/sdmmc/sdmmc_build_config.hpp @@ -33,8 +33,8 @@ //#define AMS_SDMMC_USE_OS_TIMER #define AMS_SDMMC_USE_UTIL_TIMER //#define AMS_SDMMC_ENABLE_MMC_HS400 - //#define AMS_SDMMC_ENABLE_SD_UHS_I - //#define AMS_SDMMC_SET_PLLC4_BASE + #define AMS_SDMMC_ENABLE_SD_UHS_I + #define AMS_SDMMC_SET_PLLC4_BASE //#define AMS_SDMMC_USE_SD_CARD_DETECTOR #elif defined(ATMOSPHERE_IS_MESOSPHERE) diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp index 3a494281e..d1ed02b90 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_clock_reset_controller.reg.board.nintendo_nx.cpp @@ -264,6 +264,9 @@ namespace ams::sdmmc::impl::ClockResetController::reg { /* Check that we have registers we can write to. */ AMS_ABORT_UNLESS(g_clkrst_registers_address != 0); + AMS_LOG("Setting Clock source: target = %u, actual = %u, CLK_SOURCE = %08x\n", target_frequency_khz, *out_actual_frequency_khz, clk_m | static_cast(n)); + AMS_LOG("PLLC4_BASE: %08x\n", ams::reg::Read(g_clkrst_registers_address + CLK_RST_CONTROLLER_PLLC4_BASE)); + /* Update the clock source. */ switch (module) { case Module_Sdmmc1: ams::reg::Write(g_clkrst_registers_address + CLK_RST_CONTROLLER_CLK_SOURCE_SDMMC1, clk_m | static_cast(n)); break; diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp index 9bfff1ad3..f45c8e18c 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sd_card_device_accessor.cpp @@ -494,9 +494,11 @@ namespace ams::sdmmc::impl { /* Check that we're in 4bit bus mode. */ IHostController *hc = BaseDeviceAccessor::GetHostController(); R_UNLESS(hc->GetBusWidth() == BusWidth_4Bit, sdmmc::ResultSdCardNot4BitBusWidthAtUhsIMode()); + AMS_LOG("%s\n", "BusWidth good\n"); /* Determine what speed mode/access mode we should switch to. */ R_TRY(this->IssueCommandCheckSupportedFunction(wb, wb_size)); + AMS_LOG("%s\n", "IssueCommandCheckSupportedFunction\n"); SwitchFunctionAccessMode target_am; SpeedMode target_sm; if (max_sm == SpeedMode_SdCardSdr104 && IsSupportedAccessMode(static_cast(wb), SwitchFunctionAccessMode_Sdr104)) { @@ -508,16 +510,21 @@ namespace ams::sdmmc::impl { } else { return sdmmc::ResultSdCardNotSupportSdr104AndSdr50(); } + AMS_LOG("Try Switch to %u %u\n", (u32)target_am, (u32)target_sm); /* Switch the access mode. */ R_TRY(this->SwitchAccessMode(target_am, wb, wb_size)); + AMS_LOG("%s\n", "SwitchAccessMode\n"); /* Set the host controller speed mode and perform tuning using command index 19. */ R_TRY(hc->SetSpeedMode(target_sm)); + AMS_LOG("%s\n", "SetSpeedMode\n"); R_TRY(hc->Tuning(target_sm, 19)); + AMS_LOG("%s\n", "Tuning\n"); /* Check status. */ R_TRY(BaseDeviceAccessor::IssueCommandSendStatus()); + AMS_LOG("%s\n", "IssueCommandSendStatus\n"); return ResultSuccess(); } @@ -573,65 +580,93 @@ namespace ams::sdmmc::impl { /* Wait 1ms for configuration to take. */ WaitMicroSeconds(1000); + AMS_LOG("%s\n", "Did hc->Startup()\n"); + /* Wait an additional 74 clocks for configuration to take. */ WaitClocks(74, hc->GetDeviceClockFrequencyKHz()); + AMS_LOG("%s\n", "Wait 74 clocks\n"); + /* Go to idle state. */ R_TRY(BaseDeviceAccessor::IssueCommandGoIdleState()); + AMS_LOG("%s\n", "Go Idle State\n"); + /* Check whether the spec is under 2.0. */ bool spec_under_2 = false; R_TRY_CATCH(this->IssueCommandSendIfCond()) { R_CATCH(sdmmc::ResultResponseTimeoutError) { spec_under_2 = true; } } R_END_TRY_CATCH; + AMS_LOG("%s\n", "Send If Cond\n"); + /* Set the rca to 0. */ this->sd_card_device.SetRca(0); + AMS_LOG("%s\n", "SetRca\n"); + /* Go to ready state. */ const bool can_use_uhs_i_mode = (max_bw != BusWidth_1Bit) && (max_sm == SpeedMode_SdCardSdr104 || max_sm == SpeedMode_SdCardSdr50); const bool uhs_i_supported = hc->IsSupportedTuning() && hc->IsSupportedBusPower(BusPower_1_8V); R_TRY(this->ChangeToReadyState(spec_under_2, can_use_uhs_i_mode && uhs_i_supported)); + AMS_LOG("%s\n", "ChangeToReadyState\n"); + /* Get the CID. */ R_TRY(BaseDeviceAccessor::IssueCommandAllSendCid(wb, wb_size)); this->sd_card_device.SetCid(wb, wb_size); + AMS_LOG("%s\n", "IssueCommandAllSendCid\n"); + /* Go to stby state and get the RCA. */ R_TRY(this->ChangeToStbyStateAndGetRca()); + AMS_LOG("%s\n", "ChangeToStbyStateAndGetRca\n"); + /* Get the CSD. */ R_TRY(BaseDeviceAccessor::IssueCommandSendCsd(wb, wb_size)); this->sd_card_device.SetCsd(wb, wb_size); + AMS_LOG("%s\n", "IssueCommandSendCsd\n"); R_TRY(this->SetMemoryCapacity(wb)); + AMS_LOG("%s\n", "SetMemoryCapacity\n"); + /* Set the host controller speed mode to default if we're not in uhs i mode. */ if (!this->sd_card_device.IsUhsIMode()) { R_TRY(hc->SetSpeedMode(SpeedMode_SdCardDefaultSpeed)); } + AMS_LOG("%s\n", "SetSpeedMode\n"); /* Issue select card command. */ R_TRY(BaseDeviceAccessor::IssueCommandSelectCard()); + AMS_LOG("%s\n", "IssueCommandSelectCard\n"); /* Set block length to sector size. */ R_TRY(BaseDeviceAccessor::IssueCommandSetBlockLenToSectorSize()); + AMS_LOG("%s\n", "IssueCommandSetBlockLenToSectorSize\n"); + /* Try to disconnect dat3 pullup resistor. */ TryDisconnectDat3PullUpResistor(); + AMS_LOG("%s\n", "TryDisconnectDat3PullUpResistor\n"); /* Get the SCR. */ R_TRY(this->GetScr(wb, wb_size)); const u8 sd_bw = GetSdBusWidths(static_cast(wb)); const bool spec_under_1_1 = IsLessThanSpecification1_1(static_cast(wb)); + AMS_LOG("%s\n", "GetScr\n"); /* Extend the bus width to the largest that we can. */ R_TRY(this->ExtendBusWidth(max_bw, sd_bw)); + AMS_LOG("%s\n", "ExtendBusWidth\n"); /* Extend the bus speed to as fast as we can. */ if (this->sd_card_device.IsUhsIMode()) { R_TRY(this->ExtendBusSpeedAtUhsIMode(max_sm, wb, wb_size)); + AMS_LOG("%s\n", "ExtendBusSpeedAtUhsIMode\n"); } else { R_TRY(this->ExtendBusSpeedAtNonUhsIMode(max_sm, spec_under_1_1, wb, wb_size)); + AMS_LOG("%s\n", "ExtendBusSpeedAtNonUhsIMode\n"); } /* Enable power saving. */ @@ -682,6 +717,8 @@ namespace ams::sdmmc::impl { return ResultSuccess(); } + AMS_LOG("Startup Failed, Result = %08x\n", result.GetValue()); + /* Check if we were removed. */ AMS_SDMMC_CHECK_SD_CARD_REMOVED(); diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp index d69d498e1..3e302ff65 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.cpp @@ -458,7 +458,7 @@ namespace ams::sdmmc::impl { /* Set the buffer read ready enable, and read status to ensure it takes. */ reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.normal_int_enable, SD_REG_BITS_ENUM(NORMAL_INTERRUPT_BUFFER_READ_READY, ENABLED)); - reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status); + reg::Write(this->sdmmc_registers->sd_host_standard_registers.normal_int_status, reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status)); /* Issue command with clock disabled. */ reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, DISABLE)); @@ -578,6 +578,8 @@ namespace ams::sdmmc::impl { this->drive_strength_calibration_status = sdmmc::ResultSdmmcCompOpen(); } + AMS_LOG("[sdmmc] IsSocMariko(): %d\n", IsSocMariko()); + AMS_LOG("[sdmmc] AUTO_CAL_STATUS: %08x\n", reg::Read(this->sdmmc_registers->auto_cal_status)); break; } @@ -726,6 +728,9 @@ namespace ams::sdmmc::impl { /* Check that the dat lines are all low. */ R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.present_state, SD_REG_BITS_VALUE(PRESENT_STATE_DAT0_3_LINE_SIGNAL_LEVEL, 0b0000)), sdmmc::ResultSdCardNotReadyToVoltageSwitch()); + /* Set Speed Mode. */ + R_TRY(this->SetSpeedMode(SpeedMode_SdCardSdr12)); + /* Set voltage to 1.8V. */ SdHostStandardController::EnsureControl(); R_TRY(this->LowerBusPower()); @@ -746,7 +751,7 @@ namespace ams::sdmmc::impl { R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.host_control2, SD_REG_BITS_ENUM(HOST_CONTROL2_1_8V_SIGNALING_ENABLE, 1_8V_SIGNALING)), sdmmc::ResultSdHostStandardFailSwitchTo1_8V()); /* Enable clock, and wait 1ms. */ - reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, DISABLE)); + reg::ReadWrite(this->sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, ENABLE)); SdHostStandardController::EnsureControl(); WaitMicroSeconds(1000); @@ -858,6 +863,10 @@ namespace ams::sdmmc::impl { } } + AMS_LOG("normal_status: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.normal_int_status)); + AMS_LOG("error_status: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.error_int_status)); + AMS_LOG("HOST_CONTROL2: %08x\n", reg::Read(this->sdmmc_registers->sd_host_standard_registers.host_control2)); + /* Check if we're using the tuned clock. */ R_UNLESS(reg::HasValue(this->sdmmc_registers->sd_host_standard_registers.host_control2, SD_REG_BITS_ENUM(HOST_CONTROL2_SAMPLING_CLOCK, USING_TUNED_CLOCK)), sdmmc::ResultTuningFailed()); @@ -889,7 +898,7 @@ namespace ams::sdmmc::impl { } /* If we're at 3.3V, lower to 1.8V. */ - { + if (this->current_bus_power == BusPower_3_3V) { /* pcv::ChangeVoltage(pcv::PowerControlTarget_SdCard, 1800000); */ this->power_controller->LowerBusPower(); diff --git a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp index 4c5fba691..d007d9dd0 100644 --- a/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp +++ b/libraries/libvapours/source/sdmmc/impl/sdmmc_sdmmc_controller.board.nintendo_nx.hpp @@ -394,7 +394,7 @@ namespace ams::sdmmc::impl { APB_MISC_REG_BITS_VALUE(GP_SDMMC1_PAD_CFGPADCTRL_CFG2TMC_SDMMC1_PAD_CAL_DRVUP, drvup)); /* Read to be sure our config takes. */ - reg::Read(apb_address + APB_MISC_GP_EMMC4_PAD_CFGPADCTRL); + reg::Read(apb_address + APB_MISC_GP_SDMMC1_PAD_CFGPADCTRL); } public: Sdmmc1Controller() : SdmmcController(Sdmmc1RegistersPhysicalAddress) { diff --git a/stratosphere/boot/source/boot_main.cpp b/stratosphere/boot/source/boot_main.cpp index 5019243cd..2e639196c 100644 --- a/stratosphere/boot/source/boot_main.cpp +++ b/stratosphere/boot/source/boot_main.cpp @@ -216,8 +216,6 @@ int main(int argc, char **argv) boot::CheckBatteryCharge(); } - AMS_ABORT_UNLESS(spl::GetSocType() != spl::SocType_Mariko); - /* Configure pinmux + drive pads. */ boot::SetInitialPinmuxConfiguration(); @@ -243,6 +241,8 @@ int main(int argc, char **argv) /* Finalize the i2c server library. */ boot::FinalizeI2cDriverLibrary(); + AMS_ABORT_UNLESS(spl::GetSocType() != spl::SocType_Mariko); + /* Tell PM to start boot2. */ R_ABORT_UNLESS(pmshellNotifyBootFinished());