2018-10-05 15:00:37 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2020-07-28 20:35:32 +00:00
|
|
|
#include <fastboot.h>
|
2019-11-14 19:57:46 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <net.h>
|
2018-07-27 12:10:00 +00:00
|
|
|
#include <asm/arch/boot.h>
|
2019-08-01 15:46:51 +00:00
|
|
|
#include <env.h>
|
2020-05-10 17:39:56 +00:00
|
|
|
#include <asm/cache.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-05-10 17:40:06 +00:00
|
|
|
#include <asm/ptrace.h>
|
2018-10-05 15:00:37 +00:00
|
|
|
#include <linux/libfdt.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <asm/arch/mem.h>
|
|
|
|
#include <asm/arch/sm.h>
|
|
|
|
#include <asm/armv8/mmu.h>
|
|
|
|
#include <asm/unaligned.h>
|
|
|
|
#include <efi_loader.h>
|
2019-11-14 19:57:16 +00:00
|
|
|
#include <u-boot/crc.h>
|
2018-10-05 15:00:37 +00:00
|
|
|
|
2019-05-22 11:30:25 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FASTBOOT)
|
|
|
|
#include <asm/psci.h>
|
|
|
|
#include <fastboot.h>
|
|
|
|
#endif
|
|
|
|
|
2018-10-05 15:00:37 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-10-24 12:57:54 +00:00
|
|
|
__weak int board_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-10-05 15:00:37 +00:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
const fdt64_t *val;
|
|
|
|
int offset;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
offset = fdt_path_offset(gd->fdt_blob, "/memory");
|
|
|
|
if (offset < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
val = fdt_getprop(gd->fdt_blob, offset, "reg", &len);
|
|
|
|
if (len < sizeof(*val) * 2)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Use unaligned access since cache is still disabled */
|
|
|
|
gd->ram_size = get_unaligned_be64(&val[1]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
__weak int meson_ft_board_setup(void *blob, struct bd_info *bd)
|
2018-10-24 12:57:54 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
2018-10-24 12:57:54 +00:00
|
|
|
{
|
|
|
|
meson_init_reserved_memory(blob);
|
|
|
|
|
|
|
|
return meson_ft_board_setup(blob, bd);
|
|
|
|
}
|
|
|
|
|
2018-10-05 15:00:37 +00:00
|
|
|
void meson_board_add_reserved_memory(void *fdt, u64 start, u64 size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = fdt_add_mem_rsv(fdt, start, size);
|
|
|
|
if (ret)
|
|
|
|
printf("Could not reserve zone @ 0x%llx\n", start);
|
|
|
|
|
2020-05-17 10:29:19 +00:00
|
|
|
if (IS_ENABLED(CONFIG_EFI_LOADER))
|
|
|
|
efi_add_memory_map(start, size, EFI_RESERVED_MEMORY_TYPE);
|
2018-10-05 15:00:37 +00:00
|
|
|
}
|
|
|
|
|
2019-06-12 09:49:07 +00:00
|
|
|
int meson_generate_serial_ethaddr(void)
|
|
|
|
{
|
|
|
|
u8 mac_addr[ARP_HLEN];
|
|
|
|
char serial[SM_SERIAL_SIZE];
|
|
|
|
u32 sid;
|
|
|
|
u16 sid16;
|
|
|
|
|
|
|
|
if (!meson_sm_get_serial(serial, SM_SERIAL_SIZE)) {
|
|
|
|
sid = crc32(0, (unsigned char *)serial, SM_SERIAL_SIZE);
|
|
|
|
sid16 = crc16_ccitt(0, (unsigned char *)serial, SM_SERIAL_SIZE);
|
|
|
|
|
|
|
|
/* Ensure the NIC specific bytes of the mac are not all 0 */
|
|
|
|
if ((sid & 0xffffff) == 0)
|
|
|
|
sid |= 0x800000;
|
|
|
|
|
|
|
|
/* Non OUI / registered MAC address */
|
|
|
|
mac_addr[0] = ((sid16 >> 8) & 0xfc) | 0x02;
|
|
|
|
mac_addr[1] = (sid16 >> 0) & 0xff;
|
|
|
|
mac_addr[2] = (sid >> 24) & 0xff;
|
|
|
|
mac_addr[3] = (sid >> 16) & 0xff;
|
|
|
|
mac_addr[4] = (sid >> 8) & 0xff;
|
|
|
|
mac_addr[5] = (sid >> 0) & 0xff;
|
|
|
|
|
|
|
|
eth_env_set_enetaddr("ethaddr", mac_addr);
|
|
|
|
} else
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-27 12:10:00 +00:00
|
|
|
static void meson_set_boot_source(void)
|
|
|
|
{
|
|
|
|
const char *source;
|
|
|
|
|
|
|
|
switch (meson_get_boot_device()) {
|
|
|
|
case BOOT_DEVICE_EMMC:
|
|
|
|
source = "emmc";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOT_DEVICE_NAND:
|
|
|
|
source = "nand";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOT_DEVICE_SPI:
|
|
|
|
source = "spi";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOT_DEVICE_SD:
|
|
|
|
source = "sd";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOT_DEVICE_USB:
|
|
|
|
source = "usb";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
source = "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
env_set("boot_source", source);
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak int meson_board_late_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
|
|
|
meson_set_boot_source();
|
|
|
|
|
|
|
|
return meson_board_late_init();
|
|
|
|
}
|
|
|
|
|
2019-05-22 11:30:25 +00:00
|
|
|
#if CONFIG_IS_ENABLED(FASTBOOT)
|
|
|
|
static unsigned int reboot_reason = REBOOT_REASON_NORMAL;
|
|
|
|
|
2020-07-28 20:35:32 +00:00
|
|
|
int fastboot_set_reboot_flag(enum fastboot_reboot_reason reason)
|
2019-05-22 11:30:25 +00:00
|
|
|
{
|
2020-07-28 20:35:32 +00:00
|
|
|
if (reason != FASTBOOT_REBOOT_REASON_BOOTLOADER)
|
|
|
|
return -ENOTSUPP;
|
|
|
|
|
2019-05-22 11:30:25 +00:00
|
|
|
reboot_reason = REBOOT_REASON_BOOTLOADER;
|
|
|
|
|
|
|
|
printf("Using reboot reason: 0x%x\n", reboot_reason);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2019-05-22 11:30:25 +00:00
|
|
|
{
|
|
|
|
struct pt_regs regs;
|
|
|
|
|
|
|
|
regs.regs[0] = ARM_PSCI_0_2_FN_SYSTEM_RESET;
|
|
|
|
regs.regs[1] = reboot_reason;
|
|
|
|
|
|
|
|
printf("Rebooting with reason: 0x%lx\n", regs.regs[1]);
|
|
|
|
|
|
|
|
smc_call(®s);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
#else
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2018-10-05 15:00:37 +00:00
|
|
|
{
|
|
|
|
psci_system_reset();
|
|
|
|
}
|
2019-05-22 11:30:25 +00:00
|
|
|
#endif
|