1. 程式人生 > >u-boot 新增設定網絡卡地址的命令

u-boot 新增設定網絡卡地址的命令

#if defined(CONFIG_CMD_PING)
static int do_ping(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
if (argc < 2)
return -1;

NetPingIP = string_to_ip(argv[1]);
if (NetPingIP == 0)
return CMD_RET_USAGE;

if (NetLoop(PING) < 0) {
printf("ping failed; host %s is not alive\n", argv[1]);
return 1;
}

printf("host %s is alive\n", argv[1]);

return 0;
}
int do_setmac(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
int i;
        ulong reg;
char buf[6];
char *s, *e;
struct spi_flash *flash;
struct image_header *header;
struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;

s=argv[1];
 for (reg = 0; reg < 6; ++reg) {
            buf[reg] = s ? simple_strtoul (s, &e, 16) : 0;
            if (s)
                s = (*e) ? e + 1 : e;
        }

//static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3);

if (!flash) {
puts("SPI probe failed.\n");
hang();
}
spi_flash_erase(flash, 0x94000,
       0x1000);
spi_flash_write(flash, 0x94000,
        0x1000, buf);

/* use CONFIG_SYS_TEXT_BASE as temporary storage area */

printf("mac0 %02x:%02x:%02x:%02x:%02x:%02x",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);

spi_flash_read(flash, 0x94000,
        6, buf);
printf("mac1 %02x:%02x:%02x:%02x:%02x:%02x",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);

writeb(0x10,0x1000010);
writeb(buf[0],0x1000030);
writeb(0x11,0x1000010);
writeb(buf[1],0x1000030);
writeb(0x12,0x1000010);
writeb(buf[2],0x1000030);
writeb(0x13,0x1000010);
writeb(buf[3],0x1000030);
writeb(0x14,0x1000010);
writeb(buf[4],0x1000030);
writeb(0x15,0x1000010);
writeb(buf[5],0x1000030);

writeb(0x10,0x1000008);
writeb(buf[0],0x1000028);
writeb(0x11,0x1000008);
writeb(buf[1],0x1000028);
writeb(0x12,0x1000008);
writeb(buf[2],0x1000028);
writeb(0x13,0x1000008);
writeb(buf[3],0x1000028);
writeb(0x14,0x1000008);
writeb(buf[4],0x1000028);
writeb(0x15,0x1000008);
writeb(buf[5]+1,0x1000028);
printf("set mac %s \n", argv[1]);
return 0;
}
U_BOOT_CMD(
ping, 2, 1, do_ping,
"send ICMP ECHO_REQUEST to network host",
"pingAddress"
);



U_BOOT_CMD(
setmac, 2, 1, do_setmac,
"send macaddress to dm9000 mac",
"pingAddress"
);

void load_mac_addr_from_df(void)
{
struct spi_flash *flash;
struct image_header *header;
char buf[6];
char buf1[6];
struct gpmc *gpmc_cfg = (struct gpmc *)GPMC_BASE;
//static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
flash = spi_flash_probe(CONFIG_SPL_SPI_BUS, CONFIG_SPL_SPI_CS,
CONFIG_SF_DEFAULT_SPEED, SPI_MODE_3);
if (!flash) {
puts("SPI probe failed.\n");
hang();
}

/* buf1[0]=0x12;
buf1[1]=0x34;
buf1[2]=0x56;
buf1[3]=0x78;
buf1[4]=0x90;
buf1[5]=0xab;
spi_flash_write(flash, 0x94000,
       6, buf1);*/

/* use CONFIG_SYS_TEXT_BASE as temporary storage area */
spi_flash_read(flash, 0x94000,
       6, buf);


writeb(0x10,0x1000010);
writeb(buf[0],0x1000030);
writeb(0x11,0x1000010);
writeb(buf[1],0x1000030);
writeb(0x12,0x1000010);
writeb(buf[2],0x1000030);
writeb(0x13,0x1000010);
writeb(buf[3],0x1000030);
writeb(0x14,0x1000010);
writeb(buf[4],0x1000030);
writeb(0x15,0x1000010);
writeb(buf[5],0x1000030);

writeb(0x10,0x1000008);
writeb(buf[0],0x1000028);
writeb(0x11,0x1000008);
writeb(buf[1],0x1000028);
writeb(0x12,0x1000008);
writeb(buf[2],0x1000028);
writeb(0x13,0x1000008);
writeb(buf[3],0x1000028);
writeb(0x14,0x1000008);
writeb(buf[4],0x1000028);
writeb(0x15,0x1000008);
writeb(buf[5]+1,0x1000028);

//writel(0x12345678,0x1000014);
//writel(0x11114444, &cdev->macid1h);
//writel(0x11115555, &cdev->macid1l);
printf("mac0 %02x:%02x:%02x:%02x:%02x:%02x",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5]);


}