blob: c70ffaf5dbdc8284070014735482b2bb8813a326 [file] [log] [blame]
Patrice Chotardd29531c2023-10-27 16:43:04 +02001// SPDX-License-Identifier: GPL-2.0-or-later OR BSD-3-Clause
2/*
3 * Copyright (C) 2023, STMicroelectronics - All Rights Reserved
4 */
5
6#define LOG_CATEGORY LOGC_BOARD
7
Patrice Chotardd29531c2023-10-27 16:43:04 +02008#include <config.h>
Patrice Chotard0f77af62025-04-01 18:08:44 +02009#include <env_internal.h>
Patrice Chotardd29531c2023-10-27 16:43:04 +020010#include <fdt_support.h>
Patrick Delaunayd7b448f2024-01-15 15:05:54 +010011#include <log.h>
Patrick Delaunay300cb922024-01-15 15:05:55 +010012#include <misc.h>
Patrice Chotardd29531c2023-10-27 16:43:04 +020013#include <asm/global_data.h>
14#include <asm/arch/sys_proto.h>
Patrick Delaunay300cb922024-01-15 15:05:55 +010015#include <dm/device.h>
Patrick Delaunayd7b448f2024-01-15 15:05:54 +010016#include <dm/ofnode.h>
Patrick Delaunay300cb922024-01-15 15:05:55 +010017#include <dm/uclass.h>
Patrice Chotardd29531c2023-10-27 16:43:04 +020018
19/*
20 * Get a global data pointer
21 */
22DECLARE_GLOBAL_DATA_PTR;
23
Patrick Delaunayd7b448f2024-01-15 15:05:54 +010024int checkboard(void)
25{
Patrick Delaunay300cb922024-01-15 15:05:55 +010026 int ret;
27 u32 otp;
28 struct udevice *dev;
Patrick Delaunayd7b448f2024-01-15 15:05:54 +010029 const char *fdt_compat;
30 int fdt_compat_len;
31
32 fdt_compat = ofnode_get_property(ofnode_root(), "compatible", &fdt_compat_len);
33
34 log_info("Board: stm32mp2 (%s)\n", fdt_compat && fdt_compat_len ? fdt_compat : "");
35
Patrick Delaunay300cb922024-01-15 15:05:55 +010036 /* display the STMicroelectronics board identification */
37 if (CONFIG_IS_ENABLED(CMD_STBOARD)) {
38 ret = uclass_get_device_by_driver(UCLASS_MISC,
39 DM_DRIVER_GET(stm32mp_bsec),
40 &dev);
41 if (!ret)
42 ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD),
43 &otp, sizeof(otp));
44 if (ret > 0 && otp)
45 log_info("Board: MB%04x Var%d.%d Rev.%c-%02d\n",
46 otp >> 16,
47 (otp >> 12) & 0xF,
48 (otp >> 4) & 0xF,
49 ((otp >> 8) & 0xF) - 1 + 'A',
50 otp & 0xF);
51 }
52
Patrick Delaunayd7b448f2024-01-15 15:05:54 +010053 return 0;
54}
55
Patrice Chotardd29531c2023-10-27 16:43:04 +020056/* board dependent setup after realloc */
57int board_init(void)
58{
59 return 0;
60}
61
Patrice Chotard0f77af62025-04-01 18:08:44 +020062enum env_location env_get_location(enum env_operation op, int prio)
63{
64 u32 bootmode = get_bootmode();
65
66 if (prio)
67 return ENVL_UNKNOWN;
68
69 switch (bootmode & TAMP_BOOT_DEVICE_MASK) {
70 case BOOT_FLASH_SD:
71 case BOOT_FLASH_EMMC:
72 if (CONFIG_IS_ENABLED(ENV_IS_IN_MMC))
73 return ENVL_MMC;
74 else
75 return ENVL_NOWHERE;
76 default:
77 return ENVL_NOWHERE;
78 }
79}
80
Patrice Chotardd29531c2023-10-27 16:43:04 +020081int board_late_init(void)
82{
83 const void *fdt_compat;
84 int fdt_compat_len;
85 char dtb_name[256];
86 int buf_len;
87
88 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
89 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
90 &fdt_compat_len);
91 if (fdt_compat && fdt_compat_len) {
92 if (strncmp(fdt_compat, "st,", 3) != 0) {
93 env_set("board_name", fdt_compat);
94 } else {
95 env_set("board_name", fdt_compat + 3);
96
97 buf_len = sizeof(dtb_name);
98 strlcpy(dtb_name, fdt_compat + 3, buf_len);
99 buf_len -= strlen(fdt_compat + 3);
100 strlcat(dtb_name, ".dtb", buf_len);
101 env_set("fdtfile", dtb_name);
102 }
103 }
104 }
105
106 return 0;
107}