void write_file() { unsigned long len = 0; int have_begin = 0; unsigned char* buf = (unsigned char*)0x52000000; int nodata_time = 0; unsigned char c; printf("Use minicom to send file.\n"); while(1) { if(uart_getc_nowait(&buf[len]) == 0) { have_begin = 1; nodata_time = 0; len++; } else { if(have_begin) { nodata_time++; } } if(nodata_time == 1000) { break; } } printf("Have get %d bytes data\n",len); printf("Press y to program: "); c = uart_getc(); if(c == 'y' || c == 'Y') { nand_erase_block(0); nand_write_page(0,buf,len); printf("\nUpdate program successful\n"); } else { printf("\nUpdate program cancel\n"); } }
void nand_write_test() { char buf[100]; unsigned long addr; unsigned long size; printf("Enter the start address: "); scanf("%lu",&addr); printf("\nEnter the string: "); scanf("%s",buf); size = strlen(buf) + 1; nand_write_page(addr,buf,size); }
void copy_file2nand(unsigned int ramAddr,unsigned int blockAddr,unsigned int fileSize) { //计算boot代码大小,确定需要格式化Block的块总数、需要写入的Page总数 unsigned long bootSize = fileSize; //uboot代码长度 unsigned long blockTotal,pageTotal; blockTotal = ( (bootSize + NAND_BLOCK_MASK ) & (~NAND_BLOCK_MASK) ) / NAND_BLOCK_SIZE; pageTotal = ( (bootSize + NAND_PAGE_MASK ) & (~NAND_PAGE_MASK) ) / NAND_PAGE_SIZE; printk("\r\ncode size 0x%x (%dByte)\r\n",bootSize,bootSize); printk("require block %d require page %d\r\n",blockTotal,pageTotal); //烧录进FLASH,不带坏块检测 char retErase; unsigned char *lpsrcData = (unsigned char *)ramAddr; //SDRAM 0x30000000地址的代码 unsigned int off_data,page_addr; retErase = nand_erase_block(blockAddr); // printk("retrEsdrase %d\r\n",retErase); off_data = 0; page_addr = blockAddr; while(off_data < bootSize) { nand_write_page( page_addr, (unsigned char*)(lpsrcData + off_data) , NAND_PAGE_SIZE); // nand_write_page( // page_addr, // (unsigned char*)(lpsrcData + off_data)); // printk("colum 0x%8.8x write data off %d page_addr %d\r\n",off_data,off_data,page_addr); // PrintNandFlash((unsigned char*)(lpsrcData + off_data),16); off_data += NAND_PAGE_SIZE; page_addr += NAND_PAGE_ADDR; } }