From 4f521a0c958539830380a4aefa256865e16085ce Mon Sep 17 00:00:00 2001 From: ZYH Date: Sun, 12 May 2019 21:53:47 +0800 Subject: [PATCH] [BSP][qemu-a9] auto generate mac address from host --- bsp/qemu-vexpress-a9/.gitignore | 1 + bsp/qemu-vexpress-a9/drivers/automac.h | 15 ++++++++++++++ bsp/qemu-vexpress-a9/drivers/drv_smc911x.c | 13 ++++++------ bsp/qemu-vexpress-a9/rtconfig.py | 24 ++++++++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 bsp/qemu-vexpress-a9/drivers/automac.h diff --git a/bsp/qemu-vexpress-a9/.gitignore b/bsp/qemu-vexpress-a9/.gitignore index fd1f012084..fba5a7a92e 100644 --- a/bsp/qemu-vexpress-a9/.gitignore +++ b/bsp/qemu-vexpress-a9/.gitignore @@ -41,3 +41,4 @@ settings/ *.uvguix* cconfig.h .settings +drivers/automac.h diff --git a/bsp/qemu-vexpress-a9/drivers/automac.h b/bsp/qemu-vexpress-a9/drivers/automac.h new file mode 100644 index 0000000000..5f08b79a41 --- /dev/null +++ b/bsp/qemu-vexpress-a9/drivers/automac.h @@ -0,0 +1,15 @@ + +#ifndef __MAC_AUTO_GENERATE_H__ +#define __MAC_AUTO_GENERATE_H__ + +/* Automatically generated file; DO NOT EDIT. */ +/* mac configure file for RT-Thread qemu */ + +#define AUTOMAC0 0x52 +#define AUTOMAC1 0x54 +#define AUTOMAC2 0x00 +#define AUTOMAC3 0x28 +#define AUTOMAC4 0xae +#define AUTOMAC5 0xeb + +#endif diff --git a/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c b/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c index 715cbfb75e..91a9311255 100644 --- a/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c +++ b/bsp/qemu-vexpress-a9/drivers/drv_smc911x.c @@ -2,6 +2,7 @@ #include #include #include +#include #define MAX_ADDR_LEN 6 #define SMC911X_EMAC_DEVICE(eth) (struct eth_device_smc911x*)(eth) @@ -512,12 +513,12 @@ int smc911x_emac_hw_init(void) smc911x_reg_write(&_emac, INT_CFG, INT_CFG_IRQ_POL | INT_CFG_IRQ_TYPE); /* test MAC address */ - _emac.enetaddr[0] = 0x52; - _emac.enetaddr[1] = 0x54; - _emac.enetaddr[2] = 0x00; - _emac.enetaddr[3] = 0x11; - _emac.enetaddr[4] = 0x22; - _emac.enetaddr[5] = 0x33; + _emac.enetaddr[0] = AUTOMAC0; + _emac.enetaddr[1] = AUTOMAC1; + _emac.enetaddr[2] = AUTOMAC2; + _emac.enetaddr[3] = AUTOMAC3; + _emac.enetaddr[4] = AUTOMAC4; + _emac.enetaddr[5] = AUTOMAC5; #ifdef RT_USING_DEVICE_OPS _emac.parent.parent.ops = &smc911x_emac_ops; diff --git a/bsp/qemu-vexpress-a9/rtconfig.py b/bsp/qemu-vexpress-a9/rtconfig.py index d417673898..77e8d6debb 100644 --- a/bsp/qemu-vexpress-a9/rtconfig.py +++ b/bsp/qemu-vexpress-a9/rtconfig.py @@ -1,5 +1,29 @@ import os +import uuid +def get_mac_address(): + mac=uuid.UUID(int = uuid.getnode()).hex[-12:] + return "#define AUTOMAC".join([str(e/2 + 1) + ' 0x' + mac[e:e+2] + '\n' for e in range(5,11,2)]) + +header = ''' +#ifndef __MAC_AUTO_GENERATE_H__ +#define __MAC_AUTO_GENERATE_H__ + +/* Automatically generated file; DO NOT EDIT. */ +/* mac configure file for RT-Thread qemu */ + +#define AUTOMAC0 0x52 +#define AUTOMAC1 0x54 +#define AUTOMAC2 0x00 +#define AUTOMAC''' + +end = ''' +#endif +''' + +with open('drivers/automac.h', 'w') as f: + f.write(header + get_mac_address() + end) + # toolchains options ARCH='arm' CPU='cortex-a'