Example #1
0
static int BURNT_action(int argc, char *argv[])
{
	UINT i;
	UINT32 src_addr=0x100000;
	UINT32 dest_addr=FLASH_BASE;
	UINT32 src,dest;
	UINT32 fileSize=0;
	UINT32 blockSize=0;
	INT flash_type;



	if( !_net_init )
	{
		if( Net_Init(_dhcp) < 0 )
		{
			uprintf("ERROR: Network initialization failed!\n");
			return -1;
		}
		_net_init=1;
	}

	uprintf("Waiting for download ...\n");
	if( TFTP_Download((UCHAR *)src_addr,(ULONG *)&fileSize,_dhcp)==0 )
	{
		uprintf("\nFlash programming ");
		if( _net_init )DisableIRQ();
		flash_type=FindFlash();
		if( _net_init )EnableIRQ();
		if( flash_type < 0 )
		{
			uprintf("ERROR: Un-supported flash type !!\n");
			return -1;
		}
		// Write program
		if( (fileSize&0x3) )fileSize=((fileSize&(~0x3))+4);//word-aligment
		i=fileSize; 
		src=src_addr;
		dest=dest_addr;
		while(i)
		{
			blockSize=flash[flash_type].BlockSize(dest);
			if( _net_init )DisableIRQ();
			flash[flash_type].BlockErase(dest, blockSize);
			if( i < blockSize )
			{
				flash[flash_type].BlockWrite(dest, (UCHAR *)src, i);
				blockSize=i;
			}
			else
			{
				flash[flash_type].BlockWrite(dest, (UCHAR *)src, blockSize);
			}
			if( _net_init )EnableIRQ();
			src+=blockSize;
			dest+=blockSize;
			i-=blockSize;
			uprintf(".");
		}
		uprintf(" OK!\n");

	}
	else
	{
		uprintf("\nDownload error!\n");
		return -1;
	}

	// verify data
	uprintf("Write data verifing ");
	for(i=0;i<fileSize;i+=4)
	{
		if( (i&0xFFFF)== 0x0 )uprintf(".");
		if( *((volatile unsigned int *)(src_addr+i))!=*((volatile unsigned int *)(dest_addr+i)) )
		{
			uprintf("ERROR: Data failed @ 0x%08x \n", dest_addr+i);
			return -1;
		}
	}
	uprintf(" OK!\n");


	return 0;
}
Example #2
0
/*
 * .KB_C_FN_DEFINITION_START
 * void ParseCommand(char *)
 *  This private function executes matching functions.
 * .KB_C_FN_DEFINITION_END
 */
static void
ParseCommand(char *buffer)
{
	int		argc, i;

	if ((argc = BreakCommand(buffer)) < 1)
		return;

	switch (StringToCommand(argv[0])) {
	case COMMAND_COPY:
	{
		// "c <to> <from> <size in bytes>"
		// copy memory
		char		*to, *from;
		unsigned	size;

		if (argc > 3) {
			to = (char *)p_ASCIIToHex(argv[1]);
			from = (char *)p_ASCIIToHex(argv[2]);
			size = p_ASCIIToHex(argv[3]);
			memcpy(to, from, size);
		}
		break;
	}

	case COMMAND_DUMP:
		// display boot commands
		DumpBootCommands();
		break;

	case COMMAND_EXEC:
	{
		// "e <address>"
		// execute at address
		void (*execAddr)(unsigned, unsigned, unsigned);

		if (argc > 1) {
			/* in future, include machtypes (MACH_KB9200 = 612) */
			execAddr = (void (*)(unsigned, unsigned, unsigned))
			  p_ASCIIToHex(argv[1]);
			(*execAddr)(0, 612, tagAddress);
		}
		break;
	}

	case COMMAND_TFTP:
	{
		// "tftp <local_dest_addr filename>"
		//  tftp download
		unsigned address = 0;

		if (argc > 2)
			address = p_ASCIIToHex(argv[1]);
		TFTP_Download(address, argv[2]);
		break;
	}

	case COMMAND_SERVER_IP:
		// "server_ip <server IP 192 200 1 20>"
		// set download server address
		if (argc > 4)
			SetServerIPAddress(BuildIP());
		break;

	case COMMAND_HELP:
		// dump command info
		printf("Commands:\n"
		"\tc\n"
		"\td\n"
		"\te\n"
		"\tip\n"
		"\tserver_ip\n"
		"\tm\n"
		"\ttftp\n"
		"\ts\n"
#ifdef SUPPORT_TAG_LIST
		"\tt\n"
#endif
		"\tw\n"
		"\tx\n");
		break;

	case COMMAND_LOCAL_IP:
		// "local_ip <local IP 192 200 1 21>
		// set ip of this module
		if (argc > 4)
			SetLocalIPAddress(BuildIP());
		break;

	case COMMAND_MAC:
	{
		// "m <mac address 12 34 56 78 9a bc>
		// set mac address using 6 byte values
		unsigned char mac[6];

		if (argc > 6) {
			for (i = 0; i < 6; i++)
				mac[i] = p_ASCIIToHex(argv[i + 1]);
			EMAC_SetMACAddress(mac);
		}
		break;
	}

	case COMMAND_SET:
	{
		// s <index> <new boot command>
		// set the boot command at index (0-based)
		unsigned	index;

		if (argc > 1) {
			RestoreSpace(2);
			index = p_ASCIIToHex(argv[1]);
			SetBootCommand(index, argv[2]);
		}
		break;
	}

#ifdef SUPPORT_TAG_LIST
	case COMMAND_TAG:
		// t <address> <boot command line>
		// create tag-list for linux boot
		if (argc > 2) {
			RestoreSpace(2);
			tagAddress = p_ASCIIToHex(argv[1]);
			InitTagList(argv[2], (void*)tagAddress);
		}
		break;
#endif

	case COMMAND_WRITE:
		// write the command table to non-volatile
		WriteCommandTable();
		break;

	case COMMAND_XMODEM:
	{
		// "x <address>"
		// download X-modem record at address
		if (argc > 1)
			xmodem_rx((char *)p_ASCIIToHex(argv[1]));
		break;
	}

	default:
		break;
	}

	printf("\n");
}
Example #3
0
/*
 * .KB_C_FN_DEFINITION_START
 * void ParseCommand(char *)
 *  This private function executes matching functions.
 * .KB_C_FN_DEFINITION_END
 */
static void
ParseCommand(char *buffer)
{
	int		argc, i;

	if ((argc = BreakCommand(buffer)) < 1)
		return;

	switch (StringToCommand(argv[0])) {
	case COMMAND_DUMP:
		// display boot commands
		DumpBootCommands();
		break;

	case COMMAND_EXEC:
	{
		// "e <address>"
		// execute at address
		void (*execAddr)(unsigned, unsigned);

		if (argc > 1) {
			/* in future, include machtypes (MACH_KB9200 = 612) */
			execAddr = (void (*)(unsigned, unsigned))
			    p_ASCIIToHex(argv[1]);
			(*execAddr)(0, 612);
		}
		break;
	}

	case COMMAND_TFTP:
	{
		// "tftp <local_dest_addr filename>"
		//  tftp download
		unsigned address = 0;

		if (argc > 2)
			address = p_ASCIIToHex(argv[1]);
		TFTP_Download(address, argv[2]);
		break;
	}

	case COMMAND_SERVER_IP:
		// "server_ip <server IP 192 200 1 20>"
		// set download server address
		if (argc > 4)
			SetServerIPAddress(BuildIP());
		break;

	case COMMAND_LOCAL_IP:
		// "local_ip <local IP 192 200 1 21>
		// set ip of this module
		if (argc > 4)
			SetLocalIPAddress(BuildIP());
		break;

	case COMMAND_MAC:
	{
		// "m <mac address 12 34 56 78 9a bc>
		// set mac address using 6 byte values
		unsigned char mac[6];

		if (argc > 6) {
			for (i = 0; i < 6; i++)
				mac[i] = p_ASCIIToHex(argv[i + 1]);
			EMAC_SetMACAddress(mac);
		}
		break;
	}

	case COMMAND_LOAD_SPI_KERNEL:
		// "k <address>"
		if (argc > 1)
			LoadKernelFromSpi((char *)p_ASCIIToHex(argv[1]));
		break;

	case COMMAND_XMODEM:
		// "x <address>"
		// download X-modem record at address
		if (argc > 1)
			xmodem_rx((char *)p_ASCIIToHex(argv[1]));
		break;

	case COMMAND_RESET:
		printf("Reset\n");
		reset();
		while (1) continue;
		break;

	case COMMAND_REPLACE_KERNEL_VIA_XMODEM:
		printf("Updating KERNEL image\n");
		UpdateFlash(KERNEL_OFFSET);
		break;
	case COMMAND_REPLACE_FLASH_VIA_XMODEM: 
		printf("Updating FLASH image\n");
		UpdateFlash(FLASH_OFFSET);
		break;

	case COMMAND_REPLACE_ID_EEPROM: 
	{
	    char buf[25];
		printf("Testing Config EEPROM\n");
		EEWrite(0, "This is a test", 15);
		EERead(0, buf, 15);
		printf("Found '%s'\n", buf);
		break;
	}
	default:
		break;
	}

	printf("\n");
}