//--------- FlashDiags.c --------- // This software has the potential to brick the calculator // if modified for other uses(like Flashing boot2) - an inexpensive($20) RS232-USB module is suggested as a backup in this case #include #define NAND_PAGE_SIZE 0x200 #define NAND_PAGE_FULLSIZE 0x210 #define DIAGS_PAGE_OFFSET 0xB00 #define DIAGS_SIZE 0xA0000 static const unsigned write_nand_addrs[] = {0x105DD340, 0x106144e0, 0x1027668c, 0x10276f5c}; // OS 1.7 , OS 2.0.1.60 #define write_nand SYSCALL_CUSTOM(write_nand_addrs,int, void *source,int size, unsigned int offset) static const unsigned flash_erase_range_addrs[] = {0x10226150, 0x10228160,0x10276424, 0x10276cf4}; // OS 1.7 , OS 2.0.1.60 #define flash_erase_range SYSCALL_CUSTOM(flash_erase_range_addrs,int, int offset,int size) void errormsg(char *mesg){ char title[180]; char msg[200]; ascii2utf16(title, "Diags Flashing Tool", sizeof(title)); ascii2utf16(msg, mesg, sizeof(msg)); show_dialog_box2(0, title, msg); } int main(void) { void *buf; FILE *ifile; int result,bytesread; ifile = fopen("/documents/ndless/diags.img.tns", "rb"); if (!ifile) { errormsg("Can't open input file"); return 1; } buf = malloc(DIAGS_SIZE); if (!buf) { fclose(ifile); errormsg("Can't malloc"); return 1; } memset(buf,0xff,sizeof(buf)); bytesread = fread(buf, 1, DIAGS_SIZE, ifile); if (bytesread <= 0) { fclose(ifile); free(buf); errormsg("Can't read DIAGS from input file"); return 1; } fclose(ifile); // diags_nand_offset = 0x160000 = DIAGS_PAGE_OFFSET * NAND_PAGE_SIZE // ending range = 0x1FFFFF = diags_nand_offset + DIAGS_SIZE -1 result = flash_erase_range(0x160000,0x1FFFFF); printf("flash_erase_range:%X\n",result); if(result != 1){ errormsg("Error erasing old Diags"); free(buf); return 1; } result = write_nand(buf, DIAGS_SIZE ,0x160000); printf("write_nand:%X\n",result); free(buf); if(result == 0){ errormsg("Diags successfully written!"); }else{ errormsg("Error writing Diags"); return 1; } return 0; }