mirror of
https://github.com/paolosabatino/multitool.git
synced 2024-11-25 06:26:17 +00:00
102 lines
2.9 KiB
Diff
102 lines
2.9 KiB
Diff
From 61b0555d3b8e962f3cac5cf17ab149f4fb318ca3 Mon Sep 17 00:00:00 2001
|
|
From: Jonas Karlman <jonas@kwiboo.se>
|
|
Date: Mon, 20 Aug 2018 22:55:34 +0200
|
|
Subject: [PATCH] rockchip: board: use efuse cpuid to set ethaddr
|
|
|
|
---
|
|
arch/arm/mach-rockchip/board.c | 51 ++++++++++++++++++++++++++++++++++
|
|
1 file changed, 51 insertions(+)
|
|
|
|
diff --git a/arch/arm/mach-rockchip/board.c b/arch/arm/mach-rockchip/board.c
|
|
index b56edebf13..155871f5bf 100644
|
|
--- a/arch/arm/mach-rockchip/board.c
|
|
+++ b/arch/arm/mach-rockchip/board.c
|
|
@@ -45,6 +45,9 @@
|
|
#include <of_live.h>
|
|
#include <dm/root.h>
|
|
#include <console.h>
|
|
+#include <hash.h>
|
|
+#include <u-boot/sha256.h>
|
|
+
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
/* define serialno max length, the max length is 512 Bytes
|
|
@@ -67,6 +70,40 @@
|
|
sprintf(buf, "%pM", ethaddr);
|
|
env_set("ethaddr", buf);
|
|
}
|
|
+#elif 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];
|
|
+
|
|
+ /* Only generate a MAC address, if none is set in the environment */
|
|
+ if (env_get("ethaddr"))
|
|
+ return 0;
|
|
+
|
|
+ if (!cpuid) {
|
|
+ debug("%s: could not retrieve 'cpuid#'\n", __func__);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
|
|
+ if (ret) {
|
|
+ debug("%s: failed to calculate SHA256\n", __func__);
|
|
+ return -EINVAL;
|
|
+ }
|
|
+
|
|
+ /* 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);
|
|
+
|
|
+ /* Make a valid MAC address for eth1 */
|
|
+ mac_addr[5] += 0x20;
|
|
+ mac_addr[5] &= 0xff;
|
|
+ eth_env_set_enetaddr("eth1addr", mac_addr);
|
|
#endif
|
|
return 0;
|
|
}
|
|
@@ -74,6 +111,9 @@
|
|
static int rockchip_set_serialno(void)
|
|
{
|
|
char serialno_str[VENDOR_SN_MAX];
|
|
+#ifdef CONFIG_ROCKCHIP_EFUSE
|
|
+ char cpuid_str[CPUID_LEN * 2 + 1];
|
|
+#endif
|
|
int ret = 0, i;
|
|
u8 cpuid[CPUID_LEN] = {0};
|
|
u8 low[CPUID_LEN / 2], high[CPUID_LEN / 2];
|
|
@@ -103,6 +143,13 @@
|
|
printf("%s: reading cpuid from the efuses failed\n", __func__);
|
|
return ret;
|
|
}
|
|
+
|
|
+ memset(cpuid_str, 0, sizeof(cpuid_str));
|
|
+ for (i = 0; i < CPUID_LEN; i++) {
|
|
+ sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);
|
|
+ }
|
|
+
|
|
+ env_set("cpuid#", cpuid_str);
|
|
#else
|
|
/* generate random cpuid */
|
|
for (i = 0; i < CPUID_LEN; i++) {
|
|
|
|
--- a/arch/arm/mach-rockchip/board.c
|
|
+++ b/arch/arm/mach-rockchip/board.c
|
|
@@ -205,8 +205,8 @@
|
|
|
|
int board_late_init(void)
|
|
{
|
|
- rockchip_set_ethaddr();
|
|
rockchip_set_serialno();
|
|
+ rockchip_set_ethaddr();
|
|
#if (CONFIG_ROCKCHIP_BOOT_MODE_REG > 0)
|
|
setup_boot_mode();
|
|
#endif
|