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: 
Visitor parampampam
Visitor
6,683 Views
Registered: ‎11-26-2014

Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

Hello, everyone.

 

I want to turn on LEDs on my ZedBoard using a Linux application, but my app freezes when it try to write to a physical memory. This is my code:

int main(int argc, char *argv[])
{
	unsigned int devAddr = 0x41200000;
	unsigned int pageSize = sysconf(_SC_PAGESIZE);
	unsigned int pageAddr = (devAddr & (~(pageSize - 1)));
	unsigned int pageOffset = devAddr - pageAddr;

	int fd = open("/dev/mem", O_RDWR);
	void* ptr = mmap(NULL, pageSize, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, pageAddr);

	if (ptr == NULL)
	{
		printf("Can't map memory\n");
		return -1;
	}

	unsigned int* devPtr = (unsigned int*)(ptr + pageOffset);

	devPtr[0] = 0xAAAAAAAA;
	devPtr[2] = 0xAAAAAAAA;
	munmap(ptr, pageSize);
	return 0;
}

 It halts on "devPtr[0] = 0xAAAAAAAA".

 

I performed following steps:

1. Ran ArchLinux on ZedBoard

2. Wrote bitstream via JTAG

3. Ran my application

 

Also I tried to write to the memory via U-Boot (mw.l 0x41200000 0xAAAAAAAA), but I had the same result.

 

You can see a structure of my system on the attached screenshots.

 

Thanks in advance.

Скриншот 2015-01-11 20.13.59.png
Скриншот 2015-01-11 20.14.07.png
0 Kudos
1 Solution

Accepted Solutions
Highlighted
Visitor parampampam
Visitor
10,923 Views
Registered: ‎11-26-2014

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

The problem is solved. I used cat bitsstream.bit > /dev/xdevcfg on PS instead of writing my bitstream by JTAG. It works on ArchLinux. Thanks for your replies. 

0 Kudos
6 Replies
Explorer
Explorer
6,645 Views
Registered: ‎02-16-2014

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution
mem_fd = open("/dev/mem", O_RDWR|O_SYNC);
if (mem_fd < -1)
{
    printf("TestApp: Error opening mem_fd for writing.\n");
    return -1;
}

uint32_t* gpio_addr = (uint32_t*)mmap(0, 64*1024, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, 0x41200000);
if (gpio_addr == 0)
{
    printf("TestApp: mmap() failed.\n");
    return -2;
}

*(volatile uint32_t*)(gpio_addr + 0) = 0x01;

 

Most likely it's your hardware desing. Hard to say what exactly - your block diagram looks fine to me. But it could be a problem with a clock settings or your custom module.

 

Also, code above works for me.

0 Kudos
Scholar norman_wong
Scholar
6,638 Views
Registered: ‎05-28-2012

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

If it was u-boot fail and linux works, it would be translation table setting in the FSBL. In your case, it might be what user "vanmierlo" found in this thread:

http://forums.xilinx.com/t5/Embedded-Linux/Zynq-Bus-Error-on-mmap-ed-io/td-p/354271

User "vanmierlo" found that it is not allowed to use two different clocks on both sides of the BRAM. He changed them both to use FCLK_CLK0 and got it to work.

0 Kudos
Visitor parampampam
Visitor
6,626 Views
Registered: ‎11-26-2014

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

I tried the code of fanat9, but got the same result.

 

>But it could be a problem with a clock settings or your custom module.

>User "vanmierlo" found that it is not allowed to use two different clocks on both sides of the BRAM.

At first I tried a default Vivado design for ZedBoard without any custom IPs and external clocks. I had the same freeze in the app.

 

Can this problem be connected with writing the bitstream when the linux is running? I can't write the bitstream and reboot the linux because the first stage bootloader rewrites my bitstream.

0 Kudos
Visitor parampampam
Visitor
6,594 Views
Registered: ‎11-26-2014

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

I tried to use a Linux from SD-card supplied with ZedBoard. I got "segmentation fault" with default bitstream. Then I attempted to write my bitstream by JTAG. The linux rebooted and the FSBL rewrote my bitstream by a default one. Is there any way to test my bitstream without rewriting QSPI Flash?

0 Kudos
Highlighted
Visitor parampampam
Visitor
10,924 Views
Registered: ‎11-26-2014

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

The problem is solved. I used cat bitsstream.bit > /dev/xdevcfg on PS instead of writing my bitstream by JTAG. It works on ArchLinux. Thanks for your replies. 

0 Kudos
Participant bpb
Participant
935 Views
Registered: ‎09-11-2016

Re: Linux freezes when it writes to physical memory (Zynq-7000, ArchLinux)

Jump to solution

@parampampam the real problem is that you're using MAP_PRIVATE. Try MAP_SHARED instead.

0 Kudos