blob: c97a7efff46e9fe9c8d966ab2b5621354a94a893 [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>
9#include <env.h>
10#include <fdt_support.h>
11#include <asm/global_data.h>
12#include <asm/arch/sys_proto.h>
13
14/*
15 * Get a global data pointer
16 */
17DECLARE_GLOBAL_DATA_PTR;
18
19/* board dependent setup after realloc */
20int board_init(void)
21{
22 return 0;
23}
24
25int board_late_init(void)
26{
27 const void *fdt_compat;
28 int fdt_compat_len;
29 char dtb_name[256];
30 int buf_len;
31
32 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
33 fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible",
34 &fdt_compat_len);
35 if (fdt_compat && fdt_compat_len) {
36 if (strncmp(fdt_compat, "st,", 3) != 0) {
37 env_set("board_name", fdt_compat);
38 } else {
39 env_set("board_name", fdt_compat + 3);
40
41 buf_len = sizeof(dtb_name);
42 strlcpy(dtb_name, fdt_compat + 3, buf_len);
43 buf_len -= strlen(fdt_compat + 3);
44 strlcat(dtb_name, ".dtb", buf_len);
45 env_set("fdtfile", dtb_name);
46 }
47 }
48 }
49
50 return 0;
51}