Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-18-2013, 01:52 AM   #1
Registered: Apr 2008
Posts: 97

Rep: Reputation: 24
write onto physical memory

Is there any way that I can write data into a specific memory location(physical) .I want to write data on 0x10000000( physical memory) or to get the virtual address in kernel of 0x10000000 that gurantees me to write on this physical address

Last edited by answerme; 03-18-2013 at 01:57 AM.
Old 03-18-2013, 02:19 AM   #2
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
I think you can use for example the file /dev/mem to access the physical memory, but may I ask why would you want to do that?
Old 03-18-2013, 03:39 AM   #3
Registered: Apr 2008
Posts: 97

Original Poster
Rep: Reputation: 24
Actually uboot is getting corrupted which is getting locate at 0x10000000 (loaded uboot in NOR FLASH at this address 0x10000000) .But this problem is coming once in hundred times . You can see this link whihc I have posted earlier
Old 03-19-2013, 07:01 AM   #4
Registered: Apr 2008
Posts: 97

Original Poster
Rep: Reputation: 24
I want to write data on 0x10000000( physical memory) Iam doing correct
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>

int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: %s <phys_addr> <offset>\n", argv[0]);
        return 0;
   int i,fd,pagesize;
    off_t offset = atoi(argv[1]);
    size_t len = atoi(argv[2]);

     fd = open("/dev/mem", O_SYNC);
		printf("fd not open %d\n",fd);
pagesize = getpagesize();
      unsigned char *mem = mmap(0x10000000, len, PROT_READ | PROT_WRITE,MAP_SHARED, fd, pagesize);		
      if (mem == NULL) {
        printf("Can't map memory\n");
        return -1;
    for (i = 0; i < len; ++i)
        printf("%02x ", (int)mem[i]);


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory map or physical address of some memory allocated by malloc demon007 Programming 1 02-04-2012 06:17 AM
why dmesg | grep Memory gives two different physical memory amounts? jstitch Linux - Hardware 1 10-20-2010 11:52 PM
PCIe dma-able memory location in physical memory for Intel Nehalem / Tylersburg arch robvoo Linux - Kernel 4 07-31-2009 06:21 AM
Physical memory ronlau9 Linux - Hardware 4 04-28-2008 06:41 AM
Physical Memory and Virtual Memory Murdock1979 Linux - General 1 01-28-2008 07:35 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:39 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration