devicetree: Add support for fixed-partitions

Add DT_NODE_BY_FIXED_PARTITION_LABEL that given a "label" in any
fixed-partitions map will return the node_id for that partition node.

Add DT_NODE_HAS_FIXED_PARTITION_LABEL that will test if a given
fixed-partitions "label" is valid.

Add DT_FIXED_PARTITION_ID that will return an unique ordinal value for
the partition give a node_id to the partition.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-05-06 20:54:29 -05:00 committed by Carles Cufí
commit bd97378870
4 changed files with 83 additions and 1 deletions

View file

@ -39,6 +39,8 @@ node-macro =/ %s"DT_N" path-id %s"_IRQ_IDX_" DIGIT
%s"_VAL_" dt-name [ %s"_EXISTS" ]
node-macro =/ %s"DT_N" path-id %s"_IRQ_NAME_" dt-name
%s"_VAL_" dt-name [ %s"_EXISTS" ]
; For fixed-partitions give a unique ordinal value for each partition */
node-macro =/ %s"DT_N" path-id %s"_PARTITION_ID" DIGIT
; Macros are generated for each of the node's compatibles.
node-macro =/ %s"DT_N" path-id %s"_COMPAT_MATCHES_" dt-name
; The node identifier for the node's parent in the devicetree.
@ -148,7 +150,8 @@ other-macro =/ %s"DT_CHOSEN_" dt-name
other-macro =/ %s"DT_COMPAT_" dt-name %s"_BUS_" dt-name
; #define DT_COMPAT_HAS_OKAY_vnd_dev 1
other-macro =/ %s"DT_COMPAT_HAS_OKAY_" dt-name
; Allows mapping a "label" property to a compatible node
other-macro =/ %s"DT_COMPAT_" dt-name %s"_LABEL" dt-name
; --------------------------------------------------------------------
; alternate-id: another way to specify a node besides a path-id
;

View file

@ -1585,6 +1585,7 @@
#include <devicetree/spi.h>
#include <devicetree/dma.h>
#include <devicetree/pwms.h>
#include <devicetree/fixed-partitions.h>
#include <devicetree/zephyr.h>
#endif /* DEVICETREE_H */

View file

@ -0,0 +1,57 @@
/**
* @file
* @brief Flash Devicetree macro public API header file.
*/
/*
* Copyright (c) 2020, Linaro Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_
#define ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup devicetree-fixed-partition Devicetree Fixed Partition API
* @ingroup devicetree
* @{
*/
/**
* @brief Get fixed partition with "label" property that matches label
* @param label lowercase-and-underscores value for "label" property
* @return a node identifier for the partition that matches label
*/
#define DT_NODE_BY_FIXED_PARTITION_LABEL(label) \
DT_CAT(DT_COMPAT_fixed_partitions_LABEL_, label)
/**
* @brief Test if a fixed partition with the "label" property exists
* @param label lowercase-and-underscores value for "label" property
* @return 1 if the label exists across all 'fixed-partitions' nodes
* 0 otherwise.
*/
#define DT_HAS_FIXED_PARTITION_LABEL(label) \
IS_ENABLED(DT_COMPAT_fixed_partitions_LABEL_##label##_EXISTS)
/**
* @brief 'fixed-partitions' ID
* @param node_id node identifier
* @return unique fixed partition id for given partition referenced by node_id
*/
#define DT_FIXED_PARTITION_ID(node_id) DT_CAT(node_id, _PARTITION_ID)
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_DEVICETREE_FIXED_PARTITION_H_ */

View file

@ -29,6 +29,7 @@ import edtlib
def main():
global header_file
global flash_area_num
args = parse_args()
@ -41,6 +42,8 @@ def main():
except edtlib.EDTError as e:
sys.exit(f"devicetree error: {e}")
flash_area_num = 0
# Save merged DTS source, as a debugging aid
with open(args.dts_out, "w", encoding="utf-8") as f:
print(edt.dts_source, file=f)
@ -254,6 +257,8 @@ def write_special_props(node):
# data cannot otherwise be obtained from write_vanilla_props()
# results
global flash_area_num
out_comment("Special property macros:")
# Macros that are special to the devicetree specification
@ -262,6 +267,10 @@ def write_special_props(node):
write_compatibles(node)
write_status(node)
if node.parent and "fixed-partitions" in node.parent.compats:
macro = f"{node.z_path_id}_PARTITION_ID"
out_dt_define(macro, flash_area_num)
flash_area_num += 1
def write_regs(node):
# reg property: edtlib knows the right #address-cells and
@ -586,6 +595,18 @@ def write_global_compat_info(edt):
" ".join(f"fn({edt.compat2nodes[compat].index(node)})"
for node in okay_nodes)
for compat, nodes in edt.compat2nodes.items():
for node in nodes:
if compat == "fixed-partitions":
for child in node.children.values():
if "label" in child.props:
label = child.props["label"].val
macro = f"COMPAT_{str2ident(compat)}_LABEL_{str2ident(label)}"
val = f"DT_{child.z_path_id}"
out_dt_define(macro, val)
out_dt_define(macro + "_EXISTS", 1)
out_comment('Macros for compatibles with status "okay" nodes\n')
for compat, okay_nodes in edt.compat2okay.items():
if okay_nodes: