[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ImageBuilder v2 1/2] scripts/common: Introduce phandle_next and get_next_phandle()


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Michal Orzel <michal.orzel@xxxxxxx>
  • Date: Wed, 7 Sep 2022 13:08:51 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=xhTkd5miWMsVyal32k/nHZOTb3M3/0B2WCe0WVn4U0U=; b=bLm4H3S+7fC1+ZcIQb7gfdxfJzGbk56Mv4V0uAhosM/TCy1lSi6G2Qnh151ETEGDdRNN+6X/VsM4lkthK7kiX8DmUXTAyVWTonG5x0fwJ+LUWlPBm/643cg34hXi4U4Zx9av2jYbX0E+NsDqhjsH26+eMmxbtib0VuhccQBOSfwX6XkAU5vXJPxsWG8SWakl81cDmRCJosVJbTC+2LaLz4eCkdjjvLJhpLqO8jll8riP6mhZO2SVTpYO9gn/vs3Y9iK/F2QFp+W7Hvnmhw9nZfJNRM/AnnhsBoztmAOZg3kASECCDE7BjUyZmdvGscryh1ySDjt3Rbx5SNVS2p/GoQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JIfasoA4HVCg6AlIBfmEbPry2okihsU3V8D7REGDUy6EUKZJDIIEX2m+ba7wtjlOGry6cX+BG1rCnupGSxMKhwDAz8ddNpNP/9Q3Z+b9nOp09O+GC19TlTTvcuCvMh9g0tErGxBginR/KKSyH/iZeXW10rStjTUVZgQ7En2SOOqRPcnwcOGPUhgfi08SakpaBEb8WMvtdM2+eMEymtKDAEhVhbmuFAeLBNO2b3V6yfxgkSlj19Z925y+BvaLANdEWByUmmXW53OBBN/szq1dcD5YHOXaHpzdkQQWWpEz2evXOKQQXx457GkZ5GwIHJmw5lLNDCyRcrmtAEfDQfGUkA==
  • Cc: <sstabellini@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>
  • Delivery-date: Wed, 07 Sep 2022 11:09:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 <michal.orzel@xxxxxxx>
---
To make the interface to phandle_next as simple as possible, we just
need a single function that will get us the next phandle and update the
global counter. That is why we cannot use the following:
- "phandle=$(get_next_phandle)" as a subshell cannot modify the environment
  of its parent shell,
- making use of return statement as it only works with values up to 255

The current solution with passing a variable name to a function that
will modify its value using eval is the simplest one and serves our purpose.

Changes in v2:
- new patch
---
 scripts/common | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/scripts/common b/scripts/common
index 68938beb8557..25c041270c29 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"
-- 
2.25.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.