From 22075f787417662d5f5c74af3fb85aea61dbb86a Mon Sep 17 00:00:00 2001 From: Michal Orzel Date: Wed, 7 Sep 2022 13:08:51 +0200 Subject: scripts/common: Introduce phandle_next and get_next_phandle() When dealing with device trees, we need to have a solution to add custom phandles to the nodes we create/modify. Add a global variable phandle_next to act as a countdown counter starting with the highest valid phandle value 0xfffffffe. Add a new function get_next_phandle to get a value of the next available phandle and set it to a variable whose name is passed as a first argument. The global counter will be decremented with each call to this function. Signed-off-by: Michal Orzel Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- scripts/common | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'scripts') diff --git a/scripts/common b/scripts/common index 68938be..25c0412 100644 --- a/scripts/common +++ b/scripts/common @@ -13,6 +13,9 @@ tmp_files=() tmp_dirs=() +# Highest valid phandle. Will be decremented with each call to get_next_phandle +phandle_next="0xfffffffe" + function remove_tmp_files() { for i in "${tmp_files[@]}" @@ -26,6 +29,14 @@ function remove_tmp_files() done } +# Get next phandle and set it as a value (in hex) of a variable whose name is +# passed as a first argument. Decrement global counter phandle_next. +function get_next_phandle() +{ + eval "$1=$(printf "0x%x" $phandle_next)" + phandle_next=$(( $phandle_next - 1 )) +} + function sanity_check_partial_dts() { local domU_passthrough_path="$1" -- cgit v1.2.3