cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Observer
Observer
943 Views
Registered: ‎06-01-2018

Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

Dear Community

I get a "Bus error" when using memcpy to copy 10 bytes from a local array to the On-chip memory (see code below):

int memfd = open("/dev/mem", O_RDWR | O_SYNC);
void* mapped_base_ocm = mmap(0, OCM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, OCM_BASE);
char buffer[256];
for (int i = 0; i < sizeof(buffer); i++) {
    buffer[i] = i;
}

// memcpy with non multiple of 8 bytes:
int length = 10;
memcpy(mapped_base_ocm, buffer, length);  // Error: "Signal 7: Bus error"

 

According to the TRM (technical reference manual) page 511, I take it that writing a non multiple of 8 bytes should be no problem:

"The OCM memory unit implements a read-modify-write operation to accommodate writes that are not 256 bits or unaligned to an 8 byte boundary."

  • I run the code on APU (Cortex A53) with Linux OS from Xilinx SDK (2018.2) in debug mode via TCF agent with no optimizations (-O0).
  • When I use a foor-loop to copy the 10 bytes byte-per-byte, it works without any problem.
  • Using memcpy to copy the 10 bytes to another location in RAM also works fine.
  • Using memcpy to read 10 bytes from OCM yields the same error.

Does anybody know why memcpy generates a bus error when not writing a multiple of 8 bytes to OCM?

Best Regards,
Simon

Tags (3)
0 Kudos
7 Replies
Highlighted
Xilinx Employee
Xilinx Employee
901 Views
Registered: ‎09-01-2014

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

memcpy is used for normal memory, please check your MMU setting of OCM, do you set it as a device?
0 Kudos
Highlighted
Observer
Observer
889 Views
Registered: ‎06-01-2018

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

Dear @ritakur 

Thanks for your reply.

I have to admit I'm a total beginner on this topic. Can you please tell me, where to find these settings?
(I have been looking in Vivado an BSP settings in SDK, but doesn't seem to be the right place.)

Best Regards
Simon

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
880 Views
Registered: ‎09-01-2014

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

If an address range is unknown to the Linux kernel (not in the memory node of the device tree).
These accesses are performed as device memory or strongly ordered to ensure no side effects.
So please check if your OCM memory range is set as reserved-memory in the device tree.
0 Kudos
Highlighted
Observer
Observer
871 Views
Registered: ‎06-01-2018

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

Thanks for the clarification.

At the moment I don't have time to dig into device tree settings and will use a simple for-loop instead of memcpy.
I will try your suggestion when I work on the device tree next time.

Best Regards
Simon

0 Kudos
Highlighted
Xilinx Employee
Xilinx Employee
862 Views
Registered: ‎02-01-2008

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

A while ago, I ran into issues with memcopy using baremetal (not Linux). It had to do with memcopy using SIMD instructions. I was able to get around the problem by aligning the target memory address. I'm not sure what your OCM_BASE is set to. If OCM_BASE is 64KB aligned (i.e. 0xFFFC0000) then your problem is not related to what I saw once upon a time.

0 Kudos
Highlighted
Participant
Participant
573 Views
Registered: ‎11-15-2017

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

Hi perhaps this should be a separate thread.  Please let me know if the community would be better served if this were posted as a separate question.

 

I am using a zynq RFSoC.  The PL design uses DMA to transfer ADC samples to PL DDR.  We have a UDP Dump routine that transfers the contents from PL DDR to a pbuf container using memcpy.  The ADC samples are the payload and get memcpy'd to the pbuf at an offset defined by the length of our protocol header.  (This happens to be 14bytes).

memcpy fails (I'm not a C expert so it's hard to say why...) when transferring the payload from PL DDR to the PBUF at offset 14 in the byte array. 

memcpy succeeds when transferring the payload from PL DDR to the PBUF byte array at offset 0

memcpy succeeds when transferring the payload from PL DDR to the PBUF byte array at offset 8

memcpy succeeds when transferring the payload from PL DDR to the PBUF byte array at offset 8*n

memcpy succeeds when transferring a "dummy" payload from PS DDR to the PBUF byte array at offset 14.

memcpy succeeds when transferring a "dummy" payload from PS DDR to the PBUF byte array at offset 0.

 

For now I am artificially inflating the header to end at a 8*n byte boundary.  Are you able to discuss why this only manifests when transferring from a PL AXI memory resource?

 

This is a baremetal FreeRTOS application.

 

Thanks,

Nick

 

0 Kudos
Participant
Participant
429 Views
Registered: ‎02-05-2019

Re: Zync Ultrascale+ MPSoC Bus Error on memcpy to OCM with non multiple of 8 bytes

Hi ritakur,

You mentioned setting the OCM memory range as "reserved-memory" in the device tree.  Do you have an example DTS file snippet showing such a configuration?

Also, if the OCM memory range (0xfffc0000 to 0xffffffff) is configured as "reserved-memory", would we still then access the OCM via /dev/mem and mmap()'ing it?

Thanks!

Regards,
Yu Fei

 

0 Kudos