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