Exemple #1
0
void plat_boot(void){
	int i;
	for(i=0;init[i];i++){
		init[i]();
	}
	init_sys_mmu();
	start_mmu();
//	timer_init();

	init_page_map();
	kmalloc_init();

	ramdisk_driver_init();
	romfs_init();

	struct inode *node;

	char *buf=(char *)0x30100000;

	if((node=fs_type[ROMFS]->namei(fs_type[ROMFS],"main.bin"))==(void *)0){
		printk("inode read eror\n");
		goto HALT;
	}
	

	if(fs_type[ROMFS]->device->dout(fs_type[ROMFS]->device,buf,fs_type[ROMFS]->get_daddr(node),node->dsize)){
		printk("dout error\n");
		goto HALT;
	}

	exec(buf);
	
HALT:
	while(1);
}
Exemple #2
0
void plat_boot(void) {
    int i;
    for(i=0; init[i]; i++) {
        init[i]();
    }
    init_sys_mmu();
    start_mmu();
//	timer_init();

    init_page_map();
    kmalloc_init();

    ramdisk_driver_init();
    romfs_init();

    struct inode *node;
    char buf[128];

    node=fs_type[ROMFS]->namei(fs_type[ROMFS],"number.txt");

    fs_type[ROMFS]->device->dout(fs_type[ROMFS]->device,buf,fs_type[ROMFS]->get_daddr(node),node->dsize);

    for(i=0; i<sizeof(buf); i++) {
        printk("%c ",buf[i]);
    }

    while(1);
}
Exemple #3
0
void plat_boot(void) {
    int i;
    for (i=0; init[i]; i++) {
        init[i]();
    }
    init_sys_mmu();
    start_mmu();
//    timer_init();

    init_page_map();
    kmalloc_init();
    ramdisk_driver_init();
    romfs_init();

    struct inode *node;
    struct elf32_phdr *phdr;
    struct elf32_ehdr *ehdr;
    int phnum, pos, dpos;
    char *buf;

    if ((buf = (char *)kmalloc(1024)) == (void *)0) {
        printk("get free pages error\n");
        goto HALT;
    }

    if ((node = fs_type[ROMFS]->namei(fs_type[ROMFS], "main")) == (void *)0) {
        printk("inode read error\n");
        goto HALT;
    }

    if (fs_type[ROMFS]->device->dout(fs_type[ROMFS]->device, buf, \
                fs_type[ROMFS]->get_daddr(node), node->dsize)) {
        printk("dount error\n");
        goto HALT;
    }

    ehdr = (struct elf32_ehdr *)buf;
    phdr = (struct elf32_phdr *)((char *)buf+ehdr->e_phoff);
    
    for (i = 0; i< ehdr->e_phnum; i++) {
        if (CHECK_PT_TYPE_LOAD(phdr)) {
            if (fs_type[ROMFS]->device->dout(fs_type[ROMFS]->device,\
                        (char *)phdr->p_vaddr, \
                        fs_type[ROMFS]->get_daddr(node) + \
                        phdr->p_offset, phdr->p_filesz) < 0) {
                printk("dout error\n");
                goto HALT;
            }
        }
        phdr++;
    }

    exec(ehdr->e_entry);

HALT:
    while (1);
}
Exemple #4
0
int main( void )
{
  FILE* fp;

  // Initialize platform first
  if( platform_init() != PLATFORM_OK )
  {
    // This should never happen
    while( 1 );
  }

  // Initialize device manager
  dm_init();

  // Register the ROM filesystem
  dm_register( romfs_init() );

  // Register the MMC filesystem
  dm_register( mmcfs_init() );

  // Register the remote filesystem
  dm_register( remotefs_init() );

  // Autorun: if "autorun.lua" is found in the file system, run it first
  if( ( fp = fopen( FS_AUTORUN, "r" ) ) != NULL )
  {
    fclose( fp );
    char* lua_argv[] = { "lua", FS_AUTORUN, NULL };
    lua_main( 2, lua_argv );
  }
  
#ifdef ELUA_BOOT_RPC
  boot_rpc();
#else
  
  // Run the shell
  if( shell_init() == 0 )
  {
    printf( "Unable to initialize the eLua shell!\n" );
    // Start Lua directly
    char* lua_argv[] = { "lua", NULL };
    lua_main( 1, lua_argv );
  }
  else
    shell_start();
#endif // #ifdef ELUA_BOOT_RPC

#ifdef ELUA_SIMULATOR
  hostif_exit(0);
  return 0;
#else
  while( 1 );
#endif
}
Exemple #5
0
int main( void )
{
    int i;
    FILE* fp;

    // Initialize platform first
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        while( 1 );
    }

    // Initialize device manager
    dm_init();

    // Register the ROM filesystem
    dm_register( romfs_init() );

    // Register the MMC filesystem
    dm_register( mmcfs_init() );

    // Register the Semihosting filesystem
    dm_register( semifs_init() );

    // Search for autorun files in the defined order and execute the 1st if found
    for( i = 0; i < sizeof( boot_order ) / sizeof( *boot_order ); i++ )
    {
        if( ( fp = fopen( boot_order[ i ], "r" ) ) != NULL )
        {
            fclose( fp );
            char* picoc_argv[] = { "picoc", boot_order[i], NULL };
            picoc_main( 2, picoc_argv );
            break; // autoruns only the first found
        }
    }

    // Run the shell
    if( shell_init() == 0 )
    {
        // Start picoc directly
        char* picoc_argv[] = { "picoc", NULL };
        picoc_main( 1, picoc_argv );
    }
    else
        shell_start();

    while( 1 );
}
Exemple #6
0
int main( void )
{
    FILE* fp;

    // Initialize platform first
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        while( 1 );
    }

    // Initialize device manager
    dm_init();

    // Register the ROM filesystem
    dm_register( romfs_init() );

#ifdef BUILD_XMODEM
    // Initialize XMODEM
    xmodem_init( xmodem_send, xmodem_recv );
#endif

#ifdef BUILD_TERM
    // Initialize terminal
    term_init( TERM_LINES, TERM_COLS, term_out, term_in, term_translate );
#endif

    // Autorun: if "autorun.lua" is found in the ROM file system, run it first
    if( ( fp = fopen( "/rom/autorun.lua", "r" ) ) != NULL )
    {
        fclose( fp );
        char* lua_argv[] = { "lua", "/rom/autorun.lua", NULL };
        lua_main( 2, lua_argv );
    }

    // Run the shell
    if( shell_init() == 0 )
    {
        printf( "Unable to initialize the eLua shell!\n" );
        // Start Lua directly
        char* lua_argv[] = { "lua", NULL };
        lua_main( 1, lua_argv );
    }
    else
        shell_start();

    while( 1 );
}
Exemple #7
0
int main( void )
{
  int i;
  FILE* fp;

  // Initialize platform first
  if( platform_init() != PLATFORM_OK )
  {
    // This should never happen
    while( 1 );
  }

  // Initialize device manager
  dm_init();

  // Register the ROM filesystem
  romfs_init();

  // Register the MMC filesystem
  mmcfs_init();

  // Search for autorun files in the defined order and execute the 1st if found
  for( i = 0; i < sizeof( boot_order ) / sizeof( *boot_order ); i++ )
  {
    if( ( fp = fopen( boot_order[ i ], "r" ) ) != NULL )
    {
      fclose( fp );
      // The entry point for PicoLisp.
      char* picolisp_argv[] = { "picolisp", boot_order[i], NULL };

      picolisp_main( 2, picolisp_argv );
      break; // autoruns only the first found
    }
  }
  
  // Run the shell
  if( shell_init() == 0 )
  {
    char* picolisp_argv[] = { "picolisp", NULL };
    picolisp_main( 1, picolisp_argv );
  }
  else
  {
    shell_start();
  }

  while( 1 );
}
Exemple #8
0
int main( void )
{
    // Initialize platform first
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        while( 1 );
    }

    // Initialize the TLSF allocator
    // (if TLSF is not used, the next function does nothing)
    tlsf_elua_init();

    // Initialize device manager
    dm_init();

    // Register the ROM filesystem
    dm_register( romfs_init() );

    // Initialize XMODEM
    xmodem_init( xmodem_send, xmodem_recv );

    // Initialize terminal
    term_init( TERMINAL_LINES, TERMINAL_COLS, term_out, term_in, term_translate );

    printf( ".text ends at %p\n", etext );

    // Run the shell
    if( shell_init( XMODEM_MAX_FILE_SIZE ) == 0 )
    {
        printf( "Unable to initialize the eLua shell!\n" );
        // Start Lua directly
        char* lua_argv[] = { "lua", NULL };
        lua_main( 1, lua_argv );
    }
    else
        shell_start();

    while( 1 );
}
Exemple #9
0
void plat_boot(void) {
    int i;
    for (i=0; init[i]; i++) {
        init[i]();
    }
    init_sys_mmu();
    start_mmu();
    task_init();
    timer_init();

    init_page_map();
    kmalloc_init();
    ramdisk_driver_init();
    romfs_init();
    
    i = do_fork(test_process, (void *)0x1);
    i = do_fork(test_process, (void *)0x2);

    while (1) {
        delay ();
        printk("this is the original process\n");
    }

}
Exemple #10
0
int main( void )
{
  // Initialize platform first
  if( platform_init() != PLATFORM_OK )
  {
    // This should never happen
    while( 1 );
  }
    
  // Initialize device manager
  dm_init();
  
  // Register the ROM filesystem
  dm_register( romfs_init() );  
  
  // Initialize XMODEM
  xmodem_init( xmodem_send, xmodem_recv );    
  
  // Initialize terminal
  term_init( TERMINAL_LINES, TERMINAL_COLS, term_out, term_in, term_translate );
  
  printf( ".text ends at %p, first free RAM is at %p, last free ram is at %p\r\n", etext, platform_get_first_free_ram(), platform_get_last_free_ram() );
  
  // Run the shell
  if( shell_init( XMODEM_MAX_FILE_SIZE ) == 0 )
  {
    printf( "Unable to initialize the eLua shell!\n" );
    // Start Lua directly
    char* lua_argv[] = { "lua", NULL };
    lua_main( 1, lua_argv );
  }
  else
    shell_start();

  while( 1 );
}
void nodemcu_init(void)
{
    NODE_ERR("\n");
    // Initialize platform first for lua modules.   
    if( platform_init() != PLATFORM_OK )
    {
        // This should never happen
        NODE_DBG("Can not init platform for modules.\n");
        return;
    }

#if defined(FLASH_SAFE_API)
    if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
        NODE_ERR("Self adjust flash size.\n");
        // Fit hardware real flash size.
        flash_rom_set_size_byte(flash_safe_get_size_byte());
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank();
        if( !fs_format() )
        {
            NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
            NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
        }
        else{
            NODE_ERR( "format done.\n" );
        }
        fs_unmount();   // mounted by format.
    }
#endif // defined(FLASH_SAFE_API)

    if( !flash_init_data_written() ){
        NODE_ERR("Restore init data.\n");
        // Flash init data at FLASHSIZE - 0x04000 Byte.
        flash_init_data_default();
        // Flash blank data at FLASHSIZE - 0x02000 Byte.
        flash_init_data_blank(); 
    }

#if defined( BUILD_WOFS )
    romfs_init();

    // if( !wofs_format() )
    // {
    //     NODE_ERR( "\ni*** ERROR ***: unable to erase the flash. WOFS might be compromised.\n" );
    //     NODE_ERR( "It is advised to re-flash the NodeWifi image.\n" );
    // }
    // else
    //     NODE_ERR( "format done.\n" );

    // test_romfs();
#elif defined ( BUILD_SPIFFS )
    fs_mount();
    // test_spiffs();
#endif
    // endpoint_setup();

    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"print(collectgarbage'count');ttt={};for i=1,100 do table.insert(ttt,i*2 -1);print(i);end for k, v in pairs(ttt) do print('<'..k..' '..v..'>') end print(collectgarbage'count');", NULL };
    // lua_main( 3, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL };
    // lua_main( 2, lua_argv );
    // char* lua_argv[] = { (char *)"lua", (char *)"-e", (char *)"pwm.setup(0,100,50) pwm.start(0) pwm.stop(0)", NULL };
    // lua_main( 3, lua_argv );
    // NODE_DBG("Flash sec num: 0x%x\n", flash_get_sec_num());
    task_init();
    system_os_post(USER_TASK_PRIO_0,SIG_LUA,'s');
}
/**
 * RT-Thread Components Initialization
 */
void rt_components_init(void)
{
#ifdef RT_USING_MODULE
	rt_system_module_init();
#endif

#ifdef RT_USING_FINSH
	/* initialize finsh */
	finsh_system_init();
	finsh_set_device(RT_CONSOLE_DEVICE_NAME);
#endif

#ifdef RT_USING_LWIP
	/* initialize lwip stack */
    /* register ethernetif device */
    eth_system_device_init();

    /* initialize lwip system */
    lwip_system_init();
    rt_kprintf("TCP/IP initialized!\n");
#endif

#ifdef RT_USING_DFS
	/* initialize the device file system */
	dfs_init();

#ifdef RT_USING_DFS_ELMFAT
	/* initialize the elm chan FatFS file systam*/
	elm_init();
#endif

#if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP)
	extern void nfs_init(void);
	/* initialize NFSv3 client file system */
	nfs_init();
#endif

#ifdef RT_USING_DFS_YAFFS2
	yaffs2_init();
#endif

#ifdef RT_USING_DFS_UFFS
	uffs_init();
#endif

#ifdef RT_USING_DFS_JFFS2
	jffs2_init();
#endif

#ifdef RT_USING_DFS_ROMFS
	romfs_init();
#endif

#ifdef RT_USING_DFS_DEVFS
	devfs_init();
#endif
#endif

#ifdef RT_USING_NEWLIB
	libc_system_init(RT_CONSOLE_DEVICE_NAME);
#endif

#ifdef RT_USING_PTHREADS 
	pthread_system_init();
#endif

#ifdef RT_USING_RTGUI
	rtgui_system_server_init();
#endif

	return;
}
Exemple #13
0
int main( void )
{
  int i;
  FILE* fp;

  // Initialize platform first
  if( platform_init() != PLATFORM_OK )
  {
    // This should never happen
    while( 1 );
  }

  // Initialize device manager
  dm_init();

  // Register the ROM filesystem
  romfs_init();

  // Register the MMC filesystem
  mmcfs_init();

  // Register the Semihosting filesystem
  semifs_init();

  // Register the remote filesystem
  remotefs_init();

  // Register NIFFS
  nffs_init();

  // Search for autorun files in the defined order and execute the 1st if found
  for( i = 0; i < sizeof( boot_order ) / sizeof( *boot_order ); i++ )
  {
    if( ( fp = fopen( boot_order[ i ], "r" ) ) != NULL )
    {
      fclose( fp );
      char* lua_argv[] = { (char *)"lua", (char *)boot_order[i], NULL };
      lua_main( 2, lua_argv );
      break; // autoruns only the first found
    }
  }

#ifdef ELUA_BOOT_RPC
  boot_rpc();
#else
  
  // Run the shell
  if( shell_init() == 0 )
  {
    // Start Lua directly
    char* lua_argv[] = { (char *)"lua", NULL };
    lua_main( 1, lua_argv );
  }
  else
    shell_start();
#endif // #ifdef ELUA_BOOT_RPC

#ifdef ELUA_SIMULATOR
  hostif_exit(0);
  return 0;
#else
  while( 1 );
#endif
}
Exemple #14
0
int main(int argc, char* argv[])
{
    toolcontext ctx;
    u8 magic[4];
    char infname[512];
    int c;
    u32 ncchoffset = ~0;
    char keysetfname[512] = "keys.xml";
    keyset tmpkeys;
    unsigned int checkkeysetfile = 0;

    memset(&ctx, 0, sizeof(toolcontext));
    ctx.actions = InfoFlag | ExtractFlag;
    ctx.filetype = FILETYPE_UNKNOWN;

    settings_init(&ctx.usersettings);
    keyset_init(&ctx.usersettings.keys);
    keyset_init(&tmpkeys);


    while (1)
    {
        int option_index;
        static struct option long_options[] =
        {
            {"extract", 0, NULL, 'x'},
            {"plain", 0, NULL, 'p'},
            {"info", 0, NULL, 'i'},
            {"exefs", 1, NULL, 0},
            {"romfs", 1, NULL, 1},
            {"exheader", 1, NULL, 2},
            {"certs", 1, NULL, 3},
            {"tik", 1, NULL, 4},
            {"tmd", 1, NULL, 5},
            {"contents", 1, NULL, 6},
            {"meta", 1, NULL, 7},
            {"exefsdir", 1, NULL, 8},
            {"keyset", 1, NULL, 'k'},
            {"ncch", 1, NULL, 'n'},
            {"verbose", 0, NULL, 'v'},
            {"verify", 0, NULL, 'y'},
            {"raw", 0, NULL, 'r'},
            {"unitsize", 1, NULL, 9},
            {"showkeys", 0, NULL, 10},
            {"commonkey", 1, NULL, 11},
            {"ncchkey", 1, NULL, 12},
            {"intype", 1, NULL, 't'},
            {"lzssout", 1, NULL, 13},
            {"firmdir", 1, NULL, 14},
            {"ncchsyskey", 1, NULL, 15},
            {"wav", 1, NULL, 16},
            {"romfsdir", 1, NULL, 17},
            {"listromfs", 0, NULL, 18},
            {"wavloops", 1, NULL, 19},
            {"logo", 1, NULL, 20},
            {NULL},
        };

        c = getopt_long(argc, argv, "ryxivpk:n:t:", long_options, &option_index);
        if (c == -1)
            break;

        switch (c)
        {
        case 'x':
            ctx.actions |= ExtractFlag;
            break;

        case 'v':
            ctx.actions |= VerboseFlag;
            break;

        case 'y':
            ctx.actions |= VerifyFlag;
            break;

        case 'p':
            ctx.actions |= PlainFlag;
            break;

        case 'r':
            ctx.actions |= RawFlag;
            break;

        case 'i':
            ctx.actions |= InfoFlag;
            break;

        case 'n':
            ncchoffset = strtoul(optarg, 0, 0);
            break;

        case 'k':
            strncpy(keysetfname, optarg, sizeof(keysetfname));
            checkkeysetfile = 1;
            break;

        case 't':
            if (!strcmp(optarg, "exheader"))
                ctx.filetype = FILETYPE_EXHEADER;
            else if (!strcmp(optarg, "ncch"))
                ctx.filetype = FILETYPE_CXI;
            else if (!strcmp(optarg, "ncsd"))
                ctx.filetype = FILETYPE_CCI;
            else if (!strcmp(optarg, "cia"))
                ctx.filetype = FILETYPE_CIA;
            else if (!strcmp(optarg, "tmd"))
                ctx.filetype = FILETYPE_TMD;
            else if (!strcmp(optarg, "lzss"))
                ctx.filetype = FILETYPE_LZSS;
            else if (!strcmp(optarg, "firm"))
                ctx.filetype = FILETYPE_FIRM;
            else if (!strcmp(optarg, "cwav"))
                ctx.filetype = FILETYPE_CWAV;
            else if (!strcmp(optarg, "romfs"))
                ctx.filetype = FILETYPE_ROMFS;
            break;

        case 0:
            settings_set_exefs_path(&ctx.usersettings, optarg);
            break;
        case 1:
            settings_set_romfs_path(&ctx.usersettings, optarg);
            break;
        case 2:
            settings_set_exheader_path(&ctx.usersettings, optarg);
            break;
        case 3:
            settings_set_certs_path(&ctx.usersettings, optarg);
            break;
        case 4:
            settings_set_tik_path(&ctx.usersettings, optarg);
            break;
        case 5:
            settings_set_tmd_path(&ctx.usersettings, optarg);
            break;
        case 6:
            settings_set_content_path(&ctx.usersettings, optarg);
            break;
        case 7:
            settings_set_content_path(&ctx.usersettings, optarg);
            break;
        case 8:
            settings_set_exefs_dir_path(&ctx.usersettings, optarg);
            break;
        case 9:
            settings_set_mediaunit_size(&ctx.usersettings, strtoul(optarg, 0, 0));
            break;
        case 10:
            ctx.actions |= ShowKeysFlag;
            break;
        case 11:
            keyset_parse_commonkey(&tmpkeys, optarg, strlen(optarg));
            break;
        case 12:
            keyset_parse_ncchkey(&tmpkeys, optarg, strlen(optarg));
            break;
        case 13:
            settings_set_lzss_path(&ctx.usersettings, optarg);
            break;
        case 14:
            settings_set_firm_dir_path(&ctx.usersettings, optarg);
            break;
        case 15:
            keyset_parse_ncchfixedsystemkey(&tmpkeys, optarg, strlen(optarg));
            break;
        case 16:
            settings_set_wav_path(&ctx.usersettings, optarg);
            break;
        case 17:
            settings_set_romfs_dir_path(&ctx.usersettings, optarg);
            break;
        case 18:
            settings_set_list_romfs_files(&ctx.usersettings, 1);
            break;
        case 19:
            settings_set_cwav_loopcount(&ctx.usersettings, strtoul(optarg, 0, 0));
            break;
        case 20:
            settings_set_logo_path(&ctx.usersettings, optarg);
            break;

        default:
            usage(argv[0]);
        }
    }

    if (optind == argc - 1)
    {
        // Exactly one extra argument - an input file
        strncpy(infname, argv[optind], sizeof(infname));
    }
    else if ( (optind < argc) || (argc == 1) )
    {
        // Too many extra args
        usage(argv[0]);
    }

    keyset_load(&ctx.usersettings.keys, keysetfname, (ctx.actions & VerboseFlag) | checkkeysetfile);
    keyset_merge(&ctx.usersettings.keys, &tmpkeys);
    if (ctx.actions & ShowKeysFlag)
        keyset_dump(&ctx.usersettings.keys);

    ctx.infile = fopen(infname, "rb");

    if (ctx.infile == 0)
    {
        fprintf(stderr, "error: could not open input file!\n");
        return -1;
    }

    fseek(ctx.infile, 0, SEEK_END);
    ctx.infilesize = ftell(ctx.infile);
    fseek(ctx.infile, 0, SEEK_SET);




    if (ctx.filetype == FILETYPE_UNKNOWN)
    {
        fseek(ctx.infile, 0x100, SEEK_SET);
        fread(&magic, 1, 4, ctx.infile);

        switch(getle32(magic))
        {
        case MAGIC_NCCH:
            ctx.filetype = FILETYPE_CXI;
            break;

        case MAGIC_NCSD:
            ctx.filetype = FILETYPE_CCI;
            break;

        default:
            break;
        }
    }

    if (ctx.filetype == FILETYPE_UNKNOWN)
    {
        fseek(ctx.infile, 0, SEEK_SET);
        fread(magic, 1, 4, ctx.infile);

        switch(getle32(magic))
        {
        case 0x2020:
            ctx.filetype = FILETYPE_CIA;
            break;

        case MAGIC_FIRM:
            ctx.filetype = FILETYPE_FIRM;
            break;

        case MAGIC_CWAV:
            ctx.filetype = FILETYPE_CWAV;
            break;

        case MAGIC_IVFC:
            ctx.filetype = FILETYPE_ROMFS; // TODO: need to determine more here.. savegames use IVFC too, but is not ROMFS.
            break;
        }
    }

    if (ctx.filetype == FILETYPE_UNKNOWN)
    {
        fprintf(stdout, "Unknown file\n");
        exit(1);
    }


    switch(ctx.filetype)
    {
    case FILETYPE_CCI:
    {
        ncsd_context ncsdctx;

        ncsd_init(&ncsdctx);
        ncsd_set_file(&ncsdctx, ctx.infile);
        ncsd_set_size(&ncsdctx, ctx.infilesize);
        ncsd_set_usersettings(&ncsdctx, &ctx.usersettings);
        ncsd_process(&ncsdctx, ctx.actions);

        break;
    }

    case FILETYPE_FIRM:
    {
        firm_context firmctx;

        firm_init(&firmctx);
        firm_set_file(&firmctx, ctx.infile);
        firm_set_size(&firmctx, ctx.infilesize);
        firm_set_usersettings(&firmctx, &ctx.usersettings);
        firm_process(&firmctx, ctx.actions);

        break;
    }

    case FILETYPE_CXI:
    {
        ncch_context ncchctx;

        ncch_init(&ncchctx);
        ncch_set_file(&ncchctx, ctx.infile);
        ncch_set_size(&ncchctx, ctx.infilesize);
        ncch_set_usersettings(&ncchctx, &ctx.usersettings);
        ncch_process(&ncchctx, ctx.actions);

        break;
    }


    case FILETYPE_CIA:
    {
        cia_context ciactx;

        cia_init(&ciactx);
        cia_set_file(&ciactx, ctx.infile);
        cia_set_size(&ciactx, ctx.infilesize);
        cia_set_usersettings(&ciactx, &ctx.usersettings);
        cia_process(&ciactx, ctx.actions);

        break;
    }

    case FILETYPE_EXHEADER:
    {
        exheader_context exheaderctx;

        exheader_init(&exheaderctx);
        exheader_set_file(&exheaderctx, ctx.infile);
        exheader_set_size(&exheaderctx, ctx.infilesize);
        settings_set_ignore_programid(&ctx.usersettings, 1);

        exheader_set_usersettings(&exheaderctx, &ctx.usersettings);
        exheader_process(&exheaderctx, ctx.actions);

        break;
    }

    case FILETYPE_TMD:
    {
        tmd_context tmdctx;

        tmd_init(&tmdctx);
        tmd_set_file(&tmdctx, ctx.infile);
        tmd_set_size(&tmdctx, ctx.infilesize);
        tmd_set_usersettings(&tmdctx, &ctx.usersettings);
        tmd_process(&tmdctx, ctx.actions);

        break;
    }

    case FILETYPE_LZSS:
    {
        lzss_context lzssctx;

        lzss_init(&lzssctx);
        lzss_set_file(&lzssctx, ctx.infile);
        lzss_set_size(&lzssctx, ctx.infilesize);
        lzss_set_usersettings(&lzssctx, &ctx.usersettings);
        lzss_process(&lzssctx, ctx.actions);

        break;
    }


    case FILETYPE_CWAV:
    {
        cwav_context cwavctx;

        cwav_init(&cwavctx);
        cwav_set_file(&cwavctx, ctx.infile);
        cwav_set_size(&cwavctx, ctx.infilesize);
        cwav_set_usersettings(&cwavctx, &ctx.usersettings);
        cwav_process(&cwavctx, ctx.actions);

        break;
    }

    case FILETYPE_ROMFS:
    {
        romfs_context romfsctx;

        romfs_init(&romfsctx);
        romfs_set_file(&romfsctx, ctx.infile);
        romfs_set_size(&romfsctx, ctx.infilesize);
        romfs_set_usersettings(&romfsctx, &ctx.usersettings);
        romfs_process(&romfsctx, ctx.actions);

        break;
    }
    }

    if (ctx.infile)
        fclose(ctx.infile);

    return 0;
}
Exemple #15
0
int action_parse(toolcontext* ctx, char* fname)
{
	u8 magic[4];

	ctx->infile = fopen(fname, "rb");

	if (ctx->infile == 0) 
	{
		fprintf(stderr, "error: could not open input file!\n");
		return -1;
	}

	fseek(ctx->infile, 0, SEEK_END);
	ctx->infilesize = ftell(ctx->infile);
	fseek(ctx->infile, 0, SEEK_SET);


	if (ctx->filetype == FILETYPE_UNKNOWN)
	{
		fseek(ctx->infile, 0x100, SEEK_SET);
		fread(&magic, 1, 4, ctx->infile);

		switch(getle32(magic))
		{
			case MAGIC_NCCH:
				ctx->filetype = FILETYPE_CXI;
			break;

			case MAGIC_NCSD:
				ctx->filetype = FILETYPE_CCI;
			break;

			default:
			break;
		}
	}

	if (ctx->filetype == FILETYPE_UNKNOWN)
	{
		fseek(ctx->infile, 0, SEEK_SET);
		fread(magic, 1, 4, ctx->infile);
		
		switch(getle32(magic))
		{
			case 0x2020:
				ctx->filetype = FILETYPE_CIA;
			break;

			case MAGIC_FIRM:
				ctx->filetype = FILETYPE_FIRM;
			break;

			case MAGIC_CWAV:
				ctx->filetype = FILETYPE_CWAV;
			break;

			case MAGIC_IVFC:
				ctx->filetype = FILETYPE_ROMFS; // TODO: need to determine more here.. savegames use IVFC too, but is not ROMFS.
			break;
		}
	}

	if (ctx->filetype == FILETYPE_UNKNOWN)
	{
		fprintf(stdout, "Unknown file\n");
		exit(1);
	}


	switch(ctx->filetype)
	{
		case FILETYPE_CCI:
		{
			ncsd_context ncsdctx;

			ncsd_init(&ncsdctx);
			ncsd_set_file(&ncsdctx, ctx->infile);
			ncsd_set_size(&ncsdctx, ctx->infilesize);
			ncsd_set_usersettings(&ncsdctx, &ctx->usersettings);
			ncsd_process(&ncsdctx, ctx->actions);
			
			break;			
		}

		case FILETYPE_FIRM:
		{
			firm_context firmctx;

			firm_init(&firmctx);
			firm_set_file(&firmctx, ctx->infile);
			firm_set_size(&firmctx, ctx->infilesize);
			firm_set_usersettings(&firmctx, &ctx->usersettings);
			firm_process(&firmctx, ctx->actions);
			
			break;			
		}
		
		case FILETYPE_CXI:
		{
			ncch_context ncchctx;

			ncch_init(&ncchctx);
			ncch_set_file(&ncchctx, ctx->infile);
			ncch_set_size(&ncchctx, ctx->infilesize);
			ncch_set_usersettings(&ncchctx, &ctx->usersettings);
			ncch_process(&ncchctx, ctx->actions);

			break;
		}
		

		case FILETYPE_CIA:
		{
			cia_context ciactx;

			cia_init(&ciactx);
			cia_set_file(&ciactx, ctx->infile);
			cia_set_size(&ciactx, ctx->infilesize);
			cia_set_usersettings(&ciactx, &ctx->usersettings);
			cia_process(&ciactx, ctx->actions);

			break;
		}

		case FILETYPE_EXHEADER:
		{
			exheader_context exheaderctx;

			exheader_init(&exheaderctx);
			exheader_set_file(&exheaderctx, ctx->infile);
			exheader_set_size(&exheaderctx, ctx->infilesize);
			settings_set_ignore_programid(&ctx->usersettings, 1);

			exheader_set_usersettings(&exheaderctx, &ctx->usersettings);
			exheader_process(&exheaderctx, ctx->actions);
	
			break;
		}

		case FILETYPE_TMD:
		{
			tmd_context tmdctx;

			tmd_init(&tmdctx);
			tmd_set_file(&tmdctx, ctx->infile);
			tmd_set_size(&tmdctx, ctx->infilesize);
			tmd_set_usersettings(&tmdctx, &ctx->usersettings);
			tmd_process(&tmdctx, ctx->actions);
	
			break;
		}

		case FILETYPE_LZSS:
		{
			lzss_context lzssctx;

			lzss_init(&lzssctx);
			lzss_set_file(&lzssctx, ctx->infile);
			lzss_set_size(&lzssctx, ctx->infilesize);
			lzss_set_usersettings(&lzssctx, &ctx->usersettings);
			lzss_process(&lzssctx, ctx->actions);
	
			break;
		}


		case FILETYPE_CWAV:
		{
			cwav_context cwavctx;

			cwav_init(&cwavctx);
			cwav_set_file(&cwavctx, ctx->infile);
			cwav_set_size(&cwavctx, ctx->infilesize);
			cwav_set_usersettings(&cwavctx, &ctx->usersettings);
			cwav_process(&cwavctx, ctx->actions);
	
			break;
		}

		case FILETYPE_EXEFS:
		{
			exefs_context exefsctx;

			exefs_init(&exefsctx);
			exefs_set_file(&exefsctx, ctx->infile);
			exefs_set_size(&exefsctx, ctx->infilesize);
			exefs_set_usersettings(&exefsctx, &ctx->usersettings);
			exefs_process(&exefsctx, ctx->actions);
	
			break;
		}

		case FILETYPE_ROMFS:
		{
			romfs_context romfsctx;

			romfs_init(&romfsctx);
			romfs_set_file(&romfsctx, ctx->infile);
			romfs_set_size(&romfsctx, ctx->infilesize);
			romfs_set_usersettings(&romfsctx, &ctx->usersettings);
			romfs_process(&romfsctx, ctx->actions);
	
			break;
		}
	}
	
	if (ctx->infile)
		fclose(ctx->infile);

	return 0;
}