简体   繁体   English

在Linux on ARM上写入物理地址

[英]Write to a physical address in Linux on ARM

I would like to write an integer(just one value, it can be also other type) to a specific register (for example: 0x60006666) on a Linux machine using the ARM platform. 我想在使用ARM平台的Linux机器上将整数(只是一个值,也可以是其他类型)写入特定寄存器(例如:0x60006666)。

There are many examples using the mmap(2), but it is not clear how to write just one value to a specific address using the mmap(). 有很多使用mmap(2)的示例,但不清楚如何使用mmap()仅将一个值写入特定地址。 Having a look at the mmap() manual, it does not specify what value to write to the specific register: http://man7.org/linux/man-pages/man2/mmap.2.html 看看mmap()手册,它没有指定要写入特定寄存器的值: http : //man7.org/linux/man-pages/man2/mmap.2.html

Here is the function: 这是函数:

void *mmap(void *addr, size_t length, int prot, int flags,
              int fd, off_t offset);

It is clear that *addr is the address, but where do we insert the value is written to this address? 很明显,* addr是地址,但是我们将值插入到哪里呢?

In my case I would like to write an int to a specific address, how would mmap look like? 就我而言,我想将int写入特定地址,mmap会是什么样子?

#define _WRITE_ADDR       0x60006666 //address where to write 
unsigned int value_addr = 0x00000080 //value to be written to the address

I would like to write the above mentioned value to the specified address. 我想将上述值写入指定的地址。 It should be trivial, but not very clear since it has been some time since I worked with this type of questions, hopefully somebody has some hints. 这应该是微不足道的,但不是很清楚,因为自从我处理此类问题已经有一段时间了,希望有人能提供一些提示。 Thanks! 谢谢!

Similar question: 类似的问题:
WRITE and READ registers in Linux on ARM Linux在ARM上的WRITE和READ寄存器

It is rather simple. 这很简单。 Example based on RPI 基于RPI的示例

first you need to: 首先,您需要:

mem_fd = open("/dev/mem", O_RDWR | O_SYNC);

then allocate memory for the map. 然后为地图分配内存。 For example for one BCM RPi peritheral it will me 4K + 4K 例如,对于一个BCM RPi腹膜,它将是4K + 4K

periph_mem = malloc( 8*1024 - 1); periph_mem = malloc(8 * 1024-1);

then make sure that it is 4k aligned and mmap it: 然后确保它对齐4k并mmap它:

gpio_map = (unsigned char *)mmap((caddr_t)poriph_mem, BLOCK_SIZE,PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, mem_fd, PERIPH_BASE    );

where PERIPH_BASE is the base address of the peripheral (for example GPIO 0x20000000 (BCM peripherals base) + 0x200000) 其中PERIPH_BASE是外设的基地址(例如GPIO 0x20000000(BCM外设基)+ 0x200000)

then you can access them as normal pointers (but remember they have to volatile ) 那么您可以将它们作为普通指针访问(但请记住,它们必须是volatile

*(volatile uint32_t *)(periph_mem + OFFSET) = VALUE;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 写入物理内存地址 - Write to physical memory address 如何在Linux中以编程方式获取物理内存地址范围 - how to programmatically get physical memory address range in linux Linux (Ubuntu), C 语言:虚拟到物理地址转换 - Linux (Ubuntu), C language: Virtual to Physical Address Translation 在Linux中将物理地址转换为虚拟地址并读取其内容 - Convert physical address to virtual in Linux and read its content 如何从Linux中的用户空间找到变量的物理地址? - How to find the physical address of a variable from user-space in Linux? 如何在Linux中获取文件中某个位置的物理地址 - How to go about getting the physical address of a location in a file in Linux 在特定物理地址处硬编码写入 RAM - write hard-codded to RAM at specific physical-address 如何启用ARM1136JFS(ARM v6)MMU在物理和虚拟地址空间之间进行一对一映射? - How to enable ARM1136JFS (ARM v6) MMU to have one to one mapping between physical and virtual address space? 在使用C ++和GCC的Linux中,是否可以将虚拟地址转换为物理地址? - In Linux using C++ and GCC, is it possible to convert the virtual address to a physical address? 在 ARM 上的 Linux 中写入和读取内存映射设备寄存器 - WRITE and READ memory mapped device registers in Linux on ARM
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM