2017-04-07 17:13:38 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2017 Theobroma Systems Design und Consulting GmbH
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
2017-09-29 17:27:54 +00:00
|
|
|
|
2017-04-07 17:13:38 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2017-04-28 15:31:44 +00:00
|
|
|
#include <misc.h>
|
2017-04-07 17:13:38 +00:00
|
|
|
#include <dm/pinctrl.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
2017-05-05 17:21:39 +00:00
|
|
|
#include <asm/setup.h>
|
2017-04-07 17:13:38 +00:00
|
|
|
#include <asm/arch/periph.h>
|
|
|
|
#include <power/regulator.h>
|
2017-09-29 17:27:54 +00:00
|
|
|
#include <spl.h>
|
2017-04-28 15:31:44 +00:00
|
|
|
#include <u-boot/sha256.h>
|
|
|
|
|
2017-04-07 17:13:38 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
int board_init(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
2017-09-29 17:28:00 +00:00
|
|
|
* We need to call into regulators_enable_boot_on() again, as the call
|
|
|
|
* during SPL may have not included all regulators.
|
2017-04-07 17:13:38 +00:00
|
|
|
*/
|
2017-09-29 17:28:00 +00:00
|
|
|
ret = regulators_enable_boot_on(false);
|
2017-04-07 17:13:38 +00:00
|
|
|
if (ret)
|
2017-09-29 17:28:00 +00:00
|
|
|
debug("%s: Cannot enable boot on regulator\n", __func__);
|
2017-04-07 17:13:38 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-29 17:27:54 +00:00
|
|
|
void spl_board_init(void)
|
|
|
|
{
|
2017-09-29 17:28:01 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Turning the eMMC and SPI back on (if disabled via the Qseven
|
|
|
|
* BIOS_ENABLE) signal is done through a always-on regulator).
|
|
|
|
*/
|
|
|
|
ret = regulators_enable_boot_on(false);
|
|
|
|
if (ret)
|
|
|
|
debug("%s: Cannot enable boot on regulator\n", __func__);
|
|
|
|
|
2017-09-29 17:27:54 +00:00
|
|
|
preloader_console_init();
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:21:40 +00:00
|
|
|
static void setup_macaddr(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_IS_ENABLED(CMD_NET)
|
|
|
|
int ret;
|
2017-08-03 18:22:12 +00:00
|
|
|
const char *cpuid = env_get("cpuid#");
|
2017-05-05 17:21:40 +00:00
|
|
|
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 */
|
2017-08-03 18:22:12 +00:00
|
|
|
if (env_get("ethaddr"))
|
2017-05-05 17:21:40 +00:00
|
|
|
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) */
|
2017-08-03 18:22:11 +00:00
|
|
|
eth_env_set_enetaddr("ethaddr", mac_addr);
|
2017-05-05 17:21:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-05-05 17:21:39 +00:00
|
|
|
static void setup_serial(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_IS_ENABLED(ROCKCHIP_EFUSE)
|
2017-07-27 11:59:03 +00:00
|
|
|
const u32 cpuid_offset = 0x7;
|
|
|
|
const u32 cpuid_length = 0x10;
|
|
|
|
|
2017-05-05 17:21:39 +00:00
|
|
|
struct udevice *dev;
|
|
|
|
int ret, i;
|
2017-07-27 11:59:03 +00:00
|
|
|
u8 cpuid[cpuid_length];
|
|
|
|
u8 low[cpuid_length/2], high[cpuid_length/2];
|
|
|
|
char cpuid_str[cpuid_length * 2 + 1];
|
2017-05-05 17:21:39 +00:00
|
|
|
u64 serialno;
|
2017-09-15 12:46:04 +00:00
|
|
|
char serialno_str[17];
|
2017-05-05 17:21:39 +00:00
|
|
|
|
2017-05-05 17:21:40 +00:00
|
|
|
/* retrieve the device */
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
|
|
|
DM_GET_DRIVER(rockchip_efuse), &dev);
|
2017-05-05 17:21:39 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: could not find efuse device\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* read the cpu_id range from the efuses */
|
2017-07-27 11:59:03 +00:00
|
|
|
ret = misc_read(dev, cpuid_offset, &cpuid, sizeof(cpuid));
|
2017-05-05 17:21:39 +00:00
|
|
|
if (ret) {
|
|
|
|
debug("%s: reading cpuid from the efuses failed\n",
|
|
|
|
__func__);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(cpuid_str, 0, sizeof(cpuid_str));
|
|
|
|
for (i = 0; i < 16; i++)
|
|
|
|
sprintf(&cpuid_str[i * 2], "%02x", cpuid[i]);
|
|
|
|
|
|
|
|
debug("cpuid: %s\n", cpuid_str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mix the cpuid bytes using the same rules as in
|
|
|
|
* ${linux}/drivers/soc/rockchip/rockchip-cpuinfo.c
|
|
|
|
*/
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
low[i] = cpuid[1 + (i << 1)];
|
|
|
|
high[i] = cpuid[i << 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
serialno = crc32_no_comp(0, low, 8);
|
|
|
|
serialno |= (u64)crc32_no_comp(serialno, high, 8) << 32;
|
|
|
|
snprintf(serialno_str, sizeof(serialno_str), "%llx", serialno);
|
|
|
|
|
2017-08-03 18:22:09 +00:00
|
|
|
env_set("cpuid#", cpuid_str);
|
|
|
|
env_set("serial#", serialno_str);
|
2017-05-05 17:21:39 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
|
|
|
setup_serial();
|
2017-05-05 17:21:40 +00:00
|
|
|
setup_macaddr();
|
2017-05-05 17:21:39 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_TAG
|
|
|
|
void get_board_serial(struct tag_serialnr *serialnr)
|
|
|
|
{
|
|
|
|
char *serial_string;
|
|
|
|
u64 serial = 0;
|
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
serial_string = env_get("serial#");
|
2017-05-05 17:21:39 +00:00
|
|
|
|
|
|
|
if (serial_string)
|
|
|
|
serial = simple_strtoull(serial_string, NULL, 16);
|
|
|
|
|
|
|
|
serialnr->high = (u32)(serial >> 32);
|
|
|
|
serialnr->low = (u32)(serial & 0xffffffff);
|
|
|
|
}
|
|
|
|
#endif
|