Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NANDReader
- #include <fcntl.h>
- #include <unistd.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <debug.h>
- #include <xenos/xenos.h>
- #include <console/console.h>
- #include <time/time.h>
- #include <usb/usbmain.h>
- #include <ppc/register.h>
- #include <xenon_nand/xenon_sfcx.h>
- #include <xenon_nand/xenon_config.h>
- #include <xenon_soc/xenon_secotp.h>
- #include <xenon_smc/xenon_smc.h>
- //Xenos, console, USB inits
- void mainInit(){
- xenos_init(VIDEO_MODE_AUTO);
- console_init();
- usb_init();
- usb_do_poll();
- }
- //Read the entire NAND to file on USB
- void writeNANDToFile() {
- if(sfcx_init()<10)
- return;
- FILE *f = fopen("uda:/NAND.bin", "wb");
- if(f){
- unsigned char* buff = (unsigned char*) malloc(sfc.block_sz_phys);
- unsigned int buffer_len = sfc.block_sz_phys;
- int i;
- for (i = 0; i < sfc.size_bytes; i += sfc.block_sz) {
- sfcx_read_block(buff, i, 1);
- if(buffer_len!=fwrite(buff, 1, buffer_len, f))
- {
- printf("Error dumping nand !!! please check disk space !!\n");
- }
- printf("Reading...\r");
- }
- fclose(f);
- free(buff);
- }
- }
- //Read UPDNAND.bin from USB, to memory buffer, to NAND
- void writeFileToFlash(){
- int j;
- FILE *UPDNAND;
- unsigned char *buffer;
- unsigned long fileLen;
- //Open file
- UPDNAND = fopen("uda:/UPDNAND.bin", "rb");
- //Get file length
- fseek(UPDNAND, 0, SEEK_END);
- fileLen=ftell(UPDNAND);
- fseek(UPDNAND, 0, SEEK_SET);
- //Allocate memory to *buffer
- buffer=(unsigned char *)malloc(fileLen+1);
- if (!buffer)
- {
- fprintf(stderr, "Memory error!");
- fclose(UPDNAND);
- return -1;
- }
- //Read file contents into buffer
- fread(buffer, fileLen, 1, UPDNAND);
- fclose(UPDNAND);
- //Do what ever with buffer
- for (i = 0; i < sfc.size_bytes; i += sfc.block_sz) {
- sfcx_read_block(buffer, i, 1);
- printf("Writing...\r");
- }
- printf("\nDone!\n");
- free(buffer);
- }
- int main(){
- mainInit();
- printf("SFCX Init.\n");
- sfcx_init();
- if (sfc.initialized != SFCX_INITIALIZED)
- {
- printf(" ! sfcx initialization failure\n");
- printf(" ! nand related features will not be available\n");
- delay(5);
- return -1;
- }
- printf("Xenon_config_init.\n");
- xenon_config_init();
- writeNANDToFile();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement