blob: 2e232d57a14fac2db666586beb82796db241c2d1 [file] [log] [blame]
Simon Glassdd6ab882014-02-26 15:59:18 -07001/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
Masahiro Yamada3247fdb2017-06-22 16:50:01 +09008#include <dm/util.h>
Heiko Stübner9a2cdca2017-02-18 19:46:21 +01009#include <libfdt.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070010#include <vsprintf.h>
11
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090012#ifdef CONFIG_DM_WARN
Simon Glassdd6ab882014-02-26 15:59:18 -070013void 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}
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090021#endif
Simon Glassdd6ab882014-02-26 15:59:18 -070022
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090023#ifdef DEBUG
Simon Glassdd6ab882014-02-26 15:59:18 -070024void 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}
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090032#endif
Simon Glassdd6ab882014-02-26 15:59:18 -070033
34int 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}
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010044
Heiko Stübner20f938a2017-02-23 17:30:38 +010045bool dm_fdt_pre_reloc(const void *blob, int offset)
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010046{
47 if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010048 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010049
50#ifdef CONFIG_TPL_BUILD
51 if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010052 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010053#elif defined(CONFIG_SPL_BUILD)
54 if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010055 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010056#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))
Heiko Stübner20f938a2017-02-23 17:30:38 +010063 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010064#endif
65
Heiko Stübner20f938a2017-02-23 17:30:38 +010066 return false;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010067}