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: 
Adventurer
Adventurer
4,880 Views
Registered: ‎05-07-2012

Using code to copy the bin file to xdevcfg instead of cat fails.

    char buff[4096]; // devcfg driver can't handle huge writes
    do {
        fpga_file.read(buff, sizeof(buff));
printf("Read chars %d\n", fpga_file.gcount());
        xdev_file.write(buff, fpga_file.gcount());
        xdev_file.flush();
    } while (fpga_file);

 I'm using this code fragment to copy the fpga binfile into the xdevcfg driver. The wierd thing is that cat foo.bin > /dev/xdevcfg works fine, but this code doesn't. I've cehcked that the code sends the write stuff to the file by changing the output file name and md5suming the output. I've also tried a few different buffer sizes.

 

Does anyone have any idea why this jsut doesn't work? (yes the files are openedin in binery mode)

0 Kudos
5 Replies
Scholar milosoftware
Scholar
4,867 Views
Registered: ‎10-26-2012

Re: Using code to copy the bin file to xdevcfg instead of cat fails.

Works fine here (though with plain C code).

 

Only difference I see is that I never flush() and I use 32k blocks instead of 4k ("cat" tends to use 32k buffer too).

 

I assume your C++ file wrappers will close() the file in the destructor?

0 Kudos
Adventurer
Adventurer
4,862 Views
Registered: ‎05-07-2012

Re: Using code to copy the bin file to xdevcfg instead of cat fails.

32768 didn't work either.

 

What promgen command are you running?

 

I need to try a c version, or inserting some printk's to get an idea what is going on at the driver level :(

0 Kudos
Scholar milosoftware
Scholar
4,859 Views
Registered: ‎10-26-2012

Re: Using code to copy the bin file to xdevcfg instead of cat fails.

Maybe post the rest of the code? The more important parts are missing, like the open() and close() calls.

 

Maybe you open the device for read+write access, which might make the driver expect you want to read the logic instead of writing it.

0 Kudos
Adventurer
Adventurer
4,849 Views
Registered: ‎05-07-2012

Re: Using code to copy the bin file to xdevcfg instead of cat fails.

So it looks like the problem is iostream ends up using writev to write to /dev/xdevcfg. xdevcfg barfs on this (ENONMEM or something like that).

 

Converting to fwrite seems to have solved the problem.

0 Kudos
Scholar milosoftware
Scholar
4,832 Views
Registered: ‎10-26-2012

Re: Using code to copy the bin file to xdevcfg instead of cat fails.

Figures, "writev" requires the driver to implement that call, which many simple char devices won't do.

 

On a side note, thanks for the reminder to avoid iostream :)

 

You might be able to use "sendfile()" to program the logic, I haven't experimented with that. That would get rid of the kernel->user->kernel transition.

0 Kudos