[coreboot] Dynamic detection of Parallel Port

Joseph Smith joe at settoplinux.org
Sat Dec 6 20:35:28 CET 2008




On Sat, 06 Dec 2008 13:51:28 -0500, Joseph Smith <joe at settoplinux.org>
wrote:
> 
> 
> 
> On Sat, 06 Dec 2008 13:07:06 -0500, Joseph Smith <joe at settoplinux.org>
> wrote:
>>
>>
>>
>> On Sat, 6 Dec 2008 09:49:32 -0800, "ron minnich" <rminnich at gmail.com>
>> wrote:
>>> you're making it too hard. :-)
>>>
>>> If you do this:
>>>  awk '/rtc/{print $1}'
>>>
>>> you get a line like this:
>>> cat /proc/ioports | awk '/rtc/{print $1}'
>>> 0070-0071
>>>
>>> OK, but you just want the first four digits, right? Well, strtoul will
>>> do this for you, so:
>>> port = strtoul(string, 0, 16);
>>>
>>> it will stop at the '-', which is not hex. Problem solved.
>>>
>>> But how do I get this into a program?
>>>
>>> paraflash `awk '/rtc/{print $1}'`
>>>
>>> First arg will be the port addresses.
>>>
>>> Instead of 'rtc', use whatever your parallel port name is.
>>>
>>> Did you want more than one? Here's another example:
>>> [rminnich at xcpu2 coreboot-v3]$ echo `cat /proc/ioports | awk
>> '/ahci/{print
>>> $1}' `
>>> 1c20-1c3f 1c40-1c43 1c44-1c47 1c48-1c4f 1c50-1c57
>>> [rminnich at xcpu2 coreboot-v3]$
>>>
>>> So your program will see a sequence of arguments, one for each parallel
>>> port.
>>>
>>> You don't have to do it exactly this way, but this is why we have all
>>> these fiddly little tools, so you can put things together without
>>> having to write lots of code.
>>>
>>> If you don't want users to see this commnand, use popen(3).
>>>
> So, to get the command into the program wouldn't I use system() ?
> 
> Something like:
> base_addrs = system("cat /proc/ioports | awk '/paraport*{print $1}'");
> 
> para1_base_addr = strtoul(base_addrs, 0, 16);
> 
> This should get the firsts parallel ports base address, right? What if I
> want to get the base address of the second parallel port, can I use
> strtoul() to skip to the next set of char after the whitespace?

I think I got it:

unsigned long * next;
para1_base_addr = strtoul(base_addrs, &next, 16);
para2_base_addr = strtoul(next, &next, 16);
para3_base_addr = strtoul(next, 0, 16);

right?

-- 
Thanks,
Joseph Smith
Set-Top-Linux
www.settoplinux.org





More information about the coreboot mailing list