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