LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices

Reply
 
Search this Thread
Old 08-06-2013, 04:07 AM   #1
moo-cow
Member
 
Registered: Mar 2006
Distribution: Debian
Posts: 105

Rep: Reputation: 25
Reading device tree from user space and kernel module


My board is an Altera FPGA running Linux 3.7. I'm trying to access a device tree that the kernel uses. I want to read the "reg" property of the following node:
Code:
memory@0 {
	device_type = "memory";
	reg = < 0x11000000 0x00080000
	  0x11085000 0x00000400
	  0x00000000 0x08000000>;
};
This is how the "reg" property shows up in the /proc file system:
Code:
root:/proc/device-tree/memory@0> hexdump -C reg 
00000000  17 03 00 21 26 f0 3f 20  17 00 40 81 26 f2 03 28  |...!&.? ..@.&..(|
00000010  17 01 c0 80 17 00 c0 89                           |........|
00000018
This doesn't look very meaningful to me. Where are my numbers 0x11000000 etc.? I also tried to read the property from a kernel module, like this:
Code:
dt_node = of_find_node_by_path("/memory@0");

struct property *pp;
u32 reg[6];
for_each_property_of_node(dt_node, pp) {
  printk("property name: %s, length: %d\n", pp->name, pp->length);
  if (pp->length == 24) {
    if (!of_property_read_u32_array(dt_node, pp->name, reg, 6))
	printk("reg: %x %x %x %x\n", reg[0], reg[1], reg[2], reg[3]);
  }
}
This gave the following output:
Code:
[ 1881.948000] property name: ���=, length: 7
[ 1881.948000] property name: &I>0�������1��, length: 24
[ 1881.948000] reg: 17030021 26f03f20 17004081 26f20328
[ 1881.948000] property name: name, length: 7
You can see that:
  1. Two property names are binary garbage, and there's a third property called "name" that's not in the device tree!?
  2. The "reg" property shows up exactly as in /proc/device-tree, but again, I can't make sense of the values.
What am I doing wrong?
 
Old 08-26-2013, 08:27 AM   #2
moo-cow
Member
 
Registered: Mar 2006
Distribution: Debian
Posts: 105

Original Poster
Rep: Reputation: 25
I found the most probable cause of the problem. After bootup the Linux kernel frees up memory that was used for initialization purposes and is not needed anymore, as the following kernel message shows:
Code:
Freeing unused kernel memory: 3828k freed (0xc026f000 - 0xc062c000)
And my kernel thinks that the device tree is not needed after bootup. Does anyone know how to tell the kernel to keep the device tree in memory? As a preliminary workaround, I compiled the driver code shown in my previous post into the kernel, and lo and behold, the binary garbage becomes plain text.
 
  


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
Reading Device Tree data (FDT/DTB) from kernel ashok449 Linux - Kernel 0 03-02-2012 04:51 AM
how to send events from kernel module to user space process yugandhar Linux - Kernel 2 02-21-2011 10:39 AM
LXer: Reading Files From The Linux Kernel Space (Module/Driver) (Fedora 14) LXer Syndicated Linux News 0 01-05-2011 07:00 AM
kernel module - write to user space mrshanim Linux - Kernel 5 12-31-2010 11:25 AM
[SOLVED] Does a kernel module run in kernel or user space? paliga Linux - General 4 10-31-2010 07:22 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration