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>
11 #include <linux/libfdt.h>
15 #include <linux/printk.h>
19 static void uniphier_set_env_fdt_file(void)
21 DECLARE_GLOBAL_DATA_PTR;
24 int buf_len = sizeof(dtb_name);
27 if (env_get("fdtfile"))
28 return; /* do nothing if it is already set */
30 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
34 /* rip off the vendor prefix "socionext," */
35 compat = strchr(compat, ',');
40 strncpy(dtb_name, compat, buf_len);
41 buf_len -= strlen(compat);
43 strncat(dtb_name, ".dtb", buf_len);
45 ret = env_set("fdtfile", dtb_name);
51 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
54 static void uniphier_set_env_addr(const char *env, const char *offset_env)
56 unsigned long offset = 0;
62 return; /* do nothing if it is already set */
65 str = env_get(offset_env);
69 offset = simple_strtoul(str, &end, 16);
74 ret = env_set_hex(env, gd->ram_base + offset);
81 pr_warn("\"%s\" environment variable was not set correctly\n", env);
84 int board_late_init(void)
88 switch (uniphier_boot_device_raw()) {
89 case BOOT_DEVICE_MMC1:
91 env_set("bootdev", "emmc");
93 case BOOT_DEVICE_MMC2:
95 env_set("bootdev", "sd");
97 case BOOT_DEVICE_NAND:
99 env_set("bootdev", "nand");
101 case BOOT_DEVICE_NOR:
103 env_set("bootdev", "nor");
105 case BOOT_DEVICE_USB:
107 env_set("bootdev", "usb");
114 if (uniphier_have_internal_stm())
116 uniphier_boot_from_backend() ? "OFF" : "ON");
120 uniphier_set_env_fdt_file();
122 uniphier_set_env_addr("dram_base", NULL);
124 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
126 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
127 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
128 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");