Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD56FC7EE23 for ; Thu, 1 Jun 2023 16:28:58 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2FEF0863A5; Thu, 1 Jun 2023 18:25:33 +0200 (CEST) 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="BhuFxU41"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AC5C986345; Thu, 1 Jun 2023 18:24:56 +0200 (CEST) Received: from mail-il1-x135.google.com (mail-il1-x135.google.com [IPv6:2607:f8b0:4864:20::135]) (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 E1C1586369 for ; Thu, 1 Jun 2023 18:24:51 +0200 (CEST) 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-il1-x135.google.com with SMTP id e9e14a558f8ab-33b04c8f3eeso3396415ab.0 for ; Thu, 01 Jun 2023 09:24:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1685636681; x=1688228681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Y3odaVOEX2pog6bi/3962/fOAXLWFyJ4XUjMBeBtFWk=; b=BhuFxU41AqUcusprAjL3RNjvWM02yi70+39QOXY1djyExVtM8w3LWD7DNZ/EBVr3Ez bnVJZpP6eZQpu9LEtXO773dX1j8gTg7Jhf69YT6WsYvtf62V96VUaiL3yCJNhza3pszI ORv6YXzhkj/f7BZakaaZZ6P6dsHgaeAy8OboQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685636681; x=1688228681; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Y3odaVOEX2pog6bi/3962/fOAXLWFyJ4XUjMBeBtFWk=; b=hQ2Vei213GD4uBVfZga1S5KYnHE7xbmmovQ2QExYfVL8wZQnshif01hXEJEuznPTY9 GHJC3mPRtEZHhUaXOwAQImUp2ipJWVczvQCyvz1ReUvGe6pF7SNmQ1xGY0VQGoSvdCXC Rv/bKZj/JbMc/VdQdKSg/qTbPXwRjwBf4FYIQoMhNG6xjk1NA1W3kw6YuydfnjwlwhM9 r1/b1CCReHfFck6Ro2Hbnh5qlqFhQ9MBUaG047Cpd83NGhYC2fJxVYF/ybFZTK4PE7/N rvrHzM05umfuc6Q/A2z8zCpjNniLSAE5CniqWYiY+0hR/NsUDrAllXDrDZyhcscyzvLM 9atw== X-Gm-Message-State: AC+VfDyixxjmYamD7C6EduPYahUXppMhiPbzl8B3MmKcZiaVNstlxZmZ 8wZHp+xgtOtfYoBHOSYdeyKieupqFgjgCgmvHFk= X-Google-Smtp-Source: ACHHUZ7tlnU0DBd//uox/keWUwVSKhvttfyBlV6tfLJI/f9Bomz7+cJpmQPpM/tYhogfJGKGjmOO5A== X-Received: by 2002:a92:c009:0:b0:33b:424a:eb41 with SMTP id q9-20020a92c009000000b0033b424aeb41mr5400590ild.2.1685636681703; Thu, 01 Jun 2023 09:24:41 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id l1-20020a922901000000b0033a6e7ee4e3sm3862098ilg.1.2023.06.01.09.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Jun 2023 09:24:41 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Heinrich Schuchardt , Tom Rini , Simon Glass , Jerry Van Baren Subject: [PATCH 18/40] fdt: Allow more general use of livetree Date: Thu, 1 Jun 2023 10:22:42 -0600 Message-ID: <20230601162404.220488-17-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.rc0.172.g3f132b7071-goog In-Reply-To: <20230601162404.220488-1-sjg@chromium.org> References: <20230601162404.220488-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 At present livetree can only be used for the control FDT. It is useful to be able to use the ofnode API for other FDTs, e.g. those used by the upcoming configuration editor. We already have most of the support present, and tests can be marked with the UT_TESTF_OTHER_FDT flag to use another FDT as a special case. But with this change, the functionality becomes more generally available. Plumb in the require support. Signed-off-by: Simon Glass --- drivers/core/ofnode.c | 26 +++++++++++++++++++++----- include/dm/ofnode.h | 10 ++++++++++ include/of_live.h | 10 ++++++++++ lib/of_live.c | 6 ++++++ test/dm/ofnode.c | 19 +++++++++++++++++++ 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index dee890b5527b..8df16e56af5c 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -51,6 +52,20 @@ static oftree oftree_ensure(void *fdt) oftree tree; int i; + if (of_live_active()) { + struct device_node *root; + int ret; + + ret = unflatten_device_tree(fdt, &root); + if (ret) { + log_err("Failed to create live tree: err=%d\n", ret); + return oftree_null(); + } + tree = oftree_from_np(root); + + return tree; + } + if (gd->flags & GD_FLG_RELOC) { i = oftree_find(fdt); if (i == -1) { @@ -60,11 +75,6 @@ static oftree oftree_ensure(void *fdt) return oftree_null(); } - if (of_live_active()) { - log_err("Cannot register a flattree when OF_LIVE is active\n"); - return oftree_null(); - } - /* register the new tree */ i = oftree_count++; oftree_list[i] = fdt; @@ -82,6 +92,12 @@ static oftree oftree_ensure(void *fdt) return tree; } +void oftree_dispose(oftree tree) +{ + if (of_live_active()) + of_live_free(tree.np); +} + void *ofnode_lookup_fdt(ofnode node) { if (gd->flags & GD_FLG_RELOC) { diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 443db6252ddc..0f38b3e736de 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -352,6 +352,16 @@ static inline oftree oftree_from_np(struct device_node *root) return tree; } +/** + * oftree_dispose() - Dispose of an oftree + * + * This can be used to dispose of a tree that has been created (other than + * the control FDT which must not be disposed) + * + * @tree: Tree to dispose + */ +void oftree_dispose(oftree tree); + /** * ofnode_name_eq() - Check if the node name is equivalent to a given name * ignoring the unit address diff --git a/include/of_live.h b/include/of_live.h index f59d6af3350d..05e86ac06b1a 100644 --- a/include/of_live.h +++ b/include/of_live.h @@ -36,4 +36,14 @@ int of_live_build(const void *fdt_blob, struct device_node **rootp); */ int unflatten_device_tree(const void *blob, struct device_node **mynodes); +/** + * of_live_free() - Dispose of a livetree + * + * This frees memory used by the tree, after which @root becomes invalid and + * cannot be used + * + * @root: Tree to dispose + */ +void of_live_free(struct device_node *root); + #endif diff --git a/lib/of_live.c b/lib/of_live.c index 05588d5ed282..25f7af61061e 100644 --- a/lib/of_live.c +++ b/lib/of_live.c @@ -330,3 +330,9 @@ int of_live_build(const void *fdt_blob, struct device_node **rootp) return ret; } + +void of_live_free(struct device_node *root) +{ + /* the tree is stored as a contiguous block of memory */ + free(root); +} diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 64baaf68db3a..6fbebc7da085 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -1266,3 +1266,22 @@ static int dm_test_livetree_align(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_livetree_align, UT_TESTF_LIVE_TREE); + +/* check that it is possible to load an arbitrary livetree */ +static int dm_test_livetree_ensure(struct unit_test_state *uts) +{ + oftree tree; + ofnode node; + + /* read from other.dtb */ + ut_assertok(test_load_other_fdt(uts)); + tree = oftree_from_fdt(uts->other_fdt); + ut_assert(oftree_valid(tree)); + node = oftree_path(tree, "/node/subnode"); + ut_assert(ofnode_valid(node)); + ut_asserteq_str("sandbox-other2", + ofnode_read_string(node, "compatible")); + + return 0; +} +DM_TEST(dm_test_livetree_ensure, 0); -- 2.41.0.rc0.172.g3f132b7071-goog