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>
13 #include <linux/printk.h>
17 static void uniphier_set_env_fdt_file(void)
19 DECLARE_GLOBAL_DATA_PTR;
22 int buf_len = sizeof(dtb_name);
25 if (env_get("fdtfile"))
26 return; /* do nothing if it is already set */
28 compat = fdt_stringlist_get(gd->fdt_blob, 0, "compatible", 0, NULL);
32 /* rip off the vendor prefix "socionext," */
33 compat = strchr(compat, ',');
38 strncpy(dtb_name, compat, buf_len);
39 buf_len -= strlen(compat);
41 strncat(dtb_name, ".dtb", buf_len);
43 ret = env_set("fdtfile", dtb_name);
49 pr_warn("\"fdt_file\" environment variable was not set correctly\n");
52 static void uniphier_set_env_addr(const char *env, const char *offset_env)
54 DECLARE_GLOBAL_DATA_PTR;
55 unsigned long offset = 0;
61 return; /* do nothing if it is already set */
64 str = env_get(offset_env);
68 offset = simple_strtoul(str, &end, 16);
73 ret = env_set_hex(env, gd->ram_base + offset);
80 pr_warn("\"%s\" environment variable was not set correctly\n", env);
83 int board_late_init(void)
87 switch (uniphier_boot_device_raw()) {
88 case BOOT_DEVICE_MMC1:
90 env_set("bootdev", "emmc");
92 case BOOT_DEVICE_MMC2:
94 env_set("bootdev", "sd");
96 case BOOT_DEVICE_NAND:
98 env_set("bootdev", "nand");
100 case BOOT_DEVICE_NOR:
102 env_set("bootdev", "nor");
104 case BOOT_DEVICE_USB:
106 env_set("bootdev", "usb");
113 if (uniphier_have_internal_stm())
115 uniphier_boot_from_backend() ? "OFF" : "ON");
119 uniphier_set_env_fdt_file();
121 uniphier_set_env_addr("dram_base", NULL);
123 uniphier_set_env_addr("loadaddr", "loadaddr_offset");
125 uniphier_set_env_addr("kernel_addr_r", "kernel_addr_r_offset");
126 uniphier_set_env_addr("ramdisk_addr_r", "ramdisk_addr_r_offset");
127 uniphier_set_env_addr("fdt_addr_r", "fdt_addr_r_offset");