From patchwork Wed Dec 23 15:11:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1420182 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=BxRuqkiz; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D1Gt74h0nz9sTX for ; Thu, 24 Dec 2020 02:13:03 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id BF181827D6; Wed, 23 Dec 2020 16:12:24 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="BxRuqkiz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F41AF82AE2; Wed, 23 Dec 2020 16:11:54 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 328F3827DB for ; Wed, 23 Dec 2020 16:11:51 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd36.google.com with SMTP id n4so15341370iow.12 for ; Wed, 23 Dec 2020 07:11:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zcpC630B4yWbn0lkvhIu3GYpoouAagYxzd+UWHRHRoU=; b=BxRuqkizjSIJRIab1Vjseek2yc5LwPVxIHP873IKjjnquOxXT8ATxEh93o2tL9GLYs j8yKa0BnYKuVNGqqVYU9zJhLv4npCU0/x1zzhhGfXaWD5XwIQzWb1Xo04KG4Ve9iruJE rXiOx5ulEH1BsHoZH2MjDr3MlT/8V2STtXTT4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zcpC630B4yWbn0lkvhIu3GYpoouAagYxzd+UWHRHRoU=; b=gxIlP4uA/1sp36Jrl5STGFzyvdXHXBDFR4+H6IVLoVmohq4ZHV5s29PPxPg+4f0Kih K9LFVeI2778N2K7UC75Z9WDfRufH5S1rYzf04DSajPhD17twU/ERuXrO8/cf71l4VXJD vjowrz4kfHdu5Ge6Pp9x/r+cmkucPElNlta0W9NI13FVijJlaAY3j5pgSyh36SPFvfGF dqrtrum3kZ4G/x+6JjfJ9Uk9nbgiJ95xJdyFNxM+fHB+VSxw+E1yYjHBposU5DNEbAVh yShE1KBwWmLvW7oWuRes9QTUmWGUN0D7lk4JGap7Zsbvn0/AHZNIIMuI8t9+eO0Qx5RT qWmQ== X-Gm-Message-State: AOAM533vKW5X7VQYKFskFyH819qRu+Mdo6bOxKsxmtiU3Egn4IxRtB7y 7iHxmQaoFkaFDMf9iilfzOOCArAc9Qr6gWpO X-Google-Smtp-Source: ABdhPJy+j2cLU1VTyU8S3smuNbhafeK3DIIb8OTZ5zhHTmqkaV5z2WJD5plguRRVm0CHWdE/zC7cfQ== X-Received: by 2002:a6b:d20d:: with SMTP id q13mr22021485iob.71.1608736309759; Wed, 23 Dec 2020 07:11:49 -0800 (PST) Received: from localhost.localdomain (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id c15sm16935667ils.87.2020.12.23.07.11.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 07:11:49 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass Subject: [PATCH v2 09/21] dtoc: Output the device in a separate function Date: Wed, 23 Dec 2020 08:11:21 -0700 Message-Id: <20201223081127.v2.9.I67c22b2d5a7917f9b2c74229dd4112c402248796@changeid> X-Mailer: git-send-email 2.29.2.729.g45daf8777d-goog In-Reply-To: <20201223151133.2205985-1-sjg@chromium.org> References: <20201223151133.2205985-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean Reduce the length of output_node() by moving the device-output functionality into a separate function. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- (no changes since v1) tools/dtoc/dtb_platdata.py | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 372f756037e..2d701ac24da 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -631,6 +631,27 @@ class DtbPlatdata(): self.buf(', '.join(vals[i:i + 8])) self.buf('}') + def _declare_device(self, var_name, struct_name, node_parent): + """Add a device declaration to the output + + This declares a U_BOOT_DEVICE() for the device being processed + + Args: + var_name (str): C name for the node + struct_name (str): Name for the dt struct associated with the node + node_parent (Node): Parent of the node (or None if none) + """ + self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) + self.buf('\t.name\t\t= "%s",\n' % struct_name) + self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) + self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) + idx = -1 + if node_parent and node_parent in self._valid_nodes: + idx = node_parent.idx + self.buf('\t.parent_idx\t= %d,\n' % idx) + self.buf('};\n') + self.buf('\n') + def output_node(self, node): """Output the C code for a node @@ -657,17 +678,7 @@ class DtbPlatdata(): self.buf(',\n') self.buf('};\n') - # Add a device declaration - self.buf('U_BOOT_DEVICE(%s) = {\n' % var_name) - self.buf('\t.name\t\t= "%s",\n' % struct_name) - self.buf('\t.plat\t= &%s%s,\n' % (VAL_PREFIX, var_name)) - self.buf('\t.plat_size\t= sizeof(%s%s),\n' % (VAL_PREFIX, var_name)) - idx = -1 - if node.parent and node.parent in self._valid_nodes: - idx = node.parent.idx - self.buf('\t.parent_idx\t= %d,\n' % idx) - self.buf('};\n') - self.buf('\n') + self._declare_device(var_name, struct_name, node.parent) self.out(''.join(self.get_buf()))