Find the answer to your Linux question:
Results 1 to 6 of 6
Hi all, The problem: 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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4

    Question mmap() and /dev/mem


    Hi all,

    The problem:

    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:

    Code:
    	// Open file and get its size
    	FILE* program = fopen(argv[3],"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
    	int temp;
    	while ((temp = getc(program)) != EOF) putc(temp, memory_stream);
    	fclose(memory_stream);
    	fclose(program);
    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.

    if anyone could help me, just telling how I could use mmap in my case?

    Thank you.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,448
    I think you should move this post to "The Linux Kernel" forum. That's where kernel boffins tend to gather.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4
    Thank you, i'll do it. Is there a way to move this thread without creating a new one?

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,448
    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.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Feb 2010
    Posts
    4
    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.

  6. #6
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,448
    Then close this thread first since duplicate postings are not allowed.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •