Skip to content

Commit 9b95ad2

Browse files
gmacdorangecms
authored andcommitted
Add support for qemu machine raspi4b
Signed-off-by: Graham MacDonald <[email protected]>
1 parent 0209f15 commit 9b95ad2

File tree

9 files changed

+182
-109
lines changed

9 files changed

+182
-109
lines changed

aarch64/lib/config_default.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
[build]
22
target = "lib/aarch64-unknown-none-elf.json"
3-
buildflags = [
4-
"-Z", "build-std=core,alloc"
5-
]
3+
buildflags = ["-Z", "build-std=core,alloc"]
64

75
[link]
86
# linker script to use
97
script = 'aarch64/lib/kernel.ld'
108

119
# kernel load address to insert into kernel.ld
1210
load-address = '0xffff800000100000 - 0x80000'
11+
12+
[qemu]
13+
machine = "raspi3b"
14+
dtb = "aarch64/lib/bcm2710-rpi-3-b.dtb"

aarch64/lib/config_raspi4b.toml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[build]
2+
target = "lib/aarch64-unknown-none-elf.json"
3+
buildflags = ["-Z", "build-std=core,alloc"]
4+
5+
[link]
6+
# linker script to use
7+
script = 'aarch64/lib/kernel.ld'
8+
9+
# kernel load address to insert into kernel.ld
10+
load-address = '0xffff800000100000 - 0x80000'
11+
12+
[qemu]
13+
machine = "raspi4b"
14+
dtb = "aarch64/lib/bcm2711-rpi-4-b.dtb"

aarch64/src/main.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ fn print_binary_sections() {
6666
}
6767
}
6868

69-
fn print_memory_info() {
69+
fn print_physical_memory_info() {
7070
println!("Physical memory map:");
7171
let arm_mem = mailbox::get_arm_memory();
7272
println!(" Memory:\t{arm_mem} ({:#x})", arm_mem.size());
7373
let vc_mem = mailbox::get_vc_memory();
7474
println!(" Video:\t{vc_mem} ({:#x})", vc_mem.size());
75+
}
7576

76-
println!("Memory usage::");
77+
fn print_memory_info() {
78+
println!("Memory usage:");
7779
let (used, total) = pagealloc::usage_bytes();
7880
println!(" Used:\t\t{used:#016x}");
7981
println!(" Total:\t{total:#016x}");
@@ -84,25 +86,26 @@ fn print_pi_name(board_revision: u32) {
8486
let name = match board_revision {
8587
0xa21041 => "Raspberry Pi 2B",
8688
0xa02082 => "Raspberry Pi 3B",
89+
0xb03115 => "Raspberry Pi 4B",
8790
0xa220a0 => "Raspberry Compute Module 3",
88-
_ => "Unknown",
91+
_ => "Unrecognised",
8992
};
90-
println!(" Board Name: {name}");
93+
println!(" Board Name:\t{name}");
9194
}
9295

9396
fn print_board_info() {
9497
println!("Board information:");
9598
let board_revision = mailbox::get_board_revision();
9699
print_pi_name(board_revision);
97-
println!(" Board Revision: {board_revision:#010x}");
100+
println!(" Board Rev:\t{board_revision:#010x}");
98101
let model = mailbox::get_board_model();
99-
println!(" Board Model: {model:#010x}");
102+
println!(" Board Model:\t{model:#010x}");
100103
let serial = mailbox::get_board_serial();
101-
println!(" Serial Number: {serial:#010x}");
104+
println!(" Serial Num:\t{serial:#010x}");
102105
let mailbox::MacAddress { a, b, c, d, e, f } = mailbox::get_board_macaddr();
103-
println!(" MAC Address: {a:02x}:{b:02x}:{c:02x}:{d:02x}:{e:02x}:{f:02x}");
106+
println!(" MAC Address:\t{a:02x}:{b:02x}:{c:02x}:{d:02x}:{e:02x}:{f:02x}");
104107
let fw_revision = mailbox::get_firmware_revision();
105-
println!(" Firmware Revision: {fw_revision:#010x}");
108+
println!(" Firmware Rev:\t{fw_revision:#010x}");
106109
}
107110

108111
/// dtb_va is the virtual address of the DTB structure. The physical address is
@@ -123,6 +126,10 @@ pub extern "C" fn main9(dtb_va: usize) {
123126
println!("DTB found at: {:#x}", dtb_va);
124127
println!("midr_el1: {:?}", registers::MidrEl1::read());
125128

129+
print_binary_sections();
130+
print_physical_memory_info();
131+
print_board_info();
132+
126133
// Map address space accurately using rust VM code to manage page tables
127134
unsafe {
128135
let dtb_range = PhysRange::with_len(from_virt_to_physaddr(dtb_va).addr(), dt.size());
@@ -132,9 +139,7 @@ pub extern "C" fn main9(dtb_va: usize) {
132139

133140
// From this point we can use the global allocator
134141

135-
print_binary_sections();
136142
print_memory_info();
137-
print_board_info();
138143

139144
kernel_root().print_recursive_tables();
140145

aarch64/src/pagealloc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use port::{
1919
};
2020

2121
/// Set up bitmap page allocator assuming everything is allocated.
22-
static PAGE_ALLOC: Lock<BitmapPageAlloc<16, PAGE_SIZE_4K>> = Lock::new(
22+
static PAGE_ALLOC: Lock<BitmapPageAlloc<32, PAGE_SIZE_4K>> = Lock::new(
2323
"page_alloc",
24-
const { BitmapPageAlloc::<16, PAGE_SIZE_4K>::new_all_allocated(PAGE_SIZE_4K) },
24+
const { BitmapPageAlloc::<32, PAGE_SIZE_4K>::new_all_allocated(PAGE_SIZE_4K) },
2525
);
2626

2727
/// The bitmap allocator has all pages marked as allocated initially. We'll

aarch64/src/uartmini.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ pub struct MiniUart {
2020
#[allow(dead_code)]
2121
impl MiniUart {
2222
pub fn new(dt: &DeviceTree, mmio_virt_offset: usize) -> MiniUart {
23-
// TODO use aliases?
23+
// Bcm2835 and bcm2711 are essentially the same for our needs here.
24+
// If fdt.rs supported aliases well, we could try to just look up 'gpio'.
2425
let gpio_range = VirtRange::from(
2526
&dt.find_compatible("brcm,bcm2835-gpio")
2627
.next()
28+
.or_else(|| dt.find_compatible("brcm,bcm2711-gpio").next())
2729
.and_then(|uart| dt.property_translated_reg_iter(uart).next())
2830
.and_then(|reg| reg.regblock())
2931
.unwrap()

port/src/bitmapalloc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ impl<const SIZE_BYTES: usize> Bitmap<SIZE_BYTES> {
3535

3636
#[derive(Debug, PartialEq)]
3737
pub enum BitmapPageAllocError {
38+
NotEnoughBitmaps,
3839
OutOfBounds,
3940
MisalignedAddr,
4041
OutOfSpace,
@@ -215,7 +216,7 @@ impl<const NUM_BITMAPS: usize, const BITMAP_SIZE_BYTES: usize>
215216
check_end: bool,
216217
) -> Result<(), BitmapPageAllocError> {
217218
if check_end && range.0.end > self.end {
218-
return Err(BitmapPageAllocError::OutOfBounds);
219+
return Err(BitmapPageAllocError::NotEnoughBitmaps);
219220
}
220221

221222
for pa in range.step_by_rounded(self.alloc_page_size) {

port/src/mem.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,7 @@ impl PhysRange {
149149

150150
impl fmt::Display for PhysRange {
151151
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
152-
write!(f, "{:#016x}..{:#016x}", self.0.start.addr(), self.0.end.addr())?;
153-
Ok(())
152+
write!(f, "{:#016x}..{:#016x}", self.0.start.addr(), self.0.end.addr())
154153
}
155154
}
156155

0 commit comments

Comments
 (0)