📄 ethdown.c
字号:
}
EdbgOutputDebugString("\r\nImage start: 0x%X length: 0x%X cache location: 0x%X\r\n", dwPhysStart, dwPhysLen, dwPhysStart + offset );
// Go ahead and apply the offset to the image start address.
dwPhysStart += offset;
bNumBytesInDataTail = 0;
BINFileParseState = BIN_PHYSADDR;
pdwRecStart=pdwRecNext=(LPDWORD)(dwPhysStart+dwPhysLen-dwOffset);
#else
if (offset == 0x40000) // downloading eboot.bin
{
EdbgOutputDebugString("\r\nDownloading bootloader image.\r\n");
// Write this image in place of the bootloader.
// Therefore, there is no offset.
dwEBOOT_OFFSET = 0x00000000;
fileType |= (BOOTLOADER | FLASHTARGET);
}
else if (offset > 0x10000000) // downloading nk.bin (IMGFLASH=1)
{
EdbgOutputDebugString("\r\nDownloading operating system image for flash target.\r\n");
// Write this image above the boot loader and configuration block.
dwEBOOT_OFFSET = 0x00080000;
fileType |= (NKBIN | FLASHTARGET);
}
else // downloading nk.bin (IMGFLASH=<not set>)
{
EdbgOutputDebugString("\r\nDownloading operating system image for SDRAM target.\r\n");
fileType |= (NKBIN | SDRAMEXE);
// This image may still be placed into flash - it depends on
// pEbootCFG->bWriteBINToFlash. If writing to flash, we'll need
// to configure this offset.
dwEBOOT_OFFSET = 0x00080000;
}
EdbgOutputDebugString("\r\nImage start: 0x%X length: 0x%X cache location: 0x%X\r\n", dwPhysStart, dwPhysLen, dwPhysStart + offset );
// Go ahead and apply the offset to the image start address.
dwPhysStart += offset;
bNumBytesInDataTail = 0;
BINFileParseState = BIN_PHYSADDR;
pdwRecStart=pdwRecNext=(LPDWORD)(dwPhysStart+dwPhysLen-dwOffset);
#endif //ifndef MMXIP_MEMMAP
}
// Check to see if this is the last packet and it's empty
else if (*cwLength == 0)
return 0;
v_PacketNum++;
// Pull the rest of the 32-bit data word that was started in the last packet
if (bNumBytesInDataTail)
{
dwCurDataWord = 0;
for ( i = 0; i < 4UL-bNumBytesInDataTail; i++ )
dwCurDataWord |= pbData[i] << ((i+bNumBytesInDataTail) * 8);
dwCurDataWord |= dwDataTailFromLastPacket;
// DWORD align the buffer
*cwLength -= 4 - bNumBytesInDataTail;
pdwBuffer = (DWORD UNALIGNED *) (pbData + (4-bNumBytesInDataTail)); //memmove( pbData, pbData + (4-bNumBytesInDataTail), *cwLength );
iBufferPos = -4;
}
else
dwCurDataWord = *pdwBuffer++;
percentComplete = (((v_PacketNum+1) * 512 * 100) / dwPhysLen);
// Update the display only when the percent complete changes
if (percentComplete != prev_percentComplete)
{
// Display percentage in decimal on the hex display
x = percentComplete / 100;
y = (percentComplete % 100) / 10;
z = ((percentComplete % 100) % 10);
BLR->hex_led = ((x << 8) | (y << 4) | (z));
prev_percentComplete = percentComplete;
}
// I'll keep looping until I get almost to the end of the packet buffer
while ( iBufferPos + 4 <= *cwLength )
{
switch ( BINFileParseState )
{
case BIN_PHYSADDR:
dwRecordAddr= dwCurDataWord;
if (dwRecordAddr != 0)
dwRecordAddr += offset;
if (offset && dwRecordAddr)
EdbgOutputDebugString("\r\nAddress fixup was 0x%X now 0x%X\r\n", dwCurDataWord, dwRecordAddr );
#ifdef ARM
dwCurDataWord-= dwOffset;
#endif
pdwDest = (DWORD UNALIGNED *)dwRecordAddr;
pbCRC = (BYTE *)dwRecordAddr;
BINFileParseState = BIN_PHYSLEN;
break;
case BIN_PHYSLEN:
dwRecordLen = dwCurDataWord;
BINFileParseState = BIN_CHECKSUM;
break;
case BIN_CHECKSUM:
if (pdwDest == 0 && dwCurDataWord == 0)
{
dwLaunchAddr = dwRecordLen;
// Display 100% on the display
BLR->hex_led = 0x100;
}
dwPerfectCRC = dwCurDataWord;
dwRecordPos = 0;
BINFileParseState = BIN_DATA;
*pdwRecNext++=dwRecordAddr;
*pdwRecNext++=dwRecordLen;
*pdwRecNext++=dwPerfectCRC;
break;
case BIN_DATA:
// If we aren't at the end of the record yet read another DWORD. Note that the number of
// bytes in a record is guaranteed to always be DWORD aligned, so we can assume that there
// won't be a partial DWORD at the end of a record.
*pdwDest++ = dwCurDataWord;
dwRecordPos += 4;
if (dwRecordPos < dwRecordLen)
BINFileParseState = BIN_DATA;
// If we have reached the end of the record
else
{
BINFileParseState = BIN_PHYSADDR;
}
break;
} // switch(BINFileParseState)
dwCurDataWord = *pdwBuffer++;
iBufferPos += 4;
} // while not at end of buffer
// Store the fragmented DWORD until we get the next packet
bNumBytesInDataTail = (BYTE)(*cwLength - iBufferPos);
dwDataTailFromLastPacket = dwCurDataWord;
// Mask off the garbage that was picked up from the end of the packet buffer
switch ( bNumBytesInDataTail )
{
case 1:
dwDataTailFromLastPacket &= 0x000000FFUL;
break;
case 2:
dwDataTailFromLastPacket &= 0x0000FFFFUL;
break;
case 3:
dwDataTailFromLastPacket &= 0x00FFFFFFUL;
break;
}
break;
case TFTPD_DESTROY:
EdbgOutputDebugString( "EthDown::TFTPD_DESTROY::%s with %u bytes\r\n", pszFileName, *cwLength );
for ( i = 0; i < *cwLength; i++ )
{
if (i > 0 && i % 8 == 0)
EdbgOutputDebugString( " " );
if (i > 0 && i % 16 == 0)
EdbgOutputDebugString( "\r\n" );
EdbgOutputDebugString( "%B ", pbData[i] );
}
break;
default:
EdbgOutputDebugString( "EthDown::Illegal Operation Code %u\r\n", Operation );
return 1;
break;
} // switch
return 0;
}
UINT16 FlashErase(DWORD dwPhysStart, DWORD dwPhysLen)
{
int FLASH_SIZE = 16777216 * 2;
int ERASE_BLOCKS = 128;
int BLOCK_SIZE = FLASH_SIZE / ERASE_BLOCKS;
int L3_BLOCK_SIZE = 65536; //64Kb per block on L3 (blocks 0 - 3)
DWORD i,j;
DWORD num_blocks;
DWORD num_blocks_to_erase;
DWORD num_l3_blocks_to_erase = 0;
DWORD num_l3_blocks_erased;
DWORD flash_start_address = (FLASH_START | CACHED_TO_UNCACHED_OFFSET);
volatile DWORD *pdwFlash;
int status;
// Determine the number of blocks to erase.
num_blocks = (dwPhysLen / (BLOCK_SIZE));
if (dwPhysLen % (BLOCK_SIZE))
num_blocks++;
if (num_blocks < 1)
{
num_blocks = 1;
EdbgOutputDebugString("Calculation error. Erase blocks = %d\n\r", num_blocks);
}
else if (num_blocks > 128)
{
num_blocks = 128;
EdbgOutputDebugString("Calculation error. Erase blocks = %d\n\r", num_blocks);
}
// If Tyax flash, need to change block count based on if we're in the first 4 blocks
// as the first 4 blocks are 16KWords (vs. 64KWords/block)
if ((flashType == L18) || (flashType == L30))
{
// Is start address within the first 4 blocks. As there are 2 devices in parallel,
// are we within the first 128KWords (2 x 64KWords)? If so, we need to account for
// increased number of blocks - which is the first 256K of addy range
if ((dwPhysStart >= flash_start_address) && (dwPhysStart < (flash_start_address + 0x40000)))
{
// If we're within the first 128K words (256K), we need to treat the block as a special case
num_l3_blocks_to_erase = 4;
num_blocks--; // Decrease the num_blocks count, as it assumes the first block is 64K
// Now add the # of L3 blocks to the # blocks calc.'ed at the beginning to get total
// # of blocks to erase on a given L3 device INCLUDING the first 4 16kWord blocks
num_blocks = num_blocks + num_l3_blocks_to_erase;
}
}
pdwFlash = (volatile DWORD *)(dwPhysStart | CACHED_TO_UNCACHED_OFFSET);
// Issue the clear lock bits and confirm command.
if (flashType == J3)
{
// For J3 FLASH, unlock all blocks at once with one command
num_blocks_to_erase = 1;
}
else if ((flashType == K3) || (flashType == K18)|| (flashType == L18) || (flashType == L30))
{
// For K3/K18 FLASH, unlock individual blocks one at a time
num_blocks_to_erase = num_blocks;
}
// For L3, need to set for use within the FOR loop
num_l3_blocks_erased = num_l3_blocks_to_erase;
for (j = 0; j < num_blocks_to_erase; j++)
{
*pdwFlash = 0x00600060;
*pdwFlash = 0x00d000d0;
i = 0;
while ((i & 0x00800080) != 0x00800080)
{
i = *pdwFlash;
}
if ((i & 0x00000008) == 0x00000008)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -