//--------- FlashBoot2.c --------- // This software has the potential to brick the calculator // 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 BOOT2_PAGE_OFFSET 0x20 #define BOOT2_SIZE 0x14C000 // max it can be 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, "Boot2 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/boot2.img.tns", "rb"); if (!ifile) { errormsg("Can't open input file"); return 1; } buf = malloc(BOOT2_SIZE); if (!buf) { fclose(ifile); errormsg("Can't malloc"); return 1; } memset(buf,0xff,sizeof(buf)); bytesread = fread(buf, 1, BOOT2_SIZE, ifile); if (bytesread <= 0) { fclose(ifile); free(buf); errormsg("Can't read BOOT2 from input file"); return 1; } fclose(ifile); // boot2_nand_offset = 0x4000 = BOOT2_PAGE_OFFSET * NAND_PAGE_SIZE // ending range = 0x14FFFF = boot2_nand_offset + BOOT2_SIZE -1 result = flash_erase_range(0x4000,0x14FFFF); printf("flash_erase_range:%X\n",result); if(result != 1){ errormsg("Error erasing old Boot2\n try again"); free(buf); return 1; } result = write_nand(buf, BOOT2_SIZE ,0x4000); printf("write_nand:%X\n",result); free(buf); if(result == 0){ errormsg("Image successfully written!"); }else{ errormsg("Error writing Image\ntry again"); return 1; } return 0; }