From nobody Sun Feb 8 21:28:28 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1661523904; cv=none; d=zohomail.com; s=zohoarc; b=OBDXu6qyprLJLHA53rtPaQlizwX3cE5boAKA8r8N9TX/wrzq4AVPl/3hbG0VQznZBSbRZOxvTDkXlgjc3IX74BUkSQjKSqb245n/mn8iCJSNnopq/qECzhkuYzHevgUBOIPjQCUCd42d/sl9PlILMG5SbKSD7Qby9W41UntFsJk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1661523904; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=KRFx6V1DJCNRq8IcfTrxMaL3ZO8XkbM3yOTe5IXGOOU=; b=J8syaQ8e8voYmAOSJBHYDa0z3PM44oQzoyeViuJAZq7J3yQn2uxD8QCuJ4Qp+r8saP34Hnk2uPuC1MJ92domV8UBYNKgB6+lWGbGbEILGhR4N4Gqv7IWGOu00wboaWrMiCJOAQbZ4C6X4278eGFT8zmT01qs2KIf2OtB6VhVuEM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1661523904734241.50723693672694; Fri, 26 Aug 2022 07:25:04 -0700 (PDT) Received: from localhost ([::1]:50974 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oRaGd-00017q-FP for importer@patchew.org; Fri, 26 Aug 2022 10:25:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oRa4m-0008JJ-I7; Fri, 26 Aug 2022 10:12:49 -0400 Received: from mail-oa1-x31.google.com ([2001:4860:4864:20::31]:33530) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oRa4k-000448-UP; Fri, 26 Aug 2022 10:12:48 -0400 Received: by mail-oa1-x31.google.com with SMTP id 586e51a60fabf-11e8b592421so721725fac.0; Fri, 26 Aug 2022 07:12:46 -0700 (PDT) Received: from balboa.COMFAST ([177.189.45.98]) by smtp.gmail.com with ESMTPSA id z12-20020a056808064c00b00344aa3f17d9sm1087736oih.10.2022.08.26.07.12.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 07:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KRFx6V1DJCNRq8IcfTrxMaL3ZO8XkbM3yOTe5IXGOOU=; b=ONqB98y0jDUIm2Oz4L9XgCud9jicnRFnzYHW//IT1jGRUvBmnNTAAosXYHT3lofO5n F45jpVC+nvEZ5C24BiJLEsvqLK0Ay0seTHzDB4VNAxQ8SwjcVYvJfcQa1WcKIQYb56Q3 H2mCpyGU7FIXqfkLLY5JJJ6yNO6xMrIvg9AK6H0XoTssBwFborL1+nvpwK1092wZi1S/ O8Fl23CK3DNSgX/FLCrBa6e/RdCMszs+Ju0/OR1EK6bHgqXLpjySucCwzzz8JRNwk25w z0I0kZaJIk6xWPj3D5xCOc+zKmoypXx+jMbYWsK0t7YaZjF15zwr6PoJNG3EaexvoDqd h5lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KRFx6V1DJCNRq8IcfTrxMaL3ZO8XkbM3yOTe5IXGOOU=; b=6EkbGV5v3WM14BziRFkmeimhXXrI7OvDJqWMdgpJSJ93I1zgVJOod9f6bjSD8FBn9a 92Hon5Qo4ep3IQiAZjxpwl8Rjk1BP2Y1QQCFnlt9jEeBw6oZ6Z7oQeSLY+xtV3E0MWos 9J3y1dWOB9tSu9GVzCqriyw4z3SK52R1yTupw3VAydrexUa9HqaeduMjIqdDWRgISf1Q miomJWxBqNRt/Y7YvOHe4HPB54KwAiKvenL4sphuzFRpSsXwrHEdbU4m9dH7x9FRzbhG zZ4D55Owu3Q50LBi0y0e6sVaE0HGopT1u3L0YCpyR0NXCpL34nTSAWqBBFeBMY5kdtAr nkzA== X-Gm-Message-State: ACgBeo0csd05hx5f5ZrUosnmst59rKk0K+fYCfil86aOfqfZrjpJV9zt aikfnZVEAApwHIrcTm08RnovnTOXvDw= X-Google-Smtp-Source: AA6agR6H71FXi7WTl+H34U8K+h1G1CiM319An9q4JUA63//sftXxoQC1dNcT7GmNYglegMx8FqRcJw== X-Received: by 2002:a05:6870:2488:b0:10c:3362:17ff with SMTP id s8-20020a056870248800b0010c336217ffmr1860749oaq.33.1661523165730; Fri, 26 Aug 2022 07:12:45 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au, alistair.francis@wdc.com, Daniel Henrique Barboza Subject: [PATCH for-7.2 v4 17/21] device_tree.c: support remaining FDT prop types Date: Fri, 26 Aug 2022 11:11:46 -0300 Message-Id: <20220826141150.7201-18-danielhb413@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220826141150.7201-1-danielhb413@gmail.com> References: <20220826141150.7201-1-danielhb413@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:4860:4864:20::31; envelope-from=danielhb413@gmail.com; helo=mail-oa1-x31.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1661523906657100001 Content-Type: text/plain; charset="utf-8" When printing a blob with 'dtc' using the '-O dts' option there are 3 distinct data types being printed: strings, arrays of uint32s and regular byte arrays. Previous patch added support to print strings. Let's add the remaining formats. We want to resemble the format that 'dtc -O dts' uses, so every uint32 array uses angle brackets (<>), and regular byte array uses square brackets ([]). For properties that has no values we keep printing just its name. The /chosen FDT node from the pSeris machine gives an example of all property types 'info fdt' is now able to display: (qemu) info fdt /chosen chosen { ibm,architecture-vec-5 =3D [00 00]; rng-seed =3D <0x9cf5071b 0xf8804213 0xbe797764 0xad3d955 0xe0c9637 0x1f= 99c61e 0xe9243741 0xe800f17d>; ibm,arch-vec-5-platform-support =3D <0x178018c0 0x19001a40>; linux,pci-probe-only =3D <0x0>; stdout-path =3D "/vdevice/vty@71000000"; linux,stdout-path =3D "/vdevice/vty@71000000"; qemu,graphic-depth =3D <0x20>; qemu,graphic-height =3D <0x258>; qemu,graphic-width =3D <0x320>; } Signed-off-by: Daniel Henrique Barboza --- softmmu/device_tree.c | 57 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c index 3e38d9ddad..a770c6c1cc 100644 --- a/softmmu/device_tree.c +++ b/softmmu/device_tree.c @@ -720,6 +720,52 @@ static void fdt_prop_format_string_array(GString *buf, g_string_append_printf(buf, ";\n"); } =20 +static bool fdt_prop_is_uint32_array(int size) +{ + return size % 4 =3D=3D 0; +} + +static void fdt_prop_format_uint32_array(GString *buf, + const char *propname, + const void *data, + int prop_size, int padding) +{ + const fdt32_t *array =3D data; + int array_len =3D prop_size / 4; + int i; + + g_string_append_printf(buf, "%*s%s =3D <", padding, "", propname); + + for (i =3D 0; i < array_len; i++) { + g_string_append_printf(buf, "0x%" PRIx32, fdt32_to_cpu(array[i])); + + if (i < array_len - 1) { + g_string_append_printf(buf, " "); + } + } + + g_string_append_printf(buf, ">;\n"); +} + +static void fdt_prop_format_val(GString *buf, const char *propname, + const void *data, int prop_size, + int padding) +{ + const char *val =3D data; + int i; + + g_string_append_printf(buf, "%*s%s =3D [", padding, "", propname); + + for (i =3D 0; i < prop_size; i++) { + g_string_append_printf(buf, "%02x", val[i]); + if (i < prop_size - 1) { + g_string_append_printf(buf, " "); + } + } + + g_string_append_printf(buf, "];\n"); +} + static void fdt_format_node(GString *buf, int node, int depth) { const struct fdt_property *prop =3D NULL; @@ -738,11 +784,20 @@ static void fdt_format_node(GString *buf, int node, i= nt depth) prop =3D fdt_get_property_by_offset(fdt, property, &prop_size); propname =3D fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); =20 + if (prop_size =3D=3D 0) { + g_string_append_printf(buf, "%*s%s;\n", padding, "", propname); + continue; + } + if (fdt_prop_is_string_array(prop->data, prop_size)) { fdt_prop_format_string_array(buf, propname, prop->data, prop_size, padding); + } else if (fdt_prop_is_uint32_array(prop_size)) { + fdt_prop_format_uint32_array(buf, propname, prop->data, prop_s= ize, + padding); } else { - g_string_append_printf(buf, "%*s%s;\n", padding, "", propname); + fdt_prop_format_val(buf, propname, prop->data, + prop_size, padding); } } =20 --=20 2.37.2