AnsweredAssumed Answered

Writing data to UIO device causes linux system to crash!

Question asked by FivePandaH on Jan 24, 2018
Latest reply on Jan 29, 2018 by FivePandaH

Hi, 

I add a custom axi4-lite interface ip to the 2017_R1 ad2965_fmc project, everything works right except the uio access.

I modified the devicetree like below:

 

fpga_axi: fpga-axi@0 {
compatible = "simple-bus";
#address-cells = <0x1>;
#size-cells = <0x1>;
ranges;

axi_spi_sja102_0: axi_spi_sja102@43c00000 {
#address-cells = <1>;
#size-cells = <1>;
compatible = "dmem-uio";
interrupts = < 0 29 0 >;
interrupt-parent = <&intc>;
reg = <0x43c00000 0x1000>;
xlnx,s00-axi-addr-width = <0x8>;
xlnx,s00-axi-data-width = <0x20>;
};

  

After the linux system boot, I can find the dev/uio0 device, the C++ code is shown below:

 

#define UIO_DEV "/dev/uio0"
#define UIO_ADDR "/sys/bus/platform/devices/43c00000.axi_spi_sja102/uio/uio0/maps/map0/addr"
#define UIO_SIZE "/sys/bus/platform/devices/43c00000.axi_spi_sja102/uio/uio0/maps/map0/size"

 

 

int Send_Command(int address, int value)
{
int uio_fd, addr_fd, size_fd;
int uio_size;
void *uio_addr, *access_address;
char uio_addr_buf[16], uio_size_buf[16];


//1.open related files
uio_fd = open(UIO_DEV, O_RDWR);
addr_fd = open(UIO_ADDR, O_RDONLY);
size_fd = open(UIO_SIZE, O_RDONLY);
if( addr_fd < 0 || size_fd < 0 || uio_fd < 0)
{
exit(-1);
return -1;
}
else;

//2.read address and size information to buffer
read(addr_fd, uio_addr_buf, sizeof(uio_addr_buf));
close(addr_fd);
read(size_fd, uio_size_buf, sizeof(uio_size_buf));
close(size_fd);

//3.conversion strings to the long int 
uio_addr = (void*)strtoul(uio_addr_buf, NULL, 0);
uio_size = (int)strtol(uio_size_buf, NULL, 0);

//4.device adress map to kernel
access_address = (char *)mmap(NULL, uio_size, PROT_READ | PROT_WRITE, MAP_SHARED, uio_fd, 0);
if ( access_address == (void*) -1)
{
//printf("address map error!\n");
exit(-1);
return -1;
}

//5.write data to file
*(int*)(access_address+sizeof(int)*address) = value;

//6.save data
munmap(access_address, uio_size);
close(uio_fd);

usleep(5);
return 0;

}

 

When debug to the red line, the system crashed! 

Who can give some help?

Outcomes