]> Git Repo - u-boot.git/blobdiff - net/net_rand.h
sunxi: dts: arm64: update emac for Orange Pi Zero 3
[u-boot.git] / net / net_rand.h
index ba9d0642cf231ab2ed14c162f2c7fb975f315574..6a52cda85e0325b0e35b5979a19eec08ac693171 100644 (file)
 #define __NET_RAND_H__
 
 #include <common.h>
+#include <dm/uclass.h>
+#include <rng.h>
 
 /*
  * Return a seed for the PRNG derived from the eth0 MAC address.
  */
 static inline unsigned int seed_mac(void)
 {
-       unsigned char enetaddr[6];
+       unsigned char enetaddr[ARP_HLEN];
        unsigned int seed;
 
        /* get our mac */
-       eth_getenv_enetaddr("ethaddr", enetaddr);
+       memcpy(enetaddr, eth_get_ethaddr(), ARP_HLEN);
 
        seed = enetaddr[5];
        seed ^= enetaddr[4] << 8;
@@ -37,7 +39,22 @@ static inline unsigned int seed_mac(void)
  */
 static inline void srand_mac(void)
 {
-       srand(seed_mac());
+       int ret;
+       struct udevice *devp;
+       u32 randv = 0;
+
+       if (IS_ENABLED(CONFIG_DM_RNG)) {
+               ret = uclass_get_device(UCLASS_RNG, 0, &devp);
+               if (ret) {
+                       ret = dm_rng_read(devp, &randv, sizeof(randv));
+                       if (ret < 0)
+                               randv = 0;
+               }
+       }
+       if (randv)
+               srand(randv);
+       else
+               srand(seed_mac());
 }
 
 #endif /* __NET_RAND_H__ */
This page took 0.026094 seconds and 4 git commands to generate.