mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-20 11:55:03 +00:00

Select environment location based on the device we boot from. Also, introduce a "boot" variable that represents the current boot device and can be used by scripts. Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
123 lines
2.5 KiB
C
123 lines
2.5 KiB
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* Copyright (C) 2022 - 2023 PHYTEC Messtechnik GmbH
|
|
* Author: Wadim Egorov <w.egorov@phytec.de>
|
|
*/
|
|
|
|
#include <asm/io.h>
|
|
#include <env.h>
|
|
#include <env_internal.h>
|
|
#include <spl.h>
|
|
#include <fdt_support.h>
|
|
#include <asm/arch/hardware.h>
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
int board_init(void)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
int dram_init(void)
|
|
{
|
|
return fdtdec_setup_mem_size_base();
|
|
}
|
|
|
|
int dram_init_banksize(void)
|
|
{
|
|
return fdtdec_setup_memory_banksize();
|
|
}
|
|
|
|
#define CTRLMMR_USB0_PHY_CTRL 0x43004008
|
|
#define CTRLMMR_USB1_PHY_CTRL 0x43004018
|
|
#define CORE_VOLTAGE 0x80000000
|
|
|
|
#ifdef CONFIG_SPL_BOARD_INIT
|
|
void spl_board_init(void)
|
|
{
|
|
u32 val;
|
|
|
|
/* Set USB0 PHY core voltage to 0.85V */
|
|
val = readl(CTRLMMR_USB0_PHY_CTRL);
|
|
val &= ~(CORE_VOLTAGE);
|
|
writel(val, CTRLMMR_USB0_PHY_CTRL);
|
|
|
|
/* Set USB1 PHY core voltage to 0.85V */
|
|
val = readl(CTRLMMR_USB1_PHY_CTRL);
|
|
val &= ~(CORE_VOLTAGE);
|
|
writel(val, CTRLMMR_USB1_PHY_CTRL);
|
|
|
|
/* We have 32k crystal, so lets enable it */
|
|
val = readl(MCU_CTRL_LFXOSC_CTRL);
|
|
val &= ~(MCU_CTRL_LFXOSC_32K_DISABLE_VAL);
|
|
writel(val, MCU_CTRL_LFXOSC_CTRL);
|
|
/* Add any TRIM needed for the crystal here.. */
|
|
/* Make sure to mux up to take the SoC 32k from the crystal */
|
|
writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL,
|
|
MCU_CTRL_DEVICE_CLKOUT_32K_CTRL);
|
|
}
|
|
#endif
|
|
|
|
#if IS_ENABLED(CONFIG_ENV_IS_IN_FAT) || IS_ENABLED(CONFIG_ENV_IS_IN_MMC)
|
|
int mmc_get_env_dev(void)
|
|
{
|
|
u32 boot_device = get_boot_device();
|
|
|
|
switch (boot_device) {
|
|
case BOOT_DEVICE_MMC1:
|
|
return 0;
|
|
case BOOT_DEVICE_MMC2:
|
|
return 1;
|
|
};
|
|
|
|
return CONFIG_SYS_MMC_ENV_DEV;
|
|
}
|
|
#endif
|
|
|
|
enum env_location env_get_location(enum env_operation op, int prio)
|
|
{
|
|
u32 boot_device = get_boot_device();
|
|
|
|
if (prio)
|
|
return ENVL_UNKNOWN;
|
|
|
|
switch (boot_device) {
|
|
case BOOT_DEVICE_MMC1:
|
|
case BOOT_DEVICE_MMC2:
|
|
if (CONFIG_IS_ENABLED(ENV_IS_IN_FAT))
|
|
return ENVL_FAT;
|
|
if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
|
|
return ENVL_MMC;
|
|
case BOOT_DEVICE_SPI:
|
|
if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
|
|
return ENVL_SPI_FLASH;
|
|
default:
|
|
return ENVL_NOWHERE;
|
|
};
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_BOARD_LATE_INIT)
|
|
int board_late_init(void)
|
|
{
|
|
u32 boot_device = get_boot_device();
|
|
|
|
switch (boot_device) {
|
|
case BOOT_DEVICE_MMC1:
|
|
env_set_ulong("mmcdev", 0);
|
|
env_set("boot", "mmc");
|
|
break;
|
|
case BOOT_DEVICE_MMC2:
|
|
env_set_ulong("mmcdev", 1);
|
|
env_set("boot", "mmc");
|
|
break;
|
|
case BOOT_DEVICE_SPI:
|
|
env_set("boot", "spi");
|
|
break;
|
|
case BOOT_DEVICE_ETHERNET:
|
|
env_set("boot", "net");
|
|
break;
|
|
};
|
|
|
|
return 0;
|
|
}
|
|
#endif
|