I've been looking into UTP and am currently trying to experiment with an implementation in Linux. With a few hints from the source code of Mfg tool and documents in various versions of Mfg tool I've put together the following code to generate a poll command:
struct __attribute__ (( packed )) utp_cmd { uint8_t oc; uint8_t cmd; uint32_t tag; uint64_t lparam; uint8_t res[2]; }; struct utp_cmd poll = { .oc = 0xf0, .cmd = 0x00, .tag = 0x1, .lparam = 0, };
I then put together the data to pass to sg like this:
uint8_t sbuf[128]; struct sg_io_hdr scsi_hdr = { .interface_id = 'S', .timeout = 2000, .cmdp = (unsigned char *)&poll, .cmd_len = sizeof(struct utp_cmd), .sbp = sbuf, .mx_sb_len = 128, .dxfer_direction = SG_DXFER_TO_DEV, };
Then I pass it all off to sg like this:
int res = ioctl(dev, SG_IO, &scsi_hdr);
This fails though though with the rather cryptic error "Bad address" (errno
set to 14). Anyone who's encountered this and solved it already?
Solved! Go to Solution.
Hi Magnus
frankly speaking I never heard about such efforts.
Best regards
chip
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I find it very unfortunate that Freescale cares so little for software developers that it only provide tools for legacy OSs :smileywink:
Kidding aside. The issue above was solved after a bit of wider searching online. The error message, "Bad address", is particularly misgiving since the issue actually is one of missing permissions. For raw access to the SCSI device one needs CAP_SYS_RAWIO (see e.g. http://lwn.net/Articles/542327/). So I got it all working when running my code as root. I now have non-IO command in UTP working, and I'm about to add command with IO. All using the sgutils library via Haskell :smileygrin:.