sunxi: board: extract creating a unique sid into a helper function
Refactor setup_environment() so we can use the created sid for a Bluetooth address too. Signed-off-by: Andre Heider <a.heider@gmail.com> Acked-by: Maxime Ripard <mripard@kernel.org> Reviewed-by: Andre Przywara <andre.przywara@arm.com> [rebased] Signed-off-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
This commit is contained in:
committed by
Andre Przywara
parent
ec9cdaaa13
commit
928f4f4868
@@ -789,6 +789,38 @@ static void parse_spl_header(const uint32_t spl_addr)
|
|||||||
env_set_hex("fel_scriptaddr", spl->fel_script_address);
|
env_set_hex("fel_scriptaddr", spl->fel_script_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool get_unique_sid(unsigned int *sid)
|
||||||
|
{
|
||||||
|
if (sunxi_get_sid(sid) != 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!sid[0])
|
||||||
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The single words 1 - 3 of the SID have quite a few bits
|
||||||
|
* which are the same on many models, so we take a crc32
|
||||||
|
* of all 3 words, to get a more unique value.
|
||||||
|
*
|
||||||
|
* Note we only do this on newer SoCs as we cannot change
|
||||||
|
* the algorithm on older SoCs since those have been using
|
||||||
|
* fixed mac-addresses based on only using word 3 for a
|
||||||
|
* long time and changing a fixed mac-address with an
|
||||||
|
* u-boot update is not good.
|
||||||
|
*/
|
||||||
|
#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
|
||||||
|
!defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
|
||||||
|
!defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
|
||||||
|
sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Ensure the NIC specific bytes of the mac are not all 0 */
|
||||||
|
if ((sid[3] & 0xffffff) == 0)
|
||||||
|
sid[3] |= 0x800000;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note this function gets called multiple times.
|
* Note this function gets called multiple times.
|
||||||
* It must not make any changes to env variables which already exist.
|
* It must not make any changes to env variables which already exist.
|
||||||
@@ -799,61 +831,40 @@ static void setup_environment(const void *fdt)
|
|||||||
unsigned int sid[4];
|
unsigned int sid[4];
|
||||||
uint8_t mac_addr[6];
|
uint8_t mac_addr[6];
|
||||||
char ethaddr[16];
|
char ethaddr[16];
|
||||||
int i, ret;
|
int i;
|
||||||
|
|
||||||
ret = sunxi_get_sid(sid);
|
if (!get_unique_sid(sid))
|
||||||
if (ret == 0 && sid[0] != 0) {
|
return;
|
||||||
/*
|
|
||||||
* The single words 1 - 3 of the SID have quite a few bits
|
|
||||||
* which are the same on many models, so we take a crc32
|
|
||||||
* of all 3 words, to get a more unique value.
|
|
||||||
*
|
|
||||||
* Note we only do this on newer SoCs as we cannot change
|
|
||||||
* the algorithm on older SoCs since those have been using
|
|
||||||
* fixed mac-addresses based on only using word 3 for a
|
|
||||||
* long time and changing a fixed mac-address with an
|
|
||||||
* u-boot update is not good.
|
|
||||||
*/
|
|
||||||
#if !defined(CONFIG_MACH_SUN4I) && !defined(CONFIG_MACH_SUN5I) && \
|
|
||||||
!defined(CONFIG_MACH_SUN6I) && !defined(CONFIG_MACH_SUN7I) && \
|
|
||||||
!defined(CONFIG_MACH_SUN8I_A23) && !defined(CONFIG_MACH_SUN8I_A33)
|
|
||||||
sid[3] = crc32(0, (unsigned char *)&sid[1], 12);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Ensure the NIC specific bytes of the mac are not all 0 */
|
for (i = 0; i < 4; i++) {
|
||||||
if ((sid[3] & 0xffffff) == 0)
|
sprintf(ethaddr, "ethernet%d", i);
|
||||||
sid[3] |= 0x800000;
|
if (!fdt_get_alias(fdt, ethaddr))
|
||||||
|
continue;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
if (i == 0)
|
||||||
sprintf(ethaddr, "ethernet%d", i);
|
strcpy(ethaddr, "ethaddr");
|
||||||
if (!fdt_get_alias(fdt, ethaddr))
|
else
|
||||||
continue;
|
sprintf(ethaddr, "eth%daddr", i);
|
||||||
|
|
||||||
if (i == 0)
|
if (env_get(ethaddr))
|
||||||
strcpy(ethaddr, "ethaddr");
|
continue;
|
||||||
else
|
|
||||||
sprintf(ethaddr, "eth%daddr", i);
|
|
||||||
|
|
||||||
if (env_get(ethaddr))
|
/* Non OUI / registered MAC address */
|
||||||
continue;
|
mac_addr[0] = (i << 4) | 0x02;
|
||||||
|
mac_addr[1] = (sid[0] >> 0) & 0xff;
|
||||||
|
mac_addr[2] = (sid[3] >> 24) & 0xff;
|
||||||
|
mac_addr[3] = (sid[3] >> 16) & 0xff;
|
||||||
|
mac_addr[4] = (sid[3] >> 8) & 0xff;
|
||||||
|
mac_addr[5] = (sid[3] >> 0) & 0xff;
|
||||||
|
|
||||||
/* Non OUI / registered MAC address */
|
eth_env_set_enetaddr(ethaddr, mac_addr);
|
||||||
mac_addr[0] = (i << 4) | 0x02;
|
}
|
||||||
mac_addr[1] = (sid[0] >> 0) & 0xff;
|
|
||||||
mac_addr[2] = (sid[3] >> 24) & 0xff;
|
|
||||||
mac_addr[3] = (sid[3] >> 16) & 0xff;
|
|
||||||
mac_addr[4] = (sid[3] >> 8) & 0xff;
|
|
||||||
mac_addr[5] = (sid[3] >> 0) & 0xff;
|
|
||||||
|
|
||||||
eth_env_set_enetaddr(ethaddr, mac_addr);
|
if (!env_get("serial#")) {
|
||||||
}
|
snprintf(serial_string, sizeof(serial_string),
|
||||||
|
"%08x%08x", sid[0], sid[3]);
|
||||||
|
|
||||||
if (!env_get("serial#")) {
|
env_set("serial#", serial_string);
|
||||||
snprintf(serial_string, sizeof(serial_string),
|
|
||||||
"%08x%08x", sid[0], sid[3]);
|
|
||||||
|
|
||||||
env_set("serial#", serial_string);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user