cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
joseer
Voyager
Voyager
723 Views
Registered: ‎07-06-2016

File operations XSDK application segmentation violation

Jump to solution

Hello,

I'm trying to work with UIO driver to control some IP registers from my sdk application in debug mode.

The test application runs well regarding memory registers access, I can read and write properly from the uio mapped addresses.

Also from the console I can write the 'cat' command to query the uio device features, as name, size...etc. e.g: "cat /sys/class/uio/uio0/maps/map0/size" will return 0x1000.

I'd like to be able to get this info. in my sdk application too, but when I run the following piece of code as soon as it tries to open the file (in red) it returns a segmentation violation:

    int fd;
    FILE *sizefd;
    char *uiod = "/dev/uio0";
    void *uiodptr;
    unsigned int size;
    
    
    // open the UIO device file to allow access to the device in user space
    fd = open(uiod, O_RDWR);
    if (fd < 1) {
        printf("Invalid UIO device file:%s.\n", uiod);
        return -1;
    }

    // mmap device into user space
    uiodptr =mmap(NULL, 0x10000, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    if (uiodptr == MAP_FAILED) {
        printf("Mmap call failure.\n");
        return -1;
    }
    printf("baseAddress: 0x%x\n", uiodptr);

    //set IP parameters
    *((volatile unsigned *)(uiodptr + ACTIVE_WIDTH)) = 0x500;
    *((volatile unsigned *)(uiodptr + ACTIVE_HEIGHT)) = 0x400;
    *((volatile unsigned *)(uiodptr + CONTROL)) = 0x81;

    sizefd = fopen("/sys/class/uio/uio0/maps/map0/size", O_RDONLY);
    if (sizefd < 1)
    {
    	printf("uio error size access \n");
        return -1;
    }
    
    fscanf(sizefd, "0x%08X", &size);
    printf("The size is: %d\n", size);

    munmap(uiodptr, 4096);
close(sizefd); close(fd);

The error:

error.jpg

I tried to search for the file "fileops.c" but I couldn't find it anywhere.

Any ideas why I'm getting this error? 

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
joseer
Voyager
Voyager
605 Views
Registered: ‎07-06-2016

@archangel-lightworks  thanks for your answer, 

I managed to solve the problem, I finally found the fileops.c file in the generated sdk folder (petalinux-build --sdk) and got it working using the function:

sizeFd = fopen("/sys/class/uio/uio0/maps/map0/size", "r");

 

 

 

View solution in original post

0 Kudos
5 Replies
706 Views
Registered: ‎07-23-2019

What I don't understand is why your compiler has a hardcoded path for a source c file 

0 Kudos
joseer
Voyager
Voyager
694 Views
Registered: ‎07-06-2016

Hi @archangel-lightworks , thanks for your answer,

I'm not sure if I follow you,  what would it be the correct path?

0 Kudos
joseer
Voyager
Voyager
635 Views
Registered: ‎07-06-2016

Nobody has an idea on this? wouldn't be possible to do file operations from sdk application?

0 Kudos
617 Views
Registered: ‎07-23-2019

You may be missing a library for io, check the warnings.

Have a look at iofopen.c line 86, where it calls something in the missing file, it looks like. Check the includes, anyone missing/ commented out?

0 Kudos
joseer
Voyager
Voyager
606 Views
Registered: ‎07-06-2016

@archangel-lightworks  thanks for your answer, 

I managed to solve the problem, I finally found the fileops.c file in the generated sdk folder (petalinux-build --sdk) and got it working using the function:

sizeFd = fopen("/sys/class/uio/uio0/maps/map0/size", "r");

 

 

 

View solution in original post

0 Kudos