diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/Makefile b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/Makefile index 95307158..5d3a611b 100644 --- a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/Makefile +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/Makefile @@ -28,15 +28,14 @@ ifndef TWLSDK_NOCRYPTO SRCS = main.c \ kami_pxi.c \ - formatter.c \ nvram_misc.c TARGET_NAME = armadillo TARGET_NEF = $(TARGET_NAME).tef -LCFILE_SPEC = ../../NandInitializerRed/ARM7.TWL/$(TARGET_NAME).lsf -LCFILE_TEMPLATE = ../../NandInitializerRed/ARM7.TWL/$(TARGET_NAME).lcf.template -LDRES_TEMPLATE = ../../NandInitializerRed/ARM7.TWL/$(TARGET_NAME).response.template +LCFILE_SPEC = $(TARGET_NAME).lsf +LCFILE_TEMPLATE = $(TARGET_NAME).lcf.template +LDRES_TEMPLATE = $(TARGET_NAME).response.template CRT0_O = crt0.SCR.TWL.o @@ -52,10 +51,7 @@ MAKELCF_FLAGS += -DISDBG_LIBS_TWL='$(if $(ISDBG_LIBS_TWL),$(ISDBG_LIBS_TWL),libs -DISDBG_LIBS_NITRO='libstubsisd_sp$(TWL_LIBSUFFIX).a' LINCLUDES = $(ROOT)/build/libraries/spi/ARM7/include \ - ../../NandInitializerRed/common/include \ - ../../NandInitializerRed/ARM7.TWL/include - -SRCDIR = ../../NandInitializerRed/ARM7.TWL/src + ..//common/include \ LLIBRARIES += libwl_sp$(TWL_LIBSUFFIX).a \ libsdio_sp$(TWL_LIBSUFFIX).a \ diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lcf.template b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lcf.template new file mode 100644 index 00000000..bfded37b --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lcf.template @@ -0,0 +1,388 @@ +#--------------------------------------------------------------------------- +# Project: TwlSDK - components - armadillo.TWL +# File: armadillo.lcf.template +# +# Copyright 2008 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. +# +# $Date:: $ +# $Rev$ +# $Author$ +#--------------------------------------------------------------------------- +MEMORY +{ + (RWX) : ORIGIN = , LENGTH = 0x0 > + binary.STATIC_FOOTER (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + F (RW) : ORIGIN = 0, LENGTH = 0x0 > + + binary.LTDAUTOLOAD_TOP (RW) : ORIGIN = 0, LENGTH = 0x0 > + + (RWX) : ORIGIN = , LENGTH = 0x0 >> + + binary.LTDAUTOLOAD_INFO (RWX) : ORIGIN = 0, LENGTH = 0x0 >> + + L (RW) : ORIGIN = 0, LENGTH = 0x0 > + + check.WORKRAM (RWX) : ORIGIN = 0x03740000, LENGTH = 0xd0000 > workram.check +} + +KEEP_SECTION +{ + .sinit +} + +SECTIONS +{ + ############################ STATIC ################################# + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_STATIC_START =.; + OBJECT(_start,*) + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_SINIT_START =.; + + + + + + + + + + + + + WRITEW 0; + + # + # DATA BLOCK: READ WRITE + # + . = ALIGN(4); + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_END =.; + + SDK_STATIC_SIZE = SDK_STATIC_END - SDK_STATIC_START; + __sinit__ = SDK_STATIC_SINIT_START; # for static initializer + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_STATIC_BSS_START =.; + + + + + + + + + + + + + . = ALIGN(4); + SDK_STATIC_BSS_END = .; + + SDK_STATIC_BSS_SIZE = SDK_STATIC_BSS_END - SDK_STATIC_BSS_START; + + } >> + + ############################ STATIC_FOOTER ########################## + .binary.STATIC_FOOTER: + { + WRITEW 0xdec00621; # LE(0x2106C0DE) = NITRO CODE + WRITEW _start_ModuleParams - ADDR(.); + WRITEW 0; # NO DIGEST + WRITEW _start_LtdModuleParams - ADDR(.); + + } > binary.STATIC_FOOTER + + ############################ OVERLAYDEFS ############################ + .F: + { + ### module information + WRITEW ADDR(.); # load address + WRITEW _start; # entry address + WRITEW SDK_STATIC_SIZE; # size of module + WRITEW _start_AutoloadDoneCallback; # callback autoload done + + } > F + + ########################### LTDAUTOLOADS ############################ + SDK_LTDAUTOLOAD_TOP_START = 0x02f00000; + SDK_LTDAUTOLOAD_TOP_SIZE = 4; # STATIC 領域が無い代わりに 4 bytes のダミーがバイナリファイルの先頭に入る # + SDK_LTDAUTOLOAD_START = SDK_LTDAUTOLOAD_TOP_START + SDK_LTDAUTOLOAD_TOP_SIZE; + SDK_LTDAUTOLOAD_SIZE = 0; + SDK_LTDAUTOLOAD_BSS_END = 0x03740000; + + .binary.LTDAUTOLOAD_TOP: + { + WRITEW 0; + + } > binary.LTDAUTOLOAD_TOP + + + .: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # TEXT BLOCK: READ ONLY + # + SDK_LTDAUTOLOAD..START =.; + + + + + + + + + . = ALIGN(4); + SDK_STATIC_ETABLE_START =.; + __exception_table_start__ =.; + EXCEPTION + __exception_table_end__ =.; + SDK_STATIC_ETABLE_END =.; + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..SINIT_START =.; + + + + + + + + + + + + + WRITEW 0; + + # + # DATA BLOCK: READ WRITE BLOCK + # + . = ALIGN(4); + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..END =.; + + SDK_LTDAUTOLOAD..SIZE = SDK_LTDAUTOLOAD..END - SDK_LTDAUTOLOAD..START; + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD..SIZE; + + } > + + ..bss: + { + ALIGNALL(4); + . = ALIGN(4); + + # + # Definition to refer overlay segment, when same name symbols exist in multiple overlays. + # + + SEARCH_SYMBOL ; + + + # + # BSS BLOCK + # + SDK_LTDAUTOLOAD..BSS_START =.; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + . = ALIGN(4); + SDK_LTDAUTOLOAD..BSS_END =.; + SDK_LTDAUTOLOAD_BSS_END =.; + + SDK_LTDAUTOLOAD..BSS_SIZE = SDK_LTDAUTOLOAD..BSS_END - SDK_LTDAUTOLOAD..BSS_START; + + } >> + + + SDK_MOUNT_INFO_TABLE = SDK_LTDAUTOLOAD_BSS_END; + SDK_LTDAUTOLOAD_BSS_END = SDK_MOUNT_INFO_TABLE + 0x400; + + ######################### LTDAUTOLOAD_INFO ########################## + .binary.LTDAUTOLOAD_INFO: + { + + WRITEW ADDR(.); + WRITEW SDK_LTDAUTOLOAD..SIZE; + WRITEW SDK_LTDAUTOLOAD..SINIT_START; + WRITEW SDK_LTDAUTOLOAD..BSS_SIZE; + + + } > binary.LTDAUTOLOAD_INFO + + SDK_LTDAUTOLOAD_LIST = SDK_LTDAUTOLOAD_START + SDK_LTDAUTOLOAD_SIZE; + SDK_LTDAUTOLOAD_LIST_END = SDK_LTDAUTOLOAD_LIST + SIZEOF(.binary.LTDAUTOLOAD_INFO); + SDK_LTDAUTOLOAD_SIZE = SDK_LTDAUTOLOAD_SIZE + SIZEOF(.binary.LTDAUTOLOAD_INFO); + + ########################## LTDOVERLAYDEFS ########################### + .L: + { + ### TWL limited extended static module information + WRITEW SDK_LTDAUTOLOAD_TOP_START; # load address + WRITEW SDK_MOUNT_INFO_TABLE; # address of the FS mount information table + WRITEW SDK_LTDAUTOLOAD_SIZE + SDK_LTDAUTOLOAD_TOP_SIZE; # size of module + WRITEW 0; # padding + + } > L + + ############################ OTHERS ################################# + SDK_SUBPRIV_ARENA_LO = 0x02ffc000; # メインメモリアリーナはサイズ 0 + SDK_SEA_KEY_STORE = SDK_LTDAUTOLOAD_BSS_END; + SDK_WRAM_ARENA_LO = SDK_LTDAUTOLOAD_BSS_END + 0x40; + + SDK_IRQ_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE = ; # allocated in WRAM + SDK_SYS_STACKSIZE_SIGN = (SDK_SYS_STACKSIZE < 0x80000000) * 2 - 1; + + .check.WORKRAM: + { + . = SDK_WRAM_ARENA_LO + 0x80 + SDK_IRQ_STACKSIZE + SDK_SYS_STACKSIZE * SDK_SYS_STACKSIZE_SIGN; + + } > check.WORKRAM +} diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lsf b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lsf new file mode 100644 index 00000000..b9709765 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.lsf @@ -0,0 +1,86 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - components - armadillo.TWL +# File: armadillo.lsf +# +# Copyright 2008 Nintendo. All rights reserved. +# +# These coded insructions, 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. +# +# $Date:: $ +# $Rev$ +# $Author$ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# +#-------- +Static $(TARGET_NAME) +{ + Address 0x02380000 + StackSize 1024 1024 + + Library $(CRT0_O) +} + +#-------- +Ltdautoload SCRWRAM +{ + Address 0x03740000 + + Library libsubpsyscall.a + Library libsyscall_sp.twl.a + Library $(CW_LIBS) + Library $(ISDBG_LIBS_TWL) + Library $(ISDBG_LIBS_NITRO) + + Object * (.etable) + Object $(OBJDIR)/main.o + Object $(OBJDIR)/kami_pxi.o + Object $(OBJDIR)/nvram_misc.o + + Library libsea_sp$(LIBSUFFIX).a + Library libcrypto_sp$(LIBSUFFIX).a + + Library libos_sp$(LIBSUFFIX).a + Library libmi_sp$(LIBSUFFIX).a + Library libstd_sp$(LIBSUFFIX).a + Library libmath_sp$(LIBSUFFIX).a + Library libpxi_sp$(LIBSUFFIX).a + Library libexi_sp$(LIBSUFFIX).a + Library libi2c_sp$(LIBSUFFIX).a + Library libsdio_sp$(LIBSUFFIX).a + Library libpad_sp$(LIBSUFFIX).a + Library libscfg_sp$(LIBSUFFIX).a + Library libmcu_sp$(LIBSUFFIX).a + Library libcdc_sp$(LIBSUFFIX).a + Library libsnd_sp$(LIBSUFFIX).a + Library libsndex_sp$(LIBSUFFIX).a + Library libspi_sp$(LIBSUFFIX).a + Library libpm_sp$(LIBSUFFIX).a + Library libtp_sp$(LIBSUFFIX).a + Library libtpex_sp$(LIBSUFFIX).a + Library libmic_sp$(LIBSUFFIX).a + Library libmicex_sp$(LIBSUFFIX).a + Library libnvram_sp$(LIBSUFFIX).a + Library librtc_sp$(LIBSUFFIX).a + Library libfatfs_sp$(LIBSUFFIX).a +# Library libwm_sp$(LIBSUFFIX).a +# Library libnwm_sp$(LIBSUFFIX).a + Library libwvr_sp$(LIBSUFFIX).a + Library libwl_sp$(LIBSUFFIX).a + Library libwpa_sp$(LIBSUFFIX).a + Library libathdrv_sp$(LIBSUFFIX).a + Library libfs_sp$(LIBSUFFIX).a + Library libcard_sp$(LIBSUFFIX).a + Library libcamera_sp$(LIBSUFFIX).a + + Object * (.wram) + Object * (.ltdwram) + Object * (.rsvwram) + Object * (.main) + Object * (.ltdmain) +} diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.response.template b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.response.template new file mode 100644 index 00000000..b68c3564 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/armadillo.response.template @@ -0,0 +1,22 @@ + + + + + -l + + + + + + + -l + + + + + + + + -l + + diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/kami_pxi.h b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/kami_pxi.h new file mode 100644 index 00000000..cbce8090 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/kami_pxi.h @@ -0,0 +1,44 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_CAMERA_TEST_CAMERATEST_H_ +#define TWL_CAMERA_TEST_CAMERATEST_H_ + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +void KamiPxiInit( void ); + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_CAMERA_TEST_CAMERATEST_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/nvram.h b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/nvram.h new file mode 100644 index 00000000..22b3ec4a --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/include/nvram.h @@ -0,0 +1,43 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: nvram.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef FIRM_NVRAM_H_ +#define FIRM_NVRAM_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef SDK_ARM9 +#else // SDK_ARM7 + +/*---------------------------------------------------------------------------* + 関数定義 + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size); +void NVRAMi_Write(u32 address, void *buf, u32 size); + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* FIRM_NVRAM_H_ */ +#endif diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/kami_pxi.c b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/kami_pxi.c new file mode 100644 index 00000000..437e2696 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/kami_pxi.c @@ -0,0 +1,251 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include "kami_pxi.h" +#include "fifo.h" +#include "twl/cdc.h" +#include "nvram.h" +#include +#include +#include +#include +#include + +typedef unsigned char byte; /* Don't change */ +typedef unsigned short word; /* Don't change */ +typedef unsigned long dword; /* Don't change */ +#define BOOLEAN int + +extern BOOL FATFSi_nandRtfsIo( int driveno, dword block, void* buffer, word count, BOOLEAN reading); +extern BOOL sdmcFormatNandLog( BOOL verify_flag); + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +#define KAMITEST_MESSAGE_ARRAY_MAX 4 // スレッド同期用メッセージキューのサイズ +#define KAMITEST_THREAD_STACK_SIZE 2048 // スレッドのスタックサイズ + +#define KAMITEST_THREAD_PRIORITY 6 + +// アライメント調整してコピーする +#define KAMI_UNPACK_U16(d, s) \ + (*(d) = (u16)((((u8*)s)[0] << 0) | (((u8*)s)[1] << 8))) +#define KAMI_UNPACK_U32(d, s) \ + (*(d) = (u32)((((u8*)s)[0] << 0) | (((u8*)s)[1] << 8) | (((u8*)s)[2] << 16) | (((u8*)s)[3] << 24))) + +/*---------------------------------------------------------------------------* + 型定義 + *---------------------------------------------------------------------------*/ +typedef struct KamiWork +{ + BOOL result; + u32 total; + u32 current; + KamiCommand command; + u8 data[KAMITEST_PXI_DATA_SIZE_MAX]; // 後続データ格納用 + + OSMessageQueue msgQ; // スレッド同期用メッセージキュー + OSMessage msgArray[KAMITEST_MESSAGE_ARRAY_MAX]; + // メッセージを格納するバッファ + OSThread thread; // KAMI用スレッド + u64 stack[KAMITEST_THREAD_STACK_SIZE / sizeof(u64)]; + // KAMI用スレッドのスタック +} +KamiWork; + +/*---------------------------------------------------------------------------* + 静的変数定義 + *---------------------------------------------------------------------------*/ +static BOOL kamiInitialized; +static KamiWork kamiWork; + +/*---------------------------------------------------------------------------* + 内部関数定義 + *---------------------------------------------------------------------------*/ +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err); +static void KamiReturnResult(KamiCommand command, KAMIPxiResult result); +static void KamiReturnResultEx(KamiCommand command, KAMIPxiResult result, u8 size, u8* data); +static void KamiThread(void *arg); + +void KamiPxiInit(void) +{ + if (kamiInitialized) + { + return; + } + kamiInitialized = TRUE; + + PXI_Init(); + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_KAMITEST, KamiPxiCallback); + + OS_InitMessageQueue(&kamiWork.msgQ, kamiWork.msgArray, KAMITEST_MESSAGE_ARRAY_MAX); + OS_CreateThread(&kamiWork.thread, KamiThread, 0, + (void *)(kamiWork.stack + (KAMITEST_THREAD_STACK_SIZE / sizeof(u64))), + KAMITEST_THREAD_STACK_SIZE, KAMITEST_THREAD_PRIORITY); + OS_WakeupThreadDirect(&kamiWork.thread); +} + +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag ) + if (err) + { + return; + } + if (data & KAMITEST_PXI_START_BIT) // 先頭データ + { + kamiWork.total = (u8)((data & KAMITEST_PXI_DATA_NUMS_MASK) >> KAMITEST_PXI_DATA_NUMS_SHIFT); + kamiWork.current = 0; + kamiWork.command = (KamiCommand)((data & KAMITEST_PXI_COMMAND_MASK) >> KAMITEST_PXI_COMMAND_SHIFT); + kamiWork.data[kamiWork.current++] = (u8)((data & KAMITEST_PXI_1ST_DATA_MASK) >> KAMITEST_PXI_1ST_DATA_SHIFT); + } + else // 後続データ + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0xFF0000) >> 16); + kamiWork.data[kamiWork.current++] = (u8)((data & 0x00FF00) >> 8); + kamiWork.data[kamiWork.current++] = (u8)((data & 0x0000FF) >> 0); + } + if (kamiWork.current >= kamiWork.total) + { + switch (kamiWork.command) + { + case KAMI_NAND_IO: + case KAMI_NVRAM_IO: + case KAMI_CLEAR_NAND_ERRORLOG: + if (!OS_SendMessage(&kamiWork.msgQ, NULL, OS_MESSAGE_NOBLOCK)) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_FATAL_ERROR); + } + break; + + default: + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_INVALID_COMMAND); + } + } +} + +static void KamiReturnResult(KamiCommand command, KAMIPxiResult result) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | KAMITEST_PXI_RESULT_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + ((1 << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((result << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } +} + +static void KamiReturnResultEx(KamiCommand command, KAMIPxiResult result, u8 size, u8* data) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | KAMITEST_PXI_RESULT_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + (((size+1) << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((result << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + int i; + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } + for (i = 0; i < size; i+= 3) + { + pxiData = (u32)((data[i] << 16) | (data[i+1] << 8) | data[i+2]); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } + } +} + +static void KamiThread(void *arg) +{ +#pragma unused( arg ) + OSMessage msg; + BOOL result; + + while (TRUE) + { + (void)OS_ReceiveMessage(&kamiWork.msgQ, &msg, OS_MESSAGE_BLOCK); + switch (kamiWork.command) + { + case KAMI_NAND_IO: + { + BOOL is_read; + u32 block; + void* buffer; + u32 count; + + is_read = (BOOL)kamiWork.data[0]; + KAMI_UNPACK_U32(&block, &kamiWork.data[1]); + KAMI_UNPACK_U32((u32 *)(&buffer), &kamiWork.data[5]); + KAMI_UNPACK_U32(&count, &kamiWork.data[9]); + + result = FATFSi_nandRtfsIo( 0, block, buffer, (u16)count, is_read ); + if (result) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_TRUE); + } + else + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_FALSE); + } + } + break; + + case KAMI_NVRAM_IO: + { + BOOL is_read; + u32 adress; + void* buffer; + u32 size; + + is_read = (BOOL)kamiWork.data[0]; + KAMI_UNPACK_U32(&adress, &kamiWork.data[1]); + KAMI_UNPACK_U32((u32 *)(&buffer), &kamiWork.data[5]); + KAMI_UNPACK_U32(&size, &kamiWork.data[9]); + + if (is_read) + { + NVRAMi_Read( adress, buffer, size ); + } + else + { + NVRAMi_Write( adress, buffer, size ); + } + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS); + } + break; + + case KAMI_CLEAR_NAND_ERRORLOG: + { + if (sdmcFormatNandLog(TRUE)) + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS); + } + else + { + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_SUCCESS_FALSE); + } + } + break; + + default: + KamiReturnResult(kamiWork.command, KAMI_PXI_RESULT_INVALID_COMMAND); + } + } +} + +#include diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/main.c b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/main.c new file mode 100644 index 00000000..7016b7c2 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/main.c @@ -0,0 +1,696 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - components - armadillo.TWL + File: main.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nvram_sp.h" +#include "kami_pxi.h" + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +/* 各スレッド優先度 */ +#define THREAD_PRIO_SPI 2 +#define THREAD_PRIO_MCU 4 // 暫定 +#define THREAD_PRIO_SND 6 +#define THREAD_PRIO_NWM_EVENT 7 +#define THREAD_PRIO_NWM_SDIO 8 +#define THREAD_PRIO_FATFS 8 +#define THREAD_PRIO_NWM_COMMAND 9 +#define THREAD_PRIO_NWM_WPA 10 +#define THREAD_PRIO_HOTSW 11 +#define THREAD_PRIO_RTC 12 +#define THREAD_PRIO_SNDEX 14 +#define THREAD_PRIO_FS 15 +/* OS_THREAD_LAUNCHER_PRIORITY 16 */ + +/* ROM 内登録エリアの拡張言語コード */ +#define ROMHEADER_FOR_CHINA_BIT 0x80 +#define ROMHEADER_FOR_KOREA_BIT 0x40 + +/* 使用 DMA 番号 */ +#define DMA_NO_FATFS FATFS_DMA_4 // = 0 +#define DMA_NO_NWM 3 + +/* カードチャタリングカウンタ */ +#define CHATTERING_COUNTER 0x1988 // 100ms分 (0x1988 * 15.3us = 100000us) + +/*---------------------------------------------------------------------------* + 内部関数定義 + *---------------------------------------------------------------------------*/ +static void PrintDebugInfo(void); +static OSHeapHandle InitializeAllocateSystem(void); +static void InitializeFatfs(void); +static void InitializeNwm(OSHeapHandle hh); +static void InitializeCdc(void); +static void DummyThread(void* arg); + +static void ReadUserInfo(void); +#ifdef NVRAM_CONFIG_DATA_EX_VERSION +static BOOL IsValidConfigEx(void); +static u16 GetRomValidLanguage(void); +static s32 CheckCorrectNCDEx(NVRAMConfigEx* ncdsp); +#else +static s32 CheckCorrectNCD(NVRAMConfig* ncdsp); +#endif +static void VBlankIntr(void); +static void AttachAES(void); + +/*---------------------------------------------------------------------------* + Name: TwlSpMain + Description: 起動ベクタ。 + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +void +TwlSpMain(void) +{ + OSHeapHandle heapHandle; + + /* OS 初期化 */ + OS_Init(); + PrintDebugInfo(); + + /* NVRAM からユーザー情報読み出し */ + ReadUserInfo(); + + /* ヒープ領域設定 */ + heapHandle = InitializeAllocateSystem(); + + /* ボタン入力サーチ初期化 */ + (void)PAD_InitXYButton(); + + /* 割込み許可 */ + (void)OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)GX_VBlankIntr(TRUE); + (void)OS_EnableIrq(); + (void)OS_EnableInterrupts(); + + // 強制AESモード + AttachAES(); + + /* 各ライブラリ初期化 */ + AES_Init(); // AES + SEA_Init(); // SEA + FS_Init(FS_DMA_NOT_USE); // FS for CARD + FS_CreateReadServerThread(THREAD_PRIO_FS); // FS for CARD + InitializeFatfs(); // FAT-FS +// InitializeNwm(heapHandle); // TWL 無線 + MCU_InitIrq(THREAD_PRIO_MCU); // マイコン + + if (OSi_IsCodecTwlMode() == TRUE) + { + InitializeCdc(); // CODEC + CAMERA_Init(); // カメラ + } + + SND_Init(THREAD_PRIO_SND); // サウンド + SNDEX_Init(THREAD_PRIO_SNDEX); // サウンド拡張 + RTC_Init(THREAD_PRIO_RTC); // RTC +// WVR_Begin(heapHandle); // NITRO 無線 + SPI_Init(THREAD_PRIO_SPI); + +/////////////// +#ifndef NAND_INITIALIZER_LIMITED_MODE + KamiPxiInit(); +#endif +/////////////// + + while (TRUE) + { + OS_Halt(); + + /* ソフトウェアリセット要求は監視しない */ + /* AGB カートリッジの挿抜チェックは行わない */ + /* DS カードの挿抜チェックは行わない */ + } +} + +/*---------------------------------------------------------------------------* + Name: PrintDebugInfo + Description: ARM7 コンポーネントの情報をデバッグ出力する。 + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +PrintDebugInfo(void) +{ + OS_TPrintf("ARM7: This component is running on TWL.\n"); + OS_TPrintf("ARM7: This component is \"armadillo.TWL\".\n"); +} + +/*---------------------------------------------------------------------------* + Name: InitializeAllocateSystem + Description: メモリ割当てシステムを初期化する。 + Arguments: None. + Returns: OSHeapHandle - WRAM アリーナ上に確保されたヒープのハンドルを返す。 + *---------------------------------------------------------------------------*/ +static OSHeapHandle +InitializeAllocateSystem(void) +{ + OSHeapHandle hh; + void* subLo = (void*)OS_GetWramSubArenaLo(); + void* subHi = (void*)OS_GetWramSubArenaHi(); + void* privLo = (void*)OS_GetWramSubPrivArenaLo(); + void* privHi = (void*)OS_GetWramSubPrivArenaHi(); + + if (((u32)privLo == HW_PRV_WRAM) && ((u32)subHi == HW_PRV_WRAM) && ((u32)subLo < HW_PRV_WRAM)) + { + /* SUB アリーナを SUBPRIV アリーナに吸収 */ + OS_SetWramSubArenaHi(subLo); + OS_SetWramSubPrivArenaLo(subLo); + privLo = subLo; + } + + /* アリーナを 0 クリア */ + MI_CpuClear8(privLo, (u32)privHi - (u32)privLo); + + /* ヒープ作成初期化 */ + privLo = OS_InitAlloc(OS_ARENA_WRAM_SUBPRIV, privLo, privHi, 1); + hh = OS_CreateHeap(OS_ARENA_WRAM_SUBPRIV, privLo, privHi); + if (hh < 0) + { + OS_Panic("ARM7: Failed to create heap.\n"); + } + + /* カレントヒープに設定 */ + (void)OS_SetCurrentHeap(OS_ARENA_WRAM_SUBPRIV, hh); + + /* ヒープサイズの確認 */ + { + u32 heapSize; + + heapSize = (u32)OS_CheckHeap(OS_ARENA_WRAM_SUBPRIV, hh); + + if (heapSize <= 0) + { + OS_Panic("ARM7: Failed to create heap.\n"); + } + OS_TPrintf("ARM7: heap size [%d]\n", heapSize); + } + + return hh; +} + +/*---------------------------------------------------------------------------* + Name: InitializeFatfs + Description: FATFSライブラリを初期化する。FATFS初期化関数内でスレッド休止 + する為、休止中動作するダミーのスレッドを立てる。 + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeFatfs(void) +{ + OSThread thread; + u32 stack[18]; + + /* ダミースレッド作成 */ + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + /* FATFS 初期化 */ + /* [TODO] DMA は NOT_USE のままで良い? */ + if(!FATFS_Init(DMA_NO_FATFS, FATFS_DMA_NOT_USE, THREAD_PRIO_FATFS)) + { + /* do nothing */ + } + + /* ダミースレッド破棄 */ + OS_KillThread(&thread, NULL); +} + +/*---------------------------------------------------------------------------* + Name: InitializeNwm + Description: NWMライブラリを初期化する。 + Arguments: hh - 利用可能なヒープのハンドルを指定。 + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeNwm(OSHeapHandle hh) +{ + NwmspInit nwmInit; + + /* [TODO] 確保しているヒープ領域が新無線一式が必要としているメモリ量以上かのチェックが必要 */ + + nwmInit.cmdPrio = THREAD_PRIO_NWM_COMMAND; + nwmInit.evtPrio = THREAD_PRIO_NWM_EVENT; + nwmInit.sdioPrio = THREAD_PRIO_NWM_SDIO; + + nwmInit.dmaNo = DMA_NO_NWM; + nwmInit.drvHeap.id = OS_ARENA_WRAM_SUBPRIV; + nwmInit.drvHeap.handle = hh; + +#ifdef WPA_BUILT_IN // WPA が組み込まれる場合、以下のメンバが追加される + nwmInit.wpaPrio = THREAD_PRIO_NWM_WPA; + nwmInit.wpaHeap.id = OS_ARENA_WRAM_SUBPRIV; + nwmInit.wpaHeap.handle = hh; +#endif + + NWMSP_Init(&nwmInit); +} + +/*---------------------------------------------------------------------------* + Name: InitializeCdc + Description: CDCライブラリを初期化する。CDC初期化関数内でスレッド休止する + 為、休止中動作するダミーのスレッドを立てる。 + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +static void +InitializeCdc(void) +{ + OSThread thread; + u32 stack[18]; +/* + // ランチャー経由で起動した場合はCODECは既に初期化されているため + // コンポーネントがCODECを初期化する必要はありません。 + // 将来的にはバッサリと切る必要がありますが、 + // 暫定的にI2Sが有効かどうかでCODECが初期化済みかどうかを判定します。 + if (reg_SND_SMX_CNT & REG_SND_SMX_CNT_E_MASK) + { + return; + } +*/ + /* ダミースレッド作成 */ + OS_CreateThread(&thread, DummyThread, NULL, + (void*)((u32)stack + (sizeof(u32) * 18)), sizeof(u32) * 18, OS_THREAD_PRIORITY_MAX); + OS_WakeupThreadDirect(&thread); + + /* CODEC 初期化 */ + CDC_Init(); + CDC_InitMic(); + + /* ダミースレッド破棄 */ + OS_KillThread(&thread, NULL); +} + +/*---------------------------------------------------------------------------* + Name: DummyThread + Description: FATFSライブラリ、CDCライブラリを初期化する際に立てるダミーの + スレッド。 + Arguments: arg - 使用しない。 + Returns: None. + *---------------------------------------------------------------------------*/ +static void +DummyThread(void* arg) +{ +#pragma unused(arg) + while (TRUE) + { + } +} + +//#ifdef WM_PRECALC_ALLOWEDCHANNEL +//extern u16 WMSP_GetAllowedChannel(u16 bitField); +//#endif +/*---------------------------------------------------------------------------* + Name: ReadUserInfo + + Description: NVRAMからユーザー情報を読み出し、共有領域に展開する。 + ミラーリングされているバッファが両方壊れている場合は、 + 共有領域のユーザー情報格納場所をクリアする。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void ReadUserInfo(void) +{ + s32 offset; +#ifdef NVRAM_CONFIG_DATA_EX_VERSION + NVRAMConfigEx temp[2]; +#else + NVRAMConfig temp[2]; +#endif + s32 check; + u8 *p = OS_GetSystemWork()->nvramUserInfo; + + // オフセット読み出し +#ifdef NVRAM_CONFIG_CONST_ADDRESS + offset = NVRAM_CONFIG_DATA_ADDRESS_DUMMY; +#else + NVRAM_ReadDataBytes(NVRAM_CONFIG_DATA_OFFSET_ADDRESS, NVRAM_CONFIG_DATA_OFFSET_SIZE, + (u8 *)(&offset)); + offset <<= NVRAM_CONFIG_DATA_OFFSET_SHIFT; +#endif + +#ifdef NVRAM_CONFIG_DATA_EX_VERSION + // ミラーされた2つのデータを読み出し + NVRAM_ReadDataBytes((u32)offset, sizeof(NVRAMConfigEx), (u8 *)(&temp[0])); + NVRAM_ReadDataBytes((u32)(offset + SPI_NVRAM_PAGE_SIZE), sizeof(NVRAMConfigEx), + (u8 *)(&temp[1])); + // 2つの内どちらを使うか判断 + check = CheckCorrectNCDEx(temp); +#else + // ミラーされた2つのデータを読み出し + NVRAM_ReadDataBytes((u32)offset, sizeof(NVRAMConfig), (u8 *)(&temp[0])); + NVRAM_ReadDataBytes((u32)(offset + SPI_NVRAM_PAGE_SIZE), sizeof(NVRAMConfig), (u8 *)(&temp[1])); + // 2つの内どちらを使うか判断 + check = CheckCorrectNCD(temp); +#endif + + if (check >= 3) + { + // アプリケーションの起動を抑制 + MI_CpuFill32(p, 0xffffffff, sizeof(NVRAMConfig)); + } + else if (check) + { + s32 i; + + // ニックネームを補正 + if (temp[check - 1].ncd.owner.nickname.length < NVRAM_CONFIG_NICKNAME_LENGTH) + { + for (i = NVRAM_CONFIG_NICKNAME_LENGTH; + i > temp[check - 1].ncd.owner.nickname.length; i--) + { + temp[check - 1].ncd.owner.nickname.str[i - 1] = 0x0000; + } + } + // コメントを補正 + if (temp[check - 1].ncd.owner.comment.length < NVRAM_CONFIG_COMMENT_LENGTH) + { + for (i = NVRAM_CONFIG_COMMENT_LENGTH; i > temp[check - 1].ncd.owner.comment.length; + i--) + { + temp[check - 1].ncd.owner.comment.str[i - 1] = 0x0000; + } + } + // 共有領域にストア + MI_CpuCopy32(&temp[check - 1], p, sizeof(NVRAMConfig)); + } + else + { + // 共有領域をクリア + MI_CpuClear32(p, sizeof(NVRAMConfig)); + } + + // 無線MACアドレスをユーザー情報の後ろに展開 + { + u8 wMac[6]; + + // NVRAMからMACアドレスを読み出し + NVRAM_ReadDataBytes(NVRAM_CONFIG_MACADDRESS_ADDRESS, 6, wMac); + // 展開先アドレスを計算 + p = (u8 *)((u32)p + ((sizeof(NVRAMConfig) + 3) & ~0x00000003)); + // 共有領域に展開 + MI_CpuCopy8(wMac, p, 6); + } +/* +#ifdef WM_PRECALC_ALLOWEDCHANNEL + // 使用可能チャンネルから使用許可チャンネルを計算 + { + u16 enableChannel; + u16 allowedChannel; + + // 使用可能チャンネルを読み出し + NVRAM_ReadDataBytes(NVRAM_CONFIG_ENABLECHANNEL_ADDRESS, 2, (u8 *)(&enableChannel)); + // 使用許可チャンネルを計算 + allowedChannel = WMSP_GetAllowedChannel((u16)(enableChannel >> 1)); + // 展開先アドレスを計算(MACアドレスの後ろの2バイト) + p = (u8 *)((u32)p + 6); + // 共有領域に展開 + *((u16 *)p) = allowedChannel; + } +#endif +*/ +} + +#ifdef NVRAM_CONFIG_DATA_EX_VERSION +/*---------------------------------------------------------------------------* + Name: IsValidConfigEx + + Description: ユーザー情報が拡張コンフィグに対応しているかどうかを調査する。 + + Arguments: None. + + Returns: BOOL - 拡張ユーザー情報が有効な場合にTRUEを返す。 + 無効である場合はFALSEを返す。 + *---------------------------------------------------------------------------*/ +static BOOL IsValidConfigEx(void) +{ + u8 ipl2_type; + + NVRAM_ReadDataBytes(NVRAM_CONFIG_IPL2_TYPE_ADDRESS, NVRAM_CONFIG_IPL2_TYPE_SIZE, &ipl2_type); + if (ipl2_type == NVRAM_CONFIG_IPL2_TYPE_NORMAL) + { + return FALSE; + } + if (ipl2_type & NVRAM_CONFIG_IPL2_TYPE_EX_MASK) + { + return TRUE; + } + return FALSE; +} + +/*---------------------------------------------------------------------------* + Name: GetRomValidLanguage + + Description: ROM内登録エリアの情報から、拡張言語コードの対応言語ビットマップ + に関する情報を抽出する。 + + Arguments: None. + + Returns: u16 - DSカード、もしくは マルチブートバイナリが対応している + 言語コードのビットマップを返す。DSカードが拡張言語 + コードに対応していない場合は 0 を返す。 + *---------------------------------------------------------------------------*/ +static u16 GetRomValidLanguage(void) +{ + u16 ret = 0x0000; + u8 langBit = OS_GetSystemWork()->rom_header[0x1d]; + + // ROM内登録エリアの拡張言語コードを確認 + if (langBit == ROMHEADER_FOR_CHINA_BIT) + { + // for CHINA + ret |= (0x0001 << NVRAM_CONFIG_LANG_CHINESE); + } + else if (langBit == ROMHEADER_FOR_KOREA_BIT) + { + // for KOREA + ret |= (0x0001 << NVRAM_CONFIG_LANG_HANGUL); + } + return ret; +} + +/*---------------------------------------------------------------------------* + Name: CheckCorrectNCDEx + + Description: ミラーリングされているユーザー情報のどちらを使うべきか判定する。 + + Arguments: nvdsp - 比較するコンフィグデータ2つの配列。 + + Returns: s32 - 0: 両方不適切。 + 1: 配列[ 0 ]が適切。 + 2: 配列[ 1 ]が適切。 + 3: アプリの起動を抑制すべき。 + *---------------------------------------------------------------------------*/ +static s32 CheckCorrectNCDEx(NVRAMConfigEx * ncdsp) +{ + u16 i; + u16 calc_crc; + s32 crc_flag = 0; + u16 saveCount; + + // IPLが拡張言語コードに対応しているか + if (IsValidConfigEx()) + { + // IPLが拡張言語コードに対応している場合 + u16 rom_valid_language = GetRomValidLanguage(); + + for (i = 0; i < 2; i++) + { + calc_crc = SVC_GetCRC16(0xffff, (void *)(&ncdsp[i].ncd), sizeof(NVRAMConfigData)); + if ((ncdsp[i].crc16 == calc_crc) && (ncdsp[i].saveCount < NVRAM_CONFIG_SAVE_COUNT_MAX)) + { + // CRC が正しく saveCount 値が 0x80 未満のデータを正当と判断 + calc_crc = + SVC_GetCRC16(0xffff, (void *)(&ncdsp[i].ncd_ex), sizeof(NVRAMConfigDataEx)); + if ((ncdsp[i].crc16_ex == calc_crc) + && ((0x0001 << ncdsp[i].ncd_ex.language) & + (ncdsp[i].ncd_ex.valid_language_bitmap))) + { + // 拡張データ用 CRC が正しく、設定言語コードが対応言語コードに含まれる場合に正当と判断 + if (rom_valid_language & ncdsp[i].ncd_ex.valid_language_bitmap) + { + // 拡張言語コードで通常言語コードを上書き + ncdsp[i].ncd.option.language = ncdsp[i].ncd_ex.language; + } + if (rom_valid_language & (0x0001 << NVRAM_CONFIG_LANG_CHINESE) & ~ncdsp[i]. + ncd_ex.valid_language_bitmap) + { + // ROM 内登録エリアに"中国語"拡張言語コードが設定されているが、 + // IPL2の対応言語コードに"中国語"拡張言語コードが含まれない場合は起動を抑制 + return 3; + } + crc_flag |= (1 << i); + } + } + } + } + else + { + // IPLが拡張言語コードに対応していない場合 + u16 rom_valid_language = GetRomValidLanguage(); + + if (rom_valid_language & (0x0001 << NVRAM_CONFIG_LANG_CHINESE)) + { + // ROM 内登録エリアに"中国語"拡張言語コードが設定されている場合は起動を抑制 + return 3; + } + for (i = 0; i < 2; i++) + { + calc_crc = SVC_GetCRC16(0xffff, (void *)(&ncdsp[i].ncd), sizeof(NVRAMConfigData)); + if ((ncdsp[i].crc16 == calc_crc) && (ncdsp[i].saveCount < NVRAM_CONFIG_SAVE_COUNT_MAX)) + { + // CRC が正しく saveCount 値が 0x80 未満のデータを正当と判断 + crc_flag |= (1 << i); + } + } + } + + // 正当なデータのうちどのデータが有効かを判定する。 + switch (crc_flag) + { + case 1: + case 2: + // 片方のCRCだけ正常 + return crc_flag; + + case 3: + // 両方ともCRCが正しければどちらが最新のデータか判断する。 + saveCount = (u8)((ncdsp[0].saveCount + 1) & NVRAM_CONFIG_SAVE_COUNT_MASK); + if (saveCount == ncdsp[1].saveCount) + { + return 2; + } + return 1; + } + + // 両方ともCRCが不正 + return 0; +} + +#else +/*---------------------------------------------------------------------------* + Name: CheckCorrectNCD + + Description: ミラーリングされているユーザー情報のどちらを使うべきか判定する。 + + Arguments: nvdsp - 比較するコンフィグデータ2つの配列。 + + Returns: s32 - 0: 両方不適切。 + 1: 配列[ 0 ]が適切。 + 2: 配列[ 1 ]が適切。 + *---------------------------------------------------------------------------*/ +static s32 CheckCorrectNCD(NVRAMConfig *ncdsp) +{ + u16 i; + u16 calc_crc; + s32 crc_flag = 0; + u16 saveCount; + + // 各ミラーデータのCRC & saveCount正当性チェック + for (i = 0; i < 2; i++) + { + calc_crc = SVC_GetCRC16(0xffff, (void *)(&ncdsp[i].ncd), sizeof(NVRAMConfigData)); + + if ((ncdsp[i].crc16 == calc_crc) && (ncdsp[i].saveCount < NVRAM_CONFIG_SAVE_COUNT_MAX)) + { + // CRCが正しく、saveCount値が0x80未満のデータを正当と判断。 + crc_flag |= (1 << i); + } + } + + // 正当なデータのうちどのデータが有効かを判定する。 + switch (crc_flag) + { + case 1: + case 2: + // 片方のCRCだけ正常 + return crc_flag; + + case 3: + // 両方ともCRCが正しければどちらが最新のデータか判断する。 + saveCount = (u8)((ncdsp[0].saveCount + 1) & NVRAM_CONFIG_SAVE_COUNT_MASK); + if (saveCount == ncdsp[1].saveCount) + { + return 2; + } + return 1; + } + + // 両方ともCRCが不正 + return 0; +} +#endif + +/*---------------------------------------------------------------------------* + Name: VBlankIntr + Description: V ブランク割り込みベクタ。 + Arguments: None. + Returns: None. + *---------------------------------------------------------------------------*/ +extern BOOL PMi_Initialized; +extern void PM_SelfBlinkProc(void); + +static void +VBlankIntr(void) +{ + if (PMi_Initialized) + { + PM_SelfBlinkProc(); + } +} + +/*---------------------------------------------------------------------------* + Name: AttachAES + + Description: 強制的にAESマウントするようにします。 + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +extern BOOL sdmc_aes_attach_for_nand; // 強制AESマウント用 + +static void AttachAES(void) +{ + // 強制AESマウント + sdmc_aes_attach_for_nand = TRUE; +} + diff --git a/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/nvram_misc.c b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/nvram_misc.c new file mode 100644 index 00000000..b5441832 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM7.TWL/src/nvram_misc.c @@ -0,0 +1,181 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: nvram_misc.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include "nvram.h" +#include "spi_sp.h" +#include "nvram_sp.h" + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToRead + + Description: NVRAMを読み出し可能な状態かどうか確認する。 + + Arguments: None. + + Returns: BOOL - 読み出し可能な状態の場合にTRUEを返す。 + FALSEの場合は読み出し禁止の状態。 + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToRead(void) +{ + u16 tempStatus; + + // ステータスレジスタ読み出し + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // 書き込みもしくは消去操作中かを確認 + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NvramCheckReadyToWrite + + Description: NVRAMを書き込み可能な状態かどうか確認する。 + + Arguments: None. + + Returns: BOOL - 書き込み可能な状態の場合にTRUEを返す。 + FALSEの場合は書き込み禁止の状態。 + *---------------------------------------------------------------------------*/ +static BOOL NvramCheckReadyToWrite(void) +{ + u16 tempStatus; + + // ステータスレジスタ読み出し + NVRAM_ReadStatusRegister((u8 *)(&tempStatus)); + // 書き込みもしくは消去操作中かを確認 + if (tempStatus & NVRAM_STATUS_REGISTER_WIP) + { + return FALSE; + } + // 書き込み許可されているかを確認 + if (!(tempStatus & NVRAM_STATUS_REGISTER_WEL)) + { + return FALSE; + } + return TRUE; +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitOperation + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitOperation(void) +{ + while( NvramCheckReadyToRead() == FALSE ) { + } +} + +/*---------------------------------------------------------------------------* + Name: NVRAM_WaitWriteEnable + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void NVRAM_WaitWriteEnable(void) +{ + while( NvramCheckReadyToWrite() == FALSE ) { + } +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Read + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Read(u32 address, void *buf, u32 size) +{ + NVRAM_WaitOperation(); + NVRAM_ReadDataBytes(address, size, buf); + return; +} + + +/*---------------------------------------------------------------------------* + Name: NVRAMi_Write + + Description: + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +void NVRAMi_Write(u32 address, void *buf, u32 size) +{ + u32 i; + u32 page_start; + u32 page_end; + u32 offset_start; + u32 offset_end; + u8 *src_ptr; + u8 temp_buffer[SPI_NVRAM_PAGE_SIZE]; + + src_ptr = (u8 *)buf; + page_start = (address / SPI_NVRAM_PAGE_SIZE) * SPI_NVRAM_PAGE_SIZE; + page_end = ((address+size-1) / SPI_NVRAM_PAGE_SIZE ) * SPI_NVRAM_PAGE_SIZE; + offset_start = address % SPI_NVRAM_PAGE_SIZE; + offset_end = (address+size-1) % SPI_NVRAM_PAGE_SIZE; + + while( page_start <= page_end ) { + if( offset_start != 0 ) { + NVRAMi_Read(page_start, temp_buffer, offset_start); + } + if( page_start != page_end ) { + for( i = offset_start ; i < SPI_NVRAM_PAGE_SIZE ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + } + else { + for( i = offset_start ; i <= offset_end ; i++ ) { + temp_buffer[i] = *src_ptr++; + } + if( offset_end != (SPI_NVRAM_PAGE_SIZE-1) ) { + NVRAMi_Read(page_start+offset_end+1, &(temp_buffer[offset_end+1]), SPI_NVRAM_PAGE_SIZE - (offset_end+1) ); + } + } + + NVRAM_WriteEnable(); + NVRAM_WaitWriteEnable(); + + NVRAM_PageErase((u32)page_start); + + NVRAM_WaitOperation(); + + NVRAM_WriteEnable(); + + NVRAM_PageWrite((u32)page_start, (u16)SPI_NVRAM_PAGE_SIZE, temp_buffer); + NVRAM_WaitOperation(); + + page_start += SPI_NVRAM_PAGE_SIZE; + offset_start = 0; + } +} diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/Makefile b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/Makefile index accdba25..4225387a 100644 --- a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/Makefile +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/Makefile @@ -54,17 +54,12 @@ SRCS = main.c \ hw_info.c \ keypad.c - -SRCS += $(ROOT)/build/tests/debugger/fio/src/fs_archive_hostio.c - LINCLUDES = include \ + ../common/include \ $(ROOT)/build/libraries/lcfg/ARM9.TWL/include \ - $(ROOT)/build/libraries/fs/common/include \ - ../../NandInitializerRed/common/include \ - ../../NandInitializerRed/ARM9.TWL/include + $(ROOT)/build/libraries/fs/common/include SRCDIR = src \ - ../../NandInitializerRed/ARM9.TWL/src \ ../../HWInfoWriter/ARM9/src #LCFILE = # using default diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_font.h b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_font.h new file mode 100644 index 00000000..ad5095e2 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_font.h @@ -0,0 +1,94 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_font.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_FONT_H_ +#define KAMI_FONT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +extern u8 prog_state; +enum +{ STATE_NONE, STATE_SELECT, STATE_KS_PARENTINIT, STATE_KS_PARENT, STATE_KS_CHILDINIT, + STATE_KS_CHILDSCAN, STATE_KS_CHILD +}; +extern OSHeapHandle heapHandle; // Heapハンドル; + +extern const u16 BgScDataMain[32 * 24]; +extern const u16 BgScDataSub[32 * 24]; +extern const u32 sampleCharData[8 * 0x100]; +extern const u16 PlttDataObj[16][16]; +extern const u16 PlttDataMain[16][16]; +extern const u16 PlttDataSub[16][16]; + +void kamiFontInit(void); +void kamiFontClear(void); +void kamiFontClearMain(void); +void kamiFontPut(u16 x, u16 y, u16 color, u16 no); +void kamiFontPrintf(s16 x, s16 y, u8 color, char *text, ...); +void kamiFontPrintfMain(s16 x, s16 y, u8 color, char *text, ...); +void kamiFontFill(s16 x, s16 y, u8 color, s16 value, s32 length); +void kamiFontFillChar(int lineNo, u8 color1, u8 color2); +void kamiFontLoadScreenData(void); +void kamiFontPrintfConsole(u8 color, const char *text, ...); +void kamiFontPrintfConsoleEx(u8 color, const char *text, ...); + +// 上画面コンソール文字列用パレット +#define CONSOLE_ORANGE 0 +#define CONSOLE_RED 1 +#define CONSOLE_GREEN 2 + +// 下画面フォント用パレット +#define FONT_COLOR_BLACK 0 +#define FONT_COLOR_RED 1 +#define FONT_COLOR_GREEN 2 +#define FONT_COLOR_BLUE 3 +#define FONT_COLOR_YELLOW 4 +#define FONT_COLOR_CYAN 5 +#define FONT_COLOR_PURPLE 6 + +// 下画面背景用パレット +#define BG_COLOR_TRANS 0 +#define BG_COLOR_WHITE 1 +#define BG_COLOR_BLACK 2 +#define BG_COLOR_GRAY 3 +#define BG_COLOR_PURPLE 4 +#define BG_COLOR_PINK 5 +#define BG_COLOR_BLUE 6 +#define BG_COLOR_GREEN 7 +#define BG_COLOR_VIOLET 8 +#define BG_COLOR_RED 9 +#define BG_COLOR_YELLOW 10 + +#define BG_COLOR_NONE 0xff + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_FONT_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_pxi.h b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_pxi.h new file mode 100644 index 00000000..1fcfb079 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_pxi.h @@ -0,0 +1,96 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef TWL_KAMI_TEST_KAMITEST_H_ +#define TWL_KAMI_TEST_KAMITEST_H_ + +#include "fifo.h" + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +// 処理結果定義 +typedef enum KAMIResult +{ + KAMI_RESULT_SUCCESS = 0, + KAMI_RESULT_SUCCESS_TRUE = 0, + KAMI_RESULT_SUCCESS_FALSE, + KAMI_RESULT_INVALID_COMMAND, + KAMI_RESULT_INVALID_PARAMETER, + KAMI_RESULT_ILLEGAL_STATUS, + KAMI_RESULT_BUSY, + KAMI_RESULT_FATAL_ERROR, + KAMI_RESULT_SEND_ERROR, + KAMI_RESULT_MAX +} +KAMIResult; + + +typedef enum { + FORMAT_MODE_QUICK, // Quickフォーマット + FORMAT_MODE_FULL // Fullフォーマット(各パーティション内を0xFFで埋める) +} FormatMode; + +// コールバック +typedef void (*KAMICallback)(KAMIResult result, void *arg); + + +void KamiPxiInit( void ); + +KAMIResult kamiNandIo(u32 block, void* buffer, u32 count, BOOL is_read); +KAMIResult kamiNvramIo(u32 address, void* buffer, u32 size, BOOL is_read); +KAMIResult kamiClearNandErrorLog( void ); + +// (重要) +// ARM7が読み書きするためリード前はInvalidate、ライト前はフラッシュしてください。 +// +static KAMIResult kamiNandRead(u32 block, void* buffer, u32 count) +{ + return kamiNandIo(block, buffer, count, TRUE); +} +static KAMIResult kamiNandWrite(u32 block, void* buffer, u32 count) +{ + return kamiNandIo(block, buffer, count, FALSE); +} +static KAMIResult kamiNvramRead(u32 adress, void* buffer, u32 size) +{ + return kamiNvramIo(adress, buffer, size, TRUE); +} +static KAMIResult kamiNvramWrite(u32 adress, void* buffer, u32 size) +{ + return kamiNvramIo(adress, buffer, size, FALSE); +} + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_KAMI_TEST_KAMITEST_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_write_nandfirm.h b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_write_nandfirm.h new file mode 100644 index 00000000..90fe68bd --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/kami_write_nandfirm.h @@ -0,0 +1,52 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_write_nandfirm.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_WRITE_NAND_FIRM +#define KAMI_WRITE_NAND_FIRM + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + 型定義 + *---------------------------------------------------------------------------*/ + +typedef void* (*KAMIAlloc)(u32 size); +typedef void (*KAMIFree)(void* ptr); + +/*---------------------------------------------------------------------------* + 関数定義 + *---------------------------------------------------------------------------*/ + +BOOL kamiWriteNandfirm(const char* pFullPath, NAMAlloc allocFunc, NAMFree freeFunc); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_WRITE_NAND_FIRM */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/keypad.h b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/keypad.h new file mode 100644 index 00000000..2f5a1602 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/include/keypad.h @@ -0,0 +1,48 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: keypad.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef KAMI_KEY_PAD_H_ +#define KAMI_KEY_PAD_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +#include + +/*---------------------------------------------------------------------------* + 関数定義 + *---------------------------------------------------------------------------*/ + +void kamiPadRead(void); +BOOL kamiPadIsTrigger(u16 key); +BOOL kamiPadIsRepeatTrigger(u16 key); +BOOL kamiPadIsPress(u16 key); + +/*===========================================================================*/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* KAMI_KEY_PAD_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_font.c b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_font.c new file mode 100644 index 00000000..fb3818b6 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_font.c @@ -0,0 +1,407 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_font.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_font.h" + +/*---------------------------------------------------------------------------* + 型定義 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +#define SCREEN_DATA_COLOR_PLTT_SHIFT 12 +#define NUM_OF_PRINT_TARGET 2 + +/*---------------------------------------------------------------------------* + 内部変数定義 + *---------------------------------------------------------------------------*/ + +static u8 sXPos; +static u8 sYPos; + +static u32 sBackColorCharData[24*8]; + +static u16 sFontScreenDataMain[32 * 24] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4,0xf0f4, + 0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5,0xf0f5, +}; + +/*---------------------------------------------------------------------------* + 内部関数宣言 + *---------------------------------------------------------------------------*/ + +static void kamiFontReturnConsole( void ); + +/*---------------------------------------------------------------------------* + 関数定義 + *---------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------* + Name: + + Description: + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontInit(void) +{ + // 背景用キャラクタデータ + MI_CpuCopy32( &sampleCharData[8 * 0xde], sBackColorCharData, sizeof(sBackColorCharData) ); + + // 背景用スクリーンデータセット + DC_FlushRange ( sBackColorScreenData, sizeof(sBackColorScreenData) ); + GXS_LoadBG1Scr ( sBackColorScreenData, 0, sizeof(sBackColorScreenData) ); +} + +/*---------------------------------------------------------------------------* + Name: + + Description: + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontLoadScreenData(void) +{ + DC_FlushRange ( sFontScreenDataMain, sizeof(sFontScreenDataMain) ); + GX_LoadBG0Scr ( sFontScreenDataMain, 0, sizeof(sFontScreenDataMain) ); + + DC_FlushRange ( sFontScreenDataSub, sizeof(sFontScreenDataSub) ); + GXS_LoadBG0Scr ( sFontScreenDataSub, 0, sizeof(sFontScreenDataSub) ); + + // 背景キャラクタデータ書き換え + DC_FlushRange( sBackColorCharData, sizeof(sBackColorCharData) ); + GXS_LoadBG0Char( sBackColorCharData, 0xde*32, sizeof(sBackColorCharData) ); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontClear + + Description: 仮想スクリーンをクリアする + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontClear(void) +{ + MI_CpuClear8( sFontScreenDataSub, sizeof(sFontScreenDataSub) ); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontClearMain + + Description: 仮想スクリーンをクリアする + + Arguments: None + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontClearMain(void) +{ + MI_CpuClear8( sFontScreenDataMain, sizeof(sFontScreenDataMain) ); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintf + + Description: 仮想スクリーンに文字列を配置する。文字列は32文字まで。 + + Arguments: x - 文字列の先頭を配置する x 座標( × 8 ドット )。 + y - 文字列の先頭を配置する y 座標( × 8 ドット )。 + color - 文字の色をパレット番号で指定。 + text - 配置する文字列。終端文字はNULL。 + ... - 仮想引数。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintf(s16 x, s16 y, u8 color, char *text, ...) +{ + va_list vlist; + char temp[32 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0x0000; + for (i = 0;temp[i] != 0x00; i++) + { + sFontScreenDataSub[((y * 32) + x + i) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintf + + Description: 仮想スクリーンに文字列を配置する。文字列は32文字まで。 + + Arguments: x - 文字列の先頭を配置する x 座標( × 8 ドット )。 + y - 文字列の先頭を配置する y 座標( × 8 ドット )。 + color - 文字の色をパレット番号で指定。 + text - 配置する文字列。終端文字はNULL。 + ... - 仮想引数。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfMain(s16 x, s16 y, u8 color, char *text, ...) +{ + va_list vlist; + char temp[32 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 33, text, vlist); + va_end(vlist); + + *(u16 *)(&temp[32]) = 0x0000; + for (i = 0;temp[i] != 0x00; i++) + { + sFontScreenDataMain[((y * 32) + x + i) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontFillChar + + Description: 仮想スクリーンに + + Arguments: x - 文字列の先頭を配置する x 座標( × 8 ドット )。 + y - 文字列の先頭を配置する y 座標( × 8 ドット )。 + color - 文字の色をパレット番号で指定。 + value + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontFillChar(int lineNo, u8 color1, u8 color2) +{ + s32 i; + u32 line; + int charNo = 0xde + lineNo; + + if (color1 < 0x10) + { + line = (u32)(0x11111111 * color1); + + for (i = 0;i<4; i++) + { + sBackColorCharData[8 * lineNo + i] = line; + } + } + + if (color2 < 0x10) + { + line = (u32)(0x11111111 * color2); + + for (i = 4;i<8; i++) + { + sBackColorCharData[8 * lineNo + i] = line; + } + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintfConsole + + Description: 仮想コンソールに文字列を配置する。文字列は256文字まで。 + + Arguments: color - 文字の色をパレット番号で指定。 + text - 配置する文字列。終端文字はNULL。 + ... - 仮想引数。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfConsole(u8 color, const char *text, ...) +{ + va_list vlist; + char temp[256 + 2]; + s32 i; + + va_start(vlist, text); + (void)vsnprintf(temp, 256, text, vlist); + va_end(vlist); + + // 終端追加 + *(u16 *)(&temp[256]) = 0x0000; + + for(i=0; temp[i] != 0x00; i++) + { + if (temp[i] == 0x0A) + { + // 改行コード + kamiFontReturnConsole(); + } + else + { + // 一文字ずつ書き込み + sFontScreenDataMain[((sYPos * 32) + sXPos) % (24 * 32)] = + (u16)((color << SCREEN_DATA_COLOR_PLTT_SHIFT) | temp[i]); + + // X座標が右端に到達した場合は改行処理 + if (++sXPos >= 32) + { + kamiFontReturnConsole(); + } + } + } +} + +/*---------------------------------------------------------------------------* + Name: kamiFontPrintfConsoleEx + + Description: 仮想コンソールに文字列を配置する。文字列は256文字まで。 + OS_Printfもついでに実行する。 + + Arguments: color - 文字の色をパレット番号で指定。 + text - 配置する文字列。終端文字はNULL。 + ... - 仮想引数。 + + Returns: None. + *---------------------------------------------------------------------------*/ +void +kamiFontPrintfConsoleEx(u8 color, const char *text, ...) +{ + va_list vlist; + char temp[256 + 2]; + + va_start(vlist, text); + (void)vsnprintf(temp, 256, text, vlist); + va_end(vlist); + + kamiFontPrintfConsole(color, temp); + OS_TPrintf(temp); +} + +/*---------------------------------------------------------------------------* + Name: kamiFontReturnConsole + + Description: 仮想コンソールにおける改行処理を行う + + Arguments: None. + + Returns: None. + *---------------------------------------------------------------------------*/ +static void +kamiFontReturnConsole( void ) +{ + sXPos = 0; + if (sYPos < 23) + { + // 次の行へ + sYPos++; + } + else + { + // 既に最終行に到達している場合シフトを行う + MI_CpuCopy32( &sFontScreenDataMain[32], sFontScreenDataMain, sizeof(u16)*32*23 ); + MI_CpuClear32( &sFontScreenDataMain[32*23], sizeof(u16)*32); + } +} + diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_pxi.c b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_pxi.c new file mode 100644 index 00000000..51775bae --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_pxi.c @@ -0,0 +1,343 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_pxi.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "kami_pxi.h" +#include "fifo.h" + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +// 詰めてコピーする +#define KAMI_PACK_U16(d, s) \ + ((d)[0] = (u8)((*((u16*)s) >> 0) & 0xFF), \ + (d)[1] = (u8)((*((u16*)s) >> 8) & 0xFF)) + +#define KAMI_PACK_U32(d, s) \ + ((d)[0] = (u8)((*((u32*)s) >> 0) & 0xFF), \ + (d)[1] = (u8)((*((u32*)s) >> 8) & 0xFF), \ + (d)[2] = (u8)((*((u32*)s) >> 16) & 0xFF), \ + (d)[3] = (u8)((*((u32*)s) >> 24) & 0xFF)) + + +/*---------------------------------------------------------------------------* + 型定義 + *---------------------------------------------------------------------------*/ +typedef struct KamiWork +{ + BOOL lock; + + KamiCommand command; + KAMIPxiResult result; + KAMICallback callback; + void* arg; + + u32 total; + u32 current; + u8* data; +} +KamiWork; + +/*---------------------------------------------------------------------------* + 静的変数定義 + *---------------------------------------------------------------------------*/ +static BOOL kamiInitialized; +static KamiWork kamiWork; + +/*---------------------------------------------------------------------------* + 内部関数定義 + *---------------------------------------------------------------------------*/ +static BOOL KamiSendPxiCommand(KamiCommand command, u8 size, u8 data); +static void KamiSendPxiData(u8 *pData); +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err); +static void KamiDone(KAMIResult result); +static void KamiWaitBusy(void); + + +void KamiPxiInit( void ) +{ + kamiWork.lock = FALSE; + + PXI_Init(); + while ( !PXI_IsCallbackReady(PXI_FIFO_TAG_KAMITEST, PXI_PROC_ARM7 )) + { + } + PXI_SetFifoRecvCallback(PXI_FIFO_TAG_KAMITEST, KamiPxiCallback); + if ( 0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, KAMITEST_PXI_START_BIT | (KAMI_TEST_COMMAND << KAMITEST_PXI_COMMAND_SHIFT), 0)) + { + return; + } +} + +/*---------------------------------------------------------------------------* + Name: NANDアクセス関数 + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult kamiNandIo(u32 block, void* buffer, u32 count, BOOL is_read) +{ + OSIntrMode enabled; + u8 data[12]; + int i; + + // ロック + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + // データ作成 + KAMI_PACK_U32(&data[0], &block); + KAMI_PACK_U32(&data[4], &buffer); + KAMI_PACK_U32(&data[8], &count); + + if (KamiSendPxiCommand(KAMI_NAND_IO, 12, (u8)is_read)) + { + for (i = 0; i < 12; i+=3) + { + KamiSendPxiData(&data[i]); + } + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: Nvramアクセス関数 + + Description: + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult kamiNvramIo(u32 address, void* buffer, u32 size, BOOL is_read) +{ + OSIntrMode enabled; + u8 data[12]; + int i; + + // ロック + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + // データ作成 + KAMI_PACK_U32(&data[0], &address); + KAMI_PACK_U32(&data[4], &buffer); + KAMI_PACK_U32(&data[8], &size); + + if (KamiSendPxiCommand(KAMI_NVRAM_IO, 12, (u8)is_read)) + { + for (i = 0; i < 12; i+=3) + { + KamiSendPxiData(&data[i]); + } + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + Name: kamiClearNandErrorLog + + Description: NVRAMのNANDエラー情報をクリアします。 + + Arguments: None. + + Returns: + *---------------------------------------------------------------------------*/ + +KAMIResult kamiClearNandErrorLog( void ) +{ + OSIntrMode enabled; + + // ロック + enabled = OS_DisableInterrupts(); + if (kamiWork.lock) + { + (void)OS_RestoreInterrupts(enabled); + return KAMI_RESULT_BUSY; + } + kamiWork.lock = TRUE; + (void)OS_RestoreInterrupts(enabled); + + kamiWork.callback = NULL; + kamiWork.arg = 0; + kamiWork.data = 0; + + if (KamiSendPxiCommand(KAMI_CLEAR_NAND_ERRORLOG, 0, (u8)0)) + { + KamiWaitBusy(); + return (KAMIResult)kamiWork.result; + } + return KAMI_RESULT_SEND_ERROR; +} + +/*---------------------------------------------------------------------------* + PXI関連 + *---------------------------------------------------------------------------*/ + +static BOOL KamiSendPxiCommand(KamiCommand command, u8 size, u8 data) +{ + u32 pxiData = (u32)(KAMITEST_PXI_START_BIT | + ((command << KAMITEST_PXI_COMMAND_SHIFT) & KAMITEST_PXI_COMMAND_MASK) | + ((size << KAMITEST_PXI_DATA_NUMS_SHIFT) & KAMITEST_PXI_DATA_NUMS_MASK) | + ((data << KAMITEST_PXI_1ST_DATA_SHIFT) & KAMITEST_PXI_1ST_DATA_MASK)); + if (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + return FALSE; + } + return TRUE; +} + +static void KamiSendPxiData(u8 *pData) +{ + u32 pxiData = (u32)((pData[0] << 16) | (pData[1] << 8) | pData[2]); + while (0 > PXI_SendWordByFifo(PXI_FIFO_TAG_KAMITEST, pxiData, 0)) + { + } +} + +static void KamiPxiCallback(PXIFifoTag tag, u32 data, BOOL err) +{ +#pragma unused( tag ) + if (err) + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + if (data & KAMITEST_PXI_START_BIT) // 先頭データ + { + if (data & KAMITEST_PXI_RESULT_BIT) + { + kamiWork.total = (u8)((data & KAMITEST_PXI_DATA_NUMS_MASK) >> KAMITEST_PXI_DATA_NUMS_SHIFT); + kamiWork.current = 0; + kamiWork.command = (KamiCommand)((data & KAMITEST_PXI_COMMAND_MASK) >> KAMITEST_PXI_COMMAND_SHIFT); + kamiWork.result = (KAMIPxiResult)((data & KAMITEST_PXI_1ST_DATA_MASK) >> KAMITEST_PXI_1ST_DATA_SHIFT); + } + else // 未知のデータ + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + } + else // 後続データ + { + if (kamiWork.data == NULL) + { + KamiDone(KAMI_RESULT_FATAL_ERROR); + return; + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0xFF0000) >> 16); + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0x00FF00) >> 8); + } + if (kamiWork.current < kamiWork.total-1) + { + kamiWork.data[kamiWork.current++] = (u8)((data & 0x0000FF) >> 0); + } + } + if (kamiWork.current == kamiWork.total-1) + { + KAMIResult result; + switch (kamiWork.result) + { + case KAMI_PXI_RESULT_SUCCESS: // alias KAMI_PXI_RESULT_SUCCESS_TRUE + result = KAMI_RESULT_SUCCESS; // alias KAMI_RESULT_SUCCESS_TRUE + break; + case KAMI_PXI_RESULT_SUCCESS_FALSE: + result = KAMI_RESULT_SUCCESS_FALSE; + break; + case KAMI_PXI_RESULT_INVALID_COMMAND: + result = KAMI_RESULT_INVALID_COMMAND; + break; + case KAMI_PXI_RESULT_INVALID_PARAMETER: + result = KAMI_RESULT_INVALID_PARAMETER; + break; + case KAMI_PXI_RESULT_ILLEGAL_STATUS: + result = KAMI_RESULT_ILLEGAL_STATUS; + break; + case KAMI_PXI_RESULT_BUSY: + result = KAMI_RESULT_BUSY; + break; + default: + result = KAMI_RESULT_FATAL_ERROR; + } + KamiDone(result); + return; + } +} + +extern void PXIi_HandlerRecvFifoNotEmpty(void); +static void KamiWaitBusy(void) +{ + volatile BOOL *p = &kamiWork.lock; + + while (*p) + { + if (OS_GetCpsrIrq() == OS_INTRMODE_IRQ_DISABLE) + { + PXIi_HandlerRecvFifoNotEmpty(); + } + } +} + +static void KamiDone(KAMIResult result) +{ + KAMICallback callback = kamiWork.callback; + void* arg = kamiWork.arg; + kamiWork.callback = NULL; + kamiWork.arg = NULL; + if (kamiWork.lock) + { + kamiWork.lock = FALSE; + } + if (callback) + { + callback(result, arg); + } +} diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_write_nandfirm.c b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_write_nandfirm.c new file mode 100644 index 00000000..78d29ca0 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/kami_write_nandfirm.c @@ -0,0 +1,300 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: kami_write_nandfirm.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include "kami_font.h" +#include "kami_pxi.h" + +#include +#include "kami_write_nandfirm.h" + +/*---------------------------------------------------------------------------* + マクロ定義 + *---------------------------------------------------------------------------*/ + +// NANDファーム書き込みの際にNVRAMの未割り当て領域+予約領域を0クリアする場合は定義します(開発用) +//#define CLEAR_NON_ASIGNED_AREA_AND_RESERVED_AREA_ALL + +#define ROUND_UP(value, alignment) \ + (((u32)(value) + (alignment-1)) & ~(alignment-1)) + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +#define NAND_BLOCK_BYTE 0x200 +#define NAND_FIRM_START_OFFSET 0x200 + +#define NVRAM_PAGE_SIZE 0x100 +#define NVRAM_NORFIRM_RESERVED_ADDRESS 0x200 +#define NVRAM_NORFIRM_NANDBOOT_FLAG_OFFSET 0xff +#define NVRAM_NORFIRM_NANDBOOT_FLAG 0x80 + +#define NVRAM_NON_ASIGNED_AREA_ADDRESS 0x300 + +/*---------------------------------------------------------------------------* + 内部変数定義 + *---------------------------------------------------------------------------*/ + +static u8 sNvramPageSizeBuffer[NVRAM_PAGE_SIZE] ATTRIBUTE_ALIGN(32); // ARM7からアクセスするためスタックでは駄目 +static u32 sReservedAreaEndAddress; + +/*---------------------------------------------------------------------------* + Name: kamiWriteNandfirm + + Description: + + Arguments: no + + Returns: None. + *---------------------------------------------------------------------------*/ +BOOL kamiWriteNandfirm(const char* pFullPath, NAMAlloc allocFunc, NAMFree freeFunc) +{ + FSFile file; + + BOOL open_is_ok; + BOOL read_is_ok; + u8* pTempBuf; + u32 file_size; + u32 alloc_size; + u32 write_size; + BOOL result = TRUE; + u16 crc_w1, crc_w2; + u16 crc_r1, crc_r2; + u16 crc_norfirm_reserved_area_w, crc_norfirm_reserved_area_r; +#ifdef CLEAR_NON_ASIGNED_AREA_AND_RESERVED_AREA_ALL + u32 write_offset; +#endif + + // .nandファイルオープン + FS_InitFile(&file); + open_is_ok = FS_OpenFile(&file, pFullPath); + if (!open_is_ok) + { + OS_Warning("Failure! FS_OpenFile"); + return FALSE; + } + + // サイズチェック + file_size = FS_GetFileLength(&file) ; + if (file_size > (800*1024)) + { + kamiFontPrintfConsoleEx(1, "too big file size!\n"); + FS_CloseFile(&file); + return FALSE; + } + + // バッファ確保 + alloc_size = ROUND_UP(file_size, 32) ; + pTempBuf = allocFunc( alloc_size ); + if (pTempBuf == NULL) + { + kamiFontPrintfConsoleEx(1, "Fail Alloc()!\n"); + FS_CloseFile(&file); + return FALSE; + } + + // .nandファイルリード + DC_InvalidateRange(pTempBuf, alloc_size); + read_is_ok = FS_ReadFile( &file, pTempBuf, (s32)file_size ); + DC_StoreRange(pTempBuf, file_size); + if (!read_is_ok) + { + kamiFontPrintfConsoleEx(1, "Fail FS_ReadFile!\n"); + FS_CloseFile(&file); + freeFunc(pTempBuf); + return FALSE; + } + + // ファイルクローズ + FS_CloseFile(&file); + + // 書き込み前のCRCを計算 + crc_w1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + crc_w2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // まずNORHeaderDS領域を書き込む(40byte?) + if (kamiNvramWrite(0, (void*)pTempBuf, sizeof(NORHeaderDS)) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + + // CRCを計算するので念のためにクリアしてからリードする + MI_CpuFill8( pTempBuf, 0xee, sizeof(NORHeaderDS) ); + DC_FlushRange(pTempBuf, sizeof(NORHeaderDS)); + + // CRCチェックのためNvramからリード + if (kamiNvramRead(0, pTempBuf, sizeof(NORHeaderDS) ) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramRead()!\n"); + } + DC_StoreRange(pTempBuf, sizeof(NORHeaderDS)); + + // 書き込み後のCRCを計算 + crc_r1 = SVC_GetCRC16( 0xffff, pTempBuf, sizeof(NORHeaderDS) ); + + // NVRAM先頭部分のCRC比較 + if ( crc_w1 != crc_r1 ) + { + freeFunc(pTempBuf); + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w1, crc_r1); + return FALSE; + } + + // nandfirm 起動フラグを立てる + MI_CpuClear8( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + sNvramPageSizeBuffer[NVRAM_NORFIRM_NANDBOOT_FLAG_OFFSET] = NVRAM_NORFIRM_NANDBOOT_FLAG; + DC_FlushRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE); + + // NORファームリザーブ領域の書き込みデータのCRCを計算 + crc_norfirm_reserved_area_w = SVC_GetCRC16( 0xffff, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + + if (kamiNvramWrite(NVRAM_NORFIRM_RESERVED_ADDRESS, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + + // CRCを計算するので念のためにクリアしてからリードする + MI_CpuFill8( sNvramPageSizeBuffer, 0xee, NVRAM_PAGE_SIZE ); + + // 読み込みはARM7が直接メモリに書き出すため + DC_FlushRange(sNvramPageSizeBuffer, NVRAM_PAGE_SIZE); + + if (kamiNvramRead(NVRAM_NORFIRM_RESERVED_ADDRESS, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramRead()\n"); + result = FALSE; + } + + // 書き込み後のCRCを計算 + DC_StoreRange(sNvramPageSizeBuffer, NVRAM_PAGE_SIZE); + crc_norfirm_reserved_area_r = SVC_GetCRC16( 0xffff, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + + // NORファームリザーブ領域のCRC比較 + if ( crc_norfirm_reserved_area_w != crc_norfirm_reserved_area_r ) + { + kamiFontPrintfConsoleEx(1, "Fail! Norfirm Reserved Area CRC check %x!=%x\n", crc_norfirm_reserved_area_w, crc_norfirm_reserved_area_r); + result = FALSE; + } + +#ifdef CLEAR_NON_ASIGNED_AREA_AND_RESERVED_AREA_ALL + DC_InvalidateRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + // 未割り当て領域+予約領域を0クリアします(開発用) + if (kamiNvramRead(NVRAM_CONFIG_DATA_OFFSET_ADDRESS, &sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramRead()\n"); + result = FALSE; + } + sReservedAreaEndAddress = (u32)(*(u16 *)sNvramPageSizeBuffer << NVRAM_CONFIG_DATA_OFFSET_SHIFT) - 0xA00;// TWL WiFi設定 + NTR WiFi設定 を差し引く + //OS_Printf("end = %x\n", sReservedAreaEndAddress); + + MI_CpuFill8( sNvramPageSizeBuffer, 0x00, NVRAM_PAGE_SIZE ); + DC_FlushRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + + for (write_offset=NVRAM_NON_ASIGNED_AREA_ADDRESS; write_offset < sReservedAreaEndAddress; write_offset += NVRAM_PAGE_SIZE) + { + if (kamiNvramWrite(write_offset, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + } + //OS_Printf("write_offset = %x\n", write_offset); +#else + // 未割り当て領域先頭256byte+予約領域を0クリアします + + MI_CpuFill8( sNvramPageSizeBuffer, 0x00, NVRAM_PAGE_SIZE ); + DC_FlushRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + + if (kamiNvramWrite(NVRAM_NON_ASIGNED_AREA_ADDRESS, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } + + DC_InvalidateRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + if (kamiNvramRead(NVRAM_CONFIG_DATA_OFFSET_ADDRESS, &sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramRead()\n"); + result = FALSE; + } + sReservedAreaEndAddress = (u32)(*(u16 *)sNvramPageSizeBuffer << NVRAM_CONFIG_DATA_OFFSET_SHIFT) - 0xA00;// TWL WiFi設定 + NTR WiFi設定 を差し引く + + MI_CpuFill8( sNvramPageSizeBuffer, 0x00, NVRAM_PAGE_SIZE ); + DC_FlushRange( sNvramPageSizeBuffer, NVRAM_PAGE_SIZE ); + + if (kamiNvramWrite(sReservedAreaEndAddress - 0x100, sNvramPageSizeBuffer, NVRAM_PAGE_SIZE) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "Fail kamiNvramWrite()\n"); + result = FALSE; + } +#endif + + // NANDログ情報のクリア + if (kamiClearNandErrorLog() != KAMI_RESULT_SUCCESS) + { + kamiFontPrintfConsoleEx(1, "Fail kamiClearNandErrorLog()\n"); + result = FALSE; + } + +// kamiFontPrintfConsoleEx(0, "NAND Firm Import Start!\n"); + + // NAND書き込み + write_size = file_size/NAND_BLOCK_BYTE + (file_size % NAND_BLOCK_BYTE != 0); + kamiNandWrite( NAND_FIRM_START_OFFSET/NAND_BLOCK_BYTE, pTempBuf+NAND_FIRM_START_OFFSET, write_size ); // ブロック単位、バイト単位、ブロック単位 + +// kamiFontPrintfConsoleEx(0, "Start CRC check\n"); + kamiFontLoadScreenData(); + + // CRCを計算するので念のためにクリアしてからリードする + MI_CpuClear8( pTempBuf, file_size ); + DC_FlushRange(pTempBuf, file_size); + + // CRCチェックのためNandからリード + if (kamiNandRead(0, pTempBuf, file_size/512 ) == KAMI_RESULT_SEND_ERROR) + { + kamiFontPrintfConsoleEx(1, "kamiNandRead ... %s!\n", "ERROR"); + } + DC_StoreRange(pTempBuf, file_size); + + // 書き込み後のCRCを計算 + crc_r2 = SVC_GetCRC16( 0xffff, pTempBuf+512, file_size-512 ); + + // NAND部分についてのCRCチェック + if (crc_w2 == crc_r2) + { +// kamiFontPrintfConsoleEx(0, "Success! CRC check %x==%x\n", crc_w2, crc_r2); + } + else + { + result = FALSE; + kamiFontPrintfConsoleEx(1, "Fail! CRC check %x!=%x\n", crc_w2, crc_r2); + } + + // メモリ解放 + freeFunc(pTempBuf); + + return result; +} + + + diff --git a/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/keypad.c b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/keypad.c new file mode 100644 index 00000000..155c4bc2 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/ARM9.TWL/src/keypad.c @@ -0,0 +1,85 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - NandInitializer + File: keypad.c + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#include +#include "keypad.h" + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ + +#define KEY_REPEAT_TRIGGER_START 20 +#define KEY_REPEAT_TRIGGER_TERM 5 + +/*---------------------------------------------------------------------------* + 内部変数定義 + *---------------------------------------------------------------------------*/ + +static u16 Cont; +static u16 Trg; +static u16 Release; +static u16 RepeatTrg; +static u8 key = 60; + +static int repeat_counter; + +/*---------------------------------------------------------------------------* + 内部関数定義 + *---------------------------------------------------------------------------*/ +void +kamiPadRead(void) +{ + u16 ReadData; + + ReadData = PAD_Read(); + Trg = (u16)(ReadData & (ReadData ^ Cont)); + Release = (u16)(Cont & (ReadData ^ Cont)); + Cont = ReadData; + + RepeatTrg = Trg; + if (++repeat_counter > (KEY_REPEAT_TRIGGER_START + KEY_REPEAT_TRIGGER_TERM)) + { + repeat_counter = KEY_REPEAT_TRIGGER_START; + } + if (repeat_counter == KEY_REPEAT_TRIGGER_START) + { + RepeatTrg = ReadData; + } + if (!ReadData) + { + repeat_counter = 0; + } +} + +BOOL +kamiPadIsTrigger(u16 key) +{ + return (Trg & key)? TRUE : FALSE; +} + +BOOL +kamiPadIsRepeatTrigger(u16 key) +{ + return (RepeatTrg & key)? TRUE : FALSE; +} + +BOOL +kamiPadIsPress(u16 key) +{ + return (Cont & key)? TRUE : FALSE; +} + diff --git a/build/systemMenu_tools/SystemUpdater/Makefile b/build/systemMenu_tools/SystemUpdater/Makefile index 96746652..359ec88e 100644 --- a/build/systemMenu_tools/SystemUpdater/Makefile +++ b/build/systemMenu_tools/SystemUpdater/Makefile @@ -21,10 +21,10 @@ include $(TWLSDK_ROOT)/build/buildtools/commondefs #---------------------------------------------------------------------------- -LAUNCHER_DIR = ../Launcher -MACHINESETTINGS_DIR = ../MachineSettings -WLANFIRM_DIR = ../wlanfirm -NANDFIRM_DIR = ../../nandfirm/menu-launcher +LAUNCHER_DIR = $(TWL_IPL_RED_ROOT)/build/systemMenu_RED/Launcher +MACHINESETTINGS_DIR = $(TWL_IPL_RED_ROOT)/build/systemMenu_RED/MachineSettings +WLANFIRM_DIR = $(TWL_IPL_RED_ROOT)/build/systemMenu_RED/wlanfirm +NANDFIRM_DIR = $(TWL_IPL_RED_ROOT)/build/nandfirm/menu-launcher SUBDIRS = $(LAUNCHER_DIR) \ $(MACHINESETTINGS_DIR) \ diff --git a/build/systemMenu_tools/SystemUpdater/common/include/fifo.h b/build/systemMenu_tools/SystemUpdater/common/include/fifo.h new file mode 100644 index 00000000..2cba5be7 --- /dev/null +++ b/build/systemMenu_tools/SystemUpdater/common/include/fifo.h @@ -0,0 +1,81 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - SystemUpdater - include + File: fifo.h + + Copyright 2008 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. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +#ifndef TWL_KAMI_TEST_FIFO_H_ +#define TWL_KAMI_TEST_FIFO_H_ + +#include + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +#define PXI_FIFO_TAG_KAMITEST PXI_FIFO_TAG_USER_1 + +#define KAMI_PXI_CONTINUOUS_PACKET_MAX 10 +#define KAMITEST_PXI_DATA_SIZE_MAX ((KAMI_PXI_CONTINUOUS_PACKET_MAX-1)*3+1) // 最大データ数 + +#define KAMITEST_PXI_START_BIT 0x02000000 // 先頭パケットを意味する +#define KAMITEST_PXI_RESULT_BIT 0x00008000 // PXIの応答を示す + +#define KAMITEST_PXI_COMMAND_SHIFT 8 // コマンド格納部分の位置 +#define KAMITEST_PXI_COMMAND_MASK 0x00007f00 // コマンド格納部分のマスク +#define KAMITEST_PXI_DATA_NUMS_MASK 0x00ff0000 // データ数領域 +#define KAMITEST_PXI_DATA_NUMS_SHIFT 16 // データ数位置 +#define KAMITEST_PXI_1ST_DATA_MASK 0x000000ff // 先頭パケットのデータ領域 +#define KAMITEST_PXI_1ST_DATA_SHIFT 0 // 先頭パケットのデータ位置 + +#ifdef __cplusplus +extern "C" { +#endif + +/*===========================================================================*/ + +typedef enum KAMIPxiResult +{ + KAMI_PXI_RESULT_SUCCESS = 0, // 処理成功 (void/void*型) // 場合により後続パケットあり + KAMI_PXI_RESULT_SUCCESS_TRUE = 0, // 処理成功 (BOOL型) + KAMI_PXI_RESULT_SUCCESS_FALSE, // 処理成功 (BOOL型) + KAMI_PXI_RESULT_INVALID_COMMAND, // 不正なPXIコマンド + KAMI_PXI_RESULT_INVALID_PARAMETER, // 不正なパラメータ + KAMI_PXI_RESULT_ILLEGAL_STATUS, // KAMIの状態により処理を実行不可 + KAMI_PXI_RESULT_BUSY, // 他のリクエストを実行中 + KAMI_PXI_RESULT_FATAL_ERROR, // その他何らかの原因で処理に失敗 + KAMI_PXI_RESULT_MAX +} +KAMIPxiResult; + + +typedef enum KamiCommand +{ + KAMI_TEST_COMMAND, + KAMI_NAND_IO, + KAMI_NVRAM_IO, + KAMI_CLEAR_NAND_ERRORLOG +} +KamiCommand; + +/*===========================================================================*/ + + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* TWL_KAMI_TEST_FIFO_H_ */ + +/*---------------------------------------------------------------------------* + End of file + *---------------------------------------------------------------------------*/ diff --git a/build/systemMenu_tools/SystemUpdater/data/Makefile b/build/systemMenu_tools/SystemUpdater/data/Makefile index e470d0e3..c09d726b 100644 --- a/build/systemMenu_tools/SystemUpdater/data/Makefile +++ b/build/systemMenu_tools/SystemUpdater/data/Makefile @@ -37,14 +37,14 @@ do-build : HNAA.tad \ HNBA.tad \ HNCA.tad \ menu_launcher.nand - -HNAA.tad: ../../Launcher/ARM9/bin/ARM9-TS.LTD/$(TWL_BUILD_DIR)/main.srl + +HNAA.tad: ../../../systemMenu_RED/Launcher/ARM9/bin/ARM9-TS.LTD/$(TWL_BUILD_DIR)/main.srl $(MAKETAD) -s $< $(MAKETAD_FLAGS) -o $@ -HNBA.tad: ../../MachineSettings/ARM9/bin/ARM9-TS.LTD/$(TWL_BUILD_DIR)/main.srl +HNBA.tad: ../../../systemMenu_RED/MachineSettings/ARM9/bin/ARM9-TS.LTD/$(TWL_BUILD_DIR)/main.srl $(MAKETAD) -s $< $(MAKETAD_FLAGS) -o $@ -HNCA.tad: ../../wlanfirm/HNCA.srl +HNCA.tad: ../../../systemMenu_RED/wlanfirm/HNCA.srl $(MAKETAD) -s $< $(MAKETAD_FLAGS) -o $@ menu_launcher.nand: ../../../nandfirm/menu-launcher/menu_launcher-$(TWL_BUILD_TYPE)$(CODEGEN_ARCH).nand