📄 nandwriter.c
字号:
/* --------------------------------------------------------------------------
FILE : nandwriter.c
PURPOSE : NAND writer main program
PROJECT : DaVinci CCS NAND Flashing Utility
AUTHOR : Daniel Allred
DATE : 04-Jun-2007
HISTORY
v1.00 - DJA - 04-Jun-2007
Completion (with support for DM6441 and DM6441_LV)
----------------------------------------------------------------------------- */
#include "stdio.h"
#include "nand.h"
#include "util.h"
#include "nandwriter.h"
#pragma DATA_SECTION(DDRStart,".ddr_mem");
VUint32 DDRStart;
#pragma DATA_SECTION(NANDStart,".aemif_mem");
VUint32 NANDStart;
/* ------------------------------------------------------------------------ *
* *
* nandwriter( ) *
* *
* ------------------------------------------------------------------------ */
Uint32 nandwriter()
{
Uint32 numPages;
NAND_BOOT gNandBoot;
PNAND_INFO pNandInfo;
FILE *fPtr;
Uint8 *ramPtr;
Int32 fileSize = 0;
Int8 fileName[256];
Int8 answer[24];
// Setup pointer in RAM (alloc 32MB space)
ramPtr = (Uint8 *) ubl_alloc_mem(MAX_IMAGE_SIZE);
printf( "Starting DV_NANDWriter.\r\n");
// Initialize NAND Flash
pNandInfo = NAND_Open((Uint32)&NANDStart);
if (pNandInfo == NULL)
{
printf( "\tERROR: NAND Initialization failed.\r\n" );
return E_FAIL;
}
// Read the file from host
printf("Enter the UBL file Name:\r\n");
scanf("%s", fileName);
fflush(stdin);
// Open an File from the hard drive
fPtr = fopen(fileName, "rb");
if(fPtr == NULL)
{
printf("\tERROR: File %s Open failed\r\n", fileName);
return E_FAIL;
}
// Initialize the pointer
fileSize = 0;
// Read file size
fseek(fPtr,0,SEEK_END);
fileSize = ftell(fPtr);
// Setup pointer in RAM
ramPtr = (Uint8 *) ubl_alloc_mem(fileSize);
if(fileSize == 0)
{
printf("\tERROR: File read failed.. Closing program.\r\n");
fclose (fPtr);
return E_FAIL;
}
fseek(fPtr,0,SEEK_SET);
if (fileSize != fread(ramPtr, 1, fileSize, fPtr))
{
printf("\tWARNING: File Size mismatch.\r\n");
}
fclose (fPtr);
numPages = 0;
while ( (numPages * pNandInfo->bytesPerPage) < (fileSize) )
{
numPages++;
}
gNandBoot.magicNum = UBL_UART_BOOT;
gNandBoot.block = START_UBL_BLOCK_NUM;
gNandBoot.page = 0;
gNandBoot.numPage = numPages;
gNandBoot.entryPoint = 0x0100; // This fixed entry point will work with the UBLs
gNandBoot.ldAddress = 0; // This doesn't matter for the UBL
if (NAND_WriteHeaderAndData(pNandInfo,&gNandBoot,ramPtr) != E_PASS)
{
printf("\tERROR: Write failed.\r\n");
return E_FAIL;
}
// Read the file from host
printf("Enter the U-boot or application file name:\r\n");
scanf("%s", fileName);
fflush(stdin);
// Open an File from the hard drive
fPtr = fopen(fileName, "rb");
if(fPtr == NULL)
{
printf("\tERROR: File %s open failed.\r\n", fileName);
return E_FAIL;
}
// Initialize the pointer
fileSize = 0;
// Read file size
fseek(fPtr,0,SEEK_END);
fileSize = ftell(fPtr);
// Setup pointer in RAM
ramPtr = (Uint8 *) ubl_alloc_mem(fileSize);
if(fileSize == 0)
{
printf("\tERROR: File read failed.. Closing program.\r\n");
fclose (fPtr);
return E_FAIL;
}
fseek(fPtr,0,SEEK_SET);
if (fileSize != fread(ramPtr, 1, fileSize, fPtr))
{
printf("\tWARNING: File Size mismatch\n");
}
fclose (fPtr);
numPages = 0;
while ( (numPages * pNandInfo->bytesPerPage) < (fileSize) )
{
numPages++;
}
// Get the entry point and load addresses
printf("Enter the U-boot or application entry point: \n");
scanf("%s", answer);
gNandBoot.entryPoint = strtoul(answer, NULL, 16);
fflush(stdin);
if ( (gNandBoot.entryPoint < RAM_START_ADDR) || (gNandBoot.entryPoint > RAM_END_ADDR) )
{
printf("\tWARNING: Entry point not in acceptable range - using default 0x81080000.\r\n");
gNandBoot.entryPoint = 0x81080000;
}
else
{
printf("Selected entry point is 0x%x.\r\n",gNandBoot.entryPoint);
}
printf("Enter the U-boot or application load address: \r\n");
scanf("%s", answer);
gNandBoot.ldAddress = strtoul(answer, NULL, 16);
if ( (gNandBoot.ldAddress < RAM_START_ADDR) || (gNandBoot.ldAddress > RAM_END_ADDR) )
{
printf("\tWARNING: Load address not in acceptable range - using default 0x81080000.\r\n");
gNandBoot.ldAddress = 0x81080000;
}
gNandBoot.magicNum = UBL_MAGIC_BIN_IMG;
gNandBoot.block = START_APP_BLOCK_NUM;
gNandBoot.page = 0;
gNandBoot.numPage = numPages;
if (NAND_WriteHeaderAndData(pNandInfo, &gNandBoot,ramPtr) != E_PASS)
{
printf("\tERROR: Write Failed\n");
return E_FAIL;
}
return E_PASS;
}
/* ------------------------------------------------------------------------ *
* *
* main( ) *
* *
* ------------------------------------------------------------------------ */
void main( void )
{
int status;
// Init memory alloc pointer
set_current_mem_loc(0);
// Execute the NAND test
status = nandwriter();
/* Check for test fail */
if (status != E_PASS)
{
/* Print error message */
printf( "\tNAND flashing failed!\r\n");
}
else
{
/* Print error message */
printf( "\tNAND boot preparation was successful!\r\n" );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -