static Uint32 LOCAL_spiwriter() { SPI_MEM_InfoHandle hSpiMemInfo; Int8 fileName[256]; Uint32 baseAddress = 0; Bool useHeaderForApp = FALSE; DEBUG_printString( "Starting "); DEBUG_printString( (String) devString); DEBUG_printString( " SPIWriter.\r\n"); // Prep device for SPI writing (pinmux/PSC) DEVICE_SPIInit(DEVICE_SPIBOOT_PERIPHNUM); // Initialize SPI Memory Device hSpiMemInfo = SPI_MEM_open(DEVICE_SPIBOOT_PERIPHNUM, DEVICE_SPIBOOT_CSNUM, hDEVICE_SPI_config); if (hSpiMemInfo == NULL) { DEBUG_printString( "\tERROR: SPI Memory Initialization failed.\r\n" ); return E_FAIL; } DEBUG_printString("Will you be writing a UBL image? (Y or y) \r\n"); DEBUG_readString(fileName); fflush(stdin); if ((strcmp(fileName,"y") == 0) || (strcmp(fileName,"Y") == 0)) { // Read the AIS file from host DEBUG_printString("Enter the binary AIS UBL file name (enter 'none' to skip): \r\n"); DEBUG_readString(fileName); fflush(stdin); LOCAL_GetAndWriteFileData(hSpiMemInfo, fileName, baseAddress, FALSE); // Assume that the UBL will fit in the first block of the SPI flash baseAddress += hSpiMemInfo->hMemParams->blockSize; useHeaderForApp = TRUE; } // Read the AIS file from host DEBUG_printString("Enter the application file name (enter 'none' to skip): \r\n"); DEBUG_readString(fileName); fflush(stdin); if (LOCAL_GetAndWriteFileData(hSpiMemInfo, fileName, baseAddress, useHeaderForApp) != E_PASS) { DEBUG_printString("SPI Flashing Failed!"); return E_FAIL; } return E_PASS; }
static Uint32 nandwriter() { Uint32 numPagesAIS; NAND_InfoHandle hNandInfo; FILE *fPtr; Uint8 *aisPtr; Int32 aisFileSize = 0,aisAllocSize = 0; Int8 fileName[256]; Int32 i=0; DEBUG_printString("Starting OMAP-L137 NANDWriter.\r\n"); // Initialize NAND Flash hNandInfo = NAND_open((Uint32)&NANDStart, DEVICE_emifBusWidth() ); if (hNandInfo == NULL) { DEBUG_printString( "\tERROR: NAND Initialization failed.\r\n" ); return E_FAIL; } // Read the file from host DEBUG_printString("Enter the binary AIS file name to flash (enter 'none' to skip) :\r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Read file size fseek(fPtr,0,SEEK_END); aisFileSize = ftell(fPtr); if(aisFileSize == 0) { DEBUG_printString("\tERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return E_FAIL; } numPagesAIS = 0; while ( (numPagesAIS * hNandInfo->dataBytesPerPage) < aisFileSize ) { numPagesAIS++; } //We want to allocate an even number of pages. aisAllocSize = numPagesAIS * hNandInfo->dataBytesPerPage; // Setup pointer in RAM aisPtr = (Uint8 *) UTIL_allocMem(aisAllocSize); // Clear memory for (i=0; i<aisAllocSize; i++) aisPtr[i]=0xFF; // Go to start of file fseek(fPtr,0,SEEK_SET); // Read file data if (aisFileSize != fread(aisPtr, 1, aisFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch.\r\n"); } // Close file fclose (fPtr); // Write the file data to the NAND flash if (LOCAL_writeData(hNandInfo, aisPtr, numPagesAIS) != E_PASS) { printf("\tERROR: Write failed.\r\n"); return E_FAIL; } } return E_PASS; }
static Uint32 norwriter() { NOR_InfoHandle hNorInfo; FILE *fPtr; Uint8 *appPtr; Int32 appFileSize = 0; Int8 fileName[256]; Uint32 baseAddress = 0; DEBUG_printString( "Starting NORWriter.\r\n"); // Initialize NOR Flash hNorInfo = NOR_open((Uint32)&NORStart, (Uint8)DEVICE_emifBusWidth() ); if (hNorInfo == NULL) { DEBUG_printString( "\tERROR: NOR Initialization failed.\r\n" ); return E_FAIL; } // Set base address to start putting data at baseAddress = hNorInfo->flashBase; // Read the UBL file from host DEBUG_printString("Enter the binary AIS application file name (enter 'none' to skip): \r\n"); #ifndef INPUT_FILE DEBUG_readString(fileName); fflush(stdin); #else strcpy(fileName, "../../../../../proj/ais/tcas_decoder.ais"); #endif if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Initialize the pointer appFileSize = 0; // Read file size fseek(fPtr,0,SEEK_END); appFileSize = ftell(fPtr); // Check to make sure image was read correctly if(appFileSize == 0) { DEBUG_printString("\tERROR: File read failed.\r\n"); fclose (fPtr); return E_FAIL; } // Check to make sure the app image will fit else if ( appFileSize > hNorInfo->flashSize ) { DEBUG_printString("\tERROR: File too big.. Closing program.\r\n"); fclose (fPtr); } // Setup pointer in RAM appPtr = (Uint8 *) UTIL_allocMem(appFileSize); fseek(fPtr,0,SEEK_SET); if (appFileSize != fread(appPtr, 1, appFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch.\r\n"); } fclose (fPtr); // Erase the NOR flash to accomadate the file size if (NOR_erase( hNorInfo, baseAddress, appFileSize ) != E_PASS) { DEBUG_printString("\tERROR: Erasing NOR failed.\r\n"); return E_FAIL; } // Write the application data to the flash if (NOR_writeBytes( hNorInfo, baseAddress, appFileSize, (Uint32)appPtr) != E_PASS) { DEBUG_printString("\tERROR: Writing NOR failed.\r\n"); return E_FAIL; } } return E_PASS; }
static Uint32 nandwriter() { Uint32 numPagesUBL; Uint32 numPagesAPP; NANDWRITER_Boot gNandBoot; NAND_InfoHandle hNandInfo; FILE *fPtr; Uint8 *ublPtr, *appPtr; Int32 ublFileSize = 0,ublAllocSize = 0, appFileSize = 0,appAllocSize = 0; Int8 fileName[256]; Int8 answer[24]; Int32 i=0; DEBUG_printString("Starting DM644x_NANDWriter.\r\n"); // Initialize NAND Flash hNandInfo = NAND_open((Uint32)&EMIFStart, (Uint8) DEVICE_emifBusWidth() ); if (hNandInfo == NULL) { DEBUG_printString( "\tERROR: NAND Initialization failed.\r\n" ); return E_FAIL; } // Read the file from host DEBUG_printString("Enter the binary UBL file Name (enter 'none' to skip) :\r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Read file size fseek(fPtr,0,SEEK_END); ublFileSize = ftell(fPtr); if(ublFileSize == 0) { DEBUG_printString("\tERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return E_FAIL; } numPagesUBL = 0; while ( (numPagesUBL * hNandInfo->dataBytesPerPage) < ublFileSize ) { numPagesUBL++; } //We want to allocate an even number of pages. ublAllocSize = numPagesUBL * hNandInfo->dataBytesPerPage; // Setup pointer in RAM ublPtr = (Uint8 *) UTIL_allocMem(ublAllocSize); for (i=0; i<ublAllocSize; i++) ublPtr[i]=0x00; fseek(fPtr,0,SEEK_SET); if (ublFileSize != fread(ublPtr, 1, ublFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch.\r\n"); } fclose (fPtr); gNandBoot.magicNum = UBL_MAGIC_SAFE; gNandBoot.block = DEVICE_NAND_RBL_SEARCH_START_BLOCK; gNandBoot.page = 0; gNandBoot.numPage = numPagesUBL; gNandBoot.entryPoint = 0x0100; // This fixed entry point will work with the UBLs gNandBoot.ldAddress = 0; // This doesn't matter for the UBL if (LOCAL_writeHeaderAndData(hNandInfo,&gNandBoot,ublPtr) != E_PASS) { printf("\tERROR: Write failed.\r\n"); return E_FAIL; } } // Read the file from host DEBUG_printString("Enter the U-boot or application file name (enter 'none' to skip):\r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Read file size fseek(fPtr,0,SEEK_END); appFileSize = ftell(fPtr); if(appFileSize == 0) { DEBUG_printString("\tERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return E_FAIL; } numPagesAPP = 0; while ( (numPagesAPP * hNandInfo->dataBytesPerPage) < (appFileSize) ) { numPagesAPP++; } // We want to allocate an even number of pages. appAllocSize = numPagesAPP * hNandInfo->dataBytesPerPage; // Setup pointer in RAM appPtr = (Uint8 *) UTIL_allocMem(appAllocSize); fseek(fPtr,0,SEEK_SET); if (appFileSize != fread(appPtr, 1, appFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch\n"); } fclose(fPtr); // Get the entry point and load addresses DEBUG_printString("Enter the U-boot or application entry point (in hex): \n"); DEBUG_readString(answer); gNandBoot.entryPoint = strtoul(answer, NULL, 16); fflush(stdin); if ( (gNandBoot.entryPoint < DEVICE_DDR2_START_ADDR) || (gNandBoot.entryPoint >= DEVICE_DDR2_END_ADDR) ) { DEBUG_printString("\tWARNING: Entry point not in acceptable range - using default 0x81080000.\r\n"); gNandBoot.entryPoint = 0x81080000; } else { DEBUG_printString("Selected entry point is "); DEBUG_printHexInt(gNandBoot.entryPoint); DEBUG_printString("\r\n"); } DEBUG_printString("Enter the U-boot or application load address (in hex): \r\n"); DEBUG_readString(answer); gNandBoot.ldAddress = strtoul(answer, NULL, 16); if ( (gNandBoot.ldAddress < DEVICE_DDR2_START_ADDR) || (gNandBoot.ldAddress >= DEVICE_DDR2_END_ADDR) ) { DEBUG_printString("\tWARNING: Load address not in acceptable range - using default 0x81080000.\r\n"); gNandBoot.ldAddress = 0x81080000; } gNandBoot.magicNum = UBL_MAGIC_BIN_IMG; gNandBoot.block = DEVICE_NAND_UBL_SEARCH_START_BLOCK; gNandBoot.page = 0; gNandBoot.numPage = numPagesAPP; if (LOCAL_writeHeaderAndData(hNandInfo, &gNandBoot, appPtr) != E_PASS) { DEBUG_printString("\tERROR: Write Failed\n"); return E_FAIL; } } return E_PASS; }
static Uint32 nandreader_ROM() { #if (1) Uint32 i,j, status; NAND_InfoHandle hNandInfo = &gMyNandInfo; #else Uint32 numPagesUBL; Uint32 numPagesAPP; Uint32 status; NANDWRITER_Boot gNandBoot; NAND_InfoHandle hNandInfo = &gMyNandInfo; FILE *fPtr; Uint8 *ublPtr, *appPtr; Int32 ublFileSize = 0,ublAllocSize = 0, appFileSize = 0,appAllocSize = 0; Int8 fileName[256]; Int8 answer[24]; #endif DEBUG_printString("Starting NANDReader_ROM.\r\n"); // Initialize NAND Flash (ROM init routine) status = NANDInit(); if (status != E_PASS) { DEBUG_printString( "\tERROR: NAND Initialization failed.\r\n" ); return E_FAIL; } hNandInfo->dataBytesPerPage = NANDFLASH_PAGESIZE(gNandInfo.page_size); hNandInfo->CSOffset = 0; hNandInfo->busWidth = (gNandInfo.nand_width==0)?BUS_8BIT:BUS_16BIT; hNandInfo->dataBytesPerOp = 512; hNandInfo->devID = gNandInfo.dev_code; hNandInfo->flashBase = 0x02000000; hNandInfo->spareBytesPerOp = 16; hNandInfo->pagesPerBlock = 0x1 << (gNandInfo.blk_shift - gNandInfo.page_shift); hNandInfo->isLargePage = gNandInfo.big_block; hNandInfo->numColAddrBytes = gNandInfo.page_shift >> 3; hNandInfo->numRowAddrBytes = gNandInfo.addr_cycles - hNandInfo->numColAddrBytes; #if (0) // Read the file from host DEBUG_printString("Enter the binary UBL file Name (enter 'none' to skip) :\r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Read file size fseek(fPtr,0,SEEK_END); ublFileSize = ftell(fPtr); if(ublFileSize == 0) { DEBUG_printString("\tERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return E_FAIL; } numPagesUBL = 0; while ( (numPagesUBL * hNandInfo->dataBytesPerPage) < ublFileSize ) { numPagesUBL++; } //We want to allocate an even number of pages. ublAllocSize = numPagesUBL * hNandInfo->dataBytesPerPage; // Setup pointer in RAM ublPtr = (Uint8 *) UTIL_allocMem(ublAllocSize); for (i=0; i<ublAllocSize; i++) ublPtr[i]=0x00; fseek(fPtr,0,SEEK_SET); if (ublFileSize != fread(ublPtr, 1, ublFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch.\r\n"); } fclose (fPtr); gNandBoot.magicNum = UBL_MAGIC_SAFE; gNandBoot.block = DEVICE_NAND_RBL_SEARCH_START_BLOCK; gNandBoot.page = 0; gNandBoot.numPage = numPagesUBL; gNandBoot.entryPoint = 0x0100; // This fixed entry point will work with the UBLs gNandBoot.ldAddress = 0; // This doesn't matter for the UBL if (LOCAL_readHeaderAndData(hNandInfo,&gNandBoot,ublPtr) != E_PASS) { printf("\tERROR: Read failed.\r\n"); return E_FAIL; } } // Read the file from host DEBUG_printString("Enter the U-boot or application file name (enter 'none' to skip):\r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Read file size fseek(fPtr,0,SEEK_END); appFileSize = ftell(fPtr); if(appFileSize == 0) { DEBUG_printString("\tERROR: File read failed.. Closing program.\r\n"); fclose (fPtr); return E_FAIL; } numPagesAPP = 0; while ( (numPagesAPP * hNandInfo->dataBytesPerPage) < (appFileSize) ) { numPagesAPP++; } // We want to allocate an even number of pages. appAllocSize = numPagesAPP * hNandInfo->dataBytesPerPage; // Setup pointer in RAM appPtr = (Uint8 *) UTIL_allocMem(appAllocSize); fseek(fPtr,0,SEEK_SET); if (appFileSize != fread(appPtr, 1, appFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch\n"); } fclose(fPtr); // Get the entry point and load addresses DEBUG_printString("Enter the U-boot or application entry point (in hex): \n"); DEBUG_readString(answer); gNandBoot.entryPoint = strtoul(answer, NULL, 16); fflush(stdin); if ( (gNandBoot.entryPoint < DEVICE_DDR2_START_ADDR) || (gNandBoot.entryPoint >= DEVICE_DDR2_END_ADDR) ) { DEBUG_printString("\tWARNING: Entry point not in acceptable range - using default 0x81080000.\r\n"); gNandBoot.entryPoint = 0x81080000; } else { DEBUG_printString("Selected entry point is "); DEBUG_printHexInt(gNandBoot.entryPoint); DEBUG_printString("\r\n"); } DEBUG_printString("Enter the U-boot or application load address (in hex): \r\n"); DEBUG_readString(answer); gNandBoot.ldAddress = strtoul(answer, NULL, 16); if ( (gNandBoot.ldAddress < DEVICE_DDR2_START_ADDR) || (gNandBoot.ldAddress >= DEVICE_DDR2_END_ADDR) ) { DEBUG_printString("\tWARNING: Load address not in acceptable range - using default 0x81080000.\r\n"); gNandBoot.ldAddress = 0x81080000; } gNandBoot.magicNum = UBL_MAGIC_BIN_IMG; gNandBoot.block = DEVICE_NAND_UBL_SEARCH_START_BLOCK; gNandBoot.page = 0; gNandBoot.numPage = numPagesAPP; if (LOCAL_readHeaderAndData(hNandInfo, &gNandBoot, appPtr) != E_PASS) { DEBUG_printString("\tERROR: Write Failed\n"); return E_FAIL; } } #else for (i = 1; i <= 5; i++) { for (j=0; j < hNandInfo->pagesPerBlock; j++) { DEBUG_printString("Block "); DEBUG_printHexInt(i); DEBUG_printString(", Page "); DEBUG_printHexInt(j); if (NANDReadPage(i,j,gNandRx) != E_PASS) { DEBUG_printString("\r\n\tRead failed\r\n"); break; } DEBUG_printString("\r\n\t1st Word = "); DEBUG_printHexInt(((Uint32 *)gNandRx)[0]); DEBUG_printString("\r\n\t2nd Word = "); DEBUG_printHexInt(((Uint32 *)gNandRx)[1]); DEBUG_printString("\r\n\t3rd Word = "); DEBUG_printHexInt(((Uint32 *)gNandRx)[2]); DEBUG_printString("\r\n\t4th Word = "); DEBUG_printHexInt(((Uint32 *)gNandRx)[3]); DEBUG_printString("\r\n"); } } #endif return E_PASS; }
static Uint32 i2cwriter() { I2C_MemInfoHandle hI2cMemInfo; FILE *fPtr; Uint8 *appPtr; Int32 appFileSize = 0; Int8 fileName[256]; Uint32 baseAddress = 0; I2C_ConfigObj i2cCfg; I2C_MemConfigObj i2cMemCfg; DEBUG_printString( "Starting I2CWriter.\r\n"); // Initialize I2C Config i2cCfg.ownAddr = 0x29; i2cCfg.prescalar = 14; i2cCfg.i2cclkl = 6; i2cCfg.i2cclkh = 6; i2cCfg.addrMode = I2C_ADDRESSING_7BIT; // Initialize I2C Memory Config i2cMemCfg.i2cMemAddr = 0x50; i2cMemCfg.addrWidth = 16; i2cMemCfg.pageSize = 64; i2cMemCfg.memorySize = 32 *1024; hI2cMemInfo = I2C_MEM_open(0,&i2cCfg,&i2cMemCfg); if (hI2cMemInfo == NULL) { DEBUG_printString( "\tERROR: I2C Initialization failed.\r\n" ); return E_FAIL; } // Set base address to start putting data at baseAddress = 0x00; // Read the UBL file from host DEBUG_printString("Enter the binary AIS application file name (enter 'none' to skip): \r\n"); DEBUG_readString(fileName); fflush(stdin); if (strcmp(fileName,"none") != 0) { // Open an File from the hard drive fPtr = fopen(fileName, "rb"); if(fPtr == NULL) { DEBUG_printString("\tERROR: File "); DEBUG_printString(fileName); DEBUG_printString(" open failed.\r\n"); return E_FAIL; } // Initialize the pointer appFileSize = 0; // Read file size fseek(fPtr,0,SEEK_END); appFileSize = ftell(fPtr); // Check to make sure image was read correctly if(appFileSize == 0) { DEBUG_printString("\tERROR: File read failed.\r\n"); fclose (fPtr); return E_FAIL; } // Check to make sure the app image will fit else if ( appFileSize > hI2cMemInfo->hI2CMemCfg->memorySize) { DEBUG_printString("\tERROR: File too big.. Closing program.\r\n"); fclose (fPtr); } // Setup pointer in RAM appPtr = (Uint8 *) UTIL_allocMem(appFileSize); fseek(fPtr,0,SEEK_SET); if (appFileSize != fread(appPtr, 1, appFileSize, fPtr)) { DEBUG_printString("\tWARNING: File Size mismatch.\r\n"); } fclose (fPtr); // Erase the I2C flash to accomodate the file size #if (0) if (I2C_MEM_eraseBytes( hI2cMemInfo, baseAddress, appFileSize ) != E_PASS) { DEBUG_printString("\tERROR: Erasing I2C failed.\r\n"); return E_FAIL; } #endif { Uint8 *verifyBuffer = UTIL_allocMem(appFileSize); // Write the application data to the flash if (I2C_MEM_writeBytes(hI2cMemInfo, baseAddress, appFileSize, appPtr) != E_PASS) { DEBUG_printString("\tERROR: Writing I2C memory failed.\r\n"); return E_FAIL; } if (I2C_MEM_verifyBytes(hI2cMemInfo, baseAddress, appFileSize, appPtr, verifyBuffer) != E_PASS) { DEBUG_printString("\tERROR: Verifying I2C memory failed.\r\n"); return E_FAIL; } } } return E_PASS; }