Skip to content

Commit f132e61

Browse files
committed
simplify including DTB file using include_bytes!()
1 parent 08b59be commit f132e61

File tree

7 files changed

+17
-51
lines changed

7 files changed

+17
-51
lines changed

kernel/build.rs

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,14 @@ fn main() {
1616
gen_vector_asm().unwrap();
1717
}
1818
"riscv32" => {}
19-
"riscv64" => {
20-
if board == "rocket_chip" {
21-
gen_dtb_asm(&String::from("riscv32"), &board).unwrap();
22-
}
23-
}
24-
"mipsel" => {
25-
gen_dtb_asm(&arch, &board).unwrap();
26-
}
19+
"riscv64" => {}
20+
"mipsel" => {}
2721
"aarch64" => {}
2822
_ => panic!("Unknown arch {}", arch),
2923
}
3024
}
3125

26+
/// Generate assembly file for x86_64 trap vector
3227
fn gen_vector_asm() -> Result<()> {
3328
let mut f = File::create("src/arch/x86_64/interrupt/vector.asm").unwrap();
3429

@@ -52,32 +47,3 @@ fn gen_vector_asm() -> Result<()> {
5247
}
5348
Ok(())
5449
}
55-
56-
fn gen_dtb_asm(arch: &String, _board: &String) -> Result<()> {
57-
let dtb = std::env::var("DTB").unwrap();
58-
59-
if !Path::new(&dtb).is_file() {
60-
panic!("DTB `{}` not found", dtb)
61-
}
62-
63-
let mut f = File::create(format!("src/arch/{}/boot/dtb.gen.s", arch)).unwrap();
64-
65-
println!("cargo:rerun-if-changed={}", dtb);
66-
println!("cargo:rerun-if-env-changed=DTB");
67-
68-
writeln!(f, "# generated by build.rs - do not edit")?;
69-
write!(
70-
f,
71-
r#"
72-
.section .dtb,"a"
73-
.align 12
74-
.global _dtb_start, _dtb_end
75-
_dtb_start:
76-
.incbin "{}"
77-
_dtb_end:
78-
"#,
79-
dtb
80-
)?;
81-
82-
Ok(())
83-
}

kernel/src/arch/mipsel/board/malta/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ pub mod vga;
1414

1515
use fb::FramebufferInfo;
1616

17+
/// Device tree bytes
18+
pub static DTB: &'static [u8] = include_bytes!("device.dtb");
19+
1720
/// Initialize serial port first
1821
pub fn init_serial_early() {
1922
// initialize serial driver

kernel/src/arch/mipsel/board/mipssim/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ pub mod fb;
88
#[path = "../../../../drivers/serial/16550_reg.rs"]
99
pub mod serial;
1010

11+
/// Device tree bytes
12+
pub static DTB: &'static [u8] = include_bytes!("device.dtb");
13+
1114
/// Initialize serial port first
1215
pub fn init_serial_early() {
1316
serial::init(0xbfd003f8);

kernel/src/arch/mipsel/board/thinpad/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub mod serial;
1111
use fb::FramebufferInfo;
1212
use fb::FramebufferResult;
1313

14+
/// Device tree bytes
15+
pub static DTB: &'static [u8] = include_bytes!("device.dtb");
16+
1417
/// Initialize serial port first
1518
pub fn init_serial_early() {
1619
serial::init(0xa3000000);

kernel/src/arch/mipsel/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ pub mod board;
2424
#[path = "board/mipssim/mod.rs"]
2525
pub mod board;
2626

27-
extern "C" {
28-
fn _dtb_start();
29-
fn _dtb_end();
30-
}
31-
3227
#[no_mangle]
3328
pub extern "C" fn rust_main() -> ! {
3429
// unsafe { cpu::set_cpu_id(hartid); }
3530

3631
let ebase = cp0::ebase::read_u32();
3732
let cpu_id = ebase & 0x3ff;
38-
let dtb_start = _dtb_start as usize;
33+
let dtb_start = board::DTB.as_ptr() as usize;
3934

4035
if cpu_id != BOOT_CPU_ID {
4136
// TODO: run others_main on other CPU
@@ -79,4 +74,3 @@ const BOOT_CPU_ID: u32 = 0;
7974
global_asm!(include_str!("boot/context.gen.s"));
8075
global_asm!(include_str!("boot/entry.gen.s"));
8176
global_asm!(include_str!("boot/trap.gen.s"));
82-
global_asm!(include_str!("boot/dtb.gen.s"));

kernel/src/arch/riscv32/board/rocket_chip/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use crate::memory::phys_to_virt;
22

3+
/// Device tree bytes
4+
pub static DTB: &'static [u8] = include_bytes!("device.dtb");
5+
36
/// Mask all external interrupt except serial.
47
pub unsafe fn init_external_interrupt() {
58
const HART0_S_MODE_INTERRUPT_ENABLES: *mut u64 = phys_to_virt(0x0C00_2080) as *mut u64;

kernel/src/arch/riscv32/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ pub extern "C" fn rust_main(hartid: usize, device_tree_paddr: usize) -> ! {
3434

3535
#[cfg(feature = "board_rocket_chip")]
3636
{
37-
extern "C" {
38-
fn _dtb_start();
39-
fn _dtb_end();
40-
}
41-
device_tree_vaddr = _dtb_start as usize;
37+
device_tree_vaddr = board::DTB.as_ptr() as usize;
4238
}
4339

4440
if hartid != BOOT_HART_ID {
@@ -126,5 +122,3 @@ global_asm!(include_str!("boot/entry64.asm"));
126122
#[cfg(feature = "board_k210")]
127123
global_asm!(include_str!("boot/entry_k210.asm"));
128124
global_asm!(include_str!("boot/trap.asm"));
129-
#[cfg(feature = "board_rocket_chip")]
130-
global_asm!(include_str!("boot/dtb.gen.s"));

0 commit comments

Comments
 (0)