//--------- FlashBoot2.c --------- // Requires Ndless 1.1.xxxx for prototypes // This program is a tool for Flashing/verifying Boot2 Images. // Dont power down or reboot till boot2 successfully flashed, otherwise an inexpensive USB-rs232 module. // is required to flash boot2. #include #include "utils.h" extern int write_nand( void *source, unsigned size, unsigned offset); #define BOOT2_SIZE 0x14C000 // maximum asm(".string \"PRG\"\n"); // Ndless 1.1 required.... int main(void) { void *boot2; FILE *ifile; int result,bytesread; // --- load the boot2 image to be flashed -------- ifile = fopen("/documents/ndless/boot2.img.tns", "rb"); if (!ifile) { errormsg("Can't open input file boot2.img.tns"); return 1; } boot2 = malloc(BOOT2_SIZE); if (!boot2) { errormsg("Can't malloc"); fclose(ifile); return 1; } memset(boot2,0xff,BOOT2_SIZE); bytesread = fread(boot2, 1,BOOT2_SIZE, ifile); if (bytesread <= 0) { fclose(ifile); free(boot2); errormsg("Can't read BOOT2 from input file"); return 1; } fclose(ifile); // boot2_nand_offset = 0x4000 = BOOT2_PAGE_OFFSET * NAND_PAGE_SIZE // ending range = 0x14BFFF = boot2_nand_offset + BOOT2_SIZE -1 result = flash_erase_range(0x4000,0x14BFFF); printf("flash_erase_range:%X\n",result); if(result != 1){ errormsg("Error erasing old Boot2\n try again"); free(boot2); return 1; } result = write_nand(boot2, BOOT2_SIZE ,0x4000); printf("write_nand:%X\n",result); free(boot2); if(result == 1){ errormsg("Image successfully written!"); }else{ errormsg("Error writing Image\ntry again"); return 1; } return 0; }