diff --git a/branches/SelfCupExecChecker/HeapManager.cpp b/branches/SelfCupExecChecker/HeapManager.cpp new file mode 100644 index 0000000..8e95885 --- /dev/null +++ b/branches/SelfCupExecChecker/HeapManager.cpp @@ -0,0 +1,59 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapManager.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include "HeapManager.h" + +nn::fnd::ThreadSafeExpHeap s_AppHeap; + + +HeapManager::HeapManager(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse) +{ + m_Ptr = s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse); +} + +HeapManager::~HeapManager() +{ + if(m_Ptr != NULL) + { + s_AppHeap.Free(m_Ptr); + } +} +void* HeapManager::GetAddr() +{ + return m_Ptr; +} + +void InitializeHeap() +{ + s_AppHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR); +} + +size_t GetAllocatableSize(s32 alignment) +{ + return s_AppHeap.GetAllocatableSize(alignment); +} + +void* ForceAllocate(size_t byteSize, s32 alignment, bit8 groupId, nn::fnd::ExpHeapBase::AllocationMode mode, bool reuse) +{ + return s_AppHeap.Allocate(byteSize, alignment, groupId, mode, reuse); +} + +void ForceFree(void* ptr) +{ + if(ptr != NULL) + { + s_AppHeap.Free(ptr); + } +} diff --git a/branches/SelfCupExecChecker/HeapManager.h b/branches/SelfCupExecChecker/HeapManager.h new file mode 100644 index 0000000..f50f3fe --- /dev/null +++ b/branches/SelfCupExecChecker/HeapManager.h @@ -0,0 +1,46 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: HeapManager.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef HEAPMANAGER_H_ +#define HEAPMANAGER_H_ + +#include +#include + +class HeapManager +{ +public: + explicit HeapManager(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0, + nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false); + virtual ~HeapManager(); + + void* GetAddr(); + +private: + void* m_Ptr; + +}; + +void InitializeHeap(); +size_t GetAllocatableSize(s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT); + +// HeapManagerを使わず確保する場合のみ +void* ForceAllocate(size_t byteSize, s32 alignment = nn::fnd::ExpHeapBase::DEFAULT_ALIGNMENT, bit8 groupId = 0, + nn::fnd::ExpHeapBase::AllocationMode mode = nn::fnd::ExpHeapBase::ALLOCATION_MODE_FIRST_FIT, bool reuse = false); + +// HeapManagerを使わず解放する場合のみ +void ForceFree(void* ptr); + +#endif /* HEAPMANAGER_H_ */ diff --git a/branches/SelfCupExecChecker/OMakefile b/branches/SelfCupExecChecker/OMakefile index 1db8c44..fd964c1 100644 --- a/branches/SelfCupExecChecker/OMakefile +++ b/branches/SelfCupExecChecker/OMakefile @@ -23,12 +23,15 @@ INCLUDES += $(SAMPLED_DEMOS_COMMON_INCLUDE_DIR) SOURCES[] = main.cpp scrollBuffer.cpp + VersionDetect.cpp + HeapManager.cpp LIBS += lib_demo \ libnn_am \ libnn_cup \ libnn_ns \ +ROMFS_ROOT = romfiles DESCRIPTOR = $(HORIZON_ROOT)/resources/specfiles/SelfCup.desc diff --git a/branches/SelfCupExecChecker/Readme.txt b/branches/SelfCupExecChecker/Readme.txt index b54f3e8..01dd48d 100644 Binary files a/branches/SelfCupExecChecker/Readme.txt and b/branches/SelfCupExecChecker/Readme.txt differ diff --git a/branches/SelfCupExecChecker/SelfCupTool.bsf b/branches/SelfCupExecChecker/SelfCupTool.bsf new file mode 100644 index 0000000..104a94d Binary files /dev/null and b/branches/SelfCupExecChecker/SelfCupTool.bsf differ diff --git a/branches/SelfCupExecChecker/SelfCupTool.rsf b/branches/SelfCupExecChecker/SelfCupTool.rsf new file mode 100644 index 0000000..4a361c9 --- /dev/null +++ b/branches/SelfCupExecChecker/SelfCupTool.rsf @@ -0,0 +1,26 @@ +BasicInfo: + Title: SelfCupTool + ProductCode: CTR-P-234A + BackupMemoryType: None + Logo: Nintendo + +CardInfo: + CardDevice: None + +TitleInfo: + Use: Evaluation + UniqueId: 0xf802a + Version: 0 + +SystemControlInfo: + AppType : Application + StackSize : 65536 + Dependency: + - nwm + - socket + - ssl + - friends + - ac + - cecd + - boss + - ndm diff --git a/branches/SelfCupExecChecker/VersionDetect.cpp b/branches/SelfCupExecChecker/VersionDetect.cpp new file mode 100644 index 0000000..203e80c --- /dev/null +++ b/branches/SelfCupExecChecker/VersionDetect.cpp @@ -0,0 +1,109 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: VersionDetect.cpp + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include + +#include "VersionDetect.h" +#include "HeapManager.h" + + +void GetCupVersion(nn::pl::CTR::CardUpdateVersion* cup, nn::cfg::CTR::CfgRegionCode region) +{ + nn::Result result; + const size_t BUF_SIZE = 1024; + u8 buf[BUF_SIZE]; + // CUPバージョン + { + result = nn::fs::MountContent("cver:", nn::fs::MEDIA_TYPE_NAND, cCupVerId[region], 0, 1, 1, buf, + BUF_SIZE); + + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(L"cver:/version.bin"); + if (result.IsSuccess()) + { + s64 fileSize = fis.GetSize(); + NN_LOG("version.bin size = %lld\n", fileSize); + s32 ret; + void* addr = NULL; + HeapManager heap(fileSize); + addr = heap.GetAddr(); + if (addr != NULL) + { + result = fis.TryRead(&ret, addr, fileSize); + if (result.IsSuccess()) + { + nn::pl::CTR::CardUpdateVersion* ver_buf = reinterpret_cast (addr); + + std::memcpy(cup, ver_buf, sizeof(nn::pl::CTR::CardUpdateVersion)); + } + } + } + fis.Finalize(); + + nn::fs::Unmount("cver:"); + } + +} + + +void GetNupVersion(nn::pl::CTR::NetworkUpdateVersion* nup, nn::cfg::CTR::CfgRegionCode region) +{ + nn::Result result; + const size_t BUF_SIZE = 1024; + u8 buf[BUF_SIZE]; + + // NUPバージョン + { + result = nn::fs::MountContent("nver:", nn::fs::MEDIA_TYPE_NAND, cNupVerId[region], 0, 1, 1, buf, + BUF_SIZE); + + nn::fs::FileInputStream fis; + + result = fis.TryInitialize(L"nver:/version.bin"); + if (result.IsSuccess()) + { + s64 fileSize = fis.GetSize(); + NN_LOG("version.bin size = %lld\n", fileSize); + s32 ret; + void* addr = NULL; + HeapManager heap(fileSize); + addr = heap.GetAddr(); + if (addr != NULL) + { + result = fis.TryRead(&ret, addr, fileSize); + if (result.IsSuccess()) + { + nn::pl::CTR::NetworkUpdateVersion* ver_buf = + reinterpret_cast (addr); + + std::memcpy(nup, ver_buf, sizeof(nn::pl::CTR::NetworkUpdateVersion)); + } + } + } + + fis.Finalize(); + nn::fs::Unmount("nver:"); + } + +} + +void GetSystemVersion(VerDef* mVerData, nn::cfg::CTR::CfgRegionCode region) +{ + GetCupVersion(&mVerData->cup, region); + GetNupVersion(&mVerData->nup, region); +} diff --git a/branches/SelfCupExecChecker/VersionDetect.h b/branches/SelfCupExecChecker/VersionDetect.h new file mode 100644 index 0000000..7f94174 --- /dev/null +++ b/branches/SelfCupExecChecker/VersionDetect.h @@ -0,0 +1,55 @@ +/*---------------------------------------------------------------------------* + Project: Horizon + File: VersionDetect.h + + Copyright 2009 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Rev$ + *---------------------------------------------------------------------------*/ + +#ifndef VERSIONDETECT_H_ +#define VERSIONDETECT_H_ + +#include +#include +#include + +struct VerDef +{ + nn::pl::CTR::CardUpdateVersion cup; + nn::pl::CTR::NetworkUpdateVersion nup; +}; + +// TODO:リージョン追加時に範囲外アクセスにならないよう注意 +const nn::ProgramId cCupVerId[] = +{ + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_JP, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_US, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_CN, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_KR, + nn::pl::CTR::SHAREDDATA_TITLEID_CUP_VERSION_TW, +}; + +const nn::ProgramId cNupVerId[] = +{ + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_JP, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_US, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_EU, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_CN, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_KR, + nn::pl::CTR::SHAREDDATA_TITLEID_NUP_VERSION_TW, +}; + +// リージョンコードに基づいてバージョン情報を取得する +void GetSystemVersion(VerDef* mVerData, nn::cfg::CTR::CfgRegionCode region); + +#endif /* VERSIONDETECT_H_ */ diff --git a/branches/SelfCupExecChecker/main.cpp b/branches/SelfCupExecChecker/main.cpp index 3a7fa3f..43f73d7 100644 --- a/branches/SelfCupExecChecker/main.cpp +++ b/branches/SelfCupExecChecker/main.cpp @@ -26,16 +26,18 @@ #include #include #include +#include #include #include "demo.h" #include "scrollBuffer.h" +#include "VersionDetect.h" +#include "HeapManager.h" namespace { - const int s_GxHeapSize=0x800000; - nn::fnd::ExpHeap s_appHeap; +const s32 s_GxHeapSize = 0x800000; uptr s_GxHeap; demo::RenderSystemDrawing s_RenderSystem; @@ -47,9 +49,6 @@ namespace // デモの初期化 void Initialize() { - // os の初期化 - nn::os::Initialize(); - // NuiShellの初期化 (CUPに必須) NN_UTIL_PANIC_IF_FAILED(nn::ns::CTR::InitializeForShell()); @@ -74,15 +73,15 @@ namespace nn::cfg::Initialize(); // デバイスメモリの設定 - const int DEVICE_MEMORY_SIZE = 12*1024 * 1024; + const s32 DEVICE_MEMORY_SIZE = 32 * 1024 * 1024; NN_UTIL_PANIC_IF_FAILED(nn::os::SetDeviceMemorySize(DEVICE_MEMORY_SIZE)); // ヒープの初期化 - s_appHeap.Initialize(nn::os::GetDeviceMemoryAddress(), nn::os::GetDeviceMemorySize(), nn::os::ALLOCATE_OPTION_LINEAR); + InitializeHeap(); // 描画インスタンスの初期化 - s_GxHeap = reinterpret_cast(s_appHeap.Allocate(s_GxHeapSize)); - s_RenderSystem.Initialize(s_GxHeap, s_GxHeapSize); + s_GxHeap = reinterpret_cast(ForceAllocate(s_GxHeapSize));s_RenderSystem + .Initialize(s_GxHeap, s_GxHeapSize); // 描画インスタンスの初期化 s_scrollBufferInstance.Initialize(&s_RenderSystem); @@ -107,7 +106,7 @@ namespace // 動いていることを知らせるための、くるくる画面表示取得用メソッド const char s_progress[]="-\\|/"; - int s_progressIndex=0; +s32 s_progressIndex = 0; char GetProgressChar() { s_progressIndex=(s_progressIndex+1)%(sizeof(s_progress)-1); @@ -123,25 +122,27 @@ namespace s_scrollBuffer->AppendText("Initializing Cup Library")->Render(); SetTick(); // 初期化開始前の時間をセット result=nn::cup::CTR::Initialize(s_updaterBuffer,sizeof(s_updaterBuffer)); - if(result==nn::cup::CTR::ResultUpdatePartitionNotFound()){ + if (result == nn::cup::CTR::ResultUpdatePartitionNotFound()) + { s_scrollBuffer->AppendText(" - Update Partition Not Found (%lldmsec)", GetConsumedMillisec())->Render(); s_scrollBuffer->AppendText("")->Render(); *isHandledError=true; return result; } - if(result==nn::cup::CTR::ResultUpdateNotRequired()){ + if (result == nn::cup::CTR::ResultUpdateNotRequired()) + { s_scrollBuffer->AppendText(" - Already Updated (%lldmsec)", GetConsumedMillisec())->Render(); s_scrollBuffer->AppendText("")->Render(); *isHandledError=true; return result; } - if(result==nn::cup::CTR::ResultInvalidUpdatePartitionFormat()){ + if (result == nn::cup::CTR::ResultInvalidUpdatePartitionFormat()) + { s_scrollBuffer->AppendText(" - Invalid Update Partition (%lldmsec)", GetConsumedMillisec())->Render(); s_scrollBuffer->AppendText("")->Render(); *isHandledError=true; return result; - } - NN_UTIL_RETURN_IF_FAILED(result); + }NN_UTIL_RETURN_IF_FAILED(result); s_scrollBuffer->AppendText(" - Need Update (%lldmsec)", GetConsumedMillisec())->Render(); *needUpdate = true; @@ -156,9 +157,26 @@ namespace } } +nn::Result ExecuteCup(ScrollBuffer* scrollBuf, bool* needUpdte) +{ + nn::Result result; + bool isHandledError = false; + result = UpdateSequence(&isHandledError, needUpdte); + if (isHandledError == false && result.IsFailure()) + { + { + // それ以外の場合は、Resultを表示 + scrollBuf->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits()); + scrollBuf->AppendText("")->Render(); + } + } + + return result; +} + extern "C" void nnMain() { - NN_LOG("Start cup demo\n"); + NN_LOG("Start Self Cup\n"); nn::Result result; Initialize(); @@ -187,24 +205,12 @@ extern "C" void nnMain() break; } - nn::am::ProgramInfo outInfos; result = nn::am::GetProgramInfos(&outInfos, nn::fs::MEDIA_TYPE_NAND, &MMEN_PROGRAM_ID, 1); bool needUpdate = false; if (result.IsSuccess()) { - - /******************** CUPの実行 *******************/ - bool isHandledError = false; - result = UpdateSequence(&isHandledError, &needUpdate); - if (isHandledError == false && result.IsFailure()) - { - { - // それ以外の場合は、Resultを表示 - s_scrollBuffer->AppendText(" - Unhandled Error: 0x%08x", result.GetPrintableBits()); - s_scrollBuffer->AppendText("")->Render(); - } - } + result = ExecuteCup(s_scrollBuffer, &needUpdate); } else if(result == nn::am::ResultNotFound()) { @@ -217,6 +223,11 @@ extern "C" void nnMain() } s_scrollBuffer->AppendText("")->Render(); + VerDef versionData; + GetSystemVersion(&versionData, region); + + s_scrollBuffer->AppendText("Version: %d.%d.%d-%d%c", versionData.cup.majorVersion, versionData.cup.minorVersion, + versionData.cup.microVersion, versionData.nup.majorVersion, nn::cfg::GetRegionCodeA3(region)); for(;;) { diff --git a/branches/SelfCupExecChecker/romfiles/nup_version.bin b/branches/SelfCupExecChecker/romfiles/nup_version.bin new file mode 100644 index 0000000..45a8ca0 --- /dev/null +++ b/branches/SelfCupExecChecker/romfiles/nup_version.bin @@ -0,0 +1 @@ + \ No newline at end of file