From patchwork Sat Aug 26 09:06:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 717226 Delivered-To: patch@linaro.org Received: by 2002:a5d:688a:0:b0:317:ecd7:513f with SMTP id h10csp294570wru; Sat, 26 Aug 2023 02:07:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzxchvA88S1A5j8kTOCm02LidIUHBJMQUsoUG4oNdy/WB2asQmWbGDnT8/nT7kQHsOFizh X-Received: by 2002:a5d:5962:0:b0:319:7b96:a1be with SMTP id e34-20020a5d5962000000b003197b96a1bemr13350631wri.71.1693040832970; Sat, 26 Aug 2023 02:07:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693040832; cv=none; d=google.com; s=arc-20160816; b=W/258QNsL8zn4L3O1KwoxTENgzImjvwA0tYVVzvjVmOhnkg4LR6D1DQ3ALAh7zKBEE ICms+IBgKYr7bjBIAvfl9ygdPLto3VtG/YaxvieUSW6VUxYx2RtYyNzkA+E9Ejzs6oQf 7oS0VCdhqp0paivD2P+xZjXCs+0s7jfDle+YmlL7WfqwWbHGb3ekDemkr3+GufAkLK8r /JGTZAKMVE4lEcLXh20qZ3AWNSHvZPtgeqoTn1ZSOeAOB0pQ9wmoF+uXpSwtVUiUDd9J IQTIfC8Oz1cazu4FIIgXwynvWDrvhNwjDA1dL7gMYrv0HHsjvvzEvFjYxqNhYuYTYonW I0jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=Z3RaWYCJ15ExbeJgcomqg04ddmCR4hNpzkwCZ5lmKiY=; fh=wxXZJCQRz/XgBTfKhuJFfNV+eZ/MzU8zncY23uTJ9bU=; b=g/gHkbPHRInG2jzb5McDn0G39zkfig1jQ/nIu1sXtXMusDIh507mcZCxNVbaQj0d1Q +jH71VfF17Q1vZP1qQPGqbzwZDjt/L2x7i+E4xPl7nZC81ezmJF4ruKZ3UB1K+M1e8nY s4dCSw26UIIaeyK/+SzpnGMN5iwGkpPgZZ42AFWeMyGCHwKAQnxg68W7/GBj2iCptsI/ WuUG1VNtI3Lw8ZYpQu73O4prbWLEi9IcEY9aN6EFsFRqJvOvUh7sZHcKljf/HWhUIh0E hr/g88tERU+TCY7sgftI05RxOJguRAT5/0VtO8E7ahAvFAjZ4mZDUlbHCOoYguC50Umt PO3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id j18-20020adfea52000000b0031986aa2a8dsi513614wrn.961.2023.08.26.02.07.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 02:07:12 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EEF7D86B3A; Sat, 26 Aug 2023 11:07:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id EA32886B37; Sat, 26 Aug 2023 11:07:05 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 1C4D186B19 for ; Sat, 26 Aug 2023 11:07:03 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 906E11FB; Sat, 26 Aug 2023 02:07:42 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.46.7]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4B2A73F740; Sat, 26 Aug 2023 02:07:00 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Tom Rini , Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Sughosh Ganu Subject: [RFC PATCH 1/5] dt: Provide a way to remove non-compliant nodes and properties Date: Sat, 26 Aug 2023 14:36:29 +0530 Message-Id: <20230826090633.239342-2-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230826090633.239342-1-sughosh.ganu@linaro.org> References: <20230826090633.239342-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean Add a function which is registered to spy for a EVT_FT_FIXUP event, and removes the non upstreamed nodes and properties from the devicetree before it gets passed to the OS. This allows removing entire nodes, or specific properties under nodes from the devicetree. The required nodes and properties can be registered for removal through the DT_NON_COMPLIANT_PURGE and DT_NON_COMPLIANT_PURGE_LIST macros. Signed-off-by: Sughosh Ganu --- include/dt-structs.h | 11 +++++++ lib/Makefile | 1 + lib/dt_purge.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 lib/dt_purge.c diff --git a/include/dt-structs.h b/include/dt-structs.h index fa1622cb1d..f535c60471 100644 --- a/include/dt-structs.h +++ b/include/dt-structs.h @@ -57,3 +57,14 @@ struct phandle_2_arg { #endif #endif + +struct dt_non_compliant_purge { + const char *node_path; + const char *prop; +}; + +#define DT_NON_COMPLIANT_PURGE(__name) \ + ll_entry_declare(struct dt_non_compliant_purge, __name, dt_purge) + +#define DT_NON_COMPLIANT_PURGE_LIST(__name) \ + ll_entry_declare_list(struct dt_non_compliant_purge, __name, dt_purge) diff --git a/lib/Makefile b/lib/Makefile index 8d8ccc8bbc..82a906daa0 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -37,6 +37,7 @@ endif obj-y += crc8.o obj-y += crc16.o obj-y += crc16-ccitt.o +obj-y += dt_purge.o obj-$(CONFIG_ERRNO_STR) += errno_str.o obj-$(CONFIG_FIT) += fdtdec_common.o obj-$(CONFIG_TEST_FDTDEC) += fdtdec_test.o diff --git a/lib/dt_purge.c b/lib/dt_purge.c new file mode 100644 index 0000000000..f893ba9796 --- /dev/null +++ b/lib/dt_purge.c @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2023, Linaro Limited + */ + +#include +#include +#include + +#include + +/** + * dt_non_compliant_purge() - Remove non-upstreamed nodes and properties + * from the DT + * @ctx: Context for event + * @event: Event to process + * + * Iterate through an array of DT nodes and properties, and remove them + * from the device-tree before the DT gets handed over to the kernel. + * These are nodes and properties which do not have upstream bindings + * and need to be purged before being handed over to the kernel. + * + * If both the node and property are specified, delete the property. If + * only the node is specified, delete the entire node, including it's + * subnodes, if any. + * + * Return: 0 if OK, -ve on error + */ +static int dt_non_compliant_purge(void *ctx, struct event *event) +{ + int nodeoff = 0; + int err = 0; + void *fdt; + const struct event_ft_fixup *fixup = &event->data.ft_fixup; + struct dt_non_compliant_purge *purge_entry; + struct dt_non_compliant_purge *purge_start = + ll_entry_start(struct dt_non_compliant_purge, dt_purge); + int nentries = ll_entry_count(struct dt_non_compliant_purge, dt_purge); + + if (fixup->images) + return 0; + + fdt = fixup->tree.fdt; + for (purge_entry = purge_start; purge_entry != purge_start + nentries; + purge_entry++) { + nodeoff = fdt_path_offset(fdt, purge_entry->node_path); + if (nodeoff < 0) { + log_debug("Error (%d) getting node offset for %s\n", + nodeoff, purge_entry->node_path); + continue; + } + + if (purge_entry->prop) { + err = fdt_delprop(fdt, nodeoff, purge_entry->prop); + if (err < 0 && err != -FDT_ERR_NOTFOUND) { + log_debug("Error (%d) deleting %s\n", + err, purge_entry->prop); + goto out; + } + } else { + err = fdt_del_node(fdt, nodeoff); + if (err) { + log_debug("Error (%d) trying to delete node %s\n", + err, purge_entry->node_path); + goto out; + } + } + } + +out: + return err; +} +EVENT_SPY(EVT_FT_FIXUP, dt_non_compliant_purge);