Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import crosvm FDT writer #1

Merged
merged 5 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.aarch64-unknown-linux-musl]
rustflags = [ "-C", "target-feature=+crt-static", "-C", "link-arg=-lgcc" ]
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Add the list of code owners here (using their GitHub username)
* gatekeeper-PullAssigner
* @danielverkamp
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[package]
name = "crate-template"
name = "vm-fdt"
version = "0.1.0"
authors = [TODO]
authors = ["The Chromium OS Authors"]
license = "Apache-2.0 OR BSD-3-Clause"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All files are licensed under BSD-3-Clause, should we remove "Apache-2.0"? Or change source to " Apache-2.0 OR BSD-3-Clause"?
I remember there was a discussion about preferring "Apache-2.0 OR BSD-3-Clause".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can license them under "Apache-2.0 OR BSD-3-Clause" if that is preferred - updated to use the SPDX file header (please sanity check that this looks correct).

edition = "2018"

[dependencies]
27 changes: 27 additions & 0 deletions LICENSE-BSD-3-Clause
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2017 The Chromium OS Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45 changes: 26 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# Crate Name
# vm-fdt

## Design
The vm-fdt crate provides the ability to write Flattened Devicetree blobs as defined in the
[Devicetree specification](https://devicetree-specification.readthedocs.io/en/stable/flattened-format.html).

TODO: This section should have a high-level design of the crate.
## Design

Some questions that might help in writing this section:
- What is the purpose of this crate?
- What are the main components of the crate? How do they interact which each
other?
The [`FdtWriter` structure](src/writer.rs) provides an interface suitable
for dynamically generating a Devicetree blob at runtime.

## Usage

Expand All @@ -21,21 +20,29 @@ Some questions that might help in writing this section:

## Examples

TODO: Usage examples.
The following is a simple example of creating a device tree with various
types of properties and finalizing it as a Devicetree Blob (DTB) contained
in a vector of bytes.

```rust
use my_crate;

...
use vm_fdt::FdtWriter;

let mut fdt = FdtWriter::new(&[]);
let root_node = fdt.begin_node("")?;
fdt.property_string("compatible", "linux,dummy-virt")?;
fdt.property_u32("#address-cells", 0x2)?;
fdt.property_u32("#size-cells", 0x2)?;
let chosen_node = fdt.begin_node("chosen")?;
fdt.property_u32("linux,pci-probe-only", 1)?;
fdt.property_string("bootargs", "panic=-1 console=hvc0 root=/dev/vda")?;
fdt.end_node(chosen_node)?;
fdt.end_node(root_node)?;
let dtb = fdt.finish(0x1000)?;
```

## License

**!!!NOTICE**: The BSD-3-Clause license is not included in this template.
The license needs to be manually added because the text of the license file
also includes the copyright. The copyright can be different for different
crates. If the crate contains code from CrosVM, the crate must add the
CrosVM copyright which can be found
[here](https://chromium.googlesource.com/chromiumos/platform/crosvm/+/master/LICENSE).
For crates developed from scratch, the copyright is different and depends on
the contributors.
This project is licensed under either of

- [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0
- [BSD-3-Clause License](https://opensource.org/licenses/BSD-3-Clause)
5 changes: 5 additions & 0 deletions coverage_config_x86_64.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"coverage_score": 91.6,
"exclude_path": "",
"crate_features": ""
}
23 changes: 18 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
// Copyright 2021 The Chromium OS Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause

#![deny(missing_docs)]
andreeaflorescu marked this conversation as resolved.
Show resolved Hide resolved
//! Dummy crate needs high-level documentation.
/// Dummy public function needs documentation.
pub fn it_works() {
assert!(true);
}

//! This crate provides the ability to manipulate Flattened Devicetree blobs.

mod writer;

pub use writer::FdtWriter;
pub use writer::Result as FdtWriterResult;

/// Magic number used in the FDT header.
const FDT_MAGIC: u32 = 0xd00dfeed;

const FDT_BEGIN_NODE: u32 = 0x00000001;
const FDT_END_NODE: u32 = 0x00000002;
const FDT_PROP: u32 = 0x00000003;
const FDT_END: u32 = 0x00000009;
Loading