summaryrefslogtreecommitdiff
path: root/board/theobroma-systems
diff options
context:
space:
mode:
authorKlaus Goger <klaus.goger@theobroma-systems.com>2017-05-05 17:21:40 (GMT)
committerSimon Glass <sjg@chromium.org>2017-06-07 13:29:18 (GMT)
commit8adc9d18a8344cba01bcaa13318ca8cf1afac312 (patch)
treecc91fba6245a3216cd7df720822214334afd5645 /board/theobroma-systems
parent9415b9a7d85c6c77698a551c47765720c2caef91 (diff)
downloadu-boot-8adc9d18a8344cba01bcaa13318ca8cf1afac312.tar.xz
rockchip: board: puma_rk3399: derive ethaddr from cpuid
Generate a MAC address based on the cpuid available in the efuse block: Use the first 6 byte of the cpuid's SHA256 hash and set the locally administered bits. Also ensure that the multicast bit is cleared. The MAC address is only generated and set if there is no ethaddr present in the saved environment. Signed-off-by: Klaus Goger <klaus.goger@theobroma-systems.com> Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'board/theobroma-systems')
-rw-r--r--board/theobroma-systems/puma_rk3399/puma-rk3399.c42
1 files changed, 40 insertions, 2 deletions
diff --git a/board/theobroma-systems/puma_rk3399/puma-rk3399.c b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
index ea6d256..6fff3e1 100644
--- a/board/theobroma-systems/puma_rk3399/puma-rk3399.c
+++ b/board/theobroma-systems/puma_rk3399/puma-rk3399.c
@@ -68,6 +68,42 @@ out:
return 0;
}
+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];
+
+ /* 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__);
+ return;
+ }
+
+ ret = hash_block("sha256", (void *)cpuid, strlen(cpuid), hash, &size);
+ if (ret) {
+ debug("%s: failed to calculate SHA256\n", __func__);
+ return;
+ }
+
+ /* 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_setenv_enetaddr("ethaddr", mac_addr);
+#endif
+
+ return;
+}
+
static void setup_serial(void)
{
#if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
@@ -79,8 +115,9 @@ static void setup_serial(void)
u64 serialno;
char serialno_str[16];
- /* the first misc device will be used */
- ret = uclass_get_device(UCLASS_MISC, 0, &dev);
+ /* retrieve the device */
+ ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_GET_DRIVER(rockchip_efuse), &dev);
if (ret) {
debug("%s: could not find efuse device\n", __func__);
return;
@@ -123,6 +160,7 @@ static void setup_serial(void)
int misc_init_r(void)
{
setup_serial();
+ setup_macaddr();
return 0;
}