1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-06-15 13:50:27 +02:00

Updates to bare metal day after teaching it again (#2775)

This fixes some issues running some of the examples, and various other
minor issues I found along the way.
This commit is contained in:
Andrew Walbran
2025-06-12 11:27:22 +01:00
committed by GitHub
parent ab26027a79
commit bb1e1c9414
19 changed files with 75 additions and 120 deletions

View File

@ -13,3 +13,10 @@ writing our own.
```rust,editable,compile_fail
{{#include examples/src/main_rt.rs:main}}
```
<details>
- Run the example in QEMU with `make qemu_rt` under
`src/bare-metal/aps/examples`.
</details>

View File

@ -14,9 +14,9 @@ dependencies = [
[[package]]
name = "aarch64-rt"
version = "0.1.3"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be4edaff3b5ead5fb7e9ef0d72fa1e93b4052ec2410e0ebc93f6f360c9599ea"
checksum = "3ba0820a68948e3655dbde1071b421d9ae8c08afb58e274b72c22e8a981c548c"
dependencies = [
"cfg-if",
"smccc",

View File

@ -8,7 +8,7 @@ publish = false
[dependencies]
aarch64-paging = { version = "0.9.1", default-features = false }
aarch64-rt = "0.1.3"
aarch64-rt = "0.2.0"
arm-pl011-uart = "0.3.1"
bitflags = "2.9.1"
log = "0.4.27"

View File

@ -27,6 +27,8 @@ minimal.bin: build
cargo objcopy --bin minimal -- -O binary $@
psci.bin: build
cargo objcopy --bin psci -- -O binary $@
rt.bin: build
cargo objcopy --bin rt -- -O binary $@
qemu: improved.bin
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s
@ -36,6 +38,8 @@ qemu_minimal: minimal.bin
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s
qemu_psci: psci.bin
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s
qemu_rt: rt.bin
qemu-system-aarch64 -machine virt -cpu max -serial mon:stdio -display none -kernel $< -s
clean:
cargo clean

View File

@ -16,6 +16,7 @@
#![no_main]
#![no_std]
mod asm;
mod exceptions;
mod pl011;

View File

@ -16,6 +16,7 @@
#![no_main]
#![no_std]
mod asm;
mod exceptions;
mod logger;
mod pl011;

View File

@ -19,6 +19,7 @@
use core::arch::asm;
use core::panic::PanicInfo;
mod asm;
mod exceptions;
const PSCI_SYSTEM_OFF: u32 = 0x84000008;

View File

@ -24,7 +24,6 @@ use arm_pl011_uart::{PL011Registers, Uart, UniqueMmioPointer};
use core::fmt::Write;
use core::panic::PanicInfo;
use core::ptr::NonNull;
use log::error;
use smccc::Hvc;
use smccc::psci::system_off;
@ -67,11 +66,9 @@ fn main(x0: u64, x1: u64, x2: u64, x3: u64) -> ! {
system_off::<Hvc>().unwrap();
panic!("system_off returned");
}
// ANCHOR_END: main
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
error!("{info}");
system_off::<Hvc>().unwrap();
loop {}
}

View File

@ -27,7 +27,7 @@ On gLinux or Debian:
<!-- mdbook-xgettext: skip -->
```sh
gdb-multiarch target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1337"
gdb-multiarch target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1338"
```
On MacOS:
@ -35,7 +35,7 @@ On MacOS:
<!-- mdbook-xgettext: skip -->
```sh
arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1337"
arm-none-eabi-gdb target/thumbv7em-none-eabihf/debug/board_support --eval-command="target remote :1338"
```
<details>

View File

@ -3,6 +3,7 @@ chip = "nrf52833_xxAA"
[debug.gdb]
enabled = true
gdb_connection_string = "127.0.0.1:1338"
[debug.reset]
halt_afterwards = true

View File

@ -66,13 +66,22 @@ _Cargo.toml_ (you shouldn't need to change this):
{{#include rtc/Cargo.toml}}
```
_image.ld_ (you shouldn't need to change this):
_build.rs_ (you shouldn't need to change this):
<!-- File image.ld -->
<!-- File build.rs -->
<!-- mdbook-xgettext: skip -->
```ld
{{#include rtc/image.ld}}
{{#include rtc/build.rs}}
```
_memory.ld_ (you shouldn't need to change this):
<!-- File memory.ld -->
<!-- mdbook-xgettext: skip -->
```ld
{{#include rtc/memory.ld}}
```
_Makefile_ (you shouldn't need to change this):

View File

@ -1,3 +1,2 @@
[build]
target = "aarch64-unknown-none"
rustflags = ["-C", "link-arg=-Timage.ld"]

View File

@ -14,9 +14,9 @@ dependencies = [
[[package]]
name = "aarch64-rt"
version = "0.1.3"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3be4edaff3b5ead5fb7e9ef0d72fa1e93b4052ec2410e0ebc93f6f360c9599ea"
checksum = "3ba0820a68948e3655dbde1071b421d9ae8c08afb58e274b72c22e8a981c548c"
dependencies = [
"cfg-if",
"smccc",

View File

@ -8,7 +8,7 @@ publish = false
[dependencies]
aarch64-paging = { version = "0.9.1", default-features = false }
aarch64-rt = "0.1.3"
aarch64-rt = "0.2.0"
arm-gic = "0.4.0"
arm-pl011-uart = "0.3.1"
bitflags = "2.9.1"

View File

@ -0,0 +1,19 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
fn main() {
println!("cargo:rustc-link-arg=-Timage.ld");
println!("cargo:rustc-link-arg=-Tmemory.ld");
println!("cargo:rerun-if-changed=memory.ld");
}

View File

@ -1,104 +0,0 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Code will start running at this symbol which is placed at the start of the
* image.
*/
ENTRY(entry)
MEMORY
{
image : ORIGIN = 0x40080000, LENGTH = 2M
}
SECTIONS
{
/*
* Collect together the code.
*/
.init : ALIGN(4096) {
text_begin = .;
*(.init.entry)
*(.init.*)
} >image
.text : {
*(.text.*)
} >image
text_end = .;
/*
* Collect together read-only data.
*/
.rodata : ALIGN(4096) {
rodata_begin = .;
*(.rodata.*)
} >image
.got : {
*(.got)
} >image
rodata_end = .;
/*
* Collect together the read-write data including .bss at the end which
* will be zero'd by the entry code.
*/
.data : ALIGN(4096) {
data_begin = .;
*(.data.*)
/*
* The entry point code assumes that .data is a multiple of 32
* bytes long.
*/
. = ALIGN(32);
data_end = .;
} >image
/* Everything beyond this point will not be included in the binary. */
bin_end = .;
/* The entry point code assumes that .bss is 16-byte aligned. */
.bss : ALIGN(16) {
bss_begin = .;
*(.bss.*)
*(COMMON)
. = ALIGN(16);
bss_end = .;
} >image
.stack (NOLOAD) : ALIGN(4096) {
boot_stack_begin = .;
. += 40 * 4096;
. = ALIGN(4096);
boot_stack_end = .;
} >image
. = ALIGN(4K);
PROVIDE(dma_region = .);
/*
* Remove unused sections from the image.
*/
/DISCARD/ : {
/* The image loads itself so doesn't need these sections. */
*(.gnu.hash)
*(.hash)
*(.interp)
*(.eh_frame_hdr)
*(.eh_frame)
*(.note.gnu.build-id)
}
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
MEMORY
{
image : ORIGIN = 0x40080000, LENGTH = 2M
}

View File

@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ANCHOR: main
use arm_pl011_uart::Uart;
use core::fmt::Write;
use log::{LevelFilter, Log, Metadata, Record, SetLoggerError};

View File

@ -5,6 +5,7 @@ export const size_exemptions = [
"android/interoperability/java.html",
"android/testing.html",
"bare-metal/aps/entry-point.html",
"bare-metal/aps/aarch64-rt.html",
"exercises/bare-metal/compass.html",
"exercises/bare-metal/solutions-afternoon.html",
"exercises/bare-metal/rtc.html",