peekpoke

Crates.iopeekpoke
lib.rspeekpoke
version0.3.0
sourcesrc
created_at2023-02-23 17:56:27.108716
updated_at2023-09-25 07:38:04.533437
descriptionpeekpoke - a lightweight Rust library for accessing physical addresses using /dev/mem in Linux
homepagehttps://github.com/erickrenz/peekpoke
repositoryhttps://github.com/erickrenz/peekpoke
max_upload_size
id792961
size10,718
Eric Krenz (erickrenz)

documentation

https://docs.rs/peekpoke/

README

peekpoke

Latest Version Documentation Downloads License

A lightweight Rust library used for reading and writing from physical memory address using /dev/mem.

In Linux, /dev/mem is a character device file containing access to the physical memory in a system. This file can be used to read and write to physical addresses on the bare metal (or virtualized) hardware. This functionality for user-space applications is similar to the devmem cli utility in busybox.

For more information, refer to the linux kernel manual.

Requirements

  • Linux (WSL, Debian, Fedora, Arch)

  • Sudo permissions

Usage

Add this to your Cargo.toml:

[dependencies]
peekpoke = "0.3"

Example

let address: u32 = 0x4000_0000;
let value: u32 = 0xDEAD_BEEF;

peekpoke::write(address, value);

let result: u32 = peekpoke::read(address);

println!("{:#010X}", result); // 0xDEAD_BEEF 

Troubleshooting

Access denied to /dev/mem

  1. Configure your kernel with CONFIG_STRICT_DEVMEM=n (RECCOMENDED). The default kernel configuration denies access to RAM using /dev/mem (default: CONFIG_STRICT_DEVMEM=y) for non root users.
  2. Run as root user.

Address invalid

The default behavior for /dev/mem is to return errors if the address you enter is invalid. Refer to your hardware's manual for further troubleshooting steps.

Cross Compiling

For embedded systems development, it may be useful to cross compile your app to run on a different architecture. For more information on this process, check out this example GitHub repo for Rust cross-compiling.

License

Peekpoke is distributed under the terms of the MIT license. See terms and conditions here.

Commit count: 21

cargo fmt