示例#1
0
文件: main.c 项目: deado/buttons
int main()
{
	mainInit();
	console_clrscr();
	printf( "Welcome to the beginning...\n\n"
		"A graphical interface coming\nsomewhere down the line.\n");

	struct controller_data_s c;
	while(1)
	{
		if (get_controller_data(&c, 0))
		{
			if(c.a) printf("A\n");
			if(c.b) printf("B\n");
			if(c.x) printf("X\n");
                        if(c.y) printf("Y\n");
                        if(c.logo) printf("Logo/Guide\n");
                        if(c.lb) printf("Left Bumper\n");
                        if(c.rb) printf("Right Bumper\n");
                        if(c.up) printf("Up\n");
                        if(c.down) printf("Down\n");
			if(c.left) printf("Left\n");
			if(c.right) printf("Right\n");
			if(c.lt) printf("Left Tigger\n");
                        if(c.rt) printf("Right Trigger\n");
                        if(c.start) printf("Start\n");
                        if(c.back) printf("Back/Select\n");
			if(c.s1_x) printf("Stick 1 X: %d\n",c.s1_x);
		}
		usb_do_poll();
	}
	return 0;
}
示例#2
0
/**
* Read the NAND into a file.
*
* @param path - The path to the target file e.g "uda:/flashdmp.bin"
* @param size the size of the packet buffer to allocate
* @return none
*/
void readNand(char *path, int bb_64mb_only)
{
  FILE *f;
  int i;
  int nand_sz = sfc.size_bytes;
  unsigned char *buf = (unsigned char *) malloc(sfc.block_sz_phys);
  
  console_clrscr();
  
  if (!buf)
  {
     printf("Memory error!\n");
     waitforexit();
  }
            
  f = fopen(path, "wb");
  if (!f){
     printf(" ! %s failed to open\n", path);
     waitforexit();
  }
            
  if(bb_64mb_only){ 
     printf(" ! Detected a BIG BLOCK Console with INTEGRATED Memory Unit!\n");
     printf(" ! Will ONLY read 64 MB!\n");
     nand_sz = NAND_SIZE_64MB;
  }
            
  printf("Please wait while reading NAND to %s ... \n",path);
            
  int status;
            
  for (i = 0; i < nand_sz; i += sfc.block_sz) 
  {
     status = sfcx_read_block(buf, i, 1);
              
     if (!SFCX_SUCCESS(status))
       printf(" ! Error occured while dumping the NAND! Status: %04X\n",status);

     if(!fwrite(buf, 1, sfc.block_sz_phys, f))
     {   
       printf(" ! Error dumping NAND! Please check disk space!\n");
       waitforexit();                 
     }
  }
            
  printf("\n");
  printf("Closing file, freeing memory...\n");

  fclose(f);
  free(buf);
             
             
  printf("Reading NAND finished. Do whatever you like to do now !\n");
  waitforexit();
}
示例#3
0
/**
* Allocate memory for a packet buffer for a given netbuf.
*
* @param buf the netbuf for which to allocate a packet buffer
* @param size the size of the packet buffer to allocate
* @return pointer to the allocated memory
* NULL if no memory could be allocated
*/
int analyzeNand(int first,int last,int mode)
{
    int foundBB, foundEDC, block, page, status;
    unsigned long offset;
    unsigned char* pagebuf;
    unsigned char EDC[3];
    
    BBMnand.BadBlocksCount = 0;
    
    pagebuf = (unsigned char *)malloc(sfc.page_sz_phys);
    
    console_clrscr();
    
    printf("\nStarting Analyzation!\n\n");
    
    for (block=first; block < last; block++)
    {
        printf("\rCurrently @ block %04X",block);
        foundBB = 0;
        foundEDC= 0;
        for (page=0; page < sfc.pages_in_block; page++)
        {
            offset = (block*sfc.block_sz)+(page*sfc.page_sz);
            status = sfcx_read_page(pagebuf,offset,1);
            
            if(!sfcx_is_pageempty(pagebuf) && !sfcx_is_pagevalid(pagebuf))
                foundBB = 1;
            
            if(status & STATUS_BB_ER)
                foundBB = 1;
            
           if(mode){
               memset(EDC,0,0x3);
               memcpy(EDC,&pagebuf[sfc.page_sz_phys-0x3],0x3);
               sfcx_calcecc(pagebuf);
               
               if (memcmp(EDC,&pagebuf[sfc.page_sz_phys-0x3],0x3))
                   foundEDC = 1;
           }
        }
        if (foundBB){
            BBMnand.BadBlocks[BBMnand.BadBlocksCount++] = block;
            printf("\nBad Block found @ %04X\n",block);
        }

        if (foundEDC){
            BBMnand.EDCerrorBlocks[BBMnand.EDCerrorCount++] = block;
            printf("\nEDC Error found @ %04X\n",block);
        }

    }
    
    return 0;
}
示例#4
0
int main(){
	// Initialize the screen and clear the console.
	videoInit();
	console_clrscr();

	/* Setup two memory addresses to store data in.
	   tempAddress is where raw incoming binary data is stored. 
	   elfAddress is where tempAddress is copied to, post ELF verification.
	*/
	void *tempAddress = malloc(0x1000000);
	unsigned char *elfAddress = malloc(sizeof(tempAddress));

	while(1){
		// Print status.
		printf("Reading");
		printf(".");

		// Variable to hold read binary data.
		unsigned char data = getch();

		// Instantiate a counter for the number of bytes we have read.
		long int bytesRead = 0;

		// Up the counter of the number of bytes we have read.
		bytesRead++;
		int numBytes = bytesRead;

		// Copy data to memory buffer.
		memcpy(tempAddress, data, numBytes);

		/* If no more data is being received, perform ELF check.
		   If check passes, copy temporary buffer contents to 
		   final buffer, free temporary buffer, and execute
		   the elf from final memory address.
		*/
		if(data == NULL){
			checkIsELF(tempAddress);

			if(isELF == 1){
				printf("do nothing");
			}
		}
	}

	return 0;
}
示例#5
0
void dump_thread_context_to_screen(PROCESSOR_DATA_BLOCK *processor,
        unsigned int exceptionCode, CONTEXT *context)
{
    console_set_colors(0x000080ff, 0xffffffff);
    console_clrscr();
    
    strcpy(exception_text, exception_strings[exceptionCode]);
    
    debug_flush_console();

    sprintf(exception_text,"\nIar=%016llx Msr=%016llx Lr=%016llx Dar=%08X Pir=%02X\n\n",
                    context->Iar, context->Msr, context->Lr,
                        processor->DAR, (unsigned int)mfspr(pir));
    
    debug_flush_console();

    int i;
    for(i=0;i<8;++i)
            sprintf(exception_text,"%s%02d=%016llx %02d=%016llx %02d=%016llx %02d=%016llx\n",
                            exception_text,
                    i,context->Gpr[i],
                    i+8,context->Gpr[i+8],
                    i+16,context->Gpr[i+16],
                    i+24,context->Gpr[i+24]);

    debug_flush_console();
    
    debug_cpu_print_stack((void*)context->Iar,(void*)context->Lr,(void*)context->Gpr[1]);

    strcat(exception_text,"\n\nOn uart: 'h'=Halt, 'r'=Reboot\n\n");

    debug_flush_console();

    for(;;){
            switch(getch()){
                    case 'h':
                            xenon_smc_power_shutdown();
                            for(;;);
                            break;
                    case 'r':
                            xenon_smc_power_reboot();
                            for(;;);
                            break;
            }
    }
}
示例#6
0
void crashdump(u32 exception,u64 * context)
{
	console_set_colors(0x000080ff, 0xffffffff);
	console_init();
	console_clrscr();
        
        switch(exception)
        {
            case 0x200:
                strcpy(text,"\nMachine Check!\n\n");
                break;
            case 0x380:
                strcpy(text,"\nData SegFault!\n\n");
                break;
            case 0x480:
                strcpy(text,"\nInstruction SegFault!\n\n");
                break;
            case 0x500:
                strcpy(text,"\nExternal Interrupt!\n\n");
                break;
            case 0x600:
                strcpy(text,"\nAlignment!\n\n");
                break;
            case 0x700:
                strcpy(text,"\nProgram Interrupt!\n\n");
                break;
            case 0x800:
                strcpy(text,"\nFPU Unavailable!\n\n");
                break;
            case 0x900:
                strcpy(text,"\nDecrementer!\n\n");
                break;
            case 0x980:
                strcpy(text,"\nHV Decrementer!\n\n");
                break;
            case 0xC00:
                strcpy(text,"\nSystem Call!\n\n");
                break;
            case 0xD00:
                strcpy(text,"\nTrace!\n\n");
                break;
            case 0xE00:
                strcpy(text,"\nFPU Assist!\n\n");
                break;
            case 0xF20:
                strcpy(text,"\nVPU Unavailable!\n\n");
                break;
            case 0x1600:
                strcpy(text,"\nMaintenance!\n\n");
                break;
            case 0x1700:
                strcpy(text,"\nVMX Assist!\n\n");
                break;
            case 0x1800:
                strcpy(text,"\nThermal Managment!\n\n");
                break;
            case 0:
                strcpy(text,"\nSegmentation Fault!\n\n");
                break;
            default:
                sprintf(text,"\nException Vector! (%p)\n\n",exception);
                break;
        }
		
	flush_console();
	
	sprintf(text,"%spir=%016llx dar=%016llx\nIar=%016llx Msr=%016llx lr=%016llx\n\n",
			text,context[39],context[38],context[36],context[37],context[32]);
	
	flush_console();
	
	int i;
	for(i=0;i<8;++i)
		sprintf(text,"%s%02d=%016llx %02d=%016llx %02d=%016llx %02d=%016llx\n",
				text,i,context[i],i+8,context[i+8],i+16,context[i+16],i+24,context[i+24]);
	
	flush_console();
	
	_cpu_print_stack((void*)(u32)context[36],(void*)(u32)context[32],(void*)(u32)context[1]);
	
	strcat(text,"\n\nOn uart: 'x'=Xell, 'h'=Halt, 'r'=Reboot\n\n");

	flush_console();

	for(;;){
		switch(getch()){
			case 'x':
				exit(0);
				break;
			case 'h':
				xenon_smc_power_shutdown();
				for(;;);
				break;
			case 'r':
				xenon_smc_power_reboot();
				for(;;);
				break;
		}
	}
}
示例#7
0
文件: main.c 项目: AirBrowse/libxenon
int main(){
	const char * s;
	char path[256];
	
	int handle;
	struct controller_data_s pad;
	int pos=0,ppos=-1,start,count,i;

	xenos_init(VIDEO_MODE_AUTO);
	console_init();

	xenon_make_it_faster(XENON_SPEED_FULL);
	
	usb_init();
	usb_do_poll();
	
	xenon_ata_init();

	xenon_atapi_init();
	
	fatInitDefault();

	handle=-1;
    handle=bdev_enum(handle,&s);
    if(handle<0) return 0;

	strcpy(path,s);
	strcat(path,":/");	

	load_dir(path);
	
	for(;;){
 		usb_do_poll();		
 		get_controller_data(&pad, 0);
		
		if (pad.s1_y>STICK_THRESHOLD) --pos;
		if (pad.s1_y<-STICK_THRESHOLD) ++pos;
		
		if (entrycount && (pos<0 || pos>=entrycount)){
			pos=ppos;
			continue;
		}
		
		if (pad.logo) return 0;
		
		if (pad.a){
			if(entries[pos].d_type&DT_DIR){
				append_dir_to_path(path,entries[pos].d_name);
				load_dir(path);
				ppos=-1;
				pos=0;
			}else{
				char fn[256];
				strcpy(fn,path);
				strcat(fn,entries[pos].d_name);
				
				printf("%s\n",fn);

				if (strstr(entries[pos].d_name,".elf") || strstr(entries[pos].d_name,".elf32")) { // ugly
					elf_runFromDisk(fn);
				}else{
					FILE * f=fopen(fn,"rb");
					if(f){
						int size=1024*1024;
						int totred=0,red;

						void * buf=malloc(size);

						u64 beg=mftb();
						do{
							red=fread(buf,1,size,f);
							totred+=red;
							console_putch('.');
						}while(red==size);

						printf("\n%d bytes, %f KB/s\n",totred, (float)(totred/1024.0)/((float)(mftb()-beg)/PPC_TIMEBASE_FREQ));

						free(buf);

						fclose(f);
					}
				}
			}
		}
		
		if(pad.back){
			append_dir_to_path(path,"..");
			load_dir(path);
			ppos=-1;
			pos=0;
		}
		
		if(pad.b){
		    do{
				handle=bdev_enum(handle,&s);
			}while(handle<0);
			strcpy(path,s);
			strcat(path,":/");
			load_dir(path);
			ppos=-1;
			pos=0;
		}

		if (ppos==pos) continue;
		
		memset(&pad,0,sizeof(struct controller_data_s));
		
		console_set_colors(BG_COL,FG_COL);
		console_clrscr();
		printf("A: select, B: change disk, Back: parent dir, Logo: reload Xell\n\n%s\n\n",path);
		
		start=MAX(0,pos-MAX_DISPLAYED_ENTRIES/2);
		count=MIN(MAX_DISPLAYED_ENTRIES,entrycount-start);
		
		for(i=start;i<start+count;++i){
			struct dirent *de = &entries[i];

			if (i==pos){
				console_set_colors(FG_COL,BG_COL);
			}else{
				console_set_colors(BG_COL,FG_COL);
			}
			
			if (de->d_type&DT_DIR) console_putch('[');

			s=de->d_name;
			while(*s) console_putch(*s++);
			
			if (de->d_type&DT_DIR) console_putch(']');

			console_putch('\r');
			console_putch('\n');
		}
			
		ppos=pos;
		
		do{
	 		usb_do_poll();		
			get_controller_data(&pad, 0);
		}while(pad.a || pad.b || pad.back || pad.s1_y>STICK_THRESHOLD || pad.s1_y<-STICK_THRESHOLD);
	}
	
	
	return 0;
}
示例#8
0
文件: main.c 项目: IUNIXI/LxNAND
void prompt(int menu)
{
    	console_clrscr();
        
        switch (menu)
        {
            case MAIN_MENU:{            
                printf("\n  LibXenon NANDFlasher v%s  \n",version);
                printf("  **************************\n\n");
                printf("Flashconfig 0x%08X\n",flashconfig);
                printf("NAND-Size %i MB\n\n",sfc.size_mb);
                printf("Press A to save NAND to file on USB.\n");
                printf("Press X to write file from USB to NAND.\n");
                printf("Press B to analyze NAND.\n");
                printf("Press Y to update XeLL.\n");
                printf("Press START for DMA test.\n");
                printf("Press GUIDE to return to XeLL.\n");
        
                struct controller_data_s controller;
                while(1)
                { 		
                struct controller_data_s button;
                
                if (get_controller_data(&button, 0))
                  {
                    if((button.a)&&(!controller.a))
                        prompt(DUMP_SUBMENU);

                    if((button.x)&&(!controller.x))
                        writeNand("uda:/updflash.bin");

                    if((button.b)&&(!controller.b))
                        prompt(ANALYZE_SUBMENU);
                               
                    if((button.y)&&(!controller.y))
                        updateXeLL("uda:/updxell.bin");
                    
                    if((button.start)&&(!controller.start))                    
                        dmatest();
                    
                    if((button.logo)&&(!controller.logo))
                        break;
                                
                    controller=button;
		   }
 		usb_do_poll();
                }
            }
            case DUMP_SUBMENU:{
                
                int nand_sz = sfc.size_bytes;
                
                if (nand_sz != NAND_SIZE_256MB && nand_sz != NAND_SIZE_512MB)
                    readNand("uda:/flashdmp.bin", FULL_DUMP);
                
                printf("\n         DUMP MENU          \n");
                printf("  **************************\n\n");
                printf("Press A to dump whole NAND.\n");
                printf("Press B to dump only flash-partition.\n");
                printf("Press BACK to go back to main menu.\n");
                
                struct controller_data_s controller;
                while(1)
                { 		
                struct controller_data_s button;
                
                if (get_controller_data(&button, 0))
                  {
                    if((button.a)&&(!controller.a))
                        readNand("uda:/flashdmp.bin", FULL_DUMP);

                    if((button.b)&&(!controller.b))
                        readNand("uda:/flashdmp.bin", BB64MB_ONLY);
                               
                    if((button.select)&&(!controller.select))
                        prompt(MAIN_MENU);
                                
                    controller=button;
		   }
 		usb_do_poll();
                }
            }
            case ANALYZE_SUBMENU:{
                
                printf("\n       ANALYZE MENU        \n");
                printf("  **************************\n\n");
                printf("Press A to analyze physical NAND.\n");
                printf("Press B to analyze file updflash.bin.\n");
                printf("Press BACK to go back to main menu.\n");
                
                struct controller_data_s controller;
                while(1)
                { 		
                struct controller_data_s button;
                
                if (get_controller_data(&button, 0))
                  {
                    if((button.a)&&(!controller.a))
                        prompt(ANALYZE_PHYS_SUBMENU);

                    if((button.b)&&(!controller.b))
                        prompt(ANALYZE_FILE_SUBMENU);
                               
                    if((button.select)&&(!controller.select))
                        prompt(MAIN_MENU);
                                
                    controller=button;
		   }
 		usb_do_poll();
                }
            }
            case ANALYZE_PHYS_SUBMENU:{
                
                int nand_sz = sfc.size_bytes;
                int blocks = sfc.size_blocks;
                if (nand_sz == NAND_SIZE_256MB || nand_sz == NAND_SIZE_512MB)
                    blocks = 0x200;
                
                printf("\n       ANALYZE NAND       \n");
                printf("  **************************\n\n");
                printf("Press A to scan for Bad Blocks.\n");
                printf("Press B to scan for Bad Blocks and EDC errors.\n");
                printf("Press BACK to go back to main menu.\n");
                
                struct controller_data_s controller;
                while(1)
                { 		
                struct controller_data_s button;
                
                if (get_controller_data(&button, 0))
                  {
                    if((button.a)&&(!controller.a)){
                        analyzeNand(0,blocks,0);
                        printReport(BBMnand);
                        waitforexit();
                    }

                    if((button.b)&&(!controller.b)){
                        analyzeNand(0,blocks,1);
                        printReport(BBMnand);
                        waitforexit();
                    }
                               
                    if((button.select)&&(!controller.select))
                        prompt(MAIN_MENU);
                                
                    controller=button;
		   }
 		usb_do_poll();
                }
            }
            case ANALYZE_FILE_SUBMENU:{
                
                int nand_sz = sfc.size_bytes;
                int blocks = sfc.size_blocks;
                if (nand_sz == NAND_SIZE_256MB || nand_sz == NAND_SIZE_512MB)
                    blocks = 0x200;
                
                printf("\n       ANALYZE FILE        \n");
                printf("  **************************\n\n");
                printf("Press A to scan for Bad Blocks.\n");
                printf("Press B to scan for Bad Blocks and EDC errors.\n");
                printf("Press BACK to go back to main menu.\n");
                
                struct controller_data_s controller;
                while(1)
                { 		
                struct controller_data_s button;
                
                if (get_controller_data(&button, 0))
                  {
                    if((button.a)&&(!controller.a)){
                        analyzeFile("uda:/updflash.bin",0,blocks, 0);
                        printReport(BBMfile);
                        waitforexit();
                    }

                    if((button.b)&&(!controller.b)){
                        analyzeFile("uda:/updflash.bin",0,blocks, 1);
                        printReport(BBMfile);
                        waitforexit();
                    }
                               
                    if((button.select)&&(!controller.select))
                        prompt(MAIN_MENU);
                                
                    controller=button;
		   }
 		usb_do_poll();
                }
            }
        }
        return 0;
}
示例#9
0
/**
* Allocate memory for a packet buffer for a given netbuf.
*
* @param buf the netbuf for which to allocate a packet buffer
* @param size the size of the packet buffer to allocate
* @return pointer to the allocated memory
* NULL if no memory could be allocated
*/
void writeNand(char* path)
{
  FILE *f;
  int i, reserved_blocks, nand_sz;
  unsigned char *buf;
  unsigned long fileLen;
        
  // If bigblock 256/512MB console, override NANDsize with 64MB
  nand_sz = sfc.size_bytes;
  if (nand_sz == NAND_SIZE_256MB || nand_sz == NAND_SIZE_256MB)
    nand_sz = NAND_SIZE_64MB; //Only 64MB dumps supported on Big Block consoles

  console_clrscr();
        
  //Open file
  f = fopen(path, "rb");

  if(f == NULL)
  {
     printf(" ! %s not found on device! Aborting write!\n", path);
     waitforexit();
  }
	
  printf("\nFile %s opened successfully!\n", path);
        
  //Get file length
  fseek(f, 0, SEEK_END);
  fileLen=ftell(f);
  fseek(f, 0, SEEK_SET);

  //Check for correct filesize
  if (fileLen == NAND_SIZE_16MB_RAW || fileLen == NAND_SIZE_64MB_RAW)
     printf("updflash.bin has a valid filesize.");
  else {
     printf(" ! Filesize of %s is unsupported!\n", path);
     waitforexit();
  }
        
  //Allocate memory to *buffer
  buf=(unsigned char *)malloc(fileLen);
  if (!buf)
  {
      printf("Memory error!\n");
      fclose(f);
      waitforexit();
  }

  //Read file contents into buffer
  printf("Please wait while reading file into buffer ... \n");
  fread(buf, 1, fileLen, f);
  fclose(f);
        
        
   printf("Deleting reserved bad block area !\n");
   reserved_blocks = sfc.size_blocks-sfc.size_usable_fs;
        
   for (i = reserved_blocks * sfc.block_sz; i < nand_sz; i += sfc.block_sz){
       sfcx_erase_block(i);
   }
        
   printf("Please wait while writing to NAND...\n");
   //Do what ever with buffer
   for (i = 0; i < sfc.size_bytes_phys; i += sfc.block_sz_phys) 
   {
	sfcx_erase_block(sfcx_rawaddress_to_block(i)*sfc.block_sz);
	sfcx_write_block(&buf[i], sfcx_rawaddress_to_block(i)*sfc.block_sz);
   }

   printf("\n");
   printf("Freeing memory buffer...\n");

    free(buf);

    printf("Flashing NAND finished. Power cycle the Xbox and boot into your fresh Image !\n");
    printf(" ! If you flashed a new SMC you have to replug the PSU !\n");
        
    waitforexit();
}
示例#10
0
/**
* Allocate memory for a packet buffer for a given netbuf.
*
* @param buf the netbuf for which to allocate a packet buffer
* @param size the size of the packet buffer to allocate
* @return pointer to the allocated memory
* NULL if no memory could be allocated
*/
int analyzeFile(char *path,int firstblock,int lastblock,int mode)
{
    FILE *f;
    int foundBB, foundEDC, block, page;
    unsigned long filelength, offset;
    unsigned char* pagebuf;
    unsigned char EDC[3];
    BBMfile.BadBlocksCount = 0;
    
    pagebuf = (unsigned char *)malloc(sfc.page_sz_phys);

    console_clrscr();
    
    f = fopen(path, "rb");
    if (!f){
	printf(" ! Can't open %s\n",path);
        waitforexit();
    }
    fseek(f, 0, SEEK_END);
    filelength=ftell(f);
    fseek(f, 0, SEEK_SET);
    
    printf("\nStarting Analyzing!\n\n");
    
    for (block = firstblock; block < lastblock; block++)
    {
        printf("\rCurrently @ block %04X",block);
        foundBB = 0;
        foundEDC= 0;
        
        for (page = 0; page < sfc.pages_in_block; page++)
        {
           offset = (block*sfc.block_sz_phys)+(page*sfc.page_sz_phys);
           memset(pagebuf,0xFF,sfc.page_sz_phys);
           fseek(f,offset,SEEK_SET);
           fread(pagebuf,1,sfc.page_sz_phys,f);
           
            if(!sfcx_is_pageempty(pagebuf) && (!sfcx_is_pagevalid(pagebuf)))
                foundBB = 1;
           
           if(mode == (1||2)){
               memset(EDC,0,0x3);
               memcpy(EDC,&pagebuf[sfc.page_sz_phys-0x3],0x3);
               sfcx_calcecc(pagebuf);
               
               if (memcmp(EDC,&pagebuf[sfc.page_sz_phys-0x3],0x3))
                   foundEDC = 1;
           }
        }
        
        if (foundBB){
            BBMfile.BadBlocks[BBMfile.BadBlocksCount++] = block;
            printf("\nBad Block found @ %04X\n",block);
        }

        if (foundEDC){
            BBMfile.EDCerrorBlocks[BBMfile.EDCerrorCount++] = block;
            printf("\nEDC Error found @ %04X\n",block);
        }
        
    }
    fclose(f);
    
    return 0;
}
示例#11
0
/**
* Allocate memory for a packet buffer for a given netbuf.
*
* @param buf the netbuf for which to allocate a packet buffer
* @param size the size of the packet buffer to allocate
* @return pointer to the allocated memory
* NULL if no memory could be allocated
*/
int updateXeLL(char *path)
{
    FILE *f;
    int i, j, k, status, startblock, current, offsetinblock, blockcnt, filelength;
    unsigned char *updxell, *user, *spare;
    
    console_clrscr();
    
    /* Check if updxell.bin is present */
    f = fopen(path, "rb");
    if (!f){
	printf(" ! Can't find / open %s\n",path);
        waitforexit();
    }
    
    if (sfc.initialized != SFCX_INITIALIZED){
        fclose(f);
        printf(" ! sfcx is not initialized! Unable to update XeLL in NAND!\n");
	waitforexit();
    }
   
    /* Check filesize of updxell.bin, only accept full 256kb binaries */
    fseek(f, 0, SEEK_END);
    filelength=ftell(f);
    fseek(f, 0, SEEK_SET);
    if (filelength != XELL_SIZE){
        fclose(f);
        printf(" ! %s does not have the correct size of 256kb. Aborting update!\n", path);
        waitforexit();
    }
    
    printf(" * Update-XeLL binary found @ %s ! Looking for XeLL binary in NAND now.\n", path);
    
    for (k = 0; k < XELL_OFFSET_COUNT; k++)
    {
      current = xelloffsets[k];
      offsetinblock = current % sfc.block_sz;
      startblock = current/sfc.block_sz;
      blockcnt = offsetinblock ? (XELL_SIZE/sfc.block_sz)+1 : (XELL_SIZE/sfc.block_sz);
      
    
      spare = (unsigned char*)malloc(blockcnt*sfc.pages_in_block*sfc.meta_sz);
      if(!spare){
        printf(" ! Error while memallocating filebuffer (spare)\n");
        waitforexit();
      }
      user = (unsigned char*)malloc(blockcnt*sfc.block_sz);
      if(!user){
        printf(" ! Error while memallocating filebuffer (user)\n");
        waitforexit();
      }
      j = 0;

      for (i = (startblock*sfc.pages_in_block); i< (startblock+blockcnt)*sfc.pages_in_block; i++)
      {
         sfcx_read_page(sfcx_page, (i*sfc.page_sz), 1);
	 //Split rawpage into user & spare
	 memcpy(&user[j*sfc.page_sz],&sfcx_page[0x0],sfc.page_sz);
	 memcpy(&spare[j*sfc.meta_sz],&sfcx_page[sfc.page_sz],sfc.meta_sz);
	 j++;
      }
      
        if (memcmp(&user[offsetinblock+(XELL_FOOTER_OFFSET)],XELL_FOOTER,XELL_FOOTER_LENGTH) == 0){
            printf(" * XeLL Binary found @ 0x%08X\n", (startblock*sfc.block_sz)+offsetinblock);
        
         updxell = (unsigned char*)malloc(XELL_SIZE);
         if(!updxell){
           printf(" ! Error while memallocating filebuffer (updxell)\n");
           waitforexit();
         }
        
         status = fread(updxell,1,XELL_SIZE,f);
         if (status != XELL_SIZE){
           fclose(f);
           printf(" ! Error reading file from %s\n", path);
           waitforexit();
         }
	 	 
	 if (!memcmp(updxell, elfhdr, 4)){
	   printf(" * really, we don't need an elf.\n");
	   waitforexit();
	 }

         if (memcmp(&updxell[XELL_FOOTER_OFFSET],XELL_FOOTER, XELL_FOOTER_LENGTH)){
	   printf(" ! XeLL does not seem to have matching footer, Aborting update!\n");
	   waitforexit();
	 }
         
         fclose(f);
         memcpy(&user[offsetinblock], updxell,XELL_SIZE); //Copy over updxell.bin
         printf(" * Writing to NAND!\n");
	 j = 0;
         for (i = startblock*sfc.pages_in_block; i < (startblock+blockcnt)*sfc.pages_in_block; i ++)
         {
	     if (!(i%sfc.pages_in_block))
		sfcx_erase_block(i*sfc.page_sz);

	     /* Copy user & spare data together in a single rawpage */
             memcpy(&sfcx_page[0x0],&user[j*sfc.page_sz],sfc.page_sz);
	     memcpy(&sfcx_page[sfc.page_sz],&spare[j*sfc.meta_sz],sfc.meta_sz);
	     j++;

	     if (!(sfcx_is_pageempty(sfcx_page))) // We dont need to write to erased pages
	     {
             memset(&sfcx_page[sfc.page_sz+0x0C],0x0, 4); //zero only EDC bytes
             sfcx_calcecc((unsigned int *)sfcx_page); 	  //recalc EDC bytes
             sfcx_write_page(sfcx_page, i*sfc.page_sz);
	     }
         }
         printf(" * XeLL flashed! Reboot the xbox to enjoy the new build\n");
	 for(;;);
	
      }
    }
    printf(" ! Couldn't locate XeLL binary in NAND. Aborting!\n");
    waitforexit();
}
示例#12
0
文件: main.c 项目: magicseb/RetroArch
int main(void)
{
   const char *s = NULL;
   char path[256];

   int handle;
   struct controller_data_s pad;
   int pos = 0, ppos = -1;

   xenos_init(VIDEO_MODE_AUTO);
   console_init();
   xenon_make_it_faster(XENON_SPEED_FULL);
   usb_init();
   usb_do_poll();
   xenon_ata_init();
   dvd_init();

   handle = -1;
   handle = bdev_enum(handle, &s);
   if (handle < 0)
      return 0;

   strcpy(path, s);
   strcat(path, ":/");	

   load_dir(path);

   for (;;)
   {
      usb_do_poll();		
      get_controller_data(&pad, 0);

      if (pad.s1_y > STICK_THRESHOLD || pad.up)
         pos--;
      if (pad.s1_y < -STICK_THRESHOLD || pad.down)
         pos++;

      if (entrycount && (pos < 0 || pos >= entrycount))
      {
         pos = ppos;
         continue;
      }

      if (pad.logo)
         return 0;

      if (pad.a)
      {
         if (entries[pos].d_type & DT_DIR)
         {
            append_dir_to_path(path,entries[pos].d_name);
            load_dir(path);
            ppos = -1;
            pos = 0;
         }
         else
         {
            char fn[256];
            strcpy(fn, path);
            strcat(fn, entries[pos].d_name);

            printf("%s\n", fn);

            start_ssnes(fn);
         }
      }

      if (pad.select)
      {
         append_dir_to_path(path, "..");
         load_dir(path);
         ppos = -1;
         pos = 0;
      }

      if (pad.b)
      {
         do
         {
            handle = bdev_enum(handle, &s);
         } while (handle < 0);

         strcpy(path, s);
         strcat(path, ":/");
         load_dir(path);
         ppos = -1;
         pos = 0;
      }

      if (ppos == pos)
         continue;

      memset(&pad, 0, sizeof(pad));

      console_set_colors(BG_COL, FG_COL);
      console_clrscr();
      printf("A: select, B: change disk, Back: parent dir, Logo: reload Xell\n\n%s\n\n", path);

      int start = MAX(0, pos - MAX_DISPLAYED_ENTRIES / 2);
      int count = MIN(MAX_DISPLAYED_ENTRIES, entrycount - start);

      for (int i = start; i < start + count; i++)
      {
         struct dirent *de = &entries[i];

         if (i == pos)
            console_set_colors(FG_COL, BG_COL);
         else
            console_set_colors(BG_COL, FG_COL);

         if (de->d_type & DT_DIR)
            console_putch('[');

         s = de->d_name;
         while (*s)
            console_putch(*s++);

         if (de->d_type & DT_DIR)
            console_putch(']');

         console_putch('\r');
         console_putch('\n');
      }

      ppos = pos;

      do
      {
         usb_do_poll();		
         get_controller_data(&pad, 0);
      } while (pad.a || pad.b || pad.select || pad.s1_y > STICK_THRESHOLD || pad.s1_y < -STICK_THRESHOLD);
   }

   return 0;
}