RTCデータを移行するように

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-05-23%20-%20ctr.7z%20+%20svn_v1.068.zip/ctr/svn/ctr_Repair@14 385bec56-5757-e545-9c3a-d8741f4650f1
This commit is contained in:
N2614 2011-02-04 04:16:00 +00:00
parent f68caa975d
commit 89b4c7fdba
9 changed files with 144 additions and 10 deletions

View File

@ -74,6 +74,7 @@ size_t s_SizeofIvs;
// IVSが読めるかどうか
bool s_CanReadIvs = false;
nn::Handle s_McuSession;
} // namespace <unnamed>
@ -132,6 +133,11 @@ u32 GetRenderTarget(u32 target, bool flip)
}
}
nn::Handle GetMcuHandle()
{
return s_McuSession;
}
extern "C" void nnMain(void)
{
@ -164,10 +170,9 @@ extern "C" void nnMain(void)
result = nn::friends::detail::Initialize();
// mcuの初期化
nn::Handle mcuSession;
nn::mcu::CTR::InitializeHwCheck(&mcuSession);
nn::mcu::CTR::InitializeHwCheck(&s_McuSession);
nn::mcu::CTR::HwCheck mcu(mcuSession);
nn::mcu::CTR::HwCheck mcu(s_McuSession);
// ヒープの確保
common::HeapManager::GetHeap()->Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR);
@ -418,7 +423,7 @@ extern "C" void nnMain(void)
nn::fs::Unmount(common::SDMC_ARCHIVE_NAME);
s_RenderSystem.Finalize();
nn::mcu::CTR::FinalizeHwCheck(&mcuSession);
nn::mcu::CTR::FinalizeHwCheck(&s_McuSession);
nn::friends::detail::Finalize();
nn::ps::Finalize();
nn::ptm::CTR::FinalizeForSystemMenu();

View File

@ -27,6 +27,7 @@ bool CanReadIVS();
bool CanReadSerialNumber();
void GetSerialNumber(u8** serial, size_t* size);
void GetIvs(void** ivs, size_t* size);
nn::Handle GetMcuHandle();
const u32 CONSOLE_WIDTH = 38;
const u32 CONSOLE_HEIGHT = 24;

View File

@ -26,6 +26,7 @@
#include <nn/ps/CTR/ps_API.h>
#include <nn/drivers/aes/CTR/ARM946ES/driverAes_Types.h>
#include <nn/crypto/crypto_SwAesCtrContext.h>
#include <nn/mcu.h>
#include "Exporter.h"
#include "CommonLogger.h"
@ -337,6 +338,29 @@ void WriteTwlSoundData()
WriteTwlData(common::TWL_SOUND);
}
void WriteMcuRtcData()
{
COMMON_LOGGER("Create RTC Backup.\n");
nn::Result result;
nn::Handle handle = GetMcuHandle();
if(handle.IsValid())
{
nn::mcu::CTR::HwCheck mcu(handle);
nn::mcu::CTR::RtcData rtc;
result = mcu.GetRtcAll(&rtc);
NN_LOG("RTC = 20%02d/%02d/%02d %02d:%02d:%02d\n", rtc.m_Year, rtc.m_Month, rtc.m_Day, rtc.m_Hour, rtc.m_Minute, rtc.m_Second);
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
s_SdWriter.WriteBuf(common::MCU_RTC_PATHNAME, &rtc, sizeof(rtc));
}
else
{
NN_LOG("invalid handle\n");
}
}
void ExportThreadFunc()
{
nn::Result result;
@ -449,6 +473,9 @@ void ExportData()
// TWLサウンド領域のデータをSDに書き出す
WriteTwlSoundData();
// RTCをSDに書き出す
WriteMcuRtcData();
// NANDのセーブデータをSDに書き出す
WriteSaveData();

View File

@ -55,7 +55,7 @@ namespace {
const size_t s_GxHeapSize = 0x800000;
demo::RenderSystemDrawing s_RenderSystem;
nn::Handle mcuSession;
nn::Handle s_McuSession;
const u16 PROGRESS_MAX_LINES = 160;
@ -142,7 +142,7 @@ void FinalizeAll()
nn::fs::Unmount("sdmc:");
s_RenderSystem.Finalize();
nn::mcu::CTR::FinalizeHwCheck(&mcuSession);
nn::mcu::CTR::FinalizeHwCheck(&s_McuSession);
nn::friends::detail::Finalize();
nn::ps::Finalize();
nn::ptm::CTR::FinalizeForSystemMenu();
@ -155,6 +155,11 @@ void FinalizeAll()
nn::applet::CloseApplication();
}
nn::Handle GetMcuHandle()
{
return s_McuSession;
}
extern "C" void nnMain(void)
{
nn::Result result;
@ -186,9 +191,8 @@ extern "C" void nnMain(void)
result = nn::friends::detail::Initialize();
// mcuの初期化
nn::mcu::CTR::InitializeHwCheck(&mcuSession);
nn::mcu::CTR::HwCheck mcu(mcuSession);
nn::mcu::CTR::InitializeHwCheck(&s_McuSession);
nn::mcu::CTR::HwCheck mcu(s_McuSession);
// amの初期化
nn::am::InitializeForSystemMenu();

View File

@ -27,6 +27,7 @@ bool CanReadIVS();
bool CanReadSerialNumber();
void GetSerialNumber(u8** serial, size_t* size);
void GetIvs(void** ivs, size_t* size);
nn::Handle GetMcuHandle();
void FinalizeAll();

View File

@ -17,6 +17,7 @@
#include <nn/ns.h>
#include <nn/CTR/CTR_DeliverArg.h>
#include <nn/fs/CTR/MPCore/fs_FileSystemBasePrivate.h>
#include <nn/ptm/CTR/ptm_ApiSysmenu.h>
#include "Controller.h"
#include "ConsoleRestore.h"
@ -137,6 +138,17 @@ void PutAliveMessage(::std::vector<std::string>& operationMessage, const char* s
i += 4;
}
void ExecSyncMcuRtc()
{
if(!ExistsRtcSyncFinishedFile())
{
ImportMcuRtc();
// 時計を無効化する
nn::ptm::CTR::InvalidateSystemTime();
CreateRtcSyncFinishedFile();
}
}
void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep, bool& continueRestore)
{
// 状態遷移Controller
@ -465,6 +477,10 @@ void ControlState(::std::vector<std::string>& operationMessage, bool& nextStep,
if (nextStep)
{
// RTC同期を行う
// RTC書き込み後できるだけ早いタイミングで再起動したいのでここで同期
ExecSyncMcuRtc();
s_RestoreState = REBOOTING;
}
}

View File

@ -30,6 +30,8 @@
#include <nn/ac/CTR/private/ac_InternalApi.h>
#include <nn/socket.h>
#include <nn/nwm/CTR/nwm_InfraAPI.h>
#include <nn/mcu.h>
#include <nn/drivers/mcu/CTR/driverMcuRegisterMap.h>
#include "FileName.h"
#include "Importer.h"
@ -295,6 +297,11 @@ bool ExistsAPSetting()
return ExistsFile(EXISTS_AP_SETTING);
}
bool ExistsRtcSyncFinishedFile()
{
return ExistsFile(EXISTS_RTC_SYNC_FINISHED);
}
bool EqualsIVSFileandIVS()
{
nn::Result result;
@ -435,6 +442,67 @@ void ImportCountryLanguageData()
}
}
inline u8 DecimalToBcd(u8 param)
{
u8 theTen, theOne;
theTen = param / 10;
theOne = param - theTen * 10;
return (theTen << 4 | theOne);
}
void ImportMcuRtc()
{
COMMON_LOGGER("Import RTC Data.\n");
nn::Result result;
nn::Handle handle = GetMcuHandle();
if(handle.IsValid())
{
size_t bufSize = common::HeapManager::GetHeap()->GetAllocatableSize();
NN_LOG("AllocatableSize = %d\n", bufSize);
void* buf = common::HeapManager::GetHeap()->Allocate(bufSize);
if (buf != NULL)
{
common::SdReaderWriter sdReader;
size_t readSize;
result = sdReader.ReadBuf(common::MCU_RTC_PATHNAME, buf, bufSize, &readSize);
if (result.IsSuccess())
{
// mcuを使ってセットする
nn::mcu::CTR::HwCheck mcu(handle);
nn::mcu::CTR::RtcData* rtc = reinterpret_cast<nn::mcu::CTR::RtcData*>(buf);
NN_LOG("RTC = 20%02d/%02d/%02d %02d:%02d:%02d\n", rtc->m_Year, rtc->m_Month, rtc->m_Day, rtc->m_Hour, rtc->m_Minute, rtc->m_Second);
// BCD変換が必要
size_t RTC_PARAM_SIZE = sizeof(nn::mcu::CTR::RtcData);
u8 bcd[RTC_PARAM_SIZE];
for (int i = 0; i < RTC_PARAM_SIZE; i++)
{
bcd[i] = DecimalToBcd(reinterpret_cast<u8*>(rtc)[i]);
}
result = mcu.WriteBySend(nn::drivers::mcu::CTR::MCU_RTC_SEC_ADDR, bcd, RTC_PARAM_SIZE);
COMMON_LOGGER_RESULT_IF_FAILED_WITH_LINE(result);
}
else
{
COMMON_LOGGER_RESULT_WITH_LINE(result , __LINE__);
}
common::HeapManager::GetHeap()->Free(buf);
}
else
{
COMMON_LOGGER("Failed Allocate Heap!!\n");
}
}
}
void InitializeFileSystem()
{
nn::Result result;
@ -748,6 +816,11 @@ void CreateUpdateFinishedFile()
CreateEmptyFile(common::UPDATE_CHECK_PATHNAME);
}
void CreateRtcSyncFinishedFile()
{
CreateEmptyFile(common::RTC_SYNC_CHECK_PATHNAME);
}
u32 GetImportProgress()
{
return common::GetProgress();

View File

@ -31,6 +31,7 @@ typedef enum FILE_EXISTS_CHECK
EXISTS_CONSOLE_INTIALIZED,
EXISTS_WRITE_FINISHED,
EXISTS_AP_SETTING,
EXISTS_RTC_SYNC_FINISHED,
EXISTS_MAX
} FileExistsCheck;
@ -41,7 +42,8 @@ const wchar_t* const FILENAME_TABLE[EXISTS_MAX] =
common::IVS_PATHNAME,
common::INITIALIZED_CHECK_PATHNAME,
common::WRITE_FINISHED_PATHNAME,
common::AP_SETTING_PATHNAME
common::AP_SETTING_PATHNAME,
common::RTC_SYNC_CHECK_PATHNAME
};
bool ExistsUpdateCheckedFile();
@ -53,12 +55,14 @@ void InitializeFileCheck();
u8* ReadSerialNumber();
bool ExistsWriteFinishedFile();
bool ExistsAPSetting();
bool ExistsRtcSyncFinishedFile();
bool IsImportFinished();
void ImportData();
void CreateWriteFinishedFile();
void CreateUpdateFinishedFile();
void CreateConsoleInitializedFile();
void CreateRtcSyncFinishedFile();
u32 GetImportProgress();
// NANDのごみを削除する
@ -87,6 +91,7 @@ struct CheckedNetworkSetting
CheckedNetworkSetting* GetTempNetworkSetting();
void ImportCountryLanguageData();
void ImportMcuRtc();
// TWL写真領域を初期化してから本体初期化を行う
void InitializeFileSystem();

View File

@ -34,6 +34,7 @@ const wchar_t* const AP_SETTING_FILENAME = L"APSetting.txt";
const wchar_t* const AP_SETTING_PATHNAME = L"sdmc:/APSetting.txt";
const wchar_t* const NOR_PATHNAME = L"sdmc:/NtrNorSetting.bin";
const wchar_t* const SERIAL_PATHNAME = L"sdmc:/serial.bin";
const wchar_t* const MCU_RTC_PATHNAME = L"sdmc:/rtc.bin";
const wchar_t* const IVS_NAND_PATHNAME = L"nand:/private/movable.sed";
const wchar_t* const IVS_PATHNAME = L"sdmc:/movable.sed";
const wchar_t* const NAND_DATA_ROOT_PATHNAME_WITH_SLASH = L"nand:/data/";
@ -43,6 +44,7 @@ const wchar_t* const SDMC_ROOT_DIRECTORY_PATH = L"sdmc:/";
const wchar_t* const WRITE_FINISHED_PATHNAME = L"sdmc:/WriteFinished";
const wchar_t* const UPDATE_CHECK_PATHNAME = L"sdmc:/UpdateFinished";
const wchar_t* const INITIALIZED_CHECK_PATHNAME = L"sdmc:/ConsoleInitialized";
const wchar_t* const RTC_SYNC_CHECK_PATHNAME = L"sdmc:/RtcSyncFinished";
enum TWL_PATHNAME
{