Converting SW to Linux

Hi, My current software is for an embedded system, running VxWorks OS, on PPC860. I need to convert it to Linux. The HW is memory mapped, and in VxWorks I just write or read from specific addresses to access the HW device. How should I implement it in Linux? I am thinking about writting a char device. Is it the right choice? If so, is there a sample code for such a char device?

Thanks.

Reply to
Rami
Loading thread data ...

I lately attended a speech by SysGO. They clime to supply tools to convert VxWorkx projects to Linux.

I did not check into this further.

-Michael

Reply to
Michael Schnell

One option would be to write a driver that impliments mmap() by mapping the device's address range to user-space.

It's what I'd do to start with.

I wrote a driver demonstrating just that a long time ago:

ftp://ftp.visi.com/users/grante/stuff/demomm.tar.gz

That driver assumes the device is on the PCI bus and uses PCI calls to obtain the address range for the memory-mapped HW. IIRC, that was back around 2.0/2.2, so don't expect it to compile...

--
Grant Edwards                   grante             Yow!  My DIGITAL WATCH
                                  at               has an automatic SNOOZE
                               visi.com            FEATURE!!
Reply to
Grant Edwards

Well, you *can* do it the same way. All you need to do in addition to what you did on vxWorks is to map the device's registers using mmap() (*). What you can *not* do from user space is handle interrupts. Also, note that your program needs to run as root and that this is a huge security hole (as it is in vxWorks).

Definitely. However, porting vxWorks code that was designed with a "we-can-access-any-hardware-directly-as-we-please" mindset can be tedious. In most cases, you'll need to design a whole new interface between what remains in the application and what goes into the driver. The art is to get this interface small, efficient and yet comprehensive.

So many that it is hard to pick a suitable example. Best start probably is to read "Linux Device Drivers" by Corbet & Rubini. AFAIK, this book is also available as PDF for free download (try google).

HTH

Rob

(*) A long time ago I wrote two small programs (called "peek" and "poke", ever programmed in BASIC ;-)) that allow you to inspect/modify arbitrary memory locations including HW registers. Drop me a mail if you're interested and I'll send you the source code.

--
Robert Kaiser                     email: rkaiser AT sysgo DOT com
SYSGO AG                          http://www.elinos.com
Klein-Winternheim / Germany       http://www.sysgo.com
Reply to
Robert Kaiser

I don't recall any restriction on mmap() only being usable from programs run as root. It's been a couple years since I did a lot with mmap, but I'm pretty sure I ran my apps as a normal user. The mmap(2) man page doesn't mention any requirement to be root either.

--
Grant Edwards                   grante             Yow!  .. someone in DAYTON,
                                  at               Ohio is selling USED
                               visi.com            CARPETS to a SERBO-CROATIAN
Reply to
Grant Edwards

Reply to
Ed Skinner

... and I should add that, unless things have changed, the /dev/kmem driver imposes this security requirement not via the normal permissions you might see on the device node. Instead, it is implemented in the driver itself so "chmod" and "chown" won't bypass the root check.

Reply to
Ed Skinner

This probably refers to the vxWorks to Linux migration library which has been integrated into our embedded Linux suite "ElinOS". It provides an API that maps VxWorks functions to Linux ones. It simplifies porting efforts a lot, but unfortunately it does not cover the OP's problem of accessing HW registers from application programs directly.

Then, there is also the possibility of creating a vxWorks server to run alongside Linux on our soon-to-be-released microkernel-based multi-OS platform "PikeOS" (see

formatting link
That would allow a vxWorks system to coexist with Linux in the same machine. However, I'm afraid such a server is not likely to be available in the near future.

Rob

--
Robert Kaiser                     email: rkaiser AT sysgo DOT com
SYSGO AG                          http://www.elinos.com
Klein-Winternheim / Germany       http://www.sysgo.com
Reply to
Robert Kaiser

Right. I wasn't thinking about /dev/kmem. When I've done things with memory mapped I/O devcies, I wrote a driver that implimented mmap() to allow user-space process to map the device into memory. That allows you to set the ownership and protection of the device appropriately. Using kmem is a bit dangerous.

--
Grant Edwards                   grante             Yow!  I want to dress you
                                  at               up as TALLULAH BANKHEAD and
                               visi.com            cover you with VASELINE and
                                                   WHEAT THINS...
Reply to
Grant Edwards

Thank you.

I have only 4 address of HW mapped in my system. Is using ioctl(), instead of mmap(), a better choice in my case? Will it solve the above root problem?

Thanks.

Reply to
Rami

How would we know? We have no idea what sort of device it is and what sort of operations you do upon it. Perhaps ioctl() is the best solution, perhaps mmap() is.

In order to use ioctl() you'll have to write a driver. If you write a driver, you can just as easily impliment mmap(). If you write a driver you'll have the exact same permissions for mmap() that you will for ioctl().

--
Grant Edwards                   grante             Yow!  .. I think I'd
                                  at               better go back to my DESK
                               visi.com            and toy with a few common
                                                   MISAPPREHENSIONS...
Reply to
Grant Edwards

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.