firefly rk3288 解决刷入Linux固件后mac地址一样的问题

原理:使用cpuid生成mac地址

1、修改u-boot/net/eth_common.c里的eth_env_set_enetaddr函数为:

int eth_env_set_enetaddr(const char *name, const uchar *enetaddr)
{
        char buf[ARP_HLEN_ASCII + 1];
        sprintf(buf, "%pM", enetaddr);
		return env_set(name, buf);
}

2、修改u-boot/board/firefly/firefly-rk3288/firefly-rk3288.c里的setup_macaddr函数为:

void setup_macaddr(void)
{
#if CONFIG_IS_ENABLED(CMD_NET)
        int ret;
        const char *cpuid = env_get("cpuid#");
        u8 hash[SHA256_SUM_LEN];
        int size = sizeof(hash);
        u8 mac_addr[6];
        u8 mac1_addr[6];

        /* Only generate a MAC address, if none is set in the environment */
        //if (env_get("ethaddr"))
        //      return;

        if (!cpuid) {
                debug("%s: could not retrieve 'cpuid#'\n", __func__);
                return;
        }

        ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
        if (ret) {
                debug("%s: failed to calculate SHA256\n", __func__);
                return;
        }

        /* Copy 6 bytes of the hash to base the MAC address on */
        memcpy(mac_addr, hash, 6);

        /* Make this a valid MAC address and set it */
        mac_addr[0] &= 0xfe;  /* clear multicast bit */
        mac_addr[0] |= 0x02;  /* set local assignment bit (IEEE802) */
        eth_env_set_enetaddr("ethaddr", mac_addr);
        memcpy(mac1_addr, hash, 6);
        mac1_addr[5]++;
        eth_env_set_enetaddr("eth1addr", mac1_addr);
#endif

        return;
}

4、在u-boot/include/common.h里添加如下函数定义(我加在45行):

void setup_macaddr(void);

5、在u-boot/common/autoboot.c的autoboot_command函数入口,调用setup_macaddr函数:

void autoboot_command(const char *s)
{
        debug("### main_loop: bootcmd=\"%s\"\n", s ? s : "<UNDEFINED>");
        setup_macaddr();
        if (stored_bootdelay != -1 && s && !abortboot(stored_bootdelay)) {
#if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC)
                int prev = disable_ctrlc(1);    /* disable Control C checking */
#endif

                run_command_list(s, -1, 0);
                autoboot_command_fail_handle();

#if defined(CONFIG_AUTOBOOT_KEYED) && !defined(CONFIG_AUTOBOOT_KEYED_CTRLC)
                disable_ctrlc(prev);    /* restore Control C checking */
#endif
        }

#ifdef CONFIG_MENUKEY
        if (menukey == CONFIG_MENUKEY) {
                s = env_get("menucmd");
                if (s)
                        run_command_list(s, -1, 0);
        }
#endif /* CONFIG_MENUKEY */
}

结束。

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-22 07:20:02       52 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-22 07:20:02       54 阅读
  3. 在Django里面运行非项目文件

    2024-07-22 07:20:02       45 阅读
  4. Python语言-面向对象

    2024-07-22 07:20:02       55 阅读

热门阅读

  1. Symfony数据库抽象层:深入理解其工作原理

    2024-07-22 07:20:02       16 阅读
  2. 设计模式--职责链模式

    2024-07-22 07:20:02       17 阅读
  3. PXIe-6592

    PXIe-6592

    2024-07-22 07:20:02      13 阅读
  4. FPGA 中的 IOE与IO BANK

    2024-07-22 07:20:02       18 阅读
  5. 前端部署后提示用户刷新页面

    2024-07-22 07:20:02       16 阅读
  6. 编写测试用例:策略、技巧与最佳实践

    2024-07-22 07:20:02       17 阅读
  7. 自动化测试的艺术:Xcode中GUI测试的全面指南

    2024-07-22 07:20:02       17 阅读
  8. C++基础语法:STL之容器(6)--序列容器中的forward_list

    2024-07-22 07:20:02       15 阅读
  9. MongoDB Map-Reduce 简介

    2024-07-22 07:20:02       15 阅读
  10. 【SpringBoot】第3章 SpringBoot的系统配置

    2024-07-22 07:20:02       15 阅读
  11. Python中with 关键字、tell() 和 seek() 方法

    2024-07-22 07:20:02       17 阅读
  12. 初识数据结构中的“栈”

    2024-07-22 07:20:02       16 阅读
  13. 44、PHP 实现数据流中的中位数(含源码)

    2024-07-22 07:20:02       16 阅读