From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796398718; b=qsFFIjD9uyGvIIxQWq2NkpglO7ahhdGsk9KjTofispBXU80YrVe+LtDJm7OtnZHzpywr vbBkgnD95spisBy09iKLjgT9A/TgCGfy0gK2do/BhOS81SewbmrG95ZIwMxHi64cuH5KU NMBanWtG+J33uSyIMeast7hGdqvBZUC4eJkyuvc6jAEKqzrRQW2ylFIc34Y5alCUuOE3E uE8uM2jNk53bAFseRKKOxnktl6hfpb5Z5AOUi8nItuXrsLLtHXzQMiDtIqT3+QQiRT39B K96LCJv6+MbbAip9uikeDYrAeT52HFBlQpDHAW8wnubUgwakxxJMrUKoHeISDaneRdg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796398718; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=MxofkkNnQ00zjxFzf7Kuf/mEe6hxv2E7ue38tUZw0O8=; b=KHPZzWJ4Ff2pxlc5bqDDA/cnsLZD9gNGHe3uBbBjh3VvG9Y7/rKoIRaRvcYaOdywiZj9 HzQtTSgqsR5dcxYFzrybfxdKp4u5fkVxTwnP8K2+fn+yeBDk4R/mcTn82Q8TM0dejBWZU Y0c1hZIyZdj2gM9AUp/gTcnHCx+do57U3x6h47aZjp+Xt9Cl2yhetxi5EyJiPLsNSvsSU YeE4FbLoOteUFs7r2R5s0Nx/Nl1bls10zGpQ8py/Z5WdmsncsFlOuyo2JWGEqpNcCYQBs XHuPMplwFcRCrssm0GMY85k/xG8HZZpkG18vA98Rn6nwrx4YQzswCVjYhcwt34VX15Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=BtxQ50Zs; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51C6D606A69F for ; Fri, 4 Dec 2026 15:38:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 51C6D606A69F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=BtxQ50Zs Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-3869f03af6aso1365411eec.1 for ; Fri, 04 Dec 2026 07:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1796398717; x=1797003517; darn=vger.kernel.org; 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:content-type; bh=MxofkkNnQ00zjxFzf7Kuf/mEe6hxv2E7ue38tUZw0O8=; b=BtxQ50ZsyCs0B9v8FEj16WMaKOL/T+8gx+PofT8bbPvTvHWBdE8irCQbqYqA+ZqeCI dsIPv/0hUrpWq0AIly8YnHgeOIZrvikrcKeZTbpXIvvqa/rzn+pdv93oMSX9QQhjjHOq ze1+JPLvDg7G+F6uauKPoBndyJeZLVz/JUwys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796398717; x=1797003517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=MxofkkNnQ00zjxFzf7Kuf/mEe6hxv2E7ue38tUZw0O8=; b=GJN4Q1PFqHg0tEeeV4ZoMXj3MyBnY5Z9UNFZ4QI69255nbWsnQ1+12gdsh6DaL2Vlf QRgWo8eGHRJAk3IFC5+Ln32TYD1/TGRLzcG9i0UVFoNibr3lzkLaZ5Kyc5dr+mVT371v iaF5XVuM69uqaILSktWy8r3Xo1x3Yyzjs4ifpxPSMGed4f75F4Iz3N+hPr5y3m02pIX+ bnxHMeMZtEwkP14oUSLAXrinEkmyZymzgbOQstbR1iW2hKk5LI94wb77LUgNi26Xn3AA TajQUy4jUDiZNnNF4smnPUWJCMKcwBrcx4lZa6b1JhC5CTjn8VD0q+rAgqi4qho3kdNV jnoQ== X-Forwarded-Encrypted: i=1; AL+hErEctwxNlHHUW45XOY38lgRj+a8cJlAgLw/L3wBK0WQZMb1WEJJJg0eAbFGFyLAOchdCaNUR7Gop+Uh1@vger.kernel.org X-Gm-Message-State: AB4q+uHUzDWFAXxR6ey/4vD9DWCDnMZVp3hUmw/aw5fWGU83qJGlvyfP Y9HZgrNdMbx9pyEEumHdg8eiP9yHvK03jJdfmOsB/C478ic2uDWa+SoQxo3KNGC8xw== X-Gm-Gg: AZFdTZenL09avYQXkJ9Xi8YqHb76HQgbgvVTsxSS/Vrp5FLKARwP1lth+1dGB15JsP6 dPi0ClKj8vI96bfDvkgmRYZfWM0ImKTmH2gHgrvC7L+pidK4o4AJnvVFeH3CRSZvgqSKcIjJdVK 9Rc1ZQNbI+CjjNVDXGkWvqJAnsmaz/g1YYx82/IT1R9j0A/LvRwTen26g/pqoV3C5MvaLuZxcuh Gd7y1ob9ExpyAoi6a5KtFjT1tdzOJotE/hhpaXaZWKulsvMFWTBfm+4MRXQ4FJ80nZ4CzJOnrRm R0LwPpl1gJWfxM8MJ4ktKxRLk3d+6iVYSGjxZol6vAVG/oSCouirOpyRLPzvMOPjucryS0Fo9UE svFHQABbJO72Kf4X6DDO0ytN/6jGMZgQ68FTMX+JTe1+vV/rerRM29hugbPtz+fEGnAIUC/e/hI 5ciX4uObxa0bIoa8s7w3ER8N69YR92RhW/6bp+yWuYOwkdztIXhi5Og8Smzqav1uFlATWNIMYK3 aav+F8L9zuEG1GY9uZS6z9RXgGHt8OzvCiaWqpTdrAZgcCSJA+hNT2XmVvDDe7oYcxE6yP3bVtt /+T35lCcMjHsoQWJchrr9+P2jsW8fBcE0J/YzrXvpgxeiMxRa1EXAFrjXT7GtvHOfgpW2tXO1f2 R5EMldrT6lSQA X-Received: by 2002:a05:693c:8202:b0:387:44b1:3b3a with SMTP id 5a478bee46e88-3875219a78amr2279789eec.14.1796398717227; Fri, 04 Dec 2026 07:38:37 -0800 (PST) Received: from dianders.sjc.corp.google.com ([2a00:79e0:2e7c:8:fba:375a:d40:ff68]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875218bd23sm9518875eec.8.2026.12.04.07.38.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 07:38:36 -0800 (PST) From: Douglas Anderson To: Devicetree-compiler@vger.kernel.org, David Gibson , Simon Glass Cc: Conor Dooley , Devicetree@vger.kernel.org, Konrad Dybcio , Peter Griffin , Brian Norris , David Laight , Julius Werner , Krzysztof Kozlowski , =?UTF-8?q?Andr=C3=A9=20Draszik?= , Rob Herring , Saravana Kannan , Tudor Ambarus , Chen-Yu Tsai , linux-kernel@vger.kernel.org, Douglas Anderson Subject: [PATCH v5 5/8] fdtfactor: Add -S/--strip-local-fixups option Date: Fri, 4 Dec 2026 07:36:42 -0800 Message-ID: <20261204153756.1926794-6-dianders@chromium.org> X-Mailer: git-send-email 2.56.1.987.g2ec0ab4260-goog In-Reply-To: <20261204153756.1926794-1-dianders@chromium.org> References: <20261204153756.1926794-1-dianders@chromium.org> X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit By default, `fdtfactor` preserves `/__local_fixups__` on `base.dtb` so that when `fdt_overlay_apply()` merges a `.dtbo` overlay, the reconstructed device tree retains full `/__local_fixups__` information (for instance, if an OS kernel wants to know which property cells contain phandles at runtime). When `-L` was passed to `dtc` solely to help `fdtfactor` locate phandle cells at build time and `/__local_fixups__` is not needed at runtime, retaining `/__local_fixups__` in `base.dtb` wastes space. Add `-S` / `--strip-local-fixups` to omit `/__local_fixups__` from `base.dtb` (and therefore from the merged device trees produced by `fdt_overlay_apply()`). On a set of 47 Qualcomm SC7180 Trogdor Chromebook board DTBs, `fdtfactor` without `-S` reduces total uncompressed size from 7.69 MB to 932 KB (88.2% savings), while `fdtfactor -S` reduces it to 634 KB (91.8% savings, saving an additional 298 KB by omitting `/__local_fixups__` from `base.dtb`). Add a test case in `tests/run_tests.sh` verifying that `fdtfactor -S` followed by `fdtoverlay` reproduces DTBs compiled with `-@` (without `-L`) via `dtbs_equal_unordered`. Reviewed-by: Simon Glass Reviewed-by: David Gibson Assisted-by: Gemini:gemini-pro-prerelease Signed-off-by: Douglas Anderson --- (no changes since v4) Changes in v4: - Use 4-space indentation instead of mixed tabs and spaces in tests/run_tests.sh, and update context for -o/--output (David Gibson) Changes in v3: - Include both non--S (932 KB) and -S (634 KB) Trogdor size numbers in the commit message to show the savings of -S itself (Simon Glass) - Pass -S to the negative test verifying that inputs lacking /__local_fixups__ are still rejected when -S is used, and move the non--S rejection test to the base fdtfactor patch (Simon Glass) Changes in v2: - Split -S/--strip-local-fixups into a separate opt-in patch (David Gibson) README.md | 9 +++++++++ fdtfactor | 21 ++++++++++++++++++--- tests/run_tests.sh | 19 +++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9a8be74d47fe..198384cd8456 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,15 @@ Options: * `-o`, `--output`: Output directory for generated `.dtbo` files and `--output-base-dtb` (default: alongside each input `.dtb` for `.dtbo` files, current directory for `--output-base-dtb`). +* `-S`, `--strip-local-fixups`: Omit `/__local_fixups__` from the generated + `base.dtb` and final reconstructed device trees. By default, `fdtfactor` + preserves `/__local_fixups__` on `base.dtb` so that when `fdt_overlay_apply()` + merges a `.dtbo` overlay, the reconstructed device tree retains full + `/__local_fixups__` information (e.g., for an OS kernel that wants to + know which property cells contain phandles at runtime). When `-L` was + passed to `dtc` solely to help `fdtfactor` locate phandles at build time + and `/__local_fixups__` is not needed at runtime, passing `-S` strips it + from `base.dtb` to save space. * `-s`, `--stats`: Print size savings summary. ### TODO diff --git a/fdtfactor b/fdtfactor index dfbee0aea2d6..a083a8c380a0 100755 --- a/fdtfactor +++ b/fdtfactor @@ -675,11 +675,13 @@ def _build_board_dtbo(dtb, base_nodes, base_dtb_symbols, return bytes(dtbo_root.flatten().as_bytearray()) -def create_base_dtb_and_overlays(dtbs): +def create_base_dtb_and_overlays(dtbs, strip_local_fixups=False): """Compute the base DTB and per-board DTBO blobs from parsed DTBs. Args: dtbs: Sequence of `ParsedDtb` instances (at least two). + strip_local_fixups: If True, omit `/__local_fixups__` from the + generated `base.dtb`. Returns: Tuple of `(base_dtb_blob, dtbo_blobs)` where `base_dtb_blob` is the @@ -694,7 +696,9 @@ def create_base_dtb_and_overlays(dtbs): base_dtb_blob = _serialize_base_dtb( base_nodes, base_dtb_symbols, dtbs[0].mem_rsv, dtbs[0].boot_cpuid_phys, - emit_local_fixups=any(d.has_local_fixups for d in dtbs), + emit_local_fixups=( + not strip_local_fixups and any(d.has_local_fixups for d in dtbs) + ), ) dtbo_blobs = [ _build_board_dtbo( @@ -757,6 +761,14 @@ def parse_args(argv=None): 'current directory for --output-base-dtb)' ), ) + parser.add_argument( + '-S', '--strip-local-fixups', + action='store_true', + help=( + 'Omit /__local_fixups__ from the generated base .dtb and ' + 'reconstructed device trees' + ), + ) parser.add_argument( '-s', '--stats', action='store_true', @@ -841,7 +853,10 @@ def factor_dtb_files(args): seen_paths.add(abs_out) dtbo_paths.append(out_path) - base_dtb_blob, dtbo_blobs = create_base_dtb_and_overlays(dtbs) + base_dtb_blob, dtbo_blobs = create_base_dtb_and_overlays( + dtbs, + strip_local_fixups=args.strip_local_fixups, + ) if args.output: os.makedirs(args.output, exist_ok=True) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 6e36ff1719f8..646a0ed7095f 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -1372,6 +1372,25 @@ fdtfactor_tests () { done run_wrap_error_test $PYTHON $FDTFACTOR -o fdtfactor_legacy.test.dir \ fdtfactor_board1.nolf.test.dtb fdtfactor_board2.test.dtb + + # Strip local fixups (-S): verify that merged DTBs match DTBs compiled + # with -@ (without -L), and that inputs lacking /__local_fixups__ are + # still rejected even when -S is passed. + run_wrap_error_test $PYTHON $FDTFACTOR -S -o fdtfactor_strip.test.dir \ + fdtfactor_board1.nolf.test.dtb fdtfactor_board2.test.dtb + rm -rf fdtfactor_strip.test.dir + run_wrap_test $PYTHON $FDTFACTOR -S --output-base-dtb base_strip.test.dtb \ + -o fdtfactor_strip.test.dir \ + fdtfactor_board1.test.dtb fdtfactor_board2.test.dtb \ + fdtfactor_board3.test.dtb + for i in 1 2 3; do + run_wrap_test $FDTOVERLAY \ + -i fdtfactor_strip.test.dir/base_strip.test.dtb \ + -o fdtfactor_strip.test.dir/merged${i}.test.dtb \ + fdtfactor_strip.test.dir/fdtfactor_board${i}.test.dtbo + run_test dtbs_equal_unordered fdtfactor_board${i}.nolf.test.dtb \ + fdtfactor_strip.test.dir/merged${i}.test.dtb + done } while getopts "vt:me" ARG ; do -- 2.56.1.987.g2ec0ab4260-goog