1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014 Panasonic Corporation
4 * Copyright (C) 2015-2016 Socionext Inc.
5 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
12 #include <linux/libfdt.h>
16 #include <linux/printk.h>
20 static void uniphier_set_env_fdt_file(void)
22 DECLARE_GLOBAL_DATA_PTR;
25 int buf_len = sizeof(dtb_name);
28 if (env_get("fdtfile"))
29 return; /* do nothing if it is already set */
31 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
35 /* rip off the vendor prefix "socionext," */
36 compat = strchr(compat, ',');
41 strncpy(dtb_name, compat, buf_len);
42 buf_len -= strlen(compat);
44 strncat(dtb_name, ".dtb", buf_len);
46 ret = env_set("fdtfile", dtb_name);
52 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
55 static void uniphier_set_env_addr(const char *env, const char *offset_env)
57 unsigned long offset = 0;
63 return; /* do nothing if it is already set */
66 str = env_get(offset_env);
70 offset = simple_strtoul(str, &end, 16);
75 ret = env_set_hex(env, gd->ram_base + offset);
82 pr_warn("\"%s\" environment variable was not set correctly\n", env);
85 int board_late_init(void)
89 switch (uniphier_boot_device_raw()) {
90 case BOOT_DEVICE_MMC1:
92 env_set("bootdev", "emmc");
94 case BOOT_DEVICE_MMC2:
96 env_set("bootdev", "sd");
98 case BOOT_DEVICE_NAND:
100 env_set("bootdev", "nand");
102 case BOOT_DEVICE_NOR:
104 env_set("bootdev", "nor");
106 case BOOT_DEVICE_USB:
108 env_set("bootdev", "usb");
115 if (uniphier_have_internal_stm())
117 uniphier_boot_from_backend() ? "OFF" : "ON");
121 uniphier_set_env_fdt_file();
123 uniphier_set_env_addr("dram_base", NULL);
125 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
127 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
128 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
129 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");