Skip to content

Commit 91f6abb

Browse files
authored
Merge pull request #2675 from lymzzyh/qemu-mac
[BSP][qemu-a9] auto generate mac address from host
2 parents 9fd017c + 4f521a0 commit 91f6abb

File tree

4 files changed

+47
-6
lines changed

4 files changed

+47
-6
lines changed

bsp/qemu-vexpress-a9/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ settings/
4141
*.uvguix*
4242
cconfig.h
4343
.settings
44+
drivers/automac.h
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
#ifndef __MAC_AUTO_GENERATE_H__
3+
#define __MAC_AUTO_GENERATE_H__
4+
5+
/* Automatically generated file; DO NOT EDIT. */
6+
/* mac configure file for RT-Thread qemu */
7+
8+
#define AUTOMAC0 0x52
9+
#define AUTOMAC1 0x54
10+
#define AUTOMAC2 0x00
11+
#define AUTOMAC3 0x28
12+
#define AUTOMAC4 0xae
13+
#define AUTOMAC5 0xeb
14+
15+
#endif

bsp/qemu-vexpress-a9/drivers/drv_smc911x.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <rtthread.h>
33
#include <netif/ethernetif.h>
44
#include <lwipopts.h>
5+
#include <automac.h>
56

67
#define MAX_ADDR_LEN 6
78
#define SMC911X_EMAC_DEVICE(eth) (struct eth_device_smc911x*)(eth)
@@ -512,12 +513,12 @@ int smc911x_emac_hw_init(void)
512513
smc911x_reg_write(&_emac, INT_CFG, INT_CFG_IRQ_POL | INT_CFG_IRQ_TYPE);
513514

514515
/* test MAC address */
515-
_emac.enetaddr[0] = 0x52;
516-
_emac.enetaddr[1] = 0x54;
517-
_emac.enetaddr[2] = 0x00;
518-
_emac.enetaddr[3] = 0x11;
519-
_emac.enetaddr[4] = 0x22;
520-
_emac.enetaddr[5] = 0x33;
516+
_emac.enetaddr[0] = AUTOMAC0;
517+
_emac.enetaddr[1] = AUTOMAC1;
518+
_emac.enetaddr[2] = AUTOMAC2;
519+
_emac.enetaddr[3] = AUTOMAC3;
520+
_emac.enetaddr[4] = AUTOMAC4;
521+
_emac.enetaddr[5] = AUTOMAC5;
521522

522523
#ifdef RT_USING_DEVICE_OPS
523524
_emac.parent.parent.ops = &smc911x_emac_ops;

bsp/qemu-vexpress-a9/rtconfig.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
import os
22

3+
import uuid
4+
def get_mac_address():
5+
mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
6+
return "#define AUTOMAC".join([str(e/2 + 1) + ' 0x' + mac[e:e+2] + '\n' for e in range(5,11,2)])
7+
8+
header = '''
9+
#ifndef __MAC_AUTO_GENERATE_H__
10+
#define __MAC_AUTO_GENERATE_H__
11+
12+
/* Automatically generated file; DO NOT EDIT. */
13+
/* mac configure file for RT-Thread qemu */
14+
15+
#define AUTOMAC0 0x52
16+
#define AUTOMAC1 0x54
17+
#define AUTOMAC2 0x00
18+
#define AUTOMAC'''
19+
20+
end = '''
21+
#endif
22+
'''
23+
24+
with open('drivers/automac.h', 'w') as f:
25+
f.write(header + get_mac_address() + end)
26+
327
# toolchains options
428
ARCH='arm'
529
CPU='cortex-a'

0 commit comments

Comments
 (0)