|
5 | 5 | # data coming from the devicetree for configurations using
|
6 | 6 | # a bootloader.
|
7 | 7 |
|
8 |
| -function(get_address_from_dt_partition_nodelabel label address) |
9 |
| - dt_nodelabel(partition_node TARGET ${DEFAULT_IMAGE} NODELABEL ${label} REQUIRED) |
10 |
| - dt_reg_addr(partition_offset TARGET ${DEFAULT_IMAGE} PATH ${partition_node}) |
| 8 | +function(_dt_get_parent node) |
| 9 | + string(FIND "${${node}}" "/" pos REVERSE) |
| 10 | + |
| 11 | + if(pos EQUAL -1) |
| 12 | + message(FATAL_ERROR "Unable to get parent of node: ${${node}}") |
| 13 | + endif() |
| 14 | + |
| 15 | + string(SUBSTRING "${${node}}" 0 ${pos} ${node}) |
| 16 | + set(${node} "${${node}}" PARENT_SCOPE) |
| 17 | +endfunction() |
| 18 | + |
| 19 | +# Usage: |
| 20 | +# dt_partition_addr(<var> [LABEL <label>|PATH <path>] [TARGET <target>] |
| 21 | +# [ABSOLUTE]) |
| 22 | +# |
| 23 | +# Get the partition address, based on the path or label. |
| 24 | +# The value will be returned in the <var> parameter. |
| 25 | +# The returned address is either relative to the memory controller, or absolute |
| 26 | +# if ABSOLUTE is specified. |
| 27 | +# |
| 28 | +# The <path> value may be any of these: |
| 29 | +# |
| 30 | +# - absolute path to a node, like '/foo/bar' |
| 31 | +# - a node alias, like 'my-alias' |
| 32 | +# - a node alias followed by a path to a child node, like 'my-alias/child-node' |
| 33 | +# |
| 34 | +# Results can be: |
| 35 | +# - The base address of the register block |
| 36 | +# - <var> will be undefined if node does not exists or does not have a register |
| 37 | +# block at the requested index or with the requested name |
| 38 | +# |
| 39 | +# <var> : Return variable where the address value will be stored |
| 40 | +# LABEL <label> : Node label |
| 41 | +# PATH <path> : Node path |
| 42 | +# TARGET <target>: Optional target to retrieve devicetree information from |
| 43 | +# ABSOLUTE : Return absolute address rather than address relative to |
| 44 | +# the memory controller |
| 45 | +# REQUIRED : Generate a fatal error if the node is not found |
| 46 | +function(dt_partition_addr var) |
| 47 | + cmake_parse_arguments(DT_PARTITION "ABSOLUTE;REQUIRED" "LABEL;PATH;TARGET" "" |
| 48 | + ${ARGN}) |
11 | 49 |
|
12 |
| - # Get the parent "two levels up" (../../) of the partition node |
13 |
| - # This is the partition flash area node |
14 |
| - string(REPLACE "/" ";" partition_node_split ${partition_node}) |
15 |
| - list(LENGTH partition_node_split child_path_length) |
16 |
| - math(EXPR parent_path_length "${child_path_length} - 2") |
17 |
| - list(SUBLIST partition_node_split 0 ${parent_path_length} parent_path_split) |
18 |
| - string(REPLACE ";" "/" flash_area_node "${parent_path_split}") |
| 50 | + if(NOT DT_PARTITION_PATH AND NOT DT_PARTITION_LABEL) |
| 51 | + message(FATAL_ERROR "dt_partition_addr: Either PATH or LABEL must be set") |
| 52 | + elseif(DT_PARTITION_PATH AND DT_PARTITION_LABEL) |
| 53 | + message(FATAL_ERROR "dt_partition_addr: Only one of PATH or LABEL can be set") |
| 54 | + elseif(NOT DT_PARTITION_PATH) |
| 55 | + dt_nodelabel(DT_PARTITION_PATH NODELABEL ${DT_PARTITION_LABEL} TARGET |
| 56 | + ${DT_PARTITION_TARGET}) |
| 57 | + if(NOT DEFINED DT_PARTITION_PATH) |
| 58 | + if(DT_PARTITION_REQUIRED) |
| 59 | + message(FATAL_ERROR |
| 60 | + "dt_partition_addr: Unable to find node with label: ${DT_PARTITION_LABEL}") |
| 61 | + else() |
| 62 | + set(${var} "" PARENT_SCOPE) |
| 63 | + return() |
| 64 | + endif() |
| 65 | + endif() |
| 66 | + else() |
| 67 | + dt_node_exists(DT_PARTITION_EXISTS PATH ${DT_PARTITION_PATH} TARGET |
| 68 | + ${DT_PARTITION_TARGET}) |
| 69 | + if(NOT DT_PARTITION_EXISTS) |
| 70 | + if(DT_PARTITION_REQUIRED) |
| 71 | + message(FATAL_ERROR |
| 72 | + "dt_partition_addr: Unable to find node with path: ${DT_PARTITION_PATH}") |
| 73 | + else() |
| 74 | + set(${var} "" PARENT_SCOPE) |
| 75 | + return() |
| 76 | + endif() |
| 77 | + endif() |
| 78 | + endif() |
19 | 79 |
|
20 |
| - dt_reg_addr(flash_area_addr TARGET ${DEFAULT_IMAGE} PATH ${flash_area_node}) |
| 80 | + # The "fixed-partition" as well as "fixed-subpartition" compatible is not set |
| 81 | + # in the CMake DTS nodes. The first node with the compatible property set is |
| 82 | + # the NVM driver/controller node. |
| 83 | + set(dt_partition_base_addr 0) |
| 84 | + set(dt_partition_parent "${DT_PARTITION_PATH}") |
| 85 | + dt_prop(compat PATH ${dt_partition_parent} PROPERTY compatible TARGET |
| 86 | + ${DT_PARTITION_TARGET}) |
| 87 | + while(DT_PARTITION_ABSOLUTE OR (NOT compat)) |
| 88 | + # If a node contains <reg> property, child node address is relative to this |
| 89 | + # node. |
| 90 | + dt_prop(reg PATH ${dt_partition_parent} PROPERTY reg TARGET |
| 91 | + ${DT_PARTITION_TARGET}) |
| 92 | + if(reg) |
| 93 | + dt_reg_addr(parent_addr PATH ${dt_partition_parent} TARGET |
| 94 | + ${DT_PARTITION_TARGET}) |
| 95 | + math(EXPR dt_partition_base_addr |
| 96 | + "${dt_partition_base_addr} + ${parent_addr}" OUTPUT_FORMAT HEXADECIMAL) |
| 97 | + endif() |
21 | 98 |
|
22 |
| - math(EXPR ${address} "${flash_area_addr} + ${partition_offset}") |
| 99 | + _dt_get_parent(dt_partition_parent) |
| 100 | + if("${dt_partition_parent}" STREQUAL "") |
| 101 | + break() |
| 102 | + endif() |
| 103 | + |
| 104 | + dt_prop(compat PATH ${dt_partition_parent} PROPERTY compatible TARGET |
| 105 | + ${DT_PARTITION_TARGET}) |
| 106 | + endwhile() |
| 107 | + |
| 108 | + set(${var} "${dt_partition_base_addr}" PARENT_SCOPE) |
| 109 | +endfunction() |
| 110 | + |
| 111 | +function(get_address_from_dt_partition_nodelabel label address) |
| 112 | + dt_partition_addr(${address} LABEL ${label} TARGET ${DEFAULT_IMAGE} ABSOLUTE |
| 113 | + REQUIRED) |
23 | 114 | set(${address} ${${address}} PARENT_SCOPE)
|
24 | 115 | endfunction()
|
0 commit comments