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/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/.github/workflows/test.yml b/.github/workflows/test.yml index 59a1595..ca5bff9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,15 +1,25 @@ name: Test on: - workflow_call: + push: + branches: + - main + pull_request: + branches: + - main + jobs: ci: 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 + run: cargo fmt --all -- --check + - name: Clippy + run: cargo clippy --all-features - name: Unit test run: cargo test -- --nocapture 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..be18f0b 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,27 @@ 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]