LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-18-2013, 02:52 AM   #1
answerme
Member
 
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 02:57 AM.
 
Old 03-18-2013, 03:19 AM   #2
millgates
Member
 
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, 04:39 AM   #3
answerme
Member
 
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
Code:
http://www.linuxquestions.org/questions/programming-9/debugging-uboot-4175445239/
 
Old 03-19-2013, 08:01 AM   #4
answerme
Member
 
Registered: Apr 2008
Posts: 97

Original Poster
Rep: Reputation: 24
I want to write data on 0x10000000( physical memory) Iam doing correct
Code:
#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);
    if(fd==-1)
	{
		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]);
}
 
  


Reply


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 07:17 AM
why dmesg | grep Memory gives two different physical memory amounts? jstitch Linux - Hardware 1 10-21-2010 12:52 AM
PCIe dma-able memory location in physical memory for Intel Nehalem / Tylersburg arch robvoo Linux - Kernel 4 07-31-2009 07:21 AM
Physical memory ronlau9 Linux - Hardware 4 04-28-2008 07:41 AM
Physical Memory and Virtual Memory Murdock1979 Linux - General 1 01-28-2008 08:35 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:30 AM.

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