int check_trx(int mode)
{
	ulong addr;
	ulong data, len, checksum;
    int verify;
    char *s;
	image_header_t *hdr = &header;
	
	s = getenv("verify");
	verify = (s && (*s == 'n')) ? 0 : 1;
	
	if (mode == 0)
		addr = CFG_FLASH_BASE + 0x50000;
	else
		addr = load_addr;
	
//	printf("## Booting image at %08lx ...\n", addr);
	printf("## Checking image at %08lx ...\n", addr);
	
	/* Copy header so we can blank CRC field for re-calculation */
#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr))
	{
		read_dataflash(addr, sizeof(image_header_t), (char *)&header);
	} 
#endif
#if defined (CFG_ENV_IS_IN_NAND)
	if (addr >= CFG_FLASH_BASE)
		ranand_read(&header, (char *)(addr - CFG_FLASH_BASE), sizeof(image_header_t));
	else
		memmove (&header, (char *)addr, sizeof(image_header_t));
#elif defined (CFG_ENV_IS_IN_SPI)
	if (addr >= CFG_FLASH_BASE)
		raspi_read(&header, (char *)(addr - CFG_FLASH_BASE), sizeof(image_header_t));
	else
		memmove (&header, (char *)addr, sizeof(image_header_t));
#else //CFG_ENV_IS_IN_FLASH
	memmove (&header, (char *)addr, sizeof(image_header_t));
#endif //CFG_ENV_IS_IN_FLASH
	
	if (ntohl(hdr->ih_magic) != IH_MAGIC)
	{
		printf("Bad Magic Number,%08X \n", ntohl(hdr->ih_magic));
		return 1;
	}
//	else
//		printf("Magic Number: %08X, OK\n", ntohl(hdr->ih_magic));
	
	data = (ulong)&header;
	len  = sizeof(image_header_t);
	
	checksum = ntohl(hdr->ih_hcrc);
	hdr->ih_hcrc = 0;
	
	if (crc32(0, (char *)data, len) != checksum)
	{
		puts("Bad Header Checksum\n");
		return 1; 
	}
//	else
//		puts("Header Checksum OK\n");
	
	/* for multi-file images we need the data part, too */
	print_image_hdr((image_header_t *)hdr);
	
	data = addr + sizeof(image_header_t);
	len  = ntohl(hdr->ih_size);
	
#ifdef CONFIG_HAS_DATAFLASH
	if (addr_dataflash(addr))
	{
		read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
		data = CFG_LOAD_ADDR;
	}
#endif
	
#if defined (CFG_ENV_IS_IN_NAND)
	if (addr >= CFG_FLASH_BASE) {
		ulong load_addr = CFG_SPINAND_LOAD_ADDR;
		ranand_read(load_addr, data - CFG_FLASH_BASE, len);
		data = load_addr;
	}
#elif defined (CFG_ENV_IS_IN_SPI)
	if (addr >= CFG_FLASH_BASE) {
		ulong load_addr = CFG_SPINAND_LOAD_ADDR;
		raspi_read(load_addr, data - CFG_FLASH_BASE, len);
		data = load_addr;
	}
#else //CFG_ENV_IS_IN_FLASH
#endif

	if (verify) 
	{
		puts("   Verifying Checksum ... ");
		if (crc32(0, (char *)data, len) != ntohl(hdr->ih_dcrc)) 
		{
			printf("Bad Data CRC\n");
			return 1;
		}
//		puts("Data CRC OK\n");
	}
	return 0;			
}
Beispiel #2
0
int eth_initialize(bd_t *bis)
{
	unsigned char rt2880_gmac1_mac[6];
	int eth_number = 0, regValue=0;

	eth_devices = NULL;
	eth_current = NULL;

#ifdef CONFIG_DB64360
	mv6436x_eth_initialize(bis);
#endif
#ifdef CONFIG_CPCI750
	mv6436x_eth_initialize(bis);
#endif
#ifdef CONFIG_DB64460
	mv6446x_eth_initialize(bis);
#endif
#if defined(CONFIG_405GP) || defined(CONFIG_405EP) || \
  ( defined(CONFIG_440) && !defined(CONFIG_NET_MULTI) )
	ppc_4xx_eth_initialize(bis);
#endif
#if defined(CONFIG_440) && defined(CONFIG_NET_MULTI)
	ppc_440x_eth_initialize(bis);
#endif
#ifdef CONFIG_INCA_IP_SWITCH
	inca_switch_initialize(bis);
#endif
#ifdef CONFIG_PLB2800_ETHER

	plb2800_eth_initialize(bis);
#endif
#ifdef SCC_ENET
	scc_initialize(bis);
#endif
#if defined(FEC_ENET) || defined(CONFIG_ETHER_ON_FCC)
	fec_initialize(bis);
#endif
#if defined(CONFIG_MPC5xxx_FEC)
	mpc5xxx_fec_initialize(bis);
#endif
#if defined(CONFIG_MPC8220)
	mpc8220_fec_initialize(bis);
#endif
#if defined(CONFIG_SK98)
	skge_initialize(bis);
#endif
#if defined(CONFIG_MPC85XX_TSEC1)
	tsec_initialize(bis, 0);
#endif
#if defined(CONFIG_MPC85XX_TSEC2)
	tsec_initialize(bis, 1);
#endif
#if defined(CONFIG_MPC85XX_FEC)
	tsec_initialize(bis, 2);
#endif
#if defined(CONFIG_AU1X00)
	au1x00_enet_initialize(bis);
#endif
#ifdef CONFIG_E1000
	e1000_initialize(bis);
#endif
#ifdef CONFIG_EEPRO100
	eepro100_initialize(bis);
#endif
#ifdef CONFIG_TULIP
	dc21x4x_initialize(bis);
#endif
#ifdef CONFIG_3COM
	eth_3com_initialize(bis);
#endif
#ifdef CONFIG_PCNET
	pcnet_initialize(bis);
#endif
#ifdef CFG_GT_6426x
	gt6426x_eth_initialize(bis);
#endif
#ifdef CONFIG_NATSEMI
	natsemi_initialize(bis);
#endif
#ifdef CONFIG_NS8382X
	ns8382x_initialize(bis);
#endif
#if defined(CONFIG_RTL8139)
	rtl8139_initialize(bis);
#endif
#if defined(CONFIG_RTL8169)
	rtl8169_initialize(bis);
#endif

#if defined(CONFIG_RT2880_ETH)
	rt2880_eth_initialize(bis);
#endif

	if (!eth_devices) {
		puts ("No ethernet found.\n");
	} else {
		struct eth_device *dev = eth_devices;
		char *ethprime = getenv ("ethprime");
		unsigned char empty_mac[6]={0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};


		do {
			if (eth_number)
				puts (", ");

			if (ethprime && strcmp (dev->name, ethprime) == 0) {
				eth_current = dev;
				puts (" [PRIME]");
			}

#if defined (MT7621_MP)
#define GMAC0_OFFSET	0xE000
#else
#define GMAC0_OFFSET	0x28
#endif

			//get Ethernet mac address from flash
#if defined (CFG_ENV_IS_IN_NAND)
			ranand_read(rt2880_gmac1_mac, 
				CFG_FACTORY_ADDR - CFG_FLASH_BASE + GMAC0_OFFSET, 6);
#elif defined (CFG_ENV_IS_IN_SPI)
			raspi_read(rt2880_gmac1_mac, 
				CFG_FACTORY_ADDR - CFG_FLASH_BASE + GMAC0_OFFSET, 6);
#else //CFG_ENV_IS_IN_FLASH
			memmove(rt2880_gmac1_mac, CFG_FACTORY_ADDR + GMAC0_OFFSET, 6);
#endif

			//if flash is empty, use default mac address
			if (memcmp(rt2880_gmac1_mac, empty_mac, 6) == 0)
				eth_parse_enetaddr(CONFIG_ETHADDR, rt2880_gmac1_mac);

			if (memcmp (rt2880_gmac1_mac, "\0\0\0\0\0\0", 6) == 0)
				eth_parse_enetaddr(CONFIG_ETHADDR, rt2880_gmac1_mac);

			memcpy(dev->enetaddr, rt2880_gmac1_mac, 6);

			eth_number++;
			dev = dev->next;
		} while(dev != eth_devices);

#ifdef CONFIG_NET_MULTI
		/* update current ethernet name */
		if (eth_current) {
			char *act = getenv("ethact");
			if (act == NULL || strcmp(act, eth_current->name) != 0)
				setenv("ethact", eth_current->name);
		} else
			setenv("ethact", NULL);
#endif
		//printf("\n eth_current->name = %s\n",eth_current->name);
		printf("\n");
	}

	return eth_number;
}