Skip to content

Commit

Permalink
fix: fix the problem of wrong overwritten mac address
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-yue-yu authored and RevySR committed Jun 27, 2023
1 parent b576804 commit d6c9182
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 48 deletions.
76 changes: 29 additions & 47 deletions board/thead/light-c910/light.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,10 +1858,9 @@ int board_init(void)
static void light_usb_boot_check(void)
{
int boot_mode;
// uchar env_enetaddr[6]={0};
// uchar env_enet1addr[6]={0};

// int env_ethaddr_flag,env_eth1addr_flag;
uchar env_enetaddr[6]={0};
uchar env_enet1addr[6]={0};
int env_ethaddr_flag,env_eth1addr_flag;
boot_mode = readl((void *)SOC_OM_ADDRBASE) & 0x7;
if (boot_mode & BIT(2))
return;
Expand All @@ -1870,56 +1869,40 @@ static void light_usb_boot_check(void)
env_set("usb_fastboot", "yes");
#endif
/*Get this version ethaddr(mac addr) env,which follows one board, trans to next version env*/
// env_ethaddr_flag = eth_env_get_enetaddr_by_index("eth", 0, env_enetaddr);
// env_eth1addr_flag = eth_env_get_enetaddr_by_index("eth", 1, env_enet1addr);
env_ethaddr_flag = eth_env_get_enetaddr_by_index("eth", 0, env_enetaddr);
env_eth1addr_flag = eth_env_get_enetaddr_by_index("eth", 1, env_enet1addr);

run_command("env default -a -f", 0);

/*If mac addr in last version env is valid, before save,inherit env mac addr */
// if(env_ethaddr_flag){
// eth_env_set_enetaddr_by_index("eth", 0, env_enetaddr);
// run_command("printenv ethaddr",0);
// }else{
// printf("env ethaddr not exist or invalid\n");
// }

// if(env_eth1addr_flag){
// eth_env_set_enetaddr_by_index("eth", 1, env_enet1addr);
// run_command("printenv eth1addr",0);
// }else{
// printf("env eth1addr not exist or invalid\n");
// }
if(env_ethaddr_flag){
eth_env_set_enetaddr_by_index("eth", 0, env_enetaddr);
run_command("printenv ethaddr",0);
}else{
net_random_ethaddr(env_enetaddr);
eth_env_set_enetaddr_by_index("eth", 0, env_enetaddr);
env_enetaddr[5] += 0x01;
eth_env_set_enetaddr_by_index("eth", 1, env_enetaddr);
//printf("env ethaddr not exist or invalid\n");
printf("use random addr as fixed mac addr\n");
}

if(env_eth1addr_flag){
eth_env_set_enetaddr_by_index("eth", 1, env_enet1addr);
run_command("printenv eth1addr",0);
}else{
net_random_ethaddr(env_enet1addr);
eth_env_set_enetaddr_by_index("eth", 1, env_enet1addr);
env_enet1addr[5] -= 0x01;
eth_env_set_enetaddr_by_index("eth", 0, env_enet1addr);
//printf("env eth1addr not exist or invalid\n");
printf("use random addr as fixed mac addr\n");
}

run_command("env save", 0);
run_command("run gpt_partition", 0);
run_command("fastboot usb 0", 0);
}

static void set_fixed_mac(void)
{
uchar tmp_enetaddr[6] = {0};
uchar tmp_enet1addr[6] = {0};
int env_ethaddr_flag, env_eth1addr_flag;

env_ethaddr_flag = eth_env_get_enetaddr("ethaddr", tmp_enetaddr);
env_eth1addr_flag = eth_env_set_enetaddr("eth1addr", tmp_enet1addr);

if(!env_ethaddr_flag){
net_random_ethaddr(tmp_enetaddr);
eth_env_set_enetaddr("ethaddr", tmp_enetaddr);
tmp_enetaddr[5] += 0x01;
eth_env_set_enetaddr("eth1addr", tmp_enetaddr);
run_command("env save", 0);
return ;
}
if(!env_eth1addr_flag){
net_random_ethaddr(tmp_enet1addr);
eth_env_set_enetaddr("eth1addr", tmp_enet1addr);
tmp_enet1addr[5] -= 0x01;
eth_env_set_enetaddr("ethaddr", tmp_enet1addr);
run_command("env save", 0);
}
}

int board_late_init(void)
{

Expand All @@ -1930,7 +1913,6 @@ int board_late_init(void)
sec_firmware_version_dump();
#endif
light_usb_boot_check();
set_fixed_mac();
ap_peri_clk_disable();
return 0;
}
Expand Down
1 change: 0 additions & 1 deletion include/configs/light-c910.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#define PLIC_BASE_ADDR 0xffd8000000
#define PMP_BASE_ADDR 0xffdc020000

#define CONFIG_ENV_OVERWRITE 1 //make sure env var can be modified successfully

/* Network Configuration */
#define CONFIG_DW_ALTDESCRIPTOR
Expand Down

0 comments on commit d6c9182

Please sign in to comment.