I.MX6 MAC Address hacking

/**************************************************************************
 *                       I.MX6 MAC Address hacking
 * 说明:
 *     本文记录I.MX6驱动是如何获取MAC地址的。
 *
 *                                  2016-6-24 深圳 南山平山村 曾剑锋
 **************************************************************************/



/*
 * initialize __mach_desc_MX6Q_SABRESD data structure.
 */
MACHINE_START(MX6Q_SABRESD, "Freescale i.MX 6Quad/DualLite/Solo Sabre-SD Board")
    /* Maintainer: Freescale Semiconductor, Inc. */
    .boot_params = MX6_PHYS_OFFSET + 0x100,
    .fixup = fixup_mxc_board,
    .map_io = mx6_map_io,
    .init_irq = mx6_init_irq,
    .init_machine = mx6_sabresd_board_init,        --------------+
    .timer = &mx6_sabresd_timer,                                 |
    .reserve = mx6q_sabresd_reserve,                             |
MACHINE_END                                                      |
                                                                 |
                                                                 |
static void __init mx6_sabresd_board_init(void)    <-------------+
{
    ......
    imx6_init_fec(fec_data);                       --------------------+
    ......                                                             |
}                                                                      |
                                                                       |
void __init imx6_init_fec(struct fec_platform_data fec_data)      <----+
{
    fec_get_mac_addr(fec_data.mac);                      ----------+
    if (!is_valid_ether_addr(fec_data.mac))                        |
        random_ether_addr(fec_data.mac);                           |
                                                                   |
    if (cpu_is_mx6sl())                                            |
        imx6sl_add_fec(&fec_data);                                 |
    else                                                           |
        imx6q_add_fec(&fec_data);                                  |
}                                                                  |
                                                                   |
static int fec_get_mac_addr(unsigned char *mac)         <----------+
{
    unsigned int value;

    value = readl(MX6_IO_ADDRESS(OCOTP_BASE_ADDR) + HW_OCOTP_MACn(0));
    mac[5] = value & 0xff;
    mac[4] = (value >> 8) & 0xff;
    mac[3] = (value >> 16) & 0xff;
    mac[2] = (value >> 24) & 0xff;
    value = readl(MX6_IO_ADDRESS(OCOTP_BASE_ADDR) + HW_OCOTP_MACn(1));
    mac[1] = value & 0xff;
    mac[0] = (value >> 8) & 0xff;

    return 0;
}

 

posted on 2016-06-24 20:05  zengjf  阅读(621)  评论(0编辑  收藏  举报

导航