xref: /openbmc/u-boot/drivers/core/util.c (revision fd1e959e)
1 /*
2  * Copyright (c) 2013 Google, Inc
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 
7 #include <common.h>
8 #include <dm/util.h>
9 #include <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 #ifdef DEBUG
24 void dm_dbg(const char *fmt, ...)
25 {
26 	va_list args;
27 
28 	va_start(args, fmt);
29 	vprintf(fmt, args);
30 	va_end(args);
31 }
32 #endif
33 
34 int list_count_items(struct list_head *head)
35 {
36 	struct list_head *node;
37 	int count = 0;
38 
39 	list_for_each(node, head)
40 		count++;
41 
42 	return count;
43 }
44 
45 bool dm_fdt_pre_reloc(const void *blob, int offset)
46 {
47 	if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
48 		return true;
49 
50 #ifdef CONFIG_TPL_BUILD
51 	if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
52 		return true;
53 #elif defined(CONFIG_SPL_BUILD)
54 	if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL))
55 		return true;
56 #else
57 	/*
58 	 * In regular builds individual spl and tpl handling both
59 	 * count as handled pre-relocation for later second init.
60 	 */
61 	if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL) ||
62 	    fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
63 		return true;
64 #endif
65 
66 	return false;
67 }
68