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

Parse device tree #94

Draft
wants to merge 28 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0d5859c
wip: Add annotated DTSpec pdf
berkus Aug 3, 2021
326c19d
docs: Add DTB spec
berkus Nov 7, 2021
34c1df7
wip: Add wrapper for device_tree crate, bootup with DTB
berkus May 12, 2022
163eb86
wip: try to use fdt-rs for DTB parsing
berkus Feb 12, 2022
b076f1d
wip: Add more dtbs for the boards I have
berkus Feb 12, 2022
b07287d
wip: DTB poking
berkus May 12, 2022
6f62a07
wip: implemented DeviceTree::get_prop_by_path()
berkus Jun 10, 2022
2b8ccee
feat: Add iterator for memory reg property
berkus May 12, 2022
069b6e6
wip(rustfmt): reformat the device_tree code
berkus Aug 3, 2021
6f1e514
wip: reshuffle the docs
berkus Aug 3, 2021
fd0271e
wip: Print board name only when available
berkus Aug 3, 2021
97c0f6f
wip: impl custom eret
berkus Feb 12, 2022
6ebb6b2
wip: fix compilation
berkus May 12, 2022
feb4559
wip: improve alloc/dealloc
berkus Jun 12, 2022
f2d4519
wip: cargo.lock update
berkus Jun 12, 2022
d35d21a
wip: fix lints
berkus Jun 12, 2022
f98c15b
wip: chainloader must pass through the DTB
berkus Jun 12, 2022
999d62c
wip: calc address-cells and size-cells internally
berkus Jun 13, 2022
1484abe
wip: props iterator to do
berkus Jun 20, 2022
2044ae4
wip: add boot.s comment
berkus Jun 21, 2022
ddaf2f4
wip: Improve props iterator
berkus Jun 20, 2022
6096330
wip: convert reserved memory to native-endian
berkus Jun 22, 2022
af47caf
wip: cleanup code
berkus Jun 21, 2022
b9506a1
wip: add payload iter tests - @todo finish them
berkus Jun 21, 2022
ed2b6de
wip: add dump of entire live FDT from the board
berkus Jun 21, 2022
abac379
wip: additional memory regions steps
berkus Jun 22, 2022
adacca8
wip: DRY it up
berkus Jun 22, 2022
ce4d7ad
wip: sq formatting
berkus Jun 28, 2022
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
182 changes: 181 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bin/chainboot/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ pub unsafe extern "C" fn _start() -> ! {
/// The function is called from the assembly `_start` function, keep it to support "asm" feature.
#[no_mangle]
#[inline(always)]
pub unsafe fn _start_rust(max_kernel_size: u64) -> ! {
crate::kernel_init(max_kernel_size)
pub unsafe fn _start_rust(dtb: u32, max_kernel_size: u64) -> ! {
crate::kernel_init(dtb, max_kernel_size)
}
36 changes: 19 additions & 17 deletions bin/chainboot/src/boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
//------------------------------------------------------------------------------
// fn _start()
//------------------------------------------------------------------------------
// x0 contains DTB address on entry, preserve it until the call to Rust.
_start:
// Only proceed on the boot core. Park it otherwise.
mrs x1, MPIDR_EL1
Expand All @@ -49,39 +50,40 @@ _start:
// If execution reaches here, it is the boot core.

// Initialize bss.
ADR_ABS x0, __bss_start
ADR_ABS x1, __bss_end_exclusive
ADR_ABS x1, __bss_start
ADR_ABS x2, __bss_end_exclusive

.L_bss_init_loop:
cmp x0, x1
cmp x1, x2
b.eq .L_relocate_binary
stp xzr, xzr, [x0], #16
stp xzr, xzr, [x1], #16
b .L_bss_init_loop

// Next, relocate the binary.
.L_relocate_binary:
ADR_REL x0, __binary_nonzero_lma // The address the binary got loaded to.
ADR_ABS x1, __binary_nonzero_vma // The address the binary was linked to.
ADR_ABS x2, __binary_nonzero_vma_end_exclusive
sub x4, x1, x0 // Get difference between vma and lma as max size
ADR_REL x1, __binary_nonzero_lma // The address the binary got loaded to.
ADR_ABS x2, __binary_nonzero_vma // The address the binary was linked to.
ADR_ABS x3, __binary_nonzero_vma_end_exclusive
sub x4, x2, x1 // Get difference between vma and lma as max size

.L_copy_loop:
ldr x3, [x0], #8
str x3, [x1], #8
cmp x1, x2
ldr x5, [x1], #8
str x5, [x2], #8
cmp x2, x3
b.lo .L_copy_loop

// Prepare the jump to Rust code.
// Set the stack pointer.
ADR_ABS x0, __rpi_phys_binary_load_addr
mov sp, x0
ADR_ABS x1, __rpi_phys_binary_load_addr
mov sp, x1

// Pass maximum kernel size as an argument to Rust init function.
mov x0, x4
// Pass DTB location in x0 to Rust init function.
// Pass maximum kernel size as an argument in x1 to Rust init function.
mov x1, x4

// Jump to the relocated Rust code.
ADR_ABS x1, _start_rust
br x1
ADR_ABS x2, _start_rust
br x2

// Infinitely wait for events (aka "park the core").
.L_parking_loop:
Expand Down
11 changes: 6 additions & 5 deletions bin/chainboot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod boot;
/// - Only a single core must be active and running this function.
/// - The init calls in this function must appear in the correct order.
#[inline(always)]
unsafe fn kernel_init(max_kernel_size: u64) -> ! {
unsafe fn kernel_init(dtb: u32, max_kernel_size: u64) -> ! {
#[cfg(feature = "jtag")]
machine::arch::jtag::wait_debugger();

Expand All @@ -41,7 +41,7 @@ unsafe fn kernel_init(max_kernel_size: u64) -> ! {
// println! is usable from here on.

// Transition from unsafe to safe.
kernel_main(max_kernel_size)
kernel_main(dtb, max_kernel_size)
}

// https://onlineasciitools.com/convert-text-to-ascii-art (FIGlet) with `cricket` font
Expand All @@ -68,12 +68,13 @@ fn read_u64() -> u64 {

/// The main function running after the early init.
#[inline(always)]
fn kernel_main(max_kernel_size: u64) -> ! {
fn kernel_main(dtb: u32, max_kernel_size: u64) -> ! {
#[cfg(test)]
test_main();

print!("{}", LOGO);
println!("{:>51}\n", BcmHost::board_name());
println!("Preserving DTB at {:8x}", dtb);
println!("⏪ Requesting kernel image...");

let kernel_addr: *mut u8 = BcmHost::kernel_load_address() as *mut u8;
Expand Down Expand Up @@ -136,13 +137,13 @@ fn kernel_main(max_kernel_size: u64) -> ! {
CONSOLE.lock(|c| c.flush());

// Use black magic to create a function pointer.
let kernel: fn() -> ! = unsafe { core::mem::transmute(kernel_addr) };
let kernel: fn(u32) -> ! = unsafe { core::mem::transmute(kernel_addr) };

// Force everything to complete before we jump.
unsafe { barrier::isb(barrier::SY) };

// Jump to loaded kernel!
kernel()
kernel(dtb)
}

#[cfg(not(test))]
Expand Down
Binary file added doc/Power_ePAPR_APPROVED_v1.1.pdf
Binary file not shown.
Binary file added doc/devicetree-specification-v0.3.pdf
Binary file not shown.
Loading