Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 7 | #include <dm/ofnode.h> |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 8 | #include <dm/util.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 9 | #include <linux/libfdt.h> |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 10 | #include <vsprintf.h> |
| 11 | |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 12 | #ifdef CONFIG_DM_WARN |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 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 | } |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 21 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 22 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 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 | } |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 33 | |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 34 | bool dm_fdt_pre_reloc(const void *blob, int offset) |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 35 | { |
| 36 | if (fdt_getprop(blob, offset, "u-boot,dm-pre-reloc", NULL)) |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 37 | return true; |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 38 | |
| 39 | #ifdef CONFIG_TPL_BUILD |
| 40 | if (fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL)) |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 41 | return true; |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 42 | #elif defined(CONFIG_SPL_BUILD) |
| 43 | if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL)) |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 44 | return true; |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 45 | #else |
| 46 | /* |
| 47 | * In regular builds individual spl and tpl handling both |
| 48 | * count as handled pre-relocation for later second init. |
| 49 | */ |
| 50 | if (fdt_getprop(blob, offset, "u-boot,dm-spl", NULL) || |
| 51 | fdt_getprop(blob, offset, "u-boot,dm-tpl", NULL)) |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 52 | return true; |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 53 | #endif |
| 54 | |
Heiko Stübner | 20f938a | 2017-02-23 17:30:38 +0100 | [diff] [blame] | 55 | return false; |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 56 | } |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 57 | |
| 58 | bool dm_ofnode_pre_reloc(ofnode node) |
| 59 | { |
| 60 | if (ofnode_read_bool(node, "u-boot,dm-pre-reloc")) |
| 61 | return true; |
| 62 | |
| 63 | #ifdef CONFIG_TPL_BUILD |
| 64 | if (ofnode_read_bool(node, "u-boot,dm-tpl")) |
| 65 | return true; |
| 66 | #elif defined(CONFIG_SPL_BUILD) |
| 67 | if (ofnode_read_bool(node, "u-boot,dm-spl")) |
| 68 | return true; |
| 69 | #else |
| 70 | /* |
| 71 | * In regular builds individual spl and tpl handling both |
| 72 | * count as handled pre-relocation for later second init. |
| 73 | */ |
| 74 | if (ofnode_read_bool(node, "u-boot,dm-spl") || |
| 75 | ofnode_read_bool(node, "u-boot,dm-tpl")) |
| 76 | return true; |
| 77 | #endif |
| 78 | |
| 79 | return false; |
| 80 | } |