mmap() and /dev/mem
I'm running an embedded Linux kernel, and I want to obtain a real memory address from user space.
After goggeling a little, I found that the only way was to use mmap to access /dev/mem.
But I never used mmap, and everything I read about it didn't help me much more.
Si, I wondered if someone could explain me how I could do in my case?
What I want to do:
I want to load a program in memory, in order to make it available from another processor, that has access to the DDR, but not to the flash memory where program is stored.
Here is the code I use:
As you can see, program_address is only a virtual address. But I need to know its real address, in order to transmit it to the other processor, that does not have a Linux, but a standalone application that I wrote by myself.
// Open file and get its size
FILE* program = fopen(argv,"rb");
fseek(program, 0, SEEK_END);
long program_size = ftell(program);
fseek(program, 0, SEEK_SET);
// Prepare memory to copy it in
void* program_address = malloc(program_size+1);
FILE* memory_stream = fmemopen(program_real_address, program_size + 1, "wb");
printf("Program address: 0x%x\n", (int)program_address);
// Do the copy
while ((temp = getc(program)) != EOF) putc(temp, memory_stream);
if anyone could help me, just telling how I could use mmap in my case?
I think you should move this post to "The Linux Kernel" forum. That's where kernel boffins tend to gather.
Thank you, i'll do it. Is there a way to move this thread without creating a new one?
I know moderators can, but I think the originator of a thread can also move it. Look at the "Thread Tools" tab at the top of the thread.
I've already looked there, and there is no option for that.
That's not a problem, I'll create a new one in the kernel section.
Then close this thread first since duplicate postings are not allowed.