summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoy Cho <joy.cho@hardkernel.com>2017-11-10 05:36:19 +0300
committerJeongHwaCho <joycho78@gmail.com>2017-12-06 10:16:50 +0300
commitffd60a1ae57f3197d0172dc2bff2179a1f2de0aa (patch)
tree1ebf97598b7b5386858df4074d292d8b71548d56
parent2c09c96974f920fa44107555af5858c418fee7ec (diff)
downloadu-boot-odroidn1-v2017.07-android.tar.xz
board: odroidn1: update mac generation scheme based on hardkernel rulerk3399_7.1.2_v1.0odroidn1-v2017.07-android
Change-Id: I248f68089bd0cbde0d8f1df9dea61fdb1803eacb
-rw-r--r--board/rockchip/odroidn1/odroidn1.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/board/rockchip/odroidn1/odroidn1.c b/board/rockchip/odroidn1/odroidn1.c
index cab73f93b0..005929b61e 100644
--- a/board/rockchip/odroidn1/odroidn1.c
+++ b/board/rockchip/odroidn1/odroidn1.c
@@ -15,6 +15,7 @@
#include <u-boot/sha256.h>
#include <usb.h>
#include <dwc3-uboot.h>
+#include <crc.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -115,36 +116,66 @@ out:
return 0;
}
+/*
+ * basic rule of mac generation
+ * fixed pattern : first 3bytes and 4bit msb of 4rd byte
+ * 00:1e:06:xx:xx:xx
+ */
static void setup_macaddr(void)
{
#if CONFIG_IS_ENABLED(CMD_NET)
- int ret;
- const char *cpuid = getenv("cpuid#");
- u8 hash[SHA256_SUM_LEN];
- int size = sizeof(hash);
u8 mac_addr[6];
+ u64 temp;
+ u8 cpuid[RK3399_CPUID_LEN];
+ u8 low[RK3399_CPUID_LEN/2], high[RK3399_CPUID_LEN/2];
+ int ret, i;
+ struct udevice *dev;
/* Only generate a MAC address, if none is set in the environment */
if (getenv("ethaddr"))
return;
- if (!cpuid) {
- debug("%s: could not retrieve 'cpuid#'\n", __func__);
+ /* retrieve the device */
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(rockchip_efuse), &dev);
+ if (ret) {
+ printf("%s: could not find efuse device\n", __func__);
return;
}
- ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
+ /* read the cpu_id range from the efuses */
+ ret = misc_read(dev, RK3399_CPUID_OFF, &cpuid, sizeof(cpuid));
if (ret) {
- debug("%s: failed to calculate SHA256\n", __func__);
+ printf("%s: reading cpuid from the efuses failed\n",
+ __func__);
return;
}
- /* Copy 6 bytes of the hash to base the MAC address on */
- memcpy(mac_addr, hash, 6);
+ temp = 0ul;
+
+ /* rearrange cpuid as 8bytes unit */
+ for (i = 0; i < 8; i++) {
+ low[i] = cpuid[1 + (i << 1)];
+ high[i] = cpuid[i << 1];
+ }
+
+ /* calculate crc16 using low : 8byte input -> 2byte output */
+ temp = crc16_ccitt(0, low, 8);
+
+ /* calculate crc8 using high : 8byte input -> 1byte output */
+ temp |= (u64)crc8(temp, high, 8) << 16;
+
+ /* fixed pattern */
+ mac_addr[0] = 0x00;
+ mac_addr[1] = 0x1e;
+ mac_addr[2] = 0x06;
+
+ /* unique pattern */
+ mac_addr[3] = (char)(0xff & (temp >> 16));
+ mac_addr[4] = (char)(0xff & (temp >> 8));
+ mac_addr[5] = (char)(0xff & temp);
- /* 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) */
+ /* save env */
eth_setenv_enetaddr("ethaddr", mac_addr);
#endif