mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-18 09:13:06 +00:00
47d73ba4f4
Add board_fdt_blob_setup to return the device tree location which is passed by prior stage in u-boot proper. The generic board_fdt_blob_setup always returns _end, it mignt be ok because u-boot SPL would currently put the dtb there, but it would be broken if we put the dtb to another place and assigned the location into a1 register for u-boot proper. Use the location passed by prior stage would make more sence, because we actually pass the location to u-boot proper and want to use that one, rather than the dtb which in _end. We can't use CONFIG_OF_PRIOR_STAGE because it doens't distinguish the implementation of u-boot SPL and u-boot proper, so u-boot SPL need to reply on the prior stage to pass device tree location as well, but we don't pass the DT from boot rom now. In addition, when CONFIG_OF_PRIOR_STAGE is enabled, the u-boot-spl.bin and u-boot.itb won't include the device tree. Signed-off-by: Zong Li <zong.li@sifive.com> Reviewed-by: Leo Yu-Chi Liang <ycliang@andestech.com>
139 lines
2.8 KiB
C
139 lines
2.8 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (c) 2019 Western Digital Corporation or its affiliates.
|
|
*
|
|
* Authors:
|
|
* Anup Patel <anup.patel@wdc.com>
|
|
*/
|
|
|
|
#include <dm.h>
|
|
#include <env.h>
|
|
#include <init.h>
|
|
#include <log.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/bug.h>
|
|
#include <linux/delay.h>
|
|
#include <misc.h>
|
|
#include <spl.h>
|
|
#include <asm/arch/cache.h>
|
|
#include <asm/sections.h>
|
|
|
|
/*
|
|
* This define is a value used for error/unknown serial.
|
|
* If we really care about distinguishing errors and 0 is
|
|
* valid, we'll need a different one.
|
|
*/
|
|
#define ERROR_READING_SERIAL_NUMBER 0
|
|
|
|
#ifdef CONFIG_MISC_INIT_R
|
|
|
|
#if CONFIG_IS_ENABLED(SIFIVE_OTP)
|
|
static u32 otp_read_serialnum(struct udevice *dev)
|
|
{
|
|
int ret;
|
|
u32 serial[2] = {0};
|
|
|
|
for (int i = 0xfe * 4; i > 0; i -= 8) {
|
|
ret = misc_read(dev, i, serial, sizeof(serial));
|
|
|
|
if (ret != sizeof(serial)) {
|
|
printf("%s: error reading serial from OTP\n", __func__);
|
|
break;
|
|
}
|
|
|
|
if (serial[0] == ~serial[1])
|
|
return serial[0];
|
|
}
|
|
|
|
return ERROR_READING_SERIAL_NUMBER;
|
|
}
|
|
#endif
|
|
|
|
static u32 fu540_read_serialnum(void)
|
|
{
|
|
u32 serial = ERROR_READING_SERIAL_NUMBER;
|
|
|
|
#if CONFIG_IS_ENABLED(SIFIVE_OTP)
|
|
struct udevice *dev;
|
|
int ret;
|
|
|
|
/* init OTP */
|
|
ret = uclass_get_device_by_driver(UCLASS_MISC,
|
|
DM_DRIVER_GET(sifive_otp), &dev);
|
|
|
|
if (ret) {
|
|
debug("%s: could not find otp device\n", __func__);
|
|
return serial;
|
|
}
|
|
|
|
/* read serial from OTP and set env var */
|
|
serial = otp_read_serialnum(dev);
|
|
#endif
|
|
|
|
return serial;
|
|
}
|
|
|
|
static void fu540_setup_macaddr(u32 serialnum)
|
|
{
|
|
/* Default MAC address */
|
|
unsigned char mac[6] = { 0x70, 0xb3, 0xd5, 0x92, 0xf0, 0x00 };
|
|
|
|
/*
|
|
* We derive our board MAC address by ORing last three bytes
|
|
* of board serial number to above default MAC address.
|
|
*
|
|
* This logic of deriving board MAC address is taken from
|
|
* SiFive FSBL and is kept unchanged.
|
|
*/
|
|
mac[5] |= (serialnum >> 0) & 0xff;
|
|
mac[4] |= (serialnum >> 8) & 0xff;
|
|
mac[3] |= (serialnum >> 16) & 0xff;
|
|
|
|
/* Update environment variable */
|
|
eth_env_set_enetaddr("ethaddr", mac);
|
|
}
|
|
|
|
int misc_init_r(void)
|
|
{
|
|
u32 serial_num;
|
|
char buf[9] = {0};
|
|
|
|
/* Set ethaddr environment variable from board serial number */
|
|
if (!env_get("serial#")) {
|
|
serial_num = fu540_read_serialnum();
|
|
if (!serial_num) {
|
|
WARN(true, "Board serial number should not be 0 !!\n");
|
|
return 0;
|
|
}
|
|
snprintf(buf, sizeof(buf), "%08x", serial_num);
|
|
env_set("serial#", buf);
|
|
fu540_setup_macaddr(serial_num);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
#endif
|
|
|
|
void *board_fdt_blob_setup(void)
|
|
{
|
|
if (IS_ENABLED(CONFIG_OF_SEPARATE)) {
|
|
if (gd->arch.firmware_fdt_addr)
|
|
return (ulong *)gd->arch.firmware_fdt_addr;
|
|
else
|
|
return (ulong *)&_end;
|
|
}
|
|
}
|
|
|
|
int board_init(void)
|
|
{
|
|
int ret;
|
|
|
|
/* enable all cache ways */
|
|
ret = cache_enable_ways();
|
|
if (ret) {
|
|
debug("%s: could not enable cache ways\n", __func__);
|
|
return ret;
|
|
}
|
|
|
|
return 0;
|
|
}
|