fdt: Remove duplicate code
[oweals/u-boot.git] / drivers / core / util.c
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 defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD)
37         /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass
38          * had property dm-pre-reloc or u-boot,dm-spl/tpl.
39          * They are removed in final dtb (fdtgrep 2nd pass)
40          */
41         return true;
42 #else
43         if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
44                 return true;
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
57 bool dm_ofnode_pre_reloc(ofnode node)
58 {
59 #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD)
60         /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass
61          * had property dm-pre-reloc or u-boot,dm-spl/tpl.
62          * They are removed in final dtb (fdtgrep 2nd pass)
63          */
64         return true;
65 #else
66         if (ofnode_read_bool(node, "u-boot,dm-pre-reloc"))
67                 return true;
68
69         /*
70          * In regular builds individual spl and tpl handling both
71          * count as handled pre-relocation for later second init.
72          */
73         if (ofnode_read_bool(node, "u-boot,dm-spl") ||
74             ofnode_read_bool(node, "u-boot,dm-tpl"))
75                 return true;
76
77         return false;
78 #endif
79 }