xref: /openbmc/u-boot/drivers/core/util.c (revision cbd2fba1)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  */
5 
6 #include <common.h>
7 #include <dm/ofnode.h>
8 #include <dm/util.h>
9 #include <linux/libfdt.h>
10 #include <vsprintf.h>
11 
12 #ifdef CONFIG_DM_WARN
13 void dm_warn(const char *fmt, ...)
14 {
15 	va_list args;
16 
17 	va_start(args, fmt);
18 	vprintf(fmt, args);
19 	va_end(args);
20 }
21 #endif
22 
23 int list_count_items(struct list_head *head)
24 {
25 	struct list_head *node;
26 	int count = 0;
27 
28 	list_for_each(node, head)
29 		count++;
30 
31 	return count;
32 }
33 
34 bool dm_fdt_pre_reloc(const void *blob, int offset)
35 {
36 	if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
37 		return true;
38 
39 #ifdef CONFIG_TPL_BUILD
40 	if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
41 		return true;
42 #elif defined(CONFIG_SPL_BUILD)
43 	if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL))
44 		return true;
45 #else
46 	/*
47 	 * In regular builds individual spl and tpl handling both
48 	 * count as handled pre-relocation for later second init.
49 	 */
50 	if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL) ||
51 	    fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
52 		return true;
53 #endif
54 
55 	return false;
56 }
57 
58 bool dm_ofnode_pre_reloc(ofnode node)
59 {
60 	if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
61 		return true;
62 
63 #ifdef CONFIG_TPL_BUILD
64 	if (ofnode_read_bool(node, "u-boot,dm-tpl"))
65 		return true;
66 #elif defined(CONFIG_SPL_BUILD)
67 	if (ofnode_read_bool(node, "u-boot,dm-spl"))
68 		return true;
69 #else
70 	/*
71 	 * In regular builds individual spl and tpl handling both
72 	 * count as handled pre-relocation for later second init.
73 	 */
74 	if (ofnode_read_bool(node, "u-boot,dm-spl") ||
75 	    ofnode_read_bool(node, "u-boot,dm-tpl"))
76 		return true;
77 #endif
78 
79 	return false;
80 }
81