LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-29-2007, 06:35 PM   #1
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Rep: Reputation: 15
Use main CPU as microcontroller


Ive been reading Linux Appliance Design by Bob Smith, and have a question about something that was mentioned, but not covered at all in the book.
It was talking about using a microcontroller to control something such as a front panel display so you can show the progress of your appliance while its booting.
This is all it says, "An alternative (to a microcontroller) is to carve out a piece of the main CPU to use as a microcontroller while Linux is starting. You can modify the boot leader to set up a timer interrupt and use the interrupt handler to provide a front panel UI. You'll need to modify Linux so that it does not touch the timer or interrupt handler while booting. Once Linux is running, it can take over the timer and interrupt, making the front panel hardware just another device that it manages. This technique describes a form of virtual machine; as they become more popular, you may find that a VM provides all the hooks necessary to be used as an I/O controller."

Obviously I don't know what to search for on google. The only things I have found are the book itself that Im reading, and lots of info about microcontrollers.
Has anyone done this before? Maybe they could point me to a few resources? Im not looking for a how-to on here :P Just where I need to go to learn it for myself.

Thanks!!
 
Old 10-30-2007, 09:35 AM   #2
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
Haven't done it before, but the idea isn't complicated in nature, but would take a good deal of effort for the average person to implement. You'll need some good Linux internals knowledge, PC hardware (low-level programming & hardware control) knowledge, etc.
 
Old 10-30-2007, 12:58 PM   #3
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Original Poster
Rep: Reputation: 15
Effort, I've got plenty of that. Knowledge, maybe not so much. But as much as I want to do this, I think it will be a great chance for me to learn more about Linux in the process.
Back to the lack of knowledge... I just don't know where to start. The book was no use other than enticing me to want to try this.
 
Old 10-31-2007, 08:20 AM   #4
Dox Systems - Brian
Member
 
Registered: Nov 2006
Posts: 344

Rep: Reputation: 31
Go grab some books about x86 assembly language, system internals (programming side), and linux internals. :-)
 
Old 11-01-2007, 08:04 PM   #5
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,477

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Why so complicated?

Write a controller program in Linux and run it. Linux is multitasking... so what?

It doesn't have guaranteed response times, but on an ordinary PC but delays are usually in the ms range, which makes it good enough for almost anything.

jlinkels
 
Old 11-02-2007, 03:36 AM   #6
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,434

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
The OP states 'use as a microcontroller while Linux is staring'. That mean it must be code which is part of or run by the bootloader before the kernel is ready to do anything.
 
Old 11-02-2007, 09:04 AM   #7
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,477

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Yes, I read that. Why would one want to do that?
 
Old 11-02-2007, 10:40 AM   #8
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,434

Rep: Reputation: 303Reputation: 303Reputation: 303Reputation: 303
I agree that the idea is rather farfetched. I suppose that the writer of the book didn't give any examples of doing this for the same reason.
 
Old 11-02-2007, 10:59 AM   #9
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,477

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
Hmm, maybe I understand it... it seems as if during boot-up of the "real" controller, a separate process is running during boot (so it is there almost instantaneously after power-on) which gives the user information about the appliance's state. After the "real" controller boot process is completed, the "real" controller would take over.

I still think it is very complicated.

jlinkels
 
Old 11-03-2007, 07:35 PM   #10
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Original Poster
Rep: Reputation: 15
hmm... didn't get any emails about the new posts.
Thanks for all the comments about it. No, there are no examples at all in the book. That quote was it. Just enough to tease but no references on where to go.
And yes, the purpose is just as jlinkels said, to give the user that comforting feeling that something is going on.
I have an LCD panel, a CrystalFontz CF-635 that I'm using as the front panel for an Asterisk box. Using PERL to show some basic system info, things like that.
It would be nice to have the LCD update with some boot info during the boot, and this just seemed like a really interesting, if not implausible way to go about doing it.
Maybe a better idea would be to write a driver for the display and redirect the boot messages to it? Not that I know how to do that :P
Suggestions?
 
Old 11-03-2007, 08:34 PM   #11
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 64
Quote:
Originally Posted by DeltaXFX View Post
Using PERL to show some basic system info, things like that.
It would be nice to have the LCD update with some boot info during the boot, and this just seemed like a really interesting, if not implausible way to go about doing it.
Maybe a better idea would be to write a driver for the display and redirect the boot messages to it? Not that I know how to do that :P
Suggestions?
If you are able to use perl to write text to it, there is already a driver for it. From a quick websearch, it seems to be a generic UART-over-usb driver. In that case, to send bootup messages to the display you would need to do a couple things:
  1. Compile the driver into your kernel as built-in (not a loadable module).
  2. Through your bootloader, load your kernel with the extra parameter “console=ttyUSB0
You may have to adjust the number, and also the baud/parity as specified here.
 
Old 11-03-2007, 08:37 PM   #12
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 64
On second thought, this may not be such a good idea. The text will most likely scroll by too fast to read. An 80-character console line will take up an entire screenful.
 
Old 11-03-2007, 08:48 PM   #13
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 112Reputation: 112
While what the author is talking about could certainly be done, there is a piece he didn't bother to mention.

Basically, to do this, you have to treat the CPU as a bare processor with no operating system in it. You then write an assembler routine that runs in the system along with the linux boot loader (and, after a few seconds, along with Linux). This assembler routine takes over a timer (and prevents Linux from getting it as part of the boot process), and does the UI things you want to do with your appliance front panel.

Keep in mind that this assembler routine cannot access any libraries because there are no libraries available to access (no OS, remember?). You have no SDK to help you. You have to set your own stack, you have to create your own low-level interrupt service routine to respond to the timer. You have to load your code someplace in RAM where Linux won't interfere with it, you have to know exactly where it is, and your interrupt service routine has to properly invoke it. Probably, this is where you modify grub so that it will start your routine before it starts Linux.

After Linux is up and running (and your assembler routine is checking for this, somehow), your routine exits and passes control to Linux which then uses its own driver (which you have also written, but this is the easy part) to handle your appliance.

This is certainly possible.

It would be a royal b*tch to do, and the utility would be very limited.
 
Old 11-03-2007, 09:02 PM   #14
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Etch/Lenny/Squeeze
Posts: 3,477

Rep: Reputation: 308Reputation: 308Reputation: 308Reputation: 308
When were in this position, I would try to optimize the boot process as much as possible. Perhaps the boot device is solid state, which is much faster than disk. It must be possible to cut out every unnecessary action during booting, especially actions which require a lookup of something with an associated time-out. (hardware detection, DHCP, DNS lookup) If needed, those actions can be inserted later when the system is already running. Is the kernel stored in compressed form? Is that really needed (by kernel design?) There is nothing magic about booting which makes it so slow, as soon as the kernel is loaded and running it should be possible to display your messages using the normal screen driver. Would 5 seconds be realistic?

jlinkels
 
Old 11-03-2007, 09:17 PM   #15
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Original Poster
Rep: Reputation: 15
Thanks jiml8. Suddenly this sounds like a horrible idea :P

osor, I use the Device::SerialPort perl module to write to it. The only problem with that is you have to specify what line you want the text to display on. Plus you have to add a CRC to the data you send to the LCD.

At any rate, just redirecting the console to the LCD would be terribly messy I think, either having to truncate every line to 1/4 of the text, or fill the entire LCD with each line from the console.

jlinkels, optimization is where I am headed now. I was using trixbox for Asterisk, which is based on CentOS. I hope no one takes offense, but CentOS has a huge footprint (almost 2GB for a fresh install, the trixbox installer does not let you choose packages) and seems terribly cumbersome for the task. I am in the process of switching it over to Arch. I am already using a SSD for the drive, albeit a very slow one, but this is just for testing the setup at the moment. I would be happy with ~15 second boot. I read somewhere, I think it was that Appliance Design book I have, that talks about getting the system configured how you want it to be when its running, and make an image of it, then just load the image into RAM at boot.
 
  


Reply

Tags
cpu, microcontroller


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception in thread "main" java.lang.ClassFormatError: onmyown.Main (unrecognized cla zimboney Fedora 4 07-20-2007 01:00 PM
Crosscompiling C sources for an OS-less ARM microcontroller - is it possible? winterhunter Programming 2 03-26-2007 11:30 AM
Need help compiling for microcontroller jorisb Linux - Software 0 01-12-2006 04:16 PM
microcontroller programming pantera Programming 4 03-18-2005 08:37 PM
please help guys, wrong cpu speed shown with a regular non-mobile cpu !! : ( maku Linux - Hardware 1 01-02-2005 02:03 PM


All times are GMT -5. The time now is 07:43 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration