From patchwork Sat Feb 17 01:05:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 202546 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp91622dyc; Fri, 16 Feb 2024 17:22:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX9pHzkTSPGpc8nbrc2JyhBiDIYKEIY3vGeKxYRkoeU1t5j8Bf4TqSO7rzb68nFtI1zycJF0t7Vg82HLgmx92verLlKAA== X-Google-Smtp-Source: AGHT+IG2nnC1dFYDVFPmhBttWNXnJS+VjgATgtP3+Sci5FE+JvlVcMA1nojwsNGRv7Gy/SMNXWUk X-Received: by 2002:a17:90a:cb11:b0:297:efb:c33d with SMTP id z17-20020a17090acb1100b002970efbc33dmr5396110pjt.47.1708132925330; Fri, 16 Feb 2024 17:22:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708132925; cv=pass; d=google.com; s=arc-20160816; b=X72kifgSv6FpH10Ujm4CeXSzWOP2x8y/q6JgswaajYbkSxEw9vax3SDIcboR5Bqg1J A363j7yBhU90Uu5Zn9vsFftjXRaQN+xwV/Zl1iyT1k6FeiR10ITj6XywiMZKc877wmAk JLzlHvLpoBjuvM9qX8jtF/7mcsxpXYa6IOLeoDbylpbMpOekrnlkyxZK/b00akYaMWqJ B4CK4gL+u0fS38vVozfUiDoLlNcIAsAy0/idjmhvn4K5iZrfY2+Ipq8luNvo/ZzD8Olw Gk5uKxJjtrkawvurVVJr7f4mc4hj8JjCJptsbcHh2ygIwwHBslWpja0CnqjLuFifoPc4 QdZQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=txjo7axD3IOMj2sG8qZ7bqcXfpbTutPS/3Sn6RhFLnE=; fh=YL2CKQtR3hKwH4rwW9T0JOOnxDya8ZhtjXoYp3XFWPw=; b=hJ+EBXgvvx/xVLCTfkBaVTLav9zPT/vTwclKZdNUp7UjHG65zhwEVSZh6KR5hxtBQ0 raKVCFhLPKkkdHzJPXJsBctb4Ky88J8mibk5LDwMFg0OfXtPN+nF6Ax2d9FwvmCaEPQP 2jZ+SMBeWpgaEF91sznMYEVDn8uwrP0e0vc1Hsoxz6E3WVsARpejcZJafWk5tANxS1EA c3YaLH1GsvvsUaZxyZ2P/6GXbUsKG+VMI2Tb1t/WskGilBEiOz3UvZ2AMfb+rSc//y68 RiywEPcwvNO0HE6NXCNoP0ukFx8FA0Ub3q/aMNNW4h4nhw0e018L3fUZXqNqTtYsrIKl lGYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L8xIBjCa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id il8-20020a17090b164800b00297f281691asi768511pjb.98.2024.02.16.17.22.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 17:22:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L8xIBjCa; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69626-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id C67ECB20B1F for ; Sat, 17 Feb 2024 01:09:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2CE99208D3; Sat, 17 Feb 2024 01:06:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L8xIBjCa" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 678711E889; Sat, 17 Feb 2024 01:05:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131959; cv=none; b=H5YK78yQfdI1eUIfNWR2Fow0gMX622f4DVKDD2kJzL6oE5cgmvRX+fXy8+46bSxiF+1geLeaRIYGlAF0cpI2i32oxcyiM9Ay+vvKmUGkkz6osXNtqRdgjVdVAuhrmBMRIDiBDdkkwygOfMtqAdM4HYpJ8CYHol5m/6JH/fv5h0Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708131959; c=relaxed/simple; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=K6q51ue4tCkcrRvh14h4jf2lq5DVsG3FlTLLJWklsUHUUeDnFF6WSSbZrj7gC7E3VrVgh087GB/7UbsJjTsH1rxtHBaSmQ+YCc4RUookdTDqvO/dKCIGGjLzlU6iOYtn9QQEYjv9b832buVbAw/JKC8GgKZo+KuuBT1cs8CmtYc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L8xIBjCa; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 85202C43390; Sat, 17 Feb 2024 01:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708131959; bh=Qt8ricOYsTKcXJqQzKSKsHiM2MHdHGBlaBkQ7xeVb1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L8xIBjCa+dP4TX6pBp3oF6oHj02qDWwzqY5w06pu4FHMPm4oM9+4GnK7hf5lo+VW6 2PhfKNRoQPgxXisBnnsAXZ5oj4v4uKt3qaRh2dMgYSzp74qIOTG36ECnrrKJWd6Gxp +ecvRyAQwM3x1JuJba6WXapmpAKCdm8eSRGiU9p8mkN1XxFjmPHIhoWKTiFzdiJQs4 9ZK2Gchk2QqCFqUS7c9+oZoeDjD7SyQ+xcnDPpBDiWeZtpaXTNx0xGVkdlYOzqvP4t ESOs5SV9vbgJoDEkCAm5iVKsa9Qt6LOu34Dp8u1jevaN5YhRuDc5pe+VVlc7noE4gq tJba78OWDOnEQ== From: Stephen Boyd To: Rob Herring Cc: linux-kernel@vger.kernel.org, patches@lists.linux.dev, linux-um@lists.infradead.org, linux-arm-kernel@lists.infradead.org, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Frank Rowand Subject: [PATCH v4 1/7] of: Always unflatten in unflatten_and_copy_device_tree() Date: Fri, 16 Feb 2024 17:05:50 -0800 Message-ID: <20240217010557.2381548-2-sboyd@kernel.org> X-Mailer: git-send-email 2.44.0.rc0.258.g7320e95886-goog In-Reply-To: <20240217010557.2381548-1-sboyd@kernel.org> References: <20240217010557.2381548-1-sboyd@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791107190363619480 X-GMAIL-MSGID: 1791107190363619480 We want to populate an empty DT whenever CONFIG_OF is enabled so that overlays can be applied and the DT unit tests can be run. Make unflatten_and_copy_device_tree() stop printing a warning if the 'initial_boot_params' pointer is NULL. Instead, simply copy the dtb if there is one and then unflatten it. If there isn't a DT to copy, then the call to unflatten_device_tree() is largely a no-op, so nothing really changes here. Cc: Rob Herring Cc: Frank Rowand Signed-off-by: Stephen Boyd --- drivers/of/fdt.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index bf502ba8da95..dfeba8b8ce94 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -1318,6 +1318,21 @@ bool __init early_init_dt_scan(void *params) return true; } +static void *__init copy_device_tree(void *fdt) +{ + int size; + void *dt; + + size = fdt_totalsize(fdt); + dt = early_init_dt_alloc_memory_arch(size, + roundup_pow_of_two(FDT_V17_SIZE)); + + if (dt) + memcpy(dt, fdt, size); + + return dt; +} + /** * unflatten_device_tree - create tree of device_nodes from flat blob * @@ -1350,22 +1365,9 @@ void __init unflatten_device_tree(void) */ void __init unflatten_and_copy_device_tree(void) { - int size; - void *dt; + if (initial_boot_params) + initial_boot_params = copy_device_tree(initial_boot_params); - if (!initial_boot_params) { - pr_warn("No valid device tree found, continuing without\n"); - return; - } - - size = fdt_totalsize(initial_boot_params); - dt = early_init_dt_alloc_memory_arch(size, - roundup_pow_of_two(FDT_V17_SIZE)); - - if (dt) { - memcpy(dt, initial_boot_params, size); - initial_boot_params = dt; - } unflatten_device_tree(); }