Skip to content

Commit 1e6bdf2

Browse files
author
Serban Iorga
committed
move libfdt bindings to separate crate
Signed-off-by: Serban Iorga <[email protected]>
1 parent 3852406 commit 1e6bdf2

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/arch/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ utils = { path = "../utils" }
1818

1919
[dev-dependencies]
2020
device_tree = ">=1.1.0"
21+
22+
[target.'cfg(target_arch="aarch64")'.dependencies]
23+
libfdt-bindings = { path = "../libfdt-bindings" }

src/arch/src/aarch64/fdt.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
// Use of this source code is governed by a BSD-style license that can be
66
// found in the THIRD-PARTY file.
77

8-
use libc::{c_char, c_int, c_void};
8+
use libc::{c_int, c_void};
99
use std::collections::HashMap;
1010
use std::ffi::{CStr, CString, NulError};
1111
use std::fmt::Debug;
1212
use std::ptr::null;
1313
use std::{io, result};
1414

15+
use libfdt_bindings::*;
16+
1517
use super::super::DeviceType;
1618
use super::super::InitrdConfig;
1719
use super::cache_info::{read_cache_config, CacheEntry};
@@ -45,21 +47,6 @@ const GIC_FDT_IRQ_TYPE_PPI: u32 = 1;
4547
const IRQ_TYPE_EDGE_RISING: u32 = 1;
4648
const IRQ_TYPE_LEVEL_HI: u32 = 4;
4749

48-
// This links to libfdt which handles the creation of the binary blob
49-
// flattened device tree (fdt) that is passed to the kernel and indicates
50-
// the hardware configuration of the machine.
51-
extern "C" {
52-
fn fdt_create(buf: *mut c_void, bufsize: c_int) -> c_int;
53-
fn fdt_finish_reservemap(fdt: *mut c_void) -> c_int;
54-
fn fdt_begin_node(fdt: *mut c_void, name: *const c_char) -> c_int;
55-
fn fdt_property(fdt: *mut c_void, name: *const c_char, val: *const c_void, len: c_int)
56-
-> c_int;
57-
fn fdt_end_node(fdt: *mut c_void) -> c_int;
58-
fn fdt_open_into(fdt: *const c_void, buf: *mut c_void, bufsize: c_int) -> c_int;
59-
fn fdt_finish(fdt: *const c_void) -> c_int;
60-
fn fdt_pack(fdt: *mut c_void) -> c_int;
61-
}
62-
6350
/// Trait for devices to be added to the Flattened Device Tree.
6451
pub trait DeviceInfoForFDT {
6552
/// Returns the address where this device will be loaded.

src/libfdt-bindings/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "libfdt-bindings"
3+
version = "0.1.0"
4+
authors = ["Amazon Firecracker team <[email protected]>"]
5+
edition = "2018"
6+
7+
[target.'cfg(target_arch="aarch64")'.dependencies]
8+
libc = ">=0.2.39"

src/libfdt-bindings/src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
#[cfg(target_arch = "aarch64")]
5+
use libc::{c_char, c_int, c_void};
6+
7+
// This links to libfdt which handles the creation of the binary blob
8+
// flattened device tree (fdt) that is passed to the kernel and indicates
9+
// the hardware configuration of the machine.
10+
#[cfg(target_arch = "aarch64")]
11+
extern "C" {
12+
pub fn fdt_create(buf: *mut c_void, bufsize: c_int) -> c_int;
13+
pub fn fdt_finish_reservemap(fdt: *mut c_void) -> c_int;
14+
pub fn fdt_begin_node(fdt: *mut c_void, name: *const c_char) -> c_int;
15+
pub fn fdt_property(
16+
fdt: *mut c_void,
17+
name: *const c_char,
18+
val: *const c_void,
19+
len: c_int,
20+
) -> c_int;
21+
pub fn fdt_end_node(fdt: *mut c_void) -> c_int;
22+
pub fn fdt_open_into(fdt: *const c_void, buf: *mut c_void, bufsize: c_int) -> c_int;
23+
pub fn fdt_finish(fdt: *const c_void) -> c_int;
24+
pub fn fdt_pack(fdt: *mut c_void) -> c_int;
25+
}

0 commit comments

Comments
 (0)