08-14-2018 01:05 PM
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.
08-16-2018 02:53 AM
08-17-2018 07:07 AM
08-17-2018 11:27 AM - edited 08-17-2018 11:28 AM
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.
08-18-2018 02:11 AM - edited 08-18-2018 02:21 AM
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
08-19-2018 06:09 AM
This might be a very stupid question but I am not getting it.
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".
08-20-2018 12:12 AM
08-21-2018 12:20 AM
I cloned the dtc source already. But when I run the make command I am getting these errors.
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.
08-23-2018 05:31 AM
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?
08-23-2018 04:36 PM - edited 08-23-2018 04:49 PM
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
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
08-24-2018 01:28 AM
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.
09-07-2018 05:43 AM
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.
09-11-2018 06:47 AM
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 = "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?
09-12-2018 04:37 AM
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.
09-17-2018 03:41 AM
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.