u-boot 添加设置网卡地址的命令

在common 目录下 Cmd_net.c 中加入 
#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]);


}
linux里对应的mac分区 传入 mac地址 

echo -n -e "\xE4\xAD\x7F\x61\x0B\xD6" >/dev/mtd3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

solomon_大卫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值