Quantcast
Viewing all articles
Browse latest Browse all 149826

Forum Post: Help with NAND Bootloader

Hello,

We are having trouble running a custom NAND bootloader for AM335X EVM based on the TI's project in "C:\ti\AM335X_StarterWare_02_00_00_07\build\armv7a\cgt_ccs\am335x\evmAM335x\bootloader".


We used the FlashWriter project to flash both the bootloader and our application: FlashWriter writes the bootloader starting at block-index 0 and writes our application starting at block-index 4. Once we power the kit the bootloader hangs while copying the application to RAM thus failing to run our application. I've added debug messages over UART and figured out the line it hangs on which is (also check code below):

memcpy((void *)destAddr, (void *)&rxData[memBufferPtr], bytesToCopy);|

The strage thing is that if we run/debug the bootloader project from within CCS, it properly loads are application and everything works fine. Please take a look at the below source code and let me know if you can help

unsigned int BlPlatformNANDImageCopy(NandInfo_t *nandInfo) {      ti_header header;      /* Spi read function to read the header */     BlNANDReadFlash(nandInfo, IMAGE_OFFSET, sizeof(header), (unsigned char *)&header);      /* Copies application from SPI flash to DDR RAM */     BlNANDReadFlash( nandInfo, IMAGE_OFFSET + sizeof(header),                      header.image_size, (unsigned char *)(header.load_addr) );      entryPoint = (unsigned int)header.load_addr;      return (TRUE); }  void BlNANDReadFlash (NandInfo_t *hNandInfo, unsigned int flashAddr, unsigned int size, unsigned char *destAddr) {     static unsigned int currBlock = 0xFFFFFFFF;     static unsigned int currPage = 0xFFFFFFFF;      unsigned int pageSize   = hNandInfo->pageSize;     unsigned int blockSize  = hNandInfo->blkSize;     unsigned int memBufferPtr = 0;     unsigned int bytesLeftInBuff = 0;     unsigned int bytesToCopy = 0;          NandStatus_t retVal;      /* Convert the flashAddr to block, page numbers */     unsigned int blkNum = (flashAddr / blockSize);     unsigned int pageNum = (flashAddr - (blkNum * blockSize)) / pageSize;               /* Check to see if we need to buffer a new page */     if ((blkNum != currBlock) || (pageNum != currPage))     {         if(NANDBadBlockCheck(hNandInfo, blkNum) == NAND_BLOCK_GOOD)         {             currBlock = blkNum;             currPage = pageNum;                     retVal = NANDPageRead( hNandInfo, currBlock, currPage,                                    rxData, &eccData[0]);             if(retVal != NAND_STATUS_PASSED)             {                 UARTPuts("\r\n Reading Image From NAND ...NAND Read Failed.", -1);                 BootAbort();             }         }         else         {             UARTPuts("\r\n NAND Bad Block Check Failed.", -1);             BootAbort();         }     }          /* Figure out offset in buffered page */     memBufferPtr = flashAddr - (currBlock * blockSize) - (currPage * pageSize);            // Now we do the actual reading of bytes       // If there are bytes in the memory buffer, use them first     bytesLeftInBuff = NAND_DATA_BUFF_SIZE - memBufferPtr;     if (bytesLeftInBuff > 0)     {         bytesToCopy = (bytesLeftInBuff >= size) ? size : bytesLeftInBuff;              // Copy bytesToCopy bytes from current buffer pointer to the dest

//------------------HANGS AT BELOW LINE----------------------// memcpy((void *)destAddr, (void *)&rxData[memBufferPtr], bytesToCopy);

destAddr += bytesToCopy; size -= bytesToCopy; flashAddr += bytesToCopy; bytesLeftInBuff -= bytesToCopy; } // If we have one or more full blocks to copy, copy them directly // Any leftover data (partial page) gets copied via the memory buffer while (size > 0) { unsigned char *tempPtr = NULL; currPage += 1; // Check to see if curr page is at end of a block if (currPage >= hNandInfo->pagesPerBlk) { // If so, increment current block until we are in a good block do { currBlock += 1; } while (NANDBadBlockCheck(hNandInfo,currBlock)!= NAND_BLOCK_GOOD); currPage = 0; } // Read the new current page in the current block to its destination tempPtr = (unsigned char *)(size >= pageSize) ? destAddr : ((unsigned char *)rxData); bytesToCopy = (size >= pageSize) ? pageSize : size; retVal = NANDPageRead( hNandInfo, currBlock, currPage, tempPtr, &eccData[0]); if(retVal != NAND_STATUS_PASSED) { UARTPuts("\r\n Reading Image From NAND ...NAND Read Failed.", -1); BootAbort(); } if (tempPtr != destAddr) { // If the last copy was a partial page, copy byteCnt // bytes from memory buffer pointer to the dest memcpy((void *)destAddr, (void *)rxData, bytesToCopy); } size -= bytesToCopy; destAddr += bytesToCopy; flashAddr += bytesToCopy; } }

Can someone help me figure out what I am doing wrong? Thanks in advance.


Viewing all articles
Browse latest Browse all 149826

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>