UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Observer deepika07
Observer
1,983 Views
Registered: ‎05-15-2018

Read Write data from/to BRAM using LInux

I am using zc706 with ADFMCOMMS5

In my application, I used BRAM with AXI BRAM Controller which is connected to the ZYNQ Processor. I am able to read and write on the BRAM using SDK application project (standalone mode OS).

Now, I want to boot the system using Linux and communicate with BRAM in Linux.

When I searched, I found out that this can be done using mmap() function in C.

When I try to do that using mmap, it is not returning a valid address rather, it returns(-1).

Also, when I use AD9361 receiver (iio_buffer_refill in the loop) with this mmap function, the system crashes.

I have searched a lot but can't find the solution. 

0 Kudos
15 Replies
Moderator
Moderator
1,928 Views
Registered: ‎12-04-2016

Re: Read Write data from/to BRAM using LInux

Hi @deepika07

 

See if this wiki is of help, which ideally discusses on accessing bram in linux

http://www.wiki.xilinx.com/Accessing+BRAM+In+Linux

 

 

Best Regards

Shabbir

0 Kudos
Observer deepika07
Observer
1,906 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @shabbirk

 

I referred to this wiki already but as I told you the mmap is returning (-1) and not the mapped address.

Also, devmem( as described in the wiki itself) is not working

0 Kudos
Adventurer
Adventurer
1,901 Views
Registered: ‎07-31-2017

Re: Read Write data from/to BRAM using LInux

My app uses mmap:

 

   smem_fd = open("/dev/mem", O_RDWR|O_SYNC);

   // void *mmap(void *addr, size_t length, int prot, int flags,  int fd, off_t offset);
   // length, offset must be page size (4096) aligned.
   p_ shmem = (uint8_t *)mmap( NULL, MY_MMAP_TOTAL_SIZE,  PROT_READ|PROT_WRITE, MAP_SHARED, smem_fd, MY_MMAP_START);

 

Make sure you specify the BRAM memory range in the device tree and also adjust Linux's memory in the device tree to not overlap with BRAM.  You can't mmap memory that belongs to Linux.

 

Observer deepika07
Observer
1,884 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @kallensf

I think what you said might solve the problem.

Can you please tell me how can I modify the device tree? I am very new to this system.

Here is what I did:

int fd = open ("/dev/mem", O_RDWR | O_SYNC);

int *base = mmap(0x40000000, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd, NULL);

printf("base = %d\n", base);

 

I am getting base = -1

0 Kudos
Observer deepika07
Observer
1,859 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @shabbirk

 

This might be a very stupid question but I am not getting it.

In this wiki http://www.wiki.xilinx.com/Build%20Device%20Tree%20Compiler%20%28DTC%29

Screenshot (754).png

Where am I suppossed to run the make command? It says all commands have to be run in your dtc source directory (which I think is ./linux-xlnx/scripts/dtc ) I am using windows and tried to run make in git bash in this directory but it says "make: command not found".

0 Kudos
Moderator
Moderator
1,841 Views
Registered: ‎12-04-2016

Re: Read Write data from/to BRAM using LInux

Hi @deepika07

 

You need to first clone the dtc source from https://git.kernel.org/pub/scm/utils/dtc/dtc.git

 

And then run the make command

 

 

Best Regards

Shabbir

0 Kudos
Observer deepika07
Observer
1,823 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @shabbirk

I cloned the dtc source already. But when I run the make command I am getting these errors.

CMD.PNG

I am following the wiki but keep getting stuck at some or the other place. I can't figure out what to do with these errors.

I opened cmd from SDK because when I used windows command promt directly "make" is not a recognised command for cmd.

0 Kudos
Observer deepika07
Observer
1,794 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @kallensf

 

I did what you said. I added axi bram controller to the device tree and it is not overlapping with Linux's memory.

Still, when I try to execute mmap it is returning (-1). Can you suggest a what can be reason for this?

0 Kudos
Scholar vanmierlo
Scholar
1,772 Views
Registered: ‎06-10-2008

Re: Read Write data from/to BRAM using LInux

I suggest to start with getting devmem to work first. Are you running it with root privileges?

0 Kudos
Adventurer
Adventurer
1,511 Views
Registered: ‎07-31-2017

Re: Read Write data from/to BRAM using LInux

A compare of the arguments shows that I specify the BRAM address in the offset arg:

 

mmap( NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED, fd,  0x40000000  );

 

In petalinux bsp:  project-spec\meta-user\recipes-bsp\device-tree\files\system-user.dtsi

 

   memory {
      device_type = "memory";
      reg = <0x0 0x0 0x0 0x40000000 0x0 0x50000000 0x0 0x80000000>;
   };

 

reg = <0x0 0x0 : start at address  0x0 (64 bit)

0x0 0x40000000 : length of x40000000 (64 bit) bytes

0x0 0x50000000 : continue at address 0x50000000 (64 bit)

0x0 0x30000000>;   : length of x30000000 (64 bit) bytes

 

 

 

0 Kudos
Scholar vanmierlo
Scholar
1,493 Views
Registered: ‎06-10-2008

Re: Read Write data from/to BRAM using LInux

You have 768 MB in Block RAM's? Where did you buy this device?

 

By placing the BRAM memory in the device-tree memory node, you allow linux to use it!

And it will assume no overlaps!

And when linux uses it you cannot mmap it for your own purpose anymore.

0 Kudos
Newbie mugdhaj17
Newbie
1,418 Views
Registered: ‎09-07-2018

Re: Read Write data from/to BRAM using LInux

I and @deepika07 are working on the same project.

In continuation to last topic,

mmap() function is returning valid address now. I am writing new data on the first location of the mapped memory in the same C script(following the link:http://www.wiki.xilinx.com/Accessing+BRAM+In+Linux).

How should I verify that the data has been written on the first location of BRAM memory?

One way which I found was to use devmem2 command(running on terminal:sudo devmem2 <first location of physical address>), but Linux freezes by doing so.

0 Kudos
Observer deepika07
Observer
1,389 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

@vanmierlo Thanks!

I solved that issue, now I am using root privileges. But now I am unable to write to the mapped address. It is giving some finite value (base = b6f23000 in my case). But when I use base[0] = "some data" it gives the Bus error.

According to what I found out, the bus error occurs when we try to access the memory address which does not exist. That should not be a case as this address is returned by mmap itself.

How can this be solved?

0 Kudos
Scholar vanmierlo
Scholar
1,377 Views
Registered: ‎06-10-2008

Re: Read Write data from/to BRAM using LInux

What happens if you use devmem on the command line to access the physical address? If that fails as well, you have not connected the RAM correctly.

0 Kudos
Observer deepika07
Observer
1,333 Views
Registered: ‎05-15-2018

Re: Read Write data from/to BRAM using LInux

Hi @vanmierlo

I am not able to use the devmem still. "devmem command not found." I am not getting the bus error anymore. The program executes smoothly as long as I try to write on the correct memory address. But as devmem is not working I am not able to check if the data is actually written on the memory space or not. I am trying to use the data in my PL side code to confirm this. But it seems that the data is not written actually or may be deleted because of the PL side code. Is there any other way to check this? Meanwhile, I am trying to check if the fault is at the PL side.

0 Kudos