blob: 8bf9c9c67d38308552b79b3ebb1968752db8368e [file] [log] [blame]
Jagan Teki30edf402021-03-16 21:52:03 +05301// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
2/*
3 * Copyright (C) 2018, STMicroelectronics - All Rights Reserved
4 * Copyright (C) 2020 Engicam S.r.l.
5 * Copyright (C) 2020 Amarula Solutions(India)
6 * Author: Jagan Teki <jagan@amarulasolutions.com>
7 */
8
9#include <common.h>
10#include <env.h>
11#include <env_internal.h>
12#include <syscon.h>
13#include <asm/io.h>
14#include <asm/arch/sys_proto.h>
15#include <power/regulator.h>
16
17DECLARE_GLOBAL_DATA_PTR;
18
19int checkboard(void)
20{
21 char *mode;
22 const char *fdt_compat;
23 int fdt_compat_len;
24
25 if (IS_ENABLED(CONFIG_TFABOOT))
26 mode = "trusted";
27 else
28 mode = "basic";
29
30 printf("Board: stm32mp1 in %s mode", mode);
31 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
32 &fdt_compat_len);
33 if (fdt_compat && fdt_compat_len)
34 printf(" (%s)", fdt_compat);
35 puts("\n");
36
37 return 0;
38}
39
40/* board dependent setup after realloc */
41int board_init(void)
42{
43 /* address of boot parameters */
44 gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100;
45
46 if (IS_ENABLED(CONFIG_DM_REGULATOR))
47 regulators_enable_boot_on(_DEBUG);
48
49 return 0;
50}
51
52int board_late_init(void)
53{
54 return 0;
55}
56
57enum env_location env_get_location(enum env_operation op, int prio)
58{
59 u32 bootmode = get_bootmode();
60
61 if (prio)
62 return ENVL_UNKNOWN;
63
64 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
65 case BOOT_FLASH_SD:
66 case BOOT_FLASH_EMMC:
67 if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
68 return ENVL_MMC;
69 else if (CONFIG_IS_ENABLED(ENV_IS_IN_EXT4))
70 return ENVL_EXT4;
71 else
72 return ENVL_NOWHERE;
73
74 case BOOT_FLASH_NAND:
75 case BOOT_FLASH_SPINAND:
76 if (CONFIG_IS_ENABLED(ENV_IS_IN_UBI))
77 return ENVL_UBI;
78 else
79 return ENVL_NOWHERE;
80
81 case BOOT_FLASH_NOR:
82 if (CONFIG_IS_ENABLED(ENV_IS_IN_SPI_FLASH))
83 return ENVL_SPI_FLASH;
84 else
85 return ENVL_NOWHERE;
86
87 default:
88 return ENVL_NOWHERE;
89 }
90}
91
92const char *env_ext4_get_intf(void)
93{
94 u32 bootmode = get_bootmode();
95
96 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
97 case BOOT_FLASH_SD:
98 case BOOT_FLASH_EMMC:
99 return "mmc";
100 default:
101 return "";
102 }
103}
104
105const char *env_ext4_get_dev_part(void)
106{
107 static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"};
108 u32 bootmode = get_bootmode();
109
110 return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1];
111}
112
113int mmc_get_env_dev(void)
114{
115 u32 bootmode = get_bootmode();
116
117 return (bootmode & TAMP_BOOT_INSTANCE_MASK) - 1;
118}
119
120#if defined(CONFIG_OF_BOARD_SETUP)
121int ft_board_setup(void *blob, struct bd_info *bd)
122{
123 return 0;
124}
125#endif