blob: 451d4766d08c7a9db25da13f54f9fa6af52ede1d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassdd6ab882014-02-26 15:59:18 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glassdd6ab882014-02-26 15:59:18 -07004 */
5
6#include <common.h>
Masahiro Yamada3247fdb2017-06-22 16:50:01 +09007#include <dm/util.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09008#include <linux/libfdt.h>
Simon Glassdd6ab882014-02-26 15:59:18 -07009#include <vsprintf.h>
10
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090011#ifdef CONFIG_DM_WARN
Simon Glassdd6ab882014-02-26 15:59:18 -070012void 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}
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090020#endif
Simon Glassdd6ab882014-02-26 15:59:18 -070021
Simon Glassdd6ab882014-02-26 15:59:18 -070022int 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}
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010032
Heiko Stübner20f938a2017-02-23 17:30:38 +010033bool dm_fdt_pre_reloc(const void *blob, int offset)
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010034{
35 if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010036 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010037
38#ifdef CONFIG_TPL_BUILD
39 if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010040 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010041#elif defined(CONFIG_SPL_BUILD)
42 if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL))
Heiko Stübner20f938a2017-02-23 17:30:38 +010043 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010044#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))
Heiko Stübner20f938a2017-02-23 17:30:38 +010051 return true;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010052#endif
53
Heiko Stübner20f938a2017-02-23 17:30:38 +010054 return false;
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010055}