diff --git a/build/tests/fatfs/nand_formatter/ARM7/Makefile b/build/tests/fatfs/nand_formatter/ARM7/Makefile new file mode 100644 index 0000000..2ea818c --- /dev/null +++ b/build/tests/fatfs/nand_formatter/ARM7/Makefile @@ -0,0 +1,62 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - CAMERA - demos - camera-1 +# File: Makefile +# +# Copyright 2007 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. +# +# $Log: $ +# $NoKeywords: $ +#---------------------------------------------------------------------------- + +SUBDIRS = + +LCFILE_SPEC = main.lsf + +#---------------------------------------------------------------------------- + +#TWL_CODEGEN = THUMB +TWL_PROC = ARM7 + +TARGET_BIN = main.axf + +SRCS = main.c + +INCDIR += $(TWLSDK_ROOT)/include/twl \ + $(TWLSDK_ROOT)/include/twl/devices/sdmc/ARM7 \ + $(TWLSDK_ROOT)/include/twl/fatfs/ARM7 \ + +LLIBRARY_DIRS = $(TWLSDK_ROOT)/lib/ARM-BB/Release +LLIBRARIES = libfatfs_sp.twl.a \ + libsd_sp.twl.a \ + libcs_sp.twl.a \ + +#SRCDIR = # using default +#LCFILE = # using default + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + + +#---------------------------------------------------------------------------- + +do-build: $(TARGETS) + +# .sbin +#$(BINDIR)/$(TARGET_BIN_BASENAME).sbin : $(BINDIR)/$(TARGET_BIN_BASENAME).axf + objcopy -I elf32-little -O binary $(BINDIR)/$(TARGET_BIN_BASENAME).axf $(BINDIR)/$(TARGET_BIN_BASENAME).sbin + + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + + + + + +#===== End of Makefile ===== diff --git a/build/tests/fatfs/nand_formatter/ARM7/main.lsf b/build/tests/fatfs/nand_formatter/ARM7/main.lsf new file mode 100644 index 0000000..0c8cdcc --- /dev/null +++ b/build/tests/fatfs/nand_formatter/ARM7/main.lsf @@ -0,0 +1,40 @@ +#---------------------------------------------------------------------------- +# Project: TwlSDK - include +# File: ARM7-BB.lsf +# +# Copyright 2007 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. +# +# $Log: $ +# $NoKeywords: $ +#---------------------------------------------------------------------------- +# +# Nitro LCF SPEC FILE +# + +Static $(TARGET_NAME) +{ + Address 0x02010000 + Library crt0.o + StackSize 1024 512 +} + +#Objects on MAIN RAM # nothing for elf2bin +#Autoload MAIN +#{ +# Address 0x027e0000 +# Library +#} + +Autoload MAIN +{ + Address 0x02020000 + Object $(OBJS_STATIC) + Library $(LLIBS) $(GLIBS) $(CW_LIBS) + Object * (.wram) +} diff --git a/build/tests/fatfs/nand_formatter/ARM7/src/main.c b/build/tests/fatfs/nand_formatter/ARM7/src/main.c new file mode 100644 index 0000000..34edef3 --- /dev/null +++ b/build/tests/fatfs/nand_formatter/ARM7/src/main.c @@ -0,0 +1,490 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - nand_formatter_kmc + File: main.c + + Copyright 2007 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. + + $Log: main.c,v $ + $NoKeywords: $ + *---------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +#define DBG_PRINTF OS_TPrintf +#define DBG_CHAR OS_PutChar +#define kmc_getchar() ((char)vlink_dos_get_console()) +#define kmc_putchar(x) vlink_dos_put_console((char)(x)) + + + + + +extern void nandSetFormatRequest( u16 partition_num, u32* partition_sectors); + + +/*---------------------------------------------------------------------------* + 定数定義 + *---------------------------------------------------------------------------*/ +#define PRINTDEBUG OS_TPrintf + +//容量 +#define RAW_PARTITION_MBYTES 16 +#define FAT0_PARTITION_MBYTES 32 +#define FAT1_PARTITION_MBYTES 32 +#define FAT2_PARTITION_MBYTES 32 + + +//配列partition_MB_sizeのインデックス +#define INDEX_RAW_PARTITION 0 +#define INDEX_FAT0_PARTITION 1 +#define INDEX_FAT1_PARTITION 2 +#define INDEX_FAT2_PARTITION 3 +#define INDEX_FAT3_PARTITION 4 + + +/*---------------------------------------------------------------------------* + 内部関数定義 + *---------------------------------------------------------------------------*/ +static OSHeapHandle InitializeAllocateSystem(void); +static void VBlankIntr(void); + + +/*---------------------------------------------------------------------------* + + *---------------------------------------------------------------------------*/ +static u16 path_str[512/sizeof(u16)]; //ロングファイル名 + + +static BOOL getchar_yes_no_prompt(void) +{ + char c; + while( 1 ) { + c = kmc_getchar(); + kmc_putchar(c); + if( c == 'y' ) { + return TRUE; + } + else if( c == 'n' ) { + return FALSE; + } + else if( c == 'q' ) { + DBG_PRINTF("\nEnter infinite loop\n"); + while( 1 ) { ; } + } + else { + DBG_PRINTF("\nInput y or n\n"); + } + } +} + +static int pow10( int count) +{ + int i, result; + + result = 1; + for( i=0; i= '0')&&(c <= '9')) { + kmc_putchar( c); + size_num[i++] = ((int)c) % ((int)'0'); + if( i==3) { break;} + } + if( c == '\b') { + if( i != 0) { i--;} + kmc_putchar( c); + } + } + keta = i; + + result_num = 0; + for( j=0; j "); +// partition_MB_size[INDEX_FAT3_PARTITION] = get_number_prompt(); +// DBG_PRINTF( " (%d MBytes)\n\n", partition_MB_size[INDEX_FAT3_PARTITION]); + break; + } +#endif +// DBG_PRINTF( "%d FAT Partitions.\n", nand_fat_partition_num); + + + /*----- nandfirmチェック -----*/ +// pc_raw_read( 5, (byte*)block_buf, 1, 1, TRUE); + nandRtfsIo( 5, 1, (byte*)block_buf, 1, TRUE); + arm9_ofs = *(u32*)(((u8*)block_buf)+0x20); + arm9_size = *(u32*)(((u8*)block_buf)+0x2C); + arm7_ofs = *(u32*)(((u8*)block_buf)+0x30); + arm7_size = *(u32*)(((u8*)block_buf)+0x3C); + + if (arm9_ofs == 0x400 || arm7_ofs == 0x400) // simple image + { + /* + 0x000 +-------------------+ + | MBR | + 0x200 +-------------------+ + | Header (genuine) | + 0x400 +-------------------+ <- arm9_ofs or arm7_ofs by Header (genuine) + | ARM7/ARM9 IMAGE | + I+0x400 +-------------------+ <- nand_firm_size + */ + nand_firm_size = (arm9_ofs < arm7_ofs ? arm7_ofs + arm7_size : arm9_ofs + arm9_size); + } + if (arm9_ofs == 0x800 || arm7_ofs == 0x800) // double header image + { + /* + 0x000 +-------------------+ + | MBR | + 0x200 +-------------------+ + | Header (genuine) | + 0x400 +-------------------+ + | Header (original) | + 0x600 +-------------------+ + | Header (mirrored) | + 0x800 +-------------------+ <- arm9_ofs or arm7_ofs by Header (genuine) + | ARM7/ARM9 IMAGE | + | + reserved | + I+0x800 +-------------------+ + | Header (original) | + I+0xA00 +-------------------+ + | Header (mirrored) | + I+0xC00 +-------------------+ <- arm9_ofs or arm7_ofs by Header (mirroed) + | reserved for | + | ARM7/ARM9 IMAGE | + 2*I+0xC00 +-------------------+ <- nand_firm_size + */ + u32 arm9_orig = arm9_ofs; + nandRtfsIo( 5, 3, (byte*)block_buf, 1, TRUE); // get header for mirrored image + arm9_ofs = *(u32*)(((u8*)block_buf)+0x20); + arm7_ofs = *(u32*)(((u8*)block_buf)+0x30); + nand_firm_size = (arm9_ofs - arm9_orig) * 2 + 0x400; + } + if (nand_firm_size) + { + DBG_PRINTF( "nandfirm found. (size:0x%x bytes)\n", nand_firm_size); + nand_firm_size = (nand_firm_size / 1024 / 1024) + + (((nand_firm_size % (1024*1024)) != 0)? 1:0); +// DBG_PRINTF( "firm %dMB, raw %dMB\n", nand_firm_size, partition_MB_size[INDEX_RAW_PARTITION]); + + if( nand_firm_size > partition_MB_size[INDEX_RAW_PARTITION]) { + partition_MB_size[INDEX_RAW_PARTITION] = nand_firm_size; + /*RAWサイズを変えたサイン*/ + OS_SetDebugLED(0x0F); + goto NAND_FLASH_FORMAT_START; + } + }else{ +// DBG_PRINTF( "nandfirm is not found.\n"); + } + +NAND_FLASH_FORMAT_START: + /*------------------------------*/ + + + /*--- パーティション構成をセクタ単位にしてライブラリに要求 ---*/ + for( i=0; i<5; i++) { + partition_MB_size[i] *= ((1024 * 1024) / 512); +// PRINTDEBUG( "p%d : %d\n", i, partition_MB_size[i]); + } + nandSetFormatRequest( nand_fat_partition_num, partition_MB_size); + /*------------------------------------------------------------*/ + + /*マウント*/ + if( nandRtfsAttach( 5, 0) == FALSE) { //nandパーティション0をFドライブにする +// PRINTDEBUG( "nandRtfsAttach failed.\n"); + goto NAND_FLASH_FORMAT_END; + }else{ + if( nandRtfsAttach( 5, 0) == FALSE) { + }else{ +// PRINTDEBUG( "nandRtfsAttach error!.\n"); + goto NAND_FLASH_FORMAT_END; + } + } + + CS_Sjis2Unicode( path_str, "F:"); + if( !rtfs_pc_set_default_drive( (unsigned char*)path_str)) { +// PRINTDEBUG( "pc_set_default_drive failed\n"); + goto NAND_FLASH_FORMAT_END; + } + + + /**/ +// PRINTDEBUG( "pc_check_disk start. please wait.\n"); +// pc_check_disk( (byte*)"F:", &dstat, 0, 1, 1); +// PRINTDEBUG( "pc_check_disk end.\n"); + + + /*--- MBR書き込み、パーティション0フォーマット ---*/ + if( !rtfs_pc_get_media_parms( (byte*)path_str, &geometry)) { +// PRINTDEBUG( "Invalid parameter. (size over)\n"); + goto NAND_FLASH_FORMAT_END; + } + + /**/ + if( !pc_format_media( (byte*)path_str, &geometry)) { +// PRINTDEBUG( "pc_format_media failed\n"); + goto NAND_FLASH_FORMAT_END; + } +// PRINTDEBUG( "build MBR success.\n"); + + /*ボリュームフォーマット*/ + if( !pc_format_volume( (byte*)path_str, &geometry)) { +// PRINTDEBUG( "pc_format_volume (p0) failed\n"); + goto NAND_FLASH_FORMAT_END; + } +// PRINTDEBUG( "format FAT partition 0 success.\n"); + /*-------------------------------------------------*/ + + + + /*マウント(F:p0, G:p1, H:p2, I:p3)*/ + for( i=1; i + +static void VBlankIntr(void); + +/*---------------------------------------------------------------------------* + Name: TwlMain + + Description: main + + Arguments: None + + Returns: None + *---------------------------------------------------------------------------*/ +void TwlMain() +{ + // 初期化 + OS_Init(); + GX_Init(); + OS_InitTick(); + + // Vブランク割り込み設定 + OS_SetIrqFunction(OS_IE_V_BLANK, VBlankIntr); + (void)OS_EnableIrqMask(OS_IE_V_BLANK); + (void)OS_EnableIrq(); + (void)GX_VBlankIntr(TRUE); + { + u16 bg_color = GX_RGB(31, 0, 0); + GX_LoadBGPltt(&bg_color, 0, sizeof(u16)); + } + + while (1) + { + OS_WaitVBlankIntr(); + } +} + +//-------------------------------------------------------------------------------- +// Vブランク割り込み処理 +// +void VBlankIntr(void) +{ + OS_SetIrqCheckFlag(OS_IE_V_BLANK); // checking VBlank interrupt +} diff --git a/build/tests/fatfs/nand_formatter/Makefile b/build/tests/fatfs/nand_formatter/Makefile new file mode 100644 index 0000000..6988d42 --- /dev/null +++ b/build/tests/fatfs/nand_formatter/Makefile @@ -0,0 +1,42 @@ +#! make -f +#---------------------------------------------------------------------------- +# Project: TwlSDK - build +# File: Makefile +# +# Copyright 2007 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. +# +# $Log: $ +# $NoKeywords: $ +#---------------------------------------------------------------------------- + +SUBDIRS = \ + ARM7 \ + ARM9 \ + +#---------------------------------------------------------------------------- + +TARGET_BIN = nand_formatter_kmc.srl + +MAKEROM_ARM9 = ARM9/bin/$(TWL_BUILDTYPE_ARM9)/main.axf +MAKEROM_ARM7 = ARM7/bin/$(TWL_BUILDTYPE_ARM7)/main.axf + +#---------------------------------------------------------------------------- + +include $(TWLSDK_ROOT)/build/buildtools/commondefs + +#---------------------------------------------------------------------------- + +ifeq ($(TWL_PLATFORM),TS) +do-build: $(TARGETS) +endif + +include $(TWLSDK_ROOT)/build/buildtools/modulerules + + +#===== End of Makefile =====